diff options
Diffstat (limited to 'sys/kern/vfs_syscalls.c')
-rw-r--r-- | sys/kern/vfs_syscalls.c | 432 |
1 files changed, 215 insertions, 217 deletions
diff --git a/sys/kern/vfs_syscalls.c b/sys/kern/vfs_syscalls.c index fc064d9fe46..0ca88c8e73f 100644 --- a/sys/kern/vfs_syscalls.c +++ b/sys/kern/vfs_syscalls.c @@ -1,4 +1,4 @@ -/* $OpenBSD: vfs_syscalls.c,v 1.76 2001/05/23 13:15:07 art Exp $ */ +/* $OpenBSD: vfs_syscalls.c,v 1.77 2001/06/22 14:14:11 deraadt Exp $ */ /* $NetBSD: vfs_syscalls.c,v 1.71 1996/04/23 10:29:02 mycroft Exp $ */ /* @@ -72,15 +72,15 @@ static int change_dir __P((struct nameidata *, struct proc *)); void checkdirs __P((struct vnode *)); /* - * Redirection info so we don't have to include the union fs routines in + * Redirection info so we don't have to include the union fs routines in * the kernel directly. This way, we can build unionfs as an LKM. The * pointer gets filled in later, when we modload the LKM, or when the * compiled-in unionfs code gets initialized. For now, we just set * it to a stub routine. */ -int (*union_check_p) __P((struct proc *, struct vnode **, - struct file *, struct uio, int *)) = NULL; +int (*union_check_p) __P((struct proc *, struct vnode **, + struct file *, struct uio, int *)) = NULL; /* * Virtual File System System Calls @@ -171,7 +171,7 @@ sys_mount(p, v, retval) */ 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)))) { + (error = suser(p->p_ucred, &p->p_acflag)))) { vput(vp); return (error); } @@ -200,9 +200,9 @@ sys_mount(p, v, retval) * If we get an integer for the filesystem type instead of a * string, we check to see if it matches one of the historic * filesystem types. - */ + */ fstypenum = (u_long)SCARG(uap, type); - + for (vfsp = vfsconf; vfsp; vfsp = vfsp->vfc_next) if (vfsp->vfc_typenum == fstypenum) break; @@ -258,7 +258,7 @@ update: MNT_SYNCHRONOUS | MNT_UNION | MNT_ASYNC | MNT_SOFTDEP | MNT_NOATIME | MNT_FORCE); mp->mnt_flag |= SCARG(uap, flags) & (MNT_NOSUID | MNT_NOEXEC | - MNT_NODEV | MNT_SYNCHRONOUS | MNT_UNION | MNT_ASYNC | + MNT_NODEV | MNT_SYNCHRONOUS | MNT_UNION | MNT_ASYNC | MNT_SOFTDEP | MNT_NOATIME | MNT_FORCE); /* * Mount the filesystem. @@ -442,7 +442,7 @@ dounmount(mp, flags, p) if (mp->mnt_syncer != NULL) vgone(mp->mnt_syncer); if (((mp->mnt_flag & MNT_RDONLY) || - (error = VFS_SYNC(mp, MNT_WAIT, p->p_ucred, p)) == 0) || + (error = VFS_SYNC(mp, MNT_WAIT, p->p_ucred, p)) == 0) || (flags & MNT_FORCE)) error = VFS_UNMOUNT(mp, flags, p); simple_lock(&mountlist_slock); @@ -492,7 +492,7 @@ sys_sync(p, v, retval) simple_lock(&mountlist_slock); for (mp = CIRCLEQ_LAST(&mountlist); mp != CIRCLEQ_END(&mountlist); - mp = nmp) { + mp = nmp) { if (vfs_busy(mp, LK_NOWAIT, &mountlist_slock, p)) { nmp = CIRCLEQ_PREV(mp, mnt_list); continue; @@ -657,7 +657,7 @@ sys_getfsstat(p, v, retval) count = 0; simple_lock(&mountlist_slock); for (mp = CIRCLEQ_FIRST(&mountlist); mp != CIRCLEQ_END(&mountlist); - mp = nmp) { + mp = nmp) { if (vfs_busy(mp, LK_NOWAIT, &mountlist_slock, p)) { nmp = CIRCLEQ_NEXT(mp, mnt_list); continue; @@ -669,7 +669,7 @@ sys_getfsstat(p, v, retval) if (flags != MNT_NOWAIT && flags != MNT_LAZY && (flags == MNT_WAIT || - flags == 0) && + flags == 0) && (error = VFS_STATFS(mp, sp, p))) { simple_lock(&mountlist_slock); nmp = CIRCLEQ_NEXT(mp, mnt_list); @@ -737,7 +737,7 @@ sys_fchdir(p, v, retval) error = VOP_ACCESS(vp, VEXEC, p->p_ucred, p); while (!error && (mp = vp->v_mountedhere) != NULL) { - if (vfs_busy(mp, 0, 0, p)) + if (vfs_busy(mp, 0, 0, p)) continue; error = VFS_ROOT(mp, &tdp); vfs_unbusy(mp, p); @@ -969,7 +969,7 @@ sys_getfh(p, v, retval) * Must be super user */ error = suser(p->p_ucred, &p->p_acflag); - if(error) + if (error) return (error); NDINIT(&nd, LOOKUP, FOLLOW | LOCKLEAF, UIO_USERSPACE, SCARG(uap, fname), p); @@ -2036,90 +2036,90 @@ sys_fchown(p, v, retval) struct vattr vattr; int error; struct file *fp; - u_short mode; + u_short mode; - if ((error = getvnode(p->p_fd, SCARG(uap, fd), &fp)) != 0) - return (error); - vp = (struct vnode *)fp->f_data; - VOP_LEASE(vp, p, p->p_ucred, LEASE_WRITE); + if ((error = getvnode(p->p_fd, SCARG(uap, fd), &fp)) != 0) + return (error); + vp = (struct vnode *)fp->f_data; + VOP_LEASE(vp, p, p->p_ucred, LEASE_WRITE); vn_lock(vp, LK_EXCLUSIVE | LK_RETRY, p); - if (vp->v_mount->mnt_flag & MNT_RDONLY) - error = EROFS; - else { + if (vp->v_mount->mnt_flag & MNT_RDONLY) + error = EROFS; + else { if ((SCARG(uap, uid) != -1 || SCARG(uap, gid) != -1) && (suser(p->p_ucred, &p->p_acflag) || suid_clear)) { - error = VOP_GETATTR(vp, &vattr, p->p_ucred, p); - if (error) - goto out; - mode = vattr.va_mode & ~(VSUID | VSGID); - if (mode == vattr.va_mode) - mode = VNOVAL; - } - else - mode = VNOVAL; - VATTR_NULL(&vattr); - vattr.va_uid = SCARG(uap, uid); - vattr.va_gid = SCARG(uap, gid); - vattr.va_mode = mode; - error = VOP_SETATTR(vp, &vattr, p->p_ucred, p); - } + error = VOP_GETATTR(vp, &vattr, p->p_ucred, p); + if (error) + goto out; + mode = vattr.va_mode & ~(VSUID | VSGID); + if (mode == vattr.va_mode) + mode = VNOVAL; + } else + mode = VNOVAL; + VATTR_NULL(&vattr); + vattr.va_uid = SCARG(uap, uid); + vattr.va_gid = SCARG(uap, gid); + vattr.va_mode = mode; + error = VOP_SETATTR(vp, &vattr, p->p_ucred, p); + } out: - VOP_UNLOCK(vp, 0, p); - return (error); + VOP_UNLOCK(vp, 0, p); + return (error); } + /* * Set the access and modification times given a path name. */ /* ARGSUSED */ int sys_utimes(p, v, retval) - struct proc *p; - void *v; - register_t *retval; + struct proc *p; + void *v; + register_t *retval; { - register struct sys_utimes_args /* { - syscallarg(char *) path; - syscallarg(struct timeval *) tptr; - } */ *uap = v; - register struct vnode *vp; - struct timeval tv[2]; - struct vattr vattr; - int error; - struct nameidata nd; - - VATTR_NULL(&vattr); - if (SCARG(uap, tptr) == NULL) { - microtime(&tv[0]); - tv[1] = tv[0]; - vattr.va_vaflags |= VA_UTIMES_NULL; - } else { - error = copyin((caddr_t)SCARG(uap, tptr), (caddr_t)tv, - sizeof (tv)); - if (error) - return (error); + register struct sys_utimes_args /* { + syscallarg(char *) path; + syscallarg(struct timeval *) tptr; + } */ *uap = v; + register struct vnode *vp; + struct timeval tv[2]; + struct vattr vattr; + int error; + struct nameidata nd; + + VATTR_NULL(&vattr); + if (SCARG(uap, tptr) == NULL) { + microtime(&tv[0]); + tv[1] = tv[0]; + vattr.va_vaflags |= VA_UTIMES_NULL; + } else { + error = copyin((caddr_t)SCARG(uap, tptr), (caddr_t)tv, + sizeof (tv)); + if (error) + return (error); /* XXX workaround timeval matching the VFS constant VNOVAL */ if (tv[0].tv_sec == VNOVAL) tv[0].tv_sec = VNOVAL - 1; if (tv[1].tv_sec == VNOVAL) tv[1].tv_sec = VNOVAL - 1; - } - NDINIT(&nd, LOOKUP, FOLLOW, UIO_USERSPACE, SCARG(uap, path), p); - if ((error = namei(&nd)) != 0) - return (error); - vp = nd.ni_vp; - VOP_LEASE(vp, p, p->p_ucred, LEASE_WRITE); + } + NDINIT(&nd, LOOKUP, FOLLOW, UIO_USERSPACE, SCARG(uap, path), p); + if ((error = namei(&nd)) != 0) + return (error); + vp = nd.ni_vp; + VOP_LEASE(vp, p, p->p_ucred, LEASE_WRITE); vn_lock(vp, LK_EXCLUSIVE | LK_RETRY, p); - if (vp->v_mount->mnt_flag & MNT_RDONLY) - error = EROFS; - else { - vattr.va_atime.tv_sec = tv[0].tv_sec; - vattr.va_atime.tv_nsec = tv[0].tv_usec * 1000; - vattr.va_mtime.tv_sec = tv[1].tv_sec; - vattr.va_mtime.tv_nsec = tv[1].tv_usec * 1000; - error = VOP_SETATTR(vp, &vattr, p->p_ucred, p); - } + if (vp->v_mount->mnt_flag & MNT_RDONLY) + error = EROFS; + else { + vattr.va_atime.tv_sec = tv[0].tv_sec; + vattr.va_atime.tv_nsec = tv[0].tv_usec * 1000; + vattr.va_mtime.tv_sec = tv[1].tv_sec; + vattr.va_mtime.tv_nsec = tv[1].tv_usec * 1000; + error = VOP_SETATTR(vp, &vattr, p->p_ucred, p); + } vput(vp); - return (error); + return (error); } @@ -2150,7 +2150,7 @@ sys_futimes(p, v, retval) vattr.va_vaflags |= VA_UTIMES_NULL; } else { error = copyin((caddr_t)SCARG(uap, tptr), (caddr_t)tv, - sizeof (tv)); + sizeof (tv)); if (error) return (error); /* XXX workaround timeval matching the VFS constant VNOVAL */ @@ -2311,14 +2311,14 @@ sys_rename(p, v, retval) fvp = fromnd.ni_vp; flags = LOCKPARENT | LOCKLEAF | NOCACHE | SAVESTART; - /* + /* * rename("foo/", "bar/"); is OK */ if (fvp->v_type == VDIR) flags |= STRIPSLASHES; NDINIT(&tond, RENAME, flags, - UIO_USERSPACE, SCARG(uap, to), p); + UIO_USERSPACE, SCARG(uap, to), p); if ((error = namei(&tond)) != 0) { VOP_ABORTOP(fromnd.ni_dvp, &fromnd.ni_cnd); vrele(fromnd.ni_dvp); @@ -2401,9 +2401,8 @@ sys_mkdir(p, v, retval) int error; struct nameidata nd; - - NDINIT(&nd, CREATE, LOCKPARENT | STRIPSLASHES, - UIO_USERSPACE, SCARG(uap, path), p); + NDINIT(&nd, CREATE, LOCKPARENT | STRIPSLASHES, + UIO_USERSPACE, SCARG(uap, path), p); if ((error = namei(&nd)) != 0) return (error); vp = nd.ni_vp; @@ -2628,52 +2627,52 @@ getvnode(fdp, fd, fpp) */ int sys_pread(p, v, retval) - struct proc *p; - void *v; - register_t *retval; + struct proc *p; + void *v; + register_t *retval; { - struct sys_pread_args /* { - syscallarg(int) fd; - syscallarg(void *) buf; - syscallarg(size_t) nbyte; - syscallarg(int) pad; - syscallarg(off_t) offset; - } */ *uap = v; - struct filedesc *fdp = p->p_fd; - struct file *fp; - struct vnode *vp; - off_t offset; - int error, fd = SCARG(uap, fd); - - if ((u_int)fd >= fdp->fd_nfiles || - (fp = fdp->fd_ofiles[fd]) == NULL || + struct sys_pread_args /* { + syscallarg(int) fd; + syscallarg(void *) buf; + syscallarg(size_t) nbyte; + syscallarg(int) pad; + syscallarg(off_t) offset; + } */ *uap = v; + struct filedesc *fdp = p->p_fd; + struct file *fp; + struct vnode *vp; + off_t offset; + int error, fd = SCARG(uap, fd); + + if ((u_int)fd >= fdp->fd_nfiles || + (fp = fdp->fd_ofiles[fd]) == NULL || #if notyet - (fp->f_iflags & FIF_WANTCLOSE) != 0 || + (fp->f_iflags & FIF_WANTCLOSE) != 0 || #endif - (fp->f_flag & FREAD) == 0) - return (EBADF); + (fp->f_flag & FREAD) == 0) + return (EBADF); #if notyet - FILE_USE(fp); + FILE_USE(fp); #endif - vp = (struct vnode *)fp->f_data; - if (fp->f_type != DTYPE_VNODE || vp->v_type == VFIFO) { - error = ESPIPE; - goto out; - } + vp = (struct vnode *)fp->f_data; + if (fp->f_type != DTYPE_VNODE || vp->v_type == VFIFO) { + error = ESPIPE; + goto out; + } - offset = SCARG(uap, offset); + offset = SCARG(uap, offset); - /* dofileread() will unuse the descriptor for us */ - return (dofileread(p, fd, fp, SCARG(uap, buf), SCARG(uap, nbyte), - &offset, retval)); + /* dofileread() will unuse the descriptor for us */ + return (dofileread(p, fd, fp, SCARG(uap, buf), SCARG(uap, nbyte), + &offset, retval)); out: #if notyet - FILE_UNUSE(fp, p); + FILE_UNUSE(fp, p); #endif - return (error); + return (error); } /* @@ -2681,52 +2680,52 @@ sys_pread(p, v, retval) */ int sys_preadv(p, v, retval) - struct proc *p; - void *v; - register_t *retval; + struct proc *p; + void *v; + register_t *retval; { - struct sys_preadv_args /* { - syscallarg(int) fd; - syscallarg(const struct iovec *) iovp; - syscallarg(int) iovcnt; - syscallarg(int) pad; - syscallarg(off_t) offset; - } */ *uap = v; - struct filedesc *fdp = p->p_fd; - struct file *fp; - struct vnode *vp; - off_t offset; - int error, fd = SCARG(uap, fd); - - if ((u_int)fd >= fdp->fd_nfiles || - (fp = fdp->fd_ofiles[fd]) == NULL || + struct sys_preadv_args /* { + syscallarg(int) fd; + syscallarg(const struct iovec *) iovp; + syscallarg(int) iovcnt; + syscallarg(int) pad; + syscallarg(off_t) offset; + } */ *uap = v; + struct filedesc *fdp = p->p_fd; + struct file *fp; + struct vnode *vp; + off_t offset; + int error, fd = SCARG(uap, fd); + + if ((u_int)fd >= fdp->fd_nfiles || + (fp = fdp->fd_ofiles[fd]) == NULL || #if notyet - (fp->f_iflags & FIF_WANTCLOSE) != 0 || + (fp->f_iflags & FIF_WANTCLOSE) != 0 || #endif - (fp->f_flag & FREAD) == 0) - return (EBADF); + (fp->f_flag & FREAD) == 0) + return (EBADF); #if notyet - FILE_USE(fp); + FILE_USE(fp); #endif - vp = (struct vnode *)fp->f_data; - if (fp->f_type != DTYPE_VNODE || vp->v_type == VFIFO) { - error = ESPIPE; - goto out; - } + vp = (struct vnode *)fp->f_data; + if (fp->f_type != DTYPE_VNODE || vp->v_type == VFIFO) { + error = ESPIPE; + goto out; + } - offset = SCARG(uap, offset); + offset = SCARG(uap, offset); - /* dofilereadv() will unuse the descriptor for us */ - return (dofilereadv(p, fd, fp, SCARG(uap, iovp), SCARG(uap, iovcnt), - &offset, retval)); + /* dofilereadv() will unuse the descriptor for us */ + return (dofilereadv(p, fd, fp, SCARG(uap, iovp), SCARG(uap, iovcnt), + &offset, retval)); out: #if notyet - FILE_UNUSE(fp, p); + FILE_UNUSE(fp, p); #endif - return (error); + return (error); } /* @@ -2734,52 +2733,52 @@ sys_preadv(p, v, retval) */ int sys_pwrite(p, v, retval) - struct proc *p; - void *v; - register_t *retval; + struct proc *p; + void *v; + register_t *retval; { - struct sys_pwrite_args /* { - syscallarg(int) fd; - syscallarg(const void *) buf; - syscallarg(size_t) nbyte; - syscallarg(int) pad; - syscallarg(off_t) offset; - } */ *uap = v; - struct filedesc *fdp = p->p_fd; - struct file *fp; - struct vnode *vp; - off_t offset; - int error, fd = SCARG(uap, fd); - - if ((u_int)fd >= fdp->fd_nfiles || - (fp = fdp->fd_ofiles[fd]) == NULL || + struct sys_pwrite_args /* { + syscallarg(int) fd; + syscallarg(const void *) buf; + syscallarg(size_t) nbyte; + syscallarg(int) pad; + syscallarg(off_t) offset; + } */ *uap = v; + struct filedesc *fdp = p->p_fd; + struct file *fp; + struct vnode *vp; + off_t offset; + int error, fd = SCARG(uap, fd); + + if ((u_int)fd >= fdp->fd_nfiles || + (fp = fdp->fd_ofiles[fd]) == NULL || #if notyet - (fp->f_iflags & FIF_WANTCLOSE) != 0 || + (fp->f_iflags & FIF_WANTCLOSE) != 0 || #endif - (fp->f_flag & FWRITE) == 0) - return (EBADF); + (fp->f_flag & FWRITE) == 0) + return (EBADF); #if notyet - FILE_USE(fp); + FILE_USE(fp); #endif - vp = (struct vnode *)fp->f_data; - if (fp->f_type != DTYPE_VNODE || vp->v_type == VFIFO) { - error = ESPIPE; - goto out; - } + vp = (struct vnode *)fp->f_data; + if (fp->f_type != DTYPE_VNODE || vp->v_type == VFIFO) { + error = ESPIPE; + goto out; + } - offset = SCARG(uap, offset); + offset = SCARG(uap, offset); - /* dofilewrite() will unuse the descriptor for us */ - return (dofilewrite(p, fd, fp, SCARG(uap, buf), SCARG(uap, nbyte), - &offset, retval)); + /* dofilewrite() will unuse the descriptor for us */ + return (dofilewrite(p, fd, fp, SCARG(uap, buf), SCARG(uap, nbyte), + &offset, retval)); out: #if notyet - FILE_UNUSE(fp, p); + FILE_UNUSE(fp, p); #endif - return (error); + return (error); } @@ -2788,50 +2787,49 @@ sys_pwrite(p, v, retval) */ int sys_pwritev(p, v, retval) - struct proc *p; - void *v; - register_t *retval; + struct proc *p; + void *v; + register_t *retval; { - struct sys_pwritev_args /* { - syscallarg(int) fd; - syscallarg(const struct iovec *) iovp; - syscallarg(int) iovcnt; - syscallarg(int) pad; - syscallarg(off_t) offset; - } */ *uap = v; - struct filedesc *fdp = p->p_fd; - struct file *fp; - struct vnode *vp; - off_t offset; - int error, fd = SCARG(uap, fd); - - if ((u_int)fd >= fdp->fd_nfiles || - (fp = fdp->fd_ofiles[fd]) == NULL || + struct sys_pwritev_args /* { + syscallarg(int) fd; + syscallarg(const struct iovec *) iovp; + syscallarg(int) iovcnt; + syscallarg(int) pad; + syscallarg(off_t) offset; + } */ *uap = v; + struct filedesc *fdp = p->p_fd; + struct file *fp; + struct vnode *vp; + off_t offset; + int error, fd = SCARG(uap, fd); + + if ((u_int)fd >= fdp->fd_nfiles || + (fp = fdp->fd_ofiles[fd]) == NULL || #if notyet - (fp->f_iflags & FIF_WANTCLOSE) != 0 || + (fp->f_iflags & FIF_WANTCLOSE) != 0 || #endif - (fp->f_flag & FWRITE) == 0) - return (EBADF); + (fp->f_flag & FWRITE) == 0) + return (EBADF); #if notyet - FILE_USE(fp); + FILE_USE(fp); #endif - vp = (struct vnode *)fp->f_data; - if (fp->f_type != DTYPE_VNODE || vp->v_type == VFIFO) { - error = ESPIPE; - goto out; - } + vp = (struct vnode *)fp->f_data; + if (fp->f_type != DTYPE_VNODE || vp->v_type == VFIFO) { + error = ESPIPE; + goto out; + } - offset = SCARG(uap, offset); + offset = SCARG(uap, offset); - /* dofilewritev() will unuse the descriptor for us */ - return (dofilewritev(p, fd, fp, SCARG(uap, iovp), SCARG(uap, iovcnt), - &offset, retval)); + /* dofilewritev() will unuse the descriptor for us */ + return (dofilewritev(p, fd, fp, SCARG(uap, iovp), SCARG(uap, iovcnt), + &offset, retval)); out: #if notyet - FILE_UNUSE(fp, p); + FILE_UNUSE(fp, p); #endif - return (error); + return (error); } - |