open, create – prepare a fid for I/O on an existing or new file
request asks the file server to check permissions and
prepare a fid for I/O with subsequent
field determines the type of I/O:
read access, write access, read and write access,
to be checked against the permissions for the file.
In addition, if
the file is to be truncated, which requires write permission
the file is append-only, and permission is granted, the
succeeds but the file will not be truncated);
bit set, the file is to be removed when the fid
is clunked, which requires permission to remove the file from its directory.
All other bits in
should be zero.
It is illegal to write a directory, truncate it, or attempt to remove it on close.
If the file is marked for exclusive use (see
only one client can have the file open at any time.
That is, after such a file has been opened,
further opens will fail until
has been clunked.
All these permissions are checked at the time of the
request; subsequent changes to the permissions of files do not affect
the ability to read, write, or remove an open file.
request asks the file server to create a new file
supplied, in the directory
and requires write permission in the directory.
The owner of the file is the implied user id of the request,
the group of the file is the same as
and the permissions are the value of
perm & (~0666 | (dir.perm & 0666))
if a regular file is being created and
perm & (~0777 | (dir.perm & 0777))
if a directory is being created.
This means, for example, that if the
allows read permission to others, but the containing directory
does not, then the created file will not allow others to read the file.
Finally, the newly created file is opened according to
will represent the newly opened file.
is not checked against the permissions in
for the new file is returned with the
Directories are created by setting the
are special; it is illegal to create files with these names.
It is an error for either of these messages if the fid
is already the product of a successful
An attempt to
a file in a directory where the given
already exists will be rejected;
in this case, the
The algorithm used by the
first walk to the directory to contain the file.
If that fails, return an error.
to the specified file.
succeeds, send a request to
and truncate the file and return the result, successful or not.
fails, send a create message.
If that fails, it may be because the file was created by another
process after the previous walk failed, so (once) try the
For the behavior of
on a union directory, see
field returned by
may be zero.
If it is not, it is the maximum number of bytes that are guaranteed to
be read from or written to the file without breaking the I/O transfer
into multiple 9P messages; see
associated with an open file may be discovered by calling
For programs that need atomic file creation, without the race
that exists in the
sequence described above,
the kernel does the following.
bit is set in the
message is not sent; the kernel issues only the
Thus, if the file exists,
will draw an error, but if it doesn’t and the
system call succeeds, the process issuing the
is guaranteed to be the one that created the file.