xref: /openbmc/linux/fs/erofs/xattr.h (revision 9e382914)
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 
erofs_xattr_prefix(unsigned int idx,struct dentry * dentry)2147e4937aSGao Xiang static inline const char *erofs_xattr_prefix(unsigned int idx,
2247e4937aSGao Xiang 					     struct dentry *dentry)
2347e4937aSGao Xiang {
2447e4937aSGao Xiang 	const struct xattr_handler *handler = NULL;
2547e4937aSGao Xiang 
26a55861c8SVladimir Zapolskiy 	static const struct xattr_handler *xattr_handler_map[] = {
27a55861c8SVladimir Zapolskiy 		[EROFS_XATTR_INDEX_USER] = &erofs_xattr_user_handler,
2847e4937aSGao Xiang #ifdef CONFIG_EROFS_FS_POSIX_ACL
2947e4937aSGao Xiang 		[EROFS_XATTR_INDEX_POSIX_ACL_ACCESS] = &nop_posix_acl_access,
3047e4937aSGao Xiang 		[EROFS_XATTR_INDEX_POSIX_ACL_DEFAULT] = &nop_posix_acl_default,
3147e4937aSGao Xiang #endif
3247e4937aSGao Xiang 		[EROFS_XATTR_INDEX_TRUSTED] = &erofs_xattr_trusted_handler,
3347e4937aSGao Xiang #ifdef CONFIG_EROFS_FS_SECURITY
3447e4937aSGao Xiang 		[EROFS_XATTR_INDEX_SECURITY] = &erofs_xattr_security_handler,
3547e4937aSGao Xiang #endif
3647e4937aSGao Xiang 	};
3747e4937aSGao Xiang 
3847e4937aSGao Xiang 	if (idx && idx < ARRAY_SIZE(xattr_handler_map))
3947e4937aSGao Xiang 		handler = xattr_handler_map[idx];
4047e4937aSGao Xiang 
4147e4937aSGao Xiang 	if (!xattr_handler_can_list(handler, dentry))
4247e4937aSGao Xiang 		return NULL;
43*9e382914SJingbo Xu 
44*9e382914SJingbo Xu 	return xattr_prefix(handler);
4547e4937aSGao Xiang }
4647e4937aSGao Xiang 
4747e4937aSGao Xiang extern const struct xattr_handler *erofs_xattr_handlers[];
48*9e382914SJingbo Xu 
49*9e382914SJingbo Xu int erofs_xattr_prefixes_init(struct super_block *sb);
5047e4937aSGao Xiang void erofs_xattr_prefixes_cleanup(struct super_block *sb);
5147e4937aSGao Xiang int erofs_getxattr(struct inode *, int, const char *, void *, size_t);
5247e4937aSGao Xiang ssize_t erofs_listxattr(struct dentry *, char *, size_t);
5347e4937aSGao Xiang #else
erofs_xattr_prefixes_init(struct super_block * sb)5447e4937aSGao Xiang static inline int erofs_xattr_prefixes_init(struct super_block *sb) { return 0; }
erofs_xattr_prefixes_cleanup(struct super_block * sb)5547e4937aSGao Xiang static inline void erofs_xattr_prefixes_cleanup(struct super_block *sb) {}
erofs_getxattr(struct inode * inode,int index,const char * name,void * buffer,size_t buffer_size)5647e4937aSGao Xiang static inline int erofs_getxattr(struct inode *inode, int index,
57e7cda1eeSChengguang Xu 				 const char *name, void *buffer,
58e7cda1eeSChengguang Xu 				 size_t buffer_size)
5947e4937aSGao Xiang {
6047e4937aSGao Xiang 	return -EOPNOTSUPP;
6147e4937aSGao Xiang }
620cad6246SMiklos Szeredi 
6347e4937aSGao Xiang #define erofs_listxattr (NULL)
6447e4937aSGao Xiang #define erofs_xattr_handlers (NULL)
6547e4937aSGao Xiang #endif	/* !CONFIG_EROFS_FS_XATTR */
6647e4937aSGao Xiang 
6747e4937aSGao Xiang #ifdef CONFIG_EROFS_FS_POSIX_ACL
68 struct posix_acl *erofs_get_acl(struct inode *inode, int type, bool rcu);
69 #else
70 #define erofs_get_acl	(NULL)
71 #endif
72 
73 #endif
74