wok view busybox/stuff/busybox-1.22-fatattr.u @ rev 17217

Up: file (5.20).
author Aleksej Bobylev <al.bobylev@gmail.com>
date Tue Oct 14 11:50:51 2014 +0300 (2014-10-14)
parents 79c239d4e13f
children
line source
1 --- busybox-1.22.0/include/applets.src.h
2 +++ busybox-1.22.0/include/applets.src.h
3 @@ -138,6 +138,7 @@
4 IF_EXPR(APPLET(expr, BB_DIR_USR_BIN, BB_SUID_DROP))
5 IF_FAKEIDENTD(APPLET(fakeidentd, BB_DIR_USR_SBIN, BB_SUID_DROP))
6 IF_FALSE(APPLET_NOFORK(false, false, BB_DIR_BIN, BB_SUID_DROP, false))
7 +IF_FATATTR(APPLET(fatattr, BB_DIR_BIN, BB_SUID_DROP))
8 IF_FBSET(APPLET(fbset, BB_DIR_USR_SBIN, BB_SUID_DROP))
9 IF_FBSPLASH(APPLET(fbsplash, BB_DIR_SBIN, BB_SUID_DROP))
10 IF_FDFLUSH(APPLET_ODDNAME(fdflush, freeramdisk, BB_DIR_BIN, BB_SUID_DROP, fdflush))
11 --- busybox-1.22.0/e2fsprogs/Config.src
12 +++ busybox-1.22.0/e2fsprogs/Config.src
13 @@ -37,6 +37,13 @@
14 help
15 lsattr lists the file attributes on a second extended file system.
17 +config FATATTR
18 + bool "fatattr"
19 + default y
20 + select PLATFORM_LINUX
21 + help
22 + fatattr lists or changes the file attributes on a fat file system.
23 +
24 ### config MKE2FS
25 ### bool "mke2fs"
26 ### default y
27 --- busybox-1.22.0/e2fsprogs/Kbuild.src
28 +++ busybox-1.22.0/e2fsprogs/Kbuild.src
29 @@ -11,5 +11,7 @@
30 lib-$(CONFIG_CHATTR) += chattr.o e2fs_lib.o
31 lib-$(CONFIG_LSATTR) += lsattr.o e2fs_lib.o
33 +lib-$(CONFIG_FATATTR) += fatattr.o
34 +
35 lib-$(CONFIG_FSCK) += fsck.o
36 lib-$(CONFIG_TUNE2FS) += tune2fs.o
37 --- busybox-1.22.0/e2fsprogs/fatattr.c
38 +++ busybox-1.22.0/e2fsprogs/fatattr.c
39 @@ -0,0 +1,113 @@
40 +/* vi: set sw=4 ts=4: */
41 +/*
42 + * fatattr.c - Display or change file attributes on a fat file system
43 + *
44 + * Copyright 2005 H. Peter Anvin
45 + * Busybox'ed (2014) by Pascal Bellard <pascal.bellard@ads-lu.com>
46 + *
47 + * This file can be redistributed under the terms of the GNU General
48 + * Public License
49 + */
50 +
51 +//usage:#define fatattr_trivial_usage
52 +//usage: "[-+rhsvda] [FILE]..."
53 +//usage:#define fatattr_full_usage "\n\n"
54 +//usage: "Change file attributes on a fat fs\n"
55 +//usage: "\nModifiers:"
56 +//usage: "\n - Clear attributes"
57 +//usage: "\n + Set attributes"
58 +//usage: "\nAttributes:"
59 +//usage: "\n r Read only"
60 +//usage: "\n h Hidden"
61 +//usage: "\n s System"
62 +//usage: "\n v Volume label"
63 +//usage: "\n d Directory"
64 +//usage: "\n a Archive"
65 +
66 +#include "libbb.h"
67 +/* linux/msdos_fs.h says: */
68 +#ifndef FAT_IOCTL_GET_ATTRIBUTES
69 +# define FAT_IOCTL_GET_ATTRIBUTES _IOR('r', 0x10, uint32_t)
70 +#endif
71 +#ifndef FAT_IOCTL_SET_ATTRIBUTES
72 +# define FAT_IOCTL_SET_ATTRIBUTES _IOW('r', 0x11, uint32_t)
73 +#endif
74 +
75 +#define OPT_ADD 1
76 +#define OPT_REM 2
77 +
78 +struct globals {
79 + unsigned long af;
80 + unsigned long rf;
81 +};
82 +
83 +/* Currently supports only the FAT flags, not the NTFS ones */
84 +const char bit_to_char[] = "rhsvda67 ";
85 +
86 +static inline unsigned long get_flag(char c)
87 +{
88 + const char *fp = strchr(bit_to_char, c);
89 + if (fp)
90 + return 1 << (fp - bit_to_char);
91 + bb_error_msg_and_die("invalid character '%c' ", c);
92 +}
93 +
94 +static inline int decode_arg(const char *arg, struct globals *gp)
95 +{
96 + unsigned long *fl;
97 + char opt = *arg++;
98 +
99 + fl = &gp->af;
100 + if (opt == '-') {
101 + fl = &gp->rf;
102 + } else if (opt != '+') {
103 + return 0;
104 + }
105 +
106 + while (*arg)
107 + *fl |= get_flag(*arg++);
108 +
109 + return 1;
110 +}
111 +
112 +int fatattr_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
113 +int fatattr_main(int argc UNUSED_PARAM, char **argv)
114 +{
115 + struct globals g;
116 + char *arg;
117 +
118 + g.rf = g.af = 0;
119 +
120 + /* parse the args */
121 + while ((arg = *++argv)) {
122 + if (!decode_arg(arg, &g))
123 + break;
124 + }
125 +
126 + /* run sanity checks on all the arguments given us */
127 + if (!*argv)
128 + bb_show_usage();
129 +
130 + /* now proceed all the files passed to us */
131 + do {
132 + int fd, i;
133 + uint32_t attr;
134 +
135 + fd = xopen(*argv, O_RDONLY);
136 + xioctl(fd, FAT_IOCTL_GET_ATTRIBUTES, &attr);
137 + attr |= g.af;
138 + attr &= ~g.rf;
139 + if (g.af || g.rf)
140 + xioctl(fd, FAT_IOCTL_SET_ATTRIBUTES, &attr);
141 + else {
142 + for ( i = 0 ; bit_to_char[i] ; i++ ) {
143 + bb_putchar( (attr & 1) ? bit_to_char[i] : ' ' );
144 + attr >>= 1;
145 + }
146 + puts(*argv);
147 + }
148 + close(fd);
149 + } while (*++argv);
150 +
151 + return EXIT_SUCCESS;
152 +}