^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) /* SPDX-License-Identifier: GPL-2.0-only */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * Copyright (C) 2017-2018 HUAWEI, Inc.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) * https://www.huawei.com/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * Created by Gao Xiang <gaoxiang25@huawei.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) #ifndef __EROFS_XATTR_H
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) #define __EROFS_XATTR_H
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #include "internal.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include <linux/posix_acl_xattr.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <linux/xattr.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) /* Attribute not found */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #define ENOATTR ENODATA
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) static inline unsigned int inlinexattr_header_size(struct inode *inode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) return sizeof(struct erofs_xattr_ibody_header) +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) sizeof(u32) * EROFS_I(inode)->xattr_shared_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) static inline erofs_blk_t xattrblock_addr(struct erofs_sb_info *sbi,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) unsigned int xattr_id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) #ifdef CONFIG_EROFS_FS_XATTR
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) return sbi->xattr_blkaddr +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) xattr_id * sizeof(__u32) / EROFS_BLKSIZ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) static inline unsigned int xattrblock_offset(struct erofs_sb_info *sbi,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) unsigned int xattr_id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) return (xattr_id * sizeof(__u32)) % EROFS_BLKSIZ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) #ifdef CONFIG_EROFS_FS_XATTR
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) extern const struct xattr_handler erofs_xattr_user_handler;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) extern const struct xattr_handler erofs_xattr_trusted_handler;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) #ifdef CONFIG_EROFS_FS_SECURITY
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) extern const struct xattr_handler erofs_xattr_security_handler;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) static inline const struct xattr_handler *erofs_xattr_handler(unsigned int idx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) static const struct xattr_handler *xattr_handler_map[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) [EROFS_XATTR_INDEX_USER] = &erofs_xattr_user_handler,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) #ifdef CONFIG_EROFS_FS_POSIX_ACL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) [EROFS_XATTR_INDEX_POSIX_ACL_ACCESS] =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) &posix_acl_access_xattr_handler,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) [EROFS_XATTR_INDEX_POSIX_ACL_DEFAULT] =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) &posix_acl_default_xattr_handler,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) [EROFS_XATTR_INDEX_TRUSTED] = &erofs_xattr_trusted_handler,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) #ifdef CONFIG_EROFS_FS_SECURITY
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) [EROFS_XATTR_INDEX_SECURITY] = &erofs_xattr_security_handler,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) return idx && idx < ARRAY_SIZE(xattr_handler_map) ?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) xattr_handler_map[idx] : NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) extern const struct xattr_handler *erofs_xattr_handlers[];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) int erofs_getxattr(struct inode *, int, const char *, void *, size_t);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) ssize_t erofs_listxattr(struct dentry *, char *, size_t);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) static inline int erofs_getxattr(struct inode *inode, int index,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) const char *name, void *buffer,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) size_t buffer_size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) return -EOPNOTSUPP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) #define erofs_listxattr (NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) #define erofs_xattr_handlers (NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) #endif /* !CONFIG_EROFS_FS_XATTR */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) #ifdef CONFIG_EROFS_FS_POSIX_ACL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) struct posix_acl *erofs_get_acl(struct inode *inode, int type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) #define erofs_get_acl (NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90)