2000-11-13 03:30:48 +03:00
|
|
|
/* $NetBSD: dumplfs.c,v 1.17 2000/11/13 00:30:48 perseant Exp $ */
|
1995-03-18 17:54:19 +03:00
|
|
|
|
1994-06-08 22:57:30 +04:00
|
|
|
/*-
|
|
|
|
* Copyright (c) 1991, 1993
|
|
|
|
* The Regents of the University of California. All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* 3. All advertising materials mentioning features or use of this software
|
|
|
|
* must display the following acknowledgement:
|
|
|
|
* This product includes software developed by the University of
|
|
|
|
* California, Berkeley and its contributors.
|
|
|
|
* 4. Neither the name of the University nor the names of its contributors
|
|
|
|
* may be used to endorse or promote products derived from this software
|
|
|
|
* without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
1998-03-01 05:20:01 +03:00
|
|
|
#include <sys/cdefs.h>
|
|
|
|
|
1994-06-08 22:57:30 +04:00
|
|
|
#ifndef lint
|
1998-03-01 05:20:01 +03:00
|
|
|
__COPYRIGHT(
|
1994-06-08 22:57:30 +04:00
|
|
|
"@(#) Copyright (c) 1991, 1993\n\
|
1998-03-01 05:20:01 +03:00
|
|
|
The Regents of the University of California. All rights reserved.\n");
|
1994-06-08 22:57:30 +04:00
|
|
|
#endif /* not lint */
|
|
|
|
|
|
|
|
#ifndef lint
|
1995-03-18 17:54:19 +03:00
|
|
|
#if 0
|
1998-03-01 05:20:01 +03:00
|
|
|
static char sccsid[] = "@(#)dumplfs.c 8.5 (Berkeley) 5/24/95";
|
1995-03-18 17:54:19 +03:00
|
|
|
#else
|
2000-11-13 03:30:48 +03:00
|
|
|
__RCSID("$NetBSD: dumplfs.c,v 1.17 2000/11/13 00:30:48 perseant Exp $");
|
1995-03-18 17:54:19 +03:00
|
|
|
#endif
|
1994-06-08 22:57:30 +04:00
|
|
|
#endif /* not lint */
|
|
|
|
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/ucred.h>
|
|
|
|
#include <sys/mount.h>
|
|
|
|
#include <sys/time.h>
|
|
|
|
|
|
|
|
#include <ufs/ufs/dinode.h>
|
|
|
|
#include <ufs/lfs/lfs.h>
|
|
|
|
|
1994-09-23 06:18:30 +04:00
|
|
|
#include <err.h>
|
|
|
|
#include <errno.h>
|
1994-06-08 22:57:30 +04:00
|
|
|
#include <fcntl.h>
|
|
|
|
#include <fstab.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
1994-09-23 06:18:30 +04:00
|
|
|
#include <unistd.h>
|
1994-06-08 22:57:30 +04:00
|
|
|
#include "extern.h"
|
|
|
|
|
|
|
|
static void addseg __P((char *));
|
|
|
|
static void dump_cleaner_info __P((struct lfs *, void *));
|
|
|
|
static void dump_dinode __P((struct dinode *));
|
2000-06-14 05:55:37 +04:00
|
|
|
static void dump_ifile __P((int, struct lfs *, int, int));
|
1994-06-08 22:57:30 +04:00
|
|
|
static int dump_ipage_ifile __P((int, IFILE *, int));
|
|
|
|
static int dump_ipage_segusage __P((struct lfs *, int, IFILE *, int));
|
|
|
|
static void dump_segment __P((int, int, daddr_t, struct lfs *, int));
|
|
|
|
static int dump_sum __P((int, struct lfs *, SEGSUM *, int, daddr_t));
|
|
|
|
static void dump_super __P((struct lfs *));
|
|
|
|
static void usage __P((void));
|
|
|
|
|
1998-03-01 05:20:01 +03:00
|
|
|
int main __P((int, char *[]));
|
|
|
|
|
|
|
|
extern u_long cksum __P((void *, size_t));
|
|
|
|
|
1994-06-08 22:57:30 +04:00
|
|
|
typedef struct seglist SEGLIST;
|
|
|
|
struct seglist {
|
|
|
|
SEGLIST *next;
|
|
|
|
int num;
|
|
|
|
};
|
|
|
|
SEGLIST *seglist;
|
|
|
|
|
|
|
|
char *special;
|
|
|
|
|
|
|
|
/* Segment Usage formats */
|
|
|
|
#define print_suheader \
|
|
|
|
(void)printf("segnum\tflags\tnbytes\tninos\tnsums\tlastmod\n")
|
|
|
|
|
|
|
|
#define print_suentry(i, sp) \
|
|
|
|
(void)printf("%d\t%c%c%c\t%d\t%d\t%d\t%s", i, \
|
|
|
|
(((sp)->su_flags & SEGUSE_ACTIVE) ? 'A' : ' '), \
|
|
|
|
(((sp)->su_flags & SEGUSE_DIRTY) ? 'D' : 'C'), \
|
|
|
|
(((sp)->su_flags & SEGUSE_SUPERBLOCK) ? 'S' : ' '), \
|
|
|
|
(sp)->su_nbytes, (sp)->su_ninos, (sp)->su_nsums, \
|
|
|
|
ctime((time_t *)&(sp)->su_lastmod))
|
|
|
|
|
|
|
|
/* Ifile formats */
|
|
|
|
#define print_iheader \
|
|
|
|
(void)printf("inum\tstatus\tversion\tdaddr\t\tfreeptr\n")
|
|
|
|
#define print_ientry(i, ip) \
|
|
|
|
if (ip->if_daddr == LFS_UNUSED_DADDR) \
|
|
|
|
(void)printf("%d\tFREE\t%d\t \t\t%d\n", \
|
|
|
|
i, ip->if_version, ip->if_nextfree); \
|
|
|
|
else \
|
|
|
|
(void)printf("%d\tINUSE\t%d\t%8X \n", \
|
|
|
|
i, ip->if_version, ip->if_daddr)
|
1998-03-01 05:20:01 +03:00
|
|
|
|
2000-08-25 09:27:49 +04:00
|
|
|
#define datobyte(fs, da) /* disk address to bytes */ \
|
|
|
|
(((off_t)(da)) << ((fs)->lfs_bshift - (fs)->lfs_fsbtodb))
|
|
|
|
|
1994-06-08 22:57:30 +04:00
|
|
|
int
|
|
|
|
main(argc, argv)
|
|
|
|
int argc;
|
|
|
|
char *argv[];
|
|
|
|
{
|
|
|
|
struct lfs lfs_sb1, lfs_sb2, *lfs_master;
|
2000-06-14 05:55:37 +04:00
|
|
|
daddr_t seg_addr, idaddr, sbdaddr;
|
1994-06-08 22:57:30 +04:00
|
|
|
int ch, do_allsb, do_ientries, fd, segnum;
|
|
|
|
|
|
|
|
do_allsb = 0;
|
|
|
|
do_ientries = 0;
|
2000-06-14 05:55:37 +04:00
|
|
|
idaddr = 0x0;
|
|
|
|
sbdaddr = 0x0;
|
|
|
|
while ((ch = getopt(argc, argv, "ab:iI:s:")) != -1)
|
1994-06-08 22:57:30 +04:00
|
|
|
switch(ch) {
|
|
|
|
case 'a': /* Dump all superblocks */
|
|
|
|
do_allsb = 1;
|
|
|
|
break;
|
2000-06-14 05:55:37 +04:00
|
|
|
case 'b': /* Use this superblock */
|
|
|
|
sbdaddr = strtol(optarg, NULL, 0);
|
|
|
|
break;
|
1994-06-08 22:57:30 +04:00
|
|
|
case 'i': /* Dump ifile entries */
|
|
|
|
do_ientries = 1;
|
|
|
|
break;
|
2000-06-14 05:55:37 +04:00
|
|
|
case 'I': /* Use this ifile inode */
|
|
|
|
idaddr = strtol(optarg, NULL, 0);
|
|
|
|
break;
|
1994-06-08 22:57:30 +04:00
|
|
|
case 's': /* Dump out these segments */
|
|
|
|
addseg(optarg);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
usage();
|
|
|
|
}
|
|
|
|
argc -= optind;
|
|
|
|
argv += optind;
|
|
|
|
|
|
|
|
if (argc != 1)
|
|
|
|
usage();
|
|
|
|
|
|
|
|
special = argv[0];
|
|
|
|
if ((fd = open(special, O_RDONLY, 0)) < 0)
|
1994-09-23 06:18:30 +04:00
|
|
|
err(1, "%s", special);
|
1994-06-08 22:57:30 +04:00
|
|
|
|
2000-06-14 05:55:37 +04:00
|
|
|
if (sbdaddr == 0x0) {
|
|
|
|
/* Read the first superblock */
|
|
|
|
get(fd, LFS_LABELPAD, &(lfs_sb1.lfs_dlfs), sizeof(struct dlfs));
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Read the second superblock and figure out which check point is
|
|
|
|
* most up to date.
|
|
|
|
*/
|
|
|
|
get(fd,
|
2000-08-25 09:27:49 +04:00
|
|
|
datobyte(&lfs_sb1, lfs_sb1.lfs_sboffs[1]),
|
|
|
|
&(lfs_sb2.lfs_dlfs), sizeof(struct dlfs));
|
2000-06-14 05:55:37 +04:00
|
|
|
|
|
|
|
lfs_master = &lfs_sb1;
|
|
|
|
if (lfs_sb1.lfs_tstamp > lfs_sb2.lfs_tstamp) {
|
|
|
|
lfs_master = &lfs_sb2;
|
2000-08-25 09:27:49 +04:00
|
|
|
sbdaddr =
|
|
|
|
btodb(datobyte(&lfs_sb1, lfs_sb1.lfs_sboffs[1]));
|
2000-06-14 05:55:37 +04:00
|
|
|
} else
|
|
|
|
sbdaddr = btodb(LFS_LABELPAD);
|
|
|
|
} else {
|
|
|
|
/* Read the first superblock */
|
2000-08-25 09:27:49 +04:00
|
|
|
get(fd, dbtob((off_t)sbdaddr), &(lfs_sb1.lfs_dlfs),
|
|
|
|
sizeof(struct dlfs));
|
2000-06-14 05:55:37 +04:00
|
|
|
lfs_master = &lfs_sb1;
|
1999-05-02 04:26:01 +04:00
|
|
|
}
|
1994-06-08 22:57:30 +04:00
|
|
|
|
2000-06-14 05:55:37 +04:00
|
|
|
(void)printf("Master Superblock at 0x%x:\n", sbdaddr);
|
1994-06-08 22:57:30 +04:00
|
|
|
dump_super(lfs_master);
|
|
|
|
|
2000-06-14 05:55:37 +04:00
|
|
|
dump_ifile(fd, lfs_master, do_ientries, idaddr);
|
1994-06-08 22:57:30 +04:00
|
|
|
|
|
|
|
if (seglist != NULL)
|
|
|
|
for (; seglist != NULL; seglist = seglist->next) {
|
|
|
|
seg_addr = lfs_master->lfs_sboffs[0] + seglist->num *
|
|
|
|
(lfs_master->lfs_ssize << lfs_master->lfs_fsbtodb);
|
|
|
|
dump_segment(fd,
|
|
|
|
seglist->num, seg_addr, lfs_master, do_allsb);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
for (segnum = 0, seg_addr = lfs_master->lfs_sboffs[0];
|
|
|
|
segnum < lfs_master->lfs_nseg; segnum++, seg_addr +=
|
|
|
|
lfs_master->lfs_ssize << lfs_master->lfs_fsbtodb)
|
|
|
|
dump_segment(fd,
|
|
|
|
segnum, seg_addr, lfs_master, do_allsb);
|
|
|
|
|
|
|
|
(void)close(fd);
|
|
|
|
exit(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* We are reading all the blocks of an inode and dumping out the ifile table.
|
|
|
|
* This code could be tighter, but this is a first pass at getting the stuff
|
|
|
|
* printed out rather than making this code incredibly efficient.
|
|
|
|
*/
|
|
|
|
static void
|
2000-06-14 05:55:37 +04:00
|
|
|
dump_ifile(fd, lfsp, do_ientries, addr)
|
1994-06-08 22:57:30 +04:00
|
|
|
int fd;
|
|
|
|
struct lfs *lfsp;
|
|
|
|
int do_ientries;
|
2000-06-14 05:55:37 +04:00
|
|
|
daddr_t addr;
|
1994-06-08 22:57:30 +04:00
|
|
|
{
|
|
|
|
IFILE *ipage;
|
|
|
|
struct dinode *dip, *dpage;
|
2000-06-14 05:55:37 +04:00
|
|
|
daddr_t *addrp, *dindir, *iaddrp, *indir;
|
1994-12-05 23:15:31 +03:00
|
|
|
int block_limit, i, inum, j, nblocks, psize;
|
1994-06-08 22:57:30 +04:00
|
|
|
|
|
|
|
psize = lfsp->lfs_bsize;
|
2000-06-14 05:55:37 +04:00
|
|
|
if (!addr)
|
|
|
|
addr = lfsp->lfs_idaddr;
|
1994-06-08 22:57:30 +04:00
|
|
|
|
|
|
|
if (!(dpage = malloc(psize)))
|
1994-09-23 06:18:30 +04:00
|
|
|
err(1, "malloc");
|
2000-08-25 09:27:49 +04:00
|
|
|
get(fd, datobyte(lfsp, addr), dpage, psize);
|
1994-06-08 22:57:30 +04:00
|
|
|
|
|
|
|
for (dip = dpage + INOPB(lfsp) - 1; dip >= dpage; --dip)
|
|
|
|
if (dip->di_inumber == LFS_IFILE_INUM)
|
|
|
|
break;
|
|
|
|
|
|
|
|
if (dip < dpage)
|
2000-06-14 05:55:37 +04:00
|
|
|
errx(1, "unable to locate ifile inode at disk address 0x%x",
|
|
|
|
addr);
|
1994-06-08 22:57:30 +04:00
|
|
|
|
|
|
|
(void)printf("\nIFILE inode\n");
|
|
|
|
dump_dinode(dip);
|
|
|
|
|
|
|
|
(void)printf("\nIFILE contents\n");
|
|
|
|
nblocks = dip->di_size >> lfsp->lfs_bshift;
|
|
|
|
block_limit = MIN(nblocks, NDADDR);
|
|
|
|
|
|
|
|
/* Get the direct block */
|
|
|
|
if ((ipage = malloc(psize)) == NULL)
|
1994-09-23 06:18:30 +04:00
|
|
|
err(1, "malloc");
|
1994-06-08 22:57:30 +04:00
|
|
|
for (inum = 0, addrp = dip->di_db, i = 0; i < block_limit;
|
|
|
|
i++, addrp++) {
|
2000-08-25 09:27:49 +04:00
|
|
|
get(fd, datobyte(lfsp, *addrp), ipage, psize);
|
1994-06-08 22:57:30 +04:00
|
|
|
if (i < lfsp->lfs_cleansz) {
|
|
|
|
dump_cleaner_info(lfsp, ipage);
|
|
|
|
print_suheader;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (i < (lfsp->lfs_segtabsz + lfsp->lfs_cleansz)) {
|
|
|
|
inum = dump_ipage_segusage(lfsp, inum, ipage,
|
|
|
|
lfsp->lfs_sepb);
|
1998-08-27 22:03:42 +04:00
|
|
|
if (!inum) {
|
1994-06-08 22:57:30 +04:00
|
|
|
if(!do_ientries)
|
|
|
|
goto e0;
|
|
|
|
else
|
|
|
|
print_iheader;
|
1998-08-27 22:03:42 +04:00
|
|
|
}
|
1994-06-08 22:57:30 +04:00
|
|
|
} else
|
|
|
|
inum = dump_ipage_ifile(inum, ipage, lfsp->lfs_ifpb);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (nblocks <= NDADDR)
|
|
|
|
goto e0;
|
|
|
|
|
|
|
|
/* Dump out blocks off of single indirect block */
|
|
|
|
if (!(indir = malloc(psize)))
|
1994-09-23 06:18:30 +04:00
|
|
|
err(1, "malloc");
|
2000-08-25 09:27:49 +04:00
|
|
|
get(fd, datobyte(lfsp, dip->di_ib[0]), indir, psize);
|
1994-06-08 22:57:30 +04:00
|
|
|
block_limit = MIN(i + lfsp->lfs_nindir, nblocks);
|
|
|
|
for (addrp = indir; i < block_limit; i++, addrp++) {
|
|
|
|
if (*addrp == LFS_UNUSED_DADDR)
|
|
|
|
break;
|
2000-08-25 09:27:49 +04:00
|
|
|
get(fd, datobyte(lfsp, *addrp), ipage, psize);
|
1994-06-08 22:57:30 +04:00
|
|
|
if (i < lfsp->lfs_cleansz) {
|
|
|
|
dump_cleaner_info(lfsp, ipage);
|
|
|
|
continue;
|
|
|
|
} else
|
|
|
|
i -= lfsp->lfs_cleansz;
|
|
|
|
|
|
|
|
if (i < lfsp->lfs_segtabsz) {
|
|
|
|
inum = dump_ipage_segusage(lfsp, inum, ipage,
|
|
|
|
lfsp->lfs_sepb);
|
1998-08-30 05:40:15 +04:00
|
|
|
if (!inum) {
|
1994-06-08 22:57:30 +04:00
|
|
|
if(!do_ientries)
|
|
|
|
goto e1;
|
|
|
|
else
|
|
|
|
print_iheader;
|
1998-08-30 05:40:15 +04:00
|
|
|
}
|
1994-06-08 22:57:30 +04:00
|
|
|
} else
|
|
|
|
inum = dump_ipage_ifile(inum, ipage, lfsp->lfs_ifpb);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (nblocks <= lfsp->lfs_nindir * lfsp->lfs_ifpb)
|
|
|
|
goto e1;
|
|
|
|
|
|
|
|
/* Get the double indirect block */
|
|
|
|
if (!(dindir = malloc(psize)))
|
1994-09-23 06:18:30 +04:00
|
|
|
err(1, "malloc");
|
2000-08-25 09:27:49 +04:00
|
|
|
get(fd, datobyte(lfsp, dip->di_ib[1]), dindir, psize);
|
1994-06-08 22:57:30 +04:00
|
|
|
for (iaddrp = dindir, j = 0; j < lfsp->lfs_nindir; j++, iaddrp++) {
|
|
|
|
if (*iaddrp == LFS_UNUSED_DADDR)
|
|
|
|
break;
|
2000-08-25 09:27:49 +04:00
|
|
|
get(fd, datobyte(lfsp, *iaddrp), indir, psize);
|
1994-06-08 22:57:30 +04:00
|
|
|
block_limit = MIN(i + lfsp->lfs_nindir, nblocks);
|
|
|
|
for (addrp = indir; i < block_limit; i++, addrp++) {
|
|
|
|
if (*addrp == LFS_UNUSED_DADDR)
|
|
|
|
break;
|
2000-08-25 09:27:49 +04:00
|
|
|
get(fd, datobyte(lfsp, *addrp), ipage, psize);
|
1994-06-08 22:57:30 +04:00
|
|
|
if (i < lfsp->lfs_cleansz) {
|
|
|
|
dump_cleaner_info(lfsp, ipage);
|
|
|
|
continue;
|
|
|
|
} else
|
|
|
|
i -= lfsp->lfs_cleansz;
|
|
|
|
|
|
|
|
if (i < lfsp->lfs_segtabsz) {
|
|
|
|
inum = dump_ipage_segusage(lfsp,
|
|
|
|
inum, ipage, lfsp->lfs_sepb);
|
1998-08-27 22:03:42 +04:00
|
|
|
if (!inum) {
|
1994-06-08 22:57:30 +04:00
|
|
|
if(!do_ientries)
|
|
|
|
goto e2;
|
|
|
|
else
|
|
|
|
print_iheader;
|
1998-08-27 22:03:42 +04:00
|
|
|
}
|
1994-06-08 22:57:30 +04:00
|
|
|
} else
|
|
|
|
inum = dump_ipage_ifile(inum,
|
|
|
|
ipage, lfsp->lfs_ifpb);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
e2: free(dindir);
|
|
|
|
e1: free(indir);
|
|
|
|
e0: free(dpage);
|
|
|
|
free(ipage);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
dump_ipage_ifile(i, pp, tot)
|
|
|
|
int i;
|
|
|
|
IFILE *pp;
|
|
|
|
int tot;
|
|
|
|
{
|
|
|
|
IFILE *ip;
|
|
|
|
int cnt, max;
|
|
|
|
|
|
|
|
max = i + tot;
|
|
|
|
|
|
|
|
for (ip = pp, cnt = i; cnt < max; cnt++, ip++)
|
|
|
|
print_ientry(cnt, ip);
|
|
|
|
return (max);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
dump_ipage_segusage(lfsp, i, pp, tot)
|
|
|
|
struct lfs *lfsp;
|
|
|
|
int i;
|
|
|
|
IFILE *pp;
|
|
|
|
int tot;
|
|
|
|
{
|
|
|
|
SEGUSE *sp;
|
|
|
|
int cnt, max;
|
2000-06-26 01:36:16 +04:00
|
|
|
struct seglist *slp;
|
1994-06-08 22:57:30 +04:00
|
|
|
|
|
|
|
max = i + tot;
|
|
|
|
for (sp = (SEGUSE *)pp, cnt = i;
|
2000-06-26 01:36:16 +04:00
|
|
|
cnt < lfsp->lfs_nseg && cnt < max; cnt++, sp++) {
|
|
|
|
if (seglist == NULL)
|
|
|
|
print_suentry(cnt, sp);
|
|
|
|
else {
|
|
|
|
for (slp = seglist; slp != NULL; slp = slp->next)
|
|
|
|
if (cnt == slp->num) {
|
|
|
|
print_suentry(cnt, sp);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
1994-06-08 22:57:30 +04:00
|
|
|
if (max >= lfsp->lfs_nseg)
|
|
|
|
return (0);
|
|
|
|
else
|
|
|
|
return (max);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
dump_dinode(dip)
|
|
|
|
struct dinode *dip;
|
|
|
|
{
|
|
|
|
int i;
|
1995-12-15 01:30:45 +03:00
|
|
|
time_t at, mt, ct;
|
|
|
|
|
|
|
|
at = dip->di_atime;
|
|
|
|
mt = dip->di_mtime;
|
|
|
|
ct = dip->di_ctime;
|
1994-06-08 22:57:30 +04:00
|
|
|
|
1998-03-01 05:20:01 +03:00
|
|
|
(void)printf("%s%d\t%s%d\t%s%d\t%s%d\t%s%qu\n",
|
1994-06-08 22:57:30 +04:00
|
|
|
"mode ", dip->di_mode,
|
|
|
|
"nlink ", dip->di_nlink,
|
|
|
|
"uid ", dip->di_uid,
|
|
|
|
"gid ", dip->di_gid,
|
1998-03-03 10:35:50 +03:00
|
|
|
"size ", (long long)dip->di_size);
|
1994-06-08 22:57:30 +04:00
|
|
|
(void)printf("%s%s%s%s%s%s",
|
1995-12-15 01:30:45 +03:00
|
|
|
"atime ", ctime(&at),
|
|
|
|
"mtime ", ctime(&mt),
|
|
|
|
"ctime ", ctime(&ct));
|
1994-06-08 22:57:30 +04:00
|
|
|
(void)printf("inum %d\n", dip->di_inumber);
|
|
|
|
(void)printf("Direct Addresses\n");
|
|
|
|
for (i = 0; i < NDADDR; i++) {
|
2000-06-14 05:55:37 +04:00
|
|
|
(void)printf("\t0x%x", dip->di_db[i]);
|
1994-06-08 22:57:30 +04:00
|
|
|
if ((i % 6) == 5)
|
|
|
|
(void)printf("\n");
|
|
|
|
}
|
|
|
|
for (i = 0; i < NIADDR; i++)
|
2000-06-14 05:55:37 +04:00
|
|
|
(void)printf("\t0x%x", dip->di_ib[i]);
|
1994-06-08 22:57:30 +04:00
|
|
|
(void)printf("\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
dump_sum(fd, lfsp, sp, segnum, addr)
|
|
|
|
struct lfs *lfsp;
|
|
|
|
SEGSUM *sp;
|
|
|
|
int fd, segnum;
|
|
|
|
daddr_t addr;
|
|
|
|
{
|
|
|
|
FINFO *fp;
|
1998-03-01 05:20:01 +03:00
|
|
|
daddr_t *dp;
|
1994-06-08 22:57:30 +04:00
|
|
|
int i, j;
|
|
|
|
int ck;
|
1998-03-01 05:20:01 +03:00
|
|
|
int numbytes;
|
1994-06-08 22:57:30 +04:00
|
|
|
struct dinode *inop;
|
|
|
|
|
1998-03-01 05:20:01 +03:00
|
|
|
if (sp->ss_magic != SS_MAGIC ||
|
|
|
|
sp->ss_sumsum != (ck = cksum(&sp->ss_datasum,
|
1994-06-08 22:57:30 +04:00
|
|
|
LFS_SUMMARY_SIZE - sizeof(sp->ss_sumsum)))) {
|
2000-06-14 05:55:37 +04:00
|
|
|
/* Don't print "corrupt" if we're just too close to the edge */
|
|
|
|
if (datosn(lfsp, addr + fsbtodb(lfsp, lfsp->lfs_bsize)) ==
|
|
|
|
datosn(lfsp, addr))
|
|
|
|
(void)printf("dumplfs: %s %d address 0x%x\n",
|
|
|
|
"corrupt summary block; segment", segnum,
|
|
|
|
addr);
|
1994-06-08 22:57:30 +04:00
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
|
1998-03-01 05:20:01 +03:00
|
|
|
(void)printf("Segment Summary Info at 0x%x\n", addr);
|
2000-06-14 05:55:37 +04:00
|
|
|
(void)printf(" %s0x%x\t%s%d\t%s%d\t%s%c%c\n %s0x%x\t%s0x%x",
|
1994-06-08 22:57:30 +04:00
|
|
|
"next ", sp->ss_next,
|
|
|
|
"nfinfo ", sp->ss_nfinfo,
|
|
|
|
"ninos ", sp->ss_ninos,
|
2000-06-14 05:55:37 +04:00
|
|
|
"flags ", (sp->ss_flags & SS_DIROP) ? 'D' : '-',
|
|
|
|
(sp->ss_flags & SS_CONT) ? 'C' : '-',
|
1994-06-08 22:57:30 +04:00
|
|
|
"sumsum ", sp->ss_sumsum,
|
|
|
|
"datasum ", sp->ss_datasum );
|
|
|
|
(void)printf("\tcreate %s", ctime((time_t *)&sp->ss_create));
|
|
|
|
|
|
|
|
/* Dump out inode disk addresses */
|
|
|
|
dp = (daddr_t *)sp;
|
|
|
|
dp += LFS_SUMMARY_SIZE / sizeof(daddr_t);
|
|
|
|
inop = malloc(1 << lfsp->lfs_bshift);
|
|
|
|
printf(" Inode addresses:");
|
1998-03-01 05:20:01 +03:00
|
|
|
numbytes = 0;
|
1994-06-08 22:57:30 +04:00
|
|
|
for (dp--, i = 0; i < sp->ss_ninos; dp--) {
|
1998-03-01 05:20:01 +03:00
|
|
|
numbytes += lfsp->lfs_bsize; /* add bytes for inode block */
|
2000-06-14 05:55:37 +04:00
|
|
|
printf("\t0x%x {", *dp);
|
2000-08-25 09:27:49 +04:00
|
|
|
get(fd, datobyte(lfsp, *dp), inop, (1 << lfsp->lfs_bshift));
|
1994-06-08 22:57:30 +04:00
|
|
|
for (j = 0; i < sp->ss_ninos && j < INOPB(lfsp); j++, i++) {
|
|
|
|
if (j > 0)
|
|
|
|
(void)printf(", ");
|
|
|
|
(void)printf("%d", inop[j].di_inumber);
|
|
|
|
}
|
|
|
|
(void)printf("}");
|
|
|
|
if (((i/INOPB(lfsp)) % 4) == 3)
|
|
|
|
(void)printf("\n");
|
|
|
|
}
|
|
|
|
free(inop);
|
|
|
|
|
|
|
|
printf("\n");
|
|
|
|
for (fp = (FINFO *)(sp + 1), i = 0; i < sp->ss_nfinfo; i++) {
|
1998-03-01 05:20:01 +03:00
|
|
|
(void)printf(" FINFO for inode: %d version %d nblocks %d lastlength %d\n",
|
|
|
|
fp->fi_ino, fp->fi_version, fp->fi_nblocks,
|
|
|
|
fp->fi_lastlength);
|
1994-06-08 22:57:30 +04:00
|
|
|
dp = &(fp->fi_blocks[0]);
|
|
|
|
for (j = 0; j < fp->fi_nblocks; j++, dp++) {
|
|
|
|
(void)printf("\t%d", *dp);
|
|
|
|
if ((j % 8) == 7)
|
|
|
|
(void)printf("\n");
|
1998-03-01 05:20:01 +03:00
|
|
|
if (j == fp->fi_nblocks - 1)
|
|
|
|
numbytes += fp->fi_lastlength;
|
|
|
|
else
|
|
|
|
numbytes += lfsp->lfs_bsize;
|
1994-06-08 22:57:30 +04:00
|
|
|
}
|
|
|
|
if ((j % 8) != 0)
|
|
|
|
(void)printf("\n");
|
|
|
|
fp = (FINFO *)dp;
|
|
|
|
}
|
1998-03-01 05:20:01 +03:00
|
|
|
return (numbytes);
|
1994-06-08 22:57:30 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
dump_segment(fd, segnum, addr, lfsp, dump_sb)
|
|
|
|
int fd, segnum;
|
|
|
|
daddr_t addr;
|
|
|
|
struct lfs *lfsp;
|
|
|
|
int dump_sb;
|
|
|
|
{
|
|
|
|
struct lfs lfs_sb, *sbp;
|
|
|
|
SEGSUM *sump;
|
|
|
|
char sumblock[LFS_SUMMARY_SIZE];
|
1998-03-01 05:20:01 +03:00
|
|
|
int did_one, nbytes, sb;
|
2000-06-14 05:55:37 +04:00
|
|
|
off_t sum_offset;
|
|
|
|
daddr_t new_addr;
|
1994-06-08 22:57:30 +04:00
|
|
|
|
2000-06-14 05:55:37 +04:00
|
|
|
(void)printf("\nSEGMENT %d (Disk Address 0x%x)\n",
|
|
|
|
/* addr >> (lfsp->lfs_segshift - daddr_shift), */
|
|
|
|
datosn(lfsp, addr),
|
|
|
|
addr);
|
2000-08-25 09:27:49 +04:00
|
|
|
sum_offset = datobyte(lfsp, addr);
|
1994-06-08 22:57:30 +04:00
|
|
|
|
|
|
|
sb = 0;
|
|
|
|
did_one = 0;
|
|
|
|
do {
|
|
|
|
get(fd, sum_offset, sumblock, LFS_SUMMARY_SIZE);
|
|
|
|
sump = (SEGSUM *)sumblock;
|
|
|
|
if (sump->ss_sumsum != cksum (&sump->ss_datasum,
|
|
|
|
LFS_SUMMARY_SIZE - sizeof(sump->ss_sumsum))) {
|
|
|
|
sbp = (struct lfs *)sump;
|
1998-03-01 05:20:01 +03:00
|
|
|
if ((sb = (sbp->lfs_magic == LFS_MAGIC))) {
|
2000-06-14 05:55:37 +04:00
|
|
|
if (dump_sb) {
|
|
|
|
get(fd, sum_offset, &(lfs_sb.lfs_dlfs),
|
|
|
|
sizeof(struct dlfs));
|
|
|
|
(void)printf("\nSuperblock at 0x%x:\n",
|
|
|
|
(unsigned)btodb(sum_offset));
|
|
|
|
dump_super(&lfs_sb);
|
|
|
|
(void)printf("%s","\n");
|
|
|
|
}
|
1994-06-08 22:57:30 +04:00
|
|
|
sum_offset += LFS_SBPAD;
|
|
|
|
} else if (did_one)
|
|
|
|
break;
|
|
|
|
else {
|
2000-06-14 05:55:37 +04:00
|
|
|
printf("Segment at 0x%x corrupt\n", addr);
|
1994-06-08 22:57:30 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
} else {
|
1998-03-01 05:20:01 +03:00
|
|
|
nbytes = dump_sum(fd, lfsp, sump, segnum, sum_offset >>
|
1994-06-08 22:57:30 +04:00
|
|
|
(lfsp->lfs_bshift - lfsp->lfs_fsbtodb));
|
1998-03-01 05:20:01 +03:00
|
|
|
if (nbytes)
|
|
|
|
sum_offset += LFS_SUMMARY_SIZE + nbytes;
|
1994-06-08 22:57:30 +04:00
|
|
|
else
|
|
|
|
sum_offset = 0;
|
|
|
|
did_one = 1;
|
|
|
|
}
|
2000-06-14 05:55:37 +04:00
|
|
|
/* If the segment ends right on a boundary, it still ends */
|
|
|
|
new_addr = sum_offset >> (lfsp->lfs_bshift - lfsp->lfs_fsbtodb);
|
|
|
|
if (datosn(lfsp, new_addr) != datosn(lfsp, addr))
|
|
|
|
break;
|
1994-06-08 22:57:30 +04:00
|
|
|
} while (sum_offset);
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
dump_super(lfsp)
|
|
|
|
struct lfs *lfsp;
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
2000-06-14 05:55:37 +04:00
|
|
|
(void)printf("%s0x%x\t%s0x%x\t%s%d\t%s%d\n",
|
1994-06-08 22:57:30 +04:00
|
|
|
"magic ", lfsp->lfs_magic,
|
|
|
|
"version ", lfsp->lfs_version,
|
|
|
|
"size ", lfsp->lfs_size,
|
|
|
|
"ssize ", lfsp->lfs_ssize);
|
|
|
|
(void)printf("%s%d\t\t%s%d\t%s%d\t%s%d\n",
|
|
|
|
"dsize ", lfsp->lfs_dsize,
|
|
|
|
"bsize ", lfsp->lfs_bsize,
|
|
|
|
"fsize ", lfsp->lfs_fsize,
|
|
|
|
"frag ", lfsp->lfs_frag);
|
|
|
|
|
|
|
|
(void)printf("%s%d\t\t%s%d\t%s%d\t%s%d\n",
|
|
|
|
"minfree ", lfsp->lfs_minfree,
|
|
|
|
"inopb ", lfsp->lfs_inopb,
|
|
|
|
"ifpb ", lfsp->lfs_ifpb,
|
|
|
|
"nindir ", lfsp->lfs_nindir);
|
|
|
|
|
|
|
|
(void)printf("%s%d\t\t%s%d\t%s%d\t%s%d\n",
|
|
|
|
"nseg ", lfsp->lfs_nseg,
|
|
|
|
"nspf ", lfsp->lfs_nspf,
|
|
|
|
"cleansz ", lfsp->lfs_cleansz,
|
|
|
|
"segtabsz ", lfsp->lfs_segtabsz);
|
|
|
|
|
2000-06-14 05:55:37 +04:00
|
|
|
(void)printf("%s0x%x\t%s%d\t%s0x%qX\t%s%d\n",
|
1994-06-08 22:57:30 +04:00
|
|
|
"segmask ", lfsp->lfs_segmask,
|
|
|
|
"segshift ", lfsp->lfs_segshift,
|
1998-03-03 10:35:50 +03:00
|
|
|
"bmask ", (long long)lfsp->lfs_bmask,
|
1994-06-08 22:57:30 +04:00
|
|
|
"bshift ", lfsp->lfs_bshift);
|
|
|
|
|
1998-03-01 05:20:01 +03:00
|
|
|
(void)printf("%s0x%qX\t\t%s%d\t%s0x%qX\t%s%u\n",
|
1998-03-03 10:35:50 +03:00
|
|
|
"ffmask ", (long long)lfsp->lfs_ffmask,
|
1994-06-08 22:57:30 +04:00
|
|
|
"ffshift ", lfsp->lfs_ffshift,
|
1998-03-03 10:35:50 +03:00
|
|
|
"fbmask ", (long long)lfsp->lfs_fbmask,
|
1994-06-08 22:57:30 +04:00
|
|
|
"fbshift ", lfsp->lfs_fbshift);
|
|
|
|
|
2000-06-14 05:55:37 +04:00
|
|
|
(void)printf("%s%d\t%s%d\t%s0x%x\t%s0x%qx\n",
|
1994-06-08 22:57:30 +04:00
|
|
|
"sushift ", lfsp->lfs_sushift,
|
|
|
|
"fsbtodb ", lfsp->lfs_fsbtodb,
|
|
|
|
"cksum ", lfsp->lfs_cksum,
|
1998-03-03 10:35:50 +03:00
|
|
|
"maxfilesize ", (long long)lfsp->lfs_maxfilesize);
|
1994-06-08 22:57:30 +04:00
|
|
|
|
2000-11-13 03:30:48 +03:00
|
|
|
(void)printf("%s%d\t%s%d\t%s%d\n",
|
|
|
|
"nclean ", lfsp->lfs_nclean,
|
|
|
|
"dmeta ", lfsp->lfs_dmeta,
|
|
|
|
"minfreeseg ", lfsp->lfs_minfreeseg);
|
|
|
|
|
1994-06-08 22:57:30 +04:00
|
|
|
(void)printf("Superblock disk addresses:\t");
|
|
|
|
for (i = 0; i < LFS_MAXNUMSB; i++) {
|
2000-06-14 05:55:37 +04:00
|
|
|
(void)printf(" 0x%x", lfsp->lfs_sboffs[i]);
|
1994-06-08 22:57:30 +04:00
|
|
|
if ( i == (LFS_MAXNUMSB >> 1))
|
|
|
|
(void)printf("\n\t\t\t\t");
|
|
|
|
}
|
|
|
|
(void)printf("\n");
|
|
|
|
|
|
|
|
(void)printf("Checkpoint Info\n");
|
2000-06-14 05:55:37 +04:00
|
|
|
(void)printf("%s%d\t%s0x%x\t%s%d\n",
|
1994-06-08 22:57:30 +04:00
|
|
|
"free ", lfsp->lfs_free,
|
|
|
|
"idaddr ", lfsp->lfs_idaddr,
|
|
|
|
"ifile ", lfsp->lfs_ifile);
|
|
|
|
(void)printf("%s%d\t%s%d\t%s%d\n",
|
2000-11-13 03:30:48 +03:00
|
|
|
"uinodes ", lfsp->lfs_uinodes,
|
1994-06-08 22:57:30 +04:00
|
|
|
"bfree ", lfsp->lfs_bfree,
|
2000-11-13 03:30:48 +03:00
|
|
|
"avail ", lfsp->lfs_avail);
|
2000-06-14 05:55:37 +04:00
|
|
|
(void)printf("%s%d\t%s0x%x\t%s0x%x\n%s0x%x\t%s0x%x\t",
|
1994-06-08 22:57:30 +04:00
|
|
|
"nfiles ", lfsp->lfs_nfiles,
|
|
|
|
"lastseg ", lfsp->lfs_lastseg,
|
|
|
|
"nextseg ", lfsp->lfs_nextseg,
|
|
|
|
"curseg ", lfsp->lfs_curseg,
|
|
|
|
"offset ", lfsp->lfs_offset);
|
|
|
|
(void)printf("tstamp %s", ctime((time_t *)&lfsp->lfs_tstamp));
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
addseg(arg)
|
|
|
|
char *arg;
|
|
|
|
{
|
|
|
|
SEGLIST *p;
|
|
|
|
|
|
|
|
if ((p = malloc(sizeof(SEGLIST))) == NULL)
|
1994-09-23 06:18:30 +04:00
|
|
|
err(1, "malloc");
|
1994-06-08 22:57:30 +04:00
|
|
|
p->next = seglist;
|
|
|
|
p->num = atoi(arg);
|
|
|
|
seglist = p;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
dump_cleaner_info(lfsp, ipage)
|
|
|
|
struct lfs *lfsp;
|
|
|
|
void *ipage;
|
|
|
|
{
|
|
|
|
CLEANERINFO *cip;
|
|
|
|
|
|
|
|
cip = (CLEANERINFO *)ipage;
|
2000-11-13 03:30:48 +03:00
|
|
|
(void)printf("clean\t%d\tdirty\t%d\n",
|
|
|
|
cip->clean, cip->dirty);
|
|
|
|
(void)printf("bfree\t%d\tavail\t%d\n\n",
|
|
|
|
cip->bfree, cip->avail);
|
1994-06-08 22:57:30 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
usage()
|
|
|
|
{
|
|
|
|
(void)fprintf(stderr, "usage: dumplfs [-ai] [-s segnum] file\n");
|
|
|
|
exit(1);
|
|
|
|
}
|