blob: c243a3b4d69d55a6da2d70646c60fb245aedacc5 [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,
Al Viro59301222016-05-27 10:19:30 -040033 struct dentry *unused, struct inode *inode,
34 const char *name, const void *value,
35 size_t size, int flags)
Linus Torvalds1da177e2005-04-16 15:20:36 -070036{
Al Viro59301222016-05-27 10:19:30 -040037 if (!test_opt(inode->i_sb, XATTR_USER))
Linus Torvalds1da177e2005-04-16 15:20:36 -070038 return -EOPNOTSUPP;
Linus Torvalds1da177e2005-04-16 15:20:36 -070039
Al Viro59301222016-05-27 10:19:30 -040040 return ext2_xattr_set(inode, EXT2_XATTR_INDEX_USER,
Christoph Hellwig431547b2009-11-13 09:52:56 +000041 name, value, size, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -070042}
43
Stephen Hemminger749c72ef2010-05-13 17:53:16 -070044const struct xattr_handler ext2_xattr_user_handler = {
Linus Torvalds1da177e2005-04-16 15:20:36 -070045 .prefix = XATTR_USER_PREFIX,
46 .list = ext2_xattr_user_list,
47 .get = ext2_xattr_user_get,
48 .set = ext2_xattr_user_set,
49};