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