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