Skip to content

Commit 0cadea9

Browse files
committed
feat: US-010 - Add fsync to VFS interface and implement write buffering in ChunkedVFS
1 parent 983da26 commit 0cadea9

6 files changed

Lines changed: 325 additions & 51 deletions

File tree

packages/core/src/kernel/kernel.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1527,6 +1527,9 @@ class KernelImpl implements Kernel {
15271527
private releaseDescriptionInode(
15281528
description: import("./types.js").FileDescription,
15291529
): void {
1530+
// Flush buffered writes to durable storage when the last FD is closed.
1531+
void this.vfs.fsync?.(description.path);
1532+
15301533
if (description.inode === undefined) return;
15311534
this.inodeTable.decrementOpenRefs(description.inode);
15321535
if (this.inodeTable.shouldDelete(description.inode)) {

packages/core/src/kernel/mount-table.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -377,6 +377,11 @@ export class MountTable implements VirtualFileSystem {
377377
return mount.fs.truncate(relativePath, length);
378378
}
379379

380+
async fsync(path: string): Promise<void> {
381+
const { mount, relativePath } = this.resolve(path);
382+
await mount.fs.fsync?.(relativePath);
383+
}
384+
380385
// -----------------------------------------------------------------------
381386
// Helpers
382387
// -----------------------------------------------------------------------

packages/core/src/kernel/vfs.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,4 +69,7 @@ export interface VirtualFileSystem {
6969

7070
/** Write data at a specific offset without replacing the entire file. */
7171
pwrite(path: string, offset: number, data: Uint8Array): Promise<void>;
72+
73+
/** Flush buffered writes for the given path to durable storage. */
74+
fsync?(path: string): Promise<void>;
7275
}

0 commit comments

Comments
 (0)