Ignore:
Timestamp:
Nov 4, 2007, 3:16:40 AM (16 years ago)
Author:
Bruno Cornec
Message:

Update to busybox 1.7.2

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/2.2.5/mindi-busybox/e2fsprogs/lsattr.c

    r821 r1765  
     1/* vi: set sw=4 ts=4: */
    12/*
    23 * lsattr.c     - List file attributes on an ext2 file system
     
    1819 */
    1920
    20 #include <sys/types.h>
    21 #include <dirent.h>
    22 #include <errno.h>
    23 #include <fcntl.h>
    24 #include <getopt.h>
    25 #include <stdio.h>
    26 #include <unistd.h>
    27 #include <stdlib.h>
    28 #include <string.h>
    29 #include <sys/param.h>
    30 #include <sys/stat.h>
     21#include "libbb.h"
     22#include "e2fs_lib.h"
    3123
    32 #include "ext2fs/ext2_fs.h"
    33 #include "e2fsbb.h"
    34 #include "e2p/e2p.h"
    35 
    36 #define OPT_RECUR 1
    37 #define OPT_ALL 2
    38 #define OPT_DIRS_OPT 4
    39 #define OPT_PF_LONG 8
    40 #define OPT_GENERATION 16
    41 static int flags;
    42 
    43 #ifdef CONFIG_LFS
    44 # define LSTAT lstat64
    45 # define STRUCT_STAT struct stat64
    46 #else
    47 # define LSTAT lstat
    48 # define STRUCT_STAT struct stat
    49 #endif
     24enum {
     25    OPT_RECUR      = 0x1,
     26    OPT_ALL        = 0x2,
     27    OPT_DIRS_OPT   = 0x4,
     28    OPT_PF_LONG    = 0x8,
     29    OPT_GENERATION = 0x10,
     30};
    5031
    5132static void list_attributes(const char *name)
     
    5435    unsigned long generation;
    5536
    56     if (fgetflags(name, &fsflags) == -1)
     37    if (fgetflags(name, &fsflags) != 0)
    5738        goto read_err;
    58     if (flags & OPT_GENERATION) {
    59         if (fgetversion(name, &generation) == -1)
     39
     40    if (option_mask32 & OPT_GENERATION) {
     41        if (fgetversion(name, &generation) != 0)
    6042            goto read_err;
    6143        printf("%5lu ", generation);
    6244    }
    6345
    64     if (flags & OPT_PF_LONG) {
     46    if (option_mask32 & OPT_PF_LONG) {
    6547        printf("%-28s ", name);
    6648        print_flags(stdout, fsflags, PFOPT_LONG);
    67         printf("\n");
     49        puts("");
    6850    } else {
    6951        print_flags(stdout, fsflags, 0);
     
    7254
    7355    return;
    74 read_err:
     56 read_err:
    7557    bb_perror_msg("reading %s", name);
    76 }
    77 
    78 static int lsattr_dir_proc(const char *, struct dirent *, void *);
    79 
    80 static void lsattr_args(const char *name)
    81 {
    82     STRUCT_STAT st;
    83 
    84     if (LSTAT(name, &st) == -1) {
    85         bb_perror_msg("stating %s", name);
    86     } else {
    87         if (S_ISDIR(st.st_mode) && !(flags & OPT_DIRS_OPT))
    88             iterate_on_dir(name, lsattr_dir_proc, NULL);
    89         else
    90             list_attributes(name);
    91     }
    9258}
    9359
     
    9561               void *private)
    9662{
    97     STRUCT_STAT st;
     63    struct stat st;
    9864    char *path;
    9965
    10066    path = concat_path_file(dir_name, de->d_name);
    10167
    102     if (LSTAT(path, &st) == -1)
    103         bb_perror_msg(path);
    104     else {
    105         if (de->d_name[0] != '.' || (flags & OPT_ALL)) {
    106             list_attributes(path);
    107             if (S_ISDIR(st.st_mode) && (flags & OPT_RECUR) &&
    108                (de->d_name[0] != '.' && (de->d_name[1] != '\0' ||
    109                (de->d_name[1] != '.' && de->d_name[2] != '\0')))) {
    110                 printf("\n%s:\n", path);
    111                 iterate_on_dir(path, lsattr_dir_proc, NULL);
    112                 printf("\n");
    113             }
     68    if (lstat(path, &st) != 0)
     69        bb_perror_msg("stat %s", path);
     70    else if (de->d_name[0] != '.' || (option_mask32 & OPT_ALL)) {
     71        list_attributes(path);
     72        if (S_ISDIR(st.st_mode) && (option_mask32 & OPT_RECUR)
     73         && !DOT_OR_DOTDOT(de->d_name)
     74        ) {
     75            printf("\n%s:\n", path);
     76            iterate_on_dir(path, lsattr_dir_proc, NULL);
     77            puts("");
    11478        }
    11579    }
    11680
    11781    free(path);
    118 
    11982    return 0;
    12083}
    12184
     85static void lsattr_args(const char *name)
     86{
     87    struct stat st;
     88
     89    if (lstat(name, &st) == -1) {
     90        bb_perror_msg("stat %s", name);
     91    } else if (S_ISDIR(st.st_mode) && !(option_mask32 & OPT_DIRS_OPT)) {
     92        iterate_on_dir(name, lsattr_dir_proc, NULL);
     93    } else {
     94        list_attributes(name);
     95    }
     96}
     97
     98int lsattr_main(int argc, char **argv);
    12299int lsattr_main(int argc, char **argv)
    123100{
    124     int i;
     101    getopt32(argv, "Radlv");
     102    argv += optind;
    125103
    126     flags = bb_getopt_ulflags(argc, argv, "Radlv");
    127 
    128     if (optind > argc - 1)
     104    if (!*argv)
    129105        lsattr_args(".");
    130     else
    131         for (i = optind; i < argc; i++)
    132             lsattr_args(argv[i]);
     106    else {
     107        while (*argv)
     108            lsattr_args(*argv++);
     109    }
    133110
    134111    return EXIT_SUCCESS;
Note: See TracChangeset for help on using the changeset viewer.