Gao Xiang | 29b24f6 | 2019-07-31 23:57:31 +0800 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
| 2 | /* |
Gao Xiang | b17500a | 2018-07-26 20:21:52 +0800 | [diff] [blame] | 3 | * Copyright (C) 2017-2018 HUAWEI, Inc. |
Alexander A. Klimov | 592e7cd | 2020-07-13 15:09:44 +0200 | [diff] [blame] | 4 | * https://www.huawei.com/ |
Gao Xiang | b17500a | 2018-07-26 20:21:52 +0800 | [diff] [blame] | 5 | */ |
| 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 Shinde | e82a9a1 | 2019-07-15 17:51:27 +0530 | [diff] [blame] | 16 | static inline unsigned int inlinexattr_header_size(struct inode *inode) |
Gao Xiang | b17500a | 2018-07-26 20:21:52 +0800 | [diff] [blame] | 17 | { |
Gao Xiang | a5876e2 | 2019-09-04 10:08:56 +0800 | [diff] [blame] | 18 | return sizeof(struct erofs_xattr_ibody_header) + |
| 19 | sizeof(u32) * EROFS_I(inode)->xattr_shared_count; |
Gao Xiang | b17500a | 2018-07-26 20:21:52 +0800 | [diff] [blame] | 20 | } |
| 21 | |
Pratik Shinde | e82a9a1 | 2019-07-15 17:51:27 +0530 | [diff] [blame] | 22 | static inline erofs_blk_t xattrblock_addr(struct erofs_sb_info *sbi, |
| 23 | unsigned int xattr_id) |
Gao Xiang | b17500a | 2018-07-26 20:21:52 +0800 | [diff] [blame] | 24 | { |
| 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 Shinde | e82a9a1 | 2019-07-15 17:51:27 +0530 | [diff] [blame] | 33 | static inline unsigned int xattrblock_offset(struct erofs_sb_info *sbi, |
| 34 | unsigned int xattr_id) |
Gao Xiang | b17500a | 2018-07-26 20:21:52 +0800 | [diff] [blame] | 35 | { |
| 36 | return (xattr_id * sizeof(__u32)) % EROFS_BLKSIZ; |
| 37 | } |
| 38 | |
Gao Xiang | 5734fa2 | 2019-07-31 23:57:33 +0800 | [diff] [blame] | 39 | #ifdef CONFIG_EROFS_FS_XATTR |
Gao Xiang | b17500a | 2018-07-26 20:21:52 +0800 | [diff] [blame] | 40 | extern const struct xattr_handler erofs_xattr_user_handler; |
| 41 | extern const struct xattr_handler erofs_xattr_trusted_handler; |
| 42 | #ifdef CONFIG_EROFS_FS_SECURITY |
| 43 | extern const struct xattr_handler erofs_xattr_security_handler; |
| 44 | #endif |
| 45 | |
Pratik Shinde | e82a9a1 | 2019-07-15 17:51:27 +0530 | [diff] [blame] | 46 | static inline const struct xattr_handler *erofs_xattr_handler(unsigned int idx) |
Gao Xiang | b17500a | 2018-07-26 20:21:52 +0800 | [diff] [blame] | 47 | { |
Vladimir Zapolskiy | a55861c | 2020-01-02 14:02:32 +0200 | [diff] [blame] | 48 | static const struct xattr_handler *xattr_handler_map[] = { |
| 49 | [EROFS_XATTR_INDEX_USER] = &erofs_xattr_user_handler, |
Gao Xiang | b17500a | 2018-07-26 20:21:52 +0800 | [diff] [blame] | 50 | #ifdef CONFIG_EROFS_FS_POSIX_ACL |
Vladimir Zapolskiy | a55861c | 2020-01-02 14:02:32 +0200 | [diff] [blame] | 51 | [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 Xiang | b17500a | 2018-07-26 20:21:52 +0800 | [diff] [blame] | 55 | #endif |
Vladimir Zapolskiy | a55861c | 2020-01-02 14:02:32 +0200 | [diff] [blame] | 56 | [EROFS_XATTR_INDEX_TRUSTED] = &erofs_xattr_trusted_handler, |
Gao Xiang | b17500a | 2018-07-26 20:21:52 +0800 | [diff] [blame] | 57 | #ifdef CONFIG_EROFS_FS_SECURITY |
Vladimir Zapolskiy | a55861c | 2020-01-02 14:02:32 +0200 | [diff] [blame] | 58 | [EROFS_XATTR_INDEX_SECURITY] = &erofs_xattr_security_handler, |
Gao Xiang | b17500a | 2018-07-26 20:21:52 +0800 | [diff] [blame] | 59 | #endif |
Vladimir Zapolskiy | a55861c | 2020-01-02 14:02:32 +0200 | [diff] [blame] | 60 | }; |
Pratik Shinde | e82a9a1 | 2019-07-15 17:51:27 +0530 | [diff] [blame] | 61 | |
| 62 | return idx && idx < ARRAY_SIZE(xattr_handler_map) ? |
| 63 | xattr_handler_map[idx] : NULL; |
Gao Xiang | b17500a | 2018-07-26 20:21:52 +0800 | [diff] [blame] | 64 | } |
| 65 | |
Gao Xiang | 6af7b48 | 2019-01-14 19:40:25 +0800 | [diff] [blame] | 66 | extern const struct xattr_handler *erofs_xattr_handlers[]; |
| 67 | |
Gao Xiang | b17500a | 2018-07-26 20:21:52 +0800 | [diff] [blame] | 68 | int erofs_getxattr(struct inode *, int, const char *, void *, size_t); |
| 69 | ssize_t erofs_listxattr(struct dentry *, char *, size_t); |
| 70 | #else |
Gao Xiang | 5734fa2 | 2019-07-31 23:57:33 +0800 | [diff] [blame] | 71 | static inline int erofs_getxattr(struct inode *inode, int index, |
| 72 | const char *name, void *buffer, |
| 73 | size_t buffer_size) |
Gao Xiang | b17500a | 2018-07-26 20:21:52 +0800 | [diff] [blame] | 74 | { |
Gao Xiang | ff784a7 | 2019-08-14 18:37:05 +0800 | [diff] [blame] | 75 | return -EOPNOTSUPP; |
Gao Xiang | b17500a | 2018-07-26 20:21:52 +0800 | [diff] [blame] | 76 | } |
| 77 | |
Chengguang Xu | e7cda1e | 2020-05-26 17:03:43 +0800 | [diff] [blame] | 78 | #define erofs_listxattr (NULL) |
| 79 | #define erofs_xattr_handlers (NULL) |
Gao Xiang | 5734fa2 | 2019-07-31 23:57:33 +0800 | [diff] [blame] | 80 | #endif /* !CONFIG_EROFS_FS_XATTR */ |
Gao Xiang | b17500a | 2018-07-26 20:21:52 +0800 | [diff] [blame] | 81 | |
Gao Xiang | 516c115c | 2019-01-29 16:35:20 +0800 | [diff] [blame] | 82 | #ifdef CONFIG_EROFS_FS_POSIX_ACL |
Miklos Szeredi | 0cad624 | 2021-08-18 22:08:24 +0200 | [diff] [blame] | 83 | struct posix_acl *erofs_get_acl(struct inode *inode, int type, bool rcu); |
Gao Xiang | 516c115c | 2019-01-29 16:35:20 +0800 | [diff] [blame] | 84 | #else |
| 85 | #define erofs_get_acl (NULL) |
| 86 | #endif |
| 87 | |
Gao Xiang | b17500a | 2018-07-26 20:21:52 +0800 | [diff] [blame] | 88 | #endif |
| 89 | |