xref: /linux/fs/overlayfs/overlayfs.h (revision c21c839b8448dd4b1e37ffc1bde928f57d34c0db)
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>
10ee023c30SAmir Goldstein #include "ovl_entry.h"
11e9be9d5eSMiklos Szeredi 
121bd0a3aeSlijiazi #undef pr_fmt
131bd0a3aeSlijiazi #define pr_fmt(fmt) "overlayfs: " fmt
141bd0a3aeSlijiazi 
15e9be9d5eSMiklos Szeredi enum ovl_path_type {
1638e813dbSMiklos Szeredi 	__OVL_PATH_UPPER	= (1 << 0),
1738e813dbSMiklos Szeredi 	__OVL_PATH_MERGE	= (1 << 1),
1859548503SAmir Goldstein 	__OVL_PATH_ORIGIN	= (1 << 2),
19e9be9d5eSMiklos Szeredi };
20e9be9d5eSMiklos Szeredi 
211afaba1eSMiklos Szeredi #define OVL_TYPE_UPPER(type)	((type) & __OVL_PATH_UPPER)
221afaba1eSMiklos Szeredi #define OVL_TYPE_MERGE(type)	((type) & __OVL_PATH_MERGE)
2359548503SAmir Goldstein #define OVL_TYPE_ORIGIN(type)	((type) & __OVL_PATH_ORIGIN)
24d837a49bSMiklos Szeredi 
25fe2b7595SAndreas Gruenbacher #define OVL_XATTR_PREFIX XATTR_TRUSTED_PREFIX "overlay."
26fe2b7595SAndreas Gruenbacher #define OVL_XATTR_OPAQUE OVL_XATTR_PREFIX "opaque"
2702b69b28SMiklos Szeredi #define OVL_XATTR_REDIRECT OVL_XATTR_PREFIX "redirect"
283a1e819bSAmir Goldstein #define OVL_XATTR_ORIGIN OVL_XATTR_PREFIX "origin"
29ee1d6d37SAmir Goldstein #define OVL_XATTR_IMPURE OVL_XATTR_PREFIX "impure"
305f8415d6SAmir Goldstein #define OVL_XATTR_NLINK OVL_XATTR_PREFIX "nlink"
31ad1d615cSAmir Goldstein #define OVL_XATTR_UPPER OVL_XATTR_PREFIX "upper"
320c288874SVivek Goyal #define OVL_XATTR_METACOPY OVL_XATTR_PREFIX "metacopy"
333a1e819bSAmir Goldstein 
34c62520a8SAmir Goldstein enum ovl_inode_flag {
35b79e05aaSAmir Goldstein 	/* Pure upper dir that may contain non pure upper entries */
3613c72075SMiklos Szeredi 	OVL_IMPURE,
37b79e05aaSAmir Goldstein 	/* Non-merge dir that may contain whiteout entries */
38b79e05aaSAmir Goldstein 	OVL_WHITEOUTS,
39359f392cSAmir Goldstein 	OVL_INDEX,
400c288874SVivek Goyal 	OVL_UPPERDATA,
41a00c2d59SVivek Goyal 	/* Inode number will remain constant over copy up. */
42a00c2d59SVivek Goyal 	OVL_CONST_INO,
4313c72075SMiklos Szeredi };
4413c72075SMiklos Szeredi 
45c62520a8SAmir Goldstein enum ovl_entry_flag {
46c62520a8SAmir Goldstein 	OVL_E_UPPER_ALIAS,
47c62520a8SAmir Goldstein 	OVL_E_OPAQUE,
482ca3c148SAmir Goldstein 	OVL_E_CONNECTED,
49c62520a8SAmir Goldstein };
50c62520a8SAmir Goldstein 
51926e94d7SAmir Goldstein enum {
52926e94d7SAmir Goldstein 	OVL_XINO_OFF,
53926e94d7SAmir Goldstein 	OVL_XINO_AUTO,
54926e94d7SAmir Goldstein 	OVL_XINO_ON,
55926e94d7SAmir Goldstein };
56926e94d7SAmir Goldstein 
573a1e819bSAmir Goldstein /*
583a1e819bSAmir Goldstein  * The tuple (fh,uuid) is a universal unique identifier for a copy up origin,
593a1e819bSAmir Goldstein  * where:
603a1e819bSAmir Goldstein  * origin.fh	- exported file handle of the lower file
613a1e819bSAmir Goldstein  * origin.uuid	- uuid of the lower filesystem
623a1e819bSAmir Goldstein  */
633a1e819bSAmir Goldstein #define OVL_FH_VERSION	0
643a1e819bSAmir Goldstein #define OVL_FH_MAGIC	0xfb
653a1e819bSAmir Goldstein 
663a1e819bSAmir Goldstein /* CPU byte order required for fid decoding:  */
673a1e819bSAmir Goldstein #define OVL_FH_FLAG_BIG_ENDIAN	(1 << 0)
683a1e819bSAmir Goldstein #define OVL_FH_FLAG_ANY_ENDIAN	(1 << 1)
6954fb347eSAmir Goldstein /* Is the real inode encoded in fid an upper inode? */
7054fb347eSAmir Goldstein #define OVL_FH_FLAG_PATH_UPPER	(1 << 2)
713a1e819bSAmir Goldstein 
72961af647SAmir Goldstein #define OVL_FH_FLAG_ALL (OVL_FH_FLAG_BIG_ENDIAN | OVL_FH_FLAG_ANY_ENDIAN | \
73961af647SAmir Goldstein 			 OVL_FH_FLAG_PATH_UPPER)
743a1e819bSAmir Goldstein 
753a1e819bSAmir Goldstein #if defined(__LITTLE_ENDIAN)
763a1e819bSAmir Goldstein #define OVL_FH_FLAG_CPU_ENDIAN 0
773a1e819bSAmir Goldstein #elif defined(__BIG_ENDIAN)
783a1e819bSAmir Goldstein #define OVL_FH_FLAG_CPU_ENDIAN OVL_FH_FLAG_BIG_ENDIAN
793a1e819bSAmir Goldstein #else
803a1e819bSAmir Goldstein #error Endianness not defined
813a1e819bSAmir Goldstein #endif
823a1e819bSAmir Goldstein 
83cbe7fba8SAmir Goldstein /* The type used to be returned by overlay exportfs for misaligned fid */
84cbe7fba8SAmir Goldstein #define OVL_FILEID_V0	0xfb
85cbe7fba8SAmir Goldstein /* The type returned by overlay exportfs for 32bit aligned fid */
86cbe7fba8SAmir Goldstein #define OVL_FILEID_V1	0xf8
878ed5eec9SAmir Goldstein 
88cbe7fba8SAmir Goldstein /* On-disk format for "origin" file handle */
89cbe7fba8SAmir Goldstein struct ovl_fb {
903a1e819bSAmir Goldstein 	u8 version;	/* 0 */
913a1e819bSAmir Goldstein 	u8 magic;	/* 0xfb */
923a1e819bSAmir Goldstein 	u8 len;		/* size of this header + size of fid */
933a1e819bSAmir Goldstein 	u8 flags;	/* OVL_FH_FLAG_* */
943a1e819bSAmir Goldstein 	u8 type;	/* fid_type of fid */
9501633fd2SChristoph Hellwig 	uuid_t uuid;	/* uuid of filesystem */
960efbe7c4SGustavo A. R. Silva 	u32 fid[];	/* file identifier should be 32bit aligned in-memory */
973a1e819bSAmir Goldstein } __packed;
98e9be9d5eSMiklos Szeredi 
99cbe7fba8SAmir Goldstein /* In-memory and on-wire format for overlay file handle */
100cbe7fba8SAmir Goldstein struct ovl_fh {
101cbe7fba8SAmir Goldstein 	u8 padding[3];	/* make sure fb.fid is 32bit aligned */
102cbe7fba8SAmir Goldstein 	union {
103cbe7fba8SAmir Goldstein 		struct ovl_fb fb;
104cbe7fba8SAmir Goldstein 		u8 buf[0];
105cbe7fba8SAmir Goldstein 	};
106cbe7fba8SAmir Goldstein } __packed;
107cbe7fba8SAmir Goldstein 
108cbe7fba8SAmir Goldstein #define OVL_FH_WIRE_OFFSET	offsetof(struct ovl_fh, fb)
109cbe7fba8SAmir Goldstein #define OVL_FH_LEN(fh)		(OVL_FH_WIRE_OFFSET + (fh)->fb.len)
110cbe7fba8SAmir Goldstein #define OVL_FH_FID_OFFSET	(OVL_FH_WIRE_OFFSET + \
111cbe7fba8SAmir Goldstein 				 offsetof(struct ovl_fb, fid))
112cbe7fba8SAmir Goldstein 
113e9be9d5eSMiklos Szeredi static inline int ovl_do_rmdir(struct inode *dir, struct dentry *dentry)
114e9be9d5eSMiklos Szeredi {
115e9be9d5eSMiklos Szeredi 	int err = vfs_rmdir(dir, dentry);
1166cf00764SAmir Goldstein 
117e9be9d5eSMiklos Szeredi 	pr_debug("rmdir(%pd2) = %i\n", dentry, err);
118e9be9d5eSMiklos Szeredi 	return err;
119e9be9d5eSMiklos Szeredi }
120e9be9d5eSMiklos Szeredi 
121e9be9d5eSMiklos Szeredi static inline int ovl_do_unlink(struct inode *dir, struct dentry *dentry)
122e9be9d5eSMiklos Szeredi {
123e9be9d5eSMiklos Szeredi 	int err = vfs_unlink(dir, dentry, NULL);
1246cf00764SAmir Goldstein 
125e9be9d5eSMiklos Szeredi 	pr_debug("unlink(%pd2) = %i\n", dentry, err);
126e9be9d5eSMiklos Szeredi 	return err;
127e9be9d5eSMiklos Szeredi }
128e9be9d5eSMiklos Szeredi 
129e9be9d5eSMiklos Szeredi static inline int ovl_do_link(struct dentry *old_dentry, struct inode *dir,
1306cf00764SAmir Goldstein 			      struct dentry *new_dentry)
131e9be9d5eSMiklos Szeredi {
132e9be9d5eSMiklos Szeredi 	int err = vfs_link(old_dentry, dir, new_dentry, NULL);
1336cf00764SAmir Goldstein 
1346cf00764SAmir Goldstein 	pr_debug("link(%pd2, %pd2) = %i\n", old_dentry, new_dentry, err);
135e9be9d5eSMiklos Szeredi 	return err;
136e9be9d5eSMiklos Szeredi }
137e9be9d5eSMiklos Szeredi 
138e9be9d5eSMiklos Szeredi static inline int ovl_do_create(struct inode *dir, struct dentry *dentry,
1396cf00764SAmir Goldstein 				umode_t mode)
140e9be9d5eSMiklos Szeredi {
141e9be9d5eSMiklos Szeredi 	int err = vfs_create(dir, dentry, mode, true);
1426cf00764SAmir Goldstein 
143e9be9d5eSMiklos Szeredi 	pr_debug("create(%pd2, 0%o) = %i\n", dentry, mode, err);
144e9be9d5eSMiklos Szeredi 	return err;
145e9be9d5eSMiklos Szeredi }
146e9be9d5eSMiklos Szeredi 
147e9be9d5eSMiklos Szeredi static inline int ovl_do_mkdir(struct inode *dir, struct dentry *dentry,
1486cf00764SAmir Goldstein 			       umode_t mode)
149e9be9d5eSMiklos Szeredi {
150e9be9d5eSMiklos Szeredi 	int err = vfs_mkdir(dir, dentry, mode);
151e9be9d5eSMiklos Szeredi 	pr_debug("mkdir(%pd2, 0%o) = %i\n", dentry, mode, err);
152e9be9d5eSMiklos Szeredi 	return err;
153e9be9d5eSMiklos Szeredi }
154e9be9d5eSMiklos Szeredi 
155e9be9d5eSMiklos Szeredi static inline int ovl_do_mknod(struct inode *dir, struct dentry *dentry,
1566cf00764SAmir Goldstein 			       umode_t mode, dev_t dev)
157e9be9d5eSMiklos Szeredi {
158e9be9d5eSMiklos Szeredi 	int err = vfs_mknod(dir, dentry, mode, dev);
1596cf00764SAmir Goldstein 
1606cf00764SAmir Goldstein 	pr_debug("mknod(%pd2, 0%o, 0%o) = %i\n", dentry, mode, dev, err);
161e9be9d5eSMiklos Szeredi 	return err;
162e9be9d5eSMiklos Szeredi }
163e9be9d5eSMiklos Szeredi 
164e9be9d5eSMiklos Szeredi static inline int ovl_do_symlink(struct inode *dir, struct dentry *dentry,
1656cf00764SAmir Goldstein 				 const char *oldname)
166e9be9d5eSMiklos Szeredi {
167e9be9d5eSMiklos Szeredi 	int err = vfs_symlink(dir, dentry, oldname);
1686cf00764SAmir Goldstein 
169e9be9d5eSMiklos Szeredi 	pr_debug("symlink(\"%s\", %pd2) = %i\n", oldname, dentry, err);
170e9be9d5eSMiklos Szeredi 	return err;
171e9be9d5eSMiklos Szeredi }
172e9be9d5eSMiklos Szeredi 
173e9be9d5eSMiklos Szeredi static inline int ovl_do_setxattr(struct dentry *dentry, const char *name,
174e9be9d5eSMiklos Szeredi 				  const void *value, size_t size, int flags)
175e9be9d5eSMiklos Szeredi {
176e9be9d5eSMiklos Szeredi 	int err = vfs_setxattr(dentry, name, value, size, flags);
1771a8f8d2aSMiklos Szeredi 	pr_debug("setxattr(%pd2, \"%s\", \"%*pE\", %zu, 0x%x) = %i\n",
1781a8f8d2aSMiklos Szeredi 		 dentry, name, min((int)size, 48), value, size, flags, err);
179e9be9d5eSMiklos Szeredi 	return err;
180e9be9d5eSMiklos Szeredi }
181e9be9d5eSMiklos Szeredi 
182e9be9d5eSMiklos Szeredi static inline int ovl_do_removexattr(struct dentry *dentry, const char *name)
183e9be9d5eSMiklos Szeredi {
184e9be9d5eSMiklos Szeredi 	int err = vfs_removexattr(dentry, name);
185e9be9d5eSMiklos Szeredi 	pr_debug("removexattr(%pd2, \"%s\") = %i\n", dentry, name, err);
186e9be9d5eSMiklos Szeredi 	return err;
187e9be9d5eSMiklos Szeredi }
188e9be9d5eSMiklos Szeredi 
189e9be9d5eSMiklos Szeredi static inline int ovl_do_rename(struct inode *olddir, struct dentry *olddentry,
190e9be9d5eSMiklos Szeredi 				struct inode *newdir, struct dentry *newdentry,
191e9be9d5eSMiklos Szeredi 				unsigned int flags)
192e9be9d5eSMiklos Szeredi {
193e9be9d5eSMiklos Szeredi 	int err;
194e9be9d5eSMiklos Szeredi 
1956cf00764SAmir Goldstein 	pr_debug("rename(%pd2, %pd2, 0x%x)\n", olddentry, newdentry, flags);
196e9be9d5eSMiklos Szeredi 	err = vfs_rename(olddir, olddentry, newdir, newdentry, NULL, flags);
197e9be9d5eSMiklos Szeredi 	if (err) {
1982773bf00SMiklos Szeredi 		pr_debug("...rename(%pd2, %pd2, ...) = %i\n",
199e9be9d5eSMiklos Szeredi 			 olddentry, newdentry, err);
200e9be9d5eSMiklos Szeredi 	}
201e9be9d5eSMiklos Szeredi 	return err;
202e9be9d5eSMiklos Szeredi }
203e9be9d5eSMiklos Szeredi 
204e9be9d5eSMiklos Szeredi static inline int ovl_do_whiteout(struct inode *dir, struct dentry *dentry)
205e9be9d5eSMiklos Szeredi {
206e9be9d5eSMiklos Szeredi 	int err = vfs_whiteout(dir, dentry);
207e9be9d5eSMiklos Szeredi 	pr_debug("whiteout(%pd2) = %i\n", dentry, err);
208e9be9d5eSMiklos Szeredi 	return err;
209e9be9d5eSMiklos Szeredi }
210e9be9d5eSMiklos Szeredi 
211e7f52429SAmir Goldstein static inline struct dentry *ovl_do_tmpfile(struct dentry *dentry, umode_t mode)
212e7f52429SAmir Goldstein {
213e7f52429SAmir Goldstein 	struct dentry *ret = vfs_tmpfile(dentry, mode, 0);
2147879cb43SVasyl Gomonovych 	int err = PTR_ERR_OR_ZERO(ret);
215e7f52429SAmir Goldstein 
216e7f52429SAmir Goldstein 	pr_debug("tmpfile(%pd2, 0%o) = %i\n", dentry, mode, err);
217e7f52429SAmir Goldstein 	return ret;
218e7f52429SAmir Goldstein }
219e7f52429SAmir Goldstein 
2200c288874SVivek Goyal static inline bool ovl_open_flags_need_copy_up(int flags)
2210c288874SVivek Goyal {
2220c288874SVivek Goyal 	if (!flags)
2230c288874SVivek Goyal 		return false;
2240c288874SVivek Goyal 
2250c288874SVivek Goyal 	return ((OPEN_FMODE(flags) & FMODE_WRITE) || (flags & O_TRUNC));
2260c288874SVivek Goyal }
2270c288874SVivek Goyal 
228bbb1e54dSMiklos Szeredi /* util.c */
229bbb1e54dSMiklos Szeredi int ovl_want_write(struct dentry *dentry);
230bbb1e54dSMiklos Szeredi void ovl_drop_write(struct dentry *dentry);
231bbb1e54dSMiklos Szeredi struct dentry *ovl_workdir(struct dentry *dentry);
232bbb1e54dSMiklos Szeredi const struct cred *ovl_override_creds(struct super_block *sb);
233e487d889SAmir Goldstein int ovl_can_decode_fh(struct super_block *sb);
23402bcd157SAmir Goldstein struct dentry *ovl_indexdir(struct super_block *sb);
235f168f109SAmir Goldstein bool ovl_index_all(struct super_block *sb);
236f168f109SAmir Goldstein bool ovl_verify_lower(struct super_block *sb);
237bbb1e54dSMiklos Szeredi struct ovl_entry *ovl_alloc_entry(unsigned int numlower);
238bbb1e54dSMiklos Szeredi bool ovl_dentry_remote(struct dentry *dentry);
239f4288844SMiklos Szeredi void ovl_dentry_update_reval(struct dentry *dentry, struct dentry *upperdentry,
240f4288844SMiklos Szeredi 			     unsigned int mask);
241bbb1e54dSMiklos Szeredi bool ovl_dentry_weird(struct dentry *dentry);
242e9be9d5eSMiklos Szeredi enum ovl_path_type ovl_path_type(struct dentry *dentry);
243e9be9d5eSMiklos Szeredi void ovl_path_upper(struct dentry *dentry, struct path *path);
244e9be9d5eSMiklos Szeredi void ovl_path_lower(struct dentry *dentry, struct path *path);
2454f93b426SVivek Goyal void ovl_path_lowerdata(struct dentry *dentry, struct path *path);
246e9be9d5eSMiklos Szeredi enum ovl_path_type ovl_path_real(struct dentry *dentry, struct path *path);
247e9be9d5eSMiklos Szeredi struct dentry *ovl_dentry_upper(struct dentry *dentry);
248e9be9d5eSMiklos Szeredi struct dentry *ovl_dentry_lower(struct dentry *dentry);
249647d253fSVivek Goyal struct dentry *ovl_dentry_lowerdata(struct dentry *dentry);
25013464165SMiklos Szeredi const struct ovl_layer *ovl_layer_lower(struct dentry *dentry);
251e9be9d5eSMiklos Szeredi struct dentry *ovl_dentry_real(struct dentry *dentry);
2521d88f183SMiklos Szeredi struct dentry *ovl_i_dentry_upper(struct inode *inode);
25309d8b586SMiklos Szeredi struct inode *ovl_inode_upper(struct inode *inode);
25409d8b586SMiklos Szeredi struct inode *ovl_inode_lower(struct inode *inode);
2552664bd08SVivek Goyal struct inode *ovl_inode_lowerdata(struct inode *inode);
25609d8b586SMiklos Szeredi struct inode *ovl_inode_real(struct inode *inode);
2574823d49cSVivek Goyal struct inode *ovl_inode_realdata(struct inode *inode);
2584edb83bbSMiklos Szeredi struct ovl_dir_cache *ovl_dir_cache(struct inode *inode);
2594edb83bbSMiklos Szeredi void ovl_set_dir_cache(struct inode *inode, struct ovl_dir_cache *cache);
260c62520a8SAmir Goldstein void ovl_dentry_set_flag(unsigned long flag, struct dentry *dentry);
261c62520a8SAmir Goldstein void ovl_dentry_clear_flag(unsigned long flag, struct dentry *dentry);
262c62520a8SAmir Goldstein bool ovl_dentry_test_flag(unsigned long flag, struct dentry *dentry);
263e9be9d5eSMiklos Szeredi bool ovl_dentry_is_opaque(struct dentry *dentry);
264c412ce49SMiklos Szeredi bool ovl_dentry_is_whiteout(struct dentry *dentry);
2655cf5b477SMiklos Szeredi void ovl_dentry_set_opaque(struct dentry *dentry);
26655acc661SMiklos Szeredi bool ovl_dentry_has_upper_alias(struct dentry *dentry);
26755acc661SMiklos Szeredi void ovl_dentry_set_upper_alias(struct dentry *dentry);
2680c288874SVivek Goyal bool ovl_dentry_needs_data_copy_up(struct dentry *dentry, int flags);
2690c288874SVivek Goyal bool ovl_dentry_needs_data_copy_up_locked(struct dentry *dentry, int flags);
2700c288874SVivek Goyal bool ovl_has_upperdata(struct inode *inode);
2710c288874SVivek Goyal void ovl_set_upperdata(struct inode *inode);
272a6c60655SMiklos Szeredi bool ovl_redirect_dir(struct super_block *sb);
273a6c60655SMiklos Szeredi const char *ovl_dentry_get_redirect(struct dentry *dentry);
274a6c60655SMiklos Szeredi void ovl_dentry_set_redirect(struct dentry *dentry, const char *redirect);
27509d8b586SMiklos Szeredi void ovl_inode_update(struct inode *inode, struct dentry *upperdentry);
276d9854c87SMiklos Szeredi void ovl_dir_modified(struct dentry *dentry, bool impurity);
277bbb1e54dSMiklos Szeredi u64 ovl_dentry_version_get(struct dentry *dentry);
278bbb1e54dSMiklos Szeredi bool ovl_is_whiteout(struct dentry *dentry);
279e9be9d5eSMiklos Szeredi struct file *ovl_path_open(struct path *path, int flags);
2800c288874SVivek Goyal int ovl_copy_up_start(struct dentry *dentry, int flags);
28139d3d60aSAmir Goldstein void ovl_copy_up_end(struct dentry *dentry);
2820c288874SVivek Goyal bool ovl_already_copied_up(struct dentry *dentry, int flags);
283b79e05aaSAmir Goldstein bool ovl_check_origin_xattr(struct dentry *dentry);
284f3a15685SAmir Goldstein bool ovl_check_dir_xattr(struct dentry *dentry, const char *name);
285f3a15685SAmir Goldstein int ovl_check_setxattr(struct dentry *dentry, struct dentry *upperdentry,
286f3a15685SAmir Goldstein 		       const char *name, const void *value, size_t size,
287f3a15685SAmir Goldstein 		       int xerr);
288f3a15685SAmir Goldstein int ovl_set_impure(struct dentry *dentry, struct dentry *upperdentry);
28913c72075SMiklos Szeredi void ovl_set_flag(unsigned long flag, struct inode *inode);
2904edb83bbSMiklos Szeredi void ovl_clear_flag(unsigned long flag, struct inode *inode);
29113c72075SMiklos Szeredi bool ovl_test_flag(unsigned long flag, struct inode *inode);
292ad0af710SAmir Goldstein bool ovl_inuse_trylock(struct dentry *dentry);
293ad0af710SAmir Goldstein void ovl_inuse_unlock(struct dentry *dentry);
294146d62e5SAmir Goldstein bool ovl_is_inuse(struct dentry *dentry);
29524b33ee1SAmir Goldstein bool ovl_need_index(struct dentry *dentry);
2960e32992fSAmir Goldstein int ovl_nlink_start(struct dentry *dentry);
2970e32992fSAmir Goldstein void ovl_nlink_end(struct dentry *dentry);
2985820dc08SAmir Goldstein int ovl_lock_rename_workdir(struct dentry *workdir, struct dentry *upperdir);
2999d3dfea3SVivek Goyal int ovl_check_metacopy_xattr(struct dentry *dentry);
30067d756c2SVivek Goyal bool ovl_is_metacopy_dentry(struct dentry *dentry);
3010a2d0d3fSVivek Goyal char *ovl_get_redirect_xattr(struct dentry *dentry, int padding);
302993a0b2aSVivek Goyal ssize_t ovl_getxattr(struct dentry *dentry, char *name, char **value,
303993a0b2aSVivek Goyal 		     size_t padding);
304f3a15685SAmir Goldstein 
305f3a15685SAmir Goldstein static inline bool ovl_is_impuredir(struct dentry *dentry)
306f3a15685SAmir Goldstein {
307f3a15685SAmir Goldstein 	return ovl_check_dir_xattr(dentry, OVL_XATTR_IMPURE);
308f3a15685SAmir Goldstein }
309f3a15685SAmir Goldstein 
310926e94d7SAmir Goldstein /*
311926e94d7SAmir Goldstein  * With xino=auto, we do best effort to keep all inodes on same st_dev and
312926e94d7SAmir Goldstein  * d_ino consistent with st_ino.
313926e94d7SAmir Goldstein  * With xino=on, we do the same effort but we warn if we failed.
314926e94d7SAmir Goldstein  */
315926e94d7SAmir Goldstein static inline bool ovl_xino_warn(struct super_block *sb)
316926e94d7SAmir Goldstein {
317926e94d7SAmir Goldstein 	return OVL_FS(sb)->config.xino == OVL_XINO_ON;
318926e94d7SAmir Goldstein }
319926e94d7SAmir Goldstein 
3200f831ec8SAmir Goldstein /* All layers on same fs? */
3210f831ec8SAmir Goldstein static inline bool ovl_same_fs(struct super_block *sb)
3220f831ec8SAmir Goldstein {
3230f831ec8SAmir Goldstein 	return OVL_FS(sb)->xino_mode == 0;
3240f831ec8SAmir Goldstein }
3250f831ec8SAmir Goldstein 
3260f831ec8SAmir Goldstein /* All overlay inodes have same st_dev? */
3270f831ec8SAmir Goldstein static inline bool ovl_same_dev(struct super_block *sb)
3280f831ec8SAmir Goldstein {
3290f831ec8SAmir Goldstein 	return OVL_FS(sb)->xino_mode >= 0;
3300f831ec8SAmir Goldstein }
3310f831ec8SAmir Goldstein 
332e487d889SAmir Goldstein static inline unsigned int ovl_xino_bits(struct super_block *sb)
333e487d889SAmir Goldstein {
3340f831ec8SAmir Goldstein 	return ovl_same_dev(sb) ? OVL_FS(sb)->xino_mode : 0;
335e487d889SAmir Goldstein }
336e487d889SAmir Goldstein 
337531d3040SAmir Goldstein static inline void ovl_inode_lock(struct inode *inode)
338531d3040SAmir Goldstein {
339531d3040SAmir Goldstein 	mutex_lock(&OVL_I(inode)->lock);
340531d3040SAmir Goldstein }
341531d3040SAmir Goldstein 
342531d3040SAmir Goldstein static inline int ovl_inode_lock_interruptible(struct inode *inode)
3431e92e307SAmir Goldstein {
3441e92e307SAmir Goldstein 	return mutex_lock_interruptible(&OVL_I(inode)->lock);
3451e92e307SAmir Goldstein }
3461e92e307SAmir Goldstein 
3471e92e307SAmir Goldstein static inline void ovl_inode_unlock(struct inode *inode)
3481e92e307SAmir Goldstein {
3491e92e307SAmir Goldstein 	mutex_unlock(&OVL_I(inode)->lock);
3501e92e307SAmir Goldstein }
3511e92e307SAmir Goldstein 
352e9be9d5eSMiklos Szeredi 
353bbb1e54dSMiklos Szeredi /* namei.c */
354cbe7fba8SAmir Goldstein int ovl_check_fb_len(struct ovl_fb *fb, int fb_len);
355cbe7fba8SAmir Goldstein 
356cbe7fba8SAmir Goldstein static inline int ovl_check_fh_len(struct ovl_fh *fh, int fh_len)
357cbe7fba8SAmir Goldstein {
358cbe7fba8SAmir Goldstein 	return ovl_check_fb_len(&fh->fb, fh_len - OVL_FH_WIRE_OFFSET);
359cbe7fba8SAmir Goldstein }
360cbe7fba8SAmir Goldstein 
3618a22efa1SAmir Goldstein struct dentry *ovl_decode_real_fh(struct ovl_fh *fh, struct vfsmount *mnt,
3628a22efa1SAmir Goldstein 				  bool connected);
3638a22efa1SAmir Goldstein int ovl_check_origin_fh(struct ovl_fs *ofs, struct ovl_fh *fh, bool connected,
364f941866fSAmir Goldstein 			struct dentry *upperdentry, struct ovl_path **stackp);
36505122443SAmir Goldstein int ovl_verify_set_fh(struct dentry *dentry, const char *name,
36605122443SAmir Goldstein 		      struct dentry *real, bool is_upper, bool set);
3673b0bfc6eSAmir Goldstein struct dentry *ovl_index_upper(struct ovl_fs *ofs, struct dentry *index);
3681eff1a1dSAmir Goldstein int ovl_verify_index(struct ovl_fs *ofs, struct dentry *index);
369359f392cSAmir Goldstein int ovl_get_index_name(struct dentry *origin, struct qstr *name);
37091ffe7beSAmir Goldstein struct dentry *ovl_get_index_fh(struct ovl_fs *ofs, struct ovl_fh *fh);
37106170154SAmir Goldstein struct dentry *ovl_lookup_index(struct ovl_fs *ofs, struct dentry *upper,
37206170154SAmir Goldstein 				struct dentry *origin, bool verify);
373bbb1e54dSMiklos Szeredi int ovl_path_next(int idx, struct dentry *dentry, struct path *path);
3741eff1a1dSAmir Goldstein struct dentry *ovl_lookup(struct inode *dir, struct dentry *dentry,
3751eff1a1dSAmir Goldstein 			  unsigned int flags);
376bbb1e54dSMiklos Szeredi bool ovl_lower_positive(struct dentry *dentry);
377e9be9d5eSMiklos Szeredi 
37805122443SAmir Goldstein static inline int ovl_verify_origin(struct dentry *upper,
37905122443SAmir Goldstein 				    struct dentry *origin, bool set)
38005122443SAmir Goldstein {
38105122443SAmir Goldstein 	return ovl_verify_set_fh(upper, OVL_XATTR_ORIGIN, origin, false, set);
38205122443SAmir Goldstein }
38305122443SAmir Goldstein 
384ad1d615cSAmir Goldstein static inline int ovl_verify_upper(struct dentry *index,
385ad1d615cSAmir Goldstein 				    struct dentry *upper, bool set)
386ad1d615cSAmir Goldstein {
387ad1d615cSAmir Goldstein 	return ovl_verify_set_fh(index, OVL_XATTR_UPPER, upper, true, set);
388ad1d615cSAmir Goldstein }
389ad1d615cSAmir Goldstein 
390e9be9d5eSMiklos Szeredi /* readdir.c */
391e9be9d5eSMiklos Szeredi extern const struct file_operations ovl_dir_operations;
392e9be9d5eSMiklos Szeredi int ovl_check_empty_dir(struct dentry *dentry, struct list_head *list);
393e9be9d5eSMiklos Szeredi void ovl_cleanup_whiteouts(struct dentry *upper, struct list_head *list);
394e9be9d5eSMiklos Szeredi void ovl_cache_free(struct list_head *list);
3954edb83bbSMiklos Szeredi void ovl_dir_cache_free(struct inode *inode);
39645aebeafSVivek Goyal int ovl_check_d_type_supported(struct path *realpath);
3973011645bSAmir Goldstein int ovl_workdir_cleanup(struct inode *dir, struct vfsmount *mnt,
398eea2fb48SMiklos Szeredi 			struct dentry *dentry, int level);
3991eff1a1dSAmir Goldstein int ovl_indexdir_cleanup(struct ovl_fs *ofs);
400e9be9d5eSMiklos Szeredi 
401e9be9d5eSMiklos Szeredi /* inode.c */
4025f8415d6SAmir Goldstein int ovl_set_nlink_upper(struct dentry *dentry);
4035f8415d6SAmir Goldstein int ovl_set_nlink_lower(struct dentry *dentry);
404caf70cb2SAmir Goldstein unsigned int ovl_get_nlink(struct dentry *lowerdentry,
405caf70cb2SAmir Goldstein 			   struct dentry *upperdentry,
406caf70cb2SAmir Goldstein 			   unsigned int fallback);
407e9be9d5eSMiklos Szeredi int ovl_setattr(struct dentry *dentry, struct iattr *attr);
4085b712091SMiklos Szeredi int ovl_getattr(const struct path *path, struct kstat *stat,
4095b712091SMiklos Szeredi 		u32 request_mask, unsigned int flags);
410e9be9d5eSMiklos Szeredi int ovl_permission(struct inode *inode, int mask);
4111d88f183SMiklos Szeredi int ovl_xattr_set(struct dentry *dentry, struct inode *inode, const char *name,
4121d88f183SMiklos Szeredi 		  const void *value, size_t size, int flags);
4131d88f183SMiklos Szeredi int ovl_xattr_get(struct dentry *dentry, struct inode *inode, const char *name,
4140eb45fc3SAndreas Gruenbacher 		  void *value, size_t size);
415e9be9d5eSMiklos Szeredi ssize_t ovl_listxattr(struct dentry *dentry, char *list, size_t size);
41639a25b2bSVivek Goyal struct posix_acl *ovl_get_acl(struct inode *inode, int type);
41795582b00SDeepa Dinamani int ovl_update_time(struct inode *inode, struct timespec64 *ts, int flags);
4180956254aSMiklos Szeredi bool ovl_is_private_xattr(const char *name);
419e9be9d5eSMiklos Szeredi 
420ac6a52ebSVivek Goyal struct ovl_inode_params {
42101b39dccSAmir Goldstein 	struct inode *newinode;
422ac6a52ebSVivek Goyal 	struct dentry *upperdentry;
423ac6a52ebSVivek Goyal 	struct ovl_path *lowerpath;
424ac6a52ebSVivek Goyal 	struct dentry *index;
425ac6a52ebSVivek Goyal 	unsigned int numlower;
4269cec54c8SVivek Goyal 	char *redirect;
4272664bd08SVivek Goyal 	struct dentry *lowerdata;
428ac6a52ebSVivek Goyal };
42962c832edSAmir Goldstein void ovl_inode_init(struct inode *inode, struct ovl_inode_params *oip,
43062c832edSAmir Goldstein 		    unsigned long ino, int fsid);
431ca4c8a3aSMiklos Szeredi struct inode *ovl_new_inode(struct super_block *sb, umode_t mode, dev_t rdev);
4324b91c30aSAmir Goldstein struct inode *ovl_lookup_inode(struct super_block *sb, struct dentry *real,
4334b91c30aSAmir Goldstein 			       bool is_upper);
434146d62e5SAmir Goldstein bool ovl_lookup_trap_inode(struct super_block *sb, struct dentry *dir);
435146d62e5SAmir Goldstein struct inode *ovl_get_trap_inode(struct super_block *sb, struct dentry *dir);
436ac6a52ebSVivek Goyal struct inode *ovl_get_inode(struct super_block *sb,
437ac6a52ebSVivek Goyal 			    struct ovl_inode_params *oip);
438e9be9d5eSMiklos Szeredi static inline void ovl_copyattr(struct inode *from, struct inode *to)
439e9be9d5eSMiklos Szeredi {
440e9be9d5eSMiklos Szeredi 	to->i_uid = from->i_uid;
441e9be9d5eSMiklos Szeredi 	to->i_gid = from->i_gid;
44207a2daabSVivek Goyal 	to->i_mode = from->i_mode;
443d719e8f2SMiklos Szeredi 	to->i_atime = from->i_atime;
444d719e8f2SMiklos Szeredi 	to->i_mtime = from->i_mtime;
445d719e8f2SMiklos Szeredi 	to->i_ctime = from->i_ctime;
44646e5d0a3SMiklos Szeredi 	i_size_write(to, i_size_read(from));
447e9be9d5eSMiklos Szeredi }
448e9be9d5eSMiklos Szeredi 
4494f357295SMiklos Szeredi static inline void ovl_copyflags(struct inode *from, struct inode *to)
4504f357295SMiklos Szeredi {
4514f357295SMiklos Szeredi 	unsigned int mask = S_SYNC | S_IMMUTABLE | S_APPEND | S_NOATIME;
4524f357295SMiklos Szeredi 
4534f357295SMiklos Szeredi 	inode_set_flags(to, from->i_flags & mask, mask);
4544f357295SMiklos Szeredi }
4554f357295SMiklos Szeredi 
456e9be9d5eSMiklos Szeredi /* dir.c */
457e9be9d5eSMiklos Szeredi extern const struct inode_operations ovl_dir_inode_operations;
458*c21c839bSChengguang Xu int ovl_cleanup_and_whiteout(struct ovl_fs *ofs, struct inode *dir,
459e7dd0e71SAmir Goldstein 			     struct dentry *dentry);
460471ec5dcSAmir Goldstein struct ovl_cattr {
46132a3d848SAl Viro 	dev_t rdev;
46232a3d848SAl Viro 	umode_t mode;
46332a3d848SAl Viro 	const char *link;
464471ec5dcSAmir Goldstein 	struct dentry *hardlink;
46532a3d848SAl Viro };
466471ec5dcSAmir Goldstein 
467471ec5dcSAmir Goldstein #define OVL_CATTR(m) (&(struct ovl_cattr) { .mode = (m) })
468471ec5dcSAmir Goldstein 
46995a1c815SMiklos Szeredi struct dentry *ovl_create_real(struct inode *dir, struct dentry *newdentry,
470471ec5dcSAmir Goldstein 			       struct ovl_cattr *attr);
471415543d5SAmir Goldstein int ovl_cleanup(struct inode *dir, struct dentry *dentry);
472cad218abSAmir Goldstein struct dentry *ovl_lookup_temp(struct dentry *workdir);
473137ec526SAmir Goldstein struct dentry *ovl_create_temp(struct dentry *workdir, struct ovl_cattr *attr);
474e9be9d5eSMiklos Szeredi 
475d1d04ef8SMiklos Szeredi /* file.c */
476d1d04ef8SMiklos Szeredi extern const struct file_operations ovl_file_operations;
4772406a307SJiufei Xue int __init ovl_aio_request_cache_init(void);
4782406a307SJiufei Xue void ovl_aio_request_cache_destroy(void);
479d1d04ef8SMiklos Szeredi 
480e9be9d5eSMiklos Szeredi /* copy_up.c */
481e9be9d5eSMiklos Szeredi int ovl_copy_up(struct dentry *dentry);
482d1e6f6a9SVivek Goyal int ovl_copy_up_with_data(struct dentry *dentry);
4839aba6521SAmir Goldstein int ovl_copy_up_flags(struct dentry *dentry, int flags);
4843428030dSAmir Goldstein int ovl_maybe_copy_up(struct dentry *dentry, int flags);
485e9be9d5eSMiklos Szeredi int ovl_copy_xattr(struct dentry *old, struct dentry *new);
486e9be9d5eSMiklos Szeredi int ovl_set_attr(struct dentry *upper, struct kstat *stat);
4875b2cccd3SAmir Goldstein struct ovl_fh *ovl_encode_real_fh(struct dentry *real, bool is_upper);
4889678e630SAmir Goldstein int ovl_set_origin(struct dentry *dentry, struct dentry *lower,
4899678e630SAmir Goldstein 		   struct dentry *upper);
4908ed5eec9SAmir Goldstein 
4918ed5eec9SAmir Goldstein /* export.c */
4928ed5eec9SAmir Goldstein extern const struct export_operations ovl_export_operations;
493