xattr_user.c 1.3 KB
Newer Older
1
#include "reiserfs.h"
L
Linus Torvalds 已提交
2 3 4 5
#include <linux/errno.h>
#include <linux/fs.h>
#include <linux/pagemap.h>
#include <linux/xattr.h>
6
#include "xattr.h"
7
#include <linux/uaccess.h>
L
Linus Torvalds 已提交
8 9

static int
10 11
user_get(const struct xattr_handler *handler, struct dentry *dentry,
	 const char *name, void *buffer, size_t size)
L
Linus Torvalds 已提交
12 13
{

14 15
	if (strlen(name) < sizeof(XATTR_USER_PREFIX))
		return -EINVAL;
16
	if (!reiserfs_xattrs_user(dentry->d_sb))
17
		return -EOPNOTSUPP;
18
	return reiserfs_xattr_get(d_inode(dentry), name, buffer, size);
L
Linus Torvalds 已提交
19 20 21
}

static int
22 23
user_set(const struct xattr_handler *handler, struct dentry *dentry,
	 const char *name, const void *buffer, size_t size, int flags)
L
Linus Torvalds 已提交
24
{
25 26
	if (strlen(name) < sizeof(XATTR_USER_PREFIX))
		return -EINVAL;
L
Linus Torvalds 已提交
27

28
	if (!reiserfs_xattrs_user(dentry->d_sb))
29
		return -EOPNOTSUPP;
30
	return reiserfs_xattr_set(d_inode(dentry), name, buffer, size, flags);
L
Linus Torvalds 已提交
31 32
}

33 34 35
static size_t user_list(const struct xattr_handler *handler,
			struct dentry *dentry, char *list, size_t list_size,
			const char *name, size_t name_len)
L
Linus Torvalds 已提交
36
{
37
	const size_t len = name_len + 1;
L
Linus Torvalds 已提交
38

39
	if (!reiserfs_xattrs_user(dentry->d_sb))
40
		return 0;
41 42 43 44
	if (list && len <= list_size) {
		memcpy(list, name, name_len);
		list[name_len] = '\0';
	}
45
	return len;
L
Linus Torvalds 已提交
46 47
}

48
const struct xattr_handler reiserfs_xattr_user_handler = {
L
Linus Torvalds 已提交
49 50 51 52 53
	.prefix = XATTR_USER_PREFIX,
	.get = user_get,
	.set = user_set,
	.list = user_list,
};