[Top] [Prev] [Next]

open, create - open/create a file for reading or writing

include "sys.m";
sys:= load Sys Sys->PATH;
open:  fn(file: string, omode: int)      : ref FD;
create:fn(file: string, omode, perm: int): ref FD;

Description

open (file, omode)

The open function opens the file for I/O and returns an associated file descriptor. The omode argument is one of
OREAD

open for reading

OWRITE

open for writing

ORDWR

open for reading and writing

the following:

The following values may be OR'ed with the above values for additional actions:
OTRUNC

Truncate the file before opening it; this requires write permission even if omode is OREAD.

ORCLOSE

Remove the file on closure.

The open function returns nil if the file does not exist or the user does not have permission to open it as requested (see stat, fstat, fwstat, wstat - get and put file status for a description of permissions).

create (file, omode, perm)

The create function creates a new file or prepares to rewrite an existing file. The function opens it according to omode as described for open, and returns an associated file descriptor.

If the file is new, the owner is set to the user id of the creating process group, the group to that of the containing directory. Also the permissions to perm are AND'ed with the permissions of the containing directory. See the section - The create Transaction in Chapter 3 of open.

If the file already exists, it is truncated to 0 length, and the permissions, owner, and group remain unchanged.

file mode bits in perm
16r80000000

Directory.
The Sys module defines this as CHDIR.

8r400

Read permission by owner.

8r200

Write permission by owner.

8r100

Execute permission (search on directory) by owner

8r070

Read, write, execute (search) by group.

8r007

Read, write, execute (search) by others.

The created file will be a directory if the CHDIR bit is set in omode.

The create function returns nil if the path up to the last element of file cannot be evaluated, if the user does not have write permission in the final directory, or if the file already exists and does not permit the access defined by omode.

If the file is new and the directory in which it is created is a union directory (see Limbo System Module), then the directory where the file is created depends on the structure of the union: see bind, mount, unmount - change file name space.

Caveat

There is no explicit close routine; when the last reference to the file descriptor is released, the system closes the associated file.

For devices and network protocols where shutdown must be guaranteed, write a hangup message to the associated control file and use the return value of the write to verify closure. For example, see ip - TCP, UDP network protocols over IP in Chapter 2.

See Also
Limbo System Module

bind, mount, unmount - change file name space

stat, fstat, fwstat, wstat - get and put file status

open, create - prepare a fid for I/O on a file in Chapter 3



[Top] [Prev] [Next]

infernosupport@lucent.com
Copyright © 1996,Lucent Technologies, Inc. All rights reserved.