Merge branch 'stable-3.2' into pandora-3.2
[pandora-kernel.git] / fs / aufs / fstype.h
1 /*
2  * Copyright (C) 2005-2013 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, write to the Free Software
16  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
17  */
18
19 /*
20  * judging filesystem type
21  */
22
23 #ifndef __AUFS_FSTYPE_H__
24 #define __AUFS_FSTYPE_H__
25
26 #ifdef __KERNEL__
27
28 #include <linux/fs.h>
29 #include <linux/magic.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 defined(CONFIG_ROMFS_FS) || defined(CONFIG_ROMFS_FS_MODULE)
45         return sb->s_magic == ROMFS_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 defined(CONFIG_ISO9660_FS) || defined(CONFIG_ISO9660_FS_MODULE)
54         return sb->s_magic == ISOFS_SUPER_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 defined(CONFIG_CRAMFS) || defined(CONFIG_CRAMFS_MODULE)
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 defined(CONFIG_NFS_FS) || defined(CONFIG_NFS_FS_MODULE)
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 defined(CONFIG_FUSE_FS) || defined(CONFIG_FUSE_FS_MODULE)
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 defined(CONFIG_XFS_FS) || defined(CONFIG_XFS_FS_MODULE)
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 defined(CONFIG_ECRYPT_FS) || defined(CONFIG_ECRYPT_FS_MODULE)
107         return !strcmp(au_sbtype(sb), "ecryptfs");
108 #else
109         return 0;
110 #endif
111 }
112
113 static inline int au_test_ocfs2(struct super_block *sb __maybe_unused)
114 {
115 #if defined(CONFIG_OCFS2_FS) || defined(CONFIG_OCFS2_FS_MODULE)
116         return sb->s_magic == OCFS2_SUPER_MAGIC;
117 #else
118         return 0;
119 #endif
120 }
121
122 static inline int au_test_ocfs2_dlmfs(struct super_block *sb __maybe_unused)
123 {
124 #if defined(CONFIG_OCFS2_FS_O2CB) || defined(CONFIG_OCFS2_FS_O2CB_MODULE)
125         return sb->s_magic == DLMFS_MAGIC;
126 #else
127         return 0;
128 #endif
129 }
130
131 static inline int au_test_coda(struct super_block *sb __maybe_unused)
132 {
133 #if defined(CONFIG_CODA_FS) || defined(CONFIG_CODA_FS_MODULE)
134         return sb->s_magic == CODA_SUPER_MAGIC;
135 #else
136         return 0;
137 #endif
138 }
139
140 static inline int au_test_v9fs(struct super_block *sb __maybe_unused)
141 {
142 #if defined(CONFIG_9P_FS) || defined(CONFIG_9P_FS_MODULE)
143         return sb->s_magic == V9FS_MAGIC;
144 #else
145         return 0;
146 #endif
147 }
148
149 static inline int au_test_ext4(struct super_block *sb __maybe_unused)
150 {
151 #if defined(CONFIG_EXT4_FS) || defined(CONFIG_EXT4_FS_MODULE)
152         return sb->s_magic == EXT4_SUPER_MAGIC;
153 #else
154         return 0;
155 #endif
156 }
157
158 static inline int au_test_sysv(struct super_block *sb __maybe_unused)
159 {
160 #if defined(CONFIG_SYSV_FS) || defined(CONFIG_SYSV_FS_MODULE)
161         return !strcmp(au_sbtype(sb), "sysv");
162 #else
163         return 0;
164 #endif
165 }
166
167 static inline int au_test_ramfs(struct super_block *sb)
168 {
169         return sb->s_magic == RAMFS_MAGIC;
170 }
171
172 static inline int au_test_ubifs(struct super_block *sb __maybe_unused)
173 {
174 #if defined(CONFIG_UBIFS_FS) || defined(CONFIG_UBIFS_FS_MODULE)
175         return sb->s_magic == UBIFS_SUPER_MAGIC;
176 #else
177         return 0;
178 #endif
179 }
180
181 static inline int au_test_procfs(struct super_block *sb __maybe_unused)
182 {
183 #ifdef CONFIG_PROC_FS
184         return sb->s_magic == PROC_SUPER_MAGIC;
185 #else
186         return 0;
187 #endif
188 }
189
190 static inline int au_test_sysfs(struct super_block *sb __maybe_unused)
191 {
192 #ifdef CONFIG_SYSFS
193         return sb->s_magic == SYSFS_MAGIC;
194 #else
195         return 0;
196 #endif
197 }
198
199 static inline int au_test_configfs(struct super_block *sb __maybe_unused)
200 {
201 #if defined(CONFIG_CONFIGFS_FS) || defined(CONFIG_CONFIGFS_FS_MODULE)
202         return sb->s_magic == CONFIGFS_MAGIC;
203 #else
204         return 0;
205 #endif
206 }
207
208 static inline int au_test_minix(struct super_block *sb __maybe_unused)
209 {
210 #if defined(CONFIG_MINIX_FS) || defined(CONFIG_MINIX_FS_MODULE)
211         return sb->s_magic == MINIX3_SUPER_MAGIC
212                 || sb->s_magic == MINIX2_SUPER_MAGIC
213                 || sb->s_magic == MINIX2_SUPER_MAGIC2
214                 || sb->s_magic == MINIX_SUPER_MAGIC
215                 || sb->s_magic == MINIX_SUPER_MAGIC2;
216 #else
217         return 0;
218 #endif
219 }
220
221 static inline int au_test_cifs(struct super_block *sb __maybe_unused)
222 {
223 #if defined(CONFIG_CIFS_FS) || defined(CONFIGCIFS_FS_MODULE)
224         return sb->s_magic == CIFS_MAGIC_NUMBER;
225 #else
226         return 0;
227 #endif
228 }
229
230 static inline int au_test_fat(struct super_block *sb __maybe_unused)
231 {
232 #if defined(CONFIG_FAT_FS) || defined(CONFIG_FAT_FS_MODULE)
233         return sb->s_magic == MSDOS_SUPER_MAGIC;
234 #else
235         return 0;
236 #endif
237 }
238
239 static inline int au_test_msdos(struct super_block *sb)
240 {
241         return au_test_fat(sb);
242 }
243
244 static inline int au_test_vfat(struct super_block *sb)
245 {
246         return au_test_fat(sb);
247 }
248
249 static inline int au_test_securityfs(struct super_block *sb __maybe_unused)
250 {
251 #ifdef CONFIG_SECURITYFS
252         return sb->s_magic == SECURITYFS_MAGIC;
253 #else
254         return 0;
255 #endif
256 }
257
258 static inline int au_test_squashfs(struct super_block *sb __maybe_unused)
259 {
260 #if defined(CONFIG_SQUASHFS) || defined(CONFIG_SQUASHFS_MODULE)
261         return sb->s_magic == SQUASHFS_MAGIC;
262 #else
263         return 0;
264 #endif
265 }
266
267 static inline int au_test_btrfs(struct super_block *sb __maybe_unused)
268 {
269 #if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
270         return sb->s_magic == BTRFS_SUPER_MAGIC;
271 #else
272         return 0;
273 #endif
274 }
275
276 static inline int au_test_xenfs(struct super_block *sb __maybe_unused)
277 {
278 #if defined(CONFIG_XENFS) || defined(CONFIG_XENFS_MODULE)
279         return sb->s_magic == XENFS_SUPER_MAGIC;
280 #else
281         return 0;
282 #endif
283 }
284
285 static inline int au_test_debugfs(struct super_block *sb __maybe_unused)
286 {
287 #ifdef CONFIG_DEBUG_FS
288         return sb->s_magic == DEBUGFS_MAGIC;
289 #else
290         return 0;
291 #endif
292 }
293
294 static inline int au_test_nilfs(struct super_block *sb __maybe_unused)
295 {
296 #if defined(CONFIG_NILFS) || defined(CONFIG_NILFS_MODULE)
297         return sb->s_magic == NILFS_SUPER_MAGIC;
298 #else
299         return 0;
300 #endif
301 }
302
303 static inline int au_test_hfsplus(struct super_block *sb __maybe_unused)
304 {
305 #if defined(CONFIG_HFSPLUS_FS) || defined(CONFIG_HFSPLUS_FS_MODULE)
306         return sb->s_magic == HFSPLUS_SUPER_MAGIC;
307 #else
308         return 0;
309 #endif
310 }
311
312 /* ---------------------------------------------------------------------- */
313 /*
314  * they can't be an aufs branch.
315  */
316 static inline int au_test_fs_unsuppoted(struct super_block *sb)
317 {
318         return
319 #ifndef CONFIG_AUFS_BR_RAMFS
320                 au_test_ramfs(sb) ||
321 #endif
322                 au_test_procfs(sb)
323                 || au_test_sysfs(sb)
324                 || au_test_configfs(sb)
325                 || au_test_debugfs(sb)
326                 || au_test_securityfs(sb)
327                 || au_test_xenfs(sb)
328                 || au_test_ecryptfs(sb)
329                 /* || !strcmp(au_sbtype(sb), "unionfs") */
330                 || au_test_aufs(sb); /* will be supported in next version */
331 }
332
333 /*
334  * If the filesystem supports NFS-export, then it has to support NULL as
335  * a nameidata parameter for ->create(), ->lookup() and ->d_revalidate().
336  * We can apply this principle when we handle a lower filesystem.
337  */
338 static inline int au_test_fs_null_nd(struct super_block *sb)
339 {
340         return !!sb->s_export_op;
341 }
342
343 static inline int au_test_fs_remote(struct super_block *sb)
344 {
345         return !au_test_tmpfs(sb)
346 #ifdef CONFIG_AUFS_BR_RAMFS
347                 && !au_test_ramfs(sb)
348 #endif
349                 && !(sb->s_type->fs_flags & FS_REQUIRES_DEV);
350 }
351
352 /* ---------------------------------------------------------------------- */
353
354 /*
355  * Note: these functions (below) are created after reading ->getattr() in all
356  * filesystems under linux/fs. it means we have to do so in every update...
357  */
358
359 /*
360  * some filesystems require getattr to refresh the inode attributes before
361  * referencing.
362  * in most cases, we can rely on the inode attribute in NFS (or every remote fs)
363  * and leave the work for d_revalidate()
364  */
365 static inline int au_test_fs_refresh_iattr(struct super_block *sb)
366 {
367         return au_test_nfs(sb)
368                 || au_test_fuse(sb)
369                 /* || au_test_ocfs2(sb) */      /* untested */
370                 /* || au_test_btrfs(sb) */      /* untested */
371                 /* || au_test_coda(sb) */       /* untested */
372                 /* || au_test_v9fs(sb) */       /* untested */
373                 ;
374 }
375
376 /*
377  * filesystems which don't maintain i_size or i_blocks.
378  */
379 static inline int au_test_fs_bad_iattr_size(struct super_block *sb)
380 {
381         return au_test_xfs(sb)
382                 || au_test_btrfs(sb)
383                 || au_test_ubifs(sb)
384                 || au_test_hfsplus(sb)  /* maintained, but incorrect */
385                 /* || au_test_ext4(sb) */       /* untested */
386                 /* || au_test_ocfs2(sb) */      /* untested */
387                 /* || au_test_ocfs2_dlmfs(sb) */ /* untested */
388                 /* || au_test_sysv(sb) */       /* untested */
389                 /* || au_test_minix(sb) */      /* untested */
390                 ;
391 }
392
393 /*
394  * filesystems which don't store the correct value in some of their inode
395  * attributes.
396  */
397 static inline int au_test_fs_bad_iattr(struct super_block *sb)
398 {
399         return au_test_fs_bad_iattr_size(sb)
400                 /* || au_test_cifs(sb) */       /* untested */
401                 || au_test_fat(sb)
402                 || au_test_msdos(sb)
403                 || au_test_vfat(sb);
404 }
405
406 /* they don't check i_nlink in link(2) */
407 static inline int au_test_fs_no_limit_nlink(struct super_block *sb)
408 {
409         return au_test_tmpfs(sb)
410 #ifdef CONFIG_AUFS_BR_RAMFS
411                 || au_test_ramfs(sb)
412 #endif
413                 || au_test_ubifs(sb)
414                 || au_test_btrfs(sb)
415                 || au_test_hfsplus(sb);
416 }
417
418 /*
419  * filesystems which sets S_NOATIME and S_NOCMTIME.
420  */
421 static inline int au_test_fs_notime(struct super_block *sb)
422 {
423         return au_test_nfs(sb)
424                 || au_test_fuse(sb)
425                 || au_test_ubifs(sb)
426                 /* || au_test_cifs(sb) */       /* untested */
427                 ;
428 }
429
430 /*
431  * filesystems which requires replacing i_mapping.
432  */
433 static inline int au_test_fs_bad_mapping(struct super_block *sb)
434 {
435         return au_test_fuse(sb)
436                 || au_test_ubifs(sb);
437 }
438
439 /* temporary support for i#1 in cramfs */
440 static inline int au_test_fs_unique_ino(struct inode *inode)
441 {
442         if (au_test_cramfs(inode->i_sb))
443                 return inode->i_ino != 1;
444         return 1;
445 }
446
447 /* ---------------------------------------------------------------------- */
448
449 /*
450  * the filesystem where the xino files placed must support i/o after unlink and
451  * maintain i_size and i_blocks.
452  */
453 static inline int au_test_fs_bad_xino(struct super_block *sb)
454 {
455         return au_test_fs_remote(sb)
456                 || au_test_fs_bad_iattr_size(sb)
457 #ifdef CONFIG_AUFS_BR_RAMFS
458                 || !(au_test_ramfs(sb) || au_test_fs_null_nd(sb))
459 #else
460                 || !au_test_fs_null_nd(sb) /* to keep xino code simple */
461 #endif
462                 /* don't want unnecessary work for xino */
463                 || au_test_aufs(sb)
464                 || au_test_ecryptfs(sb)
465                 || au_test_nilfs(sb);
466 }
467
468 static inline int au_test_fs_trunc_xino(struct super_block *sb)
469 {
470         return au_test_tmpfs(sb)
471                 || au_test_ramfs(sb);
472 }
473
474 /*
475  * test if the @sb is real-readonly.
476  */
477 static inline int au_test_fs_rr(struct super_block *sb)
478 {
479         return au_test_squashfs(sb)
480                 || au_test_iso9660(sb)
481                 || au_test_cramfs(sb)
482                 || au_test_romfs(sb);
483 }
484
485 #endif /* __KERNEL__ */
486 #endif /* __AUFS_FSTYPE_H__ */