2019-07-31 18:57:31 +03:00
/* SPDX-License-Identifier: GPL-2.0-only */
/*
2018-07-26 15:21:52 +03:00
* Copyright ( C ) 2017 - 2018 HUAWEI , Inc .
2020-07-13 16:09:44 +03:00
* https : //www.huawei.com/
2018-07-26 15:21:52 +03:00
*/
# 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-31 18:57:33 +03:00
# ifdef CONFIG_EROFS_FS_XATTR
2018-07-26 15:21:52 +03:00
extern const struct xattr_handler erofs_xattr_user_handler ;
extern const struct xattr_handler erofs_xattr_trusted_handler ;
extern const struct xattr_handler erofs_xattr_security_handler ;
2023-02-01 16:14:56 +03:00
static inline const char * erofs_xattr_prefix ( unsigned int idx ,
struct dentry * dentry )
2018-07-26 15:21:52 +03:00
{
2023-02-01 16:14:56 +03:00
const struct xattr_handler * handler = NULL ;
2020-01-02 15:02:32 +03:00
static const struct xattr_handler * xattr_handler_map [ ] = {
[ EROFS_XATTR_INDEX_USER ] = & erofs_xattr_user_handler ,
2018-07-26 15:21:52 +03:00
# ifdef CONFIG_EROFS_FS_POSIX_ACL
2023-02-01 16:14:58 +03:00
[ EROFS_XATTR_INDEX_POSIX_ACL_ACCESS ] = & nop_posix_acl_access ,
[ EROFS_XATTR_INDEX_POSIX_ACL_DEFAULT ] = & nop_posix_acl_default ,
2018-07-26 15:21:52 +03:00
# endif
2020-01-02 15:02:32 +03:00
[ EROFS_XATTR_INDEX_TRUSTED ] = & erofs_xattr_trusted_handler ,
2018-07-26 15:21:52 +03:00
# ifdef CONFIG_EROFS_FS_SECURITY
2020-01-02 15:02:32 +03:00
[ EROFS_XATTR_INDEX_SECURITY ] = & erofs_xattr_security_handler ,
2018-07-26 15:21:52 +03:00
# endif
2020-01-02 15:02:32 +03:00
} ;
2019-07-15 15:21:27 +03:00
2023-02-01 16:14:56 +03:00
if ( idx & & idx < ARRAY_SIZE ( xattr_handler_map ) )
handler = xattr_handler_map [ idx ] ;
if ( ! xattr_handler_can_list ( handler , dentry ) )
return NULL ;
return xattr_prefix ( handler ) ;
2018-07-26 15:21:52 +03:00
}
2019-01-14 14:40:25 +03:00
extern const struct xattr_handler * erofs_xattr_handlers [ ] ;
2023-04-07 17:17:08 +03:00
int erofs_xattr_prefixes_init ( struct super_block * sb ) ;
void erofs_xattr_prefixes_cleanup ( struct super_block * sb ) ;
2018-07-26 15:21:52 +03:00
int erofs_getxattr ( struct inode * , int , const char * , void * , size_t ) ;
ssize_t erofs_listxattr ( struct dentry * , char * , size_t ) ;
# else
2023-04-07 17:17:08 +03:00
static inline int erofs_xattr_prefixes_init ( struct super_block * sb ) { return 0 ; }
static inline void erofs_xattr_prefixes_cleanup ( struct super_block * sb ) { }
2019-07-31 18:57:33 +03:00
static inline int erofs_getxattr ( struct inode * inode , int index ,
const char * name , void * buffer ,
size_t buffer_size )
2018-07-26 15:21:52 +03:00
{
2019-08-14 13:37:05 +03:00
return - EOPNOTSUPP ;
2018-07-26 15:21:52 +03:00
}
2020-05-26 12:03:43 +03:00
# define erofs_listxattr (NULL)
# define erofs_xattr_handlers (NULL)
2019-07-31 18:57:33 +03:00
# endif /* !CONFIG_EROFS_FS_XATTR */
2018-07-26 15:21:52 +03:00
2019-01-29 11:35:20 +03:00
# ifdef CONFIG_EROFS_FS_POSIX_ACL
2021-08-18 23:08:24 +03:00
struct posix_acl * erofs_get_acl ( struct inode * inode , int type , bool rcu ) ;
2019-01-29 11:35:20 +03:00
# else
# define erofs_get_acl (NULL)
# endif
2018-07-26 15:21:52 +03:00
# endif