ExtUnix.All
All functions, those not available on this platform will raise Not_available
with function name as an argument
ExtUnix
These functions are thin wrappers for underlying system API, consult the corresponding man pages and/or system documentation for details.
Not_available "symbol"
may be raised by functions in ExtUnix.All
if the wrapped C function or constant is not available on this platform.
ExtUnix.Specific
includes only functions available on the current platform and will not raise Not_available
. Note that libc wrappers underlying ExtUnix.Specific
functions may still raise ENOSYS
(Not implemented) error even though the function is available.
type of bigarray used by BA submodules that read from files into bigarrays or write bigarrays into files. The only constraint here is Bigarray.c_layout
.
Naming: "bigarray with C layout" -> "carray".
type 'a carray8 =
( 'a, Stdlib.Bigarray.int8_unsigned_elt, Stdlib.Bigarray.c_layout )
Stdlib.Bigarray.Array1.t
type of bigarray used by BA submodules that work with endianness and memory. Constraints are:
Bigarray.c_layout
,Naming: "bigarray with C layout and 8-bit elements" -> "carray8".
module Syslog : sig ... end
module Uname : sig ... end
val uname : unit -> Uname.t
causes all buffered modifications to file metadata and data to be written to the underlying file systems
like sync
, but synchronizes just the file system containing file referred to by the open file descriptor fd
type st_flag =
file system flags
type statvfs = {
f_bsize : int; | (* file system block size *) |
f_blocks : int64; | (* size of file system in blocks *) |
f_bfree : int64; | (* free blocks *) |
f_bavail : int64; | (* free blocks for unprivileged users *) |
f_files : int64; | (* inodes *) |
f_ffree : int64; | (* free inodes *) |
f_favail : int64; | (* free inodes for unprivileged users *) |
f_fsid : int64; | (* file system ID *) |
f_flag : int; | (* mount flags (raw value) *) |
f_flags : st_flag list; | (* mount flags (decoded) *) |
f_namemax : int; | (* maximum filename length *) |
}
val statvfs : string -> statvfs
On Windows, statvfs root
is emulated. root
must be the root directory of the volume to be described. A trailing backslash is required. The f_flag
and f_fsid
fields are retrieved from a call to GetVolumeInformation
. Filesystem flags are provided raw in f_flag
, and only FILE_READ_ONLY_VOLUME
is mapped to ST_RDONLY
in f_flags
.
val fstatvfs : Unix.file_descr -> statvfs
val openat :
Unix.file_descr ->
string ->
open_flag list ->
Unix.file_perm ->
Unix.file_descr
val fstatat : Unix.file_descr -> string -> at_flag list -> Unix.stats
Supported flags : AT_SYMLINK_NOFOLLOW AT_NO_AUTOMOUNT
val unlinkat : Unix.file_descr -> string -> at_flag list -> unit
Supported flags : AT_REMOVEDIR
val linkat :
Unix.file_descr ->
string ->
Unix.file_descr ->
string ->
at_flag list ->
unit
Supported flags : AT_SYMLINK_FOLLOW
val fchownat : Unix.file_descr -> string -> int -> int -> at_flag list -> unit
val fchmodat : Unix.file_descr -> string -> int -> at_flag list -> unit
type advice =
access pattern
val fadvise : Unix.file_descr -> int -> int -> advice -> unit
predeclare an access pattern for file data
Allocate disk space for file
fallocate fd off len
allocates disk space to ensure that subsequent writes between off
and off + len
in fd
will not fail because of lack of disk space. The file size is modified if off + len
is bigger than the current size.
all_pread fd off buf ofs len
reads up to len
bytes from file descriptor fd
at offset off
(from the start of the file) into the string buf
at offset ofs
. The file offset is not changed.
all_pread
repeats the read operation until all characters have been read or an error occurs. Returns less than the number of characters requested on EAGAIN, EWOULDBLOCK or End-of-file but only ever returns 0 on End-of-file. Continues the read operation on EINTR. Raises an Unix.Unix_error exception in all other cases.
single_pread fd off buf ifs len
reads up to len
bytes from file descriptor fd
at offset off
(from the start of the file) into the string buf
at offset ofs
. The file offset is not changed.
single_pread
attempts to read only once. Returns the number of characters read or raises an Unix.Unix_error exception.
pread fd off buf ofs len
reads up to len
bytes from file descriptor fd
at offset off
(from the start of the file) into the string buf
at offset ofs
. The file offset is not changed.
pread
repeats the read operation until all characters have been read or an error occurs. Raises an Unix.Unix_error exception if 0 characters could be read before an error occurs. Continues the read operation on EINTR. Returns the number of characters written in all other cases.
intr_pread fd off buf ofs len
reads up to len
bytes from file descriptor fd
at offset off
(from the start of the file) into the string buf
at offset ofs
. The file offset is not changed.
intr_pread
repeats the read operation until all characters have been read or an error occurs. Raises an Unix.Unix_error exception if 0 characters could be read before an error occurs. Does NOT continue on EINTR. Returns the number of characters written in all other cases.
all_pwrite fd off buf ofs len
writes up to len
bytes from file descriptor fd
at offset off
(from the start of the file) into the string buf
at offset ofs
. The file offset is not changed.
all_pwrite
repeats the write operation until all characters have been written or an error occurs. Returns less than the number of characters requested on EAGAIN, EWOULDBLOCK but never 0. Continues the write operation on EINTR. Raises an Unix.Unix_error exception in all other cases.
single_pwrite fd off buf ofs len
writes up to len
bytes from file descriptor fd
at offset off
(from the start of the file) into the string buf
at offset ofs
. The file offset is not changed.
single_pwrite
attempts to write only once. Returns the number of characters written or raises an Unix.Unix_error exception.
pwrite fd off buf ofs len
writes up to len
bytes from file descriptor fd
at offset off
(from the start of the file) into the string buf
at offset ofs
. The file offset is not changed.
pwrite
repeats the write operation until all characters have been written or an error occurs. Raises an Unix.Unix_error exception if 0 characters could be written before an error occurs. Continues the write operation on EINTR. Returns the number of characters written in all other cases.
intr_pwrite fd off buf ofs len
writes up to len
bytes from file descriptor fd
at offset off
(from the start of the file) into the string buf
at offset ofs
. The file offset is not changed.
intr_pwrite
repeats the write operation until all characters have been written or an error occurs. Raises an Unix.Unix_error exception if 0 characters could be written before an error occurs. Does NOT continue on EINTR. Returns the number of characters written in all other cases.
all_read fd buf ofs len
reads up to len
bytes from file descriptor fd
into the string buf
at offset ofs
.
all_read
repeats the read operation until all characters have been read or an error occurs. Returns less than the number of characters requested on EAGAIN, EWOULDBLOCK or End-of-file but only ever returns 0 on End-of-file. Continues the read operation on EINTR. Raises an Unix.Unix_error exception in all other cases.
single_read fd buf ifs len
reads up to len
bytes from file descriptor fd
into the string buf
at offset ofs
.
single_read
attempts to read only once. Returns the number of characters read or raises an Unix.Unix_error exception.
read fd buf ofs len
reads up to len
bytes from file descriptor fd
into the string buf
at offset ofs
.
read
repeats the read operation until all characters have been read or an error occurs. Raises an Unix.Unix_error exception if 0 characters could be read before an error occurs. Continues the read operation on EINTR. Returns the number of characters written in all other cases.
intr_read fd buf ofs len
reads up to len
bytes from file descriptor fd
into the string buf
at offset ofs
.
intr_read
repeats the read operation until all characters have been read or an error occurs. Raises an Unix.Unix_error exception if 0 characters could be read before an error occurs. Does NOT continue on EINTR. Returns the number of characters written in all other cases.
all_write fd buf ofs len
writes up to len
bytes from file descriptor fd
into the string buf
at offset ofs
.
all_write
repeats the write operation until all characters have been written or an error occurs. Returns less than the number of characters requested on EAGAIN, EWOULDBLOCK but never 0. Continues the write operation on EINTR. Raises an Unix.Unix_error exception in all other cases.
single_write fd buf ofs len
writes up to len
bytes from file descriptor fd
into the string buf
at offset ofs
.
single_write
attempts to write only once. Returns the number of characters written or raises an Unix.Unix_error exception.
write fd buf ofs len
writes up to len
bytes from file descriptor fd
into the string buf
at offset ofs
.
write
repeats the write operation until all characters have been written or an error occurs. Raises an Unix.Unix_error exception if 0 characters could be written before an error occurs. Continues the write operation on EINTR. Returns the number of characters written in all other cases.
intr_write fd buf ofs len
writes up to len
bytes from file descriptor fd
into the string buf
at offset ofs
.
intr_write
repeats the write operation until all characters have been written or an error occurs. Raises an Unix.Unix_error exception if 0 characters could be written before an error occurs. Does NOT continue on EINTR. Returns the number of characters written in all other cases.
module LargeFile : sig ... end
File operations on large files. This sub-module provides 64-bit variants of the functions ExtUnix.fadvise
(for predeclaring an access pattern for file data), ExtUnix.fallocate
(for allocating disk space for a file), ExtUnix.all_pread
, ExtUnix.single_pread
, ExtUnix.pread
, ExtUnix.intr_pread
, ExtUnix.all_pwrite
, ExtUnix.single_pwrite
, ExtUnix.pwrite
and ExtUnix.intr_pwrite
(for reading from or writing to a file descriptor at a given offset). These alternate functions represent positions and sizes by 64-bit integers (type int64) instead of regular integers (type int), thus allowing operating on files whose sizes are greater than max_int.
type mount_flag =
val mount :
source:string ->
target:string ->
fstype:string ->
mount_flag list ->
data:string ->
unit
val umount2 : string -> umount2_flag list -> unit
module Ioctl : sig ... end
Control the underlying device parameters of special files
setpgid pid pgid
sets the process group of the process specified by pid
to pgid
. If pid
is zero, then the process ID of the calling process is used. If pgid
is zero, then the PGID of the process specified by pid
is made the same as its process ID.
getpgid pid
returns the PGID of the process specified by pid
. If pid
is zero, the process ID of the calling process is used.
getsid pid
returns the session ID of the process specified by pid
. If pid
is zero, the process ID of the calling process is used.
setreuid ruid euid
sets real and effective user IDs of the calling process. Supplying a value of -1 for either the real or effective user ID forces the system to leave that ID unchanged.
setregid rgid egid
sets real and effective group IDs of the calling process. Supplying a value of -1 for either the real or effective group ID forces the system to leave that ID unchanged.
setresuid ruid euid suid
sets real, effective and saved user IDs of the calling process. Supplying a value of -1 for either the real or effective user ID forces the system to leave that ID unchanged.
setresgid rgid egid sgid
sets real, effective and saved group IDs of the calling process. Supplying a value of -1 for either the real or effective group ID forces the system to leave that ID unchanged.
type sysinfo = {
}
NB all memory fields in this structure are the multiplies of mem_unit
bytes
val sysinfo : unit -> sysinfo
type socket_int_option =
Extra socket options with integer value not covered in Unix
module. NB: Not all options available on all platforms, use have_sockopt_int
to check at runtime (even when function is defined in Specific
module).
val have_sockopt_unit : socket_unit_option -> bool
val have_sockopt_bool : socket_bool_option -> bool
val have_sockopt_int : socket_int_option -> bool
val have_sockopt : socket_int_option -> bool
Obsolete, compatibility, use have_sockopt_int
.
val setsockopt_unit : Unix.file_descr -> socket_unit_option -> unit
Set the option without value on the given socket
val setsockopt : Unix.file_descr -> socket_bool_option -> bool -> unit
Set a boolean-valued option in the given socket
val getsockopt : Unix.file_descr -> socket_bool_option -> bool
Get the current value for the boolean-valued option in the given socket
val setsockopt_int : Unix.file_descr -> socket_int_option -> int -> unit
Set an integer-valued option in the given socket
val getsockopt_int : Unix.file_descr -> socket_int_option -> int
Get the current value for the integer-valued option in the given socket
module Poll : sig ... end
OCaml bindings for signalfd(2) and related functions
signalfd ?fd sigs flags ()
If the first optional argument is omitted, then a new file descriptor is allocated. Otherwise, the given file descriptor is modified (in which case it must have been created with signalfd
previously). When you are done with the fd, remember to Unix
.close it. Do not forget to block sigs
with Unix
.sigprocmask to prevent signal handling according to default dispositions.
val signalfd_read : Unix.file_descr -> ssi
Blocking read(2) on a signalfd. Has undefined behaviour on non-signalfds. Every successful read consumes a pending signal.
val ssi_signo_sys : ssi -> int
Get the signal value. This form is compatible with the signal values defined in the standard Sys
module.
See signalfd(2) for the details of the remaining functions. Most of these integers are actually unsigned.
val ssi_signo : ssi -> int32
val ssi_errno : ssi -> int32
val ssi_code : ssi -> int32
val ssi_pid : ssi -> int32
val ssi_uid : ssi -> int32
val ssi_fd : ssi -> Unix.file_descr
val ssi_tid : ssi -> int32
val ssi_band : ssi -> int32
val ssi_overrun : ssi -> int32
val ssi_trapno : ssi -> int32
val ssi_status : ssi -> int32
val ssi_int : ssi -> int32
val ssi_ptr : ssi -> int64
val ssi_utime : ssi -> int64
val ssi_stime : ssi -> int64
val ssi_addr : ssi -> int64
type which_prio_t =
| PRIO_PROCESS of int | (* Priority for a process id *) |
| PRIO_PGRP of int | (* Priority for a process group id *) |
| PRIO_USER of int | (* Priority for a user id *) |
priority target
type resource =
val string_of_resource : resource -> string
get resource name
module Rlimit : sig ... end
Limits
val getpriority : which_prio_t -> priority
Get nice value
val setpriority : which_prio_t -> priority -> unit
Set nice value
getrusage
is not implemented because the only meaningful information it provides are ru_utime
and ru_stime
which can be accessed through Unix.times
.
val mlockall : mlockall_flag list -> unit
Lock all pages mapped into the address space of the calling process.
val memalign : int -> int -> Stdlib.Bigarray.int8_unsigned_elt carray8
memalign alignment size
creates a Bigarray
.Array1.t of size
bytes, which data is aligned to alignment
(must be a power of 2)
This function is the converse of the strftime
function. strptime fmt data
convert a string containing time information data
into a tm
struct according to the format specified by fmt
.
Return the ascii representation of a given tm
argument. The ascii time is returned in the form of a string like 'Wed Jun 30, 21:21:21 2005\n'
This functions is the converse of the strptime
function. strftime fmt data
converts a tm
structure data
into a string according to the format specified by fmt
.
val posix_openpt : open_flag list -> Unix.file_descr
This function opens a pseudo-terminal device.
val ptrace : int -> ptrace_request -> unit
setenv name value overwrite
adds the variable name
to the environment with the value value
, if name
does not already exist or overwrite
is true
unsetenv name
removes variable name
from the environment. If name
does not exist in the environment, then the function succeeds, and the environment is unchanged.
mkdtemp template
creates a unique temporary directory (with permissions 0700). Last six characters of template
must be "XXXXXX".
mkstemp ?(suffix="") prefix
generates a unique temporary filename in the form prefix
XXXXXXsuffix
, creates and opens the file, and returns an open file descriptor and name for the file.
val mkostemp :
?suffix:string ->
?flags:open_flag list ->
string ->
Unix.file_descr * string
mkostemp ?(suffix="") ?(flags=[]) prefix
generates a unique temporary filename in the form prefix
XXXXXXsuffix
, creates and opens the file with flags
, and returns an open file descriptor and name for the file.
module BigEndian : sig ... end
module LittleEndian : sig ... end
module HostEndian : sig ... end
Reads sender credentials from a file descriptor, returning a 3-element tuple containing the sender process' PID, UID and GID.
fexecve fd args env
executes the program in file represented by file descriptor fd
with arguments args
and environment variables given by env
. As with the execv*
functions, on success fexecve
never returns; the current process is replaced by the new one.
Send a message and optionally a file descriptor through a socket. Passing file descriptors requires UNIX domain sockets and a non-empty message.
Recieve a message and possibly a file descriptor from a socket.
sendfd sock fd
sends a file descriptor fd
through a UNIX domain socket sock
. This will send a sentinel message at the same time, otherwise sendmsg
will not pass the file descriptor.
Receive a file descriptor sent through a UNIX domain socket, ignoring the message.
Receive a message sent through a UNIX domain socket. Raises Recvfd(fd, msg) if a file descriptor is recieved.
Receive a message sent through a UNIX domain socket. Closes and ignores file descriptors.
type sysconf_name =
name of the variable
val sysconf : sysconf_name -> int64
get configuration information at runtime, may raise Not_available
for non-standard options (see above) even in Specific
module
type splice_flag =
splice functions flags
val splice :
Unix.file_descr ->
int option ->
Unix.file_descr ->
int option ->
int ->
splice_flag list ->
int
splice fd_in off_in fd_out off_out len flags
moves data between two file descriptors without copying between kernel address space and user address space. It transfers up to len
bytes of data from the file descriptor fd_in
to the file descriptor fd_out
, where one of the descriptors must refer to a pipe.
If fd_in
refers to a pipe, then off_in
must be None
. If fd_in
does not refer to a pipe and off_in
is None
, then bytes are read from fd_in
starting from the current file offset, and the current file offset is adjusted appropriately. If fd_in
does not refer to a pipe and off_in
is Some n
, then n
mspecifies the starting offset from which bytes will be read from fd_in
; in this case, the current file offset of fd_in
is not changed. Analogous statements apply for fd_out
and off_out
.
val tee : Unix.file_descr -> Unix.file_descr -> int -> splice_flag list -> int
tee fd_in fd_out len flags
duplicates up to len
bytes of data from the pipe fd_in
to the pipe fd_out
. It does not consume the data that is duplicated from fd_in
; therefore, that data can be copied by a subsequent splice.
module BA : sig ... end