summaryrefslogtreecommitdiffstats
path: root/fs/reiserfs/lbalance.c
diff options
context:
space:
mode:
authorJeff Mahoney <jeffm@suse.com>2014-04-23 10:00:36 -0400
committerJan Kara <jack@suse.cz>2014-05-06 16:52:19 -0400
commit098297b27d23ad9d0fc302e3417474d9342c6c14 (patch)
tree58f2054cd9933225ef1ae9c7febedc9160041af6 /fs/reiserfs/lbalance.c
parent4cf5f7addf18ecae2ea49b11944976cbd26d5281 (diff)
reiserfs: cleanup, reformat comments to normal kernel style
This patch reformats comments in the reiserfs code to fit in 80 columns and to follow the style rules. There is no functional change but it helps make my eyes bleed less. Signed-off-by: Jeff Mahoney <jeffm@suse.com> Signed-off-by: Jan Kara <jack@suse.cz>
Diffstat (limited to 'fs/reiserfs/lbalance.c')
-rw-r--r--fs/reiserfs/lbalance.c349
1 files changed, 232 insertions, 117 deletions
diff --git a/fs/reiserfs/lbalance.c b/fs/reiserfs/lbalance.c
index b46399d98f84..d48a9e7507a1 100644
--- a/fs/reiserfs/lbalance.c
+++ b/fs/reiserfs/lbalance.c
@@ -8,28 +8,21 @@
8#include "reiserfs.h" 8#include "reiserfs.h"
9#include <linux/buffer_head.h> 9#include <linux/buffer_head.h>
10 10
11/* these are used in do_balance.c */ 11/*
12 12 * copy copy_count entries from source directory item to dest buffer
13/* leaf_move_items 13 * (creating new item if needed)
14 leaf_shift_left 14 */
15 leaf_shift_right
16 leaf_delete_items
17 leaf_insert_into_buf
18 leaf_paste_in_buffer
19 leaf_cut_from_buffer
20 leaf_paste_entries
21 */
22
23/* copy copy_count entries from source directory item to dest buffer (creating new item if needed) */
24static void leaf_copy_dir_entries(struct buffer_info *dest_bi, 15static void leaf_copy_dir_entries(struct buffer_info *dest_bi,
25 struct buffer_head *source, int last_first, 16 struct buffer_head *source, int last_first,
26 int item_num, int from, int copy_count) 17 int item_num, int from, int copy_count)
27{ 18{
28 struct buffer_head *dest = dest_bi->bi_bh; 19 struct buffer_head *dest = dest_bi->bi_bh;
29 int item_num_in_dest; /* either the number of target item, 20 /*
30 or if we must create a new item, 21 * either the number of target item, or if we must create a
31 the number of the item we will 22 * new item, the number of the item we will create it next to
32 create it next to */ 23 */
24 int item_num_in_dest;
25
33 struct item_head *ih; 26 struct item_head *ih;
34 struct reiserfs_de_head *deh; 27 struct reiserfs_de_head *deh;
35 int copy_records_len; /* length of all records in item to be copied */ 28 int copy_records_len; /* length of all records in item to be copied */
@@ -39,7 +32,10 @@ static void leaf_copy_dir_entries(struct buffer_info *dest_bi,
39 32
40 RFALSE(!is_direntry_le_ih(ih), "vs-10000: item must be directory item"); 33 RFALSE(!is_direntry_le_ih(ih), "vs-10000: item must be directory item");
41 34
42 /* length of all record to be copied and first byte of the last of them */ 35 /*
36 * length of all record to be copied and first byte of
37 * the last of them
38 */
43 deh = B_I_DEH(source, ih); 39 deh = B_I_DEH(source, ih);
44 if (copy_count) { 40 if (copy_count) {
45 copy_records_len = (from ? deh_location(&(deh[from - 1])) : 41 copy_records_len = (from ? deh_location(&(deh[from - 1])) :
@@ -59,7 +55,10 @@ static void leaf_copy_dir_entries(struct buffer_info *dest_bi,
59 LAST_TO_FIRST) ? ((B_NR_ITEMS(dest)) ? 0 : -1) : (B_NR_ITEMS(dest) 55 LAST_TO_FIRST) ? ((B_NR_ITEMS(dest)) ? 0 : -1) : (B_NR_ITEMS(dest)
60 - 1); 56 - 1);
61 57
62 /* if there are no items in dest or the first/last item in dest is not item of the same directory */ 58 /*
59 * if there are no items in dest or the first/last item in
60 * dest is not item of the same directory
61 */
63 if ((item_num_in_dest == -1) || 62 if ((item_num_in_dest == -1) ||
64 (last_first == FIRST_TO_LAST && le_ih_k_offset(ih) == DOT_OFFSET) || 63 (last_first == FIRST_TO_LAST && le_ih_k_offset(ih) == DOT_OFFSET) ||
65 (last_first == LAST_TO_FIRST 64 (last_first == LAST_TO_FIRST
@@ -83,11 +82,17 @@ static void leaf_copy_dir_entries(struct buffer_info *dest_bi,
83 if (from < ih_entry_count(ih)) { 82 if (from < ih_entry_count(ih)) {
84 set_le_ih_k_offset(&new_ih, 83 set_le_ih_k_offset(&new_ih,
85 deh_offset(&(deh[from]))); 84 deh_offset(&(deh[from])));
86 /*memcpy (&new_ih.ih_key.k_offset, &deh[from].deh_offset, SHORT_KEY_SIZE); */
87 } else { 85 } else {
88 /* no entries will be copied to this item in this function */ 86 /*
87 * no entries will be copied to this
88 * item in this function
89 */
89 set_le_ih_k_offset(&new_ih, U32_MAX); 90 set_le_ih_k_offset(&new_ih, U32_MAX);
90 /* this item is not yet valid, but we want I_IS_DIRECTORY_ITEM to return 1 for it, so we -1 */ 91 /*
92 * this item is not yet valid, but we
93 * want I_IS_DIRECTORY_ITEM to return 1
94 * for it, so we -1
95 */
91 } 96 }
92 set_le_key_k_type(KEY_FORMAT_3_5, &(new_ih.ih_key), 97 set_le_key_k_type(KEY_FORMAT_3_5, &(new_ih.ih_key),
93 TYPE_DIRENTRY); 98 TYPE_DIRENTRY);
@@ -119,30 +124,38 @@ static void leaf_copy_dir_entries(struct buffer_info *dest_bi,
119 DEH_SIZE * copy_count + copy_records_len); 124 DEH_SIZE * copy_count + copy_records_len);
120} 125}
121 126
122/* Copy the first (if last_first == FIRST_TO_LAST) or last (last_first == LAST_TO_FIRST) item or 127/*
123 part of it or nothing (see the return 0 below) from SOURCE to the end 128 * Copy the first (if last_first == FIRST_TO_LAST) or last
124 (if last_first) or beginning (!last_first) of the DEST */ 129 * (last_first == LAST_TO_FIRST) item or part of it or nothing
130 * (see the return 0 below) from SOURCE to the end (if last_first)
131 * or beginning (!last_first) of the DEST
132 */
125/* returns 1 if anything was copied, else 0 */ 133/* returns 1 if anything was copied, else 0 */
126static int leaf_copy_boundary_item(struct buffer_info *dest_bi, 134static int leaf_copy_boundary_item(struct buffer_info *dest_bi,
127 struct buffer_head *src, int last_first, 135 struct buffer_head *src, int last_first,
128 int bytes_or_entries) 136 int bytes_or_entries)
129{ 137{
130 struct buffer_head *dest = dest_bi->bi_bh; 138 struct buffer_head *dest = dest_bi->bi_bh;
131 int dest_nr_item, src_nr_item; /* number of items in the source and destination buffers */ 139 /* number of items in the source and destination buffers */
140 int dest_nr_item, src_nr_item;
132 struct item_head *ih; 141 struct item_head *ih;
133 struct item_head *dih; 142 struct item_head *dih;
134 143
135 dest_nr_item = B_NR_ITEMS(dest); 144 dest_nr_item = B_NR_ITEMS(dest);
136 145
146 /*
147 * if ( DEST is empty or first item of SOURCE and last item of
148 * DEST are the items of different objects or of different types )
149 * then there is no need to treat this item differently from the
150 * other items that we copy, so we return
151 */
137 if (last_first == FIRST_TO_LAST) { 152 if (last_first == FIRST_TO_LAST) {
138 /* if ( DEST is empty or first item of SOURCE and last item of DEST are the items of different objects
139 or of different types ) then there is no need to treat this item differently from the other items
140 that we copy, so we return */
141 ih = item_head(src, 0); 153 ih = item_head(src, 0);
142 dih = item_head(dest, dest_nr_item - 1); 154 dih = item_head(dest, dest_nr_item - 1);
155
156 /* there is nothing to merge */
143 if (!dest_nr_item 157 if (!dest_nr_item
144 || (!op_is_left_mergeable(&(ih->ih_key), src->b_size))) 158 || (!op_is_left_mergeable(&(ih->ih_key), src->b_size)))
145 /* there is nothing to merge */
146 return 0; 159 return 0;
147 160
148 RFALSE(!ih_item_len(ih), 161 RFALSE(!ih_item_len(ih),
@@ -157,8 +170,11 @@ static int leaf_copy_boundary_item(struct buffer_info *dest_bi,
157 return 1; 170 return 1;
158 } 171 }
159 172
160 /* copy part of the body of the first item of SOURCE to the end of the body of the last item of the DEST 173 /*
161 part defined by 'bytes_or_entries'; if bytes_or_entries == -1 copy whole body; don't create new item header 174 * copy part of the body of the first item of SOURCE
175 * to the end of the body of the last item of the DEST
176 * part defined by 'bytes_or_entries'; if bytes_or_entries
177 * == -1 copy whole body; don't create new item header
162 */ 178 */
163 if (bytes_or_entries == -1) 179 if (bytes_or_entries == -1)
164 bytes_or_entries = ih_item_len(ih); 180 bytes_or_entries = ih_item_len(ih);
@@ -176,8 +192,10 @@ static int leaf_copy_boundary_item(struct buffer_info *dest_bi,
176 } 192 }
177#endif 193#endif
178 194
179 /* merge first item (or its part) of src buffer with the last 195 /*
180 item of dest buffer. Both are of the same file */ 196 * merge first item (or its part) of src buffer with the last
197 * item of dest buffer. Both are of the same file
198 */
181 leaf_paste_in_buffer(dest_bi, 199 leaf_paste_in_buffer(dest_bi,
182 dest_nr_item - 1, ih_item_len(dih), 200 dest_nr_item - 1, ih_item_len(dih),
183 bytes_or_entries, ih_item_body(src, ih), 0); 201 bytes_or_entries, ih_item_body(src, ih), 0);
@@ -195,8 +213,9 @@ static int leaf_copy_boundary_item(struct buffer_info *dest_bi,
195 213
196 /* copy boundary item to right (last_first == LAST_TO_FIRST) */ 214 /* copy boundary item to right (last_first == LAST_TO_FIRST) */
197 215
198 /* ( DEST is empty or last item of SOURCE and first item of DEST 216 /*
199 are the items of different object or of different types ) 217 * (DEST is empty or last item of SOURCE and first item of DEST
218 * are the items of different object or of different types)
200 */ 219 */
201 src_nr_item = B_NR_ITEMS(src); 220 src_nr_item = B_NR_ITEMS(src);
202 ih = item_head(src, src_nr_item - 1); 221 ih = item_head(src, src_nr_item - 1);
@@ -206,8 +225,11 @@ static int leaf_copy_boundary_item(struct buffer_info *dest_bi,
206 return 0; 225 return 0;
207 226
208 if (is_direntry_le_ih(ih)) { 227 if (is_direntry_le_ih(ih)) {
228 /*
229 * bytes_or_entries = entries number in last
230 * item body of SOURCE
231 */
209 if (bytes_or_entries == -1) 232 if (bytes_or_entries == -1)
210 /* bytes_or_entries = entries number in last item body of SOURCE */
211 bytes_or_entries = ih_entry_count(ih); 233 bytes_or_entries = ih_entry_count(ih);
212 234
213 leaf_copy_dir_entries(dest_bi, src, LAST_TO_FIRST, 235 leaf_copy_dir_entries(dest_bi, src, LAST_TO_FIRST,
@@ -217,9 +239,11 @@ static int leaf_copy_boundary_item(struct buffer_info *dest_bi,
217 return 1; 239 return 1;
218 } 240 }
219 241
220 /* copy part of the body of the last item of SOURCE to the begin of the body of the first item of the DEST; 242 /*
221 part defined by 'bytes_or_entries'; if byte_or_entriess == -1 copy whole body; change first item key of the DEST; 243 * copy part of the body of the last item of SOURCE to the
222 don't create new item header 244 * begin of the body of the first item of the DEST; part defined
245 * by 'bytes_or_entries'; if byte_or_entriess == -1 copy whole body;
246 * change first item key of the DEST; don't create new item header
223 */ 247 */
224 248
225 RFALSE(is_indirect_le_ih(ih) && get_ih_free_space(ih), 249 RFALSE(is_indirect_le_ih(ih) && get_ih_free_space(ih),
@@ -276,9 +300,12 @@ static int leaf_copy_boundary_item(struct buffer_info *dest_bi,
276 return 1; 300 return 1;
277} 301}
278 302
279/* copy cpy_mun items from buffer src to buffer dest 303/*
280 * last_first == FIRST_TO_LAST means, that we copy cpy_num items beginning from first-th item in src to tail of dest 304 * copy cpy_mun items from buffer src to buffer dest
281 * last_first == LAST_TO_FIRST means, that we copy cpy_num items beginning from first-th item in src to head of dest 305 * last_first == FIRST_TO_LAST means, that we copy cpy_num items beginning
306 * from first-th item in src to tail of dest
307 * last_first == LAST_TO_FIRST means, that we copy cpy_num items beginning
308 * from first-th item in src to head of dest
282 */ 309 */
283static void leaf_copy_items_entirely(struct buffer_info *dest_bi, 310static void leaf_copy_items_entirely(struct buffer_info *dest_bi,
284 struct buffer_head *src, int last_first, 311 struct buffer_head *src, int last_first,
@@ -311,7 +338,10 @@ static void leaf_copy_items_entirely(struct buffer_info *dest_bi,
311 nr = blkh_nr_item(blkh); 338 nr = blkh_nr_item(blkh);
312 free_space = blkh_free_space(blkh); 339 free_space = blkh_free_space(blkh);
313 340
314 /* we will insert items before 0-th or nr-th item in dest buffer. It depends of last_first parameter */ 341 /*
342 * we will insert items before 0-th or nr-th item in dest buffer.
343 * It depends of last_first parameter
344 */
315 dest_before = (last_first == LAST_TO_FIRST) ? 0 : nr; 345 dest_before = (last_first == LAST_TO_FIRST) ? 0 : nr;
316 346
317 /* location of head of first new item */ 347 /* location of head of first new item */
@@ -377,8 +407,10 @@ static void leaf_copy_items_entirely(struct buffer_info *dest_bi,
377 } 407 }
378} 408}
379 409
380/* This function splits the (liquid) item into two items (useful when 410/*
381 shifting part of an item into another node.) */ 411 * This function splits the (liquid) item into two items (useful when
412 * shifting part of an item into another node.)
413 */
382static void leaf_item_bottle(struct buffer_info *dest_bi, 414static void leaf_item_bottle(struct buffer_info *dest_bi,
383 struct buffer_head *src, int last_first, 415 struct buffer_head *src, int last_first,
384 int item_num, int cpy_bytes) 416 int item_num, int cpy_bytes)
@@ -390,7 +422,10 @@ static void leaf_item_bottle(struct buffer_info *dest_bi,
390 "vs-10170: bytes == - 1 means: do not split item"); 422 "vs-10170: bytes == - 1 means: do not split item");
391 423
392 if (last_first == FIRST_TO_LAST) { 424 if (last_first == FIRST_TO_LAST) {
393 /* if ( if item in position item_num in buffer SOURCE is directory item ) */ 425 /*
426 * if ( if item in position item_num in buffer SOURCE
427 * is directory item )
428 */
394 ih = item_head(src, item_num); 429 ih = item_head(src, item_num);
395 if (is_direntry_le_ih(ih)) 430 if (is_direntry_le_ih(ih))
396 leaf_copy_dir_entries(dest_bi, src, FIRST_TO_LAST, 431 leaf_copy_dir_entries(dest_bi, src, FIRST_TO_LAST,
@@ -398,9 +433,11 @@ static void leaf_item_bottle(struct buffer_info *dest_bi,
398 else { 433 else {
399 struct item_head n_ih; 434 struct item_head n_ih;
400 435
401 /* copy part of the body of the item number 'item_num' of SOURCE to the end of the DEST 436 /*
402 part defined by 'cpy_bytes'; create new item header; change old item_header (????); 437 * copy part of the body of the item number 'item_num'
403 n_ih = new item_header; 438 * of SOURCE to the end of the DEST part defined by
439 * 'cpy_bytes'; create new item header; change old
440 * item_header (????); n_ih = new item_header;
404 */ 441 */
405 memcpy(&n_ih, ih, IH_SIZE); 442 memcpy(&n_ih, ih, IH_SIZE);
406 put_ih_item_len(&n_ih, cpy_bytes); 443 put_ih_item_len(&n_ih, cpy_bytes);
@@ -419,7 +456,10 @@ static void leaf_item_bottle(struct buffer_info *dest_bi,
419 item_body(src, item_num), 0); 456 item_body(src, item_num), 0);
420 } 457 }
421 } else { 458 } else {
422 /* if ( if item in position item_num in buffer SOURCE is directory item ) */ 459 /*
460 * if ( if item in position item_num in buffer
461 * SOURCE is directory item )
462 */
423 ih = item_head(src, item_num); 463 ih = item_head(src, item_num);
424 if (is_direntry_le_ih(ih)) 464 if (is_direntry_le_ih(ih))
425 leaf_copy_dir_entries(dest_bi, src, LAST_TO_FIRST, 465 leaf_copy_dir_entries(dest_bi, src, LAST_TO_FIRST,
@@ -429,13 +469,16 @@ static void leaf_item_bottle(struct buffer_info *dest_bi,
429 else { 469 else {
430 struct item_head n_ih; 470 struct item_head n_ih;
431 471
432 /* copy part of the body of the item number 'item_num' of SOURCE to the begin of the DEST 472 /*
433 part defined by 'cpy_bytes'; create new item header; 473 * copy part of the body of the item number 'item_num'
434 n_ih = new item_header; 474 * of SOURCE to the begin of the DEST part defined by
475 * 'cpy_bytes'; create new item header;
476 * n_ih = new item_header;
435 */ 477 */
436 memcpy(&n_ih, ih, SHORT_KEY_SIZE); 478 memcpy(&n_ih, ih, SHORT_KEY_SIZE);
437 479
438 n_ih.ih_version = ih->ih_version; /* JDM Endian safe, both le */ 480 /* Endian safe, both le */
481 n_ih.ih_version = ih->ih_version;
439 482
440 if (is_direct_le_ih(ih)) { 483 if (is_direct_le_ih(ih)) {
441 set_le_ih_k_offset(&n_ih, 484 set_le_ih_k_offset(&n_ih,
@@ -459,7 +502,8 @@ static void leaf_item_bottle(struct buffer_info *dest_bi,
459 /* set item length */ 502 /* set item length */
460 put_ih_item_len(&n_ih, cpy_bytes); 503 put_ih_item_len(&n_ih, cpy_bytes);
461 504
462 n_ih.ih_version = ih->ih_version; /* JDM Endian safe, both le */ 505 /* Endian safe, both le */
506 n_ih.ih_version = ih->ih_version;
463 507
464 leaf_insert_into_buf(dest_bi, 0, &n_ih, 508 leaf_insert_into_buf(dest_bi, 0, &n_ih,
465 item_body(src, item_num) + 509 item_body(src, item_num) +
@@ -468,10 +512,12 @@ static void leaf_item_bottle(struct buffer_info *dest_bi,
468 } 512 }
469} 513}
470 514
471/* If cpy_bytes equals minus one than copy cpy_num whole items from SOURCE to DEST. 515/*
472 If cpy_bytes not equal to minus one than copy cpy_num-1 whole items from SOURCE to DEST. 516 * If cpy_bytes equals minus one than copy cpy_num whole items from SOURCE
473 From last item copy cpy_num bytes for regular item and cpy_num directory entries for 517 * to DEST. If cpy_bytes not equal to minus one than copy cpy_num-1 whole
474 directory item. */ 518 * items from SOURCE to DEST. From last item copy cpy_num bytes for regular
519 * item and cpy_num directory entries for directory item.
520 */
475static int leaf_copy_items(struct buffer_info *dest_bi, struct buffer_head *src, 521static int leaf_copy_items(struct buffer_info *dest_bi, struct buffer_head *src,
476 int last_first, int cpy_num, int cpy_bytes) 522 int last_first, int cpy_num, int cpy_bytes)
477{ 523{
@@ -498,22 +544,34 @@ static int leaf_copy_items(struct buffer_info *dest_bi, struct buffer_head *src,
498 else 544 else
499 bytes = -1; 545 bytes = -1;
500 546
501 /* copy the first item or it part or nothing to the end of the DEST (i = leaf_copy_boundary_item(DEST,SOURCE,0,bytes)) */ 547 /*
548 * copy the first item or it part or nothing to the end of
549 * the DEST (i = leaf_copy_boundary_item(DEST,SOURCE,0,bytes))
550 */
502 i = leaf_copy_boundary_item(dest_bi, src, FIRST_TO_LAST, bytes); 551 i = leaf_copy_boundary_item(dest_bi, src, FIRST_TO_LAST, bytes);
503 cpy_num -= i; 552 cpy_num -= i;
504 if (cpy_num == 0) 553 if (cpy_num == 0)
505 return i; 554 return i;
506 pos += i; 555 pos += i;
507 if (cpy_bytes == -1) 556 if (cpy_bytes == -1)
508 /* copy first cpy_num items starting from position 'pos' of SOURCE to end of DEST */ 557 /*
558 * copy first cpy_num items starting from position
559 * 'pos' of SOURCE to end of DEST
560 */
509 leaf_copy_items_entirely(dest_bi, src, FIRST_TO_LAST, 561 leaf_copy_items_entirely(dest_bi, src, FIRST_TO_LAST,
510 pos, cpy_num); 562 pos, cpy_num);
511 else { 563 else {
512 /* copy first cpy_num-1 items starting from position 'pos-1' of the SOURCE to the end of the DEST */ 564 /*
565 * copy first cpy_num-1 items starting from position
566 * 'pos-1' of the SOURCE to the end of the DEST
567 */
513 leaf_copy_items_entirely(dest_bi, src, FIRST_TO_LAST, 568 leaf_copy_items_entirely(dest_bi, src, FIRST_TO_LAST,
514 pos, cpy_num - 1); 569 pos, cpy_num - 1);
515 570
516 /* copy part of the item which number is cpy_num+pos-1 to the end of the DEST */ 571 /*
572 * copy part of the item which number is
573 * cpy_num+pos-1 to the end of the DEST
574 */
517 leaf_item_bottle(dest_bi, src, FIRST_TO_LAST, 575 leaf_item_bottle(dest_bi, src, FIRST_TO_LAST,
518 cpy_num + pos - 1, cpy_bytes); 576 cpy_num + pos - 1, cpy_bytes);
519 } 577 }
@@ -525,7 +583,11 @@ static int leaf_copy_items(struct buffer_info *dest_bi, struct buffer_head *src,
525 else 583 else
526 bytes = -1; 584 bytes = -1;
527 585
528 /* copy the last item or it part or nothing to the begin of the DEST (i = leaf_copy_boundary_item(DEST,SOURCE,1,bytes)); */ 586 /*
587 * copy the last item or it part or nothing to the
588 * begin of the DEST
589 * (i = leaf_copy_boundary_item(DEST,SOURCE,1,bytes));
590 */
529 i = leaf_copy_boundary_item(dest_bi, src, LAST_TO_FIRST, bytes); 591 i = leaf_copy_boundary_item(dest_bi, src, LAST_TO_FIRST, bytes);
530 592
531 cpy_num -= i; 593 cpy_num -= i;
@@ -534,15 +596,24 @@ static int leaf_copy_items(struct buffer_info *dest_bi, struct buffer_head *src,
534 596
535 pos = src_nr_item - cpy_num - i; 597 pos = src_nr_item - cpy_num - i;
536 if (cpy_bytes == -1) { 598 if (cpy_bytes == -1) {
537 /* starting from position 'pos' copy last cpy_num items of SOURCE to begin of DEST */ 599 /*
600 * starting from position 'pos' copy last cpy_num
601 * items of SOURCE to begin of DEST
602 */
538 leaf_copy_items_entirely(dest_bi, src, LAST_TO_FIRST, 603 leaf_copy_items_entirely(dest_bi, src, LAST_TO_FIRST,
539 pos, cpy_num); 604 pos, cpy_num);
540 } else { 605 } else {
541 /* copy last cpy_num-1 items starting from position 'pos+1' of the SOURCE to the begin of the DEST; */ 606 /*
607 * copy last cpy_num-1 items starting from position
608 * 'pos+1' of the SOURCE to the begin of the DEST;
609 */
542 leaf_copy_items_entirely(dest_bi, src, LAST_TO_FIRST, 610 leaf_copy_items_entirely(dest_bi, src, LAST_TO_FIRST,
543 pos + 1, cpy_num - 1); 611 pos + 1, cpy_num - 1);
544 612
545 /* copy part of the item which number is pos to the begin of the DEST */ 613 /*
614 * copy part of the item which number is pos to
615 * the begin of the DEST
616 */
546 leaf_item_bottle(dest_bi, src, LAST_TO_FIRST, pos, 617 leaf_item_bottle(dest_bi, src, LAST_TO_FIRST, pos,
547 cpy_bytes); 618 cpy_bytes);
548 } 619 }
@@ -550,9 +621,11 @@ static int leaf_copy_items(struct buffer_info *dest_bi, struct buffer_head *src,
550 return i; 621 return i;
551} 622}
552 623
553/* there are types of coping: from S[0] to L[0], from S[0] to R[0], 624/*
554 from R[0] to L[0]. for each of these we have to define parent and 625 * there are types of coping: from S[0] to L[0], from S[0] to R[0],
555 positions of destination and source buffers */ 626 * from R[0] to L[0]. for each of these we have to define parent and
627 * positions of destination and source buffers
628 */
556static void leaf_define_dest_src_infos(int shift_mode, struct tree_balance *tb, 629static void leaf_define_dest_src_infos(int shift_mode, struct tree_balance *tb,
557 struct buffer_info *dest_bi, 630 struct buffer_info *dest_bi,
558 struct buffer_info *src_bi, 631 struct buffer_info *src_bi,
@@ -568,7 +641,9 @@ static void leaf_define_dest_src_infos(int shift_mode, struct tree_balance *tb,
568 src_bi->tb = tb; 641 src_bi->tb = tb;
569 src_bi->bi_bh = PATH_PLAST_BUFFER(tb->tb_path); 642 src_bi->bi_bh = PATH_PLAST_BUFFER(tb->tb_path);
570 src_bi->bi_parent = PATH_H_PPARENT(tb->tb_path, 0); 643 src_bi->bi_parent = PATH_H_PPARENT(tb->tb_path, 0);
571 src_bi->bi_position = PATH_H_B_ITEM_ORDER(tb->tb_path, 0); /* src->b_item_order */ 644
645 /* src->b_item_order */
646 src_bi->bi_position = PATH_H_B_ITEM_ORDER(tb->tb_path, 0);
572 dest_bi->tb = tb; 647 dest_bi->tb = tb;
573 dest_bi->bi_bh = tb->L[0]; 648 dest_bi->bi_bh = tb->L[0];
574 dest_bi->bi_parent = tb->FL[0]; 649 dest_bi->bi_parent = tb->FL[0];
@@ -633,8 +708,10 @@ static void leaf_define_dest_src_infos(int shift_mode, struct tree_balance *tb,
633 shift_mode, src_bi->bi_bh, dest_bi->bi_bh); 708 shift_mode, src_bi->bi_bh, dest_bi->bi_bh);
634} 709}
635 710
636/* copy mov_num items and mov_bytes of the (mov_num-1)th item to 711/*
637 neighbor. Delete them from source */ 712 * copy mov_num items and mov_bytes of the (mov_num-1)th item to
713 * neighbor. Delete them from source
714 */
638int leaf_move_items(int shift_mode, struct tree_balance *tb, int mov_num, 715int leaf_move_items(int shift_mode, struct tree_balance *tb, int mov_num,
639 int mov_bytes, struct buffer_head *Snew) 716 int mov_bytes, struct buffer_head *Snew)
640{ 717{
@@ -657,18 +734,24 @@ int leaf_move_items(int shift_mode, struct tree_balance *tb, int mov_num,
657 return ret_value; 734 return ret_value;
658} 735}
659 736
660/* Shift shift_num items (and shift_bytes of last shifted item if shift_bytes != -1) 737/*
661 from S[0] to L[0] and replace the delimiting key */ 738 * Shift shift_num items (and shift_bytes of last shifted item if
739 * shift_bytes != -1) from S[0] to L[0] and replace the delimiting key
740 */
662int leaf_shift_left(struct tree_balance *tb, int shift_num, int shift_bytes) 741int leaf_shift_left(struct tree_balance *tb, int shift_num, int shift_bytes)
663{ 742{
664 struct buffer_head *S0 = PATH_PLAST_BUFFER(tb->tb_path); 743 struct buffer_head *S0 = PATH_PLAST_BUFFER(tb->tb_path);
665 int i; 744 int i;
666 745
667 /* move shift_num (and shift_bytes bytes) items from S[0] to left neighbor L[0] */ 746 /*
747 * move shift_num (and shift_bytes bytes) items from S[0]
748 * to left neighbor L[0]
749 */
668 i = leaf_move_items(LEAF_FROM_S_TO_L, tb, shift_num, shift_bytes, NULL); 750 i = leaf_move_items(LEAF_FROM_S_TO_L, tb, shift_num, shift_bytes, NULL);
669 751
670 if (shift_num) { 752 if (shift_num) {
671 if (B_NR_ITEMS(S0) == 0) { /* number of items in S[0] == 0 */ 753 /* number of items in S[0] == 0 */
754 if (B_NR_ITEMS(S0) == 0) {
672 755
673 RFALSE(shift_bytes != -1, 756 RFALSE(shift_bytes != -1,
674 "vs-10270: S0 is empty now, but shift_bytes != -1 (%d)", 757 "vs-10270: S0 is empty now, but shift_bytes != -1 (%d)",
@@ -704,13 +787,18 @@ int leaf_shift_left(struct tree_balance *tb, int shift_num, int shift_bytes)
704 787
705/* CLEANING STOPPED HERE */ 788/* CLEANING STOPPED HERE */
706 789
707/* Shift shift_num (shift_bytes) items from S[0] to the right neighbor, and replace the delimiting key */ 790/*
791 * Shift shift_num (shift_bytes) items from S[0] to the right neighbor,
792 * and replace the delimiting key
793 */
708int leaf_shift_right(struct tree_balance *tb, int shift_num, int shift_bytes) 794int leaf_shift_right(struct tree_balance *tb, int shift_num, int shift_bytes)
709{ 795{
710 // struct buffer_head * S0 = PATH_PLAST_BUFFER (tb->tb_path);
711 int ret_value; 796 int ret_value;
712 797
713 /* move shift_num (and shift_bytes) items from S[0] to right neighbor R[0] */ 798 /*
799 * move shift_num (and shift_bytes) items from S[0] to
800 * right neighbor R[0]
801 */
714 ret_value = 802 ret_value =
715 leaf_move_items(LEAF_FROM_S_TO_R, tb, shift_num, shift_bytes, NULL); 803 leaf_move_items(LEAF_FROM_S_TO_R, tb, shift_num, shift_bytes, NULL);
716 804
@@ -725,12 +813,16 @@ int leaf_shift_right(struct tree_balance *tb, int shift_num, int shift_bytes)
725 813
726static void leaf_delete_items_entirely(struct buffer_info *bi, 814static void leaf_delete_items_entirely(struct buffer_info *bi,
727 int first, int del_num); 815 int first, int del_num);
728/* If del_bytes == -1, starting from position 'first' delete del_num items in whole in buffer CUR. 816/*
729 If not. 817 * If del_bytes == -1, starting from position 'first' delete del_num
730 If last_first == 0. Starting from position 'first' delete del_num-1 items in whole. Delete part of body of 818 * items in whole in buffer CUR.
731 the first item. Part defined by del_bytes. Don't delete first item header 819 * If not.
732 If last_first == 1. Starting from position 'first+1' delete del_num-1 items in whole. Delete part of body of 820 * If last_first == 0. Starting from position 'first' delete del_num-1
733 the last item . Part defined by del_bytes. Don't delete last item header. 821 * items in whole. Delete part of body of the first item. Part defined by
822 * del_bytes. Don't delete first item header
823 * If last_first == 1. Starting from position 'first+1' delete del_num-1
824 * items in whole. Delete part of body of the last item . Part defined by
825 * del_bytes. Don't delete last item header.
734*/ 826*/
735void leaf_delete_items(struct buffer_info *cur_bi, int last_first, 827void leaf_delete_items(struct buffer_info *cur_bi, int last_first,
736 int first, int del_num, int del_bytes) 828 int first, int del_num, int del_bytes)
@@ -761,32 +853,43 @@ void leaf_delete_items(struct buffer_info *cur_bi, int last_first,
761 leaf_delete_items_entirely(cur_bi, first, del_num); 853 leaf_delete_items_entirely(cur_bi, first, del_num);
762 else { 854 else {
763 if (last_first == FIRST_TO_LAST) { 855 if (last_first == FIRST_TO_LAST) {
764 /* delete del_num-1 items beginning from item in position first */ 856 /*
857 * delete del_num-1 items beginning from
858 * item in position first
859 */
765 leaf_delete_items_entirely(cur_bi, first, del_num - 1); 860 leaf_delete_items_entirely(cur_bi, first, del_num - 1);
766 861
767 /* delete the part of the first item of the bh 862 /*
768 do not delete item header 863 * delete the part of the first item of the bh
864 * do not delete item header
769 */ 865 */
770 leaf_cut_from_buffer(cur_bi, 0, 0, del_bytes); 866 leaf_cut_from_buffer(cur_bi, 0, 0, del_bytes);
771 } else { 867 } else {
772 struct item_head *ih; 868 struct item_head *ih;
773 int len; 869 int len;
774 870
775 /* delete del_num-1 items beginning from item in position first+1 */ 871 /*
872 * delete del_num-1 items beginning from
873 * item in position first+1
874 */
776 leaf_delete_items_entirely(cur_bi, first + 1, 875 leaf_delete_items_entirely(cur_bi, first + 1,
777 del_num - 1); 876 del_num - 1);
778 877
779 ih = item_head(bh, B_NR_ITEMS(bh) - 1); 878 ih = item_head(bh, B_NR_ITEMS(bh) - 1);
780 if (is_direntry_le_ih(ih)) 879 if (is_direntry_le_ih(ih))
781 /* the last item is directory */ 880 /* the last item is directory */
782 /* len = numbers of directory entries in this item */ 881 /*
882 * len = numbers of directory entries
883 * in this item
884 */
783 len = ih_entry_count(ih); 885 len = ih_entry_count(ih);
784 else 886 else
785 /* len = body len of item */ 887 /* len = body len of item */
786 len = ih_item_len(ih); 888 len = ih_item_len(ih);
787 889
788 /* delete the part of the last item of the bh 890 /*
789 do not delete item header 891 * delete the part of the last item of the bh
892 * do not delete item header
790 */ 893 */
791 leaf_cut_from_buffer(cur_bi, B_NR_ITEMS(bh) - 1, 894 leaf_cut_from_buffer(cur_bi, B_NR_ITEMS(bh) - 1,
792 len - del_bytes, del_bytes); 895 len - del_bytes, del_bytes);
@@ -867,8 +970,10 @@ void leaf_insert_into_buf(struct buffer_info *bi, int before,
867 } 970 }
868} 971}
869 972
870/* paste paste_size bytes to affected_item_num-th item. 973/*
871 When item is a directory, this only prepare space for new entries */ 974 * paste paste_size bytes to affected_item_num-th item.
975 * When item is a directory, this only prepare space for new entries
976 */
872void leaf_paste_in_buffer(struct buffer_info *bi, int affected_item_num, 977void leaf_paste_in_buffer(struct buffer_info *bi, int affected_item_num,
873 int pos_in_item, int paste_size, 978 int pos_in_item, int paste_size,
874 const char *body, int zeros_number) 979 const char *body, int zeros_number)
@@ -957,10 +1062,12 @@ void leaf_paste_in_buffer(struct buffer_info *bi, int affected_item_num,
957 } 1062 }
958} 1063}
959 1064
960/* cuts DEL_COUNT entries beginning from FROM-th entry. Directory item 1065/*
961 does not have free space, so it moves DEHs and remaining records as 1066 * cuts DEL_COUNT entries beginning from FROM-th entry. Directory item
962 necessary. Return value is size of removed part of directory item 1067 * does not have free space, so it moves DEHs and remaining records as
963 in bytes. */ 1068 * necessary. Return value is size of removed part of directory item
1069 * in bytes.
1070 */
964static int leaf_cut_entries(struct buffer_head *bh, 1071static int leaf_cut_entries(struct buffer_head *bh,
965 struct item_head *ih, int from, int del_count) 1072 struct item_head *ih, int from, int del_count)
966{ 1073{
@@ -971,8 +1078,10 @@ static int leaf_cut_entries(struct buffer_head *bh,
971 int cut_records_len; /* length of all removed records */ 1078 int cut_records_len; /* length of all removed records */
972 int i; 1079 int i;
973 1080
974 /* make sure, that item is directory and there are enough entries to 1081 /*
975 remove */ 1082 * make sure that item is directory and there are enough entries to
1083 * remove
1084 */
976 RFALSE(!is_direntry_le_ih(ih), "10180: item is not directory item"); 1085 RFALSE(!is_direntry_le_ih(ih), "10180: item is not directory item");
977 RFALSE(ih_entry_count(ih) < from + del_count, 1086 RFALSE(ih_entry_count(ih) < from + del_count,
978 "10185: item contains not enough entries: entry_count = %d, from = %d, to delete = %d", 1087 "10185: item contains not enough entries: entry_count = %d, from = %d, to delete = %d",
@@ -987,8 +1096,10 @@ static int leaf_cut_entries(struct buffer_head *bh,
987 /* entry head array */ 1096 /* entry head array */
988 deh = B_I_DEH(bh, ih); 1097 deh = B_I_DEH(bh, ih);
989 1098
990 /* first byte of remaining entries, those are BEFORE cut entries 1099 /*
991 (prev_record) and length of all removed records (cut_records_len) */ 1100 * first byte of remaining entries, those are BEFORE cut entries
1101 * (prev_record) and length of all removed records (cut_records_len)
1102 */
992 prev_record_offset = 1103 prev_record_offset =
993 (from ? deh_location(&(deh[from - 1])) : ih_item_len(ih)); 1104 (from ? deh_location(&(deh[from - 1])) : ih_item_len(ih));
994 cut_records_len = prev_record_offset /*from_record */ - 1105 cut_records_len = prev_record_offset /*from_record */ -
@@ -1021,14 +1132,15 @@ static int leaf_cut_entries(struct buffer_head *bh,
1021 return DEH_SIZE * del_count + cut_records_len; 1132 return DEH_SIZE * del_count + cut_records_len;
1022} 1133}
1023 1134
1024/* when cut item is part of regular file 1135/*
1025 pos_in_item - first byte that must be cut 1136 * when cut item is part of regular file
1026 cut_size - number of bytes to be cut beginning from pos_in_item 1137 * pos_in_item - first byte that must be cut
1027 1138 * cut_size - number of bytes to be cut beginning from pos_in_item
1028 when cut item is part of directory 1139 *
1029 pos_in_item - number of first deleted entry 1140 * when cut item is part of directory
1030 cut_size - count of deleted entries 1141 * pos_in_item - number of first deleted entry
1031 */ 1142 * cut_size - count of deleted entries
1143 */
1032void leaf_cut_from_buffer(struct buffer_info *bi, int cut_item_num, 1144void leaf_cut_from_buffer(struct buffer_info *bi, int cut_item_num,
1033 int pos_in_item, int cut_size) 1145 int pos_in_item, int cut_size)
1034{ 1146{
@@ -1055,7 +1167,6 @@ void leaf_cut_from_buffer(struct buffer_info *bi, int cut_item_num,
1055 cut_item_num); 1167 cut_item_num);
1056 /* change item key by key of first entry in the item */ 1168 /* change item key by key of first entry in the item */
1057 set_le_ih_k_offset(ih, deh_offset(B_I_DEH(bh, ih))); 1169 set_le_ih_k_offset(ih, deh_offset(B_I_DEH(bh, ih)));
1058 /*memcpy (&ih->ih_key.k_offset, &(B_I_DEH (bh, ih)->deh_offset), SHORT_KEY_SIZE); */
1059 } 1170 }
1060 } else { 1171 } else {
1061 /* item is direct or indirect */ 1172 /* item is direct or indirect */
@@ -1195,7 +1306,10 @@ static void leaf_delete_items_entirely(struct buffer_info *bi,
1195 } 1306 }
1196} 1307}
1197 1308
1198/* paste new_entry_count entries (new_dehs, records) into position before to item_num-th item */ 1309/*
1310 * paste new_entry_count entries (new_dehs, records) into position
1311 * before to item_num-th item
1312 */
1199void leaf_paste_entries(struct buffer_info *bi, 1313void leaf_paste_entries(struct buffer_info *bi,
1200 int item_num, 1314 int item_num,
1201 int before, 1315 int before,
@@ -1215,7 +1329,10 @@ void leaf_paste_entries(struct buffer_info *bi,
1215 1329
1216 ih = item_head(bh, item_num); 1330 ih = item_head(bh, item_num);
1217 1331
1218 /* make sure, that item is directory, and there are enough records in it */ 1332 /*
1333 * make sure, that item is directory, and there are enough
1334 * records in it
1335 */
1219 RFALSE(!is_direntry_le_ih(ih), "10225: item is not directory item"); 1336 RFALSE(!is_direntry_le_ih(ih), "10225: item is not directory item");
1220 RFALSE(ih_entry_count(ih) < before, 1337 RFALSE(ih_entry_count(ih) < before,
1221 "10230: there are no entry we paste entries before. entry_count = %d, before = %d", 1338 "10230: there are no entry we paste entries before. entry_count = %d, before = %d",
@@ -1277,8 +1394,6 @@ void leaf_paste_entries(struct buffer_info *bi,
1277 /* change item key if necessary (when we paste before 0-th entry */ 1394 /* change item key if necessary (when we paste before 0-th entry */
1278 if (!before) { 1395 if (!before) {
1279 set_le_ih_k_offset(ih, deh_offset(new_dehs)); 1396 set_le_ih_k_offset(ih, deh_offset(new_dehs));
1280/* memcpy (&ih->ih_key.k_offset,
1281 &new_dehs->deh_offset, SHORT_KEY_SIZE);*/
1282 } 1397 }
1283#ifdef CONFIG_REISERFS_CHECK 1398#ifdef CONFIG_REISERFS_CHECK
1284 { 1399 {