wok diff busybox/stuff/busybox-1.27-stat.u @ rev 19991
Up busybox (1.27.1), vala (0.36.4)
author | Pascal Bellard <pascal.bellard@slitaz.org> |
---|---|
date | Fri Jul 21 16:38:46 2017 +0200 (2017-07-21) |
parents | |
children |
line diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/busybox/stuff/busybox-1.27-stat.u Fri Jul 21 16:38:46 2017 +0200 1.3 @@ -0,0 +1,76 @@ 1.4 +Add non standard stat -m support to display file block list 1.5 +Useful to patch read-only filesystems such as ISO9660, for defragmentation 1.6 +tools or boot loaders 1.7 +--- busybox-1.26/coreutils/stat.c 1.8 ++++ busybox-1.26/coreutils/stat.c 1.9 +@@ -54,6 +54,7 @@ 1.10 + //usage: ) 1.11 + //usage: "\n -L Follow links" 1.12 + //usage: "\n -t Terse display" 1.13 ++//usage: "\n -m Display block list" 1.14 + //usage: IF_SELINUX( 1.15 + //usage: "\n -Z Print security context" 1.16 + //usage: ) 1.17 +@@ -106,13 +107,15 @@ 1.18 + //usage: ) 1.19 + 1.20 + #include "libbb.h" 1.21 ++#include <linux/fs.h> 1.22 + #include "common_bufsiz.h" 1.23 + 1.24 + enum { 1.25 + OPT_TERSE = (1 << 0), 1.26 + OPT_DEREFERENCE = (1 << 1), 1.27 +- OPT_FILESYS = (1 << 2) * ENABLE_FEATURE_STAT_FILESYSTEM, 1.28 +- OPT_SELINUX = (1 << (2+ENABLE_FEATURE_STAT_FILESYSTEM)) * ENABLE_SELINUX, 1.29 ++ OPT_MAP = (1 << 2), 1.30 ++ OPT_FILESYS = (1 << 3) * ENABLE_FEATURE_STAT_FILESYSTEM, 1.31 ++ OPT_SELINUX = (1 << (3+ENABLE_FEATURE_STAT_FILESYSTEM)) * ENABLE_SELINUX, 1.32 + }; 1.33 + 1.34 + #if ENABLE_FEATURE_STAT_FORMAT 1.35 +@@ -463,6 +466,25 @@ 1.36 + } 1.37 + #endif /* FEATURE_STAT_FORMAT */ 1.38 + 1.39 ++#if !ENABLE_FEATURE_STAT_FORMAT 1.40 ++#define do_mapfile(filename, format) do_mapfile(filename) 1.41 ++#endif 1.42 ++static bool do_mapfile(const char *filename, const char *format) 1.43 ++{ 1.44 ++ int i = 0; 1.45 ++ int fd = xopen(filename, O_RDONLY); 1.46 ++ 1.47 ++#if ENABLE_FEATURE_STAT_FORMAT 1.48 ++ (void) format; 1.49 ++#endif 1.50 ++ while (1) { 1.51 ++ int blk = i++; 1.52 ++ if (ioctl(fd,FIBMAP,&blk) < 0 || blk == 0) break; 1.53 ++ printf("%u\n",blk); 1.54 ++ } 1.55 ++ return 1; 1.56 ++} 1.57 ++ 1.58 + #if ENABLE_FEATURE_STAT_FILESYSTEM 1.59 + /* Stat the file system and print what we find. */ 1.60 + #if !ENABLE_FEATURE_STAT_FORMAT 1.61 +@@ -763,7 +785,7 @@ 1.62 + statfunc_ptr statfunc = do_stat; 1.63 + 1.64 + opt_complementary = "-1"; /* min one arg */ 1.65 +- opts = getopt32(argv, "tL" 1.66 ++ opts = getopt32(argv, "tLm" 1.67 + IF_FEATURE_STAT_FILESYSTEM("f") 1.68 + IF_SELINUX("Z") 1.69 + IF_FEATURE_STAT_FORMAT("c:", &format) 1.70 +@@ -777,6 +799,9 @@ 1.71 + selinux_or_die(); 1.72 + } 1.73 + #endif 1.74 ++ if (opts & OPT_MAP) { /* -m */ 1.75 ++ statfunc = do_mapfile; 1.76 ++ } 1.77 + ok = 1; 1.78 + argv += optind; 1.79 + for (i = 0; argv[i]; ++i)