Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
awilliam
GitHub Repository: awilliam/linux-vfio
Path: blob/master/fs/9p/xattr_user.c
15109 views
1
/*
2
* Copyright IBM Corporation, 2010
3
* Author Aneesh Kumar K.V <[email protected]>
4
*
5
* This program is free software; you can redistribute it and/or modify it
6
* under the terms of version 2.1 of the GNU Lesser General Public License
7
* as published by the Free Software Foundation.
8
*
9
* This program is distributed in the hope that it would be useful, but
10
* WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12
*
13
*/
14
15
16
#include <linux/module.h>
17
#include <linux/string.h>
18
#include <linux/fs.h>
19
#include <linux/slab.h>
20
#include "xattr.h"
21
22
static int v9fs_xattr_user_get(struct dentry *dentry, const char *name,
23
void *buffer, size_t size, int type)
24
{
25
int retval;
26
char *full_name;
27
size_t name_len;
28
size_t prefix_len = XATTR_USER_PREFIX_LEN;
29
30
if (name == NULL)
31
return -EINVAL;
32
33
if (strcmp(name, "") == 0)
34
return -EINVAL;
35
36
name_len = strlen(name);
37
full_name = kmalloc(prefix_len + name_len + 1 , GFP_KERNEL);
38
if (!full_name)
39
return -ENOMEM;
40
memcpy(full_name, XATTR_USER_PREFIX, prefix_len);
41
memcpy(full_name+prefix_len, name, name_len);
42
full_name[prefix_len + name_len] = '\0';
43
44
retval = v9fs_xattr_get(dentry, full_name, buffer, size);
45
kfree(full_name);
46
return retval;
47
}
48
49
static int v9fs_xattr_user_set(struct dentry *dentry, const char *name,
50
const void *value, size_t size, int flags, int type)
51
{
52
int retval;
53
char *full_name;
54
size_t name_len;
55
size_t prefix_len = XATTR_USER_PREFIX_LEN;
56
57
if (name == NULL)
58
return -EINVAL;
59
60
if (strcmp(name, "") == 0)
61
return -EINVAL;
62
63
name_len = strlen(name);
64
full_name = kmalloc(prefix_len + name_len + 1 , GFP_KERNEL);
65
if (!full_name)
66
return -ENOMEM;
67
memcpy(full_name, XATTR_USER_PREFIX, prefix_len);
68
memcpy(full_name + prefix_len, name, name_len);
69
full_name[prefix_len + name_len] = '\0';
70
71
retval = v9fs_xattr_set(dentry, full_name, value, size, flags);
72
kfree(full_name);
73
return retval;
74
}
75
76
struct xattr_handler v9fs_xattr_user_handler = {
77
.prefix = XATTR_USER_PREFIX,
78
.get = v9fs_xattr_user_get,
79
.set = v9fs_xattr_user_set,
80
};
81
82