Merge branch 'stable-3.2' into pandora-3.2
[pandora-kernel.git] / fs / aufs / dcsub.h
1 /*
2  * Copyright (C) 2005-2012 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  * sub-routines for dentry cache
21  */
22
23 #ifndef __AUFS_DCSUB_H__
24 #define __AUFS_DCSUB_H__
25
26 #ifdef __KERNEL__
27
28 #include <linux/dcache.h>
29 #include <linux/fs.h>
30
31 struct dentry;
32
33 struct au_dpage {
34         int ndentry;
35         struct dentry **dentries;
36 };
37
38 struct au_dcsub_pages {
39         int ndpage;
40         struct au_dpage *dpages;
41 };
42
43 /* ---------------------------------------------------------------------- */
44
45 /* dcsub.c */
46 int au_dpages_init(struct au_dcsub_pages *dpages, gfp_t gfp);
47 void au_dpages_free(struct au_dcsub_pages *dpages);
48 typedef int (*au_dpages_test)(struct dentry *dentry, void *arg);
49 int au_dcsub_pages(struct au_dcsub_pages *dpages, struct dentry *root,
50                    au_dpages_test test, void *arg);
51 int au_dcsub_pages_rev(struct au_dcsub_pages *dpages, struct dentry *dentry,
52                        int do_include, au_dpages_test test, void *arg);
53 int au_dcsub_pages_rev_aufs(struct au_dcsub_pages *dpages,
54                             struct dentry *dentry, int do_include);
55 int au_test_subdir(struct dentry *d1, struct dentry *d2);
56
57 /* ---------------------------------------------------------------------- */
58
59 static inline int au_d_hashed_positive(struct dentry *d)
60 {
61         int err;
62         struct inode *inode = d->d_inode;
63         err = 0;
64         if (unlikely(d_unhashed(d) || !inode || !inode->i_nlink))
65                 err = -ENOENT;
66         return err;
67 }
68
69 static inline int au_d_alive(struct dentry *d)
70 {
71         int err;
72         struct inode *inode;
73         err = 0;
74         if (!IS_ROOT(d))
75                 err = au_d_hashed_positive(d);
76         else {
77                 inode = d->d_inode;
78                 if (unlikely(d_unlinked(d) || !inode || !inode->i_nlink))
79                         err = -ENOENT;
80         }
81         return err;
82 }
83
84 static inline int au_alive_dir(struct dentry *d)
85 {
86         int err;
87         err = au_d_alive(d);
88         if (unlikely(err || IS_DEADDIR(d->d_inode)))
89                 err = -ENOENT;
90         return err;
91 }
92
93 #endif /* __KERNEL__ */
94 #endif /* __AUFS_DCSUB_H__ */