From a85066c273a205beff7096c2360f05bcf4fe9de8 Mon Sep 17 00:00:00 2001 From: Ron Yorston Date: Tue, 9 Oct 2012 15:37:26 +0100 Subject: stat: allow -f option to be disabled --- configs/mingw32_defconfig | 8 +++++--- coreutils/Config.src | 10 +++++++++- coreutils/stat.c | 23 ++++++++++++++++++++++- 3 files changed, 36 insertions(+), 5 deletions(-) diff --git a/configs/mingw32_defconfig b/configs/mingw32_defconfig index 28c8a0f65..af4b667e2 100644 --- a/configs/mingw32_defconfig +++ b/configs/mingw32_defconfig @@ -1,7 +1,7 @@ # # Automatically generated make config: don't edit # Busybox version: 1.21.0.git -# Tue Jun 26 13:14:48 2012 +# Tue Oct 9 15:33:27 2012 # CONFIG_HAVE_DOT_CONFIG=y # CONFIG_PLATFORM_POSIX is not set @@ -273,8 +273,9 @@ CONFIG_SORT=y CONFIG_FEATURE_SORT_BIG=y CONFIG_SPLIT=y CONFIG_FEATURE_SPLIT_FANCY=y -# CONFIG_STAT is not set -# CONFIG_FEATURE_STAT_FORMAT is not set +CONFIG_STAT=y +CONFIG_FEATURE_STAT_FORMAT=y +# CONFIG_FEATURE_STAT_FILESYSTEM is not set # CONFIG_STTY is not set CONFIG_SUM=y # CONFIG_SYNC is not set @@ -609,6 +610,7 @@ CONFIG_HD=y # CONFIG_FEATURE_VOLUMEID_HFS is not set # CONFIG_FEATURE_VOLUMEID_JFS is not set # CONFIG_FEATURE_VOLUMEID_XFS is not set +# CONFIG_FEATURE_VOLUMEID_NILFS is not set # CONFIG_FEATURE_VOLUMEID_NTFS is not set # CONFIG_FEATURE_VOLUMEID_ISO9660 is not set # CONFIG_FEATURE_VOLUMEID_UDF is not set diff --git a/coreutils/Config.src b/coreutils/Config.src index 81be71993..2ca71521f 100644 --- a/coreutils/Config.src +++ b/coreutils/Config.src @@ -581,7 +581,6 @@ config FEATURE_SPLIT_FANCY config STAT bool "stat" default y - select PLATFORM_LINUX # statfs() help display file or filesystem status. @@ -594,6 +593,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 3fb212f0f..5af365a7e 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,6 +74,7 @@ //usage: " %t Type in hex\n" //usage: " %T Type in human readable form" //usage: ) +//usage: ) #include "libbb.h" @@ -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, @@ -335,10 +343,18 @@ static void FAST_FUNC print_stat(char *pformat, const char m, printf(pformat, (unsigned long) 512); //ST_NBLOCKSIZE } else if (m == 'b') { strcat(pformat, "llu"); +#if !ENABLE_PLATFORM_MINGW32 printf(pformat, (unsigned long long) statbuf->st_blocks); +#else + printf(pformat, (unsigned long long) ((statbuf->st_size+511)/512)); +#endif } else if (m == 'o') { strcat(pformat, "lu"); +#if !ENABLE_PLATFORM_MINGW32 printf(pformat, (unsigned long) statbuf->st_blksize); +#else + printf(pformat, (unsigned long) 4096); +#endif } else if (m == 'x') { printfs(pformat, human_time(statbuf->st_atime)); } else if (m == 'X') { @@ -423,6 +439,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 +555,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 +732,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(); -- cgit v1.2.3-55-g6feb