xref: /linux/fs/erofs/xattr.h (revision 0ea5c948cb64bab5bc7a5516774eb8536f05aa0d)
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)21a5488f29SChristian Brauner static inline const char *erofs_xattr_prefix(unsigned int idx,
22a5488f29SChristian Brauner 					     struct dentry *dentry)
2347e4937aSGao Xiang {
24a5488f29SChristian Brauner 	const struct xattr_handler *handler = NULL;
25a5488f29SChristian Brauner 
26*3591f40eSWedson Almeida Filho 	static const struct xattr_handler * const xattr_handler_map[] = {
2747e4937aSGao Xiang 		[EROFS_XATTR_INDEX_USER] = &erofs_xattr_user_handler,
2847e4937aSGao Xiang #ifdef CONFIG_EROFS_FS_POSIX_ACL
29d549b741SChristian Brauner 		[EROFS_XATTR_INDEX_POSIX_ACL_ACCESS] = &nop_posix_acl_access,
30d549b741SChristian Brauner 		[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 
38a5488f29SChristian Brauner 	if (idx && idx < ARRAY_SIZE(xattr_handler_map))
39a5488f29SChristian Brauner 		handler = xattr_handler_map[idx];
40a5488f29SChristian Brauner 
41a5488f29SChristian Brauner 	if (!xattr_handler_can_list(handler, dentry))
42a5488f29SChristian Brauner 		return NULL;
43a5488f29SChristian Brauner 
44a5488f29SChristian Brauner 	return xattr_prefix(handler);
4547e4937aSGao Xiang }
4647e4937aSGao Xiang 
47*3591f40eSWedson Almeida Filho extern const struct xattr_handler * const erofs_xattr_handlers[];
4847e4937aSGao Xiang 
499e382914SJingbo Xu int erofs_xattr_prefixes_init(struct super_block *sb);
509e382914SJingbo Xu 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)549e382914SJingbo Xu static inline int erofs_xattr_prefixes_init(struct super_block *sb) { return 0; }
erofs_xattr_prefixes_cleanup(struct super_block * sb)559e382914SJingbo Xu 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,
5747e4937aSGao Xiang 				 const char *name, void *buffer,
5847e4937aSGao Xiang 				 size_t buffer_size)
5947e4937aSGao Xiang {
6047e4937aSGao Xiang 	return -EOPNOTSUPP;
6147e4937aSGao Xiang }
6247e4937aSGao Xiang 
63e7cda1eeSChengguang Xu #define erofs_listxattr (NULL)
64e7cda1eeSChengguang Xu #define erofs_xattr_handlers (NULL)
6547e4937aSGao Xiang #endif	/* !CONFIG_EROFS_FS_XATTR */
6647e4937aSGao Xiang 
6747e4937aSGao Xiang #ifdef CONFIG_EROFS_FS_POSIX_ACL
680cad6246SMiklos Szeredi struct posix_acl *erofs_get_acl(struct inode *inode, int type, bool rcu);
6947e4937aSGao Xiang #else
7047e4937aSGao Xiang #define erofs_get_acl	(NULL)
7147e4937aSGao Xiang #endif
7247e4937aSGao Xiang 
7347e4937aSGao Xiang #endif
74