Skip to content

Commit

Permalink
Remove the device and inode numbers from the API.
Browse files Browse the repository at this point in the history
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]: #65 (comment)
  • Loading branch information
sunfishcode committed Jan 13, 2023
1 parent 74d7d84 commit 7942bbf
Showing 1 changed file with 22 additions and 25 deletions.
47 changes: 22 additions & 25 deletions wasi-filesystem.wit.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand All @@ -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<inode>,
/// The type of the file referred to by this directory entry.
%type: descriptor-type,
Expand Down Expand Up @@ -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
}
```

0 comments on commit 7942bbf

Please sign in to comment.