Try initializing FileSystem now

- vdisk finished
- vdiskmanager finished
- devices can properly initialize and hold aswell as retireve data
- added mock synchronous store classes for testing
This commit is contained in:
2026-09-20 12:40:38 +02:00
parent 933b1fc5e8
commit f2b5f86a6c
10 changed files with 282 additions and 602 deletions
+25 -30
View File
@@ -10,15 +10,8 @@ import type {
NodeNotFoundError,
NotADirectoryError,
} from "./errors";
import {
type DirectoryNode,
type FileNode,
type NodeEntry,
type NodeHash,
type NodePointer,
type ShadowHash,
} from "./node";
import type { IDataStore } from "./vdisk";
import { NodeType, type DirectoryNode, type FileNode, type Node, type NodePointer } from "./node";
import type { IDataStore, IMetaStore, VDiskConfig } from "./vdisk";
export interface FileSystemConfig {
maxPathLength: number;
@@ -33,24 +26,23 @@ export class FileSystem {
private _SysPartitionID: number = 0;
private _Mounts: Map<NodePointer, { tinode: number; tdevice_id: number }> = new Map();
private _VDiskManager: VDiskManager = new VDiskManager();
private _EntryCache: Map<NodePointer, NodeEntry>;
private _VDiskManager: VDiskManager;
private constructor(store: IDataStore[], base: NodeHash[], overlay: ShadowHash[], id: number[]) {
for (let i = 0; i < id.length; i++) {
if (i === 0) {
this._VDiskManager.registerVDisk(store[0]!, base[0], overlay[0], id[0]);
this._Mounts.set(0, 0);
}
this._VDiskManager.registerVDisk(store[i]!, base[i], overlay[i], id[i]);
private constructor(
config: FileSystemConfig,
devices: Array<{ dstore: IDataStore; mstore: IMetaStore; config: VDiskConfig }>,
) {
this._maxNameLength = config.maxNameLength;
this._maxPathLength = config.maxPathLength;
this._maxSymlinkDepth = config.maxSymlinkDepth;
this._VDiskManager = new VDiskManager();
for (const dev of devices) {
this._VDiskManager.registerDisk(dev.config, dev.dstore, dev.mstore);
}
this._EntryCache = this.buildNodeEntryCache();
}
private updateDentryCache(key: NodePointer, entry: NodeEntry): void {}
private resolveNode(ptr: NodePointer): TreeNode | undefined {
private resolveNode(ptr: NodePointer): Node | undefined {
const dev = this._VDiskManager.getVDisk(ptr[1]);
if (!dev) return undefined;
@@ -61,24 +53,27 @@ export class FileSystem {
return dev.base.get(ptr[0]);
}
public static init(store: IDataStore[], base: NodeHash[], overlay: ShadowHash[], index: number[]): FileSystem {
if (store.length === 0 || base.length === 0 || index.length === 0) {
public static init(
config: FileSystemConfig,
devices: Array<{ dstore: IDataStore; mstore: IMetaStore; config: VDiskConfig }>,
): FileSystem {
if (devices.length === 0) {
throw {
type: "FileSystemInitializationError",
message: "File System tried to initialized without a base hashmap and store",
message: "File System tried to initialized without any devices",
timestamp: Date.now(),
} satisfies FileSystemInitializationError;
}
if (base[0]!.get(0) === undefined) {
if (!devices.find(d => d.config.id === 0)) {
throw {
type: "FileSystemInitializationError",
message: "File System failed to initialize because root node is undefined or not assigned to inode 0",
message: "File System failed to initialize because no device with id 0 was present",
timestamp: Date.now(),
} satisfies FileSystemInitializationError;
}
if (base[0]!.get(0)?.type !== TreeNodeType.Directory) {
if (devices[0]!.config.base.get(0)?.type !== NodeType.Directory) {
throw {
type: "FileSystemInitializationError",
message: "File System failed to initialize because root node is not a directory",
@@ -86,7 +81,7 @@ export class FileSystem {
} satisfies FileSystemInitializationError;
}
return new FileSystem(store, base, overlay, index);
return new FileSystem(config, devices);
}
public getRoot(): DirectoryNode {