Index: dumpfs.c =================================================================== --- dumpfs.c (revision 187790) +++ dumpfs.c (working copy) @@ -1,4 +1,10 @@ /* + * Copyright (c) 2009 Robert N. M. Watson + * All rights reserved. + * + * This software was developed at the University of Cambridge Computer + * Laboratory with support from a grant from Google, Inc. + * * Copyright (c) 2002 Networks Associates Technology, Inc. * All rights reserved. * @@ -74,8 +80,11 @@ int dumpfs(const char *); int dumpcg(void); +int dumpfreespace(const char *); +void dumpfreespacecg(); int marshal(const char *); void pbits(void *, int); +void pblklist(void *, int, off_t); void ufserr(const char *); void usage(void) __dead2; @@ -83,12 +92,15 @@ main(int argc, char *argv[]) { const char *name; - int ch, domarshal, eval; + int ch, dofreespace, domarshal, eval; - domarshal = eval = 0; + dofreespace = domarshal = eval = 0; - while ((ch = getopt(argc, argv, "m")) != -1) { + while ((ch = getopt(argc, argv, "fm")) != -1) { switch (ch) { + case 'f': + dofreespace = 1; + break; case 'm': domarshal = 1; break; @@ -102,6 +114,8 @@ if (argc < 1) usage(); + if (dofreespace && domarshal) + usage(); while ((name = *argv++) != NULL) { if (ufs_disk_fillout(&disk, name) == -1) { @@ -109,7 +123,9 @@ eval |= 1; continue; } - if (domarshal) + if (dofreespace) + eval |= dumpfreespace(name); + else if (domarshal) eval |= marshal(name); else eval |= dumpfs(name); @@ -333,6 +349,30 @@ } int +dumpfreespace(const char *name) +{ + int i; + + while ((i = cgread(&disk)) != 0) { + if (i == -1) + goto err; + dumpfreespacecg(); + } + return (0); +err: + ufserr(name); + return (1); +} + +void +dumpfreespacecg(void) +{ + + pblklist(cg_blksfree(&acg), afs.fs_fpg, + (disk.d_ccg - 1) * afs.fs_fpg); +} + +int marshal(const char *name) { struct fs *fs; @@ -401,6 +441,25 @@ } void +pblklist(void *vp, int max, off_t offset) +{ + int i, j; + char *p; + + for (i = 0, p = vp; i < max; i++) { + if (isset(p, i)) { + printf("%lld", i + offset); + j = i; + while ((i+1)