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