BSD 4_4_Lite1 release
[unix-history] / usr / src / sys / ufs / ffs / ffs_balloc.c
index d38a9f9..752feec 100644 (file)
@@ -1,10 +1,36 @@
 /*
 /*
- * Copyright (c) 1982, 1986, 1989 Regents of the University of California.
- * All rights reserved.
+ * Copyright (c) 1982, 1986, 1989, 1993
+ *     The Regents of the University of California.  All rights reserved.
  *
  *
- * %sccs.include.redist.c%
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ *     This product includes software developed by the University of
+ *     California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
  *
  *
- *     @(#)ffs_balloc.c        7.23 (Berkeley) %G%
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ *     @(#)ffs_balloc.c        8.4 (Berkeley) 9/23/93
  */
 
 #include <sys/param.h>
  */
 
 #include <sys/param.h>
@@ -41,10 +67,10 @@ ffs_balloc(ip, bn, size, cred, bpp, flags)
        struct buf *bp, *nbp;
        struct vnode *vp = ITOV(ip);
        struct indir indirs[NIADDR + 2];
        struct buf *bp, *nbp;
        struct vnode *vp = ITOV(ip);
        struct indir indirs[NIADDR + 2];
-       int osize, nsize, num, j, error;
        daddr_t newb, lbn, *bap, pref;
        daddr_t newb, lbn, *bap, pref;
+       int osize, nsize, num, i, error;
 
 
-       *bpp = (struct buf *)0;
+       *bpp = NULL;
        if (bn < 0)
                return (EFBIG);
        fs = ip->i_fs;
        if (bn < 0)
                return (EFBIG);
        fs = ip->i_fs;
@@ -67,7 +93,7 @@ ffs_balloc(ip, bn, size, cred, bpp, flags)
                        ip->i_size = (nb + 1) * fs->fs_bsize;
                        vnode_pager_setsize(vp, (u_long)ip->i_size);
                        ip->i_db[nb] = dbtofsb(fs, bp->b_blkno);
                        ip->i_size = (nb + 1) * fs->fs_bsize;
                        vnode_pager_setsize(vp, (u_long)ip->i_size);
                        ip->i_db[nb] = dbtofsb(fs, bp->b_blkno);
-                       ip->i_flag |= IUPD|ICHG;
+                       ip->i_flag |= IN_CHANGE | IN_UPDATE;
                        if (flags & B_SYNC)
                                bwrite(bp);
                        else
                        if (flags & B_SYNC)
                                bwrite(bp);
                        else
@@ -117,13 +143,13 @@ ffs_balloc(ip, bn, size, cred, bpp, flags)
                            nsize, cred, &newb);
                        if (error)
                                return (error);
                            nsize, cred, &newb);
                        if (error)
                                return (error);
-                       bp = getblk(vp, bn, nsize);
+                       bp = getblk(vp, bn, nsize, 0, 0);
                        bp->b_blkno = fsbtodb(fs, newb);
                        if (flags & B_CLRBUF)
                                clrbuf(bp);
                }
                ip->i_db[bn] = dbtofsb(fs, bp->b_blkno);
                        bp->b_blkno = fsbtodb(fs, newb);
                        if (flags & B_CLRBUF)
                                clrbuf(bp);
                }
                ip->i_db[bn] = dbtofsb(fs, bp->b_blkno);
-               ip->i_flag |= IUPD|ICHG;
+               ip->i_flag |= IN_CHANGE | IN_UPDATE;
                *bpp = bp;
                return (0);
        }
                *bpp = bp;
                return (0);
        }
@@ -148,7 +174,7 @@ ffs_balloc(ip, bn, size, cred, bpp, flags)
                    cred, &newb))
                        return (error);
                nb = newb;
                    cred, &newb))
                        return (error);
                nb = newb;
-               bp = getblk(vp, indirs[1].in_lbn, fs->fs_bsize);
+               bp = getblk(vp, indirs[1].in_lbn, fs->fs_bsize, 0, 0);
                bp->b_blkno = fsbtodb(fs, newb);
                clrbuf(bp);
                /*
                bp->b_blkno = fsbtodb(fs, newb);
                clrbuf(bp);
                /*
@@ -160,23 +186,23 @@ ffs_balloc(ip, bn, size, cred, bpp, flags)
                        return (error);
                }
                ip->i_ib[indirs[0].in_off] = newb;
                        return (error);
                }
                ip->i_ib[indirs[0].in_off] = newb;
-               ip->i_flag |= IUPD|ICHG;
+               ip->i_flag |= IN_CHANGE | IN_UPDATE;
        }
        /*
         * Fetch through the indirect blocks, allocating as necessary.
         */
        }
        /*
         * Fetch through the indirect blocks, allocating as necessary.
         */
