xattr_user.c 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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(struct dentry *dentry, char *list, size_t list_size,
  13. const char *name, size_t name_len, int type)
  14. {
  15. const size_t prefix_len = XATTR_USER_PREFIX_LEN;
  16. const size_t total_len = prefix_len + name_len + 1;
  17. if (!test_opt(dentry->d_sb, XATTR_USER))
  18. return 0;
  19. if (list && total_len <= list_size) {
  20. memcpy(list, XATTR_USER_PREFIX, prefix_len);
  21. memcpy(list+prefix_len, name, name_len);
  22. list[prefix_len + name_len] = '\0';
  23. }
  24. return total_len;
  25. }
  26. static int
  27. ext2_xattr_user_get(struct dentry *dentry, const char *name,
  28. void *buffer, size_t size, int type)
  29. {
  30. if (strcmp(name, "") == 0)
  31. return -EINVAL;
  32. if (!test_opt(dentry->d_sb, XATTR_USER))
  33. return -EOPNOTSUPP;
  34. return ext2_xattr_get(d_inode(dentry), EXT2_XATTR_INDEX_USER,
  35. name, buffer, size);
  36. }
  37. static int
  38. ext2_xattr_user_set(struct dentry *dentry, const char *name,
  39. const void *value, size_t size, int flags, int type)
  40. {
  41. if (strcmp(name, "") == 0)
  42. return -EINVAL;
  43. if (!test_opt(dentry->d_sb, XATTR_USER))
  44. return -EOPNOTSUPP;
  45. return ext2_xattr_set(d_inode(dentry), EXT2_XATTR_INDEX_USER,
  46. name, value, size, flags);
  47. }
  48. const struct xattr_handler ext2_xattr_user_handler = {
  49. .prefix = XATTR_USER_PREFIX,
  50. .list = ext2_xattr_user_list,
  51. .get = ext2_xattr_user_get,
  52. .set = ext2_xattr_user_set,
  53. };