xattr_user.c 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. /*
  2. * linux/fs/ext3/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/module.h>
  8. #include <linux/string.h>
  9. #include <linux/fs.h>
  10. #include <linux/ext3_jbd.h>
  11. #include <linux/ext3_fs.h>
  12. #include "xattr.h"
  13. #define XATTR_USER_PREFIX "user."
  14. static size_t
  15. ext3_xattr_user_list(struct inode *inode, char *list, size_t list_size,
  16. const char *name, size_t name_len)
  17. {
  18. const size_t prefix_len = sizeof(XATTR_USER_PREFIX)-1;
  19. const size_t total_len = prefix_len + name_len + 1;
  20. if (!test_opt(inode->i_sb, XATTR_USER))
  21. return 0;
  22. if (list && total_len <= list_size) {
  23. memcpy(list, XATTR_USER_PREFIX, prefix_len);
  24. memcpy(list+prefix_len, name, name_len);
  25. list[prefix_len + name_len] = '\0';
  26. }
  27. return total_len;
  28. }
  29. static int
  30. ext3_xattr_user_get(struct inode *inode, const char *name,
  31. void *buffer, size_t size)
  32. {
  33. if (strcmp(name, "") == 0)
  34. return -EINVAL;
  35. if (!test_opt(inode->i_sb, XATTR_USER))
  36. return -EOPNOTSUPP;
  37. return ext3_xattr_get(inode, EXT3_XATTR_INDEX_USER, name, buffer, size);
  38. }
  39. static int
  40. ext3_xattr_user_set(struct inode *inode, const char *name,
  41. const void *value, size_t size, int flags)
  42. {
  43. if (strcmp(name, "") == 0)
  44. return -EINVAL;
  45. if (!test_opt(inode->i_sb, XATTR_USER))
  46. return -EOPNOTSUPP;
  47. return ext3_xattr_set(inode, EXT3_XATTR_INDEX_USER, name,
  48. value, size, flags);
  49. }
  50. struct xattr_handler ext3_xattr_user_handler = {
  51. .prefix = XATTR_USER_PREFIX,
  52. .list = ext3_xattr_user_list,
  53. .get = ext3_xattr_user_get,
  54. .set = ext3_xattr_user_set,
  55. };