xref: /linux/fs/erofs/xattr.h (revision 8a79db5e83a5d52c74e6f3c40d6f312cf899213e)
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 /*
3  * Copyright (C) 2017-2018 HUAWEI, Inc.
4  *             http://www.huawei.com/
5  * Created by Gao Xiang <gaoxiang25@huawei.com>
6  */
7 #ifndef __EROFS_XATTR_H
8 #define __EROFS_XATTR_H
9 
10 #include "internal.h"
11 #include <linux/posix_acl_xattr.h>
12 #include <linux/xattr.h>
13 
14 /* Attribute not found */
15 #define ENOATTR         ENODATA
16 
17 static inline unsigned int inlinexattr_header_size(struct inode *inode)
18 {
19 	return sizeof(struct erofs_xattr_ibody_header) +
20 		sizeof(u32) * EROFS_I(inode)->xattr_shared_count;
21 }
22 
23 static inline erofs_blk_t xattrblock_addr(struct erofs_sb_info *sbi,
24 					  unsigned int xattr_id)
25 {
26 #ifdef CONFIG_EROFS_FS_XATTR
27 	return sbi->xattr_blkaddr +
28 		xattr_id * sizeof(__u32) / EROFS_BLKSIZ;
29 #else
30 	return 0;
31 #endif
32 }
33 
34 static inline unsigned int xattrblock_offset(struct erofs_sb_info *sbi,
35 					     unsigned int xattr_id)
36 {
37 	return (xattr_id * sizeof(__u32)) % EROFS_BLKSIZ;
38 }
39 
40 #ifdef CONFIG_EROFS_FS_XATTR
41 extern const struct xattr_handler erofs_xattr_user_handler;
42 extern const struct xattr_handler erofs_xattr_trusted_handler;
43 #ifdef CONFIG_EROFS_FS_SECURITY
44 extern const struct xattr_handler erofs_xattr_security_handler;
45 #endif
46 
47 static inline const struct xattr_handler *erofs_xattr_handler(unsigned int idx)
48 {
49 static const struct xattr_handler *xattr_handler_map[] = {
50 	[EROFS_XATTR_INDEX_USER] = &erofs_xattr_user_handler,
51 #ifdef CONFIG_EROFS_FS_POSIX_ACL
52 	[EROFS_XATTR_INDEX_POSIX_ACL_ACCESS] = &posix_acl_access_xattr_handler,
53 	[EROFS_XATTR_INDEX_POSIX_ACL_DEFAULT] =
54 		&posix_acl_default_xattr_handler,
55 #endif
56 	[EROFS_XATTR_INDEX_TRUSTED] = &erofs_xattr_trusted_handler,
57 #ifdef CONFIG_EROFS_FS_SECURITY
58 	[EROFS_XATTR_INDEX_SECURITY] = &erofs_xattr_security_handler,
59 #endif
60 };
61 
62 	return idx && idx < ARRAY_SIZE(xattr_handler_map) ?
63 		xattr_handler_map[idx] : NULL;
64 }
65 
66 extern const struct xattr_handler *erofs_xattr_handlers[];
67 
68 int erofs_getxattr(struct inode *, int, const char *, void *, size_t);
69 ssize_t erofs_listxattr(struct dentry *, char *, size_t);
70 #else
71 static inline int erofs_getxattr(struct inode *inode, int index,
72 				 const char *name, void *buffer,
73 				 size_t buffer_size)
74 {
75 	return -EOPNOTSUPP;
76 }
77 
78 static inline ssize_t erofs_listxattr(struct dentry *dentry,
79 				      char *buffer, size_t buffer_size)
80 {
81 	return -EOPNOTSUPP;
82 }
83 #endif	/* !CONFIG_EROFS_FS_XATTR */
84 
85 #ifdef CONFIG_EROFS_FS_POSIX_ACL
86 struct posix_acl *erofs_get_acl(struct inode *inode, int type);
87 #else
88 #define erofs_get_acl	(NULL)
89 #endif
90 
91 #endif
92 
93