1*47e4937aSGao Xiang /* SPDX-License-Identifier: GPL-2.0-only */ 2*47e4937aSGao Xiang /* 3*47e4937aSGao Xiang * Copyright (C) 2017-2018 HUAWEI, Inc. 4*47e4937aSGao Xiang * http://www.huawei.com/ 5*47e4937aSGao Xiang * Created by Gao Xiang <gaoxiang25@huawei.com> 6*47e4937aSGao Xiang */ 7*47e4937aSGao Xiang #ifndef __EROFS_XATTR_H 8*47e4937aSGao Xiang #define __EROFS_XATTR_H 9*47e4937aSGao Xiang 10*47e4937aSGao Xiang #include "internal.h" 11*47e4937aSGao Xiang #include <linux/posix_acl_xattr.h> 12*47e4937aSGao Xiang #include <linux/xattr.h> 13*47e4937aSGao Xiang 14*47e4937aSGao Xiang /* Attribute not found */ 15*47e4937aSGao Xiang #define ENOATTR ENODATA 16*47e4937aSGao Xiang 17*47e4937aSGao Xiang static inline unsigned int inlinexattr_header_size(struct inode *inode) 18*47e4937aSGao Xiang { 19*47e4937aSGao Xiang return sizeof(struct erofs_xattr_ibody_header) 20*47e4937aSGao Xiang + sizeof(u32) * EROFS_V(inode)->xattr_shared_count; 21*47e4937aSGao Xiang } 22*47e4937aSGao Xiang 23*47e4937aSGao Xiang static inline erofs_blk_t xattrblock_addr(struct erofs_sb_info *sbi, 24*47e4937aSGao Xiang unsigned int xattr_id) 25*47e4937aSGao Xiang { 26*47e4937aSGao Xiang #ifdef CONFIG_EROFS_FS_XATTR 27*47e4937aSGao Xiang return sbi->xattr_blkaddr + 28*47e4937aSGao Xiang xattr_id * sizeof(__u32) / EROFS_BLKSIZ; 29*47e4937aSGao Xiang #else 30*47e4937aSGao Xiang return 0; 31*47e4937aSGao Xiang #endif 32*47e4937aSGao Xiang } 33*47e4937aSGao Xiang 34*47e4937aSGao Xiang static inline unsigned int xattrblock_offset(struct erofs_sb_info *sbi, 35*47e4937aSGao Xiang unsigned int xattr_id) 36*47e4937aSGao Xiang { 37*47e4937aSGao Xiang return (xattr_id * sizeof(__u32)) % EROFS_BLKSIZ; 38*47e4937aSGao Xiang } 39*47e4937aSGao Xiang 40*47e4937aSGao Xiang #ifdef CONFIG_EROFS_FS_XATTR 41*47e4937aSGao Xiang extern const struct xattr_handler erofs_xattr_user_handler; 42*47e4937aSGao Xiang extern const struct xattr_handler erofs_xattr_trusted_handler; 43*47e4937aSGao Xiang #ifdef CONFIG_EROFS_FS_SECURITY 44*47e4937aSGao Xiang extern const struct xattr_handler erofs_xattr_security_handler; 45*47e4937aSGao Xiang #endif 46*47e4937aSGao Xiang 47*47e4937aSGao Xiang static inline const struct xattr_handler *erofs_xattr_handler(unsigned int idx) 48*47e4937aSGao Xiang { 49*47e4937aSGao Xiang static const struct xattr_handler *xattr_handler_map[] = { 50*47e4937aSGao Xiang [EROFS_XATTR_INDEX_USER] = &erofs_xattr_user_handler, 51*47e4937aSGao Xiang #ifdef CONFIG_EROFS_FS_POSIX_ACL 52*47e4937aSGao Xiang [EROFS_XATTR_INDEX_POSIX_ACL_ACCESS] = &posix_acl_access_xattr_handler, 53*47e4937aSGao Xiang [EROFS_XATTR_INDEX_POSIX_ACL_DEFAULT] = 54*47e4937aSGao Xiang &posix_acl_default_xattr_handler, 55*47e4937aSGao Xiang #endif 56*47e4937aSGao Xiang [EROFS_XATTR_INDEX_TRUSTED] = &erofs_xattr_trusted_handler, 57*47e4937aSGao Xiang #ifdef CONFIG_EROFS_FS_SECURITY 58*47e4937aSGao Xiang [EROFS_XATTR_INDEX_SECURITY] = &erofs_xattr_security_handler, 59*47e4937aSGao Xiang #endif 60*47e4937aSGao Xiang }; 61*47e4937aSGao Xiang 62*47e4937aSGao Xiang return idx && idx < ARRAY_SIZE(xattr_handler_map) ? 63*47e4937aSGao Xiang xattr_handler_map[idx] : NULL; 64*47e4937aSGao Xiang } 65*47e4937aSGao Xiang 66*47e4937aSGao Xiang extern const struct xattr_handler *erofs_xattr_handlers[]; 67*47e4937aSGao Xiang 68*47e4937aSGao Xiang int erofs_getxattr(struct inode *, int, const char *, void *, size_t); 69*47e4937aSGao Xiang ssize_t erofs_listxattr(struct dentry *, char *, size_t); 70*47e4937aSGao Xiang #else 71*47e4937aSGao Xiang static inline int erofs_getxattr(struct inode *inode, int index, 72*47e4937aSGao Xiang const char *name, void *buffer, 73*47e4937aSGao Xiang size_t buffer_size) 74*47e4937aSGao Xiang { 75*47e4937aSGao Xiang return -EOPNOTSUPP; 76*47e4937aSGao Xiang } 77*47e4937aSGao Xiang 78*47e4937aSGao Xiang static inline ssize_t erofs_listxattr(struct dentry *dentry, 79*47e4937aSGao Xiang char *buffer, size_t buffer_size) 80*47e4937aSGao Xiang { 81*47e4937aSGao Xiang return -EOPNOTSUPP; 82*47e4937aSGao Xiang } 83*47e4937aSGao Xiang #endif /* !CONFIG_EROFS_FS_XATTR */ 84*47e4937aSGao Xiang 85*47e4937aSGao Xiang #ifdef CONFIG_EROFS_FS_POSIX_ACL 86*47e4937aSGao Xiang struct posix_acl *erofs_get_acl(struct inode *inode, int type); 87*47e4937aSGao Xiang #else 88*47e4937aSGao Xiang #define erofs_get_acl (NULL) 89*47e4937aSGao Xiang #endif 90*47e4937aSGao Xiang 91*47e4937aSGao Xiang #endif 92*47e4937aSGao Xiang 93