xref: /netbsd-src/usr.sbin/dumplfs/dumplfs.c (revision ae9172d6cd9432a6a1a56760d86b32c57a66c39c)
1 /*-
2  * Copyright (c) 1991, 1993
3  *	The Regents of the University of California.  All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  *    notice, this list of conditions and the following disclaimer in the
12  *    documentation and/or other materials provided with the distribution.
13  * 3. All advertising materials mentioning features or use of this software
14  *    must display the following acknowledgement:
15  *	This product includes software developed by the University of
16  *	California, Berkeley and its contributors.
17  * 4. Neither the name of the University nor the names of its contributors
18  *    may be used to endorse or promote products derived from this software
19  *    without specific prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31  * SUCH DAMAGE.
32  */
33 
34 #ifndef lint
35 static char copyright[] =
36 "@(#) Copyright (c) 1991, 1993\n\
37 	The Regents of the University of California.  All rights reserved.\n";
38 #endif /* not lint */
39 
40 #ifndef lint
41 /*static char sccsid[] = "from: @(#)dumplfs.c	8.1 (Berkeley) 6/5/93";*/
42 static char *rcsid = "$Id: dumplfs.c,v 1.4 1994/12/05 20:15:39 cgd Exp $";
43 #endif /* not lint */
44 
45 #include <sys/param.h>
46 #include <sys/ucred.h>
47 #include <sys/mount.h>
48 #include <sys/time.h>
49 
50 #include <ufs/ufs/dinode.h>
51 #include <ufs/lfs/lfs.h>
52 
53 #include <err.h>
54 #include <errno.h>
55 #include <fcntl.h>
56 #include <fstab.h>
57 #include <stdlib.h>
58 #include <stdio.h>
59 #include <string.h>
60 #include <unistd.h>
61 #include "extern.h"
62 
63 static void	addseg __P((char *));
64 static void	dump_cleaner_info __P((struct lfs *, void *));
65 static void	dump_dinode __P((struct dinode *));
66 static void	dump_ifile __P((int, struct lfs *, int));
67 static int	dump_ipage_ifile __P((int, IFILE *, int));
68 static int	dump_ipage_segusage __P((struct lfs *, int, IFILE *, int));
69 static void	dump_segment __P((int, int, daddr_t, struct lfs *, int));
70 static int	dump_sum __P((int, struct lfs *, SEGSUM *, int, daddr_t));
71 static void	dump_super __P((struct lfs *));
72 static void	usage __P((void));
73 
74 typedef struct seglist SEGLIST;
75 struct seglist {
76         SEGLIST *next;
77 	int num;
78 };
79 SEGLIST	*seglist;
80 
81 int daddr_shift;
82 char *special;
83 
84 /* Segment Usage formats */
85 #define print_suheader \
86 	(void)printf("segnum\tflags\tnbytes\tninos\tnsums\tlastmod\n")
87 
88 #define print_suentry(i, sp) \
89 	(void)printf("%d\t%c%c%c\t%d\t%d\t%d\t%s", i, \
90 	    (((sp)->su_flags & SEGUSE_ACTIVE) ? 'A' : ' '), \
91 	    (((sp)->su_flags & SEGUSE_DIRTY) ? 'D' : 'C'), \
92 	    (((sp)->su_flags & SEGUSE_SUPERBLOCK) ? 'S' : ' '), \
93 	    (sp)->su_nbytes, (sp)->su_ninos, (sp)->su_nsums, \
94 	    ctime((time_t *)&(sp)->su_lastmod))
95 
96 /* Ifile formats */
97 #define print_iheader \
98 	(void)printf("inum\tstatus\tversion\tdaddr\t\tfreeptr\n")
99 #define print_ientry(i, ip) \
100 	if (ip->if_daddr == LFS_UNUSED_DADDR) \
101 		(void)printf("%d\tFREE\t%d\t \t\t%d\n", \
102 		    i, ip->if_version, ip->if_nextfree); \
103 	else \
104 		(void)printf("%d\tINUSE\t%d\t%8X    \n", \
105 		    i, ip->if_version, ip->if_daddr)
106 int
107 main(argc, argv)
108 	int argc;
109 	char *argv[];
110 {
111 	struct lfs lfs_sb1, lfs_sb2, *lfs_master;
112 	daddr_t seg_addr;
113 	int ch, do_allsb, do_ientries, fd, segnum;
114 
115 	do_allsb = 0;
116 	do_ientries = 0;
117 	while ((ch = getopt(argc, argv, "ais:")) != -1)
118 		switch(ch) {
119 		case 'a':		/* Dump all superblocks */
120 			do_allsb = 1;
121 			break;
122 		case 'i':		/* Dump ifile entries */
123 			do_ientries = 1;
124 			break;
125 		case 's':		/* Dump out these segments */
126 			addseg(optarg);
127 			break;
128 		default:
129 			usage();
130 		}
131 	argc -= optind;
132 	argv += optind;
133 
134 	if (argc != 1)
135 		usage();
136 
137 	special = argv[0];
138 	if ((fd = open(special, O_RDONLY, 0)) < 0)
139 		err(1, "%s", special);
140 
141 	/* Read the first superblock */
142 	get(fd, LFS_LABELPAD, &lfs_sb1, sizeof(struct lfs));
143 	daddr_shift = lfs_sb1.lfs_bshift - lfs_sb1.lfs_fsbtodb;
144 
145 	/*
146 	 * Read the second superblock and figure out which check point is
147 	 * most up to date.
148 	 */
149 	get(fd,
150 	    lfs_sb1.lfs_sboffs[1] << daddr_shift, &lfs_sb2, sizeof(struct lfs));
151 
152 	lfs_master = &lfs_sb1;
153 	if (lfs_sb1.lfs_tstamp < lfs_sb2.lfs_tstamp)
154 		lfs_master = &lfs_sb2;
155 
156 	(void)printf("Master Superblock:\n");
157 	dump_super(lfs_master);
158 
159 	dump_ifile(fd, lfs_master, do_ientries);
160 
161 	if (seglist != NULL)
162 		for (; seglist != NULL; seglist = seglist->next) {
163 			seg_addr = lfs_master->lfs_sboffs[0] + seglist->num *
164 			    (lfs_master->lfs_ssize << lfs_master->lfs_fsbtodb);
165 			dump_segment(fd,
166 			    seglist->num, seg_addr, lfs_master, do_allsb);
167 		}
168 	else
169 		for (segnum = 0, seg_addr = lfs_master->lfs_sboffs[0];
170 		    segnum < lfs_master->lfs_nseg; segnum++, seg_addr +=
171 		    lfs_master->lfs_ssize << lfs_master->lfs_fsbtodb)
172 			dump_segment(fd,
173 			    segnum, seg_addr, lfs_master, do_allsb);
174 
175 	(void)close(fd);
176 	exit(0);
177 }
178 
179 /*
180  * We are reading all the blocks of an inode and dumping out the ifile table.
181  * This code could be tighter, but this is a first pass at getting the stuff
182  * printed out rather than making this code incredibly efficient.
183  */
184 static void
185 dump_ifile(fd, lfsp, do_ientries)
186 	int fd;
187 	struct lfs *lfsp;
188 	int do_ientries;
189 {
190 	IFILE *ipage;
191 	struct dinode *dip, *dpage;
192 	daddr_t addr, *addrp, *dindir, *iaddrp, *indir;
193 	int block_limit, i, inum, j, nblocks, psize;
194 
195 	psize = lfsp->lfs_bsize;
196 	addr = lfsp->lfs_idaddr;
197 
198 	if (!(dpage = malloc(psize)))
199 		err(1, "malloc");
200 	get(fd, addr << daddr_shift, dpage, psize);
201 
202 	for (dip = dpage + INOPB(lfsp) - 1; dip >= dpage; --dip)
203 		if (dip->di_inumber == LFS_IFILE_INUM)
204 			break;
205 
206 	if (dip < dpage)
207 		errx(1, "unable to locate ifile inode");
208 
209 	(void)printf("\nIFILE inode\n");
210 	dump_dinode(dip);
211 
212 	(void)printf("\nIFILE contents\n");
213 	nblocks = dip->di_size >> lfsp->lfs_bshift;
214 	block_limit = MIN(nblocks, NDADDR);
215 
216 	/* Get the direct block */
217 	if ((ipage = malloc(psize)) == NULL)
218 		err(1, "malloc");
219 	for (inum = 0, addrp = dip->di_db, i = 0; i < block_limit;
220 	    i++, addrp++) {
221 		get(fd, *addrp << daddr_shift, ipage, psize);
222 		if (i < lfsp->lfs_cleansz) {
223 			dump_cleaner_info(lfsp, ipage);
224 			print_suheader;
225 			continue;
226 		}
227 
228 		if (i < (lfsp->lfs_segtabsz + lfsp->lfs_cleansz)) {
229 			inum = dump_ipage_segusage(lfsp, inum, ipage,
230 			    lfsp->lfs_sepb);
231 			if (!inum)
232 				if(!do_ientries)
233 					goto e0;
234 				else
235 					print_iheader;
236 		} else
237 			inum = dump_ipage_ifile(inum, ipage, lfsp->lfs_ifpb);
238 
239 	}
240 
241 	if (nblocks <= NDADDR)
242 		goto e0;
243 
244 	/* Dump out blocks off of single indirect block */
245 	if (!(indir = malloc(psize)))
246 		err(1, "malloc");
247 	get(fd, dip->di_ib[0] << daddr_shift, indir, psize);
248 	block_limit = MIN(i + lfsp->lfs_nindir, nblocks);
249 	for (addrp = indir; i < block_limit; i++, addrp++) {
250 		if (*addrp == LFS_UNUSED_DADDR)
251 			break;
252 		get(fd, *addrp << daddr_shift,ipage, psize);
253 		if (i < lfsp->lfs_cleansz) {
254 			dump_cleaner_info(lfsp, ipage);
255 			continue;
256 		} else
257 			i -= lfsp->lfs_cleansz;
258 
259 		if (i < lfsp->lfs_segtabsz) {
260 			inum = dump_ipage_segusage(lfsp, inum, ipage,
261 			    lfsp->lfs_sepb);
262 			if (!inum)
263 				if(!do_ientries)
264 					goto e1;
265 				else
266 					print_iheader;
267 		} else
268 			inum = dump_ipage_ifile(inum, ipage, lfsp->lfs_ifpb);
269 	}
270 
271 	if (nblocks <= lfsp->lfs_nindir * lfsp->lfs_ifpb)
272 		goto e1;
273 
274 	/* Get the double indirect block */
275 	if (!(dindir = malloc(psize)))
276 		err(1, "malloc");
277 	get(fd, dip->di_ib[1] << daddr_shift, dindir, psize);
278 	for (iaddrp = dindir, j = 0; j < lfsp->lfs_nindir; j++, iaddrp++) {
279 		if (*iaddrp == LFS_UNUSED_DADDR)
280 			break;
281 		get(fd, *iaddrp << daddr_shift, indir, psize);
282 		block_limit = MIN(i + lfsp->lfs_nindir, nblocks);
283 		for (addrp = indir; i < block_limit; i++, addrp++) {
284 			if (*addrp == LFS_UNUSED_DADDR)
285 				break;
286 			get(fd, *addrp << daddr_shift, ipage, psize);
287 			if (i < lfsp->lfs_cleansz) {
288 				dump_cleaner_info(lfsp, ipage);
289 				continue;
290 			} else
291 				i -= lfsp->lfs_cleansz;
292 
293 			if (i < lfsp->lfs_segtabsz) {
294 				inum = dump_ipage_segusage(lfsp,
295 				    inum, ipage, lfsp->lfs_sepb);
296 				if (!inum)
297 					if(!do_ientries)
298 						goto e2;
299 					else
300 						print_iheader;
301 			} else
302 				inum = dump_ipage_ifile(inum,
303 				    ipage, lfsp->lfs_ifpb);
304 		}
305 	}
306 e2:	free(dindir);
307 e1:	free(indir);
308 e0:	free(dpage);
309 	free(ipage);
310 }
311 
312 static int
313 dump_ipage_ifile(i, pp, tot)
314 	int i;
315 	IFILE *pp;
316 	int tot;
317 {
318 	IFILE *ip;
319 	int cnt, max;
320 
321 	max = i + tot;
322 
323 	for (ip = pp, cnt = i; cnt < max; cnt++, ip++)
324 		print_ientry(cnt, ip);
325 	return (max);
326 }
327 
328 static int
329 dump_ipage_segusage(lfsp, i, pp, tot)
330 	struct lfs *lfsp;
331 	int i;
332 	IFILE *pp;
333 	int tot;
334 {
335 	SEGUSE *sp;
336 	int cnt, max;
337 
338 	max = i + tot;
339 	for (sp = (SEGUSE *)pp, cnt = i;
340 	     cnt < lfsp->lfs_nseg && cnt < max; cnt++, sp++)
341 		print_suentry(cnt, sp);
342 	if (max >= lfsp->lfs_nseg)
343 		return (0);
344 	else
345 		return (max);
346 }
347 
348 static void
349 dump_dinode(dip)
350 	struct dinode *dip;
351 {
352 	int i;
353 
354 	(void)printf("%s%d\t%s%d\t%s%d\t%s%d\t%s%d\n",
355 		"mode  ", dip->di_mode,
356 		"nlink ", dip->di_nlink,
357 		"uid   ", dip->di_uid,
358 		"gid   ", dip->di_gid,
359 		"size  ", dip->di_size);
360 	(void)printf("%s%s%s%s%s%s",
361 		"atime ", ctime(&dip->di_atime.ts_sec),
362 		"mtime ", ctime(&dip->di_mtime.ts_sec),
363 		"ctime ", ctime(&dip->di_ctime.ts_sec));
364 	(void)printf("inum  %d\n", dip->di_inumber);
365 	(void)printf("Direct Addresses\n");
366 	for (i = 0; i < NDADDR; i++) {
367 		(void)printf("\t0x%X", dip->di_db[i]);
368 		if ((i % 6) == 5)
369 			(void)printf("\n");
370 	}
371 	for (i = 0; i < NIADDR; i++)
372 		(void)printf("\t0x%X", dip->di_ib[i]);
373 	(void)printf("\n");
374 }
375 
376 static int
377 dump_sum(fd, lfsp, sp, segnum, addr)
378 	struct lfs *lfsp;
379 	SEGSUM *sp;
380 	int fd, segnum;
381 	daddr_t addr;
382 {
383 	FINFO *fp;
384 	u_int32_t *dp;
385 	int i, j;
386 	int ck;
387 	int numblocks;
388 	struct dinode *inop;
389 
390 	if (sp->ss_sumsum != (ck = cksum(&sp->ss_datasum,
391 	    LFS_SUMMARY_SIZE - sizeof(sp->ss_sumsum)))) {
392 		(void)printf("dumplfs: %s %d address 0x%lx\n",
393 		    "corrupt summary block; segment", segnum, addr);
394 		return(0);
395 	}
396 
397 	(void)printf("Segment Summary Info at 0x%lx\n", addr);
398 	(void)printf("    %s0x%X\t%s%d\t%s%d\n    %s0x%X\t%s0x%X",
399 		"next     ", sp->ss_next,
400 		"nfinfo   ", sp->ss_nfinfo,
401 		"ninos    ", sp->ss_ninos,
402 		"sumsum   ", sp->ss_sumsum,
403 		"datasum  ", sp->ss_datasum );
404 	(void)printf("\tcreate   %s", ctime((time_t *)&sp->ss_create));
405 
406 	numblocks = (sp->ss_ninos + INOPB(lfsp) - 1) / INOPB(lfsp);
407 
408 	/* Dump out inode disk addresses */
409 	dp = (daddr_t *)sp;
410 	dp += LFS_SUMMARY_SIZE / sizeof(daddr_t);
411 	inop = malloc(1 << lfsp->lfs_bshift);
412 	printf("    Inode addresses:");
413 	for (dp--, i = 0; i < sp->ss_ninos; dp--) {
414 		printf("\t0x%X {", *dp);
415 		get(fd, *dp << (lfsp->lfs_bshift - lfsp->lfs_fsbtodb), inop,
416 		    (1 << lfsp->lfs_bshift));
417 		for (j = 0; i < sp->ss_ninos && j < INOPB(lfsp); j++, i++) {
418 			if (j > 0)
419 				(void)printf(", ");
420 			(void)printf("%d", inop[j].di_inumber);
421 		}
422 		(void)printf("}");
423 		if (((i/INOPB(lfsp)) % 4) == 3)
424 			(void)printf("\n");
425 	}
426 	free(inop);
427 
428 	printf("\n");
429 	for (fp = (FINFO *)(sp + 1), i = 0; i < sp->ss_nfinfo; i++) {
430 		numblocks += fp->fi_nblocks;
431 		(void)printf("    FINFO for inode: %d version %d nblocks %d\n",
432 		    fp->fi_ino, fp->fi_version, fp->fi_nblocks);
433 		dp = &(fp->fi_blocks[0]);
434 		for (j = 0; j < fp->fi_nblocks; j++, dp++) {
435 			(void)printf("\t%d", *dp);
436 			if ((j % 8) == 7)
437 				(void)printf("\n");
438 		}
439 		if ((j % 8) != 0)
440 			(void)printf("\n");
441 		fp = (FINFO *)dp;
442 	}
443 	return (numblocks);
444 }
445 
446 static void
447 dump_segment(fd, segnum, addr, lfsp, dump_sb)
448 	int fd, segnum;
449 	daddr_t addr;
450 	struct lfs *lfsp;
451 	int dump_sb;
452 {
453 	struct lfs lfs_sb, *sbp;
454 	SEGSUM *sump;
455 	char sumblock[LFS_SUMMARY_SIZE];
456 	int did_one, nblocks, sb;
457 	off_t sum_offset, super_off;
458 
459 	(void)printf("\nSEGMENT %d (Disk Address 0x%X)\n",
460 	    addr >> (lfsp->lfs_segshift - daddr_shift), addr);
461 	sum_offset = (addr << (lfsp->lfs_bshift - lfsp->lfs_fsbtodb));
462 
463 	sb = 0;
464 	did_one = 0;
465 	do {
466 		get(fd, sum_offset, sumblock, LFS_SUMMARY_SIZE);
467 		sump = (SEGSUM *)sumblock;
468 		if (sump->ss_sumsum != cksum (&sump->ss_datasum,
469 			LFS_SUMMARY_SIZE - sizeof(sump->ss_sumsum))) {
470 			sbp = (struct lfs *)sump;
471 			if (sb = (sbp->lfs_magic == LFS_MAGIC)) {
472 				super_off = sum_offset;
473 				sum_offset += LFS_SBPAD;
474 			} else if (did_one)
475 				break;
476 			else {
477 				printf("Segment at 0x%X corrupt\n", addr);
478 				break;
479 			}
480 		} else {
481 			nblocks = dump_sum(fd, lfsp, sump, segnum, sum_offset >>
482 			     (lfsp->lfs_bshift - lfsp->lfs_fsbtodb));
483 			if (nblocks)
484 				sum_offset += LFS_SUMMARY_SIZE +
485 					(nblocks << lfsp->lfs_bshift);
486 			else
487 				sum_offset = 0;
488 			did_one = 1;
489 		}
490 	} while (sum_offset);
491 
492 	if (dump_sb && sb)  {
493 		get(fd, super_off, &lfs_sb, sizeof(struct lfs));
494 		dump_super(&lfs_sb);
495 	}
496 	return;
497 }
498 
499 static void
500 dump_super(lfsp)
501 	struct lfs *lfsp;
502 {
503 	int i;
504 
505 	(void)printf("%s0x%X\t%s0x%X\t%s%d\t%s%d\n",
506 		"magic    ", lfsp->lfs_magic,
507 		"version  ", lfsp->lfs_version,
508 		"size     ", lfsp->lfs_size,
509 		"ssize    ", lfsp->lfs_ssize);
510 	(void)printf("%s%d\t\t%s%d\t%s%d\t%s%d\n",
511 		"dsize    ", lfsp->lfs_dsize,
512 		"bsize    ", lfsp->lfs_bsize,
513 		"fsize    ", lfsp->lfs_fsize,
514 		"frag     ", lfsp->lfs_frag);
515 
516 	(void)printf("%s%d\t\t%s%d\t%s%d\t%s%d\n",
517 		"minfree  ", lfsp->lfs_minfree,
518 		"inopb    ", lfsp->lfs_inopb,
519 		"ifpb     ", lfsp->lfs_ifpb,
520 		"nindir   ", lfsp->lfs_nindir);
521 
522 	(void)printf("%s%d\t\t%s%d\t%s%d\t%s%d\n",
523 		"nseg     ", lfsp->lfs_nseg,
524 		"nspf     ", lfsp->lfs_nspf,
525 		"cleansz  ", lfsp->lfs_cleansz,
526 		"segtabsz ", lfsp->lfs_segtabsz);
527 
528 	(void)printf("%s0x%X\t%s%d\t%s0x%X\t%s%d\n",
529 		"segmask  ", lfsp->lfs_segmask,
530 		"segshift ", lfsp->lfs_segshift,
531 		"bmask    ", lfsp->lfs_bmask,
532 		"bshift   ", lfsp->lfs_bshift);
533 
534 	(void)printf("%s0x%X\t\t%s%d\t%s0x%X\t%s%d\n",
535 		"ffmask   ", lfsp->lfs_ffmask,
536 		"ffshift  ", lfsp->lfs_ffshift,
537 		"fbmask   ", lfsp->lfs_fbmask,
538 		"fbshift  ", lfsp->lfs_fbshift);
539 
540 	(void)printf("%s%d\t%s%d\t%s0x%X\t%s0x%qx\n",
541 		"sushift  ", lfsp->lfs_sushift,
542 		"fsbtodb  ", lfsp->lfs_fsbtodb,
543 		"cksum    ", lfsp->lfs_cksum,
544 		"maxfilesize  ", lfsp->lfs_maxfilesize);
545 
546 	(void)printf("Superblock disk addresses:\t");
547 	for (i = 0; i < LFS_MAXNUMSB; i++) {
548 		(void)printf(" 0x%X", lfsp->lfs_sboffs[i]);
549 		if ( i == (LFS_MAXNUMSB >> 1))
550 			(void)printf("\n\t\t\t\t");
551 	}
552 	(void)printf("\n");
553 
554 	(void)printf("Checkpoint Info\n");
555 	(void)printf("%s%d\t%s0x%X\t%s%d\n",
556 		"free     ", lfsp->lfs_free,
557 		"idaddr   ", lfsp->lfs_idaddr,
558 		"ifile    ", lfsp->lfs_ifile);
559 	(void)printf("%s%d\t%s%d\t%s%d\n",
560 		"bfree    ", lfsp->lfs_bfree,
561 		"avail    ", lfsp->lfs_avail,
562 		"uinodes  ", lfsp->lfs_uinodes);
563 	(void)printf("%s%d\t%s0x%X\t%s0x%X\n%s0x%X\t%s0x%X\t",
564 		"nfiles   ", lfsp->lfs_nfiles,
565 		"lastseg  ", lfsp->lfs_lastseg,
566 		"nextseg  ", lfsp->lfs_nextseg,
567 		"curseg   ", lfsp->lfs_curseg,
568 		"offset   ", lfsp->lfs_offset);
569 	(void)printf("tstamp   %s", ctime((time_t *)&lfsp->lfs_tstamp));
570 	(void)printf("\nIn-Memory Information\n");
571 	(void)printf("%s%d\t%s0x%X\t%s%d%s%d\t%s%d\n",
572 		"seglock  ", lfsp->lfs_seglock,
573 		"iocount  ", lfsp->lfs_iocount,
574 		"writer   ", lfsp->lfs_writer,
575 		"dirops   ", lfsp->lfs_dirops,
576 		"doifile  ", lfsp->lfs_doifile);
577 	(void)printf("%s%d\t%s%d\t%s0x%X\t%s%d\n",
578 		"nactive  ", lfsp->lfs_nactive,
579 		"fmod     ", lfsp->lfs_fmod,
580 		"clean    ", lfsp->lfs_clean,
581 		"ronly    ", lfsp->lfs_ronly);
582 }
583 
584 static void
585 addseg(arg)
586 	char *arg;
587 {
588 	SEGLIST *p;
589 
590 	if ((p = malloc(sizeof(SEGLIST))) == NULL)
591 		err(1, "malloc");
592 	p->next = seglist;
593 	p->num = atoi(arg);
594 	seglist = p;
595 }
596 
597 static void
598 dump_cleaner_info(lfsp, ipage)
599 	struct lfs *lfsp;
600 	void *ipage;
601 {
602 	CLEANERINFO *cip;
603 
604 	cip = (CLEANERINFO *)ipage;
605 	(void)printf("segments clean\t%d\tsegments dirty\t%d\n\n",
606 	    cip->clean, cip->dirty);
607 }
608 
609 static void
610 usage()
611 {
612 	(void)fprintf(stderr, "usage: dumplfs [-ai] [-s segnum] file\n");
613 	exit(1);
614 }
615