Sophie

Sophie

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

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

commit a6d56a0938ad396bda77a04102c644df3202ec93
Author: Bob Peterson <bob@ganesha.peterson>
Date:   Sat Jan 16 12:07:00 2010 -0600

    Make struct_out functions operate on bh's
    
    This patch changes most the gfs2_struct_in and gfs2_struct_out functions
    so that they take a bh parameter rather than a buffer.  It ensures that
    whenever a structure is pushed to a buffer, the buffer is marked as
    modified so that it later gets written to disk.  This is one step in
    getting rid of the buffer lists and helps ensure data integrity.  This
    takes most of the guess-work out of the buffer writing: No more "rewrite
    the buffer because it may or may not have been changed."
    
    Some structures, such as rindex entries and dentry pointers, can't
    operate on a bh, mostly because they use the readi/writei functions to
    write the data out, but this covers the majority of gfs2 structures.
    
    rhbz#455300

diff --git a/gfs2/convert/gfs2_convert.c b/gfs2/convert/gfs2_convert.c
index e701169..5630b9c 100644
--- a/gfs2/convert/gfs2_convert.c
+++ b/gfs2/convert/gfs2_convert.c
@@ -31,7 +31,6 @@
 #include <linux/gfs2_ondisk.h>
 #include "osi_list.h"
 #include "copyright.cf"
-#include "ondisk.h"
 #include "libgfs2.h"
 #include "global.h"
 
@@ -217,7 +216,7 @@ static int convert_rgs(struct gfs2_sbd *sbp)
 		sbp->dinodes_alloced += rgd1->rg_useddi;
 		convert_bitmaps(sbp, rgd);
 		/* Write the updated rgrp to the gfs2 buffer */
-		gfs2_rgrp_out(&rgd->rg, rgd->bh[0]->b_data);
+		gfs2_rgrp_out(&rgd->rg, rgd->bh[0]);
 		rgs++;
 		if (rgs % 100 == 0) {
 			printf(".");
@@ -332,7 +331,7 @@ static void fix_metatree(struct gfs2_sbd *sbp, struct gfs2_inode *ip,
 			bh = bread(&sbp->buf_list, block);
 			if (new)
 				memset(bh->b_data, 0, sbp->bsize);
-			gfs2_meta_header_out(&mh, bh->b_data);
+			gfs2_meta_header_out(&mh, bh);
 		}
 
 		hdrsize = sizeof(struct gfs2_meta_header);
@@ -949,7 +948,7 @@ static int adjust_inode(struct gfs2_sbd *sbp, struct gfs2_buffer_head *bh)
 			return -1;
 	}
 	
-	gfs2_dinode_out(&inode->i_di, bh->b_data);
+	gfs2_dinode_out(&inode->i_di, bh);
 	sbp->md.next_inum++; /* update inode count */
 	return 0;
 } /* adjust_inode */
@@ -1196,7 +1195,7 @@ static int fix_one_directory_exhash(struct gfs2_sbd *sbp, struct gfs2_inode *dip
 			log_crit("Error reading leaf %" PRIx64 "\n", leaf_block);
 			break;
 		}
-		gfs2_leaf_in(&leaf, (char *)bh_leaf->b_data); /* buffer to structure */
+		gfs2_leaf_in(&leaf, bh_leaf); /* buffer to structure */
 		error = process_dirent_info(dip, sbp, bh_leaf, leaf.lf_entries);
 		bmodified(bh_leaf);
 		brelse(bh_leaf);
@@ -1374,7 +1373,7 @@ static int init(struct gfs2_sbd *sbp)
 	bh = bread(&sbp->buf_list, GFS2_SB_ADDR >> sbp->sd_fsb2bb_shift);
 	memcpy(&raw_gfs1_ondisk_sb, (struct gfs1_sb *)bh->b_data,
 		   sizeof(struct gfs1_sb));
-	gfs2_sb_in(&sbp->sd_sb, bh->b_data);
+	gfs2_sb_in(&sbp->sd_sb, bh);
 	sbp->bsize = sbp->sd_sb.sb_bsize;
 	sbp->sd_inptrs = (sbp->bsize - sizeof(struct gfs_indirect)) /
 		sizeof(uint64_t);
