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> 10*22f289ceSChristian 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 { 142a15506eaSChristian Brauner struct user_namespace *upper_mnt_userns = ovl_upper_mnt_userns(ofs); 143a15506eaSChristian Brauner struct user_namespace *fs_userns = i_user_ns(d_inode(upperdentry)); 144a15506eaSChristian Brauner 145a15506eaSChristian Brauner if (attr->ia_valid & ATTR_UID) 146a15506eaSChristian Brauner attr->ia_uid = mapped_kuid_user(upper_mnt_userns, 147a15506eaSChristian Brauner fs_userns, attr->ia_uid); 148a15506eaSChristian Brauner if (attr->ia_valid & ATTR_GID) 149a15506eaSChristian Brauner attr->ia_gid = mapped_kgid_user(upper_mnt_userns, 150a15506eaSChristian Brauner fs_userns, attr->ia_gid); 151a15506eaSChristian Brauner 152a15506eaSChristian Brauner return notify_change(upper_mnt_userns, upperdentry, attr, NULL); 153a15506eaSChristian Brauner } 154a15506eaSChristian Brauner 155576bb263SChristian Brauner static inline int ovl_do_rmdir(struct ovl_fs *ofs, 156576bb263SChristian Brauner struct inode *dir, struct dentry *dentry) 157e9be9d5eSMiklos Szeredi { 158c67cf654SChristian Brauner int err = vfs_rmdir(ovl_upper_mnt_userns(ofs), dir, dentry); 1596cf00764SAmir Goldstein 160e9be9d5eSMiklos Szeredi pr_debug("rmdir(%pd2) = %i\n", dentry, err); 161e9be9d5eSMiklos Szeredi return err; 162e9be9d5eSMiklos Szeredi } 163e9be9d5eSMiklos Szeredi 164576bb263SChristian Brauner static inline int ovl_do_unlink(struct ovl_fs *ofs, struct inode *dir, 165576bb263SChristian Brauner struct dentry *dentry) 166e9be9d5eSMiklos Szeredi { 167c67cf654SChristian Brauner int err = vfs_unlink(ovl_upper_mnt_userns(ofs), dir, dentry, NULL); 1686cf00764SAmir Goldstein 169e9be9d5eSMiklos Szeredi pr_debug("unlink(%pd2) = %i\n", dentry, err); 170e9be9d5eSMiklos Szeredi return err; 171e9be9d5eSMiklos Szeredi } 172e9be9d5eSMiklos Szeredi 173576bb263SChristian Brauner static inline int ovl_do_link(struct ovl_fs *ofs, struct dentry *old_dentry, 174576bb263SChristian Brauner struct inode *dir, struct dentry *new_dentry) 175e9be9d5eSMiklos Szeredi { 176c67cf654SChristian Brauner int err = vfs_link(old_dentry, ovl_upper_mnt_userns(ofs), dir, new_dentry, NULL); 1776cf00764SAmir Goldstein 1786cf00764SAmir Goldstein pr_debug("link(%pd2, %pd2) = %i\n", old_dentry, new_dentry, err); 179e9be9d5eSMiklos Szeredi return err; 180e9be9d5eSMiklos Szeredi } 181e9be9d5eSMiklos Szeredi 182576bb263SChristian Brauner static inline int ovl_do_create(struct ovl_fs *ofs, 183576bb263SChristian Brauner struct inode *dir, struct dentry *dentry, 1846cf00764SAmir Goldstein umode_t mode) 185e9be9d5eSMiklos Szeredi { 186c67cf654SChristian Brauner int err = vfs_create(ovl_upper_mnt_userns(ofs), dir, dentry, mode, true); 1876cf00764SAmir Goldstein 188e9be9d5eSMiklos Szeredi pr_debug("create(%pd2, 0%o) = %i\n", dentry, mode, err); 189e9be9d5eSMiklos Szeredi return err; 190e9be9d5eSMiklos Szeredi } 191e9be9d5eSMiklos Szeredi 192576bb263SChristian Brauner static inline int ovl_do_mkdir(struct ovl_fs *ofs, 193576bb263SChristian Brauner struct inode *dir, struct dentry *dentry, 1946cf00764SAmir Goldstein umode_t mode) 195e9be9d5eSMiklos Szeredi { 196c67cf654SChristian Brauner int err = vfs_mkdir(ovl_upper_mnt_userns(ofs), dir, dentry, mode); 197e9be9d5eSMiklos Szeredi pr_debug("mkdir(%pd2, 0%o) = %i\n", dentry, mode, err); 198e9be9d5eSMiklos Szeredi return err; 199e9be9d5eSMiklos Szeredi } 200e9be9d5eSMiklos Szeredi 201576bb263SChristian Brauner static inline int ovl_do_mknod(struct ovl_fs *ofs, 202576bb263SChristian Brauner struct inode *dir, struct dentry *dentry, 2036cf00764SAmir Goldstein umode_t mode, dev_t dev) 204e9be9d5eSMiklos Szeredi { 205c67cf654SChristian Brauner int err = vfs_mknod(ovl_upper_mnt_userns(ofs), dir, dentry, mode, dev); 2066cf00764SAmir Goldstein 2076cf00764SAmir Goldstein pr_debug("mknod(%pd2, 0%o, 0%o) = %i\n", dentry, mode, dev, err); 208e9be9d5eSMiklos Szeredi return err; 209e9be9d5eSMiklos Szeredi } 210e9be9d5eSMiklos Szeredi 211576bb263SChristian Brauner static inline int ovl_do_symlink(struct ovl_fs *ofs, 212576bb263SChristian Brauner struct inode *dir, struct dentry *dentry, 2136cf00764SAmir Goldstein const char *oldname) 214e9be9d5eSMiklos Szeredi { 215c67cf654SChristian Brauner int err = vfs_symlink(ovl_upper_mnt_userns(ofs), dir, dentry, oldname); 2166cf00764SAmir Goldstein 217e9be9d5eSMiklos Szeredi pr_debug("symlink(\"%s\", %pd2) = %i\n", oldname, dentry, err); 218e9be9d5eSMiklos Szeredi return err; 219e9be9d5eSMiklos Szeredi } 220e9be9d5eSMiklos Szeredi 221610afc0bSMiklos Szeredi static inline ssize_t ovl_do_getxattr(struct ovl_fs *ofs, struct dentry *dentry, 222c914c0e2SAmir Goldstein const char *name, void *value, 223610afc0bSMiklos Szeredi size_t size) 224d5dc7486SMiklos Szeredi { 2255e717c6fSAmir Goldstein int err = vfs_getxattr(&init_user_ns, dentry, name, value, size); 2265e717c6fSAmir Goldstein int len = (value && err > 0) ? err : 0; 2275e717c6fSAmir Goldstein 2285e717c6fSAmir Goldstein pr_debug("getxattr(%pd2, \"%s\", \"%*pE\", %zu, 0) = %i\n", 2295e717c6fSAmir Goldstein dentry, name, min(len, 48), value, size, err); 2305e717c6fSAmir Goldstein return err; 231d5dc7486SMiklos Szeredi } 232d5dc7486SMiklos Szeredi 233c914c0e2SAmir Goldstein static inline ssize_t ovl_getxattr(struct ovl_fs *ofs, struct dentry *dentry, 234c914c0e2SAmir Goldstein enum ovl_xattr ox, void *value, 235610afc0bSMiklos Szeredi size_t size) 236e9be9d5eSMiklos Szeredi { 237c914c0e2SAmir Goldstein return ovl_do_getxattr(ofs, dentry, ovl_xattr(ofs, ox), value, size); 238c914c0e2SAmir Goldstein } 239c914c0e2SAmir Goldstein 240c914c0e2SAmir Goldstein static inline int ovl_do_setxattr(struct ovl_fs *ofs, struct dentry *dentry, 241c914c0e2SAmir Goldstein const char *name, const void *value, 242c914c0e2SAmir Goldstein size_t size, int flags) 243c914c0e2SAmir Goldstein { 244c914c0e2SAmir Goldstein int err = vfs_setxattr(&init_user_ns, dentry, name, value, size, flags); 245c914c0e2SAmir Goldstein 246c914c0e2SAmir Goldstein pr_debug("setxattr(%pd2, \"%s\", \"%*pE\", %zu, %d) = %i\n", 247c914c0e2SAmir Goldstein dentry, name, min((int)size, 48), value, size, flags, err); 248e9be9d5eSMiklos Szeredi return err; 249e9be9d5eSMiklos Szeredi } 250e9be9d5eSMiklos Szeredi 251c914c0e2SAmir Goldstein static inline int ovl_setxattr(struct ovl_fs *ofs, struct dentry *dentry, 252c914c0e2SAmir Goldstein enum ovl_xattr ox, const void *value, 253c914c0e2SAmir Goldstein size_t size) 254e9be9d5eSMiklos Szeredi { 255c914c0e2SAmir Goldstein return ovl_do_setxattr(ofs, dentry, ovl_xattr(ofs, ox), value, size, 0); 256c914c0e2SAmir Goldstein } 257c914c0e2SAmir Goldstein 258c914c0e2SAmir Goldstein static inline int ovl_do_removexattr(struct ovl_fs *ofs, struct dentry *dentry, 259c914c0e2SAmir Goldstein const char *name) 260c914c0e2SAmir Goldstein { 261c7c7a1a1STycho Andersen int err = vfs_removexattr(&init_user_ns, dentry, name); 262e9be9d5eSMiklos Szeredi pr_debug("removexattr(%pd2, \"%s\") = %i\n", dentry, name, err); 263e9be9d5eSMiklos Szeredi return err; 264e9be9d5eSMiklos Szeredi } 265e9be9d5eSMiklos Szeredi 266c914c0e2SAmir Goldstein static inline int ovl_removexattr(struct ovl_fs *ofs, struct dentry *dentry, 267c914c0e2SAmir Goldstein enum ovl_xattr ox) 268c914c0e2SAmir Goldstein { 269c914c0e2SAmir Goldstein return ovl_do_removexattr(ofs, dentry, ovl_xattr(ofs, ox)); 270c914c0e2SAmir Goldstein } 271c914c0e2SAmir Goldstein 272576bb263SChristian Brauner static inline int ovl_do_rename(struct ovl_fs *ofs, struct inode *olddir, 273576bb263SChristian Brauner struct dentry *olddentry, struct inode *newdir, 274576bb263SChristian Brauner struct dentry *newdentry, unsigned int flags) 275e9be9d5eSMiklos Szeredi { 276e9be9d5eSMiklos Szeredi int err; 2779fe61450SChristian Brauner struct renamedata rd = { 278c67cf654SChristian Brauner .old_mnt_userns = ovl_upper_mnt_userns(ofs), 2799fe61450SChristian Brauner .old_dir = olddir, 2809fe61450SChristian Brauner .old_dentry = olddentry, 281c67cf654SChristian Brauner .new_mnt_userns = ovl_upper_mnt_userns(ofs), 2829fe61450SChristian Brauner .new_dir = newdir, 2839fe61450SChristian Brauner .new_dentry = newdentry, 2849fe61450SChristian Brauner .flags = flags, 2859fe61450SChristian Brauner }; 286e9be9d5eSMiklos Szeredi 2876cf00764SAmir Goldstein pr_debug("rename(%pd2, %pd2, 0x%x)\n", olddentry, newdentry, flags); 2889fe61450SChristian Brauner err = vfs_rename(&rd); 289e9be9d5eSMiklos Szeredi if (err) { 2902773bf00SMiklos Szeredi pr_debug("...rename(%pd2, %pd2, ...) = %i\n", 291e9be9d5eSMiklos Szeredi olddentry, newdentry, err); 292e9be9d5eSMiklos Szeredi } 293e9be9d5eSMiklos Szeredi return err; 294e9be9d5eSMiklos Szeredi } 295e9be9d5eSMiklos Szeredi 296576bb263SChristian Brauner static inline int ovl_do_whiteout(struct ovl_fs *ofs, 297576bb263SChristian Brauner struct inode *dir, struct dentry *dentry) 298e9be9d5eSMiklos Szeredi { 299c67cf654SChristian Brauner int err = vfs_whiteout(ovl_upper_mnt_userns(ofs), dir, dentry); 300e9be9d5eSMiklos Szeredi pr_debug("whiteout(%pd2) = %i\n", dentry, err); 301e9be9d5eSMiklos Szeredi return err; 302e9be9d5eSMiklos Szeredi } 303e9be9d5eSMiklos Szeredi 304576bb263SChristian Brauner static inline struct dentry *ovl_do_tmpfile(struct ovl_fs *ofs, 305576bb263SChristian Brauner struct dentry *dentry, umode_t mode) 306e7f52429SAmir Goldstein { 307c67cf654SChristian Brauner struct dentry *ret = vfs_tmpfile(ovl_upper_mnt_userns(ofs), dentry, mode, 0); 3087879cb43SVasyl Gomonovych int err = PTR_ERR_OR_ZERO(ret); 309e7f52429SAmir Goldstein 310e7f52429SAmir Goldstein pr_debug("tmpfile(%pd2, 0%o) = %i\n", dentry, mode, err); 311e7f52429SAmir Goldstein return ret; 312e7f52429SAmir Goldstein } 313e7f52429SAmir Goldstein 314*22f289ceSChristian Brauner static inline struct dentry *ovl_lookup_upper(struct ovl_fs *ofs, 315*22f289ceSChristian Brauner const char *name, 316*22f289ceSChristian Brauner struct dentry *base, int len) 317*22f289ceSChristian Brauner { 318*22f289ceSChristian Brauner return lookup_one(ovl_upper_mnt_userns(ofs), name, base, len); 319*22f289ceSChristian Brauner } 320*22f289ceSChristian Brauner 3210c288874SVivek Goyal static inline bool ovl_open_flags_need_copy_up(int flags) 3220c288874SVivek Goyal { 3230c288874SVivek Goyal if (!flags) 3240c288874SVivek Goyal return false; 3250c288874SVivek Goyal 3260c288874SVivek Goyal return ((OPEN_FMODE(flags) & FMODE_WRITE) || (flags & O_TRUNC)); 3270c288874SVivek Goyal } 3280c288874SVivek Goyal 329ca45275cSVyacheslav Yurkov static inline bool ovl_allow_offline_changes(struct ovl_fs *ofs) 330ca45275cSVyacheslav Yurkov { 331ca45275cSVyacheslav Yurkov /* 332ca45275cSVyacheslav Yurkov * To avoid regressions in existing setups with overlay lower offline 333ca45275cSVyacheslav Yurkov * changes, we allow lower changes only if none of the new features 334ca45275cSVyacheslav Yurkov * are used. 335ca45275cSVyacheslav Yurkov */ 336ca45275cSVyacheslav Yurkov return (!ofs->config.index && !ofs->config.metacopy && 337ca45275cSVyacheslav Yurkov !ofs->config.redirect_dir && ofs->config.xino != OVL_XINO_ON); 338ca45275cSVyacheslav Yurkov } 339ca45275cSVyacheslav Yurkov 340ca45275cSVyacheslav Yurkov 341bbb1e54dSMiklos Szeredi /* util.c */ 342bbb1e54dSMiklos Szeredi int ovl_want_write(struct dentry *dentry); 343bbb1e54dSMiklos Szeredi void ovl_drop_write(struct dentry *dentry); 344bbb1e54dSMiklos Szeredi struct dentry *ovl_workdir(struct dentry *dentry); 345bbb1e54dSMiklos Szeredi const struct cred *ovl_override_creds(struct super_block *sb); 346e487d889SAmir Goldstein int ovl_can_decode_fh(struct super_block *sb); 34702bcd157SAmir Goldstein struct dentry *ovl_indexdir(struct super_block *sb); 348f168f109SAmir Goldstein bool ovl_index_all(struct super_block *sb); 349f168f109SAmir Goldstein bool ovl_verify_lower(struct super_block *sb); 350bbb1e54dSMiklos Szeredi struct ovl_entry *ovl_alloc_entry(unsigned int numlower); 351bbb1e54dSMiklos Szeredi bool ovl_dentry_remote(struct dentry *dentry); 352f4288844SMiklos Szeredi void ovl_dentry_update_reval(struct dentry *dentry, struct dentry *upperdentry, 353f4288844SMiklos Szeredi unsigned int mask); 354bbb1e54dSMiklos Szeredi bool ovl_dentry_weird(struct dentry *dentry); 355e9be9d5eSMiklos Szeredi enum ovl_path_type ovl_path_type(struct dentry *dentry); 356e9be9d5eSMiklos Szeredi void ovl_path_upper(struct dentry *dentry, struct path *path); 357e9be9d5eSMiklos Szeredi void ovl_path_lower(struct dentry *dentry, struct path *path); 3584f93b426SVivek Goyal void ovl_path_lowerdata(struct dentry *dentry, struct path *path); 359e9be9d5eSMiklos Szeredi enum ovl_path_type ovl_path_real(struct dentry *dentry, struct path *path); 3601248ea4bSAmir Goldstein enum ovl_path_type ovl_path_realdata(struct dentry *dentry, struct path *path); 361e9be9d5eSMiklos Szeredi struct dentry *ovl_dentry_upper(struct dentry *dentry); 362e9be9d5eSMiklos Szeredi struct dentry *ovl_dentry_lower(struct dentry *dentry); 363647d253fSVivek Goyal struct dentry *ovl_dentry_lowerdata(struct dentry *dentry); 36413464165SMiklos Szeredi const struct ovl_layer *ovl_layer_lower(struct dentry *dentry); 365e9be9d5eSMiklos Szeredi struct dentry *ovl_dentry_real(struct dentry *dentry); 3661d88f183SMiklos Szeredi struct dentry *ovl_i_dentry_upper(struct inode *inode); 36709d8b586SMiklos Szeredi struct inode *ovl_inode_upper(struct inode *inode); 36809d8b586SMiklos Szeredi struct inode *ovl_inode_lower(struct inode *inode); 3692664bd08SVivek Goyal struct inode *ovl_inode_lowerdata(struct inode *inode); 37009d8b586SMiklos Szeredi struct inode *ovl_inode_real(struct inode *inode); 3714823d49cSVivek Goyal struct inode *ovl_inode_realdata(struct inode *inode); 3724edb83bbSMiklos Szeredi struct ovl_dir_cache *ovl_dir_cache(struct inode *inode); 3734edb83bbSMiklos Szeredi void ovl_set_dir_cache(struct inode *inode, struct ovl_dir_cache *cache); 374c62520a8SAmir Goldstein void ovl_dentry_set_flag(unsigned long flag, struct dentry *dentry); 375c62520a8SAmir Goldstein void ovl_dentry_clear_flag(unsigned long flag, struct dentry *dentry); 376c62520a8SAmir Goldstein bool ovl_dentry_test_flag(unsigned long flag, struct dentry *dentry); 377e9be9d5eSMiklos Szeredi bool ovl_dentry_is_opaque(struct dentry *dentry); 378c412ce49SMiklos Szeredi bool ovl_dentry_is_whiteout(struct dentry *dentry); 3795cf5b477SMiklos Szeredi void ovl_dentry_set_opaque(struct dentry *dentry); 38055acc661SMiklos Szeredi bool ovl_dentry_has_upper_alias(struct dentry *dentry); 38155acc661SMiklos Szeredi void ovl_dentry_set_upper_alias(struct dentry *dentry); 3820c288874SVivek Goyal bool ovl_dentry_needs_data_copy_up(struct dentry *dentry, int flags); 3830c288874SVivek Goyal bool ovl_dentry_needs_data_copy_up_locked(struct dentry *dentry, int flags); 3840c288874SVivek Goyal bool ovl_has_upperdata(struct inode *inode); 3850c288874SVivek Goyal void ovl_set_upperdata(struct inode *inode); 386a6c60655SMiklos Szeredi bool ovl_redirect_dir(struct super_block *sb); 387a6c60655SMiklos Szeredi const char *ovl_dentry_get_redirect(struct dentry *dentry); 388a6c60655SMiklos Szeredi void ovl_dentry_set_redirect(struct dentry *dentry, const char *redirect); 38909d8b586SMiklos Szeredi void ovl_inode_update(struct inode *inode, struct dentry *upperdentry); 390d9854c87SMiklos Szeredi void ovl_dir_modified(struct dentry *dentry, bool impurity); 391bbb1e54dSMiklos Szeredi u64 ovl_dentry_version_get(struct dentry *dentry); 392bbb1e54dSMiklos Szeredi bool ovl_is_whiteout(struct dentry *dentry); 393e9be9d5eSMiklos Szeredi struct file *ovl_path_open(struct path *path, int flags); 3940c288874SVivek Goyal int ovl_copy_up_start(struct dentry *dentry, int flags); 39539d3d60aSAmir Goldstein void ovl_copy_up_end(struct dentry *dentry); 3960c288874SVivek Goyal bool ovl_already_copied_up(struct dentry *dentry, int flags); 397610afc0bSMiklos Szeredi bool ovl_check_origin_xattr(struct ovl_fs *ofs, struct dentry *dentry); 398610afc0bSMiklos Szeredi bool ovl_check_dir_xattr(struct super_block *sb, struct dentry *dentry, 39943d193f8SMiklos Szeredi enum ovl_xattr ox); 400a0c236b1SAmir Goldstein int ovl_check_setxattr(struct ovl_fs *ofs, struct dentry *upperdentry, 40143d193f8SMiklos Szeredi enum ovl_xattr ox, const void *value, size_t size, 402f3a15685SAmir Goldstein int xerr); 403f3a15685SAmir Goldstein int ovl_set_impure(struct dentry *dentry, struct dentry *upperdentry); 404ad0af710SAmir Goldstein bool ovl_inuse_trylock(struct dentry *dentry); 405ad0af710SAmir Goldstein void ovl_inuse_unlock(struct dentry *dentry); 406146d62e5SAmir Goldstein bool ovl_is_inuse(struct dentry *dentry); 40724b33ee1SAmir Goldstein bool ovl_need_index(struct dentry *dentry); 4080e32992fSAmir Goldstein int ovl_nlink_start(struct dentry *dentry); 4090e32992fSAmir Goldstein void ovl_nlink_end(struct dentry *dentry); 4105820dc08SAmir Goldstein int ovl_lock_rename_workdir(struct dentry *workdir, struct dentry *upperdir); 411610afc0bSMiklos Szeredi int ovl_check_metacopy_xattr(struct ovl_fs *ofs, struct dentry *dentry); 41267d756c2SVivek Goyal bool ovl_is_metacopy_dentry(struct dentry *dentry); 413610afc0bSMiklos Szeredi char *ovl_get_redirect_xattr(struct ovl_fs *ofs, struct dentry *dentry, 414610afc0bSMiklos Szeredi int padding); 415335d3fc5SSargun Dhillon int ovl_sync_status(struct ovl_fs *ofs); 416f3a15685SAmir Goldstein 41765cd913eSAmir Goldstein static inline void ovl_set_flag(unsigned long flag, struct inode *inode) 41865cd913eSAmir Goldstein { 41965cd913eSAmir Goldstein set_bit(flag, &OVL_I(inode)->flags); 42065cd913eSAmir Goldstein } 42165cd913eSAmir Goldstein 42265cd913eSAmir Goldstein static inline void ovl_clear_flag(unsigned long flag, struct inode *inode) 42365cd913eSAmir Goldstein { 42465cd913eSAmir Goldstein clear_bit(flag, &OVL_I(inode)->flags); 42565cd913eSAmir Goldstein } 42665cd913eSAmir Goldstein 42765cd913eSAmir Goldstein static inline bool ovl_test_flag(unsigned long flag, struct inode *inode) 42865cd913eSAmir Goldstein { 42965cd913eSAmir Goldstein return test_bit(flag, &OVL_I(inode)->flags); 43065cd913eSAmir Goldstein } 43165cd913eSAmir Goldstein 432610afc0bSMiklos Szeredi static inline bool ovl_is_impuredir(struct super_block *sb, 433610afc0bSMiklos Szeredi struct dentry *dentry) 434f3a15685SAmir Goldstein { 435610afc0bSMiklos Szeredi return ovl_check_dir_xattr(sb, dentry, OVL_XATTR_IMPURE); 436f3a15685SAmir Goldstein } 437f3a15685SAmir Goldstein 438926e94d7SAmir Goldstein /* 439926e94d7SAmir Goldstein * With xino=auto, we do best effort to keep all inodes on same st_dev and 440926e94d7SAmir Goldstein * d_ino consistent with st_ino. 441926e94d7SAmir Goldstein * With xino=on, we do the same effort but we warn if we failed. 442926e94d7SAmir Goldstein */ 443926e94d7SAmir Goldstein static inline bool ovl_xino_warn(struct super_block *sb) 444926e94d7SAmir Goldstein { 445926e94d7SAmir Goldstein return OVL_FS(sb)->config.xino == OVL_XINO_ON; 446926e94d7SAmir Goldstein } 447926e94d7SAmir Goldstein 4480f831ec8SAmir Goldstein /* All layers on same fs? */ 4490f831ec8SAmir Goldstein static inline bool ovl_same_fs(struct super_block *sb) 4500f831ec8SAmir Goldstein { 4510f831ec8SAmir Goldstein return OVL_FS(sb)->xino_mode == 0; 4520f831ec8SAmir Goldstein } 4530f831ec8SAmir Goldstein 4540f831ec8SAmir Goldstein /* All overlay inodes have same st_dev? */ 4550f831ec8SAmir Goldstein static inline bool ovl_same_dev(struct super_block *sb) 4560f831ec8SAmir Goldstein { 4570f831ec8SAmir Goldstein return OVL_FS(sb)->xino_mode >= 0; 4580f831ec8SAmir Goldstein } 4590f831ec8SAmir Goldstein 460e487d889SAmir Goldstein static inline unsigned int ovl_xino_bits(struct super_block *sb) 461e487d889SAmir Goldstein { 4620f831ec8SAmir Goldstein return ovl_same_dev(sb) ? OVL_FS(sb)->xino_mode : 0; 463e487d889SAmir Goldstein } 464e487d889SAmir Goldstein 465531d3040SAmir Goldstein static inline void ovl_inode_lock(struct inode *inode) 466531d3040SAmir Goldstein { 467531d3040SAmir Goldstein mutex_lock(&OVL_I(inode)->lock); 468531d3040SAmir Goldstein } 469531d3040SAmir Goldstein 470531d3040SAmir Goldstein static inline int ovl_inode_lock_interruptible(struct inode *inode) 4711e92e307SAmir Goldstein { 4721e92e307SAmir Goldstein return mutex_lock_interruptible(&OVL_I(inode)->lock); 4731e92e307SAmir Goldstein } 4741e92e307SAmir Goldstein 4751e92e307SAmir Goldstein static inline void ovl_inode_unlock(struct inode *inode) 4761e92e307SAmir Goldstein { 4771e92e307SAmir Goldstein mutex_unlock(&OVL_I(inode)->lock); 4781e92e307SAmir Goldstein } 4791e92e307SAmir Goldstein 480e9be9d5eSMiklos Szeredi 481bbb1e54dSMiklos Szeredi /* namei.c */ 482cbe7fba8SAmir Goldstein int ovl_check_fb_len(struct ovl_fb *fb, int fb_len); 483cbe7fba8SAmir Goldstein 484cbe7fba8SAmir Goldstein static inline int ovl_check_fh_len(struct ovl_fh *fh, int fh_len) 485cbe7fba8SAmir Goldstein { 486522f6e6cSAmir Goldstein if (fh_len < sizeof(struct ovl_fh)) 487522f6e6cSAmir Goldstein return -EINVAL; 488522f6e6cSAmir Goldstein 489cbe7fba8SAmir Goldstein return ovl_check_fb_len(&fh->fb, fh_len - OVL_FH_WIRE_OFFSET); 490cbe7fba8SAmir Goldstein } 491cbe7fba8SAmir Goldstein 4921cdb0cb6SPavel Tikhomirov struct dentry *ovl_decode_real_fh(struct ovl_fs *ofs, struct ovl_fh *fh, 4931cdb0cb6SPavel Tikhomirov struct vfsmount *mnt, bool connected); 4948a22efa1SAmir Goldstein int ovl_check_origin_fh(struct ovl_fs *ofs, struct ovl_fh *fh, bool connected, 495f941866fSAmir Goldstein struct dentry *upperdentry, struct ovl_path **stackp); 496610afc0bSMiklos Szeredi int ovl_verify_set_fh(struct ovl_fs *ofs, struct dentry *dentry, 49743d193f8SMiklos Szeredi enum ovl_xattr ox, struct dentry *real, bool is_upper, 498610afc0bSMiklos Szeredi bool set); 4993b0bfc6eSAmir Goldstein struct dentry *ovl_index_upper(struct ovl_fs *ofs, struct dentry *index); 5001eff1a1dSAmir Goldstein int ovl_verify_index(struct ovl_fs *ofs, struct dentry *index); 5011cdb0cb6SPavel Tikhomirov int ovl_get_index_name(struct ovl_fs *ofs, struct dentry *origin, 5021cdb0cb6SPavel Tikhomirov struct qstr *name); 50391ffe7beSAmir Goldstein struct dentry *ovl_get_index_fh(struct ovl_fs *ofs, struct ovl_fh *fh); 50406170154SAmir Goldstein struct dentry *ovl_lookup_index(struct ovl_fs *ofs, struct dentry *upper, 50506170154SAmir Goldstein struct dentry *origin, bool verify); 506bbb1e54dSMiklos Szeredi int ovl_path_next(int idx, struct dentry *dentry, struct path *path); 5071eff1a1dSAmir Goldstein struct dentry *ovl_lookup(struct inode *dir, struct dentry *dentry, 5081eff1a1dSAmir Goldstein unsigned int flags); 509bbb1e54dSMiklos Szeredi bool ovl_lower_positive(struct dentry *dentry); 510e9be9d5eSMiklos Szeredi 511610afc0bSMiklos Szeredi static inline int ovl_verify_origin(struct ovl_fs *ofs, struct dentry *upper, 51205122443SAmir Goldstein struct dentry *origin, bool set) 51305122443SAmir Goldstein { 514610afc0bSMiklos Szeredi return ovl_verify_set_fh(ofs, upper, OVL_XATTR_ORIGIN, origin, 515610afc0bSMiklos Szeredi false, set); 51605122443SAmir Goldstein } 51705122443SAmir Goldstein 518610afc0bSMiklos Szeredi static inline int ovl_verify_upper(struct ovl_fs *ofs, struct dentry *index, 519ad1d615cSAmir Goldstein struct dentry *upper, bool set) 520ad1d615cSAmir Goldstein { 521610afc0bSMiklos Szeredi return ovl_verify_set_fh(ofs, index, OVL_XATTR_UPPER, upper, true, set); 522ad1d615cSAmir Goldstein } 523ad1d615cSAmir Goldstein 524e9be9d5eSMiklos Szeredi /* readdir.c */ 525e9be9d5eSMiklos Szeredi extern const struct file_operations ovl_dir_operations; 52661536bedSAmir Goldstein struct file *ovl_dir_real_file(const struct file *file, bool want_upper); 527e9be9d5eSMiklos Szeredi int ovl_check_empty_dir(struct dentry *dentry, struct list_head *list); 528576bb263SChristian Brauner void ovl_cleanup_whiteouts(struct ovl_fs *ofs, struct dentry *upper, 529576bb263SChristian Brauner struct list_head *list); 530e9be9d5eSMiklos Szeredi void ovl_cache_free(struct list_head *list); 5314edb83bbSMiklos Szeredi void ovl_dir_cache_free(struct inode *inode); 53245aebeafSVivek Goyal int ovl_check_d_type_supported(struct path *realpath); 533576bb263SChristian Brauner int ovl_workdir_cleanup(struct ovl_fs *ofs, struct inode *dir, 534576bb263SChristian Brauner struct vfsmount *mnt, struct dentry *dentry, int level); 5351eff1a1dSAmir Goldstein int ovl_indexdir_cleanup(struct ovl_fs *ofs); 536e9be9d5eSMiklos Szeredi 53765cd913eSAmir Goldstein /* 53865cd913eSAmir Goldstein * Can we iterate real dir directly? 53965cd913eSAmir Goldstein * 54065cd913eSAmir Goldstein * Non-merge dir may contain whiteouts from a time it was a merge upper, before 54165cd913eSAmir Goldstein * lower dir was removed under it and possibly before it was rotated from upper 54265cd913eSAmir Goldstein * to lower layer. 54365cd913eSAmir Goldstein */ 54465cd913eSAmir Goldstein static inline bool ovl_dir_is_real(struct dentry *dir) 54565cd913eSAmir Goldstein { 54665cd913eSAmir Goldstein return !ovl_test_flag(OVL_WHITEOUTS, d_inode(dir)); 54765cd913eSAmir Goldstein } 54865cd913eSAmir Goldstein 549e9be9d5eSMiklos Szeredi /* inode.c */ 5505f8415d6SAmir Goldstein int ovl_set_nlink_upper(struct dentry *dentry); 5515f8415d6SAmir Goldstein int ovl_set_nlink_lower(struct dentry *dentry); 552610afc0bSMiklos Szeredi unsigned int ovl_get_nlink(struct ovl_fs *ofs, struct dentry *lowerdentry, 553caf70cb2SAmir Goldstein struct dentry *upperdentry, 554caf70cb2SAmir Goldstein unsigned int fallback); 555549c7297SChristian Brauner int ovl_setattr(struct user_namespace *mnt_userns, struct dentry *dentry, 556549c7297SChristian Brauner struct iattr *attr); 557549c7297SChristian Brauner int ovl_getattr(struct user_namespace *mnt_userns, const struct path *path, 558549c7297SChristian Brauner struct kstat *stat, u32 request_mask, unsigned int flags); 559549c7297SChristian Brauner int ovl_permission(struct user_namespace *mnt_userns, struct inode *inode, 560549c7297SChristian Brauner int mask); 5611d88f183SMiklos Szeredi int ovl_xattr_set(struct dentry *dentry, struct inode *inode, const char *name, 5621d88f183SMiklos Szeredi const void *value, size_t size, int flags); 5631d88f183SMiklos Szeredi int ovl_xattr_get(struct dentry *dentry, struct inode *inode, const char *name, 5640eb45fc3SAndreas Gruenbacher void *value, size_t size); 565e9be9d5eSMiklos Szeredi ssize_t ovl_listxattr(struct dentry *dentry, char *list, size_t size); 5660cad6246SMiklos Szeredi struct posix_acl *ovl_get_acl(struct inode *inode, int type, bool rcu); 56795582b00SDeepa Dinamani int ovl_update_time(struct inode *inode, struct timespec64 *ts, int flags); 568610afc0bSMiklos Szeredi bool ovl_is_private_xattr(struct super_block *sb, const char *name); 569e9be9d5eSMiklos Szeredi 570ac6a52ebSVivek Goyal struct ovl_inode_params { 57101b39dccSAmir Goldstein struct inode *newinode; 572ac6a52ebSVivek Goyal struct dentry *upperdentry; 573ac6a52ebSVivek Goyal struct ovl_path *lowerpath; 57474c6e384SMiklos Szeredi bool index; 575ac6a52ebSVivek Goyal unsigned int numlower; 5769cec54c8SVivek Goyal char *redirect; 5772664bd08SVivek Goyal struct dentry *lowerdata; 578ac6a52ebSVivek Goyal }; 57962c832edSAmir Goldstein void ovl_inode_init(struct inode *inode, struct ovl_inode_params *oip, 58062c832edSAmir Goldstein unsigned long ino, int fsid); 581ca4c8a3aSMiklos Szeredi struct inode *ovl_new_inode(struct super_block *sb, umode_t mode, dev_t rdev); 5824b91c30aSAmir Goldstein struct inode *ovl_lookup_inode(struct super_block *sb, struct dentry *real, 5834b91c30aSAmir Goldstein bool is_upper); 584146d62e5SAmir Goldstein bool ovl_lookup_trap_inode(struct super_block *sb, struct dentry *dir); 585146d62e5SAmir Goldstein struct inode *ovl_get_trap_inode(struct super_block *sb, struct dentry *dir); 586ac6a52ebSVivek Goyal struct inode *ovl_get_inode(struct super_block *sb, 587ac6a52ebSVivek Goyal struct ovl_inode_params *oip); 588e9be9d5eSMiklos Szeredi static inline void ovl_copyattr(struct inode *from, struct inode *to) 589e9be9d5eSMiklos Szeredi { 590e9be9d5eSMiklos Szeredi to->i_uid = from->i_uid; 591e9be9d5eSMiklos Szeredi to->i_gid = from->i_gid; 59207a2daabSVivek Goyal to->i_mode = from->i_mode; 593d719e8f2SMiklos Szeredi to->i_atime = from->i_atime; 594d719e8f2SMiklos Szeredi to->i_mtime = from->i_mtime; 595d719e8f2SMiklos Szeredi to->i_ctime = from->i_ctime; 59646e5d0a3SMiklos Szeredi i_size_write(to, i_size_read(from)); 597e9be9d5eSMiklos Szeredi } 598e9be9d5eSMiklos Szeredi 59972db8211SAmir Goldstein /* vfs inode flags copied from real to ovl inode */ 60072db8211SAmir Goldstein #define OVL_COPY_I_FLAGS_MASK (S_SYNC | S_NOATIME | S_APPEND | S_IMMUTABLE) 601096a218aSAmir Goldstein /* vfs inode flags read from overlay.protattr xattr to ovl inode */ 602096a218aSAmir Goldstein #define OVL_PROT_I_FLAGS_MASK (S_APPEND | S_IMMUTABLE) 60372db8211SAmir Goldstein 60472db8211SAmir Goldstein /* 60572db8211SAmir Goldstein * fileattr flags copied from lower to upper inode on copy up. 606096a218aSAmir Goldstein * We cannot copy up immutable/append-only flags, because that would prevent 607096a218aSAmir Goldstein * linking temp inode to upper dir, so we store them in xattr instead. 60872db8211SAmir Goldstein */ 60972db8211SAmir Goldstein #define OVL_COPY_FS_FLAGS_MASK (FS_SYNC_FL | FS_NOATIME_FL) 61072db8211SAmir Goldstein #define OVL_COPY_FSX_FLAGS_MASK (FS_XFLAG_SYNC | FS_XFLAG_NOATIME) 611096a218aSAmir Goldstein #define OVL_PROT_FS_FLAGS_MASK (FS_APPEND_FL | FS_IMMUTABLE_FL) 612096a218aSAmir Goldstein #define OVL_PROT_FSX_FLAGS_MASK (FS_XFLAG_APPEND | FS_XFLAG_IMMUTABLE) 613096a218aSAmir Goldstein 614096a218aSAmir Goldstein void ovl_check_protattr(struct inode *inode, struct dentry *upper); 615096a218aSAmir Goldstein int ovl_set_protattr(struct inode *inode, struct dentry *upper, 616096a218aSAmir Goldstein struct fileattr *fa); 61772db8211SAmir Goldstein 6184f357295SMiklos Szeredi static inline void ovl_copyflags(struct inode *from, struct inode *to) 6194f357295SMiklos Szeredi { 62072db8211SAmir Goldstein unsigned int mask = OVL_COPY_I_FLAGS_MASK; 6214f357295SMiklos Szeredi 6224f357295SMiklos Szeredi inode_set_flags(to, from->i_flags & mask, mask); 6234f357295SMiklos Szeredi } 6244f357295SMiklos Szeredi 625e9be9d5eSMiklos Szeredi /* dir.c */ 626e9be9d5eSMiklos Szeredi extern const struct inode_operations ovl_dir_inode_operations; 627c21c839bSChengguang Xu int ovl_cleanup_and_whiteout(struct ovl_fs *ofs, struct inode *dir, 628e7dd0e71SAmir Goldstein struct dentry *dentry); 629471ec5dcSAmir Goldstein struct ovl_cattr { 63032a3d848SAl Viro dev_t rdev; 63132a3d848SAl Viro umode_t mode; 63232a3d848SAl Viro const char *link; 633471ec5dcSAmir Goldstein struct dentry *hardlink; 63432a3d848SAl Viro }; 635471ec5dcSAmir Goldstein 636471ec5dcSAmir Goldstein #define OVL_CATTR(m) (&(struct ovl_cattr) { .mode = (m) }) 637471ec5dcSAmir Goldstein 638576bb263SChristian Brauner int ovl_mkdir_real(struct ovl_fs *ofs, struct inode *dir, 639576bb263SChristian Brauner struct dentry **newdentry, umode_t mode); 640576bb263SChristian Brauner struct dentry *ovl_create_real(struct ovl_fs *ofs, 641576bb263SChristian Brauner struct inode *dir, struct dentry *newdentry, 642471ec5dcSAmir Goldstein struct ovl_cattr *attr); 643576bb263SChristian Brauner int ovl_cleanup(struct ovl_fs *ofs, struct inode *dir, struct dentry *dentry); 644576bb263SChristian Brauner struct dentry *ovl_lookup_temp(struct ovl_fs *ofs, struct dentry *workdir); 645576bb263SChristian Brauner struct dentry *ovl_create_temp(struct ovl_fs *ofs, struct dentry *workdir, 646576bb263SChristian Brauner struct ovl_cattr *attr); 647e9be9d5eSMiklos Szeredi 648d1d04ef8SMiklos Szeredi /* file.c */ 649d1d04ef8SMiklos Szeredi extern const struct file_operations ovl_file_operations; 6502406a307SJiufei Xue int __init ovl_aio_request_cache_init(void); 6512406a307SJiufei Xue void ovl_aio_request_cache_destroy(void); 65272db8211SAmir Goldstein int ovl_real_fileattr_get(struct path *realpath, struct fileattr *fa); 65372db8211SAmir Goldstein int ovl_real_fileattr_set(struct path *realpath, struct fileattr *fa); 65466dbfabfSMiklos Szeredi int ovl_fileattr_get(struct dentry *dentry, struct fileattr *fa); 65566dbfabfSMiklos Szeredi int ovl_fileattr_set(struct user_namespace *mnt_userns, 65666dbfabfSMiklos Szeredi struct dentry *dentry, struct fileattr *fa); 657d1d04ef8SMiklos Szeredi 658e9be9d5eSMiklos Szeredi /* copy_up.c */ 659e9be9d5eSMiklos Szeredi int ovl_copy_up(struct dentry *dentry); 660d1e6f6a9SVivek Goyal int ovl_copy_up_with_data(struct dentry *dentry); 6613428030dSAmir Goldstein int ovl_maybe_copy_up(struct dentry *dentry, int flags); 662610afc0bSMiklos Szeredi int ovl_copy_xattr(struct super_block *sb, struct dentry *old, 663610afc0bSMiklos Szeredi struct dentry *new); 6645272eaf3SChristian Brauner int ovl_set_attr(struct ovl_fs *ofs, struct dentry *upper, struct kstat *stat); 6651cdb0cb6SPavel Tikhomirov struct ovl_fh *ovl_encode_real_fh(struct ovl_fs *ofs, struct dentry *real, 6661cdb0cb6SPavel Tikhomirov bool is_upper); 667a0c236b1SAmir Goldstein int ovl_set_origin(struct ovl_fs *ofs, struct dentry *lower, 668a0c236b1SAmir Goldstein struct dentry *upper); 6698ed5eec9SAmir Goldstein 6708ed5eec9SAmir Goldstein /* export.c */ 6718ed5eec9SAmir Goldstein extern const struct export_operations ovl_export_operations; 672