Merge branch 'stable-3.2' into pandora-3.2
[pandora-kernel.git] / include / linux / aufs_type.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 #ifndef __AUFS_TYPE_H__
20 #define __AUFS_TYPE_H__
21
22 #define AUFS_NAME       "aufs"
23
24 #ifdef __KERNEL__
25 /*
26  * define it before including all other headers.
27  * sched.h may use pr_* macros before defining "current", so define the
28  * no-current version first, and re-define later.
29  */
30 #define pr_fmt(fmt)     AUFS_NAME " %s:%d: " fmt, __func__, __LINE__
31 #include <linux/sched.h>
32 #undef pr_fmt
33 #define pr_fmt(fmt)     AUFS_NAME " %s:%d:%s[%d]: " fmt, \
34                 __func__, __LINE__, current->comm, current->pid
35 #else
36 #include <stdint.h>
37 #include <sys/types.h>
38 #endif /* __KERNEL__ */
39
40 #include <linux/limits.h>
41
42 #define AUFS_VERSION    "3.2-20120109"
43
44 /* todo? move this to linux-2.6.19/include/magic.h */
45 #define AUFS_SUPER_MAGIC        ('a' << 24 | 'u' << 16 | 'f' << 8 | 's')
46
47 /* ---------------------------------------------------------------------- */
48
49 #ifdef CONFIG_AUFS_BRANCH_MAX_127
50 typedef int8_t aufs_bindex_t;
51 #define AUFS_BRANCH_MAX 127
52 #else
53 typedef int16_t aufs_bindex_t;
54 #ifdef CONFIG_AUFS_BRANCH_MAX_511
55 #define AUFS_BRANCH_MAX 511
56 #elif defined(CONFIG_AUFS_BRANCH_MAX_1023)
57 #define AUFS_BRANCH_MAX 1023
58 #elif defined(CONFIG_AUFS_BRANCH_MAX_32767)
59 #define AUFS_BRANCH_MAX 32767
60 #endif
61 #endif
62
63 #ifdef __KERNEL__
64 #ifndef AUFS_BRANCH_MAX
65 #error unknown CONFIG_AUFS_BRANCH_MAX value
66 #endif
67 #endif /* __KERNEL__ */
68
69 /* ---------------------------------------------------------------------- */
70
71 #define AUFS_FSTYPE             AUFS_NAME
72
73 #define AUFS_ROOT_INO           2
74 #define AUFS_FIRST_INO          11
75
76 #define AUFS_WH_PFX             ".wh."
77 #define AUFS_WH_PFX_LEN         ((int)sizeof(AUFS_WH_PFX) - 1)
78 #define AUFS_WH_TMP_LEN         4
79 /* a limit for rmdir/rename a dir */
80 #define AUFS_MAX_NAMELEN        (NAME_MAX \
81                                 - AUFS_WH_PFX_LEN * 2   /* doubly whiteouted */\
82                                 - 1                     /* dot */\
83                                 - AUFS_WH_TMP_LEN)      /* hex */
84 #define AUFS_XINO_FNAME         "." AUFS_NAME ".xino"
85 #define AUFS_XINO_DEFPATH       "/tmp/" AUFS_XINO_FNAME
86 #define AUFS_XINO_TRUNC_INIT    64 /* blocks */
87 #define AUFS_XINO_TRUNC_STEP    4  /* blocks */
88 #define AUFS_DIRWH_DEF          3
89 #define AUFS_RDCACHE_DEF        10 /* seconds */
90 #define AUFS_RDCACHE_MAX        3600 /* seconds */
91 #define AUFS_RDBLK_DEF          512 /* bytes */
92 #define AUFS_RDHASH_DEF         32
93 #define AUFS_WKQ_NAME           AUFS_NAME "d"
94 #define AUFS_MFS_DEF_SEC        30 /* seconds */
95 #define AUFS_MFS_MAX_SEC        3600 /* seconds */
96 #define AUFS_PLINK_WARN         100 /* number of plinks */
97
98 /* pseudo-link maintenace under /proc */
99 #define AUFS_PLINK_MAINT_NAME   "plink_maint"
100 #define AUFS_PLINK_MAINT_DIR    "fs/" AUFS_NAME
101 #define AUFS_PLINK_MAINT_PATH   AUFS_PLINK_MAINT_DIR "/" AUFS_PLINK_MAINT_NAME
102
103 #define AUFS_DIROPQ_NAME        AUFS_WH_PFX ".opq" /* whiteouted doubly */
104 #define AUFS_WH_DIROPQ          AUFS_WH_PFX AUFS_DIROPQ_NAME
105
106 #define AUFS_BASE_NAME          AUFS_WH_PFX AUFS_NAME
107 #define AUFS_PLINKDIR_NAME      AUFS_WH_PFX "plnk"
108 #define AUFS_ORPHDIR_NAME       AUFS_WH_PFX "orph"
109
110 /* doubly whiteouted */
111 #define AUFS_WH_BASE            AUFS_WH_PFX AUFS_BASE_NAME
112 #define AUFS_WH_PLINKDIR        AUFS_WH_PFX AUFS_PLINKDIR_NAME
113 #define AUFS_WH_ORPHDIR         AUFS_WH_PFX AUFS_ORPHDIR_NAME
114
115 /* branch permissions and attributes */
116 #define AUFS_BRPERM_RW          "rw"
117 #define AUFS_BRPERM_RO          "ro"
118 #define AUFS_BRPERM_RR          "rr"
119 #define AUFS_BRRATTR_WH         "wh"
120 #define AUFS_BRWATTR_NLWH       "nolwh"
121
122 /* ---------------------------------------------------------------------- */
123
124 /* ioctl */
125 enum {
126         /* readdir in userspace */
127         AuCtl_RDU,
128         AuCtl_RDU_INO,
129
130         /* pathconf wrapper */
131         AuCtl_WBR_FD,
132
133         /* busy inode */
134         AuCtl_IBUSY
135 };
136
137 /* borrowed from linux/include/linux/kernel.h */
138 #ifndef ALIGN
139 #define ALIGN(x, a)             __ALIGN_MASK(x, (typeof(x))(a)-1)
140 #define __ALIGN_MASK(x, mask)   (((x)+(mask))&~(mask))
141 #endif
142
143 /* borrowed from linux/include/linux/compiler-gcc3.h */
144 #ifndef __aligned
145 #define __aligned(x)                    __attribute__((aligned(x)))
146 #endif
147
148 #ifdef __KERNEL__
149 #ifndef __packed
150 #define __packed                        __attribute__((packed))
151 #endif
152 #endif
153
154 struct au_rdu_cookie {
155         uint64_t        h_pos;
156         int16_t         bindex;
157         uint8_t         flags;
158         uint8_t         pad;
159         uint32_t        generation;
160 } __aligned(8);
161
162 struct au_rdu_ent {
163         uint64_t        ino;
164         int16_t         bindex;
165         uint8_t         type;
166         uint8_t         nlen;
167         uint8_t         wh;
168         char            name[0];
169 } __aligned(8);
170
171 static inline int au_rdu_len(int nlen)
172 {
173         /* include the terminating NULL */
174         return ALIGN(sizeof(struct au_rdu_ent) + nlen + 1,
175                      sizeof(uint64_t));
176 }
177
178 union au_rdu_ent_ul {
179         struct au_rdu_ent __user        *e;
180         uint64_t                        ul;
181 };
182
183 enum {
184         AufsCtlRduV_SZ,
185         AufsCtlRduV_End
186 };
187
188 struct aufs_rdu {
189         /* input */
190         union {
191                 uint64_t        sz;     /* AuCtl_RDU */
192                 uint64_t        nent;   /* AuCtl_RDU_INO */
193         };
194         union au_rdu_ent_ul     ent;
195         uint16_t                verify[AufsCtlRduV_End];
196
197         /* input/output */
198         uint32_t                blk;
199
200         /* output */
201         union au_rdu_ent_ul     tail;
202         /* number of entries which were added in a single call */
203         uint64_t                rent;
204         uint8_t                 full;
205         uint8_t                 shwh;
206
207         struct au_rdu_cookie    cookie;
208 } __aligned(8);
209
210 /* ---------------------------------------------------------------------- */
211
212 struct aufs_wbr_fd {
213         uint32_t        oflags;
214         int16_t         brid;
215 } __aligned(8);
216
217 /* ---------------------------------------------------------------------- */
218
219 struct aufs_ibusy {
220         uint64_t        ino, h_ino;
221         int16_t         bindex;
222 } __aligned(8);
223
224 /* ---------------------------------------------------------------------- */
225
226 #define AuCtlType               'A'
227 #define AUFS_CTL_RDU            _IOWR(AuCtlType, AuCtl_RDU, struct aufs_rdu)
228 #define AUFS_CTL_RDU_INO        _IOWR(AuCtlType, AuCtl_RDU_INO, struct aufs_rdu)
229 #define AUFS_CTL_WBR_FD         _IOW(AuCtlType, AuCtl_WBR_FD, \
230                                      struct aufs_wbr_fd)
231 #define AUFS_CTL_IBUSY          _IOWR(AuCtlType, AuCtl_IBUSY, struct aufs_ibusy)
232
233 #endif /* __AUFS_TYPE_H__ */