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