![]() | Library Documentation | Structures | Signatures | Identifiers | Packages | About |
POSIX_FILE_SYS (basis)POSIX file system operations.
The structure Posix.FileSys provides access to file system operations as described in Section 5 of the POSIX standard 1003.1,1996.signature POSIX_FILE_SYS =
sig
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 option
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
eqtype mode
include BIT_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 FD :
sig
include BIT_FLAGS
val cloexec : flags
end
structure O :
sig
include BIT_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
end
Rationale: The reason for filtering out the current and parent
directory entries is that it makes recursive walks of a directory
tree easier.
[eqtype mode] A file mode is a set of (read, write, execute)
permissions for the owner of the file, members of the file's
group, and others.
[irwxu] Read, write, and execute permission for ``user'' (the
file's owner).
[irusr] Read permission for ``user'' (the file's owner).
[iwusr] Write permission for ``user'' (the file's owner).
[ixusr] Execute permission for ``user'' (the file's owner).
[irwxg] Read, write, and execute permission for members of the
file's group.
[irgrp] Read permission for members of the file's group.
[iwgrp] Write permission for members of the file's group.
[ixgrp] Execute permission for members of the file's group.
[irwxo] Read, write, and execute permission for ``others'' (all
users).
[iroth] Read permission for ``others'' (all users).
[iwoth] Write permission for ``others'' (all users).
[ixoth] Execute permission for ``others'' (all users).
[isuid] Set-user-id mode, indicating that the effective user ID of
any user executing the file should be made the same as that of the
owner of the file.
[isgid] Set-group-id mode, indicating that the effective group ID
of any user executing the file should be made the same as the
group of the file.
[append] If set, the file pointer is set to the end of the file
prior to each write.
[excl] This flag causes the open to fail if the file already
exists.
[noctty] If the path parameter identifies a terminal device, this
flag assures that the terminal device does not become the
controlling terminal for the process.
[nonblock] Open, read, and write operations on the file will be
nonblocking.
[sync] If set, updates and writes to regular files and block
devices are synchronous updates. On return from a function that
performs a synchronous update (writeVec, writeArr, ftruncate,
openf with trunc), the calling process is assured that all data
for the file has been written to permanent storage, even if the
file is also open for deferred update.
[trunc] This causes the file to be truncated (to zero length) upon
opening.
O_RDONLY : Open a file for reading only.
O_WRONLY : Open a file for writing only.
O_RDWR : Open a file for reading and writing.
[type stat] This type models status information concerning a file.
[isDir stat]
[isChr stat]
[isBlk stat]
[isReg stat]
[isFIFO stat]
[isLink stat]
[isSock stat]
These functions return true if the file described by the parameter
is, respectively, a directory, a character special device, a block
special device, a regular file, a FIFO, a symbolic link, or a
socket.
[mode st] returns the protection mode of the file described by st.
[ino stat]
[dev stat]
These functions return the file serial number (inode) and the
device identifier, respectively, of the corresponding file.
[nlink st] returns the number of hard links to the file described
by st.
[uid stat]
[gid stat]
These functions return the owner and group ID of the file.
[size st] returns the size (number of bytes) of the file described
by st.
[atime stat]
[mtime stat]
[ctime stat]
These functions return, respectively, the last access time, the
last modification time or the last status change time of the file.
"CHOWN_RESTRICTED" True if the use of chown on any files (other
than directories) in the specified directory is
restricted to processes with appropriate
privileges. This property only applies to
directories.
"LINK_MAX" The maximum value of a file's link count as
returned by the ST.nlink function.
"MAX_CANON" The maximum number of bytes that can be stored
in an input queue. This property only applies
to terminal devices.
"MAX_INPUT" The maximum number of bytes allowed in an input
queue before being read by a process. This
property only applies to terminal devices.
"NAME_MAX" The maximum number of bytes in a filename. This
value may be as small as 13, but is never
larger than 255. This property only applies to
directories and its value applies to filenames
within the directory.
"NO_TRUNC" True if supplying a filename longer than
allowed by "NAME_MAX" causes an error; false if
long filenames are truncated. This property
only applies to directories.
"PATH_MAX" The maximum number of bytes in a pathname. This
value is never larger than 65,535 and is the
maximum length of a relative pathname when the
specified directory is the working
directory. This property only applies to
directories.
"PIPE_BUF" Maximum number of bytes guaranteed to be
written atomically. This is applicable only to
a FIFO. The value returned applies to the
referenced object. If the path or file
descriptor parameter refers to a directory, the
value returned applies to any FIFO that exists
or can be created within the directory.
"VDISABLE" If defined, the integer code ord(c) of the
character c which can be used to disable the
terminal special characters specified in
Posix.TTY.V. This property only applies to
terminal devices.
"ASYNC_IO" True if asynchronous input or output operations
may be performed on the file.
"SYNC_IO" True if synchronous input or output operations
may be performed on the file.
"PRIO_IO" True if prioritized input or output operations
may be performed on the file.
Implementation note: An implementation can call the operating system's
pathconf or fpathconf functions, which return an integer. If the
returned value is -1 and errno has been set, an exception is
raised. Otherwise, a returned value of -1 should be mapped to NONE,
and other values should be wrapped in SOME and returned.