From 39754106fae12190edbda78160871fb8b694c4d8 Mon Sep 17 00:00:00 2001 From: Matthias Schmidt Date: Mon, 7 Jan 2008 12:07:06 +0000 Subject: [PATCH] If -m is specified, a newfs(8) command is printed that can be used to generate a new file system with equivalent settings. Dragonfly-bug: http://bugs.dragonflybsd.org/issue868 Submitted-by: Eric Obtained-from: FreeBSD --- sbin/dumpfs/dumpfs.8 | 16 +++++++-- sbin/dumpfs/dumpfs.c | 97 +++++++++++++++++++++++++++++++++++++++++++++++++--- 2 files changed, 105 insertions(+), 8 deletions(-) diff --git a/sbin/dumpfs/dumpfs.8 b/sbin/dumpfs/dumpfs.8 index 2b24ee13b7..220567d46d 100644 --- a/sbin/dumpfs/dumpfs.8 +++ b/sbin/dumpfs/dumpfs.8 @@ -31,7 +31,7 @@ .\" .\" @(#)dumpfs.8 8.1 (Berkeley) 6/5/93 .\" $FreeBSD: src/sbin/dumpfs/dumpfs.8,v 1.5.2.3 2002/08/21 18:58:21 trhodes Exp $ -.\" $DragonFly: src/sbin/dumpfs/dumpfs.8,v 1.2 2003/06/17 04:27:32 dillon Exp $ +.\" $DragonFly: src/sbin/dumpfs/dumpfs.8,v 1.3 2008/01/07 12:07:06 matthias Exp $ .\" .Dd June 5, 1993 .Dt DUMPFS 8 @@ -41,16 +41,26 @@ .Nd dump file system information .Sh SYNOPSIS .Nm -.Op Ar filesys No \&| Ar device +.Op Fl m +.Ar filesys No \&| Ar device .Sh DESCRIPTION The .Nm utility prints out the super block and cylinder group information -for the file system or special device specified. +for the file system or special device specified, unless +.Fl m +is specified. The listing is very long and detailed. This command is useful mostly for finding out certain file system information such as the file system block size and minimum free space percentage. +.Pp +If +.Fl m +is specified, a +.Xr newfs 8 +command is printed that can be used to generate a new file system +with equivalent settings. .Sh SEE ALSO .Xr disktab 5 , .Xr fs 5 , diff --git a/sbin/dumpfs/dumpfs.c b/sbin/dumpfs/dumpfs.c index 09a0db5e74..6fe5e3493a 100644 --- a/sbin/dumpfs/dumpfs.c +++ b/sbin/dumpfs/dumpfs.c @@ -33,7 +33,7 @@ * @(#) Copyright (c) 1983, 1992, 1993 The Regents of the University of California. All rights reserved. * @(#)dumpfs.c 8.5 (Berkeley) 4/29/95 * $FreeBSD: src/sbin/dumpfs/dumpfs.c,v 1.13.2.1 2001/01/22 18:10:11 iedowse Exp $ - * $DragonFly: src/sbin/dumpfs/dumpfs.c,v 1.8 2006/04/03 01:58:49 dillon Exp $ + * $DragonFly: src/sbin/dumpfs/dumpfs.c,v 1.9 2008/01/07 12:07:06 matthias Exp $ */ #include @@ -47,6 +47,7 @@ #include #include #include +#include #include union { @@ -65,6 +66,7 @@ long dev_bsize = 1; int dumpfs(char *); int dumpcg(char *, int, int); +int marshal(const char*); void pbits(void *, int); void usage(void); @@ -72,10 +74,15 @@ int main(int argc, char **argv) { struct fstab *fs; - int ch, eval; + int ch, domarshal, eval; - while ((ch = getopt(argc, argv, "")) != -1) + domarshal = 0; + + while ((ch = getopt(argc, argv, "m")) != -1) switch(ch) { + case 'm': + domarshal = 1; + break; case '?': default: usage(); @@ -88,9 +95,15 @@ main(int argc, char **argv) for (eval = 0; *argv; ++argv) if ((fs = getfsfile(*argv)) == NULL) - eval |= dumpfs(*argv); + if (domarshal) + eval |= marshal(*argv); + else + eval |= dumpfs(*argv); else - eval |= dumpfs(fs->fs_spec); + if (domarshal) + eval |= marshal(fs->fs_spec); + else + eval |= dumpfs(fs->fs_spec); exit(eval); } @@ -297,6 +310,80 @@ dumpcg(char *name, int fd, int c) return (0); }; +int +marshal(const char *name) +{ + ssize_t n; + int fd; + static char realname[12]; + + if ((fd = open(name, O_RDONLY, 0)) < 0) + goto err; + if (lseek(fd, (off_t)SBOFF, SEEK_SET) == (off_t)-1) + goto err; + if ((n = read(fd, &afs, SBSIZE)) == -1) + goto err; + + if (n != SBSIZE) { + warnx("%s: non-existent or truncated superblock, skipped", + name); + close(fd); + return (1); + } + if (afs.fs_magic != FS_MAGIC) { + warnx("%s: superblock has bad magic number, skipped", name); + close(fd); + return (1); + } + + if(strncmp(name, "/dev", 4) == 0) { + snprintf(realname, 12, "%s", name); + } else { + snprintf(realname, 12, "/dev/%s", name); + } + + printf("# newfs command for %s (%s)\n", name, realname); + printf("newfs "); + if (afs.fs_flags & FS_DOSOFTDEP) + printf("-U "); + printf("-a %d ", afs.fs_maxcontig); + printf("-b %d ", afs.fs_bsize); + /* -c calculated */ + /* -d should be 0 per manpage */ + printf("-e %d ", afs.fs_maxbpg); + printf("-f %d ", afs.fs_fsize); + printf("-g %d ", afs.fs_avgfilesize); + printf("-h %d ", afs.fs_avgfpdir); + /* -i calculated */ + /* -j..l not implemented */ + printf("-m %d ", afs.fs_minfree); + /* -n not implemented */ + printf(" -o "); + switch (afs.fs_optim) { + case FS_OPTSPACE: + printf("space "); + break; + case FS_OPTTIME: + printf("time "); + break; + default: + printf("unknown "); + break; + } + /* -p..r not implemented */ + printf("-s %jd ", (intmax_t)afs.fs_size); + printf("%s ", realname); + printf("\n"); + + return (0); + +err: if (fd != -1) + close(fd); + warn("%s", name); + return (1); + +} + void pbits(void *vp, int max) { -- 2.11.4.GIT