Add stat -m --- busybox-1.11.0/coreutils/stat.c +++ busybox-1.11.0/coreutils/stat.c @@ -14,12 +14,14 @@ */ #include "libbb.h" +#include /* vars to control behavior */ #define OPT_FILESYS (1 << 0) #define OPT_TERSE (1 << 1) #define OPT_DEREFERENCE (1 << 2) -#define OPT_SELINUX (1 << 3) +#define OPT_MAP (1 << 3) +#define OPT_SELINUX (1 << 4) #if ENABLE_FEATURE_STAT_FORMAT typedef bool (*statfunc_ptr)(const char *, const char *); @@ -345,6 +347,26 @@ /* Stat the file system and print what we find. */ #if !ENABLE_FEATURE_STAT_FORMAT +#define do_mapfile(filename, format) do_mapfile(filename) +#endif +static bool do_mapfile(const char *filename, const char *format) +{ + int i = 0; + int fd = xopen(filename, O_RDONLY); + +#if ENABLE_FEATURE_STAT_FORMAT + (void) format; +#endif + while (1) { + int blk = i++; + if (ioctl(fd,FIBMAP,&blk) < 0 || blk == 0) break; + printf("%u\n",blk); + } + return 1; +} + +/* Stat the file system and print what we find. */ +#if !ENABLE_FEATURE_STAT_FORMAT #define do_statfs(filename, format) do_statfs(filename) #endif static bool do_statfs(const char *filename, const char *format) @@ -632,13 +654,15 @@ int ok = 1; statfunc_ptr statfunc = do_stat; - getopt32(argv, "ftL" + getopt32(argv, "ftLm" USE_SELINUX("Z") USE_FEATURE_STAT_FORMAT("c:", &format) ); if (option_mask32 & OPT_FILESYS) /* -f */ statfunc = do_statfs; + if (option_mask32 & OPT_MAP) /* -m */ + statfunc = do_mapfile; if (argc == optind) /* files */ bb_show_usage(); --- busybox-1.11.0/include/usage.h +++ busybox-1.11.0/include/usage.h @@ -3711,6 +3711,7 @@ ) \ "\n -f Display filesystem status" \ "\n -L Dereference links" \ + "\n -m Display block list" \ "\n -t Display info in terse form" \ USE_SELINUX( \ "\n -Z Print security context" \