xref: /openbmc/linux/fs/erofs/xattr.h (revision 0cad6246)
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 static inline unsigned int inlinexattr_header_size(struct inode *inode)
1747e4937aSGao Xiang {
18a5876e24SGao Xiang 	return sizeof(struct erofs_xattr_ibody_header) +
19a5876e24SGao Xiang 		sizeof(u32) * EROFS_I(inode)->xattr_shared_count;
2047e4937aSGao Xiang }
2147e4937aSGao Xiang 
2247e4937aSGao Xiang static inline erofs_blk_t xattrblock_addr(struct erofs_sb_info *sbi,
2347e4937aSGao Xiang 					  unsigned int xattr_id)
2447e4937aSGao Xiang {
2547e4937aSGao Xiang #ifdef CONFIG_EROFS_FS_XATTR
2647e4937aSGao Xiang 	return sbi->xattr_blkaddr +
2747e4937aSGao Xiang 		xattr_id * sizeof(__u32) / EROFS_BLKSIZ;
2847e4937aSGao Xiang #else
2947e4937aSGao Xiang 	return 0;
3047e4937aSGao Xiang #endif
3147e4937aSGao Xiang }
3247e4937aSGao Xiang 
3347e4937aSGao Xiang static inline unsigned int xattrblock_offset(struct erofs_sb_info *sbi,
3447e4937aSGao Xiang 					     unsigned int xattr_id)
3547e4937aSGao Xiang {
3647e4937aSGao Xiang 	return (xattr_id * sizeof(__u32)) % EROFS_BLKSIZ;
3747e4937aSGao Xiang }
3847e4937aSGao Xiang 
3947e4937aSGao Xiang #ifdef CONFIG_EROFS_FS_XATTR
4047e4937aSGao Xiang extern const struct xattr_handler erofs_xattr_user_handler;
4147e4937aSGao Xiang extern const struct xattr_handler erofs_xattr_trusted_handler;
4247e4937aSGao Xiang #ifdef CONFIG_EROFS_FS_SECURITY
4347e4937aSGao Xiang extern const struct xattr_handler erofs_xattr_security_handler;
4447e4937aSGao Xiang #endif
4547e4937aSGao Xiang 
4647e4937aSGao Xiang static inline const struct xattr_handler *erofs_xattr_handler(unsigned int idx)
4747e4937aSGao Xiang {
4847e4937aSGao Xiang 	static const struct xattr_handler *xattr_handler_map[] = {
4947e4937aSGao Xiang 		[EROFS_XATTR_INDEX_USER] = &erofs_xattr_user_handler,
5047e4937aSGao Xiang #ifdef CONFIG_EROFS_FS_POSIX_ACL
51a55861c8SVladimir Zapolskiy 		[EROFS_XATTR_INDEX_POSIX_ACL_ACCESS] =
52a55861c8SVladimir Zapolskiy 			&posix_acl_access_xattr_handler,
5347e4937aSGao Xiang 		[EROFS_XATTR_INDEX_POSIX_ACL_DEFAULT] =
5447e4937aSGao Xiang 			&posix_acl_default_xattr_handler,
5547e4937aSGao Xiang #endif
5647e4937aSGao Xiang 		[EROFS_XATTR_INDEX_TRUSTED] = &erofs_xattr_trusted_handler,
5747e4937aSGao Xiang #ifdef CONFIG_EROFS_FS_SECURITY
5847e4937aSGao Xiang 		[EROFS_XATTR_INDEX_SECURITY] = &erofs_xattr_security_handler,
5947e4937aSGao Xiang #endif
6047e4937aSGao Xiang 	};
6147e4937aSGao Xiang 
6247e4937aSGao Xiang 	return idx && idx < ARRAY_SIZE(xattr_handler_map) ?
6347e4937aSGao Xiang 		xattr_handler_map[idx] : NULL;
6447e4937aSGao Xiang }
6547e4937aSGao Xiang 
6647e4937aSGao Xiang extern const struct xattr_handler *erofs_xattr_handlers[];
6747e4937aSGao Xiang 
6847e4937aSGao Xiang int erofs_getxattr(struct inode *, int, const char *, void *, size_t);
6947e4937aSGao Xiang ssize_t erofs_listxattr(struct dentry *, char *, size_t);
7047e4937aSGao Xiang #else
7147e4937aSGao Xiang static inline int erofs_getxattr(struct inode *inode, int index,
7247e4937aSGao Xiang 				 const char *name, void *buffer,
7347e4937aSGao Xiang 				 size_t buffer_size)
7447e4937aSGao Xiang {
7547e4937aSGao Xiang 	return -EOPNOTSUPP;
7647e4937aSGao Xiang }
7747e4937aSGao Xiang 
78e7cda1eeSChengguang Xu #define erofs_listxattr (NULL)
79e7cda1eeSChengguang Xu #define erofs_xattr_handlers (NULL)
8047e4937aSGao Xiang #endif	/* !CONFIG_EROFS_FS_XATTR */
8147e4937aSGao Xiang 
8247e4937aSGao Xiang #ifdef CONFIG_EROFS_FS_POSIX_ACL
83*0cad6246SMiklos Szeredi struct posix_acl *erofs_get_acl(struct inode *inode, int type, bool rcu);
8447e4937aSGao Xiang #else
8547e4937aSGao Xiang #define erofs_get_acl	(NULL)
8647e4937aSGao Xiang #endif
8747e4937aSGao Xiang 
8847e4937aSGao Xiang #endif
8947e4937aSGao Xiang 
90