xattr_user.c 1.5 KB

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