aboutsummaryrefslogtreecommitdiffstats
path: root/fs/reiserfs
diff options
context:
space:
mode:
Diffstat (limited to 'fs/reiserfs')
-rw-r--r--fs/reiserfs/file.c6
-rw-r--r--fs/reiserfs/fix_node.c169
-rw-r--r--fs/reiserfs/stree.c472
-rw-r--r--fs/reiserfs/tail_conversion.c28
4 files changed, 342 insertions, 333 deletions
diff --git a/fs/reiserfs/file.c b/fs/reiserfs/file.c
index a73579f66214..cde16429ff00 100644
--- a/fs/reiserfs/file.c
+++ b/fs/reiserfs/file.c
@@ -134,10 +134,10 @@ static void reiserfs_vfs_truncate_file(struct inode *inode)
134 * be removed... 134 * be removed...
135 */ 135 */
136 136
137static int reiserfs_sync_file(struct file *p_s_filp, 137static int reiserfs_sync_file(struct file *filp,
138 struct dentry *p_s_dentry, int datasync) 138 struct dentry *dentry, int datasync)
139{ 139{
140 struct inode *inode = p_s_dentry->d_inode; 140 struct inode *inode = dentry->d_inode;
141 int n_err; 141 int n_err;
142 int barrier_done; 142 int barrier_done;
143 143
diff --git a/fs/reiserfs/fix_node.c b/fs/reiserfs/fix_node.c
index 5236a8829e31..d97a55574ba9 100644
--- a/fs/reiserfs/fix_node.c
+++ b/fs/reiserfs/fix_node.c
@@ -780,9 +780,9 @@ static void free_buffers_in_tb(struct tree_balance *tb)
780/* The function is NOT SCHEDULE-SAFE! */ 780/* The function is NOT SCHEDULE-SAFE! */
781static int get_empty_nodes(struct tree_balance *tb, int n_h) 781static int get_empty_nodes(struct tree_balance *tb, int n_h)
782{ 782{
783 struct buffer_head *p_s_new_bh, 783 struct buffer_head *new_bh,
784 *p_s_Sh = PATH_H_PBUFFER(tb->tb_path, n_h); 784 *Sh = PATH_H_PBUFFER(tb->tb_path, n_h);
785 b_blocknr_t *p_n_blocknr, a_n_blocknrs[MAX_AMOUNT_NEEDED] = { 0, }; 785 b_blocknr_t *blocknr, a_n_blocknrs[MAX_AMOUNT_NEEDED] = { 0, };
786 int n_counter, n_number_of_freeblk, n_amount_needed, /* number of needed empty blocks */ 786 int n_counter, n_number_of_freeblk, n_amount_needed, /* number of needed empty blocks */
787 n_retval = CARRY_ON; 787 n_retval = CARRY_ON;
788 struct super_block *sb = tb->tb_sb; 788 struct super_block *sb = tb->tb_sb;
@@ -810,8 +810,8 @@ static int get_empty_nodes(struct tree_balance *tb, int n_h)
810 1) : 0; 810 1) : 0;
811 811
812 /* Allocate missing empty blocks. */ 812 /* Allocate missing empty blocks. */
813 /* if p_s_Sh == 0 then we are getting a new root */ 813 /* if Sh == 0 then we are getting a new root */
814 n_amount_needed = (p_s_Sh) ? (tb->blknum[n_h] - 1) : 1; 814 n_amount_needed = (Sh) ? (tb->blknum[n_h] - 1) : 1;
815 /* Amount_needed = the amount that we need more than the amount that we have. */ 815 /* Amount_needed = the amount that we need more than the amount that we have. */
816 if (n_amount_needed > n_number_of_freeblk) 816 if (n_amount_needed > n_number_of_freeblk)
817 n_amount_needed -= n_number_of_freeblk; 817 n_amount_needed -= n_number_of_freeblk;
@@ -824,25 +824,25 @@ static int get_empty_nodes(struct tree_balance *tb, int n_h)
824 return NO_DISK_SPACE; 824 return NO_DISK_SPACE;
825 825
826 /* for each blocknumber we just got, get a buffer and stick it on FEB */ 826 /* for each blocknumber we just got, get a buffer and stick it on FEB */
827 for (p_n_blocknr = a_n_blocknrs, n_counter = 0; 827 for (blocknr = a_n_blocknrs, n_counter = 0;
828 n_counter < n_amount_needed; p_n_blocknr++, n_counter++) { 828 n_counter < n_amount_needed; blocknr++, n_counter++) {
829 829
830 RFALSE(!*p_n_blocknr, 830 RFALSE(!*blocknr,
831 "PAP-8135: reiserfs_new_blocknrs failed when got new blocks"); 831 "PAP-8135: reiserfs_new_blocknrs failed when got new blocks");
832 832
833 p_s_new_bh = sb_getblk(sb, *p_n_blocknr); 833 new_bh = sb_getblk(sb, *blocknr);
834 RFALSE(buffer_dirty(p_s_new_bh) || 834 RFALSE(buffer_dirty(new_bh) ||
835 buffer_journaled(p_s_new_bh) || 835 buffer_journaled(new_bh) ||
836 buffer_journal_dirty(p_s_new_bh), 836 buffer_journal_dirty(new_bh),
837 "PAP-8140: journlaled or dirty buffer %b for the new block", 837 "PAP-8140: journlaled or dirty buffer %b for the new block",
838 p_s_new_bh); 838 new_bh);
839 839
840 /* Put empty buffers into the array. */ 840 /* Put empty buffers into the array. */
841 RFALSE(tb->FEB[tb->cur_blknum], 841 RFALSE(tb->FEB[tb->cur_blknum],
842 "PAP-8141: busy slot for new buffer"); 842 "PAP-8141: busy slot for new buffer");
843 843
844 set_buffer_journal_new(p_s_new_bh); 844 set_buffer_journal_new(new_bh);
845 tb->FEB[tb->cur_blknum++] = p_s_new_bh; 845 tb->FEB[tb->cur_blknum++] = new_bh;
846 } 846 }
847 847
848 if (n_retval == CARRY_ON && FILESYSTEM_CHANGED_TB(tb)) 848 if (n_retval == CARRY_ON && FILESYSTEM_CHANGED_TB(tb))
@@ -898,7 +898,7 @@ static int get_rfree(struct tree_balance *tb, int h)
898/* Check whether left neighbor is in memory. */ 898/* Check whether left neighbor is in memory. */
899static int is_left_neighbor_in_cache(struct tree_balance *tb, int n_h) 899static int is_left_neighbor_in_cache(struct tree_balance *tb, int n_h)
900{ 900{
901 struct buffer_head *p_s_father, *left; 901 struct buffer_head *father, *left;
902 struct super_block *sb = tb->tb_sb; 902 struct super_block *sb = tb->tb_sb;
903 b_blocknr_t n_left_neighbor_blocknr; 903 b_blocknr_t n_left_neighbor_blocknr;
904 int n_left_neighbor_position; 904 int n_left_neighbor_position;
@@ -908,18 +908,18 @@ static int is_left_neighbor_in_cache(struct tree_balance *tb, int n_h)
908 return 0; 908 return 0;
909 909
910 /* Calculate father of the node to be balanced. */ 910 /* Calculate father of the node to be balanced. */
911 p_s_father = PATH_H_PBUFFER(tb->tb_path, n_h + 1); 911 father = PATH_H_PBUFFER(tb->tb_path, n_h + 1);
912 912
913 RFALSE(!p_s_father || 913 RFALSE(!father ||
914 !B_IS_IN_TREE(p_s_father) || 914 !B_IS_IN_TREE(father) ||
915 !B_IS_IN_TREE(tb->FL[n_h]) || 915 !B_IS_IN_TREE(tb->FL[n_h]) ||
916 !buffer_uptodate(p_s_father) || 916 !buffer_uptodate(father) ||
917 !buffer_uptodate(tb->FL[n_h]), 917 !buffer_uptodate(tb->FL[n_h]),
918 "vs-8165: F[h] (%b) or FL[h] (%b) is invalid", 918 "vs-8165: F[h] (%b) or FL[h] (%b) is invalid",
919 p_s_father, tb->FL[n_h]); 919 father, tb->FL[n_h]);
920 920
921 /* Get position of the pointer to the left neighbor into the left father. */ 921 /* Get position of the pointer to the left neighbor into the left father. */
922 n_left_neighbor_position = (p_s_father == tb->FL[n_h]) ? 922 n_left_neighbor_position = (father == tb->FL[n_h]) ?
923 tb->lkey[n_h] : B_NR_ITEMS(tb->FL[n_h]); 923 tb->lkey[n_h] : B_NR_ITEMS(tb->FL[n_h]);
924 /* Get left neighbor block number. */ 924 /* Get left neighbor block number. */
925 n_left_neighbor_blocknr = 925 n_left_neighbor_blocknr =
@@ -940,10 +940,10 @@ static int is_left_neighbor_in_cache(struct tree_balance *tb, int n_h)
940#define LEFT_PARENTS 'l' 940#define LEFT_PARENTS 'l'
941#define RIGHT_PARENTS 'r' 941#define RIGHT_PARENTS 'r'
942 942
943static void decrement_key(struct cpu_key *p_s_key) 943static void decrement_key(struct cpu_key *key)
944{ 944{
945 // call item specific function for this key 945 // call item specific function for this key
946 item_ops[cpu_key_k_type(p_s_key)]->decrement_key(p_s_key); 946 item_ops[cpu_key_k_type(key)]->decrement_key(key);
947} 947}
948 948
949/* Calculate far left/right parent of the left/right neighbor of the current node, that 949/* Calculate far left/right parent of the left/right neighbor of the current node, that
@@ -956,17 +956,17 @@ static void decrement_key(struct cpu_key *p_s_key)
956 */ 956 */
957static int get_far_parent(struct tree_balance *tb, 957static int get_far_parent(struct tree_balance *tb,
958 int n_h, 958 int n_h,
959 struct buffer_head **pp_s_father, 959 struct buffer_head **pfather,
960 struct buffer_head **pp_s_com_father, char c_lr_par) 960 struct buffer_head **pcom_father, char c_lr_par)
961{ 961{
962 struct buffer_head *p_s_parent; 962 struct buffer_head *parent;
963 INITIALIZE_PATH(s_path_to_neighbor_father); 963 INITIALIZE_PATH(s_path_to_neighbor_father);
964 struct treepath *p_s_path = tb->tb_path; 964 struct treepath *path = tb->tb_path;
965 struct cpu_key s_lr_father_key; 965 struct cpu_key s_lr_father_key;
966 int n_counter, 966 int n_counter,
967 n_position = INT_MAX, 967 n_position = INT_MAX,
968 n_first_last_position = 0, 968 n_first_last_position = 0,
969 n_path_offset = PATH_H_PATH_OFFSET(p_s_path, n_h); 969 n_path_offset = PATH_H_PATH_OFFSET(path, n_h);
970 970
971 /* Starting from F[n_h] go upwards in the tree, and look for the common 971 /* Starting from F[n_h] go upwards in the tree, and look for the common
972 ancestor of F[n_h], and its neighbor l/r, that should be obtained. */ 972 ancestor of F[n_h], and its neighbor l/r, that should be obtained. */
@@ -979,25 +979,25 @@ static int get_far_parent(struct tree_balance *tb,
979 for (; n_counter > FIRST_PATH_ELEMENT_OFFSET; n_counter--) { 979 for (; n_counter > FIRST_PATH_ELEMENT_OFFSET; n_counter--) {
980 /* Check whether parent of the current buffer in the path is really parent in the tree. */ 980 /* Check whether parent of the current buffer in the path is really parent in the tree. */
981 if (!B_IS_IN_TREE 981 if (!B_IS_IN_TREE
982 (p_s_parent = PATH_OFFSET_PBUFFER(p_s_path, n_counter - 1))) 982 (parent = PATH_OFFSET_PBUFFER(path, n_counter - 1)))
983 return REPEAT_SEARCH; 983 return REPEAT_SEARCH;
984 /* Check whether position in the parent is correct. */ 984 /* Check whether position in the parent is correct. */
985 if ((n_position = 985 if ((n_position =
986 PATH_OFFSET_POSITION(p_s_path, 986 PATH_OFFSET_POSITION(path,
987 n_counter - 1)) > 987 n_counter - 1)) >
988 B_NR_ITEMS(p_s_parent)) 988 B_NR_ITEMS(parent))
989 return REPEAT_SEARCH; 989 return REPEAT_SEARCH;
990 /* Check whether parent at the path really points to the child. */ 990 /* Check whether parent at the path really points to the child. */
991 if (B_N_CHILD_NUM(p_s_parent, n_position) != 991 if (B_N_CHILD_NUM(parent, n_position) !=
992 PATH_OFFSET_PBUFFER(p_s_path, n_counter)->b_blocknr) 992 PATH_OFFSET_PBUFFER(path, n_counter)->b_blocknr)
993 return REPEAT_SEARCH; 993 return REPEAT_SEARCH;
994 /* Return delimiting key if position in the parent is not equal to first/last one. */ 994 /* Return delimiting key if position in the parent is not equal to first/last one. */
995 if (c_lr_par == RIGHT_PARENTS) 995 if (c_lr_par == RIGHT_PARENTS)
996 n_first_last_position = B_NR_ITEMS(p_s_parent); 996 n_first_last_position = B_NR_ITEMS(parent);
997 if (n_position != n_first_last_position) { 997 if (n_position != n_first_last_position) {
998 *pp_s_com_father = p_s_parent; 998 *pcom_father = parent;
999 get_bh(*pp_s_com_father); 999 get_bh(*pcom_father);
1000 /*(*pp_s_com_father = p_s_parent)->b_count++; */ 1000 /*(*pcom_father = parent)->b_count++; */
1001 break; 1001 break;
1002 } 1002 }
1003 } 1003 }
@@ -1009,22 +1009,22 @@ static int get_far_parent(struct tree_balance *tb,
1009 (tb->tb_path, 1009 (tb->tb_path,
1010 FIRST_PATH_ELEMENT_OFFSET)->b_blocknr == 1010 FIRST_PATH_ELEMENT_OFFSET)->b_blocknr ==
1011 SB_ROOT_BLOCK(tb->tb_sb)) { 1011 SB_ROOT_BLOCK(tb->tb_sb)) {
1012 *pp_s_father = *pp_s_com_father = NULL; 1012 *pfather = *pcom_father = NULL;
1013 return CARRY_ON; 1013 return CARRY_ON;
1014 } 1014 }
1015 return REPEAT_SEARCH; 1015 return REPEAT_SEARCH;
1016 } 1016 }
1017 1017
1018 RFALSE(B_LEVEL(*pp_s_com_father) <= DISK_LEAF_NODE_LEVEL, 1018 RFALSE(B_LEVEL(*pcom_father) <= DISK_LEAF_NODE_LEVEL,
1019 "PAP-8185: (%b %z) level too small", 1019 "PAP-8185: (%b %z) level too small",
1020 *pp_s_com_father, *pp_s_com_father); 1020 *pcom_father, *pcom_father);
1021 1021
1022 /* Check whether the common parent is locked. */ 1022 /* Check whether the common parent is locked. */
1023 1023
1024 if (buffer_locked(*pp_s_com_father)) { 1024 if (buffer_locked(*pcom_father)) {
1025 __wait_on_buffer(*pp_s_com_father); 1025 __wait_on_buffer(*pcom_father);
1026 if (FILESYSTEM_CHANGED_TB(tb)) { 1026 if (FILESYSTEM_CHANGED_TB(tb)) {
1027 brelse(*pp_s_com_father); 1027 brelse(*pcom_father);
1028 return REPEAT_SEARCH; 1028 return REPEAT_SEARCH;
1029 } 1029 }
1030 } 1030 }
@@ -1034,7 +1034,7 @@ static int get_far_parent(struct tree_balance *tb,
1034 1034
1035 /* Form key to get parent of the left/right neighbor. */ 1035 /* Form key to get parent of the left/right neighbor. */
1036 le_key2cpu_key(&s_lr_father_key, 1036 le_key2cpu_key(&s_lr_father_key,
1037 B_N_PDELIM_KEY(*pp_s_com_father, 1037 B_N_PDELIM_KEY(*pcom_father,
1038 (c_lr_par == 1038 (c_lr_par ==
1039 LEFT_PARENTS) ? (tb->lkey[n_h - 1] = 1039 LEFT_PARENTS) ? (tb->lkey[n_h - 1] =
1040 n_position - 1040 n_position -
@@ -1053,14 +1053,14 @@ static int get_far_parent(struct tree_balance *tb,
1053 1053
1054 if (FILESYSTEM_CHANGED_TB(tb)) { 1054 if (FILESYSTEM_CHANGED_TB(tb)) {
1055 pathrelse(&s_path_to_neighbor_father); 1055 pathrelse(&s_path_to_neighbor_father);
1056 brelse(*pp_s_com_father); 1056 brelse(*pcom_father);
1057 return REPEAT_SEARCH; 1057 return REPEAT_SEARCH;
1058 } 1058 }
1059 1059
1060 *pp_s_father = PATH_PLAST_BUFFER(&s_path_to_neighbor_father); 1060 *pfather = PATH_PLAST_BUFFER(&s_path_to_neighbor_father);
1061 1061
1062 RFALSE(B_LEVEL(*pp_s_father) != n_h + 1, 1062 RFALSE(B_LEVEL(*pfather) != n_h + 1,
1063 "PAP-8190: (%b %z) level too small", *pp_s_father, *pp_s_father); 1063 "PAP-8190: (%b %z) level too small", *pfather, *pfather);
1064 RFALSE(s_path_to_neighbor_father.path_length < 1064 RFALSE(s_path_to_neighbor_father.path_length <
1065 FIRST_PATH_ELEMENT_OFFSET, "PAP-8192: path length is too small"); 1065 FIRST_PATH_ELEMENT_OFFSET, "PAP-8192: path length is too small");
1066 1066
@@ -1078,11 +1078,11 @@ static int get_far_parent(struct tree_balance *tb,
1078 */ 1078 */
1079static int get_parents(struct tree_balance *tb, int n_h) 1079static int get_parents(struct tree_balance *tb, int n_h)
1080{ 1080{
1081 struct treepath *p_s_path = tb->tb_path; 1081 struct treepath *path = tb->tb_path;
1082 int n_position, 1082 int n_position,
1083 n_ret_value, 1083 n_ret_value,
1084 n_path_offset = PATH_H_PATH_OFFSET(tb->tb_path, n_h); 1084 n_path_offset = PATH_H_PATH_OFFSET(tb->tb_path, n_h);
1085 struct buffer_head *p_s_curf, *p_s_curcf; 1085 struct buffer_head *curf, *curcf;
1086 1086
1087 /* Current node is the root of the tree or will be root of the tree */ 1087 /* Current node is the root of the tree or will be root of the tree */
1088 if (n_path_offset <= FIRST_PATH_ELEMENT_OFFSET) { 1088 if (n_path_offset <= FIRST_PATH_ELEMENT_OFFSET) {
@@ -1100,66 +1100,65 @@ static int get_parents(struct tree_balance *tb, int n_h)
1100 } 1100 }
1101 1101
1102 /* Get parent FL[n_path_offset] of L[n_path_offset]. */ 1102 /* Get parent FL[n_path_offset] of L[n_path_offset]. */
1103 if ((n_position = PATH_OFFSET_POSITION(p_s_path, n_path_offset - 1))) { 1103 n_position = PATH_OFFSET_POSITION(path, n_path_offset - 1);
1104 if (n_position) {
1104 /* Current node is not the first child of its parent. */ 1105 /* Current node is not the first child of its parent. */
1105 /*(p_s_curf = p_s_curcf = PATH_OFFSET_PBUFFER(p_s_path, n_path_offset - 1))->b_count += 2; */ 1106 curf = PATH_OFFSET_PBUFFER(path, n_path_offset - 1);
1106 p_s_curf = p_s_curcf = 1107 curcf = PATH_OFFSET_PBUFFER(path, n_path_offset - 1);
1107 PATH_OFFSET_PBUFFER(p_s_path, n_path_offset - 1); 1108 get_bh(curf);
1108 get_bh(p_s_curf); 1109 get_bh(curf);
1109 get_bh(p_s_curf);
1110 tb->lkey[n_h] = n_position - 1; 1110 tb->lkey[n_h] = n_position - 1;
1111 } else { 1111 } else {
1112 /* Calculate current parent of L[n_path_offset], which is the left neighbor of the current node. 1112 /* Calculate current parent of L[n_path_offset], which is the left neighbor of the current node.
1113 Calculate current common parent of L[n_path_offset] and the current node. Note that 1113 Calculate current common parent of L[n_path_offset] and the current node. Note that
1114 CFL[n_path_offset] not equal FL[n_path_offset] and CFL[n_path_offset] not equal F[n_path_offset]. 1114 CFL[n_path_offset] not equal FL[n_path_offset] and CFL[n_path_offset] not equal F[n_path_offset].
1115 Calculate lkey[n_path_offset]. */ 1115 Calculate lkey[n_path_offset]. */
1116 if ((n_ret_value = get_far_parent(tb, n_h + 1, &p_s_curf, 1116 if ((n_ret_value = get_far_parent(tb, n_h + 1, &curf,
1117 &p_s_curcf, 1117 &curcf,
1118 LEFT_PARENTS)) != CARRY_ON) 1118 LEFT_PARENTS)) != CARRY_ON)
1119 return n_ret_value; 1119 return n_ret_value;
1120 } 1120 }
1121 1121
1122 brelse(tb->FL[n_h]); 1122 brelse(tb->FL[n_h]);
1123 tb->FL[n_h] = p_s_curf; /* New initialization of FL[n_h]. */ 1123 tb->FL[n_h] = curf; /* New initialization of FL[n_h]. */
1124 brelse(tb->CFL[n_h]); 1124 brelse(tb->CFL[n_h]);
1125 tb->CFL[n_h] = p_s_curcf; /* New initialization of CFL[n_h]. */ 1125 tb->CFL[n_h] = curcf; /* New initialization of CFL[n_h]. */
1126 1126
1127 RFALSE((p_s_curf && !B_IS_IN_TREE(p_s_curf)) || 1127 RFALSE((curf && !B_IS_IN_TREE(curf)) ||
1128 (p_s_curcf && !B_IS_IN_TREE(p_s_curcf)), 1128 (curcf && !B_IS_IN_TREE(curcf)),
1129 "PAP-8195: FL (%b) or CFL (%b) is invalid", p_s_curf, p_s_curcf); 1129 "PAP-8195: FL (%b) or CFL (%b) is invalid", curf, curcf);
1130 1130
1131/* Get parent FR[n_h] of R[n_h]. */ 1131/* Get parent FR[n_h] of R[n_h]. */
1132 1132
1133/* Current node is the last child of F[n_h]. FR[n_h] != F[n_h]. */ 1133/* Current node is the last child of F[n_h]. FR[n_h] != F[n_h]. */
1134 if (n_position == B_NR_ITEMS(PATH_H_PBUFFER(p_s_path, n_h + 1))) { 1134 if (n_position == B_NR_ITEMS(PATH_H_PBUFFER(path, n_h + 1))) {
1135/* Calculate current parent of R[n_h], which is the right neighbor of F[n_h]. 1135/* Calculate current parent of R[n_h], which is the right neighbor of F[n_h].
1136 Calculate current common parent of R[n_h] and current node. Note that CFR[n_h] 1136 Calculate current common parent of R[n_h] and current node. Note that CFR[n_h]
1137 not equal FR[n_path_offset] and CFR[n_h] not equal F[n_h]. */ 1137 not equal FR[n_path_offset] and CFR[n_h] not equal F[n_h]. */
1138 if ((n_ret_value = 1138 if ((n_ret_value =
1139 get_far_parent(tb, n_h + 1, &p_s_curf, &p_s_curcf, 1139 get_far_parent(tb, n_h + 1, &curf, &curcf,
1140 RIGHT_PARENTS)) != CARRY_ON) 1140 RIGHT_PARENTS)) != CARRY_ON)
1141 return n_ret_value; 1141 return n_ret_value;
1142 } else { 1142 } else {
1143/* Current node is not the last child of its parent F[n_h]. */ 1143/* Current node is not the last child of its parent F[n_h]. */
1144 /*(p_s_curf = p_s_curcf = PATH_OFFSET_PBUFFER(p_s_path, n_path_offset - 1))->b_count += 2; */ 1144 curf = PATH_OFFSET_PBUFFER(path, n_path_offset - 1);
1145 p_s_curf = p_s_curcf = 1145 curcf = PATH_OFFSET_PBUFFER(path, n_path_offset - 1);
1146 PATH_OFFSET_PBUFFER(p_s_path, n_path_offset - 1); 1146 get_bh(curf);
1147 get_bh(p_s_curf); 1147 get_bh(curf);
1148 get_bh(p_s_curf);
1149 tb->rkey[n_h] = n_position; 1148 tb->rkey[n_h] = n_position;
1150 } 1149 }
1151 1150
1152 brelse(tb->FR[n_h]); 1151 brelse(tb->FR[n_h]);
1153 /* New initialization of FR[n_path_offset]. */ 1152 /* New initialization of FR[n_path_offset]. */
1154 tb->FR[n_h] = p_s_curf; 1153 tb->FR[n_h] = curf;
1155 1154
1156 brelse(tb->CFR[n_h]); 1155 brelse(tb->CFR[n_h]);
1157 /* New initialization of CFR[n_path_offset]. */ 1156 /* New initialization of CFR[n_path_offset]. */
1158 tb->CFR[n_h] = p_s_curcf; 1157 tb->CFR[n_h] = curcf;
1159 1158
1160 RFALSE((p_s_curf && !B_IS_IN_TREE(p_s_curf)) || 1159 RFALSE((curf && !B_IS_IN_TREE(curf)) ||
1161 (p_s_curcf && !B_IS_IN_TREE(p_s_curcf)), 1160 (curcf && !B_IS_IN_TREE(curcf)),
1162 "PAP-8205: FR (%b) or CFR (%b) is invalid", p_s_curf, p_s_curcf); 1161 "PAP-8205: FR (%b) or CFR (%b) is invalid", curf, curcf);
1163 1162
1164 return CARRY_ON; 1163 return CARRY_ON;
1165} 1164}
@@ -1893,7 +1892,7 @@ static int check_balance(int mode,
1893static int get_direct_parent(struct tree_balance *tb, int n_h) 1892static int get_direct_parent(struct tree_balance *tb, int n_h)
1894{ 1893{
1895 struct buffer_head *bh; 1894 struct buffer_head *bh;
1896 struct treepath *p_s_path = tb->tb_path; 1895 struct treepath *path = tb->tb_path;
1897 int n_position, 1896 int n_position,
1898 n_path_offset = PATH_H_PATH_OFFSET(tb->tb_path, n_h); 1897 n_path_offset = PATH_H_PATH_OFFSET(tb->tb_path, n_h);
1899 1898
@@ -1903,27 +1902,27 @@ static int get_direct_parent(struct tree_balance *tb, int n_h)
1903 RFALSE(n_path_offset < FIRST_PATH_ELEMENT_OFFSET - 1, 1902 RFALSE(n_path_offset < FIRST_PATH_ELEMENT_OFFSET - 1,
1904 "PAP-8260: invalid offset in the path"); 1903 "PAP-8260: invalid offset in the path");
1905 1904
1906 if (PATH_OFFSET_PBUFFER(p_s_path, FIRST_PATH_ELEMENT_OFFSET)-> 1905 if (PATH_OFFSET_PBUFFER(path, FIRST_PATH_ELEMENT_OFFSET)->
1907 b_blocknr == SB_ROOT_BLOCK(tb->tb_sb)) { 1906 b_blocknr == SB_ROOT_BLOCK(tb->tb_sb)) {
1908 /* Root is not changed. */ 1907 /* Root is not changed. */
1909 PATH_OFFSET_PBUFFER(p_s_path, n_path_offset - 1) = NULL; 1908 PATH_OFFSET_PBUFFER(path, n_path_offset - 1) = NULL;
1910 PATH_OFFSET_POSITION(p_s_path, n_path_offset - 1) = 0; 1909 PATH_OFFSET_POSITION(path, n_path_offset - 1) = 0;
1911 return CARRY_ON; 1910 return CARRY_ON;
1912 } 1911 }
1913 return REPEAT_SEARCH; /* Root is changed and we must recalculate the path. */ 1912 return REPEAT_SEARCH; /* Root is changed and we must recalculate the path. */
1914 } 1913 }
1915 1914
1916 if (!B_IS_IN_TREE 1915 if (!B_IS_IN_TREE
1917 (bh = PATH_OFFSET_PBUFFER(p_s_path, n_path_offset - 1))) 1916 (bh = PATH_OFFSET_PBUFFER(path, n_path_offset - 1)))
1918 return REPEAT_SEARCH; /* Parent in the path is not in the tree. */ 1917 return REPEAT_SEARCH; /* Parent in the path is not in the tree. */
1919 1918
1920 if ((n_position = 1919 if ((n_position =
1921 PATH_OFFSET_POSITION(p_s_path, 1920 PATH_OFFSET_POSITION(path,
1922 n_path_offset - 1)) > B_NR_ITEMS(bh)) 1921 n_path_offset - 1)) > B_NR_ITEMS(bh))
1923 return REPEAT_SEARCH; 1922 return REPEAT_SEARCH;
1924 1923
1925 if (B_N_CHILD_NUM(bh, n_position) != 1924 if (B_N_CHILD_NUM(bh, n_position) !=
1926 PATH_OFFSET_PBUFFER(p_s_path, n_path_offset)->b_blocknr) 1925 PATH_OFFSET_PBUFFER(path, n_path_offset)->b_blocknr)
1927 /* Parent in the path is not parent of the current node in the tree. */ 1926 /* Parent in the path is not parent of the current node in the tree. */
1928 return REPEAT_SEARCH; 1927 return REPEAT_SEARCH;
1929 1928
@@ -2319,7 +2318,7 @@ static int wait_tb_buffers_until_unlocked(struct tree_balance *tb)
2319 */ 2318 */
2320 2319
2321int fix_nodes(int n_op_mode, struct tree_balance *tb, 2320int fix_nodes(int n_op_mode, struct tree_balance *tb,
2322 struct item_head *p_s_ins_ih, const void *data) 2321 struct item_head *ins_ih, const void *data)
2323{ 2322{
2324 int n_ret_value, n_h, n_item_num = PATH_LAST_POSITION(tb->tb_path); 2323 int n_ret_value, n_h, n_item_num = PATH_LAST_POSITION(tb->tb_path);
2325 int n_pos_in_item; 2324 int n_pos_in_item;
@@ -2405,7 +2404,7 @@ int fix_nodes(int n_op_mode, struct tree_balance *tb,
2405 goto repeat; 2404 goto repeat;
2406 2405
2407 n_ret_value = check_balance(n_op_mode, tb, n_h, n_item_num, 2406 n_ret_value = check_balance(n_op_mode, tb, n_h, n_item_num,
2408 n_pos_in_item, p_s_ins_ih, data); 2407 n_pos_in_item, ins_ih, data);
2409 if (n_ret_value != CARRY_ON) { 2408 if (n_ret_value != CARRY_ON) {
2410 if (n_ret_value == NO_BALANCING_NEEDED) { 2409 if (n_ret_value == NO_BALANCING_NEEDED) {
2411 /* No balancing for higher levels needed. */ 2410 /* No balancing for higher levels needed. */
diff --git a/fs/reiserfs/stree.c b/fs/reiserfs/stree.c
index 5e867be559ea..fd769c8dac32 100644
--- a/fs/reiserfs/stree.c
+++ b/fs/reiserfs/stree.c
@@ -68,10 +68,10 @@ inline int B_IS_IN_TREE(const struct buffer_head *bh)
68// 68//
69// to gets item head in le form 69// to gets item head in le form
70// 70//
71inline void copy_item_head(struct item_head *p_v_to, 71inline void copy_item_head(struct item_head *to,
72 const struct item_head *p_v_from) 72 const struct item_head *from)
73{ 73{
74 memcpy(p_v_to, p_v_from, IH_SIZE); 74 memcpy(to, from, IH_SIZE);
75} 75}
76 76
77/* k1 is pointer to on-disk structure which is stored in little-endian 77/* k1 is pointer to on-disk structure which is stored in little-endian
@@ -135,15 +135,15 @@ static inline int comp_keys(const struct reiserfs_key *le_key,
135inline int comp_short_le_keys(const struct reiserfs_key *key1, 135inline 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 *p_s_1_u32, *p_s_2_u32; 138 __u32 *k1_u32, *k2_u32;
139 int n_key_length = REISERFS_SHORT_KEY_LEN; 139 int n_key_length = REISERFS_SHORT_KEY_LEN;
140 140
141 p_s_1_u32 = (__u32 *) key1; 141 k1_u32 = (__u32 *) key1;
142 p_s_2_u32 = (__u32 *) key2; 142 k2_u32 = (__u32 *) key2;
143 for (; n_key_length--; ++p_s_1_u32, ++p_s_2_u32) { 143 for (; n_key_length--; ++k1_u32, ++k2_u32) {
144 if (le32_to_cpu(*p_s_1_u32) < le32_to_cpu(*p_s_2_u32)) 144 if (le32_to_cpu(*k1_u32) < le32_to_cpu(*k2_u32))
145 return -1; 145 return -1;
146 if (le32_to_cpu(*p_s_1_u32) > le32_to_cpu(*p_s_2_u32)) 146 if (le32_to_cpu(*k1_u32) > le32_to_cpu(*k2_u32))
147 return 1; 147 return 1;
148 } 148 }
149 return 0; 149 return 0;
@@ -174,8 +174,8 @@ inline int comp_le_keys(const struct reiserfs_key *k1,
174 * Binary search toolkit function * 174 * Binary search toolkit function *
175 * Search for an item in the array by the item key * 175 * Search for an item in the array by the item key *
176 * Returns: 1 if found, 0 if not found; * 176 * Returns: 1 if found, 0 if not found; *
177 * *p_n_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 p_v_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: n_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, n_rbound the rightmost item that it could be. We examine the item
@@ -184,28 +184,28 @@ inline int comp_le_keys(const struct reiserfs_key *k1,
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. */
187static inline int bin_search(const void *p_v_key, /* Key to search for. */ 187static inline int bin_search(const void *key, /* Key to search for. */
188 const void *p_v_base, /* First item in the array. */ 188 const void *base, /* First item in the array. */
189 int p_n_num, /* Number of items in the array. */ 189 int num, /* Number of items in the array. */
190 int p_n_width, /* Item size in the array. 190 int width, /* Item size in the array.
191 searched. Lest the reader be 191 searched. Lest the reader be
192 confused, note that this is crafted 192 confused, note that this is crafted
193 as a general function, and when it 193 as a general function, and when it
194 is applied specifically to the array 194 is applied specifically to the array
195 of item headers in a node, p_n_width 195 of item headers in a node, width
196 is actually the item header size not 196 is actually the item header size not
197 the item size. */ 197 the item size. */
198 int *p_n_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 n_rbound, n_lbound, n_j;
202 202
203 for (n_j = ((n_rbound = p_n_num - 1) + (n_lbound = 0)) / 2; 203 for (n_j = ((n_rbound = num - 1) + (n_lbound = 0)) / 2;
204 n_lbound <= n_rbound; n_j = (n_rbound + n_lbound) / 2) 204 n_lbound <= n_rbound; n_j = (n_rbound + n_lbound) / 2)
205 switch (comp_keys 205 switch (comp_keys
206 ((struct reiserfs_key *)((char *)p_v_base + 206 ((struct reiserfs_key *)((char *)base +
207 n_j * p_n_width), 207 n_j * width),
208 (struct cpu_key *)p_v_key)) { 208 (struct cpu_key *)key)) {
209 case -1: 209 case -1:
210 n_lbound = n_j + 1; 210 n_lbound = n_j + 1;
211 continue; 211 continue;
@@ -213,13 +213,13 @@ static inline int bin_search(const void *p_v_key, /* Key to search for.
213 n_rbound = n_j - 1; 213 n_rbound = n_j - 1;
214 continue; 214 continue;
215 case 0: 215 case 0:
216 *p_n_pos = n_j; 216 *pos = n_j;
217 return ITEM_FOUND; /* Key found in the array. */ 217 return ITEM_FOUND; /* Key found in the array. */
218 } 218 }
219 219
220 /* bin_search did not find given key, it returns position of key, 220 /* bin_search did not find given key, it returns position of key,
221 that is minimal and greater than the given one. */ 221 that is minimal and greater than the given one. */
222 *p_n_pos = n_lbound; 222 *pos = n_lbound;
223 return ITEM_NOT_FOUND; 223 return ITEM_NOT_FOUND;
224} 224}
225 225
@@ -243,12 +243,12 @@ static const struct reiserfs_key MAX_KEY = {
243 the path, there is no delimiting key in the tree (buffer is first or last buffer in tree), and in this 243 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. */ 244 case we return a special key, either MIN_KEY or MAX_KEY. */
245static inline const struct reiserfs_key *get_lkey(const struct treepath 245static inline const struct reiserfs_key *get_lkey(const struct treepath
246 *p_s_chk_path, 246 *chk_path,
247 const struct super_block 247 const struct super_block
248 *sb) 248 *sb)
249{ 249{
250 int n_position, n_path_offset = p_s_chk_path->path_length; 250 int n_position, n_path_offset = chk_path->path_length;
251 struct buffer_head *p_s_parent; 251 struct buffer_head *parent;
252 252
253 RFALSE(n_path_offset < FIRST_PATH_ELEMENT_OFFSET, 253 RFALSE(n_path_offset < FIRST_PATH_ELEMENT_OFFSET,
254 "PAP-5010: invalid offset in the path"); 254 "PAP-5010: invalid offset in the path");
@@ -257,42 +257,42 @@ static inline const struct reiserfs_key *get_lkey(const struct treepath
257 while (n_path_offset-- > FIRST_PATH_ELEMENT_OFFSET) { 257 while (n_path_offset-- > FIRST_PATH_ELEMENT_OFFSET) {
258 258
259 RFALSE(!buffer_uptodate 259 RFALSE(!buffer_uptodate
260 (PATH_OFFSET_PBUFFER(p_s_chk_path, n_path_offset)), 260 (PATH_OFFSET_PBUFFER(chk_path, n_path_offset)),
261 "PAP-5020: parent is not uptodate"); 261 "PAP-5020: parent is not uptodate");
262 262
263 /* Parent at the path is not in the tree now. */ 263 /* Parent at the path is not in the tree now. */
264 if (!B_IS_IN_TREE 264 if (!B_IS_IN_TREE
265 (p_s_parent = 265 (parent =
266 PATH_OFFSET_PBUFFER(p_s_chk_path, n_path_offset))) 266 PATH_OFFSET_PBUFFER(chk_path, n_path_offset)))
267 return &MAX_KEY; 267 return &MAX_KEY;
268 /* Check whether position in the parent is correct. */ 268 /* Check whether position in the parent is correct. */
269 if ((n_position = 269 if ((n_position =
270 PATH_OFFSET_POSITION(p_s_chk_path, 270 PATH_OFFSET_POSITION(chk_path,
271 n_path_offset)) > 271 n_path_offset)) >
272 B_NR_ITEMS(p_s_parent)) 272 B_NR_ITEMS(parent))
273 return &MAX_KEY; 273 return &MAX_KEY;
274 /* Check whether parent at the path really points to the child. */ 274 /* Check whether parent at the path really points to the child. */
275 if (B_N_CHILD_NUM(p_s_parent, n_position) != 275 if (B_N_CHILD_NUM(parent, n_position) !=
276 PATH_OFFSET_PBUFFER(p_s_chk_path, 276 PATH_OFFSET_PBUFFER(chk_path,
277 n_path_offset + 1)->b_blocknr) 277 n_path_offset + 1)->b_blocknr)
278 return &MAX_KEY; 278 return &MAX_KEY;
279 /* Return delimiting key if position in the parent is not equal to zero. */ 279 /* Return delimiting key if position in the parent is not equal to zero. */
280 if (n_position) 280 if (n_position)
281 return B_N_PDELIM_KEY(p_s_parent, n_position - 1); 281 return B_N_PDELIM_KEY(parent, n_position - 1);
282 } 282 }
283 /* Return MIN_KEY if we are in the root of the buffer tree. */ 283 /* Return MIN_KEY if we are in the root of the buffer tree. */
284 if (PATH_OFFSET_PBUFFER(p_s_chk_path, FIRST_PATH_ELEMENT_OFFSET)-> 284 if (PATH_OFFSET_PBUFFER(chk_path, FIRST_PATH_ELEMENT_OFFSET)->
285 b_blocknr == SB_ROOT_BLOCK(sb)) 285 b_blocknr == SB_ROOT_BLOCK(sb))
286 return &MIN_KEY; 286 return &MIN_KEY;
287 return &MAX_KEY; 287 return &MAX_KEY;
288} 288}
289 289
290/* Get delimiting key of the buffer at the path and its right neighbor. */ 290/* Get delimiting key of the buffer at the path and its right neighbor. */
291inline const struct reiserfs_key *get_rkey(const struct treepath *p_s_chk_path, 291inline const struct reiserfs_key *get_rkey(const struct treepath *chk_path,
292 const struct super_block *sb) 292 const struct super_block *sb)
293{ 293{
294 int n_position, n_path_offset = p_s_chk_path->path_length; 294 int n_position, n_path_offset = chk_path->path_length;
295 struct buffer_head *p_s_parent; 295 struct buffer_head *parent;
296 296
297 RFALSE(n_path_offset < FIRST_PATH_ELEMENT_OFFSET, 297 RFALSE(n_path_offset < FIRST_PATH_ELEMENT_OFFSET,
298 "PAP-5030: invalid offset in the path"); 298 "PAP-5030: invalid offset in the path");
@@ -300,31 +300,31 @@ inline const struct reiserfs_key *get_rkey(const struct treepath *p_s_chk_path,
300 while (n_path_offset-- > FIRST_PATH_ELEMENT_OFFSET) { 300 while (n_path_offset-- > FIRST_PATH_ELEMENT_OFFSET) {
301 301
302 RFALSE(!buffer_uptodate 302 RFALSE(!buffer_uptodate
303 (PATH_OFFSET_PBUFFER(p_s_chk_path, n_path_offset)), 303 (PATH_OFFSET_PBUFFER(chk_path, n_path_offset)),
304 "PAP-5040: parent is not uptodate"); 304 "PAP-5040: parent is not uptodate");
305 305
306 /* Parent at the path is not in the tree now. */ 306 /* Parent at the path is not in the tree now. */
307 if (!B_IS_IN_TREE 307 if (!B_IS_IN_TREE
308 (p_s_parent = 308 (parent =
309 PATH_OFFSET_PBUFFER(p_s_chk_path, n_path_offset))) 309 PATH_OFFSET_PBUFFER(chk_path, n_path_offset)))
310 return &MIN_KEY; 310 return &MIN_KEY;
311 /* Check whether position in the parent is correct. */ 311 /* Check whether position in the parent is correct. */
312 if ((n_position = 312 if ((n_position =
313 PATH_OFFSET_POSITION(p_s_chk_path, 313 PATH_OFFSET_POSITION(chk_path,
314 n_path_offset)) > 314 n_path_offset)) >
315 B_NR_ITEMS(p_s_parent)) 315 B_NR_ITEMS(parent))
316 return &MIN_KEY; 316 return &MIN_KEY;
317 /* Check whether parent at the path really points to the child. */ 317 /* Check whether parent at the path really points to the child. */
318 if (B_N_CHILD_NUM(p_s_parent, n_position) != 318 if (B_N_CHILD_NUM(parent, n_position) !=
319 PATH_OFFSET_PBUFFER(p_s_chk_path, 319 PATH_OFFSET_PBUFFER(chk_path,
320 n_path_offset + 1)->b_blocknr) 320 n_path_offset + 1)->b_blocknr)
321 return &MIN_KEY; 321 return &MIN_KEY;
322 /* Return delimiting key if position in the parent is not the last one. */ 322 /* Return delimiting key if position in the parent is not the last one. */
323 if (n_position != B_NR_ITEMS(p_s_parent)) 323 if (n_position != B_NR_ITEMS(parent))
324 return B_N_PDELIM_KEY(p_s_parent, n_position); 324 return B_N_PDELIM_KEY(parent, n_position);
325 } 325 }
326 /* Return MAX_KEY if we are in the root of the buffer tree. */ 326 /* Return MAX_KEY if we are in the root of the buffer tree. */
327 if (PATH_OFFSET_PBUFFER(p_s_chk_path, FIRST_PATH_ELEMENT_OFFSET)-> 327 if (PATH_OFFSET_PBUFFER(chk_path, FIRST_PATH_ELEMENT_OFFSET)->
328 b_blocknr == SB_ROOT_BLOCK(sb)) 328 b_blocknr == SB_ROOT_BLOCK(sb))
329 return &MAX_KEY; 329 return &MAX_KEY;
330 return &MIN_KEY; 330 return &MIN_KEY;
@@ -335,25 +335,25 @@ inline const struct reiserfs_key *get_rkey(const struct treepath *p_s_chk_path,
335 the path. These delimiting keys are stored at least one level above that buffer in the tree. If the 335 the path. These delimiting keys are stored at least one level above that buffer in the tree. If the
336 buffer is the first or last node in the tree order then one of the delimiting keys may be absent, and in 336 buffer is the first or last node in the tree order then one of the delimiting keys may be absent, and in
337 this case get_lkey and get_rkey return a special key which is MIN_KEY or MAX_KEY. */ 337 this case get_lkey and get_rkey return a special key which is MIN_KEY or MAX_KEY. */
338static inline int key_in_buffer(struct treepath *p_s_chk_path, /* Path which should be checked. */ 338static inline int key_in_buffer(struct treepath *chk_path, /* Path which should be checked. */
339 const struct cpu_key *p_s_key, /* Key which should be checked. */ 339 const struct cpu_key *key, /* Key which should be checked. */
340 struct super_block *sb /* Super block pointer. */ 340 struct super_block *sb
341 ) 341 )
342{ 342{
343 343
344 RFALSE(!p_s_key || p_s_chk_path->path_length < FIRST_PATH_ELEMENT_OFFSET 344 RFALSE(!key || chk_path->path_length < FIRST_PATH_ELEMENT_OFFSET
345 || p_s_chk_path->path_length > MAX_HEIGHT, 345 || chk_path->path_length > MAX_HEIGHT,
346 "PAP-5050: pointer to the key(%p) is NULL or invalid path length(%d)", 346 "PAP-5050: pointer to the key(%p) is NULL or invalid path length(%d)",
347 p_s_key, p_s_chk_path->path_length); 347 key, chk_path->path_length);
348 RFALSE(!PATH_PLAST_BUFFER(p_s_chk_path)->b_bdev, 348 RFALSE(!PATH_PLAST_BUFFER(chk_path)->b_bdev,
349 "PAP-5060: device must not be NODEV"); 349 "PAP-5060: device must not be NODEV");
350 350
351 if (comp_keys(get_lkey(p_s_chk_path, sb), p_s_key) == 1) 351 if (comp_keys(get_lkey(chk_path, sb), key) == 1)
352 /* left delimiting key is bigger, that the key we look for */ 352 /* left delimiting key is bigger, that the key we look for */
353 return 0; 353 return 0;
354 // if ( comp_keys(p_s_key, get_rkey(p_s_chk_path, sb)) != -1 ) 354 /* if ( comp_keys(key, get_rkey(chk_path, sb)) != -1 ) */
355 if (comp_keys(get_rkey(p_s_chk_path, sb), p_s_key) != 1) 355 if (comp_keys(get_rkey(chk_path, sb), key) != 1)
356 /* p_s_key must be less than right delimitiing key */ 356 /* key must be less than right delimitiing key */
357 return 0; 357 return 0;
358 return 1; 358 return 1;
359} 359}
@@ -369,34 +369,34 @@ int reiserfs_check_path(struct treepath *p)
369 * dirty bits clean when preparing the buffer for the log. 369 * dirty bits clean when preparing the buffer for the log.
370 * This version should only be called from fix_nodes() */ 370 * This version should only be called from fix_nodes() */
371void pathrelse_and_restore(struct super_block *sb, 371void pathrelse_and_restore(struct super_block *sb,
372 struct treepath *p_s_search_path) 372 struct treepath *search_path)
373{ 373{
374 int n_path_offset = p_s_search_path->path_length; 374 int n_path_offset = search_path->path_length;
375 375
376 RFALSE(n_path_offset < ILLEGAL_PATH_ELEMENT_OFFSET, 376 RFALSE(n_path_offset < ILLEGAL_PATH_ELEMENT_OFFSET,
377 "clm-4000: invalid path offset"); 377 "clm-4000: invalid path offset");
378 378
379 while (n_path_offset > ILLEGAL_PATH_ELEMENT_OFFSET) { 379 while (n_path_offset > ILLEGAL_PATH_ELEMENT_OFFSET) {
380 struct buffer_head *bh; 380 struct buffer_head *bh;
381 bh = PATH_OFFSET_PBUFFER(p_s_search_path, n_path_offset--); 381 bh = PATH_OFFSET_PBUFFER(search_path, n_path_offset--);
382 reiserfs_restore_prepared_buffer(sb, bh); 382 reiserfs_restore_prepared_buffer(sb, bh);
383 brelse(bh); 383 brelse(bh);
384 } 384 }
385 p_s_search_path->path_length = ILLEGAL_PATH_ELEMENT_OFFSET; 385 search_path->path_length = ILLEGAL_PATH_ELEMENT_OFFSET;
386} 386}
387 387
388/* Drop the reference to each buffer in a path */ 388/* Drop the reference to each buffer in a path */
389void pathrelse(struct treepath *p_s_search_path) 389void pathrelse(struct treepath *search_path)
390{ 390{
391 int n_path_offset = p_s_search_path->path_length; 391 int n_path_offset = search_path->path_length;
392 392
393 RFALSE(n_path_offset < ILLEGAL_PATH_ELEMENT_OFFSET, 393 RFALSE(n_path_offset < ILLEGAL_PATH_ELEMENT_OFFSET,
394 "PAP-5090: invalid path offset"); 394 "PAP-5090: invalid path offset");
395 395
396 while (n_path_offset > ILLEGAL_PATH_ELEMENT_OFFSET) 396 while (n_path_offset > ILLEGAL_PATH_ELEMENT_OFFSET)
397 brelse(PATH_OFFSET_PBUFFER(p_s_search_path, n_path_offset--)); 397 brelse(PATH_OFFSET_PBUFFER(search_path, n_path_offset--));
398 398
399 p_s_search_path->path_length = ILLEGAL_PATH_ELEMENT_OFFSET; 399 search_path->path_length = ILLEGAL_PATH_ELEMENT_OFFSET;
400} 400}
401 401
402static int is_leaf(char *buf, int blocksize, struct buffer_head *bh) 402static int is_leaf(char *buf, int blocksize, struct buffer_head *bh)
@@ -547,9 +547,9 @@ static void search_by_key_reada(struct super_block *s,
547 * Algorithm SearchByKey * 547 * Algorithm SearchByKey *
548 * look for item in the Disk S+Tree by its key * 548 * look for item in the Disk S+Tree by its key *
549 * Input: sb - super block * 549 * Input: sb - super block *
550 * p_s_key - pointer to the key to search * 550 * key - pointer to the key to search *
551 * Output: ITEM_FOUND, ITEM_NOT_FOUND or IO_ERROR * 551 * Output: ITEM_FOUND, ITEM_NOT_FOUND or IO_ERROR *
552 * p_s_search_path - path from the root to the needed leaf * 552 * search_path - path from the root to the needed leaf *
553 **************************************************************************/ 553 **************************************************************************/
554 554
555/* This function fills up the path from the root to the leaf as it 555/* This function fills up the path from the root to the leaf as it
@@ -566,8 +566,8 @@ static void search_by_key_reada(struct super_block *s,
566 correctness of the top of the path but need not be checked for the 566 correctness of the top of the path but need not be checked for the
567 correctness of the bottom of the path */ 567 correctness of the bottom of the path */
568/* The function is NOT SCHEDULE-SAFE! */ 568/* The function is NOT SCHEDULE-SAFE! */
569int search_by_key(struct super_block *sb, const struct cpu_key *p_s_key, /* Key to search. */ 569int search_by_key(struct super_block *sb, const struct cpu_key *key, /* Key to search. */
570 struct treepath *p_s_search_path,/* This structure was 570 struct treepath *search_path,/* This structure was
571 allocated and initialized 571 allocated and initialized
572 by the calling 572 by the calling
573 function. It is filled up 573 function. It is filled up
@@ -580,7 +580,7 @@ int search_by_key(struct super_block *sb, const struct cpu_key *p_s_key, /* Key
580 b_blocknr_t n_block_number; 580 b_blocknr_t n_block_number;
581 int expected_level; 581 int expected_level;
582 struct buffer_head *bh; 582 struct buffer_head *bh;
583 struct path_element *p_s_last_element; 583 struct path_element *last_element;
584 int n_node_level, n_retval; 584 int n_node_level, n_retval;
585 int right_neighbor_of_leaf_node; 585 int right_neighbor_of_leaf_node;
586 int fs_gen; 586 int fs_gen;
@@ -598,7 +598,7 @@ int search_by_key(struct super_block *sb, const struct cpu_key *p_s_key, /* Key
598 we must be careful to release all nodes in a path before we either 598 we must be careful to release all nodes in a path before we either
599 discard the path struct or re-use the path struct, as we do here. */ 599 discard the path struct or re-use the path struct, as we do here. */
600 600
601 pathrelse(p_s_search_path); 601 pathrelse(search_path);
602 602
603 right_neighbor_of_leaf_node = 0; 603 right_neighbor_of_leaf_node = 0;
604 604
@@ -615,18 +615,18 @@ int search_by_key(struct super_block *sb, const struct cpu_key *p_s_key, /* Key
615 "%s: there were %d iterations of " 615 "%s: there were %d iterations of "
616 "while loop looking for key %K", 616 "while loop looking for key %K",
617 current->comm, n_repeat_counter, 617 current->comm, n_repeat_counter,
618 p_s_key); 618 key);
619#endif 619#endif
620 620
621 /* prep path to have another element added to it. */ 621 /* prep path to have another element added to it. */
622 p_s_last_element = 622 last_element =
623 PATH_OFFSET_PELEMENT(p_s_search_path, 623 PATH_OFFSET_PELEMENT(search_path,
624 ++p_s_search_path->path_length); 624 ++search_path->path_length);
625 fs_gen = get_generation(sb); 625 fs_gen = get_generation(sb);
626 626
627 /* Read the next tree node, and set the last element in the path to 627 /* Read the next tree node, and set the last element in the path to
628 have a pointer to it. */ 628 have a pointer to it. */
629 if ((bh = p_s_last_element->pe_buffer = 629 if ((bh = last_element->pe_buffer =
630 sb_getblk(sb, n_block_number))) { 630 sb_getblk(sb, n_block_number))) {
631 if (!buffer_uptodate(bh) && reada_count > 1) 631 if (!buffer_uptodate(bh) && reada_count > 1)
632 search_by_key_reada(sb, reada_bh, 632 search_by_key_reada(sb, reada_bh,
@@ -637,8 +637,8 @@ int search_by_key(struct super_block *sb, const struct cpu_key *p_s_key, /* Key
637 goto io_error; 637 goto io_error;
638 } else { 638 } else {
639 io_error: 639 io_error:
640 p_s_search_path->path_length--; 640 search_path->path_length--;
641 pathrelse(p_s_search_path); 641 pathrelse(search_path);
642 return IO_ERROR; 642 return IO_ERROR;
643 } 643 }
644 reada_count = 0; 644 reada_count = 0;
@@ -652,12 +652,12 @@ int search_by_key(struct super_block *sb, const struct cpu_key *p_s_key, /* Key
652 if (fs_changed(fs_gen, sb) && 652 if (fs_changed(fs_gen, sb) &&
653 (!B_IS_IN_TREE(bh) || 653 (!B_IS_IN_TREE(bh) ||
654 B_LEVEL(bh) != expected_level || 654 B_LEVEL(bh) != expected_level ||
655 !key_in_buffer(p_s_search_path, p_s_key, sb))) { 655 !key_in_buffer(search_path, key, sb))) {
656 PROC_INFO_INC(sb, search_by_key_fs_changed); 656 PROC_INFO_INC(sb, search_by_key_fs_changed);
657 PROC_INFO_INC(sb, search_by_key_restarted); 657 PROC_INFO_INC(sb, search_by_key_restarted);
658 PROC_INFO_INC(sb, 658 PROC_INFO_INC(sb,
659 sbk_restarted[expected_level - 1]); 659 sbk_restarted[expected_level - 1]);
660 pathrelse(p_s_search_path); 660 pathrelse(search_path);
661 661
662 /* Get the root block number so that we can repeat the search 662 /* Get the root block number so that we can repeat the search
663 starting from the root. */ 663 starting from the root. */
@@ -669,11 +669,11 @@ int search_by_key(struct super_block *sb, const struct cpu_key *p_s_key, /* Key
669 continue; 669 continue;
670 } 670 }
671 671
672 /* only check that the key is in the buffer if p_s_key is not 672 /* only check that the key is in the buffer if key is not
673 equal to the MAX_KEY. Latter case is only possible in 673 equal to the MAX_KEY. Latter case is only possible in
674 "finish_unfinished()" processing during mount. */ 674 "finish_unfinished()" processing during mount. */
675 RFALSE(comp_keys(&MAX_KEY, p_s_key) && 675 RFALSE(comp_keys(&MAX_KEY, key) &&
676 !key_in_buffer(p_s_search_path, p_s_key, sb), 676 !key_in_buffer(search_path, key, sb),
677 "PAP-5130: key is not in the buffer"); 677 "PAP-5130: key is not in the buffer");
678#ifdef CONFIG_REISERFS_CHECK 678#ifdef CONFIG_REISERFS_CHECK
679 if (cur_tb) { 679 if (cur_tb) {
@@ -689,7 +689,7 @@ int search_by_key(struct super_block *sb, const struct cpu_key *p_s_key, /* Key
689 reiserfs_error(sb, "vs-5150", 689 reiserfs_error(sb, "vs-5150",
690 "invalid format found in block %ld. " 690 "invalid format found in block %ld. "
691 "Fsck?", bh->b_blocknr); 691 "Fsck?", bh->b_blocknr);
692 pathrelse(p_s_search_path); 692 pathrelse(search_path);
693 return IO_ERROR; 693 return IO_ERROR;
694 } 694 }
695 695
@@ -702,12 +702,12 @@ int search_by_key(struct super_block *sb, const struct cpu_key *p_s_key, /* Key
702 "vs-5152: tree level (%d) is less than stop level (%d)", 702 "vs-5152: tree level (%d) is less than stop level (%d)",
703 n_node_level, n_stop_level); 703 n_node_level, n_stop_level);
704 704
705 n_retval = bin_search(p_s_key, B_N_PITEM_HEAD(bh, 0), 705 n_retval = bin_search(key, B_N_PITEM_HEAD(bh, 0),
706 B_NR_ITEMS(bh), 706 B_NR_ITEMS(bh),
707 (n_node_level == 707 (n_node_level ==
708 DISK_LEAF_NODE_LEVEL) ? IH_SIZE : 708 DISK_LEAF_NODE_LEVEL) ? IH_SIZE :
709 KEY_SIZE, 709 KEY_SIZE,
710 &(p_s_last_element->pe_position)); 710 &(last_element->pe_position));
711 if (n_node_level == n_stop_level) { 711 if (n_node_level == n_stop_level) {
712 return n_retval; 712 return n_retval;
713 } 713 }
@@ -715,7 +715,7 @@ int search_by_key(struct super_block *sb, const struct cpu_key *p_s_key, /* Key
715 /* we are not in the stop level */ 715 /* we are not in the stop level */
716 if (n_retval == ITEM_FOUND) 716 if (n_retval == ITEM_FOUND)
717 /* item has been found, so we choose the pointer which is to the right of the found one */ 717 /* item has been found, so we choose the pointer which is to the right of the found one */
718 p_s_last_element->pe_position++; 718 last_element->pe_position++;
719 719
720 /* if item was not found we choose the position which is to 720 /* if item was not found we choose the position which is to
721 the left of the found item. This requires no code, 721 the left of the found item. This requires no code,
@@ -725,23 +725,23 @@ int search_by_key(struct super_block *sb, const struct cpu_key *p_s_key, /* Key
725 an internal node. Now we calculate child block number by 725 an internal node. Now we calculate child block number by
726 position in the node. */ 726 position in the node. */
727 n_block_number = 727 n_block_number =
728 B_N_CHILD_NUM(bh, p_s_last_element->pe_position); 728 B_N_CHILD_NUM(bh, last_element->pe_position);
729 729
730 /* if we are going to read leaf nodes, try for read ahead as well */ 730 /* if we are going to read leaf nodes, try for read ahead as well */
731 if ((p_s_search_path->reada & PATH_READA) && 731 if ((search_path->reada & PATH_READA) &&
732 n_node_level == DISK_LEAF_NODE_LEVEL + 1) { 732 n_node_level == DISK_LEAF_NODE_LEVEL + 1) {
733 int pos = p_s_last_element->pe_position; 733 int pos = last_element->pe_position;
734 int limit = B_NR_ITEMS(bh); 734 int limit = B_NR_ITEMS(bh);
735 struct reiserfs_key *le_key; 735 struct reiserfs_key *le_key;
736 736
737 if (p_s_search_path->reada & PATH_READA_BACK) 737 if (search_path->reada & PATH_READA_BACK)
738 limit = 0; 738 limit = 0;
739 while (reada_count < SEARCH_BY_KEY_READA) { 739 while (reada_count < SEARCH_BY_KEY_READA) {
740 if (pos == limit) 740 if (pos == limit)
741 break; 741 break;
742 reada_blocks[reada_count++] = 742 reada_blocks[reada_count++] =
743 B_N_CHILD_NUM(bh, pos); 743 B_N_CHILD_NUM(bh, pos);
744 if (p_s_search_path->reada & PATH_READA_BACK) 744 if (search_path->reada & PATH_READA_BACK)
745 pos--; 745 pos--;
746 else 746 else
747 pos++; 747 pos++;
@@ -751,7 +751,7 @@ int search_by_key(struct super_block *sb, const struct cpu_key *p_s_key, /* Key
751 */ 751 */
752 le_key = B_N_PDELIM_KEY(bh, pos); 752 le_key = B_N_PDELIM_KEY(bh, pos);
753 if (le32_to_cpu(le_key->k_objectid) != 753 if (le32_to_cpu(le_key->k_objectid) !=
754 p_s_key->on_disk_key.k_objectid) { 754 key->on_disk_key.k_objectid) {
755 break; 755 break;
756 } 756 }
757 } 757 }
@@ -760,11 +760,11 @@ int search_by_key(struct super_block *sb, const struct cpu_key *p_s_key, /* Key
760} 760}
761 761
762/* Form the path to an item and position in this item which contains 762/* Form the path to an item and position in this item which contains
763 file byte defined by p_s_key. If there is no such item 763 file byte defined by key. If there is no such item
764 corresponding to the key, we point the path to the item with 764 corresponding to the key, we point the path to the item with
765 maximal key less than p_s_key, and *p_n_pos_in_item is set to one 765 maximal key less than key, and *pos_in_item is set to one
766 past the last entry/byte in the item. If searching for entry in a 766 past the last entry/byte in the item. If searching for entry in a
767 directory item, and it is not found, *p_n_pos_in_item is set to one 767 directory item, and it is not found, *pos_in_item is set to one
768 entry more than the entry with maximal key which is less than the 768 entry more than the entry with maximal key which is less than the
769 sought key. 769 sought key.
770 770
@@ -777,7 +777,7 @@ int search_by_key(struct super_block *sb, const struct cpu_key *p_s_key, /* Key
777/* The function is NOT SCHEDULE-SAFE! */ 777/* The function is NOT SCHEDULE-SAFE! */
778int search_for_position_by_key(struct super_block *sb, /* Pointer to the super block. */ 778int search_for_position_by_key(struct super_block *sb, /* Pointer to the super block. */
779 const struct cpu_key *p_cpu_key, /* Key to search (cpu variable) */ 779 const struct cpu_key *p_cpu_key, /* Key to search (cpu variable) */
780 struct treepath *p_s_search_path /* Filled up by this function. */ 780 struct treepath *search_path /* Filled up by this function. */
781 ) 781 )
782{ 782{
783 struct item_head *p_le_ih; /* pointer to on-disk structure */ 783 struct item_head *p_le_ih; /* pointer to on-disk structure */
@@ -788,34 +788,34 @@ int search_for_position_by_key(struct super_block *sb, /* Pointer to the super b
788 788
789 /* If searching for directory entry. */ 789 /* If searching for directory entry. */
790 if (is_direntry_cpu_key(p_cpu_key)) 790 if (is_direntry_cpu_key(p_cpu_key))
791 return search_by_entry_key(sb, p_cpu_key, p_s_search_path, 791 return search_by_entry_key(sb, p_cpu_key, search_path,
792 &de); 792 &de);
793 793
794 /* If not searching for directory entry. */ 794 /* If not searching for directory entry. */
795 795
796 /* If item is found. */ 796 /* If item is found. */
797 retval = search_item(sb, p_cpu_key, p_s_search_path); 797 retval = search_item(sb, p_cpu_key, search_path);
798 if (retval == IO_ERROR) 798 if (retval == IO_ERROR)
799 return retval; 799 return retval;
800 if (retval == ITEM_FOUND) { 800 if (retval == ITEM_FOUND) {
801 801
802 RFALSE(!ih_item_len 802 RFALSE(!ih_item_len
803 (B_N_PITEM_HEAD 803 (B_N_PITEM_HEAD
804 (PATH_PLAST_BUFFER(p_s_search_path), 804 (PATH_PLAST_BUFFER(search_path),
805 PATH_LAST_POSITION(p_s_search_path))), 805 PATH_LAST_POSITION(search_path))),
806 "PAP-5165: item length equals zero"); 806 "PAP-5165: item length equals zero");
807 807
808 pos_in_item(p_s_search_path) = 0; 808 pos_in_item(search_path) = 0;
809 return POSITION_FOUND; 809 return POSITION_FOUND;
810 } 810 }
811 811
812 RFALSE(!PATH_LAST_POSITION(p_s_search_path), 812 RFALSE(!PATH_LAST_POSITION(search_path),
813 "PAP-5170: position equals zero"); 813 "PAP-5170: position equals zero");
814 814
815 /* Item is not found. Set path to the previous item. */ 815 /* Item is not found. Set path to the previous item. */
816 p_le_ih = 816 p_le_ih =
817 B_N_PITEM_HEAD(PATH_PLAST_BUFFER(p_s_search_path), 817 B_N_PITEM_HEAD(PATH_PLAST_BUFFER(search_path),
818 --PATH_LAST_POSITION(p_s_search_path)); 818 --PATH_LAST_POSITION(search_path));
819 n_blk_size = sb->s_blocksize; 819 n_blk_size = sb->s_blocksize;
820 820
821 if (comp_short_keys(&(p_le_ih->ih_key), p_cpu_key)) { 821 if (comp_short_keys(&(p_le_ih->ih_key), p_cpu_key)) {
@@ -829,9 +829,9 @@ int search_for_position_by_key(struct super_block *sb, /* Pointer to the super b
829 /* Needed byte is contained in the item pointed to by the path. */ 829 /* Needed byte is contained in the item pointed to by the path. */
830 if (item_offset <= offset && 830 if (item_offset <= offset &&
831 item_offset + op_bytes_number(p_le_ih, n_blk_size) > offset) { 831 item_offset + op_bytes_number(p_le_ih, n_blk_size) > offset) {
832 pos_in_item(p_s_search_path) = offset - item_offset; 832 pos_in_item(search_path) = offset - item_offset;
833 if (is_indirect_le_ih(p_le_ih)) { 833 if (is_indirect_le_ih(p_le_ih)) {
834 pos_in_item(p_s_search_path) /= n_blk_size; 834 pos_in_item(search_path) /= n_blk_size;
835 } 835 }
836 return POSITION_FOUND; 836 return POSITION_FOUND;
837 } 837 }
@@ -839,18 +839,18 @@ int search_for_position_by_key(struct super_block *sb, /* Pointer to the super b
839 /* Needed byte is not contained in the item pointed to by the 839 /* Needed byte is not contained in the item pointed to by the
840 path. Set pos_in_item out of the item. */ 840 path. Set pos_in_item out of the item. */
841 if (is_indirect_le_ih(p_le_ih)) 841 if (is_indirect_le_ih(p_le_ih))
842 pos_in_item(p_s_search_path) = 842 pos_in_item(search_path) =
843 ih_item_len(p_le_ih) / UNFM_P_SIZE; 843 ih_item_len(p_le_ih) / UNFM_P_SIZE;
844 else 844 else
845 pos_in_item(p_s_search_path) = ih_item_len(p_le_ih); 845 pos_in_item(search_path) = ih_item_len(p_le_ih);
846 846
847 return POSITION_NOT_FOUND; 847 return POSITION_NOT_FOUND;
848} 848}
849 849
850/* Compare given item and item pointed to by the path. */ 850/* Compare given item and item pointed to by the path. */
851int comp_items(const struct item_head *stored_ih, const struct treepath *p_s_path) 851int comp_items(const struct item_head *stored_ih, const struct treepath *path)
852{ 852{
853 struct buffer_head *bh = PATH_PLAST_BUFFER(p_s_path); 853 struct buffer_head *bh = PATH_PLAST_BUFFER(path);
854 struct item_head *ih; 854 struct item_head *ih;
855 855
856 /* Last buffer at the path is not in the tree. */ 856 /* Last buffer at the path is not in the tree. */
@@ -858,11 +858,11 @@ int comp_items(const struct item_head *stored_ih, const struct treepath *p_s_pat
858 return 1; 858 return 1;
859 859
860 /* Last path position is invalid. */ 860 /* Last path position is invalid. */
861 if (PATH_LAST_POSITION(p_s_path) >= B_NR_ITEMS(bh)) 861 if (PATH_LAST_POSITION(path) >= B_NR_ITEMS(bh))
862 return 1; 862 return 1;
863 863
864 /* we need only to know, whether it is the same item */ 864 /* we need only to know, whether it is the same item */
865 ih = get_ih(p_s_path); 865 ih = get_ih(path);
866 return memcmp(stored_ih, ih, IH_SIZE); 866 return memcmp(stored_ih, ih, IH_SIZE);
867} 867}
868 868
@@ -951,14 +951,14 @@ static inline int prepare_for_direntry_item(struct treepath *path,
951 In case of file truncate calculate whether this item must be deleted/truncated or last 951 In case of file truncate calculate whether this item must be deleted/truncated or last
952 unformatted node of this item will be converted to a direct item. 952 unformatted node of this item will be converted to a direct item.
953 This function returns a determination of what balance mode the calling function should employ. */ 953 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 *p_s_path, const struct cpu_key *p_s_item_key, int *p_n_removed, /* Number of unformatted nodes which were removed 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
955 from end of the file. */ 955 from end of the file. */
956 int *p_n_cut_size, unsigned long long n_new_file_length /* MAX_KEY_OFFSET in case of delete. */ 956 int *cut_size, unsigned long long n_new_file_length /* MAX_KEY_OFFSET in case of delete. */
957 ) 957 )
958{ 958{
959 struct super_block *sb = inode->i_sb; 959 struct super_block *sb = inode->i_sb;
960 struct item_head *p_le_ih = PATH_PITEM_HEAD(p_s_path); 960 struct item_head *p_le_ih = PATH_PITEM_HEAD(path);
961 struct buffer_head *bh = PATH_PLAST_BUFFER(p_s_path); 961 struct buffer_head *bh = PATH_PLAST_BUFFER(path);
962 962
963 BUG_ON(!th->t_trans_id); 963 BUG_ON(!th->t_trans_id);
964 964
@@ -968,20 +968,20 @@ static char prepare_for_delete_or_cut(struct reiserfs_transaction_handle *th, st
968 RFALSE(n_new_file_length != max_reiserfs_offset(inode), 968 RFALSE(n_new_file_length != max_reiserfs_offset(inode),
969 "PAP-5210: mode must be M_DELETE"); 969 "PAP-5210: mode must be M_DELETE");
970 970
971 *p_n_cut_size = -(IH_SIZE + ih_item_len(p_le_ih)); 971 *cut_size = -(IH_SIZE + ih_item_len(p_le_ih));
972 return M_DELETE; 972 return M_DELETE;
973 } 973 }
974 974
975 /* Directory item. */ 975 /* Directory item. */
976 if (is_direntry_le_ih(p_le_ih)) 976 if (is_direntry_le_ih(p_le_ih))
977 return prepare_for_direntry_item(p_s_path, p_le_ih, inode, 977 return prepare_for_direntry_item(path, p_le_ih, inode,
978 n_new_file_length, 978 n_new_file_length,
979 p_n_cut_size); 979 cut_size);
980 980
981 /* Direct item. */ 981 /* Direct item. */
982 if (is_direct_le_ih(p_le_ih)) 982 if (is_direct_le_ih(p_le_ih))
983 return prepare_for_direct_item(p_s_path, p_le_ih, inode, 983 return prepare_for_direct_item(path, p_le_ih, inode,
984 n_new_file_length, p_n_cut_size); 984 n_new_file_length, cut_size);
985 985
986 /* Case of an indirect item. */ 986 /* Case of an indirect item. */
987 { 987 {
@@ -1001,9 +1001,9 @@ static char prepare_for_delete_or_cut(struct reiserfs_transaction_handle *th, st
1001 1001
1002 do { 1002 do {
1003 need_re_search = 0; 1003 need_re_search = 0;
1004 *p_n_cut_size = 0; 1004 *cut_size = 0;
1005 bh = PATH_PLAST_BUFFER(p_s_path); 1005 bh = PATH_PLAST_BUFFER(path);
1006 copy_item_head(&s_ih, PATH_PITEM_HEAD(p_s_path)); 1006 copy_item_head(&s_ih, PATH_PITEM_HEAD(path));
1007 pos = I_UNFM_NUM(&s_ih); 1007 pos = I_UNFM_NUM(&s_ih);
1008 1008
1009 while (le_ih_k_offset (&s_ih) + (pos - 1) * blk_size > n_new_file_length) { 1009 while (le_ih_k_offset (&s_ih) + (pos - 1) * blk_size > n_new_file_length) {
@@ -1013,10 +1013,9 @@ static char prepare_for_delete_or_cut(struct reiserfs_transaction_handle *th, st
1013 /* Each unformatted block deletion may involve one additional 1013 /* Each unformatted block deletion may involve one additional
1014 * bitmap block into the transaction, thereby the initial 1014 * bitmap block into the transaction, thereby the initial
1015 * journal space reservation might not be enough. */ 1015 * journal space reservation might not be enough. */
1016 if (!delete && (*p_n_cut_size) != 0 && 1016 if (!delete && (*cut_size) != 0 &&
1017 reiserfs_transaction_free_space(th) < JOURNAL_FOR_FREE_BLOCK_AND_UPDATE_SD) { 1017 reiserfs_transaction_free_space(th) < JOURNAL_FOR_FREE_BLOCK_AND_UPDATE_SD)
1018 break; 1018 break;
1019 }
1020 1019
1021 unfm = (__le32 *)B_I_PITEM(bh, &s_ih) + pos - 1; 1020 unfm = (__le32 *)B_I_PITEM(bh, &s_ih) + pos - 1;
1022 block = get_block_num(unfm, 0); 1021 block = get_block_num(unfm, 0);
@@ -1030,17 +1029,17 @@ static char prepare_for_delete_or_cut(struct reiserfs_transaction_handle *th, st
1030 1029
1031 cond_resched(); 1030 cond_resched();
1032 1031
1033 if (item_moved (&s_ih, p_s_path)) { 1032 if (item_moved (&s_ih, path)) {
1034 need_re_search = 1; 1033 need_re_search = 1;
1035 break; 1034 break;
1036 } 1035 }
1037 1036
1038 pos --; 1037 pos --;
1039 (*p_n_removed) ++; 1038 (*removed)++;
1040 (*p_n_cut_size) -= UNFM_P_SIZE; 1039 (*cut_size) -= UNFM_P_SIZE;
1041 1040
1042 if (pos == 0) { 1041 if (pos == 0) {
1043 (*p_n_cut_size) -= IH_SIZE; 1042 (*cut_size) -= IH_SIZE;
1044 result = M_DELETE; 1043 result = M_DELETE;
1045 break; 1044 break;
1046 } 1045 }
@@ -1050,10 +1049,10 @@ static char prepare_for_delete_or_cut(struct reiserfs_transaction_handle *th, st
1050 ** buffer */ 1049 ** buffer */
1051 reiserfs_restore_prepared_buffer(sb, bh); 1050 reiserfs_restore_prepared_buffer(sb, bh);
1052 } while (need_re_search && 1051 } while (need_re_search &&
1053 search_for_position_by_key(sb, p_s_item_key, p_s_path) == POSITION_FOUND); 1052 search_for_position_by_key(sb, item_key, path) == POSITION_FOUND);
1054 pos_in_item(p_s_path) = pos * UNFM_P_SIZE; 1053 pos_in_item(path) = pos * UNFM_P_SIZE;
1055 1054
1056 if (*p_n_cut_size == 0) { 1055 if (*cut_size == 0) {
1057 /* Nothing were cut. maybe convert last unformatted node to the 1056 /* Nothing were cut. maybe convert last unformatted node to the
1058 * direct item? */ 1057 * direct item? */
1059 result = M_CONVERT; 1058 result = M_CONVERT;
@@ -1091,7 +1090,7 @@ static int calc_deleted_bytes_number(struct tree_balance *tb, char c_mode)
1091static void init_tb_struct(struct reiserfs_transaction_handle *th, 1090static void init_tb_struct(struct reiserfs_transaction_handle *th,
1092 struct tree_balance *tb, 1091 struct tree_balance *tb,
1093 struct super_block *sb, 1092 struct super_block *sb,
1094 struct treepath *p_s_path, int n_size) 1093 struct treepath *path, int n_size)
1095{ 1094{
1096 1095
1097 BUG_ON(!th->t_trans_id); 1096 BUG_ON(!th->t_trans_id);
@@ -1099,9 +1098,9 @@ static void init_tb_struct(struct reiserfs_transaction_handle *th,
1099 memset(tb, '\0', sizeof(struct tree_balance)); 1098 memset(tb, '\0', sizeof(struct tree_balance));
1100 tb->transaction_handle = th; 1099 tb->transaction_handle = th;
1101 tb->tb_sb = sb; 1100 tb->tb_sb = sb;
1102 tb->tb_path = p_s_path; 1101 tb->tb_path = path;
1103 PATH_OFFSET_PBUFFER(p_s_path, ILLEGAL_PATH_ELEMENT_OFFSET) = NULL; 1102 PATH_OFFSET_PBUFFER(path, ILLEGAL_PATH_ELEMENT_OFFSET) = NULL;
1104 PATH_OFFSET_POSITION(p_s_path, ILLEGAL_PATH_ELEMENT_OFFSET) = 0; 1103 PATH_OFFSET_POSITION(path, ILLEGAL_PATH_ELEMENT_OFFSET) = 0;
1105 tb->insert_size[0] = n_size; 1104 tb->insert_size[0] = n_size;
1106} 1105}
1107 1106
@@ -1141,13 +1140,17 @@ char head2type(struct item_head *ih)
1141} 1140}
1142#endif 1141#endif
1143 1142
1144/* Delete object item. */ 1143/* Delete object item.
1145int reiserfs_delete_item(struct reiserfs_transaction_handle *th, struct treepath *p_s_path, /* Path to the deleted item. */ 1144 * th - active transaction handle
1146 const struct cpu_key *p_s_item_key, /* Key to search for the deleted item. */ 1145 * path - path to the deleted item
1147 struct inode *inode, /* inode is here just to update 1146 * item_key - key to search for the deleted item
1148 * i_blocks and quotas */ 1147 * indode - used for updating i_blocks and quotas
1149 struct buffer_head *p_s_un_bh) 1148 * un_bh - NULL or unformatted node pointer
1150{ /* NULL or unformatted node pointer. */ 1149 */
1150int reiserfs_delete_item(struct reiserfs_transaction_handle *th,
1151 struct treepath *path, const struct cpu_key *item_key,
1152 struct inode *inode, struct buffer_head *un_bh)
1153{
1151 struct super_block *sb = inode->i_sb; 1154 struct super_block *sb = inode->i_sb;
1152 struct tree_balance s_del_balance; 1155 struct tree_balance s_del_balance;
1153 struct item_head s_ih; 1156 struct item_head s_ih;
@@ -1162,7 +1165,7 @@ int reiserfs_delete_item(struct reiserfs_transaction_handle *th, struct treepath
1162 1165
1163 BUG_ON(!th->t_trans_id); 1166 BUG_ON(!th->t_trans_id);
1164 1167
1165 init_tb_struct(th, &s_del_balance, sb, p_s_path, 1168 init_tb_struct(th, &s_del_balance, sb, path,
1166 0 /*size is unknown */ ); 1169 0 /*size is unknown */ );
1167 1170
1168 while (1) { 1171 while (1) {
@@ -1172,14 +1175,14 @@ int reiserfs_delete_item(struct reiserfs_transaction_handle *th, struct treepath
1172 n_iter++; 1175 n_iter++;
1173 c_mode = 1176 c_mode =
1174#endif 1177#endif
1175 prepare_for_delete_or_cut(th, inode, p_s_path, 1178 prepare_for_delete_or_cut(th, inode, path,
1176 p_s_item_key, &n_removed, 1179 item_key, &n_removed,
1177 &n_del_size, 1180 &n_del_size,
1178 max_reiserfs_offset(inode)); 1181 max_reiserfs_offset(inode));
1179 1182
1180 RFALSE(c_mode != M_DELETE, "PAP-5320: mode must be M_DELETE"); 1183 RFALSE(c_mode != M_DELETE, "PAP-5320: mode must be M_DELETE");
1181 1184
1182 copy_item_head(&s_ih, PATH_PITEM_HEAD(p_s_path)); 1185 copy_item_head(&s_ih, PATH_PITEM_HEAD(path));
1183 s_del_balance.insert_size[0] = n_del_size; 1186 s_del_balance.insert_size[0] = n_del_size;
1184 1187
1185 n_ret_value = fix_nodes(M_DELETE, &s_del_balance, NULL, NULL); 1188 n_ret_value = fix_nodes(M_DELETE, &s_del_balance, NULL, NULL);
@@ -1190,13 +1193,13 @@ int reiserfs_delete_item(struct reiserfs_transaction_handle *th, struct treepath
1190 1193
1191 // file system changed, repeat search 1194 // file system changed, repeat search
1192 n_ret_value = 1195 n_ret_value =
1193 search_for_position_by_key(sb, p_s_item_key, p_s_path); 1196 search_for_position_by_key(sb, item_key, path);
1194 if (n_ret_value == IO_ERROR) 1197 if (n_ret_value == IO_ERROR)
1195 break; 1198 break;
1196 if (n_ret_value == FILE_NOT_FOUND) { 1199 if (n_ret_value == FILE_NOT_FOUND) {
1197 reiserfs_warning(sb, "vs-5340", 1200 reiserfs_warning(sb, "vs-5340",
1198 "no items of the file %K found", 1201 "no items of the file %K found",
1199 p_s_item_key); 1202 item_key);
1200 break; 1203 break;
1201 } 1204 }
1202 } /* while (1) */ 1205 } /* while (1) */
@@ -1207,7 +1210,7 @@ int reiserfs_delete_item(struct reiserfs_transaction_handle *th, struct treepath
1207 } 1210 }
1208 // reiserfs_delete_item returns item length when success 1211 // reiserfs_delete_item returns item length when success
1209 n_ret_value = calc_deleted_bytes_number(&s_del_balance, M_DELETE); 1212 n_ret_value = calc_deleted_bytes_number(&s_del_balance, M_DELETE);
1210 q_ih = get_ih(p_s_path); 1213 q_ih = get_ih(path);
1211 quota_cut_bytes = ih_item_len(q_ih); 1214 quota_cut_bytes = ih_item_len(q_ih);
1212 1215
1213 /* hack so the quota code doesn't have to guess if the file 1216 /* hack so the quota code doesn't have to guess if the file
@@ -1224,7 +1227,7 @@ int reiserfs_delete_item(struct reiserfs_transaction_handle *th, struct treepath
1224 } 1227 }
1225 } 1228 }
1226 1229
1227 if (p_s_un_bh) { 1230 if (un_bh) {
1228 int off; 1231 int off;
1229 char *data; 1232 char *data;
1230 1233
@@ -1242,16 +1245,16 @@ int reiserfs_delete_item(struct reiserfs_transaction_handle *th, struct treepath
1242 ** The unformatted node must be dirtied later on. We can't be 1245 ** The unformatted node must be dirtied later on. We can't be
1243 ** sure here if the entire tail has been deleted yet. 1246 ** sure here if the entire tail has been deleted yet.
1244 ** 1247 **
1245 ** p_s_un_bh is from the page cache (all unformatted nodes are 1248 ** un_bh is from the page cache (all unformatted nodes are
1246 ** from the page cache) and might be a highmem page. So, we 1249 ** from the page cache) and might be a highmem page. So, we
1247 ** can't use p_s_un_bh->b_data. 1250 ** can't use un_bh->b_data.
1248 ** -clm 1251 ** -clm
1249 */ 1252 */
1250 1253
1251 data = kmap_atomic(p_s_un_bh->b_page, KM_USER0); 1254 data = kmap_atomic(un_bh->b_page, KM_USER0);
1252 off = ((le_ih_k_offset(&s_ih) - 1) & (PAGE_CACHE_SIZE - 1)); 1255 off = ((le_ih_k_offset(&s_ih) - 1) & (PAGE_CACHE_SIZE - 1));
1253 memcpy(data + off, 1256 memcpy(data + off,
1254 B_I_PITEM(PATH_PLAST_BUFFER(p_s_path), &s_ih), 1257 B_I_PITEM(PATH_PLAST_BUFFER(path), &s_ih),
1255 n_ret_value); 1258 n_ret_value);
1256 kunmap_atomic(data, KM_USER0); 1259 kunmap_atomic(data, KM_USER0);
1257 } 1260 }
@@ -1427,9 +1430,9 @@ static void unmap_buffers(struct page *page, loff_t pos)
1427static int maybe_indirect_to_direct(struct reiserfs_transaction_handle *th, 1430static int maybe_indirect_to_direct(struct reiserfs_transaction_handle *th,
1428 struct inode *inode, 1431 struct inode *inode,
1429 struct page *page, 1432 struct page *page,
1430 struct treepath *p_s_path, 1433 struct treepath *path,
1431 const struct cpu_key *p_s_item_key, 1434 const struct cpu_key *item_key,
1432 loff_t n_new_file_size, char *p_c_mode) 1435 loff_t n_new_file_size, char *mode)
1433{ 1436{
1434 struct super_block *sb = inode->i_sb; 1437 struct super_block *sb = inode->i_sb;
1435 int n_block_size = sb->s_blocksize; 1438 int n_block_size = sb->s_blocksize;
@@ -1445,17 +1448,17 @@ static int maybe_indirect_to_direct(struct reiserfs_transaction_handle *th,
1445 !tail_has_to_be_packed(inode) || 1448 !tail_has_to_be_packed(inode) ||
1446 !page || (REISERFS_I(inode)->i_flags & i_nopack_mask)) { 1449 !page || (REISERFS_I(inode)->i_flags & i_nopack_mask)) {
1447 /* leave tail in an unformatted node */ 1450 /* leave tail in an unformatted node */
1448 *p_c_mode = M_SKIP_BALANCING; 1451 *mode = M_SKIP_BALANCING;
1449 cut_bytes = 1452 cut_bytes =
1450 n_block_size - (n_new_file_size & (n_block_size - 1)); 1453 n_block_size - (n_new_file_size & (n_block_size - 1));
1451 pathrelse(p_s_path); 1454 pathrelse(path);
1452 return cut_bytes; 1455 return cut_bytes;
1453 } 1456 }
1454 /* Permorm the conversion to a direct_item. */ 1457 /* Perform the conversion to a direct_item. */
1455 /* return indirect_to_direct(inode, p_s_path, p_s_item_key, 1458 /* return indirect_to_direct(inode, path, item_key,
1456 n_new_file_size, p_c_mode); */ 1459 n_new_file_size, mode); */
1457 return indirect2direct(th, inode, page, p_s_path, p_s_item_key, 1460 return indirect2direct(th, inode, page, path, item_key,
1458 n_new_file_size, p_c_mode); 1461 n_new_file_size, mode);
1459} 1462}
1460 1463
1461/* we did indirect_to_direct conversion. And we have inserted direct 1464/* we did indirect_to_direct conversion. And we have inserted direct
@@ -1506,8 +1509,8 @@ static void indirect_to_direct_roll_back(struct reiserfs_transaction_handle *th,
1506 1509
1507/* (Truncate or cut entry) or delete object item. Returns < 0 on failure */ 1510/* (Truncate or cut entry) or delete object item. Returns < 0 on failure */
1508int reiserfs_cut_from_item(struct reiserfs_transaction_handle *th, 1511int reiserfs_cut_from_item(struct reiserfs_transaction_handle *th,
1509 struct treepath *p_s_path, 1512 struct treepath *path,
1510 struct cpu_key *p_s_item_key, 1513 struct cpu_key *item_key,
1511 struct inode *inode, 1514 struct inode *inode,
1512 struct page *page, loff_t n_new_file_size) 1515 struct page *page, loff_t n_new_file_size)
1513{ 1516{
@@ -1528,7 +1531,7 @@ int reiserfs_cut_from_item(struct reiserfs_transaction_handle *th,
1528 1531
1529 BUG_ON(!th->t_trans_id); 1532 BUG_ON(!th->t_trans_id);
1530 1533
1531 init_tb_struct(th, &s_cut_balance, inode->i_sb, p_s_path, 1534 init_tb_struct(th, &s_cut_balance, inode->i_sb, path,
1532 n_cut_size); 1535 n_cut_size);
1533 1536
1534 /* Repeat this loop until we either cut the item without needing 1537 /* Repeat this loop until we either cut the item without needing
@@ -1540,8 +1543,8 @@ int reiserfs_cut_from_item(struct reiserfs_transaction_handle *th,
1540 pointers. */ 1543 pointers. */
1541 1544
1542 c_mode = 1545 c_mode =
1543 prepare_for_delete_or_cut(th, inode, p_s_path, 1546 prepare_for_delete_or_cut(th, inode, path,
1544 p_s_item_key, &n_removed, 1547 item_key, &n_removed,
1545 &n_cut_size, n_new_file_size); 1548 &n_cut_size, n_new_file_size);
1546 if (c_mode == M_CONVERT) { 1549 if (c_mode == M_CONVERT) {
1547 /* convert last unformatted node to direct item or leave 1550 /* convert last unformatted node to direct item or leave
@@ -1551,7 +1554,7 @@ int reiserfs_cut_from_item(struct reiserfs_transaction_handle *th,
1551 1554
1552 n_ret_value = 1555 n_ret_value =
1553 maybe_indirect_to_direct(th, inode, page, 1556 maybe_indirect_to_direct(th, inode, page,
1554 p_s_path, p_s_item_key, 1557 path, item_key,
1555 n_new_file_size, &c_mode); 1558 n_new_file_size, &c_mode);
1556 if (c_mode == M_SKIP_BALANCING) 1559 if (c_mode == M_SKIP_BALANCING)
1557 /* tail has been left in the unformatted node */ 1560 /* tail has been left in the unformatted node */
@@ -1568,26 +1571,26 @@ int reiserfs_cut_from_item(struct reiserfs_transaction_handle *th,
1568 inserting the new direct item. Now we are removing the 1571 inserting the new direct item. Now we are removing the
1569 last unformatted node pointer. Set key to search for 1572 last unformatted node pointer. Set key to search for
1570 it. */ 1573 it. */
1571 set_cpu_key_k_type(p_s_item_key, TYPE_INDIRECT); 1574 set_cpu_key_k_type(item_key, TYPE_INDIRECT);
1572 p_s_item_key->key_length = 4; 1575 item_key->key_length = 4;
1573 n_new_file_size -= 1576 n_new_file_size -=
1574 (n_new_file_size & (sb->s_blocksize - 1)); 1577 (n_new_file_size & (sb->s_blocksize - 1));
1575 tail_pos = n_new_file_size; 1578 tail_pos = n_new_file_size;
1576 set_cpu_key_k_offset(p_s_item_key, n_new_file_size + 1); 1579 set_cpu_key_k_offset(item_key, n_new_file_size + 1);
1577 if (search_for_position_by_key 1580 if (search_for_position_by_key
1578 (sb, p_s_item_key, 1581 (sb, item_key,
1579 p_s_path) == POSITION_NOT_FOUND) { 1582 path) == POSITION_NOT_FOUND) {
1580 print_block(PATH_PLAST_BUFFER(p_s_path), 3, 1583 print_block(PATH_PLAST_BUFFER(path), 3,
1581 PATH_LAST_POSITION(p_s_path) - 1, 1584 PATH_LAST_POSITION(path) - 1,
1582 PATH_LAST_POSITION(p_s_path) + 1); 1585 PATH_LAST_POSITION(path) + 1);
1583 reiserfs_panic(sb, "PAP-5580", "item to " 1586 reiserfs_panic(sb, "PAP-5580", "item to "
1584 "convert does not exist (%K)", 1587 "convert does not exist (%K)",
1585 p_s_item_key); 1588 item_key);
1586 } 1589 }
1587 continue; 1590 continue;
1588 } 1591 }
1589 if (n_cut_size == 0) { 1592 if (n_cut_size == 0) {
1590 pathrelse(p_s_path); 1593 pathrelse(path);
1591 return 0; 1594 return 0;
1592 } 1595 }
1593 1596
@@ -1600,12 +1603,12 @@ int reiserfs_cut_from_item(struct reiserfs_transaction_handle *th,
1600 PROC_INFO_INC(sb, cut_from_item_restarted); 1603 PROC_INFO_INC(sb, cut_from_item_restarted);
1601 1604
1602 n_ret_value = 1605 n_ret_value =
1603 search_for_position_by_key(sb, p_s_item_key, p_s_path); 1606 search_for_position_by_key(sb, item_key, path);
1604 if (n_ret_value == POSITION_FOUND) 1607 if (n_ret_value == POSITION_FOUND)
1605 continue; 1608 continue;
1606 1609
1607 reiserfs_warning(sb, "PAP-5610", "item %K not found", 1610 reiserfs_warning(sb, "PAP-5610", "item %K not found",
1608 p_s_item_key); 1611 item_key);
1609 unfix_nodes(&s_cut_balance); 1612 unfix_nodes(&s_cut_balance);
1610 return (n_ret_value == IO_ERROR) ? -EIO : -ENOENT; 1613 return (n_ret_value == IO_ERROR) ? -EIO : -ENOENT;
1611 } /* while */ 1614 } /* while */
@@ -1615,7 +1618,7 @@ int reiserfs_cut_from_item(struct reiserfs_transaction_handle *th,
1615 if (n_is_inode_locked) { 1618 if (n_is_inode_locked) {
1616 // FIXME: this seems to be not needed: we are always able 1619 // FIXME: this seems to be not needed: we are always able
1617 // to cut item 1620 // to cut item
1618 indirect_to_direct_roll_back(th, inode, p_s_path); 1621 indirect_to_direct_roll_back(th, inode, path);
1619 } 1622 }
1620 if (n_ret_value == NO_DISK_SPACE) 1623 if (n_ret_value == NO_DISK_SPACE)
1621 reiserfs_warning(sb, "reiserfs-5092", 1624 reiserfs_warning(sb, "reiserfs-5092",
@@ -1631,7 +1634,7 @@ int reiserfs_cut_from_item(struct reiserfs_transaction_handle *th,
1631 /* Calculate number of bytes that need to be cut from the item. */ 1634 /* Calculate number of bytes that need to be cut from the item. */
1632 quota_cut_bytes = 1635 quota_cut_bytes =
1633 (c_mode == 1636 (c_mode ==
1634 M_DELETE) ? ih_item_len(get_ih(p_s_path)) : -s_cut_balance. 1637 M_DELETE) ? ih_item_len(get_ih(path)) : -s_cut_balance.
1635 insert_size[0]; 1638 insert_size[0];
1636 if (retval2 == -1) 1639 if (retval2 == -1)
1637 n_ret_value = calc_deleted_bytes_number(&s_cut_balance, c_mode); 1640 n_ret_value = calc_deleted_bytes_number(&s_cut_balance, c_mode);
@@ -1878,7 +1881,7 @@ int reiserfs_do_truncate(struct reiserfs_transaction_handle *th,
1878#ifdef CONFIG_REISERFS_CHECK 1881#ifdef CONFIG_REISERFS_CHECK
1879// this makes sure, that we __append__, not overwrite or add holes 1882// this makes sure, that we __append__, not overwrite or add holes
1880static void check_research_for_paste(struct treepath *path, 1883static void check_research_for_paste(struct treepath *path,
1881 const struct cpu_key *p_s_key) 1884 const struct cpu_key *key)
1882{ 1885{
1883 struct item_head *found_ih = get_ih(path); 1886 struct item_head *found_ih = get_ih(path);
1884 1887
@@ -1886,35 +1889,35 @@ static void check_research_for_paste(struct treepath *path,
1886 if (le_ih_k_offset(found_ih) + 1889 if (le_ih_k_offset(found_ih) +
1887 op_bytes_number(found_ih, 1890 op_bytes_number(found_ih,
1888 get_last_bh(path)->b_size) != 1891 get_last_bh(path)->b_size) !=
1889 cpu_key_k_offset(p_s_key) 1892 cpu_key_k_offset(key)
1890 || op_bytes_number(found_ih, 1893 || op_bytes_number(found_ih,
1891 get_last_bh(path)->b_size) != 1894 get_last_bh(path)->b_size) !=
1892 pos_in_item(path)) 1895 pos_in_item(path))
1893 reiserfs_panic(NULL, "PAP-5720", "found direct item " 1896 reiserfs_panic(NULL, "PAP-5720", "found direct item "
1894 "%h or position (%d) does not match " 1897 "%h or position (%d) does not match "
1895 "to key %K", found_ih, 1898 "to key %K", found_ih,
1896 pos_in_item(path), p_s_key); 1899 pos_in_item(path), key);
1897 } 1900 }
1898 if (is_indirect_le_ih(found_ih)) { 1901 if (is_indirect_le_ih(found_ih)) {
1899 if (le_ih_k_offset(found_ih) + 1902 if (le_ih_k_offset(found_ih) +
1900 op_bytes_number(found_ih, 1903 op_bytes_number(found_ih,
1901 get_last_bh(path)->b_size) != 1904 get_last_bh(path)->b_size) !=
1902 cpu_key_k_offset(p_s_key) 1905 cpu_key_k_offset(key)
1903 || I_UNFM_NUM(found_ih) != pos_in_item(path) 1906 || I_UNFM_NUM(found_ih) != pos_in_item(path)
1904 || get_ih_free_space(found_ih) != 0) 1907 || get_ih_free_space(found_ih) != 0)
1905 reiserfs_panic(NULL, "PAP-5730", "found indirect " 1908 reiserfs_panic(NULL, "PAP-5730", "found indirect "
1906 "item (%h) or position (%d) does not " 1909 "item (%h) or position (%d) does not "
1907 "match to key (%K)", 1910 "match to key (%K)",
1908 found_ih, pos_in_item(path), p_s_key); 1911 found_ih, pos_in_item(path), key);
1909 } 1912 }
1910} 1913}
1911#endif /* config reiserfs check */ 1914#endif /* config reiserfs check */
1912 1915
1913/* Paste bytes to the existing item. Returns bytes number pasted into the item. */ 1916/* Paste bytes to the existing item. Returns bytes number pasted into the item. */
1914int reiserfs_paste_into_item(struct reiserfs_transaction_handle *th, struct treepath *p_s_search_path, /* Path to the pasted item. */ 1917int reiserfs_paste_into_item(struct reiserfs_transaction_handle *th, struct treepath *search_path, /* Path to the pasted item. */
1915 const struct cpu_key *p_s_key, /* Key to search for the needed item. */ 1918 const struct cpu_key *key, /* Key to search for the needed item. */
1916 struct inode *inode, /* Inode item belongs to */ 1919 struct inode *inode, /* Inode item belongs to */
1917 const char *p_c_body, /* Pointer to the bytes to paste. */ 1920 const char *body, /* Pointer to the bytes to paste. */
1918 int n_pasted_size) 1921 int n_pasted_size)
1919{ /* Size of pasted bytes. */ 1922{ /* Size of pasted bytes. */
1920 struct tree_balance s_paste_balance; 1923 struct tree_balance s_paste_balance;
@@ -1929,17 +1932,17 @@ int reiserfs_paste_into_item(struct reiserfs_transaction_handle *th, struct tree
1929 reiserfs_debug(inode->i_sb, REISERFS_DEBUG_CODE, 1932 reiserfs_debug(inode->i_sb, REISERFS_DEBUG_CODE,
1930 "reiserquota paste_into_item(): allocating %u id=%u type=%c", 1933 "reiserquota paste_into_item(): allocating %u id=%u type=%c",
1931 n_pasted_size, inode->i_uid, 1934 n_pasted_size, inode->i_uid,
1932 key2type(&(p_s_key->on_disk_key))); 1935 key2type(&(key->on_disk_key)));
1933#endif 1936#endif
1934 1937
1935 if (DQUOT_ALLOC_SPACE_NODIRTY(inode, n_pasted_size)) { 1938 if (DQUOT_ALLOC_SPACE_NODIRTY(inode, n_pasted_size)) {
1936 pathrelse(p_s_search_path); 1939 pathrelse(search_path);
1937 return -EDQUOT; 1940 return -EDQUOT;
1938 } 1941 }
1939 init_tb_struct(th, &s_paste_balance, th->t_super, p_s_search_path, 1942 init_tb_struct(th, &s_paste_balance, th->t_super, search_path,
1940 n_pasted_size); 1943 n_pasted_size);
1941#ifdef DISPLACE_NEW_PACKING_LOCALITIES 1944#ifdef DISPLACE_NEW_PACKING_LOCALITIES
1942 s_paste_balance.key = p_s_key->on_disk_key; 1945 s_paste_balance.key = key->on_disk_key;
1943#endif 1946#endif
1944 1947
1945 /* DQUOT_* can schedule, must check before the fix_nodes */ 1948 /* DQUOT_* can schedule, must check before the fix_nodes */
@@ -1949,13 +1952,13 @@ int reiserfs_paste_into_item(struct reiserfs_transaction_handle *th, struct tree
1949 1952
1950 while ((retval = 1953 while ((retval =
1951 fix_nodes(M_PASTE, &s_paste_balance, NULL, 1954 fix_nodes(M_PASTE, &s_paste_balance, NULL,
1952 p_c_body)) == REPEAT_SEARCH) { 1955 body)) == REPEAT_SEARCH) {
1953 search_again: 1956 search_again:
1954 /* file system changed while we were in the fix_nodes */ 1957 /* file system changed while we were in the fix_nodes */
1955 PROC_INFO_INC(th->t_super, paste_into_item_restarted); 1958 PROC_INFO_INC(th->t_super, paste_into_item_restarted);
1956 retval = 1959 retval =
1957 search_for_position_by_key(th->t_super, p_s_key, 1960 search_for_position_by_key(th->t_super, key,
1958 p_s_search_path); 1961 search_path);
1959 if (retval == IO_ERROR) { 1962 if (retval == IO_ERROR) {
1960 retval = -EIO; 1963 retval = -EIO;
1961 goto error_out; 1964 goto error_out;
@@ -1963,19 +1966,19 @@ int reiserfs_paste_into_item(struct reiserfs_transaction_handle *th, struct tree
1963 if (retval == POSITION_FOUND) { 1966 if (retval == POSITION_FOUND) {
1964 reiserfs_warning(inode->i_sb, "PAP-5710", 1967 reiserfs_warning(inode->i_sb, "PAP-5710",
1965 "entry or pasted byte (%K) exists", 1968 "entry or pasted byte (%K) exists",
1966 p_s_key); 1969 key);
1967 retval = -EEXIST; 1970 retval = -EEXIST;
1968 goto error_out; 1971 goto error_out;
1969 } 1972 }
1970#ifdef CONFIG_REISERFS_CHECK 1973#ifdef CONFIG_REISERFS_CHECK
1971 check_research_for_paste(p_s_search_path, p_s_key); 1974 check_research_for_paste(search_path, key);
1972#endif 1975#endif
1973 } 1976 }
1974 1977
1975 /* Perform balancing after all resources are collected by fix_nodes, and 1978 /* Perform balancing after all resources are collected by fix_nodes, and
1976 accessing them will not risk triggering schedule. */ 1979 accessing them will not risk triggering schedule. */
1977 if (retval == CARRY_ON) { 1980 if (retval == CARRY_ON) {
1978 do_balance(&s_paste_balance, NULL /*ih */ , p_c_body, M_PASTE); 1981 do_balance(&s_paste_balance, NULL /*ih */ , body, M_PASTE);
1979 return 0; 1982 return 0;
1980 } 1983 }
1981 retval = (retval == NO_DISK_SPACE) ? -ENOSPC : -EIO; 1984 retval = (retval == NO_DISK_SPACE) ? -ENOSPC : -EIO;
@@ -1986,17 +1989,23 @@ int reiserfs_paste_into_item(struct reiserfs_transaction_handle *th, struct tree
1986 reiserfs_debug(inode->i_sb, REISERFS_DEBUG_CODE, 1989 reiserfs_debug(inode->i_sb, REISERFS_DEBUG_CODE,
1987 "reiserquota paste_into_item(): freeing %u id=%u type=%c", 1990 "reiserquota paste_into_item(): freeing %u id=%u type=%c",
1988 n_pasted_size, inode->i_uid, 1991 n_pasted_size, inode->i_uid,
1989 key2type(&(p_s_key->on_disk_key))); 1992 key2type(&(key->on_disk_key)));
1990#endif 1993#endif
1991 DQUOT_FREE_SPACE_NODIRTY(inode, n_pasted_size); 1994 DQUOT_FREE_SPACE_NODIRTY(inode, n_pasted_size);
1992 return retval; 1995 return retval;
1993} 1996}
1994 1997
1995/* Insert new item into the buffer at the path. */ 1998/* Insert new item into the buffer at the path.
1996int reiserfs_insert_item(struct reiserfs_transaction_handle *th, struct treepath *p_s_path, /* Path to the inserteded item. */ 1999 * th - active transaction handle
1997 const struct cpu_key *key, struct item_head *p_s_ih, /* Pointer to the item header to insert. */ 2000 * path - path to the inserted item
1998 struct inode *inode, const char *p_c_body) 2001 * ih - pointer to the item header to insert
1999{ /* Pointer to the bytes to insert. */ 2002 * body - pointer to the bytes to insert
2003 */
2004int reiserfs_insert_item(struct reiserfs_transaction_handle *th,
2005 struct treepath *path, const struct cpu_key *key,
2006 struct item_head *ih, struct inode *inode,
2007 const char *body)
2008{
2000 struct tree_balance s_ins_balance; 2009 struct tree_balance s_ins_balance;
2001 int retval; 2010 int retval;
2002 int fs_gen = 0; 2011 int fs_gen = 0;
@@ -2006,28 +2015,27 @@ int reiserfs_insert_item(struct reiserfs_transaction_handle *th, struct treepath
2006 2015
2007 if (inode) { /* Do we count quotas for item? */ 2016 if (inode) { /* Do we count quotas for item? */
2008 fs_gen = get_generation(inode->i_sb); 2017 fs_gen = get_generation(inode->i_sb);
2009 quota_bytes = ih_item_len(p_s_ih); 2018 quota_bytes = ih_item_len(ih);
2010 2019
2011 /* hack so the quota code doesn't have to guess if the file has 2020 /* hack so the quota code doesn't have to guess if the file has
2012 ** a tail, links are always tails, so there's no guessing needed 2021 ** a tail, links are always tails, so there's no guessing needed
2013 */ 2022 */
2014 if (!S_ISLNK(inode->i_mode) && is_direct_le_ih(p_s_ih)) { 2023 if (!S_ISLNK(inode->i_mode) && is_direct_le_ih(ih))
2015 quota_bytes = inode->i_sb->s_blocksize + UNFM_P_SIZE; 2024 quota_bytes = inode->i_sb->s_blocksize + UNFM_P_SIZE;
2016 }
2017#ifdef REISERQUOTA_DEBUG 2025#ifdef REISERQUOTA_DEBUG
2018 reiserfs_debug(inode->i_sb, REISERFS_DEBUG_CODE, 2026 reiserfs_debug(inode->i_sb, REISERFS_DEBUG_CODE,
2019 "reiserquota insert_item(): allocating %u id=%u type=%c", 2027 "reiserquota insert_item(): allocating %u id=%u type=%c",
2020 quota_bytes, inode->i_uid, head2type(p_s_ih)); 2028 quota_bytes, inode->i_uid, head2type(ih));
2021#endif 2029#endif
2022 /* We can't dirty inode here. It would be immediately written but 2030 /* We can't dirty inode here. It would be immediately written but
2023 * appropriate stat item isn't inserted yet... */ 2031 * appropriate stat item isn't inserted yet... */
2024 if (DQUOT_ALLOC_SPACE_NODIRTY(inode, quota_bytes)) { 2032 if (DQUOT_ALLOC_SPACE_NODIRTY(inode, quota_bytes)) {
2025 pathrelse(p_s_path); 2033 pathrelse(path);
2026 return -EDQUOT; 2034 return -EDQUOT;
2027 } 2035 }
2028 } 2036 }
2029 init_tb_struct(th, &s_ins_balance, th->t_super, p_s_path, 2037 init_tb_struct(th, &s_ins_balance, th->t_super, path,
2030 IH_SIZE + ih_item_len(p_s_ih)); 2038 IH_SIZE + ih_item_len(ih));
2031#ifdef DISPLACE_NEW_PACKING_LOCALITIES 2039#ifdef DISPLACE_NEW_PACKING_LOCALITIES
2032 s_ins_balance.key = key->on_disk_key; 2040 s_ins_balance.key = key->on_disk_key;
2033#endif 2041#endif
@@ -2037,12 +2045,12 @@ int reiserfs_insert_item(struct reiserfs_transaction_handle *th, struct treepath
2037 } 2045 }
2038 2046
2039 while ((retval = 2047 while ((retval =
2040 fix_nodes(M_INSERT, &s_ins_balance, p_s_ih, 2048 fix_nodes(M_INSERT, &s_ins_balance, ih,
2041 p_c_body)) == REPEAT_SEARCH) { 2049 body)) == REPEAT_SEARCH) {
2042 search_again: 2050 search_again:
2043 /* file system changed while we were in the fix_nodes */ 2051 /* file system changed while we were in the fix_nodes */
2044 PROC_INFO_INC(th->t_super, insert_item_restarted); 2052 PROC_INFO_INC(th->t_super, insert_item_restarted);
2045 retval = search_item(th->t_super, key, p_s_path); 2053 retval = search_item(th->t_super, key, path);
2046 if (retval == IO_ERROR) { 2054 if (retval == IO_ERROR) {
2047 retval = -EIO; 2055 retval = -EIO;
2048 goto error_out; 2056 goto error_out;
@@ -2058,7 +2066,7 @@ int reiserfs_insert_item(struct reiserfs_transaction_handle *th, struct treepath
2058 2066
2059 /* make balancing after all resources will be collected at a time */ 2067 /* make balancing after all resources will be collected at a time */
2060 if (retval == CARRY_ON) { 2068 if (retval == CARRY_ON) {
2061 do_balance(&s_ins_balance, p_s_ih, p_c_body, M_INSERT); 2069 do_balance(&s_ins_balance, ih, body, M_INSERT);
2062 return 0; 2070 return 0;
2063 } 2071 }
2064 2072
@@ -2069,7 +2077,7 @@ int reiserfs_insert_item(struct reiserfs_transaction_handle *th, struct treepath
2069#ifdef REISERQUOTA_DEBUG 2077#ifdef REISERQUOTA_DEBUG
2070 reiserfs_debug(th->t_super, REISERFS_DEBUG_CODE, 2078 reiserfs_debug(th->t_super, REISERFS_DEBUG_CODE,
2071 "reiserquota insert_item(): freeing %u id=%u type=%c", 2079 "reiserquota insert_item(): freeing %u id=%u type=%c",
2072 quota_bytes, inode->i_uid, head2type(p_s_ih)); 2080 quota_bytes, inode->i_uid, head2type(ih));
2073#endif 2081#endif
2074 if (inode) 2082 if (inode)
2075 DQUOT_FREE_SPACE_NODIRTY(inode, quota_bytes); 2083 DQUOT_FREE_SPACE_NODIRTY(inode, quota_bytes);
diff --git a/fs/reiserfs/tail_conversion.c b/fs/reiserfs/tail_conversion.c
index 5c5ee0d0d6a8..2b90c0e5697c 100644
--- a/fs/reiserfs/tail_conversion.c
+++ b/fs/reiserfs/tail_conversion.c
@@ -172,10 +172,12 @@ void reiserfs_unmap_buffer(struct buffer_head *bh)
172 inode */ 172 inode */
173int indirect2direct(struct reiserfs_transaction_handle *th, 173int indirect2direct(struct reiserfs_transaction_handle *th,
174 struct inode *inode, struct page *page, 174 struct inode *inode, struct page *page,
175 struct treepath *p_s_path, /* path to the indirect item. */ 175 struct treepath *path, /* path to the indirect item. */
176 const struct cpu_key *p_s_item_key, /* Key to look for unformatted node pointer to be cut. */ 176 const struct cpu_key *item_key, /* Key to look for
177 * unformatted node
178 * pointer to be cut. */
177 loff_t n_new_file_size, /* New file size. */ 179 loff_t n_new_file_size, /* New file size. */
178 char *p_c_mode) 180 char *mode)
179{ 181{
180 struct super_block *sb = inode->i_sb; 182 struct super_block *sb = inode->i_sb;
181 struct item_head s_ih; 183 struct item_head s_ih;
@@ -189,10 +191,10 @@ int indirect2direct(struct reiserfs_transaction_handle *th,
189 191
190 REISERFS_SB(sb)->s_indirect2direct++; 192 REISERFS_SB(sb)->s_indirect2direct++;
191 193
192 *p_c_mode = M_SKIP_BALANCING; 194 *mode = M_SKIP_BALANCING;
193 195
194 /* store item head path points to. */ 196 /* store item head path points to. */
195 copy_item_head(&s_ih, PATH_PITEM_HEAD(p_s_path)); 197 copy_item_head(&s_ih, PATH_PITEM_HEAD(path));
196 198
197 tail_len = (n_new_file_size & (n_block_size - 1)); 199 tail_len = (n_new_file_size & (n_block_size - 1));
198 if (get_inode_sd_version(inode) == STAT_DATA_V2) 200 if (get_inode_sd_version(inode) == STAT_DATA_V2)
@@ -211,14 +213,14 @@ int indirect2direct(struct reiserfs_transaction_handle *th,
211 213
212 tail = (char *)kmap(page); /* this can schedule */ 214 tail = (char *)kmap(page); /* this can schedule */
213 215
214 if (path_changed(&s_ih, p_s_path)) { 216 if (path_changed(&s_ih, path)) {
215 /* re-search indirect item */ 217 /* re-search indirect item */
216 if (search_for_position_by_key(sb, p_s_item_key, p_s_path) 218 if (search_for_position_by_key(sb, item_key, path)
217 == POSITION_NOT_FOUND) 219 == POSITION_NOT_FOUND)
218 reiserfs_panic(sb, "PAP-5520", 220 reiserfs_panic(sb, "PAP-5520",
219 "item to be converted %K does not exist", 221 "item to be converted %K does not exist",
220 p_s_item_key); 222 item_key);
221 copy_item_head(&s_ih, PATH_PITEM_HEAD(p_s_path)); 223 copy_item_head(&s_ih, PATH_PITEM_HEAD(path));
222#ifdef CONFIG_REISERFS_CHECK 224#ifdef CONFIG_REISERFS_CHECK
223 pos = le_ih_k_offset(&s_ih) - 1 + 225 pos = le_ih_k_offset(&s_ih) - 1 +
224 (ih_item_len(&s_ih) / UNFM_P_SIZE - 226 (ih_item_len(&s_ih) / UNFM_P_SIZE -
@@ -240,13 +242,13 @@ int indirect2direct(struct reiserfs_transaction_handle *th,
240 */ 242 */
241 tail = tail + (pos & (PAGE_CACHE_SIZE - 1)); 243 tail = tail + (pos & (PAGE_CACHE_SIZE - 1));
242 244
243 PATH_LAST_POSITION(p_s_path)++; 245 PATH_LAST_POSITION(path)++;
244 246
245 key = *p_s_item_key; 247 key = *item_key;
246 set_cpu_key_k_type(&key, TYPE_DIRECT); 248 set_cpu_key_k_type(&key, TYPE_DIRECT);
247 key.key_length = 4; 249 key.key_length = 4;
248 /* Insert tail as new direct item in the tree */ 250 /* Insert tail as new direct item in the tree */
249 if (reiserfs_insert_item(th, p_s_path, &key, &s_ih, inode, 251 if (reiserfs_insert_item(th, path, &key, &s_ih, inode,
250 tail ? tail : NULL) < 0) { 252 tail ? tail : NULL) < 0) {
251 /* No disk memory. So we can not convert last unformatted node 253 /* No disk memory. So we can not convert last unformatted node
252 to the direct item. In this case we used to adjust 254 to the direct item. In this case we used to adjust
@@ -268,7 +270,7 @@ int indirect2direct(struct reiserfs_transaction_handle *th,
268 270
269 /* We have inserted new direct item and must remove last 271 /* We have inserted new direct item and must remove last
270 unformatted node. */ 272 unformatted node. */
271 *p_c_mode = M_CUT; 273 *mode = M_CUT;
272 274
273 /* we store position of first direct item in the in-core inode */ 275 /* we store position of first direct item in the in-core inode */
274 /* mark_file_with_tail (inode, pos1 + 1); */ 276 /* mark_file_with_tail (inode, pos1 + 1); */