File: item.c

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 (252 lines) | stat: -rw-r--r-- 6,323 bytes parent folder | download | duplicates (8)
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
/* Copyright (C) 2001-2005 by Hans Reiser, licensing governed by
   reiser4progs/COPYING.
   
   item.c -- common reiser4 item functions. */

#include <reiser4/libreiser4.h>

/* Returns count of units in item. If count method is not implemented, it
   returns 1. */
uint32_t reiser4_item_units(reiser4_place_t *place) {
	aal_assert("umka-1030", place != NULL);
	aal_assert("umka-1448", place->plug != NULL);

	if (place->plug->balance->units) {
		return objcall(place, balance->units);
	}
	
	return 1;
}

#ifndef ENABLE_MINIMAL
bool_t reiser4_item_statdata(reiser4_place_t *place) {
	aal_assert("umka-1831", place != NULL);
	aal_assert("umka-2382", place->plug != NULL);

	return place->plug->p.id.group == STAT_ITEM;
}

/* Returns item type from its plugin */
rid_t reiser4_item_type(reiser4_place_t *place) {
	aal_assert("vpf-424", place != NULL);
	aal_assert("vpf-425", place->plug != NULL);
	
	if (place->plug->p.id.type != ITEM_PLUG_TYPE)
		return LAST_ITEM;
		
	return (place->plug->p.id.group < LAST_ITEM ?
		place->plug->p.id.group : LAST_ITEM);
}

int reiser4_item_mergeable(reiser4_place_t *place1, reiser4_place_t *place2) {
	aal_assert("vpf-1428", place1 != NULL);
	aal_assert("vpf-1428", place2 != NULL);

	/* Check if plugins are equal */
	if (!plug_equal(place1->plug, place2->plug))
		return 0;

	/* Check if mergeable is implemented and calling it if it is. */
	return place1->plug->balance->mergeable &&
		place1->plug->balance->mergeable(place1, place2);
}
#endif

/* Returns 1 if @place points to an nodeptr item. */
bool_t reiser4_item_branch(reiser4_item_plug_t *plug) {
	aal_assert("umka-1829", plug != NULL);
	return (plug->p.id.group == PTR_ITEM);
}

/* Returns maximal possible key may exist in item at @place. */
errno_t reiser4_item_maxposs_key(reiser4_place_t *place,
				 reiser4_key_t *key)
{
	aal_assert("umka-1270", key != NULL);
	aal_assert("umka-1269", place != NULL);
	aal_assert("umka-1456", place->plug != NULL);
	
	aal_memcpy(key, &place->key, sizeof(*key));

	if (!place->plug->balance->maxposs_key)
		return 0;
	
	return objcall(place, balance->maxposs_key, key);
}

#ifndef ENABLE_MINIMAL
/* Returns real maximal item key */
errno_t reiser4_item_maxreal_key(reiser4_place_t *place,
				 reiser4_key_t *key)
{
	aal_assert("vpf-352", key != NULL);
	aal_assert("vpf-351", place != NULL);
	aal_assert("umka-1457", place->plug != NULL);

	aal_memcpy(key, &place->key, sizeof(*key));

	if (!place->plug->balance->maxreal_key)
		return 0;

	return objcall(place, balance->maxreal_key, key);
}

errno_t reiser4_item_update_key(reiser4_place_t *place,
				reiser4_key_t *key)
{
	aal_assert("vpf-1205", key != NULL);
	aal_assert("vpf-1205", place != NULL);
	
	aal_memcpy(&place->key, key, sizeof(*key));
	
	return reiser4_node_update_key(place->node,
				       &place->pos,
				       &place->key);
}
#endif

errno_t reiser4_item_get_key(reiser4_place_t *place,
			     reiser4_key_t *key)
{
	aal_assert("vpf-1290", place != NULL);
	aal_assert("vpf-1291", key != NULL);

	/* Getting key from item or node and updating it in passed @place. */
	key->plug = place->key.plug;
	
	if (place->plug->balance->fetch_key &&
	    (place->pos.unit && place->pos.unit != MAX_UINT32))
	{
		objcall(place, balance->fetch_key, key);
	} else {
		objcall(place->node, get_key, &place->pos, key);
	}

	return 0;
}

