wok-6.x diff busybox/stuff/busybox-1.20-stat.u @ rev 13481
busybox: use slitaz-base httphelper.sh
author | Pascal Bellard <pascal.bellard@slitaz.org> |
---|---|
date | Thu Oct 11 13:43:57 2012 +0200 (2012-10-11) |
parents | |
children |
line diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/busybox/stuff/busybox-1.20-stat.u Thu Oct 11 13:43:57 2012 +0200 1.3 @@ -0,0 +1,74 @@ 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.20.0/coreutils/stat.c 1.8 ++++ busybox-1.20.0/coreutils/stat.c 1.9 +@@ -23,6 +23,7 @@ 1.10 + //usage: "\n -f Display filesystem status" 1.11 + //usage: "\n -L Follow links" 1.12 + //usage: "\n -t Display info in terse form" 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 +@@ -73,11 +74,13 @@ 1.18 + //usage: ) 1.19 + 1.20 + #include "libbb.h" 1.21 ++#include <linux/fs.h> 1.22 + 1.23 + #define OPT_FILESYS (1 << 0) 1.24 + #define OPT_TERSE (1 << 1) 1.25 + #define OPT_DEREFERENCE (1 << 2) 1.26 +-#define OPT_SELINUX (1 << 3) 1.27 ++#define OPT_MAP (1 << 3) 1.28 ++#define OPT_SELINUX (1 << 4) 1.29 + 1.30 + #if ENABLE_FEATURE_STAT_FORMAT 1.31 + typedef bool (*statfunc_ptr)(const char *, const char *); 1.32 +@@ -419,6 +422,26 @@ 1.33 + 1.34 + /* Stat the file system and print what we find. */ 1.35 + #if !ENABLE_FEATURE_STAT_FORMAT 1.36 ++#define do_mapfile(filename, format) do_mapfile(filename) 1.37 ++#endif 1.38 ++static bool do_mapfile(const char *filename, const char *format) 1.39 ++{ 1.40 ++ int i = 0; 1.41 ++ int fd = xopen(filename, O_RDONLY); 1.42 ++ 1.43 ++#if ENABLE_FEATURE_STAT_FORMAT 1.44 ++ (void) format; 1.45 ++#endif 1.46 ++ while (1) { 1.47 ++ int blk = i++; 1.48 ++ if (ioctl(fd,FIBMAP,&blk) < 0 || blk == 0) break; 1.49 ++ printf("%u\n",blk); 1.50 ++ } 1.51 ++ return 1; 1.52 ++} 1.53 ++ 1.54 ++/* Stat the file system and print what we find. */ 1.55 ++#if !ENABLE_FEATURE_STAT_FORMAT 1.56 + #define do_statfs(filename, format) do_statfs(filename) 1.57 + #endif 1.58 + static bool do_statfs(const char *filename, const char *format) 1.59 +@@ -708,7 +731,7 @@ 1.60 + statfunc_ptr statfunc = do_stat; 1.61 + 1.62 + opt_complementary = "-1"; /* min one arg */ 1.63 +- opts = getopt32(argv, "ftL" 1.64 ++ opts = getopt32(argv, "ftLm" 1.65 + IF_SELINUX("Z") 1.66 + IF_FEATURE_STAT_FORMAT("c:", &format) 1.67 + ); 1.68 +@@ -719,6 +742,9 @@ 1.69 + selinux_or_die(); 1.70 + } 1.71 + #endif 1.72 ++ if (opts & OPT_MAP) { /* -m */ 1.73 ++ statfunc = do_mapfile; 1.74 ++ } 1.75 + ok = 1; 1.76 + argv += optind; 1.77 + for (i = 0; argv[i]; ++i)