summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--e2fsprogs/chattr.c24
-rw-r--r--e2fsprogs/e2fs_lib.c98
-rw-r--r--e2fsprogs/e2fs_lib.h13
-rw-r--r--e2fsprogs/lsattr.c3
4 files changed, 80 insertions, 58 deletions
diff --git a/e2fsprogs/chattr.c b/e2fsprogs/chattr.c
index db54372..0f19af8 100644
--- a/e2fsprogs/chattr.c
+++ b/e2fsprogs/chattr.c
@@ -37,27 +37,9 @@ struct globals {
static unsigned long get_flag(char c)
{
- /* Two separate vectors take less space than vector of structs */
- static const char flags_letter[] ALIGN1 = "ASDacdijsutT";
- static const unsigned long flags_val[] = {
- /* 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];
+ const char *fp = strchr(e2attr_flags_sname_chattr, c);
+ if (fp)
+ return e2attr_flags_value_chattr[fp - e2attr_flags_sname_chattr];
bb_show_usage();
}
diff --git a/e2fsprogs/e2fs_lib.c b/e2fsprogs/e2fs_lib.c
index 890cb30..89e0500 100644
--- a/e2fsprogs/e2fs_lib.c
+++ b/e2fsprogs/e2fs_lib.c
@@ -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 */
-struct flags_name {
- unsigned long flag;
- char short_name;
- const char *long_name;
+const uint32_t e2attr_flags_value[] = {
+#ifdef ENABLE_COMPRESSION
+ EXT2_COMPRBLK_FL,
+ 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
- * 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" },
+const char e2attr_flags_sname[] =
#ifdef ENABLE_COMPRESSION
- { EXT2_COMPRBLK_FL, 'B', "Compressed_File" },
- { EXT2_DIRTY_FL, 'Z', "Compressed_Dirty_File" },
- { EXT2_NOCOMPR_FL, 'X', "Compression_Raw_Access" },
- { EXT2_ECOMPR_FL, 'E', "Compression_Error" },
+ "BZXE"
#endif
- { EXT3_JOURNAL_DATA_FL, 'j', "Journaled_Data" },
- { EXT2_INDEX_FL, 'I', "Indexed_directory" },
- { EXT2_NOTAIL_FL, 't', "No_Tailmerging" },
- { EXT2_TOPDIR_FL, 'T', "Top_of_Directory_Hierarchies" },
- { 0, '\0', NULL }
-};
+ "I"
+ "suSDiadAcjtT";
+
+static const char e2attr_flags_lname[] =
+#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)
{
- const struct flags_name *fp;
+ const uint32_t *fv;
+ const char *fn;
+ fv = e2attr_flags_value;
if (options & PFOPT_LONG) {
int first = 1;
- for (fp = flags_array; fp->short_name; fp++) {
- if (flags & fp->flag) {
+ fn = e2attr_flags_lname;
+ do {
+ if (flags & *fv) {
if (!first)
fputs(", ", f);
- fputs(fp->long_name, f);
+ fputs(fn, f);
first = 0;
}
- }
+ fv++;
+ fn += strlen(fn) + 1;
+ } while (*fn);
if (first)
fputs("---", f);
} else {
- for (fp = flags_array; fp->short_name; fp++) {
+ fn = e2attr_flags_sname;
+ do {
char c = '-';
- if (flags & fp->flag)
- c = fp->short_name;
+ if (flags & *fv)
+ c = *fn;
fputc(c, f);
- }
+ fv++;
+ fn++;
+ } while (*fn);
}
}
diff --git a/e2fsprogs/e2fs_lib.h b/e2fsprogs/e2fs_lib.h
index 1a7d3a1..d01249d 100644
--- a/e2fsprogs/e2fs_lib.h
+++ b/e2fsprogs/e2fs_lib.h
@@ -28,3 +28,16 @@ int fgetsetflags(const char *name, unsigned long *get_flags, unsigned long set_f
#define PFOPT_LONG 1
/* Print file attributes on an ext2 file system */
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
diff --git a/e2fsprogs/lsattr.c b/e2fsprogs/lsattr.c
index 6f4b974..a11f243 100644
--- a/e2fsprogs/lsattr.c
+++ b/e2fsprogs/lsattr.c
@@ -104,8 +104,7 @@ int lsattr_main(int argc, char **argv)
if (!*argv)
lsattr_args(".");
else {
- while (*argv)
- lsattr_args(*argv++);
+ do lsattr_args(*argv++); while (*argv);
}
return EXIT_SUCCESS;