- vdisk done?
- vdiskman done?
This commit is contained in:
@@ -1,30 +1,50 @@
|
||||
import type { IDataStore, NodeHash, ShadowHash, VDisk } from "@core/filesystem/vdisk";
|
||||
|
||||
//export interface VDiskManagerConfig {}
|
||||
import { IDataStore, IMetaStore, VDisk, VDiskConfig } from "@core/filesystem/vdisk";
|
||||
|
||||
export class VDiskManager {
|
||||
private _VDiskHash: Map<number, VDisk> = new Map();
|
||||
private _disks: Map<number, VDisk>;
|
||||
private _isMounted: (id: number) => boolean;
|
||||
|
||||
public getVDisk(id: number): VDisk | undefined {
|
||||
const result = this._VDiskHash.get(id);
|
||||
if (result) return result;
|
||||
return undefined;
|
||||
constructor(isMounted: (id: number) => boolean) {
|
||||
this._disks = new Map();
|
||||
this._isMounted = isMounted;
|
||||
}
|
||||
|
||||
public registerVDisk(
|
||||
store: IDataStore,
|
||||
base: NodeHash = new Map(),
|
||||
overlay: ShadowHash = new Map(),
|
||||
id: number = 0,
|
||||
): number {
|
||||
const vdisk: VDisk = {
|
||||
id,
|
||||
store,
|
||||
base,
|
||||
overlay,
|
||||
};
|
||||
public async registerDisk(config: VDiskConfig, data: IDataStore, meta: IMetaStore): Promise<VDisk> {
|
||||
if (this._disks.has(config.id)) {
|
||||
throw new Error("Disk of this id already exists");
|
||||
}
|
||||
|
||||
this._VDiskHash.set(id, vdisk);
|
||||
return id;
|
||||
const vd = await VDisk.open(config, data, meta);
|
||||
this._disks.set(config.id, vd);
|
||||
|
||||
return vd;
|
||||
}
|
||||
|
||||
public getDisk(id: number): VDisk | undefined {
|
||||
const vd = this._disks.get(id);
|
||||
return vd;
|
||||
}
|
||||
|
||||
public hasDisk(id: number): boolean {
|
||||
return this._disks.get(id) ? true : false;
|
||||
}
|
||||
|
||||
public listDisk(): VDisk[] {
|
||||
return Array.from(this._disks.values());
|
||||
}
|
||||
|
||||
public listID(): number[] {
|
||||
return Array.from(this._disks.keys());
|
||||
}
|
||||
|
||||
public unregisterDisk(id: number): void {
|
||||
if (!this._disks.has(id)) {
|
||||
throw new Error("Disk of this id doesnt exist");
|
||||
}
|
||||
if (this._isMounted(id)) {
|
||||
throw new Error("Could not unregister disk. Is mounted.");
|
||||
}
|
||||
|
||||
this._disks.delete(id);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user