blob: 2fe7ff0a479cdeda96393919c9990208e4d34bb2 [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001// SPDX-License-Identifier: GPL-2.0
Dave Kleikampac27a0e2006-10-11 01:20:50 -07002/*
Mingming Cao617ba132006-10-11 01:20:53 -07003 * linux/fs/ext4/xattr_user.c
Dave Kleikampac27a0e2006-10-11 01:20:50 -07004 * Handler for extended user attributes.
5 *
6 * Copyright (C) 2001 by Andreas Gruenbacher, <a.gruenbacher@computer.org>
7 */
8
Dave Kleikampac27a0e2006-10-11 01:20:50 -07009#include <linux/string.h>
10#include <linux/fs.h>
Christoph Hellwig3dcf5452008-04-29 18:13:32 -040011#include "ext4_jbd2.h"
12#include "ext4.h"
Dave Kleikampac27a0e2006-10-11 01:20:50 -070013#include "xattr.h"
14
Andreas Gruenbacher764a5c62015-12-02 14:44:43 +010015static bool
16ext4_xattr_user_list(struct dentry *dentry)
Dave Kleikampac27a0e2006-10-11 01:20:50 -070017{
Andreas Gruenbacher764a5c62015-12-02 14:44:43 +010018 return test_opt(dentry->d_sb, XATTR_USER);
Dave Kleikampac27a0e2006-10-11 01:20:50 -070019}
20
21static int
Andreas Gruenbacherd9a82a02015-10-04 19:18:51 +020022ext4_xattr_user_get(const struct xattr_handler *handler,
Al Virob2968212016-04-10 20:48:24 -040023 struct dentry *unused, struct inode *inode,
24 const char *name, void *buffer, size_t size)
Dave Kleikampac27a0e2006-10-11 01:20:50 -070025{
Al Virob2968212016-04-10 20:48:24 -040026 if (!test_opt(inode->i_sb, XATTR_USER))
Dave Kleikampac27a0e2006-10-11 01:20:50 -070027 return -EOPNOTSUPP;
Al Virob2968212016-04-10 20:48:24 -040028 return ext4_xattr_get(inode, EXT4_XATTR_INDEX_USER,
Christoph Hellwig431547b2009-11-13 09:52:56 +000029 name, buffer, size);
Dave Kleikampac27a0e2006-10-11 01:20:50 -070030}
31
32static int
Andreas Gruenbacherd9a82a02015-10-04 19:18:51 +020033ext4_xattr_user_set(const struct xattr_handler *handler,
Christian Braunere65ce2a2021-01-21 14:19:27 +010034 struct user_namespace *mnt_userns,
Al Viro59301222016-05-27 10:19:30 -040035 struct dentry *unused, struct inode *inode,
36 const char *name, const void *value,
37 size_t size, int flags)
Dave Kleikampac27a0e2006-10-11 01:20:50 -070038{
Al Viro59301222016-05-27 10:19:30 -040039 if (!test_opt(inode->i_sb, XATTR_USER))
Dave Kleikampac27a0e2006-10-11 01:20:50 -070040 return -EOPNOTSUPP;
Al Viro59301222016-05-27 10:19:30 -040041 return ext4_xattr_set(inode, EXT4_XATTR_INDEX_USER,
Christoph Hellwig431547b2009-11-13 09:52:56 +000042 name, value, size, flags);
Dave Kleikampac27a0e2006-10-11 01:20:50 -070043}
44
Stephen Hemminger11e27522010-05-13 17:53:18 -070045const struct xattr_handler ext4_xattr_user_handler = {
Dave Kleikampac27a0e2006-10-11 01:20:50 -070046 .prefix = XATTR_USER_PREFIX,
Mingming Cao617ba132006-10-11 01:20:53 -070047 .list = ext4_xattr_user_list,
48 .get = ext4_xattr_user_get,
49 .set = ext4_xattr_user_set,
Dave Kleikampac27a0e2006-10-11 01:20:50 -070050};