summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authordownsj <downsj@openbsd.org>1996-07-01 11:04:54 +0000
committerdownsj <downsj@openbsd.org>1996-07-01 11:04:54 +0000
commitf03b1a4931222a7a824669fcd9b711f6f337a18a (patch)
treefb63487bb3935a1198ab32d7fb190674e5418fc4
parentnewlfs changes to match new LFS code; based on Lite2. (diff)
downloadwireguard-openbsd-f03b1a4931222a7a824669fcd9b711f6f337a18a.tar.xz
wireguard-openbsd-f03b1a4931222a7a824669fcd9b711f6f337a18a.zip
new lfs_cleanerd from Lite2.
-rw-r--r--libexec/lfs_cleanerd/Makefile4
-rw-r--r--libexec/lfs_cleanerd/clean.h5
-rw-r--r--libexec/lfs_cleanerd/cleanerd.c137
-rw-r--r--libexec/lfs_cleanerd/lfs_cleanerd.85
-rw-r--r--libexec/lfs_cleanerd/library.c54
-rw-r--r--libexec/lfs_cleanerd/misc.c6
-rw-r--r--libexec/lfs_cleanerd/print.c30
7 files changed, 178 insertions, 63 deletions
diff --git a/libexec/lfs_cleanerd/Makefile b/libexec/lfs_cleanerd/Makefile
index 9b435d3a81f..5dd0807423e 100644
--- a/libexec/lfs_cleanerd/Makefile
+++ b/libexec/lfs_cleanerd/Makefile
@@ -1,8 +1,8 @@
# from: @(#)Makefile 8.1 (Berkeley) 6/5/93
-# $Id: Makefile,v 1.1.1.1 1995/10/18 08:43:18 deraadt Exp $
+# $OpenBSD: Makefile,v 1.2 1996/07/01 11:04:54 downsj Exp $
PROG= lfs_cleanerd
-CFLAGS+=-I${.CURDIR} -DDIAGNOSTIC
+CFLAGS+= -g -I${.CURDIR} -DDIAGNOSTIC
MAN= lfs_cleanerd.8
SRCS= cleanerd.c lfs_cksum.c library.c misc.c print.c
diff --git a/libexec/lfs_cleanerd/clean.h b/libexec/lfs_cleanerd/clean.h
index c02c0d20ee8..272fb91059c 100644
--- a/libexec/lfs_cleanerd/clean.h
+++ b/libexec/lfs_cleanerd/clean.h
@@ -1,3 +1,5 @@
+/* $OpenBSD: clean.h,v 1.2 1996/07/01 11:04:55 downsj Exp $ */
+
/*-
* Copyright (c) 1992, 1993
* The Regents of the University of California. All rights reserved.
@@ -30,8 +32,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * from: @(#)clean.h 8.1 (Berkeley) 6/4/93
- * $Id: clean.h,v 1.1.1.1 1995/10/18 08:43:18 deraadt Exp $
+ * @(#)clean.h 8.2 (Berkeley) 5/4/95
*/
/*
diff --git a/libexec/lfs_cleanerd/cleanerd.c b/libexec/lfs_cleanerd/cleanerd.c
index 0249d50686f..66fdb3a5c52 100644
--- a/libexec/lfs_cleanerd/cleanerd.c
+++ b/libexec/lfs_cleanerd/cleanerd.c
@@ -1,3 +1,5 @@
+/* $OpenBSD: cleanerd.c,v 1.2 1996/07/01 11:04:56 downsj Exp $ */
+
/*-
* Copyright (c) 1992, 1993
* The Regents of the University of California. All rights reserved.
@@ -38,8 +40,8 @@ static char copyright[] =
#endif /* not lint */
#ifndef lint
-/*static char sccsid[] = "from: @(#)cleanerd.c 8.2 (Berkeley) 1/13/94";*/
-static char *rcsid = "$Id: cleanerd.c,v 1.1.1.1 1995/10/18 08:43:18 deraadt Exp $";
+/*static char sccsid[] = "@(#)cleanerd.c 8.5 (Berkeley) 6/10/95";*/
+static char rcsid[] = "$OpenBSD: cleanerd.c,v 1.2 1996/07/01 11:04:56 downsj Exp $";
#endif /* not lint */
#include <sys/param.h>
@@ -58,7 +60,10 @@ static char *rcsid = "$Id: cleanerd.c,v 1.1.1.1 1995/10/18 08:43:18 deraadt Exp
char *special = "cleanerd";
int do_small = 0;
int do_mmap = 0;
+int stat_report = 0;
struct cleaner_stats {
+ double util_tot;
+ double util_sos;
int blocks_read;
int blocks_written;
int segs_cleaned;
@@ -69,7 +74,7 @@ struct cleaner_stats {
struct seglist {
int sl_id; /* segment number */
int sl_cost; /* cleaning cost */
- char sl_empty; /* is segment empty */
+ char sl_bytes; /* bytes in segment */
};
struct tossstruct {
@@ -77,6 +82,8 @@ struct tossstruct {
int seg;
};
+#define CLEAN_BYTES 0x1
+
/* function prototypes for system calls; not sure where they should go */
int lfs_segwait __P((fsid_t *, struct timeval *));
int lfs_segclean __P((fsid_t *, u_long));
@@ -87,8 +94,8 @@ int lfs_markv __P((fsid_t *, BLOCK_INFO *, int));
int bi_tossold __P((const void *, const void *, const void *));
int choose_segments __P((FS_INFO *, struct seglist *,
int (*)(FS_INFO *, SEGUSE *)));
-void clean_fs __P((FS_INFO *, int (*)(FS_INFO *, SEGUSE *)));
-int clean_loop __P((FS_INFO *));
+void clean_fs __P((FS_INFO *, int (*)(FS_INFO *, SEGUSE *), int, long));
+int clean_loop __P((FS_INFO *, int, long));
int clean_segment __P((FS_INFO *, int));
int cost_benefit __P((FS_INFO *, SEGUSE *));
int cost_compare __P((const void *, const void *));
@@ -153,22 +160,37 @@ main(argc, argv)
struct statfs *lstatfsp; /* file system stats */
struct timeval timeout; /* sleep timeout */
fsid_t fsid;
- int i, nodaemon;
+ long clean_opts; /* cleaning options */
+ int i, nodaemon, segs_per_clean;
int opt, cmd_err;
char *fs_name; /* name of filesystem to clean */
extern int optind;
cmd_err = nodaemon = 0;
- while ((opt = getopt(argc, argv, "smd")) != EOF) {
+ clean_opts = 0;
+ segs_per_clean = 1;
+ while ((opt = getopt(argc, argv, "bdmn:r:s")) != EOF) {
switch (opt) {
- case 's': /* small writes */
- do_small = 1;
+ case 'b': /*
+ * Use live bytes to determine
+ * how many segs to clean.
+ */
+ clean_opts |= CLEAN_BYTES;
+ break;
+ case 'd': /* Debug mode. */
+ nodaemon = 1;
break;
- case 'm':
+ case 'm': /* Use mmap instead of read/write */
do_mmap = 1;
break;
- case 'd':
- nodaemon = 1;
+ case 'n': /* How many segs to clean at once */
+ segs_per_clean = atoi(optarg);
+ break;
+ case 'r': /* Report every stat_report segments */
+ stat_report = atoi(optarg);
+ break;
+ case 's': /* small writes */
+ do_small = 1;
break;
default:
++cmd_err;
@@ -206,7 +228,7 @@ main(argc, argv)
* to make sure that some nasty process hasn't just
* filled the disk system up.
*/
- if (clean_loop(fsp))
+ if (clean_loop(fsp, segs_per_clean, clean_opts))
continue;
#ifdef VERBOSE
@@ -222,30 +244,42 @@ main(argc, argv)
/* return the number of segments cleaned */
int
-clean_loop(fsp)
+clean_loop(fsp, nsegs, options)
FS_INFO *fsp; /* file system information */
+ int nsegs;
+ long options;
{
double loadavg[MAXLOADS];
time_t now;
u_long max_free_segs;
+ u_long db_per_seg;
/*
* Compute the maximum possible number of free segments, given the
* number of free blocks.
*/
- max_free_segs = fsp->fi_statfsp->f_bfree / fsp->fi_lfs.lfs_ssize;
+ db_per_seg = fsbtodb(&fsp->fi_lfs, fsp->fi_lfs.lfs_ssize);
+ max_free_segs = fsp->fi_lfs.lfs_bfree / db_per_seg;
/*
* We will clean if there are not enough free blocks or total clean
* space is less than BUSY_LIM % of possible clean space.
*/
now = time((time_t *)NULL);
- if (fsp->fi_cip->clean < max_free_segs &&
+#ifdef VERBOSE
+ printf("db_er_seg = %d max_free_segs = %d, bfree = %d avail = %d ",
+ db_per_seg, max_free_segs, fsp->fi_lfs.lfs_bfree,
+ fsp->fi_lfs.lfs_avail);
+ printf("clean = %d\n", fsp->fi_cip->clean);
+#endif
+ if ((fsp->fi_lfs.lfs_bfree - fsp->fi_lfs.lfs_avail > db_per_seg &&
+ fsp->fi_lfs.lfs_avail < db_per_seg) ||
+ (fsp->fi_cip->clean < max_free_segs &&
(fsp->fi_cip->clean <= MIN_SEGS(&fsp->fi_lfs) ||
- fsp->fi_cip->clean < max_free_segs * BUSY_LIM)) {
+ fsp->fi_cip->clean < max_free_segs * BUSY_LIM))) {
printf("Cleaner Running at %s (%d of %d segments available)\n",
ctime(&now), fsp->fi_cip->clean, max_free_segs);
- clean_fs(fsp, cost_benefit);
+ clean_fs(fsp, cost_benefit, nsegs, options);
return (1);
} else {
/*
@@ -259,7 +293,7 @@ clean_loop(fsp)
}
if (loadavg[ONE_MIN] == 0.0 && loadavg[FIVE_MIN] &&
fsp->fi_cip->clean < max_free_segs * IDLE_LIM) {
- clean_fs(fsp, cost_benefit);
+ clean_fs(fsp, cost_benefit, nsegs, options);
printf("Cleaner Running at %s (system idle)\n",
ctime(&now));
return (1);
@@ -271,11 +305,14 @@ clean_loop(fsp)
void
-clean_fs(fsp, cost_func)
+clean_fs(fsp, cost_func, nsegs, options)
FS_INFO *fsp; /* file system information */
int (*cost_func) __P((FS_INFO *, SEGUSE *));
+ int nsegs;
+ long options;
{
struct seglist *segs, *sp;
+ int to_clean, cleaned_bytes;
int i;
if ((segs =
@@ -289,15 +326,33 @@ clean_fs(fsp, cost_func)
i, fsp->fi_statfsp->f_mntonname);
fflush(stdout);
#endif
- if (i)
- for (i = MIN(i, NUM_TO_CLEAN(fsp)), sp = segs; i-- ; ++sp) {
- if (clean_segment(fsp, sp->sl_id) < 0)
- perror("clean_segment failed");
- else if (lfs_segclean(&fsp->fi_statfsp->f_fsid,
- sp->sl_id) < 0)
- perror("lfs_segclean failed");
- printf("Completed cleaning segment %d\n", sp->sl_id);
- }
+ if (i) {
+ /* Check which cleaning algorithm to use. */
+ if (options & CLEAN_BYTES) {
+ cleaned_bytes = 0;
+ to_clean = nsegs <<
+ (fsp->fi_lfs.lfs_segshift + fsp->fi_lfs.lfs_bshift);
+ for (sp = segs; i && cleaned_bytes < to_clean;
+ i--, ++sp) {
+ if (clean_segment(fsp, sp->sl_id) < 0)
+ perror("clean_segment failed");
+ else if (lfs_segclean(&fsp->fi_statfsp->f_fsid,
+ sp->sl_id) < 0)
+ perror("lfs_segclean failed");
+ printf("Cleaned segment %d (%d bytes)\n",
+ sp->sl_id, sp->sl_bytes);
+ cleaned_bytes += sp->sl_bytes;
+ }
+ } else
+ for (i = MIN(i, nsegs), sp = segs; i-- ; ++sp) {
+ if (clean_segment(fsp, sp->sl_id) < 0)
+ perror("clean_segment failed");
+ else if (lfs_segclean(&fsp->fi_statfsp->f_fsid,
+ sp->sl_id) < 0)
+ perror("lfs_segclean failed");
+ printf("Completed cleaning segment %d\n", sp->sl_id);
+ }
+ }
free(segs);
}
@@ -350,7 +405,7 @@ choose_segments(fsp, seglist, cost_func)
#endif
sp->sl_cost = (*cost_func)(fsp, sup);
sp->sl_id = i;
- sp->sl_empty = sup->su_nbytes ? 0 : 1;
+ sp->sl_bytes = sup->su_nbytes;
++sp;
}
nsegs = sp - seglist;
@@ -372,6 +427,7 @@ clean_segment(fsp, id)
struct lfs *lfsp;
struct tossstruct t;
caddr_t seg_buf;
+ double util;
int num_blocks, maxblocks, clean_blocks;
lfsp = &fsp->fi_lfs;
@@ -438,8 +494,14 @@ clean_segment(fsp, id)
lp = (u_long *)_bip->bi_bp;
}
}
+
#endif
+ ++cleaner_stats.segs_cleaned;
cleaner_stats.blocks_written += num_blocks;
+ util = ((double)num_blocks / fsp->fi_lfs.lfs_ssize);
+ cleaner_stats.util_tot += util;
+ cleaner_stats.util_sos += util * util;
+
if (do_small)
maxblocks = MAXPHYS / fsp->fi_lfs.lfs_bsize - 1;
else
@@ -458,7 +520,8 @@ clean_segment(fsp, id)
free(block_array);
munmap_segment(fsp, seg_buf, do_mmap);
- ++cleaner_stats.segs_cleaned;
+ if (stat_report && cleaner_stats.segs_cleaned % stat_report == 0)
+ sig_report(SIGUSR1);
return (0);
}
@@ -481,18 +544,30 @@ void
sig_report(sig)
int sig;
{
+ double avg;
+
printf("lfs_cleanerd:\t%s%d\n\t\t%s%d\n\t\t%s%d\n\t\t%s%d\n\t\t%s%d\n",
"blocks_read ", cleaner_stats.blocks_read,
"blocks_written ", cleaner_stats.blocks_written,
"segs_cleaned ", cleaner_stats.segs_cleaned,
"segs_empty ", cleaner_stats.segs_empty,
"seg_error ", cleaner_stats.segs_error);
+ printf("\t\t%s%5.2f\n\t\t%s%5.2f\n",
+ "util_tot ", cleaner_stats.util_tot,
+ "util_sos ", cleaner_stats.util_sos);
+ printf("\t\tavg util: %4.2f std dev: %9.6f\n",
+ avg = cleaner_stats.util_tot / cleaner_stats.segs_cleaned,
+ cleaner_stats.util_sos / cleaner_stats.segs_cleaned - avg * avg);
+
+
if (sig == SIGUSR2) {
cleaner_stats.blocks_read = 0;
cleaner_stats.blocks_written = 0;
cleaner_stats.segs_cleaned = 0;
cleaner_stats.segs_empty = 0;
cleaner_stats.segs_error = 0;
+ cleaner_stats.util_tot = 0.0;
+ cleaner_stats.util_sos = 0.0;
}
if (sig == SIGINT)
exit(0);
diff --git a/libexec/lfs_cleanerd/lfs_cleanerd.8 b/libexec/lfs_cleanerd/lfs_cleanerd.8
index 709c1b4b740..287f1ec4c62 100644
--- a/libexec/lfs_cleanerd/lfs_cleanerd.8
+++ b/libexec/lfs_cleanerd/lfs_cleanerd.8
@@ -1,3 +1,5 @@
+.\" $OpenBSD: lfs_cleanerd.8,v 1.2 1996/07/01 11:04:56 downsj Exp $
+.\"
.\" Copyright (c) 1993
.\" The Regents of the University of California. All rights reserved.
.\"
@@ -29,8 +31,7 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.\" from: @(#)lfs_cleanerd.8 8.2 (Berkeley) 12/11/93
-.\" $Id: lfs_cleanerd.8,v 1.1.1.1 1995/10/18 08:43:18 deraadt Exp $
+.\" @(#)lfs_cleanerd.8 8.2 (Berkeley) 12/11/93
.\"
.Dd "December 11, 1993"
.Dt LFS_CLEANERD 8
diff --git a/libexec/lfs_cleanerd/library.c b/libexec/lfs_cleanerd/library.c
index 19141b6bd03..0a1463540bc 100644
--- a/libexec/lfs_cleanerd/library.c
+++ b/libexec/lfs_cleanerd/library.c
@@ -1,3 +1,5 @@
+/* $OpenBSD: library.c,v 1.2 1996/07/01 11:04:57 downsj Exp $ */
+
/*-
* Copyright (c) 1992, 1993
* The Regents of the University of California. All rights reserved.
@@ -32,8 +34,8 @@
*/
#ifndef lint
-/*static char sccsid[] = "from: @(#)library.c 8.1 (Berkeley) 6/4/93";*/
-static char *rcsid = "$Id: library.c,v 1.1.1.1 1995/10/18 08:43:18 deraadt Exp $";
+/*static char sccsid[] = "@(#)library.c 8.3 (Berkeley) 5/24/95";*/
+static char rcsid[] = "$OpenBSD: library.c,v 1.2 1996/07/01 11:04:57 downsj Exp $";
#endif /* not lint */
#include <sys/param.h>
@@ -88,7 +90,7 @@ fs_getmntinfo(buf, name, type)
}
/* check to see if it's the one we want */
- if (strncmp(type, (*buf)->f_fstypename, MFSNAMELEN) ||
+ if (strcmp((*buf)->f_fstypename, type) ||
strncmp(name, (*buf)->f_mntonname, MNAMELEN)) {
/* "this is not the filesystem you're looking for */
free(*buf);
@@ -150,7 +152,6 @@ get_superblock (fsp, sbp)
struct lfs *sbp;
{
char mntfromname[MNAMELEN+1];
- char buf[LFS_SBPAD];
int fid;
strcpy(mntfromname, "/dev/r");
@@ -161,8 +162,7 @@ get_superblock (fsp, sbp)
return (-1);
}
- get(fid, LFS_LABELPAD, buf, LFS_SBPAD);
- bcopy(buf, sbp, sizeof(struct lfs));
+ get(fid, LFS_LABELPAD, sbp, sizeof(struct lfs));
close (fid);
return (0);
@@ -267,7 +267,7 @@ lfs_segmapv(fsp, seg, seg_buf, blocks, bcount)
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;
@@ -284,19 +284,22 @@ lfs_segmapv(fsp, seg, seg_buf, blocks, bcount)
#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;
+ 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 */
- nblocks = pseg_valid(fsp, sp);
- if (nblocks <= 0)
- break;
-
/* Check if we have hit old data */
if (timestamp > ((SEGSUM*)s)->ss_create)
break;
@@ -306,7 +309,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);
- 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]);
@@ -371,7 +374,9 @@ add_blocks (fsp, bip, countp, sp, seg_buf, segaddr, psegaddr)
caddr_t bp;
daddr_t *dp, *iaddrp;
int db_per_block, i, j;
+ int db_frag;
u_long page_size;
+long *lp;
#ifdef VERBOSE
printf("FILE INFOS\n");
@@ -403,8 +408,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;
- 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);
}
@@ -489,6 +510,9 @@ pseg_valid (fsp, ssp)
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);
diff --git a/libexec/lfs_cleanerd/misc.c b/libexec/lfs_cleanerd/misc.c
index 33c9f667586..884b6020edd 100644
--- a/libexec/lfs_cleanerd/misc.c
+++ b/libexec/lfs_cleanerd/misc.c
@@ -1,3 +1,5 @@
+/* $OpenBSD: misc.c,v 1.2 1996/07/01 11:04:58 downsj Exp $ */
+
/*-
* Copyright (c) 1992, 1993
* The Regents of the University of California. All rights reserved.
@@ -32,8 +34,8 @@
*/
#ifndef lint
-/*static char sccsid[] = "from: @(#)misc.c 8.1 (Berkeley) 6/4/93";*/
-static char *rcsid = "$Id: misc.c,v 1.1.1.1 1995/10/18 08:43:18 deraadt Exp $";
+/*static char sccsid[] = "@(#)misc.c 8.1 (Berkeley) 6/4/93";*/
+static char rcsid[] = "$OpenBSD: misc.c,v 1.2 1996/07/01 11:04:58 downsj Exp $";
#endif /* not lint */
#include <sys/types.h>
diff --git a/libexec/lfs_cleanerd/print.c b/libexec/lfs_cleanerd/print.c
index 71db00d7d53..9aacedef429 100644
--- a/libexec/lfs_cleanerd/print.c
+++ b/libexec/lfs_cleanerd/print.c
@@ -1,3 +1,5 @@
+/* $OpenBSD: print.c,v 1.2 1996/07/01 11:04:58 downsj Exp $ */
+
/*-
* Copyright (c) 1992, 1993
* The Regents of the University of California. All rights reserved.
@@ -32,8 +34,8 @@
*/
#ifndef lint
-/*static char sccsid[] = "from: @(#)print.c 8.1 (Berkeley) 6/4/93";*/
-static char *rcsid = "$Id: print.c,v 1.1.1.1 1995/10/18 08:43:19 deraadt Exp $";
+/*static char sccsid[] = "@(#)print.c 8.2 (Berkeley) 5/24/95";*/
+static char rcsid[] = "$OpenBSD: print.c,v 1.2 1996/07/01 11:04:58 downsj Exp $";
#endif /* not lint */
#include <sys/param.h>
@@ -66,22 +68,32 @@ dump_summary(lfsp, sp, flags, iaddrp)
FINFO *fp;
int ck;
+ if (sp->ss_magic != SS_MAGIC)
+ return(-1);
+
if (sp->ss_sumsum != (ck = cksum(&sp->ss_datasum,
LFS_SUMMARY_SIZE - sizeof(sp->ss_sumsum))))
return(-1);
+ numblocks = (sp->ss_ninos + INOPB(lfsp) - 1) / INOPB(lfsp);
+
+ /* Do some basic sanity checking. */
+ if (sp->ss_nfinfo > LFS_SUMMARY_SIZE / sizeof(FINFO) ||
+ numblocks > lfsp->lfs_ssize ||
+ numblocks > LFS_SUMMARY_SIZE / sizeof(daddr_t))
+ return(-1);
+
if (flags & DUMP_SUM_HEADER) {
- (void)printf(" %s0x%X\t%s%d\t%s%d\n %s0x%X\t%s0x%X",
+ (void)printf(" %s0x%X\t%s%d\t%s%d\n %s0x%X\t%s0x%X\t%s0x%X\n",
"next ", sp->ss_next,
"nfinfo ", sp->ss_nfinfo,
"ninos ", sp->ss_ninos,
"sumsum ", sp->ss_sumsum,
- "datasum ", sp->ss_datasum );
- (void)printf("\tcreate %s", ctime((time_t *)&sp->ss_create));
+ "datasum ", sp->ss_datasum,
+ "magic ", sp->ss_magic);
+ (void)printf(" create %s", ctime((time_t *)&sp->ss_create));
}
- numblocks = (sp->ss_ninos + INOPB(lfsp) - 1) / INOPB(lfsp);
-
/* Dump out inode disk addresses */
if (flags & DUMP_INODE_ADDRS)
printf(" Inode addresses:");
@@ -162,13 +174,13 @@ dump_super(lfsp)
"cleansz ", lfsp->lfs_cleansz,
"segtabsz ", lfsp->lfs_segtabsz);
- (void)printf("%s0x%X\t%s%d\t%s0x%X\t%s%d\n",
+ (void)printf("%s0x%X\t%s%d\t%s0x%qX\t%s%d\n",
"segmask ", lfsp->lfs_segmask,
"segshift ", lfsp->lfs_segshift,
"bmask ", lfsp->lfs_bmask,
"bshift ", lfsp->lfs_bshift);
- (void)printf("%s0x%X\t\t%s%d\t%s0x%X\t%s%d\n",
+ (void)printf("%s0x%qX\t\t%s%d\t%s0x%qX\t%s%d\n",
"ffmask ", lfsp->lfs_ffmask,
"ffshift ", lfsp->lfs_ffshift,
"fbmask ", lfsp->lfs_fbmask,