]> git.proxmox.com Git - mirror_ubuntu-jammy-kernel.git/blob - include/uapi/linux/aufs_type.h
UBUNTU: SAUCE: AUFS
[mirror_ubuntu-jammy-kernel.git] / include / uapi / linux / aufs_type.h
1 /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
2 /*
3 * Copyright (C) 2005-2021 Junjiro R. Okajima
4 *
5 * This program, aufs is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
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 #include <linux/limits.h>
37 #else
38 #include <stdint.h>
39 #include <sys/types.h>
40 #include <limits.h>
41 #endif /* __KERNEL__ */
42
43 #define AUFS_VERSION "5.15.5-20211129"
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 __KERNEL__
51 #ifdef CONFIG_AUFS_BRANCH_MAX_127
52 typedef int8_t aufs_bindex_t;
53 #define AUFS_BRANCH_MAX 127
54 #else
55 typedef int16_t aufs_bindex_t;
56 #ifdef CONFIG_AUFS_BRANCH_MAX_511
57 #define AUFS_BRANCH_MAX 511
58 #elif defined(CONFIG_AUFS_BRANCH_MAX_1023)
59 #define AUFS_BRANCH_MAX 1023
60 #elif defined(CONFIG_AUFS_BRANCH_MAX_32767)
61 #define AUFS_BRANCH_MAX 32767
62 #endif
63 #endif
64
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_FHSM_CACHE_DEF_SEC 30 /* seconds */
98 #define AUFS_PLINK_WARN 50 /* number of plinks in a single bucket */
99
100 /* pseudo-link maintenace under /proc */
101 #define AUFS_PLINK_MAINT_NAME "plink_maint"
102 #define AUFS_PLINK_MAINT_DIR "fs/" AUFS_NAME
103 #define AUFS_PLINK_MAINT_PATH AUFS_PLINK_MAINT_DIR "/" AUFS_PLINK_MAINT_NAME
104
105 /* dirren, renamed dir */
106 #define AUFS_DR_INFO_PFX AUFS_WH_PFX ".dr."
107 #define AUFS_DR_BRHINO_NAME AUFS_WH_PFX "hino"
108 /* whiteouted doubly */
109 #define AUFS_WH_DR_INFO_PFX AUFS_WH_PFX AUFS_DR_INFO_PFX
110 #define AUFS_WH_DR_BRHINO AUFS_WH_PFX AUFS_DR_BRHINO_NAME
111
112 #define AUFS_DIROPQ_NAME AUFS_WH_PFX ".opq" /* whiteouted doubly */
113 #define AUFS_WH_DIROPQ AUFS_WH_PFX AUFS_DIROPQ_NAME
114
115 #define AUFS_BASE_NAME AUFS_WH_PFX AUFS_NAME
116 #define AUFS_PLINKDIR_NAME AUFS_WH_PFX "plnk"
117 #define AUFS_ORPHDIR_NAME AUFS_WH_PFX "orph"
118
119 /* doubly whiteouted */
120 #define AUFS_WH_BASE AUFS_WH_PFX AUFS_BASE_NAME
121 #define AUFS_WH_PLINKDIR AUFS_WH_PFX AUFS_PLINKDIR_NAME
122 #define AUFS_WH_ORPHDIR AUFS_WH_PFX AUFS_ORPHDIR_NAME
123
124 /* branch permissions and attributes */
125 #define AUFS_BRPERM_RW "rw"
126 #define AUFS_BRPERM_RO "ro"
127 #define AUFS_BRPERM_RR "rr"
128 #define AUFS_BRATTR_COO_REG "coo_reg"
129 #define AUFS_BRATTR_COO_ALL "coo_all"
130 #define AUFS_BRATTR_FHSM "fhsm"
131 #define AUFS_BRATTR_UNPIN "unpin"
132 #define AUFS_BRATTR_ICEX "icex"
133 #define AUFS_BRATTR_ICEX_SEC "icexsec"
134 #define AUFS_BRATTR_ICEX_SYS "icexsys"
135 #define AUFS_BRATTR_ICEX_TR "icextr"
136 #define AUFS_BRATTR_ICEX_USR "icexusr"
137 #define AUFS_BRATTR_ICEX_OTH "icexoth"
138 #define AUFS_BRRATTR_WH "wh"
139 #define AUFS_BRWATTR_NLWH "nolwh"
140 #define AUFS_BRWATTR_MOO "moo"
141
142 #define AuBrPerm_RW 1 /* writable, hardlinkable wh */
143 #define AuBrPerm_RO (1 << 1) /* readonly */
144 #define AuBrPerm_RR (1 << 2) /* natively readonly */
145 #define AuBrPerm_Mask (AuBrPerm_RW | AuBrPerm_RO | AuBrPerm_RR)
146
147 #define AuBrAttr_COO_REG (1 << 3) /* copy-up on open */
148 #define AuBrAttr_COO_ALL (1 << 4)
149 #define AuBrAttr_COO_Mask (AuBrAttr_COO_REG | AuBrAttr_COO_ALL)
150
151 #define AuBrAttr_FHSM (1 << 5) /* file-based hsm */
152 #define AuBrAttr_UNPIN (1 << 6) /* rename-able top dir of
153 branch. meaningless since
154 linux-3.18-rc1 */
155
156 /* ignore error in copying XATTR */
157 #define AuBrAttr_ICEX_SEC (1 << 7)
158 #define AuBrAttr_ICEX_SYS (1 << 8)
159 #define AuBrAttr_ICEX_TR (1 << 9)
160 #define AuBrAttr_ICEX_USR (1 << 10)
161 #define AuBrAttr_ICEX_OTH (1 << 11)
162 #define AuBrAttr_ICEX (AuBrAttr_ICEX_SEC \
163 | AuBrAttr_ICEX_SYS \
164 | AuBrAttr_ICEX_TR \
165 | AuBrAttr_ICEX_USR \
166 | AuBrAttr_ICEX_OTH)
167
168 #define AuBrRAttr_WH (1 << 12) /* whiteout-able */
169 #define AuBrRAttr_Mask AuBrRAttr_WH
170
171 #define AuBrWAttr_NoLinkWH (1 << 13) /* un-hardlinkable whiteouts */
172 #define AuBrWAttr_MOO (1 << 14) /* move-up on open */
173 #define AuBrWAttr_Mask (AuBrWAttr_NoLinkWH | AuBrWAttr_MOO)
174
175 #define AuBrAttr_CMOO_Mask (AuBrAttr_COO_Mask | AuBrWAttr_MOO)
176
177 /* #warning test userspace */
178 #ifdef __KERNEL__
179 #ifndef CONFIG_AUFS_FHSM
180 #undef AuBrAttr_FHSM
181 #define AuBrAttr_FHSM 0
182 #endif
183 #ifndef CONFIG_AUFS_XATTR
184 #undef AuBrAttr_ICEX
185 #define AuBrAttr_ICEX 0
186 #undef AuBrAttr_ICEX_SEC
187 #define AuBrAttr_ICEX_SEC 0
188 #undef AuBrAttr_ICEX_SYS
189 #define AuBrAttr_ICEX_SYS 0
190 #undef AuBrAttr_ICEX_TR
191 #define AuBrAttr_ICEX_TR 0
192 #undef AuBrAttr_ICEX_USR
193 #define AuBrAttr_ICEX_USR 0
194 #undef AuBrAttr_ICEX_OTH
195 #define AuBrAttr_ICEX_OTH 0
196 #endif
197 #endif
198
199 /* the longest combination */
200 /* AUFS_BRATTR_ICEX and AUFS_BRATTR_ICEX_TR don't affect here */
201 #define AuBrPermStrSz sizeof(AUFS_BRPERM_RW \
202 "+" AUFS_BRATTR_COO_REG \
203 "+" AUFS_BRATTR_FHSM \
204 "+" AUFS_BRATTR_UNPIN \
205 "+" AUFS_BRATTR_ICEX_SEC \
206 "+" AUFS_BRATTR_ICEX_SYS \
207 "+" AUFS_BRATTR_ICEX_USR \
208 "+" AUFS_BRATTR_ICEX_OTH \
209 "+" AUFS_BRWATTR_NLWH)
210
211 typedef struct {
212 char a[AuBrPermStrSz];
213 } au_br_perm_str_t;
214
215 static inline int au_br_writable(int brperm)
216 {
217 return brperm & AuBrPerm_RW;
218 }
219
220 static inline int au_br_whable(int brperm)
221 {
222 return brperm & (AuBrPerm_RW | AuBrRAttr_WH);
223 }
224
225 static inline int au_br_wh_linkable(int brperm)
226 {
227 return !(brperm & AuBrWAttr_NoLinkWH);
228 }
229
230 static inline int au_br_cmoo(int brperm)
231 {
232 return brperm & AuBrAttr_CMOO_Mask;
233 }
234
235 static inline int au_br_fhsm(int brperm)
236 {
237 return brperm & AuBrAttr_FHSM;
238 }
239
240 /* ---------------------------------------------------------------------- */
241
242 /* ioctl */
243 enum {
244 /* readdir in userspace */
245 AuCtl_RDU,
246 AuCtl_RDU_INO,
247
248 AuCtl_WBR_FD, /* pathconf wrapper */
249 AuCtl_IBUSY, /* busy inode */
250 AuCtl_MVDOWN, /* move-down */
251 AuCtl_BR, /* info about branches */
252 AuCtl_FHSM_FD /* connection for fhsm */
253 };
254
255 /* borrowed from linux/include/linux/kernel.h */
256 #ifndef ALIGN
257 #ifdef _GNU_SOURCE
258 #define ALIGN(x, a) __ALIGN_MASK(x, (typeof(x))(a)-1)
259 #else
260 #define ALIGN(x, a) (((x) + (a) - 1) & ~((a) - 1))
261 #endif
262 #define __ALIGN_MASK(x, mask) (((x)+(mask))&~(mask))
263 #endif
264
265 /* borrowed from linux/include/linux/compiler-gcc3.h */
266 #ifndef __aligned
267 #define __aligned(x) __attribute__((aligned(x)))
268 #endif
269
270 #ifdef __KERNEL__
271 #ifndef __packed
272 #define __packed __attribute__((packed))
273 #endif
274 #endif
275
276 struct au_rdu_cookie {
277 uint64_t h_pos;
278 int16_t bindex;
279 uint8_t flags;
280 uint8_t pad;
281 uint32_t generation;
282 } __aligned(8);
283
284 struct au_rdu_ent {
285 uint64_t ino;
286 int16_t bindex;
287 uint8_t type;
288 uint8_t nlen;
289 uint8_t wh;
290 char name[];
291 } __aligned(8);
292
293 static inline int au_rdu_len(int nlen)
294 {
295 /* include the terminating NULL */
296 return ALIGN(sizeof(struct au_rdu_ent) + nlen + 1,
297 sizeof(uint64_t));
298 }
299
300 union au_rdu_ent_ul {
301 struct au_rdu_ent __user *e;
302 uint64_t ul;
303 };
304
305 enum {
306 AufsCtlRduV_SZ,
307 AufsCtlRduV_End
308 };
309
310 struct aufs_rdu {
311 /* input */
312 union {
313 uint64_t sz; /* AuCtl_RDU */
314 uint64_t nent; /* AuCtl_RDU_INO */
315 };
316 union au_rdu_ent_ul ent;
317 uint16_t verify[AufsCtlRduV_End];
318
319 /* input/output */
320 uint32_t blk;
321
322 /* output */
323 union au_rdu_ent_ul tail;
324 /* number of entries which were added in a single call */
325 uint64_t rent;
326 uint8_t full;
327 uint8_t shwh;
328
329 struct au_rdu_cookie cookie;
330 } __aligned(8);
331
332 /* ---------------------------------------------------------------------- */
333
334 /* dirren. the branch is identified by the filename who contains this */
335 struct au_drinfo {
336 uint64_t ino;
337 union {
338 uint8_t oldnamelen;
339 uint64_t _padding;
340 };
341 uint8_t oldname[];
342 } __aligned(8);
343
344 struct au_drinfo_fdata {
345 uint32_t magic;
346 struct au_drinfo drinfo;
347 } __aligned(8);
348
349 #define AUFS_DRINFO_MAGIC_V1 ('a' << 24 | 'd' << 16 | 'r' << 8 | 0x01)
350 /* future */
351 #define AUFS_DRINFO_MAGIC_V2 ('a' << 24 | 'd' << 16 | 'r' << 8 | 0x02)
352
353 /* ---------------------------------------------------------------------- */
354
355 struct aufs_wbr_fd {
356 uint32_t oflags;
357 int16_t brid;
358 } __aligned(8);
359
360 /* ---------------------------------------------------------------------- */
361
362 struct aufs_ibusy {
363 uint64_t ino, h_ino;
364 int16_t bindex;
365 } __aligned(8);
366
367 /* ---------------------------------------------------------------------- */
368
369 /* error code for move-down */
370 /* the actual message strings are implemented in aufs-util.git */
371 enum {
372 EAU_MVDOWN_OPAQUE = 1,
373 EAU_MVDOWN_WHITEOUT,
374 EAU_MVDOWN_UPPER,
375 EAU_MVDOWN_BOTTOM,
376 EAU_MVDOWN_NOUPPER,
377 EAU_MVDOWN_NOLOWERBR,
378 EAU_Last
379 };
380
381 /* flags for move-down */
382 #define AUFS_MVDOWN_DMSG 1
383 #define AUFS_MVDOWN_OWLOWER (1 << 1) /* overwrite lower */
384 #define AUFS_MVDOWN_KUPPER (1 << 2) /* keep upper */
385 #define AUFS_MVDOWN_ROLOWER (1 << 3) /* do even if lower is RO */
386 #define AUFS_MVDOWN_ROLOWER_R (1 << 4) /* did on lower RO */
387 #define AUFS_MVDOWN_ROUPPER (1 << 5) /* do even if upper is RO */
388 #define AUFS_MVDOWN_ROUPPER_R (1 << 6) /* did on upper RO */
389 #define AUFS_MVDOWN_BRID_UPPER (1 << 7) /* upper brid */
390 #define AUFS_MVDOWN_BRID_LOWER (1 << 8) /* lower brid */
391 #define AUFS_MVDOWN_FHSM_LOWER (1 << 9) /* find fhsm attr for lower */
392 #define AUFS_MVDOWN_STFS (1 << 10) /* req. stfs */
393 #define AUFS_MVDOWN_STFS_FAILED (1 << 11) /* output: stfs is unusable */
394 #define AUFS_MVDOWN_BOTTOM (1 << 12) /* output: no more lowers */
395
396 /* index for move-down */
397 enum {
398 AUFS_MVDOWN_UPPER,
399 AUFS_MVDOWN_LOWER,
400 AUFS_MVDOWN_NARRAY
401 };
402
403 /*
404 * additional info of move-down
405 * number of free blocks and inodes.
406 * subset of struct kstatfs, but smaller and always 64bit.
407 */
408 struct aufs_stfs {
409 uint64_t f_blocks;
410 uint64_t f_bavail;
411 uint64_t f_files;
412 uint64_t f_ffree;
413 };
414
415 struct aufs_stbr {
416 int16_t brid; /* optional input */
417 int16_t bindex; /* output */
418 struct aufs_stfs stfs; /* output when AUFS_MVDOWN_STFS set */
419 } __aligned(8);
420
421 struct aufs_mvdown {
422 uint32_t flags; /* input/output */
423 struct aufs_stbr stbr[AUFS_MVDOWN_NARRAY]; /* input/output */
424 int8_t au_errno; /* output */
425 } __aligned(8);
426
427 /* ---------------------------------------------------------------------- */
428
429 union aufs_brinfo {
430 /* PATH_MAX may differ between kernel-space and user-space */
431 char _spacer[4096];
432 struct {
433 int16_t id;
434 int perm;
435 char path[];
436 };
437 } __aligned(8);
438
439 /* ---------------------------------------------------------------------- */
440
441 #define AuCtlType 'A'
442 #define AUFS_CTL_RDU _IOWR(AuCtlType, AuCtl_RDU, struct aufs_rdu)
443 #define AUFS_CTL_RDU_INO _IOWR(AuCtlType, AuCtl_RDU_INO, struct aufs_rdu)
444 #define AUFS_CTL_WBR_FD _IOW(AuCtlType, AuCtl_WBR_FD, \
445 struct aufs_wbr_fd)
446 #define AUFS_CTL_IBUSY _IOWR(AuCtlType, AuCtl_IBUSY, struct aufs_ibusy)
447 #define AUFS_CTL_MVDOWN _IOWR(AuCtlType, AuCtl_MVDOWN, \
448 struct aufs_mvdown)
449 #define AUFS_CTL_BRINFO _IOW(AuCtlType, AuCtl_BR, union aufs_brinfo)
450 #define AUFS_CTL_FHSM_FD _IOW(AuCtlType, AuCtl_FHSM_FD, int)
451
452 #endif /* __AUFS_TYPE_H__ */