"Robert P. J. Day" | 63fc1a9 | 2006-07-02 19:47:05 +0000 | [diff] [blame] | 1 | /* vi: set sw=4 ts=4: */ |
Mike Frysinger | 9b5f71e | 2005-04-23 06:26:38 +0000 | [diff] [blame] | 2 | /* |
| 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 Vlasenko | 49622d7 | 2007-03-10 16:58:49 +0000 | [diff] [blame^] | 8 | * Copyright (C) 2006 by Yoshinori Sato <ysato@users.sourceforge.jp> |
Mike Frysinger | 9b5f71e | 2005-04-23 06:26:38 +0000 | [diff] [blame] | 9 | * |
| 10 | * Written by Michael Meskes |
| 11 | * Taken from coreutils and turned into a busybox applet by Mike Frysinger |
| 12 | * |
Bernhard Reutner-Fischer | e11a01c | 2006-04-05 17:19:37 +0000 | [diff] [blame] | 13 | * Licensed under GPLv2 or later, see file LICENSE in this tarball for details. |
Mike Frysinger | 9b5f71e | 2005-04-23 06:26:38 +0000 | [diff] [blame] | 14 | */ |
| 15 | |
Mike Frysinger | 9b5f71e | 2005-04-23 06:26:38 +0000 | [diff] [blame] | 16 | #include "busybox.h" |
| 17 | |
| 18 | /* vars to control behavior */ |
Mike Frysinger | f06c494 | 2005-04-24 03:53:12 +0000 | [diff] [blame] | 19 | #define OPT_TERSE 2 |
Bernhard Reutner-Fischer | 18260d5 | 2006-04-18 14:17:49 +0000 | [diff] [blame] | 20 | #define OPT_DEREFERENCE 4 |
Denis Vlasenko | 49622d7 | 2007-03-10 16:58:49 +0000 | [diff] [blame^] | 21 | #define OPT_SELINUX 8 |
Mike Frysinger | f06c494 | 2005-04-24 03:53:12 +0000 | [diff] [blame] | 22 | static long flags; |
Mike Frysinger | 9b5f71e | 2005-04-23 06:26:38 +0000 | [diff] [blame] | 23 | |
| 24 | static char const *file_type(struct stat const *st) |
| 25 | { |
Tim Riker | c1ef7bd | 2006-01-25 00:08:53 +0000 | [diff] [blame] | 26 | /* See POSIX 1003.1-2001 XCU Table 4-8 lines 17093-17107 |
Mike Frysinger | 9b5f71e | 2005-04-23 06:26:38 +0000 | [diff] [blame] | 27 | * for some of these formats. |
Tim Riker | c1ef7bd | 2006-01-25 00:08:53 +0000 | [diff] [blame] | 28 | * To keep diagnostics grammatical in English, the |
Mike Frysinger | 9b5f71e | 2005-04-23 06:26:38 +0000 | [diff] [blame] | 29 | * 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 | |
| 47 | static char const *human_time(time_t t) |
| 48 | { |
Denis Vlasenko | 5d148e2 | 2006-11-21 00:12:09 +0000 | [diff] [blame] | 49 | /* Old |
Mike Frysinger | 9b5f71e | 2005-04-23 06:26:38 +0000 | [diff] [blame] | 50 | static char *str; |
| 51 | str = ctime(&t); |
| 52 | str[strlen(str)-1] = '\0'; |
| 53 | return str; |
Denis Vlasenko | 5d148e2 | 2006-11-21 00:12:09 +0000 | [diff] [blame] | 54 | */ |
| 55 | /* coreutils 6.3 compat: */ |
| 56 | static char buf[sizeof("YYYY-MM-DD HH:MM:SS.000000000")]; |
| 57 | strftime(buf, sizeof(buf), "%Y-%m-%d %H:%M:%S.000000000", localtime(&t)); |
| 58 | return buf; |
Mike Frysinger | 9b5f71e | 2005-04-23 06:26:38 +0000 | [diff] [blame] | 59 | } |
| 60 | |
| 61 | /* Return the type of the specified file system. |
| 62 | * Some systems have statfvs.f_basetype[FSTYPSZ]. (AIX, HP-UX, and Solaris) |
| 63 | * Others have statfs.f_fstypename[MFSNAMELEN]. (NetBSD 1.5.2) |
| 64 | * Still others have neither and have to get by with f_type (Linux). |
| 65 | */ |
| 66 | static char const *human_fstype(long f_type) |
| 67 | { |
Mike Frysinger | 408ae21 | 2005-04-24 04:11:44 +0000 | [diff] [blame] | 68 | int i; |
"Vladimir N. Oleynik" | 1f0262b | 2005-10-20 11:17:48 +0000 | [diff] [blame] | 69 | static const struct types { |
Mike Frysinger | 408ae21 | 2005-04-24 04:11:44 +0000 | [diff] [blame] | 70 | long type; |
"Vladimir N. Oleynik" | 1f0262b | 2005-10-20 11:17:48 +0000 | [diff] [blame] | 71 | const char *fs; |
Mike Frysinger | 408ae21 | 2005-04-24 04:11:44 +0000 | [diff] [blame] | 72 | } humantypes[] = { |
| 73 | { 0xADFF, "affs" }, |
| 74 | { 0x1Cd1, "devpts" }, |
| 75 | { 0x137D, "ext" }, |
| 76 | { 0xEF51, "ext2" }, |
| 77 | { 0xEF53, "ext2/ext3" }, |
| 78 | { 0x3153464a, "jfs" }, |
| 79 | { 0x58465342, "xfs" }, |
| 80 | { 0xF995E849, "hpfs" }, |
| 81 | { 0x9660, "isofs" }, |
| 82 | { 0x4000, "isofs" }, |
| 83 | { 0x4004, "isofs" }, |
| 84 | { 0x137F, "minix" }, |
| 85 | { 0x138F, "minix (30 char.)" }, |
| 86 | { 0x2468, "minix v2" }, |
| 87 | { 0x2478, "minix v2 (30 char.)" }, |
| 88 | { 0x4d44, "msdos" }, |
| 89 | { 0x4006, "fat" }, |
| 90 | { 0x564c, "novell" }, |
| 91 | { 0x6969, "nfs" }, |
| 92 | { 0x9fa0, "proc" }, |
| 93 | { 0x517B, "smb" }, |
| 94 | { 0x012FF7B4, "xenix" }, |
| 95 | { 0x012FF7B5, "sysv4" }, |
| 96 | { 0x012FF7B6, "sysv2" }, |
| 97 | { 0x012FF7B7, "coh" }, |
| 98 | { 0x00011954, "ufs" }, |
| 99 | { 0x012FD16D, "xia" }, |
| 100 | { 0x5346544e, "ntfs" }, |
| 101 | { 0x1021994, "tmpfs" }, |
| 102 | { 0x52654973, "reiserfs" }, |
| 103 | { 0x28cd3d45, "cramfs" }, |
| 104 | { 0x7275, "romfs" }, |
| 105 | { 0x858458f6, "romfs" }, |
| 106 | { 0x73717368, "squashfs" }, |
| 107 | { 0x62656572, "sysfs" }, |
Rob Landley | 0a7c8ef | 2006-02-22 17:01:00 +0000 | [diff] [blame] | 108 | { 0, "UNKNOWN" } |
Mike Frysinger | 408ae21 | 2005-04-24 04:11:44 +0000 | [diff] [blame] | 109 | }; |
| 110 | for (i=0; humantypes[i].type; ++i) |
| 111 | if (humantypes[i].type == f_type) |
Rob Landley | 0a7c8ef | 2006-02-22 17:01:00 +0000 | [diff] [blame] | 112 | break; |
Mike Frysinger | 408ae21 | 2005-04-24 04:11:44 +0000 | [diff] [blame] | 113 | return humantypes[i].fs; |
Mike Frysinger | 9b5f71e | 2005-04-23 06:26:38 +0000 | [diff] [blame] | 114 | } |
| 115 | |
| 116 | #ifdef CONFIG_FEATURE_STAT_FORMAT |
| 117 | /* print statfs info */ |
Tim Riker | c1ef7bd | 2006-01-25 00:08:53 +0000 | [diff] [blame] | 118 | static void print_statfs(char *pformat, size_t buf_len, char m, |
Denis Vlasenko | 49622d7 | 2007-03-10 16:58:49 +0000 | [diff] [blame^] | 119 | char const *filename, void const *data |
| 120 | USE_SELINUX(,security_context_t scontext) ) |
Mike Frysinger | 9b5f71e | 2005-04-23 06:26:38 +0000 | [diff] [blame] | 121 | { |
| 122 | struct statfs const *statfsbuf = data; |
| 123 | |
| 124 | switch (m) { |
| 125 | case 'n': |
| 126 | strncat(pformat, "s", buf_len); |
| 127 | printf(pformat, filename); |
| 128 | break; |
| 129 | case 'i': |
| 130 | strncat(pformat, "Lx", buf_len); |
| 131 | printf(pformat, statfsbuf->f_fsid); |
| 132 | break; |
| 133 | case 'l': |
| 134 | strncat(pformat, "lu", buf_len); |
| 135 | printf(pformat, statfsbuf->f_namelen); |
| 136 | break; |
| 137 | case 't': |
| 138 | strncat(pformat, "lx", buf_len); |
| 139 | printf(pformat, (unsigned long int) (statfsbuf->f_type)); /* no equiv. */ |
| 140 | break; |
| 141 | case 'T': |
| 142 | strncat(pformat, "s", buf_len); |
| 143 | printf(pformat, human_fstype(statfsbuf->f_type)); |
| 144 | break; |
| 145 | case 'b': |
Bernhard Reutner-Fischer | fc5f318 | 2006-04-12 08:03:11 +0000 | [diff] [blame] | 146 | strncat(pformat, "jd", buf_len); |
Mike Frysinger | 9b5f71e | 2005-04-23 06:26:38 +0000 | [diff] [blame] | 147 | printf(pformat, (intmax_t) (statfsbuf->f_blocks)); |
| 148 | break; |
| 149 | case 'f': |
Bernhard Reutner-Fischer | fc5f318 | 2006-04-12 08:03:11 +0000 | [diff] [blame] | 150 | strncat(pformat, "jd", buf_len); |
Mike Frysinger | 9b5f71e | 2005-04-23 06:26:38 +0000 | [diff] [blame] | 151 | printf(pformat, (intmax_t) (statfsbuf->f_bfree)); |
| 152 | break; |
| 153 | case 'a': |
Bernhard Reutner-Fischer | fc5f318 | 2006-04-12 08:03:11 +0000 | [diff] [blame] | 154 | strncat(pformat, "jd", buf_len); |
Mike Frysinger | 9b5f71e | 2005-04-23 06:26:38 +0000 | [diff] [blame] | 155 | printf(pformat, (intmax_t) (statfsbuf->f_bavail)); |
| 156 | break; |
Mike Frysinger | 726b2cb | 2005-07-26 22:39:56 +0000 | [diff] [blame] | 157 | case 'S': |
Mike Frysinger | 9b5f71e | 2005-04-23 06:26:38 +0000 | [diff] [blame] | 158 | case 's': |
| 159 | strncat(pformat, "lu", buf_len); |
| 160 | printf(pformat, (unsigned long int) (statfsbuf->f_bsize)); |
| 161 | break; |
Mike Frysinger | 9b5f71e | 2005-04-23 06:26:38 +0000 | [diff] [blame] | 162 | case 'c': |
Bernhard Reutner-Fischer | fc5f318 | 2006-04-12 08:03:11 +0000 | [diff] [blame] | 163 | strncat(pformat, "jd", buf_len); |
Mike Frysinger | 9b5f71e | 2005-04-23 06:26:38 +0000 | [diff] [blame] | 164 | printf(pformat, (intmax_t) (statfsbuf->f_files)); |
| 165 | break; |
| 166 | case 'd': |
Bernhard Reutner-Fischer | fc5f318 | 2006-04-12 08:03:11 +0000 | [diff] [blame] | 167 | strncat(pformat, "jd", buf_len); |
Mike Frysinger | 9b5f71e | 2005-04-23 06:26:38 +0000 | [diff] [blame] | 168 | printf(pformat, (intmax_t) (statfsbuf->f_ffree)); |
| 169 | break; |
Denis Vlasenko | 49622d7 | 2007-03-10 16:58:49 +0000 | [diff] [blame^] | 170 | #if ENABLE_SELINUX |
| 171 | case 'C': |
| 172 | if (flags & OPT_SELINUX) { |
| 173 | strncat(pformat, "s", buf_len); |
| 174 | printf(scontext); |
| 175 | } |
| 176 | break; |
| 177 | #endif |
Mike Frysinger | 9b5f71e | 2005-04-23 06:26:38 +0000 | [diff] [blame] | 178 | default: |
| 179 | strncat(pformat, "c", buf_len); |
| 180 | printf(pformat, m); |
| 181 | break; |
| 182 | } |
| 183 | } |
| 184 | |
| 185 | /* print stat info */ |
Tim Riker | c1ef7bd | 2006-01-25 00:08:53 +0000 | [diff] [blame] | 186 | static void print_stat(char *pformat, size_t buf_len, char m, |
Denis Vlasenko | 49622d7 | 2007-03-10 16:58:49 +0000 | [diff] [blame^] | 187 | char const *filename, void const *data |
| 188 | USE_SELINUX(, security_context_t scontext)) |
Mike Frysinger | 9b5f71e | 2005-04-23 06:26:38 +0000 | [diff] [blame] | 189 | { |
| 190 | #define TYPE_SIGNED(t) (! ((t) 0 < (t) -1)) |
| 191 | struct stat *statbuf = (struct stat *) data; |
| 192 | struct passwd *pw_ent; |
| 193 | struct group *gw_ent; |
| 194 | |
| 195 | switch (m) { |
| 196 | case 'n': |
| 197 | strncat(pformat, "s", buf_len); |
| 198 | printf(pformat, filename); |
| 199 | break; |
| 200 | case 'N': |
| 201 | strncat(pformat, "s", buf_len); |
| 202 | if (S_ISLNK(statbuf->st_mode)) { |
Denis Vlasenko | 6ca0444 | 2007-02-11 16:19:28 +0000 | [diff] [blame] | 203 | char *linkname = xmalloc_readlink_or_warn(filename); |
Mike Frysinger | 9b5f71e | 2005-04-23 06:26:38 +0000 | [diff] [blame] | 204 | if (linkname == NULL) { |
| 205 | bb_perror_msg("cannot read symbolic link '%s'", filename); |
| 206 | return; |
| 207 | } |
| 208 | /*printf("\"%s\" -> \"%s\"", filename, linkname); */ |
| 209 | printf(pformat, filename); |
| 210 | printf(" -> "); |
| 211 | printf(pformat, linkname); |
| 212 | } else { |
| 213 | printf(pformat, filename); |
| 214 | } |
| 215 | break; |
| 216 | case 'd': |
Bernhard Reutner-Fischer | fc5f318 | 2006-04-12 08:03:11 +0000 | [diff] [blame] | 217 | strncat(pformat, "ju", buf_len); |
Mike Frysinger | 9b5f71e | 2005-04-23 06:26:38 +0000 | [diff] [blame] | 218 | printf(pformat, (uintmax_t) statbuf->st_dev); |
| 219 | break; |
| 220 | case 'D': |
Bernhard Reutner-Fischer | fc5f318 | 2006-04-12 08:03:11 +0000 | [diff] [blame] | 221 | strncat(pformat, "jx", buf_len); |
Mike Frysinger | 9b5f71e | 2005-04-23 06:26:38 +0000 | [diff] [blame] | 222 | printf(pformat, (uintmax_t) statbuf->st_dev); |
| 223 | break; |
| 224 | case 'i': |
Bernhard Reutner-Fischer | fc5f318 | 2006-04-12 08:03:11 +0000 | [diff] [blame] | 225 | strncat(pformat, "ju", buf_len); |
Mike Frysinger | 9b5f71e | 2005-04-23 06:26:38 +0000 | [diff] [blame] | 226 | printf(pformat, (uintmax_t) statbuf->st_ino); |
| 227 | break; |
| 228 | case 'a': |
| 229 | 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))); |
| 231 | break; |
| 232 | case 'A': |
| 233 | strncat(pformat, "s", buf_len); |
| 234 | printf(pformat, bb_mode_string(statbuf->st_mode)); |
| 235 | break; |
| 236 | case 'f': |
| 237 | strncat(pformat, "lx", buf_len); |
| 238 | printf(pformat, (unsigned long int) statbuf->st_mode); |
| 239 | break; |
| 240 | case 'F': |
| 241 | strncat(pformat, "s", buf_len); |
| 242 | printf(pformat, file_type(statbuf)); |
| 243 | break; |
| 244 | case 'h': |
| 245 | strncat(pformat, "lu", buf_len); |
| 246 | printf(pformat, (unsigned long int) statbuf->st_nlink); |
| 247 | break; |
| 248 | case 'u': |
| 249 | strncat(pformat, "lu", buf_len); |
| 250 | printf(pformat, (unsigned long int) statbuf->st_uid); |
| 251 | break; |
| 252 | case 'U': |
| 253 | strncat(pformat, "s", buf_len); |
| 254 | setpwent(); |
| 255 | pw_ent = getpwuid(statbuf->st_uid); |
| 256 | printf(pformat, (pw_ent != 0L) ? pw_ent->pw_name : "UNKNOWN"); |
| 257 | break; |
| 258 | case 'g': |
| 259 | strncat(pformat, "lu", buf_len); |
| 260 | printf(pformat, (unsigned long int) statbuf->st_gid); |
| 261 | break; |
| 262 | case 'G': |
| 263 | strncat(pformat, "s", buf_len); |
| 264 | setgrent(); |
| 265 | gw_ent = getgrgid(statbuf->st_gid); |
| 266 | printf(pformat, (gw_ent != 0L) ? gw_ent->gr_name : "UNKNOWN"); |
| 267 | break; |
| 268 | case 't': |
| 269 | strncat(pformat, "lx", buf_len); |
| 270 | printf(pformat, (unsigned long int) major(statbuf->st_rdev)); |
| 271 | break; |
| 272 | case 'T': |
| 273 | strncat(pformat, "lx", buf_len); |
| 274 | printf(pformat, (unsigned long int) minor(statbuf->st_rdev)); |
| 275 | break; |
| 276 | case 's': |
Bernhard Reutner-Fischer | fc5f318 | 2006-04-12 08:03:11 +0000 | [diff] [blame] | 277 | strncat(pformat, "ju", buf_len); |
Mike Frysinger | 9b5f71e | 2005-04-23 06:26:38 +0000 | [diff] [blame] | 278 | printf(pformat, (uintmax_t) (statbuf->st_size)); |
| 279 | break; |
| 280 | case 'B': |
| 281 | strncat(pformat, "lu", buf_len); |
| 282 | printf(pformat, (unsigned long int) 512); //ST_NBLOCKSIZE |
| 283 | break; |
| 284 | case 'b': |
Bernhard Reutner-Fischer | fc5f318 | 2006-04-12 08:03:11 +0000 | [diff] [blame] | 285 | strncat(pformat, "ju", buf_len); |
Mike Frysinger | 9b5f71e | 2005-04-23 06:26:38 +0000 | [diff] [blame] | 286 | printf(pformat, (uintmax_t) statbuf->st_blocks); |
| 287 | break; |
| 288 | case 'o': |
| 289 | strncat(pformat, "lu", buf_len); |
| 290 | printf(pformat, (unsigned long int) statbuf->st_blksize); |
| 291 | break; |
| 292 | case 'x': |
| 293 | strncat(pformat, "s", buf_len); |
| 294 | printf(pformat, human_time(statbuf->st_atime)); |
| 295 | break; |
| 296 | case 'X': |
| 297 | strncat(pformat, TYPE_SIGNED(time_t) ? "ld" : "lu", buf_len); |
| 298 | printf(pformat, (unsigned long int) statbuf->st_atime); |
| 299 | break; |
| 300 | case 'y': |
| 301 | strncat(pformat, "s", buf_len); |
| 302 | printf(pformat, human_time(statbuf->st_mtime)); |
| 303 | break; |
| 304 | case 'Y': |
| 305 | strncat(pformat, TYPE_SIGNED(time_t) ? "ld" : "lu", buf_len); |
| 306 | printf(pformat, (unsigned long int) statbuf->st_mtime); |
| 307 | break; |
| 308 | case 'z': |
| 309 | strncat(pformat, "s", buf_len); |
| 310 | printf(pformat, human_time(statbuf->st_ctime)); |
| 311 | break; |
| 312 | case 'Z': |
| 313 | strncat(pformat, TYPE_SIGNED(time_t) ? "ld" : "lu", buf_len); |
| 314 | printf(pformat, (unsigned long int) statbuf->st_ctime); |
| 315 | break; |
Denis Vlasenko | 49622d7 | 2007-03-10 16:58:49 +0000 | [diff] [blame^] | 316 | #if ENABLE_SELINUX |
| 317 | case 'C': |
| 318 | if (flags & OPT_SELINUX) { |
| 319 | strncat(pformat, "s", buf_len); |
| 320 | printf(pformat, scontext); |
| 321 | } |
| 322 | break; |
| 323 | #endif |
Mike Frysinger | 9b5f71e | 2005-04-23 06:26:38 +0000 | [diff] [blame] | 324 | default: |
| 325 | strncat(pformat, "c", buf_len); |
| 326 | printf(pformat, m); |
| 327 | break; |
| 328 | } |
| 329 | } |
| 330 | |
Tim Riker | c1ef7bd | 2006-01-25 00:08:53 +0000 | [diff] [blame] | 331 | static void print_it(char const *masterformat, char const *filename, |
Denis Vlasenko | 49622d7 | 2007-03-10 16:58:49 +0000 | [diff] [blame^] | 332 | void (*print_func) (char *, size_t, char, char const *, void const * |
| 333 | USE_SELINUX(, security_context_t scontext)), |
| 334 | void const *data USE_SELINUX(, security_context_t scontext) ) |
Mike Frysinger | 9b5f71e | 2005-04-23 06:26:38 +0000 | [diff] [blame] | 335 | { |
| 336 | char *b; |
| 337 | |
| 338 | /* create a working copy of the format string */ |
Rob Landley | d921b2e | 2006-08-03 15:41:12 +0000 | [diff] [blame] | 339 | char *format = xstrdup(masterformat); |
Mike Frysinger | 9b5f71e | 2005-04-23 06:26:38 +0000 | [diff] [blame] | 340 | |
Denis Vlasenko | 5d148e2 | 2006-11-21 00:12:09 +0000 | [diff] [blame] | 341 | /* Add 2 to accomodate our conversion of the stat '%s' format string |
| 342 | * to the printf '%llu' one. */ |
Mike Frysinger | 9b5f71e | 2005-04-23 06:26:38 +0000 | [diff] [blame] | 343 | size_t n_alloc = strlen(format) + 2 + 1; |
| 344 | char *dest = xmalloc(n_alloc); |
| 345 | |
| 346 | b = format; |
| 347 | while (b) { |
Denis Vlasenko | 5d148e2 | 2006-11-21 00:12:09 +0000 | [diff] [blame] | 348 | size_t len; |
Mike Frysinger | 9b5f71e | 2005-04-23 06:26:38 +0000 | [diff] [blame] | 349 | char *p = strchr(b, '%'); |
Denis Vlasenko | 5d148e2 | 2006-11-21 00:12:09 +0000 | [diff] [blame] | 350 | if (!p) { |
| 351 | /* coreutils 6.3 always print <cr> at the end */ |
| 352 | /*fputs(b, stdout);*/ |
| 353 | puts(b); |
| 354 | break; |
| 355 | } |
| 356 | *p++ = '\0'; |
| 357 | fputs(b, stdout); |
Mike Frysinger | 9b5f71e | 2005-04-23 06:26:38 +0000 | [diff] [blame] | 358 | |
Denis Vlasenko | 5d148e2 | 2006-11-21 00:12:09 +0000 | [diff] [blame] | 359 | len = strspn(p, "#-+.I 0123456789"); |
| 360 | dest[0] = '%'; |
| 361 | memcpy(dest + 1, p, len); |
| 362 | dest[1 + len] = 0; |
| 363 | p += len; |
Mike Frysinger | 9b5f71e | 2005-04-23 06:26:38 +0000 | [diff] [blame] | 364 | |
Denis Vlasenko | 5d148e2 | 2006-11-21 00:12:09 +0000 | [diff] [blame] | 365 | b = p + 1; |
| 366 | switch (*p) { |
| 367 | case '\0': |
Mike Frysinger | 9b5f71e | 2005-04-23 06:26:38 +0000 | [diff] [blame] | 368 | b = NULL; |
Denis Vlasenko | 5d148e2 | 2006-11-21 00:12:09 +0000 | [diff] [blame] | 369 | /* fall through */ |
| 370 | case '%': |
| 371 | putchar('%'); |
| 372 | break; |
| 373 | default: |
Denis Vlasenko | 49622d7 | 2007-03-10 16:58:49 +0000 | [diff] [blame^] | 374 | print_func(dest, n_alloc, *p, filename, data USE_SELINUX(,scontext)); |
Denis Vlasenko | 5d148e2 | 2006-11-21 00:12:09 +0000 | [diff] [blame] | 375 | break; |
Mike Frysinger | 9b5f71e | 2005-04-23 06:26:38 +0000 | [diff] [blame] | 376 | } |
| 377 | } |
| 378 | |
| 379 | free(format); |
| 380 | free(dest); |
| 381 | } |
| 382 | #endif |
| 383 | |
| 384 | /* Stat the file system and print what we find. */ |
| 385 | static int do_statfs(char const *filename, char const *format) |
| 386 | { |
| 387 | struct statfs statfsbuf; |
| 388 | |
Denis Vlasenko | 49622d7 | 2007-03-10 16:58:49 +0000 | [diff] [blame^] | 389 | #if ENABLE_SELINUX |
| 390 | security_context_t scontext = NULL; |
| 391 | if (flags & OPT_SELINUX) { |
| 392 | if ((flags & OPT_DEREFERENCE ? lgetfilecon(filename, scontext): |
| 393 | getfilecon(filename, scontext))< 0) { |
| 394 | bb_perror_msg(filename); |
| 395 | return 0; |
| 396 | } |
| 397 | } |
| 398 | #endif |
Mike Frysinger | 9b5f71e | 2005-04-23 06:26:38 +0000 | [diff] [blame] | 399 | if (statfs(filename, &statfsbuf) != 0) { |
| 400 | bb_perror_msg("cannot read file system information for '%s'", filename); |
| 401 | return 0; |
| 402 | } |
| 403 | |
| 404 | #ifdef CONFIG_FEATURE_STAT_FORMAT |
| 405 | if (format == NULL) |
Denis Vlasenko | 49622d7 | 2007-03-10 16:58:49 +0000 | [diff] [blame^] | 406 | #ifndef ENABLE_SELINUX |
Mike Frysinger | f06c494 | 2005-04-24 03:53:12 +0000 | [diff] [blame] | 407 | format = (flags & OPT_TERSE |
Mike Frysinger | 726b2cb | 2005-07-26 22:39:56 +0000 | [diff] [blame] | 408 | ? "%n %i %l %t %s %b %f %a %c %d\n" |
Mike Frysinger | 9b5f71e | 2005-04-23 06:26:38 +0000 | [diff] [blame] | 409 | : " File: \"%n\"\n" |
| 410 | " ID: %-8i Namelen: %-7l Type: %T\n" |
Mike Frysinger | 726b2cb | 2005-07-26 22:39:56 +0000 | [diff] [blame] | 411 | "Block size: %-10s\n" |
Mike Frysinger | 9b5f71e | 2005-04-23 06:26:38 +0000 | [diff] [blame] | 412 | "Blocks: Total: %-10b Free: %-10f Available: %a\n" |
Denis Vlasenko | 5d148e2 | 2006-11-21 00:12:09 +0000 | [diff] [blame] | 413 | "Inodes: Total: %-10c Free: %d"); |
Denis Vlasenko | 49622d7 | 2007-03-10 16:58:49 +0000 | [diff] [blame^] | 414 | print_it(format, filename, print_statfs, &statfsbuf USE_SELINUX(, scontext)); |
Mike Frysinger | 9b5f71e | 2005-04-23 06:26:38 +0000 | [diff] [blame] | 415 | #else |
Denis Vlasenko | 49622d7 | 2007-03-10 16:58:49 +0000 | [diff] [blame^] | 416 | format = (flags & OPT_TERSE |
| 417 | ? (flags & 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") |
| 419 | : (flags & OPT_SELINUX ? |
| 420 | " File: \"%n\"\n" |
| 421 | " ID: %-8i Namelen: %-7l Type: %T\n" |
| 422 | "Block size: %-10s\n" |
| 423 | "Blocks: Total: %-10b Free: %-10f Available: %a\n" |
| 424 | "Inodes: Total: %-10c Free: %d" |
| 425 | " S_context: %C\n": |
| 426 | " File: \"%n\"\n" |
| 427 | " ID: %-8i Namelen: %-7l Type: %T\n" |
| 428 | "Block size: %-10s\n" |
| 429 | "Blocks: Total: %-10b Free: %-10f Available: %a\n" |
| 430 | "Inodes: Total: %-10c Free: %d\n") |
| 431 | ); |
| 432 | print_it(format, filename, print_statfs, &statfsbuf USE_SELINUX(, scontext)); |
| 433 | #endif /* SELINUX */ |
| 434 | #else /* FEATURE_STAT_FORMAT */ |
Mike Frysinger | f06c494 | 2005-04-24 03:53:12 +0000 | [diff] [blame] | 435 | format = (flags & OPT_TERSE |
Bernhard Reutner-Fischer | d409c3a | 2006-03-29 22:34:47 +0000 | [diff] [blame] | 436 | ? "%s %llx %lu " |
Mike Frysinger | 9b5f71e | 2005-04-23 06:26:38 +0000 | [diff] [blame] | 437 | : " File: \"%s\"\n" |
| 438 | " ID: %-8Lx Namelen: %-7lu "); |
| 439 | printf(format, |
| 440 | filename, |
| 441 | statfsbuf.f_fsid, |
| 442 | statfsbuf.f_namelen); |
| 443 | |
Mike Frysinger | f06c494 | 2005-04-24 03:53:12 +0000 | [diff] [blame] | 444 | if (flags & OPT_TERSE) |
Mike Frysinger | 9b5f71e | 2005-04-23 06:26:38 +0000 | [diff] [blame] | 445 | printf("%lx ", (unsigned long int) (statfsbuf.f_type)); |
| 446 | else |
| 447 | printf("Type: %s\n", human_fstype(statfsbuf.f_type)); |
| 448 | |
Denis Vlasenko | 49622d7 | 2007-03-10 16:58:49 +0000 | [diff] [blame^] | 449 | #if !ENABLE_SELINUX |
Mike Frysinger | f06c494 | 2005-04-24 03:53:12 +0000 | [diff] [blame] | 450 | format = (flags & OPT_TERSE |
Mike Frysinger | 726b2cb | 2005-07-26 22:39:56 +0000 | [diff] [blame] | 451 | ? "%lu %ld %ld %ld %ld %ld\n" |
| 452 | : "Block size: %-10lu\n" |
Bernhard Reutner-Fischer | fc5f318 | 2006-04-12 08:03:11 +0000 | [diff] [blame] | 453 | "Blocks: Total: %-10jd Free: %-10jd Available: %jd\n" |
| 454 | "Inodes: Total: %-10jd Free: %jd\n"); |
Mike Frysinger | 9b5f71e | 2005-04-23 06:26:38 +0000 | [diff] [blame] | 455 | printf(format, |
| 456 | (unsigned long int) (statfsbuf.f_bsize), |
Mike Frysinger | 9b5f71e | 2005-04-23 06:26:38 +0000 | [diff] [blame] | 457 | (intmax_t) (statfsbuf.f_blocks), |
| 458 | (intmax_t) (statfsbuf.f_bfree), |
| 459 | (intmax_t) (statfsbuf.f_bavail), |
| 460 | (intmax_t) (statfsbuf.f_files), |
| 461 | (intmax_t) (statfsbuf.f_ffree)); |
Denis Vlasenko | 49622d7 | 2007-03-10 16:58:49 +0000 | [diff] [blame^] | 462 | #else |
| 463 | format = (flags & OPT_TERSE |
| 464 | ? (flags & OPT_SELINUX ? "%lu %ld %ld %ld %ld %ld %C\n": |
| 465 | "%lu %ld %ld %ld %ld %ld\n") |
| 466 | : (flags & OPT_SELINUX ? |
| 467 | "Block size: %-10lu\n" |
| 468 | "Blocks: Total: %-10jd Free: %-10jd Available: %jd\n" |
| 469 | "Inodes: Total: %-10jd Free: %jd" |
| 470 | "S_context: %C\n": |
| 471 | "Block size: %-10lu\n" |
| 472 | "Blocks: Total: %-10jd Free: %-10jd Available: %jd\n" |
| 473 | "Inodes: Total: %-10jd Free: %jd\n")); |
| 474 | printf(format, |
| 475 | (unsigned long int) (statfsbuf.f_bsize), |
| 476 | (intmax_t) (statfsbuf.f_blocks), |
| 477 | (intmax_t) (statfsbuf.f_bfree), |
| 478 | (intmax_t) (statfsbuf.f_bavail), |
| 479 | (intmax_t) (statfsbuf.f_files), |
| 480 | (intmax_t) (statfsbuf.f_ffree), |
| 481 | scontext); |
Mike Frysinger | 9b5f71e | 2005-04-23 06:26:38 +0000 | [diff] [blame] | 482 | |
Denis Vlasenko | 49622d7 | 2007-03-10 16:58:49 +0000 | [diff] [blame^] | 483 | if (scontext) |
| 484 | freecon(scontext); |
| 485 | #endif |
| 486 | #endif /* FEATURE_STAT_FORMAT */ |
Mike Frysinger | 9b5f71e | 2005-04-23 06:26:38 +0000 | [diff] [blame] | 487 | return 1; |
| 488 | } |
| 489 | |
| 490 | /* stat the file and print what we find */ |
| 491 | static int do_stat(char const *filename, char const *format) |
| 492 | { |
| 493 | struct stat statbuf; |
Denis Vlasenko | 49622d7 | 2007-03-10 16:58:49 +0000 | [diff] [blame^] | 494 | #if ENABLE_SELINUX |
| 495 | security_context_t scontext = NULL; |
| 496 | if (flags & OPT_SELINUX) { |
| 497 | if ((flags & OPT_DEREFERENCE ? lgetfilecon(filename, scontext): |
| 498 | getfilecon(filename, scontext))< 0) { |
| 499 | bb_perror_msg (filename); |
| 500 | return 0; |
| 501 | } |
| 502 | } |
| 503 | #endif |
Bernhard Reutner-Fischer | 18260d5 | 2006-04-18 14:17:49 +0000 | [diff] [blame] | 504 | if ((flags & OPT_DEREFERENCE ? stat : lstat) (filename, &statbuf) != 0) { |
Mike Frysinger | 9b5f71e | 2005-04-23 06:26:38 +0000 | [diff] [blame] | 505 | bb_perror_msg("cannot stat '%s'", filename); |
| 506 | return 0; |
| 507 | } |
| 508 | |
| 509 | #ifdef CONFIG_FEATURE_STAT_FORMAT |
| 510 | if (format == NULL) { |
Denis Vlasenko | 49622d7 | 2007-03-10 16:58:49 +0000 | [diff] [blame^] | 511 | #ifndef ENABLE_SELINUX |
Mike Frysinger | f06c494 | 2005-04-24 03:53:12 +0000 | [diff] [blame] | 512 | if (flags & OPT_TERSE) { |
Denis Vlasenko | 5d148e2 | 2006-11-21 00:12:09 +0000 | [diff] [blame] | 513 | format = "%n %s %b %f %u %g %D %i %h %t %T %X %Y %Z %o"; |
Mike Frysinger | 9b5f71e | 2005-04-23 06:26:38 +0000 | [diff] [blame] | 514 | } else { |
| 515 | if (S_ISBLK(statbuf.st_mode) || S_ISCHR(statbuf.st_mode)) { |
| 516 | format = |
| 517 | " File: \"%N\"\n" |
| 518 | " Size: %-10s\tBlocks: %-10b IO Block: %-6o %F\n" |
| 519 | "Device: %Dh/%dd\tInode: %-10i Links: %-5h" |
| 520 | " Device type: %t,%T\n" |
| 521 | "Access: (%04a/%10.10A) Uid: (%5u/%8U) Gid: (%5g/%8G)\n" |
| 522 | "Access: %x\n" "Modify: %y\n" "Change: %z\n"; |
| 523 | } else { |
| 524 | format = |
| 525 | " File: \"%N\"\n" |
| 526 | " Size: %-10s\tBlocks: %-10b IO Block: %-6o %F\n" |
| 527 | "Device: %Dh/%dd\tInode: %-10i Links: %h\n" |
| 528 | "Access: (%04a/%10.10A) Uid: (%5u/%8U) Gid: (%5g/%8G)\n" |
| 529 | "Access: %x\n" "Modify: %y\n" "Change: %z\n"; |
| 530 | } |
| 531 | } |
Mike Frysinger | 9b5f71e | 2005-04-23 06:26:38 +0000 | [diff] [blame] | 532 | #else |
Denis Vlasenko | 49622d7 | 2007-03-10 16:58:49 +0000 | [diff] [blame^] | 533 | if (flags & OPT_TERSE) { |
| 534 | format = (flags & OPT_SELINUX ? |
| 535 | "%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"); |
| 537 | } else { |
| 538 | if (S_ISBLK(statbuf.st_mode) || S_ISCHR(statbuf.st_mode)) { |
| 539 | format = (flags & OPT_SELINUX ? |
| 540 | " File: \"%N\"\n" |
| 541 | " Size: %-10s\tBlocks: %-10b IO Block: %-6o %F\n" |
| 542 | "Device: %Dh/%dd\tInode: %-10i Links: %-5h" |
| 543 | " Device type: %t,%T\n" |
| 544 | "Access: (%04a/%10.10A) Uid: (%5u/%8U) Gid: (%5g/%8G)\n" |
| 545 | " S_Context: %C\n" |
| 546 | "Access: %x\n" "Modify: %y\n" "Change: %z\n": |
| 547 | " File: \"%N\"\n" |
| 548 | " Size: %-10s\tBlocks: %-10b IO Block: %-6o %F\n" |
| 549 | "Device: %Dh/%dd\tInode: %-10i Links: %-5h" |
| 550 | " Device type: %t,%T\n" |
| 551 | "Access: (%04a/%10.10A) Uid: (%5u/%8U) Gid: (%5g/%8G)\n" |
| 552 | "Access: %x\n" "Modify: %y\n" "Change: %z\n"); |
| 553 | } else { |
| 554 | format = (flags & OPT_SELINUX ? |
| 555 | " File: \"%N\"\n" |
| 556 | " Size: %-10s\tBlocks: %-10b IO Block: %-6o %F\n" |
| 557 | "Device: %Dh/%dd\tInode: %-10i Links: %h\n" |
| 558 | "Access: (%04a/%10.10A) Uid: (%5u/%8U) Gid: (%5g/%8G)\n" |
| 559 | "S_Context: %C\n" |
| 560 | "Access: %x\n" "Modify: %y\n" "Change: %z\n": |
| 561 | " File: \"%N\"\n" |
| 562 | " Size: %-10s\tBlocks: %-10b IO Block: %-6o %F\n" |
| 563 | "Device: %Dh/%dd\tInode: %-10i Links: %h\n" |
| 564 | "Access: (%04a/%10.10A) Uid: (%5u/%8U) Gid: (%5g/%8G)\n" |
| 565 | "Access: %x\n" "Modify: %y\n" "Change: %z\n"); |
| 566 | } |
| 567 | } |
| 568 | #endif |
| 569 | } |
| 570 | print_it(format, filename, print_stat, &statbuf USE_SELINUX(, scontext)); |
| 571 | #else /* FEATURE_STAT_FORMAT */ |
Mike Frysinger | f06c494 | 2005-04-24 03:53:12 +0000 | [diff] [blame] | 572 | if (flags & OPT_TERSE) { |
Denis Vlasenko | 49622d7 | 2007-03-10 16:58:49 +0000 | [diff] [blame^] | 573 | printf("%s %ju %ju %lx %lu %lu %jx %ju %lu %lx %lx %lu %lu %lu %lu" |
| 574 | SKIP_SELINUX("\n"), |
Mike Frysinger | 9b5f71e | 2005-04-23 06:26:38 +0000 | [diff] [blame] | 575 | filename, |
| 576 | (uintmax_t) (statbuf.st_size), |
| 577 | (uintmax_t) statbuf.st_blocks, |
| 578 | (unsigned long int) statbuf.st_mode, |
| 579 | (unsigned long int) statbuf.st_uid, |
| 580 | (unsigned long int) statbuf.st_gid, |
| 581 | (uintmax_t) statbuf.st_dev, |
| 582 | (uintmax_t) statbuf.st_ino, |
| 583 | (unsigned long int) statbuf.st_nlink, |
| 584 | (unsigned long int) major(statbuf.st_rdev), |
| 585 | (unsigned long int) minor(statbuf.st_rdev), |
| 586 | (unsigned long int) statbuf.st_atime, |
| 587 | (unsigned long int) statbuf.st_mtime, |
| 588 | (unsigned long int) statbuf.st_ctime, |
| 589 | (unsigned long int) statbuf.st_blksize |
| 590 | ); |
Denis Vlasenko | 49622d7 | 2007-03-10 16:58:49 +0000 | [diff] [blame^] | 591 | #if ENABLE_SELINUX |
| 592 | if (flags & OPT_SELINUX) |
| 593 | printf(" %lc\n", *scontext); |
| 594 | else |
| 595 | putchar('\n'); |
| 596 | #endif |
Mike Frysinger | 9b5f71e | 2005-04-23 06:26:38 +0000 | [diff] [blame] | 597 | } else { |
| 598 | char *linkname = NULL; |
| 599 | |
| 600 | struct passwd *pw_ent; |
| 601 | struct group *gw_ent; |
| 602 | setgrent(); |
| 603 | gw_ent = getgrgid(statbuf.st_gid); |
| 604 | setpwent(); |
| 605 | pw_ent = getpwuid(statbuf.st_uid); |
| 606 | |
| 607 | if (S_ISLNK(statbuf.st_mode)) |
Denis Vlasenko | 6ca0444 | 2007-02-11 16:19:28 +0000 | [diff] [blame] | 608 | linkname = xmalloc_readlink_or_warn(filename); |
Mike Frysinger | 9b5f71e | 2005-04-23 06:26:38 +0000 | [diff] [blame] | 609 | if (linkname) |
| 610 | printf(" File: \"%s\" -> \"%s\"\n", filename, linkname); |
| 611 | else |
| 612 | printf(" File: \"%s\"\n", filename); |
| 613 | |
Bernhard Reutner-Fischer | fc5f318 | 2006-04-12 08:03:11 +0000 | [diff] [blame] | 614 | printf(" Size: %-10ju\tBlocks: %-10ju IO Block: %-6lu %s\n" |
| 615 | "Device: %jxh/%jud\tInode: %-10ju Links: %-5lu", |
Mike Frysinger | 9b5f71e | 2005-04-23 06:26:38 +0000 | [diff] [blame] | 616 | (uintmax_t) (statbuf.st_size), |
| 617 | (uintmax_t) statbuf.st_blocks, |
| 618 | (unsigned long int) statbuf.st_blksize, |
| 619 | file_type(&statbuf), |
| 620 | (uintmax_t) statbuf.st_dev, |
| 621 | (uintmax_t) statbuf.st_dev, |
| 622 | (uintmax_t) statbuf.st_ino, |
| 623 | (unsigned long int) statbuf.st_nlink); |
| 624 | if (S_ISBLK(statbuf.st_mode) || S_ISCHR(statbuf.st_mode)) |
| 625 | printf(" Device type: %lx,%lx\n", |
| 626 | (unsigned long int) major(statbuf.st_rdev), |
| 627 | (unsigned long int) minor(statbuf.st_rdev)); |
| 628 | else |
| 629 | putchar('\n'); |
Denis Vlasenko | 49622d7 | 2007-03-10 16:58:49 +0000 | [diff] [blame^] | 630 | printf("Access: (%04lo/%10.10s) Uid: (%5lu/%8s) Gid: (%5lu/%8s)\n", |
Mike Frysinger | 9b5f71e | 2005-04-23 06:26:38 +0000 | [diff] [blame] | 631 | (unsigned long int) (statbuf.st_mode & (S_ISUID|S_ISGID|S_ISVTX|S_IRWXU|S_IRWXG|S_IRWXO)), |
| 632 | bb_mode_string(statbuf.st_mode), |
| 633 | (unsigned long int) statbuf.st_uid, |
| 634 | (pw_ent != 0L) ? pw_ent->pw_name : "UNKNOWN", |
| 635 | (unsigned long int) statbuf.st_gid, |
Denis Vlasenko | 49622d7 | 2007-03-10 16:58:49 +0000 | [diff] [blame^] | 636 | (gw_ent != 0L) ? gw_ent->gr_name : "UNKNOWN"); |
| 637 | #if ENABLE_SELINUX |
| 638 | printf(" S_Context: %lc\n", *scontext); |
| 639 | #endif |
| 640 | printf("Access: %s\n" "Modify: %s\n" "Change: %s\n", |
Mike Frysinger | 9b5f71e | 2005-04-23 06:26:38 +0000 | [diff] [blame] | 641 | human_time(statbuf.st_atime), |
| 642 | human_time(statbuf.st_mtime), |
| 643 | human_time(statbuf.st_ctime)); |
| 644 | } |
Denis Vlasenko | 49622d7 | 2007-03-10 16:58:49 +0000 | [diff] [blame^] | 645 | #endif /* FEATURE_STAT_FORMAT */ |
Mike Frysinger | 9b5f71e | 2005-04-23 06:26:38 +0000 | [diff] [blame] | 646 | return 1; |
| 647 | } |
| 648 | |
Denis Vlasenko | 06af216 | 2007-02-03 17:28:39 +0000 | [diff] [blame] | 649 | int stat_main(int argc, char **argv); |
Mike Frysinger | 9b5f71e | 2005-04-23 06:26:38 +0000 | [diff] [blame] | 650 | int stat_main(int argc, char **argv) |
| 651 | { |
| 652 | int i; |
| 653 | char *format = NULL; |
| 654 | int ok = 1; |
Mike Frysinger | 9b5f71e | 2005-04-23 06:26:38 +0000 | [diff] [blame] | 655 | int (*statfunc)(char const *, char const *) = do_stat; |
| 656 | |
Denis Vlasenko | 67b23e6 | 2006-10-03 21:00:06 +0000 | [diff] [blame] | 657 | flags = getopt32(argc, argv, "ftL" |
Denis Vlasenko | 49622d7 | 2007-03-10 16:58:49 +0000 | [diff] [blame^] | 658 | USE_SELINUX("Z") |
Denis Vlasenko | 5d148e2 | 2006-11-21 00:12:09 +0000 | [diff] [blame] | 659 | USE_FEATURE_STAT_FORMAT("c:", &format) |
Mike Frysinger | 9b5f71e | 2005-04-23 06:26:38 +0000 | [diff] [blame] | 660 | ); |
| 661 | |
| 662 | if (flags & 1) /* -f */ |
| 663 | statfunc = do_statfs; |
Mike Frysinger | 9b5f71e | 2005-04-23 06:26:38 +0000 | [diff] [blame] | 664 | if (argc == optind) /* files */ |
| 665 | bb_show_usage(); |
| 666 | |
Denis Vlasenko | 49622d7 | 2007-03-10 16:58:49 +0000 | [diff] [blame^] | 667 | #if ENABLE_SELINUX |
| 668 | if (flags & OPT_SELINUX) { |
| 669 | selinux_or_die(); |
| 670 | } |
| 671 | #endif /* ENABLE_SELINUX */ |
Mike Frysinger | 9b5f71e | 2005-04-23 06:26:38 +0000 | [diff] [blame] | 672 | for (i = optind; i < argc; ++i) |
| 673 | ok &= statfunc(argv[i], format); |
| 674 | |
| 675 | return (ok ? EXIT_SUCCESS : EXIT_FAILURE); |
| 676 | } |