Changeset 3621 in MondoRescue for branches/3.3/mindi-busybox/coreutils/stat.c


Ignore:
Timestamp:
Dec 20, 2016, 4:07:32 PM (7 years ago)
Author:
Bruno Cornec
Message:

New 3?3 banch for incorporation of latest busybox 1.25. Changing minor version to handle potential incompatibilities.

Location:
branches/3.3
Files:
1 edited
1 copied

Legend:

Unmodified
Added
Removed
  • branches/3.3/mindi-busybox/coreutils/stat.c

    r3232 r3621  
    1313 * Licensed under GPLv2 or later, see file LICENSE in this source tree.
    1414 */
     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
    1539
    1640//usage:#define stat_trivial_usage
    1741//usage:       "[OPTIONS] FILE..."
    1842//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"
    2046//usage:    IF_FEATURE_STAT_FORMAT(
    21 //usage:     "\n    -c fmt  Use the specified format"
     47//usage:     "\n    -c FMT  Use the specified format"
    2248//usage:    )
     49//usage:    IF_FEATURE_STAT_FILESYSTEM(
    2350//usage:     "\n    -f  Display filesystem status"
     51//usage:    )
    2452//usage:     "\n    -L  Follow links"
    25 //usage:     "\n    -t  Display info in terse form"
     53//usage:     "\n    -t  Terse display"
    2654//usage:    IF_SELINUX(
    2755//usage:     "\n    -Z  Print security context"
    2856//usage:    )
    2957//usage:    IF_FEATURE_STAT_FORMAT(
    30 //usage:       "\n\nValid format sequences for files:\n"
     58//usage:       "\n\nFMT sequences"IF_FEATURE_STAT_FILESYSTEM(" for files")":\n"
    3159//usage:       " %a Access rights in octal\n"
    3260//usage:       " %A Access rights in human readable form\n"
    3361//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"
    3563//usage:       " %d Device number in decimal\n"
    3664//usage:       " %D Device number in hex\n"
    3765//usage:       " %f Raw mode in hex\n"
    3866//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"
    4169//usage:       " %h Number of hard links\n"
    4270//usage:       " %i Inode number\n"
     
    4472//usage:       " %N File name, with -> TARGET if symlink\n"
    4573//usage:       " %o I/O block size\n"
    46 //usage:       " %s Total size, in bytes\n"
     74//usage:       " %s Total size in bytes\n"
    4775//usage:       " %t Major device type in hex\n"
    4876//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"
    5179//usage:       " %x Time of last access\n"
    5280//usage:       " %X Time of last access as seconds since Epoch\n"
     
    5583//usage:       " %z Time of last change\n"
    5684//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"
    5887//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"
    6392//usage:    IF_SELINUX(
    6493//usage:       " %C Security context in selinux\n"
     
    72101//usage:       " %T Type in human readable form"
    73102//usage:    )
     103//usage:    )
    74104
    75105#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
     108enum {
     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};
    81114
    82115#if ENABLE_FEATURE_STAT_FORMAT
     
    127160    /*static char buf[sizeof("YYYY-MM-DD HH:MM:SS.000000000")] ALIGN1;*/
    128161#define buf bb_common_bufsiz1
    129 
    130     strftime(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");
    131164    return buf;
    132165#undef buf
    133166}
    134167
     168#if ENABLE_FEATURE_STAT_FILESYSTEM
    135169/* Return the type of the specified file system.
    136170 * Some systems have statfvs.f_basetype[FSTYPSZ]. (AIX, HP-UX, and Solaris)
     
    203237    return r;
    204238}
     239#endif  /* FEATURE_STAT_FILESYSTEM */
    205240
    206241#if ENABLE_FEATURE_STAT_FORMAT
     
    218253}
    219254
     255#if ENABLE_FEATURE_STAT_FILESYSTEM
    220256/* print statfs info */
    221257static void FAST_FUNC print_statfs(char *pformat, const char m,
     
    264300    }
    265301}
     302#endif
    266303
    267304/* print stat info */
     
    375412    /* Create a working copy of the format string */
    376413    char *format = xstrdup(masterformat);
    377     /* Add 2 to accomodate our conversion of the stat '%s' format string
     414    /* Add 2 to accommodate our conversion of the stat '%s' format string
    378415     * to the printf '%llu' one.  */
    379416    char *dest = xmalloc(strlen(format) + 2 + 1);
     
    424461#endif  /* FEATURE_STAT_FORMAT */
    425462
     463#if ENABLE_FEATURE_STAT_FILESYSTEM
    426464/* Stat the file system and print what we find.  */
    427465#if !ENABLE_FEATURE_STAT_FORMAT
     
    539577    return 1;
    540578}
     579#endif  /* FEATURE_STAT_FILESYSTEM */
    541580
    542581/* stat the file and print what we find */
     
    656695# if ENABLE_SELINUX
    657696        if (option_mask32 & OPT_SELINUX)
    658             printf(" %lc\n", *scontext);
     697            printf(" %s\n", scontext);
    659698        else
    660699            bb_putchar('\n');
     
    701740               (gw_ent != NULL) ? gw_ent->gr_name : "UNKNOWN");
    702741# if ENABLE_SELINUX
    703         printf("   S_Context: %lc\n", *scontext);
     742        if (option_mask32 & OPT_SELINUX)
     743            printf("   S_Context: %s\n", scontext);
    704744# endif
    705745        printf("Access: %s\n", human_time(statbuf.st_atime));
     
    721761
    722762    opt_complementary = "-1"; /* min one arg */
    723     opts = getopt32(argv, "ftL"
     763    opts = getopt32(argv, "tL"
     764        IF_FEATURE_STAT_FILESYSTEM("f")
    724765        IF_SELINUX("Z")
    725766        IF_FEATURE_STAT_FORMAT("c:", &format)
    726767    );
     768#if ENABLE_FEATURE_STAT_FILESYSTEM
    727769    if (opts & OPT_FILESYS) /* -f */
    728770        statfunc = do_statfs;
     771#endif
    729772#if ENABLE_SELINUX
    730773    if (opts & OPT_SELINUX) {
Note: See TracChangeset for help on using the changeset viewer.