1d2912cb1SThomas Gleixner /* SPDX-License-Identifier: GPL-2.0-only */ 2e9be9d5eSMiklos Szeredi /* 3e9be9d5eSMiklos Szeredi * 4e9be9d5eSMiklos Szeredi * Copyright (C) 2011 Novell Inc. 5e9be9d5eSMiklos Szeredi */ 6e9be9d5eSMiklos Szeredi 7e9be9d5eSMiklos Szeredi #include <linux/kernel.h> 83a1e819bSAmir Goldstein #include <linux/uuid.h> 946e5d0a3SMiklos Szeredi #include <linux/fs.h> 1022f289ceSChristian Brauner #include <linux/namei.h> 110e641857SChristian Brauner #include <linux/posix_acl.h> 120e641857SChristian Brauner #include <linux/posix_acl_xattr.h> 13ee023c30SAmir Goldstein #include "ovl_entry.h" 14e9be9d5eSMiklos Szeredi 151bd0a3aeSlijiazi #undef pr_fmt 161bd0a3aeSlijiazi #define pr_fmt(fmt) "overlayfs: " fmt 171bd0a3aeSlijiazi 18e9be9d5eSMiklos Szeredi enum ovl_path_type { 1938e813dbSMiklos Szeredi __OVL_PATH_UPPER = (1 << 0), 2038e813dbSMiklos Szeredi __OVL_PATH_MERGE = (1 << 1), 2159548503SAmir Goldstein __OVL_PATH_ORIGIN = (1 << 2), 22e9be9d5eSMiklos Szeredi }; 23e9be9d5eSMiklos Szeredi 241afaba1eSMiklos Szeredi #define OVL_TYPE_UPPER(type) ((type) & __OVL_PATH_UPPER) 251afaba1eSMiklos Szeredi #define OVL_TYPE_MERGE(type) ((type) & __OVL_PATH_MERGE) 2659548503SAmir Goldstein #define OVL_TYPE_ORIGIN(type) ((type) & __OVL_PATH_ORIGIN) 27d837a49bSMiklos Szeredi 282d2f2d73SMiklos Szeredi #define OVL_XATTR_NAMESPACE "overlay." 292d2f2d73SMiklos Szeredi #define OVL_XATTR_TRUSTED_PREFIX XATTR_TRUSTED_PREFIX OVL_XATTR_NAMESPACE 302d2f2d73SMiklos Szeredi #define OVL_XATTR_USER_PREFIX XATTR_USER_PREFIX OVL_XATTR_NAMESPACE 3143d193f8SMiklos Szeredi 3243d193f8SMiklos Szeredi enum ovl_xattr { 3343d193f8SMiklos Szeredi OVL_XATTR_OPAQUE, 3443d193f8SMiklos Szeredi OVL_XATTR_REDIRECT, 3543d193f8SMiklos Szeredi OVL_XATTR_ORIGIN, 3643d193f8SMiklos Szeredi OVL_XATTR_IMPURE, 3743d193f8SMiklos Szeredi OVL_XATTR_NLINK, 3843d193f8SMiklos Szeredi OVL_XATTR_UPPER, 3943d193f8SMiklos Szeredi OVL_XATTR_METACOPY, 40096a218aSAmir Goldstein OVL_XATTR_PROTATTR, 4143d193f8SMiklos Szeredi }; 423a1e819bSAmir Goldstein 43c62520a8SAmir Goldstein enum ovl_inode_flag { 44b79e05aaSAmir Goldstein /* Pure upper dir that may contain non pure upper entries */ 4513c72075SMiklos Szeredi OVL_IMPURE, 46b79e05aaSAmir Goldstein /* Non-merge dir that may contain whiteout entries */ 47b79e05aaSAmir Goldstein OVL_WHITEOUTS, 48359f392cSAmir Goldstein OVL_INDEX, 490c288874SVivek Goyal OVL_UPPERDATA, 50a00c2d59SVivek Goyal /* Inode number will remain constant over copy up. */ 51a00c2d59SVivek Goyal OVL_CONST_INO, 5213c72075SMiklos Szeredi }; 5313c72075SMiklos Szeredi 54c62520a8SAmir Goldstein enum ovl_entry_flag { 55c62520a8SAmir Goldstein OVL_E_UPPER_ALIAS, 56c62520a8SAmir Goldstein OVL_E_OPAQUE, 572ca3c148SAmir Goldstein OVL_E_CONNECTED, 58c62520a8SAmir Goldstein }; 59c62520a8SAmir Goldstein 60926e94d7SAmir Goldstein enum { 61926e94d7SAmir Goldstein OVL_XINO_OFF, 62926e94d7SAmir Goldstein OVL_XINO_AUTO, 63926e94d7SAmir Goldstein OVL_XINO_ON, 64926e94d7SAmir Goldstein }; 65926e94d7SAmir Goldstein 663a1e819bSAmir Goldstein /* 673a1e819bSAmir Goldstein * The tuple (fh,uuid) is a universal unique identifier for a copy up origin, 683a1e819bSAmir Goldstein * where: 693a1e819bSAmir Goldstein * origin.fh - exported file handle of the lower file 703a1e819bSAmir Goldstein * origin.uuid - uuid of the lower filesystem 713a1e819bSAmir Goldstein */ 723a1e819bSAmir Goldstein #define OVL_FH_VERSION 0 733a1e819bSAmir Goldstein #define OVL_FH_MAGIC 0xfb 743a1e819bSAmir Goldstein 753a1e819bSAmir Goldstein /* CPU byte order required for fid decoding: */ 763a1e819bSAmir Goldstein #define OVL_FH_FLAG_BIG_ENDIAN (1 << 0) 773a1e819bSAmir Goldstein #define OVL_FH_FLAG_ANY_ENDIAN (1 << 1) 7854fb347eSAmir Goldstein /* Is the real inode encoded in fid an upper inode? */ 7954fb347eSAmir Goldstein #define OVL_FH_FLAG_PATH_UPPER (1 << 2) 803a1e819bSAmir Goldstein 81961af647SAmir Goldstein #define OVL_FH_FLAG_ALL (OVL_FH_FLAG_BIG_ENDIAN | OVL_FH_FLAG_ANY_ENDIAN | \ 82961af647SAmir Goldstein OVL_FH_FLAG_PATH_UPPER) 833a1e819bSAmir Goldstein 843a1e819bSAmir Goldstein #if defined(__LITTLE_ENDIAN) 853a1e819bSAmir Goldstein #define OVL_FH_FLAG_CPU_ENDIAN 0 863a1e819bSAmir Goldstein #elif defined(__BIG_ENDIAN) 873a1e819bSAmir Goldstein #define OVL_FH_FLAG_CPU_ENDIAN OVL_FH_FLAG_BIG_ENDIAN 883a1e819bSAmir Goldstein #else 893a1e819bSAmir Goldstein #error Endianness not defined 903a1e819bSAmir Goldstein #endif 913a1e819bSAmir Goldstein 92cbe7fba8SAmir Goldstein /* The type used to be returned by overlay exportfs for misaligned fid */ 93cbe7fba8SAmir Goldstein #define OVL_FILEID_V0 0xfb 94cbe7fba8SAmir Goldstein /* The type returned by overlay exportfs for 32bit aligned fid */ 95cbe7fba8SAmir Goldstein #define OVL_FILEID_V1 0xf8 968ed5eec9SAmir Goldstein 97cbe7fba8SAmir Goldstein /* On-disk format for "origin" file handle */ 98cbe7fba8SAmir Goldstein struct ovl_fb { 993a1e819bSAmir Goldstein u8 version; /* 0 */ 1003a1e819bSAmir Goldstein u8 magic; /* 0xfb */ 1013a1e819bSAmir Goldstein u8 len; /* size of this header + size of fid */ 1023a1e819bSAmir Goldstein u8 flags; /* OVL_FH_FLAG_* */ 1033a1e819bSAmir Goldstein u8 type; /* fid_type of fid */ 10401633fd2SChristoph Hellwig uuid_t uuid; /* uuid of filesystem */ 1050efbe7c4SGustavo A. R. Silva u32 fid[]; /* file identifier should be 32bit aligned in-memory */ 1063a1e819bSAmir Goldstein } __packed; 107e9be9d5eSMiklos Szeredi 108cbe7fba8SAmir Goldstein /* In-memory and on-wire format for overlay file handle */ 109cbe7fba8SAmir Goldstein struct ovl_fh { 110cbe7fba8SAmir Goldstein u8 padding[3]; /* make sure fb.fid is 32bit aligned */ 111cbe7fba8SAmir Goldstein union { 112cbe7fba8SAmir Goldstein struct ovl_fb fb; 113cf8aa9bfSKees Cook DECLARE_FLEX_ARRAY(u8, buf); 114cbe7fba8SAmir Goldstein }; 115cbe7fba8SAmir Goldstein } __packed; 116cbe7fba8SAmir Goldstein 117cbe7fba8SAmir Goldstein #define OVL_FH_WIRE_OFFSET offsetof(struct ovl_fh, fb) 118cbe7fba8SAmir Goldstein #define OVL_FH_LEN(fh) (OVL_FH_WIRE_OFFSET + (fh)->fb.len) 119cbe7fba8SAmir Goldstein #define OVL_FH_FID_OFFSET (OVL_FH_WIRE_OFFSET + \ 120cbe7fba8SAmir Goldstein offsetof(struct ovl_fb, fid)) 121cbe7fba8SAmir Goldstein 1222d2f2d73SMiklos Szeredi extern const char *const ovl_xattr_table[][2]; 12343d193f8SMiklos Szeredi static inline const char *ovl_xattr(struct ovl_fs *ofs, enum ovl_xattr ox) 12443d193f8SMiklos Szeredi { 1252d2f2d73SMiklos Szeredi return ovl_xattr_table[ox][ofs->config.userxattr]; 12643d193f8SMiklos Szeredi } 12743d193f8SMiklos Szeredi 128a15506eaSChristian Brauner /* 129a15506eaSChristian Brauner * When changing ownership of an upper object map the intended ownership 130a15506eaSChristian Brauner * according to the upper layer's idmapping. When an upper mount idmaps files 131a15506eaSChristian Brauner * that are stored on-disk as owned by id 1001 to id 1000 this means stat on 132a15506eaSChristian Brauner * this object will report it as being owned by id 1000 when calling stat via 133a15506eaSChristian Brauner * the upper mount. 134a15506eaSChristian Brauner * In order to change ownership of an object so stat reports id 1000 when 135a15506eaSChristian Brauner * called on an idmapped upper mount the value written to disk - i.e., the 136a15506eaSChristian Brauner * value stored in ia_*id - must 1001. The mount mapping helper will thus take 137a15506eaSChristian Brauner * care to map 1000 to 1001. 138a15506eaSChristian Brauner * The mnt idmapping helpers are nops if the upper layer isn't idmapped. 139a15506eaSChristian Brauner */ 140a15506eaSChristian Brauner static inline int ovl_do_notify_change(struct ovl_fs *ofs, 141a15506eaSChristian Brauner struct dentry *upperdentry, 142a15506eaSChristian Brauner struct iattr *attr) 143a15506eaSChristian Brauner { 144abf08576SChristian Brauner return notify_change(ovl_upper_mnt_idmap(ofs), upperdentry, attr, NULL); 145a15506eaSChristian Brauner } 146a15506eaSChristian Brauner 147576bb263SChristian Brauner static inline int ovl_do_rmdir(struct ovl_fs *ofs, 148576bb263SChristian Brauner struct inode *dir, struct dentry *dentry) 149e9be9d5eSMiklos Szeredi { 150abf08576SChristian Brauner int err = vfs_rmdir(ovl_upper_mnt_idmap(ofs), dir, dentry); 1516cf00764SAmir Goldstein 152e9be9d5eSMiklos Szeredi pr_debug("rmdir(%pd2) = %i\n", dentry, err); 153e9be9d5eSMiklos Szeredi return err; 154e9be9d5eSMiklos Szeredi } 155e9be9d5eSMiklos Szeredi 156576bb263SChristian Brauner static inline int ovl_do_unlink(struct ovl_fs *ofs, struct inode *dir, 157576bb263SChristian Brauner struct dentry *dentry) 158e9be9d5eSMiklos Szeredi { 159abf08576SChristian Brauner int err = vfs_unlink(ovl_upper_mnt_idmap(ofs), dir, dentry, NULL); 1606cf00764SAmir Goldstein 161e9be9d5eSMiklos Szeredi pr_debug("unlink(%pd2) = %i\n", dentry, err); 162e9be9d5eSMiklos Szeredi return err; 163e9be9d5eSMiklos Szeredi } 164e9be9d5eSMiklos Szeredi 165576bb263SChristian Brauner static inline int ovl_do_link(struct ovl_fs *ofs, struct dentry *old_dentry, 166576bb263SChristian Brauner struct inode *dir, struct dentry *new_dentry) 167e9be9d5eSMiklos Szeredi { 168abf08576SChristian Brauner int err = vfs_link(old_dentry, ovl_upper_mnt_idmap(ofs), dir, 169abf08576SChristian Brauner new_dentry, NULL); 1706cf00764SAmir Goldstein 1716cf00764SAmir Goldstein pr_debug("link(%pd2, %pd2) = %i\n", old_dentry, new_dentry, err); 172e9be9d5eSMiklos Szeredi return err; 173e9be9d5eSMiklos Szeredi } 174e9be9d5eSMiklos Szeredi 175576bb263SChristian Brauner static inline int ovl_do_create(struct ovl_fs *ofs, 176576bb263SChristian Brauner struct inode *dir, struct dentry *dentry, 1776cf00764SAmir Goldstein umode_t mode) 178e9be9d5eSMiklos Szeredi { 179abf08576SChristian Brauner int err = vfs_create(ovl_upper_mnt_idmap(ofs), dir, dentry, mode, true); 1806cf00764SAmir Goldstein 181e9be9d5eSMiklos Szeredi pr_debug("create(%pd2, 0%o) = %i\n", dentry, mode, err); 182e9be9d5eSMiklos Szeredi return err; 183e9be9d5eSMiklos Szeredi } 184e9be9d5eSMiklos Szeredi 185576bb263SChristian Brauner static inline int ovl_do_mkdir(struct ovl_fs *ofs, 186576bb263SChristian Brauner struct inode *dir, struct dentry *dentry, 1876cf00764SAmir Goldstein umode_t mode) 188e9be9d5eSMiklos Szeredi { 189abf08576SChristian Brauner int err = vfs_mkdir(ovl_upper_mnt_idmap(ofs), dir, dentry, mode); 190e9be9d5eSMiklos Szeredi pr_debug("mkdir(%pd2, 0%o) = %i\n", dentry, mode, err); 191e9be9d5eSMiklos Szeredi return err; 192e9be9d5eSMiklos Szeredi } 193e9be9d5eSMiklos Szeredi 194576bb263SChristian Brauner static inline int ovl_do_mknod(struct ovl_fs *ofs, 195576bb263SChristian Brauner struct inode *dir, struct dentry *dentry, 1966cf00764SAmir Goldstein umode_t mode, dev_t dev) 197e9be9d5eSMiklos Szeredi { 198abf08576SChristian Brauner int err = vfs_mknod(ovl_upper_mnt_idmap(ofs), dir, dentry, mode, dev); 1996cf00764SAmir Goldstein 2006cf00764SAmir Goldstein pr_debug("mknod(%pd2, 0%o, 0%o) = %i\n", dentry, mode, dev, err); 201e9be9d5eSMiklos Szeredi return err; 202e9be9d5eSMiklos Szeredi } 203e9be9d5eSMiklos Szeredi 204576bb263SChristian Brauner static inline int ovl_do_symlink(struct ovl_fs *ofs, 205576bb263SChristian Brauner struct inode *dir, struct dentry *dentry, 2066cf00764SAmir Goldstein const char *oldname) 207e9be9d5eSMiklos Szeredi { 208abf08576SChristian Brauner int err = vfs_symlink(ovl_upper_mnt_idmap(ofs), dir, dentry, oldname); 2096cf00764SAmir Goldstein 210e9be9d5eSMiklos Szeredi pr_debug("symlink(\"%s\", %pd2) = %i\n", oldname, dentry, err); 211e9be9d5eSMiklos Szeredi return err; 212e9be9d5eSMiklos Szeredi } 213e9be9d5eSMiklos Szeredi 2142d343087SAl Viro static inline ssize_t ovl_do_getxattr(const struct path *path, const char *name, 215dad7017aSChristian Brauner void *value, size_t size) 216d5dc7486SMiklos Szeredi { 217dad7017aSChristian Brauner int err, len; 218dad7017aSChristian Brauner 219dad7017aSChristian Brauner WARN_ON(path->dentry->d_sb != path->mnt->mnt_sb); 220dad7017aSChristian Brauner 2214609e1f1SChristian Brauner err = vfs_getxattr(mnt_idmap(path->mnt), path->dentry, 222dad7017aSChristian Brauner name, value, size); 223dad7017aSChristian Brauner len = (value && err > 0) ? err : 0; 2245e717c6fSAmir Goldstein 2255e717c6fSAmir Goldstein pr_debug("getxattr(%pd2, \"%s\", \"%*pE\", %zu, 0) = %i\n", 226dad7017aSChristian Brauner path->dentry, name, min(len, 48), value, size, err); 2275e717c6fSAmir Goldstein return err; 228d5dc7486SMiklos Szeredi } 229d5dc7486SMiklos Szeredi 230dad7017aSChristian Brauner static inline ssize_t ovl_getxattr_upper(struct ovl_fs *ofs, 231dad7017aSChristian Brauner struct dentry *upperdentry, 232c914c0e2SAmir Goldstein enum ovl_xattr ox, void *value, 233610afc0bSMiklos Szeredi size_t size) 234e9be9d5eSMiklos Szeredi { 235dad7017aSChristian Brauner struct path upperpath = { 236dad7017aSChristian Brauner .dentry = upperdentry, 237dad7017aSChristian Brauner .mnt = ovl_upper_mnt(ofs), 238dad7017aSChristian Brauner }; 239dad7017aSChristian Brauner 240dad7017aSChristian Brauner return ovl_do_getxattr(&upperpath, ovl_xattr(ofs, ox), value, size); 241dad7017aSChristian Brauner } 242dad7017aSChristian Brauner 243dad7017aSChristian Brauner static inline ssize_t ovl_path_getxattr(struct ovl_fs *ofs, 2442d343087SAl Viro const struct path *path, 245dad7017aSChristian Brauner enum ovl_xattr ox, void *value, 246dad7017aSChristian Brauner size_t size) 247dad7017aSChristian Brauner { 248dad7017aSChristian Brauner return ovl_do_getxattr(path, ovl_xattr(ofs, ox), value, size); 249c914c0e2SAmir Goldstein } 250c914c0e2SAmir Goldstein 251c914c0e2SAmir Goldstein static inline int ovl_do_setxattr(struct ovl_fs *ofs, struct dentry *dentry, 252c914c0e2SAmir Goldstein const char *name, const void *value, 253c914c0e2SAmir Goldstein size_t size, int flags) 254c914c0e2SAmir Goldstein { 2554609e1f1SChristian Brauner int err = vfs_setxattr(ovl_upper_mnt_idmap(ofs), dentry, name, 2566344e669SChristian Brauner value, size, flags); 257c914c0e2SAmir Goldstein 258c914c0e2SAmir Goldstein pr_debug("setxattr(%pd2, \"%s\", \"%*pE\", %zu, %d) = %i\n", 259c914c0e2SAmir Goldstein dentry, name, min((int)size, 48), value, size, flags, err); 260e9be9d5eSMiklos Szeredi return err; 261e9be9d5eSMiklos Szeredi } 262e9be9d5eSMiklos Szeredi 263c914c0e2SAmir Goldstein static inline int ovl_setxattr(struct ovl_fs *ofs, struct dentry *dentry, 264c914c0e2SAmir Goldstein enum ovl_xattr ox, const void *value, 265c914c0e2SAmir Goldstein size_t size) 266e9be9d5eSMiklos Szeredi { 267c914c0e2SAmir Goldstein return ovl_do_setxattr(ofs, dentry, ovl_xattr(ofs, ox), value, size, 0); 268c914c0e2SAmir Goldstein } 269c914c0e2SAmir Goldstein 270c914c0e2SAmir Goldstein static inline int ovl_do_removexattr(struct ovl_fs *ofs, struct dentry *dentry, 271c914c0e2SAmir Goldstein const char *name) 272c914c0e2SAmir Goldstein { 2734609e1f1SChristian Brauner int err = vfs_removexattr(ovl_upper_mnt_idmap(ofs), dentry, name); 274e9be9d5eSMiklos Szeredi pr_debug("removexattr(%pd2, \"%s\") = %i\n", dentry, name, err); 275e9be9d5eSMiklos Szeredi return err; 276e9be9d5eSMiklos Szeredi } 277e9be9d5eSMiklos Szeredi 278c914c0e2SAmir Goldstein static inline int ovl_removexattr(struct ovl_fs *ofs, struct dentry *dentry, 279c914c0e2SAmir Goldstein enum ovl_xattr ox) 280c914c0e2SAmir Goldstein { 281c914c0e2SAmir Goldstein return ovl_do_removexattr(ofs, dentry, ovl_xattr(ofs, ox)); 282c914c0e2SAmir Goldstein } 283c914c0e2SAmir Goldstein 2840e641857SChristian Brauner static inline int ovl_do_set_acl(struct ovl_fs *ofs, struct dentry *dentry, 2850e641857SChristian Brauner const char *acl_name, struct posix_acl *acl) 2860e641857SChristian Brauner { 28713e83a49SChristian Brauner return vfs_set_acl(ovl_upper_mnt_idmap(ofs), dentry, acl_name, acl); 2880e641857SChristian Brauner } 2890e641857SChristian Brauner 2900e641857SChristian Brauner static inline int ovl_do_remove_acl(struct ovl_fs *ofs, struct dentry *dentry, 2910e641857SChristian Brauner const char *acl_name) 2920e641857SChristian Brauner { 29313e83a49SChristian Brauner return vfs_remove_acl(ovl_upper_mnt_idmap(ofs), dentry, acl_name); 2940e641857SChristian Brauner } 2950e641857SChristian Brauner 296576bb263SChristian Brauner static inline int ovl_do_rename(struct ovl_fs *ofs, struct inode *olddir, 297576bb263SChristian Brauner struct dentry *olddentry, struct inode *newdir, 298576bb263SChristian Brauner struct dentry *newdentry, unsigned int flags) 299e9be9d5eSMiklos Szeredi { 300e9be9d5eSMiklos Szeredi int err; 3019fe61450SChristian Brauner struct renamedata rd = { 302abf08576SChristian Brauner .old_mnt_idmap = ovl_upper_mnt_idmap(ofs), 3039fe61450SChristian Brauner .old_dir = olddir, 3049fe61450SChristian Brauner .old_dentry = olddentry, 305abf08576SChristian Brauner .new_mnt_idmap = ovl_upper_mnt_idmap(ofs), 3069fe61450SChristian Brauner .new_dir = newdir, 3079fe61450SChristian Brauner .new_dentry = newdentry, 3089fe61450SChristian Brauner .flags = flags, 3099fe61450SChristian Brauner }; 310e9be9d5eSMiklos Szeredi 3116cf00764SAmir Goldstein pr_debug("rename(%pd2, %pd2, 0x%x)\n", olddentry, newdentry, flags); 3129fe61450SChristian Brauner err = vfs_rename(&rd); 313e9be9d5eSMiklos Szeredi if (err) { 3142773bf00SMiklos Szeredi pr_debug("...rename(%pd2, %pd2, ...) = %i\n", 315e9be9d5eSMiklos Szeredi olddentry, newdentry, err); 316e9be9d5eSMiklos Szeredi } 317e9be9d5eSMiklos Szeredi return err; 318e9be9d5eSMiklos Szeredi } 319e9be9d5eSMiklos Szeredi 320576bb263SChristian Brauner static inline int ovl_do_whiteout(struct ovl_fs *ofs, 321576bb263SChristian Brauner struct inode *dir, struct dentry *dentry) 322e9be9d5eSMiklos Szeredi { 323abf08576SChristian Brauner int err = vfs_whiteout(ovl_upper_mnt_idmap(ofs), dir, dentry); 324e9be9d5eSMiklos Szeredi pr_debug("whiteout(%pd2) = %i\n", dentry, err); 325e9be9d5eSMiklos Szeredi return err; 326e9be9d5eSMiklos Szeredi } 327e9be9d5eSMiklos Szeredi 3282b1a7746SMiklos Szeredi static inline struct file *ovl_do_tmpfile(struct ovl_fs *ofs, 329576bb263SChristian Brauner struct dentry *dentry, umode_t mode) 330e7f52429SAmir Goldstein { 3312b1a7746SMiklos Szeredi struct path path = { .mnt = ovl_upper_mnt(ofs), .dentry = dentry }; 332*d56e0ddbSAmir Goldstein struct file *file = kernel_tmpfile_open(ovl_upper_mnt_idmap(ofs), &path, 333*d56e0ddbSAmir Goldstein mode, O_LARGEFILE | O_WRONLY, 334*d56e0ddbSAmir Goldstein current_cred()); 3352b1a7746SMiklos Szeredi int err = PTR_ERR_OR_ZERO(file); 336e7f52429SAmir Goldstein 337e7f52429SAmir Goldstein pr_debug("tmpfile(%pd2, 0%o) = %i\n", dentry, mode, err); 3382b1a7746SMiklos Szeredi return file; 339e7f52429SAmir Goldstein } 340e7f52429SAmir Goldstein 34122f289ceSChristian Brauner static inline struct dentry *ovl_lookup_upper(struct ovl_fs *ofs, 34222f289ceSChristian Brauner const char *name, 34322f289ceSChristian Brauner struct dentry *base, int len) 34422f289ceSChristian Brauner { 3454609e1f1SChristian Brauner return lookup_one(ovl_upper_mnt_idmap(ofs), name, base, len); 34622f289ceSChristian Brauner } 34722f289ceSChristian Brauner 3480c288874SVivek Goyal static inline bool ovl_open_flags_need_copy_up(int flags) 3490c288874SVivek Goyal { 3500c288874SVivek Goyal if (!flags) 3510c288874SVivek Goyal return false; 3520c288874SVivek Goyal 3530c288874SVivek Goyal return ((OPEN_FMODE(flags) & FMODE_WRITE) || (flags & O_TRUNC)); 3540c288874SVivek Goyal } 3550c288874SVivek Goyal 356ca45275cSVyacheslav Yurkov static inline bool ovl_allow_offline_changes(struct ovl_fs *ofs) 357ca45275cSVyacheslav Yurkov { 358ca45275cSVyacheslav Yurkov /* 359ca45275cSVyacheslav Yurkov * To avoid regressions in existing setups with overlay lower offline 360ca45275cSVyacheslav Yurkov * changes, we allow lower changes only if none of the new features 361ca45275cSVyacheslav Yurkov * are used. 362ca45275cSVyacheslav Yurkov */ 363ca45275cSVyacheslav Yurkov return (!ofs->config.index && !ofs->config.metacopy && 364ca45275cSVyacheslav Yurkov !ofs->config.redirect_dir && ofs->config.xino != OVL_XINO_ON); 365ca45275cSVyacheslav Yurkov } 366ca45275cSVyacheslav Yurkov 367ca45275cSVyacheslav Yurkov 368bbb1e54dSMiklos Szeredi /* util.c */ 369bbb1e54dSMiklos Szeredi int ovl_want_write(struct dentry *dentry); 370bbb1e54dSMiklos Szeredi void ovl_drop_write(struct dentry *dentry); 371bbb1e54dSMiklos Szeredi struct dentry *ovl_workdir(struct dentry *dentry); 372bbb1e54dSMiklos Szeredi const struct cred *ovl_override_creds(struct super_block *sb); 373e487d889SAmir Goldstein int ovl_can_decode_fh(struct super_block *sb); 37402bcd157SAmir Goldstein struct dentry *ovl_indexdir(struct super_block *sb); 375f168f109SAmir Goldstein bool ovl_index_all(struct super_block *sb); 376f168f109SAmir Goldstein bool ovl_verify_lower(struct super_block *sb); 377bbb1e54dSMiklos Szeredi struct ovl_entry *ovl_alloc_entry(unsigned int numlower); 378bbb1e54dSMiklos Szeredi bool ovl_dentry_remote(struct dentry *dentry); 379f4288844SMiklos Szeredi void ovl_dentry_update_reval(struct dentry *dentry, struct dentry *upperdentry, 380f4288844SMiklos Szeredi unsigned int mask); 381bbb1e54dSMiklos Szeredi bool ovl_dentry_weird(struct dentry *dentry); 382e9be9d5eSMiklos Szeredi enum ovl_path_type ovl_path_type(struct dentry *dentry); 383e9be9d5eSMiklos Szeredi void ovl_path_upper(struct dentry *dentry, struct path *path); 384e9be9d5eSMiklos Szeredi void ovl_path_lower(struct dentry *dentry, struct path *path); 3854f93b426SVivek Goyal void ovl_path_lowerdata(struct dentry *dentry, struct path *path); 386ffa5723cSAmir Goldstein void ovl_i_path_real(struct inode *inode, struct path *path); 387e9be9d5eSMiklos Szeredi enum ovl_path_type ovl_path_real(struct dentry *dentry, struct path *path); 3881248ea4bSAmir Goldstein enum ovl_path_type ovl_path_realdata(struct dentry *dentry, struct path *path); 389e9be9d5eSMiklos Szeredi struct dentry *ovl_dentry_upper(struct dentry *dentry); 390e9be9d5eSMiklos Szeredi struct dentry *ovl_dentry_lower(struct dentry *dentry); 391647d253fSVivek Goyal struct dentry *ovl_dentry_lowerdata(struct dentry *dentry); 392ffa5723cSAmir Goldstein const struct ovl_layer *ovl_i_layer_lower(struct inode *inode); 39313464165SMiklos Szeredi const struct ovl_layer *ovl_layer_lower(struct dentry *dentry); 394e9be9d5eSMiklos Szeredi struct dentry *ovl_dentry_real(struct dentry *dentry); 3951d88f183SMiklos Szeredi struct dentry *ovl_i_dentry_upper(struct inode *inode); 39609d8b586SMiklos Szeredi struct inode *ovl_inode_upper(struct inode *inode); 39709d8b586SMiklos Szeredi struct inode *ovl_inode_lower(struct inode *inode); 3982664bd08SVivek Goyal struct inode *ovl_inode_lowerdata(struct inode *inode); 39909d8b586SMiklos Szeredi struct inode *ovl_inode_real(struct inode *inode); 4004823d49cSVivek Goyal struct inode *ovl_inode_realdata(struct inode *inode); 4014edb83bbSMiklos Szeredi struct ovl_dir_cache *ovl_dir_cache(struct inode *inode); 4024edb83bbSMiklos Szeredi void ovl_set_dir_cache(struct inode *inode, struct ovl_dir_cache *cache); 403c62520a8SAmir Goldstein void ovl_dentry_set_flag(unsigned long flag, struct dentry *dentry); 404c62520a8SAmir Goldstein void ovl_dentry_clear_flag(unsigned long flag, struct dentry *dentry); 405c62520a8SAmir Goldstein bool ovl_dentry_test_flag(unsigned long flag, struct dentry *dentry); 406e9be9d5eSMiklos Szeredi bool ovl_dentry_is_opaque(struct dentry *dentry); 407c412ce49SMiklos Szeredi bool ovl_dentry_is_whiteout(struct dentry *dentry); 4085cf5b477SMiklos Szeredi void ovl_dentry_set_opaque(struct dentry *dentry); 40955acc661SMiklos Szeredi bool ovl_dentry_has_upper_alias(struct dentry *dentry); 41055acc661SMiklos Szeredi void ovl_dentry_set_upper_alias(struct dentry *dentry); 4110c288874SVivek Goyal bool ovl_dentry_needs_data_copy_up(struct dentry *dentry, int flags); 4120c288874SVivek Goyal bool ovl_dentry_needs_data_copy_up_locked(struct dentry *dentry, int flags); 4130c288874SVivek Goyal bool ovl_has_upperdata(struct inode *inode); 4140c288874SVivek Goyal void ovl_set_upperdata(struct inode *inode); 415a6c60655SMiklos Szeredi bool ovl_redirect_dir(struct super_block *sb); 416a6c60655SMiklos Szeredi const char *ovl_dentry_get_redirect(struct dentry *dentry); 417a6c60655SMiklos Szeredi void ovl_dentry_set_redirect(struct dentry *dentry, const char *redirect); 41809d8b586SMiklos Szeredi void ovl_inode_update(struct inode *inode, struct dentry *upperdentry); 419d9854c87SMiklos Szeredi void ovl_dir_modified(struct dentry *dentry, bool impurity); 4201fa9c5c5SMiklos Szeredi u64 ovl_inode_version_get(struct inode *inode); 421bbb1e54dSMiklos Szeredi bool ovl_is_whiteout(struct dentry *dentry); 4222d343087SAl Viro struct file *ovl_path_open(const struct path *path, int flags); 4230c288874SVivek Goyal int ovl_copy_up_start(struct dentry *dentry, int flags); 42439d3d60aSAmir Goldstein void ovl_copy_up_end(struct dentry *dentry); 4250c288874SVivek Goyal bool ovl_already_copied_up(struct dentry *dentry, int flags); 4262d343087SAl Viro bool ovl_path_check_dir_xattr(struct ovl_fs *ofs, const struct path *path, 42743d193f8SMiklos Szeredi enum ovl_xattr ox); 4282d343087SAl Viro bool ovl_path_check_origin_xattr(struct ovl_fs *ofs, const struct path *path); 429dad7017aSChristian Brauner 430dad7017aSChristian Brauner static inline bool ovl_check_origin_xattr(struct ovl_fs *ofs, 431dad7017aSChristian Brauner struct dentry *upperdentry) 432dad7017aSChristian Brauner { 433dad7017aSChristian Brauner struct path upperpath = { 434dad7017aSChristian Brauner .dentry = upperdentry, 435dad7017aSChristian Brauner .mnt = ovl_upper_mnt(ofs), 436dad7017aSChristian Brauner }; 437dad7017aSChristian Brauner return ovl_path_check_origin_xattr(ofs, &upperpath); 438dad7017aSChristian Brauner } 439dad7017aSChristian Brauner 440a0c236b1SAmir Goldstein int ovl_check_setxattr(struct ovl_fs *ofs, struct dentry *upperdentry, 44143d193f8SMiklos Szeredi enum ovl_xattr ox, const void *value, size_t size, 442f3a15685SAmir Goldstein int xerr); 443f3a15685SAmir Goldstein int ovl_set_impure(struct dentry *dentry, struct dentry *upperdentry); 444ad0af710SAmir Goldstein bool ovl_inuse_trylock(struct dentry *dentry); 445ad0af710SAmir Goldstein void ovl_inuse_unlock(struct dentry *dentry); 446146d62e5SAmir Goldstein bool ovl_is_inuse(struct dentry *dentry); 44724b33ee1SAmir Goldstein bool ovl_need_index(struct dentry *dentry); 4480e32992fSAmir Goldstein int ovl_nlink_start(struct dentry *dentry); 4490e32992fSAmir Goldstein void ovl_nlink_end(struct dentry *dentry); 4505820dc08SAmir Goldstein int ovl_lock_rename_workdir(struct dentry *workdir, struct dentry *upperdir); 4512d343087SAl Viro int ovl_check_metacopy_xattr(struct ovl_fs *ofs, const struct path *path); 45267d756c2SVivek Goyal bool ovl_is_metacopy_dentry(struct dentry *dentry); 4532d343087SAl Viro char *ovl_get_redirect_xattr(struct ovl_fs *ofs, const struct path *path, int padding); 454335d3fc5SSargun Dhillon int ovl_sync_status(struct ovl_fs *ofs); 455f3a15685SAmir Goldstein 45665cd913eSAmir Goldstein static inline void ovl_set_flag(unsigned long flag, struct inode *inode) 45765cd913eSAmir Goldstein { 45865cd913eSAmir Goldstein set_bit(flag, &OVL_I(inode)->flags); 45965cd913eSAmir Goldstein } 46065cd913eSAmir Goldstein 46165cd913eSAmir Goldstein static inline void ovl_clear_flag(unsigned long flag, struct inode *inode) 46265cd913eSAmir Goldstein { 46365cd913eSAmir Goldstein clear_bit(flag, &OVL_I(inode)->flags); 46465cd913eSAmir Goldstein } 46565cd913eSAmir Goldstein 46665cd913eSAmir Goldstein static inline bool ovl_test_flag(unsigned long flag, struct inode *inode) 46765cd913eSAmir Goldstein { 46865cd913eSAmir Goldstein return test_bit(flag, &OVL_I(inode)->flags); 46965cd913eSAmir Goldstein } 47065cd913eSAmir Goldstein 471610afc0bSMiklos Szeredi static inline bool ovl_is_impuredir(struct super_block *sb, 472dad7017aSChristian Brauner struct dentry *upperdentry) 473f3a15685SAmir Goldstein { 474dad7017aSChristian Brauner struct ovl_fs *ofs = OVL_FS(sb); 475dad7017aSChristian Brauner struct path upperpath = { 476dad7017aSChristian Brauner .dentry = upperdentry, 477dad7017aSChristian Brauner .mnt = ovl_upper_mnt(ofs), 478dad7017aSChristian Brauner }; 479dad7017aSChristian Brauner 480dad7017aSChristian Brauner return ovl_path_check_dir_xattr(ofs, &upperpath, OVL_XATTR_IMPURE); 481f3a15685SAmir Goldstein } 482f3a15685SAmir Goldstein 483926e94d7SAmir Goldstein /* 484926e94d7SAmir Goldstein * With xino=auto, we do best effort to keep all inodes on same st_dev and 485926e94d7SAmir Goldstein * d_ino consistent with st_ino. 486926e94d7SAmir Goldstein * With xino=on, we do the same effort but we warn if we failed. 487926e94d7SAmir Goldstein */ 488926e94d7SAmir Goldstein static inline bool ovl_xino_warn(struct super_block *sb) 489926e94d7SAmir Goldstein { 490926e94d7SAmir Goldstein return OVL_FS(sb)->config.xino == OVL_XINO_ON; 491926e94d7SAmir Goldstein } 492926e94d7SAmir Goldstein 4930f831ec8SAmir Goldstein /* All layers on same fs? */ 4940f831ec8SAmir Goldstein static inline bool ovl_same_fs(struct super_block *sb) 4950f831ec8SAmir Goldstein { 4960f831ec8SAmir Goldstein return OVL_FS(sb)->xino_mode == 0; 4970f831ec8SAmir Goldstein } 4980f831ec8SAmir Goldstein 4990f831ec8SAmir Goldstein /* All overlay inodes have same st_dev? */ 5000f831ec8SAmir Goldstein static inline bool ovl_same_dev(struct super_block *sb) 5010f831ec8SAmir Goldstein { 5020f831ec8SAmir Goldstein return OVL_FS(sb)->xino_mode >= 0; 5030f831ec8SAmir Goldstein } 5040f831ec8SAmir Goldstein 505e487d889SAmir Goldstein static inline unsigned int ovl_xino_bits(struct super_block *sb) 506e487d889SAmir Goldstein { 5070f831ec8SAmir Goldstein return ovl_same_dev(sb) ? OVL_FS(sb)->xino_mode : 0; 508e487d889SAmir Goldstein } 509e487d889SAmir Goldstein 510531d3040SAmir Goldstein static inline void ovl_inode_lock(struct inode *inode) 511531d3040SAmir Goldstein { 512531d3040SAmir Goldstein mutex_lock(&OVL_I(inode)->lock); 513531d3040SAmir Goldstein } 514531d3040SAmir Goldstein 515531d3040SAmir Goldstein static inline int ovl_inode_lock_interruptible(struct inode *inode) 5161e92e307SAmir Goldstein { 5171e92e307SAmir Goldstein return mutex_lock_interruptible(&OVL_I(inode)->lock); 5181e92e307SAmir Goldstein } 5191e92e307SAmir Goldstein 5201e92e307SAmir Goldstein static inline void ovl_inode_unlock(struct inode *inode) 5211e92e307SAmir Goldstein { 5221e92e307SAmir Goldstein mutex_unlock(&OVL_I(inode)->lock); 5231e92e307SAmir Goldstein } 5241e92e307SAmir Goldstein 525e9be9d5eSMiklos Szeredi 526bbb1e54dSMiklos Szeredi /* namei.c */ 527cbe7fba8SAmir Goldstein int ovl_check_fb_len(struct ovl_fb *fb, int fb_len); 528cbe7fba8SAmir Goldstein 529cbe7fba8SAmir Goldstein static inline int ovl_check_fh_len(struct ovl_fh *fh, int fh_len) 530cbe7fba8SAmir Goldstein { 531522f6e6cSAmir Goldstein if (fh_len < sizeof(struct ovl_fh)) 532522f6e6cSAmir Goldstein return -EINVAL; 533522f6e6cSAmir Goldstein 534cbe7fba8SAmir Goldstein return ovl_check_fb_len(&fh->fb, fh_len - OVL_FH_WIRE_OFFSET); 535cbe7fba8SAmir Goldstein } 536cbe7fba8SAmir Goldstein 5371cdb0cb6SPavel Tikhomirov struct dentry *ovl_decode_real_fh(struct ovl_fs *ofs, struct ovl_fh *fh, 5381cdb0cb6SPavel Tikhomirov struct vfsmount *mnt, bool connected); 5398a22efa1SAmir Goldstein int ovl_check_origin_fh(struct ovl_fs *ofs, struct ovl_fh *fh, bool connected, 540f941866fSAmir Goldstein struct dentry *upperdentry, struct ovl_path **stackp); 541610afc0bSMiklos Szeredi int ovl_verify_set_fh(struct ovl_fs *ofs, struct dentry *dentry, 54243d193f8SMiklos Szeredi enum ovl_xattr ox, struct dentry *real, bool is_upper, 543610afc0bSMiklos Szeredi bool set); 5448ea28765SAmir Goldstein struct dentry *ovl_index_upper(struct ovl_fs *ofs, struct dentry *index, 5458ea28765SAmir Goldstein bool connected); 5461eff1a1dSAmir Goldstein int ovl_verify_index(struct ovl_fs *ofs, struct dentry *index); 5471cdb0cb6SPavel Tikhomirov int ovl_get_index_name(struct ovl_fs *ofs, struct dentry *origin, 5481cdb0cb6SPavel Tikhomirov struct qstr *name); 54991ffe7beSAmir Goldstein struct dentry *ovl_get_index_fh(struct ovl_fs *ofs, struct ovl_fh *fh); 55006170154SAmir Goldstein struct dentry *ovl_lookup_index(struct ovl_fs *ofs, struct dentry *upper, 55106170154SAmir Goldstein struct dentry *origin, bool verify); 552bbb1e54dSMiklos Szeredi int ovl_path_next(int idx, struct dentry *dentry, struct path *path); 5531eff1a1dSAmir Goldstein struct dentry *ovl_lookup(struct inode *dir, struct dentry *dentry, 5541eff1a1dSAmir Goldstein unsigned int flags); 555bbb1e54dSMiklos Szeredi bool ovl_lower_positive(struct dentry *dentry); 556e9be9d5eSMiklos Szeredi 557610afc0bSMiklos Szeredi static inline int ovl_verify_origin(struct ovl_fs *ofs, struct dentry *upper, 55805122443SAmir Goldstein struct dentry *origin, bool set) 55905122443SAmir Goldstein { 560610afc0bSMiklos Szeredi return ovl_verify_set_fh(ofs, upper, OVL_XATTR_ORIGIN, origin, 561610afc0bSMiklos Szeredi false, set); 56205122443SAmir Goldstein } 56305122443SAmir Goldstein 564610afc0bSMiklos Szeredi static inline int ovl_verify_upper(struct ovl_fs *ofs, struct dentry *index, 565ad1d615cSAmir Goldstein struct dentry *upper, bool set) 566ad1d615cSAmir Goldstein { 567610afc0bSMiklos Szeredi return ovl_verify_set_fh(ofs, index, OVL_XATTR_UPPER, upper, true, set); 568ad1d615cSAmir Goldstein } 569ad1d615cSAmir Goldstein 570e9be9d5eSMiklos Szeredi /* readdir.c */ 571e9be9d5eSMiklos Szeredi extern const struct file_operations ovl_dir_operations; 57261536bedSAmir Goldstein struct file *ovl_dir_real_file(const struct file *file, bool want_upper); 573e9be9d5eSMiklos Szeredi int ovl_check_empty_dir(struct dentry *dentry, struct list_head *list); 574576bb263SChristian Brauner void ovl_cleanup_whiteouts(struct ovl_fs *ofs, struct dentry *upper, 575576bb263SChristian Brauner struct list_head *list); 576e9be9d5eSMiklos Szeredi void ovl_cache_free(struct list_head *list); 5774edb83bbSMiklos Szeredi void ovl_dir_cache_free(struct inode *inode); 5782d343087SAl Viro int ovl_check_d_type_supported(const struct path *realpath); 579576bb263SChristian Brauner int ovl_workdir_cleanup(struct ovl_fs *ofs, struct inode *dir, 580576bb263SChristian Brauner struct vfsmount *mnt, struct dentry *dentry, int level); 5811eff1a1dSAmir Goldstein int ovl_indexdir_cleanup(struct ovl_fs *ofs); 582e9be9d5eSMiklos Szeredi 58365cd913eSAmir Goldstein /* 58465cd913eSAmir Goldstein * Can we iterate real dir directly? 58565cd913eSAmir Goldstein * 58665cd913eSAmir Goldstein * Non-merge dir may contain whiteouts from a time it was a merge upper, before 58765cd913eSAmir Goldstein * lower dir was removed under it and possibly before it was rotated from upper 58865cd913eSAmir Goldstein * to lower layer. 58965cd913eSAmir Goldstein */ 5901fa9c5c5SMiklos Szeredi static inline bool ovl_dir_is_real(struct inode *dir) 59165cd913eSAmir Goldstein { 5921fa9c5c5SMiklos Szeredi return !ovl_test_flag(OVL_WHITEOUTS, dir); 59365cd913eSAmir Goldstein } 59465cd913eSAmir Goldstein 595e9be9d5eSMiklos Szeredi /* inode.c */ 5965f8415d6SAmir Goldstein int ovl_set_nlink_upper(struct dentry *dentry); 5975f8415d6SAmir Goldstein int ovl_set_nlink_lower(struct dentry *dentry); 598610afc0bSMiklos Szeredi unsigned int ovl_get_nlink(struct ovl_fs *ofs, struct dentry *lowerdentry, 599caf70cb2SAmir Goldstein struct dentry *upperdentry, 600caf70cb2SAmir Goldstein unsigned int fallback); 601c1632a0fSChristian Brauner int ovl_setattr(struct mnt_idmap *idmap, struct dentry *dentry, 602549c7297SChristian Brauner struct iattr *attr); 603b74d24f7SChristian Brauner int ovl_getattr(struct mnt_idmap *idmap, const struct path *path, 604549c7297SChristian Brauner struct kstat *stat, u32 request_mask, unsigned int flags); 6054609e1f1SChristian Brauner int ovl_permission(struct mnt_idmap *idmap, struct inode *inode, 606549c7297SChristian Brauner int mask); 6071d88f183SMiklos Szeredi int ovl_xattr_set(struct dentry *dentry, struct inode *inode, const char *name, 6081d88f183SMiklos Szeredi const void *value, size_t size, int flags); 6091d88f183SMiklos Szeredi int ovl_xattr_get(struct dentry *dentry, struct inode *inode, const char *name, 6100eb45fc3SAndreas Gruenbacher void *value, size_t size); 611e9be9d5eSMiklos Szeredi ssize_t ovl_listxattr(struct dentry *dentry, char *list, size_t size); 612ded53656SYang Xu 613ded53656SYang Xu #ifdef CONFIG_FS_POSIX_ACL 61477435322SChristian Brauner struct posix_acl *do_ovl_get_acl(struct mnt_idmap *idmap, 6156c0a8bfbSChristian Brauner struct inode *inode, int type, 6166c0a8bfbSChristian Brauner bool rcu, bool noperm); 6176c0a8bfbSChristian Brauner static inline struct posix_acl *ovl_get_inode_acl(struct inode *inode, int type, 6186c0a8bfbSChristian Brauner bool rcu) 6196c0a8bfbSChristian Brauner { 62077435322SChristian Brauner return do_ovl_get_acl(&nop_mnt_idmap, inode, type, rcu, true); 6216c0a8bfbSChristian Brauner } 62277435322SChristian Brauner static inline struct posix_acl *ovl_get_acl(struct mnt_idmap *idmap, 6236c0a8bfbSChristian Brauner struct dentry *dentry, int type) 6246c0a8bfbSChristian Brauner { 62577435322SChristian Brauner return do_ovl_get_acl(idmap, d_inode(dentry), type, false, false); 6266c0a8bfbSChristian Brauner } 62713e83a49SChristian Brauner int ovl_set_acl(struct mnt_idmap *idmap, struct dentry *dentry, 6280e641857SChristian Brauner struct posix_acl *acl, int type); 62931acceb9SChristian Brauner struct posix_acl *ovl_get_acl_path(const struct path *path, 63031acceb9SChristian Brauner const char *acl_name, bool noperm); 631ded53656SYang Xu #else 6326c0a8bfbSChristian Brauner #define ovl_get_inode_acl NULL 633ded53656SYang Xu #define ovl_get_acl NULL 6340e641857SChristian Brauner #define ovl_set_acl NULL 63531acceb9SChristian Brauner static inline struct posix_acl *ovl_get_acl_path(const struct path *path, 63631acceb9SChristian Brauner const char *acl_name, 63731acceb9SChristian Brauner bool noperm) 63831acceb9SChristian Brauner { 63931acceb9SChristian Brauner return NULL; 64031acceb9SChristian Brauner } 641ded53656SYang Xu #endif 642ded53656SYang Xu 64395582b00SDeepa Dinamani int ovl_update_time(struct inode *inode, struct timespec64 *ts, int flags); 644610afc0bSMiklos Szeredi bool ovl_is_private_xattr(struct super_block *sb, const char *name); 645e9be9d5eSMiklos Szeredi 646ac6a52ebSVivek Goyal struct ovl_inode_params { 64701b39dccSAmir Goldstein struct inode *newinode; 648ac6a52ebSVivek Goyal struct dentry *upperdentry; 649ac6a52ebSVivek Goyal struct ovl_path *lowerpath; 65074c6e384SMiklos Szeredi bool index; 651ac6a52ebSVivek Goyal unsigned int numlower; 6529cec54c8SVivek Goyal char *redirect; 6532664bd08SVivek Goyal struct dentry *lowerdata; 654ac6a52ebSVivek Goyal }; 65562c832edSAmir Goldstein void ovl_inode_init(struct inode *inode, struct ovl_inode_params *oip, 65662c832edSAmir Goldstein unsigned long ino, int fsid); 657ca4c8a3aSMiklos Szeredi struct inode *ovl_new_inode(struct super_block *sb, umode_t mode, dev_t rdev); 6584b91c30aSAmir Goldstein struct inode *ovl_lookup_inode(struct super_block *sb, struct dentry *real, 6594b91c30aSAmir Goldstein bool is_upper); 660146d62e5SAmir Goldstein bool ovl_lookup_trap_inode(struct super_block *sb, struct dentry *dir); 661146d62e5SAmir Goldstein struct inode *ovl_get_trap_inode(struct super_block *sb, struct dentry *dir); 662ac6a52ebSVivek Goyal struct inode *ovl_get_inode(struct super_block *sb, 663ac6a52ebSVivek Goyal struct ovl_inode_params *oip); 6642878dffcSChristian Brauner void ovl_copyattr(struct inode *to); 665e9be9d5eSMiklos Szeredi 66672db8211SAmir Goldstein /* vfs inode flags copied from real to ovl inode */ 66772db8211SAmir Goldstein #define OVL_COPY_I_FLAGS_MASK (S_SYNC | S_NOATIME | S_APPEND | S_IMMUTABLE) 668096a218aSAmir Goldstein /* vfs inode flags read from overlay.protattr xattr to ovl inode */ 669096a218aSAmir Goldstein #define OVL_PROT_I_FLAGS_MASK (S_APPEND | S_IMMUTABLE) 67072db8211SAmir Goldstein 67172db8211SAmir Goldstein /* 67272db8211SAmir Goldstein * fileattr flags copied from lower to upper inode on copy up. 673096a218aSAmir Goldstein * We cannot copy up immutable/append-only flags, because that would prevent 674096a218aSAmir Goldstein * linking temp inode to upper dir, so we store them in xattr instead. 67572db8211SAmir Goldstein */ 67672db8211SAmir Goldstein #define OVL_COPY_FS_FLAGS_MASK (FS_SYNC_FL | FS_NOATIME_FL) 67772db8211SAmir Goldstein #define OVL_COPY_FSX_FLAGS_MASK (FS_XFLAG_SYNC | FS_XFLAG_NOATIME) 678096a218aSAmir Goldstein #define OVL_PROT_FS_FLAGS_MASK (FS_APPEND_FL | FS_IMMUTABLE_FL) 679096a218aSAmir Goldstein #define OVL_PROT_FSX_FLAGS_MASK (FS_XFLAG_APPEND | FS_XFLAG_IMMUTABLE) 680096a218aSAmir Goldstein 681096a218aSAmir Goldstein void ovl_check_protattr(struct inode *inode, struct dentry *upper); 682096a218aSAmir Goldstein int ovl_set_protattr(struct inode *inode, struct dentry *upper, 683096a218aSAmir Goldstein struct fileattr *fa); 68472db8211SAmir Goldstein 6854f357295SMiklos Szeredi static inline void ovl_copyflags(struct inode *from, struct inode *to) 6864f357295SMiklos Szeredi { 68772db8211SAmir Goldstein unsigned int mask = OVL_COPY_I_FLAGS_MASK; 6884f357295SMiklos Szeredi 6894f357295SMiklos Szeredi inode_set_flags(to, from->i_flags & mask, mask); 6904f357295SMiklos Szeredi } 6914f357295SMiklos Szeredi 692e9be9d5eSMiklos Szeredi /* dir.c */ 693e9be9d5eSMiklos Szeredi extern const struct inode_operations ovl_dir_inode_operations; 694c21c839bSChengguang Xu int ovl_cleanup_and_whiteout(struct ovl_fs *ofs, struct inode *dir, 695e7dd0e71SAmir Goldstein struct dentry *dentry); 696471ec5dcSAmir Goldstein struct ovl_cattr { 69732a3d848SAl Viro dev_t rdev; 69832a3d848SAl Viro umode_t mode; 69932a3d848SAl Viro const char *link; 700471ec5dcSAmir Goldstein struct dentry *hardlink; 70132a3d848SAl Viro }; 702471ec5dcSAmir Goldstein 703471ec5dcSAmir Goldstein #define OVL_CATTR(m) (&(struct ovl_cattr) { .mode = (m) }) 704471ec5dcSAmir Goldstein 705576bb263SChristian Brauner int ovl_mkdir_real(struct ovl_fs *ofs, struct inode *dir, 706576bb263SChristian Brauner struct dentry **newdentry, umode_t mode); 707576bb263SChristian Brauner struct dentry *ovl_create_real(struct ovl_fs *ofs, 708576bb263SChristian Brauner struct inode *dir, struct dentry *newdentry, 709471ec5dcSAmir Goldstein struct ovl_cattr *attr); 710576bb263SChristian Brauner int ovl_cleanup(struct ovl_fs *ofs, struct inode *dir, struct dentry *dentry); 711576bb263SChristian Brauner struct dentry *ovl_lookup_temp(struct ovl_fs *ofs, struct dentry *workdir); 712576bb263SChristian Brauner struct dentry *ovl_create_temp(struct ovl_fs *ofs, struct dentry *workdir, 713576bb263SChristian Brauner struct ovl_cattr *attr); 714e9be9d5eSMiklos Szeredi 715d1d04ef8SMiklos Szeredi /* file.c */ 716d1d04ef8SMiklos Szeredi extern const struct file_operations ovl_file_operations; 7172406a307SJiufei Xue int __init ovl_aio_request_cache_init(void); 7182406a307SJiufei Xue void ovl_aio_request_cache_destroy(void); 7192d343087SAl Viro int ovl_real_fileattr_get(const struct path *realpath, struct fileattr *fa); 7202d343087SAl Viro int ovl_real_fileattr_set(const struct path *realpath, struct fileattr *fa); 72166dbfabfSMiklos Szeredi int ovl_fileattr_get(struct dentry *dentry, struct fileattr *fa); 7228782a9aeSChristian Brauner int ovl_fileattr_set(struct mnt_idmap *idmap, 72366dbfabfSMiklos Szeredi struct dentry *dentry, struct fileattr *fa); 724d1d04ef8SMiklos Szeredi 725e9be9d5eSMiklos Szeredi /* copy_up.c */ 726e9be9d5eSMiklos Szeredi int ovl_copy_up(struct dentry *dentry); 727d1e6f6a9SVivek Goyal int ovl_copy_up_with_data(struct dentry *dentry); 7283428030dSAmir Goldstein int ovl_maybe_copy_up(struct dentry *dentry, int flags); 7292d343087SAl Viro int ovl_copy_xattr(struct super_block *sb, const struct path *path, struct dentry *new); 7305272eaf3SChristian Brauner int ovl_set_attr(struct ovl_fs *ofs, struct dentry *upper, struct kstat *stat); 7311cdb0cb6SPavel Tikhomirov struct ovl_fh *ovl_encode_real_fh(struct ovl_fs *ofs, struct dentry *real, 7321cdb0cb6SPavel Tikhomirov bool is_upper); 733a0c236b1SAmir Goldstein int ovl_set_origin(struct ovl_fs *ofs, struct dentry *lower, 734a0c236b1SAmir Goldstein struct dentry *upper); 7358ed5eec9SAmir Goldstein 7368ed5eec9SAmir Goldstein /* export.c */ 7378ed5eec9SAmir Goldstein extern const struct export_operations ovl_export_operations; 738