xattr_user.c 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. /*
  2. * linux/fs/ext2/xattr_user.c
  3. * Handler for extended user attributes.
  4. *
  5. * Copyright (C) 2001 by Andreas Gruenbacher, <a.gruenbacher@computer.org>
  6. */
  7. #include <linux/init.h>
  8. #include <linux/string.h>
  9. #include "ext2.h"
  10. #include "xattr.h"
  11. static size_t
  12. ext2_xattr_user_list(const struct xattr_handler *handler,
  13. struct dentry *dentry, char *list, size_t list_size,
  14. const char *name, size_t name_len)
  15. {
  16. const size_t prefix_len = XATTR_USER_PREFIX_LEN;
  17. const size_t total_len = prefix_len + name_len + 1;
  18. if (!test_opt(dentry->d_sb, XATTR_USER))
  19. return 0;
  20. if (list && total_len <= list_size) {
  21. memcpy(list, XATTR_USER_PREFIX, prefix_len);
  22. memcpy(list+prefix_len, name, name_len);
  23. list[prefix_len + name_len] = '\0';
  24. }
  25. return total_len;
  26. }
  27. static int
  28. ext2_xattr_user_get(const struct xattr_handler *handler,
  29. struct dentry *dentry, const char *name,
  30. void *buffer, size_t size)
  31. {
  32. if (strcmp(name, "") == 0)
  33. return -EINVAL;
  34. if (!test_opt(dentry->d_sb, XATTR_USER))
  35. return -EOPNOTSUPP;
  36. return ext2_xattr_get(d_inode(dentry), EXT2_XATTR_INDEX_USER,
  37. name, buffer, size);
  38. }
  39. static int
  40. ext2_xattr_user_set(const struct xattr_handler *handler,
  41. struct dentry *dentry, const char *name,
  42. const void *value, size_t size, int flags)
  43. {
  44. if (strcmp(name, "") == 0)
  45. return -EINVAL;
  46. if (!test_opt(dentry->d_sb, XATTR_USER))
  47. return -EOPNOTSUPP;
  48. return ext2_xattr_set(d_inode(dentry), EXT2_XATTR_INDEX_USER,
  49. name, value, size, flags);
  50. }
  51. const struct xattr_handler ext2_xattr_user_handler = {
  52. .prefix = XATTR_USER_PREFIX,
  53. .list = ext2_xattr_user_list,
  54. .get = ext2_xattr_user_get,
  55. .set = ext2_xattr_user_set,
  56. };