diff --git a/share/man/man9/VOP_ACCESS.9 b/share/man/man9/VOP_ACCESS.9 index 6a53d358bf40..05744c8812ba 100644 --- a/share/man/man9/VOP_ACCESS.9 +++ b/share/man/man9/VOP_ACCESS.9 @@ -1,146 +1,146 @@ .\" -*- nroff -*- .\" -*- nroff -*- .\" .\" Copyright (c) 1996 Doug Rabson .\" .\" All rights reserved. .\" .\" This program is free software. .\" .\" 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. .\" .\" THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``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 DEVELOPERS 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. .\" -.\" $Id$ +.\" $Id: VOP_ACCESS.9,v 1.1 1997/03/03 18:00:01 dfr Exp $ .\" .Dd July 24, 1996 .Os .Dt VOP_ACCESS 9 .Sh NAME .Nm VOP_ACCESS -.Nd check access permissions of a file or unix domain socket +.Nd check access permissions of a file or Unix domain socket .Sh SYNOPSIS .Fd #include .Ft int .Fn VOP_ACCESS "struct vnode *vp" "int mode" "struct ucred *cred" "struct proc *p" .Sh DESCRIPTION This entry point checks the access permissions of the file against the given credentials. .Pp Its arguments are: .Bl -tag -width mode .It Ar vp the vnode of the file to check .It Ar mode the type of access required .It Ar cred the user credentials to check .It Ar p the process which is checking .El .Pp The .Fa mode is a mask which can contain .Dv VREAD , .Dv VWRITE or .Dv VEXEC. .Sh LOCKS The vnode should be locked on entry. .Sh RETURN VALUES -If the file is accessable in the specified way, then zero is returned, +If the file is accessible in the specified way, then zero is returned, otherwise an appropriate error code is returned. .Sh PSEUDOCODE .Bd -literal int vop_access(struct vnode *vp, int mode, struct ucred *cred, struct proc *p) { int error; /* * Disallow write attempts on read-only file systems; * unless the file is a socket, fifo, or a block or * character device resident on the file system. */ if (mode & VWRITE) { switch (vp->v_type) { case VDIR: case VLNK: case VREG: if (vp->v_mount->mnt_flag & MNT_RDONLY) return EROFS; break; } } /* If immutable bit set, nobody gets to write it. */ if ((mode & VWRITE) && vp has immutable bit set) return EPERM; /* Otherwise, user id 0 always gets access. */ if (cred->cr_uid == 0) return 0; mask = 0; /* Otherwise, check the owner. */ if (cred->cr_uid == owner of vp) { if (mode & VEXEC) mask |= S_IXUSR; if (mode & VREAD) mask |= S_IRUSR; if (mode & VWRITE) mask |= S_IWUSR; return (((mode of vp) & mask) == mask ? 0 : EACCES); } /* Otherwise, check the groups. */ for (i = 0, gp = cred->cr_groups; i < cred->cr_ngroups; i++, gp++) if (group of vp == *gp) { if (mode & VEXEC) mask |= S_IXGRP; if (mode & VREAD) mask |= S_IRGRP; if (mode & VWRITE) mask |= S_IWGRP; return (((mode of vp) & mask) == mask ? 0 : EACCES); } /* Otherwise, check everyone else. */ if (mode & VEXEC) mask |= S_IXOTH; if (mode & VREAD) mask |= S_IROTH; if (mode & VWRITE) mask |= S_IWOTH; return (((mode of vp) & mask) == mask ? 0 : EACCES); } .Ed .Sh ERRORS .Bl -tag -width EACCESS .It Bq Er EPERM An attempt was made to change an immutable file .It Bq Er EACCES Permission denied .El .Sh SEE ALSO .Xr vnode 9 .Sh AUTHORS This man page was written by Doug Rabson. diff --git a/share/man/man9/VOP_IOCTL.9 b/share/man/man9/VOP_IOCTL.9 index 352179c4e269..a8845e9f80e7 100644 --- a/share/man/man9/VOP_IOCTL.9 +++ b/share/man/man9/VOP_IOCTL.9 @@ -1,78 +1,78 @@ .\" -*- nroff -*- .\" .\" Copyright (c) 1996 Doug Rabson .\" .\" All rights reserved. .\" .\" This program is free software. .\" .\" 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. .\" .\" THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``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 DEVELOPERS 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. .\" -.\" $Id$ +.\" $Id: VOP_IOCTL.9,v 1.1 1997/03/03 18:00:21 dfr Exp $ .\" .Dd July 24, 1996 .Os .Dt VOP_IOCTL 9 .Sh NAME .Nm VOP_IOCTL .Nd device specific control .Sh SYNOPSIS .Fd #include .Ft int .Fn VOP_IOCTL "struct vnode *vp" "int command" "caddr_t data" "int fflag" "struct ucred *cred" "struct proc *p" .Sh DESCRIPTION -Manipulate a file in device dependant ways. +Manipulate a file in device dependent ways. .Pp Its arguments are: .Bl -tag -width command .It Ar vp the vnode of the file (normally representing a device) .It Ar command the device specific operation to perform .It Ar cnp extra data for the specified operation .It Ar fflag some flags ??? .It Ar cred the caller's credentials .It Ar p the calling process .El .Pp Most filesystems do not implement this entry point. .Sh LOCKS The file should not be locked on entry. .Sh RETURN VALUES If successful, zero is returned, otherwise an appropriate error code. .Sh PSEUDOCODE .Bd -literal int vop_ioctl(struct vnode *vp, int command, caddr_t data, int fflag, struct ucred *cred, struct proc *p) { return EOPNOTSUPP; } .Ed .Sh SEE ALSO .Xr vnode 9 .Sh AUTHORS This man page was written by Doug Rabson. diff --git a/share/man/man9/VOP_LOCK.9 b/share/man/man9/VOP_LOCK.9 index 03cf51e35fc9..4ef44ac4181c 100644 --- a/share/man/man9/VOP_LOCK.9 +++ b/share/man/man9/VOP_LOCK.9 @@ -1,129 +1,129 @@ .\" -*- nroff -*- .\" .\" Copyright (c) 1996 Doug Rabson .\" .\" All rights reserved. .\" .\" This program is free software. .\" .\" 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. .\" .\" THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``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 DEVELOPERS 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. .\" -.\" $Id$ +.\" $Id: VOP_LOCK.9,v 1.1 1997/03/03 18:00:25 dfr Exp $ .\" .Dd July 24, 1996 .Os .Dt VOP_LOCK 9 .Sh NAME .Nm VOP_LOCK , .Nm VOP_UNLOCK , .Nm VOP_ISLOCKED .Nd serialize access to a vnode .Sh SYNOPSIS .Fd #include .Ft int .Fn VOP_LOCK "struct vnode *vp" .Ft int .Fn VOP_UNLOCK "struct vnode *vp" .Ft int .Fn VOP_ISLOCKED "struct vnode *vp" .Sh DESCRIPTION .Pp The arguments are: .Bl -tag -width vp .It Ar vp the vnode being locked or unlocked .El .Pp -These calls are used to serialise access to the filesystem, for +These calls are used to serialize access to the filesystem, for instance to prevent two writes to the same file from happening at the same time. .Sh RETURN VALUES Zero is returned on success, otherwise an error is returned. .Sh PSEUDOCODE .Bd -literal struct vopnode { int von_flag; /* * Other filesystem specific data. */ ...; }; #define VON_LOCKED 1 #define VON_WANTED 2 #define VTOVON(vp) ((struct vopnode *) (vp)->v_data) int vop_lock(struct vnode *vp) { struct vopnode* vop; start: while (vp->v_flag & VXLOCK) { vp->v_flag |= VXWANT; tsleep((caddr_t)vp, PINOD, "voplk1", 0); } if (vp->v_tag == VT_NON) return ENOENT; vop = VTOVON(vp); if (vop->von_flag & VON_LOCKED) { vop->von_flag |= VON_WANTED; tsleep((caddr_t) vop, PINOD, "voplk2", 0); goto start; } vop->von_flag |= VON_LOCKED; return 0; } int vop_unlock(struct vnode *vp) { struct vopnode *vop = VTOVON(vp); if ((vop->von_flag & VON_LOCKED) == 0) { panic("vop_unlock not locked"); } vop->von_flag &= ~VON_LOCKED; if (vop->von_flag & VON_WANTED) { vop->von_flag &= ~VON_WANTED; wakeup((caddr_t) vop); } return 0; } int vop_islocked(struct vnode *vp) { struct vopnode *vop = VTOVON(vp); if (vop->von_flag & VON_LOCKED) return 1; else return 0; } .Ed .Sh SEE ALSO .Xr vnode 9 .Sh AUTHORS This man page was written by Doug Rabson. diff --git a/share/man/man9/VOP_LOOKUP.9 b/share/man/man9/VOP_LOOKUP.9 index c878e39022d4..462ba9449916 100644 --- a/share/man/man9/VOP_LOOKUP.9 +++ b/share/man/man9/VOP_LOOKUP.9 @@ -1,447 +1,447 @@ .\" -*- nroff -*- .\" .\" Copyright (c) 1996 Doug Rabson .\" .\" All rights reserved. .\" .\" This program is free software. .\" .\" 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. .\" .\" THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``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 DEVELOPERS 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. .\" -.\" $Id$ +.\" $Id: VOP_LOOKUP.9,v 1.1 1997/03/03 18:00:26 dfr Exp $ .\" .Dd July 24, 1996 .Os FreeBSD .Dt VOP_LOOKUP 9 .Sh NAME .Nm VOP_LOOKUP .Nd lookup a component of a pathname .Sh SYNOPSIS .Fd #include .Fd #include .Ft int .Fn VOP_LOOKUP "struct vnode *dvp" "struct vnode **vpp" "struct componentname *cnp" .Sh DESCRIPTION This VFS entry point looks up a single pathname component in a given directory. .Pp Its arguments are: .Bl -tag -width vpp .It Ar dvp the locked vnode of the directory to search .It Ar vpp the address of a variable where the resulting locked vnode should be stored .It Ar cnp the pathname component to be searched for .El .Pp .Fa Cnp is a pointer to a componentname structure defined as follows: .Bd -literal struct componentname { /* * Arguments to lookup. */ u_long cn_nameiop; /* namei operation */ u_long cn_flags; /* flags to namei */ struct proc *cn_proc; /* process requesting lookup */ struct ucred *cn_cred; /* credentials */ /* * Shared between lookup and commit routines. */ char *cn_pnbuf; /* pathname buffer */ char *cn_nameptr; /* pointer to looked up name */ long cn_namelen; /* length of looked up component */ u_long cn_hash; /* hash value of looked up name */ long cn_consume; /* chars to consume in lookup() */ }; .Ed .Pp Convert a component of a pathname into a pointer to a locked vnode. This is a very central and rather complicated routine. If the file system is not maintained in a strict tree hierarchy, this can result in a deadlock situation. .Pp The .Fa cnp->cn_nameiop argument is .Dv LOOKUP , .Dv CREATE , .Dv RENAME , or .Dv DELETE depending on the intended use of the object. When .Dv CREATE , .Dv RENAME , or .Dv DELETE is specified, information usable in creating, renaming, or deleting a directory entry may be calculated. .Pp Overall outline of VOP_LOOKUP: .Bd -filled -offset indent Check accessibility of directory. Look for name in cache, if found, then return name. Search for name in directory, goto to found or notfound as appropriate. .Ed .Pp notfound: .Bd -filled -offset indent If creating or renaming and at end of pathname, return .Dv EJUSTRETURN , leaving info on available slots else return .Dv ENOENT . .Ed .Pp found: .Bd -filled -offset indent If at end of path and deleting, return information to allow delete. If at end of path and renaming, lock target inode and return info to allow rename. If not at end, add name to cache; if at end and neither creating nor deleting, add name to cache. .Ed .Sh LOCKS The directory, .Fa dvp should be locked on entry. If an error (note: the return value .Dv EJUSTRETURN is not considered an error) is detected, it will be returned locked. Otherwise, it will be unlocked unless both .Dv LOCKPARENT and .Dv ISLASTCN are specified in .Fa cnp->cn_flags . If an entry is found in the directory, it will be returned locked. .Sh RETURN VALUES Zero is returned with .Fa *vpp set to the locked vnode of the file if the component is found. If the component being searched for is ".", then the vnode just has an extra reference added to it with .Xr vref 9 . The caller must take care to release the locks appropriately in this case. .Pp If the component is not found and the operation is .Dv CREATE or .Dv RENAME , the flag .Dv ISLASTCN is specified and the operation would succeed, the special return value .Dv EJUSTRETURN is returned. Otherwise, an appropriate error code is returned. .Sh PSEUDOCODE .Bd -literal int vop_lookup(struct vnode *dvp, struct vnode **vpp, struct componentname *cnp) { int error; int nameiop = cnp->cn_nameiop; int flags = cnp->cn_flags; int lockparent = flags & LOCKPARENT; int islastcn = flags & ISLASTCN; struct vnode *vp = NULL; /* - * Check accessiblity of directory. + * Check accessibility of directory. */ if (dvp->v_type != VDIR) return ENOTDIR; error = VOP_ACCESS(dvp, VEXEC, cred, cnp->cn_proc); if (error) return (error); if (islastcn && (dvp->v_mount->mnt_flag & MNT_RDONLY) && (cnp->cn_nameiop == DELETE || cnp->cn_nameiop == RENAME)) return (EROFS); /* - * Check name cachec for directory/name pair. This returns ENOENT + * Check name cache for directory/name pair. This returns ENOENT * if the name is known not to exist, -1 if the name was found, or * zero if not. */ error = cache_lookup(dvp, vpp, cnp); if (error) { int vpid; if (error = ENOENT) return error; vp = *vpp; if (dvp == vp) { /* lookup on "." */ VREF(vp); error = 0; } else if (flags & ISDOTDOT) { /* * We need to unlock the directory before getting * the locked vnode for ".." to avoid deadlocks. */ VOP_UNLOCK(dvp); error = vget(vp, 1); if (!error) { if (lockparent && islastcn) error = VOP_LOCK(dvp); } } else { error = vget(vp, 1); if (error || !(lockparent && islastcn)) { VOP_UNLOCK(dvp); } } /* * Check that the capability number did not change * while we were waiting for the lock. */ if (!error) { if (vpid == vp->v_id) { /* * dvp is locked if lockparent && islastcn. * vp is locked. */ return (0); } vput(vp); if (dvp != vp && lockparent && islastcn) VOP_UNLOCK(pdp); } /* * Re-lock dvp for the directory search below. */ error = VOP_LOCK(dvp); if (error) { return (error); } *vpp = NULL; } /* * Search dvp for the component cnp->cn_nameptr. */ ...; if (!found) { if ((nameiop == CREATE || nameiop == RENAME) && islastcn && directory dvp has not been removed) { /* * Check for write access on directory. */ /* * Possibly record the position of a slot in the directory * large enough for the new component name. This can be * recorded in the vnode private data for dvp. * Set the SAVENAME flag to hold onto the pathname for use * later in VOP_CREATE or VOP_RENAME. */ cnp->cn_flags |= SAVENAME; if (!lockparent) /* * Note that the extra data recorded above is only * useful if lockparent is specified. */ VOP_UNLOCK(dvp); return EJUSTRETURN; } /* * Consider inserting name into cache. */ if ((cnp->cn_flags & MAKEENTRY) && nameiop != CREATE) cache_enter(dvp, NULL, cnp); return ENOENT; } else { /* * If deleting, and at end of pathname, return parameters * which can be used to remove file. If the wantparent flag * isn't set, we return only the directory, otherwise we go on * and lock the inode, being careful with ".". */ if (nameiop == DELETE && islastcn) { /* * Check for write access on directory. */ error = VOP_ACCESS(dvp, VWRITE, cred, cnp->cn_proc); if (error) return (error); if (found entry is same as dvp) { VREF(dvp); *vpp = dvp; return 0; } error = VFS_VGET(dvp->v_mount, ..., &vp); if (error) return error; if (directory is sticky && cred->cr_uid != 0 && cred->cr_uid != owner of dvp && owner of vp != cred->cr_uid) { vput(vp); return EPERM; } *vpp = vp; if (!lockparent) VOP_UNLOCK(dvp); return 0; } /* * If rewriting (RENAME), return the inode and the * information required to rewrite the present directory * Must get inode of directory entry to verify it's a * regular file, or empty directory. */ if (nameiop == RENAME && wantparent && islastcn) { error = VOP_ACCESS(dvp, VWRITE, cred, cnp->cn_proc); if (error) return (error); /* * Check for "." */ if (found entry is same as dvp) return EISDIR; error = VFS_VGET(dvp->v_mount, ..., &vp); if (error) return error; *vpp = vp; /* * Save the name for use in VOP_RENAME later. */ cnp->cn_flags |= SAVENAME; if (!lockparent) VOP_UNLOCK(dvp); return 0; } /* * Step through the translation in the name. We do not `vput' the * directory because we may need it again if a symbolic link * is relative to the current directory. Instead we save it * unlocked as "pdp". We must get the target inode before unlocking * the directory to insure that the inode will not be removed * before we get it. We prevent deadlock by always fetching * inodes from the root, moving down the directory tree. Thus * when following backward pointers ".." we must unlock the * parent directory before getting the requested directory. * There is a potential race condition here if both the current * and parent directories are removed before the VFS_VGET for the * inode associated with ".." returns. We hope that this occurs * infrequently since we cannot avoid this race condition without * implementing a sophisticated deadlock detection algorithm. * Note also that this simple deadlock detection scheme will not * work if the file system has any hard links other than ".." * that point backwards in the directory structure. */ if (flags & ISDOTDOT) { VOP_UNLOCK(dvp); /* race to get the inode */ error = VFS_VGET(dvp->v_mount, ..., &vp); if (error) { VOP_LOCK(dvp); return (error); } if (lockparent && islastcn) { error = VOP_LOCK(dvp); if (error) { vput(vp); return error; } } *vpp = vp; } else if (found entry is same as dvp) { VREF(dvp); /* we want ourself, ie "." */ *vpp = dvp; } else { error = VFS_VGET(dvp->v_mount, ..., &vp); if (error) return (error); if (!lockparent || !islastcn) VOP_UNLOCK(dvp); *vpp = vp; } /* * Insert name into cache if appropriate. */ if (cnp->cn_flags & MAKEENTRY) cache_enter(dvp, *vpp, cnp); return (0); } } .Ed .Sh ERRORS .Bl -tag -width EJUSTRETURN .It Bq Er ENOTDIR The vnode .Fa dvp does not represent a directory. .It Bq Er ENOENT The component .Fa dvp was not found in this directory. .It Bq Er EACCESS access for the specified operation is denied. .It Bq Er EJUSTRETURN a .Dv CREATE or .Dv RENAME operation would be successful .El .Sh SEE ALSO .Xr VOP_ACCESS 9 , .Xr VOP_CREATE 9 , .Xr VOP_MKNOD 9 , .Xr VOP_MKDIR 9 , .Xr VOP_SYMLINK 9 , .Xr VOP_RENAME 9 , .Xr VOP_ABORTOP 9 .Sh HISTORY The function .Nm appeared in 4.3BSD. .Sh SEE ALSO .Xr vnode 9 .Sh AUTHORS This man page was written by Doug Rabson, with some text from comments in ufs_lookup.c. diff --git a/share/man/man9/VOP_PATHCONF.9 b/share/man/man9/VOP_PATHCONF.9 index 1f7641de93d0..a1810ee178d7 100644 --- a/share/man/man9/VOP_PATHCONF.9 +++ b/share/man/man9/VOP_PATHCONF.9 @@ -1,88 +1,88 @@ .\" -*- nroff -*- .\" .\" Copyright (c) 1996 Doug Rabson .\" .\" All rights reserved. .\" .\" This program is free software. .\" .\" 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. .\" .\" THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``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 DEVELOPERS 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. .\" -.\" $Id$ +.\" $Id: VOP_PATHCONF.9,v 1.1 1997/03/03 18:00:29 dfr Exp $ .\" .Dd July 24, 1996 .Os .Dt VOP_PATHCONF 9 .Sh NAME .Nm VOP_PATHCONF .Nd return POSIX pathconf information .Sh SYNOPSIS .Fd #include .Fd #include .Ft int .Fn VOP_PATHCONF "struct vnode *vp" "int name" "int *retval" .Sh DESCRIPTION .Pp The arguments are: .Bl -tag -width retval .It Ar vp the vnode to get information about .It Ar name the type of information to return .It Ar retval the place to return the information .El .Pp The value of .Fa name specifies what should be returned: .Bl -tag -width _PC_CHOWN_RESTRICTED .It Dv _PC_LINK_MAX The maximum number of links to a file. .It Dv _PC_NAME_MAX The maximum number of bytes in a file name. .It Dv _PC_PATH_MAX The maximum number of bytes in a pathname. .It Dv _PC_PIPE_BUF The maximum number of bytes which will be written atomically to a pipe. .It Dv _PC_CHOWN_RESTRICTED Return 1 if appropriate privileges are required for the .Xr chown 2 system call, otherwise 0. .It Dv _PC_NO_TRUNC Return 1 if file names longer than .Dv KERN_NAME_MAX are truncated. .El .Sh RETURN VALUES If .Fa name -is recognised, +is recognized, .Fa *retval is set to the specified value and zero is returned, otherwise .Dv EINVAL is returned. .Sh SEE ALSO .Xr vnode 9 , .Xr pathconf 2 .Sh AUTHORS This man page was written by Doug Rabson. diff --git a/share/man/man9/VOP_RDWR.9 b/share/man/man9/VOP_RDWR.9 index 61c0635997c0..82d5dde38420 100644 --- a/share/man/man9/VOP_RDWR.9 +++ b/share/man/man9/VOP_RDWR.9 @@ -1,226 +1,226 @@ .\" -*- nroff -*- .\" .\" Copyright (c) 1996 Doug Rabson .\" .\" All rights reserved. .\" .\" This program is free software. .\" .\" 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. .\" .\" THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``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 DEVELOPERS 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. .\" -.\" $Id$ +.\" $Id: VOP_RDWR.9,v 1.1 1997/03/03 18:00:32 dfr Exp $ .\" .Dd July 24, 1996 .Os .Dt VOP_RDWR 9 .Sh NAME .Nm VOP_READ , .Nm VOP_WRITE .Nd read or write a file .Sh SYNOPSIS .Fd #include .Fd #include .Ft int .Fn VOP_READ "struct vnode *vp" "struct uio *uio" "int ioflag" "struct ucred *cred" .Ft int .Fn VOP_WRITE "struct vnode *vp" "struct uio *uio" "int ioflag" "struct ucred *cred" .Sh DESCRIPTION These entry points read or write the contents of a file .Pp The arguments are: .Bl -tag -width ioflag .It Ar vp the vnode of the file .It Ar uio the location of the data to be read or written .It Ar ioflag various flags .It Ar cnp the credentials of the caller .El .Pp The .Fa ioflag argument is a bit mask which can contain the following flags: .Bl -tag -width IO_NODELOCKED .It Dv IO_UNIT do I/O as atomic unit .It Dv IO_APPEND append write to end .It Dv IO_SYNC -do I/O syncronously +do I/O synchronously .It Dv IO_NODELOCKED underlying node already locked .It Dv IO_NDELAY .Dv FNDELAY flag set in file table .It Dv IO_VMIO -data alread in VMIO space +data already in VMIO space .El .Sh LOCKS The file should be locked on entry and will still be locked on exit. .Sh RETURN VALUES Zero is returned on success, otherwise an error code is returned. .Sh PSEUDOCODE .Bd -literal int vop_read(struct vnode *vp, struct uio *uio, int ioflag, struct ucred *cred) { struct buf *bp; off_t bytesinfile; daddr_t lbn, nextlbn; long size, xfersize, blkoffset; int error; size = block size of filesystem; for (error = 0, bp = NULL; uio->uio_resid > 0; bp = NULL) { bytesinfile = size of file - uio->uio_offset; if (bytesinfile <= 0) break; lbn = uio->uio_offset / size; blkoffset = uio->uio_offset - lbn * size; xfersize = size - blkoffset; if (uio->uio_resid < xfersize) xfersize = uio->uio_resid; if (bytesinfile < xfersize) xfersize = bytesinfile; error = bread(vp, lbn, size, NOCRED, &bp); if (error) { brelse(bp); bp = NULL; break; } /* * We should only get non-zero b_resid when an I/O error * has occurred, which should cause us to break above. * However, if the short read did not cause an error, * then we want to ensure that we do not uiomove bad * or uninitialized data. */ size -= bp->b_resid; if (size < xfersize) { if (size == 0) break; xfersize = size; } error = uiomove((char *)bp->b_data + blkoffset, (int)xfersize, uio); if (error) break; bqrelse(bp); } if (bp != NULL) bqrelse(bp); return error; } int vop_write(struct vnode *vp, struct uio *uio, int ioflag, struct ucred *cred) { struct buf *bp; off_t bytesinfile; daddr_t lbn, nextlbn; off_t osize; long size, resid, xfersize, blkoffset; int flags; int error; osize = size of file; size = block size of filesystem; resid = uio->uio_resid; if (ioflag & IO_SYNC) flags = B_SYNC; else flags = 0; for (error = 0; uio->uio_resid > 0;) { lbn = uio->uio_offset / size; blkoffset = uio->uio_offset - lbn * size; xfersize = size - blkoffset; if (uio->uio_resid < xfersize) xfersize = uio->uio_resid; if (uio->uio_offset + xfersize > size of file) vnode_pager_setsize(vp, uio->uio_offset + xfersize); if (size > xfersize) flags |= B_CLRBUF; else flags &= ~B_CLRBUF; error = find_block_in_file(vp, lbn, blkoffset + xfersize, cred, &bp, flags); if (error) break; if (uio->uio_offset + xfersize > size of file) set size of file to uio->uio_offset + xfersize; error = uiomove((char *)bp->b_data + blkoffset, (int) xfersize, uio); /* XXX ufs does not check the error here. Why? */ if (ioflag & IO_VMIO) bp->b_flags |= B_RELBUF; /* ??? */ if (ioflag & IO_SYNC) bwrite(bp); else if (xfersize + blkoffset == size) bawrite(bp); else bdwrite(bp); if (error || xfersize == 0) break; } if (error) { if (ioflag & IO_UNIT) { VOP_TRUNCATE(vp, osize, ioflag & IO_SYNC, cred, uio->uio_procp); uio->uio_offset -= resid - uio->uio_resid; uio->uio_resid = resid; } } else if (resid > uio->uio_resid && (ioflag & IO_SYNC)) { struct timeval tv; error = VOP_UPDATE(vp, &tv, &tv, 1); /* XXX what does this do? */ } return error; } .Ed .Sh ERRORS .Bl -tag -width ENOSPC .It Bq Er ENOSPC The filesystem is full. .El .Sh SEE ALSO .Xr vnode 9 , .Xr uiomove 9 .Sh AUTHORS This man page was written by Doug Rabson. diff --git a/share/man/man9/VOP_RENAME.9 b/share/man/man9/VOP_RENAME.9 index 889c51c21e20..b9df86b41256 100644 --- a/share/man/man9/VOP_RENAME.9 +++ b/share/man/man9/VOP_RENAME.9 @@ -1,306 +1,306 @@ .\" -*- nroff -*- .\" .\" Copyright (c) 1996 Doug Rabson .\" .\" All rights reserved. .\" .\" This program is free software. .\" .\" 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. .\" .\" THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``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 DEVELOPERS 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. .\" -.\" $Id$ +.\" $Id: VOP_RENAME.9,v 1.1 1997/03/03 18:00:38 dfr Exp $ .\" .Dd July 24, 1996 .Os .Dt VOP_RENAME 9 .Sh NAME .Nm VOP_RENAME .Nd rename a file .Sh SYNOPSIS .Fd #include .Ft int .Fn VOP_RENAME "struct vnode *fdvp" "struct vnode *fvp" "struct componentname *fcnp" "struct vnode *tdvp" "struct vnode *tvp" "struct componentname *tcnp" .Sh DESCRIPTION This renames a file and possibly changes its parent directory. If the destination object exists, it will be removed first. .Pp Its arguments are: .Bl -tag -width fdvp .It Ar fdvp the vnode of the old parent directory .It Ar fvp -the vnode of the file to be renameed +the vnode of the file to be renamed .It Ar fcnp pathname information about the file's current name .It Ar tdvp the vnode of the new parent directory .It Ar tvp the vnode of the target file (if it exists) .It Ar tcnp pathname information about the file's new name .El .Sh LOCKS The destination directory and file (if it exists) should be locked on entry. The source directory and file will be released on exit. The destination directory and file (if it exists) will be unlocked and released on exit. .Sh PSEUDOCODE .Bd -literal int vop_rename(struct vnode *fdvp, struct vnode *fvp, struct componentname *fcnp, struct vnode *tdvp, struct vnode *tvp, struct componentname *tcnp) { int doingdirectory = 0; int error = 0; /* * Check for cross-device rename. */ if (fvp->v_mount != tdvp->v_mount) { error = EXDEV; abortit: VOP_ABORTOP(tdvp, tcnp); if (tdvp == tvp) vrele(tdvp); else vput(tdvp); if (tvp) vput(tvp); VOP_ABORTOP(fdvp, fcnp); vrele(fdvp); vrele(fvp); return error; } if (tvp exists and is immutable) { error = EPERM; goto abortit; } /* * Check if just deleting a link name. */ if (fvp == tvp) { if (fvp->v_type == VDIR) { error = EINVAL; goto abortit; } /* * Release destination. */ VOP_ABORTOP(tdvp, tcnp); vput(tdvp); vput(tvp); /* * Delete source. Pretty bizarre stuff. */ vrele(fdvp); vrele(fvp); fcnp->cn_flags &= ~MODMASK; fcnp->cn_flags |= LOCKPARENT | LOCKLEAF; fcnp->cn_nameiop = DELETE; VREF(fdvp); error = relookup(fdvp, &fvp, fcnp); if (error == 0) vrele(fdvp); return VOP_REMOVE(fdvp, fvp, fcnp); } if (fvp is immutable) { error = EPERM; goto abortit; } error = VOP_LOCK(fvp); if (error) goto abortit; if (vp is a directory) { /* * Avoid ".", "..", and aliases of "." for obvious reasons. */ if ((fcnp->cn_namelen == 1 && fcnp->cn_nameptr[0] == '.') || fdvp == fvp || ((fcnp->cn_flags | tcnp->cn_flags) & ISDOTDOT)) { VOP_UNLOCK(fvp); error = EINVAL; goto abortit; } doingdirectory = 1; } vrele(fdvp); /* * Bump link count on fvp while we are moving stuff around. If we * crash before completing the work, the link count may be wrong * but correctable. */ ...; /* * If ".." must be changed (ie the directory gets a new * parent) then the source directory must not be in the - * directory heirarchy above the target, as this would + * directory hierarchy above the target, as this would * orphan everything below the source directory. Also * the user must have write permission in the source so * as to be able to change "..". */ error = VOP_ACCESS(fvp, VWRITE, tcnp->cn_cred, tcnp->cn_proc); VOP_UNLOCK(fvp); if (doingdirectory && fdvp != tdvp) { /* * Check for pathname conflict. */ ...; } /* * If the target doesn't exist, link the target to the source and * unlink the source. Otherwise, rewrite the target directory to * reference the source and remove the original entry. */ if (tvp == NULL) { /* * Account for ".." in new directory. */ if (doingdirectory && fdvp != tdvp) { /* * Increase link count of tdvp. */ ...; } /* * Add name in new directory. */ ...; if (error) { if (doingdirectory && fdvp != tdvp) { /* * Decrease link count if tdvp. */ ...; } goto bad; } vput(tdvp); } else { /* * Target must be empty if a directory and have no links * to it. Also, ensure source and target are compatible * (both directories, or both not directories). */ if (tvp is a directory) { if (tvp is not empty) { error = ENOTEMPTY; goto bad; } if (!doingdirectory) { error = ENOTDIR; goto bad; } /* * Update name cache since directory is going away. */ cache_purge(tdvp); } else if (doingdirectory) { error = ENOTDIR; goto bad; } /* * Change name tcnp in tdvp to point at fvp. */ ...; /* * If the target directory is in same directory as the source * directory, decrement the link count on the parent of the * target directory. This accounts for the fact that a * directory links back to its parent with "..". */ if (doingdirectory && fdvp == tdvp) { /* * Decrement link count of tdvp. */ ...; } vput(tdvp); /* * Decrement the link count of tvp since the directory no * longer points at it. */ ...; if (doingdirectory) { /* * Clean up the old directory tvp. */ ...; } vput(tvp); } /* * Unlink the source. If a directory was moved to a new parent, * update its ".." entry. Gobs of ugly UFS code omitted here. */ ...; bad: if (tvp) vput(tvp); vput(tdvp); out: if (VOP_LOCK(fvp) == 0) { /* * Decrement link count of fvp. */ ...; vput(fvp); } else vrele(fvp); return error; } .Ed .Sh ERRORS .Bl -tag -width ENOTEMPTY .It Bq Er EPERM the file is immutable .It Bq Er EXDEV cross device move .It Bq Er EINVAL illegal directory rename .It Bq Er ENOTDIR attempt to rename a directory to a file or vice versa .It Bq Er ENOTEMPTY attempt to remove a directory which is not empty .El .Sh SEE ALSO .Xr vnode 9 .Sh AUTHORS This man page was written by Doug Rabson.