original development tree for Linux kernel GTP module; now long in mainline.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

61 lines
1.6 KiB

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