wok view busybox/stuff/busybox-1.30-stat.u @ rev 21458
Update busybox-static for loram (again)
author | Pascal Bellard <pascal.bellard@slitaz.org> |
---|---|
date | Mon Apr 29 23:15:47 2019 +0200 (2019-04-29) |
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.30/coreutils/stat.c
5 +++ busybox-1.30/coreutils/stat.c
6 @@ -54,6 +54,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 @@ -106,13 +107,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 @@ -463,6 +466,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 @@ -766,7 +788,7 @@
59 opts =
60 #endif
61 getopt32(argv, "^"
62 - "tL"
63 + "tLm"
64 IF_FEATURE_STAT_FILESYSTEM("f")
65 IF_SELINUX("Z")
66 IF_FEATURE_STAT_FORMAT("c:")
67 @@ -782,6 +804,11 @@
68 selinux_or_die();
69 }
70 #endif
71 +#if ENABLE_FEATURE_STAT_FILESYSTEM
72 + if (opts & OPT_MAP) { /* -m */
73 + statfunc = do_mapfile;
74 + }
75 +#endif
76 ok = 1;
77 argv += optind;
78 for (i = 0; argv[i]; ++i)