    B-fsck.patch
    Removes code pertaining to reiserfsck conditioned by
    defined( REISERFS_FSCK ).
    Doesn't change functionality in any way.
diff -rup linux-2.4.6/fs/reiserfs/do_balan.c linux-2.4.6.cleanup/fs/reiserfs/do_balan.c
--- linux-2.4.6/fs/reiserfs/do_balan.c	Tue Jul 10 20:26:53 2001
+++ linux-2.4.6.cleanup/fs/reiserfs/do_balan.c	Tue Jul 10 20:34:34 2001
@@ -653,11 +653,7 @@ static int balance_leaf (struct tree_bal
 		{
 		    struct item_head * pasted;
 
-#ifdef REISERFS_FSCK
-		    if ( ! item_pos  && is_left_mergeable (tb->tb_sb, tb->tb_path) == 1 )
-#else
 			if ( ! item_pos  && op_is_left_mergeable (B_N_PKEY (tbS0, 0), tbS0->b_size) )
-#endif
 			{ /* if we paste into first item of S[0] and it is left mergable */
 			    /* then increment pos_in_item by the size of the last item in L[0] */
 			    pasted = B_N_PITEM_HEAD(tb->L[0],n-1);
@@ -1597,10 +1593,6 @@ struct buffer_head * get_FEB (struct tre
     tb->FEB[i] = 0;
     tb->used[i] = first_b;
 
-#ifdef REISERFS_FSCK
-    mark_block_formatted (first_b->b_blocknr);
-#endif
-
     return(first_b);
 }
 
@@ -1647,20 +1639,6 @@ void reiserfs_invalidate_buffer (struct 
     */
 
     store_thrown (tb, bh);
-#if 0
-#ifdef REISERFS_FSCK
-    {
-	struct buffer_head * to_be_forgotten;
-	
-	to_be_forgotten = find_buffer (bh->b_dev, bh->b_blocknr, bh->b_size);
-	if (to_be_forgotten) {
-	    to_be_forgotten->b_count ++;
-	    bforget (to_be_forgotten);
-	}
-	unmark_block_formatted (bh->b_blocknr);
-    }
-#endif
-#endif
 }
 
 /* Replace n_dest'th key in buffer dest by n_src'th key of buffer src.*/
@@ -1987,26 +1965,6 @@ void do_balance (struct tree_balance * t
     atomic_inc (&(fs_generation (tb->tb_sb)));
     do_balance_starts (tb);
     
-#ifdef REISERFS_FSCK
-    if (flag == M_INTERNAL) {
-	insert_ptr[0] = (struct buffer_head *)body;
-	/* we must prepare insert_key */
-
-	if (PATH_H_B_ITEM_ORDER (tb->tb_path, 0)/*LAST_POSITION (tb->tb_path)*//*item_pos*/ == -1) {
-		/* get delimiting key from buffer in tree */
-		copy_key (&insert_key[0].ih_key, B_N_PKEY (PATH_PLAST_BUFFER (tb->tb_path), 0));
-		/*insert_ptr[0]->b_item_order = 0;*/
-	} else {
-	    /* get delimiting key from new buffer */
-	    copy_key (&insert_key[0].ih_key, B_N_PKEY((struct buffer_head *)body,0));
-	    /*insert_ptr[0]->b_item_order = item_pos;*/
-	}
-      
-	/* and insert_ptr instead of balance_leaf */
-	child_pos = PATH_H_B_ITEM_ORDER (tb->tb_path, 0)/*item_pos*/;
-    } else
-#endif
-
 	/* balance leaf returns 0 except if combining L R and S into
 	   one node.  see balance_internal() for explanation of this
 	   line of code.*/
diff -rup linux-2.4.6/fs/reiserfs/fix_node.c linux-2.4.6.cleanup/fs/reiserfs/fix_node.c
--- linux-2.4.6/fs/reiserfs/fix_node.c	Tue Jul 10 20:26:53 2001
+++ linux-2.4.6.cleanup/fs/reiserfs/fix_node.c	Tue Jul 10 20:34:34 2001
@@ -113,11 +113,7 @@ static void create_virtual_node (struct 
     ih = B_N_PITEM_HEAD (Sh, 0);
 
     /* define the mergeability for 0-th item (if it is not being deleted) */
-#ifdef REISERFS_FSCK
-    if (is_left_mergeable (tb->tb_sb, tb->tb_path) == 1 && (vn->vn_mode != M_DELETE || vn->vn_affected_item_num))
-#else
     if (op_is_left_mergeable (&(ih->ih_key), Sh->b_size) && (vn->vn_mode != M_DELETE || vn->vn_affected_item_num))
-#endif
 	    vn->vn_vi[0].vi_type |= VI_TYPE_LEFT_MERGEABLE;
 
     /* go through all items those remain in the virtual node (except for the new (inserted) one) */
@@ -198,13 +194,8 @@ static void create_virtual_node (struct 
 	struct key * key;
 
 	key = B_N_PDELIM_KEY (tb->CFR[0], tb->rkey[0]);
-#ifdef REISERFS_FSCK
-	if (is_right_mergeable (tb->tb_sb, tb->tb_path) == 1 && (vn->vn_mode != M_DELETE ||
-								 vn->vn_affected_item_num != B_NR_ITEMS (Sh) - 1))
-#else
 	if (op_is_left_mergeable (key, Sh->b_size) && (vn->vn_mode != M_DELETE ||
 						       vn->vn_affected_item_num != B_NR_ITEMS (Sh) - 1))
-#endif
 		vn->vn_vi[vn->vn_nr_item-1].vi_type |= VI_TYPE_RIGHT_MERGEABLE;
 
 #ifdef CONFIG_REISERFS_CHECK
@@ -708,8 +699,6 @@ static int are_leaves_removable (struct 
     ih = B_N_PITEM_HEAD (S0, 0);
     if (tb->CFR[0] && !comp_short_le_keys (&(ih->ih_key), B_N_PDELIM_KEY (tb->CFR[0], tb->rkey[0])))
 	if (is_direntry_le_ih (ih)) {
-#ifndef REISERFS_FSCK
-		
 	    /* Directory must be in correct state here: that is
 	       somewhere at the left side should exist first directory
 	       item. But the item being deleted can not be that first
@@ -726,30 +715,6 @@ static int are_leaves_removable (struct 
 		reiserfs_panic (tb->tb_sb, "vs-8130: are_leaves_removable: "
 				"first directory item can not be removed until directory is not empty");
 #endif
-	
-	
-#else	/* REISERFS_FSCK */
-
-	    /* we can delete any directory item in fsck (if it is unreachable) */
-	    if (ih->ih_key.k_offset != DOT_OFFSET) {
-		/* must get left neighbor here to make sure, that left
-		   neighbor is of the same directory */
-		struct buffer_head * left;
-		
-		left = get_left_neighbor (tb->tb_sb, tb->tb_path);
-		if (left) {
-		    struct item_head * last;
-		    
-		    if (B_NR_ITEMS (left) == 0)
-			reiserfs_panic (tb->tb_sb, "vs-8135: are_leaves_removable: "
-					"empty node in the tree");
-		    last = B_N_PITEM_HEAD (left, B_NR_ITEMS (left) - 1);
-		    if (!comp_short_keys (&last->ih_key, &ih->ih_key))
-			ih_size = IH_SIZE;
-		    brelse (left);
-		}
-	    }
-#endif
       }
     
   }
@@ -851,11 +816,6 @@ static int  get_empty_nodes(
   struct super_block *	p_s_sb = p_s_tb->tb_sb;
 
 
-#ifdef REISERFS_FSCK
-   if (n_h == 0 && p_s_tb->insert_size[n_h] == 0x7fff)
-     return CARRY_ON;
-#endif
-
   /* number_of_freeblk is the number of empty blocks which have been
      acquired for use by the balancing algorithm minus the number of
      empty blocks used in the previous levels of the analysis,
@@ -1302,13 +1262,8 @@ static inline int can_node_be_removed (i
     if (
 	lfree + rfree + sfree < MAX_CHILD_SIZE(Sh) + levbytes
 	/* shifting may merge items which might save space */
-#ifdef REISERFS_FSCK
-	- (( ! h && is_left_mergeable (tb->tb_sb, tb->tb_path) == 1 ) ? IH_SIZE : 0)
-	- (( ! h && r_ih && is_right_mergeable (tb->tb_sb, tb->tb_path) == 1 ) ? IH_SIZE : 0)
-#else
 	- (( ! h && op_is_left_mergeable (&(ih->ih_key), Sh->b_size) ) ? IH_SIZE : 0)
 	- (( ! h && r_key && op_is_left_mergeable (r_key, Sh->b_size) ) ? IH_SIZE : 0)
-#endif
 	+ (( h ) ? KEY_SIZE : 0))
     {
 	/* node can not be removed */
@@ -1378,15 +1333,6 @@ static int ip_check_balance (struct tree
     /* Sh is the node whose balance is currently being checked */
     struct buffer_head * Sh;
   
-#ifdef REISERFS_FSCK
-    /* special mode for insert pointer to the most low internal node */
-    if (h == 0 && vn->vn_mode == M_INTERNAL) {
-	/* blk_num == 2 is to get pointer inserted to the next level */
-	set_parameters (tb, h, 0, 0, 2, NULL, -1, -1);
-	return 0;
-    }
-#endif
-
     Sh = PATH_H_PBUFFER (tb->tb_path, h);
     levbytes = tb->insert_size[h];
   
@@ -2527,19 +2473,10 @@ int fix_nodes (int n_op_mode,
 
     /* Check parameters. */
     switch (n_op_mode) {
-#ifdef REISERFS_FSCK
-    case M_INTERNAL:
-	break;
-    case M_INSERT:
-	if ( n_item_num < 0 || n_item_num > B_NR_ITEMS(p_s_tbS0) )
-	    reiserfs_panic(p_s_tb->tb_sb,"PAP-8325: fix_nodes: Incorrect item number %d (in S0 - %d) in case of insert",
-			   n_item_num, B_NR_ITEMS(p_s_tbS0));
-#else
     case M_INSERT:
 	if ( n_item_num <= 0 || n_item_num > B_NR_ITEMS(p_s_tbS0) )
 	    reiserfs_panic(p_s_tb->tb_sb,"PAP-8330: fix_nodes: Incorrect item number %d (in S0 - %d) in case of insert",
 			   n_item_num, B_NR_ITEMS(p_s_tbS0));
-#endif
 	break;
     case M_PASTE:
     case M_DELETE:
@@ -2735,151 +2672,10 @@ void unfix_nodes (struct tree_balance * 
 	    brelse (tb->used[i]);
 	}
     }
-
-#if 0 /* shouldn't this be in CONFIG_REISERFS_CHECK??? */
-    /* make sure, that all we have released got really freed */
-    for (i = 0; i < sizeof (tb->thrown) / sizeof (tb->thrown[0]); i ++)
-	if (tb->thrown[i]) {
-	    if (atomic_read (&(tb->thrown[i]->b_count))) {
-		/* the log will have the count at one and the buffers marked */
-		if (atomic_read(&(tb->thrown[i]->b_count)) > 1 || 
-		    !(buffer_journaled(tb->thrown[i]) || 
-		      buffer_journal_dirty(tb->thrown[i]))) {
-		    foo_print (tb->thrown[i], tb->tb_sb);
-		    printk ("unfix_nodes: Waiting...(block %lu, count %d)\n", 
-			    tb->thrown[i]->b_blocknr, 
-			    atomic_read (&(tb->thrown[i]->b_count)));
-		    wait_buffer_until_released (tb->thrown[i]);
-		    printk ("unfix_nodes: Done (block %lu, count %d)\n", 
-			    tb->thrown[i]->b_blocknr, 
-			    atomic_read (&(tb->thrown[i]->b_count)));
-		}
-	    }
-	}
-#endif /* 0 */
     if (tb->vn_buf) 
 	reiserfs_kfree (tb->vn_buf, tb->vn_buf_size, tb->tb_sb);
 
 } 
-
-
-
-#ifndef REISERFS_FSCK
-
-// is_left_mergeable is now one of the item methods
-
-#else
-
-// this works only in fsck
-
-int are_items_mergeable (struct item_head * left, struct item_head * right, int bsize)
-{
-  if (comp_keys (&left->ih_key, &right->ih_key) != -1) {
-    reiserfs_panic (0, "vs-16070: are_items_mergeable: left %k, right %k", &(left->ih_key), &(right->ih_key));
-  }
-
-  if (comp_short_keys (&left->ih_key, &right->ih_key))
-    return 0;
-
-  if (I_IS_DIRECTORY_ITEM (left)) {
-    return 1;
-  }
-
-  if ((I_IS_DIRECT_ITEM (left) && I_IS_DIRECT_ITEM (right)) || 
-      (I_IS_INDIRECT_ITEM (left) && I_IS_INDIRECT_ITEM (right)))
-    return (left->ih_key.k_offset + I_BYTES_NUMBER (left, bsize) == right->ih_key.k_offset) ? 1 : 0;
-
-  return 0;
-}
-
-/* get left neighbor of the leaf node */
-static struct buffer_head * get_left_neighbor (struct super_block * s, struct path * path)
-{
-  struct key key;
-  INITIALIZE_PATH (path_to_left_neighbor);
-  struct buffer_head * bh;
-
-  copy_key (&key, B_N_PKEY (PATH_PLAST_BUFFER (path), 0));
-  decrement_key (&key);
-
-/*  init_path (&path_to_left_neighbor);*/
-  search_by_key (s, &key, &path_to_left_neighbor, DISK_LEAF_NODE_LEVEL, READ_BLOCKS);
-  // FIXME: fsck is to handle I/O failures somehow as well
-  if (PATH_LAST_POSITION (&path_to_left_neighbor) == 0) {
-    pathrelse (&path_to_left_neighbor);
-    return 0;
-  }
-  bh = PATH_PLAST_BUFFER (&path_to_left_neighbor);
-  bh->b_count ++;
-  pathrelse (&path_to_left_neighbor);
-  return bh;
-}
-
-extern struct key  MIN_KEY;
-static struct buffer_head * get_right_neighbor (struct super_block * s, struct path * path)
-{
-  struct key key;
-  struct key * rkey;
-  INITIALIZE_PATH (path_to_right_neighbor);
-  struct buffer_head * bh;
-
-  rkey = get_rkey (path, s);
-  if (comp_keys (rkey, &MIN_KEY) == 0)
-    reiserfs_panic (s, "vs-16080: get_right_neighbor: get_rkey returned min key (path has changed)");
-  copy_key (&key, rkey);
-
-  
-  /*init_path (&path_to_right_neighbor);*/
-  search_by_key (s, &key, &path_to_right_neighbor, DISK_LEAF_NODE_LEVEL, READ_BLOCKS);
-  if (PATH_PLAST_BUFFER (&path_to_right_neighbor) == PATH_PLAST_BUFFER (path)) {
-    pathrelse (&path_to_right_neighbor);
-    return 0;
-  }
-  bh = PATH_PLAST_BUFFER (&path_to_right_neighbor);
-  bh->b_count ++;
-  pathrelse (&path_to_right_neighbor);
-  return bh;
-}
-
-
-int is_left_mergeable (struct super_block * s, struct path * path)
-{
-  struct item_head * right;
-  struct buffer_head * bh;
-  int retval;
-  
-  right = B_N_PITEM_HEAD (PATH_PLAST_BUFFER (path), 0);
-
-  bh = get_left_neighbor (s, path);
-  if (bh == 0) {
-    return 0;
-  }
-  retval = are_items_mergeable (B_N_PITEM_HEAD (bh, B_NR_ITEMS (bh) - 1), right, bh->b_size);
-  brelse (bh);
-  return retval;
-}
-
-
-int is_right_mergeable (struct super_block * s, struct path * path)
-{
-  struct item_head * left;
-  struct buffer_head * bh;
-  int retval;
-  
-  left = B_N_PITEM_HEAD (PATH_PLAST_BUFFER (path), B_NR_ITEMS (PATH_PLAST_BUFFER (path)) - 1);
-
-  bh = get_right_neighbor (s, path);
-  if (bh == 0) {
-    return 0;
-  }
-  retval = are_items_mergeable (left, B_N_PITEM_HEAD (bh, 0), bh->b_size);
-  brelse (bh);
-  return retval;
-}
-
-#endif /* REISERFS_FSCK */
-
-
 
 
 
diff -rup linux-2.4.6/fs/reiserfs/ibalance.c linux-2.4.6.cleanup/fs/reiserfs/ibalance.c
--- linux-2.4.6/fs/reiserfs/ibalance.c	Tue Jul 10 20:26:53 2001
+++ linux-2.4.6.cleanup/fs/reiserfs/ibalance.c	Tue Jul 10 20:34:34 2001
@@ -1094,25 +1094,11 @@ int balance_internal (struct tree_balanc
 
     n = B_NR_ITEMS (tbSh); /*number of items in S[h] */
 
-#ifdef REISERFS_FSCK
-    if ( -1 <= child_pos && child_pos <= n && insert_num > 0 ) {
-#else
 	if ( 0 <= child_pos && child_pos <= n && insert_num > 0 ) {
-#endif
 	    bi.tb = tb;
 	    bi.bi_bh = tbSh;
 	    bi.bi_parent = PATH_H_PPARENT (tb->tb_path, h);
 	    bi.bi_position = PATH_H_POSITION (tb->tb_path, h + 1);
-#ifdef REISERFS_FSCK
-	    if (child_pos == -1) {
-		/* this is a little different from original do_balance: 
-		   here we insert the minimal keys in the tree, that has never happened when file system works */
-		if (tb->CFL[h-1] || insert_num != 1 || h != 1)
-		    die ("balance_internal: invalid child_pos");
-/*      insert_child (tb->S[h], tb->S[h-1], child_pos, insert_num, B_N_ITEM_HEAD(tb->S[0],0), insert_ptr);*/
-		internal_insert_childs (&bi, child_pos, insert_num, B_N_PITEM_HEAD (PATH_PLAST_BUFFER (tb->tb_path), 0), insert_ptr);
-	    } else
-#endif
 		internal_insert_childs (
 		    &bi,/*tbSh,*/
 		    /*		( tb->S[h-1]->b_parent == tb->S[h] ) ? tb->S[h-1]->b_next :  tb->S[h]->b_child->b_next,*/
diff -rup linux-2.4.6/fs/reiserfs/lbalance.c linux-2.4.6.cleanup/fs/reiserfs/lbalance.c
--- linux-2.4.6/fs/reiserfs/lbalance.c	Tue Jul 10 20:26:53 2001
+++ linux-2.4.6.cleanup/fs/reiserfs/lbalance.c	Tue Jul 10 20:34:34 2001
@@ -58,13 +58,8 @@ static void leaf_copy_dir_entries (struc
 
     /* if there are no items in dest or the first/last item in dest is not item of the same directory */
     if ( (item_num_in_dest == - 1) ||
-#ifdef REISERFS_FSCK
-	 (last_first == FIRST_TO_LAST && are_items_mergeable (B_N_PITEM_HEAD (dest, item_num_in_dest), ih, dest->b_size) == 0) ||
-	 (last_first == LAST_TO_FIRST && are_items_mergeable (ih, B_N_PITEM_HEAD (dest, item_num_in_dest), dest->b_size) == 0)) {
-#else
 	(last_first == FIRST_TO_LAST && le_key_k_offset (ih_version (ih), &(ih->ih_key)) == DOT_OFFSET) ||
 	    (last_first == LAST_TO_FIRST && comp_short_le_keys/*COMP_SHORT_KEYS*/ (&ih->ih_key, B_N_PKEY (dest, item_num_in_dest)))) {
-#endif
 	/* create new item in dest */
 	struct item_head new_ih;
 
@@ -127,11 +122,7 @@ static int leaf_copy_boundary_item (stru
        that we copy, so we return */
     ih = B_N_PITEM_HEAD (src, 0);
     dih = B_N_PITEM_HEAD (dest, dest_nr_item - 1);
-#ifdef REISERFS_FSCK
-    if (!dest_nr_item || (are_items_mergeable (dih, ih, src->b_size) == 0))
-#else
     if (!dest_nr_item || (!op_is_left_mergeable (&(ih->ih_key), src->b_size)))
-#endif
       /* there is nothing to merge */
       return 0;
       
@@ -194,11 +185,7 @@ static int leaf_copy_boundary_item (stru
   ih = B_N_PITEM_HEAD (src, src_nr_item - 1);
   dih = B_N_PITEM_HEAD (dest, 0);
 
-#ifdef REISERFS_FSCK
-  if (!dest_nr_item || are_items_mergeable (ih, dih, src->b_size) == 0)
-#else
   if (!dest_nr_item || !op_is_left_mergeable (&(dih->ih_key), src->b_size))
-#endif
     return 0;
   
   if ( is_direntry_le_ih (ih)) {
diff -rup linux-2.4.6/include/linux/reiserfs_fs.h linux-2.4.6.cleanup/include/linux/reiserfs_fs.h
--- linux-2.4.6/include/linux/reiserfs_fs.h	Wed Jul  4 13:45:57 2001
+++ linux-2.4.6.cleanup/include/linux/reiserfs_fs.h	Tue Jul 10 20:36:00 2001
@@ -1773,17 +1773,6 @@ int get_buffers_from_range (struct super
 			    int n_max_nr_buffers_to_return);
 */
 
-#ifndef REISERFS_FSCK
-
-//inline int is_left_mergeable (struct item_head * ih, unsigned long bsize);
-
-#else
-
-int is_left_mergeable (struct super_block * s, struct path * path);
-int is_right_mergeable (struct super_block * s, struct path * path);
-int are_items_mergeable (struct item_head * left, struct item_head * right, int bsize);
-
-#endif
 void padd_item (char * item, int total_length, int length);
 
 
