xref: /linux/fs/erofs/xattr.h (revision 76a9701325d39d8602695b19c49a9d0828c897ca)
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 /*
3  * Copyright (C) 2017-2018 HUAWEI, Inc.
4  *             https://www.huawei.com/
5  */
6 #ifndef __EROFS_XATTR_H
7 #define __EROFS_XATTR_H
8 
9 #include "internal.h"
10 #include <linux/posix_acl_xattr.h>
11 #include <linux/xattr.h>
12 
13 #ifdef CONFIG_EROFS_FS_XATTR
14 extern const struct xattr_handler erofs_xattr_user_handler;
15 extern const struct xattr_handler erofs_xattr_trusted_handler;
16 extern const struct xattr_handler erofs_xattr_security_handler;
17 
erofs_xattr_prefix(unsigned int idx,struct dentry * dentry)18 static inline const char *erofs_xattr_prefix(unsigned int idx,
19 					     struct dentry *dentry)
20 {
21 	const struct xattr_handler *handler = NULL;
22 
23 	static const struct xattr_handler * const xattr_handler_map[] = {
24 		[EROFS_XATTR_INDEX_USER] = &erofs_xattr_user_handler,
25 #ifdef CONFIG_EROFS_FS_POSIX_ACL
26 		[EROFS_XATTR_INDEX_POSIX_ACL_ACCESS] = &nop_posix_acl_access,
27 		[EROFS_XATTR_INDEX_POSIX_ACL_DEFAULT] = &nop_posix_acl_default,
28 #endif
29 		[EROFS_XATTR_INDEX_TRUSTED] = &erofs_xattr_trusted_handler,
30 #ifdef CONFIG_EROFS_FS_SECURITY
31 		[EROFS_XATTR_INDEX_SECURITY] = &erofs_xattr_security_handler,
32 #endif
33 	};
34 
35 	if (idx && idx < ARRAY_SIZE(xattr_handler_map))
36 		handler = xattr_handler_map[idx];
37 
38 	if (!xattr_handler_can_list(handler, dentry))
39 		return NULL;
40 
41 	return xattr_prefix(handler);
42 }
43 
44 extern const struct xattr_handler * const erofs_xattr_handlers[];
45 
46 int erofs_xattr_prefixes_init(struct super_block *sb);
47 void erofs_xattr_prefixes_cleanup(struct super_block *sb);
48 int erofs_getxattr(struct inode *, int, const char *, void *, size_t);
49 ssize_t erofs_listxattr(struct dentry *, char *, size_t);
50 #else
erofs_xattr_prefixes_init(struct super_block * sb)51 static inline int erofs_xattr_prefixes_init(struct super_block *sb) { return 0; }
erofs_xattr_prefixes_cleanup(struct super_block * sb)52 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)53 static inline int erofs_getxattr(struct inode *inode, int index,
54 				 const char *name, void *buffer,
55 				 size_t buffer_size)
56 {
57 	return -EOPNOTSUPP;
58 }
59 
60 #define erofs_listxattr (NULL)
61 #define erofs_xattr_handlers (NULL)
62 #endif	/* !CONFIG_EROFS_FS_XATTR */
63 
64 #ifdef CONFIG_EROFS_FS_POSIX_ACL
65 struct posix_acl *erofs_get_acl(struct inode *inode, int type, bool rcu);
66 #else
67 #define erofs_get_acl	(NULL)
68 #endif
69 
70 #endif
71