[Top] [Prev] [Next]


open, create - prepare a fid for I/O on an existing or new file


Topen   tag [2]  fid [2]  mode [1]
Ropen   tag [2]  fid [2]  qid [8]
Tcreate tag [2]  fid [2]  name [28] perm [4] mode [1]
Rcreate tag [2]  fid [2]  qid [8]


The open Transaction

The open request asks the file server to check permissions and prepare a fid for I/O with subsequent read and write messages.

The mode field expresses the type of I/O requested and is checked against the permissions for the file. Additional options can also be requested. The allowed values are shown below. If other bits are set in mode they will be ignored.

Read access.


Write access.


Read and write access.


Execute access.

OTRUNC (16r10)

The file is to be truncated when opened. This option requires write permission on the file.

ORCLOSE (16r40)

The file is to be removed when the fid is clunked. This option requires write permission in the file's directory.

It is illegal to write a directory, truncate it, or attempt to remove it on close.

All these permissions are checked at the time of the open request; any subsequent changes to the permissions of files do not affect the ability to read, write, or remove an open file.

It is an error if the fid is already the product of a successful open or create message.

The create Transaction

The create request asks the file server to create a new file with the name supplied, in the directory (dir) represented by fid. This request and requires write permission in the directory. The owner of the file is the implied user id of the request and the group of the file is the same as dir.

The permissions of the newly created file depend on the permissions of the enclosing directory (dir.perm) and the perm value of the request.

For non-directories, the formula is

	(perm&(~8r777|8r111)) | (dir.perm&perm&8r666) 

For directories, the formula is

	(perm&~8r777) | (dir.perm&perm&8r777)

This means, for example, that if the create 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 mode, and fid will represent the newly opened file. The mode is not checked against the permissions in perm.

The qid for the new file is returned with the create reply message.

Directories are created by setting the CHDIR bit (16r80000000) in the perm.

The names "." and ".." are special. It is illegal to create files with these names.

It is an error if the fid is already the product of a successful open or create message.

An attempt to create a file in a directory where the given name already exists will be rejected. The create system call (see open) uses open with truncation.

The algorithm used by the create system call is:

Walk to the directory to contain the file. If that fails, return an error.

walk to the specified file. If the walk succeeds, send a request to open (with the truncate option) the file and return the result, successful or not.

If the walk 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 walk and open (with the truncate option) again.

For the behavior of create on a union directory, see bind.

Entry Points

The open and create calls both generate open messages; only create generates a create message.

See Also

bind, open, and stat

[Top] [Prev] [Next]

Copyright © 1996,Lucent Technologies, Inc. All rights reserved.