File: node40.h

package info (click to toggle)
reiser4progs 1.0.6-1
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 5,348 kB
  • ctags: 3,714
  • sloc: ansic: 33,468; sh: 8,489; makefile: 1,012
file content (296 lines) | stat: -rw-r--r-- 8,246 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
/* Copyright (C) 2001-2005 by Hans Reiser, licensing governed by
   reiser4progs/COPYING.
   
   node40.h -- reiser4 node plugin structures. */

#ifndef NODE40_H
#define NODE40_H

#include <aal/libaal.h>
#include <aux/aux.h>
#include <reiser4/plugin.h>

#define NODE40_MAGIC 0x52344653

extern reiser4_node_plug_t node40_plug;

/* Format of node header for node_common */
typedef struct node40_header {

	/* Plugin id */
	d16_t pid;
    
	/* The number of items */
	d16_t num_items;
    
	/* Node free space */
	d16_t free_space;

	/* Free space start */
	d16_t free_space_start;

	/* node magic 0x52344653 */
	d32_t magic;
	
	/* id common for all nodes, generated at mkfs time. */
	d32_t mkfs_id;
	
	/* id of the flush the node was written at. */
	d64_t flush_id;
	
	/* Useful flags. */
	d16_t flags;

	/* Node level */
	d8_t level;
	
	d8_t pad;
}  __attribute__((packed)) node40_header_t;  

extern reiser4_core_t *node40_core;

typedef int64_t (*modify_func_t) (reiser4_place_t *place,
				  trans_hint_t *hint);

extern void node40_mkdirty(reiser4_node_t *entity);
extern void node40_mkclean(reiser4_node_t *entity);
extern int node40_isdirty(reiser4_node_t *entity);

extern reiser4_node_t *node40_prepare(aal_block_t *block, 
				      reiser4_key_plug_t *kplug);

extern uint16_t node40_space(reiser4_node_t *entity);
extern uint32_t node40_items(reiser4_node_t *entity);

extern uint16_t node40_free_space_end(reiser4_node_t *entity);
extern void *node40_ih_at(reiser4_node_t *entity, uint32_t pos);
extern void *node40_ib_at(reiser4_node_t *entity, uint32_t pos);

extern uint8_t node40_get_level(reiser4_node_t *entity);
extern uint16_t node40_len(reiser4_node_t *entity, pos_t *pos);

extern uint32_t node40_size(reiser4_node_t *node, pos_t *pos,
			    uint32_t count);

extern errno_t node40_fetch(reiser4_node_t *entity,
			    pos_t *pos, reiser4_place_t *place);

extern int64_t node40_modify(reiser4_node_t *entity,
			     pos_t *pos, trans_hint_t *hint,
			     modify_func_t modify_func);

extern errno_t node40_expand(reiser4_node_t *entity, pos_t *pos,
			     uint32_t len, uint32_t count);

extern errno_t node40_shrink(reiser4_node_t *entity, pos_t *pos, 
			     uint32_t len, uint32_t count);

extern errno_t node40_copy(reiser4_node_t *dst_entity, pos_t *dst_pos,
			   reiser4_node_t *src_entity, pos_t *src_pos, 
			   uint32_t count);

extern void node40_set_flags(reiser4_node_t *entity, 
			     uint32_t pos, uint16_t flags);

extern uint16_t node40_get_flag(reiser4_node_t *entity, uint32_t pos);

#define	nh(block)                         \
        ((node40_header_t *)block->data)

#define nh_get_pid(node)                  \
        aal_get_le16(nh((node)->block), pid)

#define nh_set_pid(node, val)             \
        aal_set_le16(nh((node)->block), pid, val)

#define nh_get_level(node)                \
        (nh((node)->block)->level)

#define nh_set_level(node, val)           \
        (nh((node)->block)->level = val)

#define nh_get_magic(node)                \
        aal_get_le32(nh((node)->block), magic)

#define nh_set_magic(node, val)           \
        aal_set_le32(nh((node)->block), magic, val)

#define nh_set_mkfs_id(node, val)         \
        aal_set_le32(nh((node)->block), mkfs_id, val)

#define nh_get_mkfs_id(node)              \
        aal_get_le32(nh((node)->block), mkfs_id)

#define nh_set_flush_id(node, val)        \
        aal_set_le64(nh((node)->block), flush_id, val)

#define nh_get_flush_id(node)             \
        aal_get_le64(nh((node)->block), flush_id)

#define nh_get_num_items(node)            \
        aal_get_le16(nh((node)->block), num_items)

#define nh_set_num_items(node, val)       \
        aal_set_le16(nh((node)->block), num_items, val)

#define nh_get_free_space(node)           \
        aal_get_le16(nh((node)->block), free_space)

#define nh_set_free_space(node, val)      \
        aal_set_le16(nh((node)->block), free_space, val)

#define nh_get_free_space_start(node)     \
        aal_get_le16(nh((node)->block), free_space_start)

#define nh_set_free_space_start(node, val) \
        aal_set_le16(nh((node)->block), free_space_start, val)

#define nh_inc_free_space(node, val)      \
        nh_set_free_space(node, (nh_get_free_space(node) + (val)));

