diff options
| author | Linus Torvalds <torvalds@linux-foundation.org> | 2015-11-13 21:02:30 -0500 |
|---|---|---|
| committer | Linus Torvalds <torvalds@linux-foundation.org> | 2015-11-13 21:02:30 -0500 |
| commit | 5d2eb548b309be34ecf3b91f0b7300a2b9d09b8c (patch) | |
| tree | 89ce62fe154e6f10a018abb67f5f09015dd394fc /fs/9p | |
| parent | 2870f6c4d136e093e22159b8916918ff42c92218 (diff) | |
| parent | 29608d208b3619b3b508a6871622db789611d8a3 (diff) | |
Merge branch 'for-linus-3' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs
Pull vfs xattr cleanups from Al Viro.
* 'for-linus-3' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs:
f2fs: xattr simplifications
squashfs: xattr simplifications
9p: xattr simplifications
xattr handlers: Pass handler to operations instead of flags
jffs2: Add missing capability check for listing trusted xattrs
hfsplus: Remove unused xattr handler list operations
ubifs: Remove unused security xattr handler
vfs: Fix the posix_acl_xattr_list return value
vfs: Check attribute names in posix acl xattr handers
Diffstat (limited to 'fs/9p')
| -rw-r--r-- | fs/9p/Makefile | 5 | ||||
| -rw-r--r-- | fs/9p/acl.c | 65 | ||||
| -rw-r--r-- | fs/9p/xattr.c | 42 | ||||
| -rw-r--r-- | fs/9p/xattr.h | 3 | ||||
| -rw-r--r-- | fs/9p/xattr_security.c | 80 | ||||
| -rw-r--r-- | fs/9p/xattr_trusted.c | 80 | ||||
| -rw-r--r-- | fs/9p/xattr_user.c | 80 |
7 files changed, 56 insertions, 299 deletions
diff --git a/fs/9p/Makefile b/fs/9p/Makefile index ff7be98f84f2..9619ccadd2fc 100644 --- a/fs/9p/Makefile +++ b/fs/9p/Makefile | |||
| @@ -10,10 +10,7 @@ obj-$(CONFIG_9P_FS) := 9p.o | |||
| 10 | vfs_dentry.o \ | 10 | vfs_dentry.o \ |
| 11 | v9fs.o \ | 11 | v9fs.o \ |
| 12 | fid.o \ | 12 | fid.o \ |
| 13 | xattr.o \ | 13 | xattr.o |
| 14 | xattr_user.o \ | ||
| 15 | xattr_trusted.o | ||
| 16 | 14 | ||
| 17 | 9p-$(CONFIG_9P_FSCACHE) += cache.o | 15 | 9p-$(CONFIG_9P_FSCACHE) += cache.o |
| 18 | 9p-$(CONFIG_9P_FS_POSIX_ACL) += acl.o | 16 | 9p-$(CONFIG_9P_FS_POSIX_ACL) += acl.o |
| 19 | 9p-$(CONFIG_9P_FS_SECURITY) += xattr_security.o | ||
diff --git a/fs/9p/acl.c b/fs/9p/acl.c index 31c010372660..a7e28890f5ef 100644 --- a/fs/9p/acl.c +++ b/fs/9p/acl.c | |||
| @@ -212,26 +212,9 @@ int v9fs_acl_mode(struct inode *dir, umode_t *modep, | |||
| 212 | return 0; | 212 | return 0; |
| 213 | } | 213 | } |
| 214 | 214 | ||
| 215 | static int v9fs_remote_get_acl(struct dentry *dentry, const char *name, | 215 | static int v9fs_xattr_get_acl(const struct xattr_handler *handler, |
| 216 | void *buffer, size_t size, int type) | 216 | struct dentry *dentry, const char *name, |
| 217 | { | 217 | void *buffer, size_t size) |
| 218 | char *full_name; | ||
| 219 | |||
| 220 | switch (type) { | ||
| 221 | case ACL_TYPE_ACCESS: | ||
| 222 | full_name = POSIX_ACL_XATTR_ACCESS; | ||
| 223 | break; | ||
| 224 | case ACL_TYPE_DEFAULT: | ||
| 225 | full_name = POSIX_ACL_XATTR_DEFAULT; | ||
| 226 | break; | ||
| 227 | default: | ||
| 228 | BUG(); | ||
| 229 | } | ||
| 230 | return v9fs_xattr_get(dentry, full_name, buffer, size); | ||
| 231 | } | ||
| 232 | |||
| 233 | static int v9fs_xattr_get_acl(struct dentry *dentry, const char *name, | ||
| 234 | void *buffer, size_t size, int type) | ||
| 235 | { | 218 | { |
| 236 | struct v9fs_session_info *v9ses; | 219 | struct v9fs_session_info *v9ses; |
| 237 | struct posix_acl *acl; | 220 | struct posix_acl *acl; |
| @@ -245,9 +228,9 @@ static int v9fs_xattr_get_acl(struct dentry *dentry, const char *name, | |||
| 245 | * We allow set/get/list of acl when access=client is not specified | 228 | * We allow set/get/list of acl when access=client is not specified |
| 246 | */ | 229 | */ |
| 247 | if ((v9ses->flags & V9FS_ACCESS_MASK) != V9FS_ACCESS_CLIENT) | 230 | if ((v9ses->flags & V9FS_ACCESS_MASK) != V9FS_ACCESS_CLIENT) |
| 248 | return v9fs_remote_get_acl(dentry, name, buffer, size, type); | 231 | return v9fs_xattr_get(dentry, handler->prefix, buffer, size); |
| 249 | 232 | ||
| 250 | acl = v9fs_get_cached_acl(d_inode(dentry), type); | 233 | acl = v9fs_get_cached_acl(d_inode(dentry), handler->flags); |
| 251 | if (IS_ERR(acl)) | 234 | if (IS_ERR(acl)) |
| 252 | return PTR_ERR(acl); | 235 | return PTR_ERR(acl); |
| 253 | if (acl == NULL) | 236 | if (acl == NULL) |
| @@ -258,29 +241,9 @@ static int v9fs_xattr_get_acl(struct dentry *dentry, const char *name, | |||
| 258 | return error; | 241 | return error; |
| 259 | } | 242 | } |
| 260 | 243 | ||
| 261 | static int v9fs_remote_set_acl(struct dentry *dentry, const char *name, | 244 | static int v9fs_xattr_set_acl(const struct xattr_handler *handler, |
| 262 | const void *value, size_t size, | 245 | struct dentry *dentry, const char *name, |
| 263 | int flags, int type) | 246 | const void *value, size_t size, int flags) |
| 264 | { | ||
| 265 | char *full_name; | ||
| 266 | |||
| 267 | switch (type) { | ||
| 268 | case ACL_TYPE_ACCESS: | ||
| 269 | full_name = POSIX_ACL_XATTR_ACCESS; | ||
| 270 | break; | ||
| 271 | case ACL_TYPE_DEFAULT: | ||
| 272 | full_name = POSIX_ACL_XATTR_DEFAULT; | ||
| 273 | break; | ||
| 274 | default: | ||
| 275 | BUG(); | ||
| 276 | } | ||
| 277 | return v9fs_xattr_set(dentry, full_name, value, size, flags); | ||
| 278 | } | ||
| 279 | |||
| 280 | |||
| 281 | static int v9fs_xattr_set_acl(struct dentry *dentry, const char *name, | ||
| 282 | const void *value, size_t size, | ||
| 283 | int flags, int type) | ||
| 284 | { | 247 | { |
| 285 | int retval; | 248 | int retval; |
| 286 | struct posix_acl *acl; | 249 | struct posix_acl *acl; |
| @@ -296,8 +259,8 @@ static int v9fs_xattr_set_acl(struct dentry *dentry, const char *name, | |||
| 296 | * xattr value. We leave it to the server to validate | 259 | * xattr value. We leave it to the server to validate |
| 297 | */ | 260 | */ |
| 298 | if ((v9ses->flags & V9FS_ACCESS_MASK) != V9FS_ACCESS_CLIENT) | 261 | if ((v9ses->flags & V9FS_ACCESS_MASK) != V9FS_ACCESS_CLIENT) |
| 299 | return v9fs_remote_set_acl(dentry, name, | 262 | return v9fs_xattr_set(dentry, handler->prefix, value, size, |
| 300 | value, size, flags, type); | 263 | flags); |
| 301 | 264 | ||
| 302 | if (S_ISLNK(inode->i_mode)) | 265 | if (S_ISLNK(inode->i_mode)) |
| 303 | return -EOPNOTSUPP; | 266 | return -EOPNOTSUPP; |
| @@ -316,9 +279,8 @@ static int v9fs_xattr_set_acl(struct dentry *dentry, const char *name, | |||
| 316 | } else | 279 | } else |
| 317 | acl = NULL; | 280 | acl = NULL; |
| 318 | 281 | ||
| 319 | switch (type) { | 282 | switch (handler->flags) { |
| 320 | case ACL_TYPE_ACCESS: | 283 | case ACL_TYPE_ACCESS: |
| 321 | name = POSIX_ACL_XATTR_ACCESS; | ||
| 322 | if (acl) { | 284 | if (acl) { |
| 323 | umode_t mode = inode->i_mode; | 285 | umode_t mode = inode->i_mode; |
| 324 | retval = posix_acl_equiv_mode(acl, &mode); | 286 | retval = posix_acl_equiv_mode(acl, &mode); |
| @@ -349,7 +311,6 @@ static int v9fs_xattr_set_acl(struct dentry *dentry, const char *name, | |||
| 349 | } | 311 | } |
| 350 | break; | 312 | break; |
| 351 | case ACL_TYPE_DEFAULT: | 313 | case ACL_TYPE_DEFAULT: |
| 352 | name = POSIX_ACL_XATTR_DEFAULT; | ||
| 353 | if (!S_ISDIR(inode->i_mode)) { | 314 | if (!S_ISDIR(inode->i_mode)) { |
| 354 | retval = acl ? -EINVAL : 0; | 315 | retval = acl ? -EINVAL : 0; |
| 355 | goto err_out; | 316 | goto err_out; |
| @@ -358,9 +319,9 @@ static int v9fs_xattr_set_acl(struct dentry *dentry, const char *name, | |||
| 358 | default: | 319 | default: |
| 359 | BUG(); | 320 | BUG(); |
| 360 | } | 321 | } |
| 361 | retval = v9fs_xattr_set(dentry, name, value, size, flags); | 322 | retval = v9fs_xattr_set(dentry, handler->prefix, value, size, flags); |
| 362 | if (!retval) | 323 | if (!retval) |
| 363 | set_cached_acl(inode, type, acl); | 324 | set_cached_acl(inode, handler->flags, acl); |
| 364 | err_out: | 325 | err_out: |
| 365 | posix_acl_release(acl); | 326 | posix_acl_release(acl); |
| 366 | return retval; | 327 | return retval; |
diff --git a/fs/9p/xattr.c b/fs/9p/xattr.c index 0cf44b6cccd6..e3d026ac382e 100644 --- a/fs/9p/xattr.c +++ b/fs/9p/xattr.c | |||
| @@ -137,6 +137,48 @@ ssize_t v9fs_listxattr(struct dentry *dentry, char *buffer, size_t buffer_size) | |||
| 137 | return v9fs_xattr_get(dentry, NULL, buffer, buffer_size); | 137 | return v9fs_xattr_get(dentry, NULL, buffer, buffer_size); |
| 138 | } | 138 | } |
| 139 | 139 | ||
| 140 | static int v9fs_xattr_handler_get(const struct xattr_handler *handler, | ||
| 141 | struct dentry *dentry, const char *name, | ||
| 142 | void *buffer, size_t size) | ||
| 143 | { | ||
| 144 | const char *full_name = xattr_full_name(handler, name); | ||
| 145 | |||
| 146 | if (strcmp(name, "") == 0) | ||
| 147 | return -EINVAL; | ||
| 148 | return v9fs_xattr_get(dentry, full_name, buffer, size); | ||
| 149 | } | ||
| 150 | |||
| 151 | static int v9fs_xattr_handler_set(const struct xattr_handler *handler, | ||
| 152 | struct dentry *dentry, const char *name, | ||
| 153 | const void *value, size_t size, int flags) | ||
| 154 | { | ||
| 155 | const char *full_name = xattr_full_name(handler, name); | ||
| 156 | |||
| 157 | if (strcmp(name, "") == 0) | ||
| 158 | return -EINVAL; | ||
| 159 | return v9fs_xattr_set(dentry, full_name, value, size, flags); | ||
| 160 | } | ||
| 161 | |||
| 162 | static struct xattr_handler v9fs_xattr_user_handler = { | ||
| 163 | .prefix = XATTR_USER_PREFIX, | ||
| 164 | .get = v9fs_xattr_handler_get, | ||
| 165 | .set = v9fs_xattr_handler_set, | ||
| 166 | }; | ||
| 167 | |||
| 168 | static struct xattr_handler v9fs_xattr_trusted_handler = { | ||
| 169 | .prefix = XATTR_TRUSTED_PREFIX, | ||
| 170 | .get = v9fs_xattr_handler_get, | ||
| 171 | .set = v9fs_xattr_handler_set, | ||
| 172 | }; | ||
| 173 | |||
| 174 | #ifdef CONFIG_9P_FS_SECURITY | ||
| 175 | static struct xattr_handler v9fs_xattr_security_handler = { | ||
| 176 | .prefix = XATTR_SECURITY_PREFIX, | ||
| 177 | .get = v9fs_xattr_handler_get, | ||
| 178 | .set = v9fs_xattr_handler_set, | ||
| 179 | }; | ||
| 180 | #endif | ||
| 181 | |||
| 140 | const struct xattr_handler *v9fs_xattr_handlers[] = { | 182 | const struct xattr_handler *v9fs_xattr_handlers[] = { |
| 141 | &v9fs_xattr_user_handler, | 183 | &v9fs_xattr_user_handler, |
| 142 | &v9fs_xattr_trusted_handler, | 184 | &v9fs_xattr_trusted_handler, |
diff --git a/fs/9p/xattr.h b/fs/9p/xattr.h index d3e2ea3840be..c63c3bea5de5 100644 --- a/fs/9p/xattr.h +++ b/fs/9p/xattr.h | |||
| @@ -19,9 +19,6 @@ | |||
| 19 | #include <net/9p/client.h> | 19 | #include <net/9p/client.h> |
| 20 | 20 | ||
| 21 | extern const struct xattr_handler *v9fs_xattr_handlers[]; | 21 | extern const struct xattr_handler *v9fs_xattr_handlers[]; |
| 22 | extern struct xattr_handler v9fs_xattr_user_handler; | ||
| 23 | extern struct xattr_handler v9fs_xattr_trusted_handler; | ||
| 24 | extern struct xattr_handler v9fs_xattr_security_handler; | ||
| 25 | extern const struct xattr_handler v9fs_xattr_acl_access_handler; | 22 | extern const struct xattr_handler v9fs_xattr_acl_access_handler; |
| 26 | extern const struct xattr_handler v9fs_xattr_acl_default_handler; | 23 | extern const struct xattr_handler v9fs_xattr_acl_default_handler; |
| 27 | 24 | ||
diff --git a/fs/9p/xattr_security.c b/fs/9p/xattr_security.c deleted file mode 100644 index cb247a142a6e..000000000000 --- a/fs/9p/xattr_security.c +++ /dev/null | |||
| @@ -1,80 +0,0 @@ | |||
| 1 | /* | ||
| 2 | * Copyright IBM Corporation, 2010 | ||
| 3 | * Author Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com> | ||
| 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_security_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_SECURITY_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_SECURITY_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_security_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_SECURITY_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_SECURITY_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_security_handler = { | ||
| 77 | .prefix = XATTR_SECURITY_PREFIX, | ||
| 78 | .get = v9fs_xattr_security_get, | ||
| 79 | .set = v9fs_xattr_security_set, | ||
| 80 | }; | ||
diff --git a/fs/9p/xattr_trusted.c b/fs/9p/xattr_trusted.c deleted file mode 100644 index e30d33b8a3fb..000000000000 --- a/fs/9p/xattr_trusted.c +++ /dev/null | |||
| @@ -1,80 +0,0 @@ | |||
| 1 | /* | ||
| 2 | * Copyright IBM Corporation, 2010 | ||
| 3 | * Author Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com> | ||
| 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_trusted_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_TRUSTED_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_TRUSTED_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_trusted_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_TRUSTED_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_TRUSTED_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_trusted_handler = { | ||
| 77 | .prefix = XATTR_TRUSTED_PREFIX, | ||
| 78 | .get = v9fs_xattr_trusted_get, | ||
| 79 | .set = v9fs_xattr_trusted_set, | ||
| 80 | }; | ||
diff --git a/fs/9p/xattr_user.c b/fs/9p/xattr_user.c deleted file mode 100644 index d0b701b72080..000000000000 --- a/fs/9p/xattr_user.c +++ /dev/null | |||
| @@ -1,80 +0,0 @@ | |||
| 1 | /* | ||
| 2 | * Copyright IBM Corporation, 2010 | ||
| 3 | * Author Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com> | ||
| 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 | }; | ||
