^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) /* SPDX-License-Identifier: GPL-2.0-only */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) * Copyright (C) 2011 Novell Inc.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) #include <linux/uuid.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) #include <linux/fs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #include "ovl_entry.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #undef pr_fmt
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #define pr_fmt(fmt) "overlayfs: " fmt
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) enum ovl_path_type {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) __OVL_PATH_UPPER = (1 << 0),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) __OVL_PATH_MERGE = (1 << 1),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) __OVL_PATH_ORIGIN = (1 << 2),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) #define OVL_TYPE_UPPER(type) ((type) & __OVL_PATH_UPPER)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) #define OVL_TYPE_MERGE(type) ((type) & __OVL_PATH_MERGE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) #define OVL_TYPE_ORIGIN(type) ((type) & __OVL_PATH_ORIGIN)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) #define OVL_XATTR_PREFIX XATTR_TRUSTED_PREFIX "overlay."
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) enum ovl_xattr {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) OVL_XATTR_OPAQUE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) OVL_XATTR_REDIRECT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) OVL_XATTR_ORIGIN,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) OVL_XATTR_IMPURE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) OVL_XATTR_NLINK,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) OVL_XATTR_UPPER,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) OVL_XATTR_METACOPY,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) enum ovl_inode_flag {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) /* Pure upper dir that may contain non pure upper entries */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) OVL_IMPURE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) /* Non-merge dir that may contain whiteout entries */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) OVL_WHITEOUTS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) OVL_INDEX,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) OVL_UPPERDATA,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) /* Inode number will remain constant over copy up. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) OVL_CONST_INO,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) enum ovl_entry_flag {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) OVL_E_UPPER_ALIAS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) OVL_E_OPAQUE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) OVL_E_CONNECTED,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) enum {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) OVL_XINO_OFF,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) OVL_XINO_AUTO,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) OVL_XINO_ON,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) * The tuple (fh,uuid) is a universal unique identifier for a copy up origin,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) * where:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) * origin.fh - exported file handle of the lower file
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) * origin.uuid - uuid of the lower filesystem
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) #define OVL_FH_VERSION 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) #define OVL_FH_MAGIC 0xfb
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) /* CPU byte order required for fid decoding: */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) #define OVL_FH_FLAG_BIG_ENDIAN (1 << 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) #define OVL_FH_FLAG_ANY_ENDIAN (1 << 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) /* Is the real inode encoded in fid an upper inode? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) #define OVL_FH_FLAG_PATH_UPPER (1 << 2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) #define OVL_FH_FLAG_ALL (OVL_FH_FLAG_BIG_ENDIAN | OVL_FH_FLAG_ANY_ENDIAN | \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) OVL_FH_FLAG_PATH_UPPER)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) #if defined(__LITTLE_ENDIAN)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) #define OVL_FH_FLAG_CPU_ENDIAN 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) #elif defined(__BIG_ENDIAN)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) #define OVL_FH_FLAG_CPU_ENDIAN OVL_FH_FLAG_BIG_ENDIAN
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) #error Endianness not defined
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) /* The type used to be returned by overlay exportfs for misaligned fid */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) #define OVL_FILEID_V0 0xfb
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) /* The type returned by overlay exportfs for 32bit aligned fid */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) #define OVL_FILEID_V1 0xf8
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) /* On-disk format for "origin" file handle */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) struct ovl_fb {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) u8 version; /* 0 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) u8 magic; /* 0xfb */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) u8 len; /* size of this header + size of fid */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) u8 flags; /* OVL_FH_FLAG_* */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) u8 type; /* fid_type of fid */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) uuid_t uuid; /* uuid of filesystem */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) u32 fid[]; /* file identifier should be 32bit aligned in-memory */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) } __packed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) /* In-memory and on-wire format for overlay file handle */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) struct ovl_fh {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) u8 padding[3]; /* make sure fb.fid is 32bit aligned */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) union {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) struct ovl_fb fb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) u8 buf[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) } __packed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) #define OVL_FH_WIRE_OFFSET offsetof(struct ovl_fh, fb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) #define OVL_FH_LEN(fh) (OVL_FH_WIRE_OFFSET + (fh)->fb.len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) #define OVL_FH_FID_OFFSET (OVL_FH_WIRE_OFFSET + \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) offsetof(struct ovl_fb, fid))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) extern const char *ovl_xattr_table[];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) static inline const char *ovl_xattr(struct ovl_fs *ofs, enum ovl_xattr ox)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) return ovl_xattr_table[ox];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) static inline int ovl_do_rmdir(struct inode *dir, struct dentry *dentry)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) int err = vfs_rmdir(dir, dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) pr_debug("rmdir(%pd2) = %i\n", dentry, err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) static inline int ovl_do_unlink(struct inode *dir, struct dentry *dentry)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) int err = vfs_unlink(dir, dentry, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) pr_debug("unlink(%pd2) = %i\n", dentry, err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) static inline int ovl_do_link(struct dentry *old_dentry, struct inode *dir,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) struct dentry *new_dentry)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) int err = vfs_link(old_dentry, dir, new_dentry, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) pr_debug("link(%pd2, %pd2) = %i\n", old_dentry, new_dentry, err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) static inline int ovl_do_create(struct inode *dir, struct dentry *dentry,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) umode_t mode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) int err = vfs_create(dir, dentry, mode, true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) pr_debug("create(%pd2, 0%o) = %i\n", dentry, mode, err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) static inline int ovl_do_mkdir(struct inode *dir, struct dentry *dentry,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) umode_t mode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) int err = vfs_mkdir(dir, dentry, mode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) pr_debug("mkdir(%pd2, 0%o) = %i\n", dentry, mode, err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) static inline int ovl_do_mknod(struct inode *dir, struct dentry *dentry,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) umode_t mode, dev_t dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) int err = vfs_mknod(dir, dentry, mode, dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) pr_debug("mknod(%pd2, 0%o, 0%o) = %i\n", dentry, mode, dev, err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) static inline int ovl_do_symlink(struct inode *dir, struct dentry *dentry,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) const char *oldname)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) int err = vfs_symlink(dir, dentry, oldname);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) pr_debug("symlink(\"%s\", %pd2) = %i\n", oldname, dentry, err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) static inline ssize_t ovl_do_getxattr(struct ovl_fs *ofs, struct dentry *dentry,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) enum ovl_xattr ox, void *value,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) size_t size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) const char *name = ovl_xattr(ofs, ox);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) struct inode *ip = d_inode(dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) return __vfs_getxattr(dentry, ip, name, value, size, XATTR_NOSECURITY);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) static inline int ovl_do_setxattr(struct ovl_fs *ofs, struct dentry *dentry,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) enum ovl_xattr ox, const void *value,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) size_t size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) const char *name = ovl_xattr(ofs, ox);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) int err = vfs_setxattr(dentry, name, value, size, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) pr_debug("setxattr(%pd2, \"%s\", \"%*pE\", %zu, 0) = %i\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) dentry, name, min((int)size, 48), value, size, err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) static inline int ovl_do_removexattr(struct ovl_fs *ofs, struct dentry *dentry,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) enum ovl_xattr ox)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) const char *name = ovl_xattr(ofs, ox);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) int err = vfs_removexattr(dentry, name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) pr_debug("removexattr(%pd2, \"%s\") = %i\n", dentry, name, err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) static inline int ovl_do_rename(struct inode *olddir, struct dentry *olddentry,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) struct inode *newdir, struct dentry *newdentry,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) unsigned int flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) pr_debug("rename(%pd2, %pd2, 0x%x)\n", olddentry, newdentry, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) err = vfs_rename(olddir, olddentry, newdir, newdentry, NULL, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) if (err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) pr_debug("...rename(%pd2, %pd2, ...) = %i\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) olddentry, newdentry, err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) static inline int ovl_do_whiteout(struct inode *dir, struct dentry *dentry)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) int err = vfs_whiteout(dir, dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) pr_debug("whiteout(%pd2) = %i\n", dentry, err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) static inline struct dentry *ovl_do_tmpfile(struct dentry *dentry, umode_t mode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) struct dentry *ret = vfs_tmpfile(dentry, mode, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) int err = PTR_ERR_OR_ZERO(ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) pr_debug("tmpfile(%pd2, 0%o) = %i\n", dentry, mode, err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) static inline bool ovl_open_flags_need_copy_up(int flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) if (!flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) return ((OPEN_FMODE(flags) & FMODE_WRITE) || (flags & O_TRUNC));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) /* util.c */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) int ovl_want_write(struct dentry *dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) void ovl_drop_write(struct dentry *dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) struct dentry *ovl_workdir(struct dentry *dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) const struct cred *ovl_override_creds(struct super_block *sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) void ovl_revert_creds(struct super_block *sb, const struct cred *oldcred);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) int ovl_can_decode_fh(struct super_block *sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) struct dentry *ovl_indexdir(struct super_block *sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) bool ovl_index_all(struct super_block *sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) bool ovl_verify_lower(struct super_block *sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) struct ovl_entry *ovl_alloc_entry(unsigned int numlower);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) bool ovl_dentry_remote(struct dentry *dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) void ovl_dentry_update_reval(struct dentry *dentry, struct dentry *upperdentry,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) unsigned int mask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) bool ovl_dentry_weird(struct dentry *dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) enum ovl_path_type ovl_path_type(struct dentry *dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) void ovl_path_upper(struct dentry *dentry, struct path *path);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) void ovl_path_lower(struct dentry *dentry, struct path *path);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) void ovl_path_lowerdata(struct dentry *dentry, struct path *path);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) enum ovl_path_type ovl_path_real(struct dentry *dentry, struct path *path);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) struct dentry *ovl_dentry_upper(struct dentry *dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) struct dentry *ovl_dentry_lower(struct dentry *dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) struct dentry *ovl_dentry_lowerdata(struct dentry *dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) const struct ovl_layer *ovl_layer_lower(struct dentry *dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) struct dentry *ovl_dentry_real(struct dentry *dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) struct dentry *ovl_i_dentry_upper(struct inode *inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) struct inode *ovl_inode_upper(struct inode *inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) struct inode *ovl_inode_lower(struct inode *inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) struct inode *ovl_inode_lowerdata(struct inode *inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) struct inode *ovl_inode_real(struct inode *inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) struct inode *ovl_inode_realdata(struct inode *inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) struct ovl_dir_cache *ovl_dir_cache(struct inode *inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) void ovl_set_dir_cache(struct inode *inode, struct ovl_dir_cache *cache);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) void ovl_dentry_set_flag(unsigned long flag, struct dentry *dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) void ovl_dentry_clear_flag(unsigned long flag, struct dentry *dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) bool ovl_dentry_test_flag(unsigned long flag, struct dentry *dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) bool ovl_dentry_is_opaque(struct dentry *dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) bool ovl_dentry_is_whiteout(struct dentry *dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) void ovl_dentry_set_opaque(struct dentry *dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) bool ovl_dentry_has_upper_alias(struct dentry *dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) void ovl_dentry_set_upper_alias(struct dentry *dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) bool ovl_dentry_needs_data_copy_up(struct dentry *dentry, int flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) bool ovl_dentry_needs_data_copy_up_locked(struct dentry *dentry, int flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) bool ovl_has_upperdata(struct inode *inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) void ovl_set_upperdata(struct inode *inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) bool ovl_redirect_dir(struct super_block *sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) const char *ovl_dentry_get_redirect(struct dentry *dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) void ovl_dentry_set_redirect(struct dentry *dentry, const char *redirect);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) void ovl_inode_update(struct inode *inode, struct dentry *upperdentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) void ovl_dir_modified(struct dentry *dentry, bool impurity);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) u64 ovl_dentry_version_get(struct dentry *dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) bool ovl_is_whiteout(struct dentry *dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) struct file *ovl_path_open(struct path *path, int flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) int ovl_copy_up_start(struct dentry *dentry, int flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) void ovl_copy_up_end(struct dentry *dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) bool ovl_already_copied_up(struct dentry *dentry, int flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) bool ovl_check_origin_xattr(struct ovl_fs *ofs, struct dentry *dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) bool ovl_check_dir_xattr(struct super_block *sb, struct dentry *dentry,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) enum ovl_xattr ox);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) int ovl_check_setxattr(struct dentry *dentry, struct dentry *upperdentry,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) enum ovl_xattr ox, const void *value, size_t size,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) int xerr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) int ovl_set_impure(struct dentry *dentry, struct dentry *upperdentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) bool ovl_inuse_trylock(struct dentry *dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) void ovl_inuse_unlock(struct dentry *dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) bool ovl_is_inuse(struct dentry *dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) bool ovl_need_index(struct dentry *dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) int ovl_nlink_start(struct dentry *dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) void ovl_nlink_end(struct dentry *dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) int ovl_lock_rename_workdir(struct dentry *workdir, struct dentry *upperdir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) int ovl_check_metacopy_xattr(struct ovl_fs *ofs, struct dentry *dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) bool ovl_is_metacopy_dentry(struct dentry *dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) char *ovl_get_redirect_xattr(struct ovl_fs *ofs, struct dentry *dentry,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) int padding);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) int ovl_sync_status(struct ovl_fs *ofs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) static inline void ovl_set_flag(unsigned long flag, struct inode *inode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) set_bit(flag, &OVL_I(inode)->flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) static inline void ovl_clear_flag(unsigned long flag, struct inode *inode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) clear_bit(flag, &OVL_I(inode)->flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) static inline bool ovl_test_flag(unsigned long flag, struct inode *inode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) return test_bit(flag, &OVL_I(inode)->flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) static inline bool ovl_is_impuredir(struct super_block *sb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) struct dentry *dentry)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) return ovl_check_dir_xattr(sb, dentry, OVL_XATTR_IMPURE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) * With xino=auto, we do best effort to keep all inodes on same st_dev and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) * d_ino consistent with st_ino.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) * With xino=on, we do the same effort but we warn if we failed.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) static inline bool ovl_xino_warn(struct super_block *sb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) return OVL_FS(sb)->config.xino == OVL_XINO_ON;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) /* All layers on same fs? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) static inline bool ovl_same_fs(struct super_block *sb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) return OVL_FS(sb)->xino_mode == 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) /* All overlay inodes have same st_dev? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) static inline bool ovl_same_dev(struct super_block *sb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) return OVL_FS(sb)->xino_mode >= 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) static inline unsigned int ovl_xino_bits(struct super_block *sb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) return ovl_same_dev(sb) ? OVL_FS(sb)->xino_mode : 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) static inline void ovl_inode_lock(struct inode *inode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) mutex_lock(&OVL_I(inode)->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) static inline int ovl_inode_lock_interruptible(struct inode *inode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) return mutex_lock_interruptible(&OVL_I(inode)->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) static inline void ovl_inode_unlock(struct inode *inode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) mutex_unlock(&OVL_I(inode)->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) /* namei.c */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) int ovl_check_fb_len(struct ovl_fb *fb, int fb_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) static inline int ovl_check_fh_len(struct ovl_fh *fh, int fh_len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) if (fh_len < sizeof(struct ovl_fh))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) return ovl_check_fb_len(&fh->fb, fh_len - OVL_FH_WIRE_OFFSET);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) struct dentry *ovl_decode_real_fh(struct ovl_fh *fh, struct vfsmount *mnt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) bool connected);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) int ovl_check_origin_fh(struct ovl_fs *ofs, struct ovl_fh *fh, bool connected,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) struct dentry *upperdentry, struct ovl_path **stackp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) int ovl_verify_set_fh(struct ovl_fs *ofs, struct dentry *dentry,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) enum ovl_xattr ox, struct dentry *real, bool is_upper,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) bool set);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) struct dentry *ovl_index_upper(struct ovl_fs *ofs, struct dentry *index);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) int ovl_verify_index(struct ovl_fs *ofs, struct dentry *index);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) int ovl_get_index_name(struct dentry *origin, struct qstr *name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) struct dentry *ovl_get_index_fh(struct ovl_fs *ofs, struct ovl_fh *fh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) struct dentry *ovl_lookup_index(struct ovl_fs *ofs, struct dentry *upper,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) struct dentry *origin, bool verify);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) int ovl_path_next(int idx, struct dentry *dentry, struct path *path);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) struct dentry *ovl_lookup(struct inode *dir, struct dentry *dentry,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) unsigned int flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) bool ovl_lower_positive(struct dentry *dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) static inline int ovl_verify_origin(struct ovl_fs *ofs, struct dentry *upper,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) struct dentry *origin, bool set)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) return ovl_verify_set_fh(ofs, upper, OVL_XATTR_ORIGIN, origin,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) false, set);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) static inline int ovl_verify_upper(struct ovl_fs *ofs, struct dentry *index,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) struct dentry *upper, bool set)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) return ovl_verify_set_fh(ofs, index, OVL_XATTR_UPPER, upper, true, set);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) /* readdir.c */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) extern const struct file_operations ovl_dir_operations;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) struct file *ovl_dir_real_file(const struct file *file, bool want_upper);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) int ovl_check_empty_dir(struct dentry *dentry, struct list_head *list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) void ovl_cleanup_whiteouts(struct dentry *upper, struct list_head *list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) void ovl_cache_free(struct list_head *list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) void ovl_dir_cache_free(struct inode *inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) int ovl_check_d_type_supported(struct path *realpath);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) int ovl_workdir_cleanup(struct inode *dir, struct vfsmount *mnt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) struct dentry *dentry, int level);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) int ovl_indexdir_cleanup(struct ovl_fs *ofs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) * Can we iterate real dir directly?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) * Non-merge dir may contain whiteouts from a time it was a merge upper, before
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) * lower dir was removed under it and possibly before it was rotated from upper
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) * to lower layer.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) static inline bool ovl_dir_is_real(struct dentry *dir)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) return !ovl_test_flag(OVL_WHITEOUTS, d_inode(dir));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) /* inode.c */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) int ovl_set_nlink_upper(struct dentry *dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) int ovl_set_nlink_lower(struct dentry *dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) unsigned int ovl_get_nlink(struct ovl_fs *ofs, struct dentry *lowerdentry,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) struct dentry *upperdentry,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) unsigned int fallback);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) int ovl_setattr(struct dentry *dentry, struct iattr *attr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) int ovl_getattr(const struct path *path, struct kstat *stat,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) u32 request_mask, unsigned int flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) int ovl_permission(struct inode *inode, int mask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) int ovl_xattr_set(struct dentry *dentry, struct inode *inode, const char *name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) const void *value, size_t size, int flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) int ovl_xattr_get(struct dentry *dentry, struct inode *inode, const char *name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) void *value, size_t size, int flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) ssize_t ovl_listxattr(struct dentry *dentry, char *list, size_t size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) struct posix_acl *ovl_get_acl(struct inode *inode, int type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) int ovl_update_time(struct inode *inode, struct timespec64 *ts, int flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) bool ovl_is_private_xattr(struct super_block *sb, const char *name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) struct ovl_inode_params {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) struct inode *newinode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) struct dentry *upperdentry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) struct ovl_path *lowerpath;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) bool index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) unsigned int numlower;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) char *redirect;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) struct dentry *lowerdata;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) void ovl_inode_init(struct inode *inode, struct ovl_inode_params *oip,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) unsigned long ino, int fsid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) struct inode *ovl_new_inode(struct super_block *sb, umode_t mode, dev_t rdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) struct inode *ovl_lookup_inode(struct super_block *sb, struct dentry *real,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) bool is_upper);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) bool ovl_lookup_trap_inode(struct super_block *sb, struct dentry *dir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) struct inode *ovl_get_trap_inode(struct super_block *sb, struct dentry *dir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) struct inode *ovl_get_inode(struct super_block *sb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) struct ovl_inode_params *oip);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) static inline void ovl_copyattr(struct inode *from, struct inode *to)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) to->i_uid = from->i_uid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) to->i_gid = from->i_gid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) to->i_mode = from->i_mode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) to->i_atime = from->i_atime;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) to->i_mtime = from->i_mtime;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) to->i_ctime = from->i_ctime;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) i_size_write(to, i_size_read(from));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) static inline void ovl_copyflags(struct inode *from, struct inode *to)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) unsigned int mask = S_SYNC | S_IMMUTABLE | S_APPEND | S_NOATIME;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) inode_set_flags(to, from->i_flags & mask, mask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) /* dir.c */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) extern const struct inode_operations ovl_dir_inode_operations;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514) int ovl_cleanup_and_whiteout(struct ovl_fs *ofs, struct inode *dir,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) struct dentry *dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) struct ovl_cattr {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) dev_t rdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518) umode_t mode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) const char *link;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520) struct dentry *hardlink;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523) #define OVL_CATTR(m) (&(struct ovl_cattr) { .mode = (m) })
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525) int ovl_mkdir_real(struct inode *dir, struct dentry **newdentry, umode_t mode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526) struct dentry *ovl_create_real(struct inode *dir, struct dentry *newdentry,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527) struct ovl_cattr *attr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528) int ovl_cleanup(struct inode *dir, struct dentry *dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529) struct dentry *ovl_lookup_temp(struct dentry *workdir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530) struct dentry *ovl_create_temp(struct dentry *workdir, struct ovl_cattr *attr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532) /* file.c */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533) extern const struct file_operations ovl_file_operations;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) int __init ovl_aio_request_cache_init(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535) void ovl_aio_request_cache_destroy(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536) long ovl_ioctl(struct file *file, unsigned int cmd, unsigned long arg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537) long ovl_compat_ioctl(struct file *file, unsigned int cmd, unsigned long arg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539) /* copy_up.c */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540) int ovl_copy_up(struct dentry *dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541) int ovl_copy_up_with_data(struct dentry *dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542) int ovl_maybe_copy_up(struct dentry *dentry, int flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543) int ovl_copy_xattr(struct super_block *sb, struct dentry *old,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544) struct dentry *new);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545) int ovl_set_attr(struct dentry *upper, struct kstat *stat);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546) struct ovl_fh *ovl_encode_real_fh(struct dentry *real, bool is_upper);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547) int ovl_set_origin(struct dentry *dentry, struct dentry *lower,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548) struct dentry *upper);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550) /* export.c */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551) extern const struct export_operations ovl_export_operations;