Charles.Forsyth20060303-partialeea662d19 years agoHistory
135 lines · 3.2 KB · Text
RawDownload
.TH SYS-OPEN 2.SH NAMEopen, create \- open a file for reading or writing, create file.SH SYNOPSIS.EXinclude "sys.m";sys := load Sys Sys->PATH; create: fn(file: string, omode, perm: int): ref FD;open:   fn(file: string, omode: int):       ref FD;.EE.SH DESCRIPTION.B Openopens the.I filefor I/O and returns an associated file descriptor..I Omodeis one of.BR Sys->OREAD ,.BR Sys->OWRITE ,or.BR Sys->ORDWR ,asking for permission to read, write, or read and write, respectively.There are two values that can be OR'd with those to form.IR omode :.B Sys->OTRUNCsays to truncate the file before opening it, which requires write permissioneven if.I omodeis.BR Sys->OREAD ;and.B Sys->ORCLOSEsays to remove the file when it is closed (ie, when the last referenceto this file descriptor goes away)..PP.B Openreturns.B nilif the file does not exist, if the file name is unacceptable, if the user does not havepermission to open it as requested(see.IR sys-stat (2)for a description of permissions),or if any other error occurs..PP.B Createcreates a new.I fileor prepares to rewrite an existing.IR file ,opens it according to.I omode(as described for.BR open ),and returns an associated file descriptor..PPIf the file is new,the owner is set to the.I "user idof the creating process group,the group to that of the containing directory,and the permissions to.I permANDed with the permissions of the containing directory.The bits in .I permare the same as thosein the file mode returned by .IR sys-stat (2)..PPIf the file already exists,it is truncated to 0 length,but the permissions, owner, and group remain unchanged..PPThe created file will be a directory if the.B Sys->DMDIRbit is set in.IR perm ,and.I omodeis.BR Sys->OREAD .The file will be exclusive-use if the.B Sys->DMEXCLbit is set in.I permand the underlying file server supports it;see.IR open (5)for details.It will be append-only if the.B Sys->DMAPPENDbit is set, and the underlying file server supports it..PP.B Createreturns.B nilif the path up to the last element of.I filecannot be evaluated, if the file name is unacceptable,if the user does not have write permission in the final directory,if the file already exists and does not permit the access defined by.IR omode,or if any other error occurs..PPIf the file is new and the directory in which it is created isa union directory (see.IR sys-intro (2))then the constituent directory where the file is createddepends on the structure of the union: see.IR sys-bind (2)..PPSince create may succeed even if the file exists, a special mechanismis necessary for applications that require an atomic create operation.If the.B Sys->OEXCLbit is set in the mode for a create, the call succeeds only ifthe file does not already exist; see.IR open (5)for details..PPThere 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.B hangupmessage to the associated control file and use the return value of the.B writeto verify closure..SH SEE ALSO.IR sys-intro (2),.IR sys-bind (2),.IR sys-stat (2)