|
1 | 1 | package wasi:filesystem;
|
2 | 2 | interface types {
|
3 |
| - use wasi:clocks/wall-clock.{datetime}; |
4 | 3 |
|
5 |
| - /// File size or length of a region within a file. |
6 |
| - type filesize = u64; |
7 |
| - |
8 |
| - /// The type of a filesystem object referenced by a descriptor. |
9 |
| - enum descriptor-type { |
10 |
| - /// The descriptor refers to a directory inode. |
11 |
| - directory, |
12 |
| - /// The descriptor refers to a regular file inode. |
13 |
| - regular-file, |
14 |
| - } |
15 |
| - |
16 |
| - /// File attributes. |
17 |
| - record descriptor-stat { |
18 |
| - /// File type. |
19 |
| - %type: descriptor-type, |
20 |
| - /// File size in bytes. |
21 |
| - size: filesize, |
22 |
| - /// Last data access timestamp (optional). |
23 |
| - data-access-timestamp: option<datetime>, |
24 |
| - } |
25 |
| - |
26 |
| - /// Open flags used by `open-at`. |
27 |
| - flags open-flags { |
28 |
| - /// Create file if it does not exist, similar to `O_CREAT` in POSIX. |
29 |
| - create, |
30 |
| - /// Fail if not a directory, similar to `O_DIRECTORY` in POSIX. |
31 |
| - directory, |
32 |
| - } |
33 |
| - |
34 |
| - /// When setting a timestamp, this gives the value to set it to. |
35 |
| - variant new-timestamp { |
36 |
| - /// Leave the timestamp set to its previous value. |
37 |
| - no-change, |
38 |
| - /// Set the timestamp to the current time of the system clock associated |
39 |
| - /// with the filesystem. |
40 |
| - now, |
41 |
| - /// Set the timestamp to the given value. |
42 |
| - timestamp(datetime), |
43 |
| - } |
44 |
| - |
45 |
| - /// Error codes returned by functions, similar to `errno` in POSIX. |
46 | 4 | enum error-code {
|
47 |
| - /// Permission denied, similar to `EACCES` in POSIX. |
48 | 5 | access,
|
49 |
| - /// Resource unavailable, or operation would block, similar to `EAGAIN` and `EWOULDBLOCK` in POSIX. |
50 |
| - would-block, |
51 |
| - /// Connection already in progress, similar to `EALREADY` in POSIX. |
52 |
| - already, |
53 |
| - /// Bad descriptor, similar to `EBADF` in POSIX. |
54 | 6 | bad-descriptor,
|
55 |
| - /// Device or resource busy, similar to `EBUSY` in POSIX. |
56 |
| - busy, |
57 | 7 | }
|
58 | 8 |
|
59 |
| - /// A descriptor is a reference to a filesystem object, which may be a |
60 |
| - /// file or directory. |
61 | 9 | resource descriptor {
|
62 |
| - /// Read from a descriptor, without using and updating the descriptor's offset. |
63 |
| - /// |
64 |
| - /// This function returns a list of bytes containing the data that was |
65 |
| - /// read, along with a bool which, when true, indicates that the end of the |
66 |
| - /// file was reached. |
67 | 10 | read: func(
|
68 |
| - /// The maximum number of bytes to read. |
69 | 11 | length: filesize,
|
70 |
| - /// The offset within the file at which to read. |
71 | 12 | offset: filesize,
|
72 | 13 | ) -> result<tuple<list<u8>, bool>, error-code>;
|
73 | 14 |
|
74 |
| - /// Return the attributes of an open file or directory. |
75 |
| - stat: func() -> result<descriptor-stat, error-code>; |
76 |
| - |
77 |
| - /// Adjust the timestamps of a file or directory. |
78 |
| - set-times-at: func( |
79 |
| - /// The relative path of the file or directory to operate on. |
80 |
| - path: string, |
81 |
| - /// The desired values of the data access timestamp. |
82 |
| - data-access-timestamp: new-timestamp, |
83 |
| - ) -> result<_, error-code>; |
84 |
| - |
85 |
| - /// Open a file or directory. |
86 | 15 | open-at: func(
|
87 |
| - /// The relative path of the object to open. |
88 | 16 | path: string,
|
89 |
| - /// The method by which to open the file. |
90 |
| - open-flags: open-flags, |
91 | 17 | ) -> result<descriptor, error-code>;
|
92 | 18 |
|
93 | 19 | }
|
|
0 commit comments