18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-only */ 28c2ecf20Sopenharmony_ci/* 38c2ecf20Sopenharmony_ci * Copyright (C) 2017-2018 HUAWEI, Inc. 48c2ecf20Sopenharmony_ci * https://www.huawei.com/ 58c2ecf20Sopenharmony_ci * Created by Gao Xiang <gaoxiang25@huawei.com> 68c2ecf20Sopenharmony_ci */ 78c2ecf20Sopenharmony_ci#ifndef __EROFS_XATTR_H 88c2ecf20Sopenharmony_ci#define __EROFS_XATTR_H 98c2ecf20Sopenharmony_ci 108c2ecf20Sopenharmony_ci#include "internal.h" 118c2ecf20Sopenharmony_ci#include <linux/posix_acl_xattr.h> 128c2ecf20Sopenharmony_ci#include <linux/xattr.h> 138c2ecf20Sopenharmony_ci 148c2ecf20Sopenharmony_ci/* Attribute not found */ 158c2ecf20Sopenharmony_ci#define ENOATTR ENODATA 168c2ecf20Sopenharmony_ci 178c2ecf20Sopenharmony_cistatic inline unsigned int inlinexattr_header_size(struct inode *inode) 188c2ecf20Sopenharmony_ci{ 198c2ecf20Sopenharmony_ci return sizeof(struct erofs_xattr_ibody_header) + 208c2ecf20Sopenharmony_ci sizeof(u32) * EROFS_I(inode)->xattr_shared_count; 218c2ecf20Sopenharmony_ci} 228c2ecf20Sopenharmony_ci 238c2ecf20Sopenharmony_cistatic inline erofs_blk_t xattrblock_addr(struct erofs_sb_info *sbi, 248c2ecf20Sopenharmony_ci unsigned int xattr_id) 258c2ecf20Sopenharmony_ci{ 268c2ecf20Sopenharmony_ci#ifdef CONFIG_EROFS_FS_XATTR 278c2ecf20Sopenharmony_ci return sbi->xattr_blkaddr + 288c2ecf20Sopenharmony_ci xattr_id * sizeof(__u32) / EROFS_BLKSIZ; 298c2ecf20Sopenharmony_ci#else 308c2ecf20Sopenharmony_ci return 0; 318c2ecf20Sopenharmony_ci#endif 328c2ecf20Sopenharmony_ci} 338c2ecf20Sopenharmony_ci 348c2ecf20Sopenharmony_cistatic inline unsigned int xattrblock_offset(struct erofs_sb_info *sbi, 358c2ecf20Sopenharmony_ci unsigned int xattr_id) 368c2ecf20Sopenharmony_ci{ 378c2ecf20Sopenharmony_ci return (xattr_id * sizeof(__u32)) % EROFS_BLKSIZ; 388c2ecf20Sopenharmony_ci} 398c2ecf20Sopenharmony_ci 408c2ecf20Sopenharmony_ci#ifdef CONFIG_EROFS_FS_XATTR 418c2ecf20Sopenharmony_ciextern const struct xattr_handler erofs_xattr_user_handler; 428c2ecf20Sopenharmony_ciextern const struct xattr_handler erofs_xattr_trusted_handler; 438c2ecf20Sopenharmony_ci#ifdef CONFIG_EROFS_FS_SECURITY 448c2ecf20Sopenharmony_ciextern const struct xattr_handler erofs_xattr_security_handler; 458c2ecf20Sopenharmony_ci#endif 468c2ecf20Sopenharmony_ci 478c2ecf20Sopenharmony_cistatic inline const struct xattr_handler *erofs_xattr_handler(unsigned int idx) 488c2ecf20Sopenharmony_ci{ 498c2ecf20Sopenharmony_ci static const struct xattr_handler *xattr_handler_map[] = { 508c2ecf20Sopenharmony_ci [EROFS_XATTR_INDEX_USER] = &erofs_xattr_user_handler, 518c2ecf20Sopenharmony_ci#ifdef CONFIG_EROFS_FS_POSIX_ACL 528c2ecf20Sopenharmony_ci [EROFS_XATTR_INDEX_POSIX_ACL_ACCESS] = 538c2ecf20Sopenharmony_ci &posix_acl_access_xattr_handler, 548c2ecf20Sopenharmony_ci [EROFS_XATTR_INDEX_POSIX_ACL_DEFAULT] = 558c2ecf20Sopenharmony_ci &posix_acl_default_xattr_handler, 568c2ecf20Sopenharmony_ci#endif 578c2ecf20Sopenharmony_ci [EROFS_XATTR_INDEX_TRUSTED] = &erofs_xattr_trusted_handler, 588c2ecf20Sopenharmony_ci#ifdef CONFIG_EROFS_FS_SECURITY 598c2ecf20Sopenharmony_ci [EROFS_XATTR_INDEX_SECURITY] = &erofs_xattr_security_handler, 608c2ecf20Sopenharmony_ci#endif 618c2ecf20Sopenharmony_ci }; 628c2ecf20Sopenharmony_ci 638c2ecf20Sopenharmony_ci return idx && idx < ARRAY_SIZE(xattr_handler_map) ? 648c2ecf20Sopenharmony_ci xattr_handler_map[idx] : NULL; 658c2ecf20Sopenharmony_ci} 668c2ecf20Sopenharmony_ci 678c2ecf20Sopenharmony_ciextern const struct xattr_handler *erofs_xattr_handlers[]; 688c2ecf20Sopenharmony_ci 698c2ecf20Sopenharmony_ciint erofs_getxattr(struct inode *, int, const char *, void *, size_t); 708c2ecf20Sopenharmony_cissize_t erofs_listxattr(struct dentry *, char *, size_t); 718c2ecf20Sopenharmony_ci#else 728c2ecf20Sopenharmony_cistatic inline int erofs_getxattr(struct inode *inode, int index, 738c2ecf20Sopenharmony_ci const char *name, void *buffer, 748c2ecf20Sopenharmony_ci size_t buffer_size) 758c2ecf20Sopenharmony_ci{ 768c2ecf20Sopenharmony_ci return -EOPNOTSUPP; 778c2ecf20Sopenharmony_ci} 788c2ecf20Sopenharmony_ci 798c2ecf20Sopenharmony_ci#define erofs_listxattr (NULL) 808c2ecf20Sopenharmony_ci#define erofs_xattr_handlers (NULL) 818c2ecf20Sopenharmony_ci#endif /* !CONFIG_EROFS_FS_XATTR */ 828c2ecf20Sopenharmony_ci 838c2ecf20Sopenharmony_ci#ifdef CONFIG_EROFS_FS_POSIX_ACL 848c2ecf20Sopenharmony_cistruct posix_acl *erofs_get_acl(struct inode *inode, int type); 858c2ecf20Sopenharmony_ci#else 868c2ecf20Sopenharmony_ci#define erofs_get_acl (NULL) 878c2ecf20Sopenharmony_ci#endif 888c2ecf20Sopenharmony_ci 898c2ecf20Sopenharmony_ci#endif 908c2ecf20Sopenharmony_ci 91