blob: 5996268ef582843d76d74eb3f2f148e22458c675 [file] [log] [blame]
"Robert P. J. Day"63fc1a92006-07-02 19:47:05 +00001/* vi: set sw=4 ts=4: */
Mike Frysinger9b5f71e2005-04-23 06:26:38 +00002/*
3 * stat -- display file or file system status
4 *
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>
Denis Vlasenko49622d72007-03-10 16:58:49 +00008 * Copyright (C) 2006 by Yoshinori Sato <ysato@users.sourceforge.jp>
Mike Frysinger9b5f71e2005-04-23 06:26:38 +00009 *
10 * Written by Michael Meskes
11 * Taken from coreutils and turned into a busybox applet by Mike Frysinger
12 *
Bernhard Reutner-Fischere11a01c2006-04-05 17:19:37 +000013 * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
Mike Frysinger9b5f71e2005-04-23 06:26:38 +000014 */
15
Denis Vlasenkob6adbf12007-05-26 19:00:18 +000016#include "libbb.h"
Mike Frysinger9b5f71e2005-04-23 06:26:38 +000017
18/* vars to control behavior */
Denis Vlasenko91e52032007-10-05 20:31:23 +000019#define OPT_FILESYS (1 << 0)
20#define OPT_TERSE (1 << 1)
21#define OPT_DEREFERENCE (1 << 2)
22#define OPT_SELINUX (1 << 3)
Mike Frysinger9b5f71e2005-04-23 06:26:38 +000023
Denis Vlasenko91e52032007-10-05 20:31:23 +000024static const char *file_type(const struct stat *st)
Mike Frysinger9b5f71e2005-04-23 06:26:38 +000025{
Tim Rikerc1ef7bd2006-01-25 00:08:53 +000026 /* See POSIX 1003.1-2001 XCU Table 4-8 lines 17093-17107
Mike Frysinger9b5f71e2005-04-23 06:26:38 +000027 * for some of these formats.
Tim Rikerc1ef7bd2006-01-25 00:08:53 +000028 * To keep diagnostics grammatical in English, the
Mike Frysinger9b5f71e2005-04-23 06:26:38 +000029 * returned string must start with a consonant.
30 */
31 if (S_ISREG(st->st_mode)) return st->st_size == 0 ? "regular empty file" : "regular file";
32 if (S_ISDIR(st->st_mode)) return "directory";
33 if (S_ISBLK(st->st_mode)) return "block special file";
34 if (S_ISCHR(st->st_mode)) return "character special file";
35 if (S_ISFIFO(st->st_mode)) return "fifo";
36 if (S_ISLNK(st->st_mode)) return "symbolic link";
37 if (S_ISSOCK(st->st_mode)) return "socket";
38 if (S_TYPEISMQ(st)) return "message queue";
39 if (S_TYPEISSEM(st)) return "semaphore";
40 if (S_TYPEISSHM(st)) return "shared memory object";
41#ifdef S_TYPEISTMO
42 if (S_TYPEISTMO(st)) return "typed memory object";
43#endif
44 return "weird file";
45}
46
Denis Vlasenko91e52032007-10-05 20:31:23 +000047static const char *human_time(time_t t)
Mike Frysinger9b5f71e2005-04-23 06:26:38 +000048{
Denis Vlasenko5d148e22006-11-21 00:12:09 +000049 /* Old
Mike Frysinger9b5f71e2005-04-23 06:26:38 +000050 static char *str;
51 str = ctime(&t);
52 str[strlen(str)-1] = '\0';
53 return str;
Denis Vlasenko5d148e22006-11-21 00:12:09 +000054 */
55 /* coreutils 6.3 compat: */
Bernhard Reutner-Fischer0e6ab012007-04-04 13:58:33 +000056
Denis Vlasenko91e52032007-10-05 20:31:23 +000057 /*static char buf[sizeof("YYYY-MM-DD HH:MM:SS.000000000")] ALIGN1;*/
58#define buf bb_common_bufsiz1
59
Denis Vlasenko5d148e22006-11-21 00:12:09 +000060 strftime(buf, sizeof(buf), "%Y-%m-%d %H:%M:%S.000000000", localtime(&t));
61 return buf;
Denis Vlasenko91e52032007-10-05 20:31:23 +000062#undef buf
Mike Frysinger9b5f71e2005-04-23 06:26:38 +000063}
64
65/* Return the type of the specified file system.
66 * Some systems have statfvs.f_basetype[FSTYPSZ]. (AIX, HP-UX, and Solaris)
67 * Others have statfs.f_fstypename[MFSNAMELEN]. (NetBSD 1.5.2)
68 * Still others have neither and have to get by with f_type (Linux).
69 */
Denis Vlasenko91e52032007-10-05 20:31:23 +000070static const char *human_fstype(uint32_t f_type)
Mike Frysinger9b5f71e2005-04-23 06:26:38 +000071{
Denis Vlasenko240a1cf2007-04-08 16:07:02 +000072 static const struct types {
Denis Vlasenko91e52032007-10-05 20:31:23 +000073 uint32_t type;
Denis Vlasenko6ca409e2007-08-12 20:58:27 +000074 const char *const fs;
Mike Frysinger408ae212005-04-24 04:11:44 +000075 } humantypes[] = {
76 { 0xADFF, "affs" },
77 { 0x1Cd1, "devpts" },
78 { 0x137D, "ext" },
79 { 0xEF51, "ext2" },
80 { 0xEF53, "ext2/ext3" },
81 { 0x3153464a, "jfs" },
82 { 0x58465342, "xfs" },
83 { 0xF995E849, "hpfs" },
84 { 0x9660, "isofs" },
85 { 0x4000, "isofs" },
86 { 0x4004, "isofs" },
87 { 0x137F, "minix" },
88 { 0x138F, "minix (30 char.)" },
89 { 0x2468, "minix v2" },
90 { 0x2478, "minix v2 (30 char.)" },
91 { 0x4d44, "msdos" },
92 { 0x4006, "fat" },
93 { 0x564c, "novell" },
94 { 0x6969, "nfs" },
95 { 0x9fa0, "proc" },
96 { 0x517B, "smb" },
97 { 0x012FF7B4, "xenix" },
98 { 0x012FF7B5, "sysv4" },
99 { 0x012FF7B6, "sysv2" },
100 { 0x012FF7B7, "coh" },
101 { 0x00011954, "ufs" },
102 { 0x012FD16D, "xia" },
103 { 0x5346544e, "ntfs" },
104 { 0x1021994, "tmpfs" },
105 { 0x52654973, "reiserfs" },
106 { 0x28cd3d45, "cramfs" },
107 { 0x7275, "romfs" },
108 { 0x858458f6, "romfs" },
109 { 0x73717368, "squashfs" },
110 { 0x62656572, "sysfs" },
Rob Landley0a7c8ef2006-02-22 17:01:00 +0000111 { 0, "UNKNOWN" }
Mike Frysinger408ae212005-04-24 04:11:44 +0000112 };
Denis Vlasenko91e52032007-10-05 20:31:23 +0000113
114 int i;
115
Denis Vlasenko240a1cf2007-04-08 16:07:02 +0000116 for (i = 0; humantypes[i].type; ++i)
Mike Frysinger408ae212005-04-24 04:11:44 +0000117 if (humantypes[i].type == f_type)
Rob Landley0a7c8ef2006-02-22 17:01:00 +0000118 break;
Mike Frysinger408ae212005-04-24 04:11:44 +0000119 return humantypes[i].fs;
Mike Frysinger9b5f71e2005-04-23 06:26:38 +0000120}
121
Denis Vlasenko55761362007-10-16 22:53:05 +0000122#if ENABLE_FEATURE_STAT_FORMAT
Denis Vlasenko91e52032007-10-05 20:31:23 +0000123static void strcatc(char *str, char c)
124{
125 int len = strlen(str);
126 str[len++] = c;
127 str[len] = '\0';
128}
129
130static void printfs(char *pformat, const char *msg)
131{
132 strcatc(pformat, 's');
133 printf(pformat, msg);
134}
135
Mike Frysinger9b5f71e2005-04-23 06:26:38 +0000136/* print statfs info */
Denis Vlasenko91e52032007-10-05 20:31:23 +0000137static void print_statfs(char *pformat, const char m,
138 const char *const filename, const void *data
139 USE_SELINUX(, security_context_t scontext))
Mike Frysinger9b5f71e2005-04-23 06:26:38 +0000140{
Denis Vlasenko91e52032007-10-05 20:31:23 +0000141 const struct statfs *statfsbuf = data;
Bernhard Reutner-Fischer0e6ab012007-04-04 13:58:33 +0000142 if (m == 'n') {
Denis Vlasenko91e52032007-10-05 20:31:23 +0000143 printfs(pformat, filename);
Bernhard Reutner-Fischer0e6ab012007-04-04 13:58:33 +0000144 } else if (m == 'i') {
Denis Vlasenko91e52032007-10-05 20:31:23 +0000145 strcat(pformat, "Lx");
Mike Frysinger9b5f71e2005-04-23 06:26:38 +0000146 printf(pformat, statfsbuf->f_fsid);
Bernhard Reutner-Fischer0e6ab012007-04-04 13:58:33 +0000147 } else if (m == 'l') {
Denis Vlasenko91e52032007-10-05 20:31:23 +0000148 strcat(pformat, "lu");
Mike Frysinger9b5f71e2005-04-23 06:26:38 +0000149 printf(pformat, statfsbuf->f_namelen);
Bernhard Reutner-Fischer0e6ab012007-04-04 13:58:33 +0000150 } else if (m == 't') {
Denis Vlasenko91e52032007-10-05 20:31:23 +0000151 strcat(pformat, "lx");
Denis Vlasenko87468852007-04-13 23:22:00 +0000152 printf(pformat, (unsigned long) (statfsbuf->f_type)); /* no equiv */
Bernhard Reutner-Fischer0e6ab012007-04-04 13:58:33 +0000153 } else if (m == 'T') {
Denis Vlasenko91e52032007-10-05 20:31:23 +0000154 printfs(pformat, human_fstype(statfsbuf->f_type));
Bernhard Reutner-Fischer0e6ab012007-04-04 13:58:33 +0000155 } else if (m == 'b') {
Denis Vlasenko91e52032007-10-05 20:31:23 +0000156 strcat(pformat, "jd");
Mike Frysinger9b5f71e2005-04-23 06:26:38 +0000157 printf(pformat, (intmax_t) (statfsbuf->f_blocks));
Bernhard Reutner-Fischer0e6ab012007-04-04 13:58:33 +0000158 } else if (m == 'f') {
Denis Vlasenko91e52032007-10-05 20:31:23 +0000159 strcat(pformat, "jd");
Mike Frysinger9b5f71e2005-04-23 06:26:38 +0000160 printf(pformat, (intmax_t) (statfsbuf->f_bfree));
Bernhard Reutner-Fischer0e6ab012007-04-04 13:58:33 +0000161 } else if (m == 'a') {
Denis Vlasenko91e52032007-10-05 20:31:23 +0000162 strcat(pformat, "jd");
Mike Frysinger9b5f71e2005-04-23 06:26:38 +0000163 printf(pformat, (intmax_t) (statfsbuf->f_bavail));
Bernhard Reutner-Fischer0e6ab012007-04-04 13:58:33 +0000164 } else if (m == 's' || m == 'S') {
Denis Vlasenko91e52032007-10-05 20:31:23 +0000165 strcat(pformat, "lu");
Denis Vlasenko87468852007-04-13 23:22:00 +0000166 printf(pformat, (unsigned long) (statfsbuf->f_bsize));
Bernhard Reutner-Fischer0e6ab012007-04-04 13:58:33 +0000167 } else if (m == 'c') {
Denis Vlasenko91e52032007-10-05 20:31:23 +0000168 strcat(pformat, "jd");
Mike Frysinger9b5f71e2005-04-23 06:26:38 +0000169 printf(pformat, (intmax_t) (statfsbuf->f_files));
Bernhard Reutner-Fischer0e6ab012007-04-04 13:58:33 +0000170 } else if (m == 'd') {
Denis Vlasenko91e52032007-10-05 20:31:23 +0000171 strcat(pformat, "jd");
Mike Frysinger9b5f71e2005-04-23 06:26:38 +0000172 printf(pformat, (intmax_t) (statfsbuf->f_ffree));
Denis Vlasenko49622d72007-03-10 16:58:49 +0000173#if ENABLE_SELINUX
Bernhard Reutner-Fischer0e6ab012007-04-04 13:58:33 +0000174 } else if (m == 'C' && (option_mask32 & OPT_SELINUX)) {
Denis Vlasenko91e52032007-10-05 20:31:23 +0000175 printfs(pformat, scontext);
Denis Vlasenko49622d72007-03-10 16:58:49 +0000176#endif
Bernhard Reutner-Fischer0e6ab012007-04-04 13:58:33 +0000177 } else {
Denis Vlasenko91e52032007-10-05 20:31:23 +0000178 strcatc(pformat, 'c');
Mike Frysinger9b5f71e2005-04-23 06:26:38 +0000179 printf(pformat, m);
Mike Frysinger9b5f71e2005-04-23 06:26:38 +0000180 }
181}
182
183/* print stat info */
Denis Vlasenko91e52032007-10-05 20:31:23 +0000184static void print_stat(char *pformat, const char m,
185 const char *const filename, const void *data
186 USE_SELINUX(, security_context_t scontext))
Mike Frysinger9b5f71e2005-04-23 06:26:38 +0000187{
188#define TYPE_SIGNED(t) (! ((t) 0 < (t) -1))
189 struct stat *statbuf = (struct stat *) data;
190 struct passwd *pw_ent;
191 struct group *gw_ent;
192
Bernhard Reutner-Fischer0e6ab012007-04-04 13:58:33 +0000193 if (m == 'n') {
Denis Vlasenko91e52032007-10-05 20:31:23 +0000194 printfs(pformat, filename);
Bernhard Reutner-Fischer0e6ab012007-04-04 13:58:33 +0000195 } else if (m == 'N') {
Denis Vlasenko91e52032007-10-05 20:31:23 +0000196 strcatc(pformat, 's');
Mike Frysinger9b5f71e2005-04-23 06:26:38 +0000197 if (S_ISLNK(statbuf->st_mode)) {
Denis Vlasenko6ca04442007-02-11 16:19:28 +0000198 char *linkname = xmalloc_readlink_or_warn(filename);
Denis Vlasenko91e52032007-10-05 20:31:23 +0000199 if (linkname == NULL)
Mike Frysinger9b5f71e2005-04-23 06:26:38 +0000200 return;
Mike Frysinger9b5f71e2005-04-23 06:26:38 +0000201 /*printf("\"%s\" -> \"%s\"", filename, linkname); */
202 printf(pformat, filename);
203 printf(" -> ");
204 printf(pformat, linkname);
Denis Vlasenko91e52032007-10-05 20:31:23 +0000205 free(linkname);
Mike Frysinger9b5f71e2005-04-23 06:26:38 +0000206 } else {
207 printf(pformat, filename);
208 }
Bernhard Reutner-Fischer0e6ab012007-04-04 13:58:33 +0000209 } else if (m == 'd') {
Denis Vlasenko91e52032007-10-05 20:31:23 +0000210 strcat(pformat, "ju");
Mike Frysinger9b5f71e2005-04-23 06:26:38 +0000211 printf(pformat, (uintmax_t) statbuf->st_dev);
Bernhard Reutner-Fischer0e6ab012007-04-04 13:58:33 +0000212 } else if (m == 'D') {
Denis Vlasenko91e52032007-10-05 20:31:23 +0000213 strcat(pformat, "jx");
Mike Frysinger9b5f71e2005-04-23 06:26:38 +0000214 printf(pformat, (uintmax_t) statbuf->st_dev);
Bernhard Reutner-Fischer0e6ab012007-04-04 13:58:33 +0000215 } else if (m == 'i') {
Denis Vlasenko91e52032007-10-05 20:31:23 +0000216 strcat(pformat, "ju");
Mike Frysinger9b5f71e2005-04-23 06:26:38 +0000217 printf(pformat, (uintmax_t) statbuf->st_ino);
Bernhard Reutner-Fischer0e6ab012007-04-04 13:58:33 +0000218 } else if (m == 'a') {
Denis Vlasenko91e52032007-10-05 20:31:23 +0000219 strcat(pformat, "lo");
Denis Vlasenko87468852007-04-13 23:22:00 +0000220 printf(pformat, (unsigned long) (statbuf->st_mode & (S_ISUID|S_ISGID|S_ISVTX|S_IRWXU|S_IRWXG|S_IRWXO)));
Bernhard Reutner-Fischer0e6ab012007-04-04 13:58:33 +0000221 } else if (m == 'A') {
Denis Vlasenko91e52032007-10-05 20:31:23 +0000222 printfs(pformat, bb_mode_string(statbuf->st_mode));
Bernhard Reutner-Fischer0e6ab012007-04-04 13:58:33 +0000223 } else if (m == 'f') {
Denis Vlasenko91e52032007-10-05 20:31:23 +0000224 strcat(pformat, "lx");
Denis Vlasenko87468852007-04-13 23:22:00 +0000225 printf(pformat, (unsigned long) statbuf->st_mode);
Bernhard Reutner-Fischer0e6ab012007-04-04 13:58:33 +0000226 } else if (m == 'F') {
Denis Vlasenko91e52032007-10-05 20:31:23 +0000227 printfs(pformat, file_type(statbuf));
Bernhard Reutner-Fischer0e6ab012007-04-04 13:58:33 +0000228 } else if (m == 'h') {
Denis Vlasenko91e52032007-10-05 20:31:23 +0000229 strcat(pformat, "lu");
Denis Vlasenko87468852007-04-13 23:22:00 +0000230 printf(pformat, (unsigned long) statbuf->st_nlink);
Bernhard Reutner-Fischer0e6ab012007-04-04 13:58:33 +0000231 } else if (m == 'u') {
Denis Vlasenko91e52032007-10-05 20:31:23 +0000232 strcat(pformat, "lu");
Denis Vlasenko87468852007-04-13 23:22:00 +0000233 printf(pformat, (unsigned long) statbuf->st_uid);
Bernhard Reutner-Fischer0e6ab012007-04-04 13:58:33 +0000234 } else if (m == 'U') {
Mike Frysinger9b5f71e2005-04-23 06:26:38 +0000235 setpwent();
236 pw_ent = getpwuid(statbuf->st_uid);
Denis Vlasenko91e52032007-10-05 20:31:23 +0000237 printfs(pformat, (pw_ent != 0L) ? pw_ent->pw_name : "UNKNOWN");
Bernhard Reutner-Fischer0e6ab012007-04-04 13:58:33 +0000238 } else if (m == 'g') {
Denis Vlasenko91e52032007-10-05 20:31:23 +0000239 strcat(pformat, "lu");
Denis Vlasenko87468852007-04-13 23:22:00 +0000240 printf(pformat, (unsigned long) statbuf->st_gid);
Bernhard Reutner-Fischer0e6ab012007-04-04 13:58:33 +0000241 } else if (m == 'G') {
Mike Frysinger9b5f71e2005-04-23 06:26:38 +0000242 setgrent();
243 gw_ent = getgrgid(statbuf->st_gid);
Denis Vlasenko91e52032007-10-05 20:31:23 +0000244 printfs(pformat, (gw_ent != 0L) ? gw_ent->gr_name : "UNKNOWN");
Bernhard Reutner-Fischer0e6ab012007-04-04 13:58:33 +0000245 } else if (m == 't') {
Denis Vlasenko91e52032007-10-05 20:31:23 +0000246 strcat(pformat, "lx");
Denis Vlasenko87468852007-04-13 23:22:00 +0000247 printf(pformat, (unsigned long) major(statbuf->st_rdev));
Bernhard Reutner-Fischer0e6ab012007-04-04 13:58:33 +0000248 } else if (m == 'T') {
Denis Vlasenko91e52032007-10-05 20:31:23 +0000249 strcat(pformat, "lx");
Denis Vlasenko87468852007-04-13 23:22:00 +0000250 printf(pformat, (unsigned long) minor(statbuf->st_rdev));
Bernhard Reutner-Fischer0e6ab012007-04-04 13:58:33 +0000251 } else if (m == 's') {
Denis Vlasenko91e52032007-10-05 20:31:23 +0000252 strcat(pformat, "ju");
Mike Frysinger9b5f71e2005-04-23 06:26:38 +0000253 printf(pformat, (uintmax_t) (statbuf->st_size));
Bernhard Reutner-Fischer0e6ab012007-04-04 13:58:33 +0000254 } else if (m == 'B') {
Denis Vlasenko91e52032007-10-05 20:31:23 +0000255 strcat(pformat, "lu");
Denis Vlasenko87468852007-04-13 23:22:00 +0000256 printf(pformat, (unsigned long) 512); //ST_NBLOCKSIZE
Bernhard Reutner-Fischer0e6ab012007-04-04 13:58:33 +0000257 } else if (m == 'b') {
Denis Vlasenko91e52032007-10-05 20:31:23 +0000258 strcat(pformat, "ju");
Mike Frysinger9b5f71e2005-04-23 06:26:38 +0000259 printf(pformat, (uintmax_t) statbuf->st_blocks);
Bernhard Reutner-Fischer0e6ab012007-04-04 13:58:33 +0000260 } else if (m == 'o') {
Denis Vlasenko91e52032007-10-05 20:31:23 +0000261 strcat(pformat, "lu");
Denis Vlasenko87468852007-04-13 23:22:00 +0000262 printf(pformat, (unsigned long) statbuf->st_blksize);
Bernhard Reutner-Fischer0e6ab012007-04-04 13:58:33 +0000263 } else if (m == 'x') {
Denis Vlasenko91e52032007-10-05 20:31:23 +0000264 printfs(pformat, human_time(statbuf->st_atime));
Bernhard Reutner-Fischer0e6ab012007-04-04 13:58:33 +0000265 } else if (m == 'X') {
Denis Vlasenko91e52032007-10-05 20:31:23 +0000266 strcat(pformat, TYPE_SIGNED(time_t) ? "ld" : "lu");
Denis Vlasenko87468852007-04-13 23:22:00 +0000267 printf(pformat, (unsigned long) statbuf->st_atime);
Bernhard Reutner-Fischer0e6ab012007-04-04 13:58:33 +0000268 } else if (m == 'y') {
Denis Vlasenko91e52032007-10-05 20:31:23 +0000269 printfs(pformat, human_time(statbuf->st_mtime));
Bernhard Reutner-Fischer0e6ab012007-04-04 13:58:33 +0000270 } else if (m == 'Y') {
Denis Vlasenko91e52032007-10-05 20:31:23 +0000271 strcat(pformat, TYPE_SIGNED(time_t) ? "ld" : "lu");
Denis Vlasenko87468852007-04-13 23:22:00 +0000272 printf(pformat, (unsigned long) statbuf->st_mtime);
Bernhard Reutner-Fischer0e6ab012007-04-04 13:58:33 +0000273 } else if (m == 'z') {
Denis Vlasenko91e52032007-10-05 20:31:23 +0000274 printfs(pformat, human_time(statbuf->st_ctime));
Bernhard Reutner-Fischer0e6ab012007-04-04 13:58:33 +0000275 } else if (m == 'Z') {
Denis Vlasenko91e52032007-10-05 20:31:23 +0000276 strcat(pformat, TYPE_SIGNED(time_t) ? "ld" : "lu");
Denis Vlasenko87468852007-04-13 23:22:00 +0000277 printf(pformat, (unsigned long) statbuf->st_ctime);
Denis Vlasenko49622d72007-03-10 16:58:49 +0000278#if ENABLE_SELINUX
Bernhard Reutner-Fischer0e6ab012007-04-04 13:58:33 +0000279 } else if (m == 'C' && (option_mask32 & OPT_SELINUX)) {
Denis Vlasenko91e52032007-10-05 20:31:23 +0000280 printfs(pformat, scontext);
Denis Vlasenko49622d72007-03-10 16:58:49 +0000281#endif
Bernhard Reutner-Fischer0e6ab012007-04-04 13:58:33 +0000282 } else {
Denis Vlasenko91e52032007-10-05 20:31:23 +0000283 strcatc(pformat, 'c');
Mike Frysinger9b5f71e2005-04-23 06:26:38 +0000284 printf(pformat, m);
Mike Frysinger9b5f71e2005-04-23 06:26:38 +0000285 }
286}
287
Denis Vlasenko91e52032007-10-05 20:31:23 +0000288static void print_it(const char *masterformat, const char *filename,
289 void (*print_func) (char*, char, const char*, const void* USE_SELINUX(, security_context_t scontext)),
290 const void *data
291 USE_SELINUX(, security_context_t scontext) )
Mike Frysinger9b5f71e2005-04-23 06:26:38 +0000292{
Denis Vlasenko91e52032007-10-05 20:31:23 +0000293 /* Create a working copy of the format string */
Rob Landleyd921b2e2006-08-03 15:41:12 +0000294 char *format = xstrdup(masterformat);
Denis Vlasenko5d148e22006-11-21 00:12:09 +0000295 /* Add 2 to accomodate our conversion of the stat '%s' format string
296 * to the printf '%llu' one. */
Denis Vlasenko91e52032007-10-05 20:31:23 +0000297 char *dest = xmalloc(strlen(format) + 2 + 1);
298 char *b;
Mike Frysinger9b5f71e2005-04-23 06:26:38 +0000299
300 b = format;
301 while (b) {
Denis Vlasenko5d148e22006-11-21 00:12:09 +0000302 size_t len;
Mike Frysinger9b5f71e2005-04-23 06:26:38 +0000303 char *p = strchr(b, '%');
Denis Vlasenko5d148e22006-11-21 00:12:09 +0000304 if (!p) {
Denis Vlasenko91e52032007-10-05 20:31:23 +0000305 /* coreutils 6.3 always prints <cr> at the end */
Denis Vlasenko5d148e22006-11-21 00:12:09 +0000306 /*fputs(b, stdout);*/
307 puts(b);
308 break;
309 }
310 *p++ = '\0';
311 fputs(b, stdout);
Mike Frysinger9b5f71e2005-04-23 06:26:38 +0000312
Denis Vlasenko91e52032007-10-05 20:31:23 +0000313 /* dest = "%<modifiers>" */
Denis Vlasenko5d148e22006-11-21 00:12:09 +0000314 len = strspn(p, "#-+.I 0123456789");
315 dest[0] = '%';
316 memcpy(dest + 1, p, len);
Denis Vlasenko91e52032007-10-05 20:31:23 +0000317 dest[1 + len] = '\0';
Denis Vlasenko5d148e22006-11-21 00:12:09 +0000318 p += len;
Mike Frysinger9b5f71e2005-04-23 06:26:38 +0000319
Denis Vlasenko5d148e22006-11-21 00:12:09 +0000320 b = p + 1;
321 switch (*p) {
322 case '\0':
Mike Frysinger9b5f71e2005-04-23 06:26:38 +0000323 b = NULL;
Denis Vlasenko5d148e22006-11-21 00:12:09 +0000324 /* fall through */
325 case '%':
Denis Vlasenko4daad902007-09-27 10:20:47 +0000326 bb_putchar('%');
Denis Vlasenko5d148e22006-11-21 00:12:09 +0000327 break;
328 default:
Denis Vlasenko91e52032007-10-05 20:31:23 +0000329 /* Completes "%<modifiers>" with specifier and printfs */
330 print_func(dest, *p, filename, data USE_SELINUX(,scontext));
Denis Vlasenko5d148e22006-11-21 00:12:09 +0000331 break;
Mike Frysinger9b5f71e2005-04-23 06:26:38 +0000332 }
333 }
334
335 free(format);
336 free(dest);
337}
338#endif
339
340/* Stat the file system and print what we find. */
Denis Vlasenko91e52032007-10-05 20:31:23 +0000341static bool do_statfs(const char *filename, const char *format)
Mike Frysinger9b5f71e2005-04-23 06:26:38 +0000342{
343 struct statfs statfsbuf;
Denis Vlasenko49622d72007-03-10 16:58:49 +0000344#if ENABLE_SELINUX
345 security_context_t scontext = NULL;
Bernhard Reutner-Fischer0e6ab012007-04-04 13:58:33 +0000346
347 if (option_mask32 & OPT_SELINUX) {
Denis Vlasenko501bfe22007-08-09 08:10:13 +0000348 if ((option_mask32 & OPT_DEREFERENCE
349 ? lgetfilecon(filename, &scontext)
350 : getfilecon(filename, &scontext)
351 ) < 0
352 ) {
Denis Vlasenko49622d72007-03-10 16:58:49 +0000353 bb_perror_msg(filename);
354 return 0;
355 }
356 }
357#endif
Mike Frysinger9b5f71e2005-04-23 06:26:38 +0000358 if (statfs(filename, &statfsbuf) != 0) {
359 bb_perror_msg("cannot read file system information for '%s'", filename);
360 return 0;
361 }
362
Denis Vlasenko240a1cf2007-04-08 16:07:02 +0000363#if ENABLE_FEATURE_STAT_FORMAT
Denis Vlasenko91e52032007-10-05 20:31:23 +0000364 if (format == NULL) {
Denis Vlasenko240a1cf2007-04-08 16:07:02 +0000365#if !ENABLE_SELINUX
Bernhard Reutner-Fischer0e6ab012007-04-04 13:58:33 +0000366 format = (option_mask32 & OPT_TERSE
Mike Frysinger726b2cb2005-07-26 22:39:56 +0000367 ? "%n %i %l %t %s %b %f %a %c %d\n"
Mike Frysinger9b5f71e2005-04-23 06:26:38 +0000368 : " File: \"%n\"\n"
369 " ID: %-8i Namelen: %-7l Type: %T\n"
Mike Frysinger726b2cb2005-07-26 22:39:56 +0000370 "Block size: %-10s\n"
Mike Frysinger9b5f71e2005-04-23 06:26:38 +0000371 "Blocks: Total: %-10b Free: %-10f Available: %a\n"
Denis Vlasenko5d148e22006-11-21 00:12:09 +0000372 "Inodes: Total: %-10c Free: %d");
Mike Frysinger9b5f71e2005-04-23 06:26:38 +0000373#else
Denis Vlasenko91e52032007-10-05 20:31:23 +0000374 format = (option_mask32 & OPT_TERSE
Bernhard Reutner-Fischer0e6ab012007-04-04 13:58:33 +0000375 ? (option_mask32 & OPT_SELINUX ? "%n %i %l %t %s %b %f %a %c %d %C\n":
Denis Vlasenko49622d72007-03-10 16:58:49 +0000376 "%n %i %l %t %s %b %f %a %c %d\n")
Bernhard Reutner-Fischer0e6ab012007-04-04 13:58:33 +0000377 : (option_mask32 & OPT_SELINUX ?
Denis Vlasenko49622d72007-03-10 16:58:49 +0000378 " File: \"%n\"\n"
379 " ID: %-8i Namelen: %-7l Type: %T\n"
380 "Block size: %-10s\n"
381 "Blocks: Total: %-10b Free: %-10f Available: %a\n"
382 "Inodes: Total: %-10c Free: %d"
383 " S_context: %C\n":
384 " File: \"%n\"\n"
385 " ID: %-8i Namelen: %-7l Type: %T\n"
386 "Block size: %-10s\n"
387 "Blocks: Total: %-10b Free: %-10f Available: %a\n"
388 "Inodes: Total: %-10c Free: %d\n")
389 );
Denis Vlasenko49622d72007-03-10 16:58:49 +0000390#endif /* SELINUX */
Denis Vlasenko91e52032007-10-05 20:31:23 +0000391 }
392 print_it(format, filename, print_statfs, &statfsbuf USE_SELINUX(, scontext));
Denis Vlasenko49622d72007-03-10 16:58:49 +0000393#else /* FEATURE_STAT_FORMAT */
Bernhard Reutner-Fischer0e6ab012007-04-04 13:58:33 +0000394 format = (option_mask32 & OPT_TERSE
Bernhard Reutner-Fischerd409c3a2006-03-29 22:34:47 +0000395 ? "%s %llx %lu "
Mike Frysinger9b5f71e2005-04-23 06:26:38 +0000396 : " File: \"%s\"\n"
397 " ID: %-8Lx Namelen: %-7lu ");
398 printf(format,
399 filename,
400 statfsbuf.f_fsid,
401 statfsbuf.f_namelen);
402
Bernhard Reutner-Fischer0e6ab012007-04-04 13:58:33 +0000403 if (option_mask32 & OPT_TERSE)
Denis Vlasenko87468852007-04-13 23:22:00 +0000404 printf("%lx ", (unsigned long) (statfsbuf.f_type));
Mike Frysinger9b5f71e2005-04-23 06:26:38 +0000405 else
406 printf("Type: %s\n", human_fstype(statfsbuf.f_type));
407
Denis Vlasenko49622d72007-03-10 16:58:49 +0000408#if !ENABLE_SELINUX
Bernhard Reutner-Fischer0e6ab012007-04-04 13:58:33 +0000409 format = (option_mask32 & OPT_TERSE
Mike Frysinger726b2cb2005-07-26 22:39:56 +0000410 ? "%lu %ld %ld %ld %ld %ld\n"
411 : "Block size: %-10lu\n"
Bernhard Reutner-Fischerfc5f3182006-04-12 08:03:11 +0000412 "Blocks: Total: %-10jd Free: %-10jd Available: %jd\n"
413 "Inodes: Total: %-10jd Free: %jd\n");
Mike Frysinger9b5f71e2005-04-23 06:26:38 +0000414 printf(format,
Denis Vlasenko87468852007-04-13 23:22:00 +0000415 (unsigned long) (statfsbuf.f_bsize),
Mike Frysinger9b5f71e2005-04-23 06:26:38 +0000416 (intmax_t) (statfsbuf.f_blocks),
417 (intmax_t) (statfsbuf.f_bfree),
418 (intmax_t) (statfsbuf.f_bavail),
419 (intmax_t) (statfsbuf.f_files),
420 (intmax_t) (statfsbuf.f_ffree));
Denis Vlasenko49622d72007-03-10 16:58:49 +0000421#else
Bernhard Reutner-Fischer0e6ab012007-04-04 13:58:33 +0000422 format = (option_mask32 & OPT_TERSE
423 ? (option_mask32 & OPT_SELINUX ? "%lu %ld %ld %ld %ld %ld %C\n":
Denis Vlasenko49622d72007-03-10 16:58:49 +0000424 "%lu %ld %ld %ld %ld %ld\n")
Bernhard Reutner-Fischer0e6ab012007-04-04 13:58:33 +0000425 : (option_mask32 & OPT_SELINUX ?
Denis Vlasenko49622d72007-03-10 16:58:49 +0000426 "Block size: %-10lu\n"
427 "Blocks: Total: %-10jd Free: %-10jd Available: %jd\n"
428 "Inodes: Total: %-10jd Free: %jd"
429 "S_context: %C\n":
430 "Block size: %-10lu\n"
431 "Blocks: Total: %-10jd Free: %-10jd Available: %jd\n"
432 "Inodes: Total: %-10jd Free: %jd\n"));
433 printf(format,
Denis Vlasenko87468852007-04-13 23:22:00 +0000434 (unsigned long) (statfsbuf.f_bsize),
Denis Vlasenko49622d72007-03-10 16:58:49 +0000435 (intmax_t) (statfsbuf.f_blocks),
436 (intmax_t) (statfsbuf.f_bfree),
437 (intmax_t) (statfsbuf.f_bavail),
438 (intmax_t) (statfsbuf.f_files),
439 (intmax_t) (statfsbuf.f_ffree),
440 scontext);
Mike Frysinger9b5f71e2005-04-23 06:26:38 +0000441
Denis Vlasenko49622d72007-03-10 16:58:49 +0000442 if (scontext)
443 freecon(scontext);
444#endif
445#endif /* FEATURE_STAT_FORMAT */
Mike Frysinger9b5f71e2005-04-23 06:26:38 +0000446 return 1;
447}
448
449/* stat the file and print what we find */
Denis Vlasenko91e52032007-10-05 20:31:23 +0000450static bool do_stat(const char *filename, const char *format)
Mike Frysinger9b5f71e2005-04-23 06:26:38 +0000451{
452 struct stat statbuf;
Denis Vlasenko49622d72007-03-10 16:58:49 +0000453#if ENABLE_SELINUX
454 security_context_t scontext = NULL;
Bernhard Reutner-Fischer0e6ab012007-04-04 13:58:33 +0000455
456 if (option_mask32 & OPT_SELINUX) {
Denis Vlasenko501bfe22007-08-09 08:10:13 +0000457 if ((option_mask32 & OPT_DEREFERENCE
458 ? lgetfilecon(filename, &scontext)
459 : getfilecon(filename, &scontext)
460 ) < 0
461 ) {
462 bb_perror_msg(filename);
Denis Vlasenko49622d72007-03-10 16:58:49 +0000463 return 0;
464 }
465 }
466#endif
Bernhard Reutner-Fischer0e6ab012007-04-04 13:58:33 +0000467 if ((option_mask32 & OPT_DEREFERENCE ? stat : lstat) (filename, &statbuf) != 0) {
Mike Frysinger9b5f71e2005-04-23 06:26:38 +0000468 bb_perror_msg("cannot stat '%s'", filename);
469 return 0;
470 }
471
Denis Vlasenko240a1cf2007-04-08 16:07:02 +0000472#if ENABLE_FEATURE_STAT_FORMAT
Mike Frysinger9b5f71e2005-04-23 06:26:38 +0000473 if (format == NULL) {
Denis Vlasenko240a1cf2007-04-08 16:07:02 +0000474#if !ENABLE_SELINUX
Bernhard Reutner-Fischer0e6ab012007-04-04 13:58:33 +0000475 if (option_mask32 & OPT_TERSE) {
Denis Vlasenko5d148e22006-11-21 00:12:09 +0000476 format = "%n %s %b %f %u %g %D %i %h %t %T %X %Y %Z %o";
Mike Frysinger9b5f71e2005-04-23 06:26:38 +0000477 } else {
478 if (S_ISBLK(statbuf.st_mode) || S_ISCHR(statbuf.st_mode)) {
479 format =
480 " File: \"%N\"\n"
481 " Size: %-10s\tBlocks: %-10b IO Block: %-6o %F\n"
482 "Device: %Dh/%dd\tInode: %-10i Links: %-5h"
483 " Device type: %t,%T\n"
484 "Access: (%04a/%10.10A) Uid: (%5u/%8U) Gid: (%5g/%8G)\n"
485 "Access: %x\n" "Modify: %y\n" "Change: %z\n";
486 } else {
487 format =
488 " File: \"%N\"\n"
489 " Size: %-10s\tBlocks: %-10b IO Block: %-6o %F\n"
490 "Device: %Dh/%dd\tInode: %-10i Links: %h\n"
491 "Access: (%04a/%10.10A) Uid: (%5u/%8U) Gid: (%5g/%8G)\n"
492 "Access: %x\n" "Modify: %y\n" "Change: %z\n";
493 }
494 }
Mike Frysinger9b5f71e2005-04-23 06:26:38 +0000495#else
Bernhard Reutner-Fischer0e6ab012007-04-04 13:58:33 +0000496 if (option_mask32 & OPT_TERSE) {
497 format = (option_mask32 & OPT_SELINUX ?
Denis Vlasenko49622d72007-03-10 16:58:49 +0000498 "%n %s %b %f %u %g %D %i %h %t %T %X %Y %Z %o %C\n":
499 "%n %s %b %f %u %g %D %i %h %t %T %X %Y %Z %o\n");
500 } else {
501 if (S_ISBLK(statbuf.st_mode) || S_ISCHR(statbuf.st_mode)) {
Bernhard Reutner-Fischer0e6ab012007-04-04 13:58:33 +0000502 format = (option_mask32 & OPT_SELINUX ?
Denis Vlasenko49622d72007-03-10 16:58:49 +0000503 " File: \"%N\"\n"
504 " Size: %-10s\tBlocks: %-10b IO Block: %-6o %F\n"
505 "Device: %Dh/%dd\tInode: %-10i Links: %-5h"
506 " Device type: %t,%T\n"
507 "Access: (%04a/%10.10A) Uid: (%5u/%8U) Gid: (%5g/%8G)\n"
508 " S_Context: %C\n"
509 "Access: %x\n" "Modify: %y\n" "Change: %z\n":
510 " File: \"%N\"\n"
511 " Size: %-10s\tBlocks: %-10b IO Block: %-6o %F\n"
512 "Device: %Dh/%dd\tInode: %-10i Links: %-5h"
513 " Device type: %t,%T\n"
514 "Access: (%04a/%10.10A) Uid: (%5u/%8U) Gid: (%5g/%8G)\n"
515 "Access: %x\n" "Modify: %y\n" "Change: %z\n");
516 } else {
Bernhard Reutner-Fischer0e6ab012007-04-04 13:58:33 +0000517 format = (option_mask32 & OPT_SELINUX ?
Denis Vlasenko49622d72007-03-10 16:58:49 +0000518 " File: \"%N\"\n"
519 " Size: %-10s\tBlocks: %-10b IO Block: %-6o %F\n"
520 "Device: %Dh/%dd\tInode: %-10i Links: %h\n"
521 "Access: (%04a/%10.10A) Uid: (%5u/%8U) Gid: (%5g/%8G)\n"
522 "S_Context: %C\n"
523 "Access: %x\n" "Modify: %y\n" "Change: %z\n":
524 " File: \"%N\"\n"
525 " Size: %-10s\tBlocks: %-10b IO Block: %-6o %F\n"
526 "Device: %Dh/%dd\tInode: %-10i Links: %h\n"
527 "Access: (%04a/%10.10A) Uid: (%5u/%8U) Gid: (%5g/%8G)\n"
528 "Access: %x\n" "Modify: %y\n" "Change: %z\n");
529 }
530 }
531#endif
532 }
533 print_it(format, filename, print_stat, &statbuf USE_SELINUX(, scontext));
534#else /* FEATURE_STAT_FORMAT */
Bernhard Reutner-Fischer0e6ab012007-04-04 13:58:33 +0000535 if (option_mask32 & OPT_TERSE) {
Denis Vlasenko49622d72007-03-10 16:58:49 +0000536 printf("%s %ju %ju %lx %lu %lu %jx %ju %lu %lx %lx %lu %lu %lu %lu"
537 SKIP_SELINUX("\n"),
Mike Frysinger9b5f71e2005-04-23 06:26:38 +0000538 filename,
539 (uintmax_t) (statbuf.st_size),
540 (uintmax_t) statbuf.st_blocks,
Denis Vlasenko87468852007-04-13 23:22:00 +0000541 (unsigned long) statbuf.st_mode,
542 (unsigned long) statbuf.st_uid,
543 (unsigned long) statbuf.st_gid,
Mike Frysinger9b5f71e2005-04-23 06:26:38 +0000544 (uintmax_t) statbuf.st_dev,
545 (uintmax_t) statbuf.st_ino,
Denis Vlasenko87468852007-04-13 23:22:00 +0000546 (unsigned long) statbuf.st_nlink,
547 (unsigned long) major(statbuf.st_rdev),
548 (unsigned long) minor(statbuf.st_rdev),
549 (unsigned long) statbuf.st_atime,
550 (unsigned long) statbuf.st_mtime,
551 (unsigned long) statbuf.st_ctime,
552 (unsigned long) statbuf.st_blksize
Mike Frysinger9b5f71e2005-04-23 06:26:38 +0000553 );
Denis Vlasenko49622d72007-03-10 16:58:49 +0000554#if ENABLE_SELINUX
Bernhard Reutner-Fischer0e6ab012007-04-04 13:58:33 +0000555 if (option_mask32 & OPT_SELINUX)
Denis Vlasenko49622d72007-03-10 16:58:49 +0000556 printf(" %lc\n", *scontext);
557 else
Denis Vlasenko4daad902007-09-27 10:20:47 +0000558 bb_putchar('\n');
Denis Vlasenko49622d72007-03-10 16:58:49 +0000559#endif
Mike Frysinger9b5f71e2005-04-23 06:26:38 +0000560 } else {
561 char *linkname = NULL;
562
563 struct passwd *pw_ent;
564 struct group *gw_ent;
565 setgrent();
566 gw_ent = getgrgid(statbuf.st_gid);
567 setpwent();
568 pw_ent = getpwuid(statbuf.st_uid);
569
570 if (S_ISLNK(statbuf.st_mode))
Denis Vlasenko6ca04442007-02-11 16:19:28 +0000571 linkname = xmalloc_readlink_or_warn(filename);
Mike Frysinger9b5f71e2005-04-23 06:26:38 +0000572 if (linkname)
573 printf(" File: \"%s\" -> \"%s\"\n", filename, linkname);
574 else
575 printf(" File: \"%s\"\n", filename);
576
Bernhard Reutner-Fischerfc5f3182006-04-12 08:03:11 +0000577 printf(" Size: %-10ju\tBlocks: %-10ju IO Block: %-6lu %s\n"
578 "Device: %jxh/%jud\tInode: %-10ju Links: %-5lu",
Mike Frysinger9b5f71e2005-04-23 06:26:38 +0000579 (uintmax_t) (statbuf.st_size),
580 (uintmax_t) statbuf.st_blocks,
Denis Vlasenko87468852007-04-13 23:22:00 +0000581 (unsigned long) statbuf.st_blksize,
Mike Frysinger9b5f71e2005-04-23 06:26:38 +0000582 file_type(&statbuf),
583 (uintmax_t) statbuf.st_dev,
584 (uintmax_t) statbuf.st_dev,
585 (uintmax_t) statbuf.st_ino,
Denis Vlasenko87468852007-04-13 23:22:00 +0000586 (unsigned long) statbuf.st_nlink);
Mike Frysinger9b5f71e2005-04-23 06:26:38 +0000587 if (S_ISBLK(statbuf.st_mode) || S_ISCHR(statbuf.st_mode))
588 printf(" Device type: %lx,%lx\n",
Denis Vlasenko87468852007-04-13 23:22:00 +0000589 (unsigned long) major(statbuf.st_rdev),
590 (unsigned long) minor(statbuf.st_rdev));
Mike Frysinger9b5f71e2005-04-23 06:26:38 +0000591 else
Denis Vlasenko4daad902007-09-27 10:20:47 +0000592 bb_putchar('\n');
Denis Vlasenko49622d72007-03-10 16:58:49 +0000593 printf("Access: (%04lo/%10.10s) Uid: (%5lu/%8s) Gid: (%5lu/%8s)\n",
Denis Vlasenko87468852007-04-13 23:22:00 +0000594 (unsigned long) (statbuf.st_mode & (S_ISUID|S_ISGID|S_ISVTX|S_IRWXU|S_IRWXG|S_IRWXO)),
Mike Frysinger9b5f71e2005-04-23 06:26:38 +0000595 bb_mode_string(statbuf.st_mode),
Denis Vlasenko87468852007-04-13 23:22:00 +0000596 (unsigned long) statbuf.st_uid,
Mike Frysinger9b5f71e2005-04-23 06:26:38 +0000597 (pw_ent != 0L) ? pw_ent->pw_name : "UNKNOWN",
Denis Vlasenko87468852007-04-13 23:22:00 +0000598 (unsigned long) statbuf.st_gid,
Denis Vlasenko49622d72007-03-10 16:58:49 +0000599 (gw_ent != 0L) ? gw_ent->gr_name : "UNKNOWN");
600#if ENABLE_SELINUX
601 printf(" S_Context: %lc\n", *scontext);
602#endif
603 printf("Access: %s\n" "Modify: %s\n" "Change: %s\n",
Mike Frysinger9b5f71e2005-04-23 06:26:38 +0000604 human_time(statbuf.st_atime),
605 human_time(statbuf.st_mtime),
606 human_time(statbuf.st_ctime));
607 }
Denis Vlasenko49622d72007-03-10 16:58:49 +0000608#endif /* FEATURE_STAT_FORMAT */
Mike Frysinger9b5f71e2005-04-23 06:26:38 +0000609 return 1;
610}
611
Denis Vlasenko9b49a5e2007-10-11 10:05:36 +0000612int stat_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
Mike Frysinger9b5f71e2005-04-23 06:26:38 +0000613int stat_main(int argc, char **argv)
614{
Mike Frysinger9b5f71e2005-04-23 06:26:38 +0000615 char *format = NULL;
Bernhard Reutner-Fischer0e6ab012007-04-04 13:58:33 +0000616 int i;
Mike Frysinger9b5f71e2005-04-23 06:26:38 +0000617 int ok = 1;
Denis Vlasenko91e52032007-10-05 20:31:23 +0000618 bool (*statfunc)(const char *, const char *) = do_stat;
Mike Frysinger9b5f71e2005-04-23 06:26:38 +0000619
Denis Vlasenkofe7cd642007-08-18 15:32:12 +0000620 getopt32(argv, "ftL"
Denis Vlasenko49622d72007-03-10 16:58:49 +0000621 USE_SELINUX("Z")
Denis Vlasenko5d148e22006-11-21 00:12:09 +0000622 USE_FEATURE_STAT_FORMAT("c:", &format)
Mike Frysinger9b5f71e2005-04-23 06:26:38 +0000623 );
624
Bernhard Reutner-Fischer0e6ab012007-04-04 13:58:33 +0000625 if (option_mask32 & OPT_FILESYS) /* -f */
Mike Frysinger9b5f71e2005-04-23 06:26:38 +0000626 statfunc = do_statfs;
Mike Frysinger9b5f71e2005-04-23 06:26:38 +0000627 if (argc == optind) /* files */
628 bb_show_usage();
629
Denis Vlasenko49622d72007-03-10 16:58:49 +0000630#if ENABLE_SELINUX
Bernhard Reutner-Fischer0e6ab012007-04-04 13:58:33 +0000631 if (option_mask32 & OPT_SELINUX) {
Denis Vlasenko49622d72007-03-10 16:58:49 +0000632 selinux_or_die();
633 }
634#endif /* ENABLE_SELINUX */
Mike Frysinger9b5f71e2005-04-23 06:26:38 +0000635 for (i = optind; i < argc; ++i)
636 ok &= statfunc(argv[i], format);
637
638 return (ok ? EXIT_SUCCESS : EXIT_FAILURE);
639}