xattr_user.c 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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/module.h>
  9. #include <linux/string.h>
  10. #include "ext2.h"
  11. #include "xattr.h"
  12. #define XATTR_USER_PREFIX "user."
  13. static size_t
  14. ext2_xattr_user_list(struct inode *inode, char *list, size_t list_size,
  15. const char *name, size_t name_len)
  16. {
  17. const size_t prefix_len = sizeof(XATTR_USER_PREFIX)-1;
  18. const size_t total_len = prefix_len + name_len + 1;
  19. if (!test_opt(inode->i_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. ext2_xattr_user_get(struct inode *inode, const char *name,
  30. void *buffer, size_t size)
  31. {
  32. if (strcmp(name, "") == 0)
  33. return -EINVAL;
  34. if (!test_opt(inode->i_sb, XATTR_USER))
  35. return -EOPNOTSUPP;
  36. return ext2_xattr_get(inode, EXT2_XATTR_INDEX_USER, name, buffer, size);
  37. }
  38. static int
  39. ext2_xattr_user_set(struct inode *inode, const char *name,
  40. const void *value, size_t size, int flags)
  41. {
  42. if (strcmp(name, "") == 0)
  43. return -EINVAL;
  44. if (!test_opt(inode->i_sb, XATTR_USER))
  45. return -EOPNOTSUPP;
  46. return ext2_xattr_set(inode, EXT2_XATTR_INDEX_USER, name,
  47. value, size, flags);
  48. }
  49. struct xattr_handler ext2_xattr_user_handler = {
  50. .prefix = XATTR_USER_PREFIX,
  51. .list = ext2_xattr_user_list,
  52. .get = ext2_xattr_user_get,
  53. .set = ext2_xattr_user_set,
  54. };