From 7942bbf21c0bba8d7d7dbeb386015677dec80981 Mon Sep 17 00:00:00 2001 From: Dan Gohman Date: Fri, 13 Jan 2023 15:12:08 -0800 Subject: [PATCH] Remove the device and inode numbers from the API. As discussed [here], remove the fields which correspond to `st_dev`, `st_ino`, and `d_ino` in POSIX from the stat and directory entry structs. - Device numbers assume the existence of a global device number space, which creates implicit relationships between otherwise unrelated components. - Not all filesystem implementations have these numbers. And some that do have these numbers require extra implementation cost to retrieve them. - These numbers leak potentially sensitive or identifying information from the underlying filesystem implementation. In their place, provide two functions, `is-same-file` and `is-same-mountpoint`, for explicitly testing whether two handles are the same file or are on the same mountpoint, respectively. This doesn't cover all possible use cases for device and inode numbers, but we can add more functions as need arises. [here]: https://github.com/WebAssembly/wasi-filesystem/issues/65#issuecomment-1353986502 --- wasi-filesystem.wit.md | 47 ++++++++++++++++++++---------------------- 1 file changed, 22 insertions(+), 25 deletions(-) diff --git a/wasi-filesystem.wit.md b/wasi-filesystem.wit.md index d19ef6f..bd3b126 100644 --- a/wasi-filesystem.wit.md +++ b/wasi-filesystem.wit.md @@ -96,10 +96,6 @@ flags descriptor-flags { /// /// Note: This was called `filestat` in earlier versions of WASI. record descriptor-stat { - /// Device ID of device containing the file. - dev: device, - /// File serial number. - ino: inode, /// File type. %type: descriptor-type, /// Number of hard links to the file. @@ -162,19 +158,6 @@ flags mode { type linkcount = u64 ``` -## `device` -```wit -/// Identifier for a device containing a file system. Can be used in combination -/// with `inode` to uniquely identify a file or directory in the filesystem. -type device = u64 -``` - -## `inode` -```wit -/// Filesystem object serial number that is unique within its file system. -type inode = u64 -``` - ## `new-timestamp` ```wit /// When setting a timestamp, this gives the value to set it to. @@ -193,14 +176,6 @@ variant new-timestamp { ```wit /// A directory entry. 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, @@ -861,6 +836,28 @@ try-lock-exclusive: func() -> result<_, errno> unlock: func() -> result<_, errno> ``` +## `is-same-file` +```wit +/// Test whether two descriptors refer to the same file or directory. +/// +/// In POSIX, this corresponds to testing whether the two descriptors have the +/// same device (`st_dev`) and inode (`st_ino` or `d_ino`) numbers. +/// wasi-filesystem does not expose device and inode numbers, so this function +/// may be used instead. +is-same-file: func(other: descriptor) -> bool + +/// Test whether two descriptors refer to files or directories on the same +/// mountpoint. +/// +/// `rename-at` only works when source and destination are on the same mount +/// point. This function provides a way of testing whether two files or +/// directories are on the same mount point. +/// +/// In POSIX, this corresponds to testing whether the two descriptors have the +/// same device (`st_dev`) number. wasi-filesystem does not expose device +/// numbers, so this function may be used instead. +is-same-mountpoint(other: descriptor) -> bool + ```wit } ```