Debian Codegraph @

src/e2fsattrs.c

raw symbols SCIP
1 /*
2 * AIDE (Advanced Intrusion Detection Environment)
3 *
4 * Copyright (C) 2010, 2012, 2015-2016, 2020-2022 Hannes von Haugwitz
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License as
8 * published by the Free Software Foundation; either version 2 of the
9 * License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License along
17 * with this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 */
20
21 #include <e2p/e2p.h>
22 #include <stdbool.h>
23 #include "e2fsattrs.h"
24 #include "util.h"
25
26 typedef struct {
27 unsigned long f;
28 char c;
29 } e2fsattrs_t;
30
31 /* flag->character mappings taken from lib/e2p/pf.c (git commit 32fda1e)
32 * date: 2021-04-24
33 * sources: git://git.kernel.org/pub/scm/fs/ext2/e2fsprogs.git
34 */
35 static e2fsattrs_t e2fsattrs_flags[] = {
36 { EXT2_SECRM_FL, 's' },
37 { EXT2_UNRM_FL, 'u' },
38 { EXT2_SYNC_FL, 'S' },
39 { EXT2_DIRSYNC_FL, 'D' },
40 { EXT2_IMMUTABLE_FL, 'i' },
41 { EXT2_APPEND_FL, 'a' },
42 { EXT2_NODUMP_FL, 'd' },
43 { EXT2_NOATIME_FL, 'A' },
44 { EXT2_COMPR_FL, 'c' },
45 { EXT4_ENCRYPT_FL, 'E' },
46 { EXT3_JOURNAL_DATA_FL, 'j' },
47 { EXT2_INDEX_FL, 'I' },
48 { EXT2_NOTAIL_FL, 't' },
49 { EXT2_TOPDIR_FL, 'T' },
50 #ifdef EXT4_EXTENTS_FL
51 { EXT4_EXTENTS_FL, 'e' },
52 #endif
53 #ifdef FS_NOCOW_FL
54 { FS_NOCOW_FL, 'C' },
55 #endif
56 #ifdef FS_DAX_FL
57 { FS_DAX_FL, 'x' },
58 #endif
59 #ifdef EXT4_CASEFOLD_FL
60 { EXT4_CASEFOLD_FL, 'F' },
61 #endif
62 #ifdef EXT4_INLINE_DATA_FL
63 { EXT4_INLINE_DATA_FL, 'N' },
64 #endif
65 #ifdef EXT4_PROJINHERIT_FL
66 { EXT4_PROJINHERIT_FL, 'P' },
67 #endif
68 #ifdef EXT4_VERITY_FL
69 { EXT4_VERITY_FL, 'V' },
70 #endif
71 #ifdef EXT2_NOCOMPR_FL
72 { EXT2_NOCOMPR_FL, 'm' },
73 #endif
74 };
75
76 unsigned long num_flags = sizeof(e2fsattrs_flags)/sizeof(e2fsattrs_t);
77
78 unsigned long e2fsattrs_get_flag(char c) {
79 for (unsigned long i = 0 ; i < num_flags ; ++i) {
80 if (e2fsattrs_flags[i].c == c ) {
81 return e2fsattrs_flags[i].f;
82 }
83 }
84 return 0;
85 }
86
87 char* get_e2fsattrs_string(unsigned long flags, bool flags_only, unsigned long ignore_e2fsattrs) {
88 char* string = checked_malloc ((num_flags+1) * sizeof (char));
89 int j = 0;
90 for (unsigned long i = 0 ; i < num_flags ; i++) {
91 if (!flags_only && e2fsattrs_flags[i].f&ignore_e2fsattrs) {
92 string[j++]=':';
93 } else if (e2fsattrs_flags[i].f & flags) {
94 string[j++]=e2fsattrs_flags[i].c;
95 } else if (!flags_only) {
96 string[j++]='-';
97 }
98 }
99 string[j] = '\0';
100 return string;
101 }