OS.FileSys
structureThe OS.FileSys structure provides facilities for accessing and operating on the file system. They are meant to be portable across operating systems. They raise OS.SysErr with an argument in case of errors.
Except for fullPath and realPath, functions taking a string argument will raise the OS.SysErr exception of the string is empty.
It is expected that all functions taking a pathname as an argument (e.g., modTime or OS.Process.system) will resolve any components corresponding to symbolic links. The obvious exceptions to this rule are <isLink and readLink, where only symbolic links appearing as directory components of the pathname are resolved.
We need a general discussion of dirstreams, working directory, directory structure, etc. The introduction should say something about the model of a file system that these functions use; what features they support and what examples of features that require an OS-specific library. We should also note that the particular semantics, especially concerning errors, is OS dependent.
signature OS_FILE_SYS
structure FileSys
: OS_FILE_SYS
type dirstream
val openDir : string -> dirstream
val readDir : dirstream -> string
val rewindDir : dirstream -> unit
val closeDir : dirstream -> unit
val chDir : string -> unit
val getDir : unit -> string
val mkDir : string -> unit
val rmDir : string -> unit
val isDir : string -> bool
val isLink : string -> bool
val readLink : string -> string
val fullPath : string -> string
val realPath : string -> string
val modTime : string -> Time.time
val fileSize : string -> Position.int
val setTime : (string * Time.time option) -> unit
val remove : string -> unit
val rename : {old : string, new : string} -> unit
datatype access_mode
= A_READ
| A_WRITE
| A_EXEC
val access : (string * access_mode list) -> bool
val tmpName : unit -> string
eqtype file_id
val fileId : string -> file_id
val hash : file_id -> word
val compare : (file_id * file_id) -> order
type dirstream
openDir s
readDir dir
""
is returned. readDir filters out the names corresponding to the current and parent arcs.
rewindDir dir
closeDir dir
chDir s
The chDir function will also change the current volume (on systems with volumes) if one is specified. chDir will not allow the user to change the current working directory of another volume than the current, even on systems where this concept is otherwise supported.
getDir ()
mkDir s
rmDir s
isDir s
isLink s
true
if s names a symbolic link. Raises OS.SysErr if, for example, s does not exist or there is an access violation. On operating systems without symbolic links, it will always return false
unless an exception is raised.
readLink s
The precise form of the returned string, in particular, whether it corresponds to an absolute or relative path, is system-dependent.
fullPath s
"."
. It raises OS.SysErr if, for example, a directory on the path, or the file or directory named, does not exist or is not accessible or if there is a link loop.
realPath s
Implementation note:
realPath can be implemented as:
fun realPath p = if OS.Path.isAbsolute p then fullPath p else OS.Path.mkRelative (fullPath p, fullPath (getDir ()))
modTime s
fileSize s
setTime (s, opt)
SOME t
, then the time t is used; otherwise the current time, that is, Time.now()
, is used. Raises OS.SysErr if, for example, s does not exist or if the directory in which s resides is not accessible or the user does not have appropriate permission.
remove s
If one removes a file that has been opened for reading or writing, the behavior of subsequent reads and writes is undefined. For example, removing the file may close all existing streams or generate an exception. The Unix idiom of opening a file and then removing it is not portable.
rename {old, new}
datatype access_mode
access (s, accs)
tmpName ()
eqtype file_id
fileId s
fileId p = fileId p'
, then the paths p and p' refer to the same file system object.
hash fid
Implementation note:
hash must have the property that values produced are well distributed when taken modulo 2(n) for any n.
compare (fid, fid')
OS, OS.Path, TextIO, BinIO
Last Modified October 6, 1997
Comments to John Reppy.
Copyright © 1997 Bell Labs, Lucent Technologies