Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0-only */
0002 /*
0003  * Copyright (C) 2017-2018 HUAWEI, Inc.
0004  *             https://www.huawei.com/
0005  */
0006 #ifndef __EROFS_XATTR_H
0007 #define __EROFS_XATTR_H
0008 
0009 #include "internal.h"
0010 #include <linux/posix_acl_xattr.h>
0011 #include <linux/xattr.h>
0012 
0013 /* Attribute not found */
0014 #define ENOATTR         ENODATA
0015 
0016 static inline unsigned int inlinexattr_header_size(struct inode *inode)
0017 {
0018     return sizeof(struct erofs_xattr_ibody_header) +
0019         sizeof(u32) * EROFS_I(inode)->xattr_shared_count;
0020 }
0021 
0022 static inline erofs_blk_t xattrblock_addr(struct erofs_sb_info *sbi,
0023                       unsigned int xattr_id)
0024 {
0025 #ifdef CONFIG_EROFS_FS_XATTR
0026     return sbi->xattr_blkaddr +
0027         xattr_id * sizeof(__u32) / EROFS_BLKSIZ;
0028 #else
0029     return 0;
0030 #endif
0031 }
0032 
0033 static inline unsigned int xattrblock_offset(struct erofs_sb_info *sbi,
0034                          unsigned int xattr_id)
0035 {
0036     return (xattr_id * sizeof(__u32)) % EROFS_BLKSIZ;
0037 }
0038 
0039 #ifdef CONFIG_EROFS_FS_XATTR
0040 extern const struct xattr_handler erofs_xattr_user_handler;
0041 extern const struct xattr_handler erofs_xattr_trusted_handler;
0042 #ifdef CONFIG_EROFS_FS_SECURITY
0043 extern const struct xattr_handler erofs_xattr_security_handler;
0044 #endif
0045 
0046 static inline const struct xattr_handler *erofs_xattr_handler(unsigned int idx)
0047 {
0048     static const struct xattr_handler *xattr_handler_map[] = {
0049         [EROFS_XATTR_INDEX_USER] = &erofs_xattr_user_handler,
0050 #ifdef CONFIG_EROFS_FS_POSIX_ACL
0051         [EROFS_XATTR_INDEX_POSIX_ACL_ACCESS] =
0052             &posix_acl_access_xattr_handler,
0053         [EROFS_XATTR_INDEX_POSIX_ACL_DEFAULT] =
0054             &posix_acl_default_xattr_handler,
0055 #endif
0056         [EROFS_XATTR_INDEX_TRUSTED] = &erofs_xattr_trusted_handler,
0057 #ifdef CONFIG_EROFS_FS_SECURITY
0058         [EROFS_XATTR_INDEX_SECURITY] = &erofs_xattr_security_handler,
0059 #endif
0060     };
0061 
0062     return idx && idx < ARRAY_SIZE(xattr_handler_map) ?
0063         xattr_handler_map[idx] : NULL;
0064 }
0065 
0066 extern const struct xattr_handler *erofs_xattr_handlers[];
0067 
0068 int erofs_getxattr(struct inode *, int, const char *, void *, size_t);
0069 ssize_t erofs_listxattr(struct dentry *, char *, size_t);
0070 #else
0071 static inline int erofs_getxattr(struct inode *inode, int index,
0072                  const char *name, void *buffer,
0073                  size_t buffer_size)
0074 {
0075     return -EOPNOTSUPP;
0076 }
0077 
0078 #define erofs_listxattr (NULL)
0079 #define erofs_xattr_handlers (NULL)
0080 #endif  /* !CONFIG_EROFS_FS_XATTR */
0081 
0082 #ifdef CONFIG_EROFS_FS_POSIX_ACL
0083 struct posix_acl *erofs_get_acl(struct inode *inode, int type, bool rcu);
0084 #else
0085 #define erofs_get_acl   (NULL)
0086 #endif
0087 
0088 #endif