avoid null pointers
[unix-history] / usr / src / sys / ufs / ffs / ufs_inode.c
index 3b8c137..939c453 100644 (file)
@@ -4,25 +4,24 @@
  *
  * %sccs.include.redist.c%
  *
  *
  * %sccs.include.redist.c%
  *
- *     @(#)ufs_inode.c 7.37 (Berkeley) %G%
+ *     @(#)ufs_inode.c 7.40.1.1 (Berkeley) %G%
  */
 
 #include "param.h"
 #include "systm.h"
 #include "mount.h"
  */
 
 #include "param.h"
 #include "systm.h"
 #include "mount.h"
-#include "user.h"
 #include "proc.h"
 #include "file.h"
 #include "buf.h"
 #include "proc.h"
 #include "file.h"
 #include "buf.h"
-#include "cmap.h"
 #include "vnode.h"
 #include "vnode.h"
-#include "../ufs/quota.h"
-#include "../ufs/inode.h"
-#include "../ufs/fs.h"
-#include "../ufs/ufsmount.h"
 #include "kernel.h"
 #include "malloc.h"
 
 #include "kernel.h"
 #include "malloc.h"
 
+#include "quota.h"
+#include "inode.h"
+#include "fs.h"
+#include "ufsmount.h"
+
 #define        INOHSZ  512
 #if    ((INOHSZ&(INOHSZ-1)) == 0)
 #define        INOHASH(dev,ino)        (((dev)+(ino))&(INOHSZ-1))
 #define        INOHSZ  512
 #if    ((INOHSZ&(INOHSZ-1)) == 0)
 #define        INOHASH(dev,ino)        (((dev)+(ino))&(INOHSZ-1))
@@ -59,14 +58,11 @@ ufs_init()
 }
 
 /*
 }
 
 /*
- * Look up an vnode/inode by device,inumber.
- * If it is in core (in the inode structure),
- * honor the locking protocol.
- * If it is not in core, read it in from the
- * specified device.
- * Callers must check for mount points!!
- * In all cases, a pointer to a locked
- * inode structure is returned.
+ * Look up a UFS dinode number to find its incore vnode.
+ * If it is not in core, read it in from the specified device.
+ * If it is in core, wait for the lock bit to clear, then
+ * return the inode locked. Detection and handling of mount
+ * points must be done by the calling routine.
  */
 iget(xp, ino, ipp)
        struct inode *xp;
  */
 iget(xp, ino, ipp)
        struct inode *xp;
@@ -231,8 +227,9 @@ iput(ip)
  * Last reference to an inode, write the inode out and if necessary,
  * truncate and deallocate the file.
  */
  * Last reference to an inode, write the inode out and if necessary,
  * truncate and deallocate the file.
  */
-ufs_inactive(vp)
+ufs_inactive(vp, p)
        struct vnode *vp;
        struct vnode *vp;
+       struct proc *p;
 {
        register struct inode *ip = VTOI(vp);
        int mode, error = 0;
 {
        register struct inode *ip = VTOI(vp);
        int mode, error = 0;
@@ -310,10 +307,13 @@ ufs_reclaim(vp)
 }
 
 /*
 }
 
 /*
- * Check accessed and update flags on an inode structure.
- * If any is on, update the inode with the current time.
- * If waitfor is given, then must ensure I/O order,
- * so wait for write to complete.
+ * Update the access, modified, and inode change times as specified
+ * by the IACC, IMOD, and ICHG flags respectively. The IUPD flag
+ * is used to specify that the inode needs to be updated but that
+ * the times have already been set. The access and modified times
+ * are taken from the second and third parameters; the inode change
+ * time is always taken from the current time. If waitfor is set,
+ * then wait for the disk write of the inode to complete.
  */
 iupdat(ip, ta, tm, waitfor)
        register struct inode *ip;
  */
 iupdat(ip, ta, tm, waitfor)
        register struct inode *ip;
@@ -646,15 +646,15 @@ ilock(ip)
 
        while (ip->i_flag & ILOCKED) {
                ip->i_flag |= IWANT;
 
        while (ip->i_flag & ILOCKED) {
                ip->i_flag |= IWANT;
-               if (ip->i_spare0 == u.u_procp->p_pid)
+               if (ip->i_spare0 == curproc->p_pid)
                        panic("locking against myself");
                        panic("locking against myself");
-               ip->i_spare1 = u.u_procp->p_pid;
+               ip->i_spare1 = curproc->p_pid;
                (void) sleep((caddr_t)ip, PINOD);
        }
        ip->i_spare1 = 0;
                (void) sleep((caddr_t)ip, PINOD);
        }
        ip->i_spare1 = 0;
-       ip->i_spare0 = u.u_procp->p_pid;
-       u.u_spare[0]++;
+       ip->i_spare0 = curproc->p_pid;
        ip->i_flag |= ILOCKED;
        ip->i_flag |= ILOCKED;
+       curproc->p_spare[2]++;
 }
 
 /*
 }
 
 /*
@@ -667,8 +667,8 @@ iunlock(ip)
        if ((ip->i_flag & ILOCKED) == 0)
                vprint("iunlock: unlocked inode", ITOV(ip));
        ip->i_spare0 = 0;
        if ((ip->i_flag & ILOCKED) == 0)
                vprint("iunlock: unlocked inode", ITOV(ip));
        ip->i_spare0 = 0;
-       u.u_spare[0]--;
        ip->i_flag &= ~ILOCKED;
        ip->i_flag &= ~ILOCKED;
+       curproc->p_spare[2]--;
        if (ip->i_flag&IWANT) {
                ip->i_flag &= ~IWANT;
                wakeup((caddr_t)ip);
        if (ip->i_flag&IWANT) {
                ip->i_flag &= ~IWANT;
                wakeup((caddr_t)ip);