1e9be9d5eSMiklos Szeredi /* 2e9be9d5eSMiklos Szeredi * 3e9be9d5eSMiklos Szeredi * Copyright (C) 2011 Novell Inc. 4e9be9d5eSMiklos Szeredi * 5e9be9d5eSMiklos Szeredi * This program is free software; you can redistribute it and/or modify it 6e9be9d5eSMiklos Szeredi * under the terms of the GNU General Public License version 2 as published by 7e9be9d5eSMiklos Szeredi * the Free Software Foundation. 8e9be9d5eSMiklos Szeredi */ 9e9be9d5eSMiklos Szeredi 10e9be9d5eSMiklos Szeredi #include <linux/kernel.h> 113a1e819bSAmir Goldstein #include <linux/uuid.h> 1246e5d0a3SMiklos Szeredi #include <linux/fs.h> 13ee023c30SAmir Goldstein #include "ovl_entry.h" 14e9be9d5eSMiklos Szeredi 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, 4113c72075SMiklos Szeredi }; 4213c72075SMiklos Szeredi 43c62520a8SAmir Goldstein enum ovl_entry_flag { 44c62520a8SAmir Goldstein OVL_E_UPPER_ALIAS, 45c62520a8SAmir Goldstein OVL_E_OPAQUE, 462ca3c148SAmir Goldstein OVL_E_CONNECTED, 47c62520a8SAmir Goldstein }; 48c62520a8SAmir Goldstein 493a1e819bSAmir Goldstein /* 503a1e819bSAmir Goldstein * The tuple (fh,uuid) is a universal unique identifier for a copy up origin, 513a1e819bSAmir Goldstein * where: 523a1e819bSAmir Goldstein * origin.fh - exported file handle of the lower file 533a1e819bSAmir Goldstein * origin.uuid - uuid of the lower filesystem 543a1e819bSAmir Goldstein */ 553a1e819bSAmir Goldstein #define OVL_FH_VERSION 0 563a1e819bSAmir Goldstein #define OVL_FH_MAGIC 0xfb 573a1e819bSAmir Goldstein 583a1e819bSAmir Goldstein /* CPU byte order required for fid decoding: */ 593a1e819bSAmir Goldstein #define OVL_FH_FLAG_BIG_ENDIAN (1 << 0) 603a1e819bSAmir Goldstein #define OVL_FH_FLAG_ANY_ENDIAN (1 << 1) 6154fb347eSAmir Goldstein /* Is the real inode encoded in fid an upper inode? */ 6254fb347eSAmir Goldstein #define OVL_FH_FLAG_PATH_UPPER (1 << 2) 633a1e819bSAmir Goldstein 64961af647SAmir Goldstein #define OVL_FH_FLAG_ALL (OVL_FH_FLAG_BIG_ENDIAN | OVL_FH_FLAG_ANY_ENDIAN | \ 65961af647SAmir Goldstein OVL_FH_FLAG_PATH_UPPER) 663a1e819bSAmir Goldstein 673a1e819bSAmir Goldstein #if defined(__LITTLE_ENDIAN) 683a1e819bSAmir Goldstein #define OVL_FH_FLAG_CPU_ENDIAN 0 693a1e819bSAmir Goldstein #elif defined(__BIG_ENDIAN) 703a1e819bSAmir Goldstein #define OVL_FH_FLAG_CPU_ENDIAN OVL_FH_FLAG_BIG_ENDIAN 713a1e819bSAmir Goldstein #else 723a1e819bSAmir Goldstein #error Endianness not defined 733a1e819bSAmir Goldstein #endif 743a1e819bSAmir Goldstein 758ed5eec9SAmir Goldstein /* The type returned by overlay exportfs ops when encoding an ovl_fh handle */ 768ed5eec9SAmir Goldstein #define OVL_FILEID 0xfb 778ed5eec9SAmir Goldstein 783a1e819bSAmir Goldstein /* On-disk and in-memeory format for redirect by file handle */ 793a1e819bSAmir Goldstein struct ovl_fh { 803a1e819bSAmir Goldstein u8 version; /* 0 */ 813a1e819bSAmir Goldstein u8 magic; /* 0xfb */ 823a1e819bSAmir Goldstein u8 len; /* size of this header + size of fid */ 833a1e819bSAmir Goldstein u8 flags; /* OVL_FH_FLAG_* */ 843a1e819bSAmir Goldstein u8 type; /* fid_type of fid */ 8501633fd2SChristoph Hellwig uuid_t uuid; /* uuid of filesystem */ 863a1e819bSAmir Goldstein u8 fid[0]; /* file identifier */ 873a1e819bSAmir Goldstein } __packed; 88e9be9d5eSMiklos Szeredi 89e9be9d5eSMiklos Szeredi static inline int ovl_do_rmdir(struct inode *dir, struct dentry *dentry) 90e9be9d5eSMiklos Szeredi { 91e9be9d5eSMiklos Szeredi int err = vfs_rmdir(dir, dentry); 926cf00764SAmir Goldstein 93e9be9d5eSMiklos Szeredi pr_debug("rmdir(%pd2) = %i\n", dentry, err); 94e9be9d5eSMiklos Szeredi return err; 95e9be9d5eSMiklos Szeredi } 96e9be9d5eSMiklos Szeredi 97e9be9d5eSMiklos Szeredi static inline int ovl_do_unlink(struct inode *dir, struct dentry *dentry) 98e9be9d5eSMiklos Szeredi { 99e9be9d5eSMiklos Szeredi int err = vfs_unlink(dir, dentry, NULL); 1006cf00764SAmir Goldstein 101e9be9d5eSMiklos Szeredi pr_debug("unlink(%pd2) = %i\n", dentry, err); 102e9be9d5eSMiklos Szeredi return err; 103e9be9d5eSMiklos Szeredi } 104e9be9d5eSMiklos Szeredi 105e9be9d5eSMiklos Szeredi static inline int ovl_do_link(struct dentry *old_dentry, struct inode *dir, 1066cf00764SAmir Goldstein struct dentry *new_dentry) 107e9be9d5eSMiklos Szeredi { 108e9be9d5eSMiklos Szeredi int err = vfs_link(old_dentry, dir, new_dentry, NULL); 1096cf00764SAmir Goldstein 1106cf00764SAmir Goldstein pr_debug("link(%pd2, %pd2) = %i\n", old_dentry, new_dentry, err); 111e9be9d5eSMiklos Szeredi return err; 112e9be9d5eSMiklos Szeredi } 113e9be9d5eSMiklos Szeredi 114e9be9d5eSMiklos Szeredi static inline int ovl_do_create(struct inode *dir, struct dentry *dentry, 1156cf00764SAmir Goldstein umode_t mode) 116e9be9d5eSMiklos Szeredi { 117e9be9d5eSMiklos Szeredi int err = vfs_create(dir, dentry, mode, true); 1186cf00764SAmir Goldstein 119e9be9d5eSMiklos Szeredi pr_debug("create(%pd2, 0%o) = %i\n", dentry, mode, err); 120e9be9d5eSMiklos Szeredi return err; 121e9be9d5eSMiklos Szeredi } 122e9be9d5eSMiklos Szeredi 123e9be9d5eSMiklos Szeredi static inline int ovl_do_mkdir(struct inode *dir, struct dentry *dentry, 1246cf00764SAmir Goldstein umode_t mode) 125e9be9d5eSMiklos Szeredi { 126e9be9d5eSMiklos Szeredi int err = vfs_mkdir(dir, dentry, mode); 127e9be9d5eSMiklos Szeredi pr_debug("mkdir(%pd2, 0%o) = %i\n", dentry, mode, err); 128e9be9d5eSMiklos Szeredi return err; 129e9be9d5eSMiklos Szeredi } 130e9be9d5eSMiklos Szeredi 131e9be9d5eSMiklos Szeredi static inline int ovl_do_mknod(struct inode *dir, struct dentry *dentry, 1326cf00764SAmir Goldstein umode_t mode, dev_t dev) 133e9be9d5eSMiklos Szeredi { 134e9be9d5eSMiklos Szeredi int err = vfs_mknod(dir, dentry, mode, dev); 1356cf00764SAmir Goldstein 1366cf00764SAmir Goldstein pr_debug("mknod(%pd2, 0%o, 0%o) = %i\n", dentry, mode, dev, err); 137e9be9d5eSMiklos Szeredi return err; 138e9be9d5eSMiklos Szeredi } 139e9be9d5eSMiklos Szeredi 140e9be9d5eSMiklos Szeredi static inline int ovl_do_symlink(struct inode *dir, struct dentry *dentry, 1416cf00764SAmir Goldstein const char *oldname) 142e9be9d5eSMiklos Szeredi { 143e9be9d5eSMiklos Szeredi int err = vfs_symlink(dir, dentry, oldname); 1446cf00764SAmir Goldstein 145e9be9d5eSMiklos Szeredi pr_debug("symlink(\"%s\", %pd2) = %i\n", oldname, dentry, err); 146e9be9d5eSMiklos Szeredi return err; 147e9be9d5eSMiklos Szeredi } 148e9be9d5eSMiklos Szeredi 149e9be9d5eSMiklos Szeredi static inline int ovl_do_setxattr(struct dentry *dentry, const char *name, 150e9be9d5eSMiklos Szeredi const void *value, size_t size, int flags) 151e9be9d5eSMiklos Szeredi { 152e9be9d5eSMiklos Szeredi int err = vfs_setxattr(dentry, name, value, size, flags); 153e9be9d5eSMiklos Szeredi pr_debug("setxattr(%pd2, \"%s\", \"%*s\", 0x%x) = %i\n", 154e9be9d5eSMiklos Szeredi dentry, name, (int) size, (char *) value, flags, err); 155e9be9d5eSMiklos Szeredi return err; 156e9be9d5eSMiklos Szeredi } 157e9be9d5eSMiklos Szeredi 158e9be9d5eSMiklos Szeredi static inline int ovl_do_removexattr(struct dentry *dentry, const char *name) 159e9be9d5eSMiklos Szeredi { 160e9be9d5eSMiklos Szeredi int err = vfs_removexattr(dentry, name); 161e9be9d5eSMiklos Szeredi pr_debug("removexattr(%pd2, \"%s\") = %i\n", dentry, name, err); 162e9be9d5eSMiklos Szeredi return err; 163e9be9d5eSMiklos Szeredi } 164e9be9d5eSMiklos Szeredi 165e9be9d5eSMiklos Szeredi static inline int ovl_do_rename(struct inode *olddir, struct dentry *olddentry, 166e9be9d5eSMiklos Szeredi struct inode *newdir, struct dentry *newdentry, 167e9be9d5eSMiklos Szeredi unsigned int flags) 168e9be9d5eSMiklos Szeredi { 169e9be9d5eSMiklos Szeredi int err; 170e9be9d5eSMiklos Szeredi 1716cf00764SAmir Goldstein pr_debug("rename(%pd2, %pd2, 0x%x)\n", olddentry, newdentry, flags); 172e9be9d5eSMiklos Szeredi err = vfs_rename(olddir, olddentry, newdir, newdentry, NULL, flags); 173e9be9d5eSMiklos Szeredi if (err) { 1742773bf00SMiklos Szeredi pr_debug("...rename(%pd2, %pd2, ...) = %i\n", 175e9be9d5eSMiklos Szeredi olddentry, newdentry, err); 176e9be9d5eSMiklos Szeredi } 177e9be9d5eSMiklos Szeredi return err; 178e9be9d5eSMiklos Szeredi } 179e9be9d5eSMiklos Szeredi 180e9be9d5eSMiklos Szeredi static inline int ovl_do_whiteout(struct inode *dir, struct dentry *dentry) 181e9be9d5eSMiklos Szeredi { 182e9be9d5eSMiklos Szeredi int err = vfs_whiteout(dir, dentry); 183e9be9d5eSMiklos Szeredi pr_debug("whiteout(%pd2) = %i\n", dentry, err); 184e9be9d5eSMiklos Szeredi return err; 185e9be9d5eSMiklos Szeredi } 186e9be9d5eSMiklos Szeredi 187e7f52429SAmir Goldstein static inline struct dentry *ovl_do_tmpfile(struct dentry *dentry, umode_t mode) 188e7f52429SAmir Goldstein { 189e7f52429SAmir Goldstein struct dentry *ret = vfs_tmpfile(dentry, mode, 0); 1907879cb43SVasyl Gomonovych int err = PTR_ERR_OR_ZERO(ret); 191e7f52429SAmir Goldstein 192e7f52429SAmir Goldstein pr_debug("tmpfile(%pd2, 0%o) = %i\n", dentry, mode, err); 193e7f52429SAmir Goldstein return ret; 194e7f52429SAmir Goldstein } 195e7f52429SAmir Goldstein 1960c288874SVivek Goyal static inline bool ovl_open_flags_need_copy_up(int flags) 1970c288874SVivek Goyal { 1980c288874SVivek Goyal if (!flags) 1990c288874SVivek Goyal return false; 2000c288874SVivek Goyal 2010c288874SVivek Goyal return ((OPEN_FMODE(flags) & FMODE_WRITE) || (flags & O_TRUNC)); 2020c288874SVivek Goyal } 2030c288874SVivek Goyal 204bbb1e54dSMiklos Szeredi /* util.c */ 205bbb1e54dSMiklos Szeredi int ovl_want_write(struct dentry *dentry); 206bbb1e54dSMiklos Szeredi void ovl_drop_write(struct dentry *dentry); 207bbb1e54dSMiklos Szeredi struct dentry *ovl_workdir(struct dentry *dentry); 208bbb1e54dSMiklos Szeredi const struct cred *ovl_override_creds(struct super_block *sb); 2097bcd74b9SAmir Goldstein struct super_block *ovl_same_sb(struct super_block *sb); 210e487d889SAmir Goldstein int ovl_can_decode_fh(struct super_block *sb); 21102bcd157SAmir Goldstein struct dentry *ovl_indexdir(struct super_block *sb); 212f168f109SAmir Goldstein bool ovl_index_all(struct super_block *sb); 213f168f109SAmir Goldstein bool ovl_verify_lower(struct super_block *sb); 214bbb1e54dSMiklos Szeredi struct ovl_entry *ovl_alloc_entry(unsigned int numlower); 215bbb1e54dSMiklos Szeredi bool ovl_dentry_remote(struct dentry *dentry); 216bbb1e54dSMiklos Szeredi bool ovl_dentry_weird(struct dentry *dentry); 217e9be9d5eSMiklos Szeredi enum ovl_path_type ovl_path_type(struct dentry *dentry); 218e9be9d5eSMiklos Szeredi void ovl_path_upper(struct dentry *dentry, struct path *path); 219e9be9d5eSMiklos Szeredi void ovl_path_lower(struct dentry *dentry, struct path *path); 2204f93b426SVivek Goyal void ovl_path_lowerdata(struct dentry *dentry, struct path *path); 221e9be9d5eSMiklos Szeredi enum ovl_path_type ovl_path_real(struct dentry *dentry, struct path *path); 222e9be9d5eSMiklos Szeredi struct dentry *ovl_dentry_upper(struct dentry *dentry); 223e9be9d5eSMiklos Szeredi struct dentry *ovl_dentry_lower(struct dentry *dentry); 224647d253fSVivek Goyal struct dentry *ovl_dentry_lowerdata(struct dentry *dentry); 225da309e8cSAmir Goldstein struct ovl_layer *ovl_layer_lower(struct dentry *dentry); 226e9be9d5eSMiklos Szeredi struct dentry *ovl_dentry_real(struct dentry *dentry); 2271d88f183SMiklos Szeredi struct dentry *ovl_i_dentry_upper(struct inode *inode); 22809d8b586SMiklos Szeredi struct inode *ovl_inode_upper(struct inode *inode); 22909d8b586SMiklos Szeredi struct inode *ovl_inode_lower(struct inode *inode); 23009d8b586SMiklos Szeredi struct inode *ovl_inode_real(struct inode *inode); 2314edb83bbSMiklos Szeredi struct ovl_dir_cache *ovl_dir_cache(struct inode *inode); 2324edb83bbSMiklos Szeredi void ovl_set_dir_cache(struct inode *inode, struct ovl_dir_cache *cache); 233c62520a8SAmir Goldstein void ovl_dentry_set_flag(unsigned long flag, struct dentry *dentry); 234c62520a8SAmir Goldstein void ovl_dentry_clear_flag(unsigned long flag, struct dentry *dentry); 235c62520a8SAmir Goldstein bool ovl_dentry_test_flag(unsigned long flag, struct dentry *dentry); 236e9be9d5eSMiklos Szeredi bool ovl_dentry_is_opaque(struct dentry *dentry); 237c412ce49SMiklos Szeredi bool ovl_dentry_is_whiteout(struct dentry *dentry); 2385cf5b477SMiklos Szeredi void ovl_dentry_set_opaque(struct dentry *dentry); 23955acc661SMiklos Szeredi bool ovl_dentry_has_upper_alias(struct dentry *dentry); 24055acc661SMiklos Szeredi void ovl_dentry_set_upper_alias(struct dentry *dentry); 2410c288874SVivek Goyal bool ovl_dentry_needs_data_copy_up(struct dentry *dentry, int flags); 2420c288874SVivek Goyal bool ovl_dentry_needs_data_copy_up_locked(struct dentry *dentry, int flags); 2430c288874SVivek Goyal bool ovl_has_upperdata(struct inode *inode); 2440c288874SVivek Goyal void ovl_set_upperdata(struct inode *inode); 245a6c60655SMiklos Szeredi bool ovl_redirect_dir(struct super_block *sb); 246a6c60655SMiklos Szeredi const char *ovl_dentry_get_redirect(struct dentry *dentry); 247a6c60655SMiklos Szeredi void ovl_dentry_set_redirect(struct dentry *dentry, const char *redirect); 24809d8b586SMiklos Szeredi void ovl_inode_init(struct inode *inode, struct dentry *upperdentry, 24909d8b586SMiklos Szeredi struct dentry *lowerdentry); 25009d8b586SMiklos Szeredi void ovl_inode_update(struct inode *inode, struct dentry *upperdentry); 251d9854c87SMiklos Szeredi void ovl_dir_modified(struct dentry *dentry, bool impurity); 252bbb1e54dSMiklos Szeredi u64 ovl_dentry_version_get(struct dentry *dentry); 253bbb1e54dSMiklos Szeredi bool ovl_is_whiteout(struct dentry *dentry); 254e9be9d5eSMiklos Szeredi struct file *ovl_path_open(struct path *path, int flags); 2550c288874SVivek Goyal int ovl_copy_up_start(struct dentry *dentry, int flags); 25639d3d60aSAmir Goldstein void ovl_copy_up_end(struct dentry *dentry); 2570c288874SVivek Goyal bool ovl_already_copied_up(struct dentry *dentry, int flags); 258b79e05aaSAmir Goldstein bool ovl_check_origin_xattr(struct dentry *dentry); 259f3a15685SAmir Goldstein bool ovl_check_dir_xattr(struct dentry *dentry, const char *name); 260f3a15685SAmir Goldstein int ovl_check_setxattr(struct dentry *dentry, struct dentry *upperdentry, 261f3a15685SAmir Goldstein const char *name, const void *value, size_t size, 262f3a15685SAmir Goldstein int xerr); 263f3a15685SAmir Goldstein int ovl_set_impure(struct dentry *dentry, struct dentry *upperdentry); 26413c72075SMiklos Szeredi void ovl_set_flag(unsigned long flag, struct inode *inode); 2654edb83bbSMiklos Szeredi void ovl_clear_flag(unsigned long flag, struct inode *inode); 26613c72075SMiklos Szeredi bool ovl_test_flag(unsigned long flag, struct inode *inode); 267ad0af710SAmir Goldstein bool ovl_inuse_trylock(struct dentry *dentry); 268ad0af710SAmir Goldstein void ovl_inuse_unlock(struct dentry *dentry); 26924b33ee1SAmir Goldstein bool ovl_need_index(struct dentry *dentry); 2705f8415d6SAmir Goldstein int ovl_nlink_start(struct dentry *dentry, bool *locked); 2715f8415d6SAmir Goldstein void ovl_nlink_end(struct dentry *dentry, bool locked); 2725820dc08SAmir Goldstein int ovl_lock_rename_workdir(struct dentry *workdir, struct dentry *upperdir); 2739d3dfea3SVivek Goyal int ovl_check_metacopy_xattr(struct dentry *dentry); 274*67d756c2SVivek Goyal bool ovl_is_metacopy_dentry(struct dentry *dentry); 275f3a15685SAmir Goldstein 276f3a15685SAmir Goldstein static inline bool ovl_is_impuredir(struct dentry *dentry) 277f3a15685SAmir Goldstein { 278f3a15685SAmir Goldstein return ovl_check_dir_xattr(dentry, OVL_XATTR_IMPURE); 279f3a15685SAmir Goldstein } 280f3a15685SAmir Goldstein 281e487d889SAmir Goldstein static inline unsigned int ovl_xino_bits(struct super_block *sb) 282e487d889SAmir Goldstein { 283e487d889SAmir Goldstein struct ovl_fs *ofs = sb->s_fs_info; 284e487d889SAmir Goldstein 285e487d889SAmir Goldstein return ofs->xino_bits; 286e487d889SAmir Goldstein } 287e487d889SAmir Goldstein 288e9be9d5eSMiklos Szeredi 289bbb1e54dSMiklos Szeredi /* namei.c */ 2908556a420SAmir Goldstein int ovl_check_fh_len(struct ovl_fh *fh, int fh_len); 2918a22efa1SAmir Goldstein struct dentry *ovl_decode_real_fh(struct ovl_fh *fh, struct vfsmount *mnt, 2928a22efa1SAmir Goldstein bool connected); 2938a22efa1SAmir Goldstein int ovl_check_origin_fh(struct ovl_fs *ofs, struct ovl_fh *fh, bool connected, 294f941866fSAmir Goldstein struct dentry *upperdentry, struct ovl_path **stackp); 29505122443SAmir Goldstein int ovl_verify_set_fh(struct dentry *dentry, const char *name, 29605122443SAmir Goldstein struct dentry *real, bool is_upper, bool set); 2973b0bfc6eSAmir Goldstein struct dentry *ovl_index_upper(struct ovl_fs *ofs, struct dentry *index); 2981eff1a1dSAmir Goldstein int ovl_verify_index(struct ovl_fs *ofs, struct dentry *index); 299359f392cSAmir Goldstein int ovl_get_index_name(struct dentry *origin, struct qstr *name); 30091ffe7beSAmir Goldstein struct dentry *ovl_get_index_fh(struct ovl_fs *ofs, struct ovl_fh *fh); 30106170154SAmir Goldstein struct dentry *ovl_lookup_index(struct ovl_fs *ofs, struct dentry *upper, 30206170154SAmir Goldstein struct dentry *origin, bool verify); 303bbb1e54dSMiklos Szeredi int ovl_path_next(int idx, struct dentry *dentry, struct path *path); 3041eff1a1dSAmir Goldstein struct dentry *ovl_lookup(struct inode *dir, struct dentry *dentry, 3051eff1a1dSAmir Goldstein unsigned int flags); 306bbb1e54dSMiklos Szeredi bool ovl_lower_positive(struct dentry *dentry); 307e9be9d5eSMiklos Szeredi 30805122443SAmir Goldstein static inline int ovl_verify_origin(struct dentry *upper, 30905122443SAmir Goldstein struct dentry *origin, bool set) 31005122443SAmir Goldstein { 31105122443SAmir Goldstein return ovl_verify_set_fh(upper, OVL_XATTR_ORIGIN, origin, false, set); 31205122443SAmir Goldstein } 31305122443SAmir Goldstein 314ad1d615cSAmir Goldstein static inline int ovl_verify_upper(struct dentry *index, 315ad1d615cSAmir Goldstein struct dentry *upper, bool set) 316ad1d615cSAmir Goldstein { 317ad1d615cSAmir Goldstein return ovl_verify_set_fh(index, OVL_XATTR_UPPER, upper, true, set); 318ad1d615cSAmir Goldstein } 319ad1d615cSAmir Goldstein 320e9be9d5eSMiklos Szeredi /* readdir.c */ 321e9be9d5eSMiklos Szeredi extern const struct file_operations ovl_dir_operations; 322e9be9d5eSMiklos Szeredi int ovl_check_empty_dir(struct dentry *dentry, struct list_head *list); 323e9be9d5eSMiklos Szeredi void ovl_cleanup_whiteouts(struct dentry *upper, struct list_head *list); 324e9be9d5eSMiklos Szeredi void ovl_cache_free(struct list_head *list); 3254edb83bbSMiklos Szeredi void ovl_dir_cache_free(struct inode *inode); 32645aebeafSVivek Goyal int ovl_check_d_type_supported(struct path *realpath); 327eea2fb48SMiklos Szeredi void ovl_workdir_cleanup(struct inode *dir, struct vfsmount *mnt, 328eea2fb48SMiklos Szeredi struct dentry *dentry, int level); 3291eff1a1dSAmir Goldstein int ovl_indexdir_cleanup(struct ovl_fs *ofs); 330e9be9d5eSMiklos Szeredi 331e9be9d5eSMiklos Szeredi /* inode.c */ 3325f8415d6SAmir Goldstein int ovl_set_nlink_upper(struct dentry *dentry); 3335f8415d6SAmir Goldstein int ovl_set_nlink_lower(struct dentry *dentry); 334caf70cb2SAmir Goldstein unsigned int ovl_get_nlink(struct dentry *lowerdentry, 335caf70cb2SAmir Goldstein struct dentry *upperdentry, 336caf70cb2SAmir Goldstein unsigned int fallback); 337e9be9d5eSMiklos Szeredi int ovl_setattr(struct dentry *dentry, struct iattr *attr); 3385b712091SMiklos Szeredi int ovl_getattr(const struct path *path, struct kstat *stat, 3395b712091SMiklos Szeredi u32 request_mask, unsigned int flags); 340e9be9d5eSMiklos Szeredi int ovl_permission(struct inode *inode, int mask); 3411d88f183SMiklos Szeredi int ovl_xattr_set(struct dentry *dentry, struct inode *inode, const char *name, 3421d88f183SMiklos Szeredi const void *value, size_t size, int flags); 3431d88f183SMiklos Szeredi int ovl_xattr_get(struct dentry *dentry, struct inode *inode, const char *name, 3440eb45fc3SAndreas Gruenbacher void *value, size_t size); 345e9be9d5eSMiklos Szeredi ssize_t ovl_listxattr(struct dentry *dentry, char *list, size_t size); 34639a25b2bSVivek Goyal struct posix_acl *ovl_get_acl(struct inode *inode, int type); 34795582b00SDeepa Dinamani int ovl_update_time(struct inode *inode, struct timespec64 *ts, int flags); 3480956254aSMiklos Szeredi bool ovl_is_private_xattr(const char *name); 349e9be9d5eSMiklos Szeredi 350ac6a52ebSVivek Goyal struct ovl_inode_params { 35101b39dccSAmir Goldstein struct inode *newinode; 352ac6a52ebSVivek Goyal struct dentry *upperdentry; 353ac6a52ebSVivek Goyal struct ovl_path *lowerpath; 354ac6a52ebSVivek Goyal struct dentry *index; 355ac6a52ebSVivek Goyal unsigned int numlower; 3569cec54c8SVivek Goyal char *redirect; 357ac6a52ebSVivek Goyal }; 358ca4c8a3aSMiklos Szeredi struct inode *ovl_new_inode(struct super_block *sb, umode_t mode, dev_t rdev); 3594b91c30aSAmir Goldstein struct inode *ovl_lookup_inode(struct super_block *sb, struct dentry *real, 3604b91c30aSAmir Goldstein bool is_upper); 361ac6a52ebSVivek Goyal struct inode *ovl_get_inode(struct super_block *sb, 362ac6a52ebSVivek Goyal struct ovl_inode_params *oip); 363e9be9d5eSMiklos Szeredi static inline void ovl_copyattr(struct inode *from, struct inode *to) 364e9be9d5eSMiklos Szeredi { 365e9be9d5eSMiklos Szeredi to->i_uid = from->i_uid; 366e9be9d5eSMiklos Szeredi to->i_gid = from->i_gid; 36707a2daabSVivek Goyal to->i_mode = from->i_mode; 368d719e8f2SMiklos Szeredi to->i_atime = from->i_atime; 369d719e8f2SMiklos Szeredi to->i_mtime = from->i_mtime; 370d719e8f2SMiklos Szeredi to->i_ctime = from->i_ctime; 37146e5d0a3SMiklos Szeredi i_size_write(to, i_size_read(from)); 372e9be9d5eSMiklos Szeredi } 373e9be9d5eSMiklos Szeredi 3744f357295SMiklos Szeredi static inline void ovl_copyflags(struct inode *from, struct inode *to) 3754f357295SMiklos Szeredi { 3764f357295SMiklos Szeredi unsigned int mask = S_SYNC | S_IMMUTABLE | S_APPEND | S_NOATIME; 3774f357295SMiklos Szeredi 3784f357295SMiklos Szeredi inode_set_flags(to, from->i_flags & mask, mask); 3794f357295SMiklos Szeredi } 3804f357295SMiklos Szeredi 381e9be9d5eSMiklos Szeredi /* dir.c */ 382e9be9d5eSMiklos Szeredi extern const struct inode_operations ovl_dir_inode_operations; 383e7dd0e71SAmir Goldstein int ovl_cleanup_and_whiteout(struct dentry *workdir, struct inode *dir, 384e7dd0e71SAmir Goldstein struct dentry *dentry); 385471ec5dcSAmir Goldstein struct ovl_cattr { 38632a3d848SAl Viro dev_t rdev; 38732a3d848SAl Viro umode_t mode; 38832a3d848SAl Viro const char *link; 389471ec5dcSAmir Goldstein struct dentry *hardlink; 39032a3d848SAl Viro }; 391471ec5dcSAmir Goldstein 392471ec5dcSAmir Goldstein #define OVL_CATTR(m) (&(struct ovl_cattr) { .mode = (m) }) 393471ec5dcSAmir Goldstein 39495a1c815SMiklos Szeredi struct dentry *ovl_create_real(struct inode *dir, struct dentry *newdentry, 395471ec5dcSAmir Goldstein struct ovl_cattr *attr); 396415543d5SAmir Goldstein int ovl_cleanup(struct inode *dir, struct dentry *dentry); 397137ec526SAmir Goldstein struct dentry *ovl_create_temp(struct dentry *workdir, struct ovl_cattr *attr); 398e9be9d5eSMiklos Szeredi 399d1d04ef8SMiklos Szeredi /* file.c */ 400d1d04ef8SMiklos Szeredi extern const struct file_operations ovl_file_operations; 401d1d04ef8SMiklos Szeredi 402e9be9d5eSMiklos Szeredi /* copy_up.c */ 403e9be9d5eSMiklos Szeredi int ovl_copy_up(struct dentry *dentry); 4049aba6521SAmir Goldstein int ovl_copy_up_flags(struct dentry *dentry, int flags); 405d6eac039SVivek Goyal int ovl_open_maybe_copy_up(struct dentry *dentry, unsigned int file_flags); 406e9be9d5eSMiklos Szeredi int ovl_copy_xattr(struct dentry *old, struct dentry *new); 407e9be9d5eSMiklos Szeredi int ovl_set_attr(struct dentry *upper, struct kstat *stat); 4085b2cccd3SAmir Goldstein struct ovl_fh *ovl_encode_real_fh(struct dentry *real, bool is_upper); 4099678e630SAmir Goldstein int ovl_set_origin(struct dentry *dentry, struct dentry *lower, 4109678e630SAmir Goldstein struct dentry *upper); 4118ed5eec9SAmir Goldstein 4128ed5eec9SAmir Goldstein /* export.c */ 4138ed5eec9SAmir Goldstein extern const struct export_operations ovl_export_operations; 414