^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * linux/fs/reiserfs/xattr.c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * Copyright (c) 2002 by Jeff Mahoney, <jeffm@suse.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) * In order to implement EA/ACLs in a clean, backwards compatible manner,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) * they are implemented as files in a "private" directory.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) * Each EA is in it's own file, with the directory layout like so (/ is assumed
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) * to be relative to fs root). Inside the /.reiserfs_priv/xattrs directory,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) * directories named using the capital-hex form of the objectid and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) * generation number are used. Inside each directory are individual files
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) * named with the name of the extended attribute.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) * So, for objectid 12648430, we could have:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) * /.reiserfs_priv/xattrs/C0FFEE.0/system.posix_acl_access
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) * /.reiserfs_priv/xattrs/C0FFEE.0/system.posix_acl_default
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) * /.reiserfs_priv/xattrs/C0FFEE.0/user.Content-Type
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) * .. or similar.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) * The file contents are the text of the EA. The size is known based on the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) * stat data describing the file.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) * In the case of system.posix_acl_access and system.posix_acl_default, since
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) * these are special cases for filesystem ACLs, they are interpreted by the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) * kernel, in addition, they are negatively and positively cached and attached
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) * to the inode so that unnecessary lookups are avoided.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) * Locking works like so:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) * Directory components (xattr root, xattr dir) are protectd by their i_mutex.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) * The xattrs themselves are protected by the xattr_sem.
^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) #include "reiserfs.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) #include <linux/capability.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) #include <linux/dcache.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) #include <linux/namei.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) #include <linux/errno.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) #include <linux/gfp.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) #include <linux/fs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) #include <linux/file.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) #include <linux/pagemap.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) #include <linux/xattr.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) #include "xattr.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) #include "acl.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) #include <linux/uaccess.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) #include <net/checksum.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) #include <linux/stat.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) #include <linux/quotaops.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) #include <linux/security.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) #include <linux/posix_acl_xattr.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) #define PRIVROOT_NAME ".reiserfs_priv"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) #define XAROOT_NAME "xattrs"
^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) * Helpers for inode ops. We do this so that we don't have all the VFS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) * overhead and also for proper i_mutex annotation.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) * dir->i_mutex must be held for all of them.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) #ifdef CONFIG_REISERFS_FS_XATTR
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) static int xattr_create(struct inode *dir, struct dentry *dentry, int mode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) BUG_ON(!inode_is_locked(dir));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) return dir->i_op->create(dir, dentry, mode, true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) static int xattr_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) BUG_ON(!inode_is_locked(dir));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) return dir->i_op->mkdir(dir, dentry, mode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) * We use I_MUTEX_CHILD here to silence lockdep. It's safe because xattr
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) * mutation ops aren't called during rename or splace, which are the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) * only other users of I_MUTEX_CHILD. It violates the ordering, but that's
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) * better than allocating another subclass just for this code.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) static int xattr_unlink(struct inode *dir, struct dentry *dentry)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) int error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) BUG_ON(!inode_is_locked(dir));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) inode_lock_nested(d_inode(dentry), I_MUTEX_CHILD);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) error = dir->i_op->unlink(dir, dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) inode_unlock(d_inode(dentry));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) if (!error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) d_delete(dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) static int xattr_rmdir(struct inode *dir, struct dentry *dentry)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) int error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) BUG_ON(!inode_is_locked(dir));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) inode_lock_nested(d_inode(dentry), I_MUTEX_CHILD);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) error = dir->i_op->rmdir(dir, dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) if (!error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) d_inode(dentry)->i_flags |= S_DEAD;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) inode_unlock(d_inode(dentry));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) if (!error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) d_delete(dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) #define xattr_may_create(flags) (!flags || flags & XATTR_CREATE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) static struct dentry *open_xa_root(struct super_block *sb, int flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) struct dentry *privroot = REISERFS_SB(sb)->priv_root;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) struct dentry *xaroot;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) if (d_really_is_negative(privroot))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) return ERR_PTR(-EOPNOTSUPP);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) inode_lock_nested(d_inode(privroot), I_MUTEX_XATTR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) xaroot = dget(REISERFS_SB(sb)->xattr_root);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) if (!xaroot)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) xaroot = ERR_PTR(-EOPNOTSUPP);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) else if (d_really_is_negative(xaroot)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) int err = -ENODATA;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) if (xattr_may_create(flags))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) err = xattr_mkdir(d_inode(privroot), xaroot, 0700);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) if (err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) dput(xaroot);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) xaroot = ERR_PTR(err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) inode_unlock(d_inode(privroot));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) return xaroot;
^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 struct dentry *open_xa_dir(const struct inode *inode, int flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) struct dentry *xaroot, *xadir;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) char namebuf[17];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) xaroot = open_xa_root(inode->i_sb, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) if (IS_ERR(xaroot))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) return xaroot;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) snprintf(namebuf, sizeof(namebuf), "%X.%X",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) le32_to_cpu(INODE_PKEY(inode)->k_objectid),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) inode->i_generation);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) inode_lock_nested(d_inode(xaroot), I_MUTEX_XATTR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) xadir = lookup_one_len(namebuf, xaroot, strlen(namebuf));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) if (!IS_ERR(xadir) && d_really_is_negative(xadir)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) int err = -ENODATA;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) if (xattr_may_create(flags))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) err = xattr_mkdir(d_inode(xaroot), xadir, 0700);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) if (err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) dput(xadir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) xadir = ERR_PTR(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)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) inode_unlock(d_inode(xaroot));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) dput(xaroot);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) return xadir;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) * The following are side effects of other operations that aren't explicitly
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) * modifying extended attributes. This includes operations such as permissions
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) * or ownership changes, object deletions, etc.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) struct reiserfs_dentry_buf {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) struct dir_context ctx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) struct dentry *xadir;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) int count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) struct dentry *dentries[8];
^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 int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) fill_with_dentries(struct dir_context *ctx, const char *name, int namelen,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) loff_t offset, u64 ino, unsigned int d_type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) struct reiserfs_dentry_buf *dbuf =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) container_of(ctx, struct reiserfs_dentry_buf, ctx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) struct dentry *dentry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) WARN_ON_ONCE(!inode_is_locked(d_inode(dbuf->xadir)));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) if (dbuf->count == ARRAY_SIZE(dbuf->dentries))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) return -ENOSPC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) if (name[0] == '.' && (namelen < 2 ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) (namelen == 2 && name[1] == '.')))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) dentry = lookup_one_len(name, dbuf->xadir, namelen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) if (IS_ERR(dentry)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) dbuf->err = PTR_ERR(dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) return PTR_ERR(dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) } else if (d_really_is_negative(dentry)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) /* A directory entry exists, but no file? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) reiserfs_error(dentry->d_sb, "xattr-20003",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) "Corrupted directory: xattr %pd listed but "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) "not found for file %pd.\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) dentry, dbuf->xadir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) dput(dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) dbuf->err = -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) dbuf->dentries[dbuf->count++] = dentry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) cleanup_dentry_buf(struct reiserfs_dentry_buf *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) for (i = 0; i < buf->count; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) if (buf->dentries[i])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) dput(buf->dentries[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) static int reiserfs_for_each_xattr(struct inode *inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) int (*action)(struct dentry *, void *),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) void *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) struct dentry *dir;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) int i, err = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) struct reiserfs_dentry_buf buf = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) .ctx.actor = fill_with_dentries,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) /* Skip out, an xattr has no xattrs associated with it */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) if (IS_PRIVATE(inode) || get_inode_sd_version(inode) == STAT_DATA_V1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) dir = open_xa_dir(inode, XATTR_REPLACE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) if (IS_ERR(dir)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) err = PTR_ERR(dir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) } else if (d_really_is_negative(dir)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) err = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) goto out_dir;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) inode_lock_nested(d_inode(dir), I_MUTEX_XATTR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) buf.xadir = dir;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) while (1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) err = reiserfs_readdir_inode(d_inode(dir), &buf.ctx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) if (buf.err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) err = buf.err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) if (!buf.count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) for (i = 0; !err && i < buf.count && buf.dentries[i]; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) struct dentry *dentry = buf.dentries[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) if (!d_is_dir(dentry))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) err = action(dentry, data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) dput(dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) buf.dentries[i] = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) buf.count = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) inode_unlock(d_inode(dir));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) cleanup_dentry_buf(&buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) if (!err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) * We start a transaction here to avoid a ABBA situation
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) * between the xattr root's i_mutex and the journal lock.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) * This doesn't incur much additional overhead since the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) * new transaction will just nest inside the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) * outer transaction.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) int blocks = JOURNAL_PER_BALANCE_CNT * 2 + 2 +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) 4 * REISERFS_QUOTA_TRANS_BLOCKS(inode->i_sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) struct reiserfs_transaction_handle th;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) reiserfs_write_lock(inode->i_sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) err = journal_begin(&th, inode->i_sb, blocks);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) reiserfs_write_unlock(inode->i_sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) if (!err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) int jerror;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) inode_lock_nested(d_inode(dir->d_parent),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) I_MUTEX_XATTR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) err = action(dir, data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) reiserfs_write_lock(inode->i_sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) jerror = journal_end(&th);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) reiserfs_write_unlock(inode->i_sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) inode_unlock(d_inode(dir->d_parent));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) err = jerror ?: err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) out_dir:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) dput(dir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) * -ENODATA: this object doesn't have any xattrs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) * -EOPNOTSUPP: this file system doesn't have xattrs enabled on disk.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) * Neither are errors
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) if (err == -ENODATA || err == -EOPNOTSUPP)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) err = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) return err;
^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 int delete_one_xattr(struct dentry *dentry, void *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) struct inode *dir = d_inode(dentry->d_parent);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) /* This is the xattr dir, handle specially. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) if (d_is_dir(dentry))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) return xattr_rmdir(dir, dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) return xattr_unlink(dir, dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) static int chown_one_xattr(struct dentry *dentry, void *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) struct iattr *attrs = data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) int ia_valid = attrs->ia_valid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) * We only want the ownership bits. Otherwise, we'll do
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) * things like change a directory to a regular file if
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) * ATTR_MODE is set.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) attrs->ia_valid &= (ATTR_UID|ATTR_GID);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) err = reiserfs_setattr(dentry, attrs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) attrs->ia_valid = ia_valid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) /* No i_mutex, but the inode is unconnected. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) int reiserfs_delete_xattrs(struct inode *inode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) int err = reiserfs_for_each_xattr(inode, delete_one_xattr, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) reiserfs_warning(inode->i_sb, "jdm-20004",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) "Couldn't delete all xattrs (%d)\n", err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) /* inode->i_mutex: down */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) int reiserfs_chown_xattrs(struct inode *inode, struct iattr *attrs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) int err = reiserfs_for_each_xattr(inode, chown_one_xattr, attrs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) reiserfs_warning(inode->i_sb, "jdm-20007",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) "Couldn't chown all xattrs (%d)\n", err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) #ifdef CONFIG_REISERFS_FS_XATTR
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) * Returns a dentry corresponding to a specific extended attribute file
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) * for the inode. If flags allow, the file is created. Otherwise, a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) * valid or negative dentry, or an error is returned.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) static struct dentry *xattr_lookup(struct inode *inode, const char *name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) int flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) struct dentry *xadir, *xafile;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) int err = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) xadir = open_xa_dir(inode, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) if (IS_ERR(xadir))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) return ERR_CAST(xadir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) inode_lock_nested(d_inode(xadir), I_MUTEX_XATTR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) xafile = lookup_one_len(name, xadir, strlen(name));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) if (IS_ERR(xafile)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) err = PTR_ERR(xafile);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) if (d_really_is_positive(xafile) && (flags & XATTR_CREATE))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) err = -EEXIST;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) if (d_really_is_negative(xafile)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) err = -ENODATA;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) if (xattr_may_create(flags))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) err = xattr_create(d_inode(xadir), xafile,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) 0700|S_IFREG);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) dput(xafile);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) inode_unlock(d_inode(xadir));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) dput(xadir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) return ERR_PTR(err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) return xafile;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) /* Internal operations on file data */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) static inline void reiserfs_put_page(struct page *page)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) kunmap(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) put_page(page);
^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) static struct page *reiserfs_get_page(struct inode *dir, size_t n)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) struct address_space *mapping = dir->i_mapping;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) struct page *page;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) * We can deadlock if we try to free dentries,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) * and an unlink/rmdir has just occurred - GFP_NOFS avoids this
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) mapping_set_gfp_mask(mapping, GFP_NOFS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) page = read_mapping_page(mapping, n >> PAGE_SHIFT, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) if (!IS_ERR(page)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) kmap(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) if (PageError(page))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) goto fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) return page;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) fail:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) reiserfs_put_page(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) return ERR_PTR(-EIO);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) static inline __u32 xattr_hash(const char *msg, int len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) * csum_partial() gives different results for little-endian and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) * big endian hosts. Images created on little-endian hosts and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) * mounted on big-endian hosts(and vice versa) will see csum mismatches
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) * when trying to fetch xattrs. Treating the hash as __wsum_t would
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) * lower the frequency of mismatch. This is an endianness bug in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) * reiserfs. The return statement would result in a sparse warning. Do
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) * not fix the sparse warning so as to not hide a reminder of the bug.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) return csum_partial(msg, len, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) int reiserfs_commit_write(struct file *f, struct page *page,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) unsigned from, unsigned to);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) static void update_ctime(struct inode *inode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) struct timespec64 now = current_time(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) if (inode_unhashed(inode) || !inode->i_nlink ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) timespec64_equal(&inode->i_ctime, &now))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) inode->i_ctime = current_time(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) mark_inode_dirty(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) static int lookup_and_delete_xattr(struct inode *inode, const char *name)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) int err = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) struct dentry *dentry, *xadir;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) xadir = open_xa_dir(inode, XATTR_REPLACE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) if (IS_ERR(xadir))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) return PTR_ERR(xadir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) inode_lock_nested(d_inode(xadir), I_MUTEX_XATTR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) dentry = lookup_one_len(name, xadir, strlen(name));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) if (IS_ERR(dentry)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) err = PTR_ERR(dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) goto out_dput;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) if (d_really_is_positive(dentry)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) err = xattr_unlink(d_inode(xadir), dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) update_ctime(inode);
^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) dput(dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) out_dput:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) inode_unlock(d_inode(xadir));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) dput(xadir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) return err;
^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)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) /* Generic extended attribute operations that can be used by xa plugins */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) * inode->i_mutex: down
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518) int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) reiserfs_xattr_set_handle(struct reiserfs_transaction_handle *th,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520) struct inode *inode, const char *name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521) const void *buffer, size_t buffer_size, int flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523) int err = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524) struct dentry *dentry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525) struct page *page;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526) char *data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527) size_t file_pos = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528) size_t buffer_pos = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529) size_t new_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530) __u32 xahash = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532) if (get_inode_sd_version(inode) == STAT_DATA_V1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533) return -EOPNOTSUPP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535) if (!buffer) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536) err = lookup_and_delete_xattr(inode, name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540) dentry = xattr_lookup(inode, name, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541) if (IS_ERR(dentry))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542) return PTR_ERR(dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544) down_write(&REISERFS_I(inode)->i_xattr_sem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546) xahash = xattr_hash(buffer, buffer_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547) while (buffer_pos < buffer_size || buffer_pos == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548) size_t chunk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549) size_t skip = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550) size_t page_offset = (file_pos & (PAGE_SIZE - 1));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552) if (buffer_size - buffer_pos > PAGE_SIZE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553) chunk = PAGE_SIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555) chunk = buffer_size - buffer_pos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557) page = reiserfs_get_page(d_inode(dentry), file_pos);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 558) if (IS_ERR(page)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 559) err = PTR_ERR(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 560) goto out_unlock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 561) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 562)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 563) lock_page(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 564) data = page_address(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 565)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 566) if (file_pos == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 567) struct reiserfs_xattr_header *rxh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 568)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 569) skip = file_pos = sizeof(struct reiserfs_xattr_header);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 570) if (chunk + skip > PAGE_SIZE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 571) chunk = PAGE_SIZE - skip;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 572) rxh = (struct reiserfs_xattr_header *)data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 573) rxh->h_magic = cpu_to_le32(REISERFS_XATTR_MAGIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 574) rxh->h_hash = cpu_to_le32(xahash);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 575) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 576)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 577) reiserfs_write_lock(inode->i_sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 578) err = __reiserfs_write_begin(page, page_offset, chunk + skip);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 579) if (!err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 580) if (buffer)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 581) memcpy(data + skip, buffer + buffer_pos, chunk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 582) err = reiserfs_commit_write(NULL, page, page_offset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 583) page_offset + chunk +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 584) skip);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 585) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 586) reiserfs_write_unlock(inode->i_sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 587) unlock_page(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 588) reiserfs_put_page(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 589) buffer_pos += chunk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 590) file_pos += chunk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 591) skip = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 592) if (err || buffer_size == 0 || !buffer)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 593) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 594) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 595)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 596) new_size = buffer_size + sizeof(struct reiserfs_xattr_header);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 597) if (!err && new_size < i_size_read(d_inode(dentry))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 598) struct iattr newattrs = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 599) .ia_ctime = current_time(inode),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 600) .ia_size = new_size,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 601) .ia_valid = ATTR_SIZE | ATTR_CTIME,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 602) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 603)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 604) inode_lock_nested(d_inode(dentry), I_MUTEX_XATTR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 605) inode_dio_wait(d_inode(dentry));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 606)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 607) err = reiserfs_setattr(dentry, &newattrs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 608) inode_unlock(d_inode(dentry));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 609) } else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 610) update_ctime(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 611) out_unlock:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 612) up_write(&REISERFS_I(inode)->i_xattr_sem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 613) dput(dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 614) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 615) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 616)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 617) /* We need to start a transaction to maintain lock ordering */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 618) int reiserfs_xattr_set(struct inode *inode, const char *name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 619) const void *buffer, size_t buffer_size, int flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 620) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 621)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 622) struct reiserfs_transaction_handle th;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 623) int error, error2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 624) size_t jbegin_count = reiserfs_xattr_nblocks(inode, buffer_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 625)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 626) /* Check before we start a transaction and then do nothing. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 627) if (!d_really_is_positive(REISERFS_SB(inode->i_sb)->priv_root))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 628) return -EOPNOTSUPP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 629)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 630) if (!(flags & XATTR_REPLACE))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 631) jbegin_count += reiserfs_xattr_jcreate_nblocks(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 632)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 633) reiserfs_write_lock(inode->i_sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 634) error = journal_begin(&th, inode->i_sb, jbegin_count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 635) reiserfs_write_unlock(inode->i_sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 636) if (error) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 637) return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 638) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 639)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 640) error = reiserfs_xattr_set_handle(&th, inode, name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 641) buffer, buffer_size, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 642)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 643) reiserfs_write_lock(inode->i_sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 644) error2 = journal_end(&th);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 645) reiserfs_write_unlock(inode->i_sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 646) if (error == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 647) error = error2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 648)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 649) return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 650) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 651)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 652) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 653) * inode->i_mutex: down
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 654) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 655) int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 656) reiserfs_xattr_get(struct inode *inode, const char *name, void *buffer,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 657) size_t buffer_size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 658) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 659) ssize_t err = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 660) struct dentry *dentry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 661) size_t isize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 662) size_t file_pos = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 663) size_t buffer_pos = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 664) struct page *page;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 665) __u32 hash = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 666)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 667) if (name == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 668) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 669)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 670) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 671) * We can't have xattrs attached to v1 items since they don't have
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 672) * generation numbers
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 673) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 674) if (get_inode_sd_version(inode) == STAT_DATA_V1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 675) return -EOPNOTSUPP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 676)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 677) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 678) * priv_root needn't be initialized during mount so allow initial
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 679) * lookups to succeed.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 680) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 681) if (!REISERFS_SB(inode->i_sb)->priv_root)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 682) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 683)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 684) dentry = xattr_lookup(inode, name, XATTR_REPLACE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 685) if (IS_ERR(dentry)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 686) err = PTR_ERR(dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 687) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 688) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 689)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 690) down_read(&REISERFS_I(inode)->i_xattr_sem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 691)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 692) isize = i_size_read(d_inode(dentry));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 693)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 694) /* Just return the size needed */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 695) if (buffer == NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 696) err = isize - sizeof(struct reiserfs_xattr_header);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 697) goto out_unlock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 698) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 699)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 700) if (buffer_size < isize - sizeof(struct reiserfs_xattr_header)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 701) err = -ERANGE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 702) goto out_unlock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 703) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 704)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 705) while (file_pos < isize) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 706) size_t chunk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 707) char *data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 708) size_t skip = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 709)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 710) if (isize - file_pos > PAGE_SIZE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 711) chunk = PAGE_SIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 712) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 713) chunk = isize - file_pos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 714)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 715) page = reiserfs_get_page(d_inode(dentry), file_pos);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 716) if (IS_ERR(page)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 717) err = PTR_ERR(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 718) goto out_unlock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 719) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 720)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 721) lock_page(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 722) data = page_address(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 723) if (file_pos == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 724) struct reiserfs_xattr_header *rxh =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 725) (struct reiserfs_xattr_header *)data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 726) skip = file_pos = sizeof(struct reiserfs_xattr_header);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 727) chunk -= skip;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 728) /* Magic doesn't match up.. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 729) if (rxh->h_magic != cpu_to_le32(REISERFS_XATTR_MAGIC)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 730) unlock_page(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 731) reiserfs_put_page(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 732) reiserfs_warning(inode->i_sb, "jdm-20001",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 733) "Invalid magic for xattr (%s) "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 734) "associated with %k", name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 735) INODE_PKEY(inode));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 736) err = -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 737) goto out_unlock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 738) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 739) hash = le32_to_cpu(rxh->h_hash);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 740) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 741) memcpy(buffer + buffer_pos, data + skip, chunk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 742) unlock_page(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 743) reiserfs_put_page(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 744) file_pos += chunk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 745) buffer_pos += chunk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 746) skip = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 747) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 748) err = isize - sizeof(struct reiserfs_xattr_header);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 749)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 750) if (xattr_hash(buffer, isize - sizeof(struct reiserfs_xattr_header)) !=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 751) hash) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 752) reiserfs_warning(inode->i_sb, "jdm-20002",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 753) "Invalid hash for xattr (%s) associated "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 754) "with %k", name, INODE_PKEY(inode));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 755) err = -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 756) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 757)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 758) out_unlock:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 759) up_read(&REISERFS_I(inode)->i_xattr_sem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 760) dput(dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 761)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 762) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 763) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 764) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 765)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 766) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 767) * In order to implement different sets of xattr operations for each xattr
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 768) * prefix with the generic xattr API, a filesystem should create a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 769) * null-terminated array of struct xattr_handler (one for each prefix) and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 770) * hang a pointer to it off of the s_xattr field of the superblock.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 771) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 772) * The generic_fooxattr() functions will use this list to dispatch xattr
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 773) * operations to the correct xattr_handler.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 774) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 775) #define for_each_xattr_handler(handlers, handler) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 776) for ((handler) = *(handlers)++; \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 777) (handler) != NULL; \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 778) (handler) = *(handlers)++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 779)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 780) /* This is the implementation for the xattr plugin infrastructure */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 781) static inline const struct xattr_handler *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 782) find_xattr_handler_prefix(const struct xattr_handler **handlers,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 783) const char *name)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 784) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 785) const struct xattr_handler *xah;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 786)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 787) if (!handlers)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 788) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 789)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 790) for_each_xattr_handler(handlers, xah) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 791) const char *prefix = xattr_prefix(xah);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 792) if (strncmp(prefix, name, strlen(prefix)) == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 793) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 794) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 795)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 796) return xah;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 797) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 798)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 799) struct listxattr_buf {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 800) struct dir_context ctx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 801) size_t size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 802) size_t pos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 803) char *buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 804) struct dentry *dentry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 805) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 806)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 807) static int listxattr_filler(struct dir_context *ctx, const char *name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 808) int namelen, loff_t offset, u64 ino,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 809) unsigned int d_type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 810) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 811) struct listxattr_buf *b =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 812) container_of(ctx, struct listxattr_buf, ctx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 813) size_t size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 814)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 815) if (name[0] != '.' ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 816) (namelen != 1 && (name[1] != '.' || namelen != 2))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 817) const struct xattr_handler *handler;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 818)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 819) handler = find_xattr_handler_prefix(b->dentry->d_sb->s_xattr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 820) name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 821) if (!handler /* Unsupported xattr name */ ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 822) (handler->list && !handler->list(b->dentry)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 823) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 824) size = namelen + 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 825) if (b->buf) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 826) if (b->pos + size > b->size) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 827) b->pos = -ERANGE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 828) return -ERANGE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 829) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 830) memcpy(b->buf + b->pos, name, namelen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 831) b->buf[b->pos + namelen] = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 832) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 833) b->pos += size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 834) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 835) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 836) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 837)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 838) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 839) * Inode operation listxattr()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 840) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 841) * We totally ignore the generic listxattr here because it would be stupid
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 842) * not to. Since the xattrs are organized in a directory, we can just
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 843) * readdir to find them.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 844) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 845) ssize_t reiserfs_listxattr(struct dentry * dentry, char *buffer, size_t size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 846) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 847) struct dentry *dir;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 848) int err = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 849) struct listxattr_buf buf = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 850) .ctx.actor = listxattr_filler,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 851) .dentry = dentry,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 852) .buf = buffer,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 853) .size = buffer ? size : 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 854) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 855)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 856) if (d_really_is_negative(dentry))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 857) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 858)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 859) if (get_inode_sd_version(d_inode(dentry)) == STAT_DATA_V1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 860) return -EOPNOTSUPP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 861)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 862) dir = open_xa_dir(d_inode(dentry), XATTR_REPLACE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 863) if (IS_ERR(dir)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 864) err = PTR_ERR(dir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 865) if (err == -ENODATA)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 866) err = 0; /* Not an error if there aren't any xattrs */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 867) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 868) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 869)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 870) inode_lock_nested(d_inode(dir), I_MUTEX_XATTR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 871) err = reiserfs_readdir_inode(d_inode(dir), &buf.ctx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 872) inode_unlock(d_inode(dir));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 873)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 874) if (!err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 875) err = buf.pos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 876)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 877) dput(dir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 878) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 879) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 880) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 881)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 882) static int create_privroot(struct dentry *dentry)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 883) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 884) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 885) struct inode *inode = d_inode(dentry->d_parent);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 886)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 887) WARN_ON_ONCE(!inode_is_locked(inode));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 888)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 889) err = xattr_mkdir(inode, dentry, 0700);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 890) if (err || d_really_is_negative(dentry)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 891) reiserfs_warning(dentry->d_sb, "jdm-20006",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 892) "xattrs/ACLs enabled and couldn't "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 893) "find/create .reiserfs_priv. "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 894) "Failing mount.");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 895) return -EOPNOTSUPP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 896) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 897)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 898) d_inode(dentry)->i_flags |= S_PRIVATE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 899) d_inode(dentry)->i_opflags &= ~IOP_XATTR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 900) reiserfs_info(dentry->d_sb, "Created %s - reserved for xattr "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 901) "storage.\n", PRIVROOT_NAME);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 902)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 903) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 904) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 905)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 906) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 907) int __init reiserfs_xattr_register_handlers(void) { return 0; }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 908) void reiserfs_xattr_unregister_handlers(void) {}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 909) static int create_privroot(struct dentry *dentry) { return 0; }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 910) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 911)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 912) /* Actual operations that are exported to VFS-land */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 913) const struct xattr_handler *reiserfs_xattr_handlers[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 914) #ifdef CONFIG_REISERFS_FS_XATTR
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 915) &reiserfs_xattr_user_handler,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 916) &reiserfs_xattr_trusted_handler,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 917) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 918) #ifdef CONFIG_REISERFS_FS_SECURITY
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 919) &reiserfs_xattr_security_handler,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 920) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 921) #ifdef CONFIG_REISERFS_FS_POSIX_ACL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 922) &posix_acl_access_xattr_handler,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 923) &posix_acl_default_xattr_handler,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 924) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 925) NULL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 926) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 927)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 928) static int xattr_mount_check(struct super_block *s)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 929) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 930) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 931) * We need generation numbers to ensure that the oid mapping is correct
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 932) * v3.5 filesystems don't have them.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 933) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 934) if (old_format_only(s)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 935) if (reiserfs_xattrs_optional(s)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 936) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 937) * Old format filesystem, but optional xattrs have
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 938) * been enabled. Error out.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 939) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 940) reiserfs_warning(s, "jdm-2005",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 941) "xattrs/ACLs not supported "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 942) "on pre-v3.6 format filesystems. "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 943) "Failing mount.");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 944) return -EOPNOTSUPP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 945) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 946) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 947)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 948) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 949) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 950)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 951) int reiserfs_permission(struct inode *inode, int mask)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 952) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 953) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 954) * We don't do permission checks on the internal objects.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 955) * Permissions are determined by the "owning" object.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 956) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 957) if (IS_PRIVATE(inode))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 958) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 959)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 960) return generic_permission(inode, mask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 961) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 962)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 963) static int xattr_hide_revalidate(struct dentry *dentry, unsigned int flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 964) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 965) return -EPERM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 966) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 967)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 968) static const struct dentry_operations xattr_lookup_poison_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 969) .d_revalidate = xattr_hide_revalidate,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 970) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 971)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 972) int reiserfs_lookup_privroot(struct super_block *s)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 973) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 974) struct dentry *dentry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 975) int err = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 976)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 977) /* If we don't have the privroot located yet - go find it */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 978) inode_lock(d_inode(s->s_root));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 979) dentry = lookup_one_len(PRIVROOT_NAME, s->s_root,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 980) strlen(PRIVROOT_NAME));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 981) if (!IS_ERR(dentry)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 982) REISERFS_SB(s)->priv_root = dentry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 983) d_set_d_op(dentry, &xattr_lookup_poison_ops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 984) if (d_really_is_positive(dentry)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 985) d_inode(dentry)->i_flags |= S_PRIVATE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 986) d_inode(dentry)->i_opflags &= ~IOP_XATTR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 987) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 988) } else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 989) err = PTR_ERR(dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 990) inode_unlock(d_inode(s->s_root));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 991)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 992) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 993) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 994)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 995) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 996) * We need to take a copy of the mount flags since things like
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 997) * SB_RDONLY don't get set until *after* we're called.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 998) * mount_flags != mount_options
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 999) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1000) int reiserfs_xattr_init(struct super_block *s, int mount_flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1001) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1002) int err = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1003) struct dentry *privroot = REISERFS_SB(s)->priv_root;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1004)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1005) err = xattr_mount_check(s);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1006) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1007) goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1008)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1009) if (d_really_is_negative(privroot) && !(mount_flags & SB_RDONLY)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1010) inode_lock(d_inode(s->s_root));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1011) err = create_privroot(REISERFS_SB(s)->priv_root);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1012) inode_unlock(d_inode(s->s_root));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1013) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1014)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1015) if (d_really_is_positive(privroot)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1016) inode_lock(d_inode(privroot));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1017) if (!REISERFS_SB(s)->xattr_root) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1018) struct dentry *dentry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1019)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1020) dentry = lookup_one_len(XAROOT_NAME, privroot,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1021) strlen(XAROOT_NAME));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1022) if (!IS_ERR(dentry))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1023) REISERFS_SB(s)->xattr_root = dentry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1024) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1025) err = PTR_ERR(dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1026) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1027) inode_unlock(d_inode(privroot));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1028) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1029)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1030) error:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1031) if (err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1032) clear_bit(REISERFS_XATTRS_USER, &REISERFS_SB(s)->s_mount_opt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1033) clear_bit(REISERFS_POSIXACL, &REISERFS_SB(s)->s_mount_opt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1034) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1035)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1036) /* The super_block SB_POSIXACL must mirror the (no)acl mount option. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1037) if (reiserfs_posixacl(s))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1038) s->s_flags |= SB_POSIXACL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1039) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1040) s->s_flags &= ~SB_POSIXACL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1041)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1042) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1043) }