147e4937aSGao Xiang /* SPDX-License-Identifier: GPL-2.0-only */ 247e4937aSGao Xiang /* 347e4937aSGao Xiang * Copyright (C) 2017-2018 HUAWEI, Inc. 447e4937aSGao Xiang * http://www.huawei.com/ 547e4937aSGao Xiang * Created by Gao Xiang <gaoxiang25@huawei.com> 647e4937aSGao Xiang */ 747e4937aSGao Xiang #ifndef __EROFS_XATTR_H 847e4937aSGao Xiang #define __EROFS_XATTR_H 947e4937aSGao Xiang 1047e4937aSGao Xiang #include "internal.h" 1147e4937aSGao Xiang #include <linux/posix_acl_xattr.h> 1247e4937aSGao Xiang #include <linux/xattr.h> 1347e4937aSGao Xiang 1447e4937aSGao Xiang /* Attribute not found */ 1547e4937aSGao Xiang #define ENOATTR ENODATA 1647e4937aSGao Xiang 1747e4937aSGao Xiang static inline unsigned int inlinexattr_header_size(struct inode *inode) 1847e4937aSGao Xiang { 19a5876e24SGao Xiang return sizeof(struct erofs_xattr_ibody_header) + 20a5876e24SGao Xiang sizeof(u32) * EROFS_I(inode)->xattr_shared_count; 2147e4937aSGao Xiang } 2247e4937aSGao Xiang 2347e4937aSGao Xiang static inline erofs_blk_t xattrblock_addr(struct erofs_sb_info *sbi, 2447e4937aSGao Xiang unsigned int xattr_id) 2547e4937aSGao Xiang { 2647e4937aSGao Xiang #ifdef CONFIG_EROFS_FS_XATTR 2747e4937aSGao Xiang return sbi->xattr_blkaddr + 2847e4937aSGao Xiang xattr_id * sizeof(__u32) / EROFS_BLKSIZ; 2947e4937aSGao Xiang #else 3047e4937aSGao Xiang return 0; 3147e4937aSGao Xiang #endif 3247e4937aSGao Xiang } 3347e4937aSGao Xiang 3447e4937aSGao Xiang static inline unsigned int xattrblock_offset(struct erofs_sb_info *sbi, 3547e4937aSGao Xiang unsigned int xattr_id) 3647e4937aSGao Xiang { 3747e4937aSGao Xiang return (xattr_id * sizeof(__u32)) % EROFS_BLKSIZ; 3847e4937aSGao Xiang } 3947e4937aSGao Xiang 4047e4937aSGao Xiang #ifdef CONFIG_EROFS_FS_XATTR 4147e4937aSGao Xiang extern const struct xattr_handler erofs_xattr_user_handler; 4247e4937aSGao Xiang extern const struct xattr_handler erofs_xattr_trusted_handler; 4347e4937aSGao Xiang #ifdef CONFIG_EROFS_FS_SECURITY 4447e4937aSGao Xiang extern const struct xattr_handler erofs_xattr_security_handler; 4547e4937aSGao Xiang #endif 4647e4937aSGao Xiang 4747e4937aSGao Xiang static inline const struct xattr_handler *erofs_xattr_handler(unsigned int idx) 4847e4937aSGao Xiang { 4947e4937aSGao Xiang static const struct xattr_handler *xattr_handler_map[] = { 5047e4937aSGao Xiang [EROFS_XATTR_INDEX_USER] = &erofs_xattr_user_handler, 5147e4937aSGao Xiang #ifdef CONFIG_EROFS_FS_POSIX_ACL 52a55861c8SVladimir Zapolskiy [EROFS_XATTR_INDEX_POSIX_ACL_ACCESS] = 53a55861c8SVladimir Zapolskiy &posix_acl_access_xattr_handler, 5447e4937aSGao Xiang [EROFS_XATTR_INDEX_POSIX_ACL_DEFAULT] = 5547e4937aSGao Xiang &posix_acl_default_xattr_handler, 5647e4937aSGao Xiang #endif 5747e4937aSGao Xiang [EROFS_XATTR_INDEX_TRUSTED] = &erofs_xattr_trusted_handler, 5847e4937aSGao Xiang #ifdef CONFIG_EROFS_FS_SECURITY 5947e4937aSGao Xiang [EROFS_XATTR_INDEX_SECURITY] = &erofs_xattr_security_handler, 6047e4937aSGao Xiang #endif 6147e4937aSGao Xiang }; 6247e4937aSGao Xiang 6347e4937aSGao Xiang return idx && idx < ARRAY_SIZE(xattr_handler_map) ? 6447e4937aSGao Xiang xattr_handler_map[idx] : NULL; 6547e4937aSGao Xiang } 6647e4937aSGao Xiang 6747e4937aSGao Xiang extern const struct xattr_handler *erofs_xattr_handlers[]; 6847e4937aSGao Xiang 6947e4937aSGao Xiang int erofs_getxattr(struct inode *, int, const char *, void *, size_t); 7047e4937aSGao Xiang ssize_t erofs_listxattr(struct dentry *, char *, size_t); 7147e4937aSGao Xiang #else 7247e4937aSGao Xiang static inline int erofs_getxattr(struct inode *inode, int index, 7347e4937aSGao Xiang const char *name, void *buffer, 7447e4937aSGao Xiang size_t buffer_size) 7547e4937aSGao Xiang { 7647e4937aSGao Xiang return -EOPNOTSUPP; 7747e4937aSGao Xiang } 7847e4937aSGao Xiang 7947e4937aSGao Xiang static inline ssize_t erofs_listxattr(struct dentry *dentry, 8047e4937aSGao Xiang char *buffer, size_t buffer_size) 8147e4937aSGao Xiang { 8247e4937aSGao Xiang return -EOPNOTSUPP; 8347e4937aSGao Xiang } 8447e4937aSGao Xiang #endif /* !CONFIG_EROFS_FS_XATTR */ 8547e4937aSGao Xiang 8647e4937aSGao Xiang #ifdef CONFIG_EROFS_FS_POSIX_ACL 8747e4937aSGao Xiang struct posix_acl *erofs_get_acl(struct inode *inode, int type); 8847e4937aSGao Xiang #else 8947e4937aSGao Xiang #define erofs_get_acl (NULL) 9047e4937aSGao Xiang #endif 9147e4937aSGao Xiang 9247e4937aSGao Xiang #endif 9347e4937aSGao Xiang 94