aboutsummaryrefslogtreecommitdiff
path: root/coreutils
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2015-10-30 22:10:44 +0100
committerDenys Vlasenko <vda.linux@googlemail.com>2015-10-30 22:10:44 +0100
commitace833028f12c236ac6d148158d10129e542b985 (patch)
treec2847508318c0e025e694a0b45cfe05702638cd1 /coreutils
parentfe0dc34746b141f158908e311b405dd332c3dcb1 (diff)
downloadbusybox-ace833028f12c236ac6d148158d10129e542b985.tar.gz
stat: make -f optional. This allows to build stat for non-linux systems
function old new delta packed_usage 30761 30706 -55 Based on the patch by Ron Yorston. Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'coreutils')
-rw-r--r--coreutils/Config.src16
-rw-r--r--coreutils/stat.c81
2 files changed, 61 insertions, 36 deletions
diff --git a/coreutils/Config.src b/coreutils/Config.src
index ffbef1a31..619c2efe8 100644
--- a/coreutils/Config.src
+++ b/coreutils/Config.src
@@ -543,22 +543,6 @@ config FEATURE_SPLIT_FANCY
Supports additional suffixes 'b' for 512 bytes,
'g' for 1GiB for the -b option.
-config STAT
- bool "stat"
- default y
- select PLATFORM_LINUX # statfs()
- help
- display file or filesystem status.
-
-config FEATURE_STAT_FORMAT
- bool "Enable custom formats (-c)"
- default y
- depends on STAT
- help
- Without this, stat will not support the '-c format' option where
- users can pass a custom format string for output. This adds about
- 7k to a nonstatic build on amd64.
-
config STTY
bool "stty"
default y
diff --git a/coreutils/stat.c b/coreutils/stat.c
index f7fd227bb..1a490fef7 100644
--- a/coreutils/stat.c
+++ b/coreutils/stat.c
@@ -12,54 +12,83 @@
*
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
*/
+//config:config STAT
+//config: bool "stat"
+//config: default y
+//config: help
+//config: display file or filesystem status.
+//config:
+//config:config FEATURE_STAT_FORMAT
+//config: bool "Enable custom formats (-c)"
+//config: default y
+//config: depends on STAT
+//config: help
+//config: Without this, stat will not support the '-c format' option where
+//config: users can pass a custom format string for output. This adds about
+//config: 7k to a nonstatic build on amd64.
+//config:
+//config:config FEATURE_STAT_FILESYSTEM
+//config: bool "Enable display of filesystem status (-f)"
+//config: default y
+//config: depends on STAT
+//config: select PLATFORM_LINUX # statfs()
+//config: help
+//config: Without this, stat will not support the '-f' option to display
+//config: information about filesystem status.
+
//usage:#define stat_trivial_usage
//usage: "[OPTIONS] FILE..."
//usage:#define stat_full_usage "\n\n"
-//usage: "Display file (default) or filesystem status\n"
+//usage: "Display file"
+//usage: IF_FEATURE_STAT_FILESYSTEM(" (default) or filesystem")
+//usage: " status\n"
//usage: IF_FEATURE_STAT_FORMAT(
-//usage: "\n -c fmt Use the specified 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: "\n -t Terse display"
//usage: IF_SELINUX(
//usage: "\n -Z Print security context"
//usage: )
//usage: IF_FEATURE_STAT_FORMAT(
-//usage: "\n\nValid format sequences for files:\n"
+//usage: "\n\nFMT sequences"IF_FEATURE_STAT_FILESYSTEM(" for files")":\n"
//usage: " %a Access rights in octal\n"
//usage: " %A Access rights in human readable form\n"
//usage: " %b Number of blocks allocated (see %B)\n"
-//usage: " %B The size in bytes of each block reported by %b\n"
+//usage: " %B Size in bytes of each block reported by %b\n"
//usage: " %d Device number in decimal\n"
//usage: " %D Device number in hex\n"
//usage: " %f Raw mode in hex\n"
//usage: " %F File type\n"
-//usage: " %g Group ID of owner\n"
-//usage: " %G Group name of owner\n"
+//usage: " %g Group ID\n"
+//usage: " %G Group name\n"
//usage: " %h Number of hard links\n"
//usage: " %i Inode number\n"
//usage: " %n File name\n"
//usage: " %N File name, with -> TARGET if symlink\n"
//usage: " %o I/O block size\n"
-//usage: " %s Total size, in bytes\n"
+//usage: " %s Total size in bytes\n"
//usage: " %t Major device type in hex\n"
//usage: " %T Minor device type in hex\n"
-//usage: " %u User ID of owner\n"
-//usage: " %U User name of owner\n"
+//usage: " %u User ID\n"
+//usage: " %U User name\n"
//usage: " %x Time of last access\n"
//usage: " %X Time of last access as seconds since Epoch\n"
//usage: " %y Time of last modification\n"
//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: "\nValid format sequences for file systems:\n"
+//usage: IF_FEATURE_STAT_FILESYSTEM(
+//usage: "\nFMT sequences for file systems:\n"
//usage: " %a Free blocks available to non-superuser\n"
-//usage: " %b Total data blocks in file system\n"
-//usage: " %c Total file nodes in file system\n"
-//usage: " %d Free file nodes in file system\n"
-//usage: " %f Free blocks in file system\n"
+//usage: " %b Total data blocks\n"
+//usage: " %c Total file nodes\n"
+//usage: " %d Free file nodes\n"
+//usage: " %f Free blocks\n"
//usage: IF_SELINUX(
//usage: " %C Security context in selinux\n"
//usage: )
@@ -71,13 +100,16 @@
//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_SELINUX (1 << 3)
+enum {
+ OPT_TERSE = (1 << 0),
+ OPT_DEREFERENCE = (1 << 1),
+ OPT_FILESYS = (1 << 2) * ENABLE_FEATURE_STAT_FILESYSTEM,
+ OPT_SELINUX = (1 << (2+ENABLE_FEATURE_STAT_FILESYSTEM)) * ENABLE_SELINUX,
+};
#if ENABLE_FEATURE_STAT_FORMAT
typedef bool (*statfunc_ptr)(const char *, const char *);
@@ -132,6 +164,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 +235,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 +251,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 +298,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 +459,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 +575,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
@@ -721,12 +759,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();