diff options
Diffstat (limited to 'e2fsprogs/e2fs_lib.c')
-rw-r--r-- | e2fsprogs/e2fs_lib.c | 119 |
1 files changed, 1 insertions, 118 deletions
diff --git a/e2fsprogs/e2fs_lib.c b/e2fsprogs/e2fs_lib.c index 8d56add2d..0ec4eb2f2 100644 --- a/e2fsprogs/e2fs_lib.c +++ b/e2fsprogs/e2fs_lib.c | |||
@@ -8,8 +8,6 @@ | |||
8 | #include "libbb.h" | 8 | #include "libbb.h" |
9 | #include "e2fs_lib.h" | 9 | #include "e2fs_lib.h" |
10 | 10 | ||
11 | #define HAVE_EXT2_IOCTLS 1 | ||
12 | |||
13 | #if INT_MAX == LONG_MAX | 11 | #if INT_MAX == LONG_MAX |
14 | #define IF_LONG_IS_SAME(...) __VA_ARGS__ | 12 | #define IF_LONG_IS_SAME(...) __VA_ARGS__ |
15 | #define IF_LONG_IS_WIDER(...) | 13 | #define IF_LONG_IS_WIDER(...) |
@@ -18,14 +16,6 @@ | |||
18 | #define IF_LONG_IS_WIDER(...) __VA_ARGS__ | 16 | #define IF_LONG_IS_WIDER(...) __VA_ARGS__ |
19 | #endif | 17 | #endif |
20 | 18 | ||
21 | static void close_silently(int fd) | ||
22 | { | ||
23 | int e = errno; | ||
24 | close(fd); | ||
25 | errno = e; | ||
26 | } | ||
27 | |||
28 | |||
29 | /* Iterate a function on each entry of a directory */ | 19 | /* Iterate a function on each entry of a directory */ |
30 | int iterate_on_dir(const char *dir_name, | 20 | int iterate_on_dir(const char *dir_name, |
31 | int FAST_FUNC (*func)(const char *, struct dirent *, void *), | 21 | int FAST_FUNC (*func)(const char *, struct dirent *, void *), |
@@ -45,113 +35,6 @@ int iterate_on_dir(const char *dir_name, | |||
45 | return 0; | 35 | return 0; |
46 | } | 36 | } |
47 | 37 | ||
48 | |||
49 | /* Get/set a file version on an ext2 file system */ | ||
50 | int fgetsetversion(const char *name, unsigned long *get_version, unsigned long set_version) | ||
51 | { | ||
52 | #if HAVE_EXT2_IOCTLS | ||
53 | int fd, r; | ||
54 | IF_LONG_IS_WIDER(unsigned ver;) | ||
55 | |||
56 | fd = open(name, O_RDONLY | O_NONBLOCK); | ||
57 | if (fd == -1) | ||
58 | return -1; | ||
59 | if (!get_version) { | ||
60 | IF_LONG_IS_WIDER( | ||
61 | ver = (unsigned) set_version; | ||
62 | r = ioctl(fd, EXT2_IOC_SETVERSION, &ver); | ||
63 | ) | ||
64 | IF_LONG_IS_SAME( | ||
65 | r = ioctl(fd, EXT2_IOC_SETVERSION, (void*)&set_version); | ||
66 | ) | ||
67 | } else { | ||
68 | IF_LONG_IS_WIDER( | ||
69 | r = ioctl(fd, EXT2_IOC_GETVERSION, &ver); | ||
70 | *get_version = ver; | ||
71 | ) | ||
72 | IF_LONG_IS_SAME( | ||
73 | r = ioctl(fd, EXT2_IOC_GETVERSION, (void*)get_version); | ||
74 | ) | ||
75 | } | ||
76 | close_silently(fd); | ||
77 | return r; | ||
78 | #else /* ! HAVE_EXT2_IOCTLS */ | ||
79 | errno = EOPNOTSUPP; | ||
80 | return -1; | ||
81 | #endif /* ! HAVE_EXT2_IOCTLS */ | ||
82 | } | ||
83 | |||
84 | int fgetsetprojid(const char *name, uint32_t *get, uint32_t set) | ||
85 | { | ||
86 | #if HAVE_EXT2_IOCTLS | ||
87 | struct ext2_fsxattr fsxattr; | ||
88 | int fd, r; | ||
89 | |||
90 | fd = open(name, O_RDONLY | O_NONBLOCK); | ||
91 | if (fd == -1) | ||
92 | return -1; | ||
93 | r = ioctl(fd, EXT2_IOC_FSGETXATTR, &fsxattr); | ||
94 | /* note: ^^^ may fail in 32-bit userspace on 64-bit kernel (seen on 4.12.0) */ | ||
95 | if (r == 0) { | ||
96 | if (get) { | ||
97 | *get = fsxattr.fsx_projid; | ||
98 | } else { | ||
99 | fsxattr.fsx_projid = set; | ||
100 | r = ioctl(fd, EXT2_IOC_FSSETXATTR, &fsxattr); | ||
101 | } | ||
102 | } | ||
103 | close_silently(fd); | ||
104 | return r; | ||
105 | #else /* ! HAVE_EXT2_IOCTLS */ | ||
106 | errno = EOPNOTSUPP; | ||
107 | return -1; | ||
108 | #endif /* ! HAVE_EXT2_IOCTLS */ | ||
109 | } | ||
110 | |||
111 | /* Get/set a file flags on an ext2 file system */ | ||
112 | int fgetsetflags(const char *name, unsigned long *get_flags, unsigned long set_flags) | ||
113 | { | ||
114 | #if HAVE_EXT2_IOCTLS | ||
115 | struct stat buf; | ||
116 | int fd, r; | ||
117 | IF_LONG_IS_WIDER(unsigned f;) | ||
118 | |||
119 | if (stat(name, &buf) == 0 /* stat is ok */ | ||
120 | && !S_ISREG(buf.st_mode) && !S_ISDIR(buf.st_mode) | ||
121 | ) { | ||
122 | goto notsupp; | ||
123 | } | ||
124 | fd = open(name, O_RDONLY | O_NONBLOCK); /* neither read nor write asked for */ | ||
125 | if (fd == -1) | ||
126 | return -1; | ||
127 | |||
128 | if (!get_flags) { | ||
129 | IF_LONG_IS_WIDER( | ||
130 | f = (unsigned) set_flags; | ||
131 | r = ioctl(fd, EXT2_IOC_SETFLAGS, &f); | ||
132 | ) | ||
133 | IF_LONG_IS_SAME( | ||
134 | r = ioctl(fd, EXT2_IOC_SETFLAGS, (void*)&set_flags); | ||
135 | ) | ||
136 | } else { | ||
137 | IF_LONG_IS_WIDER( | ||
138 | r = ioctl(fd, EXT2_IOC_GETFLAGS, &f); | ||
139 | *get_flags = f; | ||
140 | ) | ||
141 | IF_LONG_IS_SAME( | ||
142 | r = ioctl(fd, EXT2_IOC_GETFLAGS, (void*)get_flags); | ||
143 | ) | ||
144 | } | ||
145 | |||
146 | close_silently(fd); | ||
147 | return r; | ||
148 | notsupp: | ||
149 | #endif /* HAVE_EXT2_IOCTLS */ | ||
150 | errno = EOPNOTSUPP; | ||
151 | return -1; | ||
152 | } | ||
153 | |||
154 | |||
155 | /* Print file attributes on an ext2 file system */ | 38 | /* Print file attributes on an ext2 file system */ |
156 | const uint32_t e2attr_flags_value[] ALIGN4 = { | 39 | const uint32_t e2attr_flags_value[] ALIGN4 = { |
157 | #ifdef ENABLE_COMPRESSION | 40 | #ifdef ENABLE_COMPRESSION |
@@ -215,7 +98,7 @@ static const char e2attr_flags_lname[] ALIGN1 = | |||
215 | "Verity" "\0" | 98 | "Verity" "\0" |
216 | /* Another trailing NUL is added by compiler */; | 99 | /* Another trailing NUL is added by compiler */; |
217 | 100 | ||
218 | void print_e2flags(FILE *f, unsigned long flags, unsigned options) | 101 | void print_e2flags(FILE *f, unsigned flags, unsigned options) |
219 | { | 102 | { |
220 | const uint32_t *fv; | 103 | const uint32_t *fv; |
221 | const char *fn; | 104 | const char *fn; |