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