BSD 4_4_Lite2 release
[unix-history] / usr / src / libexec / lfs_cleanerd / library.c
index 7cdc59c..32f7d37 100644 (file)
@@ -2,11 +2,37 @@
  * Copyright (c) 1992, 1993
  *     The Regents of the University of California.  All rights reserved.
  *
  * Copyright (c) 1992, 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.
+ *
+ * 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.
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)library.c  8.2 (Berkeley) %G%";
+static char sccsid[] = "@(#)library.c  8.3 (Berkeley) 5/24/95";
 #endif /* not lint */
 
 #include <sys/param.h>
 #endif /* not lint */
 
 #include <sys/param.h>
@@ -238,7 +264,7 @@ lfs_segmapv(fsp, seg, seg_buf, blocks, bcount)
        struct lfs *lfsp;
        caddr_t s, segend;
        daddr_t pseg_addr, seg_addr;
        struct lfs *lfsp;
        caddr_t s, segend;
        daddr_t pseg_addr, seg_addr;
-       int i, nelem, nblocks, sumsize;
+       int i, nelem, nblocks, nsegs, sumsize;
        time_t timestamp;
 
        lfsp = &fsp->fi_lfs;
        time_t timestamp;
 
        lfsp = &fsp->fi_lfs;
@@ -255,19 +281,22 @@ lfs_segmapv(fsp, seg, seg_buf, blocks, bcount)
 #endif /* VERBOSE */
 
        *bcount = 0;
 #endif /* VERBOSE */
 
        *bcount = 0;
-       for (segend = seg_buf + seg_size(lfsp), timestamp = 0; s < segend; ) {
+       for (nsegs = 0, timestamp = 0; nsegs < sup->su_nsums; nsegs++) {
                sp = (SEGSUM *)s;
 
                sp = (SEGSUM *)s;
 
+               nblocks = pseg_valid(fsp, sp);
+               if (nblocks <= 0) {
+                       printf("Warning: invalid segment summary at 0x%x\n",
+                           pseg_addr);
+                       break;
+               }
+
 #ifdef VERBOSE
                printf("\tpartial at: 0x%x\n", pseg_addr);
                print_SEGSUM(lfsp, sp);
                fflush(stdout);
 #endif /* VERBOSE */
 
 #ifdef VERBOSE
                printf("\tpartial at: 0x%x\n", pseg_addr);
                print_SEGSUM(lfsp, sp);
                fflush(stdout);
 #endif /* VERBOSE */
 
-               nblocks = pseg_valid(fsp, sp);
-               if (nblocks <= 0)
-                       break;
-
                /* Check if we have hit old data */
                if (timestamp > ((SEGSUM*)s)->ss_create)
                        break;
                /* Check if we have hit old data */
                if (timestamp > ((SEGSUM*)s)->ss_create)
                        break;
@@ -277,7 +306,7 @@ lfs_segmapv(fsp, seg, seg_buf, blocks, bcount)
                /* Verfiy size of summary block */
                sumsize = sizeof(SEGSUM) +
                    (sp->ss_ninos + INOPB(lfsp) - 1) / INOPB(lfsp);
                /* Verfiy size of summary block */
                sumsize = sizeof(SEGSUM) +
                    (sp->ss_ninos + INOPB(lfsp) - 1) / INOPB(lfsp);
-               for (fip = (FINFO *)(sp + 1); i < sp->ss_nfinfo; ++i) {
+               for (i = 0, fip = (FINFO *)(sp + 1); i < sp->ss_nfinfo; ++i) {
                        sumsize += sizeof(FINFO) +
                            (fip->fi_nblocks - 1) * sizeof(daddr_t);
                        fip = (FINFO *)(&fip->fi_blocks[fip->fi_nblocks]);
                        sumsize += sizeof(FINFO) +
                            (fip->fi_nblocks - 1) * sizeof(daddr_t);
                        fip = (FINFO *)(&fip->fi_blocks[fip->fi_nblocks]);
@@ -342,7 +371,9 @@ add_blocks (fsp, bip, countp, sp, seg_buf, segaddr, psegaddr)
        caddr_t bp;
        daddr_t *dp, *iaddrp;
        int db_per_block, i, j;
        caddr_t bp;
        daddr_t *dp, *iaddrp;
        int db_per_block, i, j;
+       int db_frag;
        u_long page_size;
        u_long page_size;
+long *lp;
 
 #ifdef VERBOSE
        printf("FILE INFOS\n");
 
 #ifdef VERBOSE
        printf("FILE INFOS\n");
@@ -374,8 +405,24 @@ add_blocks (fsp, bip, countp, sp, seg_buf, segaddr, psegaddr)
                        bip->bi_segcreate = (time_t)(sp->ss_create);
                        bip->bi_bp = bp;
                        bip->bi_version = ifp->if_version;
                        bip->bi_segcreate = (time_t)(sp->ss_create);
                        bip->bi_bp = bp;
                        bip->bi_version = ifp->if_version;
-                       psegaddr += db_per_block;
-                       bp += page_size;
+                       if (fip->fi_lastlength == page_size) {
+                               bip->bi_size = page_size;
+                               psegaddr += db_per_block;
+                               bp += page_size;
+                       } else {
+                               db_frag = fragstodb(&(fsp->fi_lfs), 
+                                   numfrags(&(fsp->fi_lfs),
+                                   fip->fi_lastlength));
+#ifdef VERBOSE
+                               printf("lastlength, frags: %d, %d, %d\n", 
+                                   fip->fi_lastlength, temp,
+                                   bytetoda(fsp, temp));
+                               fflush(stdout);
+#endif
+                               bip->bi_size = fip->fi_lastlength;
+                               bp += fip->fi_lastlength;
+                               psegaddr += db_frag;
+                       }
                        ++bip;
                        ++(*countp);
                }
                        ++bip;
                        ++(*countp);
                }
@@ -460,6 +507,9 @@ pseg_valid (fsp, ssp)
        int i, nblocks;
        u_long *datap;
 
        int i, nblocks;
        u_long *datap;
 
+       if (ssp->ss_magic != SS_MAGIC)
+               return(0);
+
        if ((nblocks = dump_summary(&fsp->fi_lfs, ssp, 0, NULL)) <= 0 ||
            nblocks > fsp->fi_lfs.lfs_ssize - 1)
                return(0);
        if ((nblocks = dump_summary(&fsp->fi_lfs, ssp, 0, NULL)) <= 0 ||
            nblocks > fsp->fi_lfs.lfs_ssize - 1)
                return(0);