From 95acdafa9c38ea581bf7c258da9389d993543f29 Mon Sep 17 00:00:00 2001 From: Antonio Huete Jimenez Date: Sat, 15 Nov 2014 18:33:28 +0100 Subject: [PATCH] manpages: VFS Compat API manpage update. - Reflect a bit better what's on the current codebase with regards to the old VFS API, which is still in use for many filesystems. - Pseudocode present on the old API manpages has been removed. In-discussion with: swildner --- Makefile_upgrade.inc | 12 + share/man/man9/Makefile | 24 +- share/man/man9/VOP_INACTIVE.9 | 44 +- share/man/man9/VOP_LEASE.9 | 56 --- share/man/man9/VOP_LOCK.9 | 167 ------- share/man/man9/VOP_LOOKUP.9 | 447 ------------------ .../man9/{VOP_CREATE.9 => VOP_OLD_CREATE.9} | 108 +---- share/man/man9/{VOP_LINK.9 => VOP_OLD_LINK.9} | 62 +-- share/man/man9/VOP_OLD_LOOKUP.9 | 189 ++++++++ .../man9/{VOP_REMOVE.9 => VOP_OLD_REMOVE.9} | 45 +- .../man9/{VOP_STRATEGY.9 => VOP_OLD_RENAME.9} | 64 ++- share/man/man9/VOP_RENAME.9 | 311 ------------ 12 files changed, 284 insertions(+), 1245 deletions(-) delete mode 100644 share/man/man9/VOP_LEASE.9 delete mode 100644 share/man/man9/VOP_LOCK.9 delete mode 100644 share/man/man9/VOP_LOOKUP.9 rename share/man/man9/{VOP_CREATE.9 => VOP_OLD_CREATE.9} (57%) rename share/man/man9/{VOP_LINK.9 => VOP_OLD_LINK.9} (71%) create mode 100644 share/man/man9/VOP_OLD_LOOKUP.9 rename share/man/man9/{VOP_REMOVE.9 => VOP_OLD_REMOVE.9} (75%) rename share/man/man9/{VOP_STRATEGY.9 => VOP_OLD_RENAME.9} (52%) delete mode 100644 share/man/man9/VOP_RENAME.9 diff --git a/Makefile_upgrade.inc b/Makefile_upgrade.inc index 01320f1f39..5eb0abdb4e 100644 --- a/Makefile_upgrade.inc +++ b/Makefile_upgrade.inc @@ -2714,6 +2714,18 @@ TO_REMOVE+=/usr/share/man/man5/usbd.conf.5.gz TO_REMOVE+=/usr/share/man/man8/usbd.8.gz TO_REMOVE+=/usr/share/man/man8/usbdevs.8.gz TO_REMOVE+=/usr/include/sys/reaper.h +TO_REMOVE+=/usr/share/man/man9/VOP_CREATE.9.gz +TO_REMOVE+=/usr/share/man/man9/VOP_MKDIR.9.gz +TO_REMOVE+=/usr/share/man/man9/VOP_MKNOD.9.gz +TO_REMOVE+=/usr/share/man/man9/VOP_SYMLINK.9.gz +TO_REMOVE+=/usr/share/man/man9/VOP_LEASE.9.gz +TO_REMOVE+=/usr/share/man/man9/VOP_LINK.9.gz +TO_REMOVE+=/usr/share/man/man9/VOP_LOCK.9.gz +TO_REMOVE+=/usr/share/man/man9/VOP_LOOKUP.9.gz +TO_REMOVE+=/usr/share/man/man9/VOP_REMOVE.9.gz +TO_REMOVE+=/usr/share/man/man9/VOP_RMDIR.9.gz +TO_REMOVE+=/usr/share/man/man9/VOP_RENAME.9.gz +TO_REMOVE+=/usr/share/man/man9/VOP_STRATEGY.9.gz .if ${MACHINE_ARCH} == "x86_64" TO_REMOVE+=/usr/sbin/stlstats diff --git a/share/man/man9/Makefile b/share/man/man9/Makefile index e76a0a8503..6c75206573 100644 --- a/share/man/man9/Makefile +++ b/share/man/man9/Makefile @@ -196,18 +196,18 @@ MAN= accept_filter.9 \ VOP_ACLCHECK.9 \ VOP_ADVLOCK.9 \ VOP_ATTRIB.9 \ - VOP_CREATE.9 \ VOP_FSYNC.9 \ VOP_GETACL.9 \ VOP_GETEXTATTR.9 \ VOP_GETPAGES.9 \ VOP_INACTIVE.9 \ VOP_IOCTL.9 \ - VOP_LEASE.9 \ - VOP_LINK.9 \ - VOP_LOCK.9 \ - VOP_LOOKUP.9 \ VOP_MMAP.9 \ + VOP_OLD_CREATE.9 \ + VOP_OLD_REMOVE.9 \ + VOP_OLD_RENAME.9 \ + VOP_OLD_LINK.9 \ + VOP_OLD_LOOKUP.9 \ VOP_OPENCLOSE.9 \ VOP_PATHCONF.9 \ VOP_PRINT.9 \ @@ -215,11 +215,8 @@ MAN= accept_filter.9 \ VOP_READDIR.9 \ VOP_READLINK.9 \ VOP_REALLOCBLKS.9 \ - VOP_REMOVE.9 \ - VOP_RENAME.9 \ VOP_SETACL.9 \ VOP_SETEXTATTR.9 \ - VOP_STRATEGY.9 \ vput.9 \ vref.9 \ vrele.9 \ @@ -1021,19 +1018,16 @@ MLINKS+=vcount.9 count_dev.9 MLINKS+=vhold.9 vdrop.9 MLINKS+=VOP_ATTRIB.9 VOP_GETATTR.9 \ VOP_ATTRIB.9 VOP_SETATTR.9 -MLINKS+=VOP_CREATE.9 VOP_MKDIR.9 \ - VOP_CREATE.9 VOP_MKNOD.9 \ - VOP_CREATE.9 VOP_SYMLINK.9 MLINKS+=VOP_GETPAGES.9 VOP_PUTPAGES.9 MLINKS+=VOP_INACTIVE.9 VOP_RECLAIM.9 -MLINKS+=VOP_LOCK.9 vn_lock.9 \ - VOP_LOCK.9 VOP_ISLOCKED.9 \ - VOP_LOCK.9 VOP_UNLOCK.9 +MLINKS+=VOP_OLD_CREATE.9 VOP_OLD_MKDIR.9 \ + VOP_OLD_CREATE.9 VOP_OLD_MKNOD.9 \ + VOP_OLD_CREATE.9 VOP_OLD_SYMLINK.9 +MLINKS+=VOP_OLD_REMOVE.9 VOP_OLD_RMDIR.9 MLINKS+=VOP_OPENCLOSE.9 VOP_CLOSE.9 \ VOP_OPENCLOSE.9 VOP_OPEN.9 MLINKS+=VOP_RDWR.9 VOP_READ.9 \ VOP_RDWR.9 VOP_WRITE.9 -MLINKS+=VOP_REMOVE.9 VOP_RMDIR.9 MLINKS+=vref.9 VREF.9 MLINKS+=vslock.9 vsunlock.9 MLINKS+=wdog.9 wdog_register.9 \ diff --git a/share/man/man9/VOP_INACTIVE.9 b/share/man/man9/VOP_INACTIVE.9 index cee6e97051..954596958b 100644 --- a/share/man/man9/VOP_INACTIVE.9 +++ b/share/man/man9/VOP_INACTIVE.9 @@ -26,7 +26,7 @@ .\" .\" $FreeBSD: src/share/man/man9/VOP_INACTIVE.9,v 1.5.2.3 2001/12/17 11:30:18 ru Exp $ .\" -.Dd July 24, 1996 +.Dd November 15, 2014 .Dt VOP_INACTIVE 9 .Os .Sh NAME @@ -37,9 +37,9 @@ .In sys/param.h .In sys/vnode.h .Ft int -.Fn VOP_INACTIVE "struct vnode *vp" "struct proc *p" +.Fn VOP_INACTIVE "struct vnode *vp" .Ft int -.Fn VOP_RECLAIM "struct vnode *vp" "struct proc *p" +.Fn VOP_RECLAIM "struct vnode *vp" .Sh DESCRIPTION The arguments are: .Bl -tag -width 2n @@ -56,44 +56,6 @@ It can be used to reclaim space for 'open but deleted' files. is called when a vnode is being reused for a different filesystem. Any filesystem specific resources associated with the vnode should be freed. -.Sh LOCKS -For VOP_INACTIVE, the vp will be locked on entry. Your VOP_INACTIVE code -must unlock the vp prior to returning. -.Pp -For VOP_RECLAIM, the vp will not be locked on entry and should be left -unlocked on return. -.Sh PSEUDOCODE -.Bd -literal -int -vop_inactive(struct vnode *vp) -{ - if (link count of vp == 0) { - /* - * Reclaim space in filesystem for vp. - */ - ...; - } - VOP_UNLOCK(vp, 0, p); - - return 0; -} - -int -vop_reclaim(struct vnode *vp) -{ - /* - * Clean out the name cache. - */ - cache_purge(vp); - - /* - * Free filesystem-related data. - */ - ...; - - return 0; -} -.Ed .Sh SEE ALSO .Xr vnode 9 .Sh AUTHORS diff --git a/share/man/man9/VOP_LEASE.9 b/share/man/man9/VOP_LEASE.9 deleted file mode 100644 index b041d296ea..0000000000 --- a/share/man/man9/VOP_LEASE.9 +++ /dev/null @@ -1,56 +0,0 @@ -.\" 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. -.\" -.\" $FreeBSD: src/share/man/man9/VOP_LEASE.9,v 1.2.2.5 2001/12/17 11:30:18 ru Exp $ -.\" -.Dd September 24, 1999 -.Dt VOP_LEASE 9 -.Os -.Sh NAME -.Nm VOP_LEASE -.Nd "validate a vnode for a particular set of credentials and operation type" -.Sh SYNOPSIS -.In sys/param.h -.In sys/mount.h -.Ft int -.Fn VOP_LEASE "struct vnode *vp" "struct proc *p" "struct ucred *cred" "int type" -.Sh DESCRIPTION -This entry point is currently not implemented. I believe the idea is to -validate a vnode for a particular set of user credentials and operation type. -The two operation types supported are LEASE_READ and LEASE_WRITE. The -function currently always returns 0. -.Sh LOCKS -The vnode must be exclusively locked on entry, and should remain exclusively -locked on return. -.Sh RETURN VALUES -If successful, zero is returned. Otherwise, well... zero is returned too. -.\".Sh ERRORS -.Sh SEE ALSO -.Xr VOP_READ 9 , -.Xr VOP_WRITE 9 -.Sh AUTHORS -This man page was written by -.An Matt Dillon . diff --git a/share/man/man9/VOP_LOCK.9 b/share/man/man9/VOP_LOCK.9 deleted file mode 100644 index ee8416289a..0000000000 --- a/share/man/man9/VOP_LOCK.9 +++ /dev/null @@ -1,167 +0,0 @@ -.\" 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. -.\" -.\" $FreeBSD: src/share/man/man9/VOP_LOCK.9,v 1.8.2.3 2001/12/17 11:30:18 ru Exp $ -.\" -.Dd April 23, 2006 -.Dt VOP_LOCK 9 -.Os -.Sh NAME -.Nm VOP_LOCK , -.Nm VOP_UNLOCK , -.Nm VOP_ISLOCKED , -.Nm vn_lock -.Nd serialize access to a vnode -.Sh SYNOPSIS -.In sys/param.h -.In sys/lock.h -.In sys/vnode.h -.Ft int -.Fn VOP_LOCK "struct vnode *vp" "int flags" "struct proc *p" -.Ft int -.Fn VOP_UNLOCK "struct vnode *vp" "int flags" "struct proc *p" -.Ft int -.Fn VOP_ISLOCKED "struct vnode *vp" "struct proc *p" -.Ft int -.Fn vn_lock "struct vnode *vp" "int flags" "struct proc *p" -.Sh DESCRIPTION -These calls are used to serialize access to the filesystem, such as -to prevent two writes to the same file from happening at the -same time. -.Pp -The arguments are: -.Bl -tag -width flags -.It Fa vp -the vnode being locked or unlocked -.It Fa flags -One of the lock request types: -.Bl -column ".Dv LK_EXCLUPGRADE" -offset indent -.It Dv LK_SHARED Ta "Shared lock" -.It Dv LK_EXCLUSIVE Ta "Exclusive lock" -.It Dv LK_UPGRADE Ta "Shared-to-exclusive upgrade" -.It Dv LK_EXCLUPGRADE Ta "First shared-to-exclusive upgrade" -.It Dv LK_DOWNGRADE Ta "Exclusive-to-shared downgrade" -.It Dv LK_RELEASE Ta "Release any type of lock" -.El -.Pp -The lock type may be -.Em or Ns 'ed -with these lock flags: -.Bl -column ".Dv LK_CANRECURSE" -offset indent -.It Dv LK_NOWAIT Ta "Do not sleep to wait for lock" -.It Dv LK_SLEEPFAIL Ta "Sleep, then return failure" -.It Dv LK_CANRECURSE Ta "Allow recursive exclusive lock" -.El -.Pp -The lock type may be -.Em or Ns 'ed -with these control flags: -.Bl -column ".Dv LK_RETRY" -offset indent -.It Dv LK_RETRY Ta "Retry until locked" -.It Dv LK_NOOBJ Ta "Don't create object" -.El -.It Ar p -process context to use for the locks -.El -.Pp -Kernel code should use -.Fn vn_lock -to lock a vnode rather than calling -.Fn VOP_LOCK -directly. -.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, 0, "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, 0, "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 -.An Doug Rabson . diff --git a/share/man/man9/VOP_LOOKUP.9 b/share/man/man9/VOP_LOOKUP.9 deleted file mode 100644 index b449655941..0000000000 --- a/share/man/man9/VOP_LOOKUP.9 +++ /dev/null @@ -1,447 +0,0 @@ -.\" 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. -.\" -.\" $FreeBSD: src/share/man/man9/VOP_LOOKUP.9,v 1.8.2.5 2001/12/17 11:30:18 ru Exp $ -.\" -.Dd November 24, 1997 -.Dt VOP_LOOKUP 9 -.Os -.Sh NAME -.Nm VOP_LOOKUP -.Nd lookup a component of a pathname -.Sh SYNOPSIS -.In sys/param.h -.In sys/vnode.h -.In sys/namei.h -.Ft int -.Fn VOP_LOOKUP "struct vnode *dvp" "struct vnode **vpp" "struct componentname *cnp" -.Sh DESCRIPTION -This entry point looks up a single pathname component in a given directory. -.Pp -Its arguments are: -.Bl -tag -width vpp -.It Fa dvp -the locked vnode of the directory to search -.It Fa vpp -the address of a variable where the resulting locked vnode should be stored -.It Fa 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 -ragged -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 -ragged -offset indent -If creating or renaming and at end of pathname, -return -.Er EJUSTRETURN , -leaving info on available slots else return -.Er ENOENT . -.Ed -.Pp -found: -.Bd -ragged -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 -.Er 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 -.Er 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 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 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 Er -.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 EACCES -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 vnode 9 , -.Xr VOP_ACCESS 9 , -.Xr VOP_CREATE 9 , -.Xr VOP_MKDIR 9 , -.Xr VOP_MKNOD 9 , -.Xr VOP_RENAME 9 , -.Xr VOP_SYMLINK 9 -.Sh HISTORY -The function -.Nm -appeared in -.Bx 4.3 . -.Sh AUTHORS -This man page was written by -.An Doug Rabson , -with some text from comments in -.Pa sys/vfs/ufs/ufs_lookup.c . diff --git a/share/man/man9/VOP_CREATE.9 b/share/man/man9/VOP_OLD_CREATE.9 similarity index 57% rename from share/man/man9/VOP_CREATE.9 rename to share/man/man9/VOP_OLD_CREATE.9 index 6f5fdbf9e6..d016134f1c 100644 --- a/share/man/man9/VOP_CREATE.9 +++ b/share/man/man9/VOP_OLD_CREATE.9 @@ -26,27 +26,27 @@ .\" .\" $FreeBSD: src/share/man/man9/VOP_CREATE.9,v 1.9.2.1 2001/12/17 11:30:18 ru Exp $ .\" -.Dd July 24, 1996 -.Dt VOP_CREATE 9 +.Dd October 13, 2014 +.Dt VOP_OLD_CREATE 9 .Os .Sh NAME -.Nm VOP_CREATE , -.Nm VOP_MKNOD , -.Nm VOP_MKDIR , -.Nm VOP_SYMLINK +.Nm VOP_OLD_CREATE , +.Nm VOP_OLD_MKNOD , +.Nm VOP_OLD_MKDIR , +.Nm VOP_OLD_SYMLINK .Nd create a file, socket, fifo, device, directory or symlink .Sh SYNOPSIS .In sys/param.h .In sys/vnode.h .In sys/namei.h .Ft int -.Fn VOP_CREATE "struct vnode *dvp" "struct vnode **vpp" "struct componentname *cnp" "struct vattr *vap" +.Fn VOP_OLD_CREATE "struct vnode *dvp" "struct vnode **vpp" "struct componentname *cnp" "struct vattr *vap" .Ft int -.Fn VOP_MKNOD "struct vnode *dvp" "struct vnode **vpp" "struct componentname *cnp" "struct vattr *vap" +.Fn VOP_OLD_MKNOD "struct vnode *dvp" "struct vnode **vpp" "struct componentname *cnp" "struct vattr *vap" .Ft int -.Fn VOP_MKDIR "struct vnode *dvp" "struct vnode **vpp" "struct componentname *cnp" "struct vattr *vap" +.Fn VOP_OLD_MKDIR "struct vnode *dvp" "struct vnode **vpp" "struct componentname *cnp" "struct vattr *vap" .Ft int -.Fn VOP_SYMLINK "struct vnode *dvp" "struct vnode **vpp" "struct componentname *cnp" "struct vattr *vap" "char *target" +.Fn VOP_OLD_SYMLINK "struct vnode *dvp" "struct vnode **vpp" "struct componentname *cnp" "struct vattr *vap" "char *target" .Sh DESCRIPTION These entry points create a new file, socket, fifo, device, directory or symlink in a given directory. @@ -66,23 +66,11 @@ the pathname of the target of the symlink .El .Pp These entry points are called after -.Xr VOP_LOOKUP 9 +.Xr VOP_OLD_LOOKUP 9 when an object is being created. -Normally, -.Xr VOP_LOOKUP 9 -will have set the -.Dv SAVENAME -flag in -.Fa cnp->cn_flags -to keep the memory pointed to by -.Fa cnp->cn_pnbuf -valid. If an error is detected when creating the file, then this memory will be freed. -If the file is created successfully, then it will be freed unless the -.Dv SAVESTART -flag is specified in -.Fa cnp . +If the file is created successfully, then it will be freed. .Sh LOCKS The directory, .Fa dvp @@ -92,76 +80,6 @@ If the call is successful, the new object will be returned locked. If successful, the vnode for the new object is placed in .Fa *vpp and zero is returned. Otherwise, an appropriate error is returned. -.Sh PSEUDOCODE -.Bd -literal -int -vop_create(struct vnode *dvp, - struct vnode **vpp, - struct componentname *cnp - struct vattr *vap) -{ - int mode = MAKEIMODE(vap->va_type, vap->va_mode); - struct vnode *vp; - int error; - - *vpp = NULL; - if ((mode & IFMT) == 0) - mode |= IFREG; - - error = SOMEFS_VALLOC(dvp, mode, cnp->cn_cred, &vp); - if (error) { - kfree(cnp->cn_pnbuf, M_NAMEI); - vput(dvp); - return error; - } - - /* - * Update the permissions for the new vnode, including - * copying the group from the directory. - */ - ...; - -#ifdef QUOTA - /* - * Possibly check quota information. - */ - ...; -#endif - - /* - * Enter new vnode in directory, taking care that the vnode - * hits the disk before the directory contents are changed. - */ - error = ...; - - if (error) - goto bad; - - if ((cnp->cn_flags & SAVESTART) == 0) - kfree(cnp->cn_pnbuf, M_NAMEI); - vput(dvp); - *vpp = vp; - - return 0; - -bad: - /* - * Write error occurred trying to update the inode - * or the directory so must deallocate the inode. - */ - kfree(cnp->cn_pnbuf, M_NAMEI); - vput(vp); - - /* - * Deallocate filesystem resources for vp. - */ - ...; - - vput(dvp); - - return error; -} -.Ed .Sh ERRORS .Bl -tag -width Er .It Bq Er ENOSPC @@ -171,7 +89,7 @@ Quota exceeded. .El .Sh SEE ALSO .Xr vnode 9 , -.Xr VOP_LOOKUP 9 +.Xr VOP_OLD_LOOKUP 9 .Sh HISTORY The function .Nm diff --git a/share/man/man9/VOP_LINK.9 b/share/man/man9/VOP_OLD_LINK.9 similarity index 71% rename from share/man/man9/VOP_LINK.9 rename to share/man/man9/VOP_OLD_LINK.9 index 1327a3c3fc..ec3b3e945f 100644 --- a/share/man/man9/VOP_LINK.9 +++ b/share/man/man9/VOP_OLD_LINK.9 @@ -26,17 +26,17 @@ .\" .\" $FreeBSD: src/share/man/man9/VOP_LINK.9,v 1.9.2.3 2001/12/17 11:30:18 ru Exp $ .\" -.Dd July 24, 1996 -.Dt VOP_LINK 9 +.Dd October 13, 2014 +.Dt VOP_OLD_LINK 9 .Os .Sh NAME -.Nm VOP_LINK +.Nm VOP_OLD_LINK .Nd create a new name for a file .Sh SYNOPSIS .In sys/param.h .In sys/vnode.h .Ft int -.Fn VOP_LINK "struct vnode *dvp" "struct vnode *vp" "struct componentname *cnp" +.Fn VOP_OLD_LINK "struct vnode *dvp" "struct vnode *vp" "struct componentname *cnp" .Sh DESCRIPTION This links a new name in the specified directory to an existing file. .Pp @@ -65,60 +65,6 @@ it must be sure to unlock prior to returning. .Sh RETURN VALUES Zero is returned if the file was linked successfully, otherwise an error is returned. -.Sh PSEUDOCODE -.Bd -literal -int -vop_link(struct vnode *dvp, struct vnode *vp, struct componentname *cnp) -{ - int error = 0; - - if (vp->v_mount != dvp->v_mount) { - VOP_ABORTOP(dvp, cnp); - error = EXDEV; - goto out2; - } - if (vp != dvp && (error = VOP_LOCK(vp))) { - VOP_ABORTOP(dvp, cnp); - goto out2; - } - - /* - * now that we've locked vp, we have to use out1 instead of out2 - */ - - if (vp would have too many links) { - VOP_ABORTOP(dvp, cnp); - error = EMLINK; - goto out1; - } - - if (vp is immutable) { - VOP_ABORTOP(dvp, cnp); - error = EPERM; - goto out1; - } - - /* - * Increment link count of vp and write back the on-disc version of it. - */ - ...; - - if (!error) { - /* - * Add the new name to the directory. - */ - ...; - } - - kfree(cnp->cn_pnbuf, M_NAMEI); -out1: - if (vp != dvp) - VOP_UNLOCK(vp); -out2: - - return error; -} -.Ed .Sh ERRORS .Bl -tag -width Er .It Bq Er EPERM diff --git a/share/man/man9/VOP_OLD_LOOKUP.9 b/share/man/man9/VOP_OLD_LOOKUP.9 new file mode 100644 index 0000000000..aa82f9302f --- /dev/null +++ b/share/man/man9/VOP_OLD_LOOKUP.9 @@ -0,0 +1,189 @@ +.\" 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. +.\" +.\" $FreeBSD: src/share/man/man9/VOP_LOOKUP.9,v 1.8.2.5 2001/12/17 11:30:18 ru Exp $ +.\" +.Dd October 13, 2014 +.Dt VOP_OLD_LOOKUP 9 +.Os +.Sh NAME +.Nm VOP_OLD_LOOKUP +.Nd lookup a component of a pathname +.Sh SYNOPSIS +.In sys/param.h +.In sys/vnode.h +.In sys/namei.h +.Ft int +.Fn VOP_OLD_LOOKUP "struct vnode *dvp" "struct vnode **vpp" "struct componentname *cnp" +.Sh DESCRIPTION +This entry point looks up a single pathname component in a given directory. +.Pp +Its arguments are: +.Bl -tag -width vpp +.It Fa dvp +the locked vnode of the directory to search +.It Fa vpp +the address of a variable where the resulting locked vnode should be stored +.It Fa 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 thread *cn_td; /* process requesting lookup */ + struct ucred *cn_cred; /* credentials */ + /* + * Shared between lookup and commit routines. + */ + char *cn_nameptr; /* pointer to looked up name */ + long cn_namelen; /* length of looked up component */ + long cn_consume; /* chars to consume in lookup() */ + int cn_timeout; /* if CNP_CACHETIMEOUT is set, in ticks */ + struct vnode *cn_notvp; /* used by NFS to check for collision */ +}; +.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 NAMEI_LOOKUP , +.Dv NAMEI_CREATE , +.Dv NAMEI_RENAME , +or +.Dv NAMEI_DELETE +depending on the intended use of the object. +When +.Dv NAMEI_CREATE , +.Dv NAMEI_RENAME , +or +.Dv NAMEI_DELETE +is specified, information usable in +creating, renaming, or deleting a directory entry may be calculated. +.Pp +Overall outline of VOP_LOOKUP: +.Bd -ragged -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 -ragged -offset indent +If creating or renaming and at end of pathname, +return +.Er EJUSTRETURN , +leaving info on available slots else return +.Er ENOENT . +.Ed +.Pp +found: +.Bd -ragged -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 +.Er EJUSTRETURN +is not considered an error) +is detected, it will be returned locked. +Otherwise, it will be unlocked unless +.Dv CNP_LOCKPARENT +is 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 NAMEI_CREATE +or +.Dv NAMEI_RENAME +the special return value +.Er EJUSTRETURN +is returned. +Otherwise, an appropriate error code is returned. +.Sh ERRORS +.Bl -tag -width Er +.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 EACCES +access for the specified operation is denied. +.It Bq Er EJUSTRETURN +a +.Dv NAMEI_CREATE +or +.Dv NAMEI_RENAME +operation would be successful +.El +.Sh SEE ALSO +.Xr vnode 9 , +.Xr VOP_ACCESS 9 , +.Xr VOP_OLD_CREATE 9 , +.Xr VOP_OLD_MKDIR 9 , +.Xr VOP_OLD_MKNOD 9 , +.Xr VOP_OLD_RENAME 9 , +.Xr VOP_OLD_SYMLINK 9 +.Sh HISTORY +The function +.Nm +appeared in +.Bx 4.3 . +.Sh AUTHORS +This man page was written by +.An Doug Rabson , +with some text from comments in +.Pa sys/vfs/ufs/ufs_lookup.c . diff --git a/share/man/man9/VOP_REMOVE.9 b/share/man/man9/VOP_OLD_REMOVE.9 similarity index 75% rename from share/man/man9/VOP_REMOVE.9 rename to share/man/man9/VOP_OLD_REMOVE.9 index c487bc6fa6..201facf836 100644 --- a/share/man/man9/VOP_REMOVE.9 +++ b/share/man/man9/VOP_OLD_REMOVE.9 @@ -26,20 +26,20 @@ .\" .\" $FreeBSD: src/share/man/man9/VOP_REMOVE.9,v 1.7.2.2 2001/12/17 11:30:18 ru Exp $ .\" -.Dd July 24, 1996 -.Dt VOP_REMOVE 9 +.Dd October 13, 2014 +.Dt VOP_OLD_REMOVE 9 .Os .Sh NAME -.Nm VOP_REMOVE , -.Nm VOP_RMDIR +.Nm VOP_OLD_REMOVE , +.Nm VOP_OLD_RMDIR .Nd remove a file or directory .Sh SYNOPSIS .In sys/param.h .In sys/vnode.h .Ft int -.Fn VOP_REMOVE "struct vnode *dvp" "struct vnode *vp" "struct componentname *cnp" +.Fn VOP_OLD_REMOVE "struct vnode *dvp" "struct vnode *vp" "struct componentname *cnp" .Ft int -.Fn VOP_RMDIR "struct vnode *dvp" "struct vnode *vp" "struct componentname *cnp" +.Fn VOP_OLD_RMDIR "struct vnode *dvp" "struct vnode *vp" "struct componentname *cnp" .Sh DESCRIPTION These entry points remove files and directories respectively. .Pp @@ -60,37 +60,6 @@ and should be locked on entry and remain locked on return. .Sh RETURN VALUES Zero is returned on success, otherwise an error code is returned. -.Sh PSEUDOCODE -.Bd -literal -int -vop_remove(struct vnode *dvp, struct vnode *vp, struct componentname *cnp) -{ - int error = 0; - - if (vp is immutable) { - error = EPERM; - goto out; - } - - /* - * Remove name cnp->cn_nameptr from directory and update link count - * of vp. - */ - ...; - - /* - * Careful about trying to remove ".". XXX this should be handled - * higher up. - */ - if (dvp == vp) - vrele(vp); - else - vput(vp); - vput(dvp); - - return error; -} -.Ed .Sh ERRORS .Bl -tag -width Er .It Bq Er EPERM @@ -100,7 +69,7 @@ attempt to remove a directory which is not empty .El .Sh SEE ALSO .Xr vnode 9 , -.Xr VOP_LOOKUP 9 +.Xr VOP_OLD_LOOKUP 9 .Sh AUTHORS This man page was written by .An Doug Rabson . diff --git a/share/man/man9/VOP_STRATEGY.9 b/share/man/man9/VOP_OLD_RENAME.9 similarity index 52% rename from share/man/man9/VOP_STRATEGY.9 rename to share/man/man9/VOP_OLD_RENAME.9 index 926e6787c8..e008028b2e 100644 --- a/share/man/man9/VOP_STRATEGY.9 +++ b/share/man/man9/VOP_OLD_RENAME.9 @@ -24,34 +24,64 @@ .\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF .\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. .\" -.\" $FreeBSD: src/share/man/man9/VOP_STRATEGY.9,v 1.8.2.3 2001/12/17 11:30:18 ru Exp $ +.\" $FreeBSD: src/share/man/man9/VOP_RENAME.9,v 1.10.2.2 2001/12/17 11:30:18 ru Exp $ .\" -.Dd July 24, 1996 -.Dt VOP_STRATEGY 9 +.Dd October 13, 2014 +.Dt VOP_OLD_RENAME 9 .Os .Sh NAME -.Nm VOP_STRATEGY -.Nd read or write a filesystem buffer +.Nm VOP_OLD_RENAME +.Nd rename a file .Sh SYNOPSIS .In sys/param.h .In sys/vnode.h .Ft int -.Fn VOP_STRATEGY "struct vnode *vp" "struct buf *bp" +.Fn VOP_OLD_RENAME "struct vnode *fdvp" "struct vnode *fvp" "struct componentname *fcnp" "struct vnode *tdvp" "struct vnode *tvp" "struct componentname *tcnp" .Sh DESCRIPTION -The arguments are: -.Bl -tag -width 2n -.It Fa vp -the vnode that the buffer is for -.It Fa bp -the buffer to be read or written +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 Fa fdvp +the vnode of the old parent directory +.It Fa fvp +the vnode of the file to be renamed +.It Fa fcnp +pathname information about the file's current name +.It Fa tdvp +the vnode of the new parent directory +.It Fa tvp +the vnode of the target file (if it exists) +.It Fa tcnp +pathname information about the file's new name .El +.Sh LOCKS +The source directory and file are unlocked but are expected to have their +ref count bumped on entry. The VOP routine is expected to +.Fn vrele +both prior +to returning. .Pp -This call either reads or writes data from a file, depending on the value of -.Fa bp->b_flags . -.Sh RETURN VALUES -Zero is returned on success, otherwise an error is returned. +The destination directory and file are locked as well as having their ref +count bumped. The VOP routine is expected to +.Fn vput +both prior to +returning. +.Sh ERRORS +.Bl -tag -width Er +.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 buf 9 , .Xr vnode 9 .Sh AUTHORS This man page was written by diff --git a/share/man/man9/VOP_RENAME.9 b/share/man/man9/VOP_RENAME.9 deleted file mode 100644 index 7e7d31848f..0000000000 --- a/share/man/man9/VOP_RENAME.9 +++ /dev/null @@ -1,311 +0,0 @@ -.\" 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. -.\" -.\" $FreeBSD: src/share/man/man9/VOP_RENAME.9,v 1.10.2.2 2001/12/17 11:30:18 ru Exp $ -.\" -.Dd July 24, 1996 -.Dt VOP_RENAME 9 -.Os -.Sh NAME -.Nm VOP_RENAME -.Nd rename a file -.Sh SYNOPSIS -.In sys/param.h -.In sys/vnode.h -.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 Fa fdvp -the vnode of the old parent directory -.It Fa fvp -the vnode of the file to be renamed -.It Fa fcnp -pathname information about the file's current name -.It Fa tdvp -the vnode of the new parent directory -.It Fa tvp -the vnode of the target file (if it exists) -.It Fa tcnp -pathname information about the file's new name -.El -.Sh LOCKS -The source directory and file are unlocked but are expected to have their -ref count bumped on entry. The VOP routine is expected to -.Fn vrele -both prior -to returning. -.Pp -The destination directory and file are locked as well as having their ref -count bumped. The VOP routine is expected to -.Fn vput -both prior to -returning. -.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 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 Er -.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 -.An Doug Rabson . -- 2.41.0