rev |
line source |
pascal@12460
|
1 Add non standard stat -m support to display file block list
|
pascal@12460
|
2 Useful to patch read-only filesystems such as ISO9660, for defragmentation
|
pascal@12460
|
3 tools or boot loaders
|
pascal@12460
|
4 --- busybox-1.20.0/coreutils/stat.c
|
pascal@12460
|
5 +++ busybox-1.20.0/coreutils/stat.c
|
pascal@12460
|
6 @@ -23,6 +23,7 @@
|
pascal@12460
|
7 //usage: "\n -f Display filesystem status"
|
pascal@12460
|
8 //usage: "\n -L Follow links"
|
pascal@12460
|
9 //usage: "\n -t Display info in terse form"
|
pascal@12460
|
10 +//usage: "\n -m Display block list"
|
pascal@12460
|
11 //usage: IF_SELINUX(
|
pascal@12460
|
12 //usage: "\n -Z Print security context"
|
pascal@12460
|
13 //usage: )
|
pascal@12460
|
14 @@ -73,11 +74,13 @@
|
pascal@12460
|
15 //usage: )
|
pascal@12460
|
16
|
pascal@12460
|
17 #include "libbb.h"
|
pascal@12460
|
18 +#include <linux/fs.h>
|
pascal@12460
|
19
|
pascal@12460
|
20 #define OPT_FILESYS (1 << 0)
|
pascal@12460
|
21 #define OPT_TERSE (1 << 1)
|
pascal@12460
|
22 #define OPT_DEREFERENCE (1 << 2)
|
pascal@12460
|
23 -#define OPT_SELINUX (1 << 3)
|
pascal@12460
|
24 +#define OPT_MAP (1 << 3)
|
pascal@12460
|
25 +#define OPT_SELINUX (1 << 4)
|
pascal@12460
|
26
|
pascal@12460
|
27 #if ENABLE_FEATURE_STAT_FORMAT
|
pascal@12460
|
28 typedef bool (*statfunc_ptr)(const char *, const char *);
|
pascal@12460
|
29 @@ -419,6 +422,26 @@
|
pascal@12460
|
30
|
pascal@12460
|
31 /* Stat the file system and print what we find. */
|
pascal@12460
|
32 #if !ENABLE_FEATURE_STAT_FORMAT
|
pascal@12460
|
33 +#define do_mapfile(filename, format) do_mapfile(filename)
|
pascal@12460
|
34 +#endif
|
pascal@12460
|
35 +static bool do_mapfile(const char *filename, const char *format)
|
pascal@12460
|
36 +{
|
pascal@12460
|
37 + int i = 0;
|
pascal@12460
|
38 + int fd = xopen(filename, O_RDONLY);
|
pascal@12460
|
39 +
|
pascal@12460
|
40 +#if ENABLE_FEATURE_STAT_FORMAT
|
pascal@12460
|
41 + (void) format;
|
pascal@12460
|
42 +#endif
|
pascal@12460
|
43 + while (1) {
|
pascal@12460
|
44 + int blk = i++;
|
pascal@12460
|
45 + if (ioctl(fd,FIBMAP,&blk) < 0 || blk == 0) break;
|
pascal@12460
|
46 + printf("%u\n",blk);
|
pascal@12460
|
47 + }
|
pascal@12460
|
48 + return 1;
|
pascal@12460
|
49 +}
|
pascal@12460
|
50 +
|
pascal@12460
|
51 +/* Stat the file system and print what we find. */
|
pascal@12460
|
52 +#if !ENABLE_FEATURE_STAT_FORMAT
|
pascal@12460
|
53 #define do_statfs(filename, format) do_statfs(filename)
|
pascal@12460
|
54 #endif
|
pascal@12460
|
55 static bool do_statfs(const char *filename, const char *format)
|
pascal@12460
|
56 @@ -708,7 +731,7 @@
|
pascal@12460
|
57 statfunc_ptr statfunc = do_stat;
|
pascal@12460
|
58
|
pascal@12460
|
59 opt_complementary = "-1"; /* min one arg */
|
pascal@12460
|
60 - opts = getopt32(argv, "ftL"
|
pascal@12460
|
61 + opts = getopt32(argv, "ftLm"
|
pascal@12460
|
62 IF_SELINUX("Z")
|
pascal@12460
|
63 IF_FEATURE_STAT_FORMAT("c:", &format)
|
pascal@12460
|
64 );
|
pascal@12460
|
65 @@ -719,6 +742,9 @@
|
pascal@12460
|
66 selinux_or_die();
|
pascal@12460
|
67 }
|
pascal@12460
|
68 #endif
|
pascal@12460
|
69 + if (opts & OPT_MAP) { /* -m */
|
pascal@12460
|
70 + statfunc = do_mapfile;
|
pascal@12460
|
71 + }
|
pascal@12460
|
72 ok = 1;
|
pascal@12460
|
73 argv += optind;
|
pascal@12460
|
74 for (i = 0; argv[i]; ++i)
|