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