[PATCH] stat: make filesystem support optional

Ron Yorston rmy at tigress.co.uk
Wed Oct 10 10:33:04 UTC 2012


stat can be useful on non-Linux platforms if filesystem support is
turned off.

Signed-off-by: Ron Yorston <rmy at tigress.co.uk>
---
 coreutils/Config.src |   10 +++++++++-
 coreutils/stat.c     |   21 +++++++++++++++++----
 2 files changed, 26 insertions(+), 5 deletions(-)

diff --git a/coreutils/Config.src b/coreutils/Config.src
index a28449b..ab01312 100644
--- a/coreutils/Config.src
+++ b/coreutils/Config.src
@@ -578,7 +578,6 @@ config FEATURE_SPLIT_FANCY
 config STAT
 	bool "stat"
 	default y
-	select PLATFORM_LINUX # statfs()
 	help
 	  display file or filesystem status.
 
@@ -591,6 +590,15 @@ config FEATURE_STAT_FORMAT
 	  users can pass a custom format string for output. This adds about
 	  7k to a nonstatic build on amd64.
 
+config FEATURE_STAT_FILESYSTEM
+	bool "Enable display of filesystem status (-f)"
+	default y
+	depends on STAT
+	select PLATFORM_LINUX # statfs()
+	help
+	  Without this, stat will not support the '-f' option to display
+	  information about filesystem status.
+
 config STTY
 	bool "stty"
 	default y
diff --git a/coreutils/stat.c b/coreutils/stat.c
index e38c8f6..1052687 100644
--- a/coreutils/stat.c
+++ b/coreutils/stat.c
@@ -20,7 +20,9 @@
 //usage:	IF_FEATURE_STAT_FORMAT(
 //usage:     "\n	-c fmt	Use the specified format"
 //usage:	)
+//usage:	IF_FEATURE_STAT_FILESYSTEM(
 //usage:     "\n	-f	Display filesystem status"
+//usage:	)
 //usage:     "\n	-L	Follow links"
 //usage:     "\n	-t	Display info in terse form"
 //usage:	IF_SELINUX(
@@ -54,6 +56,7 @@
 //usage:       " %Y	Time of last modification as seconds since Epoch\n"
 //usage:       " %z	Time of last change\n"
 //usage:       " %Z	Time of last change as seconds since Epoch\n"
+//usage:	IF_FEATURE_STAT_FILESYSTEM(
 //usage:       "\nValid format sequences for file systems:\n"
 //usage:       " %a	Free blocks available to non-superuser\n"
 //usage:       " %b	Total data blocks in file system\n"
@@ -71,12 +74,13 @@
 //usage:       " %t	Type in hex\n"
 //usage:       " %T	Type in human readable form"
 //usage:	)
+//usage:	)
 
 #include "libbb.h"
 
-#define OPT_FILESYS     (1 << 0)
-#define OPT_TERSE       (1 << 1)
-#define OPT_DEREFERENCE (1 << 2)
+#define OPT_TERSE       (1 << 0)
+#define OPT_DEREFERENCE (1 << 1)
+#define OPT_FILESYS     (1 << 2)
 #define OPT_SELINUX     (1 << 3)
 
 #if ENABLE_FEATURE_STAT_FORMAT
@@ -132,6 +136,7 @@ static const char *human_time(time_t t)
 #undef buf
 }
 
+#if ENABLE_FEATURE_STAT_FILESYSTEM
 /* Return the type of the specified file system.
  * Some systems have statfvs.f_basetype[FSTYPSZ]. (AIX, HP-UX, and Solaris)
  * Others have statfs.f_fstypename[MFSNAMELEN]. (NetBSD 1.5.2)
@@ -202,6 +207,7 @@ static unsigned long long get_f_fsid(const struct statfs *statfsbuf)
 	while (--sz > 0);
 	return r;
 }
+#endif  /* FEATURE_STAT_FILESYSTEM */
 
 #if ENABLE_FEATURE_STAT_FORMAT
 static void strcatc(char *str, char c)
@@ -217,6 +223,7 @@ static void printfs(char *pformat, const char *msg)
 	printf(pformat, msg);
 }
 
+#if ENABLE_FEATURE_STAT_FILESYSTEM
 /* print statfs info */
 static void FAST_FUNC print_statfs(char *pformat, const char m,
 		const char *const filename, const void *data
@@ -263,6 +270,7 @@ static void FAST_FUNC print_statfs(char *pformat, const char m,
 		printf(pformat, m);
 	}
 }
+#endif
 
 /* print stat info */
 static void FAST_FUNC print_stat(char *pformat, const char m,
@@ -423,6 +431,7 @@ static void print_it(const char *masterformat,
 }
 #endif  /* FEATURE_STAT_FORMAT */
 
+#if ENABLE_FEATURE_STAT_FILESYSTEM
 /* Stat the file system and print what we find.  */
 #if !ENABLE_FEATURE_STAT_FORMAT
 #define do_statfs(filename, format) do_statfs(filename)
@@ -538,6 +547,7 @@ static bool do_statfs(const char *filename, const char *format)
 #endif  /* FEATURE_STAT_FORMAT */
 	return 1;
 }
+#endif  /* FEATURE_STAT_FILESYSTEM */
 
 /* stat the file and print what we find */
 #if !ENABLE_FEATURE_STAT_FORMAT
@@ -714,12 +724,15 @@ int stat_main(int argc UNUSED_PARAM, char **argv)
 	statfunc_ptr statfunc = do_stat;
 
 	opt_complementary = "-1"; /* min one arg */
-	opts = getopt32(argv, "ftL"
+	opts = getopt32(argv, "tL"
+		IF_FEATURE_STAT_FILESYSTEM("f")
 		IF_SELINUX("Z")
 		IF_FEATURE_STAT_FORMAT("c:", &format)
 	);
+#if ENABLE_FEATURE_STAT_FILESYSTEM
 	if (opts & OPT_FILESYS) /* -f */
 		statfunc = do_statfs;
+#endif
 #if ENABLE_SELINUX
 	if (opts & OPT_SELINUX) {
 		selinux_or_die();
-- 
1.7.4.4



More information about the busybox mailing list