blob: e4e5093f012cc5f5233988f1ff46f2656e0bb6ab [file] [log] [blame]
Gao Xiang29b24f62019-07-31 23:57:31 +08001/* SPDX-License-Identifier: GPL-2.0-only */
2/*
Gao Xiangb17500a2018-07-26 20:21:52 +08003 * Copyright (C) 2017-2018 HUAWEI, Inc.
4 * http://www.huawei.com/
5 * Created by Gao Xiang <gaoxiang25@huawei.com>
Gao Xiangb17500a2018-07-26 20:21:52 +08006 */
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
Pratik Shindee82a9a12019-07-15 17:51:27 +053017static inline unsigned int inlinexattr_header_size(struct inode *inode)
Gao Xiangb17500a2018-07-26 20:21:52 +080018{
Gao Xianga5876e22019-09-04 10:08:56 +080019 return sizeof(struct erofs_xattr_ibody_header) +
20 sizeof(u32) * EROFS_I(inode)->xattr_shared_count;
Gao Xiangb17500a2018-07-26 20:21:52 +080021}
22
Pratik Shindee82a9a12019-07-15 17:51:27 +053023static inline erofs_blk_t xattrblock_addr(struct erofs_sb_info *sbi,
24 unsigned int xattr_id)
Gao Xiangb17500a2018-07-26 20:21:52 +080025{
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
Pratik Shindee82a9a12019-07-15 17:51:27 +053034static inline unsigned int xattrblock_offset(struct erofs_sb_info *sbi,
35 unsigned int xattr_id)
Gao Xiangb17500a2018-07-26 20:21:52 +080036{
37 return (xattr_id * sizeof(__u32)) % EROFS_BLKSIZ;
38}
39
Gao Xiang5734fa22019-07-31 23:57:33 +080040#ifdef CONFIG_EROFS_FS_XATTR
Gao Xiangb17500a2018-07-26 20:21:52 +080041extern const struct xattr_handler erofs_xattr_user_handler;
42extern const struct xattr_handler erofs_xattr_trusted_handler;
43#ifdef CONFIG_EROFS_FS_SECURITY
44extern const struct xattr_handler erofs_xattr_security_handler;
45#endif
46
Pratik Shindee82a9a12019-07-15 17:51:27 +053047static inline const struct xattr_handler *erofs_xattr_handler(unsigned int idx)
Gao Xiangb17500a2018-07-26 20:21:52 +080048{
Vladimir Zapolskiya55861c2020-01-02 14:02:32 +020049 static const struct xattr_handler *xattr_handler_map[] = {
50 [EROFS_XATTR_INDEX_USER] = &erofs_xattr_user_handler,
Gao Xiangb17500a2018-07-26 20:21:52 +080051#ifdef CONFIG_EROFS_FS_POSIX_ACL
Vladimir Zapolskiya55861c2020-01-02 14:02:32 +020052 [EROFS_XATTR_INDEX_POSIX_ACL_ACCESS] =
53 &posix_acl_access_xattr_handler,
54 [EROFS_XATTR_INDEX_POSIX_ACL_DEFAULT] =
55 &posix_acl_default_xattr_handler,
Gao Xiangb17500a2018-07-26 20:21:52 +080056#endif
Vladimir Zapolskiya55861c2020-01-02 14:02:32 +020057 [EROFS_XATTR_INDEX_TRUSTED] = &erofs_xattr_trusted_handler,
Gao Xiangb17500a2018-07-26 20:21:52 +080058#ifdef CONFIG_EROFS_FS_SECURITY
Vladimir Zapolskiya55861c2020-01-02 14:02:32 +020059 [EROFS_XATTR_INDEX_SECURITY] = &erofs_xattr_security_handler,
Gao Xiangb17500a2018-07-26 20:21:52 +080060#endif
Vladimir Zapolskiya55861c2020-01-02 14:02:32 +020061 };
Pratik Shindee82a9a12019-07-15 17:51:27 +053062
63 return idx && idx < ARRAY_SIZE(xattr_handler_map) ?
64 xattr_handler_map[idx] : NULL;
Gao Xiangb17500a2018-07-26 20:21:52 +080065}
66
Gao Xiang6af7b482019-01-14 19:40:25 +080067extern const struct xattr_handler *erofs_xattr_handlers[];
68
Gao Xiangb17500a2018-07-26 20:21:52 +080069int erofs_getxattr(struct inode *, int, const char *, void *, size_t);
70ssize_t erofs_listxattr(struct dentry *, char *, size_t);
71#else
Gao Xiang5734fa22019-07-31 23:57:33 +080072static inline int erofs_getxattr(struct inode *inode, int index,
73 const char *name, void *buffer,
74 size_t buffer_size)
Gao Xiangb17500a2018-07-26 20:21:52 +080075{
Gao Xiangff784a72019-08-14 18:37:05 +080076 return -EOPNOTSUPP;
Gao Xiangb17500a2018-07-26 20:21:52 +080077}
78
Chengguang Xue7cda1e2020-05-26 17:03:43 +080079#define erofs_listxattr (NULL)
80#define erofs_xattr_handlers (NULL)
Gao Xiang5734fa22019-07-31 23:57:33 +080081#endif /* !CONFIG_EROFS_FS_XATTR */
Gao Xiangb17500a2018-07-26 20:21:52 +080082
Gao Xiang516c115c2019-01-29 16:35:20 +080083#ifdef CONFIG_EROFS_FS_POSIX_ACL
84struct posix_acl *erofs_get_acl(struct inode *inode, int type);
85#else
86#define erofs_get_acl (NULL)
87#endif
88
Gao Xiangb17500a2018-07-26 20:21:52 +080089#endif
90