Changeset 3621 in MondoRescue for branches/3.3/mindi-busybox/coreutils/stat.c
- Timestamp:
- Dec 20, 2016, 4:07:32 PM (8 years ago)
- Location:
- branches/3.3
- Files:
-
- 1 edited
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
branches/3.3/mindi-busybox/coreutils/stat.c
r3232 r3621 13 13 * Licensed under GPLv2 or later, see file LICENSE in this source tree. 14 14 */ 15 //config:config STAT 16 //config: bool "stat" 17 //config: default y 18 //config: help 19 //config: display file or filesystem status. 20 //config: 21 //config:config FEATURE_STAT_FORMAT 22 //config: bool "Enable custom formats (-c)" 23 //config: default y 24 //config: depends on STAT 25 //config: help 26 //config: Without this, stat will not support the '-c format' option where 27 //config: users can pass a custom format string for output. This adds about 28 //config: 7k to a nonstatic build on amd64. 29 //config: 30 //config:config FEATURE_STAT_FILESYSTEM 31 //config: bool "Enable display of filesystem status (-f)" 32 //config: default y 33 //config: depends on STAT 34 //config: select PLATFORM_LINUX # statfs() 35 //config: help 36 //config: Without this, stat will not support the '-f' option to display 37 //config: information about filesystem status. 38 15 39 16 40 //usage:#define stat_trivial_usage 17 41 //usage: "[OPTIONS] FILE..." 18 42 //usage:#define stat_full_usage "\n\n" 19 //usage: "Display file (default) or filesystem status\n" 43 //usage: "Display file" 44 //usage: IF_FEATURE_STAT_FILESYSTEM(" (default) or filesystem") 45 //usage: " status\n" 20 46 //usage: IF_FEATURE_STAT_FORMAT( 21 //usage: "\n -c fmtUse the specified format"47 //usage: "\n -c FMT Use the specified format" 22 48 //usage: ) 49 //usage: IF_FEATURE_STAT_FILESYSTEM( 23 50 //usage: "\n -f Display filesystem status" 51 //usage: ) 24 52 //usage: "\n -L Follow links" 25 //usage: "\n -t Display info in terse form"53 //usage: "\n -t Terse display" 26 54 //usage: IF_SELINUX( 27 55 //usage: "\n -Z Print security context" 28 56 //usage: ) 29 57 //usage: IF_FEATURE_STAT_FORMAT( 30 //usage: "\n\n Valid format sequences for files:\n"58 //usage: "\n\nFMT sequences"IF_FEATURE_STAT_FILESYSTEM(" for files")":\n" 31 59 //usage: " %a Access rights in octal\n" 32 60 //usage: " %A Access rights in human readable form\n" 33 61 //usage: " %b Number of blocks allocated (see %B)\n" 34 //usage: " %B The size in bytes of each block reported by %b\n"62 //usage: " %B Size in bytes of each block reported by %b\n" 35 63 //usage: " %d Device number in decimal\n" 36 64 //usage: " %D Device number in hex\n" 37 65 //usage: " %f Raw mode in hex\n" 38 66 //usage: " %F File type\n" 39 //usage: " %g Group ID of owner\n"40 //usage: " %G Group name of owner\n"67 //usage: " %g Group ID\n" 68 //usage: " %G Group name\n" 41 69 //usage: " %h Number of hard links\n" 42 70 //usage: " %i Inode number\n" … … 44 72 //usage: " %N File name, with -> TARGET if symlink\n" 45 73 //usage: " %o I/O block size\n" 46 //usage: " %s Total size ,in bytes\n"74 //usage: " %s Total size in bytes\n" 47 75 //usage: " %t Major device type in hex\n" 48 76 //usage: " %T Minor device type in hex\n" 49 //usage: " %u User ID of owner\n"50 //usage: " %U User name of owner\n"77 //usage: " %u User ID\n" 78 //usage: " %U User name\n" 51 79 //usage: " %x Time of last access\n" 52 80 //usage: " %X Time of last access as seconds since Epoch\n" … … 55 83 //usage: " %z Time of last change\n" 56 84 //usage: " %Z Time of last change as seconds since Epoch\n" 57 //usage: "\nValid format sequences for file systems:\n" 85 //usage: IF_FEATURE_STAT_FILESYSTEM( 86 //usage: "\nFMT sequences for file systems:\n" 58 87 //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"88 //usage: " %b Total data blocks\n" 89 //usage: " %c Total file nodes\n" 90 //usage: " %d Free file nodes\n" 91 //usage: " %f Free blocks\n" 63 92 //usage: IF_SELINUX( 64 93 //usage: " %C Security context in selinux\n" … … 72 101 //usage: " %T Type in human readable form" 73 102 //usage: ) 103 //usage: ) 74 104 75 105 #include "libbb.h" 76 77 #define OPT_FILESYS (1 << 0) 78 #define OPT_TERSE (1 << 1) 79 #define OPT_DEREFERENCE (1 << 2) 80 #define OPT_SELINUX (1 << 3) 106 #include "common_bufsiz.h" 107 108 enum { 109 OPT_TERSE = (1 << 0), 110 OPT_DEREFERENCE = (1 << 1), 111 OPT_FILESYS = (1 << 2) * ENABLE_FEATURE_STAT_FILESYSTEM, 112 OPT_SELINUX = (1 << (2+ENABLE_FEATURE_STAT_FILESYSTEM)) * ENABLE_SELINUX, 113 }; 81 114 82 115 #if ENABLE_FEATURE_STAT_FORMAT … … 127 160 /*static char buf[sizeof("YYYY-MM-DD HH:MM:SS.000000000")] ALIGN1;*/ 128 161 #define buf bb_common_bufsiz1 129 130 str ftime(buf, sizeof(buf), "%Y-%m-%d %H:%M:%S.000000000", localtime(&t));162 setup_common_bufsiz(); 163 strcpy(strftime_YYYYMMDDHHMMSS(buf, COMMON_BUFSIZE, &t), ".000000000"); 131 164 return buf; 132 165 #undef buf 133 166 } 134 167 168 #if ENABLE_FEATURE_STAT_FILESYSTEM 135 169 /* Return the type of the specified file system. 136 170 * Some systems have statfvs.f_basetype[FSTYPSZ]. (AIX, HP-UX, and Solaris) … … 203 237 return r; 204 238 } 239 #endif /* FEATURE_STAT_FILESYSTEM */ 205 240 206 241 #if ENABLE_FEATURE_STAT_FORMAT … … 218 253 } 219 254 255 #if ENABLE_FEATURE_STAT_FILESYSTEM 220 256 /* print statfs info */ 221 257 static void FAST_FUNC print_statfs(char *pformat, const char m, … … 264 300 } 265 301 } 302 #endif 266 303 267 304 /* print stat info */ … … 375 412 /* Create a working copy of the format string */ 376 413 char *format = xstrdup(masterformat); 377 /* Add 2 to accom odate our conversion of the stat '%s' format string414 /* Add 2 to accommodate our conversion of the stat '%s' format string 378 415 * to the printf '%llu' one. */ 379 416 char *dest = xmalloc(strlen(format) + 2 + 1); … … 424 461 #endif /* FEATURE_STAT_FORMAT */ 425 462 463 #if ENABLE_FEATURE_STAT_FILESYSTEM 426 464 /* Stat the file system and print what we find. */ 427 465 #if !ENABLE_FEATURE_STAT_FORMAT … … 539 577 return 1; 540 578 } 579 #endif /* FEATURE_STAT_FILESYSTEM */ 541 580 542 581 /* stat the file and print what we find */ … … 656 695 # if ENABLE_SELINUX 657 696 if (option_mask32 & OPT_SELINUX) 658 printf(" % lc\n", *scontext);697 printf(" %s\n", scontext); 659 698 else 660 699 bb_putchar('\n'); … … 701 740 (gw_ent != NULL) ? gw_ent->gr_name : "UNKNOWN"); 702 741 # if ENABLE_SELINUX 703 printf(" S_Context: %lc\n", *scontext); 742 if (option_mask32 & OPT_SELINUX) 743 printf(" S_Context: %s\n", scontext); 704 744 # endif 705 745 printf("Access: %s\n", human_time(statbuf.st_atime)); … … 721 761 722 762 opt_complementary = "-1"; /* min one arg */ 723 opts = getopt32(argv, "ftL" 763 opts = getopt32(argv, "tL" 764 IF_FEATURE_STAT_FILESYSTEM("f") 724 765 IF_SELINUX("Z") 725 766 IF_FEATURE_STAT_FORMAT("c:", &format) 726 767 ); 768 #if ENABLE_FEATURE_STAT_FILESYSTEM 727 769 if (opts & OPT_FILESYS) /* -f */ 728 770 statfunc = do_statfs; 771 #endif 729 772 #if ENABLE_SELINUX 730 773 if (opts & OPT_SELINUX) {
Note:
See TracChangeset
for help on using the changeset viewer.