aboutsummaryrefslogtreecommitdiffstats
path: root/fs/reiserfs/item_ops.c
diff options
context:
space:
mode:
Diffstat (limited to 'fs/reiserfs/item_ops.c')
-rw-r--r--fs/reiserfs/item_ops.c977
1 files changed, 471 insertions, 506 deletions
diff --git a/fs/reiserfs/item_ops.c b/fs/reiserfs/item_ops.c
index e477aeba8c92..e237cd668e5b 100644
--- a/fs/reiserfs/item_ops.c
+++ b/fs/reiserfs/item_ops.c
@@ -14,760 +14,729 @@
14////////////////////////////////////////////////////////////////////////////// 14//////////////////////////////////////////////////////////////////////////////
15// stat data functions 15// stat data functions
16// 16//
17static int sd_bytes_number (struct item_head * ih, int block_size) 17static int sd_bytes_number(struct item_head *ih, int block_size)
18{ 18{
19 return 0; 19 return 0;
20} 20}
21 21
22static void sd_decrement_key (struct cpu_key * key) 22static void sd_decrement_key(struct cpu_key *key)
23{ 23{
24 key->on_disk_key.k_objectid --; 24 key->on_disk_key.k_objectid--;
25 set_cpu_key_k_type (key, TYPE_ANY); 25 set_cpu_key_k_type(key, TYPE_ANY);
26 set_cpu_key_k_offset(key, (loff_t)(-1)); 26 set_cpu_key_k_offset(key, (loff_t) (-1));
27} 27}
28 28
29static int sd_is_left_mergeable (struct reiserfs_key * key, unsigned long bsize) 29static int sd_is_left_mergeable(struct reiserfs_key *key, unsigned long bsize)
30{ 30{
31 return 0; 31 return 0;
32} 32}
33 33
34 34static char *print_time(time_t t)
35
36static char * print_time (time_t t)
37{ 35{
38 static char timebuf[256]; 36 static char timebuf[256];
39 37
40 sprintf (timebuf, "%ld", t); 38 sprintf(timebuf, "%ld", t);
41 return timebuf; 39 return timebuf;
42} 40}
43 41
44 42static void sd_print_item(struct item_head *ih, char *item)
45static void sd_print_item (struct item_head * ih, char * item)
46{ 43{
47 printk ("\tmode | size | nlinks | first direct | mtime\n"); 44 printk("\tmode | size | nlinks | first direct | mtime\n");
48 if (stat_data_v1 (ih)) { 45 if (stat_data_v1(ih)) {
49 struct stat_data_v1 * sd = (struct stat_data_v1 *)item; 46 struct stat_data_v1 *sd = (struct stat_data_v1 *)item;
50 47
51 printk ("\t0%-6o | %6u | %2u | %d | %s\n", sd_v1_mode(sd), 48 printk("\t0%-6o | %6u | %2u | %d | %s\n", sd_v1_mode(sd),
52 sd_v1_size(sd), sd_v1_nlink(sd), sd_v1_first_direct_byte(sd), 49 sd_v1_size(sd), sd_v1_nlink(sd),
53 print_time( sd_v1_mtime(sd) ) ); 50 sd_v1_first_direct_byte(sd),
54 } else { 51 print_time(sd_v1_mtime(sd)));
55 struct stat_data * sd = (struct stat_data *)item; 52 } else {
53 struct stat_data *sd = (struct stat_data *)item;
56 54
57 printk ("\t0%-6o | %6Lu | %2u | %d | %s\n", sd_v2_mode(sd), 55 printk("\t0%-6o | %6Lu | %2u | %d | %s\n", sd_v2_mode(sd),
58 (unsigned long long)sd_v2_size(sd), sd_v2_nlink(sd), 56 (unsigned long long)sd_v2_size(sd), sd_v2_nlink(sd),
59 sd_v2_rdev(sd), print_time(sd_v2_mtime(sd))); 57 sd_v2_rdev(sd), print_time(sd_v2_mtime(sd)));
60 } 58 }
61} 59}
62 60
63static void sd_check_item (struct item_head * ih, char * item) 61static void sd_check_item(struct item_head *ih, char *item)
64{ 62{
65 // FIXME: type something here! 63 // FIXME: type something here!
66} 64}
67 65
68 66static int sd_create_vi(struct virtual_node *vn,
69static int sd_create_vi (struct virtual_node * vn, 67 struct virtual_item *vi,
70 struct virtual_item * vi, 68 int is_affected, int insert_size)
71 int is_affected,
72 int insert_size)
73{ 69{
74 vi->vi_index = TYPE_STAT_DATA; 70 vi->vi_index = TYPE_STAT_DATA;
75 //vi->vi_type |= VI_TYPE_STAT_DATA;// not needed? 71 //vi->vi_type |= VI_TYPE_STAT_DATA;// not needed?
76 return 0; 72 return 0;
77} 73}
78 74
79 75static int sd_check_left(struct virtual_item *vi, int free,
80static int sd_check_left (struct virtual_item * vi, int free, 76 int start_skip, int end_skip)
81 int start_skip, int end_skip)
82{ 77{
83 if (start_skip || end_skip) 78 if (start_skip || end_skip)
84 BUG (); 79 BUG();
85 return -1; 80 return -1;
86} 81}
87 82
88 83static int sd_check_right(struct virtual_item *vi, int free)
89static int sd_check_right (struct virtual_item * vi, int free)
90{ 84{
91 return -1; 85 return -1;
92} 86}
93 87
94static int sd_part_size (struct virtual_item * vi, int first, int count) 88static int sd_part_size(struct virtual_item *vi, int first, int count)
95{ 89{
96 if (count) 90 if (count)
97 BUG (); 91 BUG();
98 return 0; 92 return 0;
99} 93}
100 94
101static int sd_unit_num (struct virtual_item * vi) 95static int sd_unit_num(struct virtual_item *vi)
102{ 96{
103 return vi->vi_item_len - IH_SIZE; 97 return vi->vi_item_len - IH_SIZE;
104} 98}
105 99
106 100static void sd_print_vi(struct virtual_item *vi)
107static void sd_print_vi (struct virtual_item * vi)
108{ 101{
109 reiserfs_warning (NULL, "STATDATA, index %d, type 0x%x, %h", 102 reiserfs_warning(NULL, "STATDATA, index %d, type 0x%x, %h",
110 vi->vi_index, vi->vi_type, vi->vi_ih); 103 vi->vi_index, vi->vi_type, vi->vi_ih);
111} 104}
112 105
113static struct item_operations stat_data_ops = { 106static struct item_operations stat_data_ops = {
114 .bytes_number = sd_bytes_number, 107 .bytes_number = sd_bytes_number,
115 .decrement_key = sd_decrement_key, 108 .decrement_key = sd_decrement_key,
116 .is_left_mergeable = sd_is_left_mergeable, 109 .is_left_mergeable = sd_is_left_mergeable,
117 .print_item = sd_print_item, 110 .print_item = sd_print_item,
118 .check_item = sd_check_item, 111 .check_item = sd_check_item,
119 112
120 .create_vi = sd_create_vi, 113 .create_vi = sd_create_vi,
121 .check_left = sd_check_left, 114 .check_left = sd_check_left,
122 .check_right = sd_check_right, 115 .check_right = sd_check_right,
123 .part_size = sd_part_size, 116 .part_size = sd_part_size,
124 .unit_num = sd_unit_num, 117 .unit_num = sd_unit_num,
125 .print_vi = sd_print_vi 118 .print_vi = sd_print_vi
126}; 119};
127 120
128
129
130////////////////////////////////////////////////////////////////////////////// 121//////////////////////////////////////////////////////////////////////////////
131// direct item functions 122// direct item functions
132// 123//
133static int direct_bytes_number (struct item_head * ih, int block_size) 124static int direct_bytes_number(struct item_head *ih, int block_size)
134{ 125{
135 return ih_item_len(ih); 126 return ih_item_len(ih);
136} 127}
137 128
138
139// FIXME: this should probably switch to indirect as well 129// FIXME: this should probably switch to indirect as well
140static void direct_decrement_key (struct cpu_key * key) 130static void direct_decrement_key(struct cpu_key *key)
141{ 131{
142 cpu_key_k_offset_dec (key); 132 cpu_key_k_offset_dec(key);
143 if (cpu_key_k_offset (key) == 0) 133 if (cpu_key_k_offset(key) == 0)
144 set_cpu_key_k_type (key, TYPE_STAT_DATA); 134 set_cpu_key_k_type(key, TYPE_STAT_DATA);
145} 135}
146 136
147 137static int direct_is_left_mergeable(struct reiserfs_key *key,
148static int direct_is_left_mergeable (struct reiserfs_key * key, unsigned long bsize) 138 unsigned long bsize)
149{ 139{
150 int version = le_key_version (key); 140 int version = le_key_version(key);
151 return ((le_key_k_offset (version, key) & (bsize - 1)) != 1); 141 return ((le_key_k_offset(version, key) & (bsize - 1)) != 1);
152} 142}
153 143
154 144static void direct_print_item(struct item_head *ih, char *item)
155static void direct_print_item (struct item_head * ih, char * item)
156{ 145{
157 int j = 0; 146 int j = 0;
158 147
159// return; 148// return;
160 printk ("\""); 149 printk("\"");
161 while (j < ih_item_len(ih)) 150 while (j < ih_item_len(ih))
162 printk ("%c", item[j++]); 151 printk("%c", item[j++]);
163 printk ("\"\n"); 152 printk("\"\n");
164} 153}
165 154
166 155static void direct_check_item(struct item_head *ih, char *item)
167static void direct_check_item (struct item_head * ih, char * item)
168{ 156{
169 // FIXME: type something here! 157 // FIXME: type something here!
170} 158}
171 159
172 160static int direct_create_vi(struct virtual_node *vn,
173static int direct_create_vi (struct virtual_node * vn, 161 struct virtual_item *vi,
174 struct virtual_item * vi, 162 int is_affected, int insert_size)
175 int is_affected,
176 int insert_size)
177{ 163{
178 vi->vi_index = TYPE_DIRECT; 164 vi->vi_index = TYPE_DIRECT;
179 //vi->vi_type |= VI_TYPE_DIRECT; 165 //vi->vi_type |= VI_TYPE_DIRECT;
180 return 0; 166 return 0;
181} 167}
182 168
183static int direct_check_left (struct virtual_item * vi, int free, 169static int direct_check_left(struct virtual_item *vi, int free,
184 int start_skip, int end_skip) 170 int start_skip, int end_skip)
185{ 171{
186 int bytes; 172 int bytes;
187 173
188 bytes = free - free % 8; 174 bytes = free - free % 8;
189 return bytes ?: -1; 175 return bytes ? : -1;
190} 176}
191 177
192 178static int direct_check_right(struct virtual_item *vi, int free)
193static int direct_check_right (struct virtual_item * vi, int free)
194{ 179{
195 return direct_check_left (vi, free, 0, 0); 180 return direct_check_left(vi, free, 0, 0);
196} 181}
197 182
198static int direct_part_size (struct virtual_item * vi, int first, int count) 183static int direct_part_size(struct virtual_item *vi, int first, int count)
199{ 184{
200 return count; 185 return count;
201} 186}
202 187
203 188static int direct_unit_num(struct virtual_item *vi)
204static int direct_unit_num (struct virtual_item * vi)
205{ 189{
206 return vi->vi_item_len - IH_SIZE; 190 return vi->vi_item_len - IH_SIZE;
207} 191}
208 192
209 193static void direct_print_vi(struct virtual_item *vi)
210static void direct_print_vi (struct virtual_item * vi)
211{ 194{
212 reiserfs_warning (NULL, "DIRECT, index %d, type 0x%x, %h", 195 reiserfs_warning(NULL, "DIRECT, index %d, type 0x%x, %h",
213 vi->vi_index, vi->vi_type, vi->vi_ih); 196 vi->vi_index, vi->vi_type, vi->vi_ih);
214} 197}
215 198
216static struct item_operations direct_ops = { 199static struct item_operations direct_ops = {
217 .bytes_number = direct_bytes_number, 200 .bytes_number = direct_bytes_number,
218 .decrement_key = direct_decrement_key, 201 .decrement_key = direct_decrement_key,
219 .is_left_mergeable = direct_is_left_mergeable, 202 .is_left_mergeable = direct_is_left_mergeable,
220 .print_item = direct_print_item, 203 .print_item = direct_print_item,
221 .check_item = direct_check_item, 204 .check_item = direct_check_item,
222 205
223 .create_vi = direct_create_vi, 206 .create_vi = direct_create_vi,
224 .check_left = direct_check_left, 207 .check_left = direct_check_left,
225 .check_right = direct_check_right, 208 .check_right = direct_check_right,
226 .part_size = direct_part_size, 209 .part_size = direct_part_size,
227 .unit_num = direct_unit_num, 210 .unit_num = direct_unit_num,
228 .print_vi = direct_print_vi 211 .print_vi = direct_print_vi
229}; 212};
230 213
231
232
233////////////////////////////////////////////////////////////////////////////// 214//////////////////////////////////////////////////////////////////////////////
234// indirect item functions 215// indirect item functions
235// 216//
236 217
237static int indirect_bytes_number (struct item_head * ih, int block_size) 218static int indirect_bytes_number(struct item_head *ih, int block_size)
238{ 219{
239 return ih_item_len(ih) / UNFM_P_SIZE * block_size; //- get_ih_free_space (ih); 220 return ih_item_len(ih) / UNFM_P_SIZE * block_size; //- get_ih_free_space (ih);
240} 221}
241 222
242
243// decrease offset, if it becomes 0, change type to stat data 223// decrease offset, if it becomes 0, change type to stat data
244static void indirect_decrement_key (struct cpu_key * key) 224static void indirect_decrement_key(struct cpu_key *key)
245{ 225{
246 cpu_key_k_offset_dec (key); 226 cpu_key_k_offset_dec(key);
247 if (cpu_key_k_offset (key) == 0) 227 if (cpu_key_k_offset(key) == 0)
248 set_cpu_key_k_type (key, TYPE_STAT_DATA); 228 set_cpu_key_k_type(key, TYPE_STAT_DATA);
249} 229}
250 230
251
252// if it is not first item of the body, then it is mergeable 231// if it is not first item of the body, then it is mergeable
253static int indirect_is_left_mergeable (struct reiserfs_key * key, unsigned long bsize) 232static int indirect_is_left_mergeable(struct reiserfs_key *key,
233 unsigned long bsize)
254{ 234{
255 int version = le_key_version (key); 235 int version = le_key_version(key);
256 return (le_key_k_offset (version, key) != 1); 236 return (le_key_k_offset(version, key) != 1);
257} 237}
258 238
259
260// printing of indirect item 239// printing of indirect item
261static void start_new_sequence (__u32 * start, int * len, __u32 new) 240static void start_new_sequence(__u32 * start, int *len, __u32 new)
262{ 241{
263 *start = new; 242 *start = new;
264 *len = 1; 243 *len = 1;
265} 244}
266 245
267 246static int sequence_finished(__u32 start, int *len, __u32 new)
268static int sequence_finished (__u32 start, int * len, __u32 new)
269{ 247{
270 if (start == INT_MAX) 248 if (start == INT_MAX)
271 return 1; 249 return 1;
272 250
273 if (start == 0 && new == 0) { 251 if (start == 0 && new == 0) {
274 (*len) ++; 252 (*len)++;
275 return 0; 253 return 0;
276 } 254 }
277 if (start != 0 && (start + *len) == new) { 255 if (start != 0 && (start + *len) == new) {
278 (*len) ++; 256 (*len)++;
279 return 0; 257 return 0;
280 } 258 }
281 return 1; 259 return 1;
282} 260}
283 261
284static void print_sequence (__u32 start, int len) 262static void print_sequence(__u32 start, int len)
285{ 263{
286 if (start == INT_MAX) 264 if (start == INT_MAX)
287 return; 265 return;
288 266
289 if (len == 1) 267 if (len == 1)
290 printk (" %d", start); 268 printk(" %d", start);
291 else 269 else
292 printk (" %d(%d)", start, len); 270 printk(" %d(%d)", start, len);
293} 271}
294 272
295 273static void indirect_print_item(struct item_head *ih, char *item)
296static void indirect_print_item (struct item_head * ih, char * item)
297{ 274{
298 int j; 275 int j;
299 __le32 * unp; 276 __le32 *unp;
300 __u32 prev = INT_MAX; 277 __u32 prev = INT_MAX;
301 int num; 278 int num;
302 279
303 unp = (__le32 *)item; 280 unp = (__le32 *) item;
304 281
305 if (ih_item_len(ih) % UNFM_P_SIZE) 282 if (ih_item_len(ih) % UNFM_P_SIZE)
306 reiserfs_warning (NULL, "indirect_print_item: invalid item len"); 283 reiserfs_warning(NULL, "indirect_print_item: invalid item len");
307 284
308 printk ("%d pointers\n[ ", (int)I_UNFM_NUM (ih)); 285 printk("%d pointers\n[ ", (int)I_UNFM_NUM(ih));
309 for (j = 0; j < I_UNFM_NUM (ih); j ++) { 286 for (j = 0; j < I_UNFM_NUM(ih); j++) {
310 if (sequence_finished (prev, &num, get_block_num(unp, j))) { 287 if (sequence_finished(prev, &num, get_block_num(unp, j))) {
311 print_sequence (prev, num); 288 print_sequence(prev, num);
312 start_new_sequence (&prev, &num, get_block_num(unp, j)); 289 start_new_sequence(&prev, &num, get_block_num(unp, j));
290 }
313 } 291 }
314 } 292 print_sequence(prev, num);
315 print_sequence (prev, num); 293 printk("]\n");
316 printk ("]\n");
317} 294}
318 295
319static void indirect_check_item (struct item_head * ih, char * item) 296static void indirect_check_item(struct item_head *ih, char *item)
320{ 297{
321 // FIXME: type something here! 298 // FIXME: type something here!
322} 299}
323 300
324 301static int indirect_create_vi(struct virtual_node *vn,
325static int indirect_create_vi (struct virtual_node * vn, 302 struct virtual_item *vi,
326 struct virtual_item * vi, 303 int is_affected, int insert_size)
327 int is_affected,
328 int insert_size)
329{ 304{
330 vi->vi_index = TYPE_INDIRECT; 305 vi->vi_index = TYPE_INDIRECT;
331 //vi->vi_type |= VI_TYPE_INDIRECT; 306 //vi->vi_type |= VI_TYPE_INDIRECT;
332 return 0; 307 return 0;
333} 308}
334 309
335static int indirect_check_left (struct virtual_item * vi, int free, 310static int indirect_check_left(struct virtual_item *vi, int free,
336 int start_skip, int end_skip) 311 int start_skip, int end_skip)
337{ 312{
338 int bytes; 313 int bytes;
339 314
340 bytes = free - free % UNFM_P_SIZE; 315 bytes = free - free % UNFM_P_SIZE;
341 return bytes ?: -1; 316 return bytes ? : -1;
342} 317}
343 318
344 319static int indirect_check_right(struct virtual_item *vi, int free)
345static int indirect_check_right (struct virtual_item * vi, int free)
346{ 320{
347 return indirect_check_left (vi, free, 0, 0); 321 return indirect_check_left(vi, free, 0, 0);
348} 322}
349 323
350
351
352// return size in bytes of 'units' units. If first == 0 - calculate from the head (left), otherwise - from tail (right) 324// return size in bytes of 'units' units. If first == 0 - calculate from the head (left), otherwise - from tail (right)
353static int indirect_part_size (struct virtual_item * vi, int first, int units) 325static int indirect_part_size(struct virtual_item *vi, int first, int units)
354{ 326{
355 // unit of indirect item is byte (yet) 327 // unit of indirect item is byte (yet)
356 return units; 328 return units;
357} 329}
358 330
359static int indirect_unit_num (struct virtual_item * vi) 331static int indirect_unit_num(struct virtual_item *vi)
360{ 332{
361 // unit of indirect item is byte (yet) 333 // unit of indirect item is byte (yet)
362 return vi->vi_item_len - IH_SIZE; 334 return vi->vi_item_len - IH_SIZE;
363} 335}
364 336
365static void indirect_print_vi (struct virtual_item * vi) 337static void indirect_print_vi(struct virtual_item *vi)
366{ 338{
367 reiserfs_warning (NULL, "INDIRECT, index %d, type 0x%x, %h", 339 reiserfs_warning(NULL, "INDIRECT, index %d, type 0x%x, %h",
368 vi->vi_index, vi->vi_type, vi->vi_ih); 340 vi->vi_index, vi->vi_type, vi->vi_ih);
369} 341}
370 342
371static struct item_operations indirect_ops = { 343static struct item_operations indirect_ops = {
372 .bytes_number = indirect_bytes_number, 344 .bytes_number = indirect_bytes_number,
373 .decrement_key = indirect_decrement_key, 345 .decrement_key = indirect_decrement_key,
374 .is_left_mergeable = indirect_is_left_mergeable, 346 .is_left_mergeable = indirect_is_left_mergeable,
375 .print_item = indirect_print_item, 347 .print_item = indirect_print_item,
376 .check_item = indirect_check_item, 348 .check_item = indirect_check_item,
377 349
378 .create_vi = indirect_create_vi, 350 .create_vi = indirect_create_vi,
379 .check_left = indirect_check_left, 351 .check_left = indirect_check_left,
380 .check_right = indirect_check_right, 352 .check_right = indirect_check_right,
381 .part_size = indirect_part_size, 353 .part_size = indirect_part_size,
382 .unit_num = indirect_unit_num, 354 .unit_num = indirect_unit_num,
383 .print_vi = indirect_print_vi 355 .print_vi = indirect_print_vi
384}; 356};
385 357
386
387////////////////////////////////////////////////////////////////////////////// 358//////////////////////////////////////////////////////////////////////////////
388// direntry functions 359// direntry functions
389// 360//
390 361
391 362static int direntry_bytes_number(struct item_head *ih, int block_size)
392static int direntry_bytes_number (struct item_head * ih, int block_size)
393{ 363{
394 reiserfs_warning (NULL, "vs-16090: direntry_bytes_number: " 364 reiserfs_warning(NULL, "vs-16090: direntry_bytes_number: "
395 "bytes number is asked for direntry"); 365 "bytes number is asked for direntry");
396 return 0; 366 return 0;
397}
398
399static void direntry_decrement_key (struct cpu_key * key)
400{
401 cpu_key_k_offset_dec (key);
402 if (cpu_key_k_offset (key) == 0)
403 set_cpu_key_k_type (key, TYPE_STAT_DATA);
404} 367}
405 368
406 369static void direntry_decrement_key(struct cpu_key *key)
407static int direntry_is_left_mergeable (struct reiserfs_key * key, unsigned long bsize)
408{ 370{
409 if (le32_to_cpu (key->u.k_offset_v1.k_offset) == DOT_OFFSET) 371 cpu_key_k_offset_dec(key);
410 return 0; 372 if (cpu_key_k_offset(key) == 0)
411 return 1; 373 set_cpu_key_k_type(key, TYPE_STAT_DATA);
412
413} 374}
414 375
415 376static int direntry_is_left_mergeable(struct reiserfs_key *key,
416static void direntry_print_item (struct item_head * ih, char * item) 377 unsigned long bsize)
417{ 378{
418 int i; 379 if (le32_to_cpu(key->u.k_offset_v1.k_offset) == DOT_OFFSET)
419 int namelen; 380 return 0;
420 struct reiserfs_de_head * deh; 381 return 1;
421 char * name;
422 static char namebuf [80];
423
424
425 printk ("\n # %-15s%-30s%-15s%-15s%-15s\n", "Name", "Key of pointed object", "Hash", "Gen number", "Status");
426 382
427 deh = (struct reiserfs_de_head *)item; 383}
428 384
429 for (i = 0; i < I_ENTRY_COUNT (ih); i ++, deh ++) { 385static void direntry_print_item(struct item_head *ih, char *item)
430 namelen = (i ? (deh_location(deh - 1)) : ih_item_len(ih)) - deh_location(deh); 386{
431 name = item + deh_location(deh); 387 int i;
432 if (name[namelen-1] == 0) 388 int namelen;
433 namelen = strlen (name); 389 struct reiserfs_de_head *deh;
434 namebuf[0] = '"'; 390 char *name;
435 if (namelen > sizeof (namebuf) - 3) { 391 static char namebuf[80];
436 strncpy (namebuf + 1, name, sizeof (namebuf) - 3); 392
437 namebuf[sizeof (namebuf) - 2] = '"'; 393 printk("\n # %-15s%-30s%-15s%-15s%-15s\n", "Name",
438 namebuf[sizeof (namebuf) - 1] = 0; 394 "Key of pointed object", "Hash", "Gen number", "Status");
439 } else { 395
440 memcpy (namebuf + 1, name, namelen); 396 deh = (struct reiserfs_de_head *)item;
441 namebuf[namelen + 1] = '"'; 397
442 namebuf[namelen + 2] = 0; 398 for (i = 0; i < I_ENTRY_COUNT(ih); i++, deh++) {
399 namelen =
400 (i ? (deh_location(deh - 1)) : ih_item_len(ih)) -
401 deh_location(deh);
402 name = item + deh_location(deh);
403 if (name[namelen - 1] == 0)
404 namelen = strlen(name);
405 namebuf[0] = '"';
406 if (namelen > sizeof(namebuf) - 3) {
407 strncpy(namebuf + 1, name, sizeof(namebuf) - 3);
408 namebuf[sizeof(namebuf) - 2] = '"';
409 namebuf[sizeof(namebuf) - 1] = 0;
410 } else {
411 memcpy(namebuf + 1, name, namelen);
412 namebuf[namelen + 1] = '"';
413 namebuf[namelen + 2] = 0;
414 }
415
416 printk("%d: %-15s%-15d%-15d%-15Ld%-15Ld(%s)\n",
417 i, namebuf,
418 deh_dir_id(deh), deh_objectid(deh),
419 GET_HASH_VALUE(deh_offset(deh)),
420 GET_GENERATION_NUMBER((deh_offset(deh))),
421 (de_hidden(deh)) ? "HIDDEN" : "VISIBLE");
443 } 422 }
444
445 printk ("%d: %-15s%-15d%-15d%-15Ld%-15Ld(%s)\n",
446 i, namebuf,
447 deh_dir_id(deh), deh_objectid(deh),
448 GET_HASH_VALUE (deh_offset (deh)), GET_GENERATION_NUMBER ((deh_offset (deh))),
449 (de_hidden (deh)) ? "HIDDEN" : "VISIBLE");
450 }
451} 423}
452 424
453 425static void direntry_check_item(struct item_head *ih, char *item)
454static void direntry_check_item (struct item_head * ih, char * item)
455{ 426{
456 int i; 427 int i;
457 struct reiserfs_de_head * deh; 428 struct reiserfs_de_head *deh;
458 429
459 // FIXME: type something here! 430 // FIXME: type something here!
460 deh = (struct reiserfs_de_head *)item; 431 deh = (struct reiserfs_de_head *)item;
461 for (i = 0; i < I_ENTRY_COUNT (ih); i ++, deh ++) { 432 for (i = 0; i < I_ENTRY_COUNT(ih); i++, deh++) {
462 ; 433 ;
463 } 434 }
464} 435}
465 436
466
467
468#define DIRENTRY_VI_FIRST_DIRENTRY_ITEM 1 437#define DIRENTRY_VI_FIRST_DIRENTRY_ITEM 1
469 438
470/* 439/*
471 * function returns old entry number in directory item in real node 440 * function returns old entry number in directory item in real node
472 * using new entry number in virtual item in virtual node */ 441 * using new entry number in virtual item in virtual node */
473static inline int old_entry_num (int is_affected, int virtual_entry_num, int pos_in_item, int mode) 442static inline int old_entry_num(int is_affected, int virtual_entry_num,
443 int pos_in_item, int mode)
474{ 444{
475 if ( mode == M_INSERT || mode == M_DELETE) 445 if (mode == M_INSERT || mode == M_DELETE)
476 return virtual_entry_num; 446 return virtual_entry_num;
477
478 if (!is_affected)
479 /* cut or paste is applied to another item */
480 return virtual_entry_num;
481
482 if (virtual_entry_num < pos_in_item)
483 return virtual_entry_num;
484 447
485 if (mode == M_CUT) 448 if (!is_affected)
486 return virtual_entry_num + 1; 449 /* cut or paste is applied to another item */
450 return virtual_entry_num;
487 451
488 RFALSE( mode != M_PASTE || virtual_entry_num == 0, 452 if (virtual_entry_num < pos_in_item)
489 "vs-8015: old_entry_num: mode must be M_PASTE (mode = \'%c\'", mode); 453 return virtual_entry_num;
490
491 return virtual_entry_num - 1;
492}
493 454
455 if (mode == M_CUT)
456 return virtual_entry_num + 1;
494 457
458 RFALSE(mode != M_PASTE || virtual_entry_num == 0,
459 "vs-8015: old_entry_num: mode must be M_PASTE (mode = \'%c\'",
460 mode);
495 461
462 return virtual_entry_num - 1;
463}
496 464
497/* Create an array of sizes of directory entries for virtual 465/* Create an array of sizes of directory entries for virtual
498 item. Return space used by an item. FIXME: no control over 466 item. Return space used by an item. FIXME: no control over
499 consuming of space used by this item handler */ 467 consuming of space used by this item handler */
500static int direntry_create_vi (struct virtual_node * vn, 468static int direntry_create_vi(struct virtual_node *vn,
501 struct virtual_item * vi, 469 struct virtual_item *vi,
502 int is_affected, 470 int is_affected, int insert_size)
503 int insert_size) 471{
504{ 472 struct direntry_uarea *dir_u = vi->vi_uarea;
505 struct direntry_uarea * dir_u = vi->vi_uarea; 473 int i, j;
506 int i, j; 474 int size = sizeof(struct direntry_uarea);
507 int size = sizeof (struct direntry_uarea); 475 struct reiserfs_de_head *deh;
508 struct reiserfs_de_head * deh;
509
510 vi->vi_index = TYPE_DIRENTRY;
511
512 if (!(vi->vi_ih) || !vi->vi_item)
513 BUG ();
514
515
516 dir_u->flags = 0;
517 if (le_ih_k_offset (vi->vi_ih) == DOT_OFFSET)
518 dir_u->flags |= DIRENTRY_VI_FIRST_DIRENTRY_ITEM;
519
520 deh = (struct reiserfs_de_head *)(vi->vi_item);
521
522
523 /* virtual directory item have this amount of entry after */
524 dir_u->entry_count = ih_entry_count (vi->vi_ih) +
525 ((is_affected) ? ((vn->vn_mode == M_CUT) ? -1 :
526 (vn->vn_mode == M_PASTE ? 1 : 0)) : 0);
527
528 for (i = 0; i < dir_u->entry_count; i ++) {
529 j = old_entry_num (is_affected, i, vn->vn_pos_in_item, vn->vn_mode);
530 dir_u->entry_sizes[i] = (j ? deh_location( &(deh[j - 1]) ) :
531 ih_item_len (vi->vi_ih)) -
532 deh_location( &(deh[j])) + DEH_SIZE;
533 }
534
535 size += (dir_u->entry_count * sizeof (short));
536
537 /* set size of pasted entry */
538 if (is_affected && vn->vn_mode == M_PASTE)
539 dir_u->entry_sizes[vn->vn_pos_in_item] = insert_size;
540 476
477 vi->vi_index = TYPE_DIRENTRY;
478
479 if (!(vi->vi_ih) || !vi->vi_item)
480 BUG();
481
482 dir_u->flags = 0;
483 if (le_ih_k_offset(vi->vi_ih) == DOT_OFFSET)
484 dir_u->flags |= DIRENTRY_VI_FIRST_DIRENTRY_ITEM;
485
486 deh = (struct reiserfs_de_head *)(vi->vi_item);
487
488 /* virtual directory item have this amount of entry after */
489 dir_u->entry_count = ih_entry_count(vi->vi_ih) +
490 ((is_affected) ? ((vn->vn_mode == M_CUT) ? -1 :
491 (vn->vn_mode == M_PASTE ? 1 : 0)) : 0);
492
493 for (i = 0; i < dir_u->entry_count; i++) {
494 j = old_entry_num(is_affected, i, vn->vn_pos_in_item,
495 vn->vn_mode);
496 dir_u->entry_sizes[i] =
497 (j ? deh_location(&(deh[j - 1])) : ih_item_len(vi->vi_ih)) -
498 deh_location(&(deh[j])) + DEH_SIZE;
499 }
500
501 size += (dir_u->entry_count * sizeof(short));
502
503 /* set size of pasted entry */
504 if (is_affected && vn->vn_mode == M_PASTE)
505 dir_u->entry_sizes[vn->vn_pos_in_item] = insert_size;
541 506
542#ifdef CONFIG_REISERFS_CHECK 507#ifdef CONFIG_REISERFS_CHECK
543 /* compare total size of entries with item length */ 508 /* compare total size of entries with item length */
544 { 509 {
545 int k, l; 510 int k, l;
546 511
547 l = 0; 512 l = 0;
548 for (k = 0; k < dir_u->entry_count; k ++) 513 for (k = 0; k < dir_u->entry_count; k++)
549 l += dir_u->entry_sizes[k]; 514 l += dir_u->entry_sizes[k];
550 515
551 if (l + IH_SIZE != vi->vi_item_len + 516 if (l + IH_SIZE != vi->vi_item_len +
552 ((is_affected && (vn->vn_mode == M_PASTE || vn->vn_mode == M_CUT)) ? insert_size : 0) ) { 517 ((is_affected
553 reiserfs_panic (NULL, "vs-8025: set_entry_sizes: (mode==%c, insert_size==%d), invalid length of directory item", 518 && (vn->vn_mode == M_PASTE
554 vn->vn_mode, insert_size); 519 || vn->vn_mode == M_CUT)) ? insert_size : 0)) {
520 reiserfs_panic(NULL,
521 "vs-8025: set_entry_sizes: (mode==%c, insert_size==%d), invalid length of directory item",
522 vn->vn_mode, insert_size);
523 }
555 } 524 }
556 }
557#endif 525#endif
558 526
559 return size; 527 return size;
560
561 528
562} 529}
563 530
564
565// 531//
566// return number of entries which may fit into specified amount of 532// return number of entries which may fit into specified amount of
567// free space, or -1 if free space is not enough even for 1 entry 533// free space, or -1 if free space is not enough even for 1 entry
568// 534//
569static int direntry_check_left (struct virtual_item * vi, int free, 535static int direntry_check_left(struct virtual_item *vi, int free,
570 int start_skip, int end_skip) 536 int start_skip, int end_skip)
571{ 537{
572 int i; 538 int i;
573 int entries = 0; 539 int entries = 0;
574 struct direntry_uarea * dir_u = vi->vi_uarea; 540 struct direntry_uarea *dir_u = vi->vi_uarea;
575 541
576 for (i = start_skip; i < dir_u->entry_count - end_skip; i ++) { 542 for (i = start_skip; i < dir_u->entry_count - end_skip; i++) {
577 if (dir_u->entry_sizes[i] > free) 543 if (dir_u->entry_sizes[i] > free)
578 /* i-th entry doesn't fit into the remaining free space */ 544 /* i-th entry doesn't fit into the remaining free space */
579 break; 545 break;
580
581 free -= dir_u->entry_sizes[i];
582 entries ++;
583 }
584 546
585 if (entries == dir_u->entry_count) { 547 free -= dir_u->entry_sizes[i];
586 reiserfs_panic (NULL, "free space %d, entry_count %d\n", free, dir_u->entry_count); 548 entries++;
587 } 549 }
588 550
589 /* "." and ".." can not be separated from each other */ 551 if (entries == dir_u->entry_count) {
590 if (start_skip == 0 && (dir_u->flags & DIRENTRY_VI_FIRST_DIRENTRY_ITEM) && entries < 2) 552 reiserfs_panic(NULL, "free space %d, entry_count %d\n", free,
591 entries = 0; 553 dir_u->entry_count);
592 554 }
593 return entries ?: -1;
594}
595 555
556 /* "." and ".." can not be separated from each other */
557 if (start_skip == 0 && (dir_u->flags & DIRENTRY_VI_FIRST_DIRENTRY_ITEM)
558 && entries < 2)
559 entries = 0;
596 560
597static int direntry_check_right (struct virtual_item * vi, int free) 561 return entries ? : -1;
562}
563
564static int direntry_check_right(struct virtual_item *vi, int free)
598{ 565{
599 int i; 566 int i;
600 int entries = 0; 567 int entries = 0;
601 struct direntry_uarea * dir_u = vi->vi_uarea; 568 struct direntry_uarea *dir_u = vi->vi_uarea;
602
603 for (i = dir_u->entry_count - 1; i >= 0; i --) {
604 if (dir_u->entry_sizes[i] > free)
605 /* i-th entry doesn't fit into the remaining free space */
606 break;
607
608 free -= dir_u->entry_sizes[i];
609 entries ++;
610 }
611 if (entries == dir_u->entry_count)
612 BUG ();
613 569
614 /* "." and ".." can not be separated from each other */ 570 for (i = dir_u->entry_count - 1; i >= 0; i--) {
615 if ((dir_u->flags & DIRENTRY_VI_FIRST_DIRENTRY_ITEM) && entries > dir_u->entry_count - 2) 571 if (dir_u->entry_sizes[i] > free)
616 entries = dir_u->entry_count - 2; 572 /* i-th entry doesn't fit into the remaining free space */
573 break;
617 574
618 return entries ?: -1; 575 free -= dir_u->entry_sizes[i];
619} 576 entries++;
577 }
578 if (entries == dir_u->entry_count)
579 BUG();
620 580
581 /* "." and ".." can not be separated from each other */
582 if ((dir_u->flags & DIRENTRY_VI_FIRST_DIRENTRY_ITEM)
583 && entries > dir_u->entry_count - 2)
584 entries = dir_u->entry_count - 2;
585
586 return entries ? : -1;
587}
621 588
622/* sum of entry sizes between from-th and to-th entries including both edges */ 589/* sum of entry sizes between from-th and to-th entries including both edges */
623static int direntry_part_size (struct virtual_item * vi, int first, int count) 590static int direntry_part_size(struct virtual_item *vi, int first, int count)
624{ 591{
625 int i, retval; 592 int i, retval;
626 int from, to; 593 int from, to;
627 struct direntry_uarea * dir_u = vi->vi_uarea; 594 struct direntry_uarea *dir_u = vi->vi_uarea;
628
629 retval = 0;
630 if (first == 0)
631 from = 0;
632 else
633 from = dir_u->entry_count - count;
634 to = from + count - 1;
635 595
636 for (i = from; i <= to; i ++) 596 retval = 0;
637 retval += dir_u->entry_sizes[i]; 597 if (first == 0)
598 from = 0;
599 else
600 from = dir_u->entry_count - count;
601 to = from + count - 1;
638 602
639 return retval; 603 for (i = from; i <= to; i++)
640} 604 retval += dir_u->entry_sizes[i];
641 605
642static int direntry_unit_num (struct virtual_item * vi) 606 return retval;
643{
644 struct direntry_uarea * dir_u = vi->vi_uarea;
645
646 return dir_u->entry_count;
647} 607}
648 608
609static int direntry_unit_num(struct virtual_item *vi)
610{
611 struct direntry_uarea *dir_u = vi->vi_uarea;
649 612
613 return dir_u->entry_count;
614}
650 615
651static void direntry_print_vi (struct virtual_item * vi) 616static void direntry_print_vi(struct virtual_item *vi)
652{ 617{
653 int i; 618 int i;
654 struct direntry_uarea * dir_u = vi->vi_uarea; 619 struct direntry_uarea *dir_u = vi->vi_uarea;
655 620
656 reiserfs_warning (NULL, "DIRENTRY, index %d, type 0x%x, %h, flags 0x%x", 621 reiserfs_warning(NULL, "DIRENTRY, index %d, type 0x%x, %h, flags 0x%x",
657 vi->vi_index, vi->vi_type, vi->vi_ih, dir_u->flags); 622 vi->vi_index, vi->vi_type, vi->vi_ih, dir_u->flags);
658 printk ("%d entries: ", dir_u->entry_count); 623 printk("%d entries: ", dir_u->entry_count);
659 for (i = 0; i < dir_u->entry_count; i ++) 624 for (i = 0; i < dir_u->entry_count; i++)
660 printk ("%d ", dir_u->entry_sizes[i]); 625 printk("%d ", dir_u->entry_sizes[i]);
661 printk ("\n"); 626 printk("\n");
662} 627}
663 628
664static struct item_operations direntry_ops = { 629static struct item_operations direntry_ops = {
665 .bytes_number = direntry_bytes_number, 630 .bytes_number = direntry_bytes_number,
666 .decrement_key = direntry_decrement_key, 631 .decrement_key = direntry_decrement_key,
667 .is_left_mergeable = direntry_is_left_mergeable, 632 .is_left_mergeable = direntry_is_left_mergeable,
668 .print_item = direntry_print_item, 633 .print_item = direntry_print_item,
669 .check_item = direntry_check_item, 634 .check_item = direntry_check_item,
670 635
671 .create_vi = direntry_create_vi, 636 .create_vi = direntry_create_vi,
672 .check_left = direntry_check_left, 637 .check_left = direntry_check_left,
673 .check_right = direntry_check_right, 638 .check_right = direntry_check_right,
674 .part_size = direntry_part_size, 639 .part_size = direntry_part_size,
675 .unit_num = direntry_unit_num, 640 .unit_num = direntry_unit_num,
676 .print_vi = direntry_print_vi 641 .print_vi = direntry_print_vi
677}; 642};
678 643
679
680////////////////////////////////////////////////////////////////////////////// 644//////////////////////////////////////////////////////////////////////////////
681// Error catching functions to catch errors caused by incorrect item types. 645// Error catching functions to catch errors caused by incorrect item types.
682// 646//
683static int errcatch_bytes_number (struct item_head * ih, int block_size) 647static int errcatch_bytes_number(struct item_head *ih, int block_size)
684{ 648{
685 reiserfs_warning (NULL, "green-16001: Invalid item type observed, run fsck ASAP"); 649 reiserfs_warning(NULL,
686 return 0; 650 "green-16001: Invalid item type observed, run fsck ASAP");
651 return 0;
687} 652}
688 653
689static void errcatch_decrement_key (struct cpu_key * key) 654static void errcatch_decrement_key(struct cpu_key *key)
690{ 655{
691 reiserfs_warning (NULL, "green-16002: Invalid item type observed, run fsck ASAP"); 656 reiserfs_warning(NULL,
657 "green-16002: Invalid item type observed, run fsck ASAP");
692} 658}
693 659
694 660static int errcatch_is_left_mergeable(struct reiserfs_key *key,
695static int errcatch_is_left_mergeable (struct reiserfs_key * key, unsigned long bsize) 661 unsigned long bsize)
696{ 662{
697 reiserfs_warning (NULL, "green-16003: Invalid item type observed, run fsck ASAP"); 663 reiserfs_warning(NULL,
698 return 0; 664 "green-16003: Invalid item type observed, run fsck ASAP");
665 return 0;
699} 666}
700 667
701 668static void errcatch_print_item(struct item_head *ih, char *item)
702static void errcatch_print_item (struct item_head * ih, char * item)
703{ 669{
704 reiserfs_warning (NULL, "green-16004: Invalid item type observed, run fsck ASAP"); 670 reiserfs_warning(NULL,
671 "green-16004: Invalid item type observed, run fsck ASAP");
705} 672}
706 673
707 674static void errcatch_check_item(struct item_head *ih, char *item)
708static void errcatch_check_item (struct item_head * ih, char * item)
709{ 675{
710 reiserfs_warning (NULL, "green-16005: Invalid item type observed, run fsck ASAP"); 676 reiserfs_warning(NULL,
677 "green-16005: Invalid item type observed, run fsck ASAP");
711} 678}
712 679
713static int errcatch_create_vi (struct virtual_node * vn, 680static int errcatch_create_vi(struct virtual_node *vn,
714 struct virtual_item * vi, 681 struct virtual_item *vi,
715 int is_affected, 682 int is_affected, int insert_size)
716 int insert_size)
717{ 683{
718 reiserfs_warning (NULL, "green-16006: Invalid item type observed, run fsck ASAP"); 684 reiserfs_warning(NULL,
719 return 0; // We might return -1 here as well, but it won't help as create_virtual_node() from where 685 "green-16006: Invalid item type observed, run fsck ASAP");
720 // this operation is called from is of return type void. 686 return 0; // We might return -1 here as well, but it won't help as create_virtual_node() from where
687 // this operation is called from is of return type void.
721} 688}
722 689
723static int errcatch_check_left (struct virtual_item * vi, int free, 690static int errcatch_check_left(struct virtual_item *vi, int free,
724 int start_skip, int end_skip) 691 int start_skip, int end_skip)
725{ 692{
726 reiserfs_warning (NULL, "green-16007: Invalid item type observed, run fsck ASAP"); 693 reiserfs_warning(NULL,
727 return -1; 694 "green-16007: Invalid item type observed, run fsck ASAP");
695 return -1;
728} 696}
729 697
730 698static int errcatch_check_right(struct virtual_item *vi, int free)
731static int errcatch_check_right (struct virtual_item * vi, int free)
732{ 699{
733 reiserfs_warning (NULL, "green-16008: Invalid item type observed, run fsck ASAP"); 700 reiserfs_warning(NULL,
734 return -1; 701 "green-16008: Invalid item type observed, run fsck ASAP");
702 return -1;
735} 703}
736 704
737static int errcatch_part_size (struct virtual_item * vi, int first, int count) 705static int errcatch_part_size(struct virtual_item *vi, int first, int count)
738{ 706{
739 reiserfs_warning (NULL, "green-16009: Invalid item type observed, run fsck ASAP"); 707 reiserfs_warning(NULL,
740 return 0; 708 "green-16009: Invalid item type observed, run fsck ASAP");
709 return 0;
741} 710}
742 711
743static int errcatch_unit_num (struct virtual_item * vi) 712static int errcatch_unit_num(struct virtual_item *vi)
744{ 713{
745 reiserfs_warning (NULL, "green-16010: Invalid item type observed, run fsck ASAP"); 714 reiserfs_warning(NULL,
746 return 0; 715 "green-16010: Invalid item type observed, run fsck ASAP");
716 return 0;
747} 717}
748 718
749static void errcatch_print_vi (struct virtual_item * vi) 719static void errcatch_print_vi(struct virtual_item *vi)
750{ 720{
751 reiserfs_warning (NULL, "green-16011: Invalid item type observed, run fsck ASAP"); 721 reiserfs_warning(NULL,
722 "green-16011: Invalid item type observed, run fsck ASAP");
752} 723}
753 724
754static struct item_operations errcatch_ops = { 725static struct item_operations errcatch_ops = {
755 errcatch_bytes_number, 726 errcatch_bytes_number,
756 errcatch_decrement_key, 727 errcatch_decrement_key,
757 errcatch_is_left_mergeable, 728 errcatch_is_left_mergeable,
758 errcatch_print_item, 729 errcatch_print_item,
759 errcatch_check_item, 730 errcatch_check_item,
760 731
761 errcatch_create_vi, 732 errcatch_create_vi,
762 errcatch_check_left, 733 errcatch_check_left,
763 errcatch_check_right, 734 errcatch_check_right,
764 errcatch_part_size, 735 errcatch_part_size,
765 errcatch_unit_num, 736 errcatch_unit_num,
766 errcatch_print_vi 737 errcatch_print_vi
767}; 738};
768 739
769
770
771////////////////////////////////////////////////////////////////////////////// 740//////////////////////////////////////////////////////////////////////////////
772// 741//
773// 742//
@@ -775,15 +744,11 @@ static struct item_operations errcatch_ops = {
775#error Item types must use disk-format assigned values. 744#error Item types must use disk-format assigned values.
776#endif 745#endif
777 746
778struct item_operations * item_ops [TYPE_ANY + 1] = { 747struct item_operations *item_ops[TYPE_ANY + 1] = {
779 &stat_data_ops, 748 &stat_data_ops,
780 &indirect_ops, 749 &indirect_ops,
781 &direct_ops, 750 &direct_ops,
782 &direntry_ops, 751 &direntry_ops,
783 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 752 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
784 &errcatch_ops /* This is to catch errors with invalid type (15th entry for TYPE_ANY) */ 753 &errcatch_ops /* This is to catch errors with invalid type (15th entry for TYPE_ANY) */
785}; 754};
786
787
788
789