]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blob - fs/aufs/fstype.h
UBUNTU: SAUCE: Import aufs driver
[mirror_ubuntu-bionic-kernel.git] / fs / aufs / fstype.h
1 /*
2 * Copyright (C) 2005-2017 Junjiro R. Okajima
3 *
4 * This program, aufs is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18 /*
19 * judging filesystem type
20 */
21
22 #ifndef __AUFS_FSTYPE_H__
23 #define __AUFS_FSTYPE_H__
24
25 #ifdef __KERNEL__
26
27 #include <linux/fs.h>
28 #include <linux/magic.h>
29 #include <linux/nfs_fs.h>
30 #include <linux/romfs_fs.h>
31
32 static inline int au_test_aufs(struct super_block *sb)
33 {
34 return sb->s_magic == AUFS_SUPER_MAGIC;
35 }
36
37 static inline const char *au_sbtype(struct super_block *sb)
38 {
39 return sb->s_type->name;
40 }
41
42 static inline int au_test_iso9660(struct super_block *sb __maybe_unused)
43 {
44 #if IS_ENABLED(CONFIG_ISO9660_FS)
45 return sb->s_magic == ISOFS_SUPER_MAGIC;
46 #else
47 return 0;
48 #endif
49 }
50
51 static inline int au_test_romfs(struct super_block *sb __maybe_unused)
52 {
53 #if IS_ENABLED(CONFIG_ROMFS_FS)
54 return sb->s_magic == ROMFS_MAGIC;
55 #else
56 return 0;
57 #endif
58 }
59
60 static inline int au_test_cramfs(struct super_block *sb __maybe_unused)
61 {
62 #if IS_ENABLED(CONFIG_CRAMFS)
63 return sb->s_magic == CRAMFS_MAGIC;
64 #endif
65 return 0;
66 }
67
68 static inline int au_test_nfs(struct super_block *sb __maybe_unused)
69 {
70 #if IS_ENABLED(CONFIG_NFS_FS)
71 return sb->s_magic == NFS_SUPER_MAGIC;
72 #else
73 return 0;
74 #endif
75 }
76
77 static inline int au_test_fuse(struct super_block *sb __maybe_unused)
78 {
79 #if IS_ENABLED(CONFIG_FUSE_FS)
80 return sb->s_magic == FUSE_SUPER_MAGIC;
81 #else
82 return 0;
83 #endif
84 }
85
86 static inline int au_test_xfs(struct super_block *sb __maybe_unused)
87 {
88 #if IS_ENABLED(CONFIG_XFS_FS)
89 return sb->s_magic == XFS_SB_MAGIC;
90 #else
91 return 0;
92 #endif
93 }
94
95 static inline int au_test_tmpfs(struct super_block *sb __maybe_unused)
96 {
97 #ifdef CONFIG_TMPFS
98 return sb->s_magic == TMPFS_MAGIC;
99 #else
100 return 0;
101 #endif
102 }
103
104 static inline int au_test_ecryptfs(struct super_block *sb __maybe_unused)
105 {
106 #if IS_ENABLED(CONFIG_ECRYPT_FS)
107 return !strcmp(au_sbtype(sb), "ecryptfs");
108 #else
109 return 0;
110 #endif
111 }
112
113 static inline int au_test_ramfs(struct super_block *sb)
114 {
115 return sb->s_magic == RAMFS_MAGIC;
116 }
117
118 static inline int au_test_ubifs(struct super_block *sb __maybe_unused)
119 {
120 #if IS_ENABLED(CONFIG_UBIFS_FS)
121 return sb->s_magic == UBIFS_SUPER_MAGIC;
122 #else
123 return 0;
124 #endif
125 }
126
127 static inline int au_test_procfs(struct super_block *sb __maybe_unused)
128 {
129 #ifdef CONFIG_PROC_FS
130 return sb->s_magic == PROC_SUPER_MAGIC;
131 #else
132 return 0;
133 #endif
134 }
135
136 static inline int au_test_sysfs(struct super_block *sb __maybe_unused)
137 {
138 #ifdef CONFIG_SYSFS
139 return sb->s_magic == SYSFS_MAGIC;
140 #else
141 return 0;
142 #endif
143 }
144
145 static inline int au_test_configfs(struct super_block *sb __maybe_unused)
146 {
147 #if IS_ENABLED(CONFIG_CONFIGFS_FS)
148 return sb->s_magic == CONFIGFS_MAGIC;
149 #else
150 return 0;
151 #endif
152 }
153
154 static inline int au_test_minix(struct super_block *sb __maybe_unused)
155 {
156 #if IS_ENABLED(CONFIG_MINIX_FS)
157 return sb->s_magic == MINIX3_SUPER_MAGIC
158 || sb->s_magic == MINIX2_SUPER_MAGIC
159 || sb->s_magic == MINIX2_SUPER_MAGIC2
160 || sb->s_magic == MINIX_SUPER_MAGIC
161 || sb->s_magic == MINIX_SUPER_MAGIC2;
162 #else
163 return 0;
164 #endif
165 }
166
167 static inline int au_test_fat(struct super_block *sb __maybe_unused)
168 {
169 #if IS_ENABLED(CONFIG_FAT_FS)
170 return sb->s_magic == MSDOS_SUPER_MAGIC;
171 #else
172 return 0;
173 #endif
174 }
175
176 static inline int au_test_msdos(struct super_block *sb)
177 {
178 return au_test_fat(sb);
179 }
180
181 static inline int au_test_vfat(struct super_block *sb)
182 {
183 return au_test_fat(sb);
184 }
185
186 static inline int au_test_securityfs(struct super_block *sb __maybe_unused)
187 {
188 #ifdef CONFIG_SECURITYFS
189 return sb->s_magic == SECURITYFS_MAGIC;
190 #else
191 return 0;
192 #endif
193 }
194
195 static inline int au_test_squashfs(struct super_block *sb __maybe_unused)
196 {
197 #if IS_ENABLED(CONFIG_SQUASHFS)
198 return sb->s_magic == SQUASHFS_MAGIC;
199 #else
200 return 0;
201 #endif
202 }
203
204 static inline int au_test_btrfs(struct super_block *sb __maybe_unused)
205 {
206 #if IS_ENABLED(CONFIG_BTRFS_FS)
207 return sb->s_magic == BTRFS_SUPER_MAGIC;
208 #else
209 return 0;
210 #endif
211 }
212
213 static inline int au_test_xenfs(struct super_block *sb __maybe_unused)
214 {
215 #if IS_ENABLED(CONFIG_XENFS)
216 return sb->s_magic == XENFS_SUPER_MAGIC;
217 #else
218 return 0;
219 #endif
220 }
221
222 static inline int au_test_debugfs(struct super_block *sb __maybe_unused)
223 {
224 #ifdef CONFIG_DEBUG_FS
225 return sb->s_magic == DEBUGFS_MAGIC;
226 #else
227 return 0;
228 #endif
229 }
230
231 static inline int au_test_nilfs(struct super_block *sb __maybe_unused)
232 {
233 #if IS_ENABLED(CONFIG_NILFS)
234 return sb->s_magic == NILFS_SUPER_MAGIC;
235 #else
236 return 0;
237 #endif
238 }
239
240 static inline int au_test_hfsplus(struct super_block *sb __maybe_unused)
241 {
242 #if IS_ENABLED(CONFIG_HFSPLUS_FS)
243 return sb->s_magic == HFSPLUS_SUPER_MAGIC;
244 #else
245 return 0;
246 #endif
247 }
248
249 /* ---------------------------------------------------------------------- */
250 /*
251 * they can't be an aufs branch.
252 */
253 static inline int au_test_fs_unsuppoted(struct super_block *sb)
254 {
255 return
256 #ifndef CONFIG_AUFS_BR_RAMFS
257 au_test_ramfs(sb) ||
258 #endif
259 au_test_procfs(sb)
260 || au_test_sysfs(sb)
261 || au_test_configfs(sb)
262 || au_test_debugfs(sb)
263 || au_test_securityfs(sb)
264 || au_test_xenfs(sb)
265 || au_test_ecryptfs(sb)
266 /* || !strcmp(au_sbtype(sb), "unionfs") */
267 || au_test_aufs(sb); /* will be supported in next version */
268 }
269
270 static inline int au_test_fs_remote(struct super_block *sb)
271 {
272 return !au_test_tmpfs(sb)
273 #ifdef CONFIG_AUFS_BR_RAMFS
274 && !au_test_ramfs(sb)
275 #endif
276 && !(sb->s_type->fs_flags & FS_REQUIRES_DEV);
277 }
278
279 /* ---------------------------------------------------------------------- */
280
281 /*
282 * Note: these functions (below) are created after reading ->getattr() in all
283 * filesystems under linux/fs. it means we have to do so in every update...
284 */
285
286 /*
287 * some filesystems require getattr to refresh the inode attributes before
288 * referencing.
289 * in most cases, we can rely on the inode attribute in NFS (or every remote fs)
290 * and leave the work for d_revalidate()
291 */
292 static inline int au_test_fs_refresh_iattr(struct super_block *sb)
293 {
294 return au_test_nfs(sb)
295 || au_test_fuse(sb)
296 /* || au_test_btrfs(sb) */ /* untested */
297 ;
298 }
299
300 /*
301 * filesystems which don't maintain i_size or i_blocks.
302 */
303 static inline int au_test_fs_bad_iattr_size(struct super_block *sb)
304 {
305 return au_test_xfs(sb)
306 || au_test_btrfs(sb)
307 || au_test_ubifs(sb)
308 || au_test_hfsplus(sb) /* maintained, but incorrect */
309 /* || au_test_minix(sb) */ /* untested */
310 ;
311 }
312
313 /*
314 * filesystems which don't store the correct value in some of their inode
315 * attributes.
316 */
317 static inline int au_test_fs_bad_iattr(struct super_block *sb)
318 {
319 return au_test_fs_bad_iattr_size(sb)
320 || au_test_fat(sb)
321 || au_test_msdos(sb)
322 || au_test_vfat(sb);
323 }
324
325 /* they don't check i_nlink in link(2) */
326 static inline int au_test_fs_no_limit_nlink(struct super_block *sb)
327 {
328 return au_test_tmpfs(sb)
329 #ifdef CONFIG_AUFS_BR_RAMFS
330 || au_test_ramfs(sb)
331 #endif
332 || au_test_ubifs(sb)
333 || au_test_hfsplus(sb);
334 }
335
336 /*
337 * filesystems which sets S_NOATIME and S_NOCMTIME.
338 */
339 static inline int au_test_fs_notime(struct super_block *sb)
340 {
341 return au_test_nfs(sb)
342 || au_test_fuse(sb)
343 || au_test_ubifs(sb)
344 ;
345 }
346
347 /* temporary support for i#1 in cramfs */
348 static inline int au_test_fs_unique_ino(struct inode *inode)
349 {
350 if (au_test_cramfs(inode->i_sb))
351 return inode->i_ino != 1;
352 return 1;
353 }
354
355 /* ---------------------------------------------------------------------- */
356
357 /*
358 * the filesystem where the xino files placed must support i/o after unlink and
359 * maintain i_size and i_blocks.
360 */
361 static inline int au_test_fs_bad_xino(struct super_block *sb)
362 {
363 return au_test_fs_remote(sb)
364 || au_test_fs_bad_iattr_size(sb)
365 /* don't want unnecessary work for xino */
366 || au_test_aufs(sb)
367 || au_test_ecryptfs(sb)
368 || au_test_nilfs(sb);
369 }
370
371 static inline int au_test_fs_trunc_xino(struct super_block *sb)
372 {
373 return au_test_tmpfs(sb)
374 || au_test_ramfs(sb);
375 }
376
377 /*
378 * test if the @sb is real-readonly.
379 */
380 static inline int au_test_fs_rr(struct super_block *sb)
381 {
382 return au_test_squashfs(sb)
383 || au_test_iso9660(sb)
384 || au_test_cramfs(sb)
385 || au_test_romfs(sb);
386 }
387
388 /*
389 * test if the @inode is nfs with 'noacl' option
390 * NFS always sets SB_POSIXACL regardless its mount option 'noacl.'
391 */
392 static inline int au_test_nfs_noacl(struct inode *inode)
393 {
394 return au_test_nfs(inode->i_sb)
395 /* && IS_POSIXACL(inode) */
396 && !nfs_server_capable(inode, NFS_CAP_ACLS);
397 }
398
399 #endif /* __KERNEL__ */
400 #endif /* __AUFS_FSTYPE_H__ */