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

Commit

Permalink
Streamlined volume descriptors
Browse files Browse the repository at this point in the history
  • Loading branch information
james-pre committed May 9, 2024
1 parent 3e08c9e commit caff7a8
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 21 deletions.
16 changes: 12 additions & 4 deletions package-lock.json

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

3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,5 +48,8 @@
},
"peerDependencies": {
"@zenfs/core": "^0.10.0"
},
"dependencies": {
"utilium": "^0.3.4"
}
}
10 changes: 5 additions & 5 deletions src/IsoFS.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { NoSyncFile, isWriteable } from '@zenfs/core/file.js';
import { FileSystem, Readonly, Sync, type FileSystemMetadata } from '@zenfs/core/filesystem.js';
import { FileType, Stats } from '@zenfs/core/stats.js';
import { DirectoryRecord } from './DirectoryRecord.js';
import { PrimaryOrSupplementaryVolumeDescriptor, PrimaryVolumeDescriptor, SupplementaryVolumeDescriptor, VolumeDescriptor, VolumeDescriptorTypeCode } from './VolumeDescriptor.js';
import { PrimaryOrSupplementaryVolumeDescriptor, PrimaryVolumeDescriptor, SupplementaryVolumeDescriptor, VolumeDescriptor, VolumeDescriptorType } from './VolumeDescriptor.js';
import { PXEntry, TFEntry, TFFlags } from './entries.js';

/**
Expand Down Expand Up @@ -55,13 +55,13 @@ export class IsoFS extends Readonly(Sync(FileSystem)) {
const slice = this._data.slice(i);
const vd = new VolumeDescriptor(slice);
switch (vd.type) {
case VolumeDescriptorTypeCode.PrimaryVolumeDescriptor:
case VolumeDescriptorType.Primary:
candidateVDs.push(new PrimaryVolumeDescriptor(slice));
break;
case VolumeDescriptorTypeCode.SupplementaryVolumeDescriptor:
case VolumeDescriptorType.Supplementary:
candidateVDs.push(new SupplementaryVolumeDescriptor(slice));
break;
case VolumeDescriptorTypeCode.VolumeDescriptorSetTerminator:
case VolumeDescriptorType.SetTerminator:
vdTerminatorFound = true;
break;
}
Expand All @@ -72,7 +72,7 @@ export class IsoFS extends Readonly(Sync(FileSystem)) {
}
for (const v of candidateVDs) {
// Take an SVD over a PVD.
if (!this._pvd || this._pvd.type !== VolumeDescriptorTypeCode.SupplementaryVolumeDescriptor) {
if (!this._pvd || this._pvd.type !== VolumeDescriptorType.Supplementary) {
this._pvd = v;
}
}
Expand Down
24 changes: 12 additions & 12 deletions src/VolumeDescriptor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,20 @@ import { ErrnoError, Errno } from '@zenfs/core/error.js';
import { DirectoryRecord, ISODirectoryRecord, JolietDirectoryRecord } from './DirectoryRecord.js';
import { getASCIIString, getDate, getJolietString } from './utils.js';

export const enum VolumeDescriptorTypeCode {
export const enum VolumeDescriptorType {
BootRecord = 0,
PrimaryVolumeDescriptor = 1,
SupplementaryVolumeDescriptor = 2,
VolumePartitionDescriptor = 3,
VolumeDescriptorSetTerminator = 255,
Primary = 1,
Supplementary = 2,
Partition = 3,
SetTerminator = 255,
}

export class VolumeDescriptor {
protected _view: DataView;
constructor(protected _data: ArrayBuffer) {
this._view = new DataView(_data);
}
public get type(): VolumeDescriptorTypeCode {
public get type(): VolumeDescriptorType {
return this._view[0];
}
public get standardIdentifier(): string {
Expand Down Expand Up @@ -124,7 +124,7 @@ export abstract class PrimaryOrSupplementaryVolumeDescriptor extends VolumeDescr
export class PrimaryVolumeDescriptor extends PrimaryOrSupplementaryVolumeDescriptor {
constructor(data: ArrayBuffer) {
super(data);
if (this.type !== VolumeDescriptorTypeCode.PrimaryVolumeDescriptor) {
if (this.type !== VolumeDescriptorType.Primary) {
throw new ErrnoError(Errno.EIO, `Invalid primary volume descriptor.`);
}
}
Expand All @@ -142,21 +142,21 @@ export class PrimaryVolumeDescriptor extends PrimaryOrSupplementaryVolumeDescrip
export class SupplementaryVolumeDescriptor extends PrimaryOrSupplementaryVolumeDescriptor {
constructor(data: ArrayBuffer) {
super(data);
if (this.type !== VolumeDescriptorTypeCode.SupplementaryVolumeDescriptor) {
throw new ErrnoError(Errno.EIO, `Invalid supplementary volume descriptor.`);
if (this.type !== VolumeDescriptorType.Supplementary) {
throw new ErrnoError(Errno.EIO, 'Invalid supplementary volume descriptor.');
}
const escapeSequence = this.escapeSequence();
const escapeSequence = this.escapeSequence;
const third = escapeSequence[2];
// Third character identifies what 'level' of the UCS specification to follow.
// We ignore it.
if (escapeSequence[0] !== 37 || escapeSequence[1] !== 47 || (third !== 64 && third !== 67 && third !== 69)) {
throw new ErrnoError(Errno.EIO, `Unrecognized escape sequence for SupplementaryVolumeDescriptor: ${escapeSequence.toString()}`);
throw new ErrnoError(Errno.EIO, 'Unrecognized escape sequence for SupplementaryVolumeDescriptor: ' + escapeSequence.toString());
}
}
public get name() {
return 'Joliet';
}
public escapeSequence(): ArrayBuffer {
public get escapeSequence(): ArrayBuffer {
return this._data.slice(88, 120);
}
protected _constructRootDirectoryRecord(data: ArrayBuffer): DirectoryRecord {
Expand Down

0 comments on commit caff7a8

Please sign in to comment.