xattr_user.c 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. /*
  2. * linux/fs/ext4/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/string.h>
  8. #include <linux/fs.h>
  9. #include "ext4_jbd2.h"
  10. #include "ext4.h"
  11. #include "xattr.h"
  12. static size_t
  13. ext4_xattr_user_list(const struct xattr_handler *handler,
  14. struct dentry *dentry, char *list, size_t list_size,
  15. const char *name, size_t name_len)
  16. {
  17. const size_t prefix_len = XATTR_USER_PREFIX_LEN;
  18. const size_t total_len = prefix_len + name_len + 1;
  19. if (!test_opt(dentry->d_sb, XATTR_USER))
  20. return 0;
  21. if (list && total_len <= list_size) {
  22. memcpy(list, XATTR_USER_PREFIX, prefix_len);
  23. memcpy(list+prefix_len, name, name_len);
  24. list[prefix_len + name_len] = '\0';
  25. }
  26. return total_len;
  27. }
  28. static int
  29. ext4_xattr_user_get(const struct xattr_handler *handler,
  30. struct dentry *dentry, const char *name,
  31. void *buffer, size_t size)
  32. {
  33. if (strcmp(name, "") == 0)
  34. return -EINVAL;
  35. if (!test_opt(dentry->d_sb, XATTR_USER))
  36. return -EOPNOTSUPP;
  37. return ext4_xattr_get(d_inode(dentry), EXT4_XATTR_INDEX_USER,
  38. name, buffer, size);
  39. }
  40. static int
  41. ext4_xattr_user_set(const struct xattr_handler *handler,
  42. struct dentry *dentry, const char *name,
  43. const void *value, size_t size, int flags)
  44. {
  45. if (strcmp(name, "") == 0)
  46. return -EINVAL;
  47. if (!test_opt(dentry->d_sb, XATTR_USER))
  48. return -EOPNOTSUPP;
  49. return ext4_xattr_set(d_inode(dentry), EXT4_XATTR_INDEX_USER,
  50. name, value, size, flags);
  51. }
  52. const struct xattr_handler ext4_xattr_user_handler = {
  53. .prefix = XATTR_USER_PREFIX,
  54. .list = ext4_xattr_user_list,
  55. .get = ext4_xattr_user_get,
  56. .set = ext4_xattr_user_set,
  57. };