"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 | * |
Denys Vlasenko | 0ef64bd | 2010-08-16 20:14:46 +0200 | [diff] [blame] | 13 | * Licensed under GPLv2 or later, see file LICENSE in this source tree. |
Mike Frysinger | 9b5f71e | 2005-04-23 06:26:38 +0000 | [diff] [blame] | 14 | */ |
Pere Orga | 3442538 | 2011-03-31 14:43:25 +0200 | [diff] [blame] | 15 | |
| 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" |
Pere Orga | 3442538 | 2011-03-31 14:43:25 +0200 | [diff] [blame] | 20 | //usage: IF_FEATURE_STAT_FORMAT( |
| 21 | //usage: "\n -c fmt Use the specified format" |
| 22 | //usage: ) |
| 23 | //usage: "\n -f Display filesystem status" |
| 24 | //usage: "\n -L Follow links" |
| 25 | //usage: "\n -t Display info in terse form" |
| 26 | //usage: IF_SELINUX( |
| 27 | //usage: "\n -Z Print security context" |
| 28 | //usage: ) |
| 29 | //usage: IF_FEATURE_STAT_FORMAT( |
| 30 | //usage: "\n\nValid format sequences for files:\n" |
| 31 | //usage: " %a Access rights in octal\n" |
| 32 | //usage: " %A Access rights in human readable form\n" |
| 33 | //usage: " %b Number of blocks allocated (see %B)\n" |
| 34 | //usage: " %B The size in bytes of each block reported by %b\n" |
| 35 | //usage: " %d Device number in decimal\n" |
| 36 | //usage: " %D Device number in hex\n" |
| 37 | //usage: " %f Raw mode in hex\n" |
| 38 | //usage: " %F File type\n" |
| 39 | //usage: " %g Group ID of owner\n" |
| 40 | //usage: " %G Group name of owner\n" |
| 41 | //usage: " %h Number of hard links\n" |
| 42 | //usage: " %i Inode number\n" |
| 43 | //usage: " %n File name\n" |
| 44 | //usage: " %N File name, with -> TARGET if symlink\n" |
| 45 | //usage: " %o I/O block size\n" |
| 46 | //usage: " %s Total size, in bytes\n" |
| 47 | //usage: " %t Major device type in hex\n" |
| 48 | //usage: " %T Minor device type in hex\n" |
| 49 | //usage: " %u User ID of owner\n" |
| 50 | //usage: " %U User name of owner\n" |
| 51 | //usage: " %x Time of last access\n" |
| 52 | //usage: " %X Time of last access as seconds since Epoch\n" |
| 53 | //usage: " %y Time of last modification\n" |
| 54 | //usage: " %Y Time of last modification as seconds since Epoch\n" |
| 55 | //usage: " %z Time of last change\n" |
| 56 | //usage: " %Z Time of last change as seconds since Epoch\n" |
| 57 | //usage: "\nValid format sequences for file systems:\n" |
| 58 | //usage: " %a Free blocks available to non-superuser\n" |
| 59 | //usage: " %b Total data blocks in file system\n" |
| 60 | //usage: " %c Total file nodes in file system\n" |
| 61 | //usage: " %d Free file nodes in file system\n" |
| 62 | //usage: " %f Free blocks in file system\n" |
| 63 | //usage: IF_SELINUX( |
| 64 | //usage: " %C Security context in selinux\n" |
| 65 | //usage: ) |
| 66 | //usage: " %i File System ID in hex\n" |
| 67 | //usage: " %l Maximum length of filenames\n" |
| 68 | //usage: " %n File name\n" |
| 69 | //usage: " %s Block size (for faster transfer)\n" |
| 70 | //usage: " %S Fundamental block size (for block counts)\n" |
| 71 | //usage: " %t Type in hex\n" |
| 72 | //usage: " %T Type in human readable form" |
| 73 | //usage: ) |
| 74 | |
Denis Vlasenko | b6adbf1 | 2007-05-26 19:00:18 +0000 | [diff] [blame] | 75 | #include "libbb.h" |
Mike Frysinger | 9b5f71e | 2005-04-23 06:26:38 +0000 | [diff] [blame] | 76 | |
Denis Vlasenko | 91e5203 | 2007-10-05 20:31:23 +0000 | [diff] [blame] | 77 | #define OPT_FILESYS (1 << 0) |
| 78 | #define OPT_TERSE (1 << 1) |
| 79 | #define OPT_DEREFERENCE (1 << 2) |
| 80 | #define OPT_SELINUX (1 << 3) |
Mike Frysinger | 9b5f71e | 2005-04-23 06:26:38 +0000 | [diff] [blame] | 81 | |
Denis Vlasenko | 85c2471 | 2008-03-17 09:04:04 +0000 | [diff] [blame] | 82 | #if ENABLE_FEATURE_STAT_FORMAT |
| 83 | typedef bool (*statfunc_ptr)(const char *, const char *); |
| 84 | #else |
| 85 | typedef bool (*statfunc_ptr)(const char *); |
| 86 | #endif |
| 87 | |
Denis Vlasenko | 91e5203 | 2007-10-05 20:31:23 +0000 | [diff] [blame] | 88 | static const char *file_type(const struct stat *st) |
Mike Frysinger | 9b5f71e | 2005-04-23 06:26:38 +0000 | [diff] [blame] | 89 | { |
Tim Riker | c1ef7bd | 2006-01-25 00:08:53 +0000 | [diff] [blame] | 90 | /* See POSIX 1003.1-2001 XCU Table 4-8 lines 17093-17107 |
Mike Frysinger | 9b5f71e | 2005-04-23 06:26:38 +0000 | [diff] [blame] | 91 | * for some of these formats. |
Tim Riker | c1ef7bd | 2006-01-25 00:08:53 +0000 | [diff] [blame] | 92 | * To keep diagnostics grammatical in English, the |
Mike Frysinger | 9b5f71e | 2005-04-23 06:26:38 +0000 | [diff] [blame] | 93 | * returned string must start with a consonant. |
| 94 | */ |
| 95 | if (S_ISREG(st->st_mode)) return st->st_size == 0 ? "regular empty file" : "regular file"; |
| 96 | if (S_ISDIR(st->st_mode)) return "directory"; |
| 97 | if (S_ISBLK(st->st_mode)) return "block special file"; |
| 98 | if (S_ISCHR(st->st_mode)) return "character special file"; |
| 99 | if (S_ISFIFO(st->st_mode)) return "fifo"; |
| 100 | if (S_ISLNK(st->st_mode)) return "symbolic link"; |
| 101 | if (S_ISSOCK(st->st_mode)) return "socket"; |
| 102 | if (S_TYPEISMQ(st)) return "message queue"; |
| 103 | if (S_TYPEISSEM(st)) return "semaphore"; |
| 104 | if (S_TYPEISSHM(st)) return "shared memory object"; |
| 105 | #ifdef S_TYPEISTMO |
| 106 | if (S_TYPEISTMO(st)) return "typed memory object"; |
| 107 | #endif |
| 108 | return "weird file"; |
| 109 | } |
| 110 | |
Denis Vlasenko | 91e5203 | 2007-10-05 20:31:23 +0000 | [diff] [blame] | 111 | static const char *human_time(time_t t) |
Mike Frysinger | 9b5f71e | 2005-04-23 06:26:38 +0000 | [diff] [blame] | 112 | { |
Denis Vlasenko | 5d148e2 | 2006-11-21 00:12:09 +0000 | [diff] [blame] | 113 | /* Old |
Mike Frysinger | 9b5f71e | 2005-04-23 06:26:38 +0000 | [diff] [blame] | 114 | static char *str; |
| 115 | str = ctime(&t); |
| 116 | str[strlen(str)-1] = '\0'; |
| 117 | return str; |
Denis Vlasenko | 5d148e2 | 2006-11-21 00:12:09 +0000 | [diff] [blame] | 118 | */ |
| 119 | /* coreutils 6.3 compat: */ |
Bernhard Reutner-Fischer | 0e6ab01 | 2007-04-04 13:58:33 +0000 | [diff] [blame] | 120 | |
Denis Vlasenko | 91e5203 | 2007-10-05 20:31:23 +0000 | [diff] [blame] | 121 | /*static char buf[sizeof("YYYY-MM-DD HH:MM:SS.000000000")] ALIGN1;*/ |
| 122 | #define buf bb_common_bufsiz1 |
| 123 | |
Denis Vlasenko | 5d148e2 | 2006-11-21 00:12:09 +0000 | [diff] [blame] | 124 | strftime(buf, sizeof(buf), "%Y-%m-%d %H:%M:%S.000000000", localtime(&t)); |
| 125 | return buf; |
Denis Vlasenko | 91e5203 | 2007-10-05 20:31:23 +0000 | [diff] [blame] | 126 | #undef buf |
Mike Frysinger | 9b5f71e | 2005-04-23 06:26:38 +0000 | [diff] [blame] | 127 | } |
| 128 | |
| 129 | /* Return the type of the specified file system. |
| 130 | * Some systems have statfvs.f_basetype[FSTYPSZ]. (AIX, HP-UX, and Solaris) |
| 131 | * Others have statfs.f_fstypename[MFSNAMELEN]. (NetBSD 1.5.2) |
| 132 | * Still others have neither and have to get by with f_type (Linux). |
| 133 | */ |
Denis Vlasenko | 91e5203 | 2007-10-05 20:31:23 +0000 | [diff] [blame] | 134 | static const char *human_fstype(uint32_t f_type) |
Mike Frysinger | 9b5f71e | 2005-04-23 06:26:38 +0000 | [diff] [blame] | 135 | { |
Denis Vlasenko | 240a1cf | 2007-04-08 16:07:02 +0000 | [diff] [blame] | 136 | static const struct types { |
Denis Vlasenko | 91e5203 | 2007-10-05 20:31:23 +0000 | [diff] [blame] | 137 | uint32_t type; |
Denis Vlasenko | 6ca409e | 2007-08-12 20:58:27 +0000 | [diff] [blame] | 138 | const char *const fs; |
Mike Frysinger | 408ae21 | 2005-04-24 04:11:44 +0000 | [diff] [blame] | 139 | } humantypes[] = { |
| 140 | { 0xADFF, "affs" }, |
| 141 | { 0x1Cd1, "devpts" }, |
| 142 | { 0x137D, "ext" }, |
| 143 | { 0xEF51, "ext2" }, |
| 144 | { 0xEF53, "ext2/ext3" }, |
| 145 | { 0x3153464a, "jfs" }, |
| 146 | { 0x58465342, "xfs" }, |
| 147 | { 0xF995E849, "hpfs" }, |
| 148 | { 0x9660, "isofs" }, |
| 149 | { 0x4000, "isofs" }, |
| 150 | { 0x4004, "isofs" }, |
| 151 | { 0x137F, "minix" }, |
| 152 | { 0x138F, "minix (30 char.)" }, |
| 153 | { 0x2468, "minix v2" }, |
| 154 | { 0x2478, "minix v2 (30 char.)" }, |
| 155 | { 0x4d44, "msdos" }, |
| 156 | { 0x4006, "fat" }, |
| 157 | { 0x564c, "novell" }, |
| 158 | { 0x6969, "nfs" }, |
| 159 | { 0x9fa0, "proc" }, |
| 160 | { 0x517B, "smb" }, |
| 161 | { 0x012FF7B4, "xenix" }, |
| 162 | { 0x012FF7B5, "sysv4" }, |
| 163 | { 0x012FF7B6, "sysv2" }, |
| 164 | { 0x012FF7B7, "coh" }, |
| 165 | { 0x00011954, "ufs" }, |
| 166 | { 0x012FD16D, "xia" }, |
| 167 | { 0x5346544e, "ntfs" }, |
| 168 | { 0x1021994, "tmpfs" }, |
| 169 | { 0x52654973, "reiserfs" }, |
| 170 | { 0x28cd3d45, "cramfs" }, |
| 171 | { 0x7275, "romfs" }, |
| 172 | { 0x858458f6, "romfs" }, |
| 173 | { 0x73717368, "squashfs" }, |
| 174 | { 0x62656572, "sysfs" }, |
Rob Landley | 0a7c8ef | 2006-02-22 17:01:00 +0000 | [diff] [blame] | 175 | { 0, "UNKNOWN" } |
Mike Frysinger | 408ae21 | 2005-04-24 04:11:44 +0000 | [diff] [blame] | 176 | }; |
Denis Vlasenko | 91e5203 | 2007-10-05 20:31:23 +0000 | [diff] [blame] | 177 | |
| 178 | int i; |
| 179 | |
Denis Vlasenko | 240a1cf | 2007-04-08 16:07:02 +0000 | [diff] [blame] | 180 | for (i = 0; humantypes[i].type; ++i) |
Mike Frysinger | 408ae21 | 2005-04-24 04:11:44 +0000 | [diff] [blame] | 181 | if (humantypes[i].type == f_type) |
Rob Landley | 0a7c8ef | 2006-02-22 17:01:00 +0000 | [diff] [blame] | 182 | break; |
Mike Frysinger | 408ae21 | 2005-04-24 04:11:44 +0000 | [diff] [blame] | 183 | return humantypes[i].fs; |
Mike Frysinger | 9b5f71e | 2005-04-23 06:26:38 +0000 | [diff] [blame] | 184 | } |
| 185 | |
Denis Vlasenko | 98f5cdf | 2008-11-11 22:25:34 +0000 | [diff] [blame] | 186 | /* "man statfs" says that statfsbuf->f_fsid is a mess */ |
| 187 | /* coreutils treats it as an array of ints, most significant first */ |
| 188 | static unsigned long long get_f_fsid(const struct statfs *statfsbuf) |
| 189 | { |
| 190 | const unsigned *p = (const void*) &statfsbuf->f_fsid; |
| 191 | unsigned sz = sizeof(statfsbuf->f_fsid) / sizeof(unsigned); |
| 192 | unsigned long long r = 0; |
| 193 | |
| 194 | do |
| 195 | r = (r << (sizeof(unsigned)*8)) | *p++; |
| 196 | while (--sz > 0); |
| 197 | return r; |
| 198 | } |
| 199 | |
Denis Vlasenko | 86c285d | 2008-11-13 21:53:32 +0000 | [diff] [blame] | 200 | #if ENABLE_FEATURE_STAT_FORMAT |
| 201 | static void strcatc(char *str, char c) |
| 202 | { |
| 203 | int len = strlen(str); |
| 204 | str[len++] = c; |
| 205 | str[len] = '\0'; |
| 206 | } |
| 207 | |
| 208 | static void printfs(char *pformat, const char *msg) |
| 209 | { |
| 210 | strcatc(pformat, 's'); |
| 211 | printf(pformat, msg); |
| 212 | } |
| 213 | |
Mike Frysinger | 9b5f71e | 2005-04-23 06:26:38 +0000 | [diff] [blame] | 214 | /* print statfs info */ |
Denys Vlasenko | 5b9b136 | 2010-02-02 03:08:57 +0100 | [diff] [blame] | 215 | static void FAST_FUNC print_statfs(char *pformat, const char m, |
Denis Vlasenko | 91e5203 | 2007-10-05 20:31:23 +0000 | [diff] [blame] | 216 | const char *const filename, const void *data |
Denis Vlasenko | 5e34ff2 | 2009-04-21 11:09:40 +0000 | [diff] [blame] | 217 | IF_SELINUX(, security_context_t scontext)) |
Mike Frysinger | 9b5f71e | 2005-04-23 06:26:38 +0000 | [diff] [blame] | 218 | { |
Denis Vlasenko | 91e5203 | 2007-10-05 20:31:23 +0000 | [diff] [blame] | 219 | const struct statfs *statfsbuf = data; |
Bernhard Reutner-Fischer | 0e6ab01 | 2007-04-04 13:58:33 +0000 | [diff] [blame] | 220 | if (m == 'n') { |
Denis Vlasenko | 91e5203 | 2007-10-05 20:31:23 +0000 | [diff] [blame] | 221 | printfs(pformat, filename); |
Bernhard Reutner-Fischer | 0e6ab01 | 2007-04-04 13:58:33 +0000 | [diff] [blame] | 222 | } else if (m == 'i') { |
Denis Vlasenko | 98f5cdf | 2008-11-11 22:25:34 +0000 | [diff] [blame] | 223 | strcat(pformat, "llx"); |
| 224 | printf(pformat, get_f_fsid(statfsbuf)); |
Bernhard Reutner-Fischer | 0e6ab01 | 2007-04-04 13:58:33 +0000 | [diff] [blame] | 225 | } else if (m == 'l') { |
Denis Vlasenko | 91e5203 | 2007-10-05 20:31:23 +0000 | [diff] [blame] | 226 | strcat(pformat, "lu"); |
Denys Vlasenko | 5b9b136 | 2010-02-02 03:08:57 +0100 | [diff] [blame] | 227 | printf(pformat, (unsigned long) statfsbuf->f_namelen); |
Bernhard Reutner-Fischer | 0e6ab01 | 2007-04-04 13:58:33 +0000 | [diff] [blame] | 228 | } else if (m == 't') { |
Denis Vlasenko | 91e5203 | 2007-10-05 20:31:23 +0000 | [diff] [blame] | 229 | strcat(pformat, "lx"); |
Denys Vlasenko | 5b9b136 | 2010-02-02 03:08:57 +0100 | [diff] [blame] | 230 | printf(pformat, (unsigned long) statfsbuf->f_type); /* no equiv */ |
Bernhard Reutner-Fischer | 0e6ab01 | 2007-04-04 13:58:33 +0000 | [diff] [blame] | 231 | } else if (m == 'T') { |
Denis Vlasenko | 91e5203 | 2007-10-05 20:31:23 +0000 | [diff] [blame] | 232 | printfs(pformat, human_fstype(statfsbuf->f_type)); |
Bernhard Reutner-Fischer | 0e6ab01 | 2007-04-04 13:58:33 +0000 | [diff] [blame] | 233 | } else if (m == 'b') { |
Denys Vlasenko | 5b9b136 | 2010-02-02 03:08:57 +0100 | [diff] [blame] | 234 | strcat(pformat, "llu"); |
| 235 | printf(pformat, (unsigned long long) statfsbuf->f_blocks); |
Bernhard Reutner-Fischer | 0e6ab01 | 2007-04-04 13:58:33 +0000 | [diff] [blame] | 236 | } else if (m == 'f') { |
Denys Vlasenko | 5b9b136 | 2010-02-02 03:08:57 +0100 | [diff] [blame] | 237 | strcat(pformat, "llu"); |
| 238 | printf(pformat, (unsigned long long) statfsbuf->f_bfree); |
Bernhard Reutner-Fischer | 0e6ab01 | 2007-04-04 13:58:33 +0000 | [diff] [blame] | 239 | } else if (m == 'a') { |
Denys Vlasenko | 5b9b136 | 2010-02-02 03:08:57 +0100 | [diff] [blame] | 240 | strcat(pformat, "llu"); |
| 241 | printf(pformat, (unsigned long long) statfsbuf->f_bavail); |
Bernhard Reutner-Fischer | 0e6ab01 | 2007-04-04 13:58:33 +0000 | [diff] [blame] | 242 | } else if (m == 's' || m == 'S') { |
Denis Vlasenko | 91e5203 | 2007-10-05 20:31:23 +0000 | [diff] [blame] | 243 | strcat(pformat, "lu"); |
Denys Vlasenko | 5b9b136 | 2010-02-02 03:08:57 +0100 | [diff] [blame] | 244 | printf(pformat, (unsigned long) statfsbuf->f_bsize); |
Bernhard Reutner-Fischer | 0e6ab01 | 2007-04-04 13:58:33 +0000 | [diff] [blame] | 245 | } else if (m == 'c') { |
Denys Vlasenko | 5b9b136 | 2010-02-02 03:08:57 +0100 | [diff] [blame] | 246 | strcat(pformat, "llu"); |
| 247 | printf(pformat, (unsigned long long) statfsbuf->f_files); |
Bernhard Reutner-Fischer | 0e6ab01 | 2007-04-04 13:58:33 +0000 | [diff] [blame] | 248 | } else if (m == 'd') { |
Denys Vlasenko | 5b9b136 | 2010-02-02 03:08:57 +0100 | [diff] [blame] | 249 | strcat(pformat, "llu"); |
| 250 | printf(pformat, (unsigned long long) statfsbuf->f_ffree); |
| 251 | # if ENABLE_SELINUX |
Bernhard Reutner-Fischer | 0e6ab01 | 2007-04-04 13:58:33 +0000 | [diff] [blame] | 252 | } else if (m == 'C' && (option_mask32 & OPT_SELINUX)) { |
Denis Vlasenko | 91e5203 | 2007-10-05 20:31:23 +0000 | [diff] [blame] | 253 | printfs(pformat, scontext); |
Denys Vlasenko | 5b9b136 | 2010-02-02 03:08:57 +0100 | [diff] [blame] | 254 | # endif |
Bernhard Reutner-Fischer | 0e6ab01 | 2007-04-04 13:58:33 +0000 | [diff] [blame] | 255 | } else { |
Denis Vlasenko | 91e5203 | 2007-10-05 20:31:23 +0000 | [diff] [blame] | 256 | strcatc(pformat, 'c'); |
Mike Frysinger | 9b5f71e | 2005-04-23 06:26:38 +0000 | [diff] [blame] | 257 | printf(pformat, m); |
Mike Frysinger | 9b5f71e | 2005-04-23 06:26:38 +0000 | [diff] [blame] | 258 | } |
| 259 | } |
| 260 | |
| 261 | /* print stat info */ |
Denys Vlasenko | 5b9b136 | 2010-02-02 03:08:57 +0100 | [diff] [blame] | 262 | static void FAST_FUNC print_stat(char *pformat, const char m, |
Denis Vlasenko | 91e5203 | 2007-10-05 20:31:23 +0000 | [diff] [blame] | 263 | const char *const filename, const void *data |
Denis Vlasenko | 5e34ff2 | 2009-04-21 11:09:40 +0000 | [diff] [blame] | 264 | IF_SELINUX(, security_context_t scontext)) |
Mike Frysinger | 9b5f71e | 2005-04-23 06:26:38 +0000 | [diff] [blame] | 265 | { |
| 266 | #define TYPE_SIGNED(t) (! ((t) 0 < (t) -1)) |
| 267 | struct stat *statbuf = (struct stat *) data; |
| 268 | struct passwd *pw_ent; |
| 269 | struct group *gw_ent; |
| 270 | |
Bernhard Reutner-Fischer | 0e6ab01 | 2007-04-04 13:58:33 +0000 | [diff] [blame] | 271 | if (m == 'n') { |
Denis Vlasenko | 91e5203 | 2007-10-05 20:31:23 +0000 | [diff] [blame] | 272 | printfs(pformat, filename); |
Bernhard Reutner-Fischer | 0e6ab01 | 2007-04-04 13:58:33 +0000 | [diff] [blame] | 273 | } else if (m == 'N') { |
Denis Vlasenko | 91e5203 | 2007-10-05 20:31:23 +0000 | [diff] [blame] | 274 | strcatc(pformat, 's'); |
Mike Frysinger | 9b5f71e | 2005-04-23 06:26:38 +0000 | [diff] [blame] | 275 | if (S_ISLNK(statbuf->st_mode)) { |
Denis Vlasenko | 6ca0444 | 2007-02-11 16:19:28 +0000 | [diff] [blame] | 276 | char *linkname = xmalloc_readlink_or_warn(filename); |
Denis Vlasenko | 91e5203 | 2007-10-05 20:31:23 +0000 | [diff] [blame] | 277 | if (linkname == NULL) |
Mike Frysinger | 9b5f71e | 2005-04-23 06:26:38 +0000 | [diff] [blame] | 278 | return; |
Seb | d2d327d | 2010-06-12 21:57:50 +0200 | [diff] [blame] | 279 | printf("'%s' -> '%s'", filename, linkname); |
Denis Vlasenko | 91e5203 | 2007-10-05 20:31:23 +0000 | [diff] [blame] | 280 | free(linkname); |
Mike Frysinger | 9b5f71e | 2005-04-23 06:26:38 +0000 | [diff] [blame] | 281 | } else { |
| 282 | printf(pformat, filename); |
| 283 | } |
Bernhard Reutner-Fischer | 0e6ab01 | 2007-04-04 13:58:33 +0000 | [diff] [blame] | 284 | } else if (m == 'd') { |
Denys Vlasenko | 5b9b136 | 2010-02-02 03:08:57 +0100 | [diff] [blame] | 285 | strcat(pformat, "llu"); |
| 286 | printf(pformat, (unsigned long long) statbuf->st_dev); |
Bernhard Reutner-Fischer | 0e6ab01 | 2007-04-04 13:58:33 +0000 | [diff] [blame] | 287 | } else if (m == 'D') { |
Denys Vlasenko | 5b9b136 | 2010-02-02 03:08:57 +0100 | [diff] [blame] | 288 | strcat(pformat, "llx"); |
| 289 | printf(pformat, (unsigned long long) statbuf->st_dev); |
Bernhard Reutner-Fischer | 0e6ab01 | 2007-04-04 13:58:33 +0000 | [diff] [blame] | 290 | } else if (m == 'i') { |
Denys Vlasenko | 5b9b136 | 2010-02-02 03:08:57 +0100 | [diff] [blame] | 291 | strcat(pformat, "llu"); |
| 292 | printf(pformat, (unsigned long long) statbuf->st_ino); |
Bernhard Reutner-Fischer | 0e6ab01 | 2007-04-04 13:58:33 +0000 | [diff] [blame] | 293 | } else if (m == 'a') { |
Denis Vlasenko | 91e5203 | 2007-10-05 20:31:23 +0000 | [diff] [blame] | 294 | strcat(pformat, "lo"); |
Denis Vlasenko | 8746885 | 2007-04-13 23:22:00 +0000 | [diff] [blame] | 295 | printf(pformat, (unsigned long) (statbuf->st_mode & (S_ISUID|S_ISGID|S_ISVTX|S_IRWXU|S_IRWXG|S_IRWXO))); |
Bernhard Reutner-Fischer | 0e6ab01 | 2007-04-04 13:58:33 +0000 | [diff] [blame] | 296 | } else if (m == 'A') { |
Denis Vlasenko | 91e5203 | 2007-10-05 20:31:23 +0000 | [diff] [blame] | 297 | printfs(pformat, bb_mode_string(statbuf->st_mode)); |
Bernhard Reutner-Fischer | 0e6ab01 | 2007-04-04 13:58:33 +0000 | [diff] [blame] | 298 | } else if (m == 'f') { |
Denis Vlasenko | 91e5203 | 2007-10-05 20:31:23 +0000 | [diff] [blame] | 299 | strcat(pformat, "lx"); |
Denis Vlasenko | 8746885 | 2007-04-13 23:22:00 +0000 | [diff] [blame] | 300 | printf(pformat, (unsigned long) statbuf->st_mode); |
Bernhard Reutner-Fischer | 0e6ab01 | 2007-04-04 13:58:33 +0000 | [diff] [blame] | 301 | } else if (m == 'F') { |
Denis Vlasenko | 91e5203 | 2007-10-05 20:31:23 +0000 | [diff] [blame] | 302 | printfs(pformat, file_type(statbuf)); |
Bernhard Reutner-Fischer | 0e6ab01 | 2007-04-04 13:58:33 +0000 | [diff] [blame] | 303 | } else if (m == 'h') { |
Denis Vlasenko | 91e5203 | 2007-10-05 20:31:23 +0000 | [diff] [blame] | 304 | strcat(pformat, "lu"); |
Denis Vlasenko | 8746885 | 2007-04-13 23:22:00 +0000 | [diff] [blame] | 305 | printf(pformat, (unsigned long) statbuf->st_nlink); |
Bernhard Reutner-Fischer | 0e6ab01 | 2007-04-04 13:58:33 +0000 | [diff] [blame] | 306 | } else if (m == 'u') { |
Denis Vlasenko | 91e5203 | 2007-10-05 20:31:23 +0000 | [diff] [blame] | 307 | strcat(pformat, "lu"); |
Denis Vlasenko | 8746885 | 2007-04-13 23:22:00 +0000 | [diff] [blame] | 308 | printf(pformat, (unsigned long) statbuf->st_uid); |
Bernhard Reutner-Fischer | 0e6ab01 | 2007-04-04 13:58:33 +0000 | [diff] [blame] | 309 | } else if (m == 'U') { |
Mike Frysinger | 9b5f71e | 2005-04-23 06:26:38 +0000 | [diff] [blame] | 310 | pw_ent = getpwuid(statbuf->st_uid); |
Denis Vlasenko | b75fe79 | 2008-06-27 22:31:07 +0000 | [diff] [blame] | 311 | printfs(pformat, (pw_ent != NULL) ? pw_ent->pw_name : "UNKNOWN"); |
Bernhard Reutner-Fischer | 0e6ab01 | 2007-04-04 13:58:33 +0000 | [diff] [blame] | 312 | } else if (m == 'g') { |
Denis Vlasenko | 91e5203 | 2007-10-05 20:31:23 +0000 | [diff] [blame] | 313 | strcat(pformat, "lu"); |
Denis Vlasenko | 8746885 | 2007-04-13 23:22:00 +0000 | [diff] [blame] | 314 | printf(pformat, (unsigned long) statbuf->st_gid); |
Bernhard Reutner-Fischer | 0e6ab01 | 2007-04-04 13:58:33 +0000 | [diff] [blame] | 315 | } else if (m == 'G') { |
Mike Frysinger | 9b5f71e | 2005-04-23 06:26:38 +0000 | [diff] [blame] | 316 | gw_ent = getgrgid(statbuf->st_gid); |
Denis Vlasenko | b75fe79 | 2008-06-27 22:31:07 +0000 | [diff] [blame] | 317 | printfs(pformat, (gw_ent != NULL) ? gw_ent->gr_name : "UNKNOWN"); |
Bernhard Reutner-Fischer | 0e6ab01 | 2007-04-04 13:58:33 +0000 | [diff] [blame] | 318 | } else if (m == 't') { |
Denis Vlasenko | 91e5203 | 2007-10-05 20:31:23 +0000 | [diff] [blame] | 319 | strcat(pformat, "lx"); |
Denis Vlasenko | 8746885 | 2007-04-13 23:22:00 +0000 | [diff] [blame] | 320 | printf(pformat, (unsigned long) major(statbuf->st_rdev)); |
Bernhard Reutner-Fischer | 0e6ab01 | 2007-04-04 13:58:33 +0000 | [diff] [blame] | 321 | } else if (m == 'T') { |
Denis Vlasenko | 91e5203 | 2007-10-05 20:31:23 +0000 | [diff] [blame] | 322 | strcat(pformat, "lx"); |
Denis Vlasenko | 8746885 | 2007-04-13 23:22:00 +0000 | [diff] [blame] | 323 | printf(pformat, (unsigned long) minor(statbuf->st_rdev)); |
Bernhard Reutner-Fischer | 0e6ab01 | 2007-04-04 13:58:33 +0000 | [diff] [blame] | 324 | } else if (m == 's') { |
Denys Vlasenko | 5b9b136 | 2010-02-02 03:08:57 +0100 | [diff] [blame] | 325 | strcat(pformat, "llu"); |
| 326 | printf(pformat, (unsigned long long) statbuf->st_size); |
Bernhard Reutner-Fischer | 0e6ab01 | 2007-04-04 13:58:33 +0000 | [diff] [blame] | 327 | } else if (m == 'B') { |
Denis Vlasenko | 91e5203 | 2007-10-05 20:31:23 +0000 | [diff] [blame] | 328 | strcat(pformat, "lu"); |
Denis Vlasenko | 8746885 | 2007-04-13 23:22:00 +0000 | [diff] [blame] | 329 | printf(pformat, (unsigned long) 512); //ST_NBLOCKSIZE |
Bernhard Reutner-Fischer | 0e6ab01 | 2007-04-04 13:58:33 +0000 | [diff] [blame] | 330 | } else if (m == 'b') { |
Denys Vlasenko | 5b9b136 | 2010-02-02 03:08:57 +0100 | [diff] [blame] | 331 | strcat(pformat, "llu"); |
| 332 | printf(pformat, (unsigned long long) statbuf->st_blocks); |
Bernhard Reutner-Fischer | 0e6ab01 | 2007-04-04 13:58:33 +0000 | [diff] [blame] | 333 | } else if (m == 'o') { |
Denis Vlasenko | 91e5203 | 2007-10-05 20:31:23 +0000 | [diff] [blame] | 334 | strcat(pformat, "lu"); |
Denis Vlasenko | 8746885 | 2007-04-13 23:22:00 +0000 | [diff] [blame] | 335 | printf(pformat, (unsigned long) statbuf->st_blksize); |
Bernhard Reutner-Fischer | 0e6ab01 | 2007-04-04 13:58:33 +0000 | [diff] [blame] | 336 | } else if (m == 'x') { |
Denis Vlasenko | 91e5203 | 2007-10-05 20:31:23 +0000 | [diff] [blame] | 337 | printfs(pformat, human_time(statbuf->st_atime)); |
Bernhard Reutner-Fischer | 0e6ab01 | 2007-04-04 13:58:33 +0000 | [diff] [blame] | 338 | } else if (m == 'X') { |
Denis Vlasenko | 91e5203 | 2007-10-05 20:31:23 +0000 | [diff] [blame] | 339 | strcat(pformat, TYPE_SIGNED(time_t) ? "ld" : "lu"); |
Denys Vlasenko | 5b9b136 | 2010-02-02 03:08:57 +0100 | [diff] [blame] | 340 | /* note: (unsigned long) would be wrong: |
| 341 | * imagine (unsigned long64)int32 */ |
| 342 | printf(pformat, (long) statbuf->st_atime); |
Bernhard Reutner-Fischer | 0e6ab01 | 2007-04-04 13:58:33 +0000 | [diff] [blame] | 343 | } else if (m == 'y') { |
Denis Vlasenko | 91e5203 | 2007-10-05 20:31:23 +0000 | [diff] [blame] | 344 | printfs(pformat, human_time(statbuf->st_mtime)); |
Bernhard Reutner-Fischer | 0e6ab01 | 2007-04-04 13:58:33 +0000 | [diff] [blame] | 345 | } else if (m == 'Y') { |
Denis Vlasenko | 91e5203 | 2007-10-05 20:31:23 +0000 | [diff] [blame] | 346 | strcat(pformat, TYPE_SIGNED(time_t) ? "ld" : "lu"); |
Denys Vlasenko | 5b9b136 | 2010-02-02 03:08:57 +0100 | [diff] [blame] | 347 | printf(pformat, (long) statbuf->st_mtime); |
Bernhard Reutner-Fischer | 0e6ab01 | 2007-04-04 13:58:33 +0000 | [diff] [blame] | 348 | } else if (m == 'z') { |
Denis Vlasenko | 91e5203 | 2007-10-05 20:31:23 +0000 | [diff] [blame] | 349 | printfs(pformat, human_time(statbuf->st_ctime)); |
Bernhard Reutner-Fischer | 0e6ab01 | 2007-04-04 13:58:33 +0000 | [diff] [blame] | 350 | } else if (m == 'Z') { |
Denis Vlasenko | 91e5203 | 2007-10-05 20:31:23 +0000 | [diff] [blame] | 351 | strcat(pformat, TYPE_SIGNED(time_t) ? "ld" : "lu"); |
Denys Vlasenko | 5b9b136 | 2010-02-02 03:08:57 +0100 | [diff] [blame] | 352 | printf(pformat, (long) statbuf->st_ctime); |
| 353 | # if ENABLE_SELINUX |
Bernhard Reutner-Fischer | 0e6ab01 | 2007-04-04 13:58:33 +0000 | [diff] [blame] | 354 | } else if (m == 'C' && (option_mask32 & OPT_SELINUX)) { |
Denis Vlasenko | 91e5203 | 2007-10-05 20:31:23 +0000 | [diff] [blame] | 355 | printfs(pformat, scontext); |
Denys Vlasenko | 5b9b136 | 2010-02-02 03:08:57 +0100 | [diff] [blame] | 356 | # endif |
Bernhard Reutner-Fischer | 0e6ab01 | 2007-04-04 13:58:33 +0000 | [diff] [blame] | 357 | } else { |
Denis Vlasenko | 91e5203 | 2007-10-05 20:31:23 +0000 | [diff] [blame] | 358 | strcatc(pformat, 'c'); |
Mike Frysinger | 9b5f71e | 2005-04-23 06:26:38 +0000 | [diff] [blame] | 359 | printf(pformat, m); |
Mike Frysinger | 9b5f71e | 2005-04-23 06:26:38 +0000 | [diff] [blame] | 360 | } |
| 361 | } |
| 362 | |
Denys Vlasenko | 5b9b136 | 2010-02-02 03:08:57 +0100 | [diff] [blame] | 363 | static void print_it(const char *masterformat, |
| 364 | const char *filename, |
| 365 | void FAST_FUNC (*print_func)(char*, char, const char*, const void* IF_SELINUX(, security_context_t scontext)), |
Denis Vlasenko | 91e5203 | 2007-10-05 20:31:23 +0000 | [diff] [blame] | 366 | const void *data |
Denys Vlasenko | 5b9b136 | 2010-02-02 03:08:57 +0100 | [diff] [blame] | 367 | IF_SELINUX(, security_context_t scontext)) |
Mike Frysinger | 9b5f71e | 2005-04-23 06:26:38 +0000 | [diff] [blame] | 368 | { |
Denis Vlasenko | 91e5203 | 2007-10-05 20:31:23 +0000 | [diff] [blame] | 369 | /* Create a working copy of the format string */ |
Rob Landley | d921b2e | 2006-08-03 15:41:12 +0000 | [diff] [blame] | 370 | char *format = xstrdup(masterformat); |
Denis Vlasenko | 5d148e2 | 2006-11-21 00:12:09 +0000 | [diff] [blame] | 371 | /* Add 2 to accomodate our conversion of the stat '%s' format string |
| 372 | * to the printf '%llu' one. */ |
Denis Vlasenko | 91e5203 | 2007-10-05 20:31:23 +0000 | [diff] [blame] | 373 | char *dest = xmalloc(strlen(format) + 2 + 1); |
| 374 | char *b; |
Mike Frysinger | 9b5f71e | 2005-04-23 06:26:38 +0000 | [diff] [blame] | 375 | |
| 376 | b = format; |
| 377 | while (b) { |
Seb | d2d327d | 2010-06-12 21:57:50 +0200 | [diff] [blame] | 378 | /* Each iteration finds next %spec, |
| 379 | * prints preceding string and handles found %spec |
| 380 | */ |
Denis Vlasenko | 5d148e2 | 2006-11-21 00:12:09 +0000 | [diff] [blame] | 381 | size_t len; |
Mike Frysinger | 9b5f71e | 2005-04-23 06:26:38 +0000 | [diff] [blame] | 382 | char *p = strchr(b, '%'); |
Denis Vlasenko | 5d148e2 | 2006-11-21 00:12:09 +0000 | [diff] [blame] | 383 | if (!p) { |
Seb | d2d327d | 2010-06-12 21:57:50 +0200 | [diff] [blame] | 384 | /* coreutils 6.3 always prints newline at the end */ |
Denis Vlasenko | 5d148e2 | 2006-11-21 00:12:09 +0000 | [diff] [blame] | 385 | /*fputs(b, stdout);*/ |
| 386 | puts(b); |
| 387 | break; |
| 388 | } |
Mike Frysinger | 9b5f71e | 2005-04-23 06:26:38 +0000 | [diff] [blame] | 389 | |
Denis Vlasenko | 91e5203 | 2007-10-05 20:31:23 +0000 | [diff] [blame] | 390 | /* dest = "%<modifiers>" */ |
Seb | d2d327d | 2010-06-12 21:57:50 +0200 | [diff] [blame] | 391 | len = 1 + strspn(p + 1, "#-+.I 0123456789"); |
| 392 | memcpy(dest, p, len); |
| 393 | dest[len] = '\0'; |
Mike Frysinger | 9b5f71e | 2005-04-23 06:26:38 +0000 | [diff] [blame] | 394 | |
Seb | d2d327d | 2010-06-12 21:57:50 +0200 | [diff] [blame] | 395 | /* print preceding string */ |
| 396 | *p = '\0'; |
| 397 | fputs(b, stdout); |
| 398 | |
| 399 | p += len; |
Denis Vlasenko | 5d148e2 | 2006-11-21 00:12:09 +0000 | [diff] [blame] | 400 | b = p + 1; |
| 401 | switch (*p) { |
| 402 | case '\0': |
Mike Frysinger | 9b5f71e | 2005-04-23 06:26:38 +0000 | [diff] [blame] | 403 | b = NULL; |
Denis Vlasenko | 5d148e2 | 2006-11-21 00:12:09 +0000 | [diff] [blame] | 404 | /* fall through */ |
| 405 | case '%': |
Denis Vlasenko | 4daad90 | 2007-09-27 10:20:47 +0000 | [diff] [blame] | 406 | bb_putchar('%'); |
Denis Vlasenko | 5d148e2 | 2006-11-21 00:12:09 +0000 | [diff] [blame] | 407 | break; |
| 408 | default: |
Denis Vlasenko | 91e5203 | 2007-10-05 20:31:23 +0000 | [diff] [blame] | 409 | /* Completes "%<modifiers>" with specifier and printfs */ |
Denis Vlasenko | 5e34ff2 | 2009-04-21 11:09:40 +0000 | [diff] [blame] | 410 | print_func(dest, *p, filename, data IF_SELINUX(,scontext)); |
Denis Vlasenko | 5d148e2 | 2006-11-21 00:12:09 +0000 | [diff] [blame] | 411 | break; |
Mike Frysinger | 9b5f71e | 2005-04-23 06:26:38 +0000 | [diff] [blame] | 412 | } |
| 413 | } |
| 414 | |
| 415 | free(format); |
| 416 | free(dest); |
| 417 | } |
Denys Vlasenko | 5b9b136 | 2010-02-02 03:08:57 +0100 | [diff] [blame] | 418 | #endif /* FEATURE_STAT_FORMAT */ |
Mike Frysinger | 9b5f71e | 2005-04-23 06:26:38 +0000 | [diff] [blame] | 419 | |
| 420 | /* Stat the file system and print what we find. */ |
Denis Vlasenko | 85c2471 | 2008-03-17 09:04:04 +0000 | [diff] [blame] | 421 | #if !ENABLE_FEATURE_STAT_FORMAT |
| 422 | #define do_statfs(filename, format) do_statfs(filename) |
| 423 | #endif |
Denis Vlasenko | 91e5203 | 2007-10-05 20:31:23 +0000 | [diff] [blame] | 424 | static bool do_statfs(const char *filename, const char *format) |
Mike Frysinger | 9b5f71e | 2005-04-23 06:26:38 +0000 | [diff] [blame] | 425 | { |
Denis Vlasenko | 98f5cdf | 2008-11-11 22:25:34 +0000 | [diff] [blame] | 426 | struct statfs statfsbuf; |
Denis Vlasenko | 85c2471 | 2008-03-17 09:04:04 +0000 | [diff] [blame] | 427 | #if !ENABLE_FEATURE_STAT_FORMAT |
| 428 | const char *format; |
| 429 | #endif |
Denis Vlasenko | 49622d7 | 2007-03-10 16:58:49 +0000 | [diff] [blame] | 430 | #if ENABLE_SELINUX |
| 431 | security_context_t scontext = NULL; |
Bernhard Reutner-Fischer | 0e6ab01 | 2007-04-04 13:58:33 +0000 | [diff] [blame] | 432 | |
| 433 | if (option_mask32 & OPT_SELINUX) { |
Denis Vlasenko | 501bfe2 | 2007-08-09 08:10:13 +0000 | [diff] [blame] | 434 | if ((option_mask32 & OPT_DEREFERENCE |
| 435 | ? lgetfilecon(filename, &scontext) |
| 436 | : getfilecon(filename, &scontext) |
| 437 | ) < 0 |
| 438 | ) { |
Denis Vlasenko | 49622d7 | 2007-03-10 16:58:49 +0000 | [diff] [blame] | 439 | bb_perror_msg(filename); |
| 440 | return 0; |
| 441 | } |
| 442 | } |
| 443 | #endif |
Mike Frysinger | 9b5f71e | 2005-04-23 06:26:38 +0000 | [diff] [blame] | 444 | if (statfs(filename, &statfsbuf) != 0) { |
Denys Vlasenko | 6331cf0 | 2009-11-13 09:08:27 +0100 | [diff] [blame] | 445 | bb_perror_msg("can't read file system information for '%s'", filename); |
Mike Frysinger | 9b5f71e | 2005-04-23 06:26:38 +0000 | [diff] [blame] | 446 | return 0; |
| 447 | } |
| 448 | |
Denis Vlasenko | 240a1cf | 2007-04-08 16:07:02 +0000 | [diff] [blame] | 449 | #if ENABLE_FEATURE_STAT_FORMAT |
Denis Vlasenko | 91e5203 | 2007-10-05 20:31:23 +0000 | [diff] [blame] | 450 | if (format == NULL) { |
Denys Vlasenko | 5b9b136 | 2010-02-02 03:08:57 +0100 | [diff] [blame] | 451 | # if !ENABLE_SELINUX |
Bernhard Reutner-Fischer | 0e6ab01 | 2007-04-04 13:58:33 +0000 | [diff] [blame] | 452 | format = (option_mask32 & OPT_TERSE |
Mike Frysinger | 726b2cb | 2005-07-26 22:39:56 +0000 | [diff] [blame] | 453 | ? "%n %i %l %t %s %b %f %a %c %d\n" |
Mike Frysinger | 9b5f71e | 2005-04-23 06:26:38 +0000 | [diff] [blame] | 454 | : " File: \"%n\"\n" |
| 455 | " ID: %-8i Namelen: %-7l Type: %T\n" |
Mike Frysinger | 726b2cb | 2005-07-26 22:39:56 +0000 | [diff] [blame] | 456 | "Block size: %-10s\n" |
Mike Frysinger | 9b5f71e | 2005-04-23 06:26:38 +0000 | [diff] [blame] | 457 | "Blocks: Total: %-10b Free: %-10f Available: %a\n" |
Denis Vlasenko | 5d148e2 | 2006-11-21 00:12:09 +0000 | [diff] [blame] | 458 | "Inodes: Total: %-10c Free: %d"); |
Denys Vlasenko | 5b9b136 | 2010-02-02 03:08:57 +0100 | [diff] [blame] | 459 | # else |
Denis Vlasenko | 91e5203 | 2007-10-05 20:31:23 +0000 | [diff] [blame] | 460 | format = (option_mask32 & OPT_TERSE |
Bernhard Reutner-Fischer | 0e6ab01 | 2007-04-04 13:58:33 +0000 | [diff] [blame] | 461 | ? (option_mask32 & OPT_SELINUX ? "%n %i %l %t %s %b %f %a %c %d %C\n": |
Denis Vlasenko | 49622d7 | 2007-03-10 16:58:49 +0000 | [diff] [blame] | 462 | "%n %i %l %t %s %b %f %a %c %d\n") |
Bernhard Reutner-Fischer | 0e6ab01 | 2007-04-04 13:58:33 +0000 | [diff] [blame] | 463 | : (option_mask32 & OPT_SELINUX ? |
Denis Vlasenko | 49622d7 | 2007-03-10 16:58:49 +0000 | [diff] [blame] | 464 | " File: \"%n\"\n" |
| 465 | " ID: %-8i Namelen: %-7l Type: %T\n" |
| 466 | "Block size: %-10s\n" |
| 467 | "Blocks: Total: %-10b Free: %-10f Available: %a\n" |
| 468 | "Inodes: Total: %-10c Free: %d" |
| 469 | " S_context: %C\n": |
| 470 | " File: \"%n\"\n" |
| 471 | " ID: %-8i Namelen: %-7l Type: %T\n" |
| 472 | "Block size: %-10s\n" |
| 473 | "Blocks: Total: %-10b Free: %-10f Available: %a\n" |
| 474 | "Inodes: Total: %-10c Free: %d\n") |
| 475 | ); |
Denys Vlasenko | 5b9b136 | 2010-02-02 03:08:57 +0100 | [diff] [blame] | 476 | # endif /* SELINUX */ |
Denis Vlasenko | 91e5203 | 2007-10-05 20:31:23 +0000 | [diff] [blame] | 477 | } |
Denis Vlasenko | 5e34ff2 | 2009-04-21 11:09:40 +0000 | [diff] [blame] | 478 | print_it(format, filename, print_statfs, &statfsbuf IF_SELINUX(, scontext)); |
Denis Vlasenko | 49622d7 | 2007-03-10 16:58:49 +0000 | [diff] [blame] | 479 | #else /* FEATURE_STAT_FORMAT */ |
Bernhard Reutner-Fischer | 0e6ab01 | 2007-04-04 13:58:33 +0000 | [diff] [blame] | 480 | format = (option_mask32 & OPT_TERSE |
Bernhard Reutner-Fischer | d409c3a | 2006-03-29 22:34:47 +0000 | [diff] [blame] | 481 | ? "%s %llx %lu " |
Mike Frysinger | 9b5f71e | 2005-04-23 06:26:38 +0000 | [diff] [blame] | 482 | : " File: \"%s\"\n" |
Denis Vlasenko | 98f5cdf | 2008-11-11 22:25:34 +0000 | [diff] [blame] | 483 | " ID: %-8llx Namelen: %-7lu "); |
Mike Frysinger | 9b5f71e | 2005-04-23 06:26:38 +0000 | [diff] [blame] | 484 | printf(format, |
| 485 | filename, |
Denis Vlasenko | 98f5cdf | 2008-11-11 22:25:34 +0000 | [diff] [blame] | 486 | get_f_fsid(&statfsbuf), |
Mike Frysinger | 9b5f71e | 2005-04-23 06:26:38 +0000 | [diff] [blame] | 487 | statfsbuf.f_namelen); |
| 488 | |
Bernhard Reutner-Fischer | 0e6ab01 | 2007-04-04 13:58:33 +0000 | [diff] [blame] | 489 | if (option_mask32 & OPT_TERSE) |
Denys Vlasenko | 5b9b136 | 2010-02-02 03:08:57 +0100 | [diff] [blame] | 490 | printf("%lx ", (unsigned long) statfsbuf.f_type); |
Mike Frysinger | 9b5f71e | 2005-04-23 06:26:38 +0000 | [diff] [blame] | 491 | else |
| 492 | printf("Type: %s\n", human_fstype(statfsbuf.f_type)); |
| 493 | |
Denys Vlasenko | 5b9b136 | 2010-02-02 03:08:57 +0100 | [diff] [blame] | 494 | # if !ENABLE_SELINUX |
Bernhard Reutner-Fischer | 0e6ab01 | 2007-04-04 13:58:33 +0000 | [diff] [blame] | 495 | format = (option_mask32 & OPT_TERSE |
Denys Vlasenko | 5b9b136 | 2010-02-02 03:08:57 +0100 | [diff] [blame] | 496 | ? "%lu %llu %llu %llu %llu %llu\n" |
Mike Frysinger | 726b2cb | 2005-07-26 22:39:56 +0000 | [diff] [blame] | 497 | : "Block size: %-10lu\n" |
Denys Vlasenko | 5b9b136 | 2010-02-02 03:08:57 +0100 | [diff] [blame] | 498 | "Blocks: Total: %-10llu Free: %-10llu Available: %llu\n" |
| 499 | "Inodes: Total: %-10llu Free: %llu\n"); |
Mike Frysinger | 9b5f71e | 2005-04-23 06:26:38 +0000 | [diff] [blame] | 500 | printf(format, |
Denys Vlasenko | 5b9b136 | 2010-02-02 03:08:57 +0100 | [diff] [blame] | 501 | (unsigned long) statfsbuf.f_bsize, |
| 502 | (unsigned long long) statfsbuf.f_blocks, |
| 503 | (unsigned long long) statfsbuf.f_bfree, |
| 504 | (unsigned long long) statfsbuf.f_bavail, |
| 505 | (unsigned long long) statfsbuf.f_files, |
| 506 | (unsigned long long) statfsbuf.f_ffree); |
| 507 | # else |
Bernhard Reutner-Fischer | 0e6ab01 | 2007-04-04 13:58:33 +0000 | [diff] [blame] | 508 | format = (option_mask32 & OPT_TERSE |
Denys Vlasenko | 5b9b136 | 2010-02-02 03:08:57 +0100 | [diff] [blame] | 509 | ? (option_mask32 & OPT_SELINUX ? "%lu %llu %llu %llu %llu %llu %C\n" : "%lu %llu %llu %llu %llu %llu\n") |
| 510 | : (option_mask32 & OPT_SELINUX |
| 511 | ? "Block size: %-10lu\n" |
| 512 | "Blocks: Total: %-10llu Free: %-10llu Available: %llu\n" |
| 513 | "Inodes: Total: %-10llu Free: %llu" |
| 514 | "S_context: %C\n" |
| 515 | : "Block size: %-10lu\n" |
| 516 | "Blocks: Total: %-10llu Free: %-10llu Available: %llu\n" |
| 517 | "Inodes: Total: %-10llu Free: %llu\n" |
| 518 | ) |
| 519 | ); |
Denis Vlasenko | 49622d7 | 2007-03-10 16:58:49 +0000 | [diff] [blame] | 520 | printf(format, |
Denys Vlasenko | 5b9b136 | 2010-02-02 03:08:57 +0100 | [diff] [blame] | 521 | (unsigned long) statfsbuf.f_bsize, |
| 522 | (unsigned long long) statfsbuf.f_blocks, |
| 523 | (unsigned long long) statfsbuf.f_bfree, |
| 524 | (unsigned long long) statfsbuf.f_bavail, |
| 525 | (unsigned long long) statfsbuf.f_files, |
| 526 | (unsigned long long) statfsbuf.f_ffree, |
Denis Vlasenko | 49622d7 | 2007-03-10 16:58:49 +0000 | [diff] [blame] | 527 | scontext); |
Mike Frysinger | 9b5f71e | 2005-04-23 06:26:38 +0000 | [diff] [blame] | 528 | |
Denis Vlasenko | 49622d7 | 2007-03-10 16:58:49 +0000 | [diff] [blame] | 529 | if (scontext) |
| 530 | freecon(scontext); |
Denys Vlasenko | 5b9b136 | 2010-02-02 03:08:57 +0100 | [diff] [blame] | 531 | # endif |
Denys Vlasenko | e4dcba1 | 2010-10-28 18:57:19 +0200 | [diff] [blame] | 532 | #endif /* FEATURE_STAT_FORMAT */ |
Mike Frysinger | 9b5f71e | 2005-04-23 06:26:38 +0000 | [diff] [blame] | 533 | return 1; |
| 534 | } |
| 535 | |
| 536 | /* stat the file and print what we find */ |
Denis Vlasenko | 85c2471 | 2008-03-17 09:04:04 +0000 | [diff] [blame] | 537 | #if !ENABLE_FEATURE_STAT_FORMAT |
| 538 | #define do_stat(filename, format) do_stat(filename) |
| 539 | #endif |
Denis Vlasenko | 91e5203 | 2007-10-05 20:31:23 +0000 | [diff] [blame] | 540 | static bool do_stat(const char *filename, const char *format) |
Mike Frysinger | 9b5f71e | 2005-04-23 06:26:38 +0000 | [diff] [blame] | 541 | { |
| 542 | struct stat statbuf; |
Denis Vlasenko | 49622d7 | 2007-03-10 16:58:49 +0000 | [diff] [blame] | 543 | #if ENABLE_SELINUX |
| 544 | security_context_t scontext = NULL; |
Bernhard Reutner-Fischer | 0e6ab01 | 2007-04-04 13:58:33 +0000 | [diff] [blame] | 545 | |
| 546 | if (option_mask32 & OPT_SELINUX) { |
Denis Vlasenko | 501bfe2 | 2007-08-09 08:10:13 +0000 | [diff] [blame] | 547 | if ((option_mask32 & OPT_DEREFERENCE |
| 548 | ? lgetfilecon(filename, &scontext) |
| 549 | : getfilecon(filename, &scontext) |
| 550 | ) < 0 |
| 551 | ) { |
| 552 | bb_perror_msg(filename); |
Denis Vlasenko | 49622d7 | 2007-03-10 16:58:49 +0000 | [diff] [blame] | 553 | return 0; |
| 554 | } |
| 555 | } |
| 556 | #endif |
Bernhard Reutner-Fischer | 0e6ab01 | 2007-04-04 13:58:33 +0000 | [diff] [blame] | 557 | if ((option_mask32 & OPT_DEREFERENCE ? stat : lstat) (filename, &statbuf) != 0) { |
Denys Vlasenko | 6331cf0 | 2009-11-13 09:08:27 +0100 | [diff] [blame] | 558 | bb_perror_msg("can't stat '%s'", filename); |
Mike Frysinger | 9b5f71e | 2005-04-23 06:26:38 +0000 | [diff] [blame] | 559 | return 0; |
| 560 | } |
| 561 | |
Denis Vlasenko | 240a1cf | 2007-04-08 16:07:02 +0000 | [diff] [blame] | 562 | #if ENABLE_FEATURE_STAT_FORMAT |
Mike Frysinger | 9b5f71e | 2005-04-23 06:26:38 +0000 | [diff] [blame] | 563 | if (format == NULL) { |
Denys Vlasenko | 5b9b136 | 2010-02-02 03:08:57 +0100 | [diff] [blame] | 564 | # if !ENABLE_SELINUX |
Bernhard Reutner-Fischer | 0e6ab01 | 2007-04-04 13:58:33 +0000 | [diff] [blame] | 565 | if (option_mask32 & OPT_TERSE) { |
Denis Vlasenko | 5d148e2 | 2006-11-21 00:12:09 +0000 | [diff] [blame] | 566 | 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] | 567 | } else { |
| 568 | if (S_ISBLK(statbuf.st_mode) || S_ISCHR(statbuf.st_mode)) { |
| 569 | format = |
Seb | d2d327d | 2010-06-12 21:57:50 +0200 | [diff] [blame] | 570 | " File: %N\n" |
Mike Frysinger | 9b5f71e | 2005-04-23 06:26:38 +0000 | [diff] [blame] | 571 | " Size: %-10s\tBlocks: %-10b IO Block: %-6o %F\n" |
| 572 | "Device: %Dh/%dd\tInode: %-10i Links: %-5h" |
| 573 | " Device type: %t,%T\n" |
| 574 | "Access: (%04a/%10.10A) Uid: (%5u/%8U) Gid: (%5g/%8G)\n" |
| 575 | "Access: %x\n" "Modify: %y\n" "Change: %z\n"; |
| 576 | } else { |
| 577 | format = |
Seb | d2d327d | 2010-06-12 21:57:50 +0200 | [diff] [blame] | 578 | " File: %N\n" |
Mike Frysinger | 9b5f71e | 2005-04-23 06:26:38 +0000 | [diff] [blame] | 579 | " Size: %-10s\tBlocks: %-10b IO Block: %-6o %F\n" |
| 580 | "Device: %Dh/%dd\tInode: %-10i Links: %h\n" |
| 581 | "Access: (%04a/%10.10A) Uid: (%5u/%8U) Gid: (%5g/%8G)\n" |
| 582 | "Access: %x\n" "Modify: %y\n" "Change: %z\n"; |
| 583 | } |
| 584 | } |
Denys Vlasenko | 5b9b136 | 2010-02-02 03:08:57 +0100 | [diff] [blame] | 585 | # else |
Bernhard Reutner-Fischer | 0e6ab01 | 2007-04-04 13:58:33 +0000 | [diff] [blame] | 586 | if (option_mask32 & OPT_TERSE) { |
| 587 | format = (option_mask32 & OPT_SELINUX ? |
Denis Vlasenko | 49622d7 | 2007-03-10 16:58:49 +0000 | [diff] [blame] | 588 | "%n %s %b %f %u %g %D %i %h %t %T %X %Y %Z %o %C\n": |
| 589 | "%n %s %b %f %u %g %D %i %h %t %T %X %Y %Z %o\n"); |
| 590 | } else { |
| 591 | if (S_ISBLK(statbuf.st_mode) || S_ISCHR(statbuf.st_mode)) { |
Bernhard Reutner-Fischer | 0e6ab01 | 2007-04-04 13:58:33 +0000 | [diff] [blame] | 592 | format = (option_mask32 & OPT_SELINUX ? |
Seb | d2d327d | 2010-06-12 21:57:50 +0200 | [diff] [blame] | 593 | " File: %N\n" |
Denis Vlasenko | 49622d7 | 2007-03-10 16:58:49 +0000 | [diff] [blame] | 594 | " Size: %-10s\tBlocks: %-10b IO Block: %-6o %F\n" |
| 595 | "Device: %Dh/%dd\tInode: %-10i Links: %-5h" |
| 596 | " Device type: %t,%T\n" |
| 597 | "Access: (%04a/%10.10A) Uid: (%5u/%8U) Gid: (%5g/%8G)\n" |
| 598 | " S_Context: %C\n" |
| 599 | "Access: %x\n" "Modify: %y\n" "Change: %z\n": |
Seb | d2d327d | 2010-06-12 21:57:50 +0200 | [diff] [blame] | 600 | " File: %N\n" |
Denis Vlasenko | 49622d7 | 2007-03-10 16:58:49 +0000 | [diff] [blame] | 601 | " Size: %-10s\tBlocks: %-10b IO Block: %-6o %F\n" |
| 602 | "Device: %Dh/%dd\tInode: %-10i Links: %-5h" |
| 603 | " Device type: %t,%T\n" |
| 604 | "Access: (%04a/%10.10A) Uid: (%5u/%8U) Gid: (%5g/%8G)\n" |
| 605 | "Access: %x\n" "Modify: %y\n" "Change: %z\n"); |
| 606 | } else { |
Bernhard Reutner-Fischer | 0e6ab01 | 2007-04-04 13:58:33 +0000 | [diff] [blame] | 607 | format = (option_mask32 & OPT_SELINUX ? |
Seb | d2d327d | 2010-06-12 21:57:50 +0200 | [diff] [blame] | 608 | " File: %N\n" |
Denis Vlasenko | 49622d7 | 2007-03-10 16:58:49 +0000 | [diff] [blame] | 609 | " Size: %-10s\tBlocks: %-10b IO Block: %-6o %F\n" |
| 610 | "Device: %Dh/%dd\tInode: %-10i Links: %h\n" |
| 611 | "Access: (%04a/%10.10A) Uid: (%5u/%8U) Gid: (%5g/%8G)\n" |
| 612 | "S_Context: %C\n" |
| 613 | "Access: %x\n" "Modify: %y\n" "Change: %z\n": |
Seb | d2d327d | 2010-06-12 21:57:50 +0200 | [diff] [blame] | 614 | " File: %N\n" |
Denis Vlasenko | 49622d7 | 2007-03-10 16:58:49 +0000 | [diff] [blame] | 615 | " Size: %-10s\tBlocks: %-10b IO Block: %-6o %F\n" |
| 616 | "Device: %Dh/%dd\tInode: %-10i Links: %h\n" |
| 617 | "Access: (%04a/%10.10A) Uid: (%5u/%8U) Gid: (%5g/%8G)\n" |
| 618 | "Access: %x\n" "Modify: %y\n" "Change: %z\n"); |
| 619 | } |
| 620 | } |
Denys Vlasenko | 5b9b136 | 2010-02-02 03:08:57 +0100 | [diff] [blame] | 621 | # endif |
Denis Vlasenko | 49622d7 | 2007-03-10 16:58:49 +0000 | [diff] [blame] | 622 | } |
Denis Vlasenko | 5e34ff2 | 2009-04-21 11:09:40 +0000 | [diff] [blame] | 623 | print_it(format, filename, print_stat, &statbuf IF_SELINUX(, scontext)); |
Denis Vlasenko | 49622d7 | 2007-03-10 16:58:49 +0000 | [diff] [blame] | 624 | #else /* FEATURE_STAT_FORMAT */ |
Bernhard Reutner-Fischer | 0e6ab01 | 2007-04-04 13:58:33 +0000 | [diff] [blame] | 625 | if (option_mask32 & OPT_TERSE) { |
Denys Vlasenko | 5b9b136 | 2010-02-02 03:08:57 +0100 | [diff] [blame] | 626 | printf("%s %llu %llu %lx %lu %lu %llx %llu %lu %lx %lx %lu %lu %lu %lu" |
Denis Vlasenko | 5e34ff2 | 2009-04-21 11:09:40 +0000 | [diff] [blame] | 627 | IF_NOT_SELINUX("\n"), |
Mike Frysinger | 9b5f71e | 2005-04-23 06:26:38 +0000 | [diff] [blame] | 628 | filename, |
Denys Vlasenko | 5b9b136 | 2010-02-02 03:08:57 +0100 | [diff] [blame] | 629 | (unsigned long long) statbuf.st_size, |
| 630 | (unsigned long long) statbuf.st_blocks, |
Denis Vlasenko | 8746885 | 2007-04-13 23:22:00 +0000 | [diff] [blame] | 631 | (unsigned long) statbuf.st_mode, |
| 632 | (unsigned long) statbuf.st_uid, |
| 633 | (unsigned long) statbuf.st_gid, |
Denys Vlasenko | 5b9b136 | 2010-02-02 03:08:57 +0100 | [diff] [blame] | 634 | (unsigned long long) statbuf.st_dev, |
| 635 | (unsigned long long) statbuf.st_ino, |
Denis Vlasenko | 8746885 | 2007-04-13 23:22:00 +0000 | [diff] [blame] | 636 | (unsigned long) statbuf.st_nlink, |
| 637 | (unsigned long) major(statbuf.st_rdev), |
| 638 | (unsigned long) minor(statbuf.st_rdev), |
| 639 | (unsigned long) statbuf.st_atime, |
| 640 | (unsigned long) statbuf.st_mtime, |
| 641 | (unsigned long) statbuf.st_ctime, |
| 642 | (unsigned long) statbuf.st_blksize |
Mike Frysinger | 9b5f71e | 2005-04-23 06:26:38 +0000 | [diff] [blame] | 643 | ); |
Denys Vlasenko | 5b9b136 | 2010-02-02 03:08:57 +0100 | [diff] [blame] | 644 | # if ENABLE_SELINUX |
Bernhard Reutner-Fischer | 0e6ab01 | 2007-04-04 13:58:33 +0000 | [diff] [blame] | 645 | if (option_mask32 & OPT_SELINUX) |
Denis Vlasenko | 49622d7 | 2007-03-10 16:58:49 +0000 | [diff] [blame] | 646 | printf(" %lc\n", *scontext); |
| 647 | else |
Denis Vlasenko | 4daad90 | 2007-09-27 10:20:47 +0000 | [diff] [blame] | 648 | bb_putchar('\n'); |
Denys Vlasenko | 5b9b136 | 2010-02-02 03:08:57 +0100 | [diff] [blame] | 649 | # endif |
Mike Frysinger | 9b5f71e | 2005-04-23 06:26:38 +0000 | [diff] [blame] | 650 | } else { |
| 651 | char *linkname = NULL; |
Mike Frysinger | 9b5f71e | 2005-04-23 06:26:38 +0000 | [diff] [blame] | 652 | struct passwd *pw_ent; |
| 653 | struct group *gw_ent; |
Alexander Shishkin | a7027bf | 2010-10-21 00:24:05 +0200 | [diff] [blame] | 654 | |
Mike Frysinger | 9b5f71e | 2005-04-23 06:26:38 +0000 | [diff] [blame] | 655 | gw_ent = getgrgid(statbuf.st_gid); |
Mike Frysinger | 9b5f71e | 2005-04-23 06:26:38 +0000 | [diff] [blame] | 656 | pw_ent = getpwuid(statbuf.st_uid); |
| 657 | |
| 658 | if (S_ISLNK(statbuf.st_mode)) |
Denis Vlasenko | 6ca0444 | 2007-02-11 16:19:28 +0000 | [diff] [blame] | 659 | linkname = xmalloc_readlink_or_warn(filename); |
Alexander Shishkin | a7027bf | 2010-10-21 00:24:05 +0200 | [diff] [blame] | 660 | if (linkname) { |
Seb | d2d327d | 2010-06-12 21:57:50 +0200 | [diff] [blame] | 661 | printf(" File: '%s' -> '%s'\n", filename, linkname); |
Alexander Shishkin | a7027bf | 2010-10-21 00:24:05 +0200 | [diff] [blame] | 662 | free(linkname); |
| 663 | } else { |
Seb | d2d327d | 2010-06-12 21:57:50 +0200 | [diff] [blame] | 664 | printf(" File: '%s'\n", filename); |
Alexander Shishkin | a7027bf | 2010-10-21 00:24:05 +0200 | [diff] [blame] | 665 | } |
Mike Frysinger | 9b5f71e | 2005-04-23 06:26:38 +0000 | [diff] [blame] | 666 | |
Denys Vlasenko | 5b9b136 | 2010-02-02 03:08:57 +0100 | [diff] [blame] | 667 | printf(" Size: %-10llu\tBlocks: %-10llu IO Block: %-6lu %s\n" |
| 668 | "Device: %llxh/%llud\tInode: %-10llu Links: %-5lu", |
| 669 | (unsigned long long) statbuf.st_size, |
| 670 | (unsigned long long) statbuf.st_blocks, |
Denis Vlasenko | 8746885 | 2007-04-13 23:22:00 +0000 | [diff] [blame] | 671 | (unsigned long) statbuf.st_blksize, |
Mike Frysinger | 9b5f71e | 2005-04-23 06:26:38 +0000 | [diff] [blame] | 672 | file_type(&statbuf), |
Denys Vlasenko | 5b9b136 | 2010-02-02 03:08:57 +0100 | [diff] [blame] | 673 | (unsigned long long) statbuf.st_dev, |
| 674 | (unsigned long long) statbuf.st_dev, |
| 675 | (unsigned long long) statbuf.st_ino, |
Denis Vlasenko | 8746885 | 2007-04-13 23:22:00 +0000 | [diff] [blame] | 676 | (unsigned long) statbuf.st_nlink); |
Mike Frysinger | 9b5f71e | 2005-04-23 06:26:38 +0000 | [diff] [blame] | 677 | if (S_ISBLK(statbuf.st_mode) || S_ISCHR(statbuf.st_mode)) |
| 678 | printf(" Device type: %lx,%lx\n", |
Denis Vlasenko | 8746885 | 2007-04-13 23:22:00 +0000 | [diff] [blame] | 679 | (unsigned long) major(statbuf.st_rdev), |
| 680 | (unsigned long) minor(statbuf.st_rdev)); |
Mike Frysinger | 9b5f71e | 2005-04-23 06:26:38 +0000 | [diff] [blame] | 681 | else |
Denis Vlasenko | 4daad90 | 2007-09-27 10:20:47 +0000 | [diff] [blame] | 682 | bb_putchar('\n'); |
Denis Vlasenko | 49622d7 | 2007-03-10 16:58:49 +0000 | [diff] [blame] | 683 | printf("Access: (%04lo/%10.10s) Uid: (%5lu/%8s) Gid: (%5lu/%8s)\n", |
Denis Vlasenko | 8746885 | 2007-04-13 23:22:00 +0000 | [diff] [blame] | 684 | (unsigned long) (statbuf.st_mode & (S_ISUID|S_ISGID|S_ISVTX|S_IRWXU|S_IRWXG|S_IRWXO)), |
Mike Frysinger | 9b5f71e | 2005-04-23 06:26:38 +0000 | [diff] [blame] | 685 | bb_mode_string(statbuf.st_mode), |
Denis Vlasenko | 8746885 | 2007-04-13 23:22:00 +0000 | [diff] [blame] | 686 | (unsigned long) statbuf.st_uid, |
Denis Vlasenko | b75fe79 | 2008-06-27 22:31:07 +0000 | [diff] [blame] | 687 | (pw_ent != NULL) ? pw_ent->pw_name : "UNKNOWN", |
Denis Vlasenko | 8746885 | 2007-04-13 23:22:00 +0000 | [diff] [blame] | 688 | (unsigned long) statbuf.st_gid, |
Denis Vlasenko | b75fe79 | 2008-06-27 22:31:07 +0000 | [diff] [blame] | 689 | (gw_ent != NULL) ? gw_ent->gr_name : "UNKNOWN"); |
Denys Vlasenko | 5b9b136 | 2010-02-02 03:08:57 +0100 | [diff] [blame] | 690 | # if ENABLE_SELINUX |
Denis Vlasenko | 49622d7 | 2007-03-10 16:58:49 +0000 | [diff] [blame] | 691 | printf(" S_Context: %lc\n", *scontext); |
Denys Vlasenko | 5b9b136 | 2010-02-02 03:08:57 +0100 | [diff] [blame] | 692 | # endif |
Eric Lammerts | 66be919 | 2010-10-30 02:48:20 +0200 | [diff] [blame] | 693 | printf("Access: %s\n", human_time(statbuf.st_atime)); |
| 694 | printf("Modify: %s\n", human_time(statbuf.st_mtime)); |
| 695 | printf("Change: %s\n", human_time(statbuf.st_ctime)); |
Mike Frysinger | 9b5f71e | 2005-04-23 06:26:38 +0000 | [diff] [blame] | 696 | } |
Denys Vlasenko | e4dcba1 | 2010-10-28 18:57:19 +0200 | [diff] [blame] | 697 | #endif /* FEATURE_STAT_FORMAT */ |
Mike Frysinger | 9b5f71e | 2005-04-23 06:26:38 +0000 | [diff] [blame] | 698 | return 1; |
| 699 | } |
| 700 | |
Denis Vlasenko | 9b49a5e | 2007-10-11 10:05:36 +0000 | [diff] [blame] | 701 | int stat_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; |
Denys Vlasenko | e992bae | 2009-11-28 15:18:53 +0100 | [diff] [blame] | 702 | int stat_main(int argc UNUSED_PARAM, char **argv) |
Mike Frysinger | 9b5f71e | 2005-04-23 06:26:38 +0000 | [diff] [blame] | 703 | { |
Denis Vlasenko | 5e34ff2 | 2009-04-21 11:09:40 +0000 | [diff] [blame] | 704 | IF_FEATURE_STAT_FORMAT(char *format = NULL;) |
Bernhard Reutner-Fischer | 0e6ab01 | 2007-04-04 13:58:33 +0000 | [diff] [blame] | 705 | int i; |
Denys Vlasenko | e992bae | 2009-11-28 15:18:53 +0100 | [diff] [blame] | 706 | int ok; |
| 707 | unsigned opts; |
Denis Vlasenko | 85c2471 | 2008-03-17 09:04:04 +0000 | [diff] [blame] | 708 | statfunc_ptr statfunc = do_stat; |
Mike Frysinger | 9b5f71e | 2005-04-23 06:26:38 +0000 | [diff] [blame] | 709 | |
Denys Vlasenko | e992bae | 2009-11-28 15:18:53 +0100 | [diff] [blame] | 710 | opt_complementary = "-1"; /* min one arg */ |
| 711 | opts = getopt32(argv, "ftL" |
Denis Vlasenko | 5e34ff2 | 2009-04-21 11:09:40 +0000 | [diff] [blame] | 712 | IF_SELINUX("Z") |
| 713 | IF_FEATURE_STAT_FORMAT("c:", &format) |
Mike Frysinger | 9b5f71e | 2005-04-23 06:26:38 +0000 | [diff] [blame] | 714 | ); |
Denys Vlasenko | e992bae | 2009-11-28 15:18:53 +0100 | [diff] [blame] | 715 | if (opts & OPT_FILESYS) /* -f */ |
Mike Frysinger | 9b5f71e | 2005-04-23 06:26:38 +0000 | [diff] [blame] | 716 | statfunc = do_statfs; |
Denis Vlasenko | 49622d7 | 2007-03-10 16:58:49 +0000 | [diff] [blame] | 717 | #if ENABLE_SELINUX |
Denys Vlasenko | e992bae | 2009-11-28 15:18:53 +0100 | [diff] [blame] | 718 | if (opts & OPT_SELINUX) { |
Denis Vlasenko | 49622d7 | 2007-03-10 16:58:49 +0000 | [diff] [blame] | 719 | selinux_or_die(); |
| 720 | } |
Denys Vlasenko | e992bae | 2009-11-28 15:18:53 +0100 | [diff] [blame] | 721 | #endif |
| 722 | ok = 1; |
| 723 | argv += optind; |
| 724 | for (i = 0; argv[i]; ++i) |
Denis Vlasenko | 5e34ff2 | 2009-04-21 11:09:40 +0000 | [diff] [blame] | 725 | ok &= statfunc(argv[i] IF_FEATURE_STAT_FORMAT(, format)); |
Mike Frysinger | 9b5f71e | 2005-04-23 06:26:38 +0000 | [diff] [blame] | 726 | |
| 727 | return (ok ? EXIT_SUCCESS : EXIT_FAILURE); |
| 728 | } |