ufs_chown and ufs_chmod now take cred pointers
[unix-history] / usr / src / sys / ufs / ffs / ufs_vnops.c
index 638eb1f..1905d54 100644 (file)
@@ -4,7 +4,7 @@
  *
  * %sccs.include.redist.c%
  *
  *
  * %sccs.include.redist.c%
  *
- *     @(#)ufs_vnops.c 7.75 (Berkeley) %G%
+ *     @(#)ufs_vnops.c 7.84 (Berkeley) %G%
  */
 
 #include <sys/param.h>
  */
 
 #include <sys/param.h>
 #include <ufs/ufs/ufsmount.h>
 #include <ufs/ufs/ufs_extern.h>
 
 #include <ufs/ufs/ufsmount.h>
 #include <ufs/ufs/ufs_extern.h>
 
-int ufs_chmod __P((struct vnode *, int, struct proc *));
-int ufs_chown __P((struct vnode *, u_int, u_int, struct proc *));
-
-enum vtype iftovt_tab[16] = {
-       VNON, VFIFO, VCHR, VNON, VDIR, VNON, VBLK, VNON,
-       VREG, VNON, VLNK, VNON, VSOCK, VNON, VNON, VBAD,
-};
-int    vttoif_tab[9] = {
-       0, IFREG, IFDIR, IFBLK, IFCHR, IFLNK, IFSOCK, IFIFO, IFMT,
-};
+int ufs_chmod __P((struct vnode *, int, struct ucred *, struct proc *));
+int ufs_chown
+       __P((struct vnode *, u_int, u_int, struct ucred *, struct proc *));
 
 #ifdef _NOQUAD
 #define        SETHIGH(q, h)   (q).val[_QUAD_HIGHWORD] = (h)
 
 #ifdef _NOQUAD
 #define        SETHIGH(q, h)   (q).val[_QUAD_HIGHWORD] = (h)
@@ -291,7 +284,7 @@ ufs_setattr(vp, vap, cred, p)
         * Go through the fields and update iff not VNOVAL.
         */
        if (vap->va_uid != (u_short)VNOVAL || vap->va_gid != (u_short)VNOVAL)
         * Go through the fields and update iff not VNOVAL.
         */
        if (vap->va_uid != (u_short)VNOVAL || vap->va_gid != (u_short)VNOVAL)
-               if (error = ufs_chown(vp, vap->va_uid, vap->va_gid, p))
+               if (error = ufs_chown(vp, vap->va_uid, vap->va_gid, cred, p))
                        return (error);
        if (vap->va_size != VNOVAL) {
                if (vp->v_type == VDIR)
                        return (error);
        if (vap->va_size != VNOVAL) {
                if (vp->v_type == VDIR)
@@ -314,7 +307,7 @@ ufs_setattr(vp, vap, cred, p)
        }
        error = 0;
        if (vap->va_mode != (u_short)VNOVAL)
        }
        error = 0;
        if (vap->va_mode != (u_short)VNOVAL)
-               error = ufs_chmod(vp, (int)vap->va_mode, p);
+               error = ufs_chmod(vp, (int)vap->va_mode, cred, p);
        if (vap->va_flags != VNOVAL) {
                if (cred->cr_uid != ip->i_uid &&
                    (error = suser(cred, &p->p_acflag)))
        if (vap->va_flags != VNOVAL) {
                if (cred->cr_uid != ip->i_uid &&
                    (error = suser(cred, &p->p_acflag)))
@@ -335,12 +328,12 @@ ufs_setattr(vp, vap, cred, p)
  * Inode must be locked before calling.
  */
 static int
  * Inode must be locked before calling.
  */
 static int
-ufs_chmod(vp, mode, p)
+ufs_chmod(vp, mode, cred, p)
        register struct vnode *vp;
        register int mode;
        register struct vnode *vp;
        register int mode;
+       register struct ucred *cred;
        struct proc *p;
 {
        struct proc *p;
 {
-       register struct ucred *cred = p->p_ucred;
        register struct inode *ip = VTOI(vp);
        int error;
 
        register struct inode *ip = VTOI(vp);
        int error;
 
@@ -366,14 +359,14 @@ ufs_chmod(vp, mode, p)
  * inode must be locked prior to call.
  */
 static int
  * inode must be locked prior to call.
  */
 static int
-ufs_chown(vp, uid, gid, p)
+ufs_chown(vp, uid, gid, cred, p)
        register struct vnode *vp;
        u_int uid;
        u_int gid;
        register struct vnode *vp;
        u_int uid;
        u_int gid;
+       struct ucred *cred;
        struct proc *p;
 {
        register struct inode *ip = VTOI(vp);
        struct proc *p;
 {
        register struct inode *ip = VTOI(vp);
-       register struct ucred *cred = p->p_ucred;
        uid_t ouid;
        gid_t ogid;
        int error = 0;
        uid_t ouid;
        gid_t ogid;
        int error = 0;
@@ -562,9 +555,9 @@ ufs_remove(dvp, vp, cnp)
  * link vnode call
  */
 int
  * link vnode call
  */
 int
-ufs_link(vp, tdvp, cnp)
-       register struct vnode *vp;   /* source vnode */
+ufs_link(tdvp, vp, cnp)
        struct vnode *tdvp;
        struct vnode *tdvp;
+       register struct vnode *vp;   /* source vnode */
        struct componentname *cnp;
 {
        register struct inode *ip;
        struct componentname *cnp;
 {
        register struct inode *ip;
@@ -686,11 +679,7 @@ relookup(dvp, vpp, cnp)
                if (*vpp != NULL)
                        panic("leaf should be empty");
 #endif
                if (*vpp != NULL)
                        panic("leaf should be empty");
 #endif
-#ifdef NAMEI_DIAGNOSTIC
-               printf("not found\n");
-#endif
-               if (cnp->cn_nameiop == LOOKUP || cnp->cn_nameiop == DELETE ||
-                   error != ENOENT)
+               if (error != EJUSTRETURN)
                        goto bad;
                /*
                 * If creating and at end of pathname, then can consider
                        goto bad;
                /*
                 * If creating and at end of pathname, then can consider
@@ -710,26 +699,16 @@ relookup(dvp, vpp, cnp)
                 */
                return (0);
        }
                 */
                return (0);
        }
-#ifdef NAMEI_DIAGNOSTIC
-       printf("found\n");
-#endif
-
        dp = *vpp;
        dp = *vpp;
+
 #ifdef DIAGNOSTIC
        /*
         * Check for symbolic link
         */
 #ifdef DIAGNOSTIC
        /*
         * Check for symbolic link
         */
-       if (dp->v_type == VLNK) {
+       if (dp->v_type == VLNK && (cnp->cn_flags & FOLLOW))
                panic ("relookup: symlink found.\n");
                panic ("relookup: symlink found.\n");
-       };
-
-       /*
-        * Check to see if the vnode has been mounted on;
-        * if so find the root of the mounted file system.
-        */
 #endif
 
 #endif
 
-
 nextname:
        /*
         * Check for read-only file systems.
 nextname:
        /*
         * Check for read-only file systems.
@@ -1062,7 +1041,7 @@ unlinkit:
                                if (dirbuf.dotdot_namlen != 2 ||
                                    dirbuf.dotdot_name[0] != '.' ||
                                    dirbuf.dotdot_name[1] != '.') {
                                if (dirbuf.dotdot_namlen != 2 ||
                                    dirbuf.dotdot_name[0] != '.' ||
                                    dirbuf.dotdot_name[1] != '.') {
-                                       ufs_dirbad(xp, 12,
+                                       ufs_dirbad(xp, (doff_t)12,
                                            "rename: mangled dir");
                                } else {
                                        dirbuf.dotdot_ino = newparent;
                                            "rename: mangled dir");
                                } else {
                                        dirbuf.dotdot_ino = newparent;
@@ -1309,7 +1288,13 @@ ufs_symlink(dvp, vpp, cnp, vap, target)
 }
 
 /*
 }
 
 /*
- * Vnode op for read and write
+ * Vnode op for reading directories.
+ * 
+ * The routine below assumes that the on-disk format of a directory
+ * is the same as that defined by <sys/dirent.h>. If the on-disk
+ * format changes, then it will be necessary to do a conversion
+ * from the on-disk format that read returns to the format defined
+ * by <sys/dirent.h>.
  */
 int
 ufs_readdir(vp, uio, cred, eofflagp)
  */
 int
 ufs_readdir(vp, uio, cred, eofflagp)
@@ -1409,8 +1394,6 @@ ufs_islocked(vp)
  * Calculate the logical to physical mapping if not done already,
  * then call the device strategy routine.
  */
  * Calculate the logical to physical mapping if not done already,
  * then call the device strategy routine.
  */
-int checkoverlap = 0;
-
 int
 ufs_strategy(bp)
        register struct buf *bp;
 int
 ufs_strategy(bp)
        register struct buf *bp;
@@ -1424,8 +1407,12 @@ ufs_strategy(bp)
                panic("ufs_strategy: spec");
        if (bp->b_blkno == bp->b_lblkno) {
                if (error =
                panic("ufs_strategy: spec");
        if (bp->b_blkno == bp->b_lblkno) {
                if (error =
-                   VOP_BMAP(bp->b_vp, bp->b_lblkno, NULL, &bp->b_blkno))
+                   VOP_BMAP(bp->b_vp, bp->b_lblkno, NULL, &bp->b_blkno)) {
+                       bp->b_error = error;
+                       bp->b_flags |= B_ERROR;
+                       biodone(bp);
                        return (error);
                        return (error);
+               }
                if ((long)bp->b_blkno == -1)
                        clrbuf(bp);
        }
                if ((long)bp->b_blkno == -1)
                        clrbuf(bp);
        }
@@ -1433,11 +1420,6 @@ ufs_strategy(bp)
                biodone(bp);
                return (0);
        }
                biodone(bp);
                return (0);
        }
-#ifdef DIAGNOSTIC
-       if (checkoverlap && bp->b_vp->v_mount->mnt_stat.f_type == MOUNT_UFS)
-               ffs_checkoverlap(bp, ip);
-#endif
-               
        vp = ip->i_devvp;
        bp->b_dev = vp->v_rdev;
        (vp->v_op->vop_strategy)(bp);
        vp = ip->i_devvp;
        bp->b_dev = vp->v_rdev;
        (vp->v_op->vop_strategy)(bp);
@@ -1800,21 +1782,3 @@ bad:
        ufs_iput(ip);
        return (error);
 }
        ufs_iput(ip);
        return (error);
 }
-
-
-#if defined(JOHNH) && 0
-/*
- * A hack to get the kernel to compile.
- */
-int
-hang_addrlist()
-{
-    return 0;
-}
-int
-free_addrlist()
-{
-    return 0;
-}
-#endif
-