Skip to content

Commit

Permalink
Fuse fd_prestat_dir_name into fd_prestat_get
Browse files Browse the repository at this point in the history
  • Loading branch information
bjorn3 committed Apr 9, 2024
1 parent 820b625 commit a62707f
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 24 deletions.
3 changes: 0 additions & 3 deletions src/fd.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,6 @@ export abstract class Fd {
fd_prestat_get(): { ret: number; prestat: wasi.Prestat | null } {
return { ret: wasi.ERRNO_NOTSUP, prestat: null };
}
fd_prestat_dir_name(): { ret: number; prestat_dir_name: string | null } {
return { ret: wasi.ERRNO_NOTSUP, prestat_dir_name: null };
}
fd_pwrite(
data: Uint8Array,
offset: bigint,
Expand Down
9 changes: 1 addition & 8 deletions src/fs_mem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -456,14 +456,7 @@ export class PreopenDirectory extends OpenDirectory {
fd_prestat_get(): { ret: number; prestat: wasi.Prestat | null } {
return {
ret: 0,
prestat: wasi.Prestat.dir(this.prestat_name.length),
};
}

fd_prestat_dir_name(): { ret: number; prestat_dir_name: string } {
return {
ret: 0,
prestat_dir_name: this.prestat_name,
prestat: wasi.Prestat.dir(this.prestat_name),
};
}
}
Expand Down
12 changes: 5 additions & 7 deletions src/wasi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -341,18 +341,16 @@ export default class WASI {
): number {
// FIXME don't ignore path_len
if (self.fds[fd] != undefined) {
const { ret, prestat_dir_name } = self.fds[fd].fd_prestat_dir_name();
if (prestat_dir_name == null) {
const { ret, prestat } = self.fds[fd].fd_prestat_get();
if (prestat == null) {
return ret;
}
const encoded_prestat_dir_name = new TextEncoder().encode(
prestat_dir_name,
);
const prestat_dir_name = prestat.inner.pr_name;

const buffer8 = new Uint8Array(self.inst.exports.memory.buffer);
buffer8.set(encoded_prestat_dir_name.slice(0, path_len), path_ptr);
buffer8.set(prestat_dir_name.slice(0, path_len), path_ptr);

return encoded_prestat_dir_name.byteLength > path_len
return prestat_dir_name.byteLength > path_len
? wasi.ERRNO_NAMETOOLONG
: wasi.ERRNO_SUCCESS;
} else {
Expand Down
12 changes: 6 additions & 6 deletions src/wasi_defs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -341,14 +341,14 @@ export const SDFLAGS_WR = 1 << 1;
export const PREOPENTYPE_DIR = 0;

export class PrestatDir {
pr_name_len: number;
pr_name: Uint8Array;

constructor(name_len: number) {
this.pr_name_len = name_len;
constructor(name: string) {
this.pr_name = new TextEncoder().encode(name);
}

write_bytes(view: DataView, ptr: number) {
view.setUint32(ptr, this.pr_name_len, true);
view.setUint32(ptr, this.pr_name.byteLength, true);
}
}

Expand All @@ -358,10 +358,10 @@ export class Prestat {
//@ts-ignore strictPropertyInitialization
inner: PrestatDir;

static dir(name_len: number): Prestat {
static dir(name: string): Prestat {
const prestat = new Prestat();
prestat.tag = PREOPENTYPE_DIR;
prestat.inner = new PrestatDir(name_len);
prestat.inner = new PrestatDir(name);
return prestat;
}

Expand Down

0 comments on commit a62707f

Please sign in to comment.