xref: /linux/fs/overlayfs/overlayfs.h (revision 2d3430875a3a9761fcbd10aed4396b464ed5078c)
1d2912cb1SThomas Gleixner /* SPDX-License-Identifier: GPL-2.0-only */
2e9be9d5eSMiklos Szeredi /*
3e9be9d5eSMiklos Szeredi  *
4e9be9d5eSMiklos Szeredi  * Copyright (C) 2011 Novell Inc.
5e9be9d5eSMiklos Szeredi  */
6e9be9d5eSMiklos Szeredi 
7e9be9d5eSMiklos Szeredi #include <linux/kernel.h>
83a1e819bSAmir Goldstein #include <linux/uuid.h>
946e5d0a3SMiklos Szeredi #include <linux/fs.h>
1022f289ceSChristian Brauner #include <linux/namei.h>
11ee023c30SAmir Goldstein #include "ovl_entry.h"
12e9be9d5eSMiklos Szeredi 
131bd0a3aeSlijiazi #undef pr_fmt
141bd0a3aeSlijiazi #define pr_fmt(fmt) "overlayfs: " fmt
151bd0a3aeSlijiazi 
16e9be9d5eSMiklos Szeredi enum ovl_path_type {
1738e813dbSMiklos Szeredi 	__OVL_PATH_UPPER	= (1 << 0),
1838e813dbSMiklos Szeredi 	__OVL_PATH_MERGE	= (1 << 1),
1959548503SAmir Goldstein 	__OVL_PATH_ORIGIN	= (1 << 2),
20e9be9d5eSMiklos Szeredi };
21e9be9d5eSMiklos Szeredi 
221afaba1eSMiklos Szeredi #define OVL_TYPE_UPPER(type)	((type) & __OVL_PATH_UPPER)
231afaba1eSMiklos Szeredi #define OVL_TYPE_MERGE(type)	((type) & __OVL_PATH_MERGE)
2459548503SAmir Goldstein #define OVL_TYPE_ORIGIN(type)	((type) & __OVL_PATH_ORIGIN)
25d837a49bSMiklos Szeredi 
262d2f2d73SMiklos Szeredi #define OVL_XATTR_NAMESPACE "overlay."
272d2f2d73SMiklos Szeredi #define OVL_XATTR_TRUSTED_PREFIX XATTR_TRUSTED_PREFIX OVL_XATTR_NAMESPACE
282d2f2d73SMiklos Szeredi #define OVL_XATTR_USER_PREFIX XATTR_USER_PREFIX OVL_XATTR_NAMESPACE
2943d193f8SMiklos Szeredi 
3043d193f8SMiklos Szeredi enum ovl_xattr {
3143d193f8SMiklos Szeredi 	OVL_XATTR_OPAQUE,
3243d193f8SMiklos Szeredi 	OVL_XATTR_REDIRECT,
3343d193f8SMiklos Szeredi 	OVL_XATTR_ORIGIN,
3443d193f8SMiklos Szeredi 	OVL_XATTR_IMPURE,
3543d193f8SMiklos Szeredi 	OVL_XATTR_NLINK,
3643d193f8SMiklos Szeredi 	OVL_XATTR_UPPER,
3743d193f8SMiklos Szeredi 	OVL_XATTR_METACOPY,
38096a218aSAmir Goldstein 	OVL_XATTR_PROTATTR,
3943d193f8SMiklos Szeredi };
403a1e819bSAmir Goldstein 
41c62520a8SAmir Goldstein enum ovl_inode_flag {
42b79e05aaSAmir Goldstein 	/* Pure upper dir that may contain non pure upper entries */
4313c72075SMiklos Szeredi 	OVL_IMPURE,
44b79e05aaSAmir Goldstein 	/* Non-merge dir that may contain whiteout entries */
45b79e05aaSAmir Goldstein 	OVL_WHITEOUTS,
46359f392cSAmir Goldstein 	OVL_INDEX,
470c288874SVivek Goyal 	OVL_UPPERDATA,
48a00c2d59SVivek Goyal 	/* Inode number will remain constant over copy up. */
49a00c2d59SVivek Goyal 	OVL_CONST_INO,
5013c72075SMiklos Szeredi };
5113c72075SMiklos Szeredi 
52c62520a8SAmir Goldstein enum ovl_entry_flag {
53c62520a8SAmir Goldstein 	OVL_E_UPPER_ALIAS,
54c62520a8SAmir Goldstein 	OVL_E_OPAQUE,
552ca3c148SAmir Goldstein 	OVL_E_CONNECTED,
56c62520a8SAmir Goldstein };
57c62520a8SAmir Goldstein 
58926e94d7SAmir Goldstein enum {
59926e94d7SAmir Goldstein 	OVL_XINO_OFF,
60926e94d7SAmir Goldstein 	OVL_XINO_AUTO,
61926e94d7SAmir Goldstein 	OVL_XINO_ON,
62926e94d7SAmir Goldstein };
63926e94d7SAmir Goldstein 
643a1e819bSAmir Goldstein /*
653a1e819bSAmir Goldstein  * The tuple (fh,uuid) is a universal unique identifier for a copy up origin,
663a1e819bSAmir Goldstein  * where:
673a1e819bSAmir Goldstein  * origin.fh	- exported file handle of the lower file
683a1e819bSAmir Goldstein  * origin.uuid	- uuid of the lower filesystem
693a1e819bSAmir Goldstein  */
703a1e819bSAmir Goldstein #define OVL_FH_VERSION	0
713a1e819bSAmir Goldstein #define OVL_FH_MAGIC	0xfb
723a1e819bSAmir Goldstein 
733a1e819bSAmir Goldstein /* CPU byte order required for fid decoding:  */
743a1e819bSAmir Goldstein #define OVL_FH_FLAG_BIG_ENDIAN	(1 << 0)
753a1e819bSAmir Goldstein #define OVL_FH_FLAG_ANY_ENDIAN	(1 << 1)
7654fb347eSAmir Goldstein /* Is the real inode encoded in fid an upper inode? */
7754fb347eSAmir Goldstein #define OVL_FH_FLAG_PATH_UPPER	(1 << 2)
783a1e819bSAmir Goldstein 
79961af647SAmir Goldstein #define OVL_FH_FLAG_ALL (OVL_FH_FLAG_BIG_ENDIAN | OVL_FH_FLAG_ANY_ENDIAN | \
80961af647SAmir Goldstein 			 OVL_FH_FLAG_PATH_UPPER)
813a1e819bSAmir Goldstein 
823a1e819bSAmir Goldstein #if defined(__LITTLE_ENDIAN)
833a1e819bSAmir Goldstein #define OVL_FH_FLAG_CPU_ENDIAN 0
843a1e819bSAmir Goldstein #elif defined(__BIG_ENDIAN)
853a1e819bSAmir Goldstein #define OVL_FH_FLAG_CPU_ENDIAN OVL_FH_FLAG_BIG_ENDIAN
863a1e819bSAmir Goldstein #else
873a1e819bSAmir Goldstein #error Endianness not defined
883a1e819bSAmir Goldstein #endif
893a1e819bSAmir Goldstein 
90cbe7fba8SAmir Goldstein /* The type used to be returned by overlay exportfs for misaligned fid */
91cbe7fba8SAmir Goldstein #define OVL_FILEID_V0	0xfb
92cbe7fba8SAmir Goldstein /* The type returned by overlay exportfs for 32bit aligned fid */
93cbe7fba8SAmir Goldstein #define OVL_FILEID_V1	0xf8
948ed5eec9SAmir Goldstein 
95cbe7fba8SAmir Goldstein /* On-disk format for "origin" file handle */
96cbe7fba8SAmir Goldstein struct ovl_fb {
973a1e819bSAmir Goldstein 	u8 version;	/* 0 */
983a1e819bSAmir Goldstein 	u8 magic;	/* 0xfb */
993a1e819bSAmir Goldstein 	u8 len;		/* size of this header + size of fid */
1003a1e819bSAmir Goldstein 	u8 flags;	/* OVL_FH_FLAG_* */
1013a1e819bSAmir Goldstein 	u8 type;	/* fid_type of fid */
10201633fd2SChristoph Hellwig 	uuid_t uuid;	/* uuid of filesystem */
1030efbe7c4SGustavo A. R. Silva 	u32 fid[];	/* file identifier should be 32bit aligned in-memory */
1043a1e819bSAmir Goldstein } __packed;
105e9be9d5eSMiklos Szeredi 
106cbe7fba8SAmir Goldstein /* In-memory and on-wire format for overlay file handle */
107cbe7fba8SAmir Goldstein struct ovl_fh {
108cbe7fba8SAmir Goldstein 	u8 padding[3];	/* make sure fb.fid is 32bit aligned */
109cbe7fba8SAmir Goldstein 	union {
110cbe7fba8SAmir Goldstein 		struct ovl_fb fb;
111cbe7fba8SAmir Goldstein 		u8 buf[0];
112cbe7fba8SAmir Goldstein 	};
113cbe7fba8SAmir Goldstein } __packed;
114cbe7fba8SAmir Goldstein 
115cbe7fba8SAmir Goldstein #define OVL_FH_WIRE_OFFSET	offsetof(struct ovl_fh, fb)
116cbe7fba8SAmir Goldstein #define OVL_FH_LEN(fh)		(OVL_FH_WIRE_OFFSET + (fh)->fb.len)
117cbe7fba8SAmir Goldstein #define OVL_FH_FID_OFFSET	(OVL_FH_WIRE_OFFSET + \
118cbe7fba8SAmir Goldstein 				 offsetof(struct ovl_fb, fid))
119cbe7fba8SAmir Goldstein 
1202d2f2d73SMiklos Szeredi extern const char *const ovl_xattr_table[][2];
12143d193f8SMiklos Szeredi static inline const char *ovl_xattr(struct ovl_fs *ofs, enum ovl_xattr ox)
12243d193f8SMiklos Szeredi {
1232d2f2d73SMiklos Szeredi 	return ovl_xattr_table[ox][ofs->config.userxattr];
12443d193f8SMiklos Szeredi }
12543d193f8SMiklos Szeredi 
126a15506eaSChristian Brauner /*
127a15506eaSChristian Brauner  * When changing ownership of an upper object map the intended ownership
128a15506eaSChristian Brauner  * according to the upper layer's idmapping. When an upper mount idmaps files
129a15506eaSChristian Brauner  * that are stored on-disk as owned by id 1001 to id 1000 this means stat on
130a15506eaSChristian Brauner  * this object will report it as being owned by id 1000 when calling stat via
131a15506eaSChristian Brauner  * the upper mount.
132a15506eaSChristian Brauner  * In order to change ownership of an object so stat reports id 1000 when
133a15506eaSChristian Brauner  * called on an idmapped upper mount the value written to disk - i.e., the
134a15506eaSChristian Brauner  * value stored in ia_*id - must 1001. The mount mapping helper will thus take
135a15506eaSChristian Brauner  * care to map 1000 to 1001.
136a15506eaSChristian Brauner  * The mnt idmapping helpers are nops if the upper layer isn't idmapped.
137a15506eaSChristian Brauner  */
138a15506eaSChristian Brauner static inline int ovl_do_notify_change(struct ovl_fs *ofs,
139a15506eaSChristian Brauner 				       struct dentry *upperdentry,
140a15506eaSChristian Brauner 				       struct iattr *attr)
141a15506eaSChristian Brauner {
142b27c82e1SChristian Brauner 	return notify_change(ovl_upper_mnt_userns(ofs), upperdentry, attr, NULL);
143a15506eaSChristian Brauner }
144a15506eaSChristian Brauner 
145576bb263SChristian Brauner static inline int ovl_do_rmdir(struct ovl_fs *ofs,
146576bb263SChristian Brauner 			       struct inode *dir, struct dentry *dentry)
147e9be9d5eSMiklos Szeredi {
148c67cf654SChristian Brauner 	int err = vfs_rmdir(ovl_upper_mnt_userns(ofs), dir, dentry);
1496cf00764SAmir Goldstein 
150e9be9d5eSMiklos Szeredi 	pr_debug("rmdir(%pd2) = %i\n", dentry, err);
151e9be9d5eSMiklos Szeredi 	return err;
152e9be9d5eSMiklos Szeredi }
153e9be9d5eSMiklos Szeredi 
154576bb263SChristian Brauner static inline int ovl_do_unlink(struct ovl_fs *ofs, struct inode *dir,
155576bb263SChristian Brauner 				struct dentry *dentry)
156e9be9d5eSMiklos Szeredi {
157c67cf654SChristian Brauner 	int err = vfs_unlink(ovl_upper_mnt_userns(ofs), dir, dentry, NULL);
1586cf00764SAmir Goldstein 
159e9be9d5eSMiklos Szeredi 	pr_debug("unlink(%pd2) = %i\n", dentry, err);
160e9be9d5eSMiklos Szeredi 	return err;
161e9be9d5eSMiklos Szeredi }
162e9be9d5eSMiklos Szeredi 
163576bb263SChristian Brauner static inline int ovl_do_link(struct ovl_fs *ofs, struct dentry *old_dentry,
164576bb263SChristian Brauner 			      struct inode *dir, struct dentry *new_dentry)
165e9be9d5eSMiklos Szeredi {
166c67cf654SChristian Brauner 	int err = vfs_link(old_dentry, ovl_upper_mnt_userns(ofs), dir, new_dentry, NULL);
1676cf00764SAmir Goldstein 
1686cf00764SAmir Goldstein 	pr_debug("link(%pd2, %pd2) = %i\n", old_dentry, new_dentry, err);
169e9be9d5eSMiklos Szeredi 	return err;
170e9be9d5eSMiklos Szeredi }
171e9be9d5eSMiklos Szeredi 
172576bb263SChristian Brauner static inline int ovl_do_create(struct ovl_fs *ofs,
173576bb263SChristian Brauner 				struct inode *dir, struct dentry *dentry,
1746cf00764SAmir Goldstein 				umode_t mode)
175e9be9d5eSMiklos Szeredi {
176c67cf654SChristian Brauner 	int err = vfs_create(ovl_upper_mnt_userns(ofs), dir, dentry, mode, true);
1776cf00764SAmir Goldstein 
178e9be9d5eSMiklos Szeredi 	pr_debug("create(%pd2, 0%o) = %i\n", dentry, mode, err);
179e9be9d5eSMiklos Szeredi 	return err;
180e9be9d5eSMiklos Szeredi }
181e9be9d5eSMiklos Szeredi 
182576bb263SChristian Brauner static inline int ovl_do_mkdir(struct ovl_fs *ofs,
183576bb263SChristian Brauner 			       struct inode *dir, struct dentry *dentry,
1846cf00764SAmir Goldstein 			       umode_t mode)
185e9be9d5eSMiklos Szeredi {
186c67cf654SChristian Brauner 	int err = vfs_mkdir(ovl_upper_mnt_userns(ofs), dir, dentry, mode);
187e9be9d5eSMiklos Szeredi 	pr_debug("mkdir(%pd2, 0%o) = %i\n", dentry, mode, err);
188e9be9d5eSMiklos Szeredi 	return err;
189e9be9d5eSMiklos Szeredi }
190e9be9d5eSMiklos Szeredi 
191576bb263SChristian Brauner static inline int ovl_do_mknod(struct ovl_fs *ofs,
192576bb263SChristian Brauner 			       struct inode *dir, struct dentry *dentry,
1936cf00764SAmir Goldstein 			       umode_t mode, dev_t dev)
194e9be9d5eSMiklos Szeredi {
195c67cf654SChristian Brauner 	int err = vfs_mknod(ovl_upper_mnt_userns(ofs), dir, dentry, mode, dev);
1966cf00764SAmir Goldstein 
1976cf00764SAmir Goldstein 	pr_debug("mknod(%pd2, 0%o, 0%o) = %i\n", dentry, mode, dev, err);
198e9be9d5eSMiklos Szeredi 	return err;
199e9be9d5eSMiklos Szeredi }
200e9be9d5eSMiklos Szeredi 
201576bb263SChristian Brauner static inline int ovl_do_symlink(struct ovl_fs *ofs,
202576bb263SChristian Brauner 				 struct inode *dir, struct dentry *dentry,
2036cf00764SAmir Goldstein 				 const char *oldname)
204e9be9d5eSMiklos Szeredi {
205c67cf654SChristian Brauner 	int err = vfs_symlink(ovl_upper_mnt_userns(ofs), dir, dentry, oldname);
2066cf00764SAmir Goldstein 
207e9be9d5eSMiklos Szeredi 	pr_debug("symlink(\"%s\", %pd2) = %i\n", oldname, dentry, err);
208e9be9d5eSMiklos Szeredi 	return err;
209e9be9d5eSMiklos Szeredi }
210e9be9d5eSMiklos Szeredi 
211*2d343087SAl Viro static inline ssize_t ovl_do_getxattr(const struct path *path, const char *name,
212dad7017aSChristian Brauner 				      void *value, size_t size)
213d5dc7486SMiklos Szeredi {
214dad7017aSChristian Brauner 	int err, len;
215dad7017aSChristian Brauner 
216dad7017aSChristian Brauner 	WARN_ON(path->dentry->d_sb != path->mnt->mnt_sb);
217dad7017aSChristian Brauner 
218dad7017aSChristian Brauner 	err = vfs_getxattr(mnt_user_ns(path->mnt), path->dentry,
219dad7017aSChristian Brauner 			       name, value, size);
220dad7017aSChristian Brauner 	len = (value && err > 0) ? err : 0;
2215e717c6fSAmir Goldstein 
2225e717c6fSAmir Goldstein 	pr_debug("getxattr(%pd2, \"%s\", \"%*pE\", %zu, 0) = %i\n",
223dad7017aSChristian Brauner 		 path->dentry, name, min(len, 48), value, size, err);
2245e717c6fSAmir Goldstein 	return err;
225d5dc7486SMiklos Szeredi }
226d5dc7486SMiklos Szeredi 
227dad7017aSChristian Brauner static inline ssize_t ovl_getxattr_upper(struct ovl_fs *ofs,
228dad7017aSChristian Brauner 					 struct dentry *upperdentry,
229c914c0e2SAmir Goldstein 					 enum ovl_xattr ox, void *value,
230610afc0bSMiklos Szeredi 					 size_t size)
231e9be9d5eSMiklos Szeredi {
232dad7017aSChristian Brauner 	struct path upperpath = {
233dad7017aSChristian Brauner 		.dentry = upperdentry,
234dad7017aSChristian Brauner 		.mnt = ovl_upper_mnt(ofs),
235dad7017aSChristian Brauner 	};
236dad7017aSChristian Brauner 
237dad7017aSChristian Brauner 	return ovl_do_getxattr(&upperpath, ovl_xattr(ofs, ox), value, size);
238dad7017aSChristian Brauner }
239dad7017aSChristian Brauner 
240dad7017aSChristian Brauner static inline ssize_t ovl_path_getxattr(struct ovl_fs *ofs,
241*2d343087SAl Viro 					 const struct path *path,
242dad7017aSChristian Brauner 					 enum ovl_xattr ox, void *value,
243dad7017aSChristian Brauner 					 size_t size)
244dad7017aSChristian Brauner {
245dad7017aSChristian Brauner 	return ovl_do_getxattr(path, ovl_xattr(ofs, ox), value, size);
246c914c0e2SAmir Goldstein }
247c914c0e2SAmir Goldstein 
248c914c0e2SAmir Goldstein static inline int ovl_do_setxattr(struct ovl_fs *ofs, struct dentry *dentry,
249c914c0e2SAmir Goldstein 				  const char *name, const void *value,
250c914c0e2SAmir Goldstein 				  size_t size, int flags)
251c914c0e2SAmir Goldstein {
2520c5fd887SChristian Brauner 	int err = vfs_setxattr(ovl_upper_mnt_userns(ofs), dentry, name,
2530c5fd887SChristian Brauner 			       (void *)value, size, flags);
254c914c0e2SAmir Goldstein 
255c914c0e2SAmir Goldstein 	pr_debug("setxattr(%pd2, \"%s\", \"%*pE\", %zu, %d) = %i\n",
256c914c0e2SAmir Goldstein 		 dentry, name, min((int)size, 48), value, size, flags, err);
257e9be9d5eSMiklos Szeredi 	return err;
258e9be9d5eSMiklos Szeredi }
259e9be9d5eSMiklos Szeredi 
260c914c0e2SAmir Goldstein static inline int ovl_setxattr(struct ovl_fs *ofs, struct dentry *dentry,
261c914c0e2SAmir Goldstein 			       enum ovl_xattr ox, const void *value,
262c914c0e2SAmir Goldstein 			       size_t size)
263e9be9d5eSMiklos Szeredi {
264c914c0e2SAmir Goldstein 	return ovl_do_setxattr(ofs, dentry, ovl_xattr(ofs, ox), value, size, 0);
265c914c0e2SAmir Goldstein }
266c914c0e2SAmir Goldstein 
267c914c0e2SAmir Goldstein static inline int ovl_do_removexattr(struct ovl_fs *ofs, struct dentry *dentry,
268c914c0e2SAmir Goldstein 				     const char *name)
269c914c0e2SAmir Goldstein {
270dad7017aSChristian Brauner 	int err = vfs_removexattr(ovl_upper_mnt_userns(ofs), dentry, name);
271e9be9d5eSMiklos Szeredi 	pr_debug("removexattr(%pd2, \"%s\") = %i\n", dentry, name, err);
272e9be9d5eSMiklos Szeredi 	return err;
273e9be9d5eSMiklos Szeredi }
274e9be9d5eSMiklos Szeredi 
275c914c0e2SAmir Goldstein static inline int ovl_removexattr(struct ovl_fs *ofs, struct dentry *dentry,
276c914c0e2SAmir Goldstein 				  enum ovl_xattr ox)
277c914c0e2SAmir Goldstein {
278c914c0e2SAmir Goldstein 	return ovl_do_removexattr(ofs, dentry, ovl_xattr(ofs, ox));
279c914c0e2SAmir Goldstein }
280c914c0e2SAmir Goldstein 
281576bb263SChristian Brauner static inline int ovl_do_rename(struct ovl_fs *ofs, struct inode *olddir,
282576bb263SChristian Brauner 				struct dentry *olddentry, struct inode *newdir,
283576bb263SChristian Brauner 				struct dentry *newdentry, unsigned int flags)
284e9be9d5eSMiklos Szeredi {
285e9be9d5eSMiklos Szeredi 	int err;
2869fe61450SChristian Brauner 	struct renamedata rd = {
287c67cf654SChristian Brauner 		.old_mnt_userns	= ovl_upper_mnt_userns(ofs),
2889fe61450SChristian Brauner 		.old_dir 	= olddir,
2899fe61450SChristian Brauner 		.old_dentry 	= olddentry,
290c67cf654SChristian Brauner 		.new_mnt_userns	= ovl_upper_mnt_userns(ofs),
2919fe61450SChristian Brauner 		.new_dir 	= newdir,
2929fe61450SChristian Brauner 		.new_dentry 	= newdentry,
2939fe61450SChristian Brauner 		.flags 		= flags,
2949fe61450SChristian Brauner 	};
295e9be9d5eSMiklos Szeredi 
2966cf00764SAmir Goldstein 	pr_debug("rename(%pd2, %pd2, 0x%x)\n", olddentry, newdentry, flags);
2979fe61450SChristian Brauner 	err = vfs_rename(&rd);
298e9be9d5eSMiklos Szeredi 	if (err) {
2992773bf00SMiklos Szeredi 		pr_debug("...rename(%pd2, %pd2, ...) = %i\n",
300e9be9d5eSMiklos Szeredi 			 olddentry, newdentry, err);
301e9be9d5eSMiklos Szeredi 	}
302e9be9d5eSMiklos Szeredi 	return err;
303e9be9d5eSMiklos Szeredi }
304e9be9d5eSMiklos Szeredi 
305576bb263SChristian Brauner static inline int ovl_do_whiteout(struct ovl_fs *ofs,
306576bb263SChristian Brauner 				  struct inode *dir, struct dentry *dentry)
307e9be9d5eSMiklos Szeredi {
308c67cf654SChristian Brauner 	int err = vfs_whiteout(ovl_upper_mnt_userns(ofs), dir, dentry);
309e9be9d5eSMiklos Szeredi 	pr_debug("whiteout(%pd2) = %i\n", dentry, err);
310e9be9d5eSMiklos Szeredi 	return err;
311e9be9d5eSMiklos Szeredi }
312e9be9d5eSMiklos Szeredi 
313576bb263SChristian Brauner static inline struct dentry *ovl_do_tmpfile(struct ovl_fs *ofs,
314576bb263SChristian Brauner 					    struct dentry *dentry, umode_t mode)
315e7f52429SAmir Goldstein {
316c67cf654SChristian Brauner 	struct dentry *ret = vfs_tmpfile(ovl_upper_mnt_userns(ofs), dentry, mode, 0);
3177879cb43SVasyl Gomonovych 	int err = PTR_ERR_OR_ZERO(ret);
318e7f52429SAmir Goldstein 
319e7f52429SAmir Goldstein 	pr_debug("tmpfile(%pd2, 0%o) = %i\n", dentry, mode, err);
320e7f52429SAmir Goldstein 	return ret;
321e7f52429SAmir Goldstein }
322e7f52429SAmir Goldstein 
32322f289ceSChristian Brauner static inline struct dentry *ovl_lookup_upper(struct ovl_fs *ofs,
32422f289ceSChristian Brauner 					      const char *name,
32522f289ceSChristian Brauner 					      struct dentry *base, int len)
32622f289ceSChristian Brauner {
32722f289ceSChristian Brauner 	return lookup_one(ovl_upper_mnt_userns(ofs), name, base, len);
32822f289ceSChristian Brauner }
32922f289ceSChristian Brauner 
3300c288874SVivek Goyal static inline bool ovl_open_flags_need_copy_up(int flags)
3310c288874SVivek Goyal {
3320c288874SVivek Goyal 	if (!flags)
3330c288874SVivek Goyal 		return false;
3340c288874SVivek Goyal 
3350c288874SVivek Goyal 	return ((OPEN_FMODE(flags) & FMODE_WRITE) || (flags & O_TRUNC));
3360c288874SVivek Goyal }
3370c288874SVivek Goyal 
338ca45275cSVyacheslav Yurkov static inline bool ovl_allow_offline_changes(struct ovl_fs *ofs)
339ca45275cSVyacheslav Yurkov {
340ca45275cSVyacheslav Yurkov 	/*
341ca45275cSVyacheslav Yurkov 	 * To avoid regressions in existing setups with overlay lower offline
342ca45275cSVyacheslav Yurkov 	 * changes, we allow lower changes only if none of the new features
343ca45275cSVyacheslav Yurkov 	 * are used.
344ca45275cSVyacheslav Yurkov 	 */
345ca45275cSVyacheslav Yurkov 	return (!ofs->config.index && !ofs->config.metacopy &&
346ca45275cSVyacheslav Yurkov 		!ofs->config.redirect_dir && ofs->config.xino != OVL_XINO_ON);
347ca45275cSVyacheslav Yurkov }
348ca45275cSVyacheslav Yurkov 
349ca45275cSVyacheslav Yurkov 
350bbb1e54dSMiklos Szeredi /* util.c */
351bbb1e54dSMiklos Szeredi int ovl_want_write(struct dentry *dentry);
352bbb1e54dSMiklos Szeredi void ovl_drop_write(struct dentry *dentry);
353bbb1e54dSMiklos Szeredi struct dentry *ovl_workdir(struct dentry *dentry);
354bbb1e54dSMiklos Szeredi const struct cred *ovl_override_creds(struct super_block *sb);
355e487d889SAmir Goldstein int ovl_can_decode_fh(struct super_block *sb);
35602bcd157SAmir Goldstein struct dentry *ovl_indexdir(struct super_block *sb);
357f168f109SAmir Goldstein bool ovl_index_all(struct super_block *sb);
358f168f109SAmir Goldstein bool ovl_verify_lower(struct super_block *sb);
359bbb1e54dSMiklos Szeredi struct ovl_entry *ovl_alloc_entry(unsigned int numlower);
360bbb1e54dSMiklos Szeredi bool ovl_dentry_remote(struct dentry *dentry);
361f4288844SMiklos Szeredi void ovl_dentry_update_reval(struct dentry *dentry, struct dentry *upperdentry,
362f4288844SMiklos Szeredi 			     unsigned int mask);
363bbb1e54dSMiklos Szeredi bool ovl_dentry_weird(struct dentry *dentry);
364e9be9d5eSMiklos Szeredi enum ovl_path_type ovl_path_type(struct dentry *dentry);
365e9be9d5eSMiklos Szeredi void ovl_path_upper(struct dentry *dentry, struct path *path);
366e9be9d5eSMiklos Szeredi void ovl_path_lower(struct dentry *dentry, struct path *path);
3674f93b426SVivek Goyal void ovl_path_lowerdata(struct dentry *dentry, struct path *path);
368ffa5723cSAmir Goldstein void ovl_i_path_real(struct inode *inode, struct path *path);
369e9be9d5eSMiklos Szeredi enum ovl_path_type ovl_path_real(struct dentry *dentry, struct path *path);
3701248ea4bSAmir Goldstein enum ovl_path_type ovl_path_realdata(struct dentry *dentry, struct path *path);
371e9be9d5eSMiklos Szeredi struct dentry *ovl_dentry_upper(struct dentry *dentry);
372e9be9d5eSMiklos Szeredi struct dentry *ovl_dentry_lower(struct dentry *dentry);
373647d253fSVivek Goyal struct dentry *ovl_dentry_lowerdata(struct dentry *dentry);
374ffa5723cSAmir Goldstein const struct ovl_layer *ovl_i_layer_lower(struct inode *inode);
37513464165SMiklos Szeredi const struct ovl_layer *ovl_layer_lower(struct dentry *dentry);
376e9be9d5eSMiklos Szeredi struct dentry *ovl_dentry_real(struct dentry *dentry);
3771d88f183SMiklos Szeredi struct dentry *ovl_i_dentry_upper(struct inode *inode);
37809d8b586SMiklos Szeredi struct inode *ovl_inode_upper(struct inode *inode);
37909d8b586SMiklos Szeredi struct inode *ovl_inode_lower(struct inode *inode);
3802664bd08SVivek Goyal struct inode *ovl_inode_lowerdata(struct inode *inode);
38109d8b586SMiklos Szeredi struct inode *ovl_inode_real(struct inode *inode);
3824823d49cSVivek Goyal struct inode *ovl_inode_realdata(struct inode *inode);
3834edb83bbSMiklos Szeredi struct ovl_dir_cache *ovl_dir_cache(struct inode *inode);
3844edb83bbSMiklos Szeredi void ovl_set_dir_cache(struct inode *inode, struct ovl_dir_cache *cache);
385c62520a8SAmir Goldstein void ovl_dentry_set_flag(unsigned long flag, struct dentry *dentry);
386c62520a8SAmir Goldstein void ovl_dentry_clear_flag(unsigned long flag, struct dentry *dentry);
387c62520a8SAmir Goldstein bool ovl_dentry_test_flag(unsigned long flag, struct dentry *dentry);
388e9be9d5eSMiklos Szeredi bool ovl_dentry_is_opaque(struct dentry *dentry);
389c412ce49SMiklos Szeredi bool ovl_dentry_is_whiteout(struct dentry *dentry);
3905cf5b477SMiklos Szeredi void ovl_dentry_set_opaque(struct dentry *dentry);
39155acc661SMiklos Szeredi bool ovl_dentry_has_upper_alias(struct dentry *dentry);
39255acc661SMiklos Szeredi void ovl_dentry_set_upper_alias(struct dentry *dentry);
3930c288874SVivek Goyal bool ovl_dentry_needs_data_copy_up(struct dentry *dentry, int flags);
3940c288874SVivek Goyal bool ovl_dentry_needs_data_copy_up_locked(struct dentry *dentry, int flags);
3950c288874SVivek Goyal bool ovl_has_upperdata(struct inode *inode);
3960c288874SVivek Goyal void ovl_set_upperdata(struct inode *inode);
397a6c60655SMiklos Szeredi bool ovl_redirect_dir(struct super_block *sb);
398a6c60655SMiklos Szeredi const char *ovl_dentry_get_redirect(struct dentry *dentry);
399a6c60655SMiklos Szeredi void ovl_dentry_set_redirect(struct dentry *dentry, const char *redirect);
40009d8b586SMiklos Szeredi void ovl_inode_update(struct inode *inode, struct dentry *upperdentry);
401d9854c87SMiklos Szeredi void ovl_dir_modified(struct dentry *dentry, bool impurity);
402bbb1e54dSMiklos Szeredi u64 ovl_dentry_version_get(struct dentry *dentry);
403bbb1e54dSMiklos Szeredi bool ovl_is_whiteout(struct dentry *dentry);
404*2d343087SAl Viro struct file *ovl_path_open(const struct path *path, int flags);
4050c288874SVivek Goyal int ovl_copy_up_start(struct dentry *dentry, int flags);
40639d3d60aSAmir Goldstein void ovl_copy_up_end(struct dentry *dentry);
4070c288874SVivek Goyal bool ovl_already_copied_up(struct dentry *dentry, int flags);
408*2d343087SAl Viro bool ovl_path_check_dir_xattr(struct ovl_fs *ofs, const struct path *path,
40943d193f8SMiklos Szeredi 			      enum ovl_xattr ox);
410*2d343087SAl Viro bool ovl_path_check_origin_xattr(struct ovl_fs *ofs, const struct path *path);
411dad7017aSChristian Brauner 
412dad7017aSChristian Brauner static inline bool ovl_check_origin_xattr(struct ovl_fs *ofs,
413dad7017aSChristian Brauner 					  struct dentry *upperdentry)
414dad7017aSChristian Brauner {
415dad7017aSChristian Brauner 	struct path upperpath = {
416dad7017aSChristian Brauner 		.dentry = upperdentry,
417dad7017aSChristian Brauner 		.mnt = ovl_upper_mnt(ofs),
418dad7017aSChristian Brauner 	};
419dad7017aSChristian Brauner 	return ovl_path_check_origin_xattr(ofs, &upperpath);
420dad7017aSChristian Brauner }
421dad7017aSChristian Brauner 
422a0c236b1SAmir Goldstein int ovl_check_setxattr(struct ovl_fs *ofs, struct dentry *upperdentry,
42343d193f8SMiklos Szeredi 		       enum ovl_xattr ox, const void *value, size_t size,
424f3a15685SAmir Goldstein 		       int xerr);
425f3a15685SAmir Goldstein int ovl_set_impure(struct dentry *dentry, struct dentry *upperdentry);
426ad0af710SAmir Goldstein bool ovl_inuse_trylock(struct dentry *dentry);
427ad0af710SAmir Goldstein void ovl_inuse_unlock(struct dentry *dentry);
428146d62e5SAmir Goldstein bool ovl_is_inuse(struct dentry *dentry);
42924b33ee1SAmir Goldstein bool ovl_need_index(struct dentry *dentry);
4300e32992fSAmir Goldstein int ovl_nlink_start(struct dentry *dentry);
4310e32992fSAmir Goldstein void ovl_nlink_end(struct dentry *dentry);
4325820dc08SAmir Goldstein int ovl_lock_rename_workdir(struct dentry *workdir, struct dentry *upperdir);
433*2d343087SAl Viro int ovl_check_metacopy_xattr(struct ovl_fs *ofs, const struct path *path);
43467d756c2SVivek Goyal bool ovl_is_metacopy_dentry(struct dentry *dentry);
435*2d343087SAl Viro char *ovl_get_redirect_xattr(struct ovl_fs *ofs, const struct path *path, int padding);
436335d3fc5SSargun Dhillon int ovl_sync_status(struct ovl_fs *ofs);
437f3a15685SAmir Goldstein 
43865cd913eSAmir Goldstein static inline void ovl_set_flag(unsigned long flag, struct inode *inode)
43965cd913eSAmir Goldstein {
44065cd913eSAmir Goldstein 	set_bit(flag, &OVL_I(inode)->flags);
44165cd913eSAmir Goldstein }
44265cd913eSAmir Goldstein 
44365cd913eSAmir Goldstein static inline void ovl_clear_flag(unsigned long flag, struct inode *inode)
44465cd913eSAmir Goldstein {
44565cd913eSAmir Goldstein 	clear_bit(flag, &OVL_I(inode)->flags);
44665cd913eSAmir Goldstein }
44765cd913eSAmir Goldstein 
44865cd913eSAmir Goldstein static inline bool ovl_test_flag(unsigned long flag, struct inode *inode)
44965cd913eSAmir Goldstein {
45065cd913eSAmir Goldstein 	return test_bit(flag, &OVL_I(inode)->flags);
45165cd913eSAmir Goldstein }
45265cd913eSAmir Goldstein 
453610afc0bSMiklos Szeredi static inline bool ovl_is_impuredir(struct super_block *sb,
454dad7017aSChristian Brauner 				    struct dentry *upperdentry)
455f3a15685SAmir Goldstein {
456dad7017aSChristian Brauner 	struct ovl_fs *ofs = OVL_FS(sb);
457dad7017aSChristian Brauner 	struct path upperpath = {
458dad7017aSChristian Brauner 		.dentry = upperdentry,
459dad7017aSChristian Brauner 		.mnt = ovl_upper_mnt(ofs),
460dad7017aSChristian Brauner 	};
461dad7017aSChristian Brauner 
462dad7017aSChristian Brauner 	return ovl_path_check_dir_xattr(ofs, &upperpath, OVL_XATTR_IMPURE);
463f3a15685SAmir Goldstein }
464f3a15685SAmir Goldstein 
465926e94d7SAmir Goldstein /*
466926e94d7SAmir Goldstein  * With xino=auto, we do best effort to keep all inodes on same st_dev and
467926e94d7SAmir Goldstein  * d_ino consistent with st_ino.
468926e94d7SAmir Goldstein  * With xino=on, we do the same effort but we warn if we failed.
469926e94d7SAmir Goldstein  */
470926e94d7SAmir Goldstein static inline bool ovl_xino_warn(struct super_block *sb)
471926e94d7SAmir Goldstein {
472926e94d7SAmir Goldstein 	return OVL_FS(sb)->config.xino == OVL_XINO_ON;
473926e94d7SAmir Goldstein }
474926e94d7SAmir Goldstein 
4750f831ec8SAmir Goldstein /* All layers on same fs? */
4760f831ec8SAmir Goldstein static inline bool ovl_same_fs(struct super_block *sb)
4770f831ec8SAmir Goldstein {
4780f831ec8SAmir Goldstein 	return OVL_FS(sb)->xino_mode == 0;
4790f831ec8SAmir Goldstein }
4800f831ec8SAmir Goldstein 
4810f831ec8SAmir Goldstein /* All overlay inodes have same st_dev? */
4820f831ec8SAmir Goldstein static inline bool ovl_same_dev(struct super_block *sb)
4830f831ec8SAmir Goldstein {
4840f831ec8SAmir Goldstein 	return OVL_FS(sb)->xino_mode >= 0;
4850f831ec8SAmir Goldstein }
4860f831ec8SAmir Goldstein 
487e487d889SAmir Goldstein static inline unsigned int ovl_xino_bits(struct super_block *sb)
488e487d889SAmir Goldstein {
4890f831ec8SAmir Goldstein 	return ovl_same_dev(sb) ? OVL_FS(sb)->xino_mode : 0;
490e487d889SAmir Goldstein }
491e487d889SAmir Goldstein 
492531d3040SAmir Goldstein static inline void ovl_inode_lock(struct inode *inode)
493531d3040SAmir Goldstein {
494531d3040SAmir Goldstein 	mutex_lock(&OVL_I(inode)->lock);
495531d3040SAmir Goldstein }
496531d3040SAmir Goldstein 
497531d3040SAmir Goldstein static inline int ovl_inode_lock_interruptible(struct inode *inode)
4981e92e307SAmir Goldstein {
4991e92e307SAmir Goldstein 	return mutex_lock_interruptible(&OVL_I(inode)->lock);
5001e92e307SAmir Goldstein }
5011e92e307SAmir Goldstein 
5021e92e307SAmir Goldstein static inline void ovl_inode_unlock(struct inode *inode)
5031e92e307SAmir Goldstein {
5041e92e307SAmir Goldstein 	mutex_unlock(&OVL_I(inode)->lock);
5051e92e307SAmir Goldstein }
5061e92e307SAmir Goldstein 
507e9be9d5eSMiklos Szeredi 
508bbb1e54dSMiklos Szeredi /* namei.c */
509cbe7fba8SAmir Goldstein int ovl_check_fb_len(struct ovl_fb *fb, int fb_len);
510cbe7fba8SAmir Goldstein 
511cbe7fba8SAmir Goldstein static inline int ovl_check_fh_len(struct ovl_fh *fh, int fh_len)
512cbe7fba8SAmir Goldstein {
513522f6e6cSAmir Goldstein 	if (fh_len < sizeof(struct ovl_fh))
514522f6e6cSAmir Goldstein 		return -EINVAL;
515522f6e6cSAmir Goldstein 
516cbe7fba8SAmir Goldstein 	return ovl_check_fb_len(&fh->fb, fh_len - OVL_FH_WIRE_OFFSET);
517cbe7fba8SAmir Goldstein }
518cbe7fba8SAmir Goldstein 
5191cdb0cb6SPavel Tikhomirov struct dentry *ovl_decode_real_fh(struct ovl_fs *ofs, struct ovl_fh *fh,
5201cdb0cb6SPavel Tikhomirov 				  struct vfsmount *mnt, bool connected);
5218a22efa1SAmir Goldstein int ovl_check_origin_fh(struct ovl_fs *ofs, struct ovl_fh *fh, bool connected,
522f941866fSAmir Goldstein 			struct dentry *upperdentry, struct ovl_path **stackp);
523610afc0bSMiklos Szeredi int ovl_verify_set_fh(struct ovl_fs *ofs, struct dentry *dentry,
52443d193f8SMiklos Szeredi 		      enum ovl_xattr ox, struct dentry *real, bool is_upper,
525610afc0bSMiklos Szeredi 		      bool set);
5263b0bfc6eSAmir Goldstein struct dentry *ovl_index_upper(struct ovl_fs *ofs, struct dentry *index);
5271eff1a1dSAmir Goldstein int ovl_verify_index(struct ovl_fs *ofs, struct dentry *index);
5281cdb0cb6SPavel Tikhomirov int ovl_get_index_name(struct ovl_fs *ofs, struct dentry *origin,
5291cdb0cb6SPavel Tikhomirov 		       struct qstr *name);
53091ffe7beSAmir Goldstein struct dentry *ovl_get_index_fh(struct ovl_fs *ofs, struct ovl_fh *fh);
53106170154SAmir Goldstein struct dentry *ovl_lookup_index(struct ovl_fs *ofs, struct dentry *upper,
53206170154SAmir Goldstein 				struct dentry *origin, bool verify);
533bbb1e54dSMiklos Szeredi int ovl_path_next(int idx, struct dentry *dentry, struct path *path);
5341eff1a1dSAmir Goldstein struct dentry *ovl_lookup(struct inode *dir, struct dentry *dentry,
5351eff1a1dSAmir Goldstein 			  unsigned int flags);
536bbb1e54dSMiklos Szeredi bool ovl_lower_positive(struct dentry *dentry);
537e9be9d5eSMiklos Szeredi 
538610afc0bSMiklos Szeredi static inline int ovl_verify_origin(struct ovl_fs *ofs, struct dentry *upper,
53905122443SAmir Goldstein 				    struct dentry *origin, bool set)
54005122443SAmir Goldstein {
541610afc0bSMiklos Szeredi 	return ovl_verify_set_fh(ofs, upper, OVL_XATTR_ORIGIN, origin,
542610afc0bSMiklos Szeredi 				 false, set);
54305122443SAmir Goldstein }
54405122443SAmir Goldstein 
545610afc0bSMiklos Szeredi static inline int ovl_verify_upper(struct ovl_fs *ofs, struct dentry *index,
546ad1d615cSAmir Goldstein 				   struct dentry *upper, bool set)
547ad1d615cSAmir Goldstein {
548610afc0bSMiklos Szeredi 	return ovl_verify_set_fh(ofs, index, OVL_XATTR_UPPER, upper, true, set);
549ad1d615cSAmir Goldstein }
550ad1d615cSAmir Goldstein 
551e9be9d5eSMiklos Szeredi /* readdir.c */
552e9be9d5eSMiklos Szeredi extern const struct file_operations ovl_dir_operations;
55361536bedSAmir Goldstein struct file *ovl_dir_real_file(const struct file *file, bool want_upper);
554e9be9d5eSMiklos Szeredi int ovl_check_empty_dir(struct dentry *dentry, struct list_head *list);
555576bb263SChristian Brauner void ovl_cleanup_whiteouts(struct ovl_fs *ofs, struct dentry *upper,
556576bb263SChristian Brauner 			   struct list_head *list);
557e9be9d5eSMiklos Szeredi void ovl_cache_free(struct list_head *list);
5584edb83bbSMiklos Szeredi void ovl_dir_cache_free(struct inode *inode);
559*2d343087SAl Viro int ovl_check_d_type_supported(const struct path *realpath);
560576bb263SChristian Brauner int ovl_workdir_cleanup(struct ovl_fs *ofs, struct inode *dir,
561576bb263SChristian Brauner 			struct vfsmount *mnt, struct dentry *dentry, int level);
5621eff1a1dSAmir Goldstein int ovl_indexdir_cleanup(struct ovl_fs *ofs);
563e9be9d5eSMiklos Szeredi 
56465cd913eSAmir Goldstein /*
56565cd913eSAmir Goldstein  * Can we iterate real dir directly?
56665cd913eSAmir Goldstein  *
56765cd913eSAmir Goldstein  * Non-merge dir may contain whiteouts from a time it was a merge upper, before
56865cd913eSAmir Goldstein  * lower dir was removed under it and possibly before it was rotated from upper
56965cd913eSAmir Goldstein  * to lower layer.
57065cd913eSAmir Goldstein  */
57165cd913eSAmir Goldstein static inline bool ovl_dir_is_real(struct dentry *dir)
57265cd913eSAmir Goldstein {
57365cd913eSAmir Goldstein 	return !ovl_test_flag(OVL_WHITEOUTS, d_inode(dir));
57465cd913eSAmir Goldstein }
57565cd913eSAmir Goldstein 
576e9be9d5eSMiklos Szeredi /* inode.c */
5775f8415d6SAmir Goldstein int ovl_set_nlink_upper(struct dentry *dentry);
5785f8415d6SAmir Goldstein int ovl_set_nlink_lower(struct dentry *dentry);
579610afc0bSMiklos Szeredi unsigned int ovl_get_nlink(struct ovl_fs *ofs, struct dentry *lowerdentry,
580caf70cb2SAmir Goldstein 			   struct dentry *upperdentry,
581caf70cb2SAmir Goldstein 			   unsigned int fallback);
582549c7297SChristian Brauner int ovl_setattr(struct user_namespace *mnt_userns, struct dentry *dentry,
583549c7297SChristian Brauner 		struct iattr *attr);
584549c7297SChristian Brauner int ovl_getattr(struct user_namespace *mnt_userns, const struct path *path,
585549c7297SChristian Brauner 		struct kstat *stat, u32 request_mask, unsigned int flags);
586549c7297SChristian Brauner int ovl_permission(struct user_namespace *mnt_userns, struct inode *inode,
587549c7297SChristian Brauner 		   int mask);
5881d88f183SMiklos Szeredi int ovl_xattr_set(struct dentry *dentry, struct inode *inode, const char *name,
5891d88f183SMiklos Szeredi 		  const void *value, size_t size, int flags);
5901d88f183SMiklos Szeredi int ovl_xattr_get(struct dentry *dentry, struct inode *inode, const char *name,
5910eb45fc3SAndreas Gruenbacher 		  void *value, size_t size);
592e9be9d5eSMiklos Szeredi ssize_t ovl_listxattr(struct dentry *dentry, char *list, size_t size);
593ded53656SYang Xu 
594ded53656SYang Xu #ifdef CONFIG_FS_POSIX_ACL
5950cad6246SMiklos Szeredi struct posix_acl *ovl_get_acl(struct inode *inode, int type, bool rcu);
596ded53656SYang Xu #else
597ded53656SYang Xu #define ovl_get_acl	NULL
598ded53656SYang Xu #endif
599ded53656SYang Xu 
60095582b00SDeepa Dinamani int ovl_update_time(struct inode *inode, struct timespec64 *ts, int flags);
601610afc0bSMiklos Szeredi bool ovl_is_private_xattr(struct super_block *sb, const char *name);
602e9be9d5eSMiklos Szeredi 
603ac6a52ebSVivek Goyal struct ovl_inode_params {
60401b39dccSAmir Goldstein 	struct inode *newinode;
605ac6a52ebSVivek Goyal 	struct dentry *upperdentry;
606ac6a52ebSVivek Goyal 	struct ovl_path *lowerpath;
60774c6e384SMiklos Szeredi 	bool index;
608ac6a52ebSVivek Goyal 	unsigned int numlower;
6099cec54c8SVivek Goyal 	char *redirect;
6102664bd08SVivek Goyal 	struct dentry *lowerdata;
611ac6a52ebSVivek Goyal };
61262c832edSAmir Goldstein void ovl_inode_init(struct inode *inode, struct ovl_inode_params *oip,
61362c832edSAmir Goldstein 		    unsigned long ino, int fsid);
614ca4c8a3aSMiklos Szeredi struct inode *ovl_new_inode(struct super_block *sb, umode_t mode, dev_t rdev);
6154b91c30aSAmir Goldstein struct inode *ovl_lookup_inode(struct super_block *sb, struct dentry *real,
6164b91c30aSAmir Goldstein 			       bool is_upper);
617146d62e5SAmir Goldstein bool ovl_lookup_trap_inode(struct super_block *sb, struct dentry *dir);
618146d62e5SAmir Goldstein struct inode *ovl_get_trap_inode(struct super_block *sb, struct dentry *dir);
619ac6a52ebSVivek Goyal struct inode *ovl_get_inode(struct super_block *sb,
620ac6a52ebSVivek Goyal 			    struct ovl_inode_params *oip);
6212878dffcSChristian Brauner void ovl_copyattr(struct inode *to);
622e9be9d5eSMiklos Szeredi 
62372db8211SAmir Goldstein /* vfs inode flags copied from real to ovl inode */
62472db8211SAmir Goldstein #define OVL_COPY_I_FLAGS_MASK	(S_SYNC | S_NOATIME | S_APPEND | S_IMMUTABLE)
625096a218aSAmir Goldstein /* vfs inode flags read from overlay.protattr xattr to ovl inode */
626096a218aSAmir Goldstein #define OVL_PROT_I_FLAGS_MASK	(S_APPEND | S_IMMUTABLE)
62772db8211SAmir Goldstein 
62872db8211SAmir Goldstein /*
62972db8211SAmir Goldstein  * fileattr flags copied from lower to upper inode on copy up.
630096a218aSAmir Goldstein  * We cannot copy up immutable/append-only flags, because that would prevent
631096a218aSAmir Goldstein  * linking temp inode to upper dir, so we store them in xattr instead.
63272db8211SAmir Goldstein  */
63372db8211SAmir Goldstein #define OVL_COPY_FS_FLAGS_MASK	(FS_SYNC_FL | FS_NOATIME_FL)
63472db8211SAmir Goldstein #define OVL_COPY_FSX_FLAGS_MASK	(FS_XFLAG_SYNC | FS_XFLAG_NOATIME)
635096a218aSAmir Goldstein #define OVL_PROT_FS_FLAGS_MASK  (FS_APPEND_FL | FS_IMMUTABLE_FL)
636096a218aSAmir Goldstein #define OVL_PROT_FSX_FLAGS_MASK (FS_XFLAG_APPEND | FS_XFLAG_IMMUTABLE)
637096a218aSAmir Goldstein 
638096a218aSAmir Goldstein void ovl_check_protattr(struct inode *inode, struct dentry *upper);
639096a218aSAmir Goldstein int ovl_set_protattr(struct inode *inode, struct dentry *upper,
640096a218aSAmir Goldstein 		      struct fileattr *fa);
64172db8211SAmir Goldstein 
6424f357295SMiklos Szeredi static inline void ovl_copyflags(struct inode *from, struct inode *to)
6434f357295SMiklos Szeredi {
64472db8211SAmir Goldstein 	unsigned int mask = OVL_COPY_I_FLAGS_MASK;
6454f357295SMiklos Szeredi 
6464f357295SMiklos Szeredi 	inode_set_flags(to, from->i_flags & mask, mask);
6474f357295SMiklos Szeredi }
6484f357295SMiklos Szeredi 
649e9be9d5eSMiklos Szeredi /* dir.c */
650e9be9d5eSMiklos Szeredi extern const struct inode_operations ovl_dir_inode_operations;
651c21c839bSChengguang Xu int ovl_cleanup_and_whiteout(struct ovl_fs *ofs, struct inode *dir,
652e7dd0e71SAmir Goldstein 			     struct dentry *dentry);
653471ec5dcSAmir Goldstein struct ovl_cattr {
65432a3d848SAl Viro 	dev_t rdev;
65532a3d848SAl Viro 	umode_t mode;
65632a3d848SAl Viro 	const char *link;
657471ec5dcSAmir Goldstein 	struct dentry *hardlink;
65832a3d848SAl Viro };
659471ec5dcSAmir Goldstein 
660471ec5dcSAmir Goldstein #define OVL_CATTR(m) (&(struct ovl_cattr) { .mode = (m) })
661471ec5dcSAmir Goldstein 
662576bb263SChristian Brauner int ovl_mkdir_real(struct ovl_fs *ofs, struct inode *dir,
663576bb263SChristian Brauner 		   struct dentry **newdentry, umode_t mode);
664576bb263SChristian Brauner struct dentry *ovl_create_real(struct ovl_fs *ofs,
665576bb263SChristian Brauner 			       struct inode *dir, struct dentry *newdentry,
666471ec5dcSAmir Goldstein 			       struct ovl_cattr *attr);
667576bb263SChristian Brauner int ovl_cleanup(struct ovl_fs *ofs, struct inode *dir, struct dentry *dentry);
668576bb263SChristian Brauner struct dentry *ovl_lookup_temp(struct ovl_fs *ofs, struct dentry *workdir);
669576bb263SChristian Brauner struct dentry *ovl_create_temp(struct ovl_fs *ofs, struct dentry *workdir,
670576bb263SChristian Brauner 			       struct ovl_cattr *attr);
671e9be9d5eSMiklos Szeredi 
672d1d04ef8SMiklos Szeredi /* file.c */
673d1d04ef8SMiklos Szeredi extern const struct file_operations ovl_file_operations;
6742406a307SJiufei Xue int __init ovl_aio_request_cache_init(void);
6752406a307SJiufei Xue void ovl_aio_request_cache_destroy(void);
676*2d343087SAl Viro int ovl_real_fileattr_get(const struct path *realpath, struct fileattr *fa);
677*2d343087SAl Viro int ovl_real_fileattr_set(const struct path *realpath, struct fileattr *fa);
67866dbfabfSMiklos Szeredi int ovl_fileattr_get(struct dentry *dentry, struct fileattr *fa);
67966dbfabfSMiklos Szeredi int ovl_fileattr_set(struct user_namespace *mnt_userns,
68066dbfabfSMiklos Szeredi 		     struct dentry *dentry, struct fileattr *fa);
681d1d04ef8SMiklos Szeredi 
682e9be9d5eSMiklos Szeredi /* copy_up.c */
683e9be9d5eSMiklos Szeredi int ovl_copy_up(struct dentry *dentry);
684d1e6f6a9SVivek Goyal int ovl_copy_up_with_data(struct dentry *dentry);
6853428030dSAmir Goldstein int ovl_maybe_copy_up(struct dentry *dentry, int flags);
686*2d343087SAl Viro int ovl_copy_xattr(struct super_block *sb, const struct path *path, struct dentry *new);
6875272eaf3SChristian Brauner int ovl_set_attr(struct ovl_fs *ofs, struct dentry *upper, struct kstat *stat);
6881cdb0cb6SPavel Tikhomirov struct ovl_fh *ovl_encode_real_fh(struct ovl_fs *ofs, struct dentry *real,
6891cdb0cb6SPavel Tikhomirov 				  bool is_upper);
690a0c236b1SAmir Goldstein int ovl_set_origin(struct ovl_fs *ofs, struct dentry *lower,
691a0c236b1SAmir Goldstein 		   struct dentry *upper);
6928ed5eec9SAmir Goldstein 
6938ed5eec9SAmir Goldstein /* export.c */
6948ed5eec9SAmir Goldstein extern const struct export_operations ovl_export_operations;
695