]> git.proxmox.com Git - mirror_ubuntu-jammy-kernel.git/blame - fs/erofs/xattr.h
net/mlx5: Fix some error handling paths in 'mlx5e_tc_add_fdb_flow()'
[mirror_ubuntu-jammy-kernel.git] / fs / erofs / xattr.h
CommitLineData
29b24f6c
GX
1/* SPDX-License-Identifier: GPL-2.0-only */
2/*
b17500a0 3 * Copyright (C) 2017-2018 HUAWEI, Inc.
592e7cd0 4 * https://www.huawei.com/
b17500a0
GX
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
e82a9a17 16static inline unsigned int inlinexattr_header_size(struct inode *inode)
b17500a0 17{
a5876e24
GX
18 return sizeof(struct erofs_xattr_ibody_header) +
19 sizeof(u32) * EROFS_I(inode)->xattr_shared_count;
b17500a0
GX
20}
21
e82a9a17
PS
22static inline erofs_blk_t xattrblock_addr(struct erofs_sb_info *sbi,
23 unsigned int xattr_id)
b17500a0
GX
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
e82a9a17
PS
33static inline unsigned int xattrblock_offset(struct erofs_sb_info *sbi,
34 unsigned int xattr_id)
b17500a0
GX
35{
36 return (xattr_id * sizeof(__u32)) % EROFS_BLKSIZ;
37}
38
5734fa21 39#ifdef CONFIG_EROFS_FS_XATTR
b17500a0
GX
40extern 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
e82a9a17 46static inline const struct xattr_handler *erofs_xattr_handler(unsigned int idx)
b17500a0 47{
a55861c8
VZ
48 static const struct xattr_handler *xattr_handler_map[] = {
49 [EROFS_XATTR_INDEX_USER] = &erofs_xattr_user_handler,
b17500a0 50#ifdef CONFIG_EROFS_FS_POSIX_ACL
a55861c8
VZ
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,
b17500a0 55#endif
a55861c8 56 [EROFS_XATTR_INDEX_TRUSTED] = &erofs_xattr_trusted_handler,
b17500a0 57#ifdef CONFIG_EROFS_FS_SECURITY
a55861c8 58 [EROFS_XATTR_INDEX_SECURITY] = &erofs_xattr_security_handler,
b17500a0 59#endif
a55861c8 60 };
e82a9a17
PS
61
62 return idx && idx < ARRAY_SIZE(xattr_handler_map) ?
63 xattr_handler_map[idx] : NULL;
b17500a0
GX
64}
65
6af7b483
GX
66extern const struct xattr_handler *erofs_xattr_handlers[];
67
b17500a0
GX
68int erofs_getxattr(struct inode *, int, const char *, void *, size_t);
69ssize_t erofs_listxattr(struct dentry *, char *, size_t);
70#else
5734fa21
GX
71static inline int erofs_getxattr(struct inode *inode, int index,
72 const char *name, void *buffer,
73 size_t buffer_size)
b17500a0 74{
ff784a78 75 return -EOPNOTSUPP;
b17500a0
GX
76}
77
e7cda1ee
CX
78#define erofs_listxattr (NULL)
79#define erofs_xattr_handlers (NULL)
5734fa21 80#endif /* !CONFIG_EROFS_FS_XATTR */
b17500a0 81
516c115c 82#ifdef CONFIG_EROFS_FS_POSIX_ACL
0cad6246 83struct posix_acl *erofs_get_acl(struct inode *inode, int type, bool rcu);
516c115c
GX
84#else
85#define erofs_get_acl (NULL)
86#endif
87
b17500a0
GX
88#endif
89