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