xattr_user.c 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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. #include <linux/module.h>
  15. #include <linux/string.h>
  16. #include <linux/fs.h>
  17. #include <linux/slab.h>
  18. #include "xattr.h"
  19. static int v9fs_xattr_user_get(struct dentry *dentry, const char *name,
  20. void *buffer, size_t size, int type)
  21. {
  22. int retval;
  23. char *full_name;
  24. size_t name_len;
  25. size_t prefix_len = XATTR_USER_PREFIX_LEN;
  26. if (name == NULL)
  27. return -EINVAL;
  28. if (strcmp(name, "") == 0)
  29. return -EINVAL;
  30. name_len = strlen(name);
  31. full_name = kmalloc(prefix_len + name_len + 1 , GFP_KERNEL);
  32. if (!full_name)
  33. return -ENOMEM;
  34. memcpy(full_name, XATTR_USER_PREFIX, prefix_len);
  35. memcpy(full_name+prefix_len, name, name_len);
  36. full_name[prefix_len + name_len] = '\0';
  37. retval = v9fs_xattr_get(dentry, full_name, buffer, size);
  38. kfree(full_name);
  39. return retval;
  40. }
  41. static int v9fs_xattr_user_set(struct dentry *dentry, const char *name,
  42. const void *value, size_t size, int flags, int type)
  43. {
  44. int retval;
  45. char *full_name;
  46. size_t name_len;
  47. size_t prefix_len = XATTR_USER_PREFIX_LEN;
  48. if (name == NULL)
  49. return -EINVAL;
  50. if (strcmp(name, "") == 0)
  51. return -EINVAL;
  52. name_len = strlen(name);
  53. full_name = kmalloc(prefix_len + name_len + 1 , GFP_KERNEL);
  54. if (!full_name)
  55. return -ENOMEM;
  56. memcpy(full_name, XATTR_USER_PREFIX, prefix_len);
  57. memcpy(full_name + prefix_len, name, name_len);
  58. full_name[prefix_len + name_len] = '\0';
  59. retval = v9fs_xattr_set(dentry, full_name, value, size, flags);
  60. kfree(full_name);
  61. return retval;
  62. }
  63. struct xattr_handler v9fs_xattr_user_handler = {
  64. .prefix = XATTR_USER_PREFIX,
  65. .get = v9fs_xattr_user_get,
  66. .set = v9fs_xattr_user_set,
  67. };