only delete space used by inode, on inode deletion; required
[unix-history] / usr / src / sys / ufs / ffs / ffs_subr.c
index 9e299f2..ec5cdcb 100644 (file)
@@ -1,22 +1,63 @@
-/*     ffs_subr.c      4.2     82/10/21        */
+/*
+ * Copyright (c) 1982, 1986, 1989 Regents of the University of California.
+ * All rights reserved.
+ *
+ * %sccs.include.redist.c%
+ *
+ *     @(#)ffs_subr.c  7.17 (Berkeley) %G%
+ */
 
 
-#ifdef KERNEL
-#include "../h/param.h"
-#include "../h/fs.h"
-#else
 #include <sys/param.h>
 #include <sys/param.h>
-#include <sys/fs.h>
-#endif
+#include <ufs/ffs/fs.h>
+#include <ufs/ffs/ffs_extern.h>
+
+#ifdef KERNEL
+#include <sys/buf.h>
+#include <sys/vnode.h>
+#include <ufs/ufs/quota.h>
+#include <ufs/ufs/inode.h>
+
+/*
+ * Return buffer with the contents of block "offset" from the beginning of
+ * directory "ip".  If "res" is non-zero, fill it in with a pointer to the
+ * remaining space in the directory.
+ */
+int
+ffs_blkatoff(vp, offset, res, bpp)
+       struct vnode *vp;
+       off_t offset;
+       char **res;
+       struct buf **bpp;
+{
+       struct inode *ip;
+       register struct fs *fs;
+       struct buf *bp;
+       daddr_t lbn;
+       int bsize, error;
 
 
-extern int around[9];
-extern int inside[9];
-extern u_char *fragtbl[];
+       ip = VTOI(vp);
+       fs = ip->i_fs;
+       lbn = lblkno(fs, offset);
+       bsize = blksize(fs, ip, lbn);
+
+       *bpp = NULL;
+       if (error = bread(vp, lbn, bsize, NOCRED, &bp)) {
+               brelse(bp);
+               return (error);
+       }
+       if (res)
+               *res = bp->b_un.b_addr + blkoff(fs, offset);
+       *bpp = bp;
+       return (0);
+}
+#endif
 
 /*
  * Update the frsum fields to reflect addition or deletion 
  * of some frags.
  */
 
 /*
  * Update the frsum fields to reflect addition or deletion 
  * of some frags.
  */
-fragacct(fs, fragmap, fraglist, cnt)
+void
+ffs_fragacct(fs, fragmap, fraglist, cnt)
        struct fs *fs;
        int fragmap;
        long fraglist[];
        struct fs *fs;
        int fragmap;
        long fraglist[];
@@ -46,37 +87,54 @@ fragacct(fs, fragmap, fraglist, cnt)
        }
 }
 
        }
 }
 
-#ifdef KERNEL
-/*
- * Check that a specified block number is in range.
- */
-badblock(fs, bn)
-       register struct fs *fs;
-       daddr_t bn;
+#if defined(KERNEL) && defined(DIAGNOSTIC)
+void
+ffs_checkoverlap(bp, ip)
+       struct buf *bp;
+       struct inode *ip;
 {
 {
+       register struct buf *ebp, *ep;
+       register daddr_t start, last;
+       struct vnode *vp;
 
 
-       if ((unsigned)bn >= fs->fs_size) {
-               printf("bad block %d, ", bn);
-               fserr(fs, "bad block");
-               return (1);
+       ebp = &buf[nbuf];
+       start = bp->b_blkno;
+       last = start + btodb(bp->b_bcount) - 1;
+       for (ep = buf; ep < ebp; ep++) {
+               if (ep == bp || (ep->b_flags & B_INVAL) ||
+                   ep->b_vp == NULLVP)
+                       continue;
+               if (VOP_BMAP(ep->b_vp, (daddr_t)0, &vp, (daddr_t)0))
+                       continue;
+               if (vp != ip->i_devvp)
+                       continue;
+               /* look for overlap */
+               if (ep->b_bcount == 0 || ep->b_blkno > last ||
+                   ep->b_blkno + btodb(ep->b_bcount) <= start)
+                       continue;
+               vprint("Disk overlap", vp);
+               (void)printf("\tstart %d, end %d overlap start %d, end %d\n",
+                       start, last, ep->b_blkno,
+                       ep->b_blkno + btodb(ep->b_bcount) - 1);
+               panic("Disk buffer overlap");
        }
        }
-       return (0);
 }
 }
