summaryrefslogtreecommitdiffstats
path: root/stat.h
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 /stat.h
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 'stat.h')
-rw-r--r--stat.h12
1 files changed, 11 insertions, 1 deletions
diff --git a/stat.h b/stat.h
index d47d248..95c61ec 100644
--- a/stat.h
+++ b/stat.h
@@ -17,7 +17,9 @@
#ifndef BFS_STAT_H
#define BFS_STAT_H
+#include <sys/param.h>
#include <sys/types.h>
+#include <sys/stat.h>
#include <time.h>
/**
@@ -47,6 +49,14 @@ enum bfs_stat_flag {
BFS_STAT_BROKEN_OK = 1 << 0,
};
+#ifdef DEV_BSIZE
+# define BFS_STAT_BLKSIZE DEV_BSIZE
+#elif defined(S_BLKSIZE)
+# define BFS_STAT_BLKSIZE S_BLKSIZE
+#else
+# define BFS_STAT_BLKSIZE 512
+#endif
+
/**
* Facade over struct stat.
*/
@@ -68,7 +78,7 @@ struct bfs_stat {
uid_t uid;
/** File size in bytes. */
off_t size;
- /** Number of 512B blocks allocated. */
+ /** Number of disk blocks allocated (of size BFS_STAT_BLKSIZE). */
blkcnt_t blocks;
/** Access time. */