Make everything compile with -Wtraditional. Make it easier to distribute
[unix-history] / sys / ufs / ufs_vnops.c
index 39d705f..d33c142 100644 (file)
@@ -31,7 +31,7 @@
  * SUCH DAMAGE.
  *
  *     from: @(#)ufs_vnops.c   7.64 (Berkeley) 5/16/91
  * SUCH DAMAGE.
  *
  *     from: @(#)ufs_vnops.c   7.64 (Berkeley) 5/16/91
- *     $Id$
+ *     $Id: ufs_vnops.c,v 1.8 1993/11/25 01:38:40 wollman Exp $
  */
 
 #include "param.h"
  */
 
 #include "param.h"
 #include "dir.h"
 #include "fs.h"
 
 #include "dir.h"
 #include "fs.h"
 
+/* Get the current value of _POSIX_CHOWN_RESTRICTED */
+#include "sys/unistd.h"                /* make sure to get sys/ version. */
+
+static int maknode(int, struct nameidata *, struct inode **);
+
+/* XXX - don't want to change ucred.h again */
+extern int groupmember(int /*gid_t*/, struct ucred *);
+
 /*
  * Create a regular file
  */
 /*
  * Create a regular file
  */
+int
 ufs_create(ndp, vap, p)
        struct nameidata *ndp;
        struct vattr *vap;
 ufs_create(ndp, vap, p)
        struct nameidata *ndp;
        struct vattr *vap;
@@ -77,6 +86,7 @@ ufs_create(ndp, vap, p)
  * Mknod vnode call
  */
 /* ARGSUSED */
  * Mknod vnode call
  */
 /* ARGSUSED */
+int
 ufs_mknod(ndp, vap, cred, p)
        struct nameidata *ndp;
        struct ucred *cred;
 ufs_mknod(ndp, vap, cred, p)
        struct nameidata *ndp;
        struct ucred *cred;
@@ -115,6 +125,7 @@ ufs_mknod(ndp, vap, cred, p)
  * Nothing to do.
  */
 /* ARGSUSED */
  * Nothing to do.
  */
 /* ARGSUSED */
+int
 ufs_open(vp, mode, cred, p)
        struct vnode *vp;
        int mode;
 ufs_open(vp, mode, cred, p)
        struct vnode *vp;
        int mode;
@@ -131,6 +142,7 @@ ufs_open(vp, mode, cred, p)
  * Update the times on the inode.
  */
 /* ARGSUSED */
  * Update the times on the inode.
  */
 /* ARGSUSED */
+int
 ufs_close(vp, fflag, cred, p)
        struct vnode *vp;
        int fflag;
 ufs_close(vp, fflag, cred, p)
        struct vnode *vp;
        int fflag;
@@ -149,6 +161,7 @@ ufs_close(vp, fflag, cred, p)
  * The mode is shifted to select the owner/group/other fields. The
  * super user is granted all permissions.
  */
  * The mode is shifted to select the owner/group/other fields. The
  * super user is granted all permissions.
  */
+int
 ufs_access(vp, mode, cred, p)
        struct vnode *vp;
        register int mode;
 ufs_access(vp, mode, cred, p)
        struct vnode *vp;
        register int mode;
@@ -200,6 +213,7 @@ found:
 }
 
 /* ARGSUSED */
 }
 
 /* ARGSUSED */
+int
 ufs_getattr(vp, vap, cred, p)
        struct vnode *vp;
        register struct vattr *vap;
 ufs_getattr(vp, vap, cred, p)
        struct vnode *vp;
        register struct vattr *vap;
@@ -249,6 +263,7 @@ ufs_getattr(vp, vap, cred, p)
 /*
  * Set attribute vnode op. called from several syscalls
  */
 /*
  * Set attribute vnode op. called from several syscalls
  */
+int
 ufs_setattr(vp, vap, cred, p)
        register struct vnode *vp;
        register struct vattr *vap;
 ufs_setattr(vp, vap, cred, p)
        register struct vnode *vp;
        register struct vattr *vap;
