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, 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 513a1e819bSAmir Goldstein /* 523a1e819bSAmir Goldstein * The tuple (fh,uuid) is a universal unique identifier for a copy up origin, 533a1e819bSAmir Goldstein * where: 543a1e819bSAmir Goldstein * origin.fh - exported file handle of the lower file 553a1e819bSAmir Goldstein * origin.uuid - uuid of the lower filesystem 563a1e819bSAmir Goldstein */ 573a1e819bSAmir Goldstein #define OVL_FH_VERSION 0 583a1e819bSAmir Goldstein #define OVL_FH_MAGIC 0xfb 593a1e819bSAmir Goldstein 603a1e819bSAmir Goldstein /* CPU byte order required for fid decoding: */ 613a1e819bSAmir Goldstein #define OVL_FH_FLAG_BIG_ENDIAN (1 << 0) 623a1e819bSAmir Goldstein #define OVL_FH_FLAG_ANY_ENDIAN (1 << 1) 6354fb347eSAmir Goldstein /* Is the real inode encoded in fid an upper inode? */ 6454fb347eSAmir Goldstein #define OVL_FH_FLAG_PATH_UPPER (1 << 2) 653a1e819bSAmir Goldstein 66961af647SAmir Goldstein #define OVL_FH_FLAG_ALL (OVL_FH_FLAG_BIG_ENDIAN | OVL_FH_FLAG_ANY_ENDIAN | \ 67961af647SAmir Goldstein OVL_FH_FLAG_PATH_UPPER) 683a1e819bSAmir Goldstein 693a1e819bSAmir Goldstein #if defined(__LITTLE_ENDIAN) 703a1e819bSAmir Goldstein #define OVL_FH_FLAG_CPU_ENDIAN 0 713a1e819bSAmir Goldstein #elif defined(__BIG_ENDIAN) 723a1e819bSAmir Goldstein #define OVL_FH_FLAG_CPU_ENDIAN OVL_FH_FLAG_BIG_ENDIAN 733a1e819bSAmir Goldstein #else 743a1e819bSAmir Goldstein #error Endianness not defined 753a1e819bSAmir Goldstein #endif 763a1e819bSAmir Goldstein 778ed5eec9SAmir Goldstein /* The type returned by overlay exportfs ops when encoding an ovl_fh handle */ 788ed5eec9SAmir Goldstein #define OVL_FILEID 0xfb 798ed5eec9SAmir Goldstein 803a1e819bSAmir Goldstein /* On-disk and in-memeory format for redirect by file handle */ 813a1e819bSAmir Goldstein struct ovl_fh { 823a1e819bSAmir Goldstein u8 version; /* 0 */ 833a1e819bSAmir Goldstein u8 magic; /* 0xfb */ 843a1e819bSAmir Goldstein u8 len; /* size of this header + size of fid */ 853a1e819bSAmir Goldstein u8 flags; /* OVL_FH_FLAG_* */ 863a1e819bSAmir Goldstein u8 type; /* fid_type of fid */ 8701633fd2SChristoph Hellwig uuid_t uuid; /* uuid of filesystem */ 883a1e819bSAmir Goldstein u8 fid[0]; /* file identifier */ 893a1e819bSAmir Goldstein } __packed; 90e9be9d5eSMiklos Szeredi 91e9be9d5eSMiklos Szeredi static inline int ovl_do_rmdir(struct inode *dir, struct dentry *dentry) 92e9be9d5eSMiklos Szeredi { 93e9be9d5eSMiklos Szeredi int err = vfs_rmdir(dir, dentry); 946cf00764SAmir Goldstein 95e9be9d5eSMiklos Szeredi pr_debug("rmdir(%pd2) = %i\n", dentry, err); 96e9be9d5eSMiklos Szeredi return err; 97e9be9d5eSMiklos Szeredi } 98e9be9d5eSMiklos Szeredi 99e9be9d5eSMiklos Szeredi static inline int ovl_do_unlink(struct inode *dir, struct dentry *dentry) 100e9be9d5eSMiklos Szeredi { 101e9be9d5eSMiklos Szeredi int err = vfs_unlink(dir, dentry, NULL); 1026cf00764SAmir Goldstein 103e9be9d5eSMiklos Szeredi pr_debug("unlink(%pd2) = %i\n", dentry, err); 104e9be9d5eSMiklos Szeredi return err; 105e9be9d5eSMiklos Szeredi } 106e9be9d5eSMiklos Szeredi 107e9be9d5eSMiklos Szeredi static inline int ovl_do_link(struct dentry *old_dentry, struct inode *dir, 1086cf00764SAmir Goldstein struct dentry *new_dentry) 109e9be9d5eSMiklos Szeredi { 110e9be9d5eSMiklos Szeredi int err = vfs_link(old_dentry, dir, new_dentry, NULL); 1116cf00764SAmir Goldstein 1126cf00764SAmir Goldstein pr_debug("link(%pd2, %pd2) = %i\n", old_dentry, new_dentry, err); 113e9be9d5eSMiklos Szeredi return err; 114e9be9d5eSMiklos Szeredi } 115e9be9d5eSMiklos Szeredi 116e9be9d5eSMiklos Szeredi static inline int ovl_do_create(struct inode *dir, struct dentry *dentry, 1176cf00764SAmir Goldstein umode_t mode) 118e9be9d5eSMiklos Szeredi { 119e9be9d5eSMiklos Szeredi int err = vfs_create(dir, dentry, mode, true); 1206cf00764SAmir Goldstein 121e9be9d5eSMiklos Szeredi pr_debug("create(%pd2, 0%o) = %i\n", dentry, mode, err); 122e9be9d5eSMiklos Szeredi return err; 123e9be9d5eSMiklos Szeredi } 124e9be9d5eSMiklos Szeredi 125e9be9d5eSMiklos Szeredi static inline int ovl_do_mkdir(struct inode *dir, struct dentry *dentry, 1266cf00764SAmir Goldstein umode_t mode) 127e9be9d5eSMiklos Szeredi { 128e9be9d5eSMiklos Szeredi int err = vfs_mkdir(dir, dentry, mode); 129e9be9d5eSMiklos Szeredi pr_debug("mkdir(%pd2, 0%o) = %i\n", dentry, mode, err); 130e9be9d5eSMiklos Szeredi return err; 131e9be9d5eSMiklos Szeredi } 132e9be9d5eSMiklos Szeredi 133e9be9d5eSMiklos Szeredi static inline int ovl_do_mknod(struct inode *dir, struct dentry *dentry, 1346cf00764SAmir Goldstein umode_t mode, dev_t dev) 135e9be9d5eSMiklos Szeredi { 136e9be9d5eSMiklos Szeredi int err = vfs_mknod(dir, dentry, mode, dev); 1376cf00764SAmir Goldstein 1386cf00764SAmir Goldstein pr_debug("mknod(%pd2, 0%o, 0%o) = %i\n", dentry, mode, dev, err); 139e9be9d5eSMiklos Szeredi return err; 140e9be9d5eSMiklos Szeredi } 141e9be9d5eSMiklos Szeredi 142e9be9d5eSMiklos Szeredi static inline int ovl_do_symlink(struct inode *dir, struct dentry *dentry, 1436cf00764SAmir Goldstein const char *oldname) 144e9be9d5eSMiklos Szeredi { 145e9be9d5eSMiklos Szeredi int err = vfs_symlink(dir, dentry, oldname); 1466cf00764SAmir Goldstein 147e9be9d5eSMiklos Szeredi pr_debug("symlink(\"%s\", %pd2) = %i\n", oldname, dentry, err); 148e9be9d5eSMiklos Szeredi return err; 149e9be9d5eSMiklos Szeredi } 150e9be9d5eSMiklos Szeredi 151e9be9d5eSMiklos Szeredi static inline int ovl_do_setxattr(struct dentry *dentry, const char *name, 152e9be9d5eSMiklos Szeredi const void *value, size_t size, int flags) 153e9be9d5eSMiklos Szeredi { 154e9be9d5eSMiklos Szeredi int err = vfs_setxattr(dentry, name, value, size, flags); 1551a8f8d2aSMiklos Szeredi pr_debug("setxattr(%pd2, \"%s\", \"%*pE\", %zu, 0x%x) = %i\n", 1561a8f8d2aSMiklos Szeredi dentry, name, min((int)size, 48), value, size, flags, err); 157e9be9d5eSMiklos Szeredi return err; 158e9be9d5eSMiklos Szeredi } 159e9be9d5eSMiklos Szeredi 160e9be9d5eSMiklos Szeredi static inline int ovl_do_removexattr(struct dentry *dentry, const char *name) 161e9be9d5eSMiklos Szeredi { 162e9be9d5eSMiklos Szeredi int err = vfs_removexattr(dentry, name); 163e9be9d5eSMiklos Szeredi pr_debug("removexattr(%pd2, \"%s\") = %i\n", dentry, name, err); 164e9be9d5eSMiklos Szeredi return err; 165e9be9d5eSMiklos Szeredi } 166e9be9d5eSMiklos Szeredi 167e9be9d5eSMiklos Szeredi static inline int ovl_do_rename(struct inode *olddir, struct dentry *olddentry, 168e9be9d5eSMiklos Szeredi struct inode *newdir, struct dentry *newdentry, 169e9be9d5eSMiklos Szeredi unsigned int flags) 170e9be9d5eSMiklos Szeredi { 171e9be9d5eSMiklos Szeredi int err; 172e9be9d5eSMiklos Szeredi 1736cf00764SAmir Goldstein pr_debug("rename(%pd2, %pd2, 0x%x)\n", olddentry, newdentry, flags); 174e9be9d5eSMiklos Szeredi err = vfs_rename(olddir, olddentry, newdir, newdentry, NULL, flags); 175e9be9d5eSMiklos Szeredi if (err) { 1762773bf00SMiklos Szeredi pr_debug("...rename(%pd2, %pd2, ...) = %i\n", 177e9be9d5eSMiklos Szeredi olddentry, newdentry, err); 178e9be9d5eSMiklos Szeredi } 179e9be9d5eSMiklos Szeredi return err; 180e9be9d5eSMiklos Szeredi } 181e9be9d5eSMiklos Szeredi 182e9be9d5eSMiklos Szeredi static inline int ovl_do_whiteout(struct inode *dir, struct dentry *dentry) 183e9be9d5eSMiklos Szeredi { 184e9be9d5eSMiklos Szeredi int err = vfs_whiteout(dir, dentry); 185e9be9d5eSMiklos Szeredi pr_debug("whiteout(%pd2) = %i\n", dentry, err); 186e9be9d5eSMiklos Szeredi return err; 187e9be9d5eSMiklos Szeredi } 188e9be9d5eSMiklos Szeredi 189e7f52429SAmir Goldstein static inline struct dentry *ovl_do_tmpfile(struct dentry *dentry, umode_t mode) 190e7f52429SAmir Goldstein { 191e7f52429SAmir Goldstein struct dentry *ret = vfs_tmpfile(dentry, mode, 0); 1927879cb43SVasyl Gomonovych int err = PTR_ERR_OR_ZERO(ret); 193e7f52429SAmir Goldstein 194e7f52429SAmir Goldstein pr_debug("tmpfile(%pd2, 0%o) = %i\n", dentry, mode, err); 195e7f52429SAmir Goldstein return ret; 196e7f52429SAmir Goldstein } 197e7f52429SAmir Goldstein 1980c288874SVivek Goyal static inline bool ovl_open_flags_need_copy_up(int flags) 1990c288874SVivek Goyal { 2000c288874SVivek Goyal if (!flags) 2010c288874SVivek Goyal return false; 2020c288874SVivek Goyal 2030c288874SVivek Goyal return ((OPEN_FMODE(flags) & FMODE_WRITE) || (flags & O_TRUNC)); 2040c288874SVivek Goyal } 2050c288874SVivek Goyal 206bbb1e54dSMiklos Szeredi /* util.c */ 207bbb1e54dSMiklos Szeredi int ovl_want_write(struct dentry *dentry); 208bbb1e54dSMiklos Szeredi void ovl_drop_write(struct dentry *dentry); 209bbb1e54dSMiklos Szeredi struct dentry *ovl_workdir(struct dentry *dentry); 210bbb1e54dSMiklos Szeredi const struct cred *ovl_override_creds(struct super_block *sb); 2117bcd74b9SAmir Goldstein struct super_block *ovl_same_sb(struct super_block *sb); 212e487d889SAmir Goldstein int ovl_can_decode_fh(struct super_block *sb); 21302bcd157SAmir Goldstein struct dentry *ovl_indexdir(struct super_block *sb); 214f168f109SAmir Goldstein bool ovl_index_all(struct super_block *sb); 215f168f109SAmir Goldstein bool ovl_verify_lower(struct super_block *sb); 216bbb1e54dSMiklos Szeredi struct ovl_entry *ovl_alloc_entry(unsigned int numlower); 217bbb1e54dSMiklos Szeredi bool ovl_dentry_remote(struct dentry *dentry); 218bbb1e54dSMiklos Szeredi bool ovl_dentry_weird(struct dentry *dentry); 219e9be9d5eSMiklos Szeredi enum ovl_path_type ovl_path_type(struct dentry *dentry); 220e9be9d5eSMiklos Szeredi void ovl_path_upper(struct dentry *dentry, struct path *path); 221e9be9d5eSMiklos Szeredi void ovl_path_lower(struct dentry *dentry, struct path *path); 2224f93b426SVivek Goyal void ovl_path_lowerdata(struct dentry *dentry, struct path *path); 223e9be9d5eSMiklos Szeredi enum ovl_path_type ovl_path_real(struct dentry *dentry, struct path *path); 224e9be9d5eSMiklos Szeredi struct dentry *ovl_dentry_upper(struct dentry *dentry); 225e9be9d5eSMiklos Szeredi struct dentry *ovl_dentry_lower(struct dentry *dentry); 226647d253fSVivek Goyal struct dentry *ovl_dentry_lowerdata(struct dentry *dentry); 227da309e8cSAmir Goldstein struct ovl_layer *ovl_layer_lower(struct dentry *dentry); 228e9be9d5eSMiklos Szeredi struct dentry *ovl_dentry_real(struct dentry *dentry); 2291d88f183SMiklos Szeredi struct dentry *ovl_i_dentry_upper(struct inode *inode); 23009d8b586SMiklos Szeredi struct inode *ovl_inode_upper(struct inode *inode); 23109d8b586SMiklos Szeredi struct inode *ovl_inode_lower(struct inode *inode); 2322664bd08SVivek Goyal struct inode *ovl_inode_lowerdata(struct inode *inode); 23309d8b586SMiklos Szeredi struct inode *ovl_inode_real(struct inode *inode); 2344823d49cSVivek Goyal struct inode *ovl_inode_realdata(struct inode *inode); 2354edb83bbSMiklos Szeredi struct ovl_dir_cache *ovl_dir_cache(struct inode *inode); 2364edb83bbSMiklos Szeredi void ovl_set_dir_cache(struct inode *inode, struct ovl_dir_cache *cache); 237c62520a8SAmir Goldstein void ovl_dentry_set_flag(unsigned long flag, struct dentry *dentry); 238c62520a8SAmir Goldstein void ovl_dentry_clear_flag(unsigned long flag, struct dentry *dentry); 239c62520a8SAmir Goldstein bool ovl_dentry_test_flag(unsigned long flag, struct dentry *dentry); 240e9be9d5eSMiklos Szeredi bool ovl_dentry_is_opaque(struct dentry *dentry); 241c412ce49SMiklos Szeredi bool ovl_dentry_is_whiteout(struct dentry *dentry); 2425cf5b477SMiklos Szeredi void ovl_dentry_set_opaque(struct dentry *dentry); 24355acc661SMiklos Szeredi bool ovl_dentry_has_upper_alias(struct dentry *dentry); 24455acc661SMiklos Szeredi void ovl_dentry_set_upper_alias(struct dentry *dentry); 2450c288874SVivek Goyal bool ovl_dentry_needs_data_copy_up(struct dentry *dentry, int flags); 2460c288874SVivek Goyal bool ovl_dentry_needs_data_copy_up_locked(struct dentry *dentry, int flags); 2470c288874SVivek Goyal bool ovl_has_upperdata(struct inode *inode); 2480c288874SVivek Goyal void ovl_set_upperdata(struct inode *inode); 249a6c60655SMiklos Szeredi bool ovl_redirect_dir(struct super_block *sb); 250a6c60655SMiklos Szeredi const char *ovl_dentry_get_redirect(struct dentry *dentry); 251a6c60655SMiklos Szeredi void ovl_dentry_set_redirect(struct dentry *dentry, const char *redirect); 25209d8b586SMiklos Szeredi void ovl_inode_init(struct inode *inode, struct dentry *upperdentry, 2532664bd08SVivek Goyal struct dentry *lowerdentry, struct dentry *lowerdata); 25409d8b586SMiklos Szeredi void ovl_inode_update(struct inode *inode, struct dentry *upperdentry); 255d9854c87SMiklos Szeredi void ovl_dir_modified(struct dentry *dentry, bool impurity); 256bbb1e54dSMiklos Szeredi u64 ovl_dentry_version_get(struct dentry *dentry); 257bbb1e54dSMiklos Szeredi bool ovl_is_whiteout(struct dentry *dentry); 258e9be9d5eSMiklos Szeredi struct file *ovl_path_open(struct path *path, int flags); 2590c288874SVivek Goyal int ovl_copy_up_start(struct dentry *dentry, int flags); 26039d3d60aSAmir Goldstein void ovl_copy_up_end(struct dentry *dentry); 2610c288874SVivek Goyal bool ovl_already_copied_up(struct dentry *dentry, int flags); 262b79e05aaSAmir Goldstein bool ovl_check_origin_xattr(struct dentry *dentry); 263f3a15685SAmir Goldstein bool ovl_check_dir_xattr(struct dentry *dentry, const char *name); 264f3a15685SAmir Goldstein int ovl_check_setxattr(struct dentry *dentry, struct dentry *upperdentry, 265f3a15685SAmir Goldstein const char *name, const void *value, size_t size, 266f3a15685SAmir Goldstein int xerr); 267f3a15685SAmir Goldstein int ovl_set_impure(struct dentry *dentry, struct dentry *upperdentry); 26813c72075SMiklos Szeredi void ovl_set_flag(unsigned long flag, struct inode *inode); 2694edb83bbSMiklos Szeredi void ovl_clear_flag(unsigned long flag, struct inode *inode); 27013c72075SMiklos Szeredi bool ovl_test_flag(unsigned long flag, struct inode *inode); 271ad0af710SAmir Goldstein bool ovl_inuse_trylock(struct dentry *dentry); 272ad0af710SAmir Goldstein void ovl_inuse_unlock(struct dentry *dentry); 273*146d62e5SAmir Goldstein bool ovl_is_inuse(struct dentry *dentry); 27424b33ee1SAmir Goldstein bool ovl_need_index(struct dentry *dentry); 2750e32992fSAmir Goldstein int ovl_nlink_start(struct dentry *dentry); 2760e32992fSAmir Goldstein void ovl_nlink_end(struct dentry *dentry); 2775820dc08SAmir Goldstein int ovl_lock_rename_workdir(struct dentry *workdir, struct dentry *upperdir); 2789d3dfea3SVivek Goyal int ovl_check_metacopy_xattr(struct dentry *dentry); 27967d756c2SVivek Goyal bool ovl_is_metacopy_dentry(struct dentry *dentry); 2800a2d0d3fSVivek Goyal char *ovl_get_redirect_xattr(struct dentry *dentry, int padding); 281993a0b2aSVivek Goyal ssize_t ovl_getxattr(struct dentry *dentry, char *name, char **value, 282993a0b2aSVivek Goyal size_t padding); 283f3a15685SAmir Goldstein 284f3a15685SAmir Goldstein static inline bool ovl_is_impuredir(struct dentry *dentry) 285f3a15685SAmir Goldstein { 286f3a15685SAmir Goldstein return ovl_check_dir_xattr(dentry, OVL_XATTR_IMPURE); 287f3a15685SAmir Goldstein } 288f3a15685SAmir Goldstein 289e487d889SAmir Goldstein static inline unsigned int ovl_xino_bits(struct super_block *sb) 290e487d889SAmir Goldstein { 291e487d889SAmir Goldstein struct ovl_fs *ofs = sb->s_fs_info; 292e487d889SAmir Goldstein 293e487d889SAmir Goldstein return ofs->xino_bits; 294e487d889SAmir Goldstein } 295e487d889SAmir Goldstein 2961e92e307SAmir Goldstein static inline int ovl_inode_lock(struct inode *inode) 2971e92e307SAmir Goldstein { 2981e92e307SAmir Goldstein return mutex_lock_interruptible(&OVL_I(inode)->lock); 2991e92e307SAmir Goldstein } 3001e92e307SAmir Goldstein 3011e92e307SAmir Goldstein static inline void ovl_inode_unlock(struct inode *inode) 3021e92e307SAmir Goldstein { 3031e92e307SAmir Goldstein mutex_unlock(&OVL_I(inode)->lock); 3041e92e307SAmir Goldstein } 3051e92e307SAmir Goldstein 306e9be9d5eSMiklos Szeredi 307bbb1e54dSMiklos Szeredi /* namei.c */ 3088556a420SAmir Goldstein int ovl_check_fh_len(struct ovl_fh *fh, int fh_len); 3098a22efa1SAmir Goldstein struct dentry *ovl_decode_real_fh(struct ovl_fh *fh, struct vfsmount *mnt, 3108a22efa1SAmir Goldstein bool connected); 3118a22efa1SAmir Goldstein int ovl_check_origin_fh(struct ovl_fs *ofs, struct ovl_fh *fh, bool connected, 312f941866fSAmir Goldstein struct dentry *upperdentry, struct ovl_path **stackp); 31305122443SAmir Goldstein int ovl_verify_set_fh(struct dentry *dentry, const char *name, 31405122443SAmir Goldstein struct dentry *real, bool is_upper, bool set); 3153b0bfc6eSAmir Goldstein struct dentry *ovl_index_upper(struct ovl_fs *ofs, struct dentry *index); 3161eff1a1dSAmir Goldstein int ovl_verify_index(struct ovl_fs *ofs, struct dentry *index); 317359f392cSAmir Goldstein int ovl_get_index_name(struct dentry *origin, struct qstr *name); 31891ffe7beSAmir Goldstein struct dentry *ovl_get_index_fh(struct ovl_fs *ofs, struct ovl_fh *fh); 31906170154SAmir Goldstein struct dentry *ovl_lookup_index(struct ovl_fs *ofs, struct dentry *upper, 32006170154SAmir Goldstein struct dentry *origin, bool verify); 321bbb1e54dSMiklos Szeredi int ovl_path_next(int idx, struct dentry *dentry, struct path *path); 3221eff1a1dSAmir Goldstein struct dentry *ovl_lookup(struct inode *dir, struct dentry *dentry, 3231eff1a1dSAmir Goldstein unsigned int flags); 324bbb1e54dSMiklos Szeredi bool ovl_lower_positive(struct dentry *dentry); 325e9be9d5eSMiklos Szeredi 32605122443SAmir Goldstein static inline int ovl_verify_origin(struct dentry *upper, 32705122443SAmir Goldstein struct dentry *origin, bool set) 32805122443SAmir Goldstein { 32905122443SAmir Goldstein return ovl_verify_set_fh(upper, OVL_XATTR_ORIGIN, origin, false, set); 33005122443SAmir Goldstein } 33105122443SAmir Goldstein 332ad1d615cSAmir Goldstein static inline int ovl_verify_upper(struct dentry *index, 333ad1d615cSAmir Goldstein struct dentry *upper, bool set) 334ad1d615cSAmir Goldstein { 335ad1d615cSAmir Goldstein return ovl_verify_set_fh(index, OVL_XATTR_UPPER, upper, true, set); 336ad1d615cSAmir Goldstein } 337ad1d615cSAmir Goldstein 338e9be9d5eSMiklos Szeredi /* readdir.c */ 339e9be9d5eSMiklos Szeredi extern const struct file_operations ovl_dir_operations; 340e9be9d5eSMiklos Szeredi int ovl_check_empty_dir(struct dentry *dentry, struct list_head *list); 341e9be9d5eSMiklos Szeredi void ovl_cleanup_whiteouts(struct dentry *upper, struct list_head *list); 342e9be9d5eSMiklos Szeredi void ovl_cache_free(struct list_head *list); 3434edb83bbSMiklos Szeredi void ovl_dir_cache_free(struct inode *inode); 34445aebeafSVivek Goyal int ovl_check_d_type_supported(struct path *realpath); 345eea2fb48SMiklos Szeredi void ovl_workdir_cleanup(struct inode *dir, struct vfsmount *mnt, 346eea2fb48SMiklos Szeredi struct dentry *dentry, int level); 3471eff1a1dSAmir Goldstein int ovl_indexdir_cleanup(struct ovl_fs *ofs); 348e9be9d5eSMiklos Szeredi 349e9be9d5eSMiklos Szeredi /* inode.c */ 3505f8415d6SAmir Goldstein int ovl_set_nlink_upper(struct dentry *dentry); 3515f8415d6SAmir Goldstein int ovl_set_nlink_lower(struct dentry *dentry); 352caf70cb2SAmir Goldstein unsigned int ovl_get_nlink(struct dentry *lowerdentry, 353caf70cb2SAmir Goldstein struct dentry *upperdentry, 354caf70cb2SAmir Goldstein unsigned int fallback); 355e9be9d5eSMiklos Szeredi int ovl_setattr(struct dentry *dentry, struct iattr *attr); 3565b712091SMiklos Szeredi int ovl_getattr(const struct path *path, struct kstat *stat, 3575b712091SMiklos Szeredi u32 request_mask, unsigned int flags); 358e9be9d5eSMiklos Szeredi int ovl_permission(struct inode *inode, int mask); 3591d88f183SMiklos Szeredi int ovl_xattr_set(struct dentry *dentry, struct inode *inode, const char *name, 3601d88f183SMiklos Szeredi const void *value, size_t size, int flags); 3611d88f183SMiklos Szeredi int ovl_xattr_get(struct dentry *dentry, struct inode *inode, const char *name, 3620eb45fc3SAndreas Gruenbacher void *value, size_t size); 363e9be9d5eSMiklos Szeredi ssize_t ovl_listxattr(struct dentry *dentry, char *list, size_t size); 36439a25b2bSVivek Goyal struct posix_acl *ovl_get_acl(struct inode *inode, int type); 36595582b00SDeepa Dinamani int ovl_update_time(struct inode *inode, struct timespec64 *ts, int flags); 3660956254aSMiklos Szeredi bool ovl_is_private_xattr(const char *name); 367e9be9d5eSMiklos Szeredi 368ac6a52ebSVivek Goyal struct ovl_inode_params { 36901b39dccSAmir Goldstein struct inode *newinode; 370ac6a52ebSVivek Goyal struct dentry *upperdentry; 371ac6a52ebSVivek Goyal struct ovl_path *lowerpath; 372ac6a52ebSVivek Goyal struct dentry *index; 373ac6a52ebSVivek Goyal unsigned int numlower; 3749cec54c8SVivek Goyal char *redirect; 3752664bd08SVivek Goyal struct dentry *lowerdata; 376ac6a52ebSVivek Goyal }; 377ca4c8a3aSMiklos Szeredi struct inode *ovl_new_inode(struct super_block *sb, umode_t mode, dev_t rdev); 3784b91c30aSAmir Goldstein struct inode *ovl_lookup_inode(struct super_block *sb, struct dentry *real, 3794b91c30aSAmir Goldstein bool is_upper); 380*146d62e5SAmir Goldstein bool ovl_lookup_trap_inode(struct super_block *sb, struct dentry *dir); 381*146d62e5SAmir Goldstein struct inode *ovl_get_trap_inode(struct super_block *sb, struct dentry *dir); 382ac6a52ebSVivek Goyal struct inode *ovl_get_inode(struct super_block *sb, 383ac6a52ebSVivek Goyal struct ovl_inode_params *oip); 384e9be9d5eSMiklos Szeredi static inline void ovl_copyattr(struct inode *from, struct inode *to) 385e9be9d5eSMiklos Szeredi { 386e9be9d5eSMiklos Szeredi to->i_uid = from->i_uid; 387e9be9d5eSMiklos Szeredi to->i_gid = from->i_gid; 38807a2daabSVivek Goyal to->i_mode = from->i_mode; 389d719e8f2SMiklos Szeredi to->i_atime = from->i_atime; 390d719e8f2SMiklos Szeredi to->i_mtime = from->i_mtime; 391d719e8f2SMiklos Szeredi to->i_ctime = from->i_ctime; 39246e5d0a3SMiklos Szeredi i_size_write(to, i_size_read(from)); 393e9be9d5eSMiklos Szeredi } 394e9be9d5eSMiklos Szeredi 3954f357295SMiklos Szeredi static inline void ovl_copyflags(struct inode *from, struct inode *to) 3964f357295SMiklos Szeredi { 3974f357295SMiklos Szeredi unsigned int mask = S_SYNC | S_IMMUTABLE | S_APPEND | S_NOATIME; 3984f357295SMiklos Szeredi 3994f357295SMiklos Szeredi inode_set_flags(to, from->i_flags & mask, mask); 4004f357295SMiklos Szeredi } 4014f357295SMiklos Szeredi 402e9be9d5eSMiklos Szeredi /* dir.c */ 403e9be9d5eSMiklos Szeredi extern const struct inode_operations ovl_dir_inode_operations; 404e7dd0e71SAmir Goldstein int ovl_cleanup_and_whiteout(struct dentry *workdir, struct inode *dir, 405e7dd0e71SAmir Goldstein struct dentry *dentry); 406471ec5dcSAmir Goldstein struct ovl_cattr { 40732a3d848SAl Viro dev_t rdev; 40832a3d848SAl Viro umode_t mode; 40932a3d848SAl Viro const char *link; 410471ec5dcSAmir Goldstein struct dentry *hardlink; 41132a3d848SAl Viro }; 412471ec5dcSAmir Goldstein 413471ec5dcSAmir Goldstein #define OVL_CATTR(m) (&(struct ovl_cattr) { .mode = (m) }) 414471ec5dcSAmir Goldstein 41595a1c815SMiklos Szeredi struct dentry *ovl_create_real(struct inode *dir, struct dentry *newdentry, 416471ec5dcSAmir Goldstein struct ovl_cattr *attr); 417415543d5SAmir Goldstein int ovl_cleanup(struct inode *dir, struct dentry *dentry); 418137ec526SAmir Goldstein struct dentry *ovl_create_temp(struct dentry *workdir, struct ovl_cattr *attr); 419e9be9d5eSMiklos Szeredi 420d1d04ef8SMiklos Szeredi /* file.c */ 421d1d04ef8SMiklos Szeredi extern const struct file_operations ovl_file_operations; 422d1d04ef8SMiklos Szeredi 423e9be9d5eSMiklos Szeredi /* copy_up.c */ 424e9be9d5eSMiklos Szeredi int ovl_copy_up(struct dentry *dentry); 425d1e6f6a9SVivek Goyal int ovl_copy_up_with_data(struct dentry *dentry); 4269aba6521SAmir Goldstein int ovl_copy_up_flags(struct dentry *dentry, int flags); 4273428030dSAmir Goldstein int ovl_maybe_copy_up(struct dentry *dentry, int flags); 428e9be9d5eSMiklos Szeredi int ovl_copy_xattr(struct dentry *old, struct dentry *new); 429e9be9d5eSMiklos Szeredi int ovl_set_attr(struct dentry *upper, struct kstat *stat); 4305b2cccd3SAmir Goldstein struct ovl_fh *ovl_encode_real_fh(struct dentry *real, bool is_upper); 4319678e630SAmir Goldstein int ovl_set_origin(struct dentry *dentry, struct dentry *lower, 4329678e630SAmir Goldstein struct dentry *upper); 4338ed5eec9SAmir Goldstein 4348ed5eec9SAmir Goldstein /* export.c */ 4358ed5eec9SAmir Goldstein extern const struct export_operations ovl_export_operations; 436