ReactOS 0.4.16-dev-297-gc569aee
ext4_xattr.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2015 Grzegorz Kostka (kostka.grzegorz@gmail.com)
3 * Copyright (c) 2015 Kaho Ng (ngkaho1234@gmail.com)
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * - Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * - Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * - The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
37#ifndef EXT4_XATTR_H_
38#define EXT4_XATTR_H_
39
40#include <ext2fs.h>
41#include <linux/rbtree.h>
42
43/* Extended Attribute(EA) */
44
45/* Magic value in attribute blocks */
46#define EXT4_XATTR_MAGIC 0xEA020000
47
48/* Maximum number of references to one attribute block */
49#define EXT4_XATTR_REFCOUNT_MAX 1024
50
51/* Name indexes */
52#define EXT4_XATTR_INDEX_USER 1
53#define EXT4_XATTR_INDEX_POSIX_ACL_ACCESS 2
54#define EXT4_XATTR_INDEX_POSIX_ACL_DEFAULT 3
55#define EXT4_XATTR_INDEX_TRUSTED 4
56#define EXT4_XATTR_INDEX_LUSTRE 5
57#define EXT4_XATTR_INDEX_SECURITY 6
58#define EXT4_XATTR_INDEX_SYSTEM 7
59#define EXT4_XATTR_INDEX_RICHACL 8
60#define EXT4_XATTR_INDEX_ENCRYPTION 9
61
62#pragma pack(push, 1)
63
65 __le32 h_magic; /* magic number for identification */
66 __le32 h_refcount; /* reference count */
67 __le32 h_blocks; /* number of disk blocks used */
68 __le32 h_hash; /* hash value of all attributes */
69 __le32 h_checksum; /* crc32c(uuid+id+xattrblock) */
70 /* id = inum if refcount=1, blknum otherwise */
71 __le32 h_reserved[3]; /* zero right now */
72};
73
75 __le32 h_magic; /* magic number for identification */
76};
77
79 __u8 e_name_len; /* length of name */
80 __u8 e_name_index; /* attribute name index */
81 __le16 e_value_offs; /* offset in disk block of value */
82 __le32 e_value_block; /* disk block attribute is stored on (n/i) */
83 __le32 e_value_size; /* size of attribute value */
84 __le32 e_hash; /* hash value of name and value */
85};
86
87#pragma pack(pop)
88
89#define EXT4_GOOD_OLD_INODE_SIZE EXT2_GOOD_OLD_INODE_SIZE
90
91#define EXT4_XATTR_PAD_BITS 2
92#define EXT4_XATTR_PAD (1<<EXT4_XATTR_PAD_BITS)
93#define EXT4_XATTR_ROUND (EXT4_XATTR_PAD-1)
94#define EXT4_XATTR_LEN(name_len) \
95 (((name_len) + EXT4_XATTR_ROUND + \
96 sizeof(struct ext4_xattr_entry)) & ~EXT4_XATTR_ROUND)
97#define EXT4_XATTR_NEXT(entry) \
98 ((struct ext4_xattr_entry *)( \
99 (char *)(entry) + EXT4_XATTR_LEN((entry)->e_name_len)))
100#define EXT4_XATTR_SIZE(size) \
101 (((size) + EXT4_XATTR_ROUND) & ~EXT4_XATTR_ROUND)
102#define EXT4_XATTR_NAME(entry) \
103 ((char *)((entry) + 1))
104
105#define EXT4_XATTR_IHDR(raw_inode) \
106 ((struct ext4_xattr_ibody_header *) \
107 ((char *)raw_inode + \
108 EXT4_GOOD_OLD_INODE_SIZE + \
109 (raw_inode)->i_extra_isize))
110#define EXT4_XATTR_IFIRST(hdr) \
111 ((struct ext4_xattr_entry *)((hdr)+1))
112
113#define EXT4_XATTR_BHDR(block) \
114 ((struct ext4_xattr_header *)((block)->b_data))
115#define EXT4_XATTR_ENTRY(ptr) \
116 ((struct ext4_xattr_entry *)(ptr))
117#define EXT4_XATTR_BFIRST(block) \
118 EXT4_XATTR_ENTRY(EXT4_XATTR_BHDR(block)+1)
119#define EXT4_XATTR_IS_LAST_ENTRY(entry) \
120 (*(__le32 *)(entry) == 0)
121
122#define EXT4_ZERO_XATTR_VALUE ((void *)-1)
123
124
126 /* This attribute should be stored in inode body */
129
131 char *name;
132 size_t name_len;
133 void *data;
134 size_t data_size;
135
136 struct rb_node node;
138};
139
145
148
150 size_t ea_size;
154
155 void *iter_arg;
157
158 struct rb_root root;
160};
161
162#define EXT4_XATTR_ITERATE_CONT 0
163#define EXT4_XATTR_ITERATE_STOP 1
164#define EXT4_XATTR_ITERATE_PAUSE 2
165
167 struct ext4_xattr_ref *ref);
168
170
171int ext4_fs_set_xattr(struct ext4_xattr_ref *ref, __u8 name_index,
172 const char *name, size_t name_len, const void *data,
173 size_t data_size, BOOL replace);
174
175int ext4_fs_set_xattr_ordered(struct ext4_xattr_ref *ref, __u8 name_index,
176 const char *name, size_t name_len, const void *data,
177 size_t data_size);
178
179int ext4_fs_remove_xattr(struct ext4_xattr_ref *ref, __u8 name_index,
180 const char *name, size_t name_len);
181
182int ext4_fs_get_xattr(struct ext4_xattr_ref *ref, __u8 name_index,
183 const char *name, size_t name_len, void *buf,
184 size_t buf_size, size_t *data_size);
185
187 int(*iter)(struct ext4_xattr_ref *ref,
188 struct ext4_xattr_item *item,
189 BOOL is_last));
190
192
193const char *ext4_extract_xattr_name(const char *full_name, size_t full_name_len,
194 __u8 *name_index, size_t *name_len,
195 BOOL *found);
196
197const char *ext4_get_xattr_name_prefix(__u8 name_index,
198 size_t *ret_prefix_len);
199
200void ext4_xattr_purge_items(struct ext4_xattr_ref *xattr_ref);
201
202#endif
u8 __u8
Definition: btrfs.h:17
#define __le16
Definition: types.h:43
#define __le32
Definition: types.h:44
unsigned int BOOL
Definition: ntddk_ex.h:94
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl.h:1950
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
int ext4_fs_get_xattr(struct ext4_xattr_ref *ref, __u8 name_index, const char *name, size_t name_len, void *buf, size_t buf_size, size_t *data_size)
Definition: ext4_xattr.c:1078
int ext4_fs_set_xattr(struct ext4_xattr_ref *ref, __u8 name_index, const char *name, size_t name_len, const void *data, size_t data_size, BOOL replace)
Definition: ext4_xattr.c:1024
int ext4_fs_set_xattr_ordered(struct ext4_xattr_ref *ref, __u8 name_index, const char *name, size_t name_len, const void *data, size_t data_size)
Definition: ext4_xattr.c:1055
const char * ext4_extract_xattr_name(const char *full_name, size_t full_name_len, __u8 *name_index, size_t *name_len, BOOL *found)
Definition: ext4_xattr.c:1234
void ext4_fs_xattr_iterate_reset(struct ext4_xattr_ref *ref)
Definition: ext4_xattr.c:1019
void ext4_fs_xattr_iterate(struct ext4_xattr_ref *ref, int(*iter)(struct ext4_xattr_ref *ref, struct ext4_xattr_item *item, BOOL is_last))
Definition: ext4_xattr.c:978
void ext4_xattr_purge_items(struct ext4_xattr_ref *xattr_ref)
Definition: ext4_xattr.c:736
const char * ext4_get_xattr_name_prefix(__u8 name_index, size_t *ret_prefix_len)
Definition: ext4_xattr.c:1277
int ext4_fs_remove_xattr(struct ext4_xattr_ref *ref, __u8 name_index, const char *name, size_t name_len)
Definition: ext4_xattr.c:1072
int ext4_fs_put_xattr_ref(struct ext4_xattr_ref *ref)
Definition: ext4_xattr.c:1176
int ext4_fs_get_xattr_ref(PEXT2_IRP_CONTEXT IrpContext, PEXT2_VCB fs, PEXT2_MCB inode_ref, struct ext4_xattr_ref *ref)
Definition: ext4_xattr.c:1105
static ATOM item
Definition: dde.c:856
INT replace(TCHAR source[MAX_PATH], TCHAR dest[MAX_PATH], DWORD dwFlags, BOOL *doMore)
Definition: replace.c:38
Definition: ext4_xattr.h:78
__le32 e_value_block
Definition: ext4_xattr.h:82
__le32 e_hash
Definition: ext4_xattr.h:84
__le32 e_value_size
Definition: ext4_xattr.h:83
__le16 e_value_offs
Definition: ext4_xattr.h:81
__u8 e_name_len
Definition: ext4_xattr.h:79
__u8 e_name_index
Definition: ext4_xattr.h:80
__le32 h_reserved[3]
Definition: ext4_xattr.h:71
struct list_head list_node
Definition: ext4_xattr.h:137
size_t data_size
Definition: ext4_xattr.h:134
size_t block_size_rem
Definition: ext4_xattr.h:152
size_t ea_size
Definition: ext4_xattr.h:150
PEXT2_VCB fs
Definition: ext4_xattr.h:153
void * iter_arg
Definition: ext4_xattr.h:155
struct ext4_xattr_item * iter_from
Definition: ext4_xattr.h:156
BOOL IsOnDiskInodeDirty
Definition: ext4_xattr.h:147
PEXT2_IRP_CONTEXT IrpContext
Definition: ext4_xattr.h:141
struct buffer_head * block_bh
Definition: ext4_xattr.h:143
size_t inode_size_rem
Definition: ext4_xattr.h:151
PEXT2_INODE OnDiskInode
Definition: ext4_xattr.h:146
PEXT2_MCB inode_ref
Definition: ext4_xattr.h:144
struct list_head ordered_list
Definition: ext4_xattr.h:159
Definition: ffs.h:70
Definition: list.h:15
Definition: name.c:39
Definition: rbtree.h:98
Definition: send.c:48
Definition: dlist.c:348