1 /* vi: set sw=4 ts=4: */
3 * stat -- display file or file system status
5 * Copyright (C) 2001, 2002, 2003, 2004, 2005 Free Software Foundation.
6 * Copyright (C) 2005 by Erik Andersen <andersen@codepoet.org>
7 * Copyright (C) 2005 by Mike Frysinger <vapier@gentoo.org>
8 * Copyright (C) 2006 by Yoshinori Sato <ysato@users.sourceforge.jp>
10 * Written by Michael Meskes
11 * Taken from coreutils and turned into a busybox applet by Mike Frysinger
13 * Licensed under GPLv2 or later, see file LICENSE in this source tree.
16 //usage:#define stat_trivial_usage
17 //usage: "[OPTIONS] FILE..."
18 //usage:#define stat_full_usage "\n\n"
19 //usage: "Display file (default) or filesystem status\n"
21 //usage: IF_FEATURE_STAT_FORMAT(
22 //usage: "\n -c fmt Use the specified format"
24 //usage: "\n -f Display filesystem status"
25 //usage: "\n -L Follow links"
26 //usage: "\n -t Display info in terse form"
28 //usage: "\n -Z Print security context"
30 //usage: IF_FEATURE_STAT_FORMAT(
31 //usage: "\n\nValid format sequences for files:\n"
32 //usage: " %a Access rights in octal\n"
33 //usage: " %A Access rights in human readable form\n"
34 //usage: " %b Number of blocks allocated (see %B)\n"
35 //usage: " %B The size in bytes of each block reported by %b\n"
36 //usage: " %d Device number in decimal\n"
37 //usage: " %D Device number in hex\n"
38 //usage: " %f Raw mode in hex\n"
39 //usage: " %F File type\n"
40 //usage: " %g Group ID of owner\n"
41 //usage: " %G Group name of owner\n"
42 //usage: " %h Number of hard links\n"
43 //usage: " %i Inode number\n"
44 //usage: " %n File name\n"
45 //usage: " %N File name, with -> TARGET if symlink\n"
46 //usage: " %o I/O block size\n"
47 //usage: " %s Total size, in bytes\n"
48 //usage: " %t Major device type in hex\n"
49 //usage: " %T Minor device type in hex\n"
50 //usage: " %u User ID of owner\n"
51 //usage: " %U User name of owner\n"
52 //usage: " %x Time of last access\n"
53 //usage: " %X Time of last access as seconds since Epoch\n"
54 //usage: " %y Time of last modification\n"
55 //usage: " %Y Time of last modification as seconds since Epoch\n"
56 //usage: " %z Time of last change\n"
57 //usage: " %Z Time of last change as seconds since Epoch\n"
58 //usage: "\nValid format sequences for file systems:\n"
59 //usage: " %a Free blocks available to non-superuser\n"
60 //usage: " %b Total data blocks in file system\n"
61 //usage: " %c Total file nodes in file system\n"
62 //usage: " %d Free file nodes in file system\n"
63 //usage: " %f Free blocks in file system\n"
65 //usage: " %C Security context in selinux\n"
67 //usage: " %i File System ID in hex\n"
68 //usage: " %l Maximum length of filenames\n"
69 //usage: " %n File name\n"
70 //usage: " %s Block size (for faster transfer)\n"
71 //usage: " %S Fundamental block size (for block counts)\n"
72 //usage: " %t Type in hex\n"
73 //usage: " %T Type in human readable form"
78 #define OPT_FILESYS (1 << 0)
79 #define OPT_TERSE (1 << 1)
80 #define OPT_DEREFERENCE (1 << 2)
81 #define OPT_SELINUX (1 << 3)
83 #if ENABLE_FEATURE_STAT_FORMAT
84 typedef bool (*statfunc_ptr)(const char *, const char *);
86 typedef bool (*statfunc_ptr)(const char *);
89 static const char *file_type(const struct stat *st)
91 /* See POSIX 1003.1-2001 XCU Table 4-8 lines 17093-17107
92 * for some of these formats.
93 * To keep diagnostics grammatical in English, the
94 * returned string must start with a consonant.
96 if (S_ISREG(st->st_mode)) return st->st_size == 0 ? "regular empty file" : "regular file";
97 if (S_ISDIR(st->st_mode)) return "directory";
98 if (S_ISBLK(st->st_mode)) return "block special file";
99 if (S_ISCHR(st->st_mode)) return "character special file";
100 if (S_ISFIFO(st->st_mode)) return "fifo";
101 if (S_ISLNK(st->st_mode)) return "symbolic link";
102 if (S_ISSOCK(st->st_mode)) return "socket";
103 if (S_TYPEISMQ(st)) return "message queue";
104 if (S_TYPEISSEM(st)) return "semaphore";
105 if (S_TYPEISSHM(st)) return "shared memory object";
107 if (S_TYPEISTMO(st)) return "typed memory object";
112 static const char *human_time(time_t t)
117 str[strlen(str)-1] = '\0';
120 /* coreutils 6.3 compat: */
122 /*static char buf[sizeof("YYYY-MM-DD HH:MM:SS.000000000")] ALIGN1;*/
123 #define buf bb_common_bufsiz1
125 strftime(buf, sizeof(buf), "%Y-%m-%d %H:%M:%S.000000000", localtime(&t));
130 /* Return the type of the specified file system.
131 * Some systems have statfvs.f_basetype[FSTYPSZ]. (AIX, HP-UX, and Solaris)
132 * Others have statfs.f_fstypename[MFSNAMELEN]. (NetBSD 1.5.2)
133 * Still others have neither and have to get by with f_type (Linux).
135 static const char *human_fstype(uint32_t f_type)
137 static const struct types {
139 const char *const fs;
142 { 0x1Cd1, "devpts" },
145 { 0xEF53, "ext2/ext3" },
146 { 0x3153464a, "jfs" },
147 { 0x58465342, "xfs" },
148 { 0xF995E849, "hpfs" },
153 { 0x138F, "minix (30 char.)" },
154 { 0x2468, "minix v2" },
155 { 0x2478, "minix v2 (30 char.)" },
158 { 0x564c, "novell" },
162 { 0x012FF7B4, "xenix" },
163 { 0x012FF7B5, "sysv4" },
164 { 0x012FF7B6, "sysv2" },
165 { 0x012FF7B7, "coh" },
166 { 0x00011954, "ufs" },
167 { 0x012FD16D, "xia" },
168 { 0x5346544e, "ntfs" },
169 { 0x1021994, "tmpfs" },
170 { 0x52654973, "reiserfs" },
171 { 0x28cd3d45, "cramfs" },
173 { 0x858458f6, "romfs" },
174 { 0x73717368, "squashfs" },
175 { 0x62656572, "sysfs" },
181 for (i = 0; humantypes[i].type; ++i)
182 if (humantypes[i].type == f_type)
184 return humantypes[i].fs;
187 /* "man statfs" says that statfsbuf->f_fsid is a mess */
188 /* coreutils treats it as an array of ints, most significant first */
189 static unsigned long long get_f_fsid(const struct statfs *statfsbuf)
191 const unsigned *p = (const void*) &statfsbuf->f_fsid;
192 unsigned sz = sizeof(statfsbuf->f_fsid) / sizeof(unsigned);
193 unsigned long long r = 0;
196 r = (r << (sizeof(unsigned)*8)) | *p++;
201 #if ENABLE_FEATURE_STAT_FORMAT
202 static void strcatc(char *str, char c)
204 int len = strlen(str);
209 static void printfs(char *pformat, const char *msg)
211 strcatc(pformat, 's');
212 printf(pformat, msg);
215 /* print statfs info */
216 static void FAST_FUNC print_statfs(char *pformat, const char m,
217 const char *const filename, const void *data
218 IF_SELINUX(, security_context_t scontext))
220 const struct statfs *statfsbuf = data;
222 printfs(pformat, filename);
223 } else if (m == 'i') {
224 strcat(pformat, "llx");
225 printf(pformat, get_f_fsid(statfsbuf));
226 } else if (m == 'l') {
227 strcat(pformat, "lu");
228 printf(pformat, (unsigned long) statfsbuf->f_namelen);
229 } else if (m == 't') {
230 strcat(pformat, "lx");
231 printf(pformat, (unsigned long) statfsbuf->f_type); /* no equiv */
232 } else if (m == 'T') {
233 printfs(pformat, human_fstype(statfsbuf->f_type));
234 } else if (m == 'b') {
235 strcat(pformat, "llu");
236 printf(pformat, (unsigned long long) statfsbuf->f_blocks);
237 } else if (m == 'f') {
238 strcat(pformat, "llu");
239 printf(pformat, (unsigned long long) statfsbuf->f_bfree);
240 } else if (m == 'a') {
241 strcat(pformat, "llu");
242 printf(pformat, (unsigned long long) statfsbuf->f_bavail);
243 } else if (m == 's' || m == 'S') {
244 strcat(pformat, "lu");
245 printf(pformat, (unsigned long) statfsbuf->f_bsize);
246 } else if (m == 'c') {
247 strcat(pformat, "llu");
248 printf(pformat, (unsigned long long) statfsbuf->f_files);
249 } else if (m == 'd') {
250 strcat(pformat, "llu");
251 printf(pformat, (unsigned long long) statfsbuf->f_ffree);
253 } else if (m == 'C' && (option_mask32 & OPT_SELINUX)) {
254 printfs(pformat, scontext);
257 strcatc(pformat, 'c');
262 /* print stat info */
263 static void FAST_FUNC print_stat(char *pformat, const char m,
264 const char *const filename, const void *data
265 IF_SELINUX(, security_context_t scontext))
267 #define TYPE_SIGNED(t) (! ((t) 0 < (t) -1))
268 struct stat *statbuf = (struct stat *) data;
269 struct passwd *pw_ent;
270 struct group *gw_ent;
273 printfs(pformat, filename);
274 } else if (m == 'N') {
275 strcatc(pformat, 's');
276 if (S_ISLNK(statbuf->st_mode)) {
277 char *linkname = xmalloc_readlink_or_warn(filename);
278 if (linkname == NULL)
280 printf("'%s' -> '%s'", filename, linkname);
283 printf(pformat, filename);
285 } else if (m == 'd') {
286 strcat(pformat, "llu");
287 printf(pformat, (unsigned long long) statbuf->st_dev);
288 } else if (m == 'D') {
289 strcat(pformat, "llx");
290 printf(pformat, (unsigned long long) statbuf->st_dev);
291 } else if (m == 'i') {
292 strcat(pformat, "llu");
293 printf(pformat, (unsigned long long) statbuf->st_ino);
294 } else if (m == 'a') {
295 strcat(pformat, "lo");
296 printf(pformat, (unsigned long) (statbuf->st_mode & (S_ISUID|S_ISGID|S_ISVTX|S_IRWXU|S_IRWXG|S_IRWXO)));
297 } else if (m == 'A') {
298 printfs(pformat, bb_mode_string(statbuf->st_mode));
299 } else if (m == 'f') {
300 strcat(pformat, "lx");
301 printf(pformat, (unsigned long) statbuf->st_mode);
302 } else if (m == 'F') {
303 printfs(pformat, file_type(statbuf));
304 } else if (m == 'h') {
305 strcat(pformat, "lu");
306 printf(pformat, (unsigned long) statbuf->st_nlink);
307 } else if (m == 'u') {
308 strcat(pformat, "lu");
309 printf(pformat, (unsigned long) statbuf->st_uid);
310 } else if (m == 'U') {
311 pw_ent = getpwuid(statbuf->st_uid);
312 printfs(pformat, (pw_ent != NULL) ? pw_ent->pw_name : "UNKNOWN");
313 } else if (m == 'g') {
314 strcat(pformat, "lu");
315 printf(pformat, (unsigned long) statbuf->st_gid);
316 } else if (m == 'G') {
317 gw_ent = getgrgid(statbuf->st_gid);
318 printfs(pformat, (gw_ent != NULL) ? gw_ent->gr_name : "UNKNOWN");
319 } else if (m == 't') {
320 strcat(pformat, "lx");
321 printf(pformat, (unsigned long) major(statbuf->st_rdev));
322 } else if (m == 'T') {
323 strcat(pformat, "lx");
324 printf(pformat, (unsigned long) minor(statbuf->st_rdev));
325 } else if (m == 's') {
326 strcat(pformat, "llu");
327 printf(pformat, (unsigned long long) statbuf->st_size);
328 } else if (m == 'B') {
329 strcat(pformat, "lu");
330 printf(pformat, (unsigned long) 512); //ST_NBLOCKSIZE
331 } else if (m == 'b') {
332 strcat(pformat, "llu");
333 printf(pformat, (unsigned long long) statbuf->st_blocks);
334 } else if (m == 'o') {
335 strcat(pformat, "lu");
336 printf(pformat, (unsigned long) statbuf->st_blksize);
337 } else if (m == 'x') {
338 printfs(pformat, human_time(statbuf->st_atime));
339 } else if (m == 'X') {
340 strcat(pformat, TYPE_SIGNED(time_t) ? "ld" : "lu");
341 /* note: (unsigned long) would be wrong:
342 * imagine (unsigned long64)int32 */
343 printf(pformat, (long) statbuf->st_atime);
344 } else if (m == 'y') {
345 printfs(pformat, human_time(statbuf->st_mtime));
346 } else if (m == 'Y') {
347 strcat(pformat, TYPE_SIGNED(time_t) ? "ld" : "lu");
348 printf(pformat, (long) statbuf->st_mtime);
349 } else if (m == 'z') {
350 printfs(pformat, human_time(statbuf->st_ctime));
351 } else if (m == 'Z') {
352 strcat(pformat, TYPE_SIGNED(time_t) ? "ld" : "lu");
353 printf(pformat, (long) statbuf->st_ctime);
355 } else if (m == 'C' && (option_mask32 & OPT_SELINUX)) {
356 printfs(pformat, scontext);
359 strcatc(pformat, 'c');
364 static void print_it(const char *masterformat,
365 const char *filename,
366 void FAST_FUNC (*print_func)(char*, char, const char*, const void* IF_SELINUX(, security_context_t scontext)),
368 IF_SELINUX(, security_context_t scontext))
370 /* Create a working copy of the format string */
371 char *format = xstrdup(masterformat);
372 /* Add 2 to accomodate our conversion of the stat '%s' format string
373 * to the printf '%llu' one. */
374 char *dest = xmalloc(strlen(format) + 2 + 1);
379 /* Each iteration finds next %spec,
380 * prints preceding string and handles found %spec
383 char *p = strchr(b, '%');
385 /* coreutils 6.3 always prints newline at the end */
386 /*fputs(b, stdout);*/
391 /* dest = "%<modifiers>" */
392 len = 1 + strspn(p + 1, "#-+.I 0123456789");
393 memcpy(dest, p, len);
396 /* print preceding string */
410 /* Completes "%<modifiers>" with specifier and printfs */
411 print_func(dest, *p, filename, data IF_SELINUX(,scontext));
419 #endif /* FEATURE_STAT_FORMAT */
421 /* Stat the file system and print what we find. */
422 #if !ENABLE_FEATURE_STAT_FORMAT
423 #define do_statfs(filename, format) do_statfs(filename)
425 static bool do_statfs(const char *filename, const char *format)
427 struct statfs statfsbuf;
428 #if !ENABLE_FEATURE_STAT_FORMAT
432 security_context_t scontext = NULL;
434 if (option_mask32 & OPT_SELINUX) {
435 if ((option_mask32 & OPT_DEREFERENCE
436 ? lgetfilecon(filename, &scontext)
437 : getfilecon(filename, &scontext)
440 bb_perror_msg(filename);
445 if (statfs(filename, &statfsbuf) != 0) {
446 bb_perror_msg("can't read file system information for '%s'", filename);
450 #if ENABLE_FEATURE_STAT_FORMAT
451 if (format == NULL) {
453 format = (option_mask32 & OPT_TERSE
454 ? "%n %i %l %t %s %b %f %a %c %d\n"
456 " ID: %-8i Namelen: %-7l Type: %T\n"
457 "Block size: %-10s\n"
458 "Blocks: Total: %-10b Free: %-10f Available: %a\n"
459 "Inodes: Total: %-10c Free: %d");
461 format = (option_mask32 & OPT_TERSE
462 ? (option_mask32 & OPT_SELINUX ? "%n %i %l %t %s %b %f %a %c %d %C\n":
463 "%n %i %l %t %s %b %f %a %c %d\n")
464 : (option_mask32 & OPT_SELINUX ?
466 " ID: %-8i Namelen: %-7l Type: %T\n"
467 "Block size: %-10s\n"
468 "Blocks: Total: %-10b Free: %-10f Available: %a\n"
469 "Inodes: Total: %-10c Free: %d"
472 " ID: %-8i Namelen: %-7l Type: %T\n"
473 "Block size: %-10s\n"
474 "Blocks: Total: %-10b Free: %-10f Available: %a\n"
475 "Inodes: Total: %-10c Free: %d\n")
477 # endif /* SELINUX */
479 print_it(format, filename, print_statfs, &statfsbuf IF_SELINUX(, scontext));
480 #else /* FEATURE_STAT_FORMAT */
481 format = (option_mask32 & OPT_TERSE
484 " ID: %-8llx Namelen: %-7lu ");
487 get_f_fsid(&statfsbuf),
488 statfsbuf.f_namelen);
490 if (option_mask32 & OPT_TERSE)
491 printf("%lx ", (unsigned long) statfsbuf.f_type);
493 printf("Type: %s\n", human_fstype(statfsbuf.f_type));
496 format = (option_mask32 & OPT_TERSE
497 ? "%lu %llu %llu %llu %llu %llu\n"
498 : "Block size: %-10lu\n"
499 "Blocks: Total: %-10llu Free: %-10llu Available: %llu\n"
500 "Inodes: Total: %-10llu Free: %llu\n");
502 (unsigned long) statfsbuf.f_bsize,
503 (unsigned long long) statfsbuf.f_blocks,
504 (unsigned long long) statfsbuf.f_bfree,
505 (unsigned long long) statfsbuf.f_bavail,
506 (unsigned long long) statfsbuf.f_files,
507 (unsigned long long) statfsbuf.f_ffree);
509 format = (option_mask32 & OPT_TERSE
510 ? (option_mask32 & OPT_SELINUX ? "%lu %llu %llu %llu %llu %llu %C\n" : "%lu %llu %llu %llu %llu %llu\n")
511 : (option_mask32 & OPT_SELINUX
512 ? "Block size: %-10lu\n"
513 "Blocks: Total: %-10llu Free: %-10llu Available: %llu\n"
514 "Inodes: Total: %-10llu Free: %llu"
516 : "Block size: %-10lu\n"
517 "Blocks: Total: %-10llu Free: %-10llu Available: %llu\n"
518 "Inodes: Total: %-10llu Free: %llu\n"
522 (unsigned long) statfsbuf.f_bsize,
523 (unsigned long long) statfsbuf.f_blocks,
524 (unsigned long long) statfsbuf.f_bfree,
525 (unsigned long long) statfsbuf.f_bavail,
526 (unsigned long long) statfsbuf.f_files,
527 (unsigned long long) statfsbuf.f_ffree,
533 #endif /* FEATURE_STAT_FORMAT */
537 /* stat the file and print what we find */
538 #if !ENABLE_FEATURE_STAT_FORMAT
539 #define do_stat(filename, format) do_stat(filename)
541 static bool do_stat(const char *filename, const char *format)
545 security_context_t scontext = NULL;
547 if (option_mask32 & OPT_SELINUX) {
548 if ((option_mask32 & OPT_DEREFERENCE
549 ? lgetfilecon(filename, &scontext)
550 : getfilecon(filename, &scontext)
553 bb_perror_msg(filename);
558 if ((option_mask32 & OPT_DEREFERENCE ? stat : lstat) (filename, &statbuf) != 0) {
559 bb_perror_msg("can't stat '%s'", filename);
563 #if ENABLE_FEATURE_STAT_FORMAT
564 if (format == NULL) {
566 if (option_mask32 & OPT_TERSE) {
567 format = "%n %s %b %f %u %g %D %i %h %t %T %X %Y %Z %o";
569 if (S_ISBLK(statbuf.st_mode) || S_ISCHR(statbuf.st_mode)) {
572 " Size: %-10s\tBlocks: %-10b IO Block: %-6o %F\n"
573 "Device: %Dh/%dd\tInode: %-10i Links: %-5h"
574 " Device type: %t,%T\n"
575 "Access: (%04a/%10.10A) Uid: (%5u/%8U) Gid: (%5g/%8G)\n"
576 "Access: %x\n" "Modify: %y\n" "Change: %z\n";
580 " Size: %-10s\tBlocks: %-10b IO Block: %-6o %F\n"
581 "Device: %Dh/%dd\tInode: %-10i Links: %h\n"
582 "Access: (%04a/%10.10A) Uid: (%5u/%8U) Gid: (%5g/%8G)\n"
583 "Access: %x\n" "Modify: %y\n" "Change: %z\n";
587 if (option_mask32 & OPT_TERSE) {
588 format = (option_mask32 & OPT_SELINUX ?
589 "%n %s %b %f %u %g %D %i %h %t %T %X %Y %Z %o %C\n":
590 "%n %s %b %f %u %g %D %i %h %t %T %X %Y %Z %o\n");
592 if (S_ISBLK(statbuf.st_mode) || S_ISCHR(statbuf.st_mode)) {
593 format = (option_mask32 & OPT_SELINUX ?
595 " Size: %-10s\tBlocks: %-10b IO Block: %-6o %F\n"
596 "Device: %Dh/%dd\tInode: %-10i Links: %-5h"
597 " Device type: %t,%T\n"
598 "Access: (%04a/%10.10A) Uid: (%5u/%8U) Gid: (%5g/%8G)\n"
600 "Access: %x\n" "Modify: %y\n" "Change: %z\n":
602 " Size: %-10s\tBlocks: %-10b IO Block: %-6o %F\n"
603 "Device: %Dh/%dd\tInode: %-10i Links: %-5h"
604 " Device type: %t,%T\n"
605 "Access: (%04a/%10.10A) Uid: (%5u/%8U) Gid: (%5g/%8G)\n"
606 "Access: %x\n" "Modify: %y\n" "Change: %z\n");
608 format = (option_mask32 & OPT_SELINUX ?
610 " Size: %-10s\tBlocks: %-10b IO Block: %-6o %F\n"
611 "Device: %Dh/%dd\tInode: %-10i Links: %h\n"
612 "Access: (%04a/%10.10A) Uid: (%5u/%8U) Gid: (%5g/%8G)\n"
614 "Access: %x\n" "Modify: %y\n" "Change: %z\n":
616 " Size: %-10s\tBlocks: %-10b IO Block: %-6o %F\n"
617 "Device: %Dh/%dd\tInode: %-10i Links: %h\n"
618 "Access: (%04a/%10.10A) Uid: (%5u/%8U) Gid: (%5g/%8G)\n"
619 "Access: %x\n" "Modify: %y\n" "Change: %z\n");
624 print_it(format, filename, print_stat, &statbuf IF_SELINUX(, scontext));
625 #else /* FEATURE_STAT_FORMAT */
626 if (option_mask32 & OPT_TERSE) {
627 printf("%s %llu %llu %lx %lu %lu %llx %llu %lu %lx %lx %lu %lu %lu %lu"
628 IF_NOT_SELINUX("\n"),
630 (unsigned long long) statbuf.st_size,
631 (unsigned long long) statbuf.st_blocks,
632 (unsigned long) statbuf.st_mode,
633 (unsigned long) statbuf.st_uid,
634 (unsigned long) statbuf.st_gid,
635 (unsigned long long) statbuf.st_dev,
636 (unsigned long long) statbuf.st_ino,
637 (unsigned long) statbuf.st_nlink,
638 (unsigned long) major(statbuf.st_rdev),
639 (unsigned long) minor(statbuf.st_rdev),
640 (unsigned long) statbuf.st_atime,
641 (unsigned long) statbuf.st_mtime,
642 (unsigned long) statbuf.st_ctime,
643 (unsigned long) statbuf.st_blksize
646 if (option_mask32 & OPT_SELINUX)
647 printf(" %lc\n", *scontext);
652 char *linkname = NULL;
653 struct passwd *pw_ent;
654 struct group *gw_ent;
656 gw_ent = getgrgid(statbuf.st_gid);
657 pw_ent = getpwuid(statbuf.st_uid);
659 if (S_ISLNK(statbuf.st_mode))
660 linkname = xmalloc_readlink_or_warn(filename);
662 printf(" File: '%s' -> '%s'\n", filename, linkname);
665 printf(" File: '%s'\n", filename);
668 printf(" Size: %-10llu\tBlocks: %-10llu IO Block: %-6lu %s\n"
669 "Device: %llxh/%llud\tInode: %-10llu Links: %-5lu",
670 (unsigned long long) statbuf.st_size,
671 (unsigned long long) statbuf.st_blocks,
672 (unsigned long) statbuf.st_blksize,
674 (unsigned long long) statbuf.st_dev,
675 (unsigned long long) statbuf.st_dev,
676 (unsigned long long) statbuf.st_ino,
677 (unsigned long) statbuf.st_nlink);
678 if (S_ISBLK(statbuf.st_mode) || S_ISCHR(statbuf.st_mode))
679 printf(" Device type: %lx,%lx\n",
680 (unsigned long) major(statbuf.st_rdev),
681 (unsigned long) minor(statbuf.st_rdev));
684 printf("Access: (%04lo/%10.10s) Uid: (%5lu/%8s) Gid: (%5lu/%8s)\n",
685 (unsigned long) (statbuf.st_mode & (S_ISUID|S_ISGID|S_ISVTX|S_IRWXU|S_IRWXG|S_IRWXO)),
686 bb_mode_string(statbuf.st_mode),
687 (unsigned long) statbuf.st_uid,
688 (pw_ent != NULL) ? pw_ent->pw_name : "UNKNOWN",
689 (unsigned long) statbuf.st_gid,
690 (gw_ent != NULL) ? gw_ent->gr_name : "UNKNOWN");
692 printf(" S_Context: %lc\n", *scontext);
694 printf("Access: %s\n", human_time(statbuf.st_atime));
695 printf("Modify: %s\n", human_time(statbuf.st_mtime));
696 printf("Change: %s\n", human_time(statbuf.st_ctime));
698 #endif /* FEATURE_STAT_FORMAT */
702 int stat_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
703 int stat_main(int argc UNUSED_PARAM, char **argv)
705 IF_FEATURE_STAT_FORMAT(char *format = NULL;)
709 statfunc_ptr statfunc = do_stat;
711 opt_complementary = "-1"; /* min one arg */
712 opts = getopt32(argv, "ftL"
714 IF_FEATURE_STAT_FORMAT("c:", &format)
716 if (opts & OPT_FILESYS) /* -f */
717 statfunc = do_statfs;
719 if (opts & OPT_SELINUX) {
725 for (i = 0; argv[i]; ++i)
726 ok &= statfunc(argv[i] IF_FEATURE_STAT_FORMAT(, format));
728 return (ok ? EXIT_SUCCESS : EXIT_FAILURE);