147e4937aSGao Xiang /* SPDX-License-Identifier: GPL-2.0-only */ 247e4937aSGao Xiang /* 347e4937aSGao Xiang * Copyright (C) 2017-2018 HUAWEI, Inc. 4592e7cd0SAlexander A. Klimov * https://www.huawei.com/ 547e4937aSGao Xiang */ 647e4937aSGao Xiang #ifndef __EROFS_XATTR_H 747e4937aSGao Xiang #define __EROFS_XATTR_H 847e4937aSGao Xiang 947e4937aSGao Xiang #include "internal.h" 1047e4937aSGao Xiang #include <linux/posix_acl_xattr.h> 1147e4937aSGao Xiang #include <linux/xattr.h> 1247e4937aSGao Xiang 1347e4937aSGao Xiang /* Attribute not found */ 1447e4937aSGao Xiang #define ENOATTR ENODATA 1547e4937aSGao Xiang 1647e4937aSGao Xiang #ifdef CONFIG_EROFS_FS_XATTR 1747e4937aSGao Xiang extern const struct xattr_handler erofs_xattr_user_handler; 1847e4937aSGao Xiang extern const struct xattr_handler erofs_xattr_trusted_handler; 1947e4937aSGao Xiang extern const struct xattr_handler erofs_xattr_security_handler; 2047e4937aSGao Xiang 2147e4937aSGao Xiang static inline const struct xattr_handler *erofs_xattr_handler(unsigned int idx) 2247e4937aSGao Xiang { 2347e4937aSGao Xiang static const struct xattr_handler *xattr_handler_map[] = { 2447e4937aSGao Xiang [EROFS_XATTR_INDEX_USER] = &erofs_xattr_user_handler, 2547e4937aSGao Xiang #ifdef CONFIG_EROFS_FS_POSIX_ACL 26a55861c8SVladimir Zapolskiy [EROFS_XATTR_INDEX_POSIX_ACL_ACCESS] = 27a55861c8SVladimir Zapolskiy &posix_acl_access_xattr_handler, 2847e4937aSGao Xiang [EROFS_XATTR_INDEX_POSIX_ACL_DEFAULT] = 2947e4937aSGao Xiang &posix_acl_default_xattr_handler, 3047e4937aSGao Xiang #endif 3147e4937aSGao Xiang [EROFS_XATTR_INDEX_TRUSTED] = &erofs_xattr_trusted_handler, 3247e4937aSGao Xiang #ifdef CONFIG_EROFS_FS_SECURITY 3347e4937aSGao Xiang [EROFS_XATTR_INDEX_SECURITY] = &erofs_xattr_security_handler, 3447e4937aSGao Xiang #endif 3547e4937aSGao Xiang }; 3647e4937aSGao Xiang 3747e4937aSGao Xiang return idx && idx < ARRAY_SIZE(xattr_handler_map) ? 3847e4937aSGao Xiang xattr_handler_map[idx] : NULL; 3947e4937aSGao Xiang } 4047e4937aSGao Xiang 4147e4937aSGao Xiang extern const struct xattr_handler *erofs_xattr_handlers[]; 4247e4937aSGao Xiang 43*9e382914SJingbo Xu int erofs_xattr_prefixes_init(struct super_block *sb); 44*9e382914SJingbo Xu void erofs_xattr_prefixes_cleanup(struct super_block *sb); 4547e4937aSGao Xiang int erofs_getxattr(struct inode *, int, const char *, void *, size_t); 4647e4937aSGao Xiang ssize_t erofs_listxattr(struct dentry *, char *, size_t); 4747e4937aSGao Xiang #else 48*9e382914SJingbo Xu static inline int erofs_xattr_prefixes_init(struct super_block *sb) { return 0; } 49*9e382914SJingbo Xu static inline void erofs_xattr_prefixes_cleanup(struct super_block *sb) {} 5047e4937aSGao Xiang static inline int erofs_getxattr(struct inode *inode, int index, 5147e4937aSGao Xiang const char *name, void *buffer, 5247e4937aSGao Xiang size_t buffer_size) 5347e4937aSGao Xiang { 5447e4937aSGao Xiang return -EOPNOTSUPP; 5547e4937aSGao Xiang } 5647e4937aSGao Xiang 57e7cda1eeSChengguang Xu #define erofs_listxattr (NULL) 58e7cda1eeSChengguang Xu #define erofs_xattr_handlers (NULL) 5947e4937aSGao Xiang #endif /* !CONFIG_EROFS_FS_XATTR */ 6047e4937aSGao Xiang 6147e4937aSGao Xiang #ifdef CONFIG_EROFS_FS_POSIX_ACL 620cad6246SMiklos Szeredi struct posix_acl *erofs_get_acl(struct inode *inode, int type, bool rcu); 6347e4937aSGao Xiang #else 6447e4937aSGao Xiang #define erofs_get_acl (NULL) 6547e4937aSGao Xiang #endif 6647e4937aSGao Xiang 6747e4937aSGao Xiang #endif 68