]> git.proxmox.com Git - mirror_ubuntu-focal-kernel.git/blame - fs/overlayfs/overlayfs.h
Merge remote-tracking branches 'asoc/topic/tas6424', 'asoc/topic/tfa9879', 'asoc...
[mirror_ubuntu-focal-kernel.git] / fs / overlayfs / overlayfs.h
CommitLineData
e9be9d5e
MS
1/*
2 *
3 * Copyright (C) 2011 Novell Inc.
4 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 as published by
7 * the Free Software Foundation.
8 */
9
10#include <linux/kernel.h>
3a1e819b 11#include <linux/uuid.h>
ee023c30 12#include "ovl_entry.h"
e9be9d5e 13
e9be9d5e 14enum ovl_path_type {
38e813db
MS
15 __OVL_PATH_UPPER = (1 << 0),
16 __OVL_PATH_MERGE = (1 << 1),
59548503 17 __OVL_PATH_ORIGIN = (1 << 2),
e9be9d5e
MS
18};
19
1afaba1e
MS
20#define OVL_TYPE_UPPER(type) ((type) & __OVL_PATH_UPPER)
21#define OVL_TYPE_MERGE(type) ((type) & __OVL_PATH_MERGE)
59548503 22#define OVL_TYPE_ORIGIN(type) ((type) & __OVL_PATH_ORIGIN)
d837a49b 23
fe2b7595
AG
24#define OVL_XATTR_PREFIX XATTR_TRUSTED_PREFIX "overlay."
25#define OVL_XATTR_OPAQUE OVL_XATTR_PREFIX "opaque"
02b69b28 26#define OVL_XATTR_REDIRECT OVL_XATTR_PREFIX "redirect"
3a1e819b 27#define OVL_XATTR_ORIGIN OVL_XATTR_PREFIX "origin"
ee1d6d37 28#define OVL_XATTR_IMPURE OVL_XATTR_PREFIX "impure"
5f8415d6 29#define OVL_XATTR_NLINK OVL_XATTR_PREFIX "nlink"
3a1e819b 30
13c72075 31enum ovl_flag {
b79e05aa 32 /* Pure upper dir that may contain non pure upper entries */
13c72075 33 OVL_IMPURE,
b79e05aa
AG
34 /* Non-merge dir that may contain whiteout entries */
35 OVL_WHITEOUTS,
359f392c 36 OVL_INDEX,
13c72075
MS
37};
38
3a1e819b
AG
39/*
40 * The tuple (fh,uuid) is a universal unique identifier for a copy up origin,
41 * where:
42 * origin.fh - exported file handle of the lower file
43 * origin.uuid - uuid of the lower filesystem
44 */
45#define OVL_FH_VERSION 0
46#define OVL_FH_MAGIC 0xfb
47
48/* CPU byte order required for fid decoding: */
49#define OVL_FH_FLAG_BIG_ENDIAN (1 << 0)
50#define OVL_FH_FLAG_ANY_ENDIAN (1 << 1)
54fb347e
AG
51/* Is the real inode encoded in fid an upper inode? */
52#define OVL_FH_FLAG_PATH_UPPER (1 << 2)
3a1e819b 53
961af647
AG
54#define OVL_FH_FLAG_ALL (OVL_FH_FLAG_BIG_ENDIAN | OVL_FH_FLAG_ANY_ENDIAN | \
55 OVL_FH_FLAG_PATH_UPPER)
3a1e819b
AG
56
57#if defined(__LITTLE_ENDIAN)
58#define OVL_FH_FLAG_CPU_ENDIAN 0
59#elif defined(__BIG_ENDIAN)
60#define OVL_FH_FLAG_CPU_ENDIAN OVL_FH_FLAG_BIG_ENDIAN
61#else
62#error Endianness not defined
63#endif
64
65/* On-disk and in-memeory format for redirect by file handle */
66struct ovl_fh {
67 u8 version; /* 0 */
68 u8 magic; /* 0xfb */
69 u8 len; /* size of this header + size of fid */
70 u8 flags; /* OVL_FH_FLAG_* */
71 u8 type; /* fid_type of fid */
01633fd2 72 uuid_t uuid; /* uuid of filesystem */
3a1e819b
AG
73 u8 fid[0]; /* file identifier */
74} __packed;
e9be9d5e
MS
75
76static inline int ovl_do_rmdir(struct inode *dir, struct dentry *dentry)
77{
78 int err = vfs_rmdir(dir, dentry);
79 pr_debug("rmdir(%pd2) = %i\n", dentry, err);
80 return err;
81}
82
83static inline int ovl_do_unlink(struct inode *dir, struct dentry *dentry)
84{
85 int err = vfs_unlink(dir, dentry, NULL);
86 pr_debug("unlink(%pd2) = %i\n", dentry, err);
87 return err;
88}
89
90static inline int ovl_do_link(struct dentry *old_dentry, struct inode *dir,
91 struct dentry *new_dentry, bool debug)
92{
93 int err = vfs_link(old_dentry, dir, new_dentry, NULL);
94 if (debug) {
95 pr_debug("link(%pd2, %pd2) = %i\n",
96 old_dentry, new_dentry, err);
97 }
98 return err;
99}
100
101static inline int ovl_do_create(struct inode *dir, struct dentry *dentry,
102 umode_t mode, bool debug)
103{
104 int err = vfs_create(dir, dentry, mode, true);
105 if (debug)
106 pr_debug("create(%pd2, 0%o) = %i\n", dentry, mode, err);
107 return err;
108}
109
110static inline int ovl_do_mkdir(struct inode *dir, struct dentry *dentry,
111 umode_t mode, bool debug)
112{
113 int err = vfs_mkdir(dir, dentry, mode);
114 if (debug)
115 pr_debug("mkdir(%pd2, 0%o) = %i\n", dentry, mode, err);
116 return err;
117}
118
119static inline int ovl_do_mknod(struct inode *dir, struct dentry *dentry,
120 umode_t mode, dev_t dev, bool debug)
121{
122 int err = vfs_mknod(dir, dentry, mode, dev);
123 if (debug) {
124 pr_debug("mknod(%pd2, 0%o, 0%o) = %i\n",
125 dentry, mode, dev, err);
126 }
127 return err;
128}
129
130static inline int ovl_do_symlink(struct inode *dir, struct dentry *dentry,
131 const char *oldname, bool debug)
132{
133 int err = vfs_symlink(dir, dentry, oldname);
134 if (debug)
135 pr_debug("symlink(\"%s\", %pd2) = %i\n", oldname, dentry, err);
136 return err;
137}
138
139static inline int ovl_do_setxattr(struct dentry *dentry, const char *name,
140 const void *value, size_t size, int flags)
141{
142 int err = vfs_setxattr(dentry, name, value, size, flags);
143 pr_debug("setxattr(%pd2, \"%s\", \"%*s\", 0x%x) = %i\n",
144 dentry, name, (int) size, (char *) value, flags, err);
145 return err;
146}
147
148static inline int ovl_do_removexattr(struct dentry *dentry, const char *name)
149{
150 int err = vfs_removexattr(dentry, name);
151 pr_debug("removexattr(%pd2, \"%s\") = %i\n", dentry, name, err);
152 return err;
153}
154
155static inline int ovl_do_rename(struct inode *olddir, struct dentry *olddentry,
156 struct inode *newdir, struct dentry *newdentry,
157 unsigned int flags)
158{
159 int err;
160
2773bf00 161 pr_debug("rename(%pd2, %pd2, 0x%x)\n",
e9be9d5e
MS
162 olddentry, newdentry, flags);
163
164 err = vfs_rename(olddir, olddentry, newdir, newdentry, NULL, flags);
165
166 if (err) {
2773bf00 167 pr_debug("...rename(%pd2, %pd2, ...) = %i\n",
e9be9d5e
MS
168 olddentry, newdentry, err);
169 }
170 return err;
171}
172
173static inline int ovl_do_whiteout(struct inode *dir, struct dentry *dentry)
174{
175 int err = vfs_whiteout(dir, dentry);
176 pr_debug("whiteout(%pd2) = %i\n", dentry, err);
177 return err;
178}
179
e7f52429
AG
180static inline struct dentry *ovl_do_tmpfile(struct dentry *dentry, umode_t mode)
181{
182 struct dentry *ret = vfs_tmpfile(dentry, mode, 0);
7879cb43 183 int err = PTR_ERR_OR_ZERO(ret);
e7f52429
AG
184
185 pr_debug("tmpfile(%pd2, 0%o) = %i\n", dentry, mode, err);
186 return ret;
187}
188
bbb1e54d
MS
189/* util.c */
190int ovl_want_write(struct dentry *dentry);
191void ovl_drop_write(struct dentry *dentry);
192struct dentry *ovl_workdir(struct dentry *dentry);
193const struct cred *ovl_override_creds(struct super_block *sb);
7bcd74b9 194struct super_block *ovl_same_sb(struct super_block *sb);
02bcd157
AG
195bool ovl_can_decode_fh(struct super_block *sb);
196struct dentry *ovl_indexdir(struct super_block *sb);
bbb1e54d
MS
197struct ovl_entry *ovl_alloc_entry(unsigned int numlower);
198bool ovl_dentry_remote(struct dentry *dentry);
199bool ovl_dentry_weird(struct dentry *dentry);
e9be9d5e 200enum ovl_path_type ovl_path_type(struct dentry *dentry);
e9be9d5e
MS
201void ovl_path_upper(struct dentry *dentry, struct path *path);
202void ovl_path_lower(struct dentry *dentry, struct path *path);
203enum ovl_path_type ovl_path_real(struct dentry *dentry, struct path *path);
204struct dentry *ovl_dentry_upper(struct dentry *dentry);
205struct dentry *ovl_dentry_lower(struct dentry *dentry);
206struct dentry *ovl_dentry_real(struct dentry *dentry);
1d88f183 207struct dentry *ovl_i_dentry_upper(struct inode *inode);
09d8b586
MS
208struct inode *ovl_inode_upper(struct inode *inode);
209struct inode *ovl_inode_lower(struct inode *inode);
210struct inode *ovl_inode_real(struct inode *inode);
4edb83bb
MS
211struct ovl_dir_cache *ovl_dir_cache(struct inode *inode);
212void ovl_set_dir_cache(struct inode *inode, struct ovl_dir_cache *cache);
e9be9d5e 213bool ovl_dentry_is_opaque(struct dentry *dentry);
c412ce49 214bool ovl_dentry_is_whiteout(struct dentry *dentry);
5cf5b477 215void ovl_dentry_set_opaque(struct dentry *dentry);
55acc661
MS
216bool ovl_dentry_has_upper_alias(struct dentry *dentry);
217void ovl_dentry_set_upper_alias(struct dentry *dentry);
a6c60655 218bool ovl_redirect_dir(struct super_block *sb);
a6c60655
MS
219const char *ovl_dentry_get_redirect(struct dentry *dentry);
220void ovl_dentry_set_redirect(struct dentry *dentry, const char *redirect);
09d8b586
MS
221void ovl_inode_init(struct inode *inode, struct dentry *upperdentry,
222 struct dentry *lowerdentry);
223void ovl_inode_update(struct inode *inode, struct dentry *upperdentry);
4edb83bb 224void ovl_dentry_version_inc(struct dentry *dentry, bool impurity);
bbb1e54d
MS
225u64 ovl_dentry_version_get(struct dentry *dentry);
226bool ovl_is_whiteout(struct dentry *dentry);
e9be9d5e 227struct file *ovl_path_open(struct path *path, int flags);
39d3d60a
AG
228int ovl_copy_up_start(struct dentry *dentry);
229void ovl_copy_up_end(struct dentry *dentry);
b79e05aa 230bool ovl_check_origin_xattr(struct dentry *dentry);
f3a15685
AG
231bool ovl_check_dir_xattr(struct dentry *dentry, const char *name);
232int ovl_check_setxattr(struct dentry *dentry, struct dentry *upperdentry,
233 const char *name, const void *value, size_t size,
234 int xerr);
235int ovl_set_impure(struct dentry *dentry, struct dentry *upperdentry);
13c72075 236void ovl_set_flag(unsigned long flag, struct inode *inode);
4edb83bb 237void ovl_clear_flag(unsigned long flag, struct inode *inode);
13c72075 238bool ovl_test_flag(unsigned long flag, struct inode *inode);
ad0af710
AG
239bool ovl_inuse_trylock(struct dentry *dentry);
240void ovl_inuse_unlock(struct dentry *dentry);
5f8415d6
AG
241int ovl_nlink_start(struct dentry *dentry, bool *locked);
242void ovl_nlink_end(struct dentry *dentry, bool locked);
5820dc08 243int ovl_lock_rename_workdir(struct dentry *workdir, struct dentry *upperdir);
f3a15685
AG
244
245static inline bool ovl_is_impuredir(struct dentry *dentry)
246{
247 return ovl_check_dir_xattr(dentry, OVL_XATTR_IMPURE);
248}
249
e9be9d5e 250
bbb1e54d 251/* namei.c */
d9768076
AG
252int ovl_verify_origin(struct dentry *dentry, struct dentry *origin,
253 bool is_upper, bool set);
b9343632 254int ovl_verify_index(struct dentry *index, struct ovl_path *lower,
415543d5 255 unsigned int numlower);
359f392c 256int ovl_get_index_name(struct dentry *origin, struct qstr *name);
bbb1e54d
MS
257int ovl_path_next(int idx, struct dentry *dentry, struct path *path);
258struct dentry *ovl_lookup(struct inode *dir, struct dentry *dentry, unsigned int flags);
259bool ovl_lower_positive(struct dentry *dentry);
e9be9d5e
MS
260
261/* readdir.c */
262extern const struct file_operations ovl_dir_operations;
263int ovl_check_empty_dir(struct dentry *dentry, struct list_head *list);
264void ovl_cleanup_whiteouts(struct dentry *upper, struct list_head *list);
265void ovl_cache_free(struct list_head *list);
4edb83bb 266void ovl_dir_cache_free(struct inode *inode);
45aebeaf 267int ovl_check_d_type_supported(struct path *realpath);
eea2fb48
MS
268void ovl_workdir_cleanup(struct inode *dir, struct vfsmount *mnt,
269 struct dentry *dentry, int level);
415543d5 270int ovl_indexdir_cleanup(struct dentry *dentry, struct vfsmount *mnt,
b9343632 271 struct ovl_path *lower, unsigned int numlower);
e9be9d5e
MS
272
273/* inode.c */
5f8415d6
AG
274int ovl_set_nlink_upper(struct dentry *dentry);
275int ovl_set_nlink_lower(struct dentry *dentry);
caf70cb2
AG
276unsigned int ovl_get_nlink(struct dentry *lowerdentry,
277 struct dentry *upperdentry,
278 unsigned int fallback);
e9be9d5e 279int ovl_setattr(struct dentry *dentry, struct iattr *attr);
5b712091
MS
280int ovl_getattr(const struct path *path, struct kstat *stat,
281 u32 request_mask, unsigned int flags);
e9be9d5e 282int ovl_permission(struct inode *inode, int mask);
1d88f183
MS
283int ovl_xattr_set(struct dentry *dentry, struct inode *inode, const char *name,
284 const void *value, size_t size, int flags);
285int ovl_xattr_get(struct dentry *dentry, struct inode *inode, const char *name,
0eb45fc3 286 void *value, size_t size);
e9be9d5e 287ssize_t ovl_listxattr(struct dentry *dentry, char *list, size_t size);
39a25b2b 288struct posix_acl *ovl_get_acl(struct inode *inode, int type);
2d902671 289int ovl_open_maybe_copy_up(struct dentry *dentry, unsigned int file_flags);
d719e8f2 290int ovl_update_time(struct inode *inode, struct timespec *ts, int flags);
0956254a 291bool ovl_is_private_xattr(const char *name);
e9be9d5e 292
ca4c8a3a 293struct inode *ovl_new_inode(struct super_block *sb, umode_t mode, dev_t rdev);
6eaf0111
AG
294struct inode *ovl_get_inode(struct dentry *dentry, struct dentry *upperdentry,
295 struct dentry *index);
e9be9d5e
MS
296static inline void ovl_copyattr(struct inode *from, struct inode *to)
297{
298 to->i_uid = from->i_uid;
299 to->i_gid = from->i_gid;
07a2daab 300 to->i_mode = from->i_mode;
d719e8f2
MS
301 to->i_atime = from->i_atime;
302 to->i_mtime = from->i_mtime;
303 to->i_ctime = from->i_ctime;
e9be9d5e
MS
304}
305
306/* dir.c */
307extern const struct inode_operations ovl_dir_inode_operations;
3d27573c 308struct dentry *ovl_lookup_temp(struct dentry *workdir);
32a3d848
AV
309struct cattr {
310 dev_t rdev;
311 umode_t mode;
312 const char *link;
313};
e9be9d5e 314int ovl_create_real(struct inode *dir, struct dentry *newdentry,
32a3d848 315 struct cattr *attr,
e9be9d5e 316 struct dentry *hardlink, bool debug);
415543d5 317int ovl_cleanup(struct inode *dir, struct dentry *dentry);
e9be9d5e
MS
318
319/* copy_up.c */
320int ovl_copy_up(struct dentry *dentry);
9aba6521 321int ovl_copy_up_flags(struct dentry *dentry, int flags);
e9be9d5e
MS
322int ovl_copy_xattr(struct dentry *old, struct dentry *new);
323int ovl_set_attr(struct dentry *upper, struct kstat *stat);
54fb347e 324struct ovl_fh *ovl_encode_fh(struct dentry *lower, bool is_upper);