Add non standard stat -m support to display file block list Useful to patch read-only filesystems such as ISO9660 or fragmentation checking --- busybox-1.17.1/include/usage.src.h +++ busybox-1.17.1/include/usage.src.h @@ -3979,6 +3979,7 @@ "\n -f Display filesystem status" \ "\n -L Follow links" \ "\n -t Display info in terse form" \ + "\n -m Display block list" \ IF_SELINUX( \ "\n -Z Print security context" \ ) \ --- busybox-1.17.1/coreutils/stat.c +++ busybox-1.17.1/coreutils/stat.c @@ -13,11 +13,13 @@ * Licensed under GPLv2 or later, see file LICENSE in this tarball for details. */ #include "libbb.h" +#include #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 *); @@ -361,6 +363,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) @@ -651,7 +673,7 @@ statfunc_ptr statfunc = do_stat; opt_complementary = "-1"; /* min one arg */ - opts = getopt32(argv, "ftL" + opts = getopt32(argv, "ftLm" IF_SELINUX("Z") IF_FEATURE_STAT_FORMAT("c:", &format) ); @@ -662,6 +684,9 @@ selinux_or_die(); } #endif + if (opts & OPT_MAP) { /* -m */ + statfunc = do_mapfile; + } ok = 1; argv += optind; for (i = 0; argv[i]; ++i)