aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorElliott Hughes <enh@google.com>2021-02-22 14:19:31 -0800
committerRob Landley <rob@landley.net>2021-02-22 19:02:37 -0600
commite2ad5c6c155ef63833f6d3774b607c314fbe8987 (patch)
tree03ee4500b5e528eb4f4783701efabd1dbf070aab
parent4e9837a7ca0f1ee570245bf6df505ef84a5a5ed5 (diff)
downloadtoybox-e2ad5c6c155ef63833f6d3774b607c314fbe8987.tar.gz
stat: fix macOS build and behavior.
My patch to fix df behavior on macOS broke the stat build on macOS. First off, we had %s and %S the wrong way round compared to coreutils, though since Linux always seems to use the same value for both, no-one will ever have noticed. Annoyingly, Linux and macOS disagree about what statfs::f_bsize means, and whether statfs::f_iosize and statfs::f_frsize exist (each has one or the other, depending on what f_bsize *doesn't* mean to them). This mess is presumably why statvfs exists. Unfortunately, statvfs on macOS at least doesn't contain the file system type information. So we either need to do *both* statfs() and statvfs() for macOS, or we need to take into account the different fields. This patch adds an #ifdef outside of portability.h because I wasn't sure we actually wanted to add statfs_best_transfer_size() and statfs_real_block_size() functions to lib for this. But that's an easy cleanup if desired.
-rw-r--r--toys/other/stat.c12
1 files changed, 9 insertions, 3 deletions
diff --git a/toys/other/stat.c b/toys/other/stat.c
index 37dd1808..6d5fc018 100644
--- a/toys/other/stat.c
+++ b/toys/other/stat.c
@@ -33,8 +33,8 @@ config STAT
The valid format escape sequences for filesystems:
%a Available blocks |%b Total blocks |%c Total inodes
%d Free inodes |%f Free blocks |%i File system ID
- %l Max filename length |%n File name |%s Fragment size
- %S Best transfer size |%t FS type (hex) |%T FS type (driver name)
+ %l Max filename length |%n File name |%s Best transfer size
+ %S Actual block size |%t FS type (hex) |%T FS type (driver name)
*/
#define FOR_stat
@@ -157,8 +157,14 @@ static void print_statfs(char type) {
sprintf(buf, "%08x%08x", val[0], val[1]);
strout(buf);
- } else if (type == 's') out('d', statfs->f_frsize);
+ }
+#ifdef __APPLE__
+ else if (type == 's') out('d', statfs->f_iosize);
else if (type == 'S') out('d', statfs->f_bsize);
+#else
+ else if (type == 's') out('d', statfs->f_bsize);
+ else if (type == 'S') out('d', statfs->f_frsize);
+#endif
else strout("?");
}