xattr.h 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * Copyright (C) 2017-2018 HUAWEI, Inc.
  4. * https://www.huawei.com/
  5. */
  6. #ifndef __EROFS_XATTR_H
  7. #define __EROFS_XATTR_H
  8. #include "internal.h"
  9. #include <linux/posix_acl_xattr.h>
  10. #include <linux/xattr.h>
  11. /* Attribute not found */
  12. #define ENOATTR ENODATA
  13. #ifdef CONFIG_EROFS_FS_XATTR
  14. extern const struct xattr_handler erofs_xattr_user_handler;
  15. extern const struct xattr_handler erofs_xattr_trusted_handler;
  16. extern const struct xattr_handler erofs_xattr_security_handler;
  17. static inline const char *erofs_xattr_prefix(unsigned int idx,
  18. struct dentry *dentry)
  19. {
  20. const struct xattr_handler *handler = NULL;
  21. static const struct xattr_handler * const xattr_handler_map[] = {
  22. [EROFS_XATTR_INDEX_USER] = &erofs_xattr_user_handler,
  23. #ifdef CONFIG_EROFS_FS_POSIX_ACL
  24. [EROFS_XATTR_INDEX_POSIX_ACL_ACCESS] = &nop_posix_acl_access,
  25. [EROFS_XATTR_INDEX_POSIX_ACL_DEFAULT] = &nop_posix_acl_default,
  26. #endif
  27. [EROFS_XATTR_INDEX_TRUSTED] = &erofs_xattr_trusted_handler,
  28. #ifdef CONFIG_EROFS_FS_SECURITY
  29. [EROFS_XATTR_INDEX_SECURITY] = &erofs_xattr_security_handler,
  30. #endif
  31. };
  32. if (idx && idx < ARRAY_SIZE(xattr_handler_map))
  33. handler = xattr_handler_map[idx];
  34. if (!xattr_handler_can_list(handler, dentry))
  35. return NULL;
  36. return xattr_prefix(handler);
  37. }
  38. extern const struct xattr_handler * const erofs_xattr_handlers[];
  39. int erofs_xattr_prefixes_init(struct super_block *sb);
  40. void erofs_xattr_prefixes_cleanup(struct super_block *sb);
  41. int erofs_getxattr(struct inode *, int, const char *, void *, size_t);
  42. ssize_t erofs_listxattr(struct dentry *, char *, size_t);
  43. #else
  44. static inline int erofs_xattr_prefixes_init(struct super_block *sb) { return 0; }
  45. static inline void erofs_xattr_prefixes_cleanup(struct super_block *sb) {}
  46. static inline int erofs_getxattr(struct inode *inode, int index,
  47. const char *name, void *buffer,
  48. size_t buffer_size)
  49. {
  50. return -EOPNOTSUPP;
  51. }
  52. #define erofs_listxattr (NULL)
  53. #define erofs_xattr_handlers (NULL)
  54. #endif /* !CONFIG_EROFS_FS_XATTR */
  55. #ifdef CONFIG_EROFS_FS_POSIX_ACL
  56. struct posix_acl *erofs_get_acl(struct inode *inode, int type, bool rcu);
  57. #else
  58. #define erofs_get_acl (NULL)
  59. #endif
  60. #endif