File: nodeptr40.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 (185 lines) | stat: -rw-r--r-- 4,314 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
/* Copyright (C) 2001-2005 by Hans Reiser, licensing governed by
   reiser4progs/COPYING.
   
   nodeptr40.c -- reiser4 default node pointer item plugin. */

#include "nodeptr40.h"
#include "nodeptr40_repair.h"

reiser4_core_t *nodeptr40_core = NULL;

/* Returns the number of units in nodeptr. As nodeptr40 has not units and thus
   cannot be splitted by balancing, it has one unit. */
static uint32_t nodeptr40_units(reiser4_place_t *place) {
	return 1;
}

/* Fetches nodeptr into passed @hint */
static int64_t nodeptr40_fetch_units(reiser4_place_t *place,
				     trans_hint_t *hint)
{
	nodeptr40_t *nodeptr;
	ptr_hint_t *ptr_hint;
		
	aal_assert("umka-1420", hint != NULL);
	aal_assert("umka-1419", place != NULL);

	nodeptr = nodeptr40_body(place);
	ptr_hint = (ptr_hint_t *)hint->specific;
	
	ptr_hint->width = 1;
	ptr_hint->start = np40_get_ptr(nodeptr);
	
	return 1;
}

#ifndef ENABLE_MINIMAL
/* Update nodeptr block number by passed @blk. */
static errno_t nodeptr40_update_units(reiser4_place_t *place,
				      trans_hint_t *hint)
{
	ptr_hint_t *ptr;
	
	aal_assert("umka-2667", place != NULL);
	aal_assert("vpf-1863", hint != NULL);
	
	ptr = (ptr_hint_t *)hint->specific;
	np40_set_ptr(nodeptr40_body(place), ptr->start);
	place_mkdirty(place);
	
	return 1;
}

/* Layout implementation for nodeptr40. It calls @geion_func for each block
   nodeptr points to. */
static errno_t nodeptr40_layout(reiser4_place_t *place,
				region_func_t region_func,
				void *data)
{
	blk_t blk;
	
	aal_assert("umka-1749", place != NULL);
	aal_assert("umka-2354", place->body != NULL);
	aal_assert("umka-1750", region_func != NULL);

	blk = np40_get_ptr(nodeptr40_body(place));
	return region_func(blk, 1, data);
}

/* Estimates how many bytes is needed for creating new nodeptr */
static errno_t nodeptr40_prep_insert(reiser4_place_t *place,
				     trans_hint_t *hint)
{
	aal_assert("vpf-068", hint != NULL);
	aal_assert("umka-2436", place != NULL);

	hint->overhead = 0;
	hint->len = sizeof(nodeptr40_t);
	
	return 0;
}

/* Writes of the specified nodeptr into passed @place */
static int64_t nodeptr40_insert_units(reiser4_place_t *place,
				      trans_hint_t *hint)
{
	nodeptr40_t *nodeptr;
	ptr_hint_t *ptr_hint;
		
	aal_assert("umka-1424", hint != NULL);
	aal_assert("umka-1423", place != NULL);

	nodeptr = nodeptr40_body(place);
	
	ptr_hint = (ptr_hint_t *)hint->specific;
	np40_set_ptr(nodeptr, ptr_hint->start);

	place_mkdirty(place);
	return 1;
}

/* Removes nodeptr unit. Asit is always one, we only set up passed @hint here by
   sizeof nodeptr40_t struct. */
static errno_t nodeptr40_remove_units(reiser4_place_t *place,
				      trans_hint_t *hint)
{
	aal_assert("umka-3029", hint != NULL);
	aal_assert("umka-3028", place != NULL);

	hint->overhead = 0;
	hint->len = sizeof(nodeptr40_t);
	
	return 0;
}
#endif

static item_balance_ops_t balance_ops = {
#ifndef ENABLE_MINIMAL
	.merge		  = NULL,
	.prep_shift	  = NULL,
	.shift_units	  = NULL,
	.maxreal_key	  = NULL,
	.update_key	  = NULL,
	.mergeable	  = NULL,
	.collision	  = NULL,
	.overhead	  = NULL,
#endif
	.init		  = NULL,
	.lookup		  = NULL,
	.fetch_key	  = NULL,
	.maxposs_key	  = NULL,

	.units		  = nodeptr40_units
};

static item_object_ops_t object_ops = {
#ifndef ENABLE_MINIMAL
	.layout		  = nodeptr40_layout,
	.prep_insert	  = nodeptr40_prep_insert,
	.insert_units	  = nodeptr40_insert_units,
	.remove_units	  = nodeptr40_remove_units,

	.prep_write	  = NULL,
	.write_units	  = NULL,
	.update_units	  = nodeptr40_update_units,
	.trunc_units	  = NULL,
	.size		  = NULL,
	.bytes		  = NULL,
#endif
	.read_units	  = NULL,
	.fetch_units	  = nodeptr40_fetch_units
};

#ifndef ENABLE_MINIMAL	    
static item_repair_ops_t repair_ops = {
	.check_struct	  = nodeptr40_check_struct,
	.check_layout	  = nodeptr40_check_layout,
	
	.prep_insert_raw = NULL,
	.insert_raw	  = NULL,

	.pack		  = NULL,
	.unpack		  = NULL
};

static item_debug_ops_t debug_ops = {
	.print		  = nodeptr40_print,
};
#endif

reiser4_item_plug_t nodeptr40_plug = {
	.p = {
		.id    = {ITEM_NODEPTR40_ID, PTR_ITEM, ITEM_PLUG_TYPE},
#ifndef ENABLE_MINIMAL
		.label = "nodeptr40",
		.desc  = "Node pointer item plugin.",
#endif
	},

	.object		  = &object_ops,
	.balance	  = &balance_ops,
#ifndef ENABLE_MINIMAL
	.repair		  = &repair_ops,
	.debug		  = &debug_ops
#endif
};