From owner-svn-src-head@FreeBSD.ORG Wed Jan 28 09:33:00 2009 Return-Path: Delivered-To: svn-src-head@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 8A3141065674; Wed, 28 Jan 2009 09:33:00 +0000 (UTC) (envelope-from rwatson@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 6CF198FC22; Wed, 28 Jan 2009 09:33:00 +0000 (UTC) (envelope-from rwatson@FreeBSD.org) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id n0S9X0Vg012913; Wed, 28 Jan 2009 09:33:00 GMT (envelope-from rwatson@svn.freebsd.org) Received: (from rwatson@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id n0S9X0HS012911; Wed, 28 Jan 2009 09:33:00 GMT (envelope-from rwatson@svn.freebsd.org) Message-Id: <200901280933.n0S9X0HS012911@svn.freebsd.org> From: Robert Watson Date: Wed, 28 Jan 2009 09:33:00 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r187814 - head/sbin/dumpfs X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 28 Jan 2009 09:33:01 -0000 Author: rwatson Date: Wed Jan 28 09:33:00 2009 New Revision: 187814 URL: http://svn.freebsd.org/changeset/base/187814 Log: Add a new flag to dumpfs(8), -f, which causes dumpfs to list all free fragments in the file system by fragment (block) number. This new mode does the necessary arithmetic to generate absolute fragment numbers rather than than the cg-relative numbers printed in the default mode. If -f is passed once, contiguous fragment ranges are collapsed into an X-Y format as free block lists are currently printed in regular dumpfs output, but if specified twice, all block numbers are printed individually, allowing both compact and more script-friendly representation. This proves quite handy when attempting to recover deleted data, as it allows exclusion of non-deleted data from blocks searched. MFC after: 1 week Discussed with: jeff, Richard Clayton Sponsored by: Google, Inc. Modified: head/sbin/dumpfs/dumpfs.8 head/sbin/dumpfs/dumpfs.c Modified: head/sbin/dumpfs/dumpfs.8 ============================================================================== --- head/sbin/dumpfs/dumpfs.8 Wed Jan 28 08:39:48 2009 (r187813) +++ head/sbin/dumpfs/dumpfs.8 Wed Jan 28 09:33:00 2009 (r187814) @@ -36,15 +36,18 @@ .Nd dump file system information .Sh SYNOPSIS .Nm +.Op Fl f .Op Fl m .Ar filesys | device .Sh DESCRIPTION The .Nm utility prints out the super block and cylinder group information -for the file system or special device specified, unless +for the file system or special device specified, unless the +.Fl f +or .Fl m -is specified. +flag is specified. The listing is very long and detailed. This command is useful mostly for finding out certain file system @@ -52,6 +55,15 @@ information such as the file system bloc free space percentage. .Pp If +.Fl f +is specified, a sorted list of all free fragments and free fragment ranges, +as represented in cylinder group block free lists, is printed. +If the flag is specified twice, contiguous free fragments are not collapsed +into ranges and instead printed in a simple list. +Fragment numbers may be converted to raw byte offsets by multiplying by the +fragment size, which may be useful when recovering deleted data. +.Pp +If .Fl m is specified, a .Xr newfs 8 Modified: head/sbin/dumpfs/dumpfs.c ============================================================================== --- head/sbin/dumpfs/dumpfs.c Wed Jan 28 08:39:48 2009 (r187813) +++ head/sbin/dumpfs/dumpfs.c Wed Jan 28 09:33:00 2009 (r187814) @@ -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 @@ struct uufsd disk; int dumpfs(const char *); int dumpcg(void); +int dumpfreespace(const char *, int); +void dumpfreespacecg(int); int marshal(const char *); void pbits(void *, int); +void pblklist(void *, int, off_t, int); void ufserr(const char *); void usage(void) __dead2; @@ -83,12 +92,15 @@ int 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++; + break; case 'm': domarshal = 1; break; @@ -102,6 +114,10 @@ main(int argc, char *argv[]) if (argc < 1) usage(); + if (dofreespace && domarshal) + usage(); + if (dofreespace > 2) + usage(); while ((name = *argv++) != NULL) { if (ufs_disk_fillout(&disk, name) == -1) { @@ -109,7 +125,9 @@ main(int argc, char *argv[]) eval |= 1; continue; } - if (domarshal) + if (dofreespace) + eval |= dumpfreespace(name, dofreespace); + else if (domarshal) eval |= marshal(name); else eval |= dumpfs(name); @@ -333,6 +351,30 @@ dumpcg(void) } int +dumpfreespace(const char *name, int fflag) +{ + int i; + + while ((i = cgread(&disk)) != 0) { + if (i == -1) + goto err; + dumpfreespacecg(fflag); + } + return (0); +err: + ufserr(name); + return (1); +} + +void +dumpfreespacecg(int fflag) +{ + + pblklist(cg_blksfree(&acg), afs.fs_fpg, disk.d_lcg * afs.fs_fpg, + fflag); +} + +int marshal(const char *name) { struct fs *fs; @@ -401,6 +443,27 @@ pbits(void *vp, int max) } void +pblklist(void *vp, int max, off_t offset, int fflag) +{ + int i, j; + char *p; + + for (i = 0, p = vp; i < max; i++) { + if (isset(p, i)) { + printf("%jd", (intmax_t)(i + offset)); + if (fflag < 2) { + j = i; + while ((i+1)