1 /* SPDX-License-Identifier: GPL-2.0+ OR Apache-2.0 */
2 /*
3 * Originally contributed by an anonymous person,
4 * heavily changed by Li Guifu <[email protected]>
5 * and Gao Xiang <[email protected]>
6 */
7 #ifndef __EROFS_XATTR_H
8 #define __EROFS_XATTR_H
9
10 #ifdef __cplusplus
11 extern "C"
12 {
13 #endif
14
15 #include "internal.h"
16
17 #ifndef ENOATTR
18 #define ENOATTR ENODATA
19 #endif
20
inlinexattr_header_size(struct erofs_inode * vi)21 static inline unsigned int inlinexattr_header_size(struct erofs_inode *vi)
22 {
23 return sizeof(struct erofs_xattr_ibody_header) +
24 sizeof(u32) * vi->xattr_shared_count;
25 }
26
xattrblock_addr(struct erofs_inode * vi,unsigned int xattr_id)27 static inline erofs_blk_t xattrblock_addr(struct erofs_inode *vi,
28 unsigned int xattr_id)
29 {
30 return vi->sbi->xattr_blkaddr +
31 erofs_blknr(vi->sbi, xattr_id * sizeof(__u32));
32 }
33
xattrblock_offset(struct erofs_inode * vi,unsigned int xattr_id)34 static inline unsigned int xattrblock_offset(struct erofs_inode *vi,
35 unsigned int xattr_id)
36 {
37 return erofs_blkoff(vi->sbi, xattr_id * sizeof(__u32));
38 }
39
40 #define EROFS_INODE_XATTR_ICOUNT(_size) ({\
41 u32 __size = le16_to_cpu(_size); \
42 ((__size) == 0) ? 0 : \
43 (_size - sizeof(struct erofs_xattr_ibody_header)) / \
44 sizeof(struct erofs_xattr_entry) + 1; })
45
46 int erofs_scan_file_xattrs(struct erofs_inode *inode);
47 int erofs_prepare_xattr_ibody(struct erofs_inode *inode, bool noroom);
48 char *erofs_export_xattr_ibody(struct erofs_inode *inode);
49 int erofs_build_shared_xattrs_from_path(struct erofs_sb_info *sbi, const char *path);
50
51 int erofs_xattr_insert_name_prefix(const char *prefix);
52 void erofs_xattr_cleanup_name_prefixes(void);
53 int erofs_xattr_write_name_prefixes(struct erofs_sb_info *sbi, FILE *f);
54 void erofs_xattr_prefixes_cleanup(struct erofs_sb_info *sbi);
55 int erofs_xattr_prefixes_init(struct erofs_sb_info *sbi);
56
57 int erofs_setxattr(struct erofs_inode *inode, char *key,
58 const void *value, size_t size);
59 int erofs_set_opaque_xattr(struct erofs_inode *inode);
60 void erofs_clear_opaque_xattr(struct erofs_inode *inode);
61 int erofs_set_origin_xattr(struct erofs_inode *inode);
62 int erofs_read_xattrs_from_disk(struct erofs_inode *inode);
63
64 #ifdef __cplusplus
65 }
66 #endif
67
68 #endif
69