summaryrefslogtreecommitdiff
path: root/sbin/dumpfs
diff options
context:
space:
mode:
authorJuli Mallett <jmallett@FreeBSD.org>2002-07-11 21:44:03 +0000
committerJuli Mallett <jmallett@FreeBSD.org>2002-07-11 21:44:03 +0000
commitd67caa29ef05324cac9afe74d737b21266468b77 (patch)
tree324ff25fc719494d2c8444c1bc1a98341ac6a0d4 /sbin/dumpfs
parent261755738ed542aa5dca9890a9e0b84744e60304 (diff)
downloadsrc-test2-d67caa29ef05324cac9afe74d737b21266468b77.tar.gz
src-test2-d67caa29ef05324cac9afe74d737b21266468b77.zip
Notes
Diffstat (limited to 'sbin/dumpfs')
-rw-r--r--sbin/dumpfs/Makefile1
-rw-r--r--sbin/dumpfs/dumpfs.c52
2 files changed, 14 insertions, 39 deletions
diff --git a/sbin/dumpfs/Makefile b/sbin/dumpfs/Makefile
index f26a337e871f..59e020ec6dac 100644
--- a/sbin/dumpfs/Makefile
+++ b/sbin/dumpfs/Makefile
@@ -4,5 +4,6 @@
PROG= dumpfs
WARNS= 0
MAN= dumpfs.8
+LDADD= -lufs
.include <bsd.prog.mk>
diff --git a/sbin/dumpfs/dumpfs.c b/sbin/dumpfs/dumpfs.c
index aae7e1e97db7..98b7e64256c8 100644
--- a/sbin/dumpfs/dumpfs.c
+++ b/sbin/dumpfs/dumpfs.c
@@ -67,15 +67,12 @@ static const char rcsid[] =
#include <err.h>
#include <fcntl.h>
#include <fstab.h>
+#include <libufs.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
-union {
- struct fs fs;
- char pad[MAXBSIZE];
-} fsun;
-#define afs fsun.fs
+#define afs disk.d_fs
union {
struct cg cg;
@@ -83,12 +80,7 @@ union {
} cgun;
#define acg cgun.cg
-long dev_bsize = 1;
-
-/*
- * Possible superblock locations ordered from most to least likely.
- */
-static int sblock_try[] = SBLOCKSEARCH;
+struct uufsd disk;
int dumpfs(const char *);
int dumpcg(const char *, int, int);
@@ -127,28 +119,11 @@ dumpfs(const char *name)
ssize_t n;
time_t time;
int64_t fssize;
- int fd, c, i, j, k, size;
+ int c, i, j, k, size;
- if ((fd = open(name, O_RDONLY, 0)) < 0)
- goto err;
- for (i = 0; sblock_try[i] != -1; i++) {
- if (lseek(fd, (off_t)sblock_try[i], SEEK_SET) == (off_t)-1)
- goto err;
- if ((n = read(fd, &afs, SBLOCKSIZE)) == -1)
+ if (ufs_disk_fillout(&disk, name) == -1)
goto err;
- if ((afs.fs_magic == FS_UFS1_MAGIC ||
- (afs.fs_magic == FS_UFS2_MAGIC &&
- afs.fs_sblockloc == numfrags(&afs, sblock_try[i]))) &&
- afs.fs_bsize <= MAXBSIZE &&
- afs.fs_bsize >= sizeof(struct fs))
- break;
- }
- if (sblock_try[i] == -1) {
- fprintf(stderr, "Cannot find filesystem superblock\n");
- return (1);
- }
- dev_bsize = afs.fs_fsize / fsbtodb(&afs, 1);
if (afs.fs_magic == FS_UFS2_MAGIC) {
fssize = afs.fs_size;
time = afs.fs_time;
@@ -234,11 +209,11 @@ dumpfs(const char *name)
putchar('\n');
printf("\ncs[].cs_(nbfree,ndir,nifree,nffree):\n\t");
afs.fs_csp = calloc(1, afs.fs_cssize);
- if (lseek(fd,
- (off_t)(fsbtodb(&afs, afs.fs_csaddr)) * (off_t)dev_bsize,
+ if (lseek(disk.d_fd,
+ (off_t)(fsbtodb(&afs, afs.fs_csaddr)) * (off_t)disk.d_bsize,
SEEK_SET) == (off_t)-1)
goto err;
- if (read(fd, (char *)afs.fs_csp, afs.fs_cssize) != afs.fs_cssize)
+ if (read(disk.d_fd, (char *)afs.fs_csp, afs.fs_cssize) != afs.fs_cssize)
goto err;
for (i = 0; i < afs.fs_ncg; i++) {
struct csum *cs = &afs.fs_cs(&afs, i);
@@ -257,13 +232,12 @@ dumpfs(const char *name)
(fssize % afs.fs_fpg) / afs.fs_frag);
}
for (i = 0; i < afs.fs_ncg; i++)
- if (dumpcg(name, fd, i))
+ if (dumpcg(name, disk.d_fd, i))
goto err;
- (void)close(fd);
+ ufs_disk_close(&disk);
return (0);
-err: if (fd != -1)
- (void)close(fd);
+err: ufs_disk_close(&disk);
warn("%s", name);
return (1);
};
@@ -277,9 +251,9 @@ dumpcg(const char *name, int fd, int c)
printf("\ncg %d:\n", c);
if ((cur = lseek(fd, (off_t)(fsbtodb(&afs, cgtod(&afs, c))) *
- (off_t)dev_bsize, SEEK_SET)) == (off_t)-1)
+ (off_t)disk.d_bsize, SEEK_SET)) == (off_t)-1)
return (1);
- if (read(fd, &acg, afs.fs_bsize) != afs.fs_bsize) {
+ if (read(disk.d_fd, &acg, afs.fs_bsize) != afs.fs_bsize) {
warnx("%s: error reading cg", name);
return (1);
}