wok view busybox/stuff/busybox-1.21-stat.u @ rev 15390

Up slitaz-boot-scripts (5.3.2)
author Pascal Bellard <pascal.bellard@slitaz.org>
date Wed Oct 30 18:29:11 2013 +0100 (2013-10-30)
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.20.0/coreutils/stat.c
5 +++ busybox-1.20.0/coreutils/stat.c
6 @@ -23,6 +23,7 @@
7 //usage: "\n -f Display filesystem status"
8 //usage: "\n -L Follow links"
9 //usage: "\n -t Display info in terse form"
10 +//usage: "\n -m Display block list"
11 //usage: IF_SELINUX(
12 //usage: "\n -Z Print security context"
13 //usage: )
14 @@ -73,11 +74,13 @@
15 //usage: )
17 #include "libbb.h"
18 +#include <linux/fs.h>
20 #define OPT_FILESYS (1 << 0)
21 #define OPT_TERSE (1 << 1)
22 #define OPT_DEREFERENCE (1 << 2)
23 -#define OPT_SELINUX (1 << 3)
24 +#define OPT_MAP (1 << 3)
25 +#define OPT_SELINUX (1 << 4)
27 #if ENABLE_FEATURE_STAT_FORMAT
28 typedef bool (*statfunc_ptr)(const char *, const char *);
29 @@ -425,6 +428,26 @@
31 /* Stat the file system and print what we find. */
32 #if !ENABLE_FEATURE_STAT_FORMAT
33 +#define do_mapfile(filename, format) do_mapfile(filename)
34 +#endif
35 +static bool do_mapfile(const char *filename, const char *format)
36 +{
37 + int i = 0;
38 + int fd = xopen(filename, O_RDONLY);
39 +
40 +#if ENABLE_FEATURE_STAT_FORMAT
41 + (void) format;
42 +#endif
43 + while (1) {
44 + int blk = i++;
45 + if (ioctl(fd,FIBMAP,&blk) < 0 || blk == 0) break;
46 + printf("%u\n",blk);
47 + }
48 + return 1;
49 +}
50 +
51 +/* Stat the file system and print what we find. */
52 +#if !ENABLE_FEATURE_STAT_FORMAT
53 #define do_statfs(filename, format) do_statfs(filename)
54 #endif
55 static bool do_statfs(const char *filename, const char *format)
56 @@ -720,7 +743,7 @@
57 statfunc_ptr statfunc = do_stat;
59 opt_complementary = "-1"; /* min one arg */
60 - opts = getopt32(argv, "ftL"
61 + opts = getopt32(argv, "ftLm"
62 IF_SELINUX("Z")
63 IF_FEATURE_STAT_FORMAT("c:", &format)
64 );
65 @@ -731,6 +754,9 @@
66 selinux_or_die();
67 }
68 #endif
69 + if (opts & OPT_MAP) { /* -m */
70 + statfunc = do_mapfile;
71 + }
72 ok = 1;
73 argv += optind;
74 for (i = 0; argv[i]; ++i)