aboutsummaryrefslogtreecommitdiff
path: root/coreutils/stat.c
diff options
context:
space:
mode:
authorBernhard Reutner-Fischer <rep.dot.nop@gmail.com>2007-04-04 13:58:33 +0000
committerBernhard Reutner-Fischer <rep.dot.nop@gmail.com>2007-04-04 13:58:33 +0000
commit0e6ab01c5a525fc0e298d44f4573a4f8972406f2 (patch)
tree012acc044e0e11dc2060befe05aeab12f108f7e7 /coreutils/stat.c
parent794687947fe9eb15b2512a0d9645d827348c5f6f (diff)
downloadbusybox-w32-0e6ab01c5a525fc0e298d44f4573a4f8972406f2.tar.gz
busybox-w32-0e6ab01c5a525fc0e298d44f4573a4f8972406f2.tar.bz2
busybox-w32-0e6ab01c5a525fc0e298d44f4573a4f8972406f2.zip
- remove superfluous bss user (flags) and manually unswitch some areas:
text data bss dec hex filename 4517 0 34 4551 11c7 stat.o.oorig 4300 0 30 4330 10ea stat.o
Diffstat (limited to 'coreutils/stat.c')
-rw-r--r--coreutils/stat.c230
1 files changed, 92 insertions, 138 deletions
diff --git a/coreutils/stat.c b/coreutils/stat.c
index a2cdbfb29..397e395d8 100644
--- a/coreutils/stat.c
+++ b/coreutils/stat.c
@@ -16,12 +16,14 @@
16#include "busybox.h" 16#include "busybox.h"
17 17
18/* vars to control behavior */ 18/* vars to control behavior */
19#define OPT_TERSE 2 19#define OPT_FILESYS (1<<0)
20#define OPT_DEREFERENCE 4 20#define OPT_TERSE (1<<1)
21#define OPT_SELINUX 8 21#define OPT_DEREFERENCE (1<<2)
22static long flags; 22#define OPT_SELINUX (1<<3)
23 23
24static char const *file_type(struct stat const *st) 24static char buf[sizeof("YYYY-MM-DD HH:MM:SS.000000000")];
25
26static char const * file_type(struct stat const *st)
25{ 27{
26 /* See POSIX 1003.1-2001 XCU Table 4-8 lines 17093-17107 28 /* See POSIX 1003.1-2001 XCU Table 4-8 lines 17093-17107
27 * for some of these formats. 29 * for some of these formats.
@@ -53,7 +55,7 @@ static char const *human_time(time_t t)
53 return str; 55 return str;
54 */ 56 */
55 /* coreutils 6.3 compat: */ 57 /* coreutils 6.3 compat: */
56 static char buf[sizeof("YYYY-MM-DD HH:MM:SS.000000000")]; 58
57 strftime(buf, sizeof(buf), "%Y-%m-%d %H:%M:%S.000000000", localtime(&t)); 59 strftime(buf, sizeof(buf), "%Y-%m-%d %H:%M:%S.000000000", localtime(&t));
58 return buf; 60 return buf;
59} 61}
@@ -66,9 +68,9 @@ static char const *human_time(time_t t)
66static char const *human_fstype(long f_type) 68static char const *human_fstype(long f_type)
67{ 69{
68 int i; 70 int i;
69 static const struct types { 71 const struct types {
70 long type; 72 long type;
71 const char *fs; 73 const char * const fs;
72 } humantypes[] = { 74 } humantypes[] = {
73 { 0xADFF, "affs" }, 75 { 0xADFF, "affs" },
74 { 0x1Cd1, "devpts" }, 76 { 0x1Cd1, "devpts" },
@@ -115,76 +117,58 @@ static char const *human_fstype(long f_type)
115 117
116#ifdef CONFIG_FEATURE_STAT_FORMAT 118#ifdef CONFIG_FEATURE_STAT_FORMAT
117/* print statfs info */ 119/* print statfs info */
118static void print_statfs(char *pformat, size_t buf_len, char m, 120static void print_statfs(char *pformat, const size_t buf_len, const char m,
119 char const *filename, void const *data 121 const char * const filename, void const *data
120 USE_SELINUX(,security_context_t scontext) ) 122 USE_SELINUX(, security_context_t scontext))
121{ 123{
122 struct statfs const *statfsbuf = data; 124 struct statfs const *statfsbuf = data;
123 125 if (m == 'n') {
124 switch (m) {
125 case 'n':
126 strncat(pformat, "s", buf_len); 126 strncat(pformat, "s", buf_len);
127 printf(pformat, filename); 127 printf(pformat, filename);
128 break; 128 } else if (m == 'i') {
129 case 'i':
130 strncat(pformat, "Lx", buf_len); 129 strncat(pformat, "Lx", buf_len);
131 printf(pformat, statfsbuf->f_fsid); 130 printf(pformat, statfsbuf->f_fsid);
132 break; 131 } else if (m == 'l') {
133 case 'l':
134 strncat(pformat, "lu", buf_len); 132 strncat(pformat, "lu", buf_len);
135 printf(pformat, statfsbuf->f_namelen); 133 printf(pformat, statfsbuf->f_namelen);
136 break; 134 } else if (m == 't') {
137 case 't':
138 strncat(pformat, "lx", buf_len); 135 strncat(pformat, "lx", buf_len);
139 printf(pformat, (unsigned long int) (statfsbuf->f_type)); /* no equiv. */ 136 printf(pformat, (unsigned long int) (statfsbuf->f_type)); /* no equiv */
140 break; 137 } else if (m == 'T') {
141 case 'T':
142 strncat(pformat, "s", buf_len); 138 strncat(pformat, "s", buf_len);
143 printf(pformat, human_fstype(statfsbuf->f_type)); 139 printf(pformat, human_fstype(statfsbuf->f_type));
144 break; 140 } else if (m == 'b') {
145 case 'b':
146 strncat(pformat, "jd", buf_len); 141 strncat(pformat, "jd", buf_len);
147 printf(pformat, (intmax_t) (statfsbuf->f_blocks)); 142 printf(pformat, (intmax_t) (statfsbuf->f_blocks));
148 break; 143 } else if (m == 'f') {
149 case 'f':
150 strncat(pformat, "jd", buf_len); 144 strncat(pformat, "jd", buf_len);
151 printf(pformat, (intmax_t) (statfsbuf->f_bfree)); 145 printf(pformat, (intmax_t) (statfsbuf->f_bfree));
152 break; 146 } else if (m == 'a') {
153 case 'a':
154 strncat(pformat, "jd", buf_len); 147 strncat(pformat, "jd", buf_len);
155 printf(pformat, (intmax_t) (statfsbuf->f_bavail)); 148 printf(pformat, (intmax_t) (statfsbuf->f_bavail));
156 break; 149 } else if (m == 's' || m == 'S') {
157 case 'S':
158 case 's':
159 strncat(pformat, "lu", buf_len); 150 strncat(pformat, "lu", buf_len);
160 printf(pformat, (unsigned long int) (statfsbuf->f_bsize)); 151 printf(pformat, (unsigned long int) (statfsbuf->f_bsize));
161 break; 152 } else if (m == 'c') {
162 case 'c':
163 strncat(pformat, "jd", buf_len); 153 strncat(pformat, "jd", buf_len);
164 printf(pformat, (intmax_t) (statfsbuf->f_files)); 154 printf(pformat, (intmax_t) (statfsbuf->f_files));
165 break; 155 } else if (m == 'd') {
166 case 'd':
167 strncat(pformat, "jd", buf_len); 156 strncat(pformat, "jd", buf_len);
168 printf(pformat, (intmax_t) (statfsbuf->f_ffree)); 157 printf(pformat, (intmax_t) (statfsbuf->f_ffree));
169 break;
170#if ENABLE_SELINUX 158#if ENABLE_SELINUX
171 case 'C': 159 } else if (m == 'C' && (option_mask32 & OPT_SELINUX)) {
172 if (flags & OPT_SELINUX) { 160 strncat(pformat, "s", buf_len);
173 strncat(pformat, "s", buf_len); 161 printf(scontext);
174 printf(scontext);
175 }
176 break;
177#endif 162#endif
178 default: 163 } else {
179 strncat(pformat, "c", buf_len); 164 strncat(pformat, "c", buf_len);
180 printf(pformat, m); 165 printf(pformat, m);
181 break;
182 } 166 }
183} 167}
184 168
185/* print stat info */ 169/* print stat info */
186static void print_stat(char *pformat, size_t buf_len, char m, 170static void print_stat(char *pformat, const size_t buf_len, const char m,
187 char const *filename, void const *data 171 const char * const filename, void const *data
188 USE_SELINUX(, security_context_t scontext)) 172 USE_SELINUX(, security_context_t scontext))
189{ 173{
190#define TYPE_SIGNED(t) (! ((t) 0 < (t) -1)) 174#define TYPE_SIGNED(t) (! ((t) 0 < (t) -1))
@@ -192,12 +176,10 @@ static void print_stat(char *pformat, size_t buf_len, char m,
192 struct passwd *pw_ent; 176 struct passwd *pw_ent;
193 struct group *gw_ent; 177 struct group *gw_ent;
194 178
195 switch (m) { 179 if (m == 'n') {
196 case 'n':
197 strncat(pformat, "s", buf_len); 180 strncat(pformat, "s", buf_len);
198 printf(pformat, filename); 181 printf(pformat, filename);
199 break; 182 } else if (m == 'N') {
200 case 'N':
201 strncat(pformat, "s", buf_len); 183 strncat(pformat, "s", buf_len);
202 if (S_ISLNK(statbuf->st_mode)) { 184 if (S_ISLNK(statbuf->st_mode)) {
203 char *linkname = xmalloc_readlink_or_warn(filename); 185 char *linkname = xmalloc_readlink_or_warn(filename);
@@ -212,119 +194,90 @@ static void print_stat(char *pformat, size_t buf_len, char m,
212 } else { 194 } else {
213 printf(pformat, filename); 195 printf(pformat, filename);
214 } 196 }
215 break; 197 } else if (m == 'd') {
216 case 'd':
217 strncat(pformat, "ju", buf_len); 198 strncat(pformat, "ju", buf_len);
218 printf(pformat, (uintmax_t) statbuf->st_dev); 199 printf(pformat, (uintmax_t) statbuf->st_dev);
219 break; 200 } else if (m == 'D') {
220 case 'D':
221 strncat(pformat, "jx", buf_len); 201 strncat(pformat, "jx", buf_len);
222 printf(pformat, (uintmax_t) statbuf->st_dev); 202 printf(pformat, (uintmax_t) statbuf->st_dev);
223 break; 203 } else if (m == 'i') {
224 case 'i':
225 strncat(pformat, "ju", buf_len); 204 strncat(pformat, "ju", buf_len);
226 printf(pformat, (uintmax_t) statbuf->st_ino); 205 printf(pformat, (uintmax_t) statbuf->st_ino);
227 break; 206 } else if (m == 'a') {
228 case 'a':
229 strncat(pformat, "lo", buf_len); 207 strncat(pformat, "lo", buf_len);
230 printf(pformat, (unsigned long int) (statbuf->st_mode & (S_ISUID|S_ISGID|S_ISVTX|S_IRWXU|S_IRWXG|S_IRWXO))); 208 printf(pformat, (unsigned long int) (statbuf->st_mode & (S_ISUID|S_ISGID|S_ISVTX|S_IRWXU|S_IRWXG|S_IRWXO)));
231 break; 209 } else if (m == 'A') {
232 case 'A':
233 strncat(pformat, "s", buf_len); 210 strncat(pformat, "s", buf_len);
234 printf(pformat, bb_mode_string(statbuf->st_mode)); 211 printf(pformat, bb_mode_string(statbuf->st_mode));
235 break; 212 } else if (m == 'f') {
236 case 'f':
237 strncat(pformat, "lx", buf_len); 213 strncat(pformat, "lx", buf_len);
238 printf(pformat, (unsigned long int) statbuf->st_mode); 214 printf(pformat, (unsigned long int) statbuf->st_mode);
239 break; 215 } else if (m == 'F') {
240 case 'F':
241 strncat(pformat, "s", buf_len); 216 strncat(pformat, "s", buf_len);
242 printf(pformat, file_type(statbuf)); 217 printf(pformat, file_type(statbuf));
243 break; 218 } else if (m == 'h') {
244 case 'h':
245 strncat(pformat, "lu", buf_len); 219 strncat(pformat, "lu", buf_len);
246 printf(pformat, (unsigned long int) statbuf->st_nlink); 220 printf(pformat, (unsigned long int) statbuf->st_nlink);
247 break; 221 } else if (m == 'u') {
248 case 'u':
249 strncat(pformat, "lu", buf_len); 222 strncat(pformat, "lu", buf_len);
250 printf(pformat, (unsigned long int) statbuf->st_uid); 223 printf(pformat, (unsigned long int) statbuf->st_uid);
251 break; 224 } else if (m == 'U') {
252 case 'U':
253 strncat(pformat, "s", buf_len); 225 strncat(pformat, "s", buf_len);
254 setpwent(); 226 setpwent();
255 pw_ent = getpwuid(statbuf->st_uid); 227 pw_ent = getpwuid(statbuf->st_uid);
256 printf(pformat, (pw_ent != 0L) ? pw_ent->pw_name : "UNKNOWN"); 228 printf(pformat, (pw_ent != 0L) ? pw_ent->pw_name : "UNKNOWN");
257 break; 229 } else if (m == 'g') {
258 case 'g':
259 strncat(pformat, "lu", buf_len); 230 strncat(pformat, "lu", buf_len);
260 printf(pformat, (unsigned long int) statbuf->st_gid); 231 printf(pformat, (unsigned long int) statbuf->st_gid);
261 break; 232 } else if (m == 'G') {
262 case 'G':
263 strncat(pformat, "s", buf_len); 233 strncat(pformat, "s", buf_len);
264 setgrent(); 234 setgrent();
265 gw_ent = getgrgid(statbuf->st_gid); 235 gw_ent = getgrgid(statbuf->st_gid);
266 printf(pformat, (gw_ent != 0L) ? gw_ent->gr_name : "UNKNOWN"); 236 printf(pformat, (gw_ent != 0L) ? gw_ent->gr_name : "UNKNOWN");
267 break; 237 } else if (m == 't') {
268 case 't':
269 strncat(pformat, "lx", buf_len); 238 strncat(pformat, "lx", buf_len);
270 printf(pformat, (unsigned long int) major(statbuf->st_rdev)); 239 printf(pformat, (unsigned long int) major(statbuf->st_rdev));
271 break; 240 } else if (m == 'T') {
272 case 'T':
273 strncat(pformat, "lx", buf_len); 241 strncat(pformat, "lx", buf_len);
274 printf(pformat, (unsigned long int) minor(statbuf->st_rdev)); 242 printf(pformat, (unsigned long int) minor(statbuf->st_rdev));
275 break; 243 } else if (m == 's') {
276 case 's':
277 strncat(pformat, "ju", buf_len); 244 strncat(pformat, "ju", buf_len);
278 printf(pformat, (uintmax_t) (statbuf->st_size)); 245 printf(pformat, (uintmax_t) (statbuf->st_size));
279 break; 246 } else if (m == 'B') {
280 case 'B':
281 strncat(pformat, "lu", buf_len); 247 strncat(pformat, "lu", buf_len);
282 printf(pformat, (unsigned long int) 512); //ST_NBLOCKSIZE 248 printf(pformat, (unsigned long int) 512); //ST_NBLOCKSIZE
283 break; 249 } else if (m == 'b') {
284 case 'b':
285 strncat(pformat, "ju", buf_len); 250 strncat(pformat, "ju", buf_len);
286 printf(pformat, (uintmax_t) statbuf->st_blocks); 251 printf(pformat, (uintmax_t) statbuf->st_blocks);
287 break; 252 } else if (m == 'o') {
288 case 'o':
289 strncat(pformat, "lu", buf_len); 253 strncat(pformat, "lu", buf_len);
290 printf(pformat, (unsigned long int) statbuf->st_blksize); 254 printf(pformat, (unsigned long int) statbuf->st_blksize);
291 break; 255 } else if (m == 'x') {
292 case 'x':
293 strncat(pformat, "s", buf_len); 256 strncat(pformat, "s", buf_len);
294 printf(pformat, human_time(statbuf->st_atime)); 257 printf(pformat, human_time(statbuf->st_atime));
295 break; 258 } else if (m == 'X') {
296 case 'X':
297 strncat(pformat, TYPE_SIGNED(time_t) ? "ld" : "lu", buf_len); 259 strncat(pformat, TYPE_SIGNED(time_t) ? "ld" : "lu", buf_len);
298 printf(pformat, (unsigned long int) statbuf->st_atime); 260 printf(pformat, (unsigned long int) statbuf->st_atime);
299 break; 261 } else if (m == 'y') {
300 case 'y':
301 strncat(pformat, "s", buf_len); 262 strncat(pformat, "s", buf_len);
302 printf(pformat, human_time(statbuf->st_mtime)); 263 printf(pformat, human_time(statbuf->st_mtime));
303 break; 264 } else if (m == 'Y') {
304 case 'Y':
305 strncat(pformat, TYPE_SIGNED(time_t) ? "ld" : "lu", buf_len); 265 strncat(pformat, TYPE_SIGNED(time_t) ? "ld" : "lu", buf_len);
306 printf(pformat, (unsigned long int) statbuf->st_mtime); 266 printf(pformat, (unsigned long int) statbuf->st_mtime);
307 break; 267 } else if (m == 'z') {
308 case 'z':
309 strncat(pformat, "s", buf_len); 268 strncat(pformat, "s", buf_len);
310 printf(pformat, human_time(statbuf->st_ctime)); 269 printf(pformat, human_time(statbuf->st_ctime));
311 break; 270 } else if (m == 'Z') {
312 case 'Z':
313 strncat(pformat, TYPE_SIGNED(time_t) ? "ld" : "lu", buf_len); 271 strncat(pformat, TYPE_SIGNED(time_t) ? "ld" : "lu", buf_len);
314 printf(pformat, (unsigned long int) statbuf->st_ctime); 272 printf(pformat, (unsigned long int) statbuf->st_ctime);
315 break;
316#if ENABLE_SELINUX 273#if ENABLE_SELINUX
317 case 'C': 274 } else if (m == 'C' && (option_mask32 & OPT_SELINUX)) {
318 if (flags & OPT_SELINUX) { 275 strncat(pformat, "s", buf_len);
319 strncat(pformat, "s", buf_len); 276 printf(pformat, scontext);
320 printf(pformat, scontext);
321 }
322 break;
323#endif 277#endif
324 default: 278 } else {
325 strncat(pformat, "c", buf_len); 279 strncat(pformat, "c", buf_len);
326 printf(pformat, m); 280 printf(pformat, m);
327 break;
328 } 281 }
329} 282}
330 283
@@ -382,14 +335,14 @@ static void print_it(char const *masterformat, char const *filename,
382#endif 335#endif
383 336
384/* Stat the file system and print what we find. */ 337/* Stat the file system and print what we find. */
385static int do_statfs(char const *filename, char const *format) 338static bool do_statfs(char const *filename, char const *format)
386{ 339{
387 struct statfs statfsbuf; 340 struct statfs statfsbuf;
388
389#if ENABLE_SELINUX 341#if ENABLE_SELINUX
390 security_context_t scontext = NULL; 342 security_context_t scontext = NULL;
391 if (flags & OPT_SELINUX) { 343
392 if ((flags & OPT_DEREFERENCE ? lgetfilecon(filename, scontext): 344 if (option_mask32 & OPT_SELINUX) {
345 if ((option_mask32 & OPT_DEREFERENCE ? lgetfilecon(filename, scontext):
393 getfilecon(filename, scontext))< 0) { 346 getfilecon(filename, scontext))< 0) {
394 bb_perror_msg(filename); 347 bb_perror_msg(filename);
395 return 0; 348 return 0;
@@ -404,7 +357,7 @@ static int do_statfs(char const *filename, char const *format)
404#ifdef CONFIG_FEATURE_STAT_FORMAT 357#ifdef CONFIG_FEATURE_STAT_FORMAT
405 if (format == NULL) 358 if (format == NULL)
406#ifndef ENABLE_SELINUX 359#ifndef ENABLE_SELINUX
407 format = (flags & OPT_TERSE 360 format = (option_mask32 & OPT_TERSE
408 ? "%n %i %l %t %s %b %f %a %c %d\n" 361 ? "%n %i %l %t %s %b %f %a %c %d\n"
409 : " File: \"%n\"\n" 362 : " File: \"%n\"\n"
410 " ID: %-8i Namelen: %-7l Type: %T\n" 363 " ID: %-8i Namelen: %-7l Type: %T\n"
@@ -413,10 +366,10 @@ static int do_statfs(char const *filename, char const *format)
413 "Inodes: Total: %-10c Free: %d"); 366 "Inodes: Total: %-10c Free: %d");
414 print_it(format, filename, print_statfs, &statfsbuf USE_SELINUX(, scontext)); 367 print_it(format, filename, print_statfs, &statfsbuf USE_SELINUX(, scontext));
415#else 368#else
416 format = (flags & OPT_TERSE 369 format = (option_mask32 & OPT_TERSE
417 ? (flags & OPT_SELINUX ? "%n %i %l %t %s %b %f %a %c %d %C\n": 370 ? (option_mask32 & OPT_SELINUX ? "%n %i %l %t %s %b %f %a %c %d %C\n":
418 "%n %i %l %t %s %b %f %a %c %d\n") 371 "%n %i %l %t %s %b %f %a %c %d\n")
419 : (flags & OPT_SELINUX ? 372 : (option_mask32 & OPT_SELINUX ?
420 " File: \"%n\"\n" 373 " File: \"%n\"\n"
421 " ID: %-8i Namelen: %-7l Type: %T\n" 374 " ID: %-8i Namelen: %-7l Type: %T\n"
422 "Block size: %-10s\n" 375 "Block size: %-10s\n"
@@ -432,7 +385,7 @@ static int do_statfs(char const *filename, char const *format)
432 print_it(format, filename, print_statfs, &statfsbuf USE_SELINUX(, scontext)); 385 print_it(format, filename, print_statfs, &statfsbuf USE_SELINUX(, scontext));
433#endif /* SELINUX */ 386#endif /* SELINUX */
434#else /* FEATURE_STAT_FORMAT */ 387#else /* FEATURE_STAT_FORMAT */
435 format = (flags & OPT_TERSE 388 format = (option_mask32 & OPT_TERSE
436 ? "%s %llx %lu " 389 ? "%s %llx %lu "
437 : " File: \"%s\"\n" 390 : " File: \"%s\"\n"
438 " ID: %-8Lx Namelen: %-7lu "); 391 " ID: %-8Lx Namelen: %-7lu ");
@@ -441,13 +394,13 @@ static int do_statfs(char const *filename, char const *format)
441 statfsbuf.f_fsid, 394 statfsbuf.f_fsid,
442 statfsbuf.f_namelen); 395 statfsbuf.f_namelen);
443 396
444 if (flags & OPT_TERSE) 397 if (option_mask32 & OPT_TERSE)
445 printf("%lx ", (unsigned long int) (statfsbuf.f_type)); 398 printf("%lx ", (unsigned long int) (statfsbuf.f_type));
446 else 399 else
447 printf("Type: %s\n", human_fstype(statfsbuf.f_type)); 400 printf("Type: %s\n", human_fstype(statfsbuf.f_type));
448 401
449#if !ENABLE_SELINUX 402#if !ENABLE_SELINUX
450 format = (flags & OPT_TERSE 403 format = (option_mask32 & OPT_TERSE
451 ? "%lu %ld %ld %ld %ld %ld\n" 404 ? "%lu %ld %ld %ld %ld %ld\n"
452 : "Block size: %-10lu\n" 405 : "Block size: %-10lu\n"
453 "Blocks: Total: %-10jd Free: %-10jd Available: %jd\n" 406 "Blocks: Total: %-10jd Free: %-10jd Available: %jd\n"
@@ -460,10 +413,10 @@ static int do_statfs(char const *filename, char const *format)
460 (intmax_t) (statfsbuf.f_files), 413 (intmax_t) (statfsbuf.f_files),
461 (intmax_t) (statfsbuf.f_ffree)); 414 (intmax_t) (statfsbuf.f_ffree));
462#else 415#else
463 format = (flags & OPT_TERSE 416 format = (option_mask32 & OPT_TERSE
464 ? (flags & OPT_SELINUX ? "%lu %ld %ld %ld %ld %ld %C\n": 417 ? (option_mask32 & OPT_SELINUX ? "%lu %ld %ld %ld %ld %ld %C\n":
465 "%lu %ld %ld %ld %ld %ld\n") 418 "%lu %ld %ld %ld %ld %ld\n")
466 : (flags & OPT_SELINUX ? 419 : (option_mask32 & OPT_SELINUX ?
467 "Block size: %-10lu\n" 420 "Block size: %-10lu\n"
468 "Blocks: Total: %-10jd Free: %-10jd Available: %jd\n" 421 "Blocks: Total: %-10jd Free: %-10jd Available: %jd\n"
469 "Inodes: Total: %-10jd Free: %jd" 422 "Inodes: Total: %-10jd Free: %jd"
@@ -488,20 +441,21 @@ static int do_statfs(char const *filename, char const *format)
488} 441}
489 442
490/* stat the file and print what we find */ 443/* stat the file and print what we find */
491static int do_stat(char const *filename, char const *format) 444static bool do_stat(char const *filename, char const *format)
492{ 445{
493 struct stat statbuf; 446 struct stat statbuf;
494#if ENABLE_SELINUX 447#if ENABLE_SELINUX
495 security_context_t scontext = NULL; 448 security_context_t scontext = NULL;
496 if (flags & OPT_SELINUX) { 449
497 if ((flags & OPT_DEREFERENCE ? lgetfilecon(filename, scontext): 450 if (option_mask32 & OPT_SELINUX) {
451 if ((option_mask32 & OPT_DEREFERENCE ? lgetfilecon(filename, scontext):
498 getfilecon(filename, scontext))< 0) { 452 getfilecon(filename, scontext))< 0) {
499 bb_perror_msg (filename); 453 bb_perror_msg (filename);
500 return 0; 454 return 0;
501 } 455 }
502 } 456 }
503#endif 457#endif
504 if ((flags & OPT_DEREFERENCE ? stat : lstat) (filename, &statbuf) != 0) { 458 if ((option_mask32 & OPT_DEREFERENCE ? stat : lstat) (filename, &statbuf) != 0) {
505 bb_perror_msg("cannot stat '%s'", filename); 459 bb_perror_msg("cannot stat '%s'", filename);
506 return 0; 460 return 0;
507 } 461 }
@@ -509,7 +463,7 @@ static int do_stat(char const *filename, char const *format)
509#ifdef CONFIG_FEATURE_STAT_FORMAT 463#ifdef CONFIG_FEATURE_STAT_FORMAT
510 if (format == NULL) { 464 if (format == NULL) {
511#ifndef ENABLE_SELINUX 465#ifndef ENABLE_SELINUX
512 if (flags & OPT_TERSE) { 466 if (option_mask32 & OPT_TERSE) {
513 format = "%n %s %b %f %u %g %D %i %h %t %T %X %Y %Z %o"; 467 format = "%n %s %b %f %u %g %D %i %h %t %T %X %Y %Z %o";
514 } else { 468 } else {
515 if (S_ISBLK(statbuf.st_mode) || S_ISCHR(statbuf.st_mode)) { 469 if (S_ISBLK(statbuf.st_mode) || S_ISCHR(statbuf.st_mode)) {
@@ -530,13 +484,13 @@ static int do_stat(char const *filename, char const *format)
530 } 484 }
531 } 485 }
532#else 486#else
533 if (flags & OPT_TERSE) { 487 if (option_mask32 & OPT_TERSE) {
534 format = (flags & OPT_SELINUX ? 488 format = (option_mask32 & OPT_SELINUX ?
535 "%n %s %b %f %u %g %D %i %h %t %T %X %Y %Z %o %C\n": 489 "%n %s %b %f %u %g %D %i %h %t %T %X %Y %Z %o %C\n":
536 "%n %s %b %f %u %g %D %i %h %t %T %X %Y %Z %o\n"); 490 "%n %s %b %f %u %g %D %i %h %t %T %X %Y %Z %o\n");
537 } else { 491 } else {
538 if (S_ISBLK(statbuf.st_mode) || S_ISCHR(statbuf.st_mode)) { 492 if (S_ISBLK(statbuf.st_mode) || S_ISCHR(statbuf.st_mode)) {
539 format = (flags & OPT_SELINUX ? 493 format = (option_mask32 & OPT_SELINUX ?
540 " File: \"%N\"\n" 494 " File: \"%N\"\n"
541 " Size: %-10s\tBlocks: %-10b IO Block: %-6o %F\n" 495 " Size: %-10s\tBlocks: %-10b IO Block: %-6o %F\n"
542 "Device: %Dh/%dd\tInode: %-10i Links: %-5h" 496 "Device: %Dh/%dd\tInode: %-10i Links: %-5h"
@@ -551,7 +505,7 @@ static int do_stat(char const *filename, char const *format)
551 "Access: (%04a/%10.10A) Uid: (%5u/%8U) Gid: (%5g/%8G)\n" 505 "Access: (%04a/%10.10A) Uid: (%5u/%8U) Gid: (%5g/%8G)\n"
552 "Access: %x\n" "Modify: %y\n" "Change: %z\n"); 506 "Access: %x\n" "Modify: %y\n" "Change: %z\n");
553 } else { 507 } else {
554 format = (flags & OPT_SELINUX ? 508 format = (option_mask32 & OPT_SELINUX ?
555 " File: \"%N\"\n" 509 " File: \"%N\"\n"
556 " Size: %-10s\tBlocks: %-10b IO Block: %-6o %F\n" 510 " Size: %-10s\tBlocks: %-10b IO Block: %-6o %F\n"
557 "Device: %Dh/%dd\tInode: %-10i Links: %h\n" 511 "Device: %Dh/%dd\tInode: %-10i Links: %h\n"
@@ -569,7 +523,7 @@ static int do_stat(char const *filename, char const *format)
569 } 523 }
570 print_it(format, filename, print_stat, &statbuf USE_SELINUX(, scontext)); 524 print_it(format, filename, print_stat, &statbuf USE_SELINUX(, scontext));
571#else /* FEATURE_STAT_FORMAT */ 525#else /* FEATURE_STAT_FORMAT */
572 if (flags & OPT_TERSE) { 526 if (option_mask32 & OPT_TERSE) {
573 printf("%s %ju %ju %lx %lu %lu %jx %ju %lu %lx %lx %lu %lu %lu %lu" 527 printf("%s %ju %ju %lx %lu %lu %jx %ju %lu %lx %lx %lu %lu %lu %lu"
574 SKIP_SELINUX("\n"), 528 SKIP_SELINUX("\n"),
575 filename, 529 filename,
@@ -589,7 +543,7 @@ static int do_stat(char const *filename, char const *format)
589 (unsigned long int) statbuf.st_blksize 543 (unsigned long int) statbuf.st_blksize
590 ); 544 );
591#if ENABLE_SELINUX 545#if ENABLE_SELINUX
592 if (flags & OPT_SELINUX) 546 if (option_mask32 & OPT_SELINUX)
593 printf(" %lc\n", *scontext); 547 printf(" %lc\n", *scontext);
594 else 548 else
595 putchar('\n'); 549 putchar('\n');
@@ -649,23 +603,23 @@ static int do_stat(char const *filename, char const *format)
649int stat_main(int argc, char **argv); 603int stat_main(int argc, char **argv);
650int stat_main(int argc, char **argv) 604int stat_main(int argc, char **argv)
651{ 605{
652 int i;
653 char *format = NULL; 606 char *format = NULL;
607 int i;
654 int ok = 1; 608 int ok = 1;
655 int (*statfunc)(char const *, char const *) = do_stat; 609 bool (*statfunc)(char const *, char const *) = do_stat;
656 610
657 flags = getopt32(argc, argv, "ftL" 611 getopt32(argc, argv, "ftL"
658 USE_SELINUX("Z") 612 USE_SELINUX("Z")
659 USE_FEATURE_STAT_FORMAT("c:", &format) 613 USE_FEATURE_STAT_FORMAT("c:", &format)
660 ); 614 );
661 615
662 if (flags & 1) /* -f */ 616 if (option_mask32 & OPT_FILESYS) /* -f */
663 statfunc = do_statfs; 617 statfunc = do_statfs;
664 if (argc == optind) /* files */ 618 if (argc == optind) /* files */
665 bb_show_usage(); 619 bb_show_usage();
666 620
667#if ENABLE_SELINUX 621#if ENABLE_SELINUX
668 if (flags & OPT_SELINUX) { 622 if (option_mask32 & OPT_SELINUX) {
669 selinux_or_die(); 623 selinux_or_die();
670 } 624 }
671#endif /* ENABLE_SELINUX */ 625#endif /* ENABLE_SELINUX */