blob: 4a611765a1fe9679625a63d1e4095345a0552f31 [file] [log] [blame]
Theodore Ts'o3839e651997-04-26 13:21:57 +00001/*
2 * pf.c - Print file attributes on an ext2 file system
3 *
4 * Copyright (C) 1993, 1994 Remy Card <card@masi.ibp.fr>
5 * Laboratoire MASI, Institut Blaise Pascal
6 * Universite Pierre et Marie Curie (Paris VI)
7 *
8 * This file can be redistributed under the terms of the GNU Library General
9 * Public License
10 */
11
12/*
13 * History:
14 * 93/10/30 - Creation
15 */
16
17#include <stdio.h>
Theodore Ts'o3839e651997-04-26 13:21:57 +000018
19#include "e2p.h"
20
Theodore Ts'odede39b2000-02-11 04:48:03 +000021struct flags_name {
22 unsigned long flag;
Theodore Ts'o4ea7bd02001-12-16 23:23:37 -050023 const char *short_name;
24 const char *long_name;
Theodore Ts'odede39b2000-02-11 04:48:03 +000025};
Theodore Ts'of3db3561997-04-26 13:34:30 +000026
Theodore Ts'odede39b2000-02-11 04:48:03 +000027static struct flags_name flags_array[] = {
28 { EXT2_SECRM_FL, "s", "Secure_Deletion" },
29 { EXT2_UNRM_FL, "u" , "Undelete" },
30 { EXT2_SYNC_FL, "S", "Synchronous_Updates" },
Theodore Ts'o88372d52002-06-15 18:58:39 -040031 { EXT2_DIRSYNC_FL, "D", "Synchronous_Directory_Updates" },
Theodore Ts'odede39b2000-02-11 04:48:03 +000032 { EXT2_IMMUTABLE_FL, "i", "Immutable" },
33 { EXT2_APPEND_FL, "a", "Append_Only" },
34 { EXT2_NODUMP_FL, "d", "No_Dump" },
35 { EXT2_NOATIME_FL, "A", "No_Atime" },
Theodore Ts'obda15092000-12-31 13:35:38 +000036 { EXT2_COMPR_FL, "c", "Compression_Requested" },
Theodore Ts'oc4e5e362002-11-08 19:12:48 -050037#ifdef ENABLE_COMPRESSION
Theodore Ts'obda15092000-12-31 13:35:38 +000038 { EXT2_COMPRBLK_FL, "B", "Compressed_File" },
Theodore Ts'o88372d52002-06-15 18:58:39 -040039 { EXT2_DIRTY_FL, "Z", "Compressed_Dirty_File" },
Theodore Ts'oc8199c42001-01-12 01:43:28 +000040 { EXT2_NOCOMPR_FL, "X", "Compression_Raw_Access" },
Theodore Ts'odede39b2000-02-11 04:48:03 +000041 { EXT2_ECOMPR_FL, "E", "Compression_Error" },
Theodore Ts'oc4e5e362002-11-08 19:12:48 -050042#endif
Theodore Ts'oc8199c42001-01-12 01:43:28 +000043 { EXT3_JOURNAL_DATA_FL, "j", "Journaled_Data" },
Eric Sandeen312c2a42009-05-27 23:23:43 -050044 { EXT2_INDEX_FL, "I", "Indexed_directory" },
Theodore Ts'ob3f5b4c2001-11-05 19:22:02 -050045 { EXT2_NOTAIL_FL, "t", "No_Tailmerging" },
Theodore Ts'o15f90112002-11-01 01:53:52 -050046 { EXT2_TOPDIR_FL, "T", "Top_of_Directory_Hierarchies" },
Andreas Dilger8fe81a32006-08-05 18:50:22 -040047 { EXT4_EXTENTS_FL, "e", "Extents" },
Theodore Ts'o1ca10592008-04-09 11:39:11 -040048 { EXT4_HUGE_FILE_FL, "h", "Huge_file" },
Theodore Ts'odede39b2000-02-11 04:48:03 +000049 { 0, NULL, NULL }
50};
Theodore Ts'of3db3561997-04-26 13:34:30 +000051
Theodore Ts'odede39b2000-02-11 04:48:03 +000052void print_flags (FILE * f, unsigned long flags, unsigned options)
Theodore Ts'o3839e651997-04-26 13:21:57 +000053{
Theodore Ts'odede39b2000-02-11 04:48:03 +000054 int long_opt = (options & PFOPT_LONG);
55 struct flags_name *fp;
56 int first = 1;
Theodore Ts'of3db3561997-04-26 13:34:30 +000057
Theodore Ts'odede39b2000-02-11 04:48:03 +000058 for (fp = flags_array; fp->flag != 0; fp++) {
59 if (flags & fp->flag) {
60 if (long_opt) {
61 if (first)
62 first = 0;
63 else
64 fputs(", ", f);
65 fputs(fp->long_name, f);
66 } else
67 fputs(fp->short_name, f);
68 } else {
69 if (!long_opt)
70 fputs("-", f);
71 }
Theodore Ts'of3db3561997-04-26 13:34:30 +000072 }
Theodore Ts'odede39b2000-02-11 04:48:03 +000073 if (long_opt && first)
74 fputs("---", f);
Theodore Ts'o3839e651997-04-26 13:21:57 +000075}
Theodore Ts'odede39b2000-02-11 04:48:03 +000076