From 199063ab53cbae3b3be199ff902f9f2d001d1058 Mon Sep 17 00:00:00 2001 From: Tavian Barnes Date: Tue, 24 Jul 2018 19:16:27 -0400 Subject: stat: Don't assume blocks are 512 bytes MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit POSIX says > The unit for the st_blocks member of the stat structure is not defined > within POSIX.1‐2008. and recommends using DEV_BSIZE from if available. Also, for -printf '%S', print 1 instead of NaN for empty files with no blocks. --- eval.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'eval.c') diff --git a/eval.c b/eval.c index ff81e92..6731b31 100644 --- a/eval.c +++ b/eval.c @@ -626,7 +626,7 @@ bool eval_fls(const struct expr *expr, struct eval_state *state) { } uintmax_t ino = statbuf->ino; - uintmax_t blocks = (statbuf->blocks + 1)/2; + uintmax_t blocks = ((uintmax_t)statbuf->blocks*BFS_STAT_BLKSIZE + 1023)/1024; char mode[11]; format_mode(statbuf->mode, mode); uintmax_t nlink = statbuf->nlink; @@ -886,7 +886,7 @@ bool eval_sparse(const struct expr *expr, struct eval_state *state) { return false; } - blkcnt_t expected = (statbuf->size + 511)/512; + blkcnt_t expected = (statbuf->size + BFS_STAT_BLKSIZE - 1)/BFS_STAT_BLKSIZE; return statbuf->blocks < expected; } -- cgit v1.2.3