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