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); 155e9be9d5eSMiklos Szeredi pr_debug("setxattr(%pd2, \"%s\", \"%*s\", 0x%x) = %i\n", 156e9be9d5eSMiklos Szeredi dentry, name, (int) size, (char *) value, 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); 27324b33ee1SAmir Goldstein bool ovl_need_index(struct dentry *dentry); 2745f8415d6SAmir Goldstein int ovl_nlink_start(struct dentry *dentry, bool *locked); 2755f8415d6SAmir Goldstein void ovl_nlink_end(struct dentry *dentry, bool locked); 2765820dc08SAmir Goldstein int ovl_lock_rename_workdir(struct dentry *workdir, struct dentry *upperdir); 2779d3dfea3SVivek Goyal int ovl_check_metacopy_xattr(struct dentry *dentry); 27867d756c2SVivek Goyal bool ovl_is_metacopy_dentry(struct dentry *dentry); 2790a2d0d3fSVivek Goyal char *ovl_get_redirect_xattr(struct dentry *dentry, int padding); 280f3a15685SAmir Goldstein 281f3a15685SAmir Goldstein static inline bool ovl_is_impuredir(struct dentry *dentry) 282f3a15685SAmir Goldstein { 283f3a15685SAmir Goldstein return ovl_check_dir_xattr(dentry, OVL_XATTR_IMPURE); 284f3a15685SAmir Goldstein } 285f3a15685SAmir Goldstein 286e487d889SAmir Goldstein static inline unsigned int ovl_xino_bits(struct super_block *sb) 287e487d889SAmir Goldstein { 288e487d889SAmir Goldstein struct ovl_fs *ofs = sb->s_fs_info; 289e487d889SAmir Goldstein 290e487d889SAmir Goldstein return ofs->xino_bits; 291e487d889SAmir Goldstein } 292e487d889SAmir Goldstein 293e9be9d5eSMiklos Szeredi 294bbb1e54dSMiklos Szeredi /* namei.c */ 2958556a420SAmir Goldstein int ovl_check_fh_len(struct ovl_fh *fh, int fh_len); 2968a22efa1SAmir Goldstein struct dentry *ovl_decode_real_fh(struct ovl_fh *fh, struct vfsmount *mnt, 2978a22efa1SAmir Goldstein bool connected); 2988a22efa1SAmir Goldstein int ovl_check_origin_fh(struct ovl_fs *ofs, struct ovl_fh *fh, bool connected, 299f941866fSAmir Goldstein struct dentry *upperdentry, struct ovl_path **stackp); 30005122443SAmir Goldstein int ovl_verify_set_fh(struct dentry *dentry, const char *name, 30105122443SAmir Goldstein struct dentry *real, bool is_upper, bool set); 3023b0bfc6eSAmir Goldstein struct dentry *ovl_index_upper(struct ovl_fs *ofs, struct dentry *index); 3031eff1a1dSAmir Goldstein int ovl_verify_index(struct ovl_fs *ofs, struct dentry *index); 304359f392cSAmir Goldstein int ovl_get_index_name(struct dentry *origin, struct qstr *name); 30591ffe7beSAmir Goldstein struct dentry *ovl_get_index_fh(struct ovl_fs *ofs, struct ovl_fh *fh); 30606170154SAmir Goldstein struct dentry *ovl_lookup_index(struct ovl_fs *ofs, struct dentry *upper, 30706170154SAmir Goldstein struct dentry *origin, bool verify); 308bbb1e54dSMiklos Szeredi int ovl_path_next(int idx, struct dentry *dentry, struct path *path); 3091eff1a1dSAmir Goldstein struct dentry *ovl_lookup(struct inode *dir, struct dentry *dentry, 3101eff1a1dSAmir Goldstein unsigned int flags); 311bbb1e54dSMiklos Szeredi bool ovl_lower_positive(struct dentry *dentry); 312e9be9d5eSMiklos Szeredi 31305122443SAmir Goldstein static inline int ovl_verify_origin(struct dentry *upper, 31405122443SAmir Goldstein struct dentry *origin, bool set) 31505122443SAmir Goldstein { 31605122443SAmir Goldstein return ovl_verify_set_fh(upper, OVL_XATTR_ORIGIN, origin, false, set); 31705122443SAmir Goldstein } 31805122443SAmir Goldstein 319ad1d615cSAmir Goldstein static inline int ovl_verify_upper(struct dentry *index, 320ad1d615cSAmir Goldstein struct dentry *upper, bool set) 321ad1d615cSAmir Goldstein { 322ad1d615cSAmir Goldstein return ovl_verify_set_fh(index, OVL_XATTR_UPPER, upper, true, set); 323ad1d615cSAmir Goldstein } 324ad1d615cSAmir Goldstein 325e9be9d5eSMiklos Szeredi /* readdir.c */ 326e9be9d5eSMiklos Szeredi extern const struct file_operations ovl_dir_operations; 327e9be9d5eSMiklos Szeredi int ovl_check_empty_dir(struct dentry *dentry, struct list_head *list); 328e9be9d5eSMiklos Szeredi void ovl_cleanup_whiteouts(struct dentry *upper, struct list_head *list); 329e9be9d5eSMiklos Szeredi void ovl_cache_free(struct list_head *list); 3304edb83bbSMiklos Szeredi void ovl_dir_cache_free(struct inode *inode); 33145aebeafSVivek Goyal int ovl_check_d_type_supported(struct path *realpath); 332eea2fb48SMiklos Szeredi void ovl_workdir_cleanup(struct inode *dir, struct vfsmount *mnt, 333eea2fb48SMiklos Szeredi struct dentry *dentry, int level); 3341eff1a1dSAmir Goldstein int ovl_indexdir_cleanup(struct ovl_fs *ofs); 335e9be9d5eSMiklos Szeredi 336e9be9d5eSMiklos Szeredi /* inode.c */ 3375f8415d6SAmir Goldstein int ovl_set_nlink_upper(struct dentry *dentry); 3385f8415d6SAmir Goldstein int ovl_set_nlink_lower(struct dentry *dentry); 339caf70cb2SAmir Goldstein unsigned int ovl_get_nlink(struct dentry *lowerdentry, 340caf70cb2SAmir Goldstein struct dentry *upperdentry, 341caf70cb2SAmir Goldstein unsigned int fallback); 342e9be9d5eSMiklos Szeredi int ovl_setattr(struct dentry *dentry, struct iattr *attr); 3435b712091SMiklos Szeredi int ovl_getattr(const struct path *path, struct kstat *stat, 3445b712091SMiklos Szeredi u32 request_mask, unsigned int flags); 345e9be9d5eSMiklos Szeredi int ovl_permission(struct inode *inode, int mask); 3461d88f183SMiklos Szeredi int ovl_xattr_set(struct dentry *dentry, struct inode *inode, const char *name, 3471d88f183SMiklos Szeredi const void *value, size_t size, int flags); 3481d88f183SMiklos Szeredi int ovl_xattr_get(struct dentry *dentry, struct inode *inode, const char *name, 3490eb45fc3SAndreas Gruenbacher void *value, size_t size); 350e9be9d5eSMiklos Szeredi ssize_t ovl_listxattr(struct dentry *dentry, char *list, size_t size); 35139a25b2bSVivek Goyal struct posix_acl *ovl_get_acl(struct inode *inode, int type); 35295582b00SDeepa Dinamani int ovl_update_time(struct inode *inode, struct timespec64 *ts, int flags); 3530956254aSMiklos Szeredi bool ovl_is_private_xattr(const char *name); 354e9be9d5eSMiklos Szeredi 355ac6a52ebSVivek Goyal struct ovl_inode_params { 35601b39dccSAmir Goldstein struct inode *newinode; 357ac6a52ebSVivek Goyal struct dentry *upperdentry; 358ac6a52ebSVivek Goyal struct ovl_path *lowerpath; 359ac6a52ebSVivek Goyal struct dentry *index; 360ac6a52ebSVivek Goyal unsigned int numlower; 3619cec54c8SVivek Goyal char *redirect; 3622664bd08SVivek Goyal struct dentry *lowerdata; 363ac6a52ebSVivek Goyal }; 364ca4c8a3aSMiklos Szeredi struct inode *ovl_new_inode(struct super_block *sb, umode_t mode, dev_t rdev); 3654b91c30aSAmir Goldstein struct inode *ovl_lookup_inode(struct super_block *sb, struct dentry *real, 3664b91c30aSAmir Goldstein bool is_upper); 367ac6a52ebSVivek Goyal struct inode *ovl_get_inode(struct super_block *sb, 368ac6a52ebSVivek Goyal struct ovl_inode_params *oip); 369e9be9d5eSMiklos Szeredi static inline void ovl_copyattr(struct inode *from, struct inode *to) 370e9be9d5eSMiklos Szeredi { 371e9be9d5eSMiklos Szeredi to->i_uid = from->i_uid; 372e9be9d5eSMiklos Szeredi to->i_gid = from->i_gid; 37307a2daabSVivek Goyal to->i_mode = from->i_mode; 374d719e8f2SMiklos Szeredi to->i_atime = from->i_atime; 375d719e8f2SMiklos Szeredi to->i_mtime = from->i_mtime; 376d719e8f2SMiklos Szeredi to->i_ctime = from->i_ctime; 37746e5d0a3SMiklos Szeredi i_size_write(to, i_size_read(from)); 378e9be9d5eSMiklos Szeredi } 379e9be9d5eSMiklos Szeredi 3804f357295SMiklos Szeredi static inline void ovl_copyflags(struct inode *from, struct inode *to) 3814f357295SMiklos Szeredi { 3824f357295SMiklos Szeredi unsigned int mask = S_SYNC | S_IMMUTABLE | S_APPEND | S_NOATIME; 3834f357295SMiklos Szeredi 3844f357295SMiklos Szeredi inode_set_flags(to, from->i_flags & mask, mask); 3854f357295SMiklos Szeredi } 3864f357295SMiklos Szeredi 387e9be9d5eSMiklos Szeredi /* dir.c */ 388e9be9d5eSMiklos Szeredi extern const struct inode_operations ovl_dir_inode_operations; 389e7dd0e71SAmir Goldstein int ovl_cleanup_and_whiteout(struct dentry *workdir, struct inode *dir, 390e7dd0e71SAmir Goldstein struct dentry *dentry); 391471ec5dcSAmir Goldstein struct ovl_cattr { 39232a3d848SAl Viro dev_t rdev; 39332a3d848SAl Viro umode_t mode; 39432a3d848SAl Viro const char *link; 395471ec5dcSAmir Goldstein struct dentry *hardlink; 39632a3d848SAl Viro }; 397471ec5dcSAmir Goldstein 398471ec5dcSAmir Goldstein #define OVL_CATTR(m) (&(struct ovl_cattr) { .mode = (m) }) 399471ec5dcSAmir Goldstein 40095a1c815SMiklos Szeredi struct dentry *ovl_create_real(struct inode *dir, struct dentry *newdentry, 401471ec5dcSAmir Goldstein struct ovl_cattr *attr); 402415543d5SAmir Goldstein int ovl_cleanup(struct inode *dir, struct dentry *dentry); 403137ec526SAmir Goldstein struct dentry *ovl_create_temp(struct dentry *workdir, struct ovl_cattr *attr); 404e9be9d5eSMiklos Szeredi 405d1d04ef8SMiklos Szeredi /* file.c */ 406d1d04ef8SMiklos Szeredi extern const struct file_operations ovl_file_operations; 407d1d04ef8SMiklos Szeredi 408e9be9d5eSMiklos Szeredi /* copy_up.c */ 409e9be9d5eSMiklos Szeredi int ovl_copy_up(struct dentry *dentry); 410*d1e6f6a9SVivek Goyal int ovl_copy_up_with_data(struct dentry *dentry); 4119aba6521SAmir Goldstein int ovl_copy_up_flags(struct dentry *dentry, int flags); 412d6eac039SVivek Goyal int ovl_open_maybe_copy_up(struct dentry *dentry, unsigned int file_flags); 413e9be9d5eSMiklos Szeredi int ovl_copy_xattr(struct dentry *old, struct dentry *new); 414e9be9d5eSMiklos Szeredi int ovl_set_attr(struct dentry *upper, struct kstat *stat); 4155b2cccd3SAmir Goldstein struct ovl_fh *ovl_encode_real_fh(struct dentry *real, bool is_upper); 4169678e630SAmir Goldstein int ovl_set_origin(struct dentry *dentry, struct dentry *lower, 4179678e630SAmir Goldstein struct dentry *upper); 4188ed5eec9SAmir Goldstein 4198ed5eec9SAmir Goldstein /* export.c */ 4208ed5eec9SAmir Goldstein extern const struct export_operations ovl_export_operations; 421