wok-current view busybox/stuff/busybox-1.18-stat.u @ rev 10972

Up: tor to 0.2.2.33.
author Christopher Rogers <slaxemulator@gmail.com>
date Wed Oct 12 12:39:17 2011 +0000 (2011-10-12)
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.18.0/include/usage.src.h
5 +++ busybox-1.18.0/include/usage.src.h
6 @@ -3654,6 +3654,7 @@
7 "\n -f Display filesystem status" \
8 "\n -L Follow links" \
9 "\n -t Display info in terse form" \
10 + "\n -m Display block list" \
11 IF_SELINUX( \
12 "\n -Z Print security context" \
13 ) \
15 --- busybox-1.17.1/coreutils/stat.c
16 +++ busybox-1.17.1/coreutils/stat.c
17 @@ -13,11 +13,13 @@
18 * Licensed under GPLv2 or later, see file LICENSE in this source tree.
19 */
20 #include "libbb.h"
21 +#include <linux/fs.h>
23 #define OPT_FILESYS (1 << 0)
24 #define OPT_TERSE (1 << 1)
25 #define OPT_DEREFERENCE (1 << 2)
26 -#define OPT_SELINUX (1 << 3)
27 +#define OPT_MAP (1 << 3)
28 +#define OPT_SELINUX (1 << 4)
30 #if ENABLE_FEATURE_STAT_FORMAT
31 typedef bool (*statfunc_ptr)(const char *, const char *);
32 @@ -359,6 +361,26 @@
34 /* Stat the file system and print what we find. */
35 #if !ENABLE_FEATURE_STAT_FORMAT
36 +#define do_mapfile(filename, format) do_mapfile(filename)
37 +#endif
38 +static bool do_mapfile(const char *filename, const char *format)
39 +{
40 + int i = 0;
41 + int fd = xopen(filename, O_RDONLY);
42 +
43 +#if ENABLE_FEATURE_STAT_FORMAT
44 + (void) format;
45 +#endif
46 + while (1) {
47 + int blk = i++;
48 + if (ioctl(fd,FIBMAP,&blk) < 0 || blk == 0) break;
49 + printf("%u\n",blk);
50 + }
51 + return 1;
52 +}
53 +
54 +/* Stat the file system and print what we find. */
55 +#if !ENABLE_FEATURE_STAT_FORMAT
56 #define do_statfs(filename, format) do_statfs(filename)
57 #endif
58 static bool do_statfs(const char *filename, const char *format)
59 @@ -648,7 +670,7 @@
60 statfunc_ptr statfunc = do_stat;
62 opt_complementary = "-1"; /* min one arg */
63 - opts = getopt32(argv, "ftL"
64 + opts = getopt32(argv, "ftLm"
65 IF_SELINUX("Z")
66 IF_FEATURE_STAT_FORMAT("c:", &format)
67 );
68 @@ -659,6 +681,9 @@
69 selinux_or_die();
70 }
71 #endif
72 + if (opts & OPT_MAP) { /* -m */
73 + statfunc = do_mapfile;
74 + }
75 ok = 1;
76 argv += optind;
77 for (i = 0; argv[i]; ++i)