@@ -1661,9 +1660,9 @@ static int journ_space_to_rg(struct gfs2_sbd *sdp)
 		convert_bitmaps(sdp, rgd);
 		for (x = 0; x < rgd->ri.ri_length; x++) {
 			if (x)
-				gfs2_meta_header_out(&mh, rgd->bh[x]->b_data);
+				gfs2_meta_header_out(&mh, rgd->bh[x]);
 			else
-				gfs2_rgrp_out(&rgd->rg, rgd->bh[x]->b_data);
+				gfs2_rgrp_out(&rgd->rg, rgd->bh[x]);
 		}
 		/* Add the new gfs2 rg to our list: We'll output the rg index later. */
 		osi_list_add_prev((osi_list_t *)&rgd->list,
@@ -1887,8 +1886,7 @@ int main(int argc, char **argv)
 		bh = bread(&sb2.buf_list, sb2.sb_addr);
 		sb2.sd_sb.sb_fs_format = GFS2_FORMAT_FS;
 		sb2.sd_sb.sb_multihost_format = GFS2_FORMAT_MULTI;
-		gfs2_sb_out(&sb2.sd_sb, bh->b_data);
-		bmodified(bh);
+		gfs2_sb_out(&sb2.sd_sb, bh);
 		brelse(bh);
 
 		bsync(&sb2.buf_list); /* write the buffers to disk */
diff --git a/gfs2/edit/gfs2hex.c b/gfs2/edit/gfs2hex.c
index 0cf36ef..20bbe42 100644
--- a/gfs2/edit/gfs2hex.c
+++ b/gfs2/edit/gfs2hex.c
@@ -32,21 +32,58 @@
 #include "gfs2hex.h"
 /* from libgfs2: */
 #include "libgfs2.h"
-#include "ondisk.h"
-
-
-extern struct gfs2_sb sb;
-extern char *buf;
-extern struct gfs2_dinode di;
-extern int line, termlines;
-extern char edit_fmt[80];
-extern char estring[1024];
-extern char efield[64];
-extern int edit_mode INIT(0);
-extern int edit_row[DMODES], edit_col[DMODES];
-extern int edit_size[DMODES], last_entry_onscreen[DMODES];
-extern char edit_fmt[80];
-extern enum dsp_mode dmode INIT(HEX_MODE); /* display mode */
+
+#define pv(struct, member, fmt, fmt2) do {				\
+		print_it("  "#member, fmt, fmt2, struct->member);	\
+	} while (FALSE);
+#define pv2(struct, member, fmt, fmt2) do {				\
+		print_it("  ", fmt, fmt2, struct->member);		\
+	} while (FALSE);
+
+
+struct gfs2_sb sb;
+struct gfs2_buffer_head *bh;
+struct gfs2_dinode di;
+int line, termlines;
+char edit_fmt[80];
+char estring[1024];
+char efield[64];
+int edit_mode = 0;
+int edit_row[DMODES], edit_col[DMODES];
+int edit_size[DMODES], last_entry_onscreen[DMODES];
+char edit_fmt[80];
+enum dsp_mode dmode = HEX_MODE; /* display mode */
+uint64_t block = 0;
+int blockhist = 0;
+struct iinfo *indirect;
+int indirect_blocks;
+int gfs1  = 0;
+uint64_t block_in_mem = -1;
+struct gfs2_sbd sbd;
+uint64_t starting_blk;
+struct blkstack_info blockstack[BLOCK_STACK_SIZE];
+int identify = FALSE;
+char device[NAME_MAX];
+uint64_t max_block = 0;
+int start_row[DMODES], end_row[DMODES], lines_per_row[DMODES];
+struct gfs_sb *sbd1;
+int gfs2_struct_type;
+unsigned int offset;
+int termcols = 80;
+struct indirect_info masterdir;
+struct gfs2_inum gfs1_quota_di;
+int print_entry_ndx;
+struct gfs2_inum gfs1_license_di;
+int screen_chunk_size = 512;
+uint64_t temp_blk;
+int color_scheme = 0;
+int struct_len;
+uint64_t dev_offset = 0;
+int editing = 0;
+int insert = 0;
+const char *termtype;
+WINDOW *wind;
+int dsplines = 0;
 
 const char *block_type_str[15] = {
 	"Clump",
@@ -253,7 +290,7 @@ static int indirect_dirent(struct indirect_info *indir, char *ptr, int d)
 **
 *******************************************************************************
 ******************************************************************************/
-void do_dinode_extended(struct gfs2_dinode *dine, char *dinebuf)
+void do_dinode_extended(struct gfs2_dinode *dine, struct gfs2_buffer_head *lbh)
 {
 	unsigned int x, y, ptroff = 0;
 	uint64_t p, last;
@@ -266,7 +303,7 @@ void do_dinode_extended(struct gfs2_dinode *dine, char *dinebuf)
 		/* Indirect pointers */
 		for (x = sizeof(struct gfs2_dinode); x < sbd.bsize;
 			 x += sizeof(uint64_t)) {
-			p = be64_to_cpu(*(uint64_t *)(dinebuf + x));
+			p = be64_to_cpu(*(uint64_t *)(lbh->b_data + x));
 			if (p) {
 				indirect->ii[indirect_blocks].block = p;
 				indirect->ii[indirect_blocks].mp.mp_list[0] =
@@ -285,8 +322,7 @@ void do_dinode_extended(struct gfs2_dinode *dine, char *dinebuf)
 		indirect->ii[0].block = block;
 		indirect->ii[0].is_dir = TRUE;
 		for (x = sizeof(struct gfs2_dinode); x < sbd.bsize; x += skip) {
-			skip = indirect_dirent(indirect->ii,
-					       dinebuf + x,
+			skip = indirect_dirent(indirect->ii, lbh->b_data + x,
 					       indirect->ii[0].dirents);
 			if (skip <= 0)
 				break;
@@ -297,12 +333,13 @@ void do_dinode_extended(struct gfs2_dinode *dine, char *dinebuf)
 			 dine->di_height == 0) {
 		/* Leaf Pointers: */
 		
-		last = be64_to_cpu(*(uint64_t *)(dinebuf + sizeof(struct gfs2_dinode)));
+		last = be64_to_cpu(*(uint64_t *)(lbh->b_data +
+						 sizeof(struct gfs2_dinode)));
     
 		for (x = sizeof(struct gfs2_dinode), y = 0;
 			 y < (1 << dine->di_depth);
 			 x += sizeof(uint64_t), y++) {
-			p = be64_to_cpu(*(uint64_t *)(dinebuf + x));
+			p = be64_to_cpu(*(uint64_t *)(lbh->b_data + x));
 
 			if (p != last || ((y + 1) * sizeof(uint64_t) == dine->di_size)) {
 				struct gfs2_buffer_head *tmp_bh;
@@ -313,7 +350,7 @@ void do_dinode_extended(struct gfs2_dinode *dine, char *dinebuf)
 				if (last >= max_block)
 					break;
 				tmp_bh = bread(&sbd.buf_list, last);
-				gfs2_leaf_in(&leaf, tmp_bh->b_data);
+				gfs2_leaf_in(&leaf, tmp_bh);
 				indirect->ii[indirect_blocks].dirents = 0;
 				for (direntcount = 0, bufoffset = sizeof(struct gfs2_leaf);
 					 bufoffset < sbd.bsize;
@@ -438,7 +475,7 @@ void do_leaf_extended(char *dlebuf, struct iinfo *indir)
 *******************************************************************************
 ******************************************************************************/
 
-static void do_eattr_extended(char *deebuf)
+static void do_eattr_extended(struct gfs2_buffer_head *ebh)
 {
 	struct gfs2_ea_header ea;
 	unsigned int x;
@@ -450,8 +487,9 @@ static void do_eattr_extended(char *deebuf)
 	for (x = sizeof(struct gfs2_meta_header); x < sbd.bsize; x += ea.ea_rec_len)
 	{
 		eol(0);
-		gfs2_ea_header_in(&ea, deebuf + x);
-		gfs2_ea_header_print(&ea, deebuf + x + sizeof(struct gfs2_ea_header));
+		gfs2_ea_header_in(&ea, ebh->b_data + x);
+		gfs2_ea_header_print(&ea, ebh->b_data + x +
+				     sizeof(struct gfs2_ea_header));
 	}
 }
 
@@ -509,11 +547,11 @@ static void gfs2_sb_print2(struct gfs2_sb *sbp2)
 /**
  * gfs1_rgrp_in - read in a gfs1 rgrp
  */
-static void gfs1_rgrp_in(struct gfs1_rgrp *rgrp, char *rbuf)
+static void gfs1_rgrp_in(struct gfs1_rgrp *rgrp, struct gfs2_buffer_head *rbh)
 {
-        struct gfs1_rgrp *str = (struct gfs1_rgrp *)rbuf;
+        struct gfs1_rgrp *str = (struct gfs1_rgrp *)rbh->b_data;
 
-        gfs2_meta_header_in(&rgrp->rg_header, rbuf);
+        gfs2_meta_header_in(&rgrp->rg_header, rbh);
         rgrp->rg_flags = be32_to_cpu(str->rg_flags);
         rgrp->rg_free = be32_to_cpu(str->rg_free);
         rgrp->rg_useddi = be32_to_cpu(str->rg_useddi);
@@ -569,12 +607,12 @@ int display_gfs2(void)
 
 	uint32_t magic;
 
-	magic = be32_to_cpu(*(uint32_t *)buf);
+	magic = be32_to_cpu(*(uint32_t *)bh->b_data);
 
 	switch (magic)
 	{
 	case GFS2_MAGIC:
-		gfs2_meta_header_in(&mh, buf);
+		gfs2_meta_header_in(&mh, bh);
 		if (mh.mh_type > GFS2_METATYPE_QC)
 			print_gfs2("Unknown metadata type");
 		else
@@ -584,7 +622,7 @@ int display_gfs2(void)
 		switch (mh.mh_type)
 		{
 		case GFS2_METATYPE_SB:
-			gfs2_sb_in(&sbd.sd_sb, buf);
+			gfs2_sb_in(&sbd.sd_sb, bh);
 			gfs2_sb_print2(&sbd.sd_sb);
 			break;
 
@@ -592,10 +630,10 @@ int display_gfs2(void)
 			if (gfs1) {
 				struct gfs1_rgrp rg1;
 
-				gfs1_rgrp_in(&rg1, buf);
+				gfs1_rgrp_in(&rg1, bh);
 				gfs1_rgrp_print(&rg1);
 			} else {
-				gfs2_rgrp_in(&rg, buf);
+				gfs2_rgrp_in(&rg, bh);
 				gfs2_rgrp_print(&rg);
 			}
 			break;
@@ -613,7 +651,7 @@ int display_gfs2(void)
 			break;
 
 		case GFS2_METATYPE_LF:
-			gfs2_leaf_in(&lf, buf);
+			gfs2_leaf_in(&lf, bh);
 			gfs2_leaf_print(&lf);
 			break;
 
@@ -623,21 +661,21 @@ int display_gfs2(void)
 
 		case GFS2_METATYPE_LH:
 			if (gfs1) {
-				gfs_log_header_in(&lh1, buf);
+				gfs_log_header_in(&lh1, bh);
 				gfs_log_header_print(&lh1);
 			} else {
-				gfs2_log_header_in(&lh, buf);
+				gfs2_log_header_in(&lh, bh);
 				gfs2_log_header_print(&lh);
 			}
 			break;
 
 		case GFS2_METATYPE_LD:
-			gfs2_log_descriptor_in(&ld, buf);
+			gfs2_log_descriptor_in(&ld, bh);
 			gfs2_log_descriptor_print(&ld);
 			break;
 
 		case GFS2_METATYPE_EA:
-			do_eattr_extended(buf);
+			do_eattr_extended(bh);
 			break;
 			
 		case GFS2_METATYPE_ED:
@@ -649,7 +687,7 @@ int display_gfs2(void)
 			break;
 
 		case GFS2_METATYPE_QC:
-			gfs2_quota_change_in(&qc, buf);
+			gfs2_quota_change_in(&qc, bh);
 			gfs2_quota_change_print(&qc);
 			break;
 
diff --git a/gfs2/edit/gfs2hex.h b/gfs2/edit/gfs2hex.h
index a35fce5..ebe6b0e 100644
--- a/gfs2/edit/gfs2hex.h
+++ b/gfs2/edit/gfs2hex.h
@@ -18,7 +18,7 @@
 
 int display_gfs2(void);
 int edit_gfs2(void);
-void do_dinode_extended(struct gfs2_dinode *di, char *buf);
+void do_dinode_extended(struct gfs2_dinode *di, struct gfs2_buffer_head *lbh);
 void print_gfs2(const char *fmt, ...);
 int do_indirect_extended(char *diebuf, struct iinfo *iinf, int hgt);
 void do_leaf_extended(char *dlebuf, struct iinfo *indir);
diff --git a/gfs2/edit/hexedit.c b/gfs2/edit/hexedit.c
index a0b9b81..1a9c7ae 100644
--- a/gfs2/edit/hexedit.c
+++ b/gfs2/edit/hexedit.c
@@ -42,6 +42,10 @@
 
 #define RGLIST_DUMMY_BLOCK -2
 
+#define pv(struct, member, fmt, fmt2) do {                              \
+		print_it("  "#member, fmt, fmt2, struct->member);       \
+	} while (FALSE);
+
 const char *mtypes[] = {"none", "sb", "rg", "rb", "di", "in", "lf", "jd",
 			"lh", "ld", "ea", "ed", "lb", "13", "qc"};
 const char *allocdesc[2][5] = {
@@ -444,9 +448,10 @@ static void print_usage(void)
 /* returns: metatype if block is a GFS2 structure block type                */
 /*          0 if block is not a GFS2 structure                              */
 /* ------------------------------------------------------------------------ */
-static int get_block_type(const char *lpBuffer)
+static int get_block_type(struct gfs2_buffer_head *lbh)
 {
 	int ret_type = 0;
+	char *lpBuffer = lbh->b_data;
 
 	if (*(lpBuffer+0)==0x01 && *(lpBuffer+1)==0x16 &&
 	    *(lpBuffer+2)==0x19 && *(lpBuffer+3)==0x70 &&
@@ -461,7 +466,7 @@ static int get_block_type(const char *lpBuffer)
 /* returns: metatype if block is a GFS2 structure block type                */
 /*          0 if block is not a GFS2 structure                              */
 /* ------------------------------------------------------------------------ */
-int display_block_type(const char *lpBuffer, int from_restore)
+int display_block_type(int from_restore)
 {
 	int ret_type = 0; /* return type */
 
@@ -498,8 +503,8 @@ int display_block_type(const char *lpBuffer, int from_restore)
 		ret_type = GFS2_METATYPE_RG;
 		struct_len = gfs1 ? sizeof(struct gfs_rgrp) : sizeof(struct gfs2_rgrp);
 	}
-	else if ((ret_type = get_block_type(lpBuffer))) {
-		switch (*(lpBuffer+7)) {
+	else if ((ret_type = get_block_type(bh))) {
+		switch (*(bh->b_data + 7)) {
 		case GFS2_METATYPE_SB:   /* 1 */
 			print_gfs2("(superblock)");
 			if (gfs1)
@@ -595,9 +600,9 @@ int display_block_type(const char *lpBuffer, int from_restore)
 			   sbd.bsize / screen_chunk_size + 1 : sbd.bsize /
 			   screen_chunk_size, allocdesc[gfs1][type]);
 		/*eol(9);*/
-		if ((*(lpBuffer+7) == GFS2_METATYPE_IN) ||
-		    (*(lpBuffer+7) == GFS2_METATYPE_DI &&
-		     (*(lpBuffer + 0x8b) || *(lpBuffer + 0x8a)))) {
+		if ((*(bh->b_data + 7) == GFS2_METATYPE_IN) ||
+		    (*(bh->b_data + 7) == GFS2_METATYPE_DI &&
+		     (*(bh->b_data + 0x8b) || *(bh->b_data + 0x8a)))) {
 			int ptroffset = edit_row[dmode] * 16 + edit_col[dmode];
 
 			if (ptroffset >= struct_len || pgnum) {
@@ -656,11 +661,12 @@ int display_block_type(const char *lpBuffer, int from_restore)
 /* ------------------------------------------------------------------------ */
 /* hexdump - hex dump the filesystem block to the screen                    */
 /* ------------------------------------------------------------------------ */
-static int hexdump(uint64_t startaddr, const char *lpBuffer, int len)
+static int hexdump(uint64_t startaddr, int len)
 {
 	const unsigned char *pointer,*ptr2;
 	int i;
 	uint64_t l;
+	const char *lpBuffer = bh->b_data;
 
 	strcpy(edit_fmt,"%02X");
 	pointer = (unsigned char *)lpBuffer + offset;
@@ -834,11 +840,11 @@ static uint64_t find_rgrp_block(struct gfs2_inode *dif, int rg)
 /* ------------------------------------------------------------------------ */
 /* gfs_rgrp_in - Read in a resource group header                            */
 /* ------------------------------------------------------------------------ */
-static void gfs_rgrp_in(struct gfs_rgrp *rgrp, char *gbuf)
+static void gfs_rgrp_in(struct gfs_rgrp *rgrp, struct gfs2_buffer_head *rbh)
 {
-	struct gfs_rgrp *str = (struct gfs_rgrp *)gbuf;
+	struct gfs_rgrp *str = (struct gfs_rgrp *)rbh->b_data;
 
-	gfs2_meta_header_in(&rgrp->rg_header, gbuf);
+	gfs2_meta_header_in(&rgrp->rg_header, rbh);
 	rgrp->rg_flags = be32_to_cpu(str->rg_flags);
 	rgrp->rg_free = be32_to_cpu(str->rg_free);
 	rgrp->rg_useddi = be32_to_cpu(str->rg_useddi);
@@ -851,11 +857,11 @@ static void gfs_rgrp_in(struct gfs_rgrp *rgrp, char *gbuf)
 /* ------------------------------------------------------------------------ */
 /* gfs_rgrp_out */
 /* ------------------------------------------------------------------------ */
-static void gfs_rgrp_out(struct gfs_rgrp *rgrp, char *gbuf)
+static void gfs_rgrp_out(struct gfs_rgrp *rgrp, struct gfs2_buffer_head *rbh)
 {
-	struct gfs_rgrp *str = (struct gfs_rgrp *)gbuf;
+	struct gfs_rgrp *str = (struct gfs_rgrp *)rbh->b_data;
 
-	gfs2_meta_header_out(&rgrp->rg_header, gbuf);
+	gfs2_meta_header_out(&rgrp->rg_header, rbh);
 	str->rg_flags = cpu_to_be32(rgrp->rg_flags);
 	str->rg_free = cpu_to_be32(rgrp->rg_free);
 	str->rg_useddi = cpu_to_be32(rgrp->rg_useddi);
@@ -885,7 +891,7 @@ static void gfs_rgrp_print(struct gfs_rgrp *rg)
 /* ------------------------------------------------------------------------ */
 static uint64_t get_rg_addr(int rgnum)
 {
-	struct gfs2_buffer_head *bh;
+	struct gfs2_buffer_head *lbh;
 	uint64_t rgblk = 0, gblock;
 	struct gfs2_inode *riinode;
 
@@ -893,8 +899,8 @@ static uint64_t get_rg_addr(int rgnum)
 		gblock = sbd1->sb_rindex_di.no_addr;
 	else
 		gblock = masterblock("rindex");
-	bh = bread(&sbd.buf_list, gblock);
-	riinode = inode_get(&sbd, bh);
+	lbh = bread(&sbd.buf_list, gblock);
+	riinode = inode_get(&sbd, lbh);
 	if (rgnum < riinode->i_di.di_size / risize())
 		rgblk = find_rgrp_block(riinode, rgnum);
 	else
@@ -917,26 +923,25 @@ static void set_rgrp_flags(int rgnum, uint32_t new_flags, int modify, int full)
 		struct gfs2_rgrp rg2;
 		struct gfs_rgrp rg1;
 	} rg;
-	struct gfs2_buffer_head *bh;
+	struct gfs2_buffer_head *rbh;
 	uint64_t rgblk;
 
 	rgblk = get_rg_addr(rgnum);
-	bh = bread(&sbd.buf_list, rgblk);
+	rbh = bread(&sbd.buf_list, rgblk);
 	if (gfs1)
-		gfs_rgrp_in(&rg.rg1, bh->b_data);
+		gfs_rgrp_in(&rg.rg1, rbh);
 	else
-		gfs2_rgrp_in(&rg.rg2, bh->b_data);
+		gfs2_rgrp_in(&rg.rg2, rbh);
 	if (modify) {
 		printf("RG #%d (block %llu / 0x%llx) rg_flags changed from 0x%08x to 0x%08x\n",
 		       rgnum, (unsigned long long)rgblk,
 		       (unsigned long long)rgblk, rg.rg2.rg_flags, new_flags);
 		rg.rg2.rg_flags = new_flags;
 		if (gfs1)
-			gfs_rgrp_out(&rg.rg1, bh->b_data);
+			gfs_rgrp_out(&rg.rg1, rbh);
 		else
-			gfs2_rgrp_out(&rg.rg2, bh->b_data);
-		bmodified(bh);
-		brelse(bh);
+			gfs2_rgrp_out(&rg.rg2, rbh);
+		brelse(rbh);
 	} else {
 		if (full) {
 			print_gfs2("RG #%d", rgnum);
@@ -951,7 +956,7 @@ static void set_rgrp_flags(int rgnum, uint32_t new_flags, int modify, int full)
 			printf("RG #%d (block %llu / 0x%llx) rg_flags = 0x%08x\n",
 			       rgnum, (unsigned long long)rgblk,
 			       (unsigned long long)rgblk, rg.rg2.rg_flags);
-		brelse(bh);
+		brelse(rbh);
 	}
 	if (modify)
 		bsync(&sbd.buf_list);
@@ -1009,11 +1014,11 @@ static int parse_rindex(struct gfs2_inode *dip, int print_rindex)
 				tmp_bh = bread(&sbd.buf_list, ri.ri_addr);
 				if (gfs1) {
 					struct gfs_rgrp rg1;
-					gfs_rgrp_in(&rg1, tmp_bh->b_data);
+					gfs_rgrp_in(&rg1, tmp_bh);
 					gfs_rgrp_print(&rg1);
 				} else {
 					struct gfs2_rgrp rg;
-					gfs2_rgrp_in(&rg, tmp_bh->b_data);
+					gfs2_rgrp_in(&rg, tmp_bh);
 					gfs2_rgrp_print(&rg);
 				}
 				brelse(tmp_bh);
@@ -1619,9 +1624,9 @@ int block_is_in_per_node(void)
 		return FALSE;
 
 	per_node_bh = bread(&sbd.buf_list, masterblock("per_node"));
-	gfs2_dinode_in(&per_node_di, per_node_bh->b_data);
+	gfs2_dinode_in(&per_node_di, per_node_bh);
 
-	do_dinode_extended(&per_node_di, per_node_bh->b_data);
+	do_dinode_extended(&per_node_di, per_node_bh);
 	brelse(per_node_bh);
 
 	for (d = 0; d < indirect->ii[0].dirents; d++) {
@@ -1713,15 +1718,10 @@ static void read_superblock(int fd)
 
 	sbd1 = (struct gfs_sb *)&sbd.sd_sb;
 	ioctl(fd, BLKFLSBUF, 0);
-	lseek(fd, 0x10 * 4096, SEEK_SET);
-	if (read(fd, buf, sbd.bsize) != sbd.bsize) {
-		fprintf(stderr, "bad read: %s from %s:%d: superblock\n",
-			strerror(errno), __FUNCTION__, __LINE__);
-		exit(-1);
-	}
 	memset(&sbd, 0, sizeof(struct gfs2_sbd));
-	sbd.device_fd = fd;
 	sbd.bsize = GFS2_DEFAULT_BSIZE;
+	sbd.device_fd = fd;
+	bh = bread(&sbd.buf_list, 0x10);
 	sbd.jsize = GFS2_DEFAULT_JSIZE;
 	sbd.rgsize = GFS2_DEFAULT_RGSIZE;
 	sbd.utsize = GFS2_DEFAULT_UTSIZE;
@@ -1729,13 +1729,13 @@ static void read_superblock(int fd)
 	sbd.time = time(NULL);
 	osi_list_init(&sbd.rglist);
 	init_buf_list(&sbd, &sbd.buf_list, 1 << 20);
-	gfs2_sb_in(&sbd.sd_sb, buf); /* parse it out into the sb structure */
+	gfs2_sb_in(&sbd.sd_sb, bh); /* parse it out into the sb structure */
 	/* Check to see if this is really gfs1 */
 	if (sbd1->sb_fs_format == GFS_FORMAT_FS &&
 		sbd1->sb_header.mh_type == GFS_METATYPE_SB &&
 		sbd1->sb_header.mh_format == GFS_FORMAT_SB &&
 		sbd1->sb_multihost_format == GFS_FORMAT_MULTI) {
-		struct gfs_sb *sbbuf = (struct gfs_sb *)buf;
+		struct gfs_sb *sbbuf = (struct gfs_sb *)bh->b_data;
 
 		gfs1 = TRUE;
 		sbd1->sb_flags = be32_to_cpu(sbbuf->sb_flags);
@@ -1784,7 +1784,7 @@ static void read_master_dir(void)
 	ioctl(sbd.device_fd, BLKFLSBUF, 0);
 	lseek(sbd.device_fd, sbd.sd_sb.sb_master_dir.no_addr * sbd.bsize,
 	      SEEK_SET);
-	if (read(sbd.device_fd, buf, sbd.bsize) != sbd.bsize) {
+	if (read(sbd.device_fd, bh->b_data, sbd.bsize) != sbd.bsize) {
 		fprintf(stderr, "read error: %s from %s:%d: "
 			"master dir block %lld (0x%llx)\n",
 			strerror(errno), __FUNCTION__,
@@ -1793,8 +1793,8 @@ static void read_master_dir(void)
 			(unsigned long long)sbd.sd_sb.sb_master_dir.no_addr);
 		exit(-1);
 	}
-	gfs2_dinode_in(&di, buf); /* parse disk inode into structure */
-	do_dinode_extended(&di, buf); /* get extended data, if any */
+	gfs2_dinode_in(&di, bh); /* parse disk inode into structure */
+	do_dinode_extended(&di, bh); /* get extended data, if any */
 	memcpy(&masterdir, &indirect[0], sizeof(struct indirect_info));
 }
 
@@ -1819,8 +1819,7 @@ int display(int identify_only)
 	if (block_in_mem != blk) { /* If we changed blocks from the last read */
 		dev_offset = blk * sbd.bsize;
 		ioctl(sbd.device_fd, BLKFLSBUF, 0);
-		lseek(sbd.device_fd, dev_offset, SEEK_SET);
-		if (read(sbd.device_fd, buf, sbd.bsize) != sbd.bsize) {
+		if (!(bh = bread(&sbd.buf_list, blk))) {
 			fprintf(stderr, "read error: %s from %s:%d: "
 				"offset %lld (0x%llx)\n",
 				strerror(errno), __FUNCTION__, __LINE__,
@@ -1831,13 +1830,13 @@ int display(int identify_only)
 		block_in_mem = blk; /* remember which block is in memory */
 	}
 	line = 1;
-	gfs2_struct_type = display_block_type(buf, FALSE);
+	gfs2_struct_type = display_block_type(FALSE);
 	if (identify_only)
 		return 0;
 	indirect_blocks = 0;
 	lines_per_row[dmode] = 1;
 	if (gfs2_struct_type == GFS2_METATYPE_SB || blk == 0x10 * (4096 / sbd.bsize)) {
-		gfs2_sb_in(&sbd.sd_sb, buf); /* parse it out into the sb structure */
+		gfs2_sb_in(&sbd.sd_sb, bh); /* parse it out into the sb structure */
 		memset(indirect, 0, sizeof(indirect));
 		indirect->ii[0].block = sbd.sd_sb.sb_master_dir.no_addr;
 		indirect->ii[0].is_dir = TRUE;
@@ -1860,8 +1859,8 @@ int display(int identify_only)
 		indirect->ii[0].dirent[1].dirent.de_type = DT_DIR;
 	}
 	else if (gfs2_struct_type == GFS2_METATYPE_DI) {
-		gfs2_dinode_in(&di, buf); /* parse disk inode into structure */
-		do_dinode_extended(&di, buf); /* get extended data, if any */
+		gfs2_dinode_in(&di, bh); /* parse disk inode into structure */
+		do_dinode_extended(&di, bh); /* get extended data, if any */
 	}
 	else if (gfs2_struct_type == GFS2_METATYPE_IN) { /* indirect block list */
 		int i, hgt = get_height();
@@ -1872,10 +1871,11 @@ int display(int identify_only)
 				       &blockstack[blockhist - 1].mp,
 				       sizeof(struct metapath));
 		}
-		indirect_blocks = do_indirect_extended(buf, indirect, hgt);
+		indirect_blocks = do_indirect_extended(bh->b_data, indirect,
+						       hgt);
 	}
 	else if (gfs2_struct_type == GFS2_METATYPE_LF) { /* directory leaf */
-		do_leaf_extended(buf, indirect);
+		do_leaf_extended(bh->b_data, indirect);
 	}
 	last_entry_onscreen[dmode] = 0;
 	if (dmode == EXTENDED_MODE && !block_has_extended_info())
@@ -1890,8 +1890,7 @@ int display(int identify_only)
 		move(line, 0);
 	}
 	if (dmode == HEX_MODE)          /* if hex display mode           */
-		hexdump(dev_offset, buf,
-			(gfs2_struct_type == GFS2_METATYPE_DI)?
+		hexdump(dev_offset, (gfs2_struct_type == GFS2_METATYPE_DI)?
 			struct_len + di.di_size:sbd.bsize);
 	else if (dmode == GFS2_MODE)    /* if structure display          */
 		display_gfs2();            /* display the gfs2 structure    */
@@ -1975,10 +1974,10 @@ static uint64_t find_journal_block(const char *journal, uint64_t *j_size)
 	/* read in the block */
 	jindex_bh = bread(&sbd.buf_list, jindex_block);
 	/* get the dinode data from it. */
-	gfs2_dinode_in(&di, jindex_bh->b_data); /* parse disk inode to struct*/
+	gfs2_dinode_in(&di, jindex_bh); /* parse disk inode to struct*/
 
 	if (!gfs1)
-		do_dinode_extended(&di, jindex_bh->b_data); /* parse dir. */
+		do_dinode_extended(&di, jindex_bh); /* parse dir. */
 	brelse(jindex_bh);
 
 	if (gfs1) {
@@ -2000,7 +1999,7 @@ static uint64_t find_journal_block(const char *journal, uint64_t *j_size)
 		jblock = indirect->ii[0].dirent[journal_num + 2].block;
 		j_bh = bread(&sbd.buf_list, jblock);
 		j_inode = inode_get(&sbd, j_bh);
-		gfs2_dinode_in(&jdi, j_bh->b_data);/* parse dinode to struct */
+		gfs2_dinode_in(&jdi, j_bh);/* parse dinode to struct */
 		*j_size = jdi.di_size;
 		brelse(j_bh);
 	}
@@ -2017,21 +2016,21 @@ static uint64_t find_metablockoftype_slow(uint64_t startblk, int metatype, int p
 {
 	uint64_t blk, last_fs_block;
 	int found = 0;
-	struct gfs2_buffer_head *bh;
+	struct gfs2_buffer_head *lbh;
 
 	last_fs_block = lseek(sbd.device_fd, 0, SEEK_END) / sbd.bsize;
 	for (blk = startblk + 1; blk < last_fs_block; blk++) {
-		bh = bread(&sbd.buf_list, blk);
+		lbh = bread(&sbd.buf_list, blk);
 		/* Can't use get_block_type here (returns false "none") */
-		if (bh->b_data[0] == 0x01 && bh->b_data[1] == 0x16 &&
-		    bh->b_data[2] == 0x19 && bh->b_data[3] == 0x70 &&
-		    bh->b_data[4] == 0x00 && bh->b_data[5] == 0x00 &&
-		    bh->b_data[6] == 0x00 && bh->b_data[7] == metatype) {
+		if (lbh->b_data[0] == 0x01 && lbh->b_data[1] == 0x16 &&
+		    lbh->b_data[2] == 0x19 && lbh->b_data[3] == 0x70 &&
+		    lbh->b_data[4] == 0x00 && lbh->b_data[5] == 0x00 &&
+		    lbh->b_data[6] == 0x00 && lbh->b_data[7] == metatype) {
 			found = 1;
-			brelse(bh);
+			brelse(lbh);
 			break;
 		}
-		brelse(bh);
+		brelse(lbh);
 	}
 	if (!found)
 		blk = 0;
@@ -2312,10 +2311,10 @@ static void hex_edit(int *exitch)
 				else if (estring[i+1] >= 'A' &&
 					 estring[i+1] <= 'F')
 					ch += (estring[i+1] - 'A' + 0x0a);
-				buf[offset + hexoffset] = ch;
+				bh->b_data[offset + hexoffset] = ch;
 			}
 			lseek(sbd.device_fd, dev_offset, SEEK_SET);
-			if (write(sbd.device_fd, buf, sbd.bsize) !=
+			if (write(sbd.device_fd, bh->b_data, sbd.bsize) !=
 			    sbd.bsize) {
 				fprintf(stderr, "write error: %s from %s:%d: "
 					"offset %lld (0x%llx)\n",
@@ -2402,7 +2401,8 @@ static void jump(void)
 		
 		if (edit_row[dmode] >= 0) {
 			col2 = edit_col[dmode] & 0x08;/* thus 0-7->0, 8-15->8 */
-			b = (uint64_t *)&buf[edit_row[dmode]*16 + offset + col2];
+			b = (uint64_t *)&bh->b_data[edit_row[dmode]*16 +
+						    offset + col2];
 			temp_blk=be64_to_cpu(*b);
 		}
 	}
@@ -2441,14 +2441,14 @@ static void print_block_type(uint64_t tblock, int type, const char *additional)
 static void find_print_block_type(void)
 {
 	uint64_t tblock;
-	struct gfs2_buffer_head *bh;
+	struct gfs2_buffer_head *lbh;
 	int type;
 
 	tblock = blockstack[blockhist % BLOCK_STACK_SIZE].block;
-	bh = bread(&sbd.buf_list, tblock);
-	type = get_block_type(bh->b_data);
+	lbh = bread(&sbd.buf_list, tblock);
+	type = get_block_type(lbh);
 	print_block_type(tblock, type, "");
-	brelse(bh);
+	brelse(lbh);
 	gfs2_rgrp_free(&sbd.rglist);
 	exit(0);
 }
@@ -2551,13 +2551,14 @@ static void find_change_block_alloc(int *newval)
 static void process_field(const char *field, uint64_t *newval, int print_field)
 {
 	uint64_t fblock;
-	struct gfs2_buffer_head *bh;
+	struct gfs2_buffer_head *rbh;
 	int type;
 	struct gfs2_rgrp rg;
 
 	fblock = blockstack[blockhist % BLOCK_STACK_SIZE].block;
-	bh = bread(&sbd.buf_list, fblock);
-	type = get_block_type(bh->b_data);
+	rbh = bread(&sbd.buf_list, block);
+	type = get_block_type(rbh);
+
 	switch (type) {
 	case GFS2_METATYPE_SB:
 		if (print_field)
@@ -2565,10 +2566,10 @@ static void process_field(const char *field, uint64_t *newval, int print_field)
 					 " which is not implemented");
 		break;
 	case GFS2_METATYPE_RG:
-		gfs2_rgrp_in(&rg, bh->b_data);
+		gfs2_rgrp_in(&rg, rbh);
 		if (newval) {
 			gfs2_rgrp_assignval(&rg, field, *newval);
-			gfs2_rgrp_out(&rg, bh->b_data);
+			gfs2_rgrp_out(&rg, rbh);
 			if (print_field)
 				gfs2_rgrp_printval(&rg, field);
 		} else {
@@ -2582,10 +2583,10 @@ static void process_field(const char *field, uint64_t *newval, int print_field)
 					 " which is not implemented");
 		break;
 	case GFS2_METATYPE_DI:
-		gfs2_dinode_in(&di, bh->b_data);
+		gfs2_dinode_in(&di, rbh);
 		if (newval) {
 			gfs2_dinode_assignval(&di, field, *newval);
-			gfs2_dinode_out(&di, bh->b_data);
+			gfs2_dinode_out(&di, rbh);
 			if (print_field)
 				gfs2_dinode_printval(&di, field);
 		} else {
@@ -2609,8 +2610,8 @@ static void process_field(const char *field, uint64_t *newval, int print_field)
 		break;
 	}
 	if (newval)
-		bmodified(bh);
-	brelse(bh);
+		bmodified(rbh);
+	brelse(rbh);
 	bcommit(&sbd.buf_list);
 }
 
@@ -2882,11 +2883,12 @@ static void interactive_mode(void)
 /* ------------------------------------------------------------------------ */
 /* gfs_log_header_in - read in a gfs1-style log header                      */
 /* ------------------------------------------------------------------------ */
-void gfs_log_header_in(struct gfs_log_header *head, char *inbuf)
+void gfs_log_header_in(struct gfs_log_header *head,
+		       struct gfs2_buffer_head *lbh)
 {
-	struct gfs_log_header *str = (struct gfs_log_header *) inbuf;
+	struct gfs_log_header *str = (struct gfs_log_header *)lbh->b_data;
 
-	gfs2_meta_header_in(&head->lh_header, inbuf);
+	gfs2_meta_header_in(&head->lh_header, lbh);
 
 	head->lh_flags = be32_to_cpu(str->lh_flags);
 	head->lh_pad = be32_to_cpu(str->lh_pad);
@@ -2955,7 +2957,7 @@ static int fsck_readi(struct gfs2_inode *ip, void *rbuf, uint64_t roffset,
 	       unsigned int size, uint64_t *abs_block)
 {
 	struct gfs2_sbd *sdp = ip->i_sbd;
-	struct gfs2_buffer_head *bh;
+	struct gfs2_buffer_head *lbh;
 	uint64_t lblock, dblock;
 	unsigned int o;
 	uint32_t extlen = 0;
@@ -2992,16 +2994,16 @@ static int fsck_readi(struct gfs2_inode *ip, void *rbuf, uint64_t roffset,
 			block_map(ip, lblock, &not_new, &dblock, &extlen,
 				  FALSE);
 		if (dblock) {
-			bh = bread(&sdp->buf_list, dblock);
+			lbh = bread(&sdp->buf_list, dblock);
 			if (*abs_block == 0)
-				*abs_block = bh->b_blocknr;
+				*abs_block = lbh->b_blocknr;
 			dblock++;
 			extlen--;
 		} else
-			bh = NULL;
-		if (bh) {
-			memcpy(rbuf, bh->b_data + o, amount);
-			brelse(bh);
+			lbh = NULL;
+		if (lbh) {
+			memcpy(rbuf, lbh->b_data + o, amount);
+			brelse(lbh);
 		} else {
 			memset(rbuf, 0, amount);
 		}
@@ -3032,13 +3034,13 @@ static void check_journal_wrap(uint64_t seq, uint64_t *highest_seq)
 /* ------------------------------------------------------------------------ */
 static void dump_journal(const char *journal)
 {
-	struct gfs2_buffer_head *j_bh = NULL;
+	struct gfs2_buffer_head *j_bh = NULL, dummy_bh;
 	uint64_t jblock, j_size, jb, abs_block;
 	int error, start_line, journal_num;
-	char jbuf[sbd.bsize];
 	struct gfs2_inode *j_inode = NULL;
 	int ld_blocks = 0;
 	uint64_t highest_seq = 0;
+	char *jbuf = NULL;
 
 	start_line = line;
 	lines_per_row[dmode] = 1;
@@ -3052,6 +3054,7 @@ static void dump_journal(const char *journal)
 	if (!gfs1) {
 		j_bh = bread(&sbd.buf_list, jblock);
 		j_inode = inode_get(&sbd, j_bh);
+		jbuf = malloc(sbd.bsize);
 	}
 
 	for (jb = 0; jb < j_size; jb += (gfs1 ? 1:sbd.bsize)) {
@@ -3060,14 +3063,15 @@ static void dump_journal(const char *journal)
 				brelse(j_bh);
 			j_bh = bread(&sbd.buf_list, jblock + jb);
 			abs_block = jblock + jb;
-			memcpy(jbuf, j_bh->b_data, sbd.bsize);
+			dummy_bh.b_data = j_bh->b_data;
 		} else {
 			error = fsck_readi(j_inode, (void *)&jbuf, jb,
 					   sbd.bsize, &abs_block);
 			if (!error) /* end of file */
 				break;
+			dummy_bh.b_data = jbuf;
 		}
-		if (get_block_type(jbuf) == GFS2_METATYPE_LD) {
+		if (get_block_type(&dummy_bh) == GFS2_METATYPE_LD) {
 			uint64_t *b;
 			struct gfs2_log_descriptor ld;
 			int ltndx;
@@ -3090,7 +3094,7 @@ static void dump_journal(const char *journal)
 
 			print_gfs2("0x%llx (j+%4llx): Log descriptor, ",
 				   abs_block, jb / (gfs1 ? 1 : sbd.bsize));
-			gfs2_log_descriptor_in(&ld, jbuf);
+			gfs2_log_descriptor_in(&ld, &dummy_bh);
 			print_gfs2("type %d ", ld.ld_type);
 
 			for (ltndx = 0;; ltndx++) {
@@ -3104,20 +3108,21 @@ static void dump_journal(const char *journal)
 			eol(0);
 			print_gfs2("                    ");
 			if (gfs1)
-				b = (uint64_t *)(jbuf +
+				b = (uint64_t *)(dummy_bh.b_data +
 					sizeof(struct gfs_log_descriptor));
 			else
-				b = (uint64_t *)(jbuf +
+				b = (uint64_t *)(dummy_bh.b_data +
 					sizeof(struct gfs2_log_descriptor));
 			ld_blocks = ld.ld_data1;
-			ld_blocks -= print_ld_blocks(b, (jbuf + sbd.bsize),
+			ld_blocks -= print_ld_blocks(b, (dummy_bh.b_data +
+							 sbd.bsize),
 						     start_line);
-		} else if (get_block_type(jbuf) == GFS2_METATYPE_LH) {
+		} else if (get_block_type(&dummy_bh) == GFS2_METATYPE_LH) {
 			struct gfs2_log_header lh;
 			struct gfs_log_header lh1;
 
 			if (gfs1) {
-				gfs_log_header_in(&lh1, jbuf);
+				gfs_log_header_in(&lh1, &dummy_bh);
 				check_journal_wrap(lh1.lh_sequence,
 						   &highest_seq);
 				print_gfs2("0x%llx (j+%4llx): Log header: "
@@ -3128,7 +3133,7 @@ static void dump_journal(const char *journal)
 					   lh1.lh_first, lh1.lh_tail,
 					   lh1.lh_last_dump);
 			} else {
-				gfs2_log_header_in(&lh, jbuf);
+				gfs2_log_header_in(&lh, &dummy_bh);
 				check_journal_wrap(lh.lh_sequence,
 						   &highest_seq);
 				print_gfs2("0x%llx (j+%4llx): Log header: Seq"
@@ -3143,13 +3148,14 @@ static void dump_journal(const char *journal)
 				   " continuation block", abs_block, jb);
 			eol(0);
 			print_gfs2("                    ");
-			ld_blocks -= print_ld_blocks((uint64_t *)jbuf,
-						     (jbuf + sbd.bsize),
-						     start_line);
+			ld_blocks -= print_ld_blocks((uint64_t *)dummy_bh.b_data,
+						     (dummy_bh.b_data +
+						      sbd.bsize), start_line);
 		}
 	}
 	brelse(j_bh);
 	blockhist = -1; /* So we don't print anything else */
+	free(jbuf);
 }
 
 /* ------------------------------------------------------------------------ */
@@ -3479,7 +3485,6 @@ int main(int argc, char *argv[])
 	memset(last_entry_onscreen, 0, sizeof(last_entry_onscreen));
 	dmode = INIT_MODE;
 	sbd.bsize = 4096;
-	type_alloc(buf, char, sbd.bsize); /* allocate/malloc a new 4K buffer */
 	block = starting_blk = 0x10;
 	for (i = 0; i < BLOCK_STACK_SIZE; i++) {
 		blockstack[i].dmode = HEX_MODE;
@@ -3536,8 +3541,6 @@ int main(int argc, char *argv[])
 		}
 	}
 	close(fd);
-	if (buf)
-		free(buf);
 	if (indirect)
 		free(indirect);
 	gfs2_rgrp_free(&sbd.rglist);
diff --git a/gfs2/edit/hexedit.h b/gfs2/edit/hexedit.h
index c508345..6996ab5 100644
--- a/gfs2/edit/hexedit.h
+++ b/gfs2/edit/hexedit.h
@@ -66,45 +66,45 @@ enum dsp_mode { HEX_MODE = 0, GFS2_MODE = 1, EXTENDED_MODE = 2, INIT_MODE = 3 };
 #define GFS_LOG_DESC_Q          (402)    /* quota */
 #define GFS_LOG_DESC_LAST       (500)    /* final in a logged transaction */
 
-EXTERN uint64_t block INIT(0);
-EXTERN int blockhist INIT(0);
-EXTERN int edit_mode INIT(0);
-EXTERN int line;
-EXTERN char edit_fmt[80];
-EXTERN char estring[1024]; /* edit string */
-EXTERN char efield[64];
-EXTERN uint64_t dev_offset INIT(0);
-EXTERN uint64_t max_block INIT(0);
-EXTERN char *buf INIT(NULL);
-EXTERN int termlines INIT(30);
-EXTERN int termcols INIT(80);
-EXTERN int insert INIT(0);
-EXTERN const char *termtype;
-EXTERN int line INIT(1);
-EXTERN int struct_len INIT(0);
-EXTERN unsigned int offset;
-EXTERN int edit_row[DMODES], edit_col[DMODES], print_entry_ndx;
-EXTERN int start_row[DMODES], end_row[DMODES], lines_per_row[DMODES];
-EXTERN int edit_size[DMODES], last_entry_onscreen[DMODES];
-EXTERN char edit_fmt[80];
-EXTERN struct gfs2_sbd sbd;
-EXTERN struct gfs_sb *sbd1;
-EXTERN struct gfs2_inum gfs1_quota_di;   /* kludge because gfs2 sb too small */
-EXTERN struct gfs2_inum gfs1_license_di; /* kludge because gfs2 sb too small */
-EXTERN struct gfs2_dinode di;
-EXTERN int screen_chunk_size INIT(512); /* how much of the 4K can fit on screen */
-EXTERN int gfs2_struct_type;
-EXTERN uint64_t block_in_mem INIT(-1);
-EXTERN char device[NAME_MAX];
-EXTERN int identify INIT(FALSE);
-EXTERN int color_scheme INIT(0);
-EXTERN WINDOW *wind;
-EXTERN int gfs1 INIT(0);
-EXTERN int editing INIT(0);
-EXTERN uint64_t temp_blk;
-EXTERN uint64_t starting_blk;
-EXTERN const char *block_type_str[15];
-EXTERN int dsplines;
+extern uint64_t block;
+extern int blockhist;
+extern int edit_mode;
+extern int line;
+extern char edit_fmt[80];
+extern char estring[1024]; /* edit string */
+extern char efield[64];
+extern uint64_t dev_offset;
+extern uint64_t max_block;
+extern struct gfs2_buffer_head *bh;
+extern int termlines;
+extern int termcols;
+extern int insert;
+extern const char *termtype;
+extern int line;
+extern int struct_len;
+extern unsigned int offset;
+extern int edit_row[DMODES], edit_col[DMODES], print_entry_ndx;
+extern int start_row[DMODES], end_row[DMODES], lines_per_row[DMODES];
+extern int edit_size[DMODES], last_entry_onscreen[DMODES];
+extern char edit_fmt[80];
+extern struct gfs2_sbd sbd;
+extern struct gfs_sb *sbd1;
+extern struct gfs2_inum gfs1_quota_di;   /* kludge because gfs2 sb too small */
+extern struct gfs2_inum gfs1_license_di; /* kludge because gfs2 sb too small */
+extern struct gfs2_dinode di;
+extern int screen_chunk_size; /* how much of the 4K can fit on screen */
+extern int gfs2_struct_type;
+extern uint64_t block_in_mem;
+extern char device[NAME_MAX];
+extern int identify;
+extern int color_scheme;
+extern WINDOW *wind;
+extern int gfs1;
+extern int editing;
+extern uint64_t temp_blk;
+extern uint64_t starting_blk;
+extern const char *block_type_str[15];
+extern int dsplines;
 
 struct gfs_jindex {
         uint64_t ji_addr;       /* starting block of the journal */
@@ -171,20 +171,25 @@ struct gfs_rgrp {
 	char rg_reserved[64];
 };
 
-EXTERN int block_is_jindex(void);
-EXTERN int block_is_rindex(void);
-EXTERN int block_is_inum_file(void);
-EXTERN int block_is_statfs_file(void);
-EXTERN int block_is_quota_file(void);
-EXTERN int block_is_per_node(void);
-EXTERN int block_is_in_per_node(void);
-EXTERN int display_block_type(const char *lpBuffer, int from_restore);
-EXTERN void gfs_jindex_in(struct gfs_jindex *jindex, char *buf);
-EXTERN void gfs_log_header_in(struct gfs_log_header *head, char *buf);
-EXTERN void gfs_log_header_print(struct gfs_log_header *lh);
-EXTERN void gfs_dinode_in(struct gfs_dinode *di, char *buf);
-EXTERN int display(int identify_only);
-EXTERN uint64_t check_keywords(const char *kword);
+extern int block_is_jindex(void);
+extern int block_is_rindex(void);
+extern int block_is_inum_file(void);
+extern int block_is_statfs_file(void);
+extern int block_is_quota_file(void);
+extern int block_is_per_node(void);
+extern int block_is_in_per_node(void);
+extern int display_block_type(int from_restore);
+extern void gfs_jindex_in(struct gfs_jindex *jindex, char *buf);
+extern void gfs_log_header_in(struct gfs_log_header *head,
+			      struct gfs2_buffer_head *bh);
+extern void gfs_log_header_print(struct gfs_log_header *lh);
+extern void gfs_dinode_in(struct gfs_dinode *di, struct gfs2_buffer_head *bh);
+extern void savemeta(const char *out_fn, int saveoption);
+extern void restoremeta(const char *in_fn, const char *out_device,
+			uint64_t printblocksonly);
+extern int display(int identify_only);
+extern uint64_t check_keywords(const char *kword);
+extern uint64_t masterblock(const char *fn);
 
 struct gfs2_dirents {
 	uint64_t block;
@@ -246,12 +251,12 @@ struct gfs_sb {
 	char sb_reserved[96];
 };
 
-EXTERN struct blkstack_info blockstack[BLOCK_STACK_SIZE];
-EXTERN struct iinfo *indirect; /* more than the most indirect
+extern struct blkstack_info blockstack[BLOCK_STACK_SIZE];
+extern struct iinfo *indirect; /* more than the most indirect
 			       pointers possible for any given 4K block */
-EXTERN struct indirect_info masterdir; /* Master directory info */
-EXTERN int indirect_blocks INIT(0);  /* count of indirect blocks */
-EXTERN enum dsp_mode dmode INIT(HEX_MODE);
+extern struct indirect_info masterdir; /* Master directory info */
+extern int indirect_blocks;  /* count of indirect blocks */
+extern enum dsp_mode dmode;
 
 #define SCREEN_HEIGHT   (16)
 #define SCREEN_WIDTH    (16)
diff --git a/gfs2/edit/savemeta.c b/gfs2/edit/savemeta.c
index 3a34c96..39888fa 100644
--- a/gfs2/edit/savemeta.c
+++ b/gfs2/edit/savemeta.c
@@ -46,6 +46,7 @@ struct saved_metablock {
 };
 
 struct saved_metablock *savedata;
+struct gfs2_buffer_head *savebh;
 uint64_t last_fs_block, last_reported_block, blks_saved, total_out, pct;
 struct gfs2_bmap *blocklist = NULL;
 uint64_t journal_blocks[MAX_JOURNALS_SAVED];
@@ -64,15 +65,15 @@ uint64_t masterblock(const char *fn);
  * returns: 0 if successful
  *          -1 if this isn't gfs metadata.
  */
-static int get_gfs_struct_info(char *gbuf, int *block_type, int *gstruct_len)
+static int get_gfs_struct_info(struct gfs2_buffer_head *lbh, int *block_type,
+			       int *gstruct_len)
 {
-	struct gfs2_meta_header mh, mhbuf;
+	struct gfs2_meta_header mh;
 
 	*block_type = 0;
 	*gstruct_len = sbd.bsize;
 
-	memcpy(&mhbuf, gbuf, sizeof(mhbuf));
-	gfs2_meta_header_in(&mh, (void *)&mhbuf);
+	gfs2_meta_header_in(&mh, lbh);
 	if (mh.mh_magic != GFS2_MAGIC)
 		return -1;
 
@@ -201,15 +202,15 @@ static int save_block(int fd, int out_fd, uint64_t blk)
 		return 0;
 	}
 	memset(savedata, 0, sizeof(struct saved_metablock));
-	do_lseek(fd, blk * sbd.bsize);
-	do_read(fd, savedata->buf, sbd.bsize); /* read in the block */
+	savebh = bread(&sbd.buf_list, blk);
+	memcpy(&savedata->buf, savebh->b_data, sbd.bsize);
 
 	/* If this isn't metadata and isn't a system file, we don't want it.
 	   Note that we're checking "block" here rather than blk.  That's
 	   because we want to know if the source inode's "block" is a system
 	   inode, not the block within the inode "blk". They may or may not
 	   be the same thing. */
-	if (get_gfs_struct_info(savedata->buf, &blktype, &blklen) &&
+	if (get_gfs_struct_info(savebh, &blktype, &blklen) &&
 	    !block_is_systemfile())
 		return 0; /* Not metadata, and not system file, so skip it */
 	trailing0 = 0;
@@ -371,16 +372,17 @@ static void save_inode_data(int out_fd)
 	}
 	if (inode->i_di.di_eattr) { /* if this inode has extended attributes */
 		struct gfs2_meta_header mh;
+		struct gfs2_buffer_head *lbh;
 
-		metabh = bread(&sbd.buf_list, inode->i_di.di_eattr);
+		lbh = bread(&sbd.buf_list, inode->i_di.di_eattr);
 		save_block(sbd.device_fd, out_fd, inode->i_di.di_eattr);
-		gfs2_meta_header_in(&mh, metabh->b_data);
+		gfs2_meta_header_in(&mh, lbh);
 		if (mh.mh_magic == GFS2_MAGIC &&
 		    mh.mh_type == GFS2_METATYPE_EA)
-			save_ea_block(out_fd, metabh);
+			save_ea_block(out_fd, lbh);
 		else if (mh.mh_magic == GFS2_MAGIC &&
 			 mh.mh_type == GFS2_METATYPE_IN)
-			save_indirect_blocks(out_fd, cur_list, metabh, 2, 2);
+			save_indirect_blocks(out_fd, cur_list, lbh, 2, 2);
 		else {
 			if (mh.mh_magic == GFS2_MAGIC) /* if it's metadata */
 				save_block(sbd.device_fd, out_fd,
@@ -394,15 +396,15 @@ static void save_inode_data(int out_fd)
 				(unsigned long long)block,
 				(unsigned long long)block);
 		}
-		brelse(metabh);
+		brelse(lbh);
 	}
 	inode_put(inode);
+	brelse(metabh);
 }
 
 static void get_journal_inode_blocks(void)
 {
 	int journal;
-	struct gfs2_buffer_head *bh;
 
 	journals_found = 0;
 	memset(journal_blocks, 0, sizeof(journal_blocks));
@@ -442,7 +444,7 @@ static void get_journal_inode_blocks(void)
 			jblock = indirect->ii[0].dirent[journal + 2].block;
 			bh = bread(&sbd.buf_list, jblock);
 			j_inode = inode_get(&sbd, bh);
-			gfs2_dinode_in(&jdi, bh->b_data);
+			gfs2_dinode_in(&jdi, bh);
 			inode_put(j_inode);
 		}
 		journal_blocks[journals_found++] = jblock;
@@ -456,7 +458,7 @@ static int next_rg_freemeta(struct gfs2_sbd *sdp, struct rgrp_list *rgd,
 	uint32_t length = rgd->ri.ri_length;
 	uint32_t blk = (first)? 0: (uint32_t)((*nrfblock+1)-rgd->ri.ri_data0);
 	int i;
-	struct gfs2_buffer_head *bh;
+	struct gfs2_buffer_head *lbh;
 
 	if(!first && (*nrfblock < rgd->ri.ri_data0)) {
 		log_err("next_rg_freemeta:  Start block is outside rgrp "
@@ -471,11 +473,11 @@ static int next_rg_freemeta(struct gfs2_sbd *sdp, struct rgrp_list *rgd,
 	}
 	for(; i < length; i++){
 		bits = &rgd->bits[i];
-		bh = bread(&sdp->buf_list, rgd->ri.ri_addr + i);
+		lbh = bread(&sdp->buf_list, rgd->ri.ri_addr + i);
 		blk = gfs2_bitfit((unsigned char *)bh->b_data +
 				  bits->bi_offset, bits->bi_len, blk,
 				  GFS2_BLKST_UNLINKED);
-		brelse(bh);
+		brelse(lbh);
 		if(blk != BFITNOENT){
 			*nrfblock = blk + (bits->bi_start * GFS2_NBBY) +
 				rgd->ri.ri_data0;
@@ -488,7 +490,7 @@ static int next_rg_freemeta(struct gfs2_sbd *sdp, struct rgrp_list *rgd,
 	return 0;
 }
 
-void savemeta(char *out_fn, int saveoption)
+void savemeta(const char *out_fn, int saveoption)
 {
 	int out_fd;
 	int slow;
@@ -496,7 +498,7 @@ void savemeta(char *out_fn, int saveoption)
 	uint64_t memreq;
 	int rgcount;
 	uint64_t jindex_block;
-	struct gfs2_buffer_head *bh;
+	struct gfs2_buffer_head *lbh;
 
 	slow = (saveoption == 1);
 	sbd.md.journals = 1;
@@ -569,11 +571,11 @@ void savemeta(char *out_fn, int saveoption)
 					    &sbd.md.riinode);
 			jindex_block = masterblock("jindex");
 		}
-		bh = bread(&sbd.buf_list, jindex_block);
-		gfs2_dinode_in(&di, bh->b_data);
+		lbh = bread(&sbd.buf_list, jindex_block);
+		gfs2_dinode_in(&di, lbh);
 		if (!gfs1)
-			do_dinode_extended(&di, bh->b_data);
-		brelse(bh);
+			do_dinode_extended(&di, lbh);
+		brelse(lbh);
 	}
 	if (!slow) {
 		printf("Reading resource groups...");
@@ -805,14 +807,14 @@ static int restore_data(int fd, int in_fd, int printblocksonly)
 			if (block > highest_valid_block)
 				highest_valid_block = block;
 			if (printblocksonly > 1 && printblocksonly == block) {
-				memcpy(buf, savedata->buf, sbd.bsize);
+				memcpy(bh->b_data, savedata->buf, sbd.bsize);
 				block_in_mem = block;
 				display(0);
 				return 0;
 			} else if (printblocksonly == 1) {
 				print_gfs2("%d (l=0x%x): ", blks_saved,
 					   savedata->siglen);
-				display_block_type(savedata->buf, TRUE);
+				display_block_type(TRUE);
 			}
 		} else {
 			warm_fuzzy_stuff(savedata->blk, FALSE, FALSE);
diff --git a/gfs2/fsck/fs_recovery.c b/gfs2/fsck/fs_recovery.c
index 29e7d2e..13a60ae 100644
--- a/gfs2/fsck/fs_recovery.c
+++ b/gfs2/fsck/fs_recovery.c
@@ -386,8 +386,7 @@ static int fix_journal_seq_no(struct gfs2_inode *ip)
 		log_warn( _("Renumbering it as 0x%llx\n"), lh.lh_sequence);
 		block_map(ip, blk, &new, &dblock, &extlen, FALSE);
 		bh = bread(&ip->i_sbd->buf_list, dblock);
-		gfs2_log_header_out(&lh, bh->b_data);
-		bmodified(bh);
+		gfs2_log_header_out(&lh, bh);
 		brelse(bh);
 	}
 	return 0;
diff --git a/gfs2/fsck/main.c b/gfs2/fsck/main.c
index 953c2dc..f7d1279 100644
--- a/gfs2/fsck/main.c
+++ b/gfs2/fsck/main.c
@@ -325,20 +325,25 @@ void check_statfs(struct gfs2_sbd *sdp)
 	log_err( _("The statfs file is wrong:\n\n"));
 	log_err( _("Current statfs values:\n"));
 	log_err( _("blocks:  %lld (0x%llx)\n"),
-		sc.sc_total, sc.sc_total);
+		 (unsigned long long)sc.sc_total,
+		 (unsigned long long)sc.sc_total);
 	log_err( _("free:    %lld (0x%llx)\n"),
-		sc.sc_free, sc.sc_free);
+		 (unsigned long long)sc.sc_free,
+		 (unsigned long long)sc.sc_free);
 	log_err( _("dinodes: %lld (0x%llx)\n\n"),
-		sc.sc_dinodes, sc.sc_dinodes);
+		 (unsigned long long)sc.sc_dinodes,
+		 (unsigned long long)sc.sc_dinodes);
 
 	log_err( _("Calculated statfs values:\n"));
 	log_err( _("blocks:  %lld (0x%llx)\n"),
-		sdp->blks_total, sdp->blks_total);
+		 (unsigned long long)sdp->blks_total,
+		 (unsigned long long)sdp->blks_total);
 	log_err( _("free:    %lld (0x%llx)\n"),
-		sdp->blks_total - sdp->blks_alloced,
-		sdp->blks_total - sdp->blks_alloced);
+		 (unsigned long long)(sdp->blks_total - sdp->blks_alloced),
+		 (unsigned long long)(sdp->blks_total - sdp->blks_alloced));
 	log_err( _("dinodes: %lld (0x%llx)\n"),
-		sdp->dinodes_alloced, sdp->dinodes_alloced);
+		 (unsigned long long)sdp->dinodes_alloced,
+		 (unsigned long long)sdp->dinodes_alloced);
 
 	errors_found++;
 	if (!query( _("Okay to fix the master statfs file? (y/n)"))) {
diff --git a/gfs2/fsck/metawalk.c b/gfs2/fsck/metawalk.c
index 5052eb6..d3cdd22 100644
--- a/gfs2/fsck/metawalk.c
+++ b/gfs2/fsck/metawalk.c
@@ -79,8 +79,12 @@ struct gfs2_inode *fsck_inode_get(struct gfs2_sbd *sdp,
 {
 	struct gfs2_inode *ip, *sysip;
 
-	zalloc(ip, sizeof(struct gfs2_inode));
-	gfs2_dinode_in(&ip->i_di, bh->b_data);
+	ip = calloc(1, sizeof(struct gfs2_inode));
+	if (ip == NULL) {
+		fprintf(stderr, _("Out of memory in %s\n"), __FUNCTION__);
+		exit(-1);
+	}
+	gfs2_dinode_in(&ip->i_di, bh);
 	ip->i_bh = bh;
 	ip->i_sbd = sdp;
 
@@ -101,7 +105,7 @@ void fsck_inode_put(struct gfs2_inode *ip)
 	sysip = get_system_inode(ip->i_sbd, ip->i_di.di_num.no_addr);
 	if (sysip) {
 		if (ip->i_bh->b_changed)
-			gfs2_dinode_out(&ip->i_di, ip->i_bh->b_data);
+			gfs2_dinode_out(&ip->i_di, ip->i_bh);
 		brelse(ip->i_bh);
 	} else {
 		inode_put(ip);
@@ -428,10 +432,9 @@ static int check_leaf_blks(struct gfs2_inode *ip, struct metawalk_fxns *pass)
 					factor++;
 					divisor /= 2;
 				}
-				gfs2_leaf_in(&oldleaf, lbh->b_data);
+				gfs2_leaf_in(&oldleaf, lbh);
 				oldleaf.lf_depth = ip->i_di.di_depth - factor;
-				gfs2_leaf_out(&oldleaf, lbh->b_data);
-				bmodified(lbh);
+				gfs2_leaf_out(&oldleaf, lbh);
 				brelse(lbh);
 			}
 			else
@@ -472,7 +475,7 @@ static int check_leaf_blks(struct gfs2_inode *ip, struct metawalk_fxns *pass)
 				brelse(lbh);
 				break;
 			}
-			gfs2_leaf_in(&leaf, lbh->b_data);
+			gfs2_leaf_in(&leaf, lbh);
 			if(pass->check_leaf) {
 				error = pass->check_leaf(ip, leaf_no, lbh,
 							 pass->private);
@@ -488,9 +491,8 @@ static int check_leaf_blks(struct gfs2_inode *ip, struct metawalk_fxns *pass)
 			if (leaf.lf_dirent_format == (GFS2_FORMAT_DE << 16)) {
 				log_debug( _("incorrect lf_dirent_format at leaf #%" PRIu64 "\n"), leaf_no);
 				leaf.lf_dirent_format = GFS2_FORMAT_DE;
-				gfs2_leaf_out(&leaf, lbh->b_data);
+				gfs2_leaf_out(&leaf, lbh);
 				log_debug( _("Fixing lf_dirent_format.\n"));
-				bmodified(lbh);
 			}
 
 			/* Make sure it's really a leaf. */
@@ -529,7 +531,7 @@ static int check_leaf_blks(struct gfs2_inode *ip, struct metawalk_fxns *pass)
 
 				if(count != leaf.lf_entries) {
 					lbh = bread(&sbp->buf_list, leaf_no);
-					gfs2_leaf_in(&leaf, lbh->b_data);
+					gfs2_leaf_in(&leaf, lbh);
 
 					log_err( _("Leaf %llu (0x%llx) entry "
 						"count in directory %llu"
@@ -545,9 +547,8 @@ static int check_leaf_blks(struct gfs2_inode *ip, struct metawalk_fxns *pass)
 						leaf.lf_entries, count);
 					if(query( _("Update leaf entry count? (y/n) "))) {
 						leaf.lf_entries = count;
-						gfs2_leaf_out(&leaf, lbh->b_data);
+						gfs2_leaf_out(&leaf, lbh);
 						log_warn( _("Leaf entry count updated\n"));
-						bmodified(lbh);
 					} else
 						log_err( _("Leaf entry count left in inconsistant state\n"));
 					brelse(lbh);
diff --git a/gfs2/fsck/pass1.c b/gfs2/fsck/pass1.c
index bbf2e83..de93345 100644
--- a/gfs2/fsck/pass1.c
+++ b/gfs2/fsck/pass1.c
@@ -692,7 +692,7 @@ static int handle_di(struct gfs2_sbd *sdp, struct gfs2_buffer_head *bh,
 			    PRIu64 " (0x%" PRIx64 ")? (y/n) "),
 			 block, block)) {
 			ip->i_di.di_num.no_addr = ip->i_di.di_num.no_formal_ino = block;
-			gfs2_dinode_out(&ip->i_di, ip->i_bh->b_data);
+			gfs2_dinode_out(&ip->i_di, ip->i_bh);
 			bmodified(ip->i_bh);
 		} else
 			log_err( _("Address in inode at block #%" PRIu64
@@ -890,7 +890,7 @@ 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->b_data);
+			gfs2_dinode_out(&ip->i_di, ip->i_bh);
 		} else
 			log_err( _("Bad block count for #%llu (0x%llx"
 				") not fixed\n"),
diff --git a/gfs2/fsck/pass1b.c b/gfs2/fsck/pass1b.c
index e0b7ab3..78f1ed6 100644
--- a/gfs2/fsck/pass1b.c
+++ b/gfs2/fsck/pass1b.c
@@ -164,7 +164,7 @@ static int find_dentry(struct gfs2_inode *ip, struct gfs2_dirent *de,
 	}
 	/* Return the number of leaf entries so metawalk doesn't flag this
 	   leaf as having none. */
-	gfs2_leaf_in(&leaf, bh->b_data);
+	gfs2_leaf_in(&leaf, bh);
 	*count = leaf.lf_entries;
 	return 0;
 }
diff --git a/gfs2/fsck/pass5.c b/gfs2/fsck/pass5.c
index dae2c66..efad774 100644
--- a/gfs2/fsck/pass5.c
+++ b/gfs2/fsck/pass5.c
@@ -202,7 +202,7 @@ static void update_rgrp(struct gfs2_sbd *sbp, struct rgrp_list *rgp,
 		if(query( _("Update resource group counts? (y/n) "))) {
 			log_warn( _("Resource group counts updated\n"));
 			/* write out the rgrp */
-			gfs2_rgrp_out(&rgp->rg, rgp->bh[0]->b_data);
+			gfs2_rgrp_out(&rgp->rg, rgp->bh[0]);
 		} else
 			log_err( _("Resource group counts left inconsistent\n"));
 	}
diff --git a/gfs2/fsck/rgrepair.c b/gfs2/fsck/rgrepair.c
index 65080a2..a20e9c5 100644
--- a/gfs2/fsck/rgrepair.c
+++ b/gfs2/fsck/rgrepair.c
@@ -396,16 +396,15 @@ static int rewrite_rg_block(struct gfs2_sbd *sdp, struct rgrp_list *rg,
 			mh.mh_magic = GFS2_MAGIC;
 			mh.mh_type = GFS2_METATYPE_RB;
 			mh.mh_format = GFS2_FORMAT_RB;
-			gfs2_meta_header_out(&mh, rg->bh[x]->b_data);
+			gfs2_meta_header_out(&mh, rg->bh[x]);
 		} else {
 			memset(&rg->rg, 0, sizeof(struct gfs2_rgrp));
 			rg->rg.rg_header.mh_magic = GFS2_MAGIC;
 			rg->rg.rg_header.mh_type = GFS2_METATYPE_RG;
 			rg->rg.rg_header.mh_format = GFS2_FORMAT_RG;
 			rg->rg.rg_free = rg->ri.ri_data;
-			gfs2_rgrp_out(&rg->rg, rg->bh[x]->b_data);
+			gfs2_rgrp_out(&rg->rg, rg->bh[x]);
 		}
-		bmodified(rg->bh[x]);
 		brelse(rg->bh[x]);
 		return 0;
 	}
diff --git a/gfs2/libgfs2/Makefile b/gfs2/libgfs2/Makefile
index 7eeb2ac..855bc4c 100644
--- a/gfs2/libgfs2/Makefile
+++ b/gfs2/libgfs2/Makefile
@@ -26,7 +26,7 @@ LD=gcc
 CFLAGS=-Wall -ggdb -D_FILE_OFFSET_BITS=64 -D_LARGEFILE64_SOURCE \
        -D_GNU_SOURCE -DGFS2_RELEASE_NAME=\"2\" ${INCLUDEPATH}
 
-H=gfs2_disk_hash.h libgfs2.h linux_endian.h ondisk.h osi_list.h
+H=gfs2_disk_hash.h libgfs2.h linux_endian.h osi_list.h
 C=block_list.c buf.c device_geometry.c fs_bits.c fs_geometry.c fs_ops.c gfs1.c locking.c gfs2_log.c misc.c ondisk.c recovery.c size.c structures.c super.c rgrp.c
 O=$(subst .c,.o,${C})
 
diff --git a/gfs2/libgfs2/fs_geometry.c b/gfs2/libgfs2/fs_geometry.c
index aa62edf..ea72e3d 100644
--- a/gfs2/libgfs2/fs_geometry.c
+++ b/gfs2/libgfs2/fs_geometry.c
@@ -224,10 +224,9 @@ void build_rgrps(struct gfs2_sbd *sdp, int do_write)
 			for (x = 0; x < bitblocks; x++) {
 				bh = bget(&sdp->buf_list, rl->start + x);
 				if (x)
-					gfs2_meta_header_out(&mh, bh->b_data);
+					gfs2_meta_header_out(&mh, bh);
 				else
-					gfs2_rgrp_out(&rg, bh->b_data);
-				bmodified(bh);
+					gfs2_rgrp_out(&rg, bh);
 				brelse(bh);
 			}
 		}
diff --git a/gfs2/libgfs2/fs_ops.c b/gfs2/libgfs2/fs_ops.c
index 48ad90d..1dcae78 100644
--- a/gfs2/libgfs2/fs_ops.c
+++ b/gfs2/libgfs2/fs_ops.c
@@ -35,8 +35,12 @@ struct gfs2_inode *inode_get(struct gfs2_sbd *sdp, struct gfs2_buffer_head *bh)
 {
 	struct gfs2_inode *ip;
 
-	zalloc(ip, sizeof(struct gfs2_inode));
-	gfs2_dinode_in(&ip->i_di, bh->b_data);
+	ip = calloc(1, sizeof(struct gfs2_inode));
+	if (ip == NULL) {
+		fprintf(stderr, "Out of memory in %s\n", __FUNCTION__);
+		exit(-1);
+	}
+	gfs2_dinode_in(&ip->i_di, bh);
 	ip->i_bh = bh;
 	ip->i_sbd = sdp;
 	return ip;
@@ -45,7 +49,7 @@ struct gfs2_inode *inode_get(struct gfs2_sbd *sdp, struct gfs2_buffer_head *bh)
 void inode_put(struct gfs2_inode *ip)
 {
 	if (ip->i_bh->b_changed)
-		gfs2_dinode_out(&ip->i_di, ip->i_bh->b_data);
+		gfs2_dinode_out(&ip->i_di, ip->i_bh);
 	brelse(ip->i_bh);
 	free(ip);
 }
@@ -114,7 +118,7 @@ static uint64_t blk_alloc_i(struct gfs2_sbd *sdp, unsigned int type)
 	rg->rg_free--;
 
 	bmodified(bh);
-	gfs2_rgrp_out(rg, rl->bh[0]->b_data);
+	gfs2_rgrp_out(rg, rl->bh[0]);
 
 	sdp->blks_alloced++;
 	return ri->ri_data0 + bn;
@@ -177,14 +181,13 @@ void unstuff_dinode(struct gfs2_inode *ip)
 				mh.mh_magic = GFS2_MAGIC;
 				mh.mh_type = GFS2_METATYPE_JD;
 				mh.mh_format = GFS2_FORMAT_JD;
-				gfs2_meta_header_out(&mh, bh->b_data);
+				gfs2_meta_header_out(&mh, bh);
 			}
 
 			buffer_copy_tail(sdp, bh,
 					 sizeof(struct gfs2_meta_header),
 					 ip->i_bh, sizeof(struct gfs2_dinode));
 
-			bmodified(bh);
 			brelse(bh);
 		} else {
 			block = data_alloc(ip);
@@ -192,8 +195,6 @@ void unstuff_dinode(struct gfs2_inode *ip)
 
 			buffer_copy_tail(sdp, bh, 0,
 					 ip->i_bh, sizeof(struct gfs2_dinode));
-
-			bmodified(bh);
 			brelse(bh);
 		}
 	}
@@ -202,6 +203,7 @@ void unstuff_dinode(struct gfs2_inode *ip)
 
 	if (ip->i_di.di_size) {
 		*(uint64_t *)(ip->i_bh->b_data + sizeof(struct gfs2_dinode)) = cpu_to_be64(block);
+		/* no need: bmodified(ip->i_bh); buffer_clear_tail does it */
 		ip->i_di.di_blocks++;
 	}
 
@@ -257,13 +259,11 @@ void build_height(struct gfs2_inode *ip, int height)
 				mh.mh_magic = GFS2_MAGIC;
 				mh.mh_type = GFS2_METATYPE_IN;
 				mh.mh_format = GFS2_FORMAT_IN;
-				gfs2_meta_header_out(&mh, bh->b_data);
+				gfs2_meta_header_out(&mh, bh);
 			}
 			buffer_copy_tail(sdp, bh,
 					 sizeof(struct gfs2_meta_header),
 					 ip->i_bh, sizeof(struct gfs2_dinode));
-
-			bmodified(bh);
 			brelse(bh);
 		}
 
@@ -271,6 +271,7 @@ void build_height(struct gfs2_inode *ip, int height)
 
 		if (new_block) {
 			*(uint64_t *)(ip->i_bh->b_data + sizeof(struct gfs2_dinode)) = cpu_to_be64(block);
+			/* no need: bmodified(ip->i_bh);*/
 			ip->i_di.di_blocks++;
 		}
 
@@ -375,8 +376,7 @@ void block_map(struct gfs2_inode *ip, uint64_t lblock, int *new,
 			mh.mh_magic = GFS2_MAGIC;
 			mh.mh_type = GFS2_METATYPE_IN;
 			mh.mh_format = GFS2_FORMAT_IN;
-			bmodified(bh);
-			gfs2_meta_header_out(&mh, bh->b_data);
+			gfs2_meta_header_out(&mh, bh);
 		} else
 			bh = bread(&sdp->buf_list, *dblock);
 	}
@@ -551,7 +551,7 @@ int gfs2_writei(struct gfs2_inode *ip, void *buf,
 				mh.mh_magic = GFS2_MAGIC;
 				mh.mh_type = GFS2_METATYPE_JD;
 				mh.mh_format = GFS2_FORMAT_JD;
-				gfs2_meta_header_out(&mh, bh->b_data);
+				gfs2_meta_header_out(&mh, bh);
 			}
 		} else
 			bh = bread(&sdp->buf_list, dblock);
@@ -758,7 +758,7 @@ static void dir_split_leaf(struct gfs2_inode *dip, uint32_t lindex, uint64_t lea
 		mh.mh_magic = GFS2_MAGIC;
 		mh.mh_type = GFS2_METATYPE_LF;
 		mh.mh_format = GFS2_FORMAT_LF;
-		gfs2_meta_header_out(&mh, nbh->b_data);
+		gfs2_meta_header_out(&mh, nbh);
 	}
 
 	nleaf = (struct gfs2_leaf *)nbh->b_data;
@@ -839,7 +839,6 @@ static void dir_split_leaf(struct gfs2_inode *dip, uint32_t lindex, uint64_t lea
 	dip->i_di.di_blocks++;
 
 	brelse(obh);
-	bmodified(nbh);
 	brelse(nbh);
 }
 
@@ -994,7 +993,7 @@ static void dir_e_add(struct gfs2_inode *dip, const char *filename, int len,
 					mh.mh_magic = GFS2_MAGIC;
 					mh.mh_type = GFS2_METATYPE_LF;
 					mh.mh_format = GFS2_FORMAT_LF;
-					gfs2_meta_header_out(&mh, nbh->b_data);
+					gfs2_meta_header_out(&mh, nbh);
 				}
 
 				leaf->lf_next = cpu_to_be64(bn);
@@ -1046,7 +1045,7 @@ static void dir_make_exhash(struct gfs2_inode *dip)
 		mh.mh_magic = GFS2_MAGIC;
 		mh.mh_type = GFS2_METATYPE_LF;
 		mh.mh_format = GFS2_FORMAT_LF;
-		gfs2_meta_header_out(&mh, bh->b_data);
+		gfs2_meta_header_out(&mh, bh);
 	}
 
 	leaf = (struct gfs2_leaf *)bh->b_data;
@@ -1177,7 +1176,7 @@ init_dinode(struct gfs2_sbd *sdp, struct gfs2_inum *inum,
 		di.di_entries = 2;
 	}
 
-	gfs2_dinode_out(&di, bh->b_data);
+	gfs2_dinode_out(&di, bh);
 
 	return bh;
 }
@@ -1582,7 +1581,7 @@ void gfs2_free_block(struct gfs2_sbd *sdp, uint64_t block)
 	if (rgd) {
 		gfs2_set_bitmap(sdp, block, GFS2_BLKST_FREE);
 		rgd->rg.rg_free++; /* adjust the free count */
-		gfs2_rgrp_out(&rgd->rg, rgd->bh[0]->b_data); /* back to the buffer */
+		gfs2_rgrp_out(&rgd->rg, rgd->bh[0]); /* back to the buffer */
 		sdp->blks_alloced--;
 	}
 }
@@ -1647,7 +1646,7 @@ int gfs2_freedi(struct gfs2_sbd *sdp, uint64_t diblock)
 	rgd = gfs2_blk2rgrpd(sdp, diblock);
 	rgd->rg.rg_free++;
 	rgd->rg.rg_dinodes--; /* one less inode in use */
-	gfs2_rgrp_out(&rgd->rg, rgd->bh[0]->b_data);
+	gfs2_rgrp_out(&rgd->rg, rgd->bh[0]);
 	sdp->dinodes_alloced--;
 	return 0;
 }
diff --git a/gfs2/libgfs2/gfs1.c b/gfs2/libgfs2/gfs1.c
index 0f59669..a06fe11 100644
--- a/gfs2/libgfs2/gfs1.c
+++ b/gfs2/libgfs2/gfs1.c
@@ -113,8 +113,7 @@ void gfs1_block_map(struct gfs2_inode *ip, uint64_t lblock, int *new,
 			mh.mh_magic = GFS2_MAGIC;
 			mh.mh_type = GFS2_METATYPE_IN;
 			mh.mh_format = GFS2_FORMAT_IN;
-			gfs2_meta_header_out(&mh, bh->b_data);
-			bmodified(bh);
+			gfs2_meta_header_out(&mh, bh);
 		} else {
 			bh = bread(&sdp->buf_list, *dblock);
 		}
@@ -328,11 +327,11 @@ int gfs1_ri_update(struct gfs2_sbd *sdp, int fd, int *rgcount, int quiet)
 /* ------------------------------------------------------------------------ */
 /* gfs_dinode_in */
 /* ------------------------------------------------------------------------ */
-static void gfs_dinode_in(struct gfs_dinode *di, char *buf)
+static void gfs_dinode_in(struct gfs_dinode *di, struct gfs2_buffer_head *bh)
 {
-	struct gfs_dinode *str = (struct gfs_dinode *)buf;
+	struct gfs_dinode *str = (struct gfs_dinode *)bh->b_data;
 
-	gfs2_meta_header_in(&di->di_header, buf);
+	gfs2_meta_header_in(&di->di_header, bh);
 	gfs2_inum_in(&di->di_num, (char *)&str->di_num);
 
 	di->di_mode = be32_to_cpu(str->di_mode);
@@ -363,8 +362,13 @@ struct gfs2_inode *gfs_inode_get(struct gfs2_sbd *sdp,
 	struct gfs_dinode gfs1_dinode;
 	struct gfs2_inode *ip;
 
-	zalloc(ip, sizeof(struct gfs2_inode));
-	gfs_dinode_in(&gfs1_dinode, bh->b_data);
+	ip = calloc(1, sizeof(struct gfs2_inode));
+	if (ip == NULL) {
+		fprintf(stderr, "Out of memory in %s\n", __FUNCTION__);
+		exit(-1);
+	}
+
+	gfs_dinode_in(&gfs1_dinode, bh);
 	memcpy(&ip->i_di.di_header, &gfs1_dinode.di_header,
 	       sizeof(struct gfs2_meta_header));
 	memcpy(&ip->i_di.di_num, &gfs1_dinode.di_num,
diff --git a/gfs2/libgfs2/libgfs2.h b/gfs2/libgfs2/libgfs2.h
index c158886..47faa60 100644
--- a/gfs2/libgfs2/libgfs2.h
+++ b/gfs2/libgfs2/libgfs2.h
@@ -23,7 +23,6 @@
 #include <linux/gfs2_ondisk.h>
 #include "osi_list.h"
 #include "copyright.cf"
-#include "ondisk.h"
 
 #ifndef TRUE
 #define TRUE (1)
@@ -710,17 +709,71 @@ extern int ri_update(struct gfs2_sbd *sdp, int fd, int *rgcount);
 extern int write_sb(struct gfs2_sbd *sdp);
 
 /* ondisk.c */
-uint32_t gfs2_disk_hash(const char *data, int len);
-const char *str_uuid(const unsigned char *uuid);
-void gfs2_print_uuid(const unsigned char *uuid);
-
-extern void print_it(const char *label, const char *fmt,
-					 const char *fmt2, ...);
-#define pv(struct, member, fmt, fmt2) do {				   \
-		print_it("  "#member, fmt, fmt2, struct->member); \
-        } while (FALSE);
-#define pv2(struct, member, fmt, fmt2) do {		 \
-		print_it("  ", fmt, fmt2, struct->member);	\
-        } while (FALSE);
+extern uint32_t gfs2_disk_hash(const char *data, int len);
+extern const char *str_uuid(const unsigned char *uuid);
+extern void gfs2_print_uuid(const unsigned char *uuid);
+extern void print_it(const char *label, const char *fmt, const char *fmt2, ...)
+	__attribute__((format(printf,2,4)));
+
+/* Translation functions */
+
+extern void gfs2_inum_in(struct gfs2_inum *no, char *buf);
+extern void gfs2_inum_out(struct gfs2_inum *no, char *buf);
+extern void gfs2_meta_header_in(struct gfs2_meta_header *mh,
+				struct gfs2_buffer_head *bh);
+extern void gfs2_meta_header_out(struct gfs2_meta_header *mh,
+				 struct gfs2_buffer_head *bh);
+extern void gfs2_sb_in(struct gfs2_sb *sb, struct gfs2_buffer_head *bh);
+extern void gfs2_sb_out(struct gfs2_sb *sb, struct gfs2_buffer_head *bh);
+extern void gfs2_rindex_in(struct gfs2_rindex *ri, char *buf);
+extern void gfs2_rindex_out(struct gfs2_rindex *ri, char *buf);
+extern void gfs2_rgrp_in(struct gfs2_rgrp *rg, struct gfs2_buffer_head *bh);
+extern void gfs2_rgrp_out(struct gfs2_rgrp *rg, struct gfs2_buffer_head *bh);
+extern void gfs2_quota_in(struct gfs2_quota *qu, char *buf);
+extern void gfs2_quota_out(struct gfs2_quota *qu, char *buf);
+extern void gfs2_dinode_in(struct gfs2_dinode *di,
+			   struct gfs2_buffer_head *bh);
+extern void gfs2_dinode_out(struct gfs2_dinode *di,
+			    struct gfs2_buffer_head *bh);
+extern void gfs2_dirent_in(struct gfs2_dirent *de, char *buf);
+extern void gfs2_dirent_out(struct gfs2_dirent *de, char *buf);
+extern void gfs2_leaf_in(struct gfs2_leaf *lf, struct gfs2_buffer_head *bh);
+extern void gfs2_leaf_out(struct gfs2_leaf *lf, struct gfs2_buffer_head *bh);
+extern void gfs2_ea_header_in(struct gfs2_ea_header *ea, char *buf);
+extern void gfs2_ea_header_out(struct gfs2_ea_header *ea, char *buf);
+extern void gfs2_log_header_in(struct gfs2_log_header *lh,
+			       struct gfs2_buffer_head *bh);
+extern void gfs2_log_header_out(struct gfs2_log_header *lh,
+				struct gfs2_buffer_head *bh);
+extern void gfs2_log_descriptor_in(struct gfs2_log_descriptor *ld,
+				   struct gfs2_buffer_head *bh);
+extern void gfs2_log_descriptor_out(struct gfs2_log_descriptor *ld,
+				    struct gfs2_buffer_head *bh);
+extern void gfs2_statfs_change_in(struct gfs2_statfs_change *sc, char *buf);
+extern void gfs2_statfs_change_out(struct gfs2_statfs_change *sc, char *buf);
+extern void gfs2_quota_change_in(struct gfs2_quota_change *qc,
+				 struct gfs2_buffer_head *bh);
+extern void gfs2_quota_change_out(struct gfs2_quota_change *qc,
+				  struct gfs2_buffer_head *bh);
+
+/* Printing functions */
+
+extern void gfs2_inum_print(struct gfs2_inum *no);
+extern void gfs2_meta_header_print(struct gfs2_meta_header *mh);
+extern void gfs2_sb_print(struct gfs2_sb *sb);
+extern void gfs2_rindex_print(struct gfs2_rindex *ri);
+extern void gfs2_rgrp_print(struct gfs2_rgrp *rg);
+extern void gfs2_quota_print(struct gfs2_quota *qu);
+extern void gfs2_dinode_print(struct gfs2_dinode *di);
+extern void gfs2_dirent_print(struct gfs2_dirent *de, char *name);
+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);
+
+__END_DECLS
 
 #endif /* __LIBGFS2_DOT_H__ */
diff --git a/gfs2/libgfs2/ondisk.c b/gfs2/libgfs2/ondisk.c
index 896ec73..e41d380 100644
--- a/gfs2/libgfs2/ondisk.c
+++ b/gfs2/libgfs2/ondisk.c
@@ -23,6 +23,12 @@
 
 #include "gfs2_disk_hash.h"
 
+#define pv(struct, member, fmt, fmt2) do {                              \
+		print_it("  "#member, fmt, fmt2, struct->member);       \
+	} while (FALSE);
+#define pv2(struct, member, fmt, fmt2) do {                             \
+		print_it("  ", fmt, fmt2, struct->member);              \
+	} while (FALSE);
 
 #define CPIN_08(s1, s2, member, count) {memcpy((s1->member), (s2->member), (count));}
 #define CPOUT_08(s1, s2, member, count) {memcpy((s2->member), (s1->member), (count));}
@@ -36,11 +42,11 @@
 /*
  * gfs2_xxx_in - read in an xxx struct
  * first arg: the cpu-order structure
- * buf: the disk-order buffer
+ * bh: the disk-order buffer_head
  *
  * gfs2_xxx_out - write out an xxx struct
  * first arg: the cpu-order structure
- * buf: the disk-order buffer
+ * bh: the disk-order buffer_head
  *
  * gfs2_xxx_print - print out an xxx struct
  * first arg: the cpu-order structure
@@ -68,24 +74,27 @@ void gfs2_inum_print(struct gfs2_inum *no)
 	pv(no, no_addr, "%llu", "0x%llx");
 }
 
-void gfs2_meta_header_in(struct gfs2_meta_header *mh, char *buf)
+void gfs2_meta_header_in(struct gfs2_meta_header *mh,
+			 struct gfs2_buffer_head *bh)
 {
-	struct gfs2_meta_header *str = (struct gfs2_meta_header *)buf;
+	struct gfs2_meta_header *str = (struct gfs2_meta_header *)bh->b_data;
 
 	CPIN_32(mh, str, mh_magic);
 	CPIN_32(mh, str, mh_type);
 	CPIN_32(mh, str, mh_format);
 }
 
-void gfs2_meta_header_out(struct gfs2_meta_header *mh, char *buf)
+void gfs2_meta_header_out(struct gfs2_meta_header *mh,
+			  struct gfs2_buffer_head *bh)
 {
-	struct gfs2_meta_header *str = (struct gfs2_meta_header *)buf;
+	struct gfs2_meta_header *str = (struct gfs2_meta_header *)bh->b_data;
 
 	CPOUT_32(mh, str, mh_magic);
 	CPOUT_32(mh, str, mh_type);
 	CPOUT_32(mh, str, mh_format);
 	str->__pad0 = 0;
 	str->__pad1 = 0;
+	bmodified(bh);
 }
 
 void gfs2_meta_header_print(struct gfs2_meta_header *mh)
@@ -95,11 +104,11 @@ void gfs2_meta_header_print(struct gfs2_meta_header *mh)
 	pv(mh, mh_format, "%u", "0x%x");
 }
 
-void gfs2_sb_in(struct gfs2_sb *sb, char *buf)
+void gfs2_sb_in(struct gfs2_sb *sb, struct gfs2_buffer_head *bh)
 {
-	struct gfs2_sb *str = (struct gfs2_sb *)buf;
+	struct gfs2_sb *str = (struct gfs2_sb *)bh->b_data;
 
-	gfs2_meta_header_in(&sb->sb_header, buf);
+	gfs2_meta_header_in(&sb->sb_header, bh);
 
 	CPIN_32(sb, str, sb_fs_format);
 	CPIN_32(sb, str, sb_multihost_format);
@@ -117,11 +126,11 @@ void gfs2_sb_in(struct gfs2_sb *sb, char *buf)
 #endif
 }
 
-void gfs2_sb_out(struct gfs2_sb *sb, char *buf)
+void gfs2_sb_out(struct gfs2_sb *sb, struct gfs2_buffer_head *bh)
 {
-	struct gfs2_sb *str = (struct gfs2_sb *)buf;
+	struct gfs2_sb *str = (struct gfs2_sb *)bh->b_data;
 
-	gfs2_meta_header_out(&sb->sb_header, buf);
+	gfs2_meta_header_out(&sb->sb_header, bh);
 
 	CPOUT_32(sb, str, sb_fs_format);
 	CPOUT_32(sb, str, sb_multihost_format);
@@ -137,6 +146,7 @@ void gfs2_sb_out(struct gfs2_sb *sb, char *buf)
 #ifdef GFS2_HAS_UUID
 	CPOUT_08(sb, str, sb_uuid, sizeof(sb->sb_uuid));
 #endif
+	bmodified(bh);
 }
 
 const char *str_uuid(const unsigned char *uuid)
@@ -228,11 +238,11 @@ void gfs2_rindex_print(struct gfs2_rindex *ri)
 	pv(ri, ri_bitbytes, "%u", "0x%x");
 }
 
-void gfs2_rgrp_in(struct gfs2_rgrp *rg, char *buf)
+void gfs2_rgrp_in(struct gfs2_rgrp *rg, struct gfs2_buffer_head *bh)
 {
-	struct gfs2_rgrp *str = (struct gfs2_rgrp *)buf;
+	struct gfs2_rgrp *str = (struct gfs2_rgrp *)bh->b_data;
 
-	gfs2_meta_header_in(&rg->rg_header, buf);
+	gfs2_meta_header_in(&rg->rg_header, bh);
 	CPIN_32(rg, str, rg_flags);
 	CPIN_32(rg, str, rg_free);
 	CPIN_32(rg, str, rg_dinodes);
@@ -240,16 +250,17 @@ void gfs2_rgrp_in(struct gfs2_rgrp *rg, char *buf)
 	CPIN_08(rg, str, rg_reserved, 36);
 }
 
-void gfs2_rgrp_out(struct gfs2_rgrp *rg, char *buf)
+void gfs2_rgrp_out(struct gfs2_rgrp *rg, struct gfs2_buffer_head *bh)
 {
-	struct gfs2_rgrp *str = (struct gfs2_rgrp *)buf;
+	struct gfs2_rgrp *str = (struct gfs2_rgrp *)bh->b_data;
 
-	gfs2_meta_header_out(&rg->rg_header, buf);
+	gfs2_meta_header_out(&rg->rg_header, bh);
 	CPOUT_32(rg, str, rg_flags);
 	CPOUT_32(rg, str, rg_free);
 	CPOUT_32(rg, str, rg_dinodes);
 
 	CPOUT_08(rg, str, rg_reserved, 36);
+	bmodified(bh);
 }
 
 void gfs2_rgrp_print(struct gfs2_rgrp *rg)
@@ -267,7 +278,8 @@ void gfs2_quota_in(struct gfs2_quota *qu, char *buf)
 	CPIN_64(qu, str, qu_limit);
 	CPIN_64(qu, str, qu_warn);
 	CPIN_64(qu, str, qu_value);
-	CPIN_08(qu, str, qu_reserved, sizeof(qu->qu_reserved));
+	CPIN_32(qu, str, qu_ll_next);
+	CPIN_08(qu, str, qu_reserved, 60);
 }
 
 void gfs2_quota_out(struct gfs2_quota *qu, char *buf)
@@ -277,7 +289,8 @@ void gfs2_quota_out(struct gfs2_quota *qu, char *buf)
 	CPOUT_64(qu, str, qu_limit);
 	CPOUT_64(qu, str, qu_warn);
 	CPOUT_64(qu, str, qu_value);
-	memset(qu->qu_reserved, 0, sizeof(qu->qu_reserved));
+	CPOUT_32(qu, str, qu_ll_next);
+	CPOUT_08(qu, str, qu_reserved, 60);
 }
 
 void gfs2_quota_print(struct gfs2_quota *qu)
@@ -287,11 +300,11 @@ void gfs2_quota_print(struct gfs2_quota *qu)
 	pv(qu, qu_value, "%lld", "0x%llx");
 }
 
-void gfs2_dinode_in(struct gfs2_dinode *di, char *buf)
+void gfs2_dinode_in(struct gfs2_dinode *di, struct gfs2_buffer_head *bh)
 {
-	struct gfs2_dinode *str = (struct gfs2_dinode *)buf;
+	struct gfs2_dinode *str = (struct gfs2_dinode *)bh->b_data;
 
-	gfs2_meta_header_in(&di->di_header, buf);
+	gfs2_meta_header_in(&di->di_header, bh);
 	gfs2_inum_in(&di->di_num, (char *)&str->di_num);
 
 	CPIN_32(di, str, di_mode);
@@ -322,11 +335,11 @@ void gfs2_dinode_in(struct gfs2_dinode *di, char *buf)
 	CPIN_08(di, str, di_reserved, 32);
 }
 
-void gfs2_dinode_out(struct gfs2_dinode *di, char *buf)
+void gfs2_dinode_out(struct gfs2_dinode *di, struct gfs2_buffer_head *bh)
 {
-	struct gfs2_dinode *str = (struct gfs2_dinode *)buf;
+	struct gfs2_dinode *str = (struct gfs2_dinode *)bh->b_data;
 
-	gfs2_meta_header_out(&di->di_header, buf);
+	gfs2_meta_header_out(&di->di_header, bh);
 	gfs2_inum_out(&di->di_num, (char *)&str->di_num);
 
 	CPOUT_32(di, str, di_mode);
@@ -354,6 +367,7 @@ void gfs2_dinode_out(struct gfs2_dinode *di, char *buf)
 	CPOUT_64(di, str, di_eattr);
 
 	CPOUT_08(di, str, di_reserved, 32);
+	bmodified(bh);
 }
 
 void gfs2_dinode_print(struct gfs2_dinode *di)
@@ -424,11 +438,11 @@ void gfs2_dirent_print(struct gfs2_dirent *de, char *name)
 	print_it("  name", "%s", NULL, buf);
 }
 
-void gfs2_leaf_in(struct gfs2_leaf *lf, char *buf)
+void gfs2_leaf_in(struct gfs2_leaf *lf, struct gfs2_buffer_head *bh)
 {
-	struct gfs2_leaf *str = (struct gfs2_leaf *)buf;
+	struct gfs2_leaf *str = (struct gfs2_leaf *)bh->b_data;
 
-	gfs2_meta_header_in(&lf->lf_header, buf);
+	gfs2_meta_header_in(&lf->lf_header, bh);
 	CPIN_16(lf, str, lf_depth);
 	CPIN_16(lf, str, lf_entries);
 	CPIN_32(lf, str, lf_dirent_format);
@@ -437,17 +451,18 @@ void gfs2_leaf_in(struct gfs2_leaf *lf, char *buf)
 	CPIN_08(lf, str, lf_reserved, 32);
 }
 
-void gfs2_leaf_out(struct gfs2_leaf *lf, char *buf)
+void gfs2_leaf_out(struct gfs2_leaf *lf, struct gfs2_buffer_head *bh)
 {
-	struct gfs2_leaf *str = (struct gfs2_leaf *)buf;
+	struct gfs2_leaf *str = (struct gfs2_leaf *)bh->b_data;
 
-	gfs2_meta_header_out(&lf->lf_header, buf);
+	gfs2_meta_header_out(&lf->lf_header, bh);
 	CPOUT_16(lf, str, lf_depth);
 	CPOUT_16(lf, str, lf_entries);
 	CPOUT_32(lf, str, lf_dirent_format);
 	CPOUT_64(lf, str, lf_next);
 
 	CPOUT_08(lf, str, lf_reserved, 32);
+	bmodified(bh);
 }
 
 void gfs2_leaf_print(struct gfs2_leaf *lf)
@@ -500,11 +515,12 @@ void gfs2_ea_header_print(struct gfs2_ea_header *ea, char *name)
 	print_it("  name", "%s", NULL, buf);
 }
 
-void gfs2_log_header_in(struct gfs2_log_header *lh, char *buf)
+void gfs2_log_header_in(struct gfs2_log_header *lh,
+			struct gfs2_buffer_head *bh)
 {
-	struct gfs2_log_header *str = (struct gfs2_log_header *)buf;
+	struct gfs2_log_header *str = (struct gfs2_log_header *)bh->b_data;
 
-	gfs2_meta_header_in(&lh->lh_header, buf);
+	gfs2_meta_header_in(&lh->lh_header, bh);
 	CPIN_64(lh, str, lh_sequence);
 	CPIN_32(lh, str, lh_flags);
 	CPIN_32(lh, str, lh_tail);
@@ -512,16 +528,18 @@ void gfs2_log_header_in(struct gfs2_log_header *lh, char *buf)
 	CPIN_32(lh, str, lh_hash);
 }
 
-void gfs2_log_header_out(struct gfs2_log_header *lh, char *buf)
+void gfs2_log_header_out(struct gfs2_log_header *lh,
+			 struct gfs2_buffer_head *bh)
 {
-	struct gfs2_log_header *str = (struct gfs2_log_header *)buf;
+	struct gfs2_log_header *str = (struct gfs2_log_header *)bh->b_data;
 
-	gfs2_meta_header_out(&lh->lh_header, buf);
+	gfs2_meta_header_out(&lh->lh_header, bh);
 	CPOUT_64(lh, str, lh_sequence);
 	CPOUT_32(lh, str, lh_flags);
 	CPOUT_32(lh, str, lh_tail);
 	CPOUT_32(lh, str, lh_blkno);
 	CPOUT_32(lh, str, lh_hash);
+	bmodified(bh);
 }
 
 void gfs2_log_header_print(struct gfs2_log_header *lh)
@@ -534,11 +552,12 @@ void gfs2_log_header_print(struct gfs2_log_header *lh)
 	pv(lh, lh_hash, "0x%.8X", NULL);
 }
 
-void gfs2_log_descriptor_in(struct gfs2_log_descriptor *ld, char *buf)
+void gfs2_log_descriptor_in(struct gfs2_log_descriptor *ld,
+			    struct gfs2_buffer_head *bh)
 {
-	struct gfs2_log_descriptor *str = (struct gfs2_log_descriptor *)buf;
+	struct gfs2_log_descriptor *str = (struct gfs2_log_descriptor *)bh->b_data;
 
-	gfs2_meta_header_in(&ld->ld_header, buf);
+	gfs2_meta_header_in(&ld->ld_header, bh);
 	CPIN_32(ld, str, ld_type);
 	CPIN_32(ld, str, ld_length);
 	CPIN_32(ld, str, ld_data1);
@@ -547,17 +566,19 @@ void gfs2_log_descriptor_in(struct gfs2_log_descriptor *ld, char *buf)
 	CPIN_08(ld, str, ld_reserved, 32);
 }
 
-void gfs2_log_descriptor_out(struct gfs2_log_descriptor *ld, char *buf)
+void gfs2_log_descriptor_out(struct gfs2_log_descriptor *ld,
+			     struct gfs2_buffer_head *bh)
 {
-	struct gfs2_log_descriptor *str = (struct gfs2_log_descriptor *)buf;
+	struct gfs2_log_descriptor *str = (struct gfs2_log_descriptor *)bh->b_data;
 
-	gfs2_meta_header_out(&ld->ld_header, buf);
+	gfs2_meta_header_out(&ld->ld_header, bh);
 	CPOUT_32(ld, str, ld_type);
 	CPOUT_32(ld, str, ld_length);
 	CPOUT_32(ld, str, ld_data1);
 	CPOUT_32(ld, str, ld_data2);
 
 	CPOUT_08(ld, str, ld_reserved, 32);
+	bmodified(bh);
 }
 
 void gfs2_log_descriptor_print(struct gfs2_log_descriptor *ld)
@@ -569,28 +590,6 @@ void gfs2_log_descriptor_print(struct gfs2_log_descriptor *ld)
 	pv(ld, ld_data2, "%u", "0x%x");
 }
 
-void gfs2_inum_range_in(struct gfs2_inum_range *ir, char *buf)
-{
-	struct gfs2_inum_range *str = (struct gfs2_inum_range *)buf;
-
-	CPIN_64(ir, str, ir_start);
-	CPIN_64(ir, str, ir_length);
-}
-
-void gfs2_inum_range_out(struct gfs2_inum_range *ir, char *buf)
-{
-	struct gfs2_inum_range *str = (struct gfs2_inum_range *)buf;
-
-	CPOUT_64(ir, str, ir_start);
-	CPOUT_64(ir, str, ir_length);
-}
-
-void gfs2_inum_range_print(struct gfs2_inum_range *ir)
-{
-	pv(ir, ir_start, "%llu", "0x%llx");
-	pv(ir, ir_length, "%llu", "0x%llx");
-}
-
 void gfs2_statfs_change_in(struct gfs2_statfs_change *sc, char *buf)
 {
 	struct gfs2_statfs_change *str = (struct gfs2_statfs_change *)buf;
@@ -616,22 +615,25 @@ void gfs2_statfs_change_print(struct gfs2_statfs_change *sc)
 	pv(sc, sc_dinodes, "%lld", "0x%llx");
 }
 
-void gfs2_quota_change_in(struct gfs2_quota_change *qc, char *buf)
+void gfs2_quota_change_in(struct gfs2_quota_change *qc,
+			  struct gfs2_buffer_head *bh)
 {
-	struct gfs2_quota_change *str = (struct gfs2_quota_change *)buf;
+	struct gfs2_quota_change *str = (struct gfs2_quota_change *)bh->b_data;
 
 	CPIN_64(qc, str, qc_change);
 	CPIN_32(qc, str, qc_flags);
 	CPIN_32(qc, str, qc_id);
 }
 
-void gfs2_quota_change_out(struct gfs2_quota_change *qc, char *buf)
+void gfs2_quota_change_out(struct gfs2_quota_change *qc,
+			   struct gfs2_buffer_head *bh)
 {
-	struct gfs2_quota_change *str = (struct gfs2_quota_change *)buf;
+	struct gfs2_quota_change *str = (struct gfs2_quota_change *)bh->b_data;
 
 	CPOUT_64(qc, str, qc_change);
 	CPOUT_32(qc, str, qc_flags);
 	CPOUT_32(qc, str, qc_id);
+	bmodified(bh);
 }
 
 void gfs2_quota_change_print(struct gfs2_quota_change *qc)
diff --git a/gfs2/libgfs2/recovery.c b/gfs2/libgfs2/recovery.c
index f0f119d..f6b609d 100644
--- a/gfs2/libgfs2/recovery.c
+++ b/gfs2/libgfs2/recovery.c
@@ -75,7 +75,7 @@ int get_log_header(struct gfs2_inode *ip, unsigned int blk,
 	tmp->lh_hash = 0;
 	hash = gfs2_disk_hash(bh->b_data, sizeof(struct gfs2_log_header));
 	tmp->lh_hash = saved_hash;
-	gfs2_log_header_in(&lh, bh->b_data);
+	gfs2_log_header_in(&lh, bh);
 	brelse(bh);
 
 	if (error || lh.lh_blkno != blk || lh.lh_hash != hash)
diff --git a/gfs2/libgfs2/rgrp.c b/gfs2/libgfs2/rgrp.c
index c0f9e10..092df6b 100644
--- a/gfs2/libgfs2/rgrp.c
+++ b/gfs2/libgfs2/rgrp.c
@@ -152,7 +152,7 @@ uint64_t gfs2_rgrp_read(struct gfs2_sbd *sdp, struct rgrp_list *rgd)
 		}
 	}
 
-	gfs2_rgrp_in(&rgd->rg, rgd->bh[0]->b_data);
+	gfs2_rgrp_in(&rgd->rg, rgd->bh[0]);
 	return 0;
 }
 
diff --git a/gfs2/libgfs2/structures.c b/gfs2/libgfs2/structures.c
index 89d0e12..5e4a8c3 100644
--- a/gfs2/libgfs2/structures.c
+++ b/gfs2/libgfs2/structures.c
@@ -76,8 +76,7 @@ build_sb(struct gfs2_sbd *sdp, const unsigned char *uuid)
 	memcpy(sb.sb_uuid, uuid, sizeof(sb.sb_uuid));
 #endif
 	bh = bget(&sdp->buf_list, sdp->sb_addr);
-	gfs2_sb_out(&sb, bh->b_data);
-	bmodified(bh);
+	gfs2_sb_out(&sb, bh);
 	brelse(bh);
 
 	if (sdp->debug) {
@@ -120,11 +119,10 @@ void write_journal(struct gfs2_sbd *sdp, struct gfs2_inode *ip, unsigned int j,
 
 		lh.lh_sequence = seq;
 		lh.lh_blkno = x;
-		gfs2_log_header_out(&lh, bh->b_data);
+		gfs2_log_header_out(&lh, bh);
 		hash = gfs2_disk_hash(bh->b_data, sizeof(struct gfs2_log_header));
 		((struct gfs2_log_header *)bh->b_data)->lh_hash = cpu_to_be32(hash);
 
-		bmodified(bh);
 		brelse(bh);
 
 		if (++seq == blocks)
@@ -233,9 +231,8 @@ build_quota_change(struct gfs2_inode *per_node, unsigned int j)
 		if (!bh)
 			die("build_quota_change\n");
 
-		gfs2_meta_header_out(&mh, bh->b_data);
+		gfs2_meta_header_out(&mh, bh);
 
-		bmodified(bh);
 		brelse(bh);
 	}
 
diff --git a/gfs2/libgfs2/super.c b/gfs2/libgfs2/super.c
index debe0f6..5d05f75 100644
--- a/gfs2/libgfs2/super.c
+++ b/gfs2/libgfs2/super.c
@@ -72,7 +72,7 @@ int read_sb(struct gfs2_sbd *sdp)
 	int error;
 
 	bh = bread(&sdp->buf_list, GFS2_SB_ADDR >> sdp->sd_fsb2bb_shift);
-	gfs2_sb_in(&sdp->sd_sb, bh->b_data);
+	gfs2_sb_in(&sdp->sd_sb, bh);
 	brelse(bh);
 
 	error = check_sb(&sdp->sd_sb);
@@ -270,8 +270,7 @@ int write_sb(struct gfs2_sbd *sbp)
 	struct gfs2_buffer_head *bh;
 
 	bh = bread(&sbp->buf_list, GFS2_SB_ADDR >> sbp->sd_fsb2bb_shift);
-	gfs2_sb_out(&sbp->sd_sb, bh->b_data);
-	bmodified(bh);
+	gfs2_sb_out(&sbp->sd_sb, bh);
 	brelse(bh);
 	bcommit(&sbp->buf_list); /* make sure the change gets to disk ASAP */
 	return 0;
diff --git a/gfs2/mkfs/Makefile b/gfs2/mkfs/Makefile
index 6b1d8cd..4b894ec 100644
--- a/gfs2/mkfs/Makefile
+++ b/gfs2/mkfs/Makefile
@@ -19,7 +19,7 @@ CFLAGS=-Wall -O2 -ggdb -D_FILE_OFFSET_BITS=64 -D_LARGEFILE64_SOURCE \
        -D_GNU_SOURCE -DGFS2_RELEASE_NAME=\"2\" ${INCLUDEPATH}
 LDFLAGS=-L${top_srcdir}/libgfs2 -L${libdir}
 
-H=gfs2_disk_hash.h gfs2_mkfs.h linux_endian.h ondisk.h osi_list.h
+H=gfs2_disk_hash.h gfs2_mkfs.h linux_endian.h osi_list.h
 C=main.c main_mkfs.c main_jadd.c main_grow.c
 O=$(subst .c,.o,${C})
 
diff --git a/gfs2/mkfs/gfs2_mkfs.h b/gfs2/mkfs/gfs2_mkfs.h
index 627c018..34457f2 100644
--- a/gfs2/mkfs/gfs2_mkfs.h
+++ b/gfs2/mkfs/gfs2_mkfs.h
@@ -18,7 +18,6 @@
 #include <linux/gfs2_ondisk.h>
 #include "osi_list.h"
 #include "copyright.cf"
-#include "ondisk.h"
 
 #define SRANDOM do { srandom(time(NULL) ^ getpid()); } while (0)
 #define RESRANDOM do { srandom(RANDOM(1000000000)); } while (0)
diff --git a/gfs2/mkfs/main_jadd.c b/gfs2/mkfs/main_jadd.c
index ce47ebd..c0945d1 100644
--- a/gfs2/mkfs/main_jadd.c
+++ b/gfs2/mkfs/main_jadd.c
@@ -296,7 +296,9 @@ add_qc(struct gfs2_sbd *sdp)
 			sdp->qcsize << (20 - sdp->sd_sb.sb_bsize_shift);
 		unsigned int x;
 		struct gfs2_meta_header mh;
+		struct gfs2_buffer_head dummy_bh;
 
+		dummy_bh.b_data = buf;
 		make_jdata(fd, "clear");
 		memset(buf, 0, sdp->bsize);
 
@@ -310,7 +312,7 @@ add_qc(struct gfs2_sbd *sdp)
 		mh.mh_magic = GFS2_MAGIC;
 		mh.mh_type = GFS2_METATYPE_QC;
 		mh.mh_format = GFS2_FORMAT_QC;
-		gfs2_meta_header_out(&mh, buf);
+		gfs2_meta_header_out(&mh, &dummy_bh);
 
 		for (x=0; x<blocks; x++) {
 			do_write(fd, buf, sdp->bsize);
@@ -438,10 +440,12 @@ add_j(struct gfs2_sbd *sdp)
 
 		for (x=0; x<blocks; x++) {
 			uint32_t hash;
+			struct gfs2_buffer_head dummy_bh;
 
+			dummy_bh.b_data = buf;
 			lh.lh_sequence = seq;
 			lh.lh_blkno = x;
-			gfs2_log_header_out(&lh, buf);
+			gfs2_log_header_out(&lh, &dummy_bh);
 			hash = gfs2_disk_hash(buf, sizeof(struct gfs2_log_header));
 			((struct gfs2_log_header *)buf)->lh_hash = cpu_to_be32(hash);
 
diff --git a/gfs2/quota/main.c b/gfs2/quota/main.c
index 0136d18..7cd1b7d 100644
--- a/gfs2/quota/main.c
+++ b/gfs2/quota/main.c
@@ -291,16 +291,27 @@ read_superblock(struct gfs2_sb *sb, struct gfs2_sbd *sdp)
 {
 	int fd;
 	char buf[PATH_MAX];
-	
+	struct gfs2_buffer_head dummy_bh;
+
+	dummy_bh.b_data = buf;
 	fd = open(sdp->device_name, O_RDONLY);
 	if (fd < 0) {
 		die("Could not open the block device %s: %s\n",
 			sdp->device_name, strerror(errno));
 	}
-	do_lseek(fd, 0x10 * 4096);
-	do_read(fd, buf, PATH_MAX);
-	gfs2_sb_in(sb, buf);
+	if (lseek(fd, 0x10 * 4096, SEEK_SET) != 0x10 * 4096) {
+		fprintf(stderr, "bad seek: %s from %s:%d: "
+			"superblock\n",
+			strerror(errno), __FUNCTION__, __LINE__);
 
+		exit(-1);
+	}
+	if (read(fd, buf, PATH_MAX) != PATH_MAX) {
+		fprintf(stderr, "bad read: %s from %s:%d: superblock\n",
+			strerror(errno), __FUNCTION__, __LINE__);
+		exit(-1);
+	}
+	gfs2_sb_in(sb, &dummy_bh);
 	close(fd);
 }
 
diff --git a/gfs2/tool/sb.c b/gfs2/tool/sb.c
index 44f4443..83b24a9 100644
--- a/gfs2/tool/sb.c
+++ b/gfs2/tool/sb.c
@@ -84,7 +84,9 @@ do_sb(int argc, char **argv)
 	int fd;
 	unsigned char buf[GFS2_BASIC_BLOCK], input[256];
 	struct gfs2_sb sb;
+	struct gfs2_buffer_head dummy_bh;
 
+	dummy_bh.b_data = (char *)buf;
 	if (optind == argc)
 		die("Usage: gfs2_tool sb <device> <field> [newval]\n");
 
@@ -121,7 +123,7 @@ do_sb(int argc, char **argv)
 	do_lseek(fd, GFS2_SB_ADDR * GFS2_BASIC_BLOCK);
 	do_read(fd, buf, GFS2_BASIC_BLOCK);
 
-	gfs2_sb_in(&sb, (char*) buf);
+	gfs2_sb_in(&sb, &dummy_bh);
 
 	if (sb.sb_header.mh_magic != GFS2_MAGIC ||
 	    sb.sb_header.mh_type != GFS2_METATYPE_SB)
@@ -205,7 +207,7 @@ do_sb(int argc, char **argv)
 		die( _("unknown field %s\n"), field);
 
 	if (newval) {
-		gfs2_sb_out(&sb,(char*) buf);
+		gfs2_sb_out(&sb, &dummy_bh);
 
 		do_lseek(fd, GFS2_SB_ADDR * GFS2_BASIC_BLOCK);
 		do_write(fd, buf, GFS2_BASIC_BLOCK);