1 /* $NetBSD: dumpfs.c,v 1.50 2008/07/31 05:38:07 simonb 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.50 2008/07/31 05:38:07 simonb 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 const static 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 ((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 #if BYTE_ORDER == LITTLE_ENDIAN
283 printf("endian\tbig-endian\n");
285 printf("endian\tlittle-endian\n");
287 if ((sblock
!= SBLOCK_UFS1
) || ISOPT(opt_alt_super
))
288 printf("location %lld\t(-b %lld)\n",
289 (long long)sblock
, (long long)(sblock
/dev_bsize
));
290 printf("magic\t%x (UFS%d)\ttime\t%s",
291 fs
->fs_magic
, is_ufs2
+1, ctime(&t
));
297 if (fs
->fs_old_postblformat
!= FS_42POSTBLFMT
) {
299 if (fs
->fs_old_inodefmt
>= FS_44INODEFMT
) {
303 max
= fs
->fs_maxcontig
;
304 size
= fs
->fs_contigsumsize
;
305 if ((max
< 2 && size
== 0)
306 || (max
> 1 && size
>= MIN(max
, FS_MAXCONTIG
)))
309 if (fs
->fs_old_flags
& FS_FLAGS_UPDATED
) {
314 if (!printold
|| fs
->fs_sblockloc
!= SBLOCK_UFS1
||
315 fs
->fs_id
[0] || fs
->fs_id
[1])
316 printf("superblock location\t%jd\tid\t[ %x %x ]\n",
317 (intmax_t)fs
->fs_sblockloc
, fs
->fs_id
[0], fs
->fs_id
[1]);
318 printf("cylgrp\t%s\tinodes\t%s\tsblock\t%s\tfslevel %d\n",
319 i
< 1 ? "static" : "dynamic",
320 i
< 2 ? "4.2/4.3BSD" : i
< 5 ? "4.4BSD" : "FFSv2",
321 i
< 4 ? "FFSv1" : "FFSv2", i
);
322 printf("nbfree\t%lld\tndir\t%lld\tnifree\t%lld\tnffree\t%lld\n",
323 (long long)fs
->fs_cstotal
.cs_nbfree
,
324 (long long)fs
->fs_cstotal
.cs_ndir
,
325 (long long)fs
->fs_cstotal
.cs_nifree
,
326 (long long)fs
->fs_cstotal
.cs_nffree
);
328 printf("ncg\t%d\tncyl\t%d\tsize\t%lld\tblocks\t%lld\n",
329 fs
->fs_ncg
, fs
->fs_old_ncyl
, (long long)fs
->fs_size
, (long long)fs
->fs_dsize
);
331 printf("ncg\t%d\tsize\t%lld\tblocks\t%lld\n",
332 fs
->fs_ncg
, (long long)fs
->fs_size
, (long long)fs
->fs_dsize
);
333 printf("bsize\t%d\tshift\t%d\tmask\t0x%08x\n",
334 fs
->fs_bsize
, fs
->fs_bshift
, fs
->fs_bmask
);
335 printf("fsize\t%d\tshift\t%d\tmask\t0x%08x\n",
336 fs
->fs_fsize
, fs
->fs_fshift
, fs
->fs_fmask
);
337 printf("frag\t%d\tshift\t%d\tfsbtodb\t%d\n",
338 fs
->fs_frag
, fs
->fs_fragshift
, fs
->fs_fsbtodb
);
340 printf("cpg\t%d\t", fs
->fs_old_cpg
);
341 printf("bpg\t%d\tfpg\t%d\tipg\t%d\n",
342 fs
->fs_fpg
/ fs
->fs_frag
, fs
->fs_fpg
, fs
->fs_ipg
);
343 printf("minfree\t%d%%\toptim\t%s\tmaxcontig %d\tmaxbpg\t%d\n",
344 fs
->fs_minfree
, fs
->fs_optim
== FS_OPTSPACE
? "space" : "time",
345 fs
->fs_maxcontig
, fs
->fs_maxbpg
);
347 printf("rotdelay %dms\theadswitch %dus\ttrackseek %dus\trps\t%d\n",
348 fs
->fs_old_rotdelay
, fs
->fs_old_headswitch
,
349 fs
->fs_old_trkseek
, fs
->fs_old_rps
);
350 printf("ntrak\t%d\tnsect\t%d\tnpsect\t%d\tspc\t%d\n",
351 fs
->fs_spare2
, fs
->fs_old_nsect
, fs
->fs_old_npsect
,
354 printf("symlinklen %d\t", fs
->fs_maxsymlinklen
);
356 printf("trackskew %d\tinterleave %d\t",
357 fs
->fs_old_trackskew
, fs
->fs_old_interleave
);
358 printf("contigsumsize %d\n", fs
->fs_contigsumsize
);
359 printf("maxfilesize 0x%016llx\n",
360 (unsigned long long)fs
->fs_maxfilesize
);
362 printf("nindir\t%d\tinopb\t%d\tnspf\t%d\n", fs
->fs_nindir
,
363 fs
->fs_inopb
, fs
->fs_old_nspf
);
365 printf("nindir\t%d\tinopb\t%d\n", fs
->fs_nindir
, fs
->fs_inopb
);
366 if (!printold
|| (fs
->fs_avgfilesize
> 0) || (fs
->fs_avgfpdir
> 0))
367 printf("avgfilesize %d\tavgfpdir %d\n",
368 fs
->fs_avgfilesize
, fs
->fs_avgfpdir
);
369 printf("sblkno\t%d\tcblkno\t%d\tiblkno\t%d\tdblkno\t%d\n",
370 fs
->fs_sblkno
, fs
->fs_cblkno
, fs
->fs_iblkno
, fs
->fs_dblkno
);
371 printf("sbsize\t%d\tcgsize\t%d", fs
->fs_sbsize
, fs
->fs_cgsize
);
373 printf("\toffset\t%d\tmask\t0x%08x",
374 fs
->fs_old_cgoffset
, fs
->fs_old_cgmask
);
375 printf("\ncsaddr\t%lld\tcssize\t%d",
376 (long long)fs
->fs_csaddr
, fs
->fs_cssize
);
378 printf("\tshift\t%d\tmask\t0x%08x",
379 fs
->fs_old_csshift
, fs
->fs_old_csmask
);
380 printf("\ncgrotor\t%d\tfmod\t%d\tronly\t%d\tclean\t0x%02x\n",
381 fs
->fs_cgrotor
, fs
->fs_fmod
, fs
->fs_ronly
, fs
->fs_clean
);
382 printf("wapbl version 0x%x\tlocation %u\tflags 0x%x\n",
383 fs
->fs_journal_version
, fs
->fs_journal_location
,
384 fs
->fs_journal_flags
);
385 printf("wapbl loc0 %" PRIu64
"\tloc1 %" PRIu64
,
386 fs
->fs_journallocs
[0], fs
->fs_journallocs
[1]);
387 printf("\tloc2 %" PRIu64
"\tloc3 %" PRIu64
"\n",
388 fs
->fs_journallocs
[2], fs
->fs_journallocs
[3]);
390 if (fs
->fs_flags
== 0)
392 if (fs
->fs_flags
& FS_UNCLEAN
)
394 if (fs
->fs_flags
& FS_DOSOFTDEP
)
395 printf("soft-updates ");
396 if (fs
->fs_flags
& FS_NEEDSFSCK
)
397 printf("needs fsck run ");
398 if (fs
->fs_flags
& FS_INDEXDIRS
)
399 printf("indexed directories ");
400 if (fs
->fs_flags
& FS_ACLS
)
402 if (fs
->fs_flags
& FS_MULTILABEL
)
403 printf("multilabel ");
404 if (fs
->fs_flags
& FS_FLAGS_UPDATED
)
405 printf("fs_flags expanded ");
406 if (fs
->fs_flags
& FS_DOWAPBL
)
408 fsflags
= fs
->fs_flags
& ~(FS_UNCLEAN
| FS_DOSOFTDEP
| FS_NEEDSFSCK
|
409 FS_INDEXDIRS
| FS_ACLS
| FS_MULTILABEL
|
410 FS_FLAGS_UPDATED
| FS_DOWAPBL
);
412 printf("unknown flags (%#x)", fsflags
);
413 printf("\nfsmnt\t%s\n", fs
->fs_fsmnt
);
415 printf("volname\t%s\tswuid\t%ju\n",
416 fs
->fs_volname
, (uintmax_t)fs
->fs_swuid
);
418 if (fs
->fs_old_cpc
!= 0)
419 printf("blocks available in each of %d rotational "
420 "positions\n", fs
->fs_old_nrpos
);
422 printf("(no rotational position table)\n\n");
423 if (ISOPT(opt_verbose
)) {
425 for (c
= 0; c
< fs
->fs_old_cpc
; c
++) {
426 printf("cylinder number %d:", c
);
427 for (i
= 0; i
< fs
->fs_old_nrpos
; i
++) {
428 if (old_fs_postbl(&afs
, c
, opostbl
)[i
] == -1)
430 printf("\n position %d:\t", i
);
431 for (j
= old_fs_postbl(&afs
, c
, opostbl
)[i
], k
= 1; ;
432 j
+= old_fs_rotbl(&afs
)[j
], k
++) {
436 if (old_fs_rotbl(&afs
)[j
] == 0)
449 print_cgsum(const char *name
, int fd
)
454 afs
.fs_csp
= calloc(1, afs
.fs_cssize
);
455 for (i
= 0, j
= 0; i
< afs
.fs_cssize
; i
+= afs
.fs_bsize
, j
++) {
456 size
= afs
.fs_cssize
- i
< afs
.fs_bsize
?
457 afs
.fs_cssize
- i
: afs
.fs_bsize
;
458 ccsp
= (struct csum
*)((char *)afs
.fs_csp
+ i
);
460 (off_t
)(fsbtodb(&afs
, (afs
.fs_csaddr
+ j
* afs
.fs_frag
))) *
461 dev_bsize
, SEEK_SET
) == (off_t
)-1)
463 if (read(fd
, ccsp
, size
) != size
)
466 ffs_csum_swap(ccsp
, ccsp
, size
);
469 printf("cs[].cs_(nbfree,ndir,nifree,nffree):\n\t");
470 for (i
= 0; i
< afs
.fs_ncg
; i
++) {
471 struct csum
*cs
= &afs
.fs_cs(&afs
, i
);
474 printf("(%d,%d,%d,%d) ",
475 cs
->cs_nbfree
, cs
->cs_ndir
, cs
->cs_nifree
, cs
->cs_nffree
);
478 if (printold
&& (afs
.fs_old_ncyl
% afs
.fs_old_cpg
)) {
479 printf("cylinders in last group %d\n",
480 i
= afs
.fs_old_ncyl
% afs
.fs_old_cpg
);
481 printf("blocks in last group %d\n",
482 i
* afs
.fs_old_spc
/ (afs
.fs_old_nspf
<< afs
.fs_fragshift
));
491 print_alt_super(const char *name
, int fd
)
496 uint16_t alt_opostblsave
[32*8];
499 for (i
= 0; i
< afs
.fs_ncg
; i
++) {
500 loc
= (off_t
)(fsbtodb(&afs
, cgsblock(&afs
, i
))) * dev_bsize
;
501 printf("\nalternate %d\n", i
);
502 if (pread(fd
, &alt
, sizeof alt
, loc
) != sizeof alt
) {
503 warnx("%s: error reading alt %d", name
, i
);
506 save_printold
= printold
;
507 fix_superblock(&alt
.fs
, alt_opostblsave
);
508 if (print_superblock(&alt
.fs
, alt_opostblsave
, name
, fd
, loc
)) {
509 printold
= save_printold
;
512 printold
= save_printold
;
518 print_cginfo(const char *name
, int fd
)
523 for (i
= 0; i
< afs
.fs_ncg
; i
++) {
525 if (dumpcg(name
, fd
, i
))
527 if (ISOPT(opt_inodes
) && print_inodes(name
, fd
, i
, 1))
534 print_inodes(const char *name
, int fd
, int c
, int n
)
536 void *ino_buf
= malloc(afs
.fs_bsize
);
537 void (*print_inode
)(int, int, void *);
543 print_inode
= is_ufs2
? print_ufs2_inode
: print_ufs1_inode
;
545 for (inum
= c
* afs
.fs_ipg
; inum
< (c
+n
) * afs
.fs_ipg
; inum
+= afs
.fs_inopb
) {
546 if (pread(fd
, ino_buf
, afs
.fs_bsize
,
547 ino_to_fsba(&afs
, inum
) * afs
.fs_fsize
) != afs
.fs_bsize
) {
551 for (i
= 0; i
< afs
.fs_inopb
; i
++)
552 print_inode(inum
+ i
, i
, ino_buf
);
560 dumpcg(const char *name
, int fd
, int c
)
566 printf("cg %d:\n", c
);
567 if ((cur
= lseek(fd
, (off_t
)(fsbtodb(&afs
, cgtod(&afs
, c
))) * dev_bsize
,
568 SEEK_SET
)) == (off_t
)-1)
570 if (read(fd
, &acg
, afs
.fs_bsize
) != afs
.fs_bsize
) {
571 warnx("%s: error reading cg", name
);
575 ffs_cg_swap(&acg
, &acg
, &afs
);
580 printf("magic\t%x\ttell\t%llx\ttime\t%s",
581 afs
.fs_old_postblformat
== FS_42POSTBLFMT
?
582 ((struct ocg
*)&acg
)->cg_magic
: acg
.cg_magic
,
583 (long long)cur
, ctime(&t
));
585 printf("cgx\t%d\tncyl\t%d\tniblk\t%d\tndblk\t%d\n",
586 acg
.cg_cgx
, acg
.cg_old_ncyl
, acg
.cg_old_niblk
,
589 printf("cgx\t%d\tniblk\t%d\tndblk\t%d\n",
590 acg
.cg_cgx
, acg
.cg_niblk
, acg
.cg_ndblk
);
591 printf("nbfree\t%d\tndir\t%d\tnifree\t%d\tnffree\t%d\n",
592 acg
.cg_cs
.cs_nbfree
, acg
.cg_cs
.cs_ndir
,
593 acg
.cg_cs
.cs_nifree
, acg
.cg_cs
.cs_nffree
);
594 printf("rotor\t%d\tirotor\t%d\tfrotor\t%d\nfrsum",
595 acg
.cg_rotor
, acg
.cg_irotor
, acg
.cg_frotor
);
596 for (i
= 1, j
= 0; i
< afs
.fs_frag
; i
++) {
597 printf("\t%d", acg
.cg_frsum
[i
]);
598 j
+= i
* acg
.cg_frsum
[i
];
600 printf("\nsum of frsum: %d", j
);
601 if (afs
.fs_contigsumsize
> 0) {
602 for (i
= 1; i
< afs
.fs_contigsumsize
; i
++) {
603 if ((i
- 1) % 8 == 0)
604 printf("\nclusters %d-%d:", i
,
605 afs
.fs_contigsumsize
- 1 < i
+ 7 ?
606 afs
.fs_contigsumsize
- 1 : i
+ 7);
607 printf("\t%d", cg_clustersum(&acg
, 0)[i
]);
609 printf("\nclusters size %d and over: %d\n",
610 afs
.fs_contigsumsize
,
611 cg_clustersum(&acg
, 0)[afs
.fs_contigsumsize
]);
612 printf("clusters free:\t");
613 pbits(0, cg_clustersfree(&acg
, 0), acg
.cg_nclusterblks
);
617 pbits(0 * c
* afs
.fs_ipg
, cg_inosused(&acg
, 0), afs
.fs_ipg
);
619 pbits(0, cg_blksfree(&acg
, 0), afs
.fs_fpg
);
620 if (printold
&& ISOPT(opt_verbose
)) {
622 for (i
= 0; i
< afs
.fs_old_cpg
; i
++) {
623 if (old_cg_blktot(&acg
, 0)[i
] == 0)
625 printf(" c%d:\t(%d)\t", i
, old_cg_blktot(&acg
, 0)[i
]);
626 for (j
= 0; j
< afs
.fs_old_nrpos
; j
++) {
627 if (afs
.fs_old_cpc
> 0 &&
628 old_fs_postbl(&afs
, i
% afs
.fs_old_cpc
, opostblsave
)[j
] == -1)
630 printf(" %d", old_cg_blks(&afs
, &acg
, i
, 0)[j
]);
639 print_ufs1_inode(int inum
, int i_off
, void *ibuf
)
641 struct ufs1_dinode
*i
= ibuf
;
646 ffs_dinode1_swap(i
,i
);
648 if (afs
.fs_old_inodefmt
< FS_44INODEFMT
) {
649 i
->di_uid
= i
->di_ouid
;
650 i
->di_gid
= i
->di_ogid
;
653 if (inum
% afs
.fs_ipg
== 0)
654 printf(" inode: mode nlink size"
655 " ctime.nsec flags blocks"
656 " generation uid gid\n");
657 if (i
->di_mode
== 0 && i
->di_nlink
== 0 && !ISOPT(opt_verbose
))
659 printf("%8u: %6o %6d %20" PRIu64
" %10u.%09u %8x %10u %8x %10u %10u\n",
660 inum
, i
->di_mode
, i
->di_nlink
, i
->di_size
,
661 i
->di_ctime
, i
->di_ctimensec
, i
->di_flags
, i
->di_blocks
,
662 i
->di_gen
, i
->di_uid
, i
->di_gid
);
666 print_ufs2_inode(int inum
, int i_off
, void *ibuf
)
668 struct ufs2_dinode
*i
= ibuf
;
673 ffs_dinode2_swap(i
,i
);
675 if (inum
% afs
.fs_ipg
== 0)
676 printf(" inode: mode nlink size"
677 " ctime.nsec flags blocks"
678 " generation uid gid\n");
680 if (i
->di_mode
== 0 && i
->di_nlink
== 0 && !ISOPT(opt_verbose
))
683 printf("%8u: %6o %6d %20" PRIu64
" %10" PRIu64
".%09u %8x %10" PRIu64
" %8x %10u %10u\n",
684 inum
, i
->di_mode
, i
->di_nlink
, i
->di_size
,
685 i
->di_ctime
, i
->di_ctimensec
, i
->di_flags
, i
->di_blocks
,
686 i
->di_gen
, i
->di_uid
, i
->di_gid
);
691 pbits(int offset
, void *vp
, int max
)
697 for (count
= i
= 0, p
= vp
; i
< max
; i
++)
700 printf(",%s", count
% 6 ? " " : "\n\t");
702 printf("%d", offset
+ i
);
704 while ((i
+1)<max
&& isset(p
, i
+1))
707 printf("-%d", offset
+ i
);
716 (void)fprintf(stderr
, "usage: dumpfs [-acFimsv] filesys | device [...]\n");
721 openpartition(const char *name
, int flags
, char *device
, size_t devicelen
)
723 char rawspec
[MAXPATHLEN
], *p
;
727 fs
= getfsfile(name
);
729 if ((p
= strrchr(fs
->fs_spec
, '/')) != NULL
) {
730 snprintf(rawspec
, sizeof(rawspec
), "%.*s/r%s",
731 (int)(p
- fs
->fs_spec
), fs
->fs_spec
, p
+ 1);
736 fd
= opendisk(name
, flags
, device
, devicelen
, 0);
737 if (fd
== -1 && errno
== ENOENT
) {
739 strlcpy(device
, name
, devicelen
);