aboutsummaryrefslogtreecommitdiffstats
path: root/fs/reiserfs/stree.c
diff options
context:
space:
mode:
authorJeff Mahoney <jeffm@suse.com>2009-03-30 14:02:50 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2009-03-30 15:16:40 -0400
commitee93961be1faddf9e9a638bc519145c20f0cfeba (patch)
tree9c62f05dca9ea72c2b419a7f1f9d5874b587e5ab /fs/reiserfs/stree.c
parentd68caa9530a8ba54f97002e02bf6a0ad2462b8c0 (diff)
reiserfs: rename [cn]_* variables
This patch renames n_, c_, etc variables to something more sane. This is the sixth in a series of patches to rip out some of the awful variable naming in reiserfs. Signed-off-by: Jeff Mahoney <jeffm@suse.com> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'fs/reiserfs/stree.c')
-rw-r--r--fs/reiserfs/stree.c370
1 files changed, 183 insertions, 187 deletions
diff --git a/fs/reiserfs/stree.c b/fs/reiserfs/stree.c
index fd769c8dac32..e23303daa868 100644
--- a/fs/reiserfs/stree.c
+++ b/fs/reiserfs/stree.c
@@ -136,11 +136,11 @@ inline int comp_short_le_keys(const struct reiserfs_key *key1,
136 const struct reiserfs_key *key2) 136 const struct reiserfs_key *key2)
137{ 137{
138 __u32 *k1_u32, *k2_u32; 138 __u32 *k1_u32, *k2_u32;
139 int n_key_length = REISERFS_SHORT_KEY_LEN; 139 int key_length = REISERFS_SHORT_KEY_LEN;
140 140
141 k1_u32 = (__u32 *) key1; 141 k1_u32 = (__u32 *) key1;
142 k2_u32 = (__u32 *) key2; 142 k2_u32 = (__u32 *) key2;
143 for (; n_key_length--; ++k1_u32, ++k2_u32) { 143 for (; key_length--; ++k1_u32, ++k2_u32) {
144 if (le32_to_cpu(*k1_u32) < le32_to_cpu(*k2_u32)) 144 if (le32_to_cpu(*k1_u32) < le32_to_cpu(*k2_u32))
145 return -1; 145 return -1;
146 if (le32_to_cpu(*k1_u32) > le32_to_cpu(*k2_u32)) 146 if (le32_to_cpu(*k1_u32) > le32_to_cpu(*k2_u32))
@@ -177,10 +177,10 @@ inline int comp_le_keys(const struct reiserfs_key *k1,
177 * *pos = number of the searched element if found, else the * 177 * *pos = number of the searched element if found, else the *
178 * number of the first element that is larger than key. * 178 * number of the first element that is larger than key. *
179 **************************************************************************/ 179 **************************************************************************/
180/* For those not familiar with binary search: n_lbound is the leftmost item that it 180/* For those not familiar with binary search: lbound is the leftmost item that it
181 could be, n_rbound the rightmost item that it could be. We examine the item 181 could be, rbound the rightmost item that it could be. We examine the item
182 halfway between n_lbound and n_rbound, and that tells us either that we can increase 182 halfway between lbound and rbound, and that tells us either that we can increase
183 n_lbound, or decrease n_rbound, or that we have found it, or if n_lbound <= n_rbound that 183 lbound, or decrease rbound, or that we have found it, or if lbound <= rbound that
184 there are no possible items, and we have not found it. With each examination we 184 there are no possible items, and we have not found it. With each examination we
185 cut the number of possible items it could be by one more than half rounded down, 185 cut the number of possible items it could be by one more than half rounded down,
186 or we find it. */ 186 or we find it. */
@@ -198,28 +198,27 @@ static inline int bin_search(const void *key, /* Key to search for. */
198 int *pos /* Number of the searched for element. */ 198 int *pos /* Number of the searched for element. */
199 ) 199 )
200{ 200{
201 int n_rbound, n_lbound, n_j; 201 int rbound, lbound, j;
202 202
203 for (n_j = ((n_rbound = num - 1) + (n_lbound = 0)) / 2; 203 for (j = ((rbound = num - 1) + (lbound = 0)) / 2;
204 n_lbound <= n_rbound; n_j = (n_rbound + n_lbound) / 2) 204 lbound <= rbound; j = (rbound + lbound) / 2)
205 switch (comp_keys 205 switch (comp_keys
206 ((struct reiserfs_key *)((char *)base + 206 ((struct reiserfs_key *)((char *)base + j * width),
207 n_j * width),
208 (struct cpu_key *)key)) { 207 (struct cpu_key *)key)) {
209 case -1: 208 case -1:
210 n_lbound = n_j + 1; 209 lbound = j + 1;
211 continue; 210 continue;
212 case 1: 211 case 1:
213 n_rbound = n_j - 1; 212 rbound = j - 1;
214 continue; 213 continue;
215 case 0: 214 case 0:
216 *pos = n_j; 215 *pos = j;
217 return ITEM_FOUND; /* Key found in the array. */ 216 return ITEM_FOUND; /* Key found in the array. */
218 } 217 }
219 218
220 /* bin_search did not find given key, it returns position of key, 219 /* bin_search did not find given key, it returns position of key,
221 that is minimal and greater than the given one. */ 220 that is minimal and greater than the given one. */
222 *pos = n_lbound; 221 *pos = lbound;
223 return ITEM_NOT_FOUND; 222 return ITEM_NOT_FOUND;
224} 223}
225 224
@@ -242,43 +241,41 @@ static const struct reiserfs_key MAX_KEY = {
242 of the path, and going upwards. We must check the path's validity at each step. If the key is not in 241 of the path, and going upwards. We must check the path's validity at each step. If the key is not in
243 the path, there is no delimiting key in the tree (buffer is first or last buffer in tree), and in this 242 the path, there is no delimiting key in the tree (buffer is first or last buffer in tree), and in this
244 case we return a special key, either MIN_KEY or MAX_KEY. */ 243 case we return a special key, either MIN_KEY or MAX_KEY. */
245static inline const struct reiserfs_key *get_lkey(const struct treepath 244static inline const struct reiserfs_key *get_lkey(const struct treepath *chk_path,
246 *chk_path, 245 const struct super_block *sb)
247 const struct super_block
248 *sb)
249{ 246{
250 int n_position, n_path_offset = chk_path->path_length; 247 int position, path_offset = chk_path->path_length;
251 struct buffer_head *parent; 248 struct buffer_head *parent;
252 249
253 RFALSE(n_path_offset < FIRST_PATH_ELEMENT_OFFSET, 250 RFALSE(path_offset < FIRST_PATH_ELEMENT_OFFSET,
254 "PAP-5010: invalid offset in the path"); 251 "PAP-5010: invalid offset in the path");
255 252
256 /* While not higher in path than first element. */ 253 /* While not higher in path than first element. */
257 while (n_path_offset-- > FIRST_PATH_ELEMENT_OFFSET) { 254 while (path_offset-- > FIRST_PATH_ELEMENT_OFFSET) {
258 255
259 RFALSE(!buffer_uptodate 256 RFALSE(!buffer_uptodate
260 (PATH_OFFSET_PBUFFER(chk_path, n_path_offset)), 257 (PATH_OFFSET_PBUFFER(chk_path, path_offset)),
261 "PAP-5020: parent is not uptodate"); 258 "PAP-5020: parent is not uptodate");
262 259
263 /* Parent at the path is not in the tree now. */ 260 /* Parent at the path is not in the tree now. */
264 if (!B_IS_IN_TREE 261 if (!B_IS_IN_TREE
265 (parent = 262 (parent =
266 PATH_OFFSET_PBUFFER(chk_path, n_path_offset))) 263 PATH_OFFSET_PBUFFER(chk_path, path_offset)))
267 return &MAX_KEY; 264 return &MAX_KEY;
268 /* Check whether position in the parent is correct. */ 265 /* Check whether position in the parent is correct. */
269 if ((n_position = 266 if ((position =
270 PATH_OFFSET_POSITION(chk_path, 267 PATH_OFFSET_POSITION(chk_path,
271 n_path_offset)) > 268 path_offset)) >
272 B_NR_ITEMS(parent)) 269 B_NR_ITEMS(parent))
273 return &MAX_KEY; 270 return &MAX_KEY;
274 /* Check whether parent at the path really points to the child. */ 271 /* Check whether parent at the path really points to the child. */
275 if (B_N_CHILD_NUM(parent, n_position) != 272 if (B_N_CHILD_NUM(parent, position) !=
276 PATH_OFFSET_PBUFFER(chk_path, 273 PATH_OFFSET_PBUFFER(chk_path,
277 n_path_offset + 1)->b_blocknr) 274 path_offset + 1)->b_blocknr)
278 return &MAX_KEY; 275 return &MAX_KEY;
279 /* Return delimiting key if position in the parent is not equal to zero. */ 276 /* Return delimiting key if position in the parent is not equal to zero. */
280 if (n_position) 277 if (position)
281 return B_N_PDELIM_KEY(parent, n_position - 1); 278 return B_N_PDELIM_KEY(parent, position - 1);
282 } 279 }
283 /* Return MIN_KEY if we are in the root of the buffer tree. */ 280 /* Return MIN_KEY if we are in the root of the buffer tree. */
284 if (PATH_OFFSET_PBUFFER(chk_path, FIRST_PATH_ELEMENT_OFFSET)-> 281 if (PATH_OFFSET_PBUFFER(chk_path, FIRST_PATH_ELEMENT_OFFSET)->
@@ -291,37 +288,37 @@ static inline const struct reiserfs_key *get_lkey(const struct treepath
291inline const struct reiserfs_key *get_rkey(const struct treepath *chk_path, 288inline const struct reiserfs_key *get_rkey(const struct treepath *chk_path,
292 const struct super_block *sb) 289 const struct super_block *sb)
293{ 290{
294 int n_position, n_path_offset = chk_path->path_length; 291 int position, path_offset = chk_path->path_length;
295 struct buffer_head *parent; 292 struct buffer_head *parent;
296 293
297 RFALSE(n_path_offset < FIRST_PATH_ELEMENT_OFFSET, 294 RFALSE(path_offset < FIRST_PATH_ELEMENT_OFFSET,
298 "PAP-5030: invalid offset in the path"); 295 "PAP-5030: invalid offset in the path");
299 296
300 while (n_path_offset-- > FIRST_PATH_ELEMENT_OFFSET) { 297 while (path_offset-- > FIRST_PATH_ELEMENT_OFFSET) {
301 298
302 RFALSE(!buffer_uptodate 299 RFALSE(!buffer_uptodate
303 (PATH_OFFSET_PBUFFER(chk_path, n_path_offset)), 300 (PATH_OFFSET_PBUFFER(chk_path, path_offset)),
304 "PAP-5040: parent is not uptodate"); 301 "PAP-5040: parent is not uptodate");
305 302
306 /* Parent at the path is not in the tree now. */ 303 /* Parent at the path is not in the tree now. */
307 if (!B_IS_IN_TREE 304 if (!B_IS_IN_TREE
308 (parent = 305 (parent =
309 PATH_OFFSET_PBUFFER(chk_path, n_path_offset))) 306 PATH_OFFSET_PBUFFER(chk_path, path_offset)))
310 return &MIN_KEY; 307 return &MIN_KEY;
311 /* Check whether position in the parent is correct. */ 308 /* Check whether position in the parent is correct. */
312 if ((n_position = 309 if ((position =
313 PATH_OFFSET_POSITION(chk_path, 310 PATH_OFFSET_POSITION(chk_path,
314 n_path_offset)) > 311 path_offset)) >
315 B_NR_ITEMS(parent)) 312 B_NR_ITEMS(parent))
316 return &MIN_KEY; 313 return &MIN_KEY;
317 /* Check whether parent at the path really points to the child. */ 314 /* Check whether parent at the path really points to the child. */
318 if (B_N_CHILD_NUM(parent, n_position) != 315 if (B_N_CHILD_NUM(parent, position) !=
319 PATH_OFFSET_PBUFFER(chk_path, 316 PATH_OFFSET_PBUFFER(chk_path,
320 n_path_offset + 1)->b_blocknr) 317 path_offset + 1)->b_blocknr)
321 return &MIN_KEY; 318 return &MIN_KEY;
322 /* Return delimiting key if position in the parent is not the last one. */ 319 /* Return delimiting key if position in the parent is not the last one. */
323 if (n_position != B_NR_ITEMS(parent)) 320 if (position != B_NR_ITEMS(parent))
324 return B_N_PDELIM_KEY(parent, n_position); 321 return B_N_PDELIM_KEY(parent, position);
325 } 322 }
326 /* Return MAX_KEY if we are in the root of the buffer tree. */ 323 /* Return MAX_KEY if we are in the root of the buffer tree. */
327 if (PATH_OFFSET_PBUFFER(chk_path, FIRST_PATH_ELEMENT_OFFSET)-> 324 if (PATH_OFFSET_PBUFFER(chk_path, FIRST_PATH_ELEMENT_OFFSET)->
@@ -371,14 +368,14 @@ int reiserfs_check_path(struct treepath *p)
371void pathrelse_and_restore(struct super_block *sb, 368void pathrelse_and_restore(struct super_block *sb,
372 struct treepath *search_path) 369 struct treepath *search_path)
373{ 370{
374 int n_path_offset = search_path->path_length; 371 int path_offset = search_path->path_length;
375 372
376 RFALSE(n_path_offset < ILLEGAL_PATH_ELEMENT_OFFSET, 373 RFALSE(path_offset < ILLEGAL_PATH_ELEMENT_OFFSET,
377 "clm-4000: invalid path offset"); 374 "clm-4000: invalid path offset");
378 375
379 while (n_path_offset > ILLEGAL_PATH_ELEMENT_OFFSET) { 376 while (path_offset > ILLEGAL_PATH_ELEMENT_OFFSET) {
380 struct buffer_head *bh; 377 struct buffer_head *bh;
381 bh = PATH_OFFSET_PBUFFER(search_path, n_path_offset--); 378 bh = PATH_OFFSET_PBUFFER(search_path, path_offset--);
382 reiserfs_restore_prepared_buffer(sb, bh); 379 reiserfs_restore_prepared_buffer(sb, bh);
383 brelse(bh); 380 brelse(bh);
384 } 381 }
@@ -388,13 +385,13 @@ void pathrelse_and_restore(struct super_block *sb,
388/* Drop the reference to each buffer in a path */ 385/* Drop the reference to each buffer in a path */
389void pathrelse(struct treepath *search_path) 386void pathrelse(struct treepath *search_path)
390{ 387{
391 int n_path_offset = search_path->path_length; 388 int path_offset = search_path->path_length;
392 389
393 RFALSE(n_path_offset < ILLEGAL_PATH_ELEMENT_OFFSET, 390 RFALSE(path_offset < ILLEGAL_PATH_ELEMENT_OFFSET,
394 "PAP-5090: invalid path offset"); 391 "PAP-5090: invalid path offset");
395 392
396 while (n_path_offset > ILLEGAL_PATH_ELEMENT_OFFSET) 393 while (path_offset > ILLEGAL_PATH_ELEMENT_OFFSET)
397 brelse(PATH_OFFSET_PBUFFER(search_path, n_path_offset--)); 394 brelse(PATH_OFFSET_PBUFFER(search_path, path_offset--));
398 395
399 search_path->path_length = ILLEGAL_PATH_ELEMENT_OFFSET; 396 search_path->path_length = ILLEGAL_PATH_ELEMENT_OFFSET;
400} 397}
@@ -572,16 +569,16 @@ int search_by_key(struct super_block *sb, const struct cpu_key *key, /* Key to s
572 by the calling 569 by the calling
573 function. It is filled up 570 function. It is filled up
574 by this function. */ 571 by this function. */
575 int n_stop_level /* How far down the tree to search. To 572 int stop_level /* How far down the tree to search. To
576 stop at leaf level - set to 573 stop at leaf level - set to
577 DISK_LEAF_NODE_LEVEL */ 574 DISK_LEAF_NODE_LEVEL */
578 ) 575 )
579{ 576{
580 b_blocknr_t n_block_number; 577 b_blocknr_t block_number;
581 int expected_level; 578 int expected_level;
582 struct buffer_head *bh; 579 struct buffer_head *bh;
583 struct path_element *last_element; 580 struct path_element *last_element;
584 int n_node_level, n_retval; 581 int node_level, retval;
585 int right_neighbor_of_leaf_node; 582 int right_neighbor_of_leaf_node;
586 int fs_gen; 583 int fs_gen;
587 struct buffer_head *reada_bh[SEARCH_BY_KEY_READA]; 584 struct buffer_head *reada_bh[SEARCH_BY_KEY_READA];
@@ -589,7 +586,7 @@ int search_by_key(struct super_block *sb, const struct cpu_key *key, /* Key to s
589 int reada_count = 0; 586 int reada_count = 0;
590 587
591#ifdef CONFIG_REISERFS_CHECK 588#ifdef CONFIG_REISERFS_CHECK
592 int n_repeat_counter = 0; 589 int repeat_counter = 0;
593#endif 590#endif
594 591
595 PROC_INFO_INC(sb, search_by_key); 592 PROC_INFO_INC(sb, search_by_key);
@@ -605,16 +602,16 @@ int search_by_key(struct super_block *sb, const struct cpu_key *key, /* Key to s
605 /* With each iteration of this loop we search through the items in the 602 /* With each iteration of this loop we search through the items in the
606 current node, and calculate the next current node(next path element) 603 current node, and calculate the next current node(next path element)
607 for the next iteration of this loop.. */ 604 for the next iteration of this loop.. */
608 n_block_number = SB_ROOT_BLOCK(sb); 605 block_number = SB_ROOT_BLOCK(sb);
609 expected_level = -1; 606 expected_level = -1;
610 while (1) { 607 while (1) {
611 608
612#ifdef CONFIG_REISERFS_CHECK 609#ifdef CONFIG_REISERFS_CHECK
613 if (!(++n_repeat_counter % 50000)) 610 if (!(++repeat_counter % 50000))
614 reiserfs_warning(sb, "PAP-5100", 611 reiserfs_warning(sb, "PAP-5100",
615 "%s: there were %d iterations of " 612 "%s: there were %d iterations of "
616 "while loop looking for key %K", 613 "while loop looking for key %K",
617 current->comm, n_repeat_counter, 614 current->comm, repeat_counter,
618 key); 615 key);
619#endif 616#endif
620 617
@@ -627,7 +624,7 @@ int search_by_key(struct super_block *sb, const struct cpu_key *key, /* Key to s
627 /* Read the next tree node, and set the last element in the path to 624 /* Read the next tree node, and set the last element in the path to
628 have a pointer to it. */ 625 have a pointer to it. */
629 if ((bh = last_element->pe_buffer = 626 if ((bh = last_element->pe_buffer =
630 sb_getblk(sb, n_block_number))) { 627 sb_getblk(sb, block_number))) {
631 if (!buffer_uptodate(bh) && reada_count > 1) 628 if (!buffer_uptodate(bh) && reada_count > 1)
632 search_by_key_reada(sb, reada_bh, 629 search_by_key_reada(sb, reada_bh,
633 reada_blocks, reada_count); 630 reada_blocks, reada_count);
@@ -661,7 +658,7 @@ int search_by_key(struct super_block *sb, const struct cpu_key *key, /* Key to s
661 658
662 /* Get the root block number so that we can repeat the search 659 /* Get the root block number so that we can repeat the search
663 starting from the root. */ 660 starting from the root. */
664 n_block_number = SB_ROOT_BLOCK(sb); 661 block_number = SB_ROOT_BLOCK(sb);
665 expected_level = -1; 662 expected_level = -1;
666 right_neighbor_of_leaf_node = 0; 663 right_neighbor_of_leaf_node = 0;
667 664
@@ -694,26 +691,26 @@ int search_by_key(struct super_block *sb, const struct cpu_key *key, /* Key to s
694 } 691 }
695 692
696 /* ok, we have acquired next formatted node in the tree */ 693 /* ok, we have acquired next formatted node in the tree */
697 n_node_level = B_LEVEL(bh); 694 node_level = B_LEVEL(bh);
698 695
699 PROC_INFO_BH_STAT(sb, bh, n_node_level - 1); 696 PROC_INFO_BH_STAT(sb, bh, node_level - 1);
700 697
701 RFALSE(n_node_level < n_stop_level, 698 RFALSE(node_level < stop_level,
702 "vs-5152: tree level (%d) is less than stop level (%d)", 699 "vs-5152: tree level (%d) is less than stop level (%d)",
703 n_node_level, n_stop_level); 700 node_level, stop_level);
704 701
705 n_retval = bin_search(key, B_N_PITEM_HEAD(bh, 0), 702 retval = bin_search(key, B_N_PITEM_HEAD(bh, 0),
706 B_NR_ITEMS(bh), 703 B_NR_ITEMS(bh),
707 (n_node_level == 704 (node_level ==
708 DISK_LEAF_NODE_LEVEL) ? IH_SIZE : 705 DISK_LEAF_NODE_LEVEL) ? IH_SIZE :
709 KEY_SIZE, 706 KEY_SIZE,
710 &(last_element->pe_position)); 707 &(last_element->pe_position));
711 if (n_node_level == n_stop_level) { 708 if (node_level == stop_level) {
712 return n_retval; 709 return retval;
713 } 710 }
714 711
715 /* we are not in the stop level */ 712 /* we are not in the stop level */
716 if (n_retval == ITEM_FOUND) 713 if (retval == ITEM_FOUND)
717 /* item has been found, so we choose the pointer which is to the right of the found one */ 714 /* item has been found, so we choose the pointer which is to the right of the found one */
718 last_element->pe_position++; 715 last_element->pe_position++;
719 716
@@ -724,12 +721,12 @@ int search_by_key(struct super_block *sb, const struct cpu_key *key, /* Key to s
724 /* So we have chosen a position in the current node which is 721 /* So we have chosen a position in the current node which is
725 an internal node. Now we calculate child block number by 722 an internal node. Now we calculate child block number by
726 position in the node. */ 723 position in the node. */
727 n_block_number = 724 block_number =
728 B_N_CHILD_NUM(bh, last_element->pe_position); 725 B_N_CHILD_NUM(bh, last_element->pe_position);
729 726
730 /* if we are going to read leaf nodes, try for read ahead as well */ 727 /* if we are going to read leaf nodes, try for read ahead as well */
731 if ((search_path->reada & PATH_READA) && 728 if ((search_path->reada & PATH_READA) &&
732 n_node_level == DISK_LEAF_NODE_LEVEL + 1) { 729 node_level == DISK_LEAF_NODE_LEVEL + 1) {
733 int pos = last_element->pe_position; 730 int pos = last_element->pe_position;
734 int limit = B_NR_ITEMS(bh); 731 int limit = B_NR_ITEMS(bh);
735 struct reiserfs_key *le_key; 732 struct reiserfs_key *le_key;
@@ -781,7 +778,7 @@ int search_for_position_by_key(struct super_block *sb, /* Pointer to the super b
781 ) 778 )
782{ 779{
783 struct item_head *p_le_ih; /* pointer to on-disk structure */ 780 struct item_head *p_le_ih; /* pointer to on-disk structure */
784 int n_blk_size; 781 int blk_size;
785 loff_t item_offset, offset; 782 loff_t item_offset, offset;
786 struct reiserfs_dir_entry de; 783 struct reiserfs_dir_entry de;
787 int retval; 784 int retval;
@@ -816,7 +813,7 @@ int search_for_position_by_key(struct super_block *sb, /* Pointer to the super b
816 p_le_ih = 813 p_le_ih =
817 B_N_PITEM_HEAD(PATH_PLAST_BUFFER(search_path), 814 B_N_PITEM_HEAD(PATH_PLAST_BUFFER(search_path),
818 --PATH_LAST_POSITION(search_path)); 815 --PATH_LAST_POSITION(search_path));
819 n_blk_size = sb->s_blocksize; 816 blk_size = sb->s_blocksize;
820 817
821 if (comp_short_keys(&(p_le_ih->ih_key), p_cpu_key)) { 818 if (comp_short_keys(&(p_le_ih->ih_key), p_cpu_key)) {
822 return FILE_NOT_FOUND; 819 return FILE_NOT_FOUND;
@@ -828,10 +825,10 @@ int search_for_position_by_key(struct super_block *sb, /* Pointer to the super b
828 825
829 /* Needed byte is contained in the item pointed to by the path. */ 826 /* Needed byte is contained in the item pointed to by the path. */
830 if (item_offset <= offset && 827 if (item_offset <= offset &&
831 item_offset + op_bytes_number(p_le_ih, n_blk_size) > offset) { 828 item_offset + op_bytes_number(p_le_ih, blk_size) > offset) {
832 pos_in_item(search_path) = offset - item_offset; 829 pos_in_item(search_path) = offset - item_offset;
833 if (is_indirect_le_ih(p_le_ih)) { 830 if (is_indirect_le_ih(p_le_ih)) {
834 pos_in_item(search_path) /= n_blk_size; 831 pos_in_item(search_path) /= blk_size;
835 } 832 }
836 return POSITION_FOUND; 833 return POSITION_FOUND;
837 } 834 }
@@ -891,7 +888,7 @@ static inline int prepare_for_direct_item(struct treepath *path,
891 if (get_inode_item_key_version(inode) == KEY_FORMAT_3_6) { 888 if (get_inode_item_key_version(inode) == KEY_FORMAT_3_6) {
892 // 889 //
893 round_len = ROUND_UP(new_file_length); 890 round_len = ROUND_UP(new_file_length);
894 /* this was n_new_file_length < le_ih ... */ 891 /* this was new_file_length < le_ih ... */
895 if (round_len < le_ih_k_offset(le_ih)) { 892 if (round_len < le_ih_k_offset(le_ih)) {
896 *cut_size = -(IH_SIZE + ih_item_len(le_ih)); 893 *cut_size = -(IH_SIZE + ih_item_len(le_ih));
897 return M_DELETE; /* Delete this item. */ 894 return M_DELETE; /* Delete this item. */
@@ -953,7 +950,7 @@ static inline int prepare_for_direntry_item(struct treepath *path,
953 This function returns a determination of what balance mode the calling function should employ. */ 950 This function returns a determination of what balance mode the calling function should employ. */
954static char prepare_for_delete_or_cut(struct reiserfs_transaction_handle *th, struct inode *inode, struct treepath *path, const struct cpu_key *item_key, int *removed, /* Number of unformatted nodes which were removed 951static char prepare_for_delete_or_cut(struct reiserfs_transaction_handle *th, struct inode *inode, struct treepath *path, const struct cpu_key *item_key, int *removed, /* Number of unformatted nodes which were removed
955 from end of the file. */ 952 from end of the file. */
956 int *cut_size, unsigned long long n_new_file_length /* MAX_KEY_OFFSET in case of delete. */ 953 int *cut_size, unsigned long long new_file_length /* MAX_KEY_OFFSET in case of delete. */
957 ) 954 )
958{ 955{
959 struct super_block *sb = inode->i_sb; 956 struct super_block *sb = inode->i_sb;
@@ -965,7 +962,7 @@ static char prepare_for_delete_or_cut(struct reiserfs_transaction_handle *th, st
965 /* Stat_data item. */ 962 /* Stat_data item. */
966 if (is_statdata_le_ih(p_le_ih)) { 963 if (is_statdata_le_ih(p_le_ih)) {
967 964
968 RFALSE(n_new_file_length != max_reiserfs_offset(inode), 965 RFALSE(new_file_length != max_reiserfs_offset(inode),
969 "PAP-5210: mode must be M_DELETE"); 966 "PAP-5210: mode must be M_DELETE");
970 967
971 *cut_size = -(IH_SIZE + ih_item_len(p_le_ih)); 968 *cut_size = -(IH_SIZE + ih_item_len(p_le_ih));
@@ -975,13 +972,13 @@ static char prepare_for_delete_or_cut(struct reiserfs_transaction_handle *th, st
975 /* Directory item. */ 972 /* Directory item. */
976 if (is_direntry_le_ih(p_le_ih)) 973 if (is_direntry_le_ih(p_le_ih))
977 return prepare_for_direntry_item(path, p_le_ih, inode, 974 return prepare_for_direntry_item(path, p_le_ih, inode,
978 n_new_file_length, 975 new_file_length,
979 cut_size); 976 cut_size);
980 977
981 /* Direct item. */ 978 /* Direct item. */
982 if (is_direct_le_ih(p_le_ih)) 979 if (is_direct_le_ih(p_le_ih))
983 return prepare_for_direct_item(path, p_le_ih, inode, 980 return prepare_for_direct_item(path, p_le_ih, inode,
984 n_new_file_length, cut_size); 981 new_file_length, cut_size);
985 982
986 /* Case of an indirect item. */ 983 /* Case of an indirect item. */
987 { 984 {
@@ -992,10 +989,10 @@ static char prepare_for_delete_or_cut(struct reiserfs_transaction_handle *th, st
992 int result = M_CUT; 989 int result = M_CUT;
993 int pos = 0; 990 int pos = 0;
994 991
995 if ( n_new_file_length == max_reiserfs_offset (inode) ) { 992 if ( new_file_length == max_reiserfs_offset (inode) ) {
996 /* prepare_for_delete_or_cut() is called by 993 /* prepare_for_delete_or_cut() is called by
997 * reiserfs_delete_item() */ 994 * reiserfs_delete_item() */
998 n_new_file_length = 0; 995 new_file_length = 0;
999 delete = 1; 996 delete = 1;
1000 } 997 }
1001 998
@@ -1006,7 +1003,7 @@ static char prepare_for_delete_or_cut(struct reiserfs_transaction_handle *th, st
1006 copy_item_head(&s_ih, PATH_PITEM_HEAD(path)); 1003 copy_item_head(&s_ih, PATH_PITEM_HEAD(path));
1007 pos = I_UNFM_NUM(&s_ih); 1004 pos = I_UNFM_NUM(&s_ih);
1008 1005
1009 while (le_ih_k_offset (&s_ih) + (pos - 1) * blk_size > n_new_file_length) { 1006 while (le_ih_k_offset (&s_ih) + (pos - 1) * blk_size > new_file_length) {
1010 __le32 *unfm; 1007 __le32 *unfm;
1011 __u32 block; 1008 __u32 block;
1012 1009
@@ -1062,35 +1059,34 @@ static char prepare_for_delete_or_cut(struct reiserfs_transaction_handle *th, st
1062} 1059}
1063 1060
1064/* Calculate number of bytes which will be deleted or cut during balance */ 1061/* Calculate number of bytes which will be deleted or cut during balance */
1065static int calc_deleted_bytes_number(struct tree_balance *tb, char c_mode) 1062static int calc_deleted_bytes_number(struct tree_balance *tb, char mode)
1066{ 1063{
1067 int n_del_size; 1064 int del_size;
1068 struct item_head *p_le_ih = PATH_PITEM_HEAD(tb->tb_path); 1065 struct item_head *p_le_ih = PATH_PITEM_HEAD(tb->tb_path);
1069 1066
1070 if (is_statdata_le_ih(p_le_ih)) 1067 if (is_statdata_le_ih(p_le_ih))
1071 return 0; 1068 return 0;
1072 1069
1073 n_del_size = 1070 del_size =
1074 (c_mode == 1071 (mode ==
1075 M_DELETE) ? ih_item_len(p_le_ih) : -tb->insert_size[0]; 1072 M_DELETE) ? ih_item_len(p_le_ih) : -tb->insert_size[0];
1076 if (is_direntry_le_ih(p_le_ih)) { 1073 if (is_direntry_le_ih(p_le_ih)) {
1077 // return EMPTY_DIR_SIZE; /* We delete emty directoris only. */ 1074 /* return EMPTY_DIR_SIZE; We delete emty directoris only.
1078 // we can't use EMPTY_DIR_SIZE, as old format dirs have a different 1075 * we can't use EMPTY_DIR_SIZE, as old format dirs have a different
1079 // empty size. ick. FIXME, is this right? 1076 * empty size. ick. FIXME, is this right? */
1080 // 1077 return del_size;
1081 return n_del_size;
1082 } 1078 }
1083 1079
1084 if (is_indirect_le_ih(p_le_ih)) 1080 if (is_indirect_le_ih(p_le_ih))
1085 n_del_size = (n_del_size / UNFM_P_SIZE) * 1081 del_size = (del_size / UNFM_P_SIZE) *
1086 (PATH_PLAST_BUFFER(tb->tb_path)->b_size); 1082 (PATH_PLAST_BUFFER(tb->tb_path)->b_size);
1087 return n_del_size; 1083 return del_size;
1088} 1084}
1089 1085
1090static void init_tb_struct(struct reiserfs_transaction_handle *th, 1086static void init_tb_struct(struct reiserfs_transaction_handle *th,
1091 struct tree_balance *tb, 1087 struct tree_balance *tb,
1092 struct super_block *sb, 1088 struct super_block *sb,
1093 struct treepath *path, int n_size) 1089 struct treepath *path, int size)
1094{ 1090{
1095 1091
1096 BUG_ON(!th->t_trans_id); 1092 BUG_ON(!th->t_trans_id);
@@ -1101,7 +1097,7 @@ static void init_tb_struct(struct reiserfs_transaction_handle *th,
1101 tb->tb_path = path; 1097 tb->tb_path = path;
1102 PATH_OFFSET_PBUFFER(path, ILLEGAL_PATH_ELEMENT_OFFSET) = NULL; 1098 PATH_OFFSET_PBUFFER(path, ILLEGAL_PATH_ELEMENT_OFFSET) = NULL;
1103 PATH_OFFSET_POSITION(path, ILLEGAL_PATH_ELEMENT_OFFSET) = 0; 1099 PATH_OFFSET_POSITION(path, ILLEGAL_PATH_ELEMENT_OFFSET) = 0;
1104 tb->insert_size[0] = n_size; 1100 tb->insert_size[0] = size;
1105} 1101}
1106 1102
1107void padd_item(char *item, int total_length, int length) 1103void padd_item(char *item, int total_length, int length)
@@ -1156,11 +1152,11 @@ int reiserfs_delete_item(struct reiserfs_transaction_handle *th,
1156 struct item_head s_ih; 1152 struct item_head s_ih;
1157 struct item_head *q_ih; 1153 struct item_head *q_ih;
1158 int quota_cut_bytes; 1154 int quota_cut_bytes;
1159 int n_ret_value, n_del_size, n_removed; 1155 int ret_value, del_size, removed;
1160 1156
1161#ifdef CONFIG_REISERFS_CHECK 1157#ifdef CONFIG_REISERFS_CHECK
1162 char c_mode; 1158 char mode;
1163 int n_iter = 0; 1159 int iter = 0;
1164#endif 1160#endif
1165 1161
1166 BUG_ON(!th->t_trans_id); 1162 BUG_ON(!th->t_trans_id);
@@ -1169,34 +1165,34 @@ int reiserfs_delete_item(struct reiserfs_transaction_handle *th,
1169 0 /*size is unknown */ ); 1165 0 /*size is unknown */ );
1170 1166
1171 while (1) { 1167 while (1) {
1172 n_removed = 0; 1168 removed = 0;
1173 1169
1174#ifdef CONFIG_REISERFS_CHECK 1170#ifdef CONFIG_REISERFS_CHECK
1175 n_iter++; 1171 iter++;
1176 c_mode = 1172 mode =
1177#endif 1173#endif
1178 prepare_for_delete_or_cut(th, inode, path, 1174 prepare_for_delete_or_cut(th, inode, path,
1179 item_key, &n_removed, 1175 item_key, &removed,
1180 &n_del_size, 1176 &del_size,
1181 max_reiserfs_offset(inode)); 1177 max_reiserfs_offset(inode));
1182 1178
1183 RFALSE(c_mode != M_DELETE, "PAP-5320: mode must be M_DELETE"); 1179 RFALSE(mode != M_DELETE, "PAP-5320: mode must be M_DELETE");
1184 1180
1185 copy_item_head(&s_ih, PATH_PITEM_HEAD(path)); 1181 copy_item_head(&s_ih, PATH_PITEM_HEAD(path));
1186 s_del_balance.insert_size[0] = n_del_size; 1182 s_del_balance.insert_size[0] = del_size;
1187 1183
1188 n_ret_value = fix_nodes(M_DELETE, &s_del_balance, NULL, NULL); 1184 ret_value = fix_nodes(M_DELETE, &s_del_balance, NULL, NULL);
1189 if (n_ret_value != REPEAT_SEARCH) 1185 if (ret_value != REPEAT_SEARCH)
1190 break; 1186 break;
1191 1187
1192 PROC_INFO_INC(sb, delete_item_restarted); 1188 PROC_INFO_INC(sb, delete_item_restarted);
1193 1189
1194 // file system changed, repeat search 1190 // file system changed, repeat search
1195 n_ret_value = 1191 ret_value =
1196 search_for_position_by_key(sb, item_key, path); 1192 search_for_position_by_key(sb, item_key, path);
1197 if (n_ret_value == IO_ERROR) 1193 if (ret_value == IO_ERROR)
1198 break; 1194 break;
1199 if (n_ret_value == FILE_NOT_FOUND) { 1195 if (ret_value == FILE_NOT_FOUND) {
1200 reiserfs_warning(sb, "vs-5340", 1196 reiserfs_warning(sb, "vs-5340",
1201 "no items of the file %K found", 1197 "no items of the file %K found",
1202 item_key); 1198 item_key);
@@ -1204,12 +1200,12 @@ int reiserfs_delete_item(struct reiserfs_transaction_handle *th,
1204 } 1200 }
1205 } /* while (1) */ 1201 } /* while (1) */
1206 1202
1207 if (n_ret_value != CARRY_ON) { 1203 if (ret_value != CARRY_ON) {
1208 unfix_nodes(&s_del_balance); 1204 unfix_nodes(&s_del_balance);
1209 return 0; 1205 return 0;
1210 } 1206 }
1211 // reiserfs_delete_item returns item length when success 1207 // reiserfs_delete_item returns item length when success
1212 n_ret_value = calc_deleted_bytes_number(&s_del_balance, M_DELETE); 1208 ret_value = calc_deleted_bytes_number(&s_del_balance, M_DELETE);
1213 q_ih = get_ih(path); 1209 q_ih = get_ih(path);
1214 quota_cut_bytes = ih_item_len(q_ih); 1210 quota_cut_bytes = ih_item_len(q_ih);
1215 1211
@@ -1255,7 +1251,7 @@ int reiserfs_delete_item(struct reiserfs_transaction_handle *th,
1255 off = ((le_ih_k_offset(&s_ih) - 1) & (PAGE_CACHE_SIZE - 1)); 1251 off = ((le_ih_k_offset(&s_ih) - 1) & (PAGE_CACHE_SIZE - 1));
1256 memcpy(data + off, 1252 memcpy(data + off,
1257 B_I_PITEM(PATH_PLAST_BUFFER(path), &s_ih), 1253 B_I_PITEM(PATH_PLAST_BUFFER(path), &s_ih),
1258 n_ret_value); 1254 ret_value);
1259 kunmap_atomic(data, KM_USER0); 1255 kunmap_atomic(data, KM_USER0);
1260 } 1256 }
1261 /* Perform balancing after all resources have been collected at once. */ 1257 /* Perform balancing after all resources have been collected at once. */
@@ -1269,7 +1265,7 @@ int reiserfs_delete_item(struct reiserfs_transaction_handle *th,
1269 DQUOT_FREE_SPACE_NODIRTY(inode, quota_cut_bytes); 1265 DQUOT_FREE_SPACE_NODIRTY(inode, quota_cut_bytes);
1270 1266
1271 /* Return deleted body length */ 1267 /* Return deleted body length */
1272 return n_ret_value; 1268 return ret_value;
1273} 1269}
1274 1270
1275/* Summary Of Mechanisms For Handling Collisions Between Processes: 1271/* Summary Of Mechanisms For Handling Collisions Between Processes:
@@ -1432,13 +1428,13 @@ static int maybe_indirect_to_direct(struct reiserfs_transaction_handle *th,
1432 struct page *page, 1428 struct page *page,
1433 struct treepath *path, 1429 struct treepath *path,
1434 const struct cpu_key *item_key, 1430 const struct cpu_key *item_key,
1435 loff_t n_new_file_size, char *mode) 1431 loff_t new_file_size, char *mode)
1436{ 1432{
1437 struct super_block *sb = inode->i_sb; 1433 struct super_block *sb = inode->i_sb;
1438 int n_block_size = sb->s_blocksize; 1434 int block_size = sb->s_blocksize;
1439 int cut_bytes; 1435 int cut_bytes;
1440 BUG_ON(!th->t_trans_id); 1436 BUG_ON(!th->t_trans_id);
1441 BUG_ON(n_new_file_size != inode->i_size); 1437 BUG_ON(new_file_size != inode->i_size);
1442 1438
1443 /* the page being sent in could be NULL if there was an i/o error 1439 /* the page being sent in could be NULL if there was an i/o error
1444 ** reading in the last block. The user will hit problems trying to 1440 ** reading in the last block. The user will hit problems trying to
@@ -1450,15 +1446,15 @@ static int maybe_indirect_to_direct(struct reiserfs_transaction_handle *th,
1450 /* leave tail in an unformatted node */ 1446 /* leave tail in an unformatted node */
1451 *mode = M_SKIP_BALANCING; 1447 *mode = M_SKIP_BALANCING;
1452 cut_bytes = 1448 cut_bytes =
1453 n_block_size - (n_new_file_size & (n_block_size - 1)); 1449 block_size - (new_file_size & (block_size - 1));
1454 pathrelse(path); 1450 pathrelse(path);
1455 return cut_bytes; 1451 return cut_bytes;
1456 } 1452 }
1457 /* Perform the conversion to a direct_item. */ 1453 /* Perform the conversion to a direct_item. */
1458 /* return indirect_to_direct(inode, path, item_key, 1454 /* return indirect_to_direct(inode, path, item_key,
1459 n_new_file_size, mode); */ 1455 new_file_size, mode); */
1460 return indirect2direct(th, inode, page, path, item_key, 1456 return indirect2direct(th, inode, page, path, item_key,
1461 n_new_file_size, mode); 1457 new_file_size, mode);
1462} 1458}
1463 1459
1464/* we did indirect_to_direct conversion. And we have inserted direct 1460/* we did indirect_to_direct conversion. And we have inserted direct
@@ -1512,7 +1508,7 @@ int reiserfs_cut_from_item(struct reiserfs_transaction_handle *th,
1512 struct treepath *path, 1508 struct treepath *path,
1513 struct cpu_key *item_key, 1509 struct cpu_key *item_key,
1514 struct inode *inode, 1510 struct inode *inode,
1515 struct page *page, loff_t n_new_file_size) 1511 struct page *page, loff_t new_file_size)
1516{ 1512{
1517 struct super_block *sb = inode->i_sb; 1513 struct super_block *sb = inode->i_sb;
1518 /* Every function which is going to call do_balance must first 1514 /* Every function which is going to call do_balance must first
@@ -1521,10 +1517,10 @@ int reiserfs_cut_from_item(struct reiserfs_transaction_handle *th,
1521 After that we can make tree balancing. */ 1517 After that we can make tree balancing. */
1522 struct tree_balance s_cut_balance; 1518 struct tree_balance s_cut_balance;
1523 struct item_head *p_le_ih; 1519 struct item_head *p_le_ih;
1524 int n_cut_size = 0, /* Amount to be cut. */ 1520 int cut_size = 0, /* Amount to be cut. */
1525 n_ret_value = CARRY_ON, n_removed = 0, /* Number of the removed unformatted nodes. */ 1521 ret_value = CARRY_ON, removed = 0, /* Number of the removed unformatted nodes. */
1526 n_is_inode_locked = 0; 1522 is_inode_locked = 0;
1527 char c_mode; /* Mode of the balance. */ 1523 char mode; /* Mode of the balance. */
1528 int retval2 = -1; 1524 int retval2 = -1;
1529 int quota_cut_bytes; 1525 int quota_cut_bytes;
1530 loff_t tail_pos = 0; 1526 loff_t tail_pos = 0;
@@ -1532,7 +1528,7 @@ int reiserfs_cut_from_item(struct reiserfs_transaction_handle *th,
1532 BUG_ON(!th->t_trans_id); 1528 BUG_ON(!th->t_trans_id);
1533 1529
1534 init_tb_struct(th, &s_cut_balance, inode->i_sb, path, 1530 init_tb_struct(th, &s_cut_balance, inode->i_sb, path,
1535 n_cut_size); 1531 cut_size);
1536 1532
1537 /* Repeat this loop until we either cut the item without needing 1533 /* Repeat this loop until we either cut the item without needing
1538 to balance, or we fix_nodes without schedule occurring */ 1534 to balance, or we fix_nodes without schedule occurring */
@@ -1542,30 +1538,30 @@ int reiserfs_cut_from_item(struct reiserfs_transaction_handle *th,
1542 free unformatted nodes which are pointed to by the cut 1538 free unformatted nodes which are pointed to by the cut
1543 pointers. */ 1539 pointers. */
1544 1540
1545 c_mode = 1541 mode =
1546 prepare_for_delete_or_cut(th, inode, path, 1542 prepare_for_delete_or_cut(th, inode, path,
1547 item_key, &n_removed, 1543 item_key, &removed,
1548 &n_cut_size, n_new_file_size); 1544 &cut_size, new_file_size);
1549 if (c_mode == M_CONVERT) { 1545 if (mode == M_CONVERT) {
1550 /* convert last unformatted node to direct item or leave 1546 /* convert last unformatted node to direct item or leave
1551 tail in the unformatted node */ 1547 tail in the unformatted node */
1552 RFALSE(n_ret_value != CARRY_ON, 1548 RFALSE(ret_value != CARRY_ON,
1553 "PAP-5570: can not convert twice"); 1549 "PAP-5570: can not convert twice");
1554 1550
1555 n_ret_value = 1551 ret_value =
1556 maybe_indirect_to_direct(th, inode, page, 1552 maybe_indirect_to_direct(th, inode, page,
1557 path, item_key, 1553 path, item_key,
1558 n_new_file_size, &c_mode); 1554 new_file_size, &mode);
1559 if (c_mode == M_SKIP_BALANCING) 1555 if (mode == M_SKIP_BALANCING)
1560 /* tail has been left in the unformatted node */ 1556 /* tail has been left in the unformatted node */
1561 return n_ret_value; 1557 return ret_value;
1562 1558
1563 n_is_inode_locked = 1; 1559 is_inode_locked = 1;
1564 1560
1565 /* removing of last unformatted node will change value we 1561 /* removing of last unformatted node will change value we
1566 have to return to truncate. Save it */ 1562 have to return to truncate. Save it */
1567 retval2 = n_ret_value; 1563 retval2 = ret_value;
1568 /*retval2 = sb->s_blocksize - (n_new_file_size & (sb->s_blocksize - 1)); */ 1564 /*retval2 = sb->s_blocksize - (new_file_size & (sb->s_blocksize - 1)); */
1569 1565
1570 /* So, we have performed the first part of the conversion: 1566 /* So, we have performed the first part of the conversion:
1571 inserting the new direct item. Now we are removing the 1567 inserting the new direct item. Now we are removing the
@@ -1573,10 +1569,10 @@ int reiserfs_cut_from_item(struct reiserfs_transaction_handle *th,
1573 it. */ 1569 it. */
1574 set_cpu_key_k_type(item_key, TYPE_INDIRECT); 1570 set_cpu_key_k_type(item_key, TYPE_INDIRECT);
1575 item_key->key_length = 4; 1571 item_key->key_length = 4;
1576 n_new_file_size -= 1572 new_file_size -=
1577 (n_new_file_size & (sb->s_blocksize - 1)); 1573 (new_file_size & (sb->s_blocksize - 1));
1578 tail_pos = n_new_file_size; 1574 tail_pos = new_file_size;
1579 set_cpu_key_k_offset(item_key, n_new_file_size + 1); 1575 set_cpu_key_k_offset(item_key, new_file_size + 1);
1580 if (search_for_position_by_key 1576 if (search_for_position_by_key
1581 (sb, item_key, 1577 (sb, item_key,
1582 path) == POSITION_NOT_FOUND) { 1578 path) == POSITION_NOT_FOUND) {
@@ -1589,38 +1585,38 @@ int reiserfs_cut_from_item(struct reiserfs_transaction_handle *th,
1589 } 1585 }
1590 continue; 1586 continue;
1591 } 1587 }
1592 if (n_cut_size == 0) { 1588 if (cut_size == 0) {
1593 pathrelse(path); 1589 pathrelse(path);
1594 return 0; 1590 return 0;
1595 } 1591 }
1596 1592
1597 s_cut_balance.insert_size[0] = n_cut_size; 1593 s_cut_balance.insert_size[0] = cut_size;
1598 1594
1599 n_ret_value = fix_nodes(c_mode, &s_cut_balance, NULL, NULL); 1595 ret_value = fix_nodes(mode, &s_cut_balance, NULL, NULL);
1600 if (n_ret_value != REPEAT_SEARCH) 1596 if (ret_value != REPEAT_SEARCH)
1601 break; 1597 break;
1602 1598
1603 PROC_INFO_INC(sb, cut_from_item_restarted); 1599 PROC_INFO_INC(sb, cut_from_item_restarted);
1604 1600
1605 n_ret_value = 1601 ret_value =
1606 search_for_position_by_key(sb, item_key, path); 1602 search_for_position_by_key(sb, item_key, path);
1607 if (n_ret_value == POSITION_FOUND) 1603 if (ret_value == POSITION_FOUND)
1608 continue; 1604 continue;
1609 1605
1610 reiserfs_warning(sb, "PAP-5610", "item %K not found", 1606 reiserfs_warning(sb, "PAP-5610", "item %K not found",
1611 item_key); 1607 item_key);
1612 unfix_nodes(&s_cut_balance); 1608 unfix_nodes(&s_cut_balance);
1613 return (n_ret_value == IO_ERROR) ? -EIO : -ENOENT; 1609 return (ret_value == IO_ERROR) ? -EIO : -ENOENT;
1614 } /* while */ 1610 } /* while */
1615 1611
1616 // check fix_nodes results (IO_ERROR or NO_DISK_SPACE) 1612 // check fix_nodes results (IO_ERROR or NO_DISK_SPACE)
1617 if (n_ret_value != CARRY_ON) { 1613 if (ret_value != CARRY_ON) {
1618 if (n_is_inode_locked) { 1614 if (is_inode_locked) {
1619 // FIXME: this seems to be not needed: we are always able 1615 // FIXME: this seems to be not needed: we are always able
1620 // to cut item 1616 // to cut item
1621 indirect_to_direct_roll_back(th, inode, path); 1617 indirect_to_direct_roll_back(th, inode, path);
1622 } 1618 }
1623 if (n_ret_value == NO_DISK_SPACE) 1619 if (ret_value == NO_DISK_SPACE)
1624 reiserfs_warning(sb, "reiserfs-5092", 1620 reiserfs_warning(sb, "reiserfs-5092",
1625 "NO_DISK_SPACE"); 1621 "NO_DISK_SPACE");
1626 unfix_nodes(&s_cut_balance); 1622 unfix_nodes(&s_cut_balance);
@@ -1629,24 +1625,24 @@ int reiserfs_cut_from_item(struct reiserfs_transaction_handle *th,
1629 1625
1630 /* go ahead and perform balancing */ 1626 /* go ahead and perform balancing */
1631 1627
1632 RFALSE(c_mode == M_PASTE || c_mode == M_INSERT, "invalid mode"); 1628 RFALSE(mode == M_PASTE || mode == M_INSERT, "invalid mode");
1633 1629
1634 /* Calculate number of bytes that need to be cut from the item. */ 1630 /* Calculate number of bytes that need to be cut from the item. */
1635 quota_cut_bytes = 1631 quota_cut_bytes =
1636 (c_mode == 1632 (mode ==
1637 M_DELETE) ? ih_item_len(get_ih(path)) : -s_cut_balance. 1633 M_DELETE) ? ih_item_len(get_ih(path)) : -s_cut_balance.
1638 insert_size[0]; 1634 insert_size[0];
1639 if (retval2 == -1) 1635 if (retval2 == -1)
1640 n_ret_value = calc_deleted_bytes_number(&s_cut_balance, c_mode); 1636 ret_value = calc_deleted_bytes_number(&s_cut_balance, mode);
1641 else 1637 else
1642 n_ret_value = retval2; 1638 ret_value = retval2;
1643 1639
1644 /* For direct items, we only change the quota when deleting the last 1640 /* For direct items, we only change the quota when deleting the last
1645 ** item. 1641 ** item.
1646 */ 1642 */
1647 p_le_ih = PATH_PITEM_HEAD(s_cut_balance.tb_path); 1643 p_le_ih = PATH_PITEM_HEAD(s_cut_balance.tb_path);
1648 if (!S_ISLNK(inode->i_mode) && is_direct_le_ih(p_le_ih)) { 1644 if (!S_ISLNK(inode->i_mode) && is_direct_le_ih(p_le_ih)) {
1649 if (c_mode == M_DELETE && 1645 if (mode == M_DELETE &&
1650 (le_ih_k_offset(p_le_ih) & (sb->s_blocksize - 1)) == 1646 (le_ih_k_offset(p_le_ih) & (sb->s_blocksize - 1)) ==
1651 1) { 1647 1) {
1652 // FIXME: this is to keep 3.5 happy 1648 // FIXME: this is to keep 3.5 happy
@@ -1657,7 +1653,7 @@ int reiserfs_cut_from_item(struct reiserfs_transaction_handle *th,
1657 } 1653 }
1658 } 1654 }
1659#ifdef CONFIG_REISERFS_CHECK 1655#ifdef CONFIG_REISERFS_CHECK
1660 if (n_is_inode_locked) { 1656 if (is_inode_locked) {
1661 struct item_head *le_ih = 1657 struct item_head *le_ih =
1662 PATH_PITEM_HEAD(s_cut_balance.tb_path); 1658 PATH_PITEM_HEAD(s_cut_balance.tb_path);
1663 /* we are going to complete indirect2direct conversion. Make 1659 /* we are going to complete indirect2direct conversion. Make
@@ -1667,13 +1663,13 @@ int reiserfs_cut_from_item(struct reiserfs_transaction_handle *th,
1667 reiserfs_panic(sb, "vs-5652", 1663 reiserfs_panic(sb, "vs-5652",
1668 "item must be indirect %h", le_ih); 1664 "item must be indirect %h", le_ih);
1669 1665
1670 if (c_mode == M_DELETE && ih_item_len(le_ih) != UNFM_P_SIZE) 1666 if (mode == M_DELETE && ih_item_len(le_ih) != UNFM_P_SIZE)
1671 reiserfs_panic(sb, "vs-5653", "completing " 1667 reiserfs_panic(sb, "vs-5653", "completing "
1672 "indirect2direct conversion indirect " 1668 "indirect2direct conversion indirect "
1673 "item %h being deleted must be of " 1669 "item %h being deleted must be of "
1674 "4 byte long", le_ih); 1670 "4 byte long", le_ih);
1675 1671
1676 if (c_mode == M_CUT 1672 if (mode == M_CUT
1677 && s_cut_balance.insert_size[0] != -UNFM_P_SIZE) { 1673 && s_cut_balance.insert_size[0] != -UNFM_P_SIZE) {
1678 reiserfs_panic(sb, "vs-5654", "can not complete " 1674 reiserfs_panic(sb, "vs-5654", "can not complete "
1679 "indirect2direct conversion of %h " 1675 "indirect2direct conversion of %h "
@@ -1685,8 +1681,8 @@ int reiserfs_cut_from_item(struct reiserfs_transaction_handle *th,
1685 } 1681 }
1686#endif 1682#endif
1687 1683
1688 do_balance(&s_cut_balance, NULL, NULL, c_mode); 1684 do_balance(&s_cut_balance, NULL, NULL, mode);
1689 if (n_is_inode_locked) { 1685 if (is_inode_locked) {
1690 /* we've done an indirect->direct conversion. when the data block 1686 /* we've done an indirect->direct conversion. when the data block
1691 ** was freed, it was removed from the list of blocks that must 1687 ** was freed, it was removed from the list of blocks that must
1692 ** be flushed before the transaction commits, make sure to 1688 ** be flushed before the transaction commits, make sure to
@@ -1701,7 +1697,7 @@ int reiserfs_cut_from_item(struct reiserfs_transaction_handle *th,
1701 quota_cut_bytes, inode->i_uid, '?'); 1697 quota_cut_bytes, inode->i_uid, '?');
1702#endif 1698#endif
1703 DQUOT_FREE_SPACE_NODIRTY(inode, quota_cut_bytes); 1699 DQUOT_FREE_SPACE_NODIRTY(inode, quota_cut_bytes);
1704 return n_ret_value; 1700 return ret_value;
1705} 1701}
1706 1702
1707static void truncate_directory(struct reiserfs_transaction_handle *th, 1703static void truncate_directory(struct reiserfs_transaction_handle *th,
@@ -1733,9 +1729,9 @@ int reiserfs_do_truncate(struct reiserfs_transaction_handle *th,
1733 INITIALIZE_PATH(s_search_path); /* Path to the current object item. */ 1729 INITIALIZE_PATH(s_search_path); /* Path to the current object item. */
1734 struct item_head *p_le_ih; /* Pointer to an item header. */ 1730 struct item_head *p_le_ih; /* Pointer to an item header. */
1735 struct cpu_key s_item_key; /* Key to search for a previous file item. */ 1731 struct cpu_key s_item_key; /* Key to search for a previous file item. */
1736 loff_t n_file_size, /* Old file size. */ 1732 loff_t file_size, /* Old file size. */
1737 n_new_file_size; /* New file size. */ 1733 new_file_size; /* New file size. */
1738 int n_deleted; /* Number of deleted or truncated bytes. */ 1734 int deleted; /* Number of deleted or truncated bytes. */
1739 int retval; 1735 int retval;
1740 int err = 0; 1736 int err = 0;
1741 1737
@@ -1752,7 +1748,7 @@ int reiserfs_do_truncate(struct reiserfs_transaction_handle *th,
1752 } 1748 }
1753 1749
1754 /* Get new file size. */ 1750 /* Get new file size. */
1755 n_new_file_size = inode->i_size; 1751 new_file_size = inode->i_size;
1756 1752
1757 // FIXME: note, that key type is unimportant here 1753 // FIXME: note, that key type is unimportant here
1758 make_cpu_key(&s_item_key, inode, max_reiserfs_offset(inode), 1754 make_cpu_key(&s_item_key, inode, max_reiserfs_offset(inode),
@@ -1782,7 +1778,7 @@ int reiserfs_do_truncate(struct reiserfs_transaction_handle *th,
1782 /* Get real file size (total length of all file items) */ 1778 /* Get real file size (total length of all file items) */
1783 p_le_ih = PATH_PITEM_HEAD(&s_search_path); 1779 p_le_ih = PATH_PITEM_HEAD(&s_search_path);
1784 if (is_statdata_le_ih(p_le_ih)) 1780 if (is_statdata_le_ih(p_le_ih))
1785 n_file_size = 0; 1781 file_size = 0;
1786 else { 1782 else {
1787 loff_t offset = le_ih_k_offset(p_le_ih); 1783 loff_t offset = le_ih_k_offset(p_le_ih);
1788 int bytes = 1784 int bytes =
@@ -1791,42 +1787,42 @@ int reiserfs_do_truncate(struct reiserfs_transaction_handle *th,
1791 /* this may mismatch with real file size: if last direct item 1787 /* this may mismatch with real file size: if last direct item
1792 had no padding zeros and last unformatted node had no free 1788 had no padding zeros and last unformatted node had no free
1793 space, this file would have this file size */ 1789 space, this file would have this file size */
1794 n_file_size = offset + bytes - 1; 1790 file_size = offset + bytes - 1;
1795 } 1791 }
1796 /* 1792 /*
1797 * are we doing a full truncate or delete, if so 1793 * are we doing a full truncate or delete, if so
1798 * kick in the reada code 1794 * kick in the reada code
1799 */ 1795 */
1800 if (n_new_file_size == 0) 1796 if (new_file_size == 0)
1801 s_search_path.reada = PATH_READA | PATH_READA_BACK; 1797 s_search_path.reada = PATH_READA | PATH_READA_BACK;
1802 1798
1803 if (n_file_size == 0 || n_file_size < n_new_file_size) { 1799 if (file_size == 0 || file_size < new_file_size) {
1804 goto update_and_out; 1800 goto update_and_out;
1805 } 1801 }
1806 1802
1807 /* Update key to search for the last file item. */ 1803 /* Update key to search for the last file item. */
1808 set_cpu_key_k_offset(&s_item_key, n_file_size); 1804 set_cpu_key_k_offset(&s_item_key, file_size);
1809 1805
1810 do { 1806 do {
1811 /* Cut or delete file item. */ 1807 /* Cut or delete file item. */
1812 n_deleted = 1808 deleted =
1813 reiserfs_cut_from_item(th, &s_search_path, &s_item_key, 1809 reiserfs_cut_from_item(th, &s_search_path, &s_item_key,
1814 inode, page, n_new_file_size); 1810 inode, page, new_file_size);
1815 if (n_deleted < 0) { 1811 if (deleted < 0) {
1816 reiserfs_warning(inode->i_sb, "vs-5665", 1812 reiserfs_warning(inode->i_sb, "vs-5665",
1817 "reiserfs_cut_from_item failed"); 1813 "reiserfs_cut_from_item failed");
1818 reiserfs_check_path(&s_search_path); 1814 reiserfs_check_path(&s_search_path);
1819 return 0; 1815 return 0;
1820 } 1816 }
1821 1817
1822 RFALSE(n_deleted > n_file_size, 1818 RFALSE(deleted > file_size,
1823 "PAP-5670: reiserfs_cut_from_item: too many bytes deleted: deleted %d, file_size %lu, item_key %K", 1819 "PAP-5670: reiserfs_cut_from_item: too many bytes deleted: deleted %d, file_size %lu, item_key %K",
1824 n_deleted, n_file_size, &s_item_key); 1820 deleted, file_size, &s_item_key);
1825 1821
1826 /* Change key to search the last file item. */ 1822 /* Change key to search the last file item. */
1827 n_file_size -= n_deleted; 1823 file_size -= deleted;
1828 1824
1829 set_cpu_key_k_offset(&s_item_key, n_file_size); 1825 set_cpu_key_k_offset(&s_item_key, file_size);
1830 1826
1831 /* While there are bytes to truncate and previous file item is presented in the tree. */ 1827 /* While there are bytes to truncate and previous file item is presented in the tree. */
1832 1828
@@ -1857,13 +1853,13 @@ int reiserfs_do_truncate(struct reiserfs_transaction_handle *th,
1857 goto out; 1853 goto out;
1858 reiserfs_update_inode_transaction(inode); 1854 reiserfs_update_inode_transaction(inode);
1859 } 1855 }
1860 } while (n_file_size > ROUND_UP(n_new_file_size) && 1856 } while (file_size > ROUND_UP(new_file_size) &&
1861 search_for_position_by_key(inode->i_sb, &s_item_key, 1857 search_for_position_by_key(inode->i_sb, &s_item_key,
1862 &s_search_path) == POSITION_FOUND); 1858 &s_search_path) == POSITION_FOUND);
1863 1859
1864 RFALSE(n_file_size > ROUND_UP(n_new_file_size), 1860 RFALSE(file_size > ROUND_UP(new_file_size),
1865 "PAP-5680: truncate did not finish: new_file_size %Ld, current %Ld, oid %d", 1861 "PAP-5680: truncate did not finish: new_file_size %Ld, current %Ld, oid %d",
1866 n_new_file_size, n_file_size, s_item_key.on_disk_key.k_objectid); 1862 new_file_size, file_size, s_item_key.on_disk_key.k_objectid);
1867 1863
1868 update_and_out: 1864 update_and_out:
1869 if (update_timestamps) { 1865 if (update_timestamps) {
@@ -1918,7 +1914,7 @@ int reiserfs_paste_into_item(struct reiserfs_transaction_handle *th, struct tree
1918 const struct cpu_key *key, /* Key to search for the needed item. */ 1914 const struct cpu_key *key, /* Key to search for the needed item. */
1919 struct inode *inode, /* Inode item belongs to */ 1915 struct inode *inode, /* Inode item belongs to */
1920 const char *body, /* Pointer to the bytes to paste. */ 1916 const char *body, /* Pointer to the bytes to paste. */
1921 int n_pasted_size) 1917 int pasted_size)
1922{ /* Size of pasted bytes. */ 1918{ /* Size of pasted bytes. */
1923 struct tree_balance s_paste_balance; 1919 struct tree_balance s_paste_balance;
1924 int retval; 1920 int retval;
@@ -1931,16 +1927,16 @@ int reiserfs_paste_into_item(struct reiserfs_transaction_handle *th, struct tree
1931#ifdef REISERQUOTA_DEBUG 1927#ifdef REISERQUOTA_DEBUG
1932 reiserfs_debug(inode->i_sb, REISERFS_DEBUG_CODE, 1928 reiserfs_debug(inode->i_sb, REISERFS_DEBUG_CODE,
1933 "reiserquota paste_into_item(): allocating %u id=%u type=%c", 1929 "reiserquota paste_into_item(): allocating %u id=%u type=%c",
1934 n_pasted_size, inode->i_uid, 1930 pasted_size, inode->i_uid,
1935 key2type(&(key->on_disk_key))); 1931 key2type(&(key->on_disk_key)));
1936#endif 1932#endif
1937 1933
1938 if (DQUOT_ALLOC_SPACE_NODIRTY(inode, n_pasted_size)) { 1934 if (DQUOT_ALLOC_SPACE_NODIRTY(inode, pasted_size)) {
1939 pathrelse(search_path); 1935 pathrelse(search_path);
1940 return -EDQUOT; 1936 return -EDQUOT;
1941 } 1937 }
1942 init_tb_struct(th, &s_paste_balance, th->t_super, search_path, 1938 init_tb_struct(th, &s_paste_balance, th->t_super, search_path,
1943 n_pasted_size); 1939 pasted_size);
1944#ifdef DISPLACE_NEW_PACKING_LOCALITIES 1940#ifdef DISPLACE_NEW_PACKING_LOCALITIES
1945 s_paste_balance.key = key->on_disk_key; 1941 s_paste_balance.key = key->on_disk_key;
1946#endif 1942#endif
@@ -1988,10 +1984,10 @@ int reiserfs_paste_into_item(struct reiserfs_transaction_handle *th, struct tree
1988#ifdef REISERQUOTA_DEBUG 1984#ifdef REISERQUOTA_DEBUG
1989 reiserfs_debug(inode->i_sb, REISERFS_DEBUG_CODE, 1985 reiserfs_debug(inode->i_sb, REISERFS_DEBUG_CODE,
1990 "reiserquota paste_into_item(): freeing %u id=%u type=%c", 1986 "reiserquota paste_into_item(): freeing %u id=%u type=%c",
1991 n_pasted_size, inode->i_uid, 1987 pasted_size, inode->i_uid,
1992 key2type(&(key->on_disk_key))); 1988 key2type(&(key->on_disk_key)));
1993#endif 1989#endif
1994 DQUOT_FREE_SPACE_NODIRTY(inode, n_pasted_size); 1990 DQUOT_FREE_SPACE_NODIRTY(inode, pasted_size);
1995 return retval; 1991 return retval;
1996} 1992}
1997 1993