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-w32-ace833028f12c236ac6d148158d10129e542b985.tar.gz
busybox-w32-ace833028f12c236ac6d148158d10129e542b985.tar.bz2
busybox-w32-ace833028f12c236ac6d148158d10129e542b985.zip
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
543 Supports additional suffixes 'b' for 512 bytes, 543 Supports additional suffixes 'b' for 512 bytes,
544 'g' for 1GiB for the -b option. 544 'g' for 1GiB for the -b option.
545 545
546config STAT
547 bool "stat"
548 default y
549 select PLATFORM_LINUX # statfs()
550 help
551 display file or filesystem status.
552
553config FEATURE_STAT_FORMAT
554 bool "Enable custom formats (-c)"
555 default y
556 depends on STAT
557 help
558 Without this, stat will not support the '-c format' option where
559 users can pass a custom format string for output. This adds about
560 7k to a nonstatic build on amd64.
561
562config STTY 546config STTY
563 bool "stty" 547 bool "stty"
564 default y 548 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 @@
12 * 12 *
13 * Licensed under GPLv2 or later, see file LICENSE in this source tree. 13 * Licensed under GPLv2 or later, see file LICENSE in this source tree.
14 */ 14 */
15//config:config STAT
16//config: bool "stat"
17//config: default y
18//config: help
19//config: display file or filesystem status.
20//config:
21//config:config FEATURE_STAT_FORMAT
22//config: bool "Enable custom formats (-c)"
23//config: default y
24//config: depends on STAT
25//config: help
26//config: Without this, stat will not support the '-c format' option where
27//config: users can pass a custom format string for output. This adds about
28//config: 7k to a nonstatic build on amd64.
29//config:
30//config:config FEATURE_STAT_FILESYSTEM
31//config: bool "Enable display of filesystem status (-f)"
32//config: default y
33//config: depends on STAT
34//config: select PLATFORM_LINUX # statfs()
35//config: help
36//config: Without this, stat will not support the '-f' option to display
37//config: information about filesystem status.
38
15 39
16//usage:#define stat_trivial_usage 40//usage:#define stat_trivial_usage
17//usage: "[OPTIONS] FILE..." 41//usage: "[OPTIONS] FILE..."
18//usage:#define stat_full_usage "\n\n" 42//usage:#define stat_full_usage "\n\n"
19//usage: "Display file (default) or filesystem status\n" 43//usage: "Display file"
44//usage: IF_FEATURE_STAT_FILESYSTEM(" (default) or filesystem")
45//usage: " status\n"
20//usage: IF_FEATURE_STAT_FORMAT( 46//usage: IF_FEATURE_STAT_FORMAT(
21//usage: "\n -c fmt Use the specified format" 47//usage: "\n -c FMT Use the specified format"
22//usage: ) 48//usage: )
49//usage: IF_FEATURE_STAT_FILESYSTEM(
23//usage: "\n -f Display filesystem status" 50//usage: "\n -f Display filesystem status"
51//usage: )
24//usage: "\n -L Follow links" 52//usage: "\n -L Follow links"
25//usage: "\n -t Display info in terse form" 53//usage: "\n -t Terse display"
26//usage: IF_SELINUX( 54//usage: IF_SELINUX(
27//usage: "\n -Z Print security context" 55//usage: "\n -Z Print security context"
28//usage: ) 56//usage: )
29//usage: IF_FEATURE_STAT_FORMAT( 57//usage: IF_FEATURE_STAT_FORMAT(
30//usage: "\n\nValid format sequences for files:\n" 58//usage: "\n\nFMT sequences"IF_FEATURE_STAT_FILESYSTEM(" for files")":\n"
31//usage: " %a Access rights in octal\n" 59//usage: " %a Access rights in octal\n"
32//usage: " %A Access rights in human readable form\n" 60//usage: " %A Access rights in human readable form\n"
33//usage: " %b Number of blocks allocated (see %B)\n" 61//usage: " %b Number of blocks allocated (see %B)\n"
34//usage: " %B The size in bytes of each block reported by %b\n" 62//usage: " %B Size in bytes of each block reported by %b\n"
35//usage: " %d Device number in decimal\n" 63//usage: " %d Device number in decimal\n"
36//usage: " %D Device number in hex\n" 64//usage: " %D Device number in hex\n"
37//usage: " %f Raw mode in hex\n" 65//usage: " %f Raw mode in hex\n"
38//usage: " %F File type\n" 66//usage: " %F File type\n"
39//usage: " %g Group ID of owner\n" 67//usage: " %g Group ID\n"
40//usage: " %G Group name of owner\n" 68//usage: " %G Group name\n"
41//usage: " %h Number of hard links\n" 69//usage: " %h Number of hard links\n"
42//usage: " %i Inode number\n" 70//usage: " %i Inode number\n"
43//usage: " %n File name\n" 71//usage: " %n File name\n"
44//usage: " %N File name, with -> TARGET if symlink\n" 72//usage: " %N File name, with -> TARGET if symlink\n"
45//usage: " %o I/O block size\n" 73//usage: " %o I/O block size\n"
46//usage: " %s Total size, in bytes\n" 74//usage: " %s Total size in bytes\n"
47//usage: " %t Major device type in hex\n" 75//usage: " %t Major device type in hex\n"
48//usage: " %T Minor device type in hex\n" 76//usage: " %T Minor device type in hex\n"
49//usage: " %u User ID of owner\n" 77//usage: " %u User ID\n"
50//usage: " %U User name of owner\n" 78//usage: " %U User name\n"
51//usage: " %x Time of last access\n" 79//usage: " %x Time of last access\n"
52//usage: " %X Time of last access as seconds since Epoch\n" 80//usage: " %X Time of last access as seconds since Epoch\n"
53//usage: " %y Time of last modification\n" 81//usage: " %y Time of last modification\n"
54//usage: " %Y Time of last modification as seconds since Epoch\n" 82//usage: " %Y Time of last modification as seconds since Epoch\n"
55//usage: " %z Time of last change\n" 83//usage: " %z Time of last change\n"
56//usage: " %Z Time of last change as seconds since Epoch\n" 84//usage: " %Z Time of last change as seconds since Epoch\n"
57//usage: "\nValid format sequences for file systems:\n" 85//usage: IF_FEATURE_STAT_FILESYSTEM(
86//usage: "\nFMT sequences for file systems:\n"
58//usage: " %a Free blocks available to non-superuser\n" 87//usage: " %a Free blocks available to non-superuser\n"
59//usage: " %b Total data blocks in file system\n" 88//usage: " %b Total data blocks\n"
60//usage: " %c Total file nodes in file system\n" 89//usage: " %c Total file nodes\n"
61//usage: " %d Free file nodes in file system\n" 90//usage: " %d Free file nodes\n"
62//usage: " %f Free blocks in file system\n" 91//usage: " %f Free blocks\n"
63//usage: IF_SELINUX( 92//usage: IF_SELINUX(
64//usage: " %C Security context in selinux\n" 93//usage: " %C Security context in selinux\n"
65//usage: ) 94//usage: )
@@ -71,13 +100,16 @@
71//usage: " %t Type in hex\n" 100//usage: " %t Type in hex\n"
72//usage: " %T Type in human readable form" 101//usage: " %T Type in human readable form"
73//usage: ) 102//usage: )
103//usage: )
74 104
75#include "libbb.h" 105#include "libbb.h"
76 106
77#define OPT_FILESYS (1 << 0) 107enum {
78#define OPT_TERSE (1 << 1) 108 OPT_TERSE = (1 << 0),
79#define OPT_DEREFERENCE (1 << 2) 109 OPT_DEREFERENCE = (1 << 1),
80#define OPT_SELINUX (1 << 3) 110 OPT_FILESYS = (1 << 2) * ENABLE_FEATURE_STAT_FILESYSTEM,
111 OPT_SELINUX = (1 << (2+ENABLE_FEATURE_STAT_FILESYSTEM)) * ENABLE_SELINUX,
112};
81 113
82#if ENABLE_FEATURE_STAT_FORMAT 114#if ENABLE_FEATURE_STAT_FORMAT
83typedef bool (*statfunc_ptr)(const char *, const char *); 115typedef bool (*statfunc_ptr)(const char *, const char *);
@@ -132,6 +164,7 @@ static const char *human_time(time_t t)
132#undef buf 164#undef buf
133} 165}
134 166
167#if ENABLE_FEATURE_STAT_FILESYSTEM
135/* Return the type of the specified file system. 168/* Return the type of the specified file system.
136 * Some systems have statfvs.f_basetype[FSTYPSZ]. (AIX, HP-UX, and Solaris) 169 * Some systems have statfvs.f_basetype[FSTYPSZ]. (AIX, HP-UX, and Solaris)
137 * Others have statfs.f_fstypename[MFSNAMELEN]. (NetBSD 1.5.2) 170 * 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)
202 while (--sz > 0); 235 while (--sz > 0);
203 return r; 236 return r;
204} 237}
238#endif /* FEATURE_STAT_FILESYSTEM */
205 239
206#if ENABLE_FEATURE_STAT_FORMAT 240#if ENABLE_FEATURE_STAT_FORMAT
207static void strcatc(char *str, char c) 241static void strcatc(char *str, char c)
@@ -217,6 +251,7 @@ static void printfs(char *pformat, const char *msg)
217 printf(pformat, msg); 251 printf(pformat, msg);
218} 252}
219 253
254#if ENABLE_FEATURE_STAT_FILESYSTEM
220/* print statfs info */ 255/* print statfs info */
221static void FAST_FUNC print_statfs(char *pformat, const char m, 256static void FAST_FUNC print_statfs(char *pformat, const char m,
222 const char *const filename, const void *data 257 const char *const filename, const void *data
@@ -263,6 +298,7 @@ static void FAST_FUNC print_statfs(char *pformat, const char m,
263 printf(pformat, m); 298 printf(pformat, m);
264 } 299 }
265} 300}
301#endif
266 302
267/* print stat info */ 303/* print stat info */
268static void FAST_FUNC print_stat(char *pformat, const char m, 304static void FAST_FUNC print_stat(char *pformat, const char m,
@@ -423,6 +459,7 @@ static void print_it(const char *masterformat,
423} 459}
424#endif /* FEATURE_STAT_FORMAT */ 460#endif /* FEATURE_STAT_FORMAT */
425 461
462#if ENABLE_FEATURE_STAT_FILESYSTEM
426/* Stat the file system and print what we find. */ 463/* Stat the file system and print what we find. */
427#if !ENABLE_FEATURE_STAT_FORMAT 464#if !ENABLE_FEATURE_STAT_FORMAT
428#define do_statfs(filename, format) do_statfs(filename) 465#define do_statfs(filename, format) do_statfs(filename)
@@ -538,6 +575,7 @@ static bool do_statfs(const char *filename, const char *format)
538#endif /* FEATURE_STAT_FORMAT */ 575#endif /* FEATURE_STAT_FORMAT */
539 return 1; 576 return 1;
540} 577}
578#endif /* FEATURE_STAT_FILESYSTEM */
541 579
542/* stat the file and print what we find */ 580/* stat the file and print what we find */
543#if !ENABLE_FEATURE_STAT_FORMAT 581#if !ENABLE_FEATURE_STAT_FORMAT
@@ -721,12 +759,15 @@ int stat_main(int argc UNUSED_PARAM, char **argv)
721 statfunc_ptr statfunc = do_stat; 759 statfunc_ptr statfunc = do_stat;
722 760
723 opt_complementary = "-1"; /* min one arg */ 761 opt_complementary = "-1"; /* min one arg */
724 opts = getopt32(argv, "ftL" 762 opts = getopt32(argv, "tL"
763 IF_FEATURE_STAT_FILESYSTEM("f")
725 IF_SELINUX("Z") 764 IF_SELINUX("Z")
726 IF_FEATURE_STAT_FORMAT("c:", &format) 765 IF_FEATURE_STAT_FORMAT("c:", &format)
727 ); 766 );
767#if ENABLE_FEATURE_STAT_FILESYSTEM
728 if (opts & OPT_FILESYS) /* -f */ 768 if (opts & OPT_FILESYS) /* -f */
729 statfunc = do_statfs; 769 statfunc = do_statfs;
770#endif
730#if ENABLE_SELINUX 771#if ENABLE_SELINUX
731 if (opts & OPT_SELINUX) { 772 if (opts & OPT_SELINUX) {
732 selinux_or_die(); 773 selinux_or_die();