blob: 58092449f8ffe2279d38d3f7d96012d68463e146 [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001// SPDX-License-Identifier: GPL-2.0
Linus Torvalds1da177e2005-04-16 15:20:36 -07002/*
3 * linux/fs/ext2/xattr_user.c
4 * Handler for extended user attributes.
5 *
6 * Copyright (C) 2001 by Andreas Gruenbacher, <a.gruenbacher@computer.org>
7 */
8
9#include <linux/init.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070010#include <linux/string.h>
11#include "ext2.h"
12#include "xattr.h"
13
Andreas Gruenbacher764a5c62015-12-02 14:44:43 +010014static bool
15ext2_xattr_user_list(struct dentry *dentry)
Linus Torvalds1da177e2005-04-16 15:20:36 -070016{
Andreas Gruenbacher764a5c62015-12-02 14:44:43 +010017 return test_opt(dentry->d_sb, XATTR_USER);
Linus Torvalds1da177e2005-04-16 15:20:36 -070018}
19
20static int
Andreas Gruenbacherd9a82a02015-10-04 19:18:51 +020021ext2_xattr_user_get(const struct xattr_handler *handler,
Al Virob2968212016-04-10 20:48:24 -040022 struct dentry *unused, struct inode *inode,
23 const char *name, void *buffer, size_t size)
Linus Torvalds1da177e2005-04-16 15:20:36 -070024{
Al Virob2968212016-04-10 20:48:24 -040025 if (!test_opt(inode->i_sb, XATTR_USER))
Linus Torvalds1da177e2005-04-16 15:20:36 -070026 return -EOPNOTSUPP;
Al Virob2968212016-04-10 20:48:24 -040027 return ext2_xattr_get(inode, EXT2_XATTR_INDEX_USER,
Christoph Hellwig431547b2009-11-13 09:52:56 +000028 name, buffer, size);
Linus Torvalds1da177e2005-04-16 15:20:36 -070029}
30
31static int
Andreas Gruenbacherd9a82a02015-10-04 19:18:51 +020032ext2_xattr_user_set(const struct xattr_handler *handler,
Christian Braunere65ce2a2021-01-21 14:19:27 +010033 struct user_namespace *mnt_userns,
Al Viro59301222016-05-27 10:19:30 -040034 struct dentry *unused, struct inode *inode,
35 const char *name, const void *value,
36 size_t size, int flags)
Linus Torvalds1da177e2005-04-16 15:20:36 -070037{
Al Viro59301222016-05-27 10:19:30 -040038 if (!test_opt(inode->i_sb, XATTR_USER))
Linus Torvalds1da177e2005-04-16 15:20:36 -070039 return -EOPNOTSUPP;
Linus Torvalds1da177e2005-04-16 15:20:36 -070040
Al Viro59301222016-05-27 10:19:30 -040041 return ext2_xattr_set(inode, EXT2_XATTR_INDEX_USER,
Christoph Hellwig431547b2009-11-13 09:52:56 +000042 name, value, size, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -070043}
44
Stephen Hemminger749c72ef2010-05-13 17:53:16 -070045const struct xattr_handler ext2_xattr_user_handler = {
Linus Torvalds1da177e2005-04-16 15:20:36 -070046 .prefix = XATTR_USER_PREFIX,
47 .list = ext2_xattr_user_list,
48 .get = ext2_xattr_user_get,
49 .set = ext2_xattr_user_set,
50};