162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-only */ 262306a36Sopenharmony_ci/* 362306a36Sopenharmony_ci * Copyright (C) 2017-2018 HUAWEI, Inc. 462306a36Sopenharmony_ci * https://www.huawei.com/ 562306a36Sopenharmony_ci */ 662306a36Sopenharmony_ci#ifndef __EROFS_XATTR_H 762306a36Sopenharmony_ci#define __EROFS_XATTR_H 862306a36Sopenharmony_ci 962306a36Sopenharmony_ci#include "internal.h" 1062306a36Sopenharmony_ci#include <linux/posix_acl_xattr.h> 1162306a36Sopenharmony_ci#include <linux/xattr.h> 1262306a36Sopenharmony_ci 1362306a36Sopenharmony_ci/* Attribute not found */ 1462306a36Sopenharmony_ci#define ENOATTR ENODATA 1562306a36Sopenharmony_ci 1662306a36Sopenharmony_ci#ifdef CONFIG_EROFS_FS_XATTR 1762306a36Sopenharmony_ciextern const struct xattr_handler erofs_xattr_user_handler; 1862306a36Sopenharmony_ciextern const struct xattr_handler erofs_xattr_trusted_handler; 1962306a36Sopenharmony_ciextern const struct xattr_handler erofs_xattr_security_handler; 2062306a36Sopenharmony_ci 2162306a36Sopenharmony_cistatic inline const char *erofs_xattr_prefix(unsigned int idx, 2262306a36Sopenharmony_ci struct dentry *dentry) 2362306a36Sopenharmony_ci{ 2462306a36Sopenharmony_ci const struct xattr_handler *handler = NULL; 2562306a36Sopenharmony_ci 2662306a36Sopenharmony_ci static const struct xattr_handler *xattr_handler_map[] = { 2762306a36Sopenharmony_ci [EROFS_XATTR_INDEX_USER] = &erofs_xattr_user_handler, 2862306a36Sopenharmony_ci#ifdef CONFIG_EROFS_FS_POSIX_ACL 2962306a36Sopenharmony_ci [EROFS_XATTR_INDEX_POSIX_ACL_ACCESS] = &nop_posix_acl_access, 3062306a36Sopenharmony_ci [EROFS_XATTR_INDEX_POSIX_ACL_DEFAULT] = &nop_posix_acl_default, 3162306a36Sopenharmony_ci#endif 3262306a36Sopenharmony_ci [EROFS_XATTR_INDEX_TRUSTED] = &erofs_xattr_trusted_handler, 3362306a36Sopenharmony_ci#ifdef CONFIG_EROFS_FS_SECURITY 3462306a36Sopenharmony_ci [EROFS_XATTR_INDEX_SECURITY] = &erofs_xattr_security_handler, 3562306a36Sopenharmony_ci#endif 3662306a36Sopenharmony_ci }; 3762306a36Sopenharmony_ci 3862306a36Sopenharmony_ci if (idx && idx < ARRAY_SIZE(xattr_handler_map)) 3962306a36Sopenharmony_ci handler = xattr_handler_map[idx]; 4062306a36Sopenharmony_ci 4162306a36Sopenharmony_ci if (!xattr_handler_can_list(handler, dentry)) 4262306a36Sopenharmony_ci return NULL; 4362306a36Sopenharmony_ci 4462306a36Sopenharmony_ci return xattr_prefix(handler); 4562306a36Sopenharmony_ci} 4662306a36Sopenharmony_ci 4762306a36Sopenharmony_ciextern const struct xattr_handler *erofs_xattr_handlers[]; 4862306a36Sopenharmony_ci 4962306a36Sopenharmony_ciint erofs_xattr_prefixes_init(struct super_block *sb); 5062306a36Sopenharmony_civoid erofs_xattr_prefixes_cleanup(struct super_block *sb); 5162306a36Sopenharmony_ciint erofs_getxattr(struct inode *, int, const char *, void *, size_t); 5262306a36Sopenharmony_cissize_t erofs_listxattr(struct dentry *, char *, size_t); 5362306a36Sopenharmony_ci#else 5462306a36Sopenharmony_cistatic inline int erofs_xattr_prefixes_init(struct super_block *sb) { return 0; } 5562306a36Sopenharmony_cistatic inline void erofs_xattr_prefixes_cleanup(struct super_block *sb) {} 5662306a36Sopenharmony_cistatic inline int erofs_getxattr(struct inode *inode, int index, 5762306a36Sopenharmony_ci const char *name, void *buffer, 5862306a36Sopenharmony_ci size_t buffer_size) 5962306a36Sopenharmony_ci{ 6062306a36Sopenharmony_ci return -EOPNOTSUPP; 6162306a36Sopenharmony_ci} 6262306a36Sopenharmony_ci 6362306a36Sopenharmony_ci#define erofs_listxattr (NULL) 6462306a36Sopenharmony_ci#define erofs_xattr_handlers (NULL) 6562306a36Sopenharmony_ci#endif /* !CONFIG_EROFS_FS_XATTR */ 6662306a36Sopenharmony_ci 6762306a36Sopenharmony_ci#ifdef CONFIG_EROFS_FS_POSIX_ACL 6862306a36Sopenharmony_cistruct posix_acl *erofs_get_acl(struct inode *inode, int type, bool rcu); 6962306a36Sopenharmony_ci#else 7062306a36Sopenharmony_ci#define erofs_get_acl (NULL) 7162306a36Sopenharmony_ci#endif 7262306a36Sopenharmony_ci 7362306a36Sopenharmony_ci#endif 74