Sys/File
Edit on GitHubThis module provides utilities to access the filesystem.
Many of the functions in this module are not intended to be used directly, but rather for other libraries to be built on top of them.
Types
File.FileDescriptor
A FileDescriptor represents a handle to an open file on the system.
File.LookupFlag
These flags determine how paths should be resolved when looking up a file or directory.
File.OpenFlag
1 | enum OpenFlag { |
These flags determine how a file or directory should be opened.
File.Rights
These flags determine which rights a FileDescriptor
should have and which rights new FileDescriptor
s should inherit from this FileDescriptor
.
File.FdFlag
These flags determine the mode(s) that a file descriptor operates in.
File.Filetype
The type of file a FileDescriptor
refers to.
File.Whence
1 | enum Whence { |
These flags determine where seeking should begin in a file.
File.Stats
1 | record Stats { |
Information about a FileDescriptor
.
File.Filestats
1 | record Filestats { |
Information about the file that a FileDescriptor
refers to.
File.DirectoryEntry
An entry in a directory.
Values
File.stdin
The FileDescriptor
for stdin
.
File.stdout
The FileDescriptor
for stdout
.
File.stderr
The FileDescriptor
for stderr
.
File.pwdfd
The FileDescriptor
for the current working directory of the process.
File.pathOpen
1 | pathOpen : ( |
Open a file or directory.
Parameters:
- dirFd: The directory in which path resolution starts
- dirFlags: Flags which affect path resolution
- path: The path to the file or directory
- openFlags: Flags that decide how the path will be opened
- rights: The rights that dictate what may be done with the returned file descriptor
- rightsInheriting: The rights that dictate what may be done with file descriptors derived from this file descriptor
- flags: Flags which affect read/write operations on this file descriptor
Returns a FileDescriptor
for the opened file or directory.
File.fdRead
Read from a file descriptor.
Parameters:
- fd: FileDescriptor The file descriptor to read from
- size: Number The maximum number of bytes to read from the file descriptor
Returns the bytes read and the number of bytes read.
File.fdPread
Read from a file descriptor without updating the file descriptor’s offset.
- fd: The file descriptor to read from
- offset: The position within the file to begin reading
- size: The maximum number of bytes to read from the file descriptor
Returns the bytes read and the number of bytes read.
File.fdWrite
Write to a file descriptor.
Parameters:
- fd: The file descriptor to which data will be written
- data: The data to be written
Returns the number The number of bytes written.
File.fdPwrite
Write to a file descriptor without updating the file descriptor’s offset.
Parameters:
- fd: The file descriptor to which data will be written
- data: The data to be written
- offset: The position within the file to begin writing
Returns the number The number of bytes written.
File.fdAllocate
Allocate space within a file.
Parameters:
- fd: The file descriptor in which space will be allocated
- offset: The position within the file to begin writing
- size: The number of bytes to allocate
File.fdClose
Close a file descriptor.
Parameters:
- fd: The file descriptor to close
File.fdDatasync
Synchronize the data of a file to disk.
Parameters:
- fd: The file descriptor to synchronize
File.fdSync
Synchronize the data and metadata of a file to disk.
Parameters:
- fd: The file descriptor to synchronize
File.fdStats
Retrieve information about a file descriptor.
Parameters:
- fd: The file descriptor of which to retrieve information
Returns a record containing the filetype, flags, rights, and inheriting rights associated with the file descriptor.
File.fdSetFlags
Update the flags associated with a file descriptor.
Parameters:
- fd: The file descriptor to update flags
- flags: The flags to apply to the file descriptor
File.fdSetRights
Update the rights associated with a file descriptor.
Parameters:
- fd: The file descriptor to update rights
- rights: Rights to apply to the file descriptor
- rightsInheriting: Inheriting rights to apply to the file descriptor
File.fdFilestats
Retrieve information about a file.
Parameters:
- fd: The file descriptor of the file to retrieve information
Returns a record containing the information about the file.
File.fdSetSize
Set (truncate) the size of a file.
Parameters:
- fd: The file descriptor of the file to truncate
- size: The number of bytes to retain in the file
File.fdSetAccessTime
Set the access (created) time of a file.
Parameters:
- fd: The file descriptor of the file to update
- timestamp: The time to set
File.fdSetAccessTimeNow
Set the access (created) time of a file to the current time.
Parameters:
- fd: The file descriptor of the file to update
File.fdSetModifiedTime
Set the modified time of a file.
Parameters:
- fd: The file descriptor of the file to update
- timestamp: The time to set
File.fdSetModifiedTimeNow
Set the modified time of a file to the current time.
Parameters:
- fd: The file descriptor of the file to update
File.fdReaddir
Read the entries of a directory.
Parameters:
- fd: The directory to read.
Returns an array of records containing information about each entry in the directory.
File.fdRenumber
Atomically replace a file descriptor by renumbering another file descriptor.
Parameters:
- fromFd: The file descriptor to renumber
- toFd: The file descriptor to overwrite
File.fdSeek
Update a file descriptor’s offset.
Parameters:
- fd: The file descriptor to operate on
- offset: The number of bytes to move the offset
- whence: The location from which the offset is relative
Returns the new offset of the file descriptor, relative to the start of the file.
File.fdTell
Read a file descriptor’s offset.
Parameters:
- fd: The file descriptor to read the offset
Returns the offset of the file descriptor, relative to the start of the file.
File.pathCreateDirectory
Create a directory.
Parameters:
- fd: The file descriptor of the directory in which path resolution starts
- path: The path to the new directory
File.pathFilestats
Retrieve information about a file.
Parameters:
- fd: The file descriptor of the directory in which path resolution starts
- dirFlags: Flags which affect path resolution
- path: The path to retrieve information about
Returns a record containing information about the file.
File.pathSetAccessTime
Set the access (created) time of a file.
Parameters:
- fd: The file descriptor of the directory in which path resolution starts
- dirFlags: Flags which affect path resolution
- path: The path to set the time
- timestamp: The time to set
File.pathSetAccessTimeNow
Set the access (created) time of a file to the current time.
Parameters:
- fd: The file descriptor of the directory in which path resolution starts
- dirFlags: Flags which affect path resolution
- path: The path to set the time
File.pathSetModifiedTime
Set the modified time of a file.
Parameters:
- fd: The file descriptor of the directory in which path resolution starts
- dirFlags: Flags which affect path resolution
- path: The path to set the time
- timestamp: The time to set
File.pathSetModifiedTimeNow
Set the modified time of a file to the current time.
Parameters:
- fd: The file descriptor of the directory in which path resolution starts
- dirFlags: Flags which affect path resolution
- path: The path to set the time
File.pathLink
Create a hard link.
Parameters:
- sourceFd: The file descriptor of the directory in which the source path resolution starts
- dirFlags: Flags which affect path resolution
- sourcePath: The path to the source of the link
- targetFd: The file descriptor of the directory in which the target path resolution starts
- targetPath: The path to the target of the link
File.pathSymlink
Create a symlink.
Parameters:
- fd: The file descriptor of the directory in which path resolution starts
- sourcePath: The path to the source of the link
- targetPath: The path to the target of the link
File.pathUnlink
Unlink a file.
Parameters:
- fd: The file descriptor of the directory in which path resolution starts
- path: The path of the file to unlink
File.pathReadlink
Read the contents of a symbolic link.
Parameters:
- fd: The file descriptor of the directory in which path resolution starts
- path: The path to the symlink
- size: number of bytes to read
Returns the bytes read and the number of bytes read.
File.pathRemoveDirectory
Remove a directory.
Parameters:
- fd: The file descriptor of the directory in which path resolution starts
- path: The path to the directory to remove
File.pathRename
Rename a file or directory.
Parameters:
- sourceFd: The file descriptor of the directory in which the source path resolution starts
- sourcePath: The path of the file to rename
- targetFd: The file descriptor of the directory in which the target path resolution starts
- targetPath: The new path of the file