Convert dumpfs(8) to libufs(3), rather than rolling local functions for a
number of things.
This commit is contained in:
parent
261755738e
commit
d67caa29ef
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=99826
@ -4,5 +4,6 @@
|
|||||||
PROG= dumpfs
|
PROG= dumpfs
|
||||||
WARNS= 0
|
WARNS= 0
|
||||||
MAN= dumpfs.8
|
MAN= dumpfs.8
|
||||||
|
LDADD= -lufs
|
||||||
|
|
||||||
.include <bsd.prog.mk>
|
.include <bsd.prog.mk>
|
||||||
|
@ -67,15 +67,12 @@ static const char rcsid[] =
|
|||||||
#include <err.h>
|
#include <err.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <fstab.h>
|
#include <fstab.h>
|
||||||
|
#include <libufs.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
union {
|
#define afs disk.d_fs
|
||||||
struct fs fs;
|
|
||||||
char pad[MAXBSIZE];
|
|
||||||
} fsun;
|
|
||||||
#define afs fsun.fs
|
|
||||||
|
|
||||||
union {
|
union {
|
||||||
struct cg cg;
|
struct cg cg;
|
||||||
@ -83,12 +80,7 @@ union {
|
|||||||
} cgun;
|
} cgun;
|
||||||
#define acg cgun.cg
|
#define acg cgun.cg
|
||||||
|
|
||||||
long dev_bsize = 1;
|
struct uufsd disk;
|
||||||
|
|
||||||
/*
|
|
||||||
* Possible superblock locations ordered from most to least likely.
|
|
||||||
*/
|
|
||||||
static int sblock_try[] = SBLOCKSEARCH;
|
|
||||||
|
|
||||||
int dumpfs(const char *);
|
int dumpfs(const char *);
|
||||||
int dumpcg(const char *, int, int);
|
int dumpcg(const char *, int, int);
|
||||||
@ -127,28 +119,11 @@ dumpfs(const char *name)
|
|||||||
ssize_t n;
|
ssize_t n;
|
||||||
time_t time;
|
time_t time;
|
||||||
int64_t fssize;
|
int64_t fssize;
|
||||||
int fd, c, i, j, k, size;
|
int c, i, j, k, size;
|
||||||
|
|
||||||
if ((fd = open(name, O_RDONLY, 0)) < 0)
|
if (ufs_disk_fillout(&disk, name) == -1)
|
||||||
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;
|
goto err;
|
||||||
if ((n = read(fd, &afs, SBLOCKSIZE)) == -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) {
|
if (afs.fs_magic == FS_UFS2_MAGIC) {
|
||||||
fssize = afs.fs_size;
|
fssize = afs.fs_size;
|
||||||
time = afs.fs_time;
|
time = afs.fs_time;
|
||||||
@ -234,11 +209,11 @@ dumpfs(const char *name)
|
|||||||
putchar('\n');
|
putchar('\n');
|
||||||
printf("\ncs[].cs_(nbfree,ndir,nifree,nffree):\n\t");
|
printf("\ncs[].cs_(nbfree,ndir,nifree,nffree):\n\t");
|
||||||
afs.fs_csp = calloc(1, afs.fs_cssize);
|
afs.fs_csp = calloc(1, afs.fs_cssize);
|
||||||
if (lseek(fd,
|
if (lseek(disk.d_fd,
|
||||||
(off_t)(fsbtodb(&afs, afs.fs_csaddr)) * (off_t)dev_bsize,
|
(off_t)(fsbtodb(&afs, afs.fs_csaddr)) * (off_t)disk.d_bsize,
|
||||||
SEEK_SET) == (off_t)-1)
|
SEEK_SET) == (off_t)-1)
|
||||||
goto err;
|
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;
|
goto err;
|
||||||
for (i = 0; i < afs.fs_ncg; i++) {
|
for (i = 0; i < afs.fs_ncg; i++) {
|
||||||
struct csum *cs = &afs.fs_cs(&afs, i);
|
struct csum *cs = &afs.fs_cs(&afs, i);
|
||||||
@ -257,13 +232,12 @@ dumpfs(const char *name)
|
|||||||
(fssize % afs.fs_fpg) / afs.fs_frag);
|
(fssize % afs.fs_fpg) / afs.fs_frag);
|
||||||
}
|
}
|
||||||
for (i = 0; i < afs.fs_ncg; i++)
|
for (i = 0; i < afs.fs_ncg; i++)
|
||||||
if (dumpcg(name, fd, i))
|
if (dumpcg(name, disk.d_fd, i))
|
||||||
goto err;
|
goto err;
|
||||||
(void)close(fd);
|
ufs_disk_close(&disk);
|
||||||
return (0);
|
return (0);
|
||||||
|
|
||||||
err: if (fd != -1)
|
err: ufs_disk_close(&disk);
|
||||||
(void)close(fd);
|
|
||||||
warn("%s", name);
|
warn("%s", name);
|
||||||
return (1);
|
return (1);
|
||||||
};
|
};
|
||||||
@ -277,9 +251,9 @@ dumpcg(const char *name, int fd, int c)
|
|||||||
|
|
||||||
printf("\ncg %d:\n", c);
|
printf("\ncg %d:\n", c);
|
||||||
if ((cur = lseek(fd, (off_t)(fsbtodb(&afs, cgtod(&afs, 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);
|
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);
|
warnx("%s: error reading cg", name);
|
||||||
return (1);
|
return (1);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user