diff options
author | dwmalone <dwmalone@FreeBSD.org> | 2013-03-03 20:10:56 +0000 |
---|---|---|
committer | dwmalone <dwmalone@FreeBSD.org> | 2013-03-03 20:10:56 +0000 |
commit | 8bb3da133f0682d6d4de1df7fcc02836faaddb68 (patch) | |
tree | 0b46db9b2f431142315be4b5f8be443ed56f2e40 | |
parent | 86693db26f9c8a1f2d05bf4404db92af6158471c (diff) | |
download | FreeBSD-src-8bb3da133f0682d6d4de1df7fcc02836faaddb68.zip FreeBSD-src-8bb3da133f0682d6d4de1df7fcc02836faaddb68.tar.gz |
Add an option for finding sparse files.
Reviewed by: iedowse
MFC after: 3 weeks
-rw-r--r-- | usr.bin/find/extern.h | 2 | ||||
-rw-r--r-- | usr.bin/find/find.1 | 6 | ||||
-rw-r--r-- | usr.bin/find/function.c | 23 | ||||
-rw-r--r-- | usr.bin/find/option.c | 1 |
4 files changed, 31 insertions, 1 deletions
diff --git a/usr.bin/find/extern.h b/usr.bin/find/extern.h index 6fa25d2..90b9b29 100644 --- a/usr.bin/find/extern.h +++ b/usr.bin/find/extern.h @@ -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; diff --git a/usr.bin/find/find.1 b/usr.bin/find/find.1 index 47c40d8..cffeacf 100644 --- a/usr.bin/find/find.1 +++ b/usr.bin/find/find.1 @@ -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 diff --git a/usr.bin/find/function.c b/usr.bin/find/function.c index cad6eb1..61d61cb 100644 --- a/usr.bin/find/function.c +++ b/usr.bin/find/function.c @@ -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 diff --git a/usr.bin/find/option.c b/usr.bin/find/option.c index b89420c..4fc63b6 100644 --- a/usr.bin/find/option.c +++ b/usr.bin/find/option.c @@ -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 }, |