-       for (j = 1; ; ) {
-               error = bread(vp, indirs[j].in_lbn, (int)fs->fs_bsize, NOCRED,
-                   &bp);
+       for (i = 1;;) {
+               error = bread(vp,
+                   indirs[i].in_lbn, (int)fs->fs_bsize, NOCRED, &bp);
                if (error) {
                        brelse(bp);
                        return (error);
                }
                if (error) {
                        brelse(bp);
                        return (error);
                }
-               bap = bp->b_un.b_daddr;
-               nb = bap[indirs[j].in_off];
-               if (j == num)
+               bap = (daddr_t *)bp->b_data;
+               nb = bap[indirs[i].in_off];
+               if (i == num)
                        break;
                        break;
-               j += 1;
+               i += 1;
                if (nb != 0) {
                        brelse(bp);
                        continue;
                if (nb != 0) {
                        brelse(bp);
                        continue;
@@ -189,7 +215,7 @@ ffs_balloc(ip, bn, size, cred, bpp, flags)
                        return (error);
                }
                nb = newb;
                        return (error);
                }
                nb = newb;
-               nbp = getblk(vp, indirs[j].in_lbn, fs->fs_bsize);
+               nbp = getblk(vp, indirs[i].in_lbn, fs->fs_bsize, 0, 0);
                nbp->b_blkno = fsbtodb(fs, nb);
                clrbuf(nbp);
                /*
                nbp->b_blkno = fsbtodb(fs, nb);
                clrbuf(nbp);
                /*
@@ -201,7 +227,7 @@ ffs_balloc(ip, bn, size, cred, bpp, flags)
                        brelse(bp);
                        return (error);
                }
                        brelse(bp);
                        return (error);
                }
-               bap[indirs[j].in_off] = nb;
+               bap[indirs[i - 1].in_off] = nb;
                /*
                 * If required, write synchronously, otherwise use
                 * delayed write.
                /*
                 * If required, write synchronously, otherwise use
                 * delayed write.
@@ -216,18 +242,18 @@ ffs_balloc(ip, bn, size, cred, bpp, flags)
         * Get the data block, allocating if necessary.
         */
        if (nb == 0) {
         * Get the data block, allocating if necessary.
         */
        if (nb == 0) {
-               pref = ffs_blkpref(ip, lbn, indirs[j].in_off, &bap[0]);
-               if (error =
-                   ffs_alloc(ip, lbn, pref, (int)fs->fs_bsize, cred, &newb)) {
+               pref = ffs_blkpref(ip, lbn, indirs[i].in_off, &bap[0]);
+               if (error = ffs_alloc(ip,
+                   lbn, pref, (int)fs->fs_bsize, cred, &newb)) {
                        brelse(bp);
                        return (error);
                }
                nb = newb;
                        brelse(bp);
                        return (error);
                }
                nb = newb;
-               nbp = getblk(vp, lbn, fs->fs_bsize);
+               nbp = getblk(vp, lbn, fs->fs_bsize, 0, 0);
                nbp->b_blkno = fsbtodb(fs, nb);
                if (flags & B_CLRBUF)
                        clrbuf(nbp);
                nbp->b_blkno = fsbtodb(fs, nb);
                if (flags & B_CLRBUF)
                        clrbuf(nbp);
-               bap[indirs[j].in_off] = nb;
+               bap[indirs[i].in_off] = nb;
                /*
                 * If required, write synchronously, otherwise use
                 * delayed write.
                /*
                 * If required, write synchronously, otherwise use
                 * delayed write.
@@ -248,7 +274,7 @@ ffs_balloc(ip, bn, size, cred, bpp, flags)
                        return (error);
                }
        } else {
                        return (error);
                }
        } else {
-               nbp = getblk(vp, lbn, fs->fs_bsize);
+               nbp = getblk(vp, lbn, fs->fs_bsize, 0, 0);
                nbp->b_blkno = fsbtodb(fs, nb);
        }
        *bpp = nbp;
                nbp->b_blkno = fsbtodb(fs, nb);
        }
        *bpp = nbp;