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