@@ -300,7 +315,7 @@ ufs_setattr(vp, vap, cred, p)
                if (cred->cr_uid == 0) {
                        ip->i_flags = vap->va_flags;
                } else {
                if (cred->cr_uid == 0) {
                        ip->i_flags = vap->va_flags;
                } else {
-                       ip->i_flags &= 0xffff0000;
+                       ip->i_flags &= 0xffff0000ul;
                        ip->i_flags |= (vap->va_flags & 0xffff);
                }
                ip->i_flag |= ICHG;
                        ip->i_flags |= (vap->va_flags & 0xffff);
                }
                ip->i_flag |= ICHG;
@@ -312,6 +327,7 @@ ufs_setattr(vp, vap, cred, p)
  * Change the mode on a file.
  * Inode must be locked before calling.
  */
  * Change the mode on a file.
  * Inode must be locked before calling.
  */
+int
 chmod1(vp, mode, p)
        register struct vnode *vp;
        register int mode;
 chmod1(vp, mode, p)
        register struct vnode *vp;
        register int mode;
@@ -342,6 +358,7 @@ chmod1(vp, mode, p)
  * Perform chown operation on inode ip;
  * inode must be locked prior to call.
  */
  * Perform chown operation on inode ip;
  * inode must be locked prior to call.
  */
+int
 chown1(vp, uid, gid, p)
        register struct vnode *vp;
        uid_t uid;
 chown1(vp, uid, gid, p)
        register struct vnode *vp;
        uid_t uid;
@@ -367,10 +384,16 @@ chown1(vp, uid, gid, p)
         * of the file, or are not a member of the target group,
         * the caller must be superuser or the call fails.
         */
         * of the file, or are not a member of the target group,
         * the caller must be superuser or the call fails.
         */
+#ifdef _POSIX_CHOWN_RESTRICTED
        if ((cred->cr_uid != ip->i_uid || uid != ip->i_uid ||
            !groupmember((gid_t)gid, cred)) &&
            (error = suser(cred, &p->p_acflag)))
                return (error);
        if ((cred->cr_uid != ip->i_uid || uid != ip->i_uid ||
            !groupmember((gid_t)gid, cred)) &&
            (error = suser(cred, &p->p_acflag)))
                return (error);
+#else
+       if ((cred->cr_uid != ip->i_uid || !groupmember((gid_t)gid, cred))
+           && (error = suser(cred, &p->p_acflag)))
+               return error;
+#endif
        ouid = ip->i_uid;
        ogid = ip->i_gid;
 #ifdef QUOTA
        ouid = ip->i_uid;
        ogid = ip->i_gid;
 #ifdef QUOTA
@@ -448,6 +471,7 @@ good:
  * Vnode op for reading.
  */
 /* ARGSUSED */
  * Vnode op for reading.
  */
 /* ARGSUSED */
+int
 ufs_read(vp, uio, ioflag, cred)
        struct vnode *vp;
        register struct uio *uio;
 ufs_read(vp, uio, ioflag, cred)
        struct vnode *vp;
        register struct uio *uio;
@@ -510,6 +534,7 @@ ufs_read(vp, uio, ioflag, cred)
 /*
  * Vnode op for writing.
  */
 /*
  * Vnode op for writing.
  */
+int
 ufs_write(vp, uio, ioflag, cred)
        register struct vnode *vp;
        struct uio *uio;
 ufs_write(vp, uio, ioflag, cred)
        register struct vnode *vp;
        struct uio *uio;
@@ -607,6 +632,7 @@ ufs_write(vp, uio, ioflag, cred)
 }
 
 /* ARGSUSED */
 }
 
 /* ARGSUSED */
+int
 ufs_ioctl(vp, com, data, fflag, cred, p)
        struct vnode *vp;
        int com;
 ufs_ioctl(vp, com, data, fflag, cred, p)
        struct vnode *vp;
        int com;