#define nh_dec_free_space(node, val)      \
        nh_set_free_space(node, (nh_get_free_space(node) - (val)));

#define nh_inc_free_space_start(node, val) \
	nh_set_free_space_start(node, (nh_get_free_space_start(node) + (val)));

#define nh_dec_free_space_start(node, val) \
	nh_set_free_space_start(node, (nh_get_free_space_start(node) - (val)));

#define nh_inc_num_items(node, val)       \
	nh_set_num_items(node, (nh_get_num_items(node) + (val)));

#define nh_dec_num_items(node, val)       \
	nh_set_num_items(node, (nh_get_num_items(node) - (val)));

#ifdef ENABLE_SHORT_KEYS
typedef union key3 {
	d64_t el[3];
	int pad;
} key3_t;

typedef struct item_header3 {
	key3_t key3;
    
	d16_t offset;
	d16_t flags;
	d16_t pid;
} __attribute__((packed)) item_header3_t;
#endif

#ifdef ENABLE_LARGE_KEYS
typedef union key4 {
	d64_t el[4];
	int pad;
} key4_t;

typedef struct item_header4 {
	key4_t key4;
    
	d16_t offset;
	d16_t flags;
	d16_t pid;
} __attribute__((packed)) item_header4_t;
#endif

#if defined(ENABLE_SHORT_KEYS) && defined(ENABLE_LARGE_KEYS)
#define ih_size(pol)						\
        ((pol == 3) ?						\
	 sizeof(item_header3_t) :				\
         sizeof(item_header4_t))

#define key_size(pol)						\
        ((pol == 3) ?						\
	 sizeof(key3_t) :					\
	 sizeof(key4_t))

#define ih_get_offset(ih, pol)					\
        ((pol == 3) ?						\
	 aal_get_le16((item_header3_t *)(ih), offset) :		\
         aal_get_le16((item_header4_t *)(ih), offset))

#define ih_set_offset(ih, val, pol)				\
        ((pol == 3) ?						\
	 aal_set_le16((item_header3_t *)(ih), offset, val) :	\
         aal_set_le16((item_header4_t *)(ih), offset, val))

#define ih_get_flags(ih, pol)					\
        ((pol == 3) ?						\
         aal_get_le16((item_header3_t *)(ih), flags) :		\
	 aal_get_le16((item_header4_t *)(ih), flags))

#define ih_set_flags(ih, val, pol)				\
        ((pol == 3) ?						\
         aal_set_le16((item_header3_t *)(ih), flags, val) :	\
	 aal_set_le16((item_header4_t *)(ih), flags, val))

#define ih_get_pid(ih, pol)					\
        ((pol == 3) ?						\
         aal_get_le16((item_header3_t *)(ih), pid) :		\
	 aal_get_le16((item_header4_t *)(ih), pid))

#define ih_set_pid(ih, val, pol)				\
        ((pol == 3) ?						\
         aal_set_le16((item_header3_t *)(ih), pid, val) :	\
	 aal_set_le16((item_header4_t *)(ih), pid, val))
#else
#if defined(ENABLE_SHORT_KEYS)
#define ih_size(pol)						\
        sizeof(item_header3_t)

#define key_size(pol)						\
        sizeof(key3_t)

#define ih_get_offset(ih, pol)					\
        aal_get_le16((item_header3_t *)(ih), offset)

#define ih_set_offset(ih, val, pol)				\
	aal_set_le16((item_header3_t *)(ih), offset, val)

#define ih_get_flags(ih, pol)					\
        aal_get_le16((item_header3_t *)(ih), flags)

#define ih_set_flags(ih, val, pol)				\
        aal_set_le16((item_header3_t *)(ih), flags, val)

#define ih_get_pid(ih, pol)					\
        aal_get_le16((item_header3_t *)(ih), pid)

#define ih_set_pid(ih, val, pol)				\
        aal_set_le16((item_header3_t *)(ih), pid, val)
#else
#define ih_size(pol)						\
        sizeof(item_header4_t)

#define key_size(pol)						\
        sizeof(key4_t)

#define ih_get_offset(ih, pol)					\
        aal_get_le16((item_header4_t *)(ih), offset)

#define ih_set_offset(ih, val, pol)				\
	aal_set_le16((item_header4_t *)(ih), offset, val)

#define ih_get_flags(ih, pol)					\
        aal_get_le16((item_header4_t *)(ih), flags)

#define ih_set_flags(ih, val, pol)				\
        aal_set_le16((item_header4_t *)(ih), flags, val)

#define ih_get_pid(ih, pol)					\
        aal_get_le16((item_header4_t *)(ih), pid)

#define ih_set_pid(ih, val, pol)				\
        aal_set_le16((item_header4_t *)(ih), pid, val)
#endif
#endif

#define ih_inc_offset(ih, val, pol)				\
        ih_set_offset((ih), (ih_get_offset((ih), pol) +		\
        (val)), pol)

#define ih_dec_offset(ih, val, pol)				\
        ih_set_offset((ih), (ih_get_offset((ih), pol) -		\
        (val)), pol)

#endif