summaryrefslogtreecommitdiffstats
path: root/eval.c
diff options
context:
space:
mode:
authorTavian Barnes <tavianator@tavianator.com>2018-07-24 19:16:27 -0400
committerTavian Barnes <tavianator@tavianator.com>2018-07-24 19:16:27 -0400
commit199063ab53cbae3b3be199ff902f9f2d001d1058 (patch)
treee533572ad08648917322e35a05fd1465f99bae6b /eval.c
parent86f0049bff0c8c802bb07fcb52ae468608ec0920 (diff)
downloadbfs-199063ab53cbae3b3be199ff902f9f2d001d1058.tar.xz
stat: Don't assume blocks are 512 bytes
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 <sys/param.h> if available. Also, for -printf '%S', print 1 instead of NaN for empty files with no blocks.
Diffstat (limited to 'eval.c')
-rw-r--r--eval.c4
1 files changed, 2 insertions, 2 deletions
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;
}