Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 3 Mar 2013 20:10:56 +0000 (UTC)
From:      David Malone <dwmalone@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r247730 - head/usr.bin/find
Message-ID:  <201303032010.r23KAusJ069153@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
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 },



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201303032010.r23KAusJ069153>