Sophie

Sophie

distrib > Scientific%20Linux > 5x > x86_64 > by-pkgid > 9383e745e23602bc45f9c92184feea59 > files > 14

gfs2-utils-0.1.62-28.el5.src.rpm

commit 9b487b83bb443ab2f55e39d2f81f26e67b6ad791
Author: Bob Peterson <bob@ganesha.peterson>
Date:   Wed Jan 20 15:46:50 2010 -0600

    gfs2: libgfs2 and fsck.gfs2 cleanups
    
    This patch is big, but mostly cosmetic.  There are a few places
    where I found and fixed a bug with the previous patches.  However,
    by and large, this patch is comprised of (1) comment changes,
    (2) code reformatting for readability, (3) variable renames to
    aid in readability, (4) code restructuring for efficiency, as in
    the case where I got rid of useless function scan_meta and just
    inlined it, (5) improved error messages given to aid in debugging.
    
    rhbz#455300

diff --git a/gfs2/convert/gfs2_convert.c b/gfs2/convert/gfs2_convert.c
index d05eff5..fac5fec 100644
--- a/gfs2/convert/gfs2_convert.c
+++ b/gfs2/convert/gfs2_convert.c
@@ -340,8 +340,7 @@ static void fix_metatree(struct gfs2_sbd *sbp, struct gfs2_inode *ip,
 		if (amount > sbp->bsize - hdrsize - ptramt)
 			amount = sbp->bsize - hdrsize - ptramt;
 
-		memcpy(bh->b_data + hdrsize + ptramt,
-		       (char *)srcptr, amount);
+		memcpy(bh->b_data + hdrsize + ptramt, (char *)srcptr, amount);
 		srcptr += amount;
 		bmodified(bh);
 		if (bh != ip->i_bh)
@@ -1074,7 +1073,7 @@ static int fetch_inum(struct gfs2_sbd *sbp, uint64_t iblock,
 /* Returns: 0 on success, -1 on failure                                      */
 /* ------------------------------------------------------------------------- */
 static int process_dirent_info(struct gfs2_inode *dip, struct gfs2_sbd *sbp,
-						struct gfs2_buffer_head *bh, int dir_entries)
+			       struct gfs2_buffer_head *bh, int dir_entries)
 {
 	int error;
 	struct gfs2_dirent *dent;
diff --git a/gfs2/edit/gfs2hex.c b/gfs2/edit/gfs2hex.c
index ef76f58..2934877 100644
--- a/gfs2/edit/gfs2hex.c
+++ b/gfs2/edit/gfs2hex.c
@@ -484,7 +484,8 @@ static void do_eattr_extended(struct gfs2_buffer_head *ebh)
 	print_gfs2("Eattr Entries:");
 	eol(0);
 
-	for (x = sizeof(struct gfs2_meta_header); x < sbd.bsize; x += ea.ea_rec_len)
+	for (x = sizeof(struct gfs2_meta_header); x < sbd.bsize;
+	     x += ea.ea_rec_len)
 	{
 		eol(0);
 		gfs2_ea_header_in(&ea, ebh->b_data + x);
diff --git a/gfs2/edit/hexedit.c b/gfs2/edit/hexedit.c
index 4d3d77c..643fdb5 100644
--- a/gfs2/edit/hexedit.c
+++ b/gfs2/edit/hexedit.c
@@ -3056,7 +3056,7 @@ static void dump_journal(const char *journal)
 			abs_block = jblock + jb;
 			dummy_bh.b_data = j_bh->b_data;
 		} else {
-			error = fsck_readi(j_inode, (void *)&jbuf, jb,
+			error = fsck_readi(j_inode, (void *)jbuf, jb,
 					   sbd.bsize, &abs_block);
 			if (!error) /* end of file */
 				break;
diff --git a/gfs2/edit/savemeta.c b/gfs2/edit/savemeta.c
index 77ec485..554a3da 100644
--- a/gfs2/edit/savemeta.c
+++ b/gfs2/edit/savemeta.c
@@ -820,8 +820,25 @@ static int restore_data(int fd, int in_fd, int printblocksonly)
 				       "device; quitting.\n");
 				break;
 			}
-			do_lseek(fd, savedata->blk * sbd.bsize);
-			do_write(fd, savedata->buf, sbd.bsize);
+			if (lseek(fd, savedata->blk * sbd.bsize, SEEK_SET) !=
+			    savedata->blk * sbd.bsize) {
+				fprintf(stderr, "bad seek: %s from %s:"
+					"%d: block %lld (0x%llx)\n",
+					strerror(errno), __FUNCTION__,
+					__LINE__,
+					(unsigned long long)savedata->blk,
+					(unsigned long long)savedata->blk);
+				exit(-1);
+			}
+			if (write(fd, savedata->buf, sbd.bsize) != sbd.bsize) {
+				fprintf(stderr, "write error: %s from "
+					"%s:%d: block %lld (0x%llx)\n",
+					strerror(errno), __FUNCTION__,
+					__LINE__,
+					(unsigned long long)savedata->blk,
+					(unsigned long long)savedata->blk);
+				exit(-1);
+			}
 			writes++;
 		}
 		blks_saved++;
diff --git a/gfs2/fsck/eattr.c b/gfs2/fsck/eattr.c
index cc9fec4..fb84854 100644
--- a/gfs2/fsck/eattr.c
+++ b/gfs2/fsck/eattr.c
@@ -54,17 +54,12 @@ int clear_eattr_entry (struct gfs2_inode *ip,
 		       void *private)
 {
 	struct gfs2_sbd *sdp = ip->i_sbd;
-	char ea_name[256];
 
 	if(!ea_hdr->ea_name_len){
 		/* Skip this entry for now */
 		return 1;
 	}
 
-	memset(ea_name, 0, sizeof(ea_name));
-	strncpy(ea_name, (char *)ea_hdr + sizeof(struct gfs2_ea_header),
-		ea_hdr->ea_name_len);
-
 	if(!GFS2_EATYPE_VALID(ea_hdr->ea_type) &&
 	   ((ea_hdr_prev) || (!ea_hdr_prev && ea_hdr->ea_type))){
 		/* Skip invalid entry */
@@ -83,8 +78,7 @@ int clear_eattr_entry (struct gfs2_inode *ip,
 		} else {
 			log_debug( _("  Pointers Required: %d\n"
 				  "  Pointers Reported: %d\n"),
-				  max_ptrs,
-				  ea_hdr->ea_num_ptrs);
+				  max_ptrs, ea_hdr->ea_num_ptrs);
 		}
 
 
diff --git a/gfs2/fsck/fsck.h b/gfs2/fsck/fsck.h
index 2510ecb..5594548 100644
--- a/gfs2/fsck/fsck.h
+++ b/gfs2/fsck/fsck.h
@@ -73,7 +73,7 @@ enum rgindex_trust_level { /* how far can we trust our RG index? */
 
 struct dup_blks {
 	osi_list_t list;
-	uint64_t block_no;
+	uint64_t block;
 	osi_list_t ref_inode_list;
 };
 
@@ -82,19 +82,21 @@ extern struct gfs2_inode *fsck_inode_get(struct gfs2_sbd *sdp,
 				  struct gfs2_buffer_head *bh);
 extern void fsck_inode_put(struct gfs2_inode **ip);
 
-int initialize(struct gfs2_sbd *sbp, int force_check, int preen,
-	       int *all_clean);
-void destroy(struct gfs2_sbd *sbp);
-int pass1(struct gfs2_sbd *sbp);
-int pass1b(struct gfs2_sbd *sbp);
-int pass1c(struct gfs2_sbd *sbp);
-int pass2(struct gfs2_sbd *sbp);
-int pass3(struct gfs2_sbd *sbp);
-int pass4(struct gfs2_sbd *sbp);
-int pass5(struct gfs2_sbd *sbp);
-int rg_repair(struct gfs2_sbd *sdp, int trust_lvl, int *rg_count);
-int fsck_query(const char *format, ...)
+extern int initialize(struct gfs2_sbd *sbp, int force_check, int preen,
+		      int *all_clean);
+extern void destroy(struct gfs2_sbd *sbp);
+extern int pass1(struct gfs2_sbd *sbp);
+extern int pass1b(struct gfs2_sbd *sbp);
+extern int pass1c(struct gfs2_sbd *sbp);
+extern int pass2(struct gfs2_sbd *sbp);
+extern int pass3(struct gfs2_sbd *sbp);
+extern int pass4(struct gfs2_sbd *sbp);
+extern int pass5(struct gfs2_sbd *sbp);
+extern int rg_repair(struct gfs2_sbd *sdp, int trust_lvl, int *rg_count);
+extern int fsck_query(const char *format, ...)
 	__attribute__((format(printf,1,2)));
+extern struct dir_info *dirtree_find(uint64_t block);
+extern void dirtree_delete(struct dir_info *b);
 
 /* FIXME: Hack to get this going for pass2 - this should be pulled out
  * of pass1 and put somewhere else... */
diff --git a/gfs2/fsck/lost_n_found.c b/gfs2/fsck/lost_n_found.c
index 5fa5ce4..0e55724 100644
--- a/gfs2/fsck/lost_n_found.c
+++ b/gfs2/fsck/lost_n_found.c
@@ -38,8 +38,6 @@
  */
 int add_inode_to_lf(struct gfs2_inode *ip){
 	char tmp_name[256];
-	char *filename;
-	int filename_len;
 	__be32 inode_type;
 
 	if(!lf_dip) {
@@ -47,7 +45,8 @@ int add_inode_to_lf(struct gfs2_inode *ip){
 
 		log_info( _("Locating/Creating lost and found directory\n"));
 
-        lf_dip = createi(ip->i_sbd->md.rooti, "lost+found", S_IFDIR | 0700, 0);
+		lf_dip = createi(ip->i_sbd->md.rooti, "lost+found",
+				 S_IFDIR | 0700, 0);
 		q = block_type(lf_dip->i_di.di_num.no_addr);
 		if(q != gfs2_inode_dir) {
 			/* This is a new lost+found directory, so set its
@@ -72,29 +71,18 @@ int add_inode_to_lf(struct gfs2_inode *ip){
 	}
 	switch(ip->i_di.di_mode & S_IFMT){
 	case S_IFDIR:
-		log_info( _("Adding .. entry pointing to lost+found for %llu\n"),
-				 (unsigned long long)ip->i_di.di_num.no_addr);
-		sprintf(tmp_name, "..");
-		filename_len = strlen(tmp_name);  /* no trailing NULL */
-		if(!(filename = malloc((sizeof(char) * filename_len) + 1))) {
-			log_err( _("Unable to allocate name\n"));
-			stack;
-			return -1;
-		}
-		if(!memset(filename, 0, (sizeof(char) * filename_len) + 1)) {
-			log_err( _("Unable to zero name\n"));
-			stack;
-			return -1;
-		}
-		memcpy(filename, tmp_name, filename_len);
+		log_info( _("Adding .. entry pointing to lost+found for "
+			    "directory %llu (0x%llx)\n"),
+			  (unsigned long long)ip->i_di.di_num.no_addr,
+			  (unsigned long long)ip->i_di.di_num.no_addr);
 
-		if(gfs2_dirent_del(ip, filename, filename_len))
-			log_warn( _("add_inode_to_lf:  "
-					 "Unable to remove \"..\" directory entry.\n"));
+		if(gfs2_dirent_del(ip, "..", 2))
+			log_warn( _("add_inode_to_lf: Unable to remove "
+				    "\"..\" directory entry.\n"));
 
-		dir_add(ip, filename, filename_len, &(lf_dip->i_di.di_num), DT_DIR);
-		free(filename);
-		sprintf(tmp_name, "lost_dir_%llu", ip->i_di.di_num.no_addr);
+		dir_add(ip, "..", 2, &(lf_dip->i_di.di_num), DT_DIR);
+		sprintf(tmp_name, "lost_dir_%llu",
+			(unsigned long long)ip->i_di.di_num.no_addr);
 		inode_type = DT_DIR;
 		break;
 	case S_IFREG:
@@ -126,26 +114,14 @@ int add_inode_to_lf(struct gfs2_inode *ip){
 		inode_type = DT_REG;
 		break;
 	}
-	filename_len = strlen(tmp_name);  /* no trailing NULL */
-	if(!(filename = malloc(sizeof(char) * filename_len))) {
-		log_err( _("Unable to allocate name\n"));
-			stack;
-			return -1;
-		}
-	if(!memset(filename, 0, sizeof(char) * filename_len)) {
-		log_err( _("Unable to zero name\n"));
-		stack;
-		return -1;
-	}
-	memcpy(filename, tmp_name, filename_len);
 
-	dir_add(lf_dip, filename, filename_len, &(ip->i_di.di_num), inode_type);
-  	increment_link(ip->i_sbd, ip->i_di.di_num.no_addr);
+	dir_add(lf_dip, tmp_name, strlen(tmp_name), &(ip->i_di.di_num),
+		inode_type);
+	increment_link(ip->i_sbd, ip->i_di.di_num.no_addr);
 	if(S_ISDIR(ip->i_di.di_mode))
 		increment_link(ip->i_sbd, lf_dip->i_di.di_num.no_addr);
 
-	free(filename);
 	log_notice( _("Added inode #%llu to lost+found dir\n"),
-		   (unsigned long long)ip->i_di.di_num.no_addr);
+		    (unsigned long long)ip->i_di.di_num.no_addr);
 	return 0;
 }
diff --git a/gfs2/fsck/metawalk.c b/gfs2/fsck/metawalk.c
index 1a701e1..b547f44 100644
--- a/gfs2/fsck/metawalk.c
+++ b/gfs2/fsck/metawalk.c
@@ -37,7 +37,7 @@ struct dup_blks *dupfind(uint64_t num)
 
 	for (tmp = head->next; tmp != head; tmp = tmp->next) {
 		b = osi_list_entry(tmp, struct dup_blks, list);
-		if (b->block_no == num)
+		if (b->block == num)
 			return b;
 	}
 	return NULL;
@@ -293,8 +293,7 @@ static int check_entries(struct gfs2_inode *ip, struct gfs2_buffer_head *bh,
 				bmodified(bh);
 				/* Mark dirent buffer as modified */
 				first = 0;
-			}
-			else {
+			} else {
 				error = pass->check_dentry(ip, dent, prev, bh,
 							   filename, count,
 							   pass->private);
@@ -306,7 +305,12 @@ static int check_entries(struct gfs2_inode *ip, struct gfs2_buffer_head *bh,
 		}
 
 		if ((char *)dent + de.de_rec_len >= bh_end){
-			log_debug( _("Last entry processed.\n"));
+			log_debug( _("Last entry processed for %lld->%lld "
+				     "(0x%llx->0x%llx).\n"),
+				   (unsigned long long)ip->i_di.di_num.no_addr,
+				   (unsigned long long)bh->b_blocknr,
+				   (unsigned long long)ip->i_di.di_num.no_addr,
+				   (unsigned long long)bh->b_blocknr);
 			break;
 		}
 
@@ -399,8 +403,7 @@ static int check_leaf_blks(struct gfs2_inode *ip, struct metawalk_fxns *pass)
 								  leaf info */
 			ref_count++;
 			continue;
-		}
-		else if(old_leaf == leaf_no) {
+		} else if(old_leaf == leaf_no) {
 			ref_count++;
 			continue;
 		}
@@ -502,11 +505,11 @@ static int check_leaf_blks(struct gfs2_inode *ip, struct metawalk_fxns *pass)
 				break;
 			}
 			exp_count = (1 << (ip->i_di.di_depth - leaf.lf_depth));
-			log_debug( _("expected count %u - di_depth %u, leaf depth %u\n"),
-					  exp_count, ip->i_di.di_depth, leaf.lf_depth);
+			/*log_debug( _("expected count %u - di_depth %u,
+			  leaf depth %u\n"),
+			  exp_count, ip->i_di.di_depth, leaf.lf_depth);*/
 
-			if(pass->check_dentry &&
-			   S_ISDIR(ip->i_di.di_mode)) {
+			if(pass->check_dentry && S_ISDIR(ip->i_di.di_mode)) {
 				error = check_entries(ip, lbh, DIR_EXHASH,
 						      &count, pass);
 
@@ -572,9 +575,8 @@ static int check_eattr_entries(struct gfs2_inode *ip,
 	int error = 0;
 	uint32_t offset = (uint32_t)sizeof(struct gfs2_meta_header);
 
-	if(!pass->check_eattr_entry) {
+	if(!pass->check_eattr_entry)
 		return 0;
-	}
 
 	ea_hdr = (struct gfs2_ea_header *)(bh->b_data +
 					  sizeof(struct gfs2_meta_header));
@@ -773,7 +775,7 @@ static int check_indirect_eattr(struct gfs2_inode *ip, uint64_t indirect,
 							 pass->private);
 			}
 			if (leaf_pointer_errors == leaf_pointers) {
-				if (indirect_buf->b_changed)
+				if (indirect_buf->b_modified)
 					gfs2_set_bitmap(sdp, indirect,
 							GFS2_BLKST_FREE);
 				gfs2_blockmap_set(sdp, bl, indirect,
@@ -806,8 +808,7 @@ int check_inode_eattr(struct gfs2_inode *ip, struct metawalk_fxns *pass)
 		  (unsigned long long)ip->i_di.di_num.no_addr);
 
 	if(ip->i_di.di_flags & GFS2_DIF_EA_INDIRECT){
-		if((error = check_indirect_eattr(ip, ip->i_di.di_eattr,
-						 pass)))
+		if((error = check_indirect_eattr(ip, ip->i_di.di_eattr, pass)))
 			stack;
 	} else {
 		error = check_leaf_eattr(ip, ip->i_di.di_eattr,
@@ -821,12 +822,13 @@ int check_inode_eattr(struct gfs2_inode *ip, struct metawalk_fxns *pass)
 
 /**
  * build_and_check_metalist - check a bunch of indirect blocks
- * Note: Every buffer put on the metalist should be "held".
+ *                            This includes hash table blocks for directories
+ *                            which are technically "data" in the bitmap.
+ *
  * @ip:
  * @mlp:
  */
-static int build_and_check_metalist(struct gfs2_inode *ip,
-				    osi_list_t *mlp,
+static int build_and_check_metalist(struct gfs2_inode *ip, osi_list_t *mlp,
 				    struct metawalk_fxns *pass)
 {
 	uint32_t height = ip->i_di.di_height;
@@ -841,7 +843,7 @@ static int build_and_check_metalist(struct gfs2_inode *ip,
 	/* if(<there are no indirect blocks to check>) */
 	if (height < 2)
 		return 0;
-	for (i = 1; i < height; i++){
+	for (i = 1; i < height; i++) {
 		prev_list = &mlp[i - 1];
 		cur_list = &mlp[i];
 
@@ -860,7 +862,7 @@ static int build_and_check_metalist(struct gfs2_inode *ip,
 					continue;
 				head_size = sizeof(struct gfs2_dinode);
 			}
-
+			/* Now check the metadata itself */
 			for (ptr = (uint64_t *)(bh->b_data + head_size);
 			     (char *)ptr < (bh->b_data + ip->i_sbd->bsize);
 			     ptr++) {
@@ -994,7 +996,6 @@ int check_metatree(struct gfs2_inode *ip, struct metawalk_fxns *pass)
 				big_file_comfort(ip, blks_checked);
 		}
 	}
-
 	if (ip->i_di.di_blocks > COMFORTABLE_BLKS) {
 		log_notice( _("\rLarge file at %lld (0x%llx) - 100 percent "
 			      "complete.                                   "
@@ -1036,8 +1037,8 @@ end:
 }
 
 /* Checks stuffed inode directories */
-static int check_linear_dir(struct gfs2_inode *ip, struct gfs2_buffer_head *bh,
-			    struct metawalk_fxns *pass)
+int check_linear_dir(struct gfs2_inode *ip, struct gfs2_buffer_head *bh,
+		     struct metawalk_fxns *pass)
 {
 	int error = 0;
 	uint16_t count = 0;
@@ -1051,7 +1052,6 @@ static int check_linear_dir(struct gfs2_inode *ip, struct gfs2_buffer_head *bh,
 	return error;
 }
 
-
 int check_dir(struct gfs2_sbd *sbp, uint64_t block, struct metawalk_fxns *pass)
 {
 	struct gfs2_inode *ip;
diff --git a/gfs2/fsck/metawalk.h b/gfs2/fsck/metawalk.h
index 0744ae6..1c1a646 100644
--- a/gfs2/fsck/metawalk.h
+++ b/gfs2/fsck/metawalk.h
@@ -18,26 +18,33 @@
 
 struct metawalk_fxns;
 
-int check_inode_eattr(struct gfs2_inode *ip, struct metawalk_fxns *pass);
-int check_metatree(struct gfs2_inode *ip, struct metawalk_fxns *pass);
-int check_dir(struct gfs2_sbd *sbp, uint64_t block,
-			  struct metawalk_fxns *pass);
-int remove_dentry_from_dir(struct gfs2_sbd *sbp, uint64_t dir,
-						   uint64_t dentryblock);
-int find_di(struct gfs2_sbd *sbp, uint64_t childblock, struct dir_info **dip);
-int dinode_hash_insert(osi_list_t *buckets, uint64_t key, struct dir_info *di);
-int dinode_hash_remove(osi_list_t *buckets, uint64_t key);
-int delete_blocks(struct gfs2_inode *ip, uint64_t block,
-		  struct gfs2_buffer_head **bh, const char *btype,
-		  void *private);
-int delete_metadata(struct gfs2_inode *ip, uint64_t block,
-		    struct gfs2_buffer_head **bh, void *private);
-int delete_data(struct gfs2_inode *ip, uint64_t block, void *private);
-int delete_eattr_indir(struct gfs2_inode *ip, uint64_t block, uint64_t parent,
-		       struct gfs2_buffer_head **bh, void *private);
-int delete_eattr_leaf(struct gfs2_inode *ip, uint64_t block, uint64_t parent,
-		      struct gfs2_buffer_head **bh, void *private);
-struct dup_blks *dupfind(uint64_t num);
+extern int check_inode_eattr(struct gfs2_inode *ip,
+			     struct metawalk_fxns *pass);
+extern int check_metatree(struct gfs2_inode *ip, struct metawalk_fxns *pass);
+extern int check_dir(struct gfs2_sbd *sbp, uint64_t block,
+		     struct metawalk_fxns *pass);
+extern int check_linear_dir(struct gfs2_inode *ip, struct gfs2_buffer_head *bh,
+			    struct metawalk_fxns *pass);
+extern int remove_dentry_from_dir(struct gfs2_sbd *sbp, uint64_t dir,
+				  uint64_t dentryblock);
+extern int find_di(struct gfs2_sbd *sbp, uint64_t childblock,
+		   struct dir_info **dip);
+extern int dinode_hash_insert(osi_list_t *buckets, uint64_t key,
+			      struct dir_info *di);
+extern int dinode_hash_remove(osi_list_t *buckets, uint64_t key);
+extern int delete_blocks(struct gfs2_inode *ip, uint64_t block,
+			 struct gfs2_buffer_head **bh, const char *btype,
+			 void *private);
+extern int delete_metadata(struct gfs2_inode *ip, uint64_t block,
+			   struct gfs2_buffer_head **bh, void *private);
+extern int delete_data(struct gfs2_inode *ip, uint64_t block, void *private);
+extern int delete_eattr_indir(struct gfs2_inode *ip, uint64_t block,
+			      uint64_t parent, struct gfs2_buffer_head **bh,
+			      void *private);
+extern int delete_eattr_leaf(struct gfs2_inode *ip, uint64_t block,
+			     uint64_t parent, struct gfs2_buffer_head **bh,
+			     void *private);
+extern struct dup_blks *dupfind(uint64_t num);
 
 #define is_duplicate(dblock) ((dupfind(dblock)) ? 1 : 0)
 
@@ -86,8 +93,7 @@ struct metawalk_fxns {
 				     struct gfs2_ea_header *ea_hdr_prev,
 				     void *private);
 	int (*finish_eattr_indir) (struct gfs2_inode *ip, int leaf_pointers,
-				   int leaf_pointer_errors,
-				   void *private);
+				   int leaf_pointer_errors, void *private);
 };
 
 #endif /* _METAWALK_H */
diff --git a/gfs2/fsck/pass1.c b/gfs2/fsck/pass1.c
index 40d316e..961a59c 100644
--- a/gfs2/fsck/pass1.c
+++ b/gfs2/fsck/pass1.c
@@ -87,8 +87,11 @@ static int leaf(struct gfs2_inode *ip, uint64_t block,
 {
 	struct block_count *bc = (struct block_count *) private;
 
-	log_debug( _("\tLeaf block at %15" PRIu64 " (0x%" PRIx64 ")\n"),
-			  block, block);
+	log_debug( _("\tDinode %lld (0x%llx) references leaf block #%lld "
+		     "(0x%llx)\n"),
+		   (unsigned long long)ip->i_di.di_num.no_addr,
+		   (unsigned long long)ip->i_di.di_num.no_addr,
+		   (unsigned long long)block, (unsigned long long)block);
 	gfs2_blockmap_set(ip->i_sbd, bl, block, gfs2_leaf_blk);
 	bc->indir_count++;
 	return 0;
@@ -162,7 +165,7 @@ static int check_data(struct gfs2_inode *ip, uint64_t block, void *private)
 		return 1;
 	}
 	q = block_type(block);
-	if(q != gfs2_block_free) {
+	if (q != gfs2_block_free) {
 		log_err( _("Found duplicate block referenced as data at %"
 			   PRIu64 " (0x%"PRIx64 ")\n"), block, block);
 		if (q != gfs2_meta_inval) {
@@ -248,8 +251,7 @@ static int ask_remove_inode_eattr(struct gfs2_inode *ip,
 	log_err( _("Inode %lld (0x%llx) has unrecoverable Extended Attribute "
 		   "errors.\n"), (unsigned long long)ip->i_di.di_num.no_addr,
 		 (unsigned long long)ip->i_di.di_num.no_addr);
-	if (query( _("Clear all Extended Attributes from the "
-		     "inode? (y/n) "))) {
+	if (query( _("Clear all Extended Attributes from the inode? (y/n) "))){
 		if (!remove_inode_eattr(ip, bc,
 					is_duplicate(ip->i_di.di_eattr)))
 			log_err( _("Extended attributes were removed.\n"));
@@ -799,14 +801,14 @@ static int handle_di(struct gfs2_sbd *sdp, struct gfs2_buffer_head *bh,
 	}
 
 	pass1_fxns.private = &bc;
-
 	error = check_metatree(ip, &pass1_fxns);
 	if (fsck_abort || error < 0) {
 		fsck_inode_put(&ip);
 		return 0;
 	}
-	if(error > 0) {
-		log_warn( _("Marking inode #%llu (0x%llx) invalid\n"),
+	if (error > 0) {
+		log_err( _("Error: inode %llu (0x%llx) has unrecoverable "
+			   "errors; invalidating.\n"),
 			 (unsigned long long)ip->i_di.di_num.no_addr,
 			 (unsigned long long)ip->i_di.di_num.no_addr);
 		/* FIXME: Must set all leaves invalid as well */
@@ -843,7 +845,9 @@ static int handle_di(struct gfs2_sbd *sdp, struct gfs2_buffer_head *bh,
 			ip->i_di.di_blocks = 1 + bc.indir_count + bc.data_count +
 				bc.ea_count;
 			bmodified(ip->i_bh);
-			gfs2_dinode_out(&ip->i_di, ip->i_bh);
+			log_err( _("Block count for #%llu (0x%llx) fixed\n"),
+				(unsigned long long)ip->i_di.di_num.no_addr,
+				(unsigned long long)ip->i_di.di_num.no_addr);
 		} else
 			log_err( _("Bad block count for #%llu (0x%llx"
 				") not fixed\n"),
@@ -855,46 +859,6 @@ static int handle_di(struct gfs2_sbd *sdp, struct gfs2_buffer_head *bh,
 	return 0;
 }
 
-static int scan_meta(struct gfs2_sbd *sdp, struct gfs2_buffer_head *bh,
-			  uint64_t block)
-{
-	if (gfs2_check_meta(bh, 0)) {
-		log_info( _("Found invalid metadata at #%llu (0x%llx)\n"),
-			  (unsigned long long)block,
-			  (unsigned long long)block);
-		if(gfs2_blockmap_set(sdp, bl, block, gfs2_meta_inval)) {
-			stack;
-			return -1;
-		}
-		if(query( _("Okay to free the invalid block? (y/n)"))) {
-			gfs2_set_bitmap(sdp, block, GFS2_BLKST_FREE);
-			log_err( _("The invalid block was freed.\n"));
-		} else {
-			log_err( _("The invalid block was ignored.\n"));
-		}
-		return 0;
-	}
-
-	log_debug( _("Checking metadata block #%" PRIu64 " (0x%" PRIx64 ")\n"), block,
-			  block);
-
-	if (!gfs2_check_meta(bh, GFS2_METATYPE_DI)) {
-		/* handle_di calls inode_get, then inode_put, which does brelse.   */
-		/* In order to prevent brelse from getting the count off, hold it. */
-		if(handle_di(sdp, bh, block)) {
-			stack;
-			return -1;
-		}
-	}
-	/* Ignore everything else - they should be hit by the handle_di step.
-	 * Don't check NONE either, because check_meta passes everything if
-	 * GFS2_METATYPE_NONE is specified.
-	 * Hopefully, other metadata types such as indirect blocks will be
-	 * handled when the inode itself is processed, and if it's not, it
-	 * should be caught in pass5. */
-	return 0;
-}
-
 /**
  * pass1 - walk through inodes and check inode state
  *
@@ -935,10 +899,9 @@ int pass1(struct gfs2_sbd *sbp)
 	 * uses the rg bitmaps, so maybe that's the best way to start
 	 * things - we can change the method later if necessary.
 	 */
-
 	for (tmp = sbp->rglist.next; tmp != &sbp->rglist;
-	     tmp = tmp->next, rg_count++){
-		log_info( _("Checking metadata in Resource Group #%" PRIu64 "\n"),
+	     tmp = tmp->next, rg_count++) {
+		log_debug( _("Checking metadata in Resource Group #%" PRIu64 "\n"),
 				 rg_count);
 		rgd = osi_list_entry(tmp, struct rgrp_list, list);
 		for (i = 0; i < rgd->ri.ri_length; i++) {
@@ -955,9 +918,12 @@ int pass1(struct gfs2_sbd *sbp)
 
 		while (1) {
 			/* "block" is relative to the entire file system */
+			/* Get the next dinode in the file system, according
+			   to the bitmap.  This should ONLY be dinodes. */
 			if (gfs2_next_rg_meta(rgd, &block, first))
 				break;
 			warm_fuzzy_stuff(block);
+
 			if (fsck_abort) /* if asked to abort */
 				return FSCK_OK;
 			if (skip_this_pass) {
@@ -967,11 +933,36 @@ int pass1(struct gfs2_sbd *sbp)
 			}
 			bh = bread(sbp, block);
 
-			if (scan_meta(sbp, bh, block)) {
+			/*log_debug( _("Checking metadata block #%" PRIu64
+			  " (0x%" PRIx64 ")\n"), block, block);*/
+
+			if (gfs2_check_meta(bh, GFS2_METATYPE_DI)) {
+				log_err( _("Found invalid inode at block #"
+					   "%llu (0x%llx)\n"),
+					 (unsigned long long)block,
+					 (unsigned long long)block);
+				if(query( _("Okay to free the invalid block? "
+					    "(y/n)"))) {
+					gfs2_set_bitmap(sbp, block,
+							GFS2_BLKST_FREE);
+					log_err( _("The invalid block was "
+						   "freed.\n"));
+				} else {
+					log_err( _("The invalid block was "
+						   "ignored.\n"));
+				}
+			} else if (handle_di(sbp, bh, block) < 0) {
 				stack;
 				brelse(bh);
 				return FSCK_ERROR;
 			}
+			/* Ignore everything else - they should be hit by the
+			   handle_di step.  Don't check NONE either, because
+			   check_meta passes everything if GFS2_METATYPE_NONE
+			   is specified.  Hopefully, other metadata types such
+			   as indirect blocks will be handled when the inode
+			   itself is processed, and if it's not, it should be
+			   caught in pass5. */
 			brelse(bh);
 			first = 0;
 		}
diff --git a/gfs2/fsck/pass1b.c b/gfs2/fsck/pass1b.c
index 43158ef..57e4c47 100644
--- a/gfs2/fsck/pass1b.c
+++ b/gfs2/fsck/pass1b.c
@@ -176,7 +176,7 @@ static int clear_dup_metalist(struct gfs2_inode *ip, uint64_t block,
 
 	if(dh->ref_count == 1)
 		return 1;
-	if(block == dh->b->block_no) {
+	if(block == dh->b->block) {
 		log_err( _("Found duplicate reference in inode \"%s\" at "
 			   "block #%llu (0x%llx) to block #%llu (0x%llx)\n"),
 			 dh->id->name ? dh->id->name : _("unknown name"),
@@ -210,7 +210,7 @@ static int clear_dup_eattr_indir(struct gfs2_inode *ip, uint64_t block,
 	*bh = NULL;
 	if(dh->ref_count == 1)
 		return 1;
-	if(block == dh->b->block_no) {
+	if(block == dh->b->block) {
 		log_err( _("Found dup in inode \"%s\" with address #%llu"
 			" (0x%llx) with block #%llu (0x%llx)\n"),
 			dh->id->name ? dh->id->name : _("unknown name"),
@@ -236,7 +236,7 @@ static int clear_dup_eattr_leaf(struct gfs2_inode *ip, uint64_t block,
 
 	if(dh->ref_count == 1)
 		return 1;
-	if(block == dh->b->block_no) {
+	if(block == dh->b->block) {
 		log_err( _("Found dup in inode \"%s\" with address #%llu"
 			" (0x%llx) with block #%llu (0x%llx)\n"),
 			dh->id->name ? dh->id->name : _("unknown name"),
@@ -308,7 +308,7 @@ static int clear_eattr_extentry(struct gfs2_inode *ip, uint64_t *ea_data_ptr,
 
 	if(dh->ref_count == 1)
 		return 1;
-	if(block == dh->b->block_no) {
+	if(block == dh->b->block) {
 		log_err( _("Found dup in inode \"%s\" with address #%llu"
 			" (0x%llx) with block #%llu (0x%llx)\n"),
 			dh->id->name ? dh->id->name : _("unknown name"),
@@ -331,7 +331,7 @@ static int clear_eattr_extentry(struct gfs2_inode *ip, uint64_t *ea_data_ptr,
 static int find_block_ref(struct gfs2_sbd *sbp, uint64_t inode, struct dup_blks *b)
 {
 	struct gfs2_inode *ip;
-	struct fxn_info myfi = {b->block_no, 0, 1};
+	struct fxn_info myfi = {b->block, 0, 1};
 	struct inode_with_dups *id = NULL;
 	struct metawalk_fxns find_refs = {
 		.private = (void*) &myfi,
@@ -348,7 +348,7 @@ static int find_block_ref(struct gfs2_sbd *sbp, uint64_t inode, struct dup_blks
 	ip = fsck_load_inode(sbp, inode); /* bread, inode_get */
 	log_debug( _("Checking inode %" PRIu64 " (0x%" PRIx64 ")'s "
 		     "metatree for references to block %" PRIu64 " (0x%" PRIx64
-		     ")\n"), inode, inode, b->block_no, b->block_no);
+		     ")\n"), inode, inode, b->block, b->block);
 	if(check_metatree(ip, &find_refs)) {
 		stack;
 		fsck_inode_put(&ip); /* out, brelse, free */
@@ -372,7 +372,7 @@ static int find_block_ref(struct gfs2_sbd *sbp, uint64_t inode, struct dup_blks
 		}
 		log_debug( _("Found %d entries with block %" PRIu64
 				  " (0x%" PRIx64 ") in inode #%" PRIu64 " (0x%" PRIx64 ")\n"),
-				  myfi.found, b->block_no, b->block_no, inode, inode);
+				  myfi.found, b->block, b->block, inode, inode);
 		id->dup_count = myfi.found;
 		id->block_no = inode;
 		id->ea_only = myfi.ea_only;
@@ -417,7 +417,7 @@ static int handle_dup_blk(struct gfs2_sbd *sbp, struct dup_blks *b)
 		struct gfs2_buffer_head *bh;
 		uint32_t cmagic;
 
-		bh = bread(sbp, b->block_no);
+		bh = bread(sbp, b->block);
 		cmagic = ((struct gfs2_meta_header *)(bh->b_data))->mh_magic;
 		brelse(bh);
 		if (be32_to_cpu(cmagic) == GFS2_MAGIC) {
@@ -428,8 +428,8 @@ static int handle_dup_blk(struct gfs2_sbd *sbp, struct dup_blks *b)
 				    "but the block is really metadata.\n"),
 				  id->name, (unsigned long long)id->block_no,
 				  (unsigned long long)id->block_no,
-				  (unsigned long long)b->block_no,
-				  (unsigned long long)b->block_no);
+				  (unsigned long long)b->block,
+				  (unsigned long long)b->block);
 			if (query( _("Clear the inode? (y/n) "))) {
 				log_warn( _("Clearing inode %lld (0x%llx)...\n"),
 					 (unsigned long long)id->block_no,
@@ -453,8 +453,7 @@ static int handle_dup_blk(struct gfs2_sbd *sbp, struct dup_blks *b)
 
 	log_notice( _("Block %llu (0x%llx) has %d inodes referencing it"
 		   " for a total of %d duplicate references\n"),
-		   (unsigned long long)b->block_no,
-		   (unsigned long long)b->block_no,
+		   (unsigned long long)b->block, (unsigned long long)b->block,
 		   dh.ref_inode_count, dh.ref_count);
 
 	osi_list_foreach(tmp, &b->ref_inode_list) {
@@ -463,8 +462,8 @@ static int handle_dup_blk(struct gfs2_sbd *sbp, struct dup_blks *b)
 			    "block %llu (0x%llx)\n"), id->name,
 			  (unsigned long long)id->block_no,
 			  (unsigned long long)id->block_no,
-			  id->dup_count, (unsigned long long)b->block_no,
-			  (unsigned long long)b->block_no);
+			  id->dup_count, (unsigned long long)b->block,
+			  (unsigned long long)b->block);
 	}
 	osi_list_foreach(tmp, &b->ref_inode_list) {
 		id = osi_list_entry(tmp, struct inode_with_dups, list);
@@ -565,6 +564,12 @@ out:
                 b = osi_list_entry(tmp, struct dup_blks, list);
 		if (!skip_this_pass && !rc) /* no error & not asked to skip the rest */
 			handle_dup_blk(sbp, b);
+		/* Do not attempt to free the dup_blocks list or its parts
+		   here because any func that calls check_metatree needs
+		   to check duplicate status based on this linked list.
+		   This is especially true for pass2 where it may delete "bad"
+		   inodes, and we can't delete an inode's indirect block if
+		   it was a duplicate (therefore in use by another dinode). */
 	}
 	return rc;
 }
diff --git a/gfs2/fsck/pass1c.c b/gfs2/fsck/pass1c.c
index 06020f0..d89b3b4 100644
--- a/gfs2/fsck/pass1c.c
+++ b/gfs2/fsck/pass1c.c
@@ -219,7 +219,6 @@ static int check_eattr_extentry(struct gfs2_inode *ip, uint64_t *ea_ptr,
 	uint8_t q;
 	struct gfs2_sbd *sbp = ip->i_sbd;
 
-
 	q = block_type(be64_to_cpu(*ea_ptr));
 	if(q != gfs2_meta_eattr) {
 		if(remove_eattr_entry(sbp, leaf_bh, ea_hdr, ea_hdr_prev)){
diff --git a/gfs2/fsck/pass2.c b/gfs2/fsck/pass2.c
index 2d748e1..1547e6e 100644
--- a/gfs2/fsck/pass2.c
+++ b/gfs2/fsck/pass2.c
@@ -32,7 +32,7 @@
 /* Set children's parent inode in dir_info structure - ext2 does not set
  * dotdot inode here, but instead in pass3 - should we? */
 static int set_parent_dir(struct gfs2_sbd *sbp, uint64_t childblock,
-				   uint64_t parentblock)
+			  uint64_t parentblock)
 {
 	struct dir_info *di;
 
@@ -50,7 +50,7 @@ static int set_parent_dir(struct gfs2_sbd *sbp, uint64_t childblock,
 		}
 	} else {
 		log_err( _("Unable to find block %"PRIu64" (0x%" PRIx64
-				") in dir_info list\n"),	childblock,	childblock);
+			   ") in dir_info list\n"), childblock, childblock);
 		return -1;
 	}
 
@@ -106,9 +106,9 @@ static int check_eattr_leaf(struct gfs2_inode *ip, uint64_t block,
 static const char *de_type_string(uint8_t de_type)
 {
 	const char *de_types[15] = {"unknown", "fifo", "chrdev", "invalid",
-								"directory", "invalid", "blkdev", "invalid",
-								"file", "invalid", "symlink", "invalid",
-								"socket", "invalid", "wht"};
+				    "directory", "invalid", "blkdev", "invalid",
+				    "file", "invalid", "symlink", "invalid",
+				    "socket", "invalid", "wht"};
 	if (de_type < 15)
 		return de_types[de_type];
 	return de_types[3]; /* invalid */
@@ -233,8 +233,10 @@ static int check_dentry(struct gfs2_inode *ip, struct gfs2_dirent *dent,
 		strncpy(tmp_name, filename, MAX_FILENAME - 1);
 
 	if(gfs2_check_range(ip->i_sbd, entryblock)) {
-		log_err( _("Block # referenced by directory entry %s is out of range\n"),
-				tmp_name);
+		log_err( _("Block # referenced by directory entry %s in inode "
+			   "%lld (0x%llx) is out of range\n"),
+			 tmp_name, (unsigned long long)ip->i_di.di_num.no_addr,
+			 (unsigned long long)ip->i_di.di_num.no_addr);
 		if(query( _("Clear directory entry tp out of range block? (y/n) "))) {
 			log_err( _("Clearing %s\n"), tmp_name);
 			dirent2_del(ip, bh, prev_de, dent);
@@ -244,10 +246,12 @@ static int check_dentry(struct gfs2_inode *ip, struct gfs2_dirent *dent,
 			log_err( _("Directory entry to out of range block remains\n"));
 			(*count)++;
 			ds->entry_count++;
+			/* can't do this because the block is out of range:
+			   increment_link(entryblock); */
 			return 0;
 		}
 	}
-	q = block_type(de->de_inum.no_addr);
+	q = block_type(entryblock);
 	/* Get the status of the directory inode */
 	if(q == gfs2_bad_block) {
 		/* This entry's inode has bad blocks in it */
@@ -256,14 +260,13 @@ static int check_dentry(struct gfs2_inode *ip, struct gfs2_dirent *dent,
 		log_err( _("Found a bad directory entry: %s\n"), filename);
 
 		if(query( _("Delete inode containing bad blocks? (y/n)"))) {
-			entry_ip = fsck_load_inode(sbp, de->de_inum.no_addr);
+			entry_ip = fsck_load_inode(sbp, entryblock);
 			check_inode_eattr(entry_ip, &pass2_fxns_delete);
 			check_metatree(entry_ip, &pass2_fxns_delete);
 			bmodified(entry_ip->i_bh);
 			fsck_inode_put(&entry_ip);
 			dirent2_del(ip, bh, prev_de, dent);
-			gfs2_blockmap_set(sbp, bl, de->de_inum.no_addr,
-				       gfs2_block_free);
+			gfs2_blockmap_set(sbp, bl, entryblock, gfs2_block_free);
 			bmodified(bh);
 			log_warn( _("The inode containing bad blocks was "
 				    "deleted.\n"));
@@ -276,15 +279,12 @@ static int check_dentry(struct gfs2_inode *ip, struct gfs2_dirent *dent,
 		}
 
 	}
-	if(q != gfs2_inode_dir && q != gfs2_inode_file &&
-	   q != gfs2_inode_lnk && q != gfs2_inode_blk &&
-	   q != gfs2_inode_chr && q != gfs2_inode_fifo &&
-	   q != gfs2_inode_sock) {
-		log_err( _("Directory entry '%s' at block %llu (0x%llx"
-			   ") in dir inode %llu (0x%llx"
-			   ") block type %d: %s.\n"), tmp_name,
-			 (unsigned long long)de->de_inum.no_addr,
-			 (unsigned long long)de->de_inum.no_addr,
+	if(q < gfs2_inode_dir || q > gfs2_inode_sock) {
+		log_err( _("Directory entry '%s' referencing inode %llu "
+			   "(0x%llx) in dir inode %llu (0x%llx) block type "
+			   "%d: %s.\n"), tmp_name,
+			 (unsigned long long)entryblock,
+			 (unsigned long long)entryblock,
 			 (unsigned long long)ip->i_di.di_num.no_addr,
 			 (unsigned long long)ip->i_di.di_num.no_addr,
 			 q, q == gfs2_meta_inval ?
@@ -305,20 +305,19 @@ static int check_dentry(struct gfs2_inode *ip, struct gfs2_dirent *dent,
 				return 1;
 
 			/* Now try to clear the dinode, if it is an dinode */
-			bhi = bread(sbp, de->de_inum.no_addr);
+			bhi = bread(sbp, entryblock);
 			error = gfs2_check_meta(bhi, GFS2_METATYPE_DI);
 			bmodified(bhi);
 			brelse(bhi);
 			if (error)
 				return 1; /* not a dinode: nothing to delete */
 
-			entry_ip = fsck_load_inode(sbp, de->de_inum.no_addr);
+			entry_ip = fsck_load_inode(sbp, entryblock);
 			check_inode_eattr(entry_ip, &pass2_fxns_delete);
 			check_metatree(entry_ip, &pass2_fxns_delete);
 			bmodified(entry_ip->i_bh);
 			fsck_inode_put(&entry_ip);
-			gfs2_blockmap_set(sbp, bl, de->de_inum.no_addr,
-				       gfs2_block_free);
+			gfs2_blockmap_set(sbp, bl, entryblock, gfs2_block_free);
 
 			return 1;
 		} else {
@@ -331,19 +330,29 @@ static int check_dentry(struct gfs2_inode *ip, struct gfs2_dirent *dent,
 
 	error = check_file_type(de->de_type, q);
 	if(error < 0) {
+		log_err( _("Error: directory entry type is "
+			   "incompatible with block type at block %lld "
+			   "(0x%llx) in directory inode %llu (0x%llx).\n"),
+			 (unsigned long long)entryblock,
+			 (unsigned long long)entryblock,
+			 (unsigned long long)ip->i_di.di_num.no_addr,
+			 (unsigned long long)ip->i_di.di_num.no_addr);
+		log_err( _("Directory entry type is %d, block type is %d.\n"),
+			 de->de_type, q);
 		stack;
 		return -1;
 	}
 	if(error > 0) {
-		log_warn( _("Type '%s' in dir entry (%s, %llu/0x%llx) conflicts"
+		log_err( _("Type '%s' in dir entry (%s, %llu/0x%llx) conflicts"
 			 " with type '%s' in dinode. (Dir entry is stale.)\n"),
 			 de_type_string(de->de_type), tmp_name,
-			 (unsigned long long)de->de_inum.no_addr,
-			 (unsigned long long)de->de_inum.no_addr,
+			 (unsigned long long)entryblock,
+			 (unsigned long long)entryblock,
 			 block_type_string(q));
 		if(query( _("Clear stale directory entry? (y/n) "))) {
-			entry_ip = fsck_load_inode(sbp, de->de_inum.no_addr);
-			check_inode_eattr(entry_ip, &clear_eattrs);
+			entry_ip = fsck_load_inode(sbp, entryblock);
+		check_inode_eattr(entry_ip, &clear_eattrs);
+		if (entry_ip != ip)
 			fsck_inode_put(&entry_ip);
 
 			dirent2_del(ip, bh, prev_de, dent);
@@ -367,7 +376,7 @@ static int check_dentry(struct gfs2_inode *ip, struct gfs2_dirent *dent,
 				(unsigned long long)ip->i_di.di_num.no_addr,
 				(unsigned long long)ip->i_di.di_num.no_addr);
 			if(query( _("Clear duplicate '.' entry? (y/n) "))) {
-				entry_ip = fsck_load_inode(sbp, de->de_inum.no_addr);
+				entry_ip = fsck_load_inode(sbp, entryblock);
 				check_inode_eattr(entry_ip, &clear_eattrs);
 				fsck_inode_put(&entry_ip);
 
@@ -379,7 +388,7 @@ static int check_dentry(struct gfs2_inode *ip, struct gfs2_dirent *dent,
 				/* FIXME: Should we continue on here
 				 * and check the rest of the '.'
 				 * entry? */
-				increment_link(sbp, de->de_inum.no_addr);
+				increment_link(sbp, entryblock);
 				(*count)++;
 				ds->entry_count++;
 				return 0;
@@ -390,19 +399,19 @@ static int check_dentry(struct gfs2_inode *ip, struct gfs2_dirent *dent,
 		 * location */
 
 		/* check that '.' refers to this inode */
-		if(de->de_inum.no_addr != ip->i_di.di_num.no_addr) {
+		if(entryblock != ip->i_di.di_num.no_addr) {
 			log_err( _("'.' entry's value incorrect in directory %llu"
 				" (0x%llx).  Points to %llu"
 				" (0x%llx) when it should point to %llu"
 				" (0x%llx).\n"),
-				(unsigned long long)de->de_inum.no_addr,
-				(unsigned long long)de->de_inum.no_addr,
-				(unsigned long long)de->de_inum.no_addr,
-				(unsigned long long)de->de_inum.no_addr,
+				(unsigned long long)entryblock,
+				(unsigned long long)entryblock,
+				(unsigned long long)entryblock,
+				(unsigned long long)entryblock,
 				(unsigned long long)ip->i_di.di_num.no_addr,
 				(unsigned long long)ip->i_di.di_num.no_addr);
 			if(query( _("Remove '.' reference? (y/n) "))) {
-				entry_ip = fsck_load_inode(sbp, de->de_inum.no_addr);
+				entry_ip = fsck_load_inode(sbp, entryblock);
 				check_inode_eattr(entry_ip, &clear_eattrs);
 				fsck_inode_put(&entry_ip);
 
@@ -414,7 +423,7 @@ static int check_dentry(struct gfs2_inode *ip, struct gfs2_dirent *dent,
 				log_err( _("Invalid '.' reference remains\n"));
 				/* Not setting ds->dotdir here since
 				 * this '.' entry is invalid */
-				increment_link(sbp, de->de_inum.no_addr);
+				increment_link(sbp, entryblock);
 				(*count)++;
 				ds->entry_count++;
 				return 0;
@@ -422,7 +431,7 @@ static int check_dentry(struct gfs2_inode *ip, struct gfs2_dirent *dent,
 		}
 
 		ds->dotdir = 1;
-		increment_link(sbp, de->de_inum.no_addr);
+		increment_link(sbp, entryblock);
 		(*count)++;
 		ds->entry_count++;
 
@@ -437,7 +446,7 @@ static int check_dentry(struct gfs2_inode *ip, struct gfs2_dirent *dent,
 				(unsigned long long)ip->i_di.di_num.no_addr);
 			if(query( _("Clear duplicate '..' entry? (y/n) "))) {
 
-				entry_ip = fsck_load_inode(sbp, de->de_inum.no_addr);
+				entry_ip = fsck_load_inode(sbp, entryblock);
 				check_inode_eattr(entry_ip, &clear_eattrs);
 				fsck_inode_put(&entry_ip);
 
@@ -449,7 +458,7 @@ static int check_dentry(struct gfs2_inode *ip, struct gfs2_dirent *dent,
 				/* FIXME: Should we continue on here
 				 * and check the rest of the '..'
 				 * entry? */
-				increment_link(sbp, de->de_inum.no_addr);
+				increment_link(sbp, entryblock);
 				(*count)++;
 				ds->entry_count++;
 				return 0;
@@ -462,8 +471,9 @@ static int check_dentry(struct gfs2_inode *ip, struct gfs2_dirent *dent,
 				(unsigned long long)ip->i_di.di_num.no_addr,
 				(unsigned long long)ip->i_di.di_num.no_addr);
 			if(query( _("Clear bad '..' directory entry? (y/n) "))) {
-				entry_ip = fsck_load_inode(sbp, de->de_inum.no_addr);
-				check_inode_eattr(entry_ip, &clear_eattrs);
+				entry_ip = fsck_load_inode(sbp, entryblock);
+			check_inode_eattr(entry_ip, &clear_eattrs);
+			if (entry_ip != ip)
 				fsck_inode_put(&entry_ip);
 
 				dirent2_del(ip, bh, prev_de, dent);
@@ -471,14 +481,13 @@ static int check_dentry(struct gfs2_inode *ip, struct gfs2_dirent *dent,
 				return 1;
 			} else {
 				log_err( _("Bad '..' directory entry remains\n"));
-				increment_link(sbp, de->de_inum.no_addr);
+				increment_link(sbp, entryblock);
 				(*count)++;
 				ds->entry_count++;
 				return 0;
 			}
 		}
-		/* GFS2 does not rely on '..' being in a
-		 * certain location */
+		/* GFS2 does not rely on '..' being in a certain location */
 
 		/* Add the address this entry is pointing to
 		 * to this inode's dotdot_parent in
@@ -489,27 +498,26 @@ static int check_dentry(struct gfs2_inode *ip, struct gfs2_dirent *dent,
 		}
 
 		ds->dotdotdir = 1;
-		increment_link(sbp, de->de_inum.no_addr);
+		increment_link(sbp, entryblock);
 		(*count)++;
 		ds->entry_count++;
 		return 0;
 	}
 
-	/* After this point we're only concerned with
-	 * directories */
+	/* After this point we're only concerned with directories */
 	if(q != gfs2_inode_dir) {
 		log_debug( _("Found non-dir inode dentry\n"));
-		increment_link(sbp, de->de_inum.no_addr);
+		increment_link(sbp, entryblock);
 		(*count)++;
 		ds->entry_count++;
 		return 0;
 	}
 
-	log_debug( _("Found plain directory dentry\n"));
+	/*log_debug( _("Found plain directory dentry\n"));*/
 	error = set_parent_dir(sbp, entryblock, ip->i_di.di_num.no_addr);
 	if(error > 0) {
 		log_err( _("%s: Hard link to block %" PRIu64" (0x%" PRIx64
-				") detected.\n"), filename, entryblock, entryblock);
+			   ") detected.\n"), tmp_name, entryblock, entryblock);
 
 		if(query( _("Clear hard link to directory? (y/n) "))) {
 			bmodified(bh);
@@ -523,12 +531,11 @@ static int check_dentry(struct gfs2_inode *ip, struct gfs2_dirent *dent,
 			ds->entry_count++;
 			return 0;
 		}
-	}
-	else if (error < 0) {
+	} else if (error < 0) {
 		stack;
 		return -1;
 	}
-	increment_link(sbp, de->de_inum.no_addr);
+	increment_link(sbp, entryblock);
 	(*count)++;
 	ds->entry_count++;
 	/* End of checks */
@@ -663,7 +670,7 @@ static inline int is_system_dir(struct gfs2_sbd *sbp, uint64_t block)
  */
 int pass2(struct gfs2_sbd *sbp)
 {
-	uint64_t i;
+	uint64_t dirblk;
 	uint8_t q;
 	struct dir_status ds = {0};
 	struct gfs2_inode *ip;
@@ -692,43 +699,44 @@ int pass2(struct gfs2_sbd *sbp)
 	}
 	log_info( _("Checking directory inodes.\n"));
 	/* Grab each directory inode, and run checks on it */
-	for(i = 0; i < last_fs_block; i++) {
-		warm_fuzzy_stuff(i);
+	for(dirblk = 0; dirblk < last_fs_block; dirblk++) {
+		warm_fuzzy_stuff(dirblk);
 		if (skip_this_pass || fsck_abort) /* if asked to skip the rest */
 			return FSCK_OK;
 
 		/* Skip the system inodes - they're checked above */
-		if (is_system_dir(sbp, i))
+		if (is_system_dir(sbp, dirblk))
 			continue;
 
-		q = block_type(i);
+		q = block_type(dirblk);
 
 		if(q != gfs2_inode_dir)
 			continue;
 
 		log_debug( _("Checking directory inode at block %"PRIu64" (0x%"
-				  PRIx64 ")\n"), i, i);
+				  PRIx64 ")\n"), dirblk, dirblk);
 
 		memset(&ds, 0, sizeof(ds));
 		pass2_fxns.private = (void *) &ds;
 		if(ds.q == gfs2_bad_block) {
 			/* First check that the directory's metatree
 			 * is valid */
-			ip = fsck_load_inode(sbp, i);
+			ip = fsck_load_inode(sbp, dirblk);
 			if(check_metatree(ip, &pass2_fxns)) {
 				fsck_inode_put(&ip);
 				stack;
 				return FSCK_ERROR;
 			}
 		}
-		error = check_dir(sbp, i, &pass2_fxns);
+		error = check_dir(sbp, dirblk, &pass2_fxns);
 		if(error < 0) {
 			stack;
 			return FSCK_ERROR;
 		}
 		if (error > 0) {
 			struct dir_info *di = NULL;
-			error = find_di(sbp, i, &di);
+
+			error = find_di(sbp, dirblk, &di);
 			if(error < 0) {
 				stack;
 				return FSCK_ERROR;
@@ -737,30 +745,33 @@ int pass2(struct gfs2_sbd *sbp)
 				/* FIXME: factor */
 				if(query( _("Remove directory entry for bad"
 					    " inode %"PRIu64" (0x%" PRIx64 ") in %"PRIu64
-					    " (0x%" PRIx64 ")? (y/n)"), i, i, di->treewalk_parent,
+					    " (0x%" PRIx64 ")? (y/n)"),
+					  dirblk, dirblk, di->treewalk_parent,
 					  di->treewalk_parent)) {
-					error = remove_dentry_from_dir(sbp, di->treewalk_parent,
-												   i);
+					error = remove_dentry_from_dir(sbp,
+							di->treewalk_parent,
+								       dirblk);
 					if(error < 0) {
 						stack;
 						return FSCK_ERROR;
 					}
 					if(error > 0) {
 						log_warn( _("Unable to find dentry for %"
-								 PRIu64 " (0x%" PRIx64 ") in %" PRIu64
-								 " (0x%" PRIx64 ")\n"), i, i,
-								 di->treewalk_parent, di->treewalk_parent);
+							    PRIu64 " (0x%" PRIx64 ") in %" PRIu64
+							    " (0x%" PRIx64 ")\n"), dirblk, dirblk,
+							  di->treewalk_parent, di->treewalk_parent);
 					}
 					log_warn( _("Directory entry removed\n"));
 				} else
 					log_err( _("Directory entry to invalid inode remains.\n"));
 			}
-			gfs2_blockmap_set(sbp, bl, i, gfs2_meta_inval);
+			gfs2_blockmap_set(sbp, bl, dirblk, gfs2_meta_inval);
 		}
-		ip = fsck_load_inode(sbp, i);
+		ip = fsck_load_inode(sbp, dirblk);
 		if(!ds.dotdir) {
 			log_err(_("No '.' entry found for directory inode at "
-				  "block %"PRIu64" (0x%" PRIx64 ")\n"), i, i);
+				  "block %"PRIu64" (0x%" PRIx64 ")\n"),
+				dirblk, dirblk);
 
 			if (query( _("Is it okay to add '.' entry? (y/n) "))) {
 				sprintf(tmp_name, ".");
diff --git a/gfs2/fsck/pass3.c b/gfs2/fsck/pass3.c
index 7d4fe41..5ccccc8 100644
--- a/gfs2/fsck/pass3.c
+++ b/gfs2/fsck/pass3.c
@@ -68,11 +68,12 @@ static int attach_dotdot_to(struct gfs2_sbd *sbp, uint64_t newdotdot,
 	bmodified(ip->i_bh);
 	fsck_inode_put(&ip);
 	fsck_inode_put(&pip);
+	free(filename);
 	return 0;
 }
 
 static struct dir_info *mark_and_return_parent(struct gfs2_sbd *sbp,
-										struct dir_info *di)
+					       struct dir_info *di)
 {
 	struct dir_info *pdi;
 	uint8_t q_dotdot, q_treewalk;
@@ -111,8 +112,7 @@ static struct dir_info *mark_and_return_parent(struct gfs2_sbd *sbp,
 								 di->dotdot_parent, di->dinode);
 				di->dotdot_parent = di->treewalk_parent;
 			}
-		}
-		else {
+		} else {
 			if(q_treewalk != gfs2_inode_dir) {
 				int error = 0;
 				log_warn( _(".. parent is valid, but treewalk"
@@ -146,10 +146,11 @@ static struct dir_info *mark_and_return_parent(struct gfs2_sbd *sbp,
 			}
 			else {
 				log_err( _("Both .. and treewalk parents are "
-						"directories, going with treewalk for "
-						"now...\n"));
+					   "directories, going with treewalk "
+					   "for now...\n"));
 				attach_dotdot_to(sbp, di->treewalk_parent,
-								 di->dotdot_parent, di->dinode);
+						 di->dotdot_parent,
+						 di->dinode);
 				di->dotdot_parent = di->treewalk_parent;
 			}
 		}
diff --git a/gfs2/fsck/pass4.c b/gfs2/fsck/pass4.c
index 8a1f2e3..eb4f413 100644
--- a/gfs2/fsck/pass4.c
+++ b/gfs2/fsck/pass4.c
@@ -37,7 +37,8 @@ struct metawalk_fxns pass4_fxns_delete = {
 static int fix_inode_count(struct gfs2_sbd *sbp, struct inode_info *ii,
 					struct gfs2_inode *ip)
 {
-	log_info( _("Fixing inode count for %llu (0x%llx) \n"),
+	log_info( _("Fixing inode link count (%d->%d) for %llu (0x%llx) \n"),
+		  ip->i_di.di_nlink, ii->counted_links,
 		 (unsigned long long)ip->i_di.di_num.no_addr,
 		 (unsigned long long)ip->i_di.di_num.no_addr);
 	if(ip->i_di.di_nlink == ii->counted_links)
@@ -68,8 +69,6 @@ static int scan_inode_list(struct gfs2_sbd *sbp, osi_list_t *list) {
 			log_crit( _("osi_list_foreach broken in scan_info_list!!\n"));
 			exit(FSCK_ERROR);
 		}
-		log_debug( _("Checking reference count on inode at block %" PRIu64
-				  " (0x%" PRIx64 ")\n"), ii->inode, ii->inode);
 		if(ii->counted_links == 0) {
 			log_err( _("Found unlinked inode at %" PRIu64 " (0x%" PRIx64 ")\n"),
 					ii->inode, ii->inode);
@@ -100,8 +99,11 @@ static int scan_inode_list(struct gfs2_sbd *sbp, osi_list_t *list) {
 			   q != gfs2_inode_chr &&
 			   q != gfs2_inode_fifo &&
 			   q != gfs2_inode_sock) {
-				log_err( _("Unlinked block marked as inode is "
-					   "not an inode (%d)\n"), q);
+				log_err( _("Unlinked block %lld (0x%llx) "
+					   "marked as inode is "
+					   "not an inode (%d)\n"),
+					 (unsigned long long)ii->inode,
+					 (unsigned long long)ii->inode, q);
 				ip = fsck_load_inode(sbp, ii->inode);
 				if(query(_("Delete unlinked inode? (y/n) "))) {
 					check_inode_eattr(ip,
@@ -139,8 +141,7 @@ static int scan_inode_list(struct gfs2_sbd *sbp, osi_list_t *list) {
 					stack;
 					fsck_inode_put(&ip);
 					return -1;
-				}
-				else {
+				} else {
 					fix_inode_count(sbp, ii, ip);
 					lf_addition = 1;
 				}
@@ -161,8 +162,10 @@ static int scan_inode_list(struct gfs2_sbd *sbp, osi_list_t *list) {
 				fix_inode_count(sbp, ii, ip);
 				bmodified(ip->i_bh);
 				fsck_inode_put(&ip); /* out, brelse, free */
-				log_warn( _("Link count updated for inode %"
-						 PRIu64 " (0x%" PRIx64 ") \n"), ii->inode, ii->inode);
+				log_warn( _("Link count updated to %d for "
+					    "inode %" PRIu64 " (0x%"
+					    PRIx64 ") \n"), ii->link_count,
+					  ii->inode, ii->inode);
 			} else {
 				log_err( _("Link count for inode %" PRIu64 " (0x%" PRIx64
 						") still incorrect\n"), ii->inode, ii->inode);
diff --git a/gfs2/fsck/pass5.c b/gfs2/fsck/pass5.c
index c6b005a..08217c7 100644
--- a/gfs2/fsck/pass5.c
+++ b/gfs2/fsck/pass5.c
@@ -56,7 +56,7 @@ static int convert_mark(uint8_t q, uint32_t *count)
 		return GFS2_BLKST_USED;
 
 	default:
-		log_err( _("Invalid state %d found\n"), q);
+		log_err( _("Invalid block type %d found\n"), q);
 		return -1;
 	}
 	return -1;
@@ -135,9 +135,9 @@ static int check_block_status(struct gfs2_sbd *sbp, char *buffer, unsigned int b
 			log_err( _("Metadata type is %u (%s)\n"), q,
 					block_type_string(q));
 
-			if(query( _("Fix bitmap for block %" PRIu64
-				    " (0x%" PRIx64 ") ? (y/n) "),
-				  block, block)) {
+			if(query(_("Fix bitmap for block %" PRIu64
+				   " (0x%" PRIx64 ") ? (y/n) "),
+				 block, block)) {
 				if(gfs2_set_bitmap(sbp, block, block_status))
 					log_err( _("Failed.\n"));
 				else
diff --git a/gfs2/fsck/rgrepair.c b/gfs2/fsck/rgrepair.c
index 9d7653a..aaf699b 100644
--- a/gfs2/fsck/rgrepair.c
+++ b/gfs2/fsck/rgrepair.c
@@ -32,11 +32,11 @@ struct special_blocks false_rgrps;
 
 #define ri_compare(rg, ondisk, expected, field, fmt)	\
 	if (ondisk.field != expected.field) { \
-		log_warn("rindex #%d " #field " discrepancy: index 0x%" fmt \
-			 " != expected: 0x%" fmt "\n",			\
-			 rg + 1, ondisk.field, expected.field);		\
-		ondisk.field = expected.field; \
-		rindex_modified = TRUE; \
+		log_warn( _("rindex #%d " #field " discrepancy: index 0x%" \
+			    fmt	" != expected: 0x%" fmt "\n"),		\
+			  rg + 1, ondisk.field, expected.field);	\
+		ondisk.field = expected.field;				\
+		rindex_modified = TRUE;					\
 	}
 
 /*
diff --git a/gfs2/fsck/util.c b/gfs2/fsck/util.c
index d0dd4af..264489a 100644
--- a/gfs2/fsck/util.c
+++ b/gfs2/fsck/util.c
@@ -104,7 +104,7 @@ void warm_fuzzy_stuff(uint64_t block)
 	static uint64_t one_percent = 0;
 	static struct timeval tv;
 	static uint32_t seconds = 0;
-	
+
 	if (!one_percent)
 		one_percent = last_fs_block / 100;
 	if (block - last_reported_block >= one_percent) {
@@ -206,7 +206,7 @@ void gfs2_dup_set(uint64_t block)
 	b = malloc(sizeof(struct dup_blks));
 	if (b) {
 		memset(b, 0, sizeof(*b));
-		b->block_no = block;
+		b->block = block;
 		osi_list_init(&b->ref_inode_list);
 		osi_list_add(&b->list, &dup_blocks.list);
 	}
diff --git a/gfs2/libgfs2/block_list.c b/gfs2/libgfs2/block_list.c
index b57f58d..153ed9a 100644
--- a/gfs2/libgfs2/block_list.c
+++ b/gfs2/libgfs2/block_list.c
@@ -103,7 +103,6 @@ void gfs2_special_set(struct special_blocks *blocklist, uint64_t block)
 		b->block = block;
 		osi_list_add(&b->list, &blocklist->list);
 	}
-	return;
 }
 
 void gfs2_special_clear(struct special_blocks *blocklist, uint64_t block)
diff --git a/gfs2/libgfs2/buf.c b/gfs2/libgfs2/buf.c
index 4d5f2b5..3a96ef3 100644
--- a/gfs2/libgfs2/buf.c
+++ b/gfs2/libgfs2/buf.c
@@ -81,7 +81,7 @@ int bwrite(struct gfs2_buffer_head *bh)
 	if (write(sdp->device_fd, bh->b_data, sdp->bsize) != sdp->bsize)
 		return -1;
 	sdp->writes++;
-	bh->b_changed = 0;
+	bh->b_modified = 0;
 	return 0;
 }
 
@@ -91,7 +91,7 @@ int brelse(struct gfs2_buffer_head *bh)
 
 	if (bh->b_blocknr == -1)
 		printf("Double free!\n");
-	if (bh->b_changed)
+	if (bh->b_modified)
 		error = bwrite(bh);
 	bh->b_blocknr = -1;
 	if (bh->b_altlist.next && !osi_list_empty(&bh->b_altlist))
diff --git a/gfs2/libgfs2/fs_ops.c b/gfs2/libgfs2/fs_ops.c
index 27362e1..e9c7626 100644
--- a/gfs2/libgfs2/fs_ops.c
+++ b/gfs2/libgfs2/fs_ops.c
@@ -96,7 +96,7 @@ void inode_put(struct gfs2_inode **ip_in)
 	uint64_t block = ip->i_di.di_num.no_addr;
 	struct gfs2_sbd *sdp = ip->i_sbd;
 
-	if (ip->i_bh->b_changed) {
+	if (ip->i_bh->b_modified) {
 		gfs2_dinode_out(&ip->i_di, ip->i_bh);
 		if (!ip->bh_owned && is_system_inode(sdp, block))
 			fprintf(stderr, "Warning: Change made to inode "
@@ -157,8 +157,9 @@ static uint64_t blk_alloc_i(struct gfs2_sbd *sdp, unsigned int type)
 
  found:
 	if (bn >= ri->ri_bitbytes * GFS2_NBBY)
-		die("allocation is broken (2): %u %u %"PRIu64" %u\n",
-		    bn, ri->ri_bitbytes * GFS2_NBBY,
+		die("allocation is broken (2): bn: %u %u rgrp: %"PRIu64
+		    " (0x%" PRIx64 ") Free:%u\n",
+		    bn, ri->ri_bitbytes * GFS2_NBBY, (uint64_t)rl->ri.ri_addr,
 		    (uint64_t)rl->ri.ri_addr, rl->rg.rg_free);
 
 	switch (type) {
@@ -237,15 +238,14 @@ void unstuff_dinode(struct gfs2_inode *ip)
 
 	if (ip->i_di.di_size) {
 		if (isdir) {
+			struct gfs2_meta_header mh;
+
 			block = meta_alloc(ip);
 			bh = bget(sdp, block);
-			{
-				struct gfs2_meta_header mh;
-				mh.mh_magic = GFS2_MAGIC;
-				mh.mh_type = GFS2_METATYPE_JD;
-				mh.mh_format = GFS2_FORMAT_JD;
-				gfs2_meta_header_out(&mh, bh);
-			}
+			mh.mh_magic = GFS2_MAGIC;
+			mh.mh_type = GFS2_METATYPE_JD;
+			mh.mh_format = GFS2_FORMAT_JD;
+			gfs2_meta_header_out(&mh, bh);
 
 			buffer_copy_tail(sdp, bh,
 					 sizeof(struct gfs2_meta_header),
@@ -315,15 +315,14 @@ void build_height(struct gfs2_inode *ip, int height)
 			}
 
 		if (new_block) {
+			struct gfs2_meta_header mh;
+
 			block = meta_alloc(ip);
 			bh = bget(sdp, block);
-			{
-				struct gfs2_meta_header mh;
-				mh.mh_magic = GFS2_MAGIC;
-				mh.mh_type = GFS2_METATYPE_IN;
-				mh.mh_format = GFS2_FORMAT_IN;
-				gfs2_meta_header_out(&mh, bh);
-			}
+			mh.mh_magic = GFS2_MAGIC;
+			mh.mh_type = GFS2_METATYPE_IN;
+			mh.mh_format = GFS2_FORMAT_IN;
+			gfs2_meta_header_out(&mh, bh);
 			buffer_copy_tail(sdp, bh,
 					 sizeof(struct gfs2_meta_header),
 					 ip->i_bh, sizeof(struct gfs2_dinode));
@@ -567,7 +566,7 @@ int gfs2_readi(struct gfs2_inode *ip, void *buf,
 }
 
 static void copy_from_mem(struct gfs2_buffer_head *bh, void **buf,
-						  unsigned int offset, unsigned int size)
+			  unsigned int offset, unsigned int size)
 {
 	char **p = (char **)buf;
 
@@ -762,7 +761,7 @@ static int dirent_alloc(struct gfs2_inode *dip, struct gfs2_buffer_head *bh,
 				memset(new, 0, sizeof(struct gfs2_dirent));
 
 				new->de_rec_len = cpu_to_be16(cur_rec_len -
-											  GFS2_DIRENT_SIZE(cur_name_len));
+					  GFS2_DIRENT_SIZE(cur_name_len));
 				new->de_name_len = cpu_to_be16(name_len);
 				dent->de_rec_len = cpu_to_be16(cur_rec_len -
 											   be16_to_cpu(new->de_rec_len));
@@ -809,14 +808,13 @@ void dirent2_del(struct gfs2_inode *dip, struct gfs2_buffer_head *bh,
 }
 
 void gfs2_get_leaf_nr(struct gfs2_inode *dip, uint32_t lindex,
-					  uint64_t *leaf_out)
+		      uint64_t *leaf_out)
 {
 	uint64_t leaf_no;
 	int count;
 
-	count = gfs2_readi(dip, (char *)&leaf_no,
-		      lindex * sizeof(uint64_t),
-		      sizeof(uint64_t));
+	count = gfs2_readi(dip, (char *)&leaf_no, lindex * sizeof(uint64_t),
+			   sizeof(uint64_t));
 	if (count != sizeof(uint64_t))
 		die("gfs2_get_leaf_nr:  Bad internal read.\n");
 
@@ -835,7 +833,8 @@ void gfs2_put_leaf_nr(struct gfs2_inode *dip, uint32_t inx, uint64_t leaf_out)
 		die("gfs2_put_leaf_nr:  Bad internal write.\n");
 }
 
-static void dir_split_leaf(struct gfs2_inode *dip, uint32_t lindex, uint64_t leaf_no)
+static void dir_split_leaf(struct gfs2_inode *dip, uint32_t lindex,
+			   uint64_t leaf_no)
 {
 	struct gfs2_buffer_head *nbh, *obh;
 	struct gfs2_leaf *nleaf, *oleaf;
@@ -867,18 +866,16 @@ static void dir_split_leaf(struct gfs2_inode *dip, uint32_t lindex, uint64_t lea
 
 	start = (lindex & ~(len - 1));
 
-	zalloc(lp, half_len * sizeof(uint64_t));
-
-	count = gfs2_readi(dip, (char *)lp, start * sizeof(uint64_t),
-		      half_len * sizeof(uint64_t));
-	if (count != half_len * sizeof(uint64_t))
-		die("dir_split_leaf (1)\n");
-
+	lp = calloc(1, half_len * sizeof(uint64_t));
+	if (lp == NULL) {
+		fprintf(stderr, "Out of memory in %s\n", __FUNCTION__);
+		exit(-1);
+	}
 	for (x = 0; x < half_len; x++)
 		lp[x] = cpu_to_be64(bn);
 
 	count = gfs2_writei(dip, (char *)lp, start * sizeof(uint64_t),
-		       half_len * sizeof(uint64_t));
+			    half_len * sizeof(uint64_t));
 	if (count != half_len * sizeof(uint64_t))
 		die("dir_split_leaf (2)\n");
 
@@ -966,7 +963,7 @@ static void dir_double_exhash(struct gfs2_inode *dip)
 		}
 
 		count = gfs2_writei(dip, (char *)buf + sdp->sd_hash_bsize,
-							block * sdp->bsize, sdp->bsize);
+				    block * sdp->bsize, sdp->bsize);
 		if (count != sdp->bsize)
 			die("dir_double_exhash (2)\n");
 
@@ -1052,8 +1049,8 @@ static void dir_e_add(struct gfs2_inode *dip, const char *filename, int len,
 	uint32_t hash;
 	uint64_t leaf_no, bn;
 
- restart:
 	hash = gfs2_disk_hash(filename, len);
+restart:
 	/* Have to kludge because (hash >> 32) gives hash for some reason. */
 	if (dip->i_di.di_depth)
 		lindex = hash >> (32 - dip->i_di.di_depth);
@@ -1084,15 +1081,14 @@ static void dir_e_add(struct gfs2_inode *dip, const char *filename, int len,
 				continue;
 
 			} else {
+				struct gfs2_meta_header mh;
+
 				bn = meta_alloc(dip);
 				nbh = bget(dip->i_sbd, bn);
-				{
-					struct gfs2_meta_header mh;
-					mh.mh_magic = GFS2_MAGIC;
-					mh.mh_type = GFS2_METATYPE_LF;
-					mh.mh_format = GFS2_FORMAT_LF;
-					gfs2_meta_header_out(&mh, nbh);
-				}
+				mh.mh_magic = GFS2_MAGIC;
+				mh.mh_type = GFS2_METATYPE_LF;
+				mh.mh_format = GFS2_FORMAT_LF;
+				gfs2_meta_header_out(&mh, nbh);
 
 				leaf->lf_next = cpu_to_be64(bn);
 
diff --git a/gfs2/libgfs2/gfs2_log.c b/gfs2/libgfs2/gfs2_log.c
index fbb30e0..d3cf7e5 100644
--- a/gfs2/libgfs2/gfs2_log.c
+++ b/gfs2/libgfs2/gfs2_log.c
@@ -61,19 +61,16 @@ void print_msg(int priority, const char *file, int line, const char *format,
 		vfprintf(stderr, format, args);
 		break;
 	}
-	return;
 }
 
 
 void print_fsck_log(int iif, int priority, const char *file, int line,
 		    const char *format, ...)
 {
-
 	va_list args;
 	const char *transform;
 
-        va_start(args, format);
-
+	va_start(args, format);
 	transform = _(format);
 
 	if((_state.print_level == priority) ||
@@ -158,7 +155,6 @@ char generic_interrupt(const char *caller, const char *where,
 int gfs2_query(int *setonabort, struct gfs2_options *opts,
 	       const char *format, ...)
 {
-
 	va_list args;
 	const char *transform;
 	char response;
diff --git a/gfs2/libgfs2/libgfs2.h b/gfs2/libgfs2/libgfs2.h
index e243d3f..1cd441f 100644
--- a/gfs2/libgfs2/libgfs2.h
+++ b/gfs2/libgfs2/libgfs2.h
@@ -108,7 +108,7 @@ struct rgrp_list {
 struct gfs2_buffer_head {
 	osi_list_t b_altlist; /* alternate list */
 	uint64_t b_blocknr;
-	int b_changed;
+	int b_modified;
 	char *b_data;
 	struct gfs2_sbd *sdp;
 };
@@ -329,7 +329,7 @@ extern struct gfs2_buffer_head *__bread(struct gfs2_sbd *sdp, uint64_t num,
 extern int bwrite(struct gfs2_buffer_head *bh);
 extern int brelse(struct gfs2_buffer_head *bh);
 
-#define bmodified(bh) do { bh->b_changed = 1; } while(0)
+#define bmodified(bh) do { bh->b_modified = 1; } while(0)
 
 #define bget_generic(bl, num, find, read) __bget_generic(bl, num, find, read, \
 							 __LINE__, \
@@ -734,7 +734,6 @@ extern void gfs2_leaf_print(struct gfs2_leaf *lf);
 extern void gfs2_ea_header_print(struct gfs2_ea_header *ea, char *name);
 extern void gfs2_log_header_print(struct gfs2_log_header *lh);
 extern void gfs2_log_descriptor_print(struct gfs2_log_descriptor *ld);
-extern void gfs2_inum_range_print(struct gfs2_inum_range *ir);
 extern void gfs2_statfs_change_print(struct gfs2_statfs_change *sc);
 extern void gfs2_quota_change_print(struct gfs2_quota_change *qc);
 
diff --git a/gfs2/libgfs2/super.c b/gfs2/libgfs2/super.c
index dd805b4..f48bad5 100644
--- a/gfs2/libgfs2/super.c
+++ b/gfs2/libgfs2/super.c
@@ -144,7 +144,7 @@ int ji_update(struct gfs2_sbd *sdp)
 	int i;
 
 	if(!ip) {
-		log_crit("Journal inode not found.\n");
+		log_crit("Journal index inode not found.\n");
 		return -1;
 	}