Posix.FileSys
structureThe structure Posix.FileSys provides access to file system operations as described in in Section 5 of the POSIX standard [CITE]1003.1,1996/
signature POSIX_FILE_SYS
structure FileSys
: POSIX_FILE_SYS
eqtype uid
eqtype gid
eqtype file_desc
val fdToWord : file_desc -> SysWord.word
val wordToFD : SysWord.word -> file_desc
val fdToIOD : file_desc -> OS.IO.iodesc
val iodToFD : OS.IO.iodesc -> file_desc option
type dirstream
val opendir : string -> dirstream
val readdir : dirstream -> string
val rewinddir : dirstream -> unit
val closedir : dirstream -> unit
val chdir : string -> unit
val getcwd : unit -> string
val stdin : file_desc
val stdout : file_desc
val stderr : file_desc
structure S : sig
type mode
include POSIX_FLAGS
where type flags = mode
val irwxu : mode
val irusr : mode
val iwusr : mode
val ixusr : mode
val irwxg : mode
val irgrp : mode
val iwgrp : mode
val ixgrp : mode
val irwxo : mode
val iroth : mode
val iwoth : mode
val ixoth : mode
val isuid : mode
val isgid : mode
end
structure O : sig
include POSIX_FLAGS
val append : flags
val excl : flags
val noctty : flags
val nonblock : flags
val sync : flags
val trunc : flags
end
datatype open_mode = O_RDONLY | O_WRONLY | O_RDWR
val openf : (string * open_mode * O.flags) -> file_desc
val createf : (string * open_mode * O.flags * S.mode) -> file_desc
val creat : (string * S.mode) -> file_desc
val umask : S.mode -> S.mode
val link : {old : string, new : string} -> unit
val mkdir : (string * S.mode) -> unit
val mkfifo : (string * S.mode) -> unit
val unlink : string -> unit
val rmdir : string -> unit
val rename : {old : string, new : string} -> unit
val symlink : {old : string, new : string} -> unit
val readlink : string -> string
eqtype dev
val wordToDev : SysWord.word -> dev
val devToWord : dev -> SysWord.word
eqtype ino
val wordToIno : SysWord.word -> ino
val inoToWord : ino -> SysWord.word
structure ST : sig
type stat
val isDir : stat -> bool
val isChr : stat -> bool
val isBlk : stat -> bool
val isReg : stat -> bool
val isFIFO : stat -> bool
val isLink : stat -> bool
val isSock : stat -> bool
val mode : stat -> S.mode
val ino : stat -> ino
val dev : stat -> dev
val nlink : stat -> int
val uid : stat -> uid
val gid : stat -> gid
val size : stat -> Position.int
val atime : stat -> Time.time
val mtime : stat -> Time.time
val ctime : stat -> Time.time
end
val stat : string -> ST.stat
val lstat : string -> ST.stat
val fstat : file_desc -> ST.stat
datatype access_mode
= A_READ
| A_WRITE
| A_EXEC
val access : (string * access_mode list) -> bool
val chmod : (string * S.mode) -> unit
val fchmod : (file_desc * S.mode) -> unit
val chown : (string * uid * gid) -> unit
val fchown : (file_desc * uid * gid) -> unit
val utime : (string * {actime : Time.time, modtime : Time.time} option) -> unit
val ftruncate : (file_desc * Position.int) -> unit
val pathconf : (string * string) -> SysWord.word option
val fpathconf : (file_desc * string) -> SysWord.word option
eqtype uid
eqtype gid
eqtype file_desc
fdToWord fd
wordToFD i
wordToFD
corresponds to an actually open file.
fdToIOD fd
iodToFD iod
type dirstream
opendir dirName
readdir d
"."
(current directory) and ".."
(parent directory) are never returned.
Rationale:
The reason for filtering out the current and parent directory entries is that it makes recursive walks of a directory tree easier.
rewinddir d
closedir d
chdir s
getcwd ()
stdin
stdout
stderr
structure S
type mode
val irwxu
val irusr
val iwusr
val ixusr
val irwxg
val irgrp
val iwgrp
val ixgrp
val irwxo
val iroth
val iwoth
val ixoth
val isuid
val isgid
structure O
val append
val excl
val noctty
val nonblock
val sync
trunc
datatype open_mode
O_RDONLY
O_WRONLY
O_RDWR
openf (s, om, f)
createf (s, om, f, m)
Note that, in C, the roles of openf and createf are combined in the function open
. The first acts like open
without the O_CREAT
flag; the second acts like open
with the O_CREAT
flag and the specified permission mode. Also, the createf function should not be confused with the creat function below, which behaves like its C namesake.
creat (s, m)
createf(s,O_WRONLY,O.trunc,m)
umask cmask
Whenever a file is created (by openf, creat, mkdir etc.), all file permission bits set in the file mode creation mask are cleared in the mode of the created file. This clearing allows users to restrict the default access to their files.
The mask is inherited by child processes.
link {old, new}
Both old and new must reside on the same file system. A hard link to a directory cannot be created.
Upon successful completion, link updates the file status change time of the old file, and updates the file status change and modification times of the directory containing the new entry. (See ST.)
mkdir (s, m)
mkfifo (s, m)
unlink path
When all links to a file are removed and no process has the file open or mapped, all resources associated with the file are reclaimed, and the file is no longer accessible. If one or more processes have the file open or mapped when the last link is removed, the link is removed before unlink returns, but the removal of the file contents is post- poned until all open or map references to the file are removed. If the path parameter names a symbolic link, the symbolic link itself is removed.
rmdir s
rename {old, new}
symlink {old, new}
readlink s
eqtype dev
wordToDev i
devToWord dev
eqtype ino
wordToIno i
inoToWord ino
structure ST
type stat
isDir st
true
if the file is a directory.
isChr st
true
if the file is a character special device.
isBlk st
true
if the file is a block special device.
isReg st
true
if the file is a regular file.
isFIFO st
true
if the file is a FIFO.
isLink st
true
if the file is a symbolic link.
isSock st
true
if the file is a socket.
mode st
ino st
dev st
nlink st
uid st
gid st
size st
atime st
mtime st
ctime st
stat s
lstat s
fstat fd
lstat differs from stat in that, if s is a symbolic link, the information concerns the link itself, not the file to which the link points.
datatype access_mode
access (s, l)
Only access bits are checked. A directory may be indicated as writable by access, but an attempt to open it for writing will fail (although files may be created there); a file's access bits may indicate that it is executable, but the exec can fail if the file does not contain the proper format.
chmod (s, mode)
fchmod (fd, mode)
chown (s, uid, gid)
fchown (fd, uid, gid)
utime (s, SOME(a,m))
utime (s, NONE)
ftruncate (fd, n)
pathconf (s, p)
fpathconf (fd, p)
SOME v
is returned, where v is the value. The OS.SysErr exception is raised if something goes wrong, including if the name p is not a valid property, or if the implementation does not associate the property with the file.
In the case of pathconf, read, write, or execute permission of the named file is not required, but all directories in the path leading to the file must be searchable.
The properties required by Posix are described below. A given implementation may support additional properties.
Posix, Posix.ProcEnv, Posix.Process, Posix.IO
Last Modified June 14, 1996
Comments to John Reppy.
Copyright © 1997 Bell Labs, Lucent Technologies