diff options
author | David Malone <dwmalone@FreeBSD.org> | 2013-03-03 20:10:56 +0000 |
---|---|---|
committer | David Malone <dwmalone@FreeBSD.org> | 2013-03-03 20:10:56 +0000 |
commit | 9ed0c92c91e9a8459462774b33c368b56e2c7ced (patch) | |
tree | 0b46db9b2f431142315be4b5f8be443ed56f2e40 /usr.bin/find/function.c | |
parent | b6bc5f51faf75e6433e51ba31d47015eefd8d8de (diff) | |
download | src-9ed0c92c91e9a8459462774b33c368b56e2c7ced.tar.gz src-9ed0c92c91e9a8459462774b33c368b56e2c7ced.zip |
Add an option for finding sparse files.
Reviewed by: iedowse
MFC after: 3 weeks
Notes
Notes:
svn path=/head/; revision=247730
Diffstat (limited to 'usr.bin/find/function.c')
-rw-r--r-- | usr.bin/find/function.c | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/usr.bin/find/function.c b/usr.bin/find/function.c index cad6eb15fc87..61d61cb49077 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 |