From owner-svn-src-head@FreeBSD.ORG Sun Mar 3 20:10:57 2013 Return-Path: Delivered-To: svn-src-head@freebsd.org Received: from mx1.freebsd.org (mx1.FreeBSD.org [8.8.178.115]) by hub.freebsd.org (Postfix) with ESMTP id D8CF0EA6; Sun, 3 Mar 2013 20:10:57 +0000 (UTC) (envelope-from dwmalone@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) by mx1.freebsd.org (Postfix) with ESMTP id B2DF373A; Sun, 3 Mar 2013 20:10:57 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.5/8.14.5) with ESMTP id r23KAvq4069162; Sun, 3 Mar 2013 20:10:57 GMT (envelope-from dwmalone@svn.freebsd.org) Received: (from dwmalone@localhost) by svn.freebsd.org (8.14.5/8.14.5/Submit) id r23KAusJ069153; Sun, 3 Mar 2013 20:10:56 GMT (envelope-from dwmalone@svn.freebsd.org) Message-Id: <201303032010.r23KAusJ069153@svn.freebsd.org> From: David Malone Date: Sun, 3 Mar 2013 20:10:56 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r247730 - head/usr.bin/find X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.14 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: Sun, 03 Mar 2013 20:10:57 -0000 Author: dwmalone Date: Sun Mar 3 20:10:56 2013 New Revision: 247730 URL: http://svnweb.freebsd.org/changeset/base/247730 Log: Add an option for finding sparse files. Reviewed by: iedowse MFC after: 3 weeks Modified: head/usr.bin/find/extern.h head/usr.bin/find/find.1 head/usr.bin/find/function.c head/usr.bin/find/option.c Modified: head/usr.bin/find/extern.h ============================================================================== --- head/usr.bin/find/extern.h Sun Mar 3 19:31:44 2013 (r247729) +++ head/usr.bin/find/extern.h Sun Mar 3 20:10:56 2013 (r247730) @@ -73,6 +73,7 @@ creat_f c_regex; creat_f c_samefile; creat_f c_simple; creat_f c_size; +creat_f c_sparse; creat_f c_type; creat_f c_user; creat_f c_xdev; @@ -109,6 +110,7 @@ exec_f f_prune; exec_f f_quit; exec_f f_regex; exec_f f_size; +exec_f f_sparse; exec_f f_type; exec_f f_user; Modified: head/usr.bin/find/find.1 ============================================================================== --- head/usr.bin/find/find.1 Sun Mar 3 19:31:44 2013 (r247729) +++ head/usr.bin/find/find.1 Sun Mar 3 20:10:56 2013 (r247730) @@ -816,6 +816,10 @@ terabytes (1024 gigabytes) .It Cm P petabytes (1024 terabytes) .El +.It Ic -sparse +True if the current file is sparse, +i.e. has fewer blocks allocated than expected based on its size in bytes. +This might also match files that have been compressed by the filesystem. .It Ic -type Ar t True if the file is of the specified type. Possible file types are as follows: @@ -997,7 +1001,7 @@ and as well as .Ic -amin , -anewer , -cmin , -cnewer , -delete , -empty , -fstype , .Ic -iname , -inum , -iregex , -ls , -maxdepth , -mindepth , -mmin , -.Ic -path , -print0 , -regex +.Ic -path , -print0 , -regex, -sparse and all of the .Ic -B* birthtime related primaries are extensions to Modified: head/usr.bin/find/function.c ============================================================================== --- head/usr.bin/find/function.c Sun Mar 3 19:31:44 2013 (r247729) +++ head/usr.bin/find/function.c Sun Mar 3 20:10:56 2013 (r247730) @@ -1497,6 +1497,29 @@ c_size(OPTION *option, char ***argvp) } /* + * -sparse functions -- + * + * Check if a file is sparse by finding if it occupies fewer blocks + * than we expect based on its size. + */ +int +f_sparse(PLAN *plan __unused, FTSENT *entry) +{ + off_t expected_blocks; + + expected_blocks = (entry->fts_statp->st_size + 511) / 512; + return entry->fts_statp->st_blocks < expected_blocks; +} + +PLAN * +c_sparse(OPTION *option, char ***argvp __unused) +{ + ftsoptions &= ~FTS_NOSTAT; + + return palloc(option); +} + +/* * -type c functions -- * * True if the type of the file is c, where c is b, c, d, p, f or w Modified: head/usr.bin/find/option.c ============================================================================== --- head/usr.bin/find/option.c Sun Mar 3 19:31:44 2013 (r247729) +++ head/usr.bin/find/option.c Sun Mar 3 20:10:56 2013 (r247730) @@ -145,6 +145,7 @@ static OPTION const options[] = { { "-regex", c_regex, f_regex, 0 }, { "-samefile", c_samefile, f_inum, 0 }, { "-size", c_size, f_size, 0 }, + { "-sparse", c_sparse, f_sparse, 0 }, { "-true", c_simple, f_always_true, 0 }, { "-type", c_type, f_type, 0 }, { "-uid", c_user, f_user, 0 },