Skip to content
This repository has been archived by the owner on Dec 10, 2024. It is now read-only.

Commit

Permalink
Overhauled to use struct
Browse files Browse the repository at this point in the history
  • Loading branch information
james-pre committed May 16, 2024
1 parent caff7a8 commit b6f9c71
Show file tree
Hide file tree
Showing 8 changed files with 217 additions and 292 deletions.
2 changes: 1 addition & 1 deletion jest.config.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"^.+\\.ts$": [
"ts-jest",
{
"tsconfig": "test/tsconfig.json",
"tsconfig": "tests/tsconfig.json",
"useESM": true
}
]
Expand Down
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
"typescript": "5.2.2"
},
"peerDependencies": {
"@zenfs/core": "^0.10.0"
"@zenfs/core": "~0.11.0"
},
"dependencies": {
"utilium": "^0.3.4"
Expand Down
14 changes: 7 additions & 7 deletions src/Directory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ export abstract class Directory<T extends DirectoryRecord> {
constructor(record: T, isoData: ArrayBuffer) {
this._record = record;
let i = record.lba;
let iLimit = i + record.dataLength;
let limit = i + record.dataLength;
if (!(record.fileFlags & FileFlags.Directory)) {
// Must have a CL entry.
const cl = <CLEntry>record.getSUEntries(isoData).filter(e => e instanceof CLEntry)[0];
i = cl.childDirectoryLba() * 2048;
iLimit = Infinity;
const cl = record.getSUEntries(isoData).filter(e => e instanceof CLEntry)[0] as CLEntry;
i = cl.childDirectoryLba * 2048;
limit = Infinity;
}

while (i < iLimit) {
while (i < limit) {
const len = isoData[i];
// Zero-padding between sectors.
// TODO: Could optimize this to seek to nearest-sector upon
Expand All @@ -35,9 +35,9 @@ export abstract class Directory<T extends DirectoryRecord> {
this._fileMap[fname] = r;
this._fileList.push(fname);
}
} else if (iLimit === Infinity) {
} else if (limit === Infinity) {
// First entry contains needed data.
iLimit = i + r.dataLength;
limit = i + r.dataLength;
}
i += r.length;
}
Expand Down
12 changes: 6 additions & 6 deletions src/DirectoryRecord.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,13 +169,13 @@ export abstract class DirectoryRecord {
protected abstract _constructDirectory(isoData: ArrayBuffer): Directory<DirectoryRecord>;
protected _rockRidgeFilename(isoData: ArrayBuffer): string | null {
const nmEntries = <NMEntry[]>this.getSUEntries(isoData).filter(e => e instanceof NMEntry);
if (nmEntries.length === 0 || nmEntries[0].flags() & (NMFlags.CURRENT | NMFlags.PARENT)) {
if (nmEntries.length === 0 || nmEntries[0].flags & (NMFlags.CURRENT | NMFlags.PARENT)) {
return null;
}
let str = '';
for (const e of nmEntries) {
str += e.name(this._getString);
if (!(e.flags() & NMFlags.CONTINUE)) {
if (!(e.flags & NMFlags.CONTINUE)) {
break;
}
}
Expand All @@ -188,7 +188,7 @@ export abstract class DirectoryRecord {
i++;
}
i += this._rockRidgeOffset;
this._suEntries = constructSystemUseEntries(this.data, i, this.length, isoData);
this._suEntries = constructSystemUseEntries(this.data, i, BigInt(this.length), isoData);
}
/**
* !!ONLY VALID ON FIRST ENTRY OF ROOT DIRECTORY!!
Expand All @@ -202,13 +202,13 @@ export abstract class DirectoryRecord {
const suEntries = this.getSUEntries(isoData);
if (suEntries.length > 0) {
const spEntry = suEntries[0];
if (spEntry instanceof SPEntry && spEntry.checkBytesPass()) {
if (spEntry instanceof SPEntry && spEntry.checkMagic()) {
// SUSP is in use.
for (let i = 1; i < suEntries.length; i++) {
const entry = suEntries[i];
if (entry instanceof RREntry || (entry instanceof EREntry && entry.extensionIdentifier() === rockRidgeIdentifier)) {
if (entry instanceof RREntry || (entry instanceof EREntry && entry.extensionIdentifier === rockRidgeIdentifier)) {
// Rock Ridge is in use!
return spEntry.bytesSkipped();
return spEntry.skip;
}
}
}
Expand Down
25 changes: 12 additions & 13 deletions src/IsoFS.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { ErrnoError, Errno } from '@zenfs/core/error.js';
import type { Backend } from '@zenfs/core/backends/backend.js';
import type { Cred } from '@zenfs/core/cred.js';
import * as path from '@zenfs/core/emulation/path.js';
import { resolve } from '@zenfs/core/emulation/path.js';
import { NoSyncFile, isWriteable } from '@zenfs/core/file.js';
import { FileSystem, Readonly, Sync, type FileSystemMetadata } from '@zenfs/core/filesystem.js';
Expand Down Expand Up @@ -89,12 +88,12 @@ export class IsoFS extends Readonly(Sync(FileSystem)) {
};
}

public statSync(p: string): Stats {
const record = this._getDirectoryRecord(p);
public statSync(path: string): Stats {
const record = this._getDirectoryRecord(path);
if (!record) {
throw ErrnoError.With('ENOENT', p, 'stat');
throw ErrnoError.With('ENOENT', path, 'stat');
}
return this._getStats(p, record)!;
return this._getStats(path, record)!;
}

public openFileSync(path: string, flag: string, cred: Cred): NoSyncFile<this> {
Expand Down Expand Up @@ -150,9 +149,9 @@ export class IsoFS extends Readonly(Sync(FileSystem)) {
return dir;
}

private _getStats(p: string, record: DirectoryRecord): Stats | null {
private _getStats(path: string, record: DirectoryRecord): Stats | null {
if (record.isSymlink(this._data)) {
const newP = path.resolve(p, record.getSymlinkPath(this._data));
const newP = resolve(path, record.getSymlinkPath(this._data));
const dirRec = this._getDirectoryRecord(newP);
if (!dirRec) {
return null;
Expand All @@ -169,22 +168,22 @@ export class IsoFS extends Readonly(Sync(FileSystem)) {
const entries = record.getSUEntries(this._data);
for (const entry of entries) {
if (entry instanceof PXEntry) {
mode = entry.mode();
mode = Number(entry.mode);
continue;
}

if (!(entry instanceof TFEntry)) {
continue;
}
const flags = entry.flags();
const flags = entry.flags;
if (flags & TFFlags.ACCESS) {
atimeMs = entry.access()!.getTime();
atimeMs = entry.access!.getTime();
}
if (flags & TFFlags.MODIFY) {
mtimeMs = entry.modify()!.getTime();
mtimeMs = entry.modify!.getTime();
}
if (flags & TFFlags.CREATION) {
ctimeMs = entry.creation()!.getTime();
ctimeMs = entry.creation!.getTime();
}
}
}
Expand Down Expand Up @@ -223,4 +222,4 @@ export const Iso = {
create(options: IsoOptions) {
return new IsoFS(options);
},
} satisfies Backend<IsoFS, IsoOptions>;
} as const satisfies Backend<IsoFS, IsoOptions>;
Loading

0 comments on commit b6f9c71

Please sign in to comment.