Index: head/lib/libc/sys/chdir.2 =================================================================== --- head/lib/libc/sys/chdir.2 (revision 326434) +++ head/lib/libc/sys/chdir.2 (revision 326435) @@ -1,132 +1,132 @@ .\" Copyright (c) 1980, 1991, 1993 .\" The Regents of the University of California. All rights reserved. .\" .\" Redistribution and use in source and binary forms, with or without .\" modification, are permitted provided that the following conditions .\" are met: .\" 1. Redistributions of source code must retain the above copyright .\" notice, this list of conditions and the following disclaimer. .\" 2. Redistributions in binary form must reproduce the above copyright .\" notice, this list of conditions and the following disclaimer in the .\" documentation and/or other materials provided with the distribution. .\" 3. Neither the name of the University nor the names of its contributors .\" may be used to endorse or promote products derived from this software .\" without specific prior written permission. .\" .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" .\" @(#)chdir.2 8.2 (Berkeley) 12/11/93 .\" $FreeBSD$ .\" -.Dd December 11, 1993 +.Dd December 1, 2017 .Dt CHDIR 2 .Os .Sh NAME .Nm chdir , .Nm fchdir .Nd change current working directory .Sh LIBRARY .Lb libc .Sh SYNOPSIS .In unistd.h .Ft int .Fn chdir "const char *path" .Ft int .Fn fchdir "int fd" .Sh DESCRIPTION The .Fa path argument points to the pathname of a directory. The .Fn chdir system call causes the named directory to become the current working directory, that is, the starting point for path searches of pathnames not beginning with a slash, .Ql / . .Pp The .Fn fchdir system call causes the directory referenced by .Fa fd to become the current working directory, the starting point for path searches of pathnames not beginning with a slash, .Ql / . .Pp In order for a directory to become the current directory, a process must have execute (search) access to the directory. .Sh RETURN VALUES .Rv -std .Sh ERRORS The .Fn chdir system call will fail and the current working directory will be unchanged if one or more of the following are true: .Bl -tag -width Er .It Bq Er ENOTDIR A component of the path prefix is not a directory. .It Bq Er ENAMETOOLONG A component of a pathname exceeded 255 characters, or an entire path name exceeded 1023 characters. .It Bq Er ENOENT The named directory does not exist. .It Bq Er ELOOP Too many symbolic links were encountered in translating the pathname. .It Bq Er EACCES Search permission is denied for any component of the path name. .It Bq Er EFAULT The .Fa path argument points outside the process's allocated address space. .It Bq Er EIO An I/O error occurred while reading from or writing to the file system. .El .Pp The .Fn fchdir system call will fail and the current working directory will be unchanged if one or more of the following are true: .Bl -tag -width Er .It Bq Er EACCES Search permission is denied for the directory referenced by the file descriptor. .It Bq Er ENOTDIR The file descriptor does not reference a directory. .It Bq Er EBADF The argument .Fa fd is not a valid file descriptor. .El .Sh SEE ALSO .Xr chroot 2 .Sh STANDARDS The .Fn chdir system call is expected to conform to .St -p1003.1-90 . .Sh HISTORY The .Fn chdir system call appeared in -.At v7 . +.At v1 . The .Fn fchdir system call appeared in .Bx 4.2 . Index: head/lib/libc/sys/chmod.2 =================================================================== --- head/lib/libc/sys/chmod.2 (revision 326434) +++ head/lib/libc/sys/chmod.2 (revision 326435) @@ -1,327 +1,327 @@ .\" Copyright (c) 1980, 1991, 1993 .\" The Regents of the University of California. All rights reserved. .\" .\" Redistribution and use in source and binary forms, with or without .\" modification, are permitted provided that the following conditions .\" are met: .\" 1. Redistributions of source code must retain the above copyright .\" notice, this list of conditions and the following disclaimer. .\" 2. Redistributions in binary form must reproduce the above copyright .\" notice, this list of conditions and the following disclaimer in the .\" documentation and/or other materials provided with the distribution. .\" 3. Neither the name of the University nor the names of its contributors .\" may be used to endorse or promote products derived from this software .\" without specific prior written permission. .\" .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" .\" @(#)chmod.2 8.1 (Berkeley) 6/4/93 .\" $FreeBSD$ .\" -.Dd December 1, 2013 +.Dd December 1, 2017 .Dt CHMOD 2 .Os .Sh NAME .Nm chmod , .Nm fchmod , .Nm lchmod , .Nm fchmodat .Nd change mode of file .Sh LIBRARY .Lb libc .Sh SYNOPSIS .In sys/stat.h .Ft int .Fn chmod "const char *path" "mode_t mode" .Ft int .Fn fchmod "int fd" "mode_t mode" .Ft int .Fn lchmod "const char *path" "mode_t mode" .Ft int .Fn fchmodat "int fd" "const char *path" "mode_t mode" "int flag" .Sh DESCRIPTION The file permission bits of the file named specified by .Fa path or referenced by the file descriptor .Fa fd are changed to .Fa mode . The .Fn chmod system call verifies that the process owner (user) either owns the file specified by .Fa path (or .Fa fd ) , or is the super-user. The .Fn chmod system call follows symbolic links to operate on the target of the link rather than the link itself. .Pp The .Fn lchmod system call is similar to .Fn chmod but does not follow symbolic links. .Pp The .Fn fchmodat is equivalent to either .Fn chmod or .Fn lchmod depending on the .Fa flag except in the case where .Fa path specifies a relative path. In this case the file to be changed is determined relative to the directory associated with the file descriptor .Fa fd instead of the current working directory. The values for the .Fa flag are constructed by a bitwise-inclusive OR of flags from the following list, defined in .In fcntl.h : .Bl -tag -width indent .It Dv AT_SYMLINK_NOFOLLOW If .Fa path names a symbolic link, then the mode of the symbolic link is changed. .El .Pp If .Fn fchmodat is passed the special value .Dv AT_FDCWD in the .Fa fd parameter, the current working directory is used. If also .Fa flag is zero, the behavior is identical to a call to .Fn chmod . .Pp A mode is created from .Em or'd permission bit masks defined in .In sys/stat.h : .Pp .Bd -literal -offset indent -compact #define S_IRWXU 0000700 /* RWX mask for owner */ #define S_IRUSR 0000400 /* R for owner */ #define S_IWUSR 0000200 /* W for owner */ #define S_IXUSR 0000100 /* X for owner */ #define S_IRWXG 0000070 /* RWX mask for group */ #define S_IRGRP 0000040 /* R for group */ #define S_IWGRP 0000020 /* W for group */ #define S_IXGRP 0000010 /* X for group */ #define S_IRWXO 0000007 /* RWX mask for other */ #define S_IROTH 0000004 /* R for other */ #define S_IWOTH 0000002 /* W for other */ #define S_IXOTH 0000001 /* X for other */ #define S_ISUID 0004000 /* set user id on execution */ #define S_ISGID 0002000 /* set group id on execution */ #define S_ISVTX 0001000 /* sticky bit */ .Ed .Pp The non-standard .Dv S_ISTXT is a synonym for .Dv S_ISVTX . .Pp The .Fx VM system totally ignores the sticky bit .Pq Dv S_ISVTX for executables. On UFS-based file systems (FFS, LFS) the sticky bit may only be set upon directories. .Pp If mode .Dv S_ISVTX (the `sticky bit') is set on a directory, an unprivileged user may not delete or rename files of other users in that directory. The sticky bit may be set by any user on a directory which the user owns or has appropriate permissions. For more details of the properties of the sticky bit, see .Xr sticky 7 . .Pp If mode ISUID (set UID) is set on a directory, and the MNT_SUIDDIR option was used in the mount of the file system, then the owner of any new files and sub-directories created within this directory are set to be the same as the owner of that directory. If this function is enabled, new directories will inherit the bit from their parents. Execute bits are removed from the file, and it will not be given to root. This behavior does not change the requirements for the user to be allowed to write the file, but only the eventual owner after it has been created. Group inheritance is not affected. .Pp This feature is designed for use on fileservers serving PC users via ftp, SAMBA, or netatalk. It provides security holes for shell users and as such should not be used on shell machines, especially on home directories. This option requires the SUIDDIR option in the kernel to work. Only UFS file systems support this option. For more details of the suiddir mount option, see .Xr mount 8 . .Pp Writing or changing the owner of a file turns off the set-user-id and set-group-id bits unless the user is the super-user. This makes the system somewhat more secure by protecting set-user-id (set-group-id) files from remaining set-user-id (set-group-id) if they are modified, at the expense of a degree of compatibility. .Sh RETURN VALUES .Rv -std .Sh ERRORS The .Fn chmod system call will fail and the file mode will be unchanged if: .Bl -tag -width Er .It Bq Er ENOTDIR A component of the path prefix is not a directory. .It Bq Er ENAMETOOLONG A component of a pathname exceeded 255 characters, or an entire path name exceeded 1023 characters. .It Bq Er ENOENT The named file does not exist. .It Bq Er EACCES Search permission is denied for a component of the path prefix. .It Bq Er ELOOP Too many symbolic links were encountered in translating the pathname. .It Bq Er EPERM The effective user ID does not match the owner of the file and the effective user ID is not the super-user. .It Bq Er EPERM The effective user ID is not the super-user, the effective user ID do match the owner of the file, but the group ID of the file does not match the effective group ID nor one of the supplementary group IDs. .It Bq Er EPERM The named file has its immutable or append-only flag set, see the .Xr chflags 2 manual page for more information. .It Bq Er EROFS The named file resides on a read-only file system. .It Bq Er EFAULT The .Fa path argument points outside the process's allocated address space. .It Bq Er EIO An I/O error occurred while reading from or writing to the file system. .It Bq Er EFTYPE The effective user ID is not the super-user, the mode includes the sticky bit .Dv ( S_ISVTX ) , and path does not refer to a directory. .El .Pp The .Fn fchmod system call will fail if: .Bl -tag -width Er .It Bq Er EBADF The descriptor is not valid. .It Bq Er EINVAL The .Fa fd argument refers to a socket, not to a file. .It Bq Er EROFS The file resides on a read-only file system. .It Bq Er EIO An I/O error occurred while reading from or writing to the file system. .El .Pp In addition to the .Fn chmod errors, .Fn fchmodat fails if: .Bl -tag -width Er .It Bq Er EBADF The .Fa path argument does not specify an absolute path and the .Fa fd argument is neither .Fa AT_FDCWD nor a valid file descriptor open for searching. .It Bq Er EINVAL The value of the .Fa flag argument is not valid. .It Bq Er ENOTDIR The .Fa path argument is not an absolute path and .Fa fd is neither .Dv AT_FDCWD nor a file descriptor associated with a directory. .El .Sh SEE ALSO .Xr chmod 1 , .Xr chflags 2 , .Xr chown 2 , .Xr open 2 , .Xr stat 2 , .Xr sticky 7 .Sh STANDARDS The .Fn chmod system call is expected to conform to .St -p1003.1-90 , except for the return of .Er EFTYPE . The .Dv S_ISVTX bit on directories is expected to conform to .St -susv3 . The .Fn fchmodat system call is expected to conform to .St -p1003.1-2008 . .Sh HISTORY The .Fn chmod function appeared in -.At v7 . +.At v1 . The .Fn fchmod system call appeared in .Bx 4.2 . The .Fn lchmod system call appeared in .Fx 3.0 . The .Fn fchmodat system call appeared in .Fx 8.0 . Index: head/lib/libc/sys/chown.2 =================================================================== --- head/lib/libc/sys/chown.2 (revision 326434) +++ head/lib/libc/sys/chown.2 (revision 326435) @@ -1,268 +1,268 @@ .\" Copyright (c) 1980, 1991, 1993, 1994 .\" The Regents of the University of California. All rights reserved. .\" .\" Redistribution and use in source and binary forms, with or without .\" modification, are permitted provided that the following conditions .\" are met: .\" 1. Redistributions of source code must retain the above copyright .\" notice, this list of conditions and the following disclaimer. .\" 2. Redistributions in binary form must reproduce the above copyright .\" notice, this list of conditions and the following disclaimer in the .\" documentation and/or other materials provided with the distribution. .\" 3. Neither the name of the University nor the names of its contributors .\" may be used to endorse or promote products derived from this software .\" without specific prior written permission. .\" .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" .\" @(#)chown.2 8.4 (Berkeley) 4/19/94 .\" $FreeBSD$ .\" -.Dd April 10, 2008 +.Dd December 1, 2017 .Dt CHOWN 2 .Os .Sh NAME .Nm chown , .Nm fchown , .Nm lchown , .Nm fchownat .Nd change owner and group of a file .Sh LIBRARY .Lb libc .Sh SYNOPSIS .In unistd.h .Ft int .Fn chown "const char *path" "uid_t owner" "gid_t group" .Ft int .Fn fchown "int fd" "uid_t owner" "gid_t group" .Ft int .Fn lchown "const char *path" "uid_t owner" "gid_t group" .Ft int .Fn fchownat "int fd" "const char *path" "uid_t owner" "gid_t group" "int flag" .Sh DESCRIPTION The owner ID and group ID of the file named by .Fa path or referenced by .Fa fd is changed as specified by the arguments .Fa owner and .Fa group . The owner of a file may change the .Fa group to a group of which he or she is a member, but the change .Fa owner capability is restricted to the super-user. .Pp The .Fn chown system call clears the set-user-id and set-group-id bits on the file to prevent accidental or mischievous creation of set-user-id and set-group-id programs if not executed by the super-user. The .Fn chown system call follows symbolic links to operate on the target of the link rather than the link itself. .Pp The .Fn fchown system call is particularly useful when used in conjunction with the file locking primitives (see .Xr flock 2 ) . .Pp The .Fn lchown system call is similar to .Fn chown but does not follow symbolic links. .Pp The .Fn fchownat system call is equivalent to the .Fn chown and .Fn lchown except in the case where .Fa path specifies a relative path. In this case the file to be changed is determined relative to the directory associated with the file descriptor .Fa fd instead of the current working directory. .Pp Values for .Fa flag are constructed by a bitwise-inclusive OR of flags from the following list, defined in .In fcntl.h : .Bl -tag -width indent .It Dv AT_SYMLINK_NOFOLLOW If .Fa path names a symbolic link, ownership of the symbolic link is changed. .El .Pp If .Fn fchownat is passed the special value .Dv AT_FDCWD in the .Fa fd parameter, the current working directory is used and the behavior is identical to a call to .Fn chown or .Fn lchown respectively, depending on whether or not the .Dv AT_SYMLINK_NOFOLLOW bit is set in the .Fa flag argument. .Pp One of the owner or group id's may be left unchanged by specifying it as -1. .Sh RETURN VALUES .Rv -std .Sh ERRORS The .Fn chown and .Fn lchown will fail and the file will be unchanged if: .Bl -tag -width Er .It Bq Er ENOTDIR A component of the path prefix is not a directory. .It Bq Er ENAMETOOLONG A component of a pathname exceeded 255 characters, or an entire path name exceeded 1023 characters. .It Bq Er ENOENT The named file does not exist. .It Bq Er EACCES Search permission is denied for a component of the path prefix. .It Bq Er ELOOP Too many symbolic links were encountered in translating the pathname. .It Bq Er EPERM The operation would change the ownership, but the effective user ID is not the super-user. .It Bq Er EPERM The named file has its immutable or append-only flag set, see the .Xr chflags 2 manual page for more information. .It Bq Er EROFS The named file resides on a read-only file system. .It Bq Er EFAULT The .Fa path argument points outside the process's allocated address space. .It Bq Er EIO An I/O error occurred while reading from or writing to the file system. .El .Pp The .Fn fchown system call will fail if: .Bl -tag -width Er .It Bq Er EBADF The .Fa fd argument does not refer to a valid descriptor. .It Bq Er EINVAL The .Fa fd argument refers to a socket, not a file. .It Bq Er EPERM The effective user ID is not the super-user. .It Bq Er EROFS The named file resides on a read-only file system. .It Bq Er EIO An I/O error occurred while reading from or writing to the file system. .El .Pp In addition to the errors specified for .Fn chown and .Fn lchown , the .Fn fchownat system call may fail if: .Bl -tag -width Er .It Bq Er EBADF The .Fa path argument does not specify an absolute path and the .Fa fd argument is neither .Dv AT_FDCWD nor a valid file descriptor open for searching. .It Bq Er EINVAL The value of the .Fa flag argument is not valid. .It Bq Er ENOTDIR The .Fa path argument is not an absolute path and .Fa fd is neither .Dv AT_FDCWD nor a file descriptor associated with a directory. .El .Sh SEE ALSO .Xr chgrp 1 , .Xr chflags 2 , .Xr chmod 2 , .Xr flock 2 , .Xr chown 8 .Sh STANDARDS The .Fn chown system call is expected to conform to .St -p1003.1-90 . The .Fn fchownat system call follows The Open Group Extended API Set 2 specification. .Sh HISTORY The .Fn chown function appeared in -.At v7 . +.At v1 . The .Fn fchown system call appeared in .Bx 4.2 . .Pp The .Fn chown system call was changed to follow symbolic links in .Bx 4.4 . The .Fn lchown system call was added in .Fx 3.0 to compensate for the loss of functionality. .Pp The .Fn fchownat system call appeared in .Fx 8.0 . Index: head/lib/libc/sys/close.2 =================================================================== --- head/lib/libc/sys/close.2 (revision 326434) +++ head/lib/libc/sys/close.2 (revision 326435) @@ -1,144 +1,144 @@ .\" Copyright (c) 1980, 1991, 1993, 1994 .\" The Regents of the University of California. All rights reserved. .\" .\" Redistribution and use in source and binary forms, with or without .\" modification, are permitted provided that the following conditions .\" are met: .\" 1. Redistributions of source code must retain the above copyright .\" notice, this list of conditions and the following disclaimer. .\" 2. Redistributions in binary form must reproduce the above copyright .\" notice, this list of conditions and the following disclaimer in the .\" documentation and/or other materials provided with the distribution. .\" 3. Neither the name of the University nor the names of its contributors .\" may be used to endorse or promote products derived from this software .\" without specific prior written permission. .\" .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" .\" @(#)close.2 8.2 (Berkeley) 4/19/94 .\" $FreeBSD$ .\" -.Dd September 11, 2013 +.Dd December 1, 2017 .Dt CLOSE 2 .Os .Sh NAME .Nm close .Nd delete a descriptor .Sh LIBRARY .Lb libc .Sh SYNOPSIS .In unistd.h .Ft int .Fn close "int fd" .Sh DESCRIPTION The .Fn close system call deletes a descriptor from the per-process object reference table. If this is the last reference to the underlying object, the object will be deactivated. For example, on the last close of a file the current .Em seek pointer associated with the file is lost; on the last close of a .Xr socket 2 associated naming information and queued data are discarded; on the last close of a file holding an advisory lock the lock is released (see further .Xr flock 2 ) . However, the semantics of System V and .St -p1003.1-88 dictate that all .Xr fcntl 2 advisory record locks associated with a file for a given process are removed when .Em any file descriptor for that file is closed by that process. .Pp When a process exits, all associated file descriptors are freed, but since there is a limit on active descriptors per processes, the .Fn close system call is useful when a large quantity of file descriptors are being handled. .Pp When a process forks (see .Xr fork 2 ) , all descriptors for the new child process reference the same objects as they did in the parent before the fork. If a new process is then to be run using .Xr execve 2 , the process would normally inherit these descriptors. Most of the descriptors can be rearranged with .Xr dup2 2 or deleted with .Fn close before the .Xr execve 2 is attempted, but if some of these descriptors will still be needed if the execve fails, it is necessary to arrange for them to be closed if the execve succeeds. For this reason, the call .Dq Li fcntl(d, F_SETFD, FD_CLOEXEC) is provided, which arranges that a descriptor will be closed after a successful execve; the call .Dq Li fcntl(d, F_SETFD, 0) restores the default, which is to not close the descriptor. .Sh RETURN VALUES .Rv -std close .Sh ERRORS The .Fn close system call will fail if: .Bl -tag -width Er .It Bq Er EBADF The .Fa fd argument is not an active descriptor. .It Bq Er EINTR An interrupt was received. .It Bq Er ENOSPC The underlying object did not fit, cached data was lost. .It Bq Er ECONNRESET The underlying object was a stream socket that was shut down by the peer before all pending data was delivered. .El .Pp In case of any error except .Er EBADF , the supplied file descriptor is deallocated and therefore is no longer valid. .Sh SEE ALSO .Xr accept 2 , .Xr closefrom 2 , .Xr execve 2 , .Xr fcntl 2 , .Xr flock 2 , .Xr open 2 , .Xr pipe 2 , .Xr socket 2 , .Xr socketpair 2 .Sh STANDARDS The .Fn close system call is expected to conform to .St -p1003.1-90 . .Sh HISTORY The .Fn close function appeared in -.At v7 . +.At v1 . Index: head/lib/libc/sys/fork.2 =================================================================== --- head/lib/libc/sys/fork.2 (revision 326434) +++ head/lib/libc/sys/fork.2 (revision 326435) @@ -1,148 +1,148 @@ .\" Copyright (c) 1980, 1991, 1993 .\" The Regents of the University of California. All rights reserved. .\" .\" Redistribution and use in source and binary forms, with or without .\" modification, are permitted provided that the following conditions .\" are met: .\" 1. Redistributions of source code must retain the above copyright .\" notice, this list of conditions and the following disclaimer. .\" 2. Redistributions in binary form must reproduce the above copyright .\" notice, this list of conditions and the following disclaimer in the .\" documentation and/or other materials provided with the distribution. .\" 3. Neither the name of the University nor the names of its contributors .\" may be used to endorse or promote products derived from this software .\" without specific prior written permission. .\" .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" .\" @(#)fork.2 8.1 (Berkeley) 6/4/93 .\" $FreeBSD$ .\" -.Dd May 1, 2015 +.Dd December 1, 2017 .Dt FORK 2 .Os .Sh NAME .Nm fork .Nd create a new process .Sh LIBRARY .Lb libc .Sh SYNOPSIS .In unistd.h .Ft pid_t .Fn fork void .Sh DESCRIPTION The .Fn fork system call causes creation of a new process. The new process (child process) is an exact copy of the calling process (parent process) except for the following: .Bl -bullet -offset indent .It The child process has a unique process ID. .It The child process has a different parent process ID (i.e., the process ID of the parent process). .It The child process has its own copy of the parent's descriptors, except for descriptors returned by .Xr kqueue 2 , which are not inherited from the parent process. These descriptors reference the same underlying objects, so that, for instance, file pointers in file objects are shared between the child and the parent, so that an .Xr lseek 2 on a descriptor in the child process can affect a subsequent .Xr read 2 or .Xr write 2 by the parent. This descriptor copying is also used by the shell to establish standard input and output for newly created processes as well as to set up pipes. .It The child process' resource utilizations are set to 0; see .Xr setrlimit 2 . .It All interval timers are cleared; see .Xr setitimer 2 . .It The child process has only one thread, corresponding to the calling thread in the parent process. If the process has more than one thread, locks and other resources held by the other threads are not released and therefore only async-signal-safe functions (see .Xr sigaction 2 ) are guaranteed to work in the child process until a call to .Xr execve 2 or a similar function. .El .Sh RETURN VALUES Upon successful completion, .Fn fork returns a value of 0 to the child process and returns the process ID of the child process to the parent process. Otherwise, a value of -1 is returned to the parent process, no child process is created, and the global variable .Va errno is set to indicate the error. .Sh ERRORS The .Fn fork system call will fail and no child process will be created if: .Bl -tag -width Er .It Bq Er EAGAIN The system-imposed limit on the total number of processes under execution would be exceeded. The limit is given by the .Xr sysctl 3 MIB variable .Dv KERN_MAXPROC . (The limit is actually ten less than this except for the super user). .It Bq Er EAGAIN The user is not the super user, and the system-imposed limit on the total number of processes under execution by a single user would be exceeded. The limit is given by the .Xr sysctl 3 MIB variable .Dv KERN_MAXPROCPERUID . .It Bq Er EAGAIN The user is not the super user, and the soft resource limit corresponding to the .Fa resource argument .Dv RLIMIT_NPROC would be exceeded (see .Xr getrlimit 2 ) . .It Bq Er ENOMEM There is insufficient swap space for the new process. .El .Sh SEE ALSO .Xr execve 2 , .Xr rfork 2 , .Xr setitimer 2 , .Xr setrlimit 2 , .Xr sigaction 2 , .Xr vfork 2 , .Xr wait 2 .Sh HISTORY The .Fn fork function appeared in -.At v6 . +.At v1 . Index: head/lib/libc/sys/getuid.2 =================================================================== --- head/lib/libc/sys/getuid.2 (revision 326434) +++ head/lib/libc/sys/getuid.2 (revision 326435) @@ -1,89 +1,91 @@ .\" Copyright (c) 1980, 1991, 1993 .\" The Regents of the University of California. All rights reserved. .\" .\" Redistribution and use in source and binary forms, with or without .\" modification, are permitted provided that the following conditions .\" are met: .\" 1. Redistributions of source code must retain the above copyright .\" notice, this list of conditions and the following disclaimer. .\" 2. Redistributions in binary form must reproduce the above copyright .\" notice, this list of conditions and the following disclaimer in the .\" documentation and/or other materials provided with the distribution. .\" 3. Neither the name of the University nor the names of its contributors .\" may be used to endorse or promote products derived from this software .\" without specific prior written permission. .\" .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" .\" @(#)getuid.2 8.1 (Berkeley) 6/4/93 .\" $FreeBSD$ .\" -.Dd December 15, 2015 +.Dd December 1, 2017 .Dt GETUID 2 .Os .Sh NAME .Nm getuid , .Nm geteuid .Nd get user identification .Sh LIBRARY .Lb libc .Sh SYNOPSIS .In unistd.h .Ft uid_t .Fn getuid void .Ft uid_t .Fn geteuid void .Sh DESCRIPTION The .Fn getuid system call returns the real user ID of the calling process. The .Fn geteuid system call returns the effective user ID of the calling process. .Pp The real user ID is that of the user who has invoked the program. As the effective user ID gives the process additional permissions during execution of .Dq Em set-user-ID mode processes, .Fn getuid is used to determine the real-user-id of the calling process. .Sh ERRORS The .Fn getuid and .Fn geteuid system calls are always successful, and no return value is reserved to indicate an error. .Sh SEE ALSO .Xr getgid 2 , .Xr issetugid 2 , .Xr setgid 2 , .Xr setreuid 2 , .Xr setuid 2 .Sh STANDARDS The .Fn geteuid and .Fn getuid system calls are expected to conform to .St -p1003.1-90 . .Sh HISTORY The .Fn getuid -and +function appeared in +.At v1 . +The .Fn geteuid -functions appeared in +function appeared in .At v7 . Index: head/lib/libc/sys/link.2 =================================================================== --- head/lib/libc/sys/link.2 (revision 326434) +++ head/lib/libc/sys/link.2 (revision 326435) @@ -1,288 +1,288 @@ .\" Copyright (c) 1980, 1991, 1993 .\" The Regents of the University of California. All rights reserved. .\" .\" Redistribution and use in source and binary forms, with or without .\" modification, are permitted provided that the following conditions .\" are met: .\" 1. Redistributions of source code must retain the above copyright .\" notice, this list of conditions and the following disclaimer. .\" 2. Redistributions in binary form must reproduce the above copyright .\" notice, this list of conditions and the following disclaimer in the .\" documentation and/or other materials provided with the distribution. .\" 3. Neither the name of the University nor the names of its contributors .\" may be used to endorse or promote products derived from this software .\" without specific prior written permission. .\" .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" .\" @(#)link.2 8.3 (Berkeley) 1/12/94 .\" $FreeBSD$ .\" -.Dd April 10, 2008 +.Dd December 1, 2017 .Dt LINK 2 .Os .Sh NAME .Nm link , .Nm linkat .Nd make a hard file link .Sh LIBRARY .Lb libc .Sh SYNOPSIS .In unistd.h .Ft int .Fn link "const char *name1" "const char *name2" .Ft int .Fo linkat .Fa "int fd1" "const char *name1" "int fd2" "const char *name2" "int flag" .Fc .Sh DESCRIPTION The .Fn link system call atomically creates the specified directory entry (hard link) .Fa name2 with the attributes of the underlying object pointed at by .Fa name1 . If the link is successful: the link count of the underlying object is incremented; .Fa name1 and .Fa name2 share equal access and rights to the underlying object. .Pp If .Fa name1 is removed, the file .Fa name2 is not deleted and the link count of the underlying object is decremented. .Pp The object pointed at by the .Fa name1 argument must exist for the hard link to succeed and both .Fa name1 and .Fa name2 must be in the same file system. The .Fa name1 argument may not be a directory. .Pp The .Fn linkat system call is equivalent to .Fa link except in the case where either .Fa name1 or .Fa name2 or both are relative paths. In this case a relative path .Fa name1 is interpreted relative to the directory associated with the file descriptor .Fa fd1 instead of the current working directory and similarly for .Fa name2 and the file descriptor .Fa fd2 . .Pp Values for .Fa flag are constructed by a bitwise-inclusive OR of flags from the following list, defined in .In fcntl.h : .Bl -tag -width indent .It Dv AT_SYMLINK_FOLLOW If .Fa name1 names a symbolic link, a new link for the target of the symbolic link is created. .El .Pp If .Fn linkat is passed the special value .Dv AT_FDCWD in the .Fa fd1 or .Fa fd2 parameter, the current working directory is used for the respective .Fa name argument. If both .Fa fd1 and .Fa fd2 have value .Dv AT_FDCWD , the behavior is identical to a call to .Fn link . Unless .Fa flag contains the .Dv AT_SYMLINK_FOLLOW flag, if .Fa name1 names a symbolic link, a new link is created for the symbolic link .Fa name1 and not its target. .Sh RETURN VALUES .Rv -std link .Sh ERRORS The .Fn link system call will fail and no link will be created if: .Bl -tag -width Er .It Bq Er ENOTDIR A component of either path prefix is not a directory. .It Bq Er ENAMETOOLONG A component of either pathname exceeded 255 characters, or entire length of either path name exceeded 1023 characters. .It Bq Er ENOENT A component of either path prefix does not exist. .It Bq Er EOPNOTSUPP The file system containing the file named by .Fa name1 does not support links. .It Bq Er EMLINK The link count of the file named by .Fa name1 would exceed 32767. .It Bq Er EACCES A component of either path prefix denies search permission. .It Bq Er EACCES The requested link requires writing in a directory with a mode that denies write permission. .It Bq Er ELOOP Too many symbolic links were encountered in translating one of the pathnames. .It Bq Er ENOENT The file named by .Fa name1 does not exist. .It Bq Er EEXIST The link named by .Fa name2 does exist. .It Bq Er EPERM The file named by .Fa name1 is a directory. .It Bq Er EPERM The file named by .Fa name1 has its immutable or append-only flag set, see the .Xr chflags 2 manual page for more information. .It Bq Er EPERM The parent directory of the file named by .Fa name2 has its immutable flag set. .It Bq Er EXDEV The link named by .Fa name2 and the file named by .Fa name1 are on different file systems. .It Bq Er ENOSPC The directory in which the entry for the new link is being placed cannot be extended because there is no space left on the file system containing the directory. .It Bq Er EDQUOT The directory in which the entry for the new link is being placed cannot be extended because the user's quota of disk blocks on the file system containing the directory has been exhausted. .It Bq Er EIO An I/O error occurred while reading from or writing to the file system to make the directory entry. .It Bq Er EROFS The requested link requires writing in a directory on a read-only file system. .It Bq Er EFAULT One of the pathnames specified is outside the process's allocated address space. .El .Pp In addition to the errors returned by the .Fn link , the .Fn linkat system call may fail if: .Bl -tag -width Er .It Bq Er EBADF The .Fa name1 or .Fa name2 argument does not specify an absolute path and the .Fa fd1 or .Fa fd2 argument, respectively, is neither .Dv AT_FDCWD nor a valid file descriptor open for searching. .It Bq Er EINVAL The value of the .Fa flag argument is not valid. .It Bq Er ENOTDIR The .Fa name1 or .Fa name2 argument is not an absolute path and .Fa fd1 or .Fa fd2 , respectively, is neither .Dv AT_FDCWD nor a file descriptor associated with a directory. .El .Sh SEE ALSO .Xr chflags 2 , .Xr readlink 2 , .Xr symlink 2 , .Xr unlink 2 .Sh STANDARDS The .Fn link system call is expected to conform to .St -p1003.1-90 . The .Fn linkat system call follows The Open Group Extended API Set 2 specification. .Sh HISTORY The .Fn link function appeared in -.At v7 . +.At v1 . The .Fn linkat system call appeared in .Fx 8.0 . .Pp The .Fn link system call traditionally allows the super-user to link directories which corrupts the file system coherency. This implementation no longer permits it. Index: head/lib/libc/sys/mkdir.2 =================================================================== --- head/lib/libc/sys/mkdir.2 (revision 326434) +++ head/lib/libc/sys/mkdir.2 (revision 326435) @@ -1,176 +1,180 @@ .\" Copyright (c) 1983, 1991, 1993 .\" The Regents of the University of California. All rights reserved. .\" .\" Redistribution and use in source and binary forms, with or without .\" modification, are permitted provided that the following conditions .\" are met: .\" 1. Redistributions of source code must retain the above copyright .\" notice, this list of conditions and the following disclaimer. .\" 2. Redistributions in binary form must reproduce the above copyright .\" notice, this list of conditions and the following disclaimer in the .\" documentation and/or other materials provided with the distribution. .\" 3. Neither the name of the University nor the names of its contributors .\" may be used to endorse or promote products derived from this software .\" without specific prior written permission. .\" .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" .\" @(#)mkdir.2 8.2 (Berkeley) 12/11/93 .\" $FreeBSD$ .\" .Dd June 26, 2008 .Dt MKDIR 2 .Os .Sh NAME .Nm mkdir , .Nm mkdirat .Nd make a directory file .Sh LIBRARY .Lb libc .Sh SYNOPSIS .In sys/stat.h .Ft int .Fn mkdir "const char *path" "mode_t mode" .Ft int .Fn mkdirat "int fd" "const char *path" "mode_t mode" .Sh DESCRIPTION The directory .Fa path is created with the access permissions specified by .Fa mode and restricted by the .Xr umask 2 of the calling process. .Pp The directory's owner ID is set to the process's effective user ID. The directory's group ID is set to that of the parent directory in which it is created. .Pp The .Fn mkdirat system call is equivalent to .Fn mkdir except in the case where .Fa path specifies a relative path. In this case the newly created directory is created relative to the directory associated with the file descriptor .Fa fd instead of the current working directory. If .Fn mkdirat is passed the special value .Dv AT_FDCWD in the .Fa fd parameter, the current working directory is used and the behavior is identical to a call to .Fn mkdir . .Sh RETURN VALUES .Rv -std mkdir .Sh ERRORS The .Fn mkdir system call will fail and no directory will be created if: .Bl -tag -width Er .It Bq Er ENOTDIR A component of the path prefix is not a directory. .It Bq Er ENAMETOOLONG A component of a pathname exceeded 255 characters, or an entire path name exceeded 1023 characters. .It Bq Er ENOENT A component of the path prefix does not exist. .It Bq Er EACCES Search permission is denied for a component of the path prefix, or write permission is denied on the parent directory of the directory to be created. .It Bq Er ELOOP Too many symbolic links were encountered in translating the pathname. .It Bq Er EPERM The parent directory of the directory to be created has its immutable flag set, see the .Xr chflags 2 manual page for more information. .It Bq Er EROFS The named directory would reside on a read-only file system. .It Bq Er EMLINK The new directory cannot be created because the parent directory contains too many subdirectories. .It Bq Er EEXIST The named file exists. .It Bq Er ENOSPC The new directory cannot be created because there is no space left on the file system that will contain the directory. .It Bq Er ENOSPC There are no free inodes on the file system on which the directory is being created. .It Bq Er EDQUOT The new directory cannot be created because the user's quota of disk blocks on the file system that will contain the directory has been exhausted. .It Bq Er EDQUOT The user's quota of inodes on the file system on which the directory is being created has been exhausted. .It Bq Er EIO An I/O error occurred while making the directory entry or allocating the inode. .It Bq Er EIO An I/O error occurred while reading from or writing to the file system. .It Bq Er EFAULT The .Fa path argument points outside the process's allocated address space. .El .Pp In addition to the errors returned by the .Fn mkdir , the .Fn mkdirat may fail if: .Bl -tag -width Er .It Bq Er EBADF The .Fa path argument does not specify an absolute path and the .Fa fd argument is neither .Dv AT_FDCWD nor a valid file descriptor open for searching. .It Bq Er ENOTDIR The .Fa path argument is not an absolute path and .Fa fd is neither .Dv AT_FDCWD nor a file descriptor associated with a directory. .El .Sh SEE ALSO .Xr chflags 2 , .Xr chmod 2 , .Xr stat 2 , .Xr umask 2 .Sh STANDARDS The .Fn mkdir system call is expected to conform to .St -p1003.1-90 . The .Fn mkdirat system call follows The Open Group Extended API Set 2 specification. .Sh HISTORY The .Fn mkdirat system call appeared in .Fx 8.0 . +The +.Fn mkdir +system call appeared in +.At v1 . Index: head/lib/libc/sys/mount.2 =================================================================== --- head/lib/libc/sys/mount.2 (revision 326434) +++ head/lib/libc/sys/mount.2 (revision 326435) @@ -1,378 +1,378 @@ .\" Copyright (c) 1980, 1989, 1993 .\" The Regents of the University of California. All rights reserved. .\" .\" Redistribution and use in source and binary forms, with or without .\" modification, are permitted provided that the following conditions .\" are met: .\" 1. Redistributions of source code must retain the above copyright .\" notice, this list of conditions and the following disclaimer. .\" 2. Redistributions in binary form must reproduce the above copyright .\" notice, this list of conditions and the following disclaimer in the .\" documentation and/or other materials provided with the distribution. .\" 3. Neither the name of the University nor the names of its contributors .\" may be used to endorse or promote products derived from this software .\" without specific prior written permission. .\" .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" .\" @(#)mount.2 8.3 (Berkeley) 5/24/95 .\" $FreeBSD$ .\" -.Dd April 13, 2015 +.Dd December 1, 2017 .Dt MOUNT 2 .Os .Sh NAME .Nm mount , .Nm nmount , .Nm unmount .Nd mount or dismount a file system .Sh LIBRARY .Lb libc .Sh SYNOPSIS .In sys/param.h .In sys/mount.h .Ft int .Fn mount "const char *type" "const char *dir" "int flags" "void *data" .Ft int .Fn unmount "const char *dir" "int flags" .In sys/uio.h .Ft int .Fn nmount "struct iovec *iov" "u_int niov" "int flags" .Sh DESCRIPTION The .Fn mount system call grafts a file system object onto the system file tree at the point .Fa dir . The argument .Fa data describes the file system object to be mounted. The argument .Fa type tells the kernel how to interpret .Fa data (See .Fa type below). The contents of the file system become available through the new mount point .Fa dir . Any files in .Fa dir at the time of a successful mount are swept under the carpet so to speak, and are unavailable until the file system is unmounted. .Pp The .Fn nmount system call behaves similarly to .Fn mount , except that the mount options (file system type name, device to mount, mount-point name, etc.) are passed as an array of name-value pairs in the array .Fa iov , containing .Fa niov elements. The following options are required by all file systems: .Bl -column fstype -offset indent .It .Li fstype Ta file system type name (e.g., Dq Li procfs ) .It .Li fspath Ta mount point pathname (e.g., Dq Li /proc ) .El .Pp Depending on the file system type, other options may be recognized or required; for example, most disk-based file systems require a .Dq Li from option containing the pathname of a special device in addition to the options listed above. .Pp By default only the super-user may call the .Fn mount system call. This restriction can be removed by setting the .Va vfs.usermount .Xr sysctl 8 variable to a non-zero value; see the BUGS section for more information. .Pp The following .Fa flags may be specified to suppress default semantics which affect file system access. .Bl -tag -width MNT_SYNCHRONOUS .It Dv MNT_RDONLY The file system should be treated as read-only; even the super-user may not write on it. Specifying MNT_UPDATE without this option will upgrade a read-only file system to read/write. .It Dv MNT_NOEXEC Do not allow files to be executed from the file system. .It Dv MNT_NOSUID Do not honor setuid or setgid bits on files when executing them. This flag is set automatically when the caller is not the super-user. .It Dv MNT_NOATIME Disable update of file access times. .It Dv MNT_SNAPSHOT Create a snapshot of the file system. This is currently only supported on UFS2 file systems, see .Xr mksnap_ffs 8 for more information. .It Dv MNT_SUIDDIR Directories with the SUID bit set chown new files to their own owner. This flag requires the SUIDDIR option to have been compiled into the kernel to have any effect. See the .Xr mount 8 and .Xr chmod 2 pages for more information. .It Dv MNT_SYNCHRONOUS All I/O to the file system should be done synchronously. .It Dv MNT_ASYNC All I/O to the file system should be done asynchronously. .It Dv MNT_FORCE Force a read-write mount even if the file system appears to be unclean. Dangerous. Together with .Dv MNT_UPDATE and .Dv MNT_RDONLY , specify that the file system is to be forcibly downgraded to a read-only mount even if some files are open for writing. .It Dv MNT_NOCLUSTERR Disable read clustering. .It Dv MNT_NOCLUSTERW Disable write clustering. .El .Pp The flag .Dv MNT_UPDATE indicates that the mount command is being applied to an already mounted file system. This allows the mount flags to be changed without requiring that the file system be unmounted and remounted. Some file systems may not allow all flags to be changed. For example, many file systems will not allow a change from read-write to read-only. .Pp The flag .Dv MNT_RELOAD causes the vfs subsystem to update its data structures pertaining to the specified already mounted file system. .Pp The .Fa type argument names the file system. The types of file systems known to the system can be obtained with .Xr lsvfs 1 . .Pp The .Fa data argument is a pointer to a structure that contains the type specific arguments to mount. The format for these argument structures is described in the manual page for each file system. By convention file system manual pages are named by prefixing ``mount_'' to the name of the file system as returned by .Xr lsvfs 1 . Thus the .Tn NFS file system is described by the .Xr mount_nfs 8 manual page. It should be noted that a manual page for default file systems, known as UFS and UFS2, does not exist. .Pp The .Fn unmount system call disassociates the file system from the specified mount point .Fa dir . .Pp The .Fa flags argument may include .Dv MNT_FORCE to specify that the file system should be forcibly unmounted even if files are still active. Active special devices continue to work, but any further accesses to any other active files result in errors even if the file system is later remounted. .Pp If the .Dv MNT_BYFSID flag is specified, .Fa dir should instead be a file system ID encoded as .Dq Li FSID : Ns Ar val0 : Ns Ar val1 , where .Ar val0 and .Ar val1 are the contents of the .Vt fsid_t .Va val[] array in decimal. The file system that has the specified file system ID will be unmounted. .Sh RETURN VALUES .Rv -std .Sh ERRORS The .Fn mount and .Fn nmount system calls will fail when one of the following occurs: .Bl -tag -width Er .It Bq Er EPERM The caller is neither the super-user nor the owner of .Fa dir . .It Bq Er ENAMETOOLONG A component of a pathname exceeded 255 characters, or the entire length of a path name exceeded 1023 characters. .It Bq Er ELOOP Too many symbolic links were encountered in translating a pathname. .It Bq Er ENOENT A component of .Fa dir does not exist. .It Bq Er ENOTDIR A component of .Fa name is not a directory, or a path prefix of .Fa special is not a directory. .It Bq Er EBUSY Another process currently holds a reference to .Fa dir . .It Bq Er EFAULT The .Fa dir argument points outside the process's allocated address space. .El .Pp The following errors can occur for a .Em ufs file system mount: .Bl -tag -width Er .It Bq Er ENODEV A component of ufs_args .Fa fspec does not exist. .It Bq Er ENOTBLK The .Fa fspec argument is not a block device. .It Bq Er ENXIO The major device number of .Fa fspec is out of range (this indicates no device driver exists for the associated hardware). .It Bq Er EBUSY .Fa fspec is already mounted. .It Bq Er EMFILE No space remains in the mount table. .It Bq Er EINVAL The super block for the file system had a bad magic number or an out of range block size. .It Bq Er ENOMEM Not enough memory was available to read the cylinder group information for the file system. .It Bq Er EIO An I/O error occurred while reading the super block or cylinder group information. .It Bq Er EFAULT The .Fa fspec argument points outside the process's allocated address space. .El .Pp The following errors can occur for a .Em nfs file system mount: .Bl -tag -width Er .It Bq Er ETIMEDOUT .Em Nfs timed out trying to contact the server. .It Bq Er EFAULT Some part of the information described by nfs_args points outside the process's allocated address space. .El .Pp The .Fn unmount system call may fail with one of the following errors: .Bl -tag -width Er .It Bq Er EPERM The caller is neither the super-user nor the user who issued the corresponding .Fn mount call. .It Bq Er ENAMETOOLONG The length of the path name exceeded 1023 characters. .It Bq Er EINVAL The requested directory is not in the mount table. .It Bq Er ENOENT The file system ID specified using .Dv MNT_BYFSID was not found in the mount table. .It Bq Er EINVAL The file system ID specified using .Dv MNT_BYFSID could not be decoded. .It Bq Er EINVAL The specified file system is the root file system. .It Bq Er EBUSY A process is holding a reference to a file located on the file system. .It Bq Er EIO An I/O error occurred while writing cached file system information. .It Bq Er EFAULT The .Fa dir argument points outside the process's allocated address space. .El .Sh SEE ALSO .Xr lsvfs 1 , .Xr mksnap_ffs 8 , .Xr mount 8 , .Xr umount 8 .Sh HISTORY The .Fn mount and .Fn unmount functions appeared in -.At v6 . +.At v1 . The .Fn nmount system call first appeared in .Fx 5.0 . .Sh BUGS Some of the error codes need translation to more obvious messages. .Pp Allowing untrusted users to mount arbitrary media, e.g. by enabling .Va vfs.usermount , should not be considered safe. Most file systems in .Fx were not built to safeguard against malicious devices. Index: head/lib/libc/sys/open.2 =================================================================== --- head/lib/libc/sys/open.2 (revision 326434) +++ head/lib/libc/sys/open.2 (revision 326435) @@ -1,544 +1,544 @@ .\" Copyright (c) 1980, 1991, 1993 .\" The Regents of the University of California. All rights reserved. .\" .\" Redistribution and use in source and binary forms, with or without .\" modification, are permitted provided that the following conditions .\" are met: .\" 1. Redistributions of source code must retain the above copyright .\" notice, this list of conditions and the following disclaimer. .\" 2. Redistributions in binary form must reproduce the above copyright .\" notice, this list of conditions and the following disclaimer in the .\" documentation and/or other materials provided with the distribution. .\" 3. Neither the name of the University nor the names of its contributors .\" may be used to endorse or promote products derived from this software .\" without specific prior written permission. .\" .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" .\" @(#)open.2 8.2 (Berkeley) 11/16/93 .\" $FreeBSD$ .\" -.Dd September 15, 2017 +.Dd December 1, 2017 .Dt OPEN 2 .Os .Sh NAME .Nm open , openat .Nd open or create a file for reading, writing or executing .Sh LIBRARY .Lb libc .Sh SYNOPSIS .In fcntl.h .Ft int .Fn open "const char *path" "int flags" "..." .Ft int .Fn openat "int fd" "const char *path" "int flags" "..." .Sh DESCRIPTION The file name specified by .Fa path is opened for either execution or reading and/or writing as specified by the argument .Fa flags and the file descriptor returned to the calling process. The .Fa flags argument may indicate the file is to be created if it does not exist (by specifying the .Dv O_CREAT flag). In this case .Fn open and .Fn openat require an additional argument .Fa "mode_t mode" , and the file is created with mode .Fa mode as described in .Xr chmod 2 and modified by the process' umask value (see .Xr umask 2 ) . .Pp The .Fn openat function is equivalent to the .Fn open function except in the case where the .Fa path specifies a relative path. In this case the file to be opened is determined relative to the directory associated with the file descriptor .Fa fd instead of the current working directory. The .Fa flag parameter and the optional fourth parameter correspond exactly to the parameters of .Fn open . If .Fn openat is passed the special value .Dv AT_FDCWD in the .Fa fd parameter, the current working directory is used and the behavior is identical to a call to .Fn open . .Pp In .Xr capsicum 4 capability mode, .Fn open is not permitted. The .Fa path argument to .Fn openat must be strictly relative to a file descriptor .Fa fd , as defined in .Pa sys/kern/vfs_lookup.c . .Fa path must not be an absolute path and must not contain ".." components. Additionally, no symbolic link in .Fa path may contain ".." components either. .Fa fd must not be .Dv AT_FDCWD . .Pp The flags specified are formed by .Em or Ns 'ing the following values .Pp .Bd -literal -offset indent -compact O_RDONLY open for reading only O_WRONLY open for writing only O_RDWR open for reading and writing O_EXEC open for execute only O_NONBLOCK do not block on open O_APPEND append on each write O_CREAT create file if it does not exist O_TRUNC truncate size to 0 O_EXCL error if create and file exists O_SHLOCK atomically obtain a shared lock O_EXLOCK atomically obtain an exclusive lock O_DIRECT eliminate or reduce cache effects O_FSYNC synchronous writes O_SYNC synchronous writes O_NOFOLLOW do not follow symlinks O_NOCTTY ignored O_TTY_INIT ignored O_DIRECTORY error if file is not a directory O_CLOEXEC set FD_CLOEXEC upon open O_VERIFY verify the contents of the file .Ed .Pp Opening a file with .Dv O_APPEND set causes each write on the file to be appended to the end. If .Dv O_TRUNC is specified and the file exists, the file is truncated to zero length. If .Dv O_EXCL is set with .Dv O_CREAT and the file already exists, .Fn open returns an error. This may be used to implement a simple exclusive access locking mechanism. If .Dv O_EXCL is set and the last component of the pathname is a symbolic link, .Fn open will fail even if the symbolic link points to a non-existent name. If the .Dv O_NONBLOCK flag is specified and the .Fn open system call would result in the process being blocked for some reason (e.g., waiting for carrier on a dialup line), .Fn open returns immediately. The descriptor remains in non-blocking mode for subsequent operations. .Pp If .Dv O_FSYNC is used in the mask, all writes will immediately be written to disk, the kernel will not cache written data and all writes on the descriptor will not return until the data to be written completes. .Pp .Dv O_SYNC is a synonym for .Dv O_FSYNC required by .Tn POSIX . .Pp If .Dv O_NOFOLLOW is used in the mask and the target file passed to .Fn open is a symbolic link then the .Fn open will fail. .Pp When opening a file, a lock with .Xr flock 2 semantics can be obtained by setting .Dv O_SHLOCK for a shared lock, or .Dv O_EXLOCK for an exclusive lock. If creating a file with .Dv O_CREAT , the request for the lock will never fail (provided that the underlying file system supports locking). .Pp .Dv O_DIRECT may be used to minimize or eliminate the cache effects of reading and writing. The system will attempt to avoid caching the data you read or write. If it cannot avoid caching the data, it will minimize the impact the data has on the cache. Use of this flag can drastically reduce performance if not used with care. .Pp .Dv O_NOCTTY may be used to ensure the OS does not assign this file as the controlling terminal when it opens a tty device. This is the default on .Fx , but is present for .Tn POSIX compatibility. The .Fn open system call will not assign controlling terminals on .Fx . .Pp .Dv O_TTY_INIT may be used to ensure the OS restores the terminal attributes when initially opening a TTY. This is the default on .Fx , but is present for .Tn POSIX compatibility. The initial call to .Fn open on a TTY will always restore default terminal attributes on .Fx . .Pp .Dv O_DIRECTORY may be used to ensure the resulting file descriptor refers to a directory. This flag can be used to prevent applications with elevated privileges from opening files which are even unsafe to open with .Dv O_RDONLY , such as device nodes. .Pp .Dv O_CLOEXEC may be used to set .Dv FD_CLOEXEC flag for the newly returned file descriptor. .Pp .Dv O_VERIFY may be used to indicate to the kernel that the contents of the file should be verified before allowing the open to proceed. The details of what .Dq verified means is implementation specific. The run-time linker (rtld) uses this flag to ensure shared objects have been verified before operating on them. .Pp If successful, .Fn open returns a non-negative integer, termed a file descriptor. It returns \-1 on failure. The file pointer used to mark the current position within the file is set to the beginning of the file. .Pp If a sleeping open of a device node from .Xr devfs 5 is interrupted by a signal, the call always fails with .Er EINTR , even if the .Dv SA_RESTART flag is set for the signal. A sleeping open of a fifo (see .Xr mkfifo 2 ) is restarted as normal. .Pp When a new file is created it is given the group of the directory which contains it. .Pp Unless .Dv O_CLOEXEC flag was specified, the new descriptor is set to remain open across .Xr execve 2 system calls; see .Xr close 2 , .Xr fcntl 2 and .Dv O_CLOEXEC description. .Pp The system imposes a limit on the number of file descriptors open simultaneously by one process. The .Xr getdtablesize 2 system call returns the current system limit. .Sh RETURN VALUES If successful, .Fn open and .Fn openat return a non-negative integer, termed a file descriptor. They return \-1 on failure, and set .Va errno to indicate the error. .Sh ERRORS The named file is opened unless: .Bl -tag -width Er .It Bq Er ENOTDIR A component of the path prefix is not a directory. .It Bq Er ENAMETOOLONG A component of a pathname exceeded 255 characters, or an entire path name exceeded 1023 characters. .It Bq Er ENOENT .Dv O_CREAT is not set and the named file does not exist. .It Bq Er ENOENT A component of the path name that must exist does not exist. .It Bq Er EACCES Search permission is denied for a component of the path prefix. .It Bq Er EACCES The required permissions (for reading and/or writing) are denied for the given flags. .It Bq Er EACCES .Dv O_TRUNC is specified and write permission is denied. .It Bq Er EACCES .Dv O_CREAT is specified, the file does not exist, and the directory in which it is to be created does not permit writing. .It Bq Er EPERM .Dv O_CREAT is specified, the file does not exist, and the directory in which it is to be created has its immutable flag set, see the .Xr chflags 2 manual page for more information. .It Bq Er EPERM The named file has its immutable flag set and the file is to be modified. .It Bq Er EPERM The named file has its append-only flag set, the file is to be modified, and .Dv O_TRUNC is specified or .Dv O_APPEND is not specified. .It Bq Er ELOOP Too many symbolic links were encountered in translating the pathname. .It Bq Er EISDIR The named file is a directory, and the arguments specify it is to be modified. .It Bq Er EROFS The named file resides on a read-only file system, and the file is to be modified. .It Bq Er EROFS .Dv O_CREAT is specified and the named file would reside on a read-only file system. .It Bq Er EMFILE The process has already reached its limit for open file descriptors. .It Bq Er ENFILE The system file table is full. .It Bq Er EMLINK .Dv O_NOFOLLOW was specified and the target is a symbolic link. .It Bq Er ENXIO The named file is a character special or block special file, and the device associated with this special file does not exist. .It Bq Er ENXIO .Dv O_NONBLOCK is set, the named file is a fifo, .Dv O_WRONLY is set, and no process has the file open for reading. .It Bq Er EINTR The .Fn open operation was interrupted by a signal. .It Bq Er EOPNOTSUPP .Dv O_SHLOCK or .Dv O_EXLOCK is specified but the underlying file system does not support locking. .It Bq Er EOPNOTSUPP The named file is a special file mounted through a file system that does not support access to it (e.g.\& NFS). .It Bq Er EWOULDBLOCK .Dv O_NONBLOCK and one of .Dv O_SHLOCK or .Dv O_EXLOCK is specified and the file is locked. .It Bq Er ENOSPC .Dv O_CREAT is specified, the file does not exist, and the directory in which the entry for the new file is being placed cannot be extended because there is no space left on the file system containing the directory. .It Bq Er ENOSPC .Dv O_CREAT is specified, the file does not exist, and there are no free inodes on the file system on which the file is being created. .It Bq Er EDQUOT .Dv O_CREAT is specified, the file does not exist, and the directory in which the entry for the new file is being placed cannot be extended because the user's quota of disk blocks on the file system containing the directory has been exhausted. .It Bq Er EDQUOT .Dv O_CREAT is specified, the file does not exist, and the user's quota of inodes on the file system on which the file is being created has been exhausted. .It Bq Er EIO An I/O error occurred while making the directory entry or allocating the inode for .Dv O_CREAT . .It Bq Er ETXTBSY The file is a pure procedure (shared text) file that is being executed and the .Fn open system call requests write access. .It Bq Er EFAULT The .Fa path argument points outside the process's allocated address space. .It Bq Er EEXIST .Dv O_CREAT and .Dv O_EXCL were specified and the file exists. .It Bq Er EOPNOTSUPP An attempt was made to open a socket (not currently implemented). .It Bq Er EINVAL An attempt was made to open a descriptor with an illegal combination of .Dv O_RDONLY , .Dv O_WRONLY , .Dv O_RDWR and .Dv O_EXEC . .It Bq Er EBADF The .Fa path argument does not specify an absolute path and the .Fa fd argument is neither .Dv AT_FDCWD nor a valid file descriptor open for searching. .It Bq Er ENOTDIR The .Fa path argument is not an absolute path and .Fa fd is neither .Dv AT_FDCWD nor a file descriptor associated with a directory. .It Bq Er ENOTDIR .Dv O_DIRECTORY is specified and the file is not a directory. .It Bq Er ECAPMODE .Dv AT_FDCWD is specified and the process is in capability mode. .It Bq Er ECAPMODE .Fn open was called and the process is in capability mode. .It Bq Er ENOTCAPABLE .Fa path is an absolute path or contained a ".." component leading to a directory outside of the directory hierarchy specified by .Fa fd . .El .Sh SEE ALSO .Xr chmod 2 , .Xr close 2 , .Xr dup 2 , .Xr fexecve 2 , .Xr fhopen 2 , .Xr getdtablesize 2 , .Xr getfh 2 , .Xr lgetfh 2 , .Xr lseek 2 , .Xr read 2 , .Xr umask 2 , .Xr write 2 , .Xr fopen 3 , .Xr capsicum 4 .Sh STANDARDS These functions are specified by .St -p1003.1-2008 . .Fx sets .Va errno to .Er EMLINK instead of .Er ELOOP as specified by .Tn POSIX when .Dv O_NOFOLLOW is set in flags and the final component of pathname is a symbolic link to distinguish it from the case of too many symbolic link traversals in one of its non-final components. .Sh HISTORY The .Fn open function appeared in -.At v6 . +.At v1 . The .Fn openat function was introduced in .Fx 8.0 . .Sh BUGS The Open Group Extended API Set 2 specification requires that the test for whether .Fa fd is searchable is based on whether .Fa fd is open for searching, not whether the underlying directory currently permits searches. The present implementation of the .Fa openat checks the current permissions of directory instead. Index: head/lib/libc/sys/read.2 =================================================================== --- head/lib/libc/sys/read.2 (revision 326434) +++ head/lib/libc/sys/read.2 (revision 326435) @@ -1,284 +1,284 @@ .\" Copyright (c) 1980, 1991, 1993 .\" The Regents of the University of California. All rights reserved. .\" .\" Redistribution and use in source and binary forms, with or without .\" modification, are permitted provided that the following conditions .\" are met: .\" 1. Redistributions of source code must retain the above copyright .\" notice, this list of conditions and the following disclaimer. .\" 2. Redistributions in binary form must reproduce the above copyright .\" notice, this list of conditions and the following disclaimer in the .\" documentation and/or other materials provided with the distribution. .\" 3. Neither the name of the University nor the names of its contributors .\" may be used to endorse or promote products derived from this software .\" without specific prior written permission. .\" .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" .\" @(#)read.2 8.4 (Berkeley) 2/26/94 .\" $FreeBSD$ .\" -.Dd December 15, 2015 +.Dd December 1, 2017 .Dt READ 2 .Os .Sh NAME .Nm read , .Nm readv , .Nm pread , .Nm preadv .Nd read input .Sh LIBRARY .Lb libc .Sh SYNOPSIS .In unistd.h .Ft ssize_t .Fn read "int fd" "void *buf" "size_t nbytes" .Ft ssize_t .Fn pread "int fd" "void *buf" "size_t nbytes" "off_t offset" .In sys/uio.h .Ft ssize_t .Fn readv "int fd" "const struct iovec *iov" "int iovcnt" .Ft ssize_t .Fn preadv "int fd" "const struct iovec *iov" "int iovcnt" "off_t offset" .Sh DESCRIPTION The .Fn read system call attempts to read .Fa nbytes of data from the object referenced by the descriptor .Fa fd into the buffer pointed to by .Fa buf . The .Fn readv system call performs the same action, but scatters the input data into the .Fa iovcnt buffers specified by the members of the .Fa iov array: iov[0], iov[1], ..., iov[iovcnt\|\-\|1]. The .Fn pread and .Fn preadv system calls perform the same functions, but read from the specified position in the file without modifying the file pointer. .Pp For .Fn readv and .Fn preadv , the .Fa iovec structure is defined as: .Pp .Bd -literal -offset indent -compact struct iovec { void *iov_base; /* Base address. */ size_t iov_len; /* Length. */ }; .Ed .Pp Each .Fa iovec entry specifies the base address and length of an area in memory where data should be placed. The .Fn readv system call will always fill an area completely before proceeding to the next. .Pp On objects capable of seeking, the .Fn read starts at a position given by the pointer associated with .Fa fd (see .Xr lseek 2 ) . Upon return from .Fn read , the pointer is incremented by the number of bytes actually read. .Pp Objects that are not capable of seeking always read from the current position. The value of the pointer associated with such an object is undefined. .Pp Upon successful completion, .Fn read , .Fn readv , .Fn pread and .Fn preadv return the number of bytes actually read and placed in the buffer. The system guarantees to read the number of bytes requested if the descriptor references a normal file that has that many bytes left before the end-of-file, but in no other case. .Sh RETURN VALUES If successful, the number of bytes actually read is returned. Upon reading end-of-file, zero is returned. Otherwise, a -1 is returned and the global variable .Va errno is set to indicate the error. .Sh ERRORS The .Fn read , .Fn readv , .Fn pread and .Fn preadv system calls will succeed unless: .Bl -tag -width Er .It Bq Er EBADF The .Fa fd argument is not a valid file or socket descriptor open for reading. .It Bq Er ECONNRESET The .Fa fd argument refers to a socket, and the remote socket end is forcibly closed. .It Bq Er EFAULT The .Fa buf argument points outside the allocated address space. .It Bq Er EIO An I/O error occurred while reading from the file system. .It Bq Er EBUSY Failed to read from a file, e.g. /proc//regs while is not stopped .It Bq Er EINTR A read from a slow device (i.e.\& one that might block for an arbitrary amount of time) was interrupted by the delivery of a signal before any data arrived. .It Bq Er EINVAL The pointer associated with .Fa fd was negative. .It Bq Er EAGAIN The file was marked for non-blocking I/O, and no data were ready to be read. .It Bq Er EISDIR The file descriptor is associated with a directory residing on a file system that does not allow regular read operations on directories (e.g.\& NFS). .It Bq Er EOPNOTSUPP The file descriptor is associated with a file system and file type that do not allow regular read operations on it. .It Bq Er EOVERFLOW The file descriptor is associated with a regular file, .Fa nbytes is greater than 0, .Fa offset is before the end-of-file, and .Fa offset is greater than or equal to the offset maximum established for this file system. .It Bq Er EINVAL The value .Fa nbytes is greater than .Dv INT_MAX . .El .Pp In addition, .Fn readv and .Fn preadv may return one of the following errors: .Bl -tag -width Er .It Bq Er EINVAL The .Fa iovcnt argument was less than or equal to 0, or greater than .Dv IOV_MAX . .It Bq Er EINVAL One of the .Fa iov_len values in the .Fa iov array was negative. .It Bq Er EINVAL The sum of the .Fa iov_len values in the .Fa iov array overflowed a 32-bit integer. .It Bq Er EFAULT Part of the .Fa iov array points outside the process's allocated address space. .El .Pp The .Fn pread and .Fn preadv system calls may also return the following errors: .Bl -tag -width Er .It Bq Er EINVAL The .Fa offset value was negative. .It Bq Er ESPIPE The file descriptor is associated with a pipe, socket, or FIFO. .El .Sh SEE ALSO .Xr dup 2 , .Xr fcntl 2 , .Xr getdirentries 2 , .Xr open 2 , .Xr pipe 2 , .Xr select 2 , .Xr socket 2 , .Xr socketpair 2 , .Xr fread 3 , .Xr readdir 3 .Sh STANDARDS The .Fn read system call is expected to conform to .St -p1003.1-90 . The .Fn readv and .Fn pread system calls are expected to conform to .St -xpg4.2 . .Sh HISTORY The .Fn preadv system call appeared in .Fx 6.0 . The .Fn pread function appeared in .At V.4 . The .Fn readv system call appeared in .Bx 4.2 . The .Fn read function appeared in -.At v6 . +.At v1 . Index: head/lib/libc/sys/setuid.2 =================================================================== --- head/lib/libc/sys/setuid.2 (revision 326434) +++ head/lib/libc/sys/setuid.2 (revision 326435) @@ -1,187 +1,189 @@ .\" Copyright (c) 1983, 1991, 1993 .\" The Regents of the University of California. All rights reserved. .\" .\" Redistribution and use in source and binary forms, with or without .\" modification, are permitted provided that the following conditions .\" are met: .\" 1. Redistributions of source code must retain the above copyright .\" notice, this list of conditions and the following disclaimer. .\" 2. Redistributions in binary form must reproduce the above copyright .\" notice, this list of conditions and the following disclaimer in the .\" documentation and/or other materials provided with the distribution. .\" 3. Neither the name of the University nor the names of its contributors .\" may be used to endorse or promote products derived from this software .\" without specific prior written permission. .\" .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" .\" @(#)setuid.2 8.1 (Berkeley) 6/4/93 .\" $FreeBSD$ .\" .Dd December 15, 2015 .Dt SETUID 2 .Os .Sh NAME .Nm setuid , .Nm seteuid , .Nm setgid , .Nm setegid .Nd set user and group ID .Sh LIBRARY .Lb libc .Sh SYNOPSIS .In unistd.h .Ft int .Fn setuid "uid_t uid" .Ft int .Fn seteuid "uid_t euid" .Ft int .Fn setgid "gid_t gid" .Ft int .Fn setegid "gid_t egid" .Sh DESCRIPTION The .Fn setuid system call sets the real and effective user IDs and the saved set-user-ID of the current process to the specified value. .\" Comment out next block for !_POSIX_SAVED_IDS .\" The real user ID and the saved set-user-ID are changed only if the .\" effective user ID is that of the super user. .\" I.e. .\" .Fn setuid .\" system call is equal to .\" .Fn seteuid .\" system call if the effective user ID is not that of the super user. .\" End of block The .Fn setuid system call is permitted if the specified ID is equal to the real user ID .\" Comment out next line for !_POSIX_SAVED_IDS .\" or the saved set-user-ID .\" Next line is for Appendix B.4.2.2 case. or the effective user ID of the process, or if the effective user ID is that of the super user. .Pp The .Fn setgid system call sets the real and effective group IDs and the saved set-group-ID of the current process to the specified value. .\" Comment out next block for !_POSIX_SAVED_IDS .\" The real group ID and the saved set-group-ID are changed only if the .\" effective user ID is that of the super user. .\" I.e. .\" .Fn setgid .\" system call is equal to .\" .Fn setegid .\" system call if the effective user ID is not that of the super user. .\" End of block The .Fn setgid system call is permitted if the specified ID is equal to the real group ID .\" Comment out next line for !_POSIX_SAVED_IDS .\" or the saved set-group-ID .\" Next line is for Appendix B.4.2.2 case. or the effective group ID of the process, or if the effective user ID is that of the super user. .Pp The .Fn seteuid system call .Pq Fn setegid sets the effective user ID (group ID) of the current process. The effective user ID may be set to the value of the real user ID or the saved set-user-ID (see .Xr intro 2 and .Xr execve 2 ) ; in this way, the effective user ID of a set-user-ID executable may be toggled by switching to the real user ID, then re-enabled by reverting to the set-user-ID value. Similarly, the effective group ID may be set to the value of the real group ID or the saved set-group-ID. .Sh RETURN VALUES .Rv -std .Sh ERRORS The system calls will fail if: .Bl -tag -width Er .It Bq Er EPERM The user is not the super user and the ID specified is not the real, effective ID, or saved ID. .El .Sh SEE ALSO .Xr getgid 2 , .Xr getuid 2 , .Xr issetugid 2 , .Xr setregid 2 , .Xr setreuid 2 .Sh STANDARDS The .Fn setuid and .Fn setgid system calls are compliant with the .St -p1003.1-90 specification with .Li _POSIX_SAVED_IDS .\" Uncomment next line for !_POSIX_SAVED_IDS not defined with the permitted extensions from Appendix B.4.2.2. The .Fn seteuid and .Fn setegid system calls are extensions based on the .Tn POSIX concept of .Li _POSIX_SAVED_IDS , and have been proposed for a future revision of the standard. .Sh HISTORY The .Fn setuid -and +function appeared in +.At v1 . +The .Fn setgid -functions appeared in +function appeared in .At v7 . .Sh SECURITY CONSIDERATIONS Read and write permissions to files are determined upon a call to .Xr open 2 . Once a file descriptor is open, dropping privilege does not affect the process's read/write permissions, even if the user ID specified has no read or write permissions to the file. These files normally remain open in any new process executed, resulting in a user being able to read or modify potentially sensitive data. .Pp To prevent these files from remaining open after an .Xr exec 3 call, be sure to set the close-on-exec flag: .Bd -literal void pseudocode(void) { int fd; /* ... */ fd = open("/path/to/sensitive/data", O_RDWR | O_CLOEXEC); if (fd == -1) err(1, "open"); /* ... */ execve(path, argv, environ); } .Ed Index: head/lib/libc/sys/stat.2 =================================================================== --- head/lib/libc/sys/stat.2 (revision 326434) +++ head/lib/libc/sys/stat.2 (revision 326435) @@ -1,441 +1,441 @@ .\" Copyright (c) 1980, 1991, 1993, 1994 .\" The Regents of the University of California. All rights reserved. .\" .\" Redistribution and use in source and binary forms, with or without .\" modification, are permitted provided that the following conditions .\" are met: .\" 1. Redistributions of source code must retain the above copyright .\" notice, this list of conditions and the following disclaimer. .\" 2. Redistributions in binary form must reproduce the above copyright .\" notice, this list of conditions and the following disclaimer in the .\" documentation and/or other materials provided with the distribution. .\" 3. Neither the name of the University nor the names of its contributors .\" may be used to endorse or promote products derived from this software .\" without specific prior written permission. .\" .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" .\" @(#)stat.2 8.4 (Berkeley) 5/1/95 .\" $FreeBSD$ .\" -.Dd June 23, 2017 +.Dd December 1, 2017 .Dt STAT 2 .Os .Sh NAME .Nm stat , .Nm lstat , .Nm fstat , .Nm fstatat .Nd get file status .Sh LIBRARY .Lb libc .Sh SYNOPSIS .In sys/stat.h .Ft int .Fn stat "const char * restrict path" "struct stat * restrict sb" .Ft int .Fn lstat "const char * restrict path" "struct stat * restrict sb" .Ft int .Fn fstat "int fd" "struct stat *sb" .Ft int .Fn fstatat "int fd" "const char *path" "struct stat *buf" "int flag" .Sh DESCRIPTION The .Fn stat system call obtains information about the file pointed to by .Fa path . Read, write or execute permission of the named file is not required, but all directories listed in the path name leading to the file must be searchable. .Pp The .Fn lstat system call is like .Fn stat except when the named file is a symbolic link, in which case .Fn lstat returns information about the link, while .Fn stat returns information about the file the link references. .Pp The .Fn fstat system call obtains the same information about an open file known by the file descriptor .Fa fd . .Pp The .Fn fstatat system call is equivalent to .Fn stat and .Fn lstat except when the .Fa path specifies a relative path. In this case the status is retrieved from a file relative to the directory associated with the file descriptor .Fa fd instead of the current working directory. .Pp The values for the .Fa flag are constructed by a bitwise-inclusive OR of flags from this list, defined in .In fcntl.h : .Bl -tag -width indent .It Dv AT_SYMLINK_NOFOLLOW If .Fa path names a symbolic link, the status of the symbolic link is returned. .El .Pp If .Fn fstatat is passed the special value .Dv AT_FDCWD in the .Fa fd parameter, the current working directory is used and the behavior is identical to a call to .Fn stat or .Fn lstat respectively, depending on whether or not the .Dv AT_SYMLINK_NOFOLLOW bit is set in .Fa flag . .Pp The .Fa sb argument is a pointer to a .Vt stat structure as defined by .In sys/stat.h and into which information is placed concerning the file. .Pp The fields of .Vt "struct stat" related to the file system are: .Bl -tag -width ".Va st_nlink" .It Va st_dev Numeric ID of the device containing the file. .It Va st_ino The file's inode number. .It Va st_nlink Number of hard links to the file. .It Va st_flags Flags enabled for the file. See .Xr chflags 2 for the list of flags and their description. .El .Pp The .Va st_dev and .Va st_ino fields together identify the file uniquely within the system. .Pp The time-related fields of .Vt "struct stat" are: .Bl -tag -width ".Va st_birthtim" .It Va st_atim Time when file data was last accessed. Changed by the .Xr mknod 2 , .Xr utimes 2 , .Xr read 2 and .Xr readv 2 system calls. .It Va st_mtim Time when file data was last modified. Changed by the .Xr mkdir 2 , .Xr mkfifo 2 , .Xr mknod 2 , .Xr utimes 2 , .Xr write 2 and .Xr writev 2 system calls. .It Va st_ctim Time when file status was last changed (inode data modification). Changed by the .Xr chflags 2 , .Xr chmod 2 , .Xr chown 2 , .Xr creat 2 , .Xr link 2 , .Xr mkdir 2 , .Xr mkfifo 2 , .Xr mknod 2 , .Xr rename 2 , .Xr rmdir 2 , .Xr symlink 2 , .Xr truncate 2 , .Xr unlink 2 , .Xr utimes 2 , .Xr write 2 and .Xr writev 2 system calls. .It Va st_birthtim Time when the inode was created. .El .Pp These time-related macros are defined for compatibility: .Bd -literal #define st_atime st_atim.tv_sec #define st_mtime st_mtim.tv_sec #define st_ctime st_ctim.tv_sec #ifndef _POSIX_SOURCE #define st_birthtime st_birthtim.tv_sec #endif #ifndef _POSIX_SOURCE #define st_atimespec st_atim #define st_mtimespec st_mtim #define st_ctimespec st_ctim #define st_birthtimespec st_birthtim #endif .Ed .Pp Size-related fields of the .Vt "struct stat" are: .Bl -tag -width ".Va st_blksize" .It Va st_size File size in bytes. .It Va st_blksize Optimal I/O block size for the file. .It Va st_blocks Actual number of blocks allocated for the file in 512-byte units. As short symbolic links are stored in the inode, this number may be zero. .El .Pp The access-related fields of .Vt "struct stat" are: .Bl -tag -width ".Va st_mode" .It Va st_uid User ID of the file's owner. .It Va st_gid Group ID of the file. .It Va st_mode Status of the file (see below). .El .Pp The status information word .Fa st_mode has these bits: .Bd -literal #define S_IFMT 0170000 /* type of file mask */ #define S_IFIFO 0010000 /* named pipe (fifo) */ #define S_IFCHR 0020000 /* character special */ #define S_IFDIR 0040000 /* directory */ #define S_IFBLK 0060000 /* block special */ #define S_IFREG 0100000 /* regular */ #define S_IFLNK 0120000 /* symbolic link */ #define S_IFSOCK 0140000 /* socket */ #define S_IFWHT 0160000 /* whiteout */ #define S_ISUID 0004000 /* set user id on execution */ #define S_ISGID 0002000 /* set group id on execution */ #define S_ISVTX 0001000 /* save swapped text even after use */ #define S_IRWXU 0000700 /* RWX mask for owner */ #define S_IRUSR 0000400 /* read permission, owner */ #define S_IWUSR 0000200 /* write permission, owner */ #define S_IXUSR 0000100 /* execute/search permission, owner */ #define S_IRWXG 0000070 /* RWX mask for group */ #define S_IRGRP 0000040 /* read permission, group */ #define S_IWGRP 0000020 /* write permission, group */ #define S_IXGRP 0000010 /* execute/search permission, group */ #define S_IRWXO 0000007 /* RWX mask for other */ #define S_IROTH 0000004 /* read permission, other */ #define S_IWOTH 0000002 /* write permission, other */ #define S_IXOTH 0000001 /* execute/search permission, other */ .Ed .Pp For a list of access modes, see .In sys/stat.h , .Xr access 2 and .Xr chmod 2 . These macros are available to test whether a .Va st_mode value passed in the .Fa m argument corresponds to a file of the specified type: .Bl -tag -width ".Fn S_ISFIFO m" .It Fn S_ISBLK m Test for a block special file. .It Fn S_ISCHR m Test for a character special file. .It Fn S_ISDIR m Test for a directory. .It Fn S_ISFIFO m Test for a pipe or FIFO special file. .It Fn S_ISLNK m Test for a symbolic link. .It Fn S_ISREG m Test for a regular file. .It Fn S_ISSOCK m Test for a socket. .It Fn S_ISWHT m Test for a whiteout. .El .Pp The macros evaluate to a non-zero value if the test is true or to the value 0 if the test is false. .Sh RETURN VALUES .Rv -std .Sh COMPATIBILITY Previous versions of the system used different types for the .Va st_dev , .Va st_uid , .Va st_gid , .Va st_rdev , .Va st_size , .Va st_blksize and .Va st_blocks fields. .Sh ERRORS The .Fn stat and .Fn lstat system calls will fail if: .Bl -tag -width Er .It Bq Er EACCES Search permission is denied for a component of the path prefix. .It Bq Er EFAULT The .Fa sb or .Fa path argument points to an invalid address. .It Bq Er EIO An I/O error occurred while reading from or writing to the file system. .It Bq Er ELOOP Too many symbolic links were encountered in translating the pathname. .It Bq Er ENAMETOOLONG A component of a pathname exceeded 255 characters, or an entire path name exceeded 1023 characters. .It Bq Er ENOENT The named file does not exist. .It Bq Er ENOTDIR A component of the path prefix is not a directory. .It Bq Er EOVERFLOW The file size in bytes cannot be represented correctly in the structure pointed to by .Fa sb . .El .Pp The .Fn fstat system call will fail if: .Bl -tag -width Er .It Bq Er EBADF The .Fa fd argument is not a valid open file descriptor. .It Bq Er EFAULT The .Fa sb argument points to an invalid address. .It Bq Er EIO An I/O error occurred while reading from or writing to the file system. .It Bq Er EOVERFLOW The file size in bytes cannot be represented correctly in the structure pointed to by .Fa sb . .El .Pp In addition to the errors returned by the .Fn lstat , the .Fn fstatat may fail if: .Bl -tag -width Er .It Bq Er EBADF The .Fa path argument does not specify an absolute path and the .Fa fd argument is neither .Dv AT_FDCWD nor a valid file descriptor open for searching. .It Bq Er EINVAL The value of the .Fa flag argument is not valid. .It Bq Er ENOTDIR The .Fa path argument is not an absolute path and .Fa fd is neither .Dv AT_FDCWD nor a file descriptor associated with a directory. .El .Sh SEE ALSO .Xr access 2 , .Xr chmod 2 , .Xr chown 2 , .Xr fhstat 2 , .Xr statfs 2 , .Xr utimes 2 , .Xr sticky 7 , .Xr symlink 7 .Sh STANDARDS The .Fn stat and .Fn fstat system calls are expected to conform to .St -p1003.1-90 . The .Fn fstatat system call follows The Open Group Extended API Set 2 specification. .Sh HISTORY The .Fn stat and .Fn fstat system calls appeared in -.At v7 . +.At v1 . The .Fn lstat system call appeared in .Bx 4.2 . The .Fn fstatat system call appeared in .Fx 8.0 . .Sh BUGS Applying .Fn fstat to a socket returns a zeroed buffer, except for the blocksize field, and a unique device and inode number. Index: head/lib/libc/sys/unlink.2 =================================================================== --- head/lib/libc/sys/unlink.2 (revision 326434) +++ head/lib/libc/sys/unlink.2 (revision 326435) @@ -1,228 +1,228 @@ .\" Copyright (c) 1980, 1991, 1993 .\" The Regents of the University of California. All rights reserved. .\" .\" Redistribution and use in source and binary forms, with or without .\" modification, are permitted provided that the following conditions .\" are met: .\" 1. Redistributions of source code must retain the above copyright .\" notice, this list of conditions and the following disclaimer. .\" 2. Redistributions in binary form must reproduce the above copyright .\" notice, this list of conditions and the following disclaimer in the .\" documentation and/or other materials provided with the distribution. .\" 3. Neither the name of the University nor the names of its contributors .\" may be used to endorse or promote products derived from this software .\" without specific prior written permission. .\" .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" .\" @(#)unlink.2 8.1 (Berkeley) 6/4/93 .\" $FreeBSD$ .\" -.Dd July 28, 2015 +.Dd December 1, 2017 .Dt UNLINK 2 .Os .Sh NAME .Nm unlink , .Nm unlinkat .Nd remove directory entry .Sh LIBRARY .Lb libc .Sh SYNOPSIS .In unistd.h .Ft int .Fn unlink "const char *path" .Ft int .Fn unlinkat "int fd" "const char *path" "int flag" .Sh DESCRIPTION The .Fn unlink system call removes the link named by .Fa path from its directory and decrements the link count of the file which was referenced by the link. If that decrement reduces the link count of the file to zero, and no process has the file open, then all resources associated with the file are reclaimed. If one or more process have the file open when the last link is removed, the link is removed, but the removal of the file is delayed until all references to it have been closed. The .Fa path argument may not be a directory. .Pp The .Fn unlinkat system call is equivalent to .Fn unlink or .Fn rmdir except in the case where .Fa path specifies a relative path. In this case the directory entry to be removed is determined relative to the directory associated with the file descriptor .Fa fd instead of the current working directory. .Pp The values for .Fa flag are constructed by a bitwise-inclusive OR of flags from the following list, defined in .In fcntl.h : .Bl -tag -width indent .It Dv AT_REMOVEDIR Remove the directory entry specified by .Fa fd and .Fa path as a directory, not a normal file. .El .Pp If .Fn unlinkat is passed the special value .Dv AT_FDCWD in the .Fa fd parameter, the current working directory is used and the behavior is identical to a call to .Fa unlink or .Fa rmdir respectively, depending on whether or not the .Dv AT_REMOVEDIR bit is set in flag. .Sh RETURN VALUES .Rv -std unlink .Sh ERRORS The .Fn unlink succeeds unless: .Bl -tag -width Er .It Bq Er ENOTDIR A component of the path prefix is not a directory. .It Bq Er EISDIR The named file is a directory. .It Bq Er ENAMETOOLONG A component of a pathname exceeded 255 characters, or an entire path name exceeded 1023 characters. .It Bq Er ENOENT The named file does not exist. .It Bq Er EACCES Search permission is denied for a component of the path prefix. .It Bq Er EACCES Write permission is denied on the directory containing the link to be removed. .It Bq Er ELOOP Too many symbolic links were encountered in translating the pathname. .It Bq Er EPERM The named file is a directory. .It Bq Er EPERM The named file has its immutable, undeletable or append-only flag set, see the .Xr chflags 2 manual page for more information. .It Bq Er EPERM The parent directory of the named file has its immutable or append-only flag set. .It Bq Er EPERM The directory containing the file is marked sticky, and neither the containing directory nor the file to be removed are owned by the effective user ID. .It Bq Er EIO An I/O error occurred while deleting the directory entry or deallocating the inode. .It Bq Er EROFS The named file resides on a read-only file system. .It Bq Er EFAULT The .Fa path argument points outside the process's allocated address space. .It Bq Er ENOSPC On file systems supporting copy-on-write or snapshots, there was not enough free space to record metadata for the delete operation of the file. .El .Pp In addition to the errors returned by the .Fn unlink , the .Fn unlinkat may fail if: .Bl -tag -width Er .It Bq Er EBADF The .Fa path argument does not specify an absolute path and the .Fa fd argument is neither .Dv AT_FDCWD nor a valid file descriptor open for searching. .It Bq Er ENOTEMPTY The .Fa flag parameter has the .Dv AT_REMOVEDIR bit set and the .Fa path argument names a directory that is not an empty directory, or there are hard links to the directory other than dot or a single entry in dot-dot. .It Bq Er ENOTDIR The .Fa flag parameter has the .Dv AT_REMOVEDIR bit set and .Fa path does not name a directory. .It Bq Er EINVAL The value of the .Fa flag argument is not valid. .It Bq Er ENOTDIR The .Fa path argument is not an absolute path and .Fa fd is neither .Dv AT_FDCWD nor a file descriptor associated with a directory. .El .Sh SEE ALSO .Xr chflags 2 , .Xr close 2 , .Xr link 2 , .Xr rmdir 2 , .Xr symlink 7 .Sh STANDARDS The .Fn unlinkat system call follows The Open Group Extended API Set 2 specification. .Sh HISTORY The .Fn unlink function appeared in -.At v6 . +.At v1 . The .Fn unlinkat system call appeared in .Fx 8.0 . .Pp The .Fn unlink system call traditionally allows the super-user to unlink directories which can damage the file system integrity. This implementation no longer permits it. Index: head/lib/libc/sys/wait.2 =================================================================== --- head/lib/libc/sys/wait.2 (revision 326434) +++ head/lib/libc/sys/wait.2 (revision 326435) @@ -1,678 +1,678 @@ .\" Copyright (c) 1980, 1991, 1993, 1994 .\" The Regents of the University of California. All rights reserved. .\" .\" Redistribution and use in source and binary forms, with or without .\" modification, are permitted provided that the following conditions .\" are met: .\" 1. Redistributions of source code must retain the above copyright .\" notice, this list of conditions and the following disclaimer. .\" 2. Redistributions in binary form must reproduce the above copyright .\" notice, this list of conditions and the following disclaimer in the .\" documentation and/or other materials provided with the distribution. .\" 3. Neither the name of the University nor the names of its contributors .\" may be used to endorse or promote products derived from this software .\" without specific prior written permission. .\" .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" .\" @(#)wait.2 8.2 (Berkeley) 4/19/94 .\" $FreeBSD$ .\" -.Dd June 17, 2017 +.Dd December 1, 2017 .Dt WAIT 2 .Os .Sh NAME .Nm wait , .Nm waitid , .Nm waitpid , .Nm wait3 , .Nm wait4 , .Nm wait6 .Nd wait for processes to change status .Sh LIBRARY .Lb libc .Sh SYNOPSIS .In sys/types.h .In sys/wait.h .Ft pid_t .Fn wait "int *status" .Ft pid_t .Fn waitpid "pid_t wpid" "int *status" "int options" .In signal.h .Ft int .Fn waitid "idtype_t idtype" "id_t id" "siginfo_t *info" "int options" .In sys/time.h .In sys/resource.h .Ft pid_t .Fn wait3 "int *status" "int options" "struct rusage *rusage" .Ft pid_t .Fn wait4 "pid_t wpid" "int *status" "int options" "struct rusage *rusage" .Ft pid_t .Fn wait6 "idtype_t idtype" "id_t id" "int *status" "int options" "struct __wrusage *wrusage" "siginfo_t *infop" .Sh DESCRIPTION The .Fn wait function suspends execution of its calling thread until .Fa status information is available for a child process or a signal is received. On return from a successful .Fn wait call, the .Fa status area contains information about the process that reported a status change as defined below. .Pp The .Fn wait4 and .Fn wait6 system calls provide a more general interface for programs that need to wait for specific child processes, that need resource utilization statistics accumulated by child processes, or that require options. The other wait functions are implemented using either .Fn wait4 or .Fn wait6 . .Pp The .Fn wait6 function is the most general function in this family and its distinct features are: .Pp All of the desired process statuses to be waited on must be explicitly specified in .Fa options . The .Fn wait , .Fn waitpid , .Fn wait3 , and .Fn wait4 functions all implicitly wait for exited and trapped processes, but the .Fn waitid and .Fn wait6 functions require the corresponding .Dv WEXITED and .Dv WTRAPPED flags to be explicitly specified. This allows waiting for processes which have experienced other status changes without having to also handle the exit status from terminated processes. .Pp The .Fn wait6 function accepts a .Fa wrusage argument which points to a structure defined as: .Bd -literal struct __wrusage { struct rusage wru_self; struct rusage wru_children; }; .Ed .Pp This allows the calling process to collect resource usage statistics from both its own child process as well as from its grand children. When no resource usage statistics are needed this pointer can be .Dv NULL . .Pp The last argument .Fa infop must be either .Dv NULL or a pointer to a .Fa siginfo_t structure. If .Pf non- Dv NULL , the structure is filled with the same data as for a .Dv SIGCHLD signal delivered when the process changed state. .Pp The set of child processes to be queried is specified by the arguments .Fa idtype and .Fa id . The separate .Fa idtype and .Fa id arguments support many other types of identifiers in addition to process IDs and process group IDs. .Bl -bullet -offset indent .It If .Fa idtype is .Dv P_PID , .Fn waitid and .Fn wait6 wait for the child process with a process ID equal to .Dv (pid_t)id . .It If .Fa idtype is .Dv P_PGID , .Fn waitid and .Fn wait6 wait for the child process with a process group ID equal to .Dv (pid_t)id . .It If .Fa idtype is .Dv P_ALL , .Fn waitid and .Fn wait6 wait for any child process and the .Dv id is ignored. .It If .Fa idtype is .Dv P_PID or .Dv P_PGID and the .Dv id is zero, .Fn waitid and .Fn wait6 wait for any child process in the same process group as the caller. .El .Pp Non-standard identifier types supported by this implementation of .Fn waitid and .Fn wait6 are: .Bl -tag -width P_JAILID .It Dv P_UID Wait for processes whose effective user ID is equal to .Dv (uid_t) Fa id . .It Dv P_GID Wait for processes whose effective group ID is equal to .Dv (gid_t) Fa id . .It Dv P_SID Wait for processes whose session ID is equal to .Fa id . .\" This is just how sessions work, not sure this needs to be documented here If the child process started its own session, its session ID will be the same as its process ID. Otherwise the session ID of a child process will match the caller's session ID. .It Dv P_JAILID Waits for processes within a jail whose jail identifier is equal to .Fa id . .El .Pp For the .Fn waitpid and .Fn wait4 functions, the single .Fa wpid argument specifies the set of child processes for which to wait. .Bl -bullet -offset indent .It If .Fa wpid is -1, the call waits for any child process. .It If .Fa wpid is 0, the call waits for any child process in the process group of the caller. .It If .Fa wpid is greater than zero, the call waits for the process with process ID .Fa wpid . .It If .Fa wpid is less than -1, the call waits for any process whose process group ID equals the absolute value of .Fa wpid . .El .Pp The .Fa status argument is defined below. .Pp The .Fa options argument contains the bitwise OR of any of the following options. .Bl -tag -width WCONTINUED .It Dv WCONTINUED Report the status of selected processes that have continued from a job control stop by receiving a .Dv SIGCONT signal. .It Dv WNOHANG Do not block when there are no processes wishing to report status. .It Dv WUNTRACED Report the status of selected processes which are stopped due to a .Dv SIGTTIN , SIGTTOU , SIGTSTP , or .Dv SIGSTOP signal. .It Dv WSTOPPED An alias for .Dv WUNTRACED . .It Dv WTRAPPED Report the status of selected processes which are being traced via .Xr ptrace 2 and have trapped or reached a breakpoint. This flag is implicitly set for the functions .Fn wait , .Fn waitpid , .Fn wait3 , and .Fn wait4 . .br For the .Fn waitid and .Fn wait6 functions, the flag has to be explicitly included in .Fa options if status reports from trapped processes are expected. .It Dv WEXITED Report the status of selected processes which have terminated. This flag is implicitly set for the functions .Fn wait , .Fn waitpid , .Fn wait3 , and .Fn wait4 . .br For the .Fn waitid and .Fn wait6 functions, the flag has to be explicitly included in .Fa options if status reports from terminated processes are expected. .It Dv WNOWAIT Keep the process whose status is returned in a waitable state. The process may be waited for again after this call completes. .El .sp For the .Fn waitid and .Fn wait6 functions, at least one of the options .Dv WEXITED , .Dv WUNTRACED , .Dv WSTOPPED , .Dv WTRAPPED , or .Dv WCONTINUED must be specified. Otherwise there will be no events for the call to report. To avoid hanging indefinitely in such a case these functions return -1 with .Dv errno set to .Dv EINVAL . .Pp If .Fa rusage is non-NULL, a summary of the resources used by the terminated process and all its children is returned. .Pp If .Fa wrusage is non-NULL, separate summaries are returned for the resources used by the terminated process and the resources used by all its children. .Pp If .Fa infop is non-NULL, a .Dv siginfo_t structure is returned with the .Fa si_signo field set to .Dv SIGCHLD and the .Fa si_pid field set to the process ID of the process reporting status. For the exited process, the .Fa si_status field of the .Dv siginfo_t structure contains the full 32 bit exit status passed to .Xr _exit 2 ; the .Fa status argument of other calls only returns 8 lowest bits of the exit status. .Pp When the .Dv WNOHANG option is specified and no processes wish to report status, .Fn waitid sets the .Fa si_signo and .Fa si_pid fields in .Fa infop to zero. Checking these fields is the only way to know if a status change was reported. .Pp When the .Dv WNOHANG option is specified and no processes wish to report status, .Fn wait4 and .Fn wait6 return a process id of 0. .Pp The .Fn wait call is the same as .Fn wait4 with a .Fa wpid value of -1, with an .Fa options value of zero, and a .Fa rusage value of .Dv NULL . The .Fn waitpid function is identical to .Fn wait4 with an .Fa rusage value of .Dv NULL . The older .Fn wait3 call is the same as .Fn wait4 with a .Fa wpid value of -1. The .Fn wait4 function is identical to .Fn wait6 with the flags .Dv WEXITED and .Dv WTRAPPED set in .Fa options and .Fa infop set to .Dv NULL . .Pp The following macros may be used to test the current status of the process. Exactly one of the following four macros will evaluate to a non-zero .Pq true value: .Bl -tag -width Ds .It Fn WIFCONTINUED status True if the process has not terminated, and has continued after a job control stop. This macro can be true only if the wait call specified the .Dv WCONTINUED option. .It Fn WIFEXITED status True if the process terminated normally by a call to .Xr _exit 2 or .Xr exit 3 . .It Fn WIFSIGNALED status True if the process terminated due to receipt of a signal. .It Fn WIFSTOPPED status True if the process has not terminated, but has stopped and can be restarted. This macro can be true only if the wait call specified the .Dv WUNTRACED option or if the child process is being traced (see .Xr ptrace 2 ) . .El .Pp Depending on the values of those macros, the following macros produce the remaining status information about the child process: .Bl -tag -width Ds .It Fn WEXITSTATUS status If .Fn WIFEXITED status is true, evaluates to the low-order 8 bits of the argument passed to .Xr _exit 2 or .Xr exit 3 by the child. .It Fn WTERMSIG status If .Fn WIFSIGNALED status is true, evaluates to the number of the signal that caused the termination of the process. .It Fn WCOREDUMP status If .Fn WIFSIGNALED status is true, evaluates as true if the termination of the process was accompanied by the creation of a core file containing an image of the process when the signal was received. .It Fn WSTOPSIG status If .Fn WIFSTOPPED status is true, evaluates to the number of the signal that caused the process to stop. .El .Sh NOTES See .Xr sigaction 2 for a list of termination signals. A status of 0 indicates normal termination. .Pp If a parent process terminates without waiting for all of its child processes to terminate, the remaining child processes are assigned the parent process 1 ID (the init process ID). .Pp If a signal is caught while any of the .Fn wait calls are pending, the call may be interrupted or restarted when the signal-catching routine returns, depending on the options in effect for the signal; see discussion of .Dv SA_RESTART in .Xr sigaction 2 . .Pp The implementation queues one .Dv SIGCHLD signal for each child process whose status has changed; if .Fn wait returns because the status of a child process is available, the pending SIGCHLD signal associated with the process ID of the child process will be discarded. Any other pending .Dv SIGCHLD signals remain pending. .Pp If .Dv SIGCHLD is blocked and .Fn wait returns because the status of a child process is available, the pending .Dv SIGCHLD signal will be cleared unless another status of the child process is available. .Sh RETURN VALUES If .Fn wait returns due to a stopped, continued, or terminated child process, the process ID of the child is returned to the calling process. Otherwise, a value of \-1 is returned and .Va errno is set to indicate the error. .Pp If .Fn wait6 , .Fn wait4 , .Fn wait3 , or .Fn waitpid returns due to a stopped, continued, or terminated child process, the process ID of the child is returned to the calling process. If there are no children not previously awaited, -1 is returned with .Va errno set to .Er ECHILD . Otherwise, if .Dv WNOHANG is specified and there are no stopped, continued or exited children, 0 is returned. If an error is detected or a caught signal aborts the call, a value of -1 is returned and .Va errno is set to indicate the error. .Pp If .Fn waitid returns because one or more processes have a state change to report, 0 is returned. If an error is detected, a value of -1 is returned and .Va errno is set to indicate the error. If .Dv WNOHANG is specified and there are no stopped, continued or exited children, 0 is returned. The .Fa si_signo and .Fa si_pid fields of .Fa infop must be checked against zero to determine if a process reported status. .Pp .Fn wait called with -1 to wait for any child process will ignore a child that is referenced by a process descriptor (see .Xr pdfork 2 ) . Specific processes can still be waited on by specifying the process ID. .Sh ERRORS The .Fn wait function will fail and return immediately if: .Bl -tag -width Er .It Bq Er ECHILD The calling process has no existing unwaited-for child processes. .It Bq Er ECHILD No status from the terminated child process is available because the calling process has asked the system to discard such status by ignoring the signal .Dv SIGCHLD or setting the flag .Dv SA_NOCLDWAIT for that signal. .It Bq Er EFAULT The .Fa status or .Fa rusage argument points to an illegal address. (May not be detected before exit of a child process.) .It Bq Er EINTR The call was interrupted by a caught signal, or the signal did not have the .Dv SA_RESTART flag set. .It Bq Er EINVAL An invalid value was specified for .Fa options , or .Fa idtype and .Fa id do not specify a valid set of processes. .El .Sh SEE ALSO .Xr _exit 2 , .Xr ptrace 2 , .Xr sigaction 2 , .Xr exit 3 , .Xr siginfo 3 .Sh STANDARDS The .Fn wait , .Fn waitpid , and .Fn waitid functions are defined by POSIX; .Fn wait6 , .Fn wait4 , and .Fn wait3 are not specified by POSIX. The .Fn WCOREDUMP macro is an extension to the POSIX interface. .Pp The ability to use the .Dv WNOWAIT flag with .Fn waitpid is an extension; .Tn POSIX only permits this flag with .Fn waitid . .Sh HISTORY The .Fn wait function appeared in -.At v6 . +.At v1 . Index: head/lib/libc/sys/write.2 =================================================================== --- head/lib/libc/sys/write.2 (revision 326434) +++ head/lib/libc/sys/write.2 (revision 326435) @@ -1,290 +1,290 @@ .\" Copyright (c) 1980, 1991, 1993 .\" The Regents of the University of California. All rights reserved. .\" .\" Redistribution and use in source and binary forms, with or without .\" modification, are permitted provided that the following conditions .\" are met: .\" 1. Redistributions of source code must retain the above copyright .\" notice, this list of conditions and the following disclaimer. .\" 2. Redistributions in binary form must reproduce the above copyright .\" notice, this list of conditions and the following disclaimer in the .\" documentation and/or other materials provided with the distribution. .\" 3. Neither the name of the University nor the names of its contributors .\" may be used to endorse or promote products derived from this software .\" without specific prior written permission. .\" .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" .\" @(#)write.2 8.5 (Berkeley) 4/2/94 .\" $FreeBSD$ .\" -.Dd October 16, 2017 +.Dd December 1, 2017 .Dt WRITE 2 .Os .Sh NAME .Nm write , .Nm writev , .Nm pwrite , .Nm pwritev .Nd write output .Sh LIBRARY .Lb libc .Sh SYNOPSIS .In unistd.h .Ft ssize_t .Fn write "int fd" "const void *buf" "size_t nbytes" .Ft ssize_t .Fn pwrite "int fd" "const void *buf" "size_t nbytes" "off_t offset" .In sys/uio.h .Ft ssize_t .Fn writev "int fd" "const struct iovec *iov" "int iovcnt" .Ft ssize_t .Fn pwritev "int fd" "const struct iovec *iov" "int iovcnt" "off_t offset" .Sh DESCRIPTION The .Fn write system call attempts to write .Fa nbytes of data to the object referenced by the descriptor .Fa fd from the buffer pointed to by .Fa buf . The .Fn writev system call performs the same action, but gathers the output data from the .Fa iovcnt buffers specified by the members of the .Fa iov array: iov[0], iov[1], ..., iov[iovcnt\|-\|1]. The .Fn pwrite and .Fn pwritev system calls perform the same functions, but write to the specified position in the file without modifying the file pointer. .Pp For .Fn writev and .Fn pwritev , the .Fa iovec structure is defined as: .Pp .Bd -literal -offset indent -compact struct iovec { void *iov_base; /* Base address. */ size_t iov_len; /* Length. */ }; .Ed .Pp Each .Fa iovec entry specifies the base address and length of an area in memory from which data should be written. The .Fn writev system call will always write a complete area before proceeding to the next. .Pp On objects capable of seeking, the .Fn write starts at a position given by the pointer associated with .Fa fd , see .Xr lseek 2 . Upon return from .Fn write , the pointer is incremented by the number of bytes which were written. .Pp Objects that are not capable of seeking always write from the current position. The value of the pointer associated with such an object is undefined. .Pp If the real user is not the super-user, then .Fn write clears the set-user-id bit on a file. This prevents penetration of system security by a user who .Dq captures a writable set-user-id file owned by the super-user. .Pp When using non-blocking I/O on objects such as sockets that are subject to flow control, .Fn write and .Fn writev may write fewer bytes than requested; the return value must be noted, and the remainder of the operation should be retried when possible. .Sh RETURN VALUES Upon successful completion the number of bytes which were written is returned. Otherwise a -1 is returned and the global variable .Va errno is set to indicate the error. .Sh ERRORS The .Fn write , .Fn writev , .Fn pwrite and .Fn pwritev system calls will fail and the file pointer will remain unchanged if: .Bl -tag -width Er .It Bq Er EBADF The .Fa fd argument is not a valid descriptor open for writing. .It Bq Er EPIPE An attempt is made to write to a pipe that is not open for reading by any process. .It Bq Er EPIPE An attempt is made to write to a socket of type .Dv SOCK_STREAM that is not connected to a peer socket. .It Bq Er EFBIG An attempt was made to write a file that exceeds the process's file size limit or the maximum file size. .It Bq Er EFAULT Part of .Fa iov or data to be written to the file points outside the process's allocated address space. .It Bq Er EINVAL The pointer associated with .Fa fd was negative. .It Bq Er ENOSPC There is no free space remaining on the file system containing the file. .It Bq Er EDQUOT The user's quota of disk blocks on the file system containing the file has been exhausted. .It Bq Er EIO An I/O error occurred while reading from or writing to the file system. .It Bq Er EINTR A signal interrupted the write before it could be completed. .It Bq Er EAGAIN The file was marked for non-blocking I/O, and no data could be written immediately. .It Bq Er EROFS An attempt was made to write over a disk label area at the beginning of a slice. Use .Xr disklabel 8 .Fl W to enable writing on the disk label area. .It Bq Er EINVAL The value .Fa nbytes is greater than .Dv SSIZE_MAX (or greater than .Dv INT_MAX , if the sysctl .Va debug.iosize_max_clamp is non-zero). .El .Pp In addition, .Fn writev and .Fn pwritev may return one of the following errors: .Bl -tag -width Er .It Bq Er EDESTADDRREQ The destination is no longer available when writing to a .Ux domain datagram socket on which .Xr connect 2 had been used to set a destination address. .It Bq Er EINVAL The .Fa iovcnt argument was less than or equal to 0, or greater than .Dv IOV_MAX . .It Bq Er EINVAL One of the .Fa iov_len values in the .Fa iov array was negative. .It Bq Er EINVAL The sum of the .Fa iov_len values in the .Fa iov array overflowed a 32-bit integer. .It Bq Er ENOBUFS The mbuf pool has been completely exhausted when writing to a socket. .El .Pp The .Fn pwrite and .Fn pwritev system calls may also return the following errors: .Bl -tag -width Er .It Bq Er EINVAL The .Fa offset value was negative. .It Bq Er ESPIPE The file descriptor is associated with a pipe, socket, or FIFO. .El .Sh SEE ALSO .Xr fcntl 2 , .Xr lseek 2 , .Xr open 2 , .Xr pipe 2 , .Xr select 2 .Sh STANDARDS The .Fn write system call is expected to conform to .St -p1003.1-90 . The .Fn writev and .Fn pwrite system calls are expected to conform to .St -xpg4.2 . .Sh HISTORY The .Fn pwritev system call appeared in .Fx 6.0 . The .Fn pwrite function appeared in .At V.4 . The .Fn writev system call appeared in .Bx 4.2 . The .Fn write function appeared in -.At v6 . +.At v1 .