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