@@ -620,6 +646,7 @@ ufs_ioctl(vp, com, data, fflag, cred, p)
 }
 
 /* ARGSUSED */
 }
 
 /* ARGSUSED */
+int
 ufs_select(vp, which, fflags, cred, p)
        struct vnode *vp;
        int which, fflags;
 ufs_select(vp, which, fflags, cred, p)
        struct vnode *vp;
        int which, fflags;
@@ -639,6 +666,7 @@ ufs_select(vp, which, fflags, cred, p)
  * NB Currently unsupported.
  */
 /* ARGSUSED */
  * NB Currently unsupported.
  */
 /* ARGSUSED */
+int
 ufs_mmap(vp, fflags, cred, p)
        struct vnode *vp;
        int fflags;
 ufs_mmap(vp, fflags, cred, p)
        struct vnode *vp;
        int fflags;
@@ -653,6 +681,7 @@ ufs_mmap(vp, fflags, cred, p)
  * Synch an open file.
  */
 /* ARGSUSED */
  * Synch an open file.
  */
 /* ARGSUSED */
+int
 ufs_fsync(vp, fflags, cred, waitfor, p)
        struct vnode *vp;
        int fflags;
 ufs_fsync(vp, fflags, cred, waitfor, p)
        struct vnode *vp;
        int fflags;
@@ -674,6 +703,7 @@ ufs_fsync(vp, fflags, cred, waitfor, p)
  * Nothing to do, so just return.
  */
 /* ARGSUSED */
  * Nothing to do, so just return.
  */
 /* ARGSUSED */
+int
 ufs_seek(vp, oldoff, newoff, cred)
        struct vnode *vp;
        off_t oldoff, newoff;
 ufs_seek(vp, oldoff, newoff, cred)
        struct vnode *vp;
        off_t oldoff, newoff;
@@ -688,6 +718,7 @@ ufs_seek(vp, oldoff, newoff, cred)
  * Hard to avoid races here, especially
  * in unlinking directories.
  */
  * Hard to avoid races here, especially
  * in unlinking directories.
  */
+int
 ufs_remove(ndp, p)
        struct nameidata *ndp;
        struct proc *p;
 ufs_remove(ndp, p)
        struct nameidata *ndp;
        struct proc *p;
@@ -713,6 +744,7 @@ ufs_remove(ndp, p)
 /*
  * link vnode call
  */
 /*
  * link vnode call
  */
+int
 ufs_link(vp, ndp, p)
        register struct vnode *vp;
        register struct nameidata *ndp;
 ufs_link(vp, ndp, p)
        register struct vnode *vp;
        register struct nameidata *ndp;
@@ -721,7 +753,7 @@ ufs_link(vp, ndp, p)
        register struct inode *ip = VTOI(vp);
        int error;
 
        register struct inode *ip = VTOI(vp);
        int error;
 
-#ifdef DIANOSTIC
+#ifdef DIAGNOSTIC
        if ((ndp->ni_nameiop & HASBUF) == 0)
                panic("ufs_link: no name");
 #endif
        if ((ndp->ni_nameiop & HASBUF) == 0)
                panic("ufs_link: no name");
 #endif
@@ -771,6 +803,7 @@ ufs_link(vp, ndp, p)
  *    is different from the source, patch the ".." entry in the
  *    directory.
  */
  *    is different from the source, patch the ".." entry in the
  *    directory.
  */
+int
 ufs_rename(fndp, tndp, p)
        register struct nameidata *fndp, *tndp;
        struct proc *p;
 ufs_rename(fndp, tndp, p)
        register struct nameidata *fndp, *tndp;
        struct proc *p;
@@ -780,7 +813,7 @@ ufs_rename(fndp, tndp, p)
        int doingdirectory = 0, oldparent = 0, newparent = 0;
        int error = 0;
 
        int doingdirectory = 0, oldparent = 0, newparent = 0;
        int error = 0;
 
