blob: 94090c74b3f7a37b17800ee7cfdffe92dc1c06d7 [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.
Alexander A. Klimov592e7cd2020-07-13 15:09:44 +02004 * https://www.huawei.com/
Gao Xiangb17500a2018-07-26 20:21:52 +08005 */
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/* Attribute not found */
14#define ENOATTR ENODATA
15
Pratik Shindee82a9a12019-07-15 17:51:27 +053016static inline unsigned int inlinexattr_header_size(struct inode *inode)
Gao Xiangb17500a2018-07-26 20:21:52 +080017{
Gao Xianga5876e22019-09-04 10:08:56 +080018 return sizeof(struct erofs_xattr_ibody_header) +
19 sizeof(u32) * EROFS_I(inode)->xattr_shared_count;
Gao Xiangb17500a2018-07-26 20:21:52 +080020}
21
Pratik Shindee82a9a12019-07-15 17:51:27 +053022static inline erofs_blk_t xattrblock_addr(struct erofs_sb_info *sbi,
23 unsigned int xattr_id)
Gao Xiangb17500a2018-07-26 20:21:52 +080024{
25#ifdef CONFIG_EROFS_FS_XATTR
26 return sbi->xattr_blkaddr +
27 xattr_id * sizeof(__u32) / EROFS_BLKSIZ;
28#else
29 return 0;
30#endif
31}
32
Pratik Shindee82a9a12019-07-15 17:51:27 +053033static inline unsigned int xattrblock_offset(struct erofs_sb_info *sbi,
34 unsigned int xattr_id)
Gao Xiangb17500a2018-07-26 20:21:52 +080035{
36 return (xattr_id * sizeof(__u32)) % EROFS_BLKSIZ;
37}
38
Gao Xiang5734fa22019-07-31 23:57:33 +080039#ifdef CONFIG_EROFS_FS_XATTR
Gao Xiangb17500a2018-07-26 20:21:52 +080040extern const struct xattr_handler erofs_xattr_user_handler;
41extern const struct xattr_handler erofs_xattr_trusted_handler;
42#ifdef CONFIG_EROFS_FS_SECURITY
43extern const struct xattr_handler erofs_xattr_security_handler;
44#endif
45
Pratik Shindee82a9a12019-07-15 17:51:27 +053046static inline const struct xattr_handler *erofs_xattr_handler(unsigned int idx)
Gao Xiangb17500a2018-07-26 20:21:52 +080047{
Vladimir Zapolskiya55861c2020-01-02 14:02:32 +020048 static const struct xattr_handler *xattr_handler_map[] = {
49 [EROFS_XATTR_INDEX_USER] = &erofs_xattr_user_handler,
Gao Xiangb17500a2018-07-26 20:21:52 +080050#ifdef CONFIG_EROFS_FS_POSIX_ACL
Vladimir Zapolskiya55861c2020-01-02 14:02:32 +020051 [EROFS_XATTR_INDEX_POSIX_ACL_ACCESS] =
52 &posix_acl_access_xattr_handler,
53 [EROFS_XATTR_INDEX_POSIX_ACL_DEFAULT] =
54 &posix_acl_default_xattr_handler,
Gao Xiangb17500a2018-07-26 20:21:52 +080055#endif
Vladimir Zapolskiya55861c2020-01-02 14:02:32 +020056 [EROFS_XATTR_INDEX_TRUSTED] = &erofs_xattr_trusted_handler,
Gao Xiangb17500a2018-07-26 20:21:52 +080057#ifdef CONFIG_EROFS_FS_SECURITY
Vladimir Zapolskiya55861c2020-01-02 14:02:32 +020058 [EROFS_XATTR_INDEX_SECURITY] = &erofs_xattr_security_handler,
Gao Xiangb17500a2018-07-26 20:21:52 +080059#endif
Vladimir Zapolskiya55861c2020-01-02 14:02:32 +020060 };
Pratik Shindee82a9a12019-07-15 17:51:27 +053061
62 return idx && idx < ARRAY_SIZE(xattr_handler_map) ?
63 xattr_handler_map[idx] : NULL;
Gao Xiangb17500a2018-07-26 20:21:52 +080064}
65
Gao Xiang6af7b482019-01-14 19:40:25 +080066extern const struct xattr_handler *erofs_xattr_handlers[];
67
Gao Xiangb17500a2018-07-26 20:21:52 +080068int erofs_getxattr(struct inode *, int, const char *, void *, size_t);
69ssize_t erofs_listxattr(struct dentry *, char *, size_t);
70#else
Gao Xiang5734fa22019-07-31 23:57:33 +080071static inline int erofs_getxattr(struct inode *inode, int index,
72 const char *name, void *buffer,
73 size_t buffer_size)
Gao Xiangb17500a2018-07-26 20:21:52 +080074{
Gao Xiangff784a72019-08-14 18:37:05 +080075 return -EOPNOTSUPP;
Gao Xiangb17500a2018-07-26 20:21:52 +080076}
77
Chengguang Xue7cda1e2020-05-26 17:03:43 +080078#define erofs_listxattr (NULL)
79#define erofs_xattr_handlers (NULL)
Gao Xiang5734fa22019-07-31 23:57:33 +080080#endif /* !CONFIG_EROFS_FS_XATTR */
Gao Xiangb17500a2018-07-26 20:21:52 +080081
Gao Xiang516c115c2019-01-29 16:35:20 +080082#ifdef CONFIG_EROFS_FS_POSIX_ACL
Miklos Szeredi0cad6242021-08-18 22:08:24 +020083struct posix_acl *erofs_get_acl(struct inode *inode, int type, bool rcu);
Gao Xiang516c115c2019-01-29 16:35:20 +080084#else
85#define erofs_get_acl (NULL)
86#endif
87
Gao Xiangb17500a2018-07-26 20:21:52 +080088#endif
89