1 /* $NetBSD: dumpfs.c,v 1.52 2009/04/15 05:43:22 lukem Exp $ */
4 * Copyright (c) 1983, 1992, 1993
5 * The Regents of the University of California. All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. Neither the name of the University nor the names of its contributors
16 * may be used to endorse or promote products derived from this software
17 * without specific prior written permission.
19 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 #include <sys/cdefs.h>
34 __COPYRIGHT("@(#) Copyright (c) 1983, 1992, 1993\
35 The Regents of the University of California. All rights reserved.");
40 static char sccsid
[] = "@(#)dumpfs.c 8.5 (Berkeley) 4/29/95";
42 __RCSID("$NetBSD: dumpfs.c,v 1.52 2009/04/15 05:43:22 lukem Exp $");
46 #include <sys/param.h>
49 #include <ufs/ufs/dinode.h>
50 #include <ufs/ufs/ufs_bswap.h>
51 #include <ufs/ffs/fs.h>
52 #include <ufs/ffs/ffs_extern.h>
71 uint16_t opostblsave
[32*8];
79 #define OPT_FLAG(ch) (1 << ((ch) & 31))
80 #define ISOPT(opt) (opt_flags & (opt))
81 #define opt_alt_super OPT_FLAG('a')
82 #define opt_superblock OPT_FLAG('s')
83 #define opt_cg_summary OPT_FLAG('m')
84 #define opt_cg_info OPT_FLAG('c')
85 #define opt_inodes OPT_FLAG('i')
86 #define opt_verbose OPT_FLAG('v')
87 #define DFLT_CHECK (opt_alt_super | opt_cg_info | opt_inodes | \
88 opt_cg_summary | opt_superblock)
89 #define DFLT_OPTS (opt_superblock | opt_cg_summary | opt_cg_info | opt_verbose)
92 int needswap
, printold
, is_ufs2
;
97 int dumpfs(const char *);
98 int print_superblock(struct fs
*, uint16_t *, const char *, int, off_t
);
99 int print_cgsum(const char *, int);
100 int print_cginfo(const char *, int);
101 int print_inodes(const char *, int, int, int);
102 int print_alt_super(const char *, int);
103 int dumpcg(const char *, int, int);
104 int main(int, char **);
105 int openpartition(const char *, int, char *, size_t);
106 void pbits(int, void *, int);
108 void print_ufs1_inode(int, int, void *);
109 void print_ufs2_inode(int, int, void *);
110 void fix_superblock(struct fs
*, uint16_t *);
113 main(int argc
, char *argv
[])
117 while ((ch
= getopt(argc
, argv
, "acimsvF")) != -1)
119 case 'a': /* alternate superblocks */
120 case 'c': /* cylinder group info */
121 case 'i': /* actual inodes */
122 case 'm': /* cylinder group summary */
123 case 's': /* superblock */
124 case 'v': /* more verbose */
125 opt_flags
|= OPT_FLAG(ch
);
127 case 'F': /* File (not device) */
137 if ((opt_flags
& DFLT_CHECK
) == 0)
138 opt_flags
|= DFLT_OPTS
;
143 for (eval
= 0; *argv
; ++argv
) {
144 eval
|= dumpfs(*argv
);
152 dumpfs(const char *name
)
154 static const off_t sblock_try
[] = SBLOCKSEARCH
;
155 char device
[MAXPATHLEN
];
160 fd
= open(name
, O_RDONLY
);
162 fd
= openpartition(name
, O_RDONLY
, device
, sizeof(device
));
169 if (sblock_try
[i
] == -1) {
170 warnx("%s: could not find superblock, skipped", name
);
173 if (lseek(fd
, sblock_try
[i
], SEEK_SET
) == (off_t
)-1)
175 if (read(fd
, &afs
, SBLOCKSIZE
) != SBLOCKSIZE
)
177 switch(afs
.fs_magic
) {
183 case FS_UFS2_MAGIC_SWAPPED
:
187 case FS_UFS1_MAGIC_SWAPPED
:
193 fix_superblock(&afs
, opostblsave
);
195 if (sblock_try
[i
] == SBLOCK_UFS2
)
196 /* This might be an alternate superblock */
199 if (sblock_try
[i
] != afs
.fs_sblockloc
)
200 /* This must be an alternate superblock */
207 dev_bsize
= afs
.fs_fsize
/ fsbtodb(&afs
, 1);
210 printf("file system: %s\n", name
);
212 if (ISOPT(opt_superblock
))
213 rval
= print_superblock(&afs
, opostblsave
, name
, fd
, sblock_try
[i
]);
214 if (rval
== 0 && ISOPT(opt_cg_summary
))
215 rval
= print_cgsum(name
, fd
);
216 if (rval
== 0 && ISOPT(opt_alt_super
))
217 rval
= print_alt_super(name
, fd
);
218 if (rval
== 0 && ISOPT(opt_cg_info
))
219 rval
= print_cginfo(name
, fd
);
220 else if (rval
== 0 && ISOPT(opt_inodes
))
221 rval
= print_inodes(name
, fd
, 0, afs
.fs_ncg
);
232 fix_superblock(struct fs
*fs
, uint16_t *opostbl
)
235 (((int32_t)bswap32(fs
->fs_old_postblformat
) == FS_42POSTBLFMT
) ||
236 (bswap32(fs
->fs_old_postbloff
) == offsetof(struct fs
, fs_old_postbl_start
)))) {
238 memcpy(opostbl
, &fs
->fs_old_postbl_start
, 512);
240 opostbl
[i
] = bswap16(opostbl
[i
]);
241 } else if (!needswap
&&
242 ((fs
->fs_old_postblformat
== FS_42POSTBLFMT
) ||
243 (fs
->fs_old_postbloff
== offsetof(struct fs
, fs_old_postbl_start
)))) {
244 memcpy(opostbl
, &fs
->fs_old_postbl_start
, 512);
250 printold
= (fs
->fs_magic
== FS_UFS1_MAGIC
&&
251 (fs
->fs_old_flags
& FS_FLAGS_UPDATED
) == 0);
253 fs
->fs_sblockloc
= SBLOCK_UFS1
;
254 fs
->fs_flags
= fs
->fs_old_flags
;
255 fs
->fs_maxbsize
= fs
->fs_bsize
;
256 fs
->fs_time
= fs
->fs_old_time
;
257 fs
->fs_size
= fs
->fs_old_size
;
258 fs
->fs_dsize
= fs
->fs_old_dsize
;
259 fs
->fs_csaddr
= fs
->fs_old_csaddr
;
260 fs
->fs_cstotal
.cs_ndir
= fs
->fs_old_cstotal
.cs_ndir
;
261 fs
->fs_cstotal
.cs_nbfree
= fs
->fs_old_cstotal
.cs_nbfree
;
262 fs
->fs_cstotal
.cs_nifree
= fs
->fs_old_cstotal
.cs_nifree
;
263 fs
->fs_cstotal
.cs_nffree
= fs
->fs_old_cstotal
.cs_nffree
;
266 if (printold
&& fs
->fs_old_postblformat
== FS_42POSTBLFMT
)
267 fs
->fs_old_nrpos
= 8;
271 print_superblock(struct fs
*fs
, uint16_t *opostbl
,
272 const char *name
, int fd
, off_t sblock
)
278 printf("format\tFFSv%d\n", is_ufs2
+1);
279 #if BYTE_ORDER == LITTLE_ENDIAN
284 printf("endian\tbig-endian\n");
286 printf("endian\tlittle-endian\n");
288 if ((sblock
!= SBLOCK_UFS1
) || ISOPT(opt_alt_super
))
289 printf("location %lld\t(-b %lld)\n",
290 (long long)sblock
, (long long)(sblock
/dev_bsize
));
291 printf("magic\t%-8x\ttime\t%s",
292 fs
->fs_magic
, ctime(&t
));
298 if (fs
->fs_old_postblformat
!= FS_42POSTBLFMT
) {
300 if (fs
->fs_old_inodefmt
>= FS_44INODEFMT
) {
304 max
= fs
->fs_maxcontig
;
305 size
= fs
->fs_contigsumsize
;
306 if ((max
< 2 && size
== 0)
307 || (max
> 1 && size
>= MIN(max
, FS_MAXCONTIG
)))
310 if (fs
->fs_old_flags
& FS_FLAGS_UPDATED
) {
315 if (!printold
|| fs
->fs_sblockloc
!= SBLOCK_UFS1
||
316 fs
->fs_id
[0] || fs
->fs_id
[1])
317 printf("superblock location\t%jd\tid\t[ %x %x ]\n",
318 (intmax_t)fs
->fs_sblockloc
, fs
->fs_id
[0], fs
->fs_id
[1]);
319 printf("cylgrp\t%s\tinodes\t%s\tsblock\t%s\tfslevel %d\n",
320 i
< 1 ? "static" : "dynamic",
321 i
< 2 ? "4.2/4.3BSD" : i
< 5 ? "4.4BSD" : "FFSv2",
322 i
< 4 ? "FFSv1" : "FFSv2", i
);
323 printf("nbfree\t%lld\tndir\t%lld\tnifree\t%lld\tnffree\t%lld\n",
324 (long long)fs
->fs_cstotal
.cs_nbfree
,
325 (long long)fs
->fs_cstotal
.cs_ndir
,
326 (long long)fs
->fs_cstotal
.cs_nifree
,
327 (long long)fs
->fs_cstotal
.cs_nffree
);
329 printf("ncg\t%d\tncyl\t%d\tsize\t%lld\tblocks\t%lld\n",
330 fs
->fs_ncg
, fs
->fs_old_ncyl
, (long long)fs
->fs_size
, (long long)fs
->fs_dsize
);
332 printf("ncg\t%d\tsize\t%lld\tblocks\t%lld\n",
333 fs
->fs_ncg
, (long long)fs
->fs_size
, (long long)fs
->fs_dsize
);
334 printf("bsize\t%d\tshift\t%d\tmask\t0x%08x\n",
335 fs
->fs_bsize
, fs
->fs_bshift
, fs
->fs_bmask
);
336 printf("fsize\t%d\tshift\t%d\tmask\t0x%08x\n",
337 fs
->fs_fsize
, fs
->fs_fshift
, fs
->fs_fmask
);
338 printf("frag\t%d\tshift\t%d\tfsbtodb\t%d\n",
339 fs
->fs_frag
, fs
->fs_fragshift
, fs
->fs_fsbtodb
);
341 printf("cpg\t%d\t", fs
->fs_old_cpg
);
342 printf("bpg\t%d\tfpg\t%d\tipg\t%d\n",
343 fs
->fs_fpg
/ fs
->fs_frag
, fs
->fs_fpg
, fs
->fs_ipg
);
344 printf("minfree\t%d%%\toptim\t%s\tmaxcontig %d\tmaxbpg\t%d\n",
345 fs
->fs_minfree
, fs
->fs_optim
== FS_OPTSPACE
? "space" : "time",
346 fs
->fs_maxcontig
, fs
->fs_maxbpg
);
348 printf("rotdelay %dms\theadswitch %dus\ttrackseek %dus\trps\t%d\n",
349 fs
->fs_old_rotdelay
, fs
->fs_old_headswitch
,
350 fs
->fs_old_trkseek
, fs
->fs_old_rps
);
351 printf("ntrak\t%d\tnsect\t%d\tnpsect\t%d\tspc\t%d\n",
352 fs
->fs_spare2
, fs
->fs_old_nsect
, fs
->fs_old_npsect
,
355 printf("symlinklen %d\t", fs
->fs_maxsymlinklen
);
357 printf("trackskew %d\tinterleave %d\t",
358 fs
->fs_old_trackskew
, fs
->fs_old_interleave
);
359 printf("contigsumsize %d\n", fs
->fs_contigsumsize
);
360 printf("maxfilesize 0x%016llx\n",
361 (unsigned long long)fs
->fs_maxfilesize
);
363 printf("nindir\t%d\tinopb\t%d\tnspf\t%d\n", fs
->fs_nindir
,
364 fs
->fs_inopb
, fs
->fs_old_nspf
);
366 printf("nindir\t%d\tinopb\t%d\n", fs
->fs_nindir
, fs
->fs_inopb
);
367 if (!printold
|| (fs
->fs_avgfilesize
> 0) || (fs
->fs_avgfpdir
> 0))
368 printf("avgfilesize %d\tavgfpdir %d\n",
369 fs
->fs_avgfilesize
, fs
->fs_avgfpdir
);
370 printf("sblkno\t%d\tcblkno\t%d\tiblkno\t%d\tdblkno\t%d\n",
371 fs
->fs_sblkno
, fs
->fs_cblkno
, fs
->fs_iblkno
, fs
->fs_dblkno
);
372 printf("sbsize\t%d\tcgsize\t%d", fs
->fs_sbsize
, fs
->fs_cgsize
);
374 printf("\toffset\t%d\tmask\t0x%08x",
375 fs
->fs_old_cgoffset
, fs
->fs_old_cgmask
);
376 printf("\ncsaddr\t%lld\tcssize\t%d",
377 (long long)fs
->fs_csaddr
, fs
->fs_cssize
);
379 printf("\tshift\t%d\tmask\t0x%08x",
380 fs
->fs_old_csshift
, fs
->fs_old_csmask
);
381 printf("\ncgrotor\t%d\tfmod\t%d\tronly\t%d\tclean\t0x%02x\n",
382 fs
->fs_cgrotor
, fs
->fs_fmod
, fs
->fs_ronly
, fs
->fs_clean
);
383 printf("wapbl version 0x%x\tlocation %u\tflags 0x%x\n",
384 fs
->fs_journal_version
, fs
->fs_journal_location
,
385 fs
->fs_journal_flags
);
386 printf("wapbl loc0 %" PRIu64
"\tloc1 %" PRIu64
,
387 fs
->fs_journallocs
[0], fs
->fs_journallocs
[1]);
388 printf("\tloc2 %" PRIu64
"\tloc3 %" PRIu64
"\n",
389 fs
->fs_journallocs
[2], fs
->fs_journallocs
[3]);
391 if (fs
->fs_flags
== 0)
393 if (fs
->fs_flags
& FS_UNCLEAN
)
395 if (fs
->fs_flags
& FS_DOSOFTDEP
)
396 printf("soft-updates ");
397 if (fs
->fs_flags
& FS_NEEDSFSCK
)
398 printf("needs fsck run ");
399 if (fs
->fs_flags
& FS_INDEXDIRS
)
400 printf("indexed directories ");
401 if (fs
->fs_flags
& FS_ACLS
)
403 if (fs
->fs_flags
& FS_MULTILABEL
)
404 printf("multilabel ");
405 if (fs
->fs_flags
& FS_FLAGS_UPDATED
)
406 printf("fs_flags expanded ");
407 if (fs
->fs_flags
& FS_DOWAPBL
)
409 fsflags
= fs
->fs_flags
& ~(FS_UNCLEAN
| FS_DOSOFTDEP
| FS_NEEDSFSCK
|
410 FS_INDEXDIRS
| FS_ACLS
| FS_MULTILABEL
|
411 FS_FLAGS_UPDATED
| FS_DOWAPBL
);
413 printf("unknown flags (%#x)", fsflags
);
414 printf("\nfsmnt\t%s\n", fs
->fs_fsmnt
);
416 printf("volname\t%s\tswuid\t%ju\n",
417 fs
->fs_volname
, (uintmax_t)fs
->fs_swuid
);
419 if (fs
->fs_old_cpc
!= 0)
420 printf("blocks available in each of %d rotational "
421 "positions\n", fs
->fs_old_nrpos
);
423 printf("(no rotational position table)\n\n");
424 if (ISOPT(opt_verbose
)) {
426 for (c
= 0; c
< fs
->fs_old_cpc
; c
++) {
427 printf("cylinder number %d:", c
);
428 for (i
= 0; i
< fs
->fs_old_nrpos
; i
++) {
429 if (old_fs_postbl(&afs
, c
, opostbl
)[i
] == -1)
431 printf("\n position %d:\t", i
);
432 for (j
= old_fs_postbl(&afs
, c
, opostbl
)[i
], k
= 1; ;
433 j
+= old_fs_rotbl(&afs
)[j
], k
++) {
437 if (old_fs_rotbl(&afs
)[j
] == 0)
450 print_cgsum(const char *name
, int fd
)
455 afs
.fs_csp
= calloc(1, afs
.fs_cssize
);
456 for (i
= 0, j
= 0; i
< afs
.fs_cssize
; i
+= afs
.fs_bsize
, j
++) {
457 size
= afs
.fs_cssize
- i
< afs
.fs_bsize
?
458 afs
.fs_cssize
- i
: afs
.fs_bsize
;
459 ccsp
= (struct csum
*)((char *)afs
.fs_csp
+ i
);
461 (off_t
)(fsbtodb(&afs
, (afs
.fs_csaddr
+ j
* afs
.fs_frag
))) *
462 dev_bsize
, SEEK_SET
) == (off_t
)-1)
464 if (read(fd
, ccsp
, size
) != size
)
467 ffs_csum_swap(ccsp
, ccsp
, size
);
470 printf("cs[].cs_(nbfree,ndir,nifree,nffree):\n\t");
471 for (i
= 0; i
< afs
.fs_ncg
; i
++) {
472 struct csum
*cs
= &afs
.fs_cs(&afs
, i
);
475 printf("(%d,%d,%d,%d) ",
476 cs
->cs_nbfree
, cs
->cs_ndir
, cs
->cs_nifree
, cs
->cs_nffree
);
479 if (printold
&& (afs
.fs_old_ncyl
% afs
.fs_old_cpg
)) {
480 printf("cylinders in last group %d\n",
481 i
= afs
.fs_old_ncyl
% afs
.fs_old_cpg
);
482 printf("blocks in last group %d\n",
483 i
* afs
.fs_old_spc
/ (afs
.fs_old_nspf
<< afs
.fs_fragshift
));
492 print_alt_super(const char *name
, int fd
)
497 uint16_t alt_opostblsave
[32*8];
500 for (i
= 0; i
< afs
.fs_ncg
; i
++) {
501 loc
= (off_t
)(fsbtodb(&afs
, cgsblock(&afs
, i
))) * dev_bsize
;
502 printf("\nalternate %d\n", i
);
503 if (pread(fd
, &alt
, sizeof alt
, loc
) != sizeof alt
) {
504 warnx("%s: error reading alt %d", name
, i
);
507 save_printold
= printold
;
508 fix_superblock(&alt
.fs
, alt_opostblsave
);
509 if (print_superblock(&alt
.fs
, alt_opostblsave
, name
, fd
, loc
)) {
510 printold
= save_printold
;
513 printold
= save_printold
;
519 print_cginfo(const char *name
, int fd
)
524 for (i
= 0; i
< afs
.fs_ncg
; i
++) {
526 if (dumpcg(name
, fd
, i
))
528 if (ISOPT(opt_inodes
) && print_inodes(name
, fd
, i
, 1))
535 print_inodes(const char *name
, int fd
, int c
, int n
)
537 void *ino_buf
= malloc(afs
.fs_bsize
);
538 void (*print_inode
)(int, int, void *);
544 print_inode
= is_ufs2
? print_ufs2_inode
: print_ufs1_inode
;
546 for (inum
= c
* afs
.fs_ipg
; inum
< (c
+n
) * afs
.fs_ipg
; inum
+= afs
.fs_inopb
) {
547 if (pread(fd
, ino_buf
, afs
.fs_bsize
,
548 ino_to_fsba(&afs
, inum
) * afs
.fs_fsize
) != afs
.fs_bsize
) {
552 for (i
= 0; i
< afs
.fs_inopb
; i
++)
553 print_inode(inum
+ i
, i
, ino_buf
);
561 dumpcg(const char *name
, int fd
, int c
)
567 printf("cg %d:\n", c
);
568 if ((cur
= lseek(fd
, (off_t
)(fsbtodb(&afs
, cgtod(&afs
, c
))) * dev_bsize
,
569 SEEK_SET
)) == (off_t
)-1)
571 if (read(fd
, &acg
, afs
.fs_bsize
) != afs
.fs_bsize
) {
572 warnx("%s: error reading cg", name
);
576 ffs_cg_swap(&acg
, &acg
, &afs
);
581 printf("magic\t%x\ttell\t%llx\ttime\t%s",
582 afs
.fs_old_postblformat
== FS_42POSTBLFMT
?
583 ((struct ocg
*)&acg
)->cg_magic
: acg
.cg_magic
,
584 (long long)cur
, ctime(&t
));
586 printf("cgx\t%d\tncyl\t%d\tniblk\t%d\tndblk\t%d\n",
587 acg
.cg_cgx
, acg
.cg_old_ncyl
, acg
.cg_old_niblk
,
590 printf("cgx\t%d\tniblk\t%d\tndblk\t%d\n",
591 acg
.cg_cgx
, acg
.cg_niblk
, acg
.cg_ndblk
);
592 printf("nbfree\t%d\tndir\t%d\tnifree\t%d\tnffree\t%d\n",
593 acg
.cg_cs
.cs_nbfree
, acg
.cg_cs
.cs_ndir
,
594 acg
.cg_cs
.cs_nifree
, acg
.cg_cs
.cs_nffree
);
595 printf("rotor\t%d\tirotor\t%d\tfrotor\t%d\nfrsum",
596 acg
.cg_rotor
, acg
.cg_irotor
, acg
.cg_frotor
);
597 for (i
= 1, j
= 0; i
< afs
.fs_frag
; i
++) {
598 printf("\t%d", acg
.cg_frsum
[i
]);
599 j
+= i
* acg
.cg_frsum
[i
];
601 printf("\nsum of frsum: %d", j
);
602 if (afs
.fs_contigsumsize
> 0) {
603 for (i
= 1; i
< afs
.fs_contigsumsize
; i
++) {
604 if ((i
- 1) % 8 == 0)
605 printf("\nclusters %d-%d:", i
,
606 afs
.fs_contigsumsize
- 1 < i
+ 7 ?
607 afs
.fs_contigsumsize
- 1 : i
+ 7);
608 printf("\t%d", cg_clustersum(&acg
, 0)[i
]);
610 printf("\nclusters size %d and over: %d\n",
611 afs
.fs_contigsumsize
,
612 cg_clustersum(&acg
, 0)[afs
.fs_contigsumsize
]);
613 printf("clusters free:\t");
614 pbits(0, cg_clustersfree(&acg
, 0), acg
.cg_nclusterblks
);
618 pbits(0 * c
* afs
.fs_ipg
, cg_inosused(&acg
, 0), afs
.fs_ipg
);
620 pbits(0, cg_blksfree(&acg
, 0), afs
.fs_fpg
);
621 if (printold
&& ISOPT(opt_verbose
)) {
623 for (i
= 0; i
< afs
.fs_old_cpg
; i
++) {
624 if (old_cg_blktot(&acg
, 0)[i
] == 0)
626 printf(" c%d:\t(%d)\t", i
, old_cg_blktot(&acg
, 0)[i
]);
627 for (j
= 0; j
< afs
.fs_old_nrpos
; j
++) {
628 if (afs
.fs_old_cpc
> 0 &&
629 old_fs_postbl(&afs
, i
% afs
.fs_old_cpc
, opostblsave
)[j
] == -1)
631 printf(" %d", old_cg_blks(&afs
, &acg
, i
, 0)[j
]);
640 print_ufs1_inode(int inum
, int i_off
, void *ibuf
)
642 struct ufs1_dinode
*i
= ibuf
;
647 ffs_dinode1_swap(i
,i
);
649 if (afs
.fs_old_inodefmt
< FS_44INODEFMT
) {
650 i
->di_uid
= i
->di_ouid
;
651 i
->di_gid
= i
->di_ogid
;
654 if (inum
% afs
.fs_ipg
== 0)
655 printf(" inode: mode nlink size"
656 " ctime.nsec flags blocks"
657 " generation uid gid\n");
658 if (i
->di_mode
== 0 && i
->di_nlink
== 0 && !ISOPT(opt_verbose
))
660 printf("%8u: %6o %6d %20" PRIu64
" %10u.%09u %8x %10u %8x %10u %10u\n",
661 inum
, i
->di_mode
, i
->di_nlink
, i
->di_size
,
662 i
->di_ctime
, i
->di_ctimensec
, i
->di_flags
, i
->di_blocks
,
663 i
->di_gen
, i
->di_uid
, i
->di_gid
);
667 print_ufs2_inode(int inum
, int i_off
, void *ibuf
)
669 struct ufs2_dinode
*i
= ibuf
;
674 ffs_dinode2_swap(i
,i
);
676 if (inum
% afs
.fs_ipg
== 0)
677 printf(" inode: mode nlink size"
678 " ctime.nsec flags blocks"
679 " generation uid gid\n");
681 if (i
->di_mode
== 0 && i
->di_nlink
== 0 && !ISOPT(opt_verbose
))
684 printf("%8u: %6o %6d %20" PRIu64
" %10" PRIu64
".%09u %8x %10" PRIu64
" %8x %10u %10u\n",
685 inum
, i
->di_mode
, i
->di_nlink
, i
->di_size
,
686 i
->di_ctime
, i
->di_ctimensec
, i
->di_flags
, i
->di_blocks
,
687 i
->di_gen
, i
->di_uid
, i
->di_gid
);
692 pbits(int offset
, void *vp
, int max
)
698 for (count
= i
= 0, p
= vp
; i
< max
; i
++)
701 printf(",%s", count
% 6 ? " " : "\n\t");
703 printf("%d", offset
+ i
);
705 while ((i
+1)<max
&& isset(p
, i
+1))
708 printf("-%d", offset
+ i
);
717 (void)fprintf(stderr
, "usage: dumpfs [-acFimsv] filesys | device [...]\n");
722 openpartition(const char *name
, int flags
, char *device
, size_t devicelen
)
724 char rawspec
[MAXPATHLEN
], *p
;
728 fs
= getfsfile(name
);
730 if ((p
= strrchr(fs
->fs_spec
, '/')) != NULL
) {
731 snprintf(rawspec
, sizeof(rawspec
), "%.*s/r%s",
732 (int)(p
- fs
->fs_spec
), fs
->fs_spec
, p
+ 1);
737 fd
= opendisk(name
, flags
, device
, devicelen
, 0);
738 if (fd
== -1 && errno
== ENOENT
) {
740 strlcpy(device
, name
, devicelen
);