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