blob: e2f8ce50a3855a5499482f3692d794d8198221f3 [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 *
Theodore Ts'o543547a2010-05-17 21:31:56 -04008 * %Begin-Header%
9 * This file may be redistributed under the terms of the GNU Library
10 * General Public License, version 2.
11 * %End-Header%
Theodore Ts'o3839e651997-04-26 13:21:57 +000012 */
13
14/*
15 * History:
16 * 93/10/30 - Creation
17 */
18
Theodore Ts'od1154eb2011-09-18 17:34:37 -040019#include "config.h"
Theodore Ts'o3839e651997-04-26 13:21:57 +000020#include <stdio.h>
Theodore Ts'o3839e651997-04-26 13:21:57 +000021
22#include "e2p.h"
23
Theodore Ts'odede39b2000-02-11 04:48:03 +000024struct flags_name {
25 unsigned long flag;
Theodore Ts'o4ea7bd02001-12-16 23:23:37 -050026 const char *short_name;
27 const char *long_name;
Theodore Ts'odede39b2000-02-11 04:48:03 +000028};
Theodore Ts'of3db3561997-04-26 13:34:30 +000029
Theodore Ts'odede39b2000-02-11 04:48:03 +000030static struct flags_name flags_array[] = {
31 { EXT2_SECRM_FL, "s", "Secure_Deletion" },
32 { EXT2_UNRM_FL, "u" , "Undelete" },
33 { EXT2_SYNC_FL, "S", "Synchronous_Updates" },
Theodore Ts'o88372d52002-06-15 18:58:39 -040034 { EXT2_DIRSYNC_FL, "D", "Synchronous_Directory_Updates" },
Theodore Ts'odede39b2000-02-11 04:48:03 +000035 { EXT2_IMMUTABLE_FL, "i", "Immutable" },
36 { EXT2_APPEND_FL, "a", "Append_Only" },
37 { EXT2_NODUMP_FL, "d", "No_Dump" },
38 { EXT2_NOATIME_FL, "A", "No_Atime" },
Theodore Ts'obda15092000-12-31 13:35:38 +000039 { EXT2_COMPR_FL, "c", "Compression_Requested" },
Theodore Ts'oc4e5e362002-11-08 19:12:48 -050040#ifdef ENABLE_COMPRESSION
Theodore Ts'obda15092000-12-31 13:35:38 +000041 { EXT2_COMPRBLK_FL, "B", "Compressed_File" },
Theodore Ts'o88372d52002-06-15 18:58:39 -040042 { EXT2_DIRTY_FL, "Z", "Compressed_Dirty_File" },
Theodore Ts'oc8199c42001-01-12 01:43:28 +000043 { EXT2_NOCOMPR_FL, "X", "Compression_Raw_Access" },
Theodore Ts'odede39b2000-02-11 04:48:03 +000044 { EXT2_ECOMPR_FL, "E", "Compression_Error" },
Theodore Ts'oc4e5e362002-11-08 19:12:48 -050045#endif
Theodore Ts'oc8199c42001-01-12 01:43:28 +000046 { EXT3_JOURNAL_DATA_FL, "j", "Journaled_Data" },
Eric Sandeen312c2a42009-05-27 23:23:43 -050047 { EXT2_INDEX_FL, "I", "Indexed_directory" },
Theodore Ts'ob3f5b4c2001-11-05 19:22:02 -050048 { EXT2_NOTAIL_FL, "t", "No_Tailmerging" },
Theodore Ts'o15f90112002-11-01 01:53:52 -050049 { EXT2_TOPDIR_FL, "T", "Top_of_Directory_Hierarchies" },
Andreas Dilger8fe81a32006-08-05 18:50:22 -040050 { EXT4_EXTENTS_FL, "e", "Extents" },
Theodore Ts'o1ca10592008-04-09 11:39:11 -040051 { EXT4_HUGE_FILE_FL, "h", "Huge_file" },
Theodore Ts'o0796e662012-06-12 17:09:39 -040052 { FS_NOCOW_FL, "C", "No_COW" },
Theodore Ts'odede39b2000-02-11 04:48:03 +000053 { 0, NULL, NULL }
54};
Theodore Ts'of3db3561997-04-26 13:34:30 +000055
Theodore Ts'odede39b2000-02-11 04:48:03 +000056void print_flags (FILE * f, unsigned long flags, unsigned options)
Theodore Ts'o3839e651997-04-26 13:21:57 +000057{
Theodore Ts'odede39b2000-02-11 04:48:03 +000058 int long_opt = (options & PFOPT_LONG);
59 struct flags_name *fp;
60 int first = 1;
Theodore Ts'of3db3561997-04-26 13:34:30 +000061
Theodore Ts'odede39b2000-02-11 04:48:03 +000062 for (fp = flags_array; fp->flag != 0; fp++) {
63 if (flags & fp->flag) {
64 if (long_opt) {
65 if (first)
66 first = 0;
67 else
68 fputs(", ", f);
69 fputs(fp->long_name, f);
70 } else
71 fputs(fp->short_name, f);
72 } else {
73 if (!long_opt)
74 fputs("-", f);
75 }
Theodore Ts'of3db3561997-04-26 13:34:30 +000076 }
Theodore Ts'odede39b2000-02-11 04:48:03 +000077 if (long_opt && first)
78 fputs("---", f);
Theodore Ts'o3839e651997-04-26 13:21:57 +000079}
Theodore Ts'odede39b2000-02-11 04:48:03 +000080