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