-#endif
+#endif /* DIAGNOSTIC */
 
 /*
  * block operations
  *
  * check if a block is available
  */
 
 /*
  * block operations
  *
  * check if a block is available
  */
-isblock(fs, cp, h)
+int
+ffs_isblock(fs, cp, h)
        struct fs *fs;
        unsigned char *cp;
        daddr_t h;
 {
        unsigned char mask;
 
        struct fs *fs;
        unsigned char *cp;
        daddr_t h;
 {
        unsigned char mask;
 
-       switch (fs->fs_frag) {
+       switch ((int)fs->fs_frag) {
        case 8:
                return (cp[h] == 0xff);
        case 4:
        case 8:
                return (cp[h] == 0xff);
        case 4:
@@ -89,21 +147,21 @@ isblock(fs, cp, h)
                mask = 0x01 << (h & 0x7);
                return ((cp[h >> 3] & mask) == mask);
        default:
                mask = 0x01 << (h & 0x7);
                return ((cp[h >> 3] & mask) == mask);
        default:
-               panic("isblock");
-               return (NULL);
+               panic("ffs_isblock");
        }
 }
 
 /*
  * take a block out of the map
  */
        }
 }
 
 /*
  * take a block out of the map
  */
-clrblock(fs, cp, h)
+void
+ffs_clrblock(fs, cp, h)
        struct fs *fs;
        u_char *cp;
        daddr_t h;
 {
 
        struct fs *fs;
        u_char *cp;
        daddr_t h;
 {
 
-       switch ((fs)->fs_frag) {
+       switch ((int)fs->fs_frag) {
        case 8:
                cp[h] = 0;
                return;
        case 8:
                cp[h] = 0;
                return;
@@ -117,20 +175,21 @@ clrblock(fs, cp, h)
                cp[h >> 3] &= ~(0x01 << (h & 0x7));
                return;
        default:
                cp[h >> 3] &= ~(0x01 << (h & 0x7));
                return;
        default:
-               panic("clrblock");
+               panic("ffs_clrblock");
        }
 }
 
 /*
  * put a block into the map
  */
        }
 }
 
 /*
  * put a block into the map
  */
-setblock(fs, cp, h)
+void
+ffs_setblock(fs, cp, h)
        struct fs *fs;
        unsigned char *cp;
        daddr_t h;
 {
 
        struct fs *fs;
        unsigned char *cp;
        daddr_t h;
 {
 
-       switch (fs->fs_frag) {
+       switch ((int)fs->fs_frag) {
 
        case 8:
                cp[h] = 0xff;
 
        case 8:
                cp[h] = 0xff;
@@ -145,6 +204,54 @@ setblock(fs, cp, h)
                cp[h >> 3] |= (0x01 << (h & 0x7));
                return;
        default:
                cp[h >> 3] |= (0x01 << (h & 0x7));
                return;
        default:
-               panic("setblock");
+               panic("ffs_setblock");
        }
 }
        }
 }
+
+#if (!defined(vax) && !defined(tahoe) && !defined(hp300)) \
+       || defined(VAX630) || defined(VAX650)
+/*
+ * C definitions of special instructions.
+ * Normally expanded with inline.
+ */
+int
+scanc(size, cp, table, mask)
+       u_int size;
+       register u_char *cp, table[];
+       register u_char mask;
+{
+       register u_char *end = &cp[size];
+
+       while (cp < end && (table[*cp] & mask) == 0)
+               cp++;
+       return (end - cp);
+}
+#endif
+
+#if !defined(vax) && !defined(tahoe) && !defined(hp300)
+int
+skpc(mask, size, cp)
+       register u_char mask;
+       u_int size;
+       register u_char *cp;
+{
+       register u_char *end = &cp[size];
+
+       while (cp < end && *cp == mask)
+               cp++;
+       return (end - cp);
+}
+
+int
+locc(mask, size, cp)
+       register u_char mask;
+       u_int size;
+       register u_char *cp;
+{
+       register u_char *end = &cp[size];
+
+       while (cp < end && *cp != mask)
+               cp++;
+       return (end - cp);
+}
+#endif