Add an option for finding sparse files.

Reviewed by:	iedowse
MFC after:	3 weeks
This commit is contained in:
David Malone 2013-03-03 20:10:56 +00:00
parent b6bc5f51fa
commit 9ed0c92c91
4 changed files with 31 additions and 1 deletions

View File

@ -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;

View File

@ -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

View File

@ -1496,6 +1496,29 @@ c_size(OPTION *option, char ***argvp)
return new;
}
/*
* -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 --
*

View File

@ -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 },