2019-07-31 22:57:31 +07:00
|
|
|
/* SPDX-License-Identifier: GPL-2.0-only */
|
|
|
|
/*
|
2018-07-26 19:21:52 +07:00
|
|
|
* Copyright (C) 2017-2018 HUAWEI, Inc.
|
|
|
|
* http://www.huawei.com/
|
|
|
|
* Created by Gao Xiang <gaoxiang25@huawei.com>
|
|
|
|
*/
|
|
|
|
#ifndef __EROFS_XATTR_H
|
|
|
|
#define __EROFS_XATTR_H
|
|
|
|
|
|
|
|
#include "internal.h"
|
|
|
|
#include <linux/posix_acl_xattr.h>
|
|
|
|
#include <linux/xattr.h>
|
|
|
|
|
|
|
|
/* Attribute not found */
|
|
|
|
#define ENOATTR ENODATA
|
|
|
|
|
2019-07-15 19:21:27 +07:00
|
|
|
static inline unsigned int inlinexattr_header_size(struct inode *inode)
|
2018-07-26 19:21:52 +07:00
|
|
|
{
|
2019-09-04 09:08:56 +07:00
|
|
|
return sizeof(struct erofs_xattr_ibody_header) +
|
|
|
|
sizeof(u32) * EROFS_I(inode)->xattr_shared_count;
|
2018-07-26 19:21:52 +07:00
|
|
|
}
|
|
|
|
|
2019-07-15 19:21:27 +07:00
|
|
|
static inline erofs_blk_t xattrblock_addr(struct erofs_sb_info *sbi,
|
|
|
|
unsigned int xattr_id)
|
2018-07-26 19:21:52 +07:00
|
|
|
{
|
|
|
|
#ifdef CONFIG_EROFS_FS_XATTR
|
|
|
|
return sbi->xattr_blkaddr +
|
|
|
|
xattr_id * sizeof(__u32) / EROFS_BLKSIZ;
|
|
|
|
#else
|
|
|
|
return 0;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2019-07-15 19:21:27 +07:00
|
|
|
static inline unsigned int xattrblock_offset(struct erofs_sb_info *sbi,
|
|
|
|
unsigned int xattr_id)
|
2018-07-26 19:21:52 +07:00
|
|
|
{
|
|
|
|
return (xattr_id * sizeof(__u32)) % EROFS_BLKSIZ;
|
|
|
|
}
|
|
|
|
|
2019-07-31 22:57:33 +07:00
|
|
|
#ifdef CONFIG_EROFS_FS_XATTR
|
2018-07-26 19:21:52 +07:00
|
|
|
extern const struct xattr_handler erofs_xattr_user_handler;
|
|
|
|
extern const struct xattr_handler erofs_xattr_trusted_handler;
|
|
|
|
#ifdef CONFIG_EROFS_FS_SECURITY
|
|
|
|
extern const struct xattr_handler erofs_xattr_security_handler;
|
|
|
|
#endif
|
|
|
|
|
2019-07-15 19:21:27 +07:00
|
|
|
static inline const struct xattr_handler *erofs_xattr_handler(unsigned int idx)
|
2018-07-26 19:21:52 +07:00
|
|
|
{
|
2020-01-02 19:02:32 +07:00
|
|
|
static const struct xattr_handler *xattr_handler_map[] = {
|
|
|
|
[EROFS_XATTR_INDEX_USER] = &erofs_xattr_user_handler,
|
2018-07-26 19:21:52 +07:00
|
|
|
#ifdef CONFIG_EROFS_FS_POSIX_ACL
|
2020-01-02 19:02:32 +07:00
|
|
|
[EROFS_XATTR_INDEX_POSIX_ACL_ACCESS] =
|
|
|
|
&posix_acl_access_xattr_handler,
|
|
|
|
[EROFS_XATTR_INDEX_POSIX_ACL_DEFAULT] =
|
|
|
|
&posix_acl_default_xattr_handler,
|
2018-07-26 19:21:52 +07:00
|
|
|
#endif
|
2020-01-02 19:02:32 +07:00
|
|
|
[EROFS_XATTR_INDEX_TRUSTED] = &erofs_xattr_trusted_handler,
|
2018-07-26 19:21:52 +07:00
|
|
|
#ifdef CONFIG_EROFS_FS_SECURITY
|
2020-01-02 19:02:32 +07:00
|
|
|
[EROFS_XATTR_INDEX_SECURITY] = &erofs_xattr_security_handler,
|
2018-07-26 19:21:52 +07:00
|
|
|
#endif
|
2020-01-02 19:02:32 +07:00
|
|
|
};
|
2019-07-15 19:21:27 +07:00
|
|
|
|
|
|
|
return idx && idx < ARRAY_SIZE(xattr_handler_map) ?
|
|
|
|
xattr_handler_map[idx] : NULL;
|
2018-07-26 19:21:52 +07:00
|
|
|
}
|
|
|
|
|
2019-01-14 18:40:25 +07:00
|
|
|
extern const struct xattr_handler *erofs_xattr_handlers[];
|
|
|
|
|
2018-07-26 19:21:52 +07:00
|
|
|
int erofs_getxattr(struct inode *, int, const char *, void *, size_t);
|
|
|
|
ssize_t erofs_listxattr(struct dentry *, char *, size_t);
|
|
|
|
#else
|
2019-07-31 22:57:33 +07:00
|
|
|
static inline int erofs_getxattr(struct inode *inode, int index,
|
|
|
|
const char *name, void *buffer,
|
|
|
|
size_t buffer_size)
|
2018-07-26 19:21:52 +07:00
|
|
|
{
|
2019-08-14 17:37:05 +07:00
|
|
|
return -EOPNOTSUPP;
|
2018-07-26 19:21:52 +07:00
|
|
|
}
|
|
|
|
|
2019-07-31 22:57:33 +07:00
|
|
|
static inline ssize_t erofs_listxattr(struct dentry *dentry,
|
|
|
|
char *buffer, size_t buffer_size)
|
2018-07-26 19:21:52 +07:00
|
|
|
{
|
2019-08-14 17:37:05 +07:00
|
|
|
return -EOPNOTSUPP;
|
2018-07-26 19:21:52 +07:00
|
|
|
}
|
2019-07-31 22:57:33 +07:00
|
|
|
#endif /* !CONFIG_EROFS_FS_XATTR */
|
2018-07-26 19:21:52 +07:00
|
|
|
|
2019-01-29 15:35:20 +07:00
|
|
|
#ifdef CONFIG_EROFS_FS_POSIX_ACL
|
|
|
|
struct posix_acl *erofs_get_acl(struct inode *inode, int type);
|
|
|
|
#else
|
|
|
|
#define erofs_get_acl (NULL)
|
|
|
|
#endif
|
|
|
|
|
2018-07-26 19:21:52 +07:00
|
|
|
#endif
|
|
|
|
|