e2fsprogs: code shrink

text    data     bss     dec     hex filename
 776594     974    9420  786988   c022c busybox_old
 776494     974    9420  786888   c01c8 busybox_unstripped
This commit is contained in:
Denis Vlasenko 2007-10-30 19:36:07 +00:00
parent 1641d614fa
commit d059ddc1bb
4 changed files with 80 additions and 58 deletions

View File

@ -37,27 +37,9 @@ struct globals {
static unsigned long get_flag(char c) static unsigned long get_flag(char c)
{ {
/* Two separate vectors take less space than vector of structs */ const char *fp = strchr(e2attr_flags_sname_chattr, c);
static const char flags_letter[] ALIGN1 = "ASDacdijsutT"; if (fp)
static const unsigned long flags_val[] = { return e2attr_flags_value_chattr[fp - e2attr_flags_sname_chattr];
/* A */ EXT2_NOATIME_FL,
/* S */ EXT2_SYNC_FL,
/* D */ EXT2_DIRSYNC_FL,
/* a */ EXT2_APPEND_FL,
/* c */ EXT2_COMPR_FL,
/* d */ EXT2_NODUMP_FL,
/* i */ EXT2_IMMUTABLE_FL,
/* j */ EXT3_JOURNAL_DATA_FL,
/* s */ EXT2_SECRM_FL,
/* u */ EXT2_UNRM_FL,
/* t */ EXT2_NOTAIL_FL,
/* T */ EXT2_TOPDIR_FL,
};
const char *fp;
for (fp = flags_letter; *fp; fp++)
if (*fp == c)
return flags_val[fp - flags_letter];
bb_show_usage(); bb_show_usage();
} }

View File

@ -141,59 +141,87 @@ int fgetsetflags(const char *name, unsigned long *get_flags, unsigned long set_f
/* Print file attributes on an ext2 file system */ /* Print file attributes on an ext2 file system */
struct flags_name { const uint32_t e2attr_flags_value[] = {
unsigned long flag; #ifdef ENABLE_COMPRESSION
char short_name; EXT2_COMPRBLK_FL,
const char *long_name; EXT2_DIRTY_FL,
EXT2_NOCOMPR_FL,
EXT2_ECOMPR_FL,
#endif
EXT2_INDEX_FL,
EXT2_SECRM_FL,
EXT2_UNRM_FL,
EXT2_SYNC_FL,
EXT2_DIRSYNC_FL,
EXT2_IMMUTABLE_FL,
EXT2_APPEND_FL,
EXT2_NODUMP_FL,
EXT2_NOATIME_FL,
EXT2_COMPR_FL,
EXT3_JOURNAL_DATA_FL,
EXT2_NOTAIL_FL,
EXT2_TOPDIR_FL
}; };
/* TODO: apart from I and (disabled) COMPRESSION flags, this const char e2attr_flags_sname[] =
* is a duplicate of a table from chattr. Merge? */
static const struct flags_name flags_array[] = {
{ EXT2_SECRM_FL, 's', "Secure_Deletion" },
{ EXT2_UNRM_FL, 'u' , "Undelete" },
{ EXT2_SYNC_FL, 'S', "Synchronous_Updates" },
{ EXT2_DIRSYNC_FL, 'D', "Synchronous_Directory_Updates" },
{ EXT2_IMMUTABLE_FL, 'i', "Immutable" },
{ EXT2_APPEND_FL, 'a', "Append_Only" },
{ EXT2_NODUMP_FL, 'd', "No_Dump" },
{ EXT2_NOATIME_FL, 'A', "No_Atime" },
{ EXT2_COMPR_FL, 'c', "Compression_Requested" },
#ifdef ENABLE_COMPRESSION #ifdef ENABLE_COMPRESSION
{ EXT2_COMPRBLK_FL, 'B', "Compressed_File" }, "BZXE"
{ EXT2_DIRTY_FL, 'Z', "Compressed_Dirty_File" },
{ EXT2_NOCOMPR_FL, 'X', "Compression_Raw_Access" },
{ EXT2_ECOMPR_FL, 'E', "Compression_Error" },
#endif #endif
{ EXT3_JOURNAL_DATA_FL, 'j', "Journaled_Data" }, "I"
{ EXT2_INDEX_FL, 'I', "Indexed_directory" }, "suSDiadAcjtT";
{ EXT2_NOTAIL_FL, 't', "No_Tailmerging" },
{ EXT2_TOPDIR_FL, 'T', "Top_of_Directory_Hierarchies" }, static const char e2attr_flags_lname[] =
{ 0, '\0', NULL } #ifdef ENABLE_COMPRESSION
}; "Compressed_File" "\0"
"Compressed_Dirty_File" "\0"
"Compression_Raw_Access" "\0"
"Compression_Error" "\0"
#endif
"Indexed_directory" "\0"
"Secure_Deletion" "\0"
"Undelete" "\0"
"Synchronous_Updates" "\0"
"Synchronous_Directory_Updates" "\0"
"Immutable" "\0"
"Append_Only" "\0"
"No_Dump" "\0"
"No_Atime" "\0"
"Compression_Requested" "\0"
"Journaled_Data" "\0"
"No_Tailmerging" "\0"
"Top_of_Directory_Hierarchies" "\0"
/* Another trailing NUL is added by compiler */;
void print_flags(FILE *f, unsigned long flags, unsigned options) void print_flags(FILE *f, unsigned long flags, unsigned options)
{ {
const struct flags_name *fp; const uint32_t *fv;
const char *fn;
fv = e2attr_flags_value;
if (options & PFOPT_LONG) { if (options & PFOPT_LONG) {
int first = 1; int first = 1;
for (fp = flags_array; fp->short_name; fp++) { fn = e2attr_flags_lname;
if (flags & fp->flag) { do {
if (flags & *fv) {
if (!first) if (!first)
fputs(", ", f); fputs(", ", f);
fputs(fp->long_name, f); fputs(fn, f);
first = 0; first = 0;
} }
} fv++;
fn += strlen(fn) + 1;
} while (*fn);
if (first) if (first)
fputs("---", f); fputs("---", f);
} else { } else {
for (fp = flags_array; fp->short_name; fp++) { fn = e2attr_flags_sname;
do {
char c = '-'; char c = '-';
if (flags & fp->flag) if (flags & *fv)
c = fp->short_name; c = *fn;
fputc(c, f); fputc(c, f);
} fv++;
fn++;
} while (*fn);
} }
} }

View File

@ -28,3 +28,16 @@ int fgetsetflags(const char *name, unsigned long *get_flags, unsigned long set_f
#define PFOPT_LONG 1 #define PFOPT_LONG 1
/* Print file attributes on an ext2 file system */ /* Print file attributes on an ext2 file system */
void print_flags(FILE *f, unsigned long flags, unsigned options); void print_flags(FILE *f, unsigned long flags, unsigned options);
extern const uint32_t e2attr_flags_value[];
extern const char e2attr_flags_sname[];
/* If you plan to ENABLE_COMPRESSION, see e2fs_lib.c and chattr.c - */
/* make sure that chattr doesn't accept bad options! */
#ifdef ENABLE_COMPRESSION
#define e2attr_flags_value_chattr (&e2attr_flags_value[5])
#define e2attr_flags_sname_chattr (&e2attr_flags_sname[5])
#else
#define e2attr_flags_value_chattr (&e2attr_flags_value[1])
#define e2attr_flags_sname_chattr (&e2attr_flags_sname[1])
#endif

View File

@ -104,8 +104,7 @@ int lsattr_main(int argc, char **argv)
if (!*argv) if (!*argv)
lsattr_args("."); lsattr_args(".");
else { else {
while (*argv) do lsattr_args(*argv++); while (*argv);
lsattr_args(*argv++);
} }
return EXIT_SUCCESS; return EXIT_SUCCESS;