blob: 2fb5c8cdc42d8d59be3c18c22d5ec211aaa0835b [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
19#include <stdio.h>
Theodore Ts'o3839e651997-04-26 13:21:57 +000020
21#include "e2p.h"
22
Theodore Ts'odede39b2000-02-11 04:48:03 +000023struct flags_name {
24 unsigned long flag;
Theodore Ts'o4ea7bd02001-12-16 23:23:37 -050025 const char *short_name;
26 const char *long_name;
Theodore Ts'odede39b2000-02-11 04:48:03 +000027};
Theodore Ts'of3db3561997-04-26 13:34:30 +000028
Theodore Ts'odede39b2000-02-11 04:48:03 +000029static struct flags_name flags_array[] = {
30 { EXT2_SECRM_FL, "s", "Secure_Deletion" },
31 { EXT2_UNRM_FL, "u" , "Undelete" },
32 { EXT2_SYNC_FL, "S", "Synchronous_Updates" },
Theodore Ts'o88372d52002-06-15 18:58:39 -040033 { EXT2_DIRSYNC_FL, "D", "Synchronous_Directory_Updates" },
Theodore Ts'odede39b2000-02-11 04:48:03 +000034 { EXT2_IMMUTABLE_FL, "i", "Immutable" },
35 { EXT2_APPEND_FL, "a", "Append_Only" },
36 { EXT2_NODUMP_FL, "d", "No_Dump" },
37 { EXT2_NOATIME_FL, "A", "No_Atime" },
Theodore Ts'obda15092000-12-31 13:35:38 +000038 { EXT2_COMPR_FL, "c", "Compression_Requested" },
Theodore Ts'oc4e5e362002-11-08 19:12:48 -050039#ifdef ENABLE_COMPRESSION
Theodore Ts'obda15092000-12-31 13:35:38 +000040 { EXT2_COMPRBLK_FL, "B", "Compressed_File" },
Theodore Ts'o88372d52002-06-15 18:58:39 -040041 { EXT2_DIRTY_FL, "Z", "Compressed_Dirty_File" },
Theodore Ts'oc8199c42001-01-12 01:43:28 +000042 { EXT2_NOCOMPR_FL, "X", "Compression_Raw_Access" },
Theodore Ts'odede39b2000-02-11 04:48:03 +000043 { EXT2_ECOMPR_FL, "E", "Compression_Error" },
Theodore Ts'o890a2f92015-07-14 22:50:51 -040044#else
45 { EXT4_ENCRYPT_FL, "E", "Encrypted" },
Theodore Ts'oc4e5e362002-11-08 19:12:48 -050046#endif
Theodore Ts'oc8199c42001-01-12 01:43:28 +000047 { EXT3_JOURNAL_DATA_FL, "j", "Journaled_Data" },
Eric Sandeen312c2a42009-05-27 23:23:43 -050048 { EXT2_INDEX_FL, "I", "Indexed_directory" },
Theodore Ts'ob3f5b4c2001-11-05 19:22:02 -050049 { EXT2_NOTAIL_FL, "t", "No_Tailmerging" },
Theodore Ts'o15f90112002-11-01 01:53:52 -050050 { EXT2_TOPDIR_FL, "T", "Top_of_Directory_Hierarchies" },
Andreas Dilger8fe81a32006-08-05 18:50:22 -040051 { EXT4_EXTENTS_FL, "e", "Extents" },
Theodore Ts'o1ca10592008-04-09 11:39:11 -040052 { EXT4_HUGE_FILE_FL, "h", "Huge_file" },
JP Abgralle0ed7402014-03-19 19:08:39 -070053 { FS_NOCOW_FL, "C", "No_COW" },
Theodore Ts'odede39b2000-02-11 04:48:03 +000054 { 0, NULL, NULL }
55};
Theodore Ts'of3db3561997-04-26 13:34:30 +000056
Theodore Ts'odede39b2000-02-11 04:48:03 +000057void print_flags (FILE * f, unsigned long flags, unsigned options)
Theodore Ts'o3839e651997-04-26 13:21:57 +000058{
Theodore Ts'odede39b2000-02-11 04:48:03 +000059 int long_opt = (options & PFOPT_LONG);
60 struct flags_name *fp;
61 int first = 1;
Theodore Ts'of3db3561997-04-26 13:34:30 +000062
Theodore Ts'odede39b2000-02-11 04:48:03 +000063 for (fp = flags_array; fp->flag != 0; fp++) {
64 if (flags & fp->flag) {
65 if (long_opt) {
66 if (first)
67 first = 0;
68 else
69 fputs(", ", f);
70 fputs(fp->long_name, f);
71 } else
72 fputs(fp->short_name, f);
73 } else {
74 if (!long_opt)
75 fputs("-", f);
76 }
Theodore Ts'of3db3561997-04-26 13:34:30 +000077 }
Theodore Ts'odede39b2000-02-11 04:48:03 +000078 if (long_opt && first)
79 fputs("---", f);
Theodore Ts'o3839e651997-04-26 13:21:57 +000080}
Theodore Ts'odede39b2000-02-11 04:48:03 +000081