wok view busybox/stuff/busybox-1.31-stat.u @ rev 24819

libnsl: add current_version
author Pascal Bellard <pascal.bellard@slitaz.org>
date Wed Mar 23 09:20:46 2022 +0000 (2022-03-23)
parents 42b4b9d947f3
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.31/coreutils/stat.c
5 +++ busybox-1.31/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 @@ -467,6 +470,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 @@ -764,13 +786,11 @@
59 int i;
60 int ok;
61 statfunc_ptr statfunc = do_stat;
62 -#if ENABLE_FEATURE_STAT_FILESYSTEM || ENABLE_SELINUX
63 unsigned opts;
65 opts =
66 -#endif
67 getopt32(argv, "^"
68 - "tL"
69 + "tLm"
70 IF_FEATURE_STAT_FILESYSTEM("f")
71 IF_SELINUX("Z")
72 IF_FEATURE_STAT_FORMAT("c:")
73 @@ -786,6 +806,9 @@
74 selinux_or_die();
75 }
76 #endif
77 + if (opts & OPT_MAP) { /* -m */
78 + statfunc = do_mapfile;
79 + }
80 ok = 1;
81 argv += optind;
82 for (i = 0; argv[i]; ++i)