File: key.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 (234 lines) | stat: -rw-r--r-- 6,168 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
/* Copyright (C) 2001-2005 by Hans Reiser, licensing governed by
   reiser4progs/COPYING.
   
   key.c -- reiser4 common key code. */  

#include <reiser4/libreiser4.h>

#ifndef ENABLE_MINIMAL
void reiser4_key_free(reiser4_key_t *key) {
	aal_free(key);
}
#endif

int reiser4_key_compshort(
	reiser4_key_t *key1,	    /* the first key for comparing */
	reiser4_key_t *key2)	    /* the second one */
{
	aal_assert("umka-764", key1 != NULL);
	aal_assert("umka-765", key2 != NULL);

	aal_assert("umka-906", key1->plug != NULL);

	return objcall(key1, compshort, key2);
}

/* Compares two keys in plugin independent manner by means of using one of
   passed keys plugin. */
int reiser4_key_compfull(
	reiser4_key_t *key1,	    /* the first key for comparing */
	reiser4_key_t *key2)	    /* the second one */
{
	aal_assert("umka-764", key1 != NULL);
	aal_assert("umka-765", key2 != NULL);

	aal_assert("umka-906", key1->plug != NULL);

	return objcall(key1, compfull, key2);
}

#ifndef ENABLE_MINIMAL
/* Builds full non-directory key */
errno_t reiser4_key_build_generic(
	reiser4_key_t *key,	    /* key to be built */
	uint32_t type,		    /* key type to be used */
	oid_t locality,		    /* locality to be used */
	uint64_t ordering,	    /* ordering to be used */
	oid_t objectid,		    /* objectid to be used */
	uint64_t offset)	    /* offset to be used */
{
	aal_assert("umka-665", key != NULL);
	aal_assert("umka-666", key->plug != NULL);

	return objcall(key, build_generic, type, locality, 
		       ordering, objectid, offset);
}

/* Builds full directory key. */
void reiser4_key_build_hashed(
	reiser4_key_t *key,	    /* key to be built */
	reiser4_hash_plug_t *hash,  /* hash plugin to be used */
	reiser4_fibre_plug_t *fibre,/* fibre plugin to be used */
	oid_t locality,		    /* loaclity to be used */
	oid_t objectid,		    /* objectid to be used */
	char *name)	            /* entry name to be hashed */
{
	aal_assert("umka-668", key != NULL);
	aal_assert("umka-670", name != NULL);
	aal_assert("umka-669", key->plug != NULL);
    
	objcall(key, build_hashed, hash, fibre, locality, objectid, name);
}

/* Sets key type */
errno_t reiser4_key_set_type(
	reiser4_key_t *key,	    /* key type will be updated in */
	uint32_t type)		    /* new key type */
{
	aal_assert("umka-686", key != NULL);
	aal_assert("umka-687", key->plug != NULL);

	objcall(key, set_type, type);
	return 0;
}

/* Updates key objectid */
errno_t reiser4_key_set_objectid(
	reiser4_key_t *key,	    /* key objectid will be updated in */
	oid_t objectid)	            /* new objectid */
{
	aal_assert("umka-694", key != NULL);
	aal_assert("umka-695", key->plug != NULL);
    
	objcall(key, set_objectid, objectid);

	return 0;
}

/* Updates key locality */
errno_t reiser4_key_set_locality(
	reiser4_key_t *key,	    /* key locality will be updated in */
	oid_t locality)	            /* new locality */
{
	aal_assert("umka-696", key != NULL);
	aal_assert("umka-697", key->plug != NULL);
    
	objcall(key, set_locality, locality);
	return 0;
}

/* Updates key ordering */
errno_t reiser4_key_set_ordering(
	reiser4_key_t *key,	    /* key, ordering will be updated in */
	uint64_t ordering)          /* new ordering */
{
	aal_assert("umka-2337", key != NULL);
	aal_assert("umka-2338", key->plug != NULL);
    
	objcall(key, set_ordering, ordering);
	return 0;
}
#endif
/* Sets key offset */
errno_t reiser4_key_set_offset(
	reiser4_key_t *key,	    /* key to be updated */
	uint64_t offset)	    /* new offset */
{
	aal_assert("umka-688", key != NULL);
	aal_assert("umka-689", key->plug != NULL);
    
	objcall(key, set_offset, offset);
	return 0;
}


/* Returns key offset */
uint64_t reiser4_key_get_offset(reiser4_key_t *key) {
	aal_assert("umka-700", key != NULL);
	aal_assert("umka-701", key->plug != NULL);

	return objcall(key, get_offset);
}

/* Increases key's offset by passed @value */
void reiser4_key_inc_offset(reiser4_key_t *key, uint64_t value) {
	reiser4_key_set_offset(key, reiser4_key_get_offset(key) + value);
}

#ifndef ENABLE_MINIMAL
/* Gets key type */
uint32_t reiser4_key_get_type(reiser4_key_t *key) {
	aal_assert("umka-698", key != NULL);
	aal_assert("umka-699", key->plug != NULL);

	return objcall(key, get_type);
}

/* Returns key objectid */
oid_t reiser4_key_get_objectid(reiser4_key_t *key) {
	aal_assert("umka-702", key != NULL);
	aal_assert("umka-703", key->plug != NULL);

	return objcall(key, get_objectid);
}

/* Returns key locality */
oid_t reiser4_key_get_locality(reiser4_key_t *key) {
	aal_assert("umka-704", key != NULL);
	aal_assert("umka-705", key->plug != NULL);

	return objcall(key, get_locality);
}

/* Returns key locality */
uint64_t reiser4_key_get_ordering(reiser4_key_t *key) {
	aal_assert("umka-2335", key != NULL);
	aal_assert("umka-2336", key->plug != NULL);

	return objcall(key, get_ordering);
}
#endif

/* Returns the maximal possible key  */
void reiser4_key_maximal(reiser4_key_t *key) {
	reiser4_key_t *entity;
    
	aal_assert("vpf-185", key != NULL);
	aal_assert("vpf-186", key->plug != NULL);

	entity = plugcall(key->plug, maximal);
	aal_memcpy(key->body, entity->body, sizeof(key->body));
}

#ifndef ENABLE_MINIMAL
/* Returns the minimal possible key */
void reiser4_key_minimal(reiser4_key_t *key) {
	reiser4_key_t *entity;
    
	aal_assert("vpf-187", key != NULL);
	aal_assert("vpf-188", key->plug != NULL);

	entity = plugcall(key->plug, minimal);
	aal_memcpy(key->body, entity->body, sizeof(key->body));
}

/* Sets key hash component */
errno_t reiser4_key_set_hash(
	reiser4_key_t *key,	    /* key hash will be updated in */
	uint64_t hash)		    /* new hash value */
{
	aal_assert("umka-706", key != NULL);
	aal_assert("umka-707", key->plug != NULL);
    
	objcall(key, set_hash, hash);
	return 0;
}

/* Returns key hash */
uint64_t reiser4_key_get_hash(reiser4_key_t *key) {
	aal_assert("umka-708", key != NULL);
	aal_assert("umka-709", key->plug != NULL);

	return objcall(key, get_hash);
}

void reiser4_key_print(reiser4_key_t *key, 
		       aal_stream_t *stream,
		       uint16_t options)
{
	aal_assert("vpf-189", key != NULL);
	aal_assert("vpf-190", key->plug != NULL);

	objcall(key, print, stream, options);
}
#endif