aboutsummaryrefslogtreecommitdiff
path: root/e2fsprogs/e2fs_lib.c
diff options
context:
space:
mode:
Diffstat (limited to 'e2fsprogs/e2fs_lib.c')
-rw-r--r--e2fsprogs/e2fs_lib.c98
1 files changed, 63 insertions, 35 deletions
diff --git a/e2fsprogs/e2fs_lib.c b/e2fsprogs/e2fs_lib.c
index 890cb302b..89e050051 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
141 141
142 142
143/* Print file attributes on an ext2 file system */ 143/* Print file attributes on an ext2 file system */
144struct flags_name { 144const uint32_t e2attr_flags_value[] = {
145 unsigned long flag; 145#ifdef ENABLE_COMPRESSION
146 char short_name; 146 EXT2_COMPRBLK_FL,
147 const char *long_name; 147 EXT2_DIRTY_FL,
148 EXT2_NOCOMPR_FL,
149 EXT2_ECOMPR_FL,
150#endif
151 EXT2_INDEX_FL,
152 EXT2_SECRM_FL,
153 EXT2_UNRM_FL,
154 EXT2_SYNC_FL,
155 EXT2_DIRSYNC_FL,
156 EXT2_IMMUTABLE_FL,
157 EXT2_APPEND_FL,
158 EXT2_NODUMP_FL,
159 EXT2_NOATIME_FL,
160 EXT2_COMPR_FL,
161 EXT3_JOURNAL_DATA_FL,
162 EXT2_NOTAIL_FL,
163 EXT2_TOPDIR_FL
148}; 164};
149 165
150/* TODO: apart from I and (disabled) COMPRESSION flags, this 166const char e2attr_flags_sname[] =
151 * is a duplicate of a table from chattr. Merge? */
152static const struct flags_name flags_array[] = {
153 { EXT2_SECRM_FL, 's', "Secure_Deletion" },
154 { EXT2_UNRM_FL, 'u' , "Undelete" },
155 { EXT2_SYNC_FL, 'S', "Synchronous_Updates" },
156 { EXT2_DIRSYNC_FL, 'D', "Synchronous_Directory_Updates" },
157 { EXT2_IMMUTABLE_FL, 'i', "Immutable" },
158 { EXT2_APPEND_FL, 'a', "Append_Only" },
159 { EXT2_NODUMP_FL, 'd', "No_Dump" },
160 { EXT2_NOATIME_FL, 'A', "No_Atime" },
161 { EXT2_COMPR_FL, 'c', "Compression_Requested" },
162#ifdef ENABLE_COMPRESSION 167#ifdef ENABLE_COMPRESSION
163 { EXT2_COMPRBLK_FL, 'B', "Compressed_File" }, 168 "BZXE"
164 { EXT2_DIRTY_FL, 'Z', "Compressed_Dirty_File" },
165 { EXT2_NOCOMPR_FL, 'X', "Compression_Raw_Access" },
166 { EXT2_ECOMPR_FL, 'E', "Compression_Error" },
167#endif 169#endif
168 { EXT3_JOURNAL_DATA_FL, 'j', "Journaled_Data" }, 170 "I"
169 { EXT2_INDEX_FL, 'I', "Indexed_directory" }, 171 "suSDiadAcjtT";
170 { EXT2_NOTAIL_FL, 't', "No_Tailmerging" }, 172
171 { EXT2_TOPDIR_FL, 'T', "Top_of_Directory_Hierarchies" }, 173static const char e2attr_flags_lname[] =
172 { 0, '\0', NULL } 174#ifdef ENABLE_COMPRESSION
173}; 175 "Compressed_File" "\0"
176 "Compressed_Dirty_File" "\0"
177 "Compression_Raw_Access" "\0"
178 "Compression_Error" "\0"
179#endif
180 "Indexed_directory" "\0"
181 "Secure_Deletion" "\0"
182 "Undelete" "\0"
183 "Synchronous_Updates" "\0"
184 "Synchronous_Directory_Updates" "\0"
185 "Immutable" "\0"
186 "Append_Only" "\0"
187 "No_Dump" "\0"
188 "No_Atime" "\0"
189 "Compression_Requested" "\0"
190 "Journaled_Data" "\0"
191 "No_Tailmerging" "\0"
192 "Top_of_Directory_Hierarchies" "\0"
193 /* Another trailing NUL is added by compiler */;
174 194
175void print_flags(FILE *f, unsigned long flags, unsigned options) 195void print_flags(FILE *f, unsigned long flags, unsigned options)
176{ 196{
177 const struct flags_name *fp; 197 const uint32_t *fv;
198 const char *fn;
178 199
200 fv = e2attr_flags_value;
179 if (options & PFOPT_LONG) { 201 if (options & PFOPT_LONG) {
180 int first = 1; 202 int first = 1;
181 for (fp = flags_array; fp->short_name; fp++) { 203 fn = e2attr_flags_lname;
182 if (flags & fp->flag) { 204 do {
205 if (flags & *fv) {
183 if (!first) 206 if (!first)
184 fputs(", ", f); 207 fputs(", ", f);
185 fputs(fp->long_name, f); 208 fputs(fn, f);
186 first = 0; 209 first = 0;
187 } 210 }
188 } 211 fv++;
212 fn += strlen(fn) + 1;
213 } while (*fn);
189 if (first) 214 if (first)
190 fputs("---", f); 215 fputs("---", f);
191 } else { 216 } else {
192 for (fp = flags_array; fp->short_name; fp++) { 217 fn = e2attr_flags_sname;
218 do {
193 char c = '-'; 219 char c = '-';
194 if (flags & fp->flag) 220 if (flags & *fv)
195 c = fp->short_name; 221 c = *fn;
196 fputc(c, f); 222 fputc(c, f);
197 } 223 fv++;
224 fn++;
225 } while (*fn);
198 } 226 }
199} 227}