-#ifdef DIANOSTIC
+#ifdef DIAGNOSTIC
        if ((tndp->ni_nameiop & HASBUF) == 0 ||
            (fndp->ni_nameiop & HASBUF) == 0)
                panic("ufs_rename: no name");
        if ((tndp->ni_nameiop & HASBUF) == 0 ||
            (fndp->ni_nameiop & HASBUF) == 0)
                panic("ufs_rename: no name");
@@ -1085,6 +1118,7 @@ struct dirtemplate mastertemplate = {
 /*
  * Mkdir system call
  */
 /*
  * Mkdir system call
  */
+int
 ufs_mkdir(ndp, vap, p)
        struct nameidata *ndp;
        struct vattr *vap;
 ufs_mkdir(ndp, vap, p)
        struct nameidata *ndp;
        struct vattr *vap;
@@ -1097,7 +1131,7 @@ ufs_mkdir(ndp, vap, p)
        int error;
        int dmode;
 
        int error;
        int dmode;
 
-#ifdef DIANOSTIC
+#ifdef DIAGNOSTIC
        if ((ndp->ni_nameiop & HASBUF) == 0)
                panic("ufs_mkdir: no name");
 #endif
        if ((ndp->ni_nameiop & HASBUF) == 0)
                panic("ufs_mkdir: no name");
 #endif
@@ -1200,6 +1234,7 @@ bad:
 /*
  * Rmdir system call.
  */
 /*
  * Rmdir system call.
  */
+int
 ufs_rmdir(ndp, p)
        register struct nameidata *ndp;
        struct proc *p;
 ufs_rmdir(ndp, p)
        register struct nameidata *ndp;
        struct proc *p;
@@ -1264,6 +1299,7 @@ out:
 /*
  * symlink -- make a symbolic link
  */
 /*
  * symlink -- make a symbolic link
  */
+int
 ufs_symlink(ndp, vap, target, p)
        struct nameidata *ndp;
        struct vattr *vap;
 ufs_symlink(ndp, vap, target, p)
        struct nameidata *ndp;
        struct vattr *vap;
@@ -1296,6 +1332,7 @@ ufs_symlink(ndp, vap, target, p)
 /*
  * Vnode op for read and write
  */
 /*
  * Vnode op for read and write
  */
+int
 ufs_readdir(vp, uio, cred, eofflagp)
        struct vnode *vp;
        register struct uio *uio;
 ufs_readdir(vp, uio, cred, eofflagp)
        struct vnode *vp;
        register struct uio *uio;
@@ -1323,6 +1360,7 @@ ufs_readdir(vp, uio, cred, eofflagp)
 /*
  * Return target name of a symbolic link
  */
 /*
  * Return target name of a symbolic link
  */
+int
 ufs_readlink(vp, uiop, cred)
        struct vnode *vp;
        struct uio *uiop;
 ufs_readlink(vp, uiop, cred)
        struct vnode *vp;
        struct uio *uiop;
@@ -1340,6 +1378,7 @@ ufs_readlink(vp, uiop, cred)
  * done. If a buffer has been saved in anticipation of a CREATE, delete it.
  */
 /* ARGSUSED */
  * done. If a buffer has been saved in anticipation of a CREATE, delete it.
  */
 /* ARGSUSED */
+int
 ufs_abortop(ndp)
        struct nameidata *ndp;
 {
 ufs_abortop(ndp)
        struct nameidata *ndp;
 {
@@ -1352,6 +1391,7 @@ ufs_abortop(ndp)
 /*
  * Lock an inode.
  */
 /*
  * Lock an inode.
  */
+int
 ufs_lock(vp)
        struct vnode *vp;
 {
 ufs_lock(vp)
        struct vnode *vp;
 {
@@ -1364,6 +1404,7 @@ ufs_lock(vp)
 /*
  * Unlock an inode.
  */
 /*
  * Unlock an inode.
  */
+int
 ufs_unlock(vp)
        struct vnode *vp;
 {
 ufs_unlock(vp)
        struct vnode *vp;
 {
@@ -1378,6 +1419,7 @@ ufs_unlock(vp)
 /*
  * Check for a locked inode.
  */
 /*
  * Check for a locked inode.
  */
+int
 ufs_islocked(vp)
        struct vnode *vp;
 {
 ufs_islocked(vp)
        struct vnode *vp;
 {
@@ -1390,6 +1432,7 @@ ufs_islocked(vp)
 /*
  * Get access to bmap
  */
 /*
  * Get access to bmap
  */
+int
 ufs_bmap(vp, bn, vpp, bnp)
        struct vnode *vp;
        daddr_t bn;
 ufs_bmap(vp, bn, vpp, bnp)
        struct vnode *vp;
        daddr_t bn;
@@ -1411,6 +1454,7 @@ ufs_bmap(vp, bn, vpp, bnp)
  */
 int checkoverlap = 0;
 
  */
 int checkoverlap = 0;
 
+int
 ufs_strategy(bp)
        register struct buf *bp;
 {
 ufs_strategy(bp)
        register struct buf *bp;
 {
@@ -1468,6 +1512,7 @@ ufs_strategy(bp)
 /*
  * Print out the contents of an inode.
  */
 /*
  * Print out the contents of an inode.
  */
+void
 ufs_print(vp)
        struct vnode *vp;
 {
 ufs_print(vp)
        struct vnode *vp;
 {
@@ -1491,6 +1536,7 @@ ufs_print(vp)
 /*
  * Read wrapper for special devices.
  */
 /*
  * Read wrapper for special devices.
  */
+int
 ufsspec_read(vp, uio, ioflag, cred)
        struct vnode *vp;
        struct uio *uio;
 ufsspec_read(vp, uio, ioflag, cred)
        struct vnode *vp;
        struct uio *uio;
@@ -1508,6 +1554,7 @@ ufsspec_read(vp, uio, ioflag, cred)
 /*
  * Write wrapper for special devices.
  */
 /*
  * Write wrapper for special devices.
  */
+int
 ufsspec_write(vp, uio, ioflag, cred)
        struct vnode *vp;
        struct uio *uio;
 ufsspec_write(vp, uio, ioflag, cred)
        struct vnode *vp;
        struct uio *uio;
@@ -1527,6 +1574,7 @@ ufsspec_write(vp, uio, ioflag, cred)
  *
  * Update the times on the inode then do device close.
  */
  *
  * Update the times on the inode then do device close.
  */
+int
 ufsspec_close(vp, fflag, cred, p)
        struct vnode *vp;
        int fflag;
 ufsspec_close(vp, fflag, cred, p)
        struct vnode *vp;
        int fflag;
@@ -1544,6 +1592,7 @@ ufsspec_close(vp, fflag, cred, p)
 /*
  * Read wrapper for fifo's
  */
 /*
  * Read wrapper for fifo's
  */
+int
 ufsfifo_read(vp, uio, ioflag, cred)
        struct vnode *vp;
        struct uio *uio;
 ufsfifo_read(vp, uio, ioflag, cred)
        struct vnode *vp;
        struct uio *uio;
@@ -1561,6 +1610,7 @@ ufsfifo_read(vp, uio, ioflag, cred)
 /*
  * Write wrapper for fifo's.
  */
 /*
  * Write wrapper for fifo's.
  */
+int
 ufsfifo_write(vp, uio, ioflag, cred)
        struct vnode *vp;
        struct uio *uio;
 ufsfifo_write(vp, uio, ioflag, cred)
        struct vnode *vp;
        struct uio *uio;
@@ -1580,6 +1630,7 @@ ufsfifo_write(vp, uio, ioflag, cred)
  *
  * Update the times on the inode then do device close.
  */
  *
  * Update the times on the inode then do device close.
  */
+int
 ufsfifo_close(vp, fflag, cred, p)
        struct vnode *vp;
        int fflag;
 ufsfifo_close(vp, fflag, cred, p)
        struct vnode *vp;
        int fflag;
@@ -1597,6 +1648,7 @@ ufsfifo_close(vp, fflag, cred, p)
 /*
  * Allocate a new inode.
  */
 /*
  * Allocate a new inode.
  */
+static int
 maknode(mode, ndp, ipp)
        int mode;
        register struct nameidata *ndp;
 maknode(mode, ndp, ipp)
        int mode;
        register struct nameidata *ndp;
@@ -1608,7 +1660,7 @@ maknode(mode, ndp, ipp)
        ino_t ipref;
        int error;
 
        ino_t ipref;
        int error;
 
-#ifdef DIANOSTIC
+#ifdef DIAGNOSTIC
        if ((ndp->ni_nameiop & HASBUF) == 0)
                panic("maknode: no name");
 #endif
        if ((ndp->ni_nameiop & HASBUF) == 0)
                panic("maknode: no name");
 #endif
@@ -1674,6 +1726,7 @@ bad:
 /*
  * Advisory record locking support
  */
 /*
  * Advisory record locking support
  */
+int
 ufs_advlock(vp, id, op, fl, flags)
        struct vnode *vp;
        caddr_t id;
 ufs_advlock(vp, id, op, fl, flags)
        struct vnode *vp;
        caddr_t id;
@@ -1682,80 +1735,8 @@ ufs_advlock(vp, id, op, fl, flags)
        int flags;
 {
        register struct inode *ip = VTOI(vp);
        int flags;
 {
        register struct inode *ip = VTOI(vp);
-       register struct lockf *lock;
-       off_t start, end;
-       int error;
-
-       /*
-        * Avoid the common case of unlocking when inode has no locks.
-        */
-       if (ip->i_lockf == (struct lockf *)0) {
-               if (op != F_SETLK) {
-                       fl->l_type = F_UNLCK;
-                       return (0);
-               }
-       }
-       /*
-        * Convert the flock structure into a start and end.
-        */
-       switch (fl->l_whence) {
-
-       case SEEK_SET:
-       case SEEK_CUR:
-               /*
-                * Caller is responsible for adding any necessary offset
-                * when SEEK_CUR is used.
-                */
-               start = fl->l_start;
-               break;
-
-       case SEEK_END:
-               start = ip->i_size + fl->l_start;
-               break;
-
-       default:
-               return (EINVAL);
-       }
-       if (start < 0)
-               return (EINVAL);
-       if (fl->l_len == 0)
-               end = -1;
-       else
-               end = start + fl->l_len - 1;
-       /*
-        * Create the lockf structure
-        */
-       MALLOC(lock, struct lockf *, sizeof *lock, M_LOCKF, M_WAITOK);
-       lock->lf_start = start;
-       lock->lf_end = end;
-       lock->lf_id = id;
-       lock->lf_inode = ip;
-       lock->lf_type = fl->l_type;
-       lock->lf_next = (struct lockf *)0;
-       lock->lf_block = (struct lockf *)0;
-       lock->lf_flags = flags;
-       /*
-        * Do the requested operation.
-        */
-       switch(op) {
-       case F_SETLK:
-               return (lf_setlock(lock));
-
-       case F_UNLCK:
-               error = lf_clearlock(lock);
-               FREE(lock, M_LOCKF);
-               return (error);
 
 
-       case F_GETLK:
-               error = lf_getlock(lock, fl);
-               FREE(lock, M_LOCKF);
-               return (error);
-       
-       default:
-               free(lock, M_LOCKF);
-               return (EINVAL);
-       }
-       /* NOTREACHED */
+       return (lf_advlock(&(ip->i_lockf), ip->i_size, id, op, fl, flags));
 }
 
 /*
 }
 
 /*