*
* %sccs.include.redist.c%
*
- * @(#)vfs_syscalls.c 8.8 (Berkeley) %G%
+ * @(#)vfs_syscalls.c 8.21 (Berkeley) %G%
*/
#include <sys/param.h>
register struct vnode *vp;
register struct mount *mp;
int error, flag;
+ struct vattr va;
struct nameidata nd;
- /*
- * Must be super user
- */
- if (error = suser(p->p_ucred, &p->p_acflag))
- return (error);
/*
* Get vnode to be covered
*/
}
mp->mnt_flag |=
uap->flags & (MNT_RELOAD | MNT_FORCE | MNT_UPDATE);
+ /*
+ * Only root, or the user that did the original mount is
+ * permitted to update it.
+ */
+ if (mp->mnt_stat.f_owner != p->p_ucred->cr_uid &&
+ (error = suser(p->p_ucred, &p->p_acflag))) {
+ vput(vp);
+ return (error);
+ }
+ /*
+ * Do not allow NFS export by non-root users. Silently
+ * enforce MNT_NOSUID and MNT_NODEV for non-root users.
+ */
+ if (p->p_ucred->cr_uid != 0) {
+ if (uap->flags & MNT_EXPORTED) {
+ vput(vp);
+ return (EPERM);
+ }
+ uap->flags |= MNT_NOSUID | MNT_NODEV;
+ }
VOP_UNLOCK(vp);
goto update;
}
- if (vp->v_usecount != 1 && (uap->flags & MNT_UNION) == 0) {
+ /*
+ * If the user is not root, ensure that they own the directory
+ * onto which we are attempting to mount.
+ */
+ if ((error = VOP_GETATTR(vp, &va, p->p_ucred, p)) ||
+ (va.va_uid != p->p_ucred->cr_uid &&
+ (error = suser(p->p_ucred, &p->p_acflag)))) {
vput(vp);
- return (EBUSY);
+ return (error);
+ }
+ /*
+ * Do not allow NFS export by non-root users. Silently
+ * enforce MNT_NOSUID and MNT_NODEV for non-root users.
+ */
+ if (p->p_ucred->cr_uid != 0) {
+ if (uap->flags & MNT_EXPORTED) {
+ vput(vp);
+ return (EPERM);
+ }
+ uap->flags |= MNT_NOSUID | MNT_NODEV;
}
if (error = vinvalbuf(vp, V_SAVE, p->p_ucred, p, 0, 0))
return (error);
}
vp->v_mountedhere = mp;
mp->mnt_vnodecovered = vp;
+ mp->mnt_stat.f_owner = p->p_ucred->cr_uid;
update:
/*
* Set the mount level flags.
int error;
struct nameidata nd;
- /*
- * Must be super user
- */
- if (error = suser(p->p_ucred, &p->p_acflag))
- return (error);
-
NDINIT(&nd, LOOKUP, FOLLOW | LOCKLEAF, UIO_USERSPACE, uap->path, p);
if (error = namei(&nd))
return (error);
vp = nd.ni_vp;
+ mp = vp->v_mount;
+
+ /*
+ * Only root, or the user that did the original mount is
+ * permitted to unmount this filesystem.
+ */
+ if ((mp->mnt_stat.f_owner != p->p_ucred->cr_uid) &&
+ (error = suser(p->p_ucred, &p->p_acflag))) {
+ vput(vp);
+ return (error);
+ }
+
/*
* Must be the root of the filesystem
*/
vput(vp);
return (EINVAL);
}
- mp = vp->v_mount;
vput(vp);
return (dounmount(mp, uap->flags, p));
}
/*
* Sync each mounted filesystem.
*/
-#ifdef DIAGNOSTIC
+#ifdef DEBUG
int syncprt = 0;
struct ctldebug debug0 = { "syncprt", &syncprt };
#endif
int asyncflag;
for (mp = mountlist.tqh_first; mp != NULL; mp = nmp) {
+ /*
+ * Get the next pointer in case we hang on vfs_busy
+ * while we are being unmounted.
+ */
nmp = mp->mnt_list.tqe_next;
/*
* The lock check below is to avoid races with mount
VFS_SYNC(mp, MNT_NOWAIT, p->p_ucred, p);
if (asyncflag)
mp->mnt_flag |= MNT_ASYNC;
+ /*
+ * Get the next pointer again, as the next filesystem
+ * might have been unmounted while we were sync'ing.
+ */
+ nmp = mp->mnt_list.tqe_next;
vfs_unbusy(mp);
}
}
register struct vnode *vp;
struct vattr vattr;
int error;
+ int whiteout;
struct nameidata nd;
CHECKPOINTREF;
VATTR_NULL(&vattr);
vattr.va_mode = (uap->mode & ALLPERMS) &~ p->p_fd->fd_cmask;
vattr.va_rdev = uap->dev;
+ whiteout = 0;
switch (uap->mode & S_IFMT) {
case S_IFMT: /* used by badsect to flag bad sectors */
case S_IFBLK:
vattr.va_type = VBLK;
break;
+ case S_IFWHT:
+ whiteout = 1;
+ break;
default:
error = EINVAL;
break;
}
}
- if (!error) {
- LEASE_CHECK(nd.ni_dvp, p, p->p_ucred, LEASE_WRITE);
+ if (whiteout) {
+ error = VOP_WHITEOUT(nd.ni_dvp, &nd.ni_cnd, CREATE);
+ vput(nd.ni_dvp);
+ } else if (!error) {
+ VOP_LEASE(nd.ni_dvp, p, p->p_ucred, LEASE_WRITE);
error = VOP_MKNOD(nd.ni_dvp, &nd.ni_vp, &nd.ni_cnd, &vattr);
} else {
VOP_ABORTOP(nd.ni_dvp, &nd.ni_cnd);
VATTR_NULL(&vattr);
vattr.va_type = VFIFO;
vattr.va_mode = (uap->mode & ALLPERMS) &~ p->p_fd->fd_cmask;
- LEASE_CHECK(nd.ni_dvp, p, p->p_ucred, LEASE_WRITE);
+ VOP_LEASE(nd.ni_dvp, p, p->p_ucred, LEASE_WRITE);
return (VOP_MKNOD(nd.ni_dvp, &nd.ni_vp, &nd.ni_cnd, &vattr));
#endif /* FIFO */
}
if (nd.ni_vp != NULL)
error = EEXIST;
if (!error) {
- LEASE_CHECK(nd.ni_dvp,
- p, p->p_ucred, LEASE_WRITE);
- LEASE_CHECK(vp,
- p, p->p_ucred, LEASE_WRITE);
+ VOP_LEASE(nd.ni_dvp, p, p->p_ucred,
+ LEASE_WRITE);
+ VOP_LEASE(vp, p, p->p_ucred, LEASE_WRITE);
error = VOP_LINK(nd.ni_dvp, vp, &nd.ni_cnd);
} else {
VOP_ABORTOP(nd.ni_dvp, &nd.ni_cnd);
}
VATTR_NULL(&vattr);
vattr.va_mode = ACCESSPERMS &~ p->p_fd->fd_cmask;
- LEASE_CHECK(nd.ni_dvp, p, p->p_ucred, LEASE_WRITE);
+ VOP_LEASE(nd.ni_dvp, p, p->p_ucred, LEASE_WRITE);
error = VOP_SYMLINK(nd.ni_dvp, &nd.ni_vp, &nd.ni_cnd, &vattr, path);
out:
FREE(path, M_NAMEI);
return (error);
}
+/*
+ * Delete a whiteout from the filesystem.
+ */
+struct unwhiteout_args {
+ char *path;
+};
+/* ARGSUSED */
+unwhiteout(p, uap, retval)
+ struct proc *p;
+ struct unwhiteout_args *uap;
+ int *retval;
+{
+ int error;
+ struct nameidata nd;
+
+ NDINIT(&nd, DELETE, LOCKPARENT|DOWHITEOUT, UIO_USERSPACE, uap->path, p);
+ error = namei(&nd);
+ if (error)
+ return (error);
+
+ if (nd.ni_vp != NULLVP || !(nd.ni_cnd.cn_flags & ISWHITEOUT)) {
+ VOP_ABORTOP(nd.ni_dvp, &nd.ni_cnd);
+ if (nd.ni_dvp == nd.ni_vp)
+ vrele(nd.ni_dvp);
+ else
+ vput(nd.ni_dvp);
+ if (nd.ni_vp)
+ vrele(nd.ni_vp);
+ return (EEXIST);
+ }
+
+ VOP_LEASE(nd.ni_dvp, p, p->p_ucred, LEASE_WRITE);
+ error = VOP_WHITEOUT(nd.ni_dvp, &nd.ni_cnd, DELETE);
+ if (error != 0)
+ VOP_ABORTOP(nd.ni_dvp, &nd.ni_cnd);
+ vput(nd.ni_dvp);
+ return (error);
+}
+
/*
* Delete a name from the filesystem.
*/
if (error = namei(&nd))
return (error);
vp = nd.ni_vp;
- LEASE_CHECK(vp, p, p->p_ucred, LEASE_WRITE);
+ VOP_LEASE(vp, p, p->p_ucred, LEASE_WRITE);
VOP_LOCK(vp);
if (vp->v_type != VDIR ||
}
if (!error) {
- LEASE_CHECK(nd.ni_dvp, p, p->p_ucred, LEASE_WRITE);
+ VOP_LEASE(nd.ni_dvp, p, p->p_ucred, LEASE_WRITE);
error = VOP_REMOVE(nd.ni_dvp, nd.ni_vp, &nd.ni_cnd);
} else {
VOP_ABORTOP(nd.ni_dvp, &nd.ni_cnd);
vrele(nd.ni_dvp);
else
vput(nd.ni_dvp);
- vput(vp);
+ if (vp != NULLVP)
+ vput(vp);
}
CHECKREFS("unlink");
return (error);
if (error = namei(&nd))
return (error);
vp = nd.ni_vp;
- LEASE_CHECK(vp, p, p->p_ucred, LEASE_WRITE);
+ VOP_LEASE(vp, p, p->p_ucred, LEASE_WRITE);
VOP_LOCK(vp);
if (vp->v_mount->mnt_flag & MNT_RDONLY)
error = EROFS;
if (error = getvnode(p->p_fd, uap->fd, &fp))
return (error);
vp = (struct vnode *)fp->f_data;
- LEASE_CHECK(vp, p, p->p_ucred, LEASE_WRITE);
+ VOP_LEASE(vp, p, p->p_ucred, LEASE_WRITE);
VOP_LOCK(vp);
if (vp->v_mount->mnt_flag & MNT_RDONLY)
error = EROFS;
if (error = namei(&nd))
return (error);
vp = nd.ni_vp;
- LEASE_CHECK(vp, p, p->p_ucred, LEASE_WRITE);
+ VOP_LEASE(vp, p, p->p_ucred, LEASE_WRITE);
VOP_LOCK(vp);
if (vp->v_mount->mnt_flag & MNT_RDONLY)
error = EROFS;
if (error = getvnode(p->p_fd, uap->fd, &fp))
return (error);
vp = (struct vnode *)fp->f_data;
- LEASE_CHECK(vp, p, p->p_ucred, LEASE_WRITE);
+ VOP_LEASE(vp, p, p->p_ucred, LEASE_WRITE);
VOP_LOCK(vp);
if (vp->v_mount->mnt_flag & MNT_RDONLY)
error = EROFS;
int error;
struct nameidata nd;
- NDINIT(&nd, LOOKUP, NOFOLLOW, UIO_USERSPACE, uap->path, p);
+ NDINIT(&nd, LOOKUP, FOLLOW, UIO_USERSPACE, uap->path, p);
if (error = namei(&nd))
return (error);
vp = nd.ni_vp;
- LEASE_CHECK(vp, p, p->p_ucred, LEASE_WRITE);
+ VOP_LEASE(vp, p, p->p_ucred, LEASE_WRITE);
VOP_LOCK(vp);
if (vp->v_mount->mnt_flag & MNT_RDONLY)
error = EROFS;
if (error = getvnode(p->p_fd, uap->fd, &fp))
return (error);
vp = (struct vnode *)fp->f_data;
- LEASE_CHECK(vp, p, p->p_ucred, LEASE_WRITE);
+ VOP_LEASE(vp, p, p->p_ucred, LEASE_WRITE);
VOP_LOCK(vp);
if (vp->v_mount->mnt_flag & MNT_RDONLY)
error = EROFS;
if (error = namei(&nd))
return (error);
vp = nd.ni_vp;
- LEASE_CHECK(vp, p, p->p_ucred, LEASE_WRITE);
+ VOP_LEASE(vp, p, p->p_ucred, LEASE_WRITE);
VOP_LOCK(vp);
if (vp->v_mount->mnt_flag & MNT_RDONLY)
error = EROFS;
if (error = namei(&nd))
return (error);
vp = nd.ni_vp;
- LEASE_CHECK(vp, p, p->p_ucred, LEASE_WRITE);
+ VOP_LEASE(vp, p, p->p_ucred, LEASE_WRITE);
VOP_LOCK(vp);
if (vp->v_type == VDIR)
error = EISDIR;
if ((fp->f_flag & FWRITE) == 0)
return (EINVAL);
vp = (struct vnode *)fp->f_data;
- LEASE_CHECK(vp, p, p->p_ucred, LEASE_WRITE);
+ VOP_LEASE(vp, p, p->p_ucred, LEASE_WRITE);
VOP_LOCK(vp);
if (vp->v_type == VDIR)
error = EISDIR;
error = -1;
out:
if (!error) {
- LEASE_CHECK(tdvp, p, p->p_ucred, LEASE_WRITE);
+ VOP_LEASE(tdvp, p, p->p_ucred, LEASE_WRITE);
if (fromnd.ni_dvp != tdvp)
- LEASE_CHECK(fromnd.ni_dvp, p, p->p_ucred, LEASE_WRITE);
+ VOP_LEASE(fromnd.ni_dvp, p, p->p_ucred, LEASE_WRITE);
if (tvp)
- LEASE_CHECK(tvp, p, p->p_ucred, LEASE_WRITE);
+ VOP_LEASE(tvp, p, p->p_ucred, LEASE_WRITE);
error = VOP_RENAME(fromnd.ni_dvp, fromnd.ni_vp, &fromnd.ni_cnd,
tond.ni_dvp, tond.ni_vp, &tond.ni_cnd);
} else {
FREE(tond.ni_cnd.cn_pnbuf, M_NAMEI);
out1:
p->p_spare[1]--;
- vrele(fromnd.ni_startdir);
+ if (fromnd.ni_startdir)
+ vrele(fromnd.ni_startdir);
FREE(fromnd.ni_cnd.cn_pnbuf, M_NAMEI);
CHECKREFS("rename");
if (error == -1)
VATTR_NULL(&vattr);
vattr.va_type = VDIR;
vattr.va_mode = (uap->mode & ACCESSPERMS) &~ p->p_fd->fd_cmask;
- LEASE_CHECK(nd.ni_dvp, p, p->p_ucred, LEASE_WRITE);
+ VOP_LEASE(nd.ni_dvp, p, p->p_ucred, LEASE_WRITE);
error = VOP_MKDIR(nd.ni_dvp, &nd.ni_vp, &nd.ni_cnd, &vattr);
if (!error)
vput(nd.ni_vp);
error = EBUSY;
out:
if (!error) {
- LEASE_CHECK(nd.ni_dvp, p, p->p_ucred, LEASE_WRITE);
- LEASE_CHECK(vp, p, p->p_ucred, LEASE_WRITE);
+ VOP_LEASE(nd.ni_dvp, p, p->p_ucred, LEASE_WRITE);
+ VOP_LEASE(vp, p, p->p_ucred, LEASE_WRITE);
error = VOP_RMDIR(nd.ni_dvp, nd.ni_vp, &nd.ni_cnd);
} else {
VOP_ABORTOP(nd.ni_dvp, &nd.ni_cnd);
struct iovec aiov, kiov;
struct dirent *dp, *edp;
caddr_t dirbuf;
- int error, readcnt;
+ int error, eofflag, readcnt;
long loff;
if (error = getvnode(p->p_fd, uap->fd, &fp))
if ((fp->f_flag & FREAD) == 0)
return (EBADF);
vp = (struct vnode *)fp->f_data;
+unionread:
if (vp->v_type != VDIR)
return (EINVAL);
aiov.iov_base = uap->buf;
loff = auio.uio_offset = fp->f_offset;
# if (BYTE_ORDER != LITTLE_ENDIAN)
if (vp->v_mount->mnt_maxsymlinklen <= 0) {
- error = VOP_READDIR(vp, &auio, fp->f_cred);
+ error = VOP_READDIR(vp, &auio, fp->f_cred, &eofflag,
+ (u_long *)0, 0);
fp->f_offset = auio.uio_offset;
} else
# endif
kiov.iov_len = uap->count;
MALLOC(dirbuf, caddr_t, uap->count, M_TEMP, M_WAITOK);
kiov.iov_base = dirbuf;
- error = VOP_READDIR(vp, &kuio, fp->f_cred);
+ error = VOP_READDIR(vp, &kuio, fp->f_cred, &eofflag,
+ (u_long *)0, 0);
fp->f_offset = kuio.uio_offset;
if (error == 0) {
readcnt = uap->count - kuio.uio_resid;
VOP_UNLOCK(vp);
if (error)
return (error);
+
+#ifdef UNION
+{
+ extern int (**union_vnodeop_p)();
+ extern struct vnode *union_lowervp __P((struct vnode *));
+
+ if ((uap->count == auio.uio_resid) &&
+ (vp->v_op == union_vnodeop_p)) {
+ struct vnode *lvp;
+
+ lvp = union_lowervp(vp);
+ if (lvp != NULLVP) {
+ struct vattr va;
+
+ /*
+ * If the directory is opaque,
+ * then don't show lower entries
+ */
+ error = VOP_GETATTR(vp, &va, fp->f_cred, p);
+ if (va.va_flags & OPAQUE) {
+ vrele(lvp);
+ lvp = NULL;
+ }
+ }
+
+ if (lvp != NULLVP) {
+ VOP_LOCK(lvp);
+ error = VOP_OPEN(lvp, FREAD, fp->f_cred, p);
+ VOP_UNLOCK(lvp);
+
+ if (error) {
+ vrele(lvp);
+ return (error);
+ }
+ fp->f_data = (caddr_t) lvp;
+ fp->f_offset = 0;
+ error = vn_close(vp, FREAD, fp->f_cred, p);
+ if (error)
+ return (error);
+ vp = lvp;
+ goto unionread;
+ }
+ }
+}
+#endif /* UNION */
+
+ if ((uap->count == auio.uio_resid) &&
+ (vp->v_flag & VROOT) &&
+ (vp->v_mount->mnt_flag & MNT_UNION)) {
+ struct vnode *tvp = vp;
+ vp = vp->v_mount->mnt_vnodecovered;
+ VREF(vp);
+ fp->f_data = (caddr_t) vp;
+ fp->f_offset = 0;
+ vrele(tvp);
+ goto unionread;
+ }
error = copyout((caddr_t)&loff, (caddr_t)uap->basep, sizeof(long));
*retval = uap->count - auio.uio_resid;
return (error);
}
-#endif
+#endif /* COMPAT_43 */
/*
* Read a block of directory entries in a file system independent format.
struct uio auio;
struct iovec aiov;
long loff;
- int error;
+ int error, eofflag;
if (error = getvnode(p->p_fd, uap->fd, &fp))
return (error);
auio.uio_resid = uap->count;
VOP_LOCK(vp);
loff = auio.uio_offset = fp->f_offset;
- error = VOP_READDIR(vp, &auio, fp->f_cred);
+ error = VOP_READDIR(vp, &auio, fp->f_cred, &eofflag, (u_long *)0, 0);
fp->f_offset = auio.uio_offset;
VOP_UNLOCK(vp);
if (error)
return (error);
+
+#ifdef UNION
+{
+ extern int (**union_vnodeop_p)();
+ extern struct vnode *union_lowervp __P((struct vnode *));
+
+ if ((uap->count == auio.uio_resid) &&
+ (vp->v_op == union_vnodeop_p)) {
+ struct vnode *lvp;
+
+ lvp = union_lowervp(vp);
+ if (lvp != NULLVP) {
+ struct vattr va;
+
+ /*
+ * If the directory is opaque,
+ * then don't show lower entries
+ */
+ error = VOP_GETATTR(vp, &va, fp->f_cred, p);
+ if (va.va_flags & OPAQUE) {
+ vrele(lvp);
+ lvp = NULL;
+ }
+ }
+
+ if (lvp != NULLVP) {
+ VOP_LOCK(lvp);
+ error = VOP_OPEN(lvp, FREAD, fp->f_cred, p);
+ VOP_UNLOCK(lvp);
+
+ if (error) {
+ vrele(lvp);
+ return (error);
+ }
+ fp->f_data = (caddr_t) lvp;
+ fp->f_offset = 0;
+ error = vn_close(vp, FREAD, fp->f_cred, p);
+ if (error)
+ return (error);
+ vp = lvp;
+ goto unionread;
+ }
+ }
+}
+#endif
+
if ((uap->count == auio.uio_resid) &&
(vp->v_flag & VROOT) &&
(vp->v_mount->mnt_flag & MNT_UNION)) {