#ifndef ENABLE_MINIMAL
errno_t reiser4_item_update_link(reiser4_place_t *place,
				 blk_t blk)
{
	trans_hint_t hint;
	ptr_hint_t ptr;
	
	aal_assert("umka-2668", place != NULL);
	
	/* Prepare @hint. */
	hint.count = 1;
	hint.specific = &ptr;
	ptr.start = blk;
	ptr.width = 1;
	
	if (objcall(place, object->update_units, &hint) != 1)
		return -EIO;
	
	return 0;
}

uint16_t reiser4_item_overhead(reiser4_item_plug_t *plug) {
	aal_assert("vpf-1514", plug != NULL);
	aal_assert("vpf-1515", plug->p.id.type == ITEM_PLUG_TYPE);
	
	if (!plug->balance->overhead)
		return 0;
	
	return plugcall(plug->balance, overhead);
}

void reiser4_item_set_flag(reiser4_place_t *place, uint16_t flag) {
	uint16_t old;
	
	aal_assert("vpf-1041", place != NULL);
	aal_assert("vpf-1111", place->node != NULL);
	aal_assert("vpf-1530", flag < sizeof(flag) * 8 - 1);
	
	old = objcall(place->node, get_flags, place->pos.item);
	
	if (old & (1 << flag))
		return;
	
	objcall(place->node, set_flags, place->pos.item, old | (1 << flag));
}

void reiser4_item_clear_flag(reiser4_place_t *place, uint16_t flag) {
	uint16_t old;
	
	aal_assert("vpf-1531", place != NULL);
	aal_assert("vpf-1532", place->node != NULL);
	aal_assert("vpf-1533", flag < sizeof(flag) * 8 - 1);
	
	old = objcall(place->node, get_flags, place->pos.item);
	
	if (~old & (1 << flag)) 
		return;
	
	objcall(place->node, set_flags, place->pos.item, old & ~(1 << flag));
}

void reiser4_item_clear_flags(reiser4_place_t *place) {
	uint16_t old;
	
	aal_assert("vpf-1042", place != NULL);
	aal_assert("vpf-1112", place->node != NULL);
	
	old = objcall(place->node, get_flags, place->pos.item);
	
	if (!old) return;
	
	objcall(place->node, set_flags, place->pos.item, 0);
}

bool_t reiser4_item_test_flag(reiser4_place_t *place, uint16_t flag) {
	uint16_t old;
	
	aal_assert("vpf-1043", place != NULL);
	aal_assert("vpf-1113", place->node != NULL);
	aal_assert("vpf-1534", flag < sizeof(flag) * 8 - 1);
	
	old = objcall(place->node, get_flags, place->pos.item);
	
	return old & (1 << flag);
}

void reiser4_item_dup_flags(reiser4_place_t *place, uint16_t flags) {
	aal_assert("vpf-1540", place != NULL);

	objcall(place->node, set_flags, place->pos.item, flags);
}

uint16_t reiser4_item_get_flags(reiser4_place_t *place) {
	aal_assert("vpf-1541", place != NULL);

	return objcall(place->node, get_flags, place->pos.item);
}

lookup_t reiser4_item_collision(reiser4_place_t *place, coll_hint_t *hint) {
	aal_assert("vpf-1550", place != NULL);
	aal_assert("vpf-1551", place->plug != NULL);
	
	if (!place->plug->balance->collision)
		return PRESENT;

	return place->plug->balance->collision(place, hint);
}
#endif

/* Return block number nodeptr item contains. */
blk_t reiser4_item_down_link(reiser4_place_t *place) {
	trans_hint_t hint;
	ptr_hint_t ptr;
	
	aal_assert("umka-2666", place != NULL);
	
	/* Prepare @hint. */
	hint.count = 1;
	hint.specific = &ptr;

	if (objcall(place, object->fetch_units, &hint) != 1)
		return MAX_UINT64;
	
	return ptr.start;
}