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" 323a1e819bSAmir Goldstein 33c62520a8SAmir Goldstein enum ovl_inode_flag { 34b79e05aaSAmir Goldstein /* Pure upper dir that may contain non pure upper entries */ 3513c72075SMiklos Szeredi OVL_IMPURE, 36b79e05aaSAmir Goldstein /* Non-merge dir that may contain whiteout entries */ 37b79e05aaSAmir Goldstein OVL_WHITEOUTS, 38359f392cSAmir Goldstein OVL_INDEX, 3913c72075SMiklos Szeredi }; 4013c72075SMiklos Szeredi 41c62520a8SAmir Goldstein enum ovl_entry_flag { 42c62520a8SAmir Goldstein OVL_E_UPPER_ALIAS, 43c62520a8SAmir Goldstein OVL_E_OPAQUE, 442ca3c148SAmir Goldstein OVL_E_CONNECTED, 45c62520a8SAmir Goldstein }; 46c62520a8SAmir Goldstein 473a1e819bSAmir Goldstein /* 483a1e819bSAmir Goldstein * The tuple (fh,uuid) is a universal unique identifier for a copy up origin, 493a1e819bSAmir Goldstein * where: 503a1e819bSAmir Goldstein * origin.fh - exported file handle of the lower file 513a1e819bSAmir Goldstein * origin.uuid - uuid of the lower filesystem 523a1e819bSAmir Goldstein */ 533a1e819bSAmir Goldstein #define OVL_FH_VERSION 0 543a1e819bSAmir Goldstein #define OVL_FH_MAGIC 0xfb 553a1e819bSAmir Goldstein 563a1e819bSAmir Goldstein /* CPU byte order required for fid decoding: */ 573a1e819bSAmir Goldstein #define OVL_FH_FLAG_BIG_ENDIAN (1 << 0) 583a1e819bSAmir Goldstein #define OVL_FH_FLAG_ANY_ENDIAN (1 << 1) 5954fb347eSAmir Goldstein /* Is the real inode encoded in fid an upper inode? */ 6054fb347eSAmir Goldstein #define OVL_FH_FLAG_PATH_UPPER (1 << 2) 613a1e819bSAmir Goldstein 62961af647SAmir Goldstein #define OVL_FH_FLAG_ALL (OVL_FH_FLAG_BIG_ENDIAN | OVL_FH_FLAG_ANY_ENDIAN | \ 63961af647SAmir Goldstein OVL_FH_FLAG_PATH_UPPER) 643a1e819bSAmir Goldstein 653a1e819bSAmir Goldstein #if defined(__LITTLE_ENDIAN) 663a1e819bSAmir Goldstein #define OVL_FH_FLAG_CPU_ENDIAN 0 673a1e819bSAmir Goldstein #elif defined(__BIG_ENDIAN) 683a1e819bSAmir Goldstein #define OVL_FH_FLAG_CPU_ENDIAN OVL_FH_FLAG_BIG_ENDIAN 693a1e819bSAmir Goldstein #else 703a1e819bSAmir Goldstein #error Endianness not defined 713a1e819bSAmir Goldstein #endif 723a1e819bSAmir Goldstein 738ed5eec9SAmir Goldstein /* The type returned by overlay exportfs ops when encoding an ovl_fh handle */ 748ed5eec9SAmir Goldstein #define OVL_FILEID 0xfb 758ed5eec9SAmir Goldstein 763a1e819bSAmir Goldstein /* On-disk and in-memeory format for redirect by file handle */ 773a1e819bSAmir Goldstein struct ovl_fh { 783a1e819bSAmir Goldstein u8 version; /* 0 */ 793a1e819bSAmir Goldstein u8 magic; /* 0xfb */ 803a1e819bSAmir Goldstein u8 len; /* size of this header + size of fid */ 813a1e819bSAmir Goldstein u8 flags; /* OVL_FH_FLAG_* */ 823a1e819bSAmir Goldstein u8 type; /* fid_type of fid */ 8301633fd2SChristoph Hellwig uuid_t uuid; /* uuid of filesystem */ 843a1e819bSAmir Goldstein u8 fid[0]; /* file identifier */ 853a1e819bSAmir Goldstein } __packed; 86e9be9d5eSMiklos Szeredi 87e9be9d5eSMiklos Szeredi static inline int ovl_do_rmdir(struct inode *dir, struct dentry *dentry) 88e9be9d5eSMiklos Szeredi { 89e9be9d5eSMiklos Szeredi int err = vfs_rmdir(dir, dentry); 906cf00764SAmir Goldstein 91e9be9d5eSMiklos Szeredi pr_debug("rmdir(%pd2) = %i\n", dentry, err); 92e9be9d5eSMiklos Szeredi return err; 93e9be9d5eSMiklos Szeredi } 94e9be9d5eSMiklos Szeredi 95e9be9d5eSMiklos Szeredi static inline int ovl_do_unlink(struct inode *dir, struct dentry *dentry) 96e9be9d5eSMiklos Szeredi { 97e9be9d5eSMiklos Szeredi int err = vfs_unlink(dir, dentry, NULL); 986cf00764SAmir Goldstein 99e9be9d5eSMiklos Szeredi pr_debug("unlink(%pd2) = %i\n", dentry, err); 100e9be9d5eSMiklos Szeredi return err; 101e9be9d5eSMiklos Szeredi } 102e9be9d5eSMiklos Szeredi 103e9be9d5eSMiklos Szeredi static inline int ovl_do_link(struct dentry *old_dentry, struct inode *dir, 1046cf00764SAmir Goldstein struct dentry *new_dentry) 105e9be9d5eSMiklos Szeredi { 106e9be9d5eSMiklos Szeredi int err = vfs_link(old_dentry, dir, new_dentry, NULL); 1076cf00764SAmir Goldstein 1086cf00764SAmir Goldstein pr_debug("link(%pd2, %pd2) = %i\n", old_dentry, new_dentry, err); 109e9be9d5eSMiklos Szeredi return err; 110e9be9d5eSMiklos Szeredi } 111e9be9d5eSMiklos Szeredi 112e9be9d5eSMiklos Szeredi static inline int ovl_do_create(struct inode *dir, struct dentry *dentry, 1136cf00764SAmir Goldstein umode_t mode) 114e9be9d5eSMiklos Szeredi { 115e9be9d5eSMiklos Szeredi int err = vfs_create(dir, dentry, mode, true); 1166cf00764SAmir Goldstein 117e9be9d5eSMiklos Szeredi pr_debug("create(%pd2, 0%o) = %i\n", dentry, mode, err); 118e9be9d5eSMiklos Szeredi return err; 119e9be9d5eSMiklos Szeredi } 120e9be9d5eSMiklos Szeredi 121e9be9d5eSMiklos Szeredi static inline int ovl_do_mkdir(struct inode *dir, struct dentry *dentry, 1226cf00764SAmir Goldstein umode_t mode) 123e9be9d5eSMiklos Szeredi { 124e9be9d5eSMiklos Szeredi int err = vfs_mkdir(dir, dentry, mode); 125e9be9d5eSMiklos Szeredi pr_debug("mkdir(%pd2, 0%o) = %i\n", dentry, mode, err); 126e9be9d5eSMiklos Szeredi return err; 127e9be9d5eSMiklos Szeredi } 128e9be9d5eSMiklos Szeredi 129e9be9d5eSMiklos Szeredi static inline int ovl_do_mknod(struct inode *dir, struct dentry *dentry, 1306cf00764SAmir Goldstein umode_t mode, dev_t dev) 131e9be9d5eSMiklos Szeredi { 132e9be9d5eSMiklos Szeredi int err = vfs_mknod(dir, dentry, mode, dev); 1336cf00764SAmir Goldstein 1346cf00764SAmir Goldstein pr_debug("mknod(%pd2, 0%o, 0%o) = %i\n", dentry, mode, dev, err); 135e9be9d5eSMiklos Szeredi return err; 136e9be9d5eSMiklos Szeredi } 137e9be9d5eSMiklos Szeredi 138e9be9d5eSMiklos Szeredi static inline int ovl_do_symlink(struct inode *dir, struct dentry *dentry, 1396cf00764SAmir Goldstein const char *oldname) 140e9be9d5eSMiklos Szeredi { 141e9be9d5eSMiklos Szeredi int err = vfs_symlink(dir, dentry, oldname); 1426cf00764SAmir Goldstein 143e9be9d5eSMiklos Szeredi pr_debug("symlink(\"%s\", %pd2) = %i\n", oldname, dentry, err); 144e9be9d5eSMiklos Szeredi return err; 145e9be9d5eSMiklos Szeredi } 146e9be9d5eSMiklos Szeredi 147e9be9d5eSMiklos Szeredi static inline int ovl_do_setxattr(struct dentry *dentry, const char *name, 148e9be9d5eSMiklos Szeredi const void *value, size_t size, int flags) 149e9be9d5eSMiklos Szeredi { 150e9be9d5eSMiklos Szeredi int err = vfs_setxattr(dentry, name, value, size, flags); 151e9be9d5eSMiklos Szeredi pr_debug("setxattr(%pd2, \"%s\", \"%*s\", 0x%x) = %i\n", 152e9be9d5eSMiklos Szeredi dentry, name, (int) size, (char *) value, flags, err); 153e9be9d5eSMiklos Szeredi return err; 154e9be9d5eSMiklos Szeredi } 155e9be9d5eSMiklos Szeredi 156e9be9d5eSMiklos Szeredi static inline int ovl_do_removexattr(struct dentry *dentry, const char *name) 157e9be9d5eSMiklos Szeredi { 158e9be9d5eSMiklos Szeredi int err = vfs_removexattr(dentry, name); 159e9be9d5eSMiklos Szeredi pr_debug("removexattr(%pd2, \"%s\") = %i\n", dentry, name, err); 160e9be9d5eSMiklos Szeredi return err; 161e9be9d5eSMiklos Szeredi } 162e9be9d5eSMiklos Szeredi 163e9be9d5eSMiklos Szeredi static inline int ovl_do_rename(struct inode *olddir, struct dentry *olddentry, 164e9be9d5eSMiklos Szeredi struct inode *newdir, struct dentry *newdentry, 165e9be9d5eSMiklos Szeredi unsigned int flags) 166e9be9d5eSMiklos Szeredi { 167e9be9d5eSMiklos Szeredi int err; 168e9be9d5eSMiklos Szeredi 1696cf00764SAmir Goldstein pr_debug("rename(%pd2, %pd2, 0x%x)\n", olddentry, newdentry, flags); 170e9be9d5eSMiklos Szeredi err = vfs_rename(olddir, olddentry, newdir, newdentry, NULL, flags); 171e9be9d5eSMiklos Szeredi if (err) { 1722773bf00SMiklos Szeredi pr_debug("...rename(%pd2, %pd2, ...) = %i\n", 173e9be9d5eSMiklos Szeredi olddentry, newdentry, err); 174e9be9d5eSMiklos Szeredi } 175e9be9d5eSMiklos Szeredi return err; 176e9be9d5eSMiklos Szeredi } 177e9be9d5eSMiklos Szeredi 178e9be9d5eSMiklos Szeredi static inline int ovl_do_whiteout(struct inode *dir, struct dentry *dentry) 179e9be9d5eSMiklos Szeredi { 180e9be9d5eSMiklos Szeredi int err = vfs_whiteout(dir, dentry); 181e9be9d5eSMiklos Szeredi pr_debug("whiteout(%pd2) = %i\n", dentry, err); 182e9be9d5eSMiklos Szeredi return err; 183e9be9d5eSMiklos Szeredi } 184e9be9d5eSMiklos Szeredi 185e7f52429SAmir Goldstein static inline struct dentry *ovl_do_tmpfile(struct dentry *dentry, umode_t mode) 186e7f52429SAmir Goldstein { 187e7f52429SAmir Goldstein struct dentry *ret = vfs_tmpfile(dentry, mode, 0); 1887879cb43SVasyl Gomonovych int err = PTR_ERR_OR_ZERO(ret); 189e7f52429SAmir Goldstein 190e7f52429SAmir Goldstein pr_debug("tmpfile(%pd2, 0%o) = %i\n", dentry, mode, err); 191e7f52429SAmir Goldstein return ret; 192e7f52429SAmir Goldstein } 193e7f52429SAmir Goldstein 194bbb1e54dSMiklos Szeredi /* util.c */ 195bbb1e54dSMiklos Szeredi int ovl_want_write(struct dentry *dentry); 196bbb1e54dSMiklos Szeredi void ovl_drop_write(struct dentry *dentry); 197bbb1e54dSMiklos Szeredi struct dentry *ovl_workdir(struct dentry *dentry); 198bbb1e54dSMiklos Szeredi const struct cred *ovl_override_creds(struct super_block *sb); 1997bcd74b9SAmir Goldstein struct super_block *ovl_same_sb(struct super_block *sb); 200e487d889SAmir Goldstein int ovl_can_decode_fh(struct super_block *sb); 20102bcd157SAmir Goldstein struct dentry *ovl_indexdir(struct super_block *sb); 202f168f109SAmir Goldstein bool ovl_index_all(struct super_block *sb); 203f168f109SAmir Goldstein bool ovl_verify_lower(struct super_block *sb); 204bbb1e54dSMiklos Szeredi struct ovl_entry *ovl_alloc_entry(unsigned int numlower); 205bbb1e54dSMiklos Szeredi bool ovl_dentry_remote(struct dentry *dentry); 206bbb1e54dSMiklos Szeredi bool ovl_dentry_weird(struct dentry *dentry); 207e9be9d5eSMiklos Szeredi enum ovl_path_type ovl_path_type(struct dentry *dentry); 208e9be9d5eSMiklos Szeredi void ovl_path_upper(struct dentry *dentry, struct path *path); 209e9be9d5eSMiklos Szeredi void ovl_path_lower(struct dentry *dentry, struct path *path); 210e9be9d5eSMiklos Szeredi enum ovl_path_type ovl_path_real(struct dentry *dentry, struct path *path); 211e9be9d5eSMiklos Szeredi struct dentry *ovl_dentry_upper(struct dentry *dentry); 212e9be9d5eSMiklos Szeredi struct dentry *ovl_dentry_lower(struct dentry *dentry); 213da309e8cSAmir Goldstein struct ovl_layer *ovl_layer_lower(struct dentry *dentry); 214e9be9d5eSMiklos Szeredi struct dentry *ovl_dentry_real(struct dentry *dentry); 2151d88f183SMiklos Szeredi struct dentry *ovl_i_dentry_upper(struct inode *inode); 21609d8b586SMiklos Szeredi struct inode *ovl_inode_upper(struct inode *inode); 21709d8b586SMiklos Szeredi struct inode *ovl_inode_lower(struct inode *inode); 21809d8b586SMiklos Szeredi struct inode *ovl_inode_real(struct inode *inode); 2194edb83bbSMiklos Szeredi struct ovl_dir_cache *ovl_dir_cache(struct inode *inode); 2204edb83bbSMiklos Szeredi void ovl_set_dir_cache(struct inode *inode, struct ovl_dir_cache *cache); 221c62520a8SAmir Goldstein void ovl_dentry_set_flag(unsigned long flag, struct dentry *dentry); 222c62520a8SAmir Goldstein void ovl_dentry_clear_flag(unsigned long flag, struct dentry *dentry); 223c62520a8SAmir Goldstein bool ovl_dentry_test_flag(unsigned long flag, struct dentry *dentry); 224e9be9d5eSMiklos Szeredi bool ovl_dentry_is_opaque(struct dentry *dentry); 225c412ce49SMiklos Szeredi bool ovl_dentry_is_whiteout(struct dentry *dentry); 2265cf5b477SMiklos Szeredi void ovl_dentry_set_opaque(struct dentry *dentry); 22755acc661SMiklos Szeredi bool ovl_dentry_has_upper_alias(struct dentry *dentry); 22855acc661SMiklos Szeredi void ovl_dentry_set_upper_alias(struct dentry *dentry); 229a6c60655SMiklos Szeredi bool ovl_redirect_dir(struct super_block *sb); 230a6c60655SMiklos Szeredi const char *ovl_dentry_get_redirect(struct dentry *dentry); 231a6c60655SMiklos Szeredi void ovl_dentry_set_redirect(struct dentry *dentry, const char *redirect); 23209d8b586SMiklos Szeredi void ovl_inode_init(struct inode *inode, struct dentry *upperdentry, 23309d8b586SMiklos Szeredi struct dentry *lowerdentry); 23409d8b586SMiklos Szeredi void ovl_inode_update(struct inode *inode, struct dentry *upperdentry); 235d9854c87SMiklos Szeredi void ovl_dir_modified(struct dentry *dentry, bool impurity); 236bbb1e54dSMiklos Szeredi u64 ovl_dentry_version_get(struct dentry *dentry); 237bbb1e54dSMiklos Szeredi bool ovl_is_whiteout(struct dentry *dentry); 238e9be9d5eSMiklos Szeredi struct file *ovl_path_open(struct path *path, int flags); 23939d3d60aSAmir Goldstein int ovl_copy_up_start(struct dentry *dentry); 24039d3d60aSAmir Goldstein void ovl_copy_up_end(struct dentry *dentry); 241b79e05aaSAmir Goldstein bool ovl_check_origin_xattr(struct dentry *dentry); 242f3a15685SAmir Goldstein bool ovl_check_dir_xattr(struct dentry *dentry, const char *name); 243f3a15685SAmir Goldstein int ovl_check_setxattr(struct dentry *dentry, struct dentry *upperdentry, 244f3a15685SAmir Goldstein const char *name, const void *value, size_t size, 245f3a15685SAmir Goldstein int xerr); 246f3a15685SAmir Goldstein int ovl_set_impure(struct dentry *dentry, struct dentry *upperdentry); 24713c72075SMiklos Szeredi void ovl_set_flag(unsigned long flag, struct inode *inode); 2484edb83bbSMiklos Szeredi void ovl_clear_flag(unsigned long flag, struct inode *inode); 24913c72075SMiklos Szeredi bool ovl_test_flag(unsigned long flag, struct inode *inode); 250ad0af710SAmir Goldstein bool ovl_inuse_trylock(struct dentry *dentry); 251ad0af710SAmir Goldstein void ovl_inuse_unlock(struct dentry *dentry); 25224b33ee1SAmir Goldstein bool ovl_need_index(struct dentry *dentry); 2535f8415d6SAmir Goldstein int ovl_nlink_start(struct dentry *dentry, bool *locked); 2545f8415d6SAmir Goldstein void ovl_nlink_end(struct dentry *dentry, bool locked); 2555820dc08SAmir Goldstein int ovl_lock_rename_workdir(struct dentry *workdir, struct dentry *upperdir); 256f3a15685SAmir Goldstein 257f3a15685SAmir Goldstein static inline bool ovl_is_impuredir(struct dentry *dentry) 258f3a15685SAmir Goldstein { 259f3a15685SAmir Goldstein return ovl_check_dir_xattr(dentry, OVL_XATTR_IMPURE); 260f3a15685SAmir Goldstein } 261f3a15685SAmir Goldstein 262e487d889SAmir Goldstein static inline unsigned int ovl_xino_bits(struct super_block *sb) 263e487d889SAmir Goldstein { 264e487d889SAmir Goldstein struct ovl_fs *ofs = sb->s_fs_info; 265e487d889SAmir Goldstein 266e487d889SAmir Goldstein return ofs->xino_bits; 267e487d889SAmir Goldstein } 268e487d889SAmir Goldstein 269e9be9d5eSMiklos Szeredi 270bbb1e54dSMiklos Szeredi /* namei.c */ 2718556a420SAmir Goldstein int ovl_check_fh_len(struct ovl_fh *fh, int fh_len); 2728a22efa1SAmir Goldstein struct dentry *ovl_decode_real_fh(struct ovl_fh *fh, struct vfsmount *mnt, 2738a22efa1SAmir Goldstein bool connected); 2748a22efa1SAmir Goldstein int ovl_check_origin_fh(struct ovl_fs *ofs, struct ovl_fh *fh, bool connected, 275f941866fSAmir Goldstein struct dentry *upperdentry, struct ovl_path **stackp); 27605122443SAmir Goldstein int ovl_verify_set_fh(struct dentry *dentry, const char *name, 27705122443SAmir Goldstein struct dentry *real, bool is_upper, bool set); 2783b0bfc6eSAmir Goldstein struct dentry *ovl_index_upper(struct ovl_fs *ofs, struct dentry *index); 2791eff1a1dSAmir Goldstein int ovl_verify_index(struct ovl_fs *ofs, struct dentry *index); 280359f392cSAmir Goldstein int ovl_get_index_name(struct dentry *origin, struct qstr *name); 28191ffe7beSAmir Goldstein struct dentry *ovl_get_index_fh(struct ovl_fs *ofs, struct ovl_fh *fh); 28206170154SAmir Goldstein struct dentry *ovl_lookup_index(struct ovl_fs *ofs, struct dentry *upper, 28306170154SAmir Goldstein struct dentry *origin, bool verify); 284bbb1e54dSMiklos Szeredi int ovl_path_next(int idx, struct dentry *dentry, struct path *path); 2851eff1a1dSAmir Goldstein struct dentry *ovl_lookup(struct inode *dir, struct dentry *dentry, 2861eff1a1dSAmir Goldstein unsigned int flags); 287bbb1e54dSMiklos Szeredi bool ovl_lower_positive(struct dentry *dentry); 288e9be9d5eSMiklos Szeredi 28905122443SAmir Goldstein static inline int ovl_verify_origin(struct dentry *upper, 29005122443SAmir Goldstein struct dentry *origin, bool set) 29105122443SAmir Goldstein { 29205122443SAmir Goldstein return ovl_verify_set_fh(upper, OVL_XATTR_ORIGIN, origin, false, set); 29305122443SAmir Goldstein } 29405122443SAmir Goldstein 295ad1d615cSAmir Goldstein static inline int ovl_verify_upper(struct dentry *index, 296ad1d615cSAmir Goldstein struct dentry *upper, bool set) 297ad1d615cSAmir Goldstein { 298ad1d615cSAmir Goldstein return ovl_verify_set_fh(index, OVL_XATTR_UPPER, upper, true, set); 299ad1d615cSAmir Goldstein } 300ad1d615cSAmir Goldstein 301e9be9d5eSMiklos Szeredi /* readdir.c */ 302e9be9d5eSMiklos Szeredi extern const struct file_operations ovl_dir_operations; 303e9be9d5eSMiklos Szeredi int ovl_check_empty_dir(struct dentry *dentry, struct list_head *list); 304e9be9d5eSMiklos Szeredi void ovl_cleanup_whiteouts(struct dentry *upper, struct list_head *list); 305e9be9d5eSMiklos Szeredi void ovl_cache_free(struct list_head *list); 3064edb83bbSMiklos Szeredi void ovl_dir_cache_free(struct inode *inode); 30745aebeafSVivek Goyal int ovl_check_d_type_supported(struct path *realpath); 308eea2fb48SMiklos Szeredi void ovl_workdir_cleanup(struct inode *dir, struct vfsmount *mnt, 309eea2fb48SMiklos Szeredi struct dentry *dentry, int level); 3101eff1a1dSAmir Goldstein int ovl_indexdir_cleanup(struct ovl_fs *ofs); 311e9be9d5eSMiklos Szeredi 312e9be9d5eSMiklos Szeredi /* inode.c */ 3135f8415d6SAmir Goldstein int ovl_set_nlink_upper(struct dentry *dentry); 3145f8415d6SAmir Goldstein int ovl_set_nlink_lower(struct dentry *dentry); 315caf70cb2SAmir Goldstein unsigned int ovl_get_nlink(struct dentry *lowerdentry, 316caf70cb2SAmir Goldstein struct dentry *upperdentry, 317caf70cb2SAmir Goldstein unsigned int fallback); 318e9be9d5eSMiklos Szeredi int ovl_setattr(struct dentry *dentry, struct iattr *attr); 3195b712091SMiklos Szeredi int ovl_getattr(const struct path *path, struct kstat *stat, 3205b712091SMiklos Szeredi u32 request_mask, unsigned int flags); 321e9be9d5eSMiklos Szeredi int ovl_permission(struct inode *inode, int mask); 3221d88f183SMiklos Szeredi int ovl_xattr_set(struct dentry *dentry, struct inode *inode, const char *name, 3231d88f183SMiklos Szeredi const void *value, size_t size, int flags); 3241d88f183SMiklos Szeredi int ovl_xattr_get(struct dentry *dentry, struct inode *inode, const char *name, 3250eb45fc3SAndreas Gruenbacher void *value, size_t size); 326e9be9d5eSMiklos Szeredi ssize_t ovl_listxattr(struct dentry *dentry, char *list, size_t size); 32739a25b2bSVivek Goyal struct posix_acl *ovl_get_acl(struct inode *inode, int type); 3282d902671SMiklos Szeredi int ovl_open_maybe_copy_up(struct dentry *dentry, unsigned int file_flags); 32995582b00SDeepa Dinamani int ovl_update_time(struct inode *inode, struct timespec64 *ts, int flags); 3300956254aSMiklos Szeredi bool ovl_is_private_xattr(const char *name); 331e9be9d5eSMiklos Szeredi 332ac6a52ebSVivek Goyal struct ovl_inode_params { 33301b39dccSAmir Goldstein struct inode *newinode; 334ac6a52ebSVivek Goyal struct dentry *upperdentry; 335ac6a52ebSVivek Goyal struct ovl_path *lowerpath; 336ac6a52ebSVivek Goyal struct dentry *index; 337ac6a52ebSVivek Goyal unsigned int numlower; 338*9cec54c8SVivek Goyal char *redirect; 339ac6a52ebSVivek Goyal }; 340ca4c8a3aSMiklos Szeredi struct inode *ovl_new_inode(struct super_block *sb, umode_t mode, dev_t rdev); 3414b91c30aSAmir Goldstein struct inode *ovl_lookup_inode(struct super_block *sb, struct dentry *real, 3424b91c30aSAmir Goldstein bool is_upper); 343ac6a52ebSVivek Goyal struct inode *ovl_get_inode(struct super_block *sb, 344ac6a52ebSVivek Goyal struct ovl_inode_params *oip); 345e9be9d5eSMiklos Szeredi static inline void ovl_copyattr(struct inode *from, struct inode *to) 346e9be9d5eSMiklos Szeredi { 347e9be9d5eSMiklos Szeredi to->i_uid = from->i_uid; 348e9be9d5eSMiklos Szeredi to->i_gid = from->i_gid; 34907a2daabSVivek Goyal to->i_mode = from->i_mode; 350d719e8f2SMiklos Szeredi to->i_atime = from->i_atime; 351d719e8f2SMiklos Szeredi to->i_mtime = from->i_mtime; 352d719e8f2SMiklos Szeredi to->i_ctime = from->i_ctime; 35346e5d0a3SMiklos Szeredi i_size_write(to, i_size_read(from)); 354e9be9d5eSMiklos Szeredi } 355e9be9d5eSMiklos Szeredi 3564f357295SMiklos Szeredi static inline void ovl_copyflags(struct inode *from, struct inode *to) 3574f357295SMiklos Szeredi { 3584f357295SMiklos Szeredi unsigned int mask = S_SYNC | S_IMMUTABLE | S_APPEND | S_NOATIME; 3594f357295SMiklos Szeredi 3604f357295SMiklos Szeredi inode_set_flags(to, from->i_flags & mask, mask); 3614f357295SMiklos Szeredi } 3624f357295SMiklos Szeredi 363e9be9d5eSMiklos Szeredi /* dir.c */ 364e9be9d5eSMiklos Szeredi extern const struct inode_operations ovl_dir_inode_operations; 365e7dd0e71SAmir Goldstein int ovl_cleanup_and_whiteout(struct dentry *workdir, struct inode *dir, 366e7dd0e71SAmir Goldstein struct dentry *dentry); 367471ec5dcSAmir Goldstein struct ovl_cattr { 36832a3d848SAl Viro dev_t rdev; 36932a3d848SAl Viro umode_t mode; 37032a3d848SAl Viro const char *link; 371471ec5dcSAmir Goldstein struct dentry *hardlink; 37232a3d848SAl Viro }; 373471ec5dcSAmir Goldstein 374471ec5dcSAmir Goldstein #define OVL_CATTR(m) (&(struct ovl_cattr) { .mode = (m) }) 375471ec5dcSAmir Goldstein 37695a1c815SMiklos Szeredi struct dentry *ovl_create_real(struct inode *dir, struct dentry *newdentry, 377471ec5dcSAmir Goldstein struct ovl_cattr *attr); 378415543d5SAmir Goldstein int ovl_cleanup(struct inode *dir, struct dentry *dentry); 379137ec526SAmir Goldstein struct dentry *ovl_create_temp(struct dentry *workdir, struct ovl_cattr *attr); 380e9be9d5eSMiklos Szeredi 381d1d04ef8SMiklos Szeredi /* file.c */ 382d1d04ef8SMiklos Szeredi extern const struct file_operations ovl_file_operations; 383d1d04ef8SMiklos Szeredi 384e9be9d5eSMiklos Szeredi /* copy_up.c */ 385e9be9d5eSMiklos Szeredi int ovl_copy_up(struct dentry *dentry); 3869aba6521SAmir Goldstein int ovl_copy_up_flags(struct dentry *dentry, int flags); 387e9be9d5eSMiklos Szeredi int ovl_copy_xattr(struct dentry *old, struct dentry *new); 388e9be9d5eSMiklos Szeredi int ovl_set_attr(struct dentry *upper, struct kstat *stat); 3895b2cccd3SAmir Goldstein struct ovl_fh *ovl_encode_real_fh(struct dentry *real, bool is_upper); 3909678e630SAmir Goldstein int ovl_set_origin(struct dentry *dentry, struct dentry *lower, 3919678e630SAmir Goldstein struct dentry *upper); 3928ed5eec9SAmir Goldstein 3938ed5eec9SAmir Goldstein /* export.c */ 3948ed5eec9SAmir Goldstein extern const struct export_operations ovl_export_operations; 395