1 /* SPDX-License-Identifier: GPL-2.0-only */
3 * Copyright (C) 2017-2018 HUAWEI, Inc.
4 * https://www.huawei.com/
6 #ifndef __EROFS_XATTR_H
7 #define __EROFS_XATTR_H
10 #include <linux/posix_acl_xattr.h>
11 #include <linux/xattr.h>
13 /* Attribute not found */
14 #define ENOATTR ENODATA
16 static inline unsigned int inlinexattr_header_size(struct inode
*inode
)
18 return sizeof(struct erofs_xattr_ibody_header
) +
19 sizeof(u32
) * EROFS_I(inode
)->xattr_shared_count
;
22 static inline erofs_blk_t
xattrblock_addr(struct erofs_sb_info
*sbi
,
23 unsigned int xattr_id
)
25 #ifdef CONFIG_EROFS_FS_XATTR
26 return sbi
->xattr_blkaddr
+
27 xattr_id
* sizeof(__u32
) / EROFS_BLKSIZ
;
33 static inline unsigned int xattrblock_offset(struct erofs_sb_info
*sbi
,
34 unsigned int xattr_id
)
36 return (xattr_id
* sizeof(__u32
)) % EROFS_BLKSIZ
;
39 #ifdef CONFIG_EROFS_FS_XATTR
40 extern const struct xattr_handler erofs_xattr_user_handler
;
41 extern const struct xattr_handler erofs_xattr_trusted_handler
;
42 extern const struct xattr_handler erofs_xattr_security_handler
;
44 static inline const char *erofs_xattr_prefix(unsigned int idx
,
45 struct dentry
*dentry
)
47 const struct xattr_handler
*handler
= NULL
;
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
] = &nop_posix_acl_access
,
53 [EROFS_XATTR_INDEX_POSIX_ACL_DEFAULT
] = &nop_posix_acl_default
,
55 [EROFS_XATTR_INDEX_TRUSTED
] = &erofs_xattr_trusted_handler
,
56 #ifdef CONFIG_EROFS_FS_SECURITY
57 [EROFS_XATTR_INDEX_SECURITY
] = &erofs_xattr_security_handler
,
61 if (idx
&& idx
< ARRAY_SIZE(xattr_handler_map
))
62 handler
= xattr_handler_map
[idx
];
64 if (!xattr_handler_can_list(handler
, dentry
))
67 return xattr_prefix(handler
);
70 extern const struct xattr_handler
*erofs_xattr_handlers
[];
72 int erofs_getxattr(struct inode
*, int, const char *, void *, size_t);
73 ssize_t
erofs_listxattr(struct dentry
*, char *, size_t);
75 static inline int erofs_getxattr(struct inode
*inode
, int index
,
76 const char *name
, void *buffer
,
82 #define erofs_listxattr (NULL)
83 #define erofs_xattr_handlers (NULL)
84 #endif /* !CONFIG_EROFS_FS_XATTR */
86 #ifdef CONFIG_EROFS_FS_POSIX_ACL
87 struct posix_acl
*erofs_get_acl(struct inode
*inode
, int type
, bool rcu
);
89 #define erofs_get_acl (NULL)