From ea4c64088ca3e387b26b32258076453e19d0b154 Mon Sep 17 00:00:00 2001 From: Dan Gohman Date: Wed, 7 Dec 2022 16:06:13 -0800 Subject: [PATCH] Update directory iteration APIs. This pulls in https://github.com/WebAssembly/wasi-filesystem/pull/72. --- host/src/filesystem.rs | 10 ++++++++-- wit/wasi.wit | 44 +++++++++++++++++++----------------------- 2 files changed, 28 insertions(+), 26 deletions(-) diff --git a/host/src/filesystem.rs b/host/src/filesystem.rs index 64308550..d7c1b62a 100644 --- a/host/src/filesystem.rs +++ b/host/src/filesystem.rs @@ -85,8 +85,14 @@ impl wasi_filesystem::WasiFilesystem for WasiCtx { fn readdir( &mut self, fd: wasi_filesystem::Descriptor, - rewind: bool, - ) -> HostResult, wasi_filesystem::Errno> { + ) -> HostResult { + todo!() + } + + fn read_dir_entry( + &mut self, + stream: wasi_filesystem::DirEntryStream, + ) -> HostResult { todo!() } diff --git a/wit/wasi.wit b/wit/wasi.wit index 2760ae84..4c556c9c 100644 --- a/wit/wasi.wit +++ b/wit/wasi.wit @@ -181,6 +181,10 @@ interface wasi-filesystem { /// A "file" descriptor. In the future, this will be replaced by handle types. type descriptor = u32 + /// A directory entry stream. In the future, this will be replaced by an + /// actual stream. + type dir-entry-stream = u32 + /// Size of a range of bytes in memory. type size = u32 @@ -318,13 +322,18 @@ interface wasi-filesystem { } /// A directory entry. - record dirent { - /// The serial number of the file referred to by this directory entry. - ino: inode, - /// The length of the name of the directory entry. - namelen: size, + record dir-entry { + /// The serial number of the object referred to by this directory entry. + /// May be none if the inode value is not known. + /// + /// When this is none, libc implementations might do an extra `stat-at` + /// call to retrieve the inode number to fill their `d_ino` fields, so + /// implementations which can set this to a non-none value should do so. + ino: option, /// The type of the file referred to by this directory entry. %type: descriptor-type, + /// The name of the object. + name: string, } /// Error codes returned by functions. @@ -610,25 +619,12 @@ interface wasi-filesystem { /// Read directory entries from a directory. /// - /// TODO this shouldnt be a binary interface. Instead, define the struct - /// and whatever of its members are required here, and then return a list - /// of those structs. Delete the rewind argument. - /// - /// When successful, the contents of the output buffer consist of a sequence of - /// directory entries. Each directory entry consists of a `dirent` object, - /// followed by `dirent::d_namlen` bytes holding the name of the directory - /// entry. - /// - /// This function fills the output buffer as much as possible, potentially - /// truncating the last directory entry. This allows the caller to grow its - /// read buffer size in case it's too small to fit a single large directory - /// entry, or skip the oversized directory entry. - readdir: func( - /// The resource to operate on. - fd: descriptor, - /// If true, rewind the current position to the beginning before reading. - rewind: bool - ) -> result, errno> + /// This always returns a new stream which starts at the beginning of the + /// directory. + readdir: func(fd: descriptor) -> result + + /// Read a single directory entry from a `dir-entry-stream`. + read-dir-entry: func(dir-stream: dir-entry-stream) -> result /// Move the offset of a descriptor. ///