LogoopenSUSE Build Service > Projects
Sign Up | Log In

View File gfs2_edit_handle_corrupt_filesystems_better.patch of Package cluster (Project home:sschapiro:openstack:upstream)

commit 4cb8599397ca7a519e5b95b76824536b8c4b6e33
Author: Bob Peterson <rpeterso@redhat.com>
Date:   Wed Feb 2 15:49:22 2011 -0600

    gfs2_edit: handle corrupt file systems better
    
    This patch adds some checks to gfs2_edit so that it will not segfault
    when it encounters certain types of file system corruption.  This makes
    it a more useful tool for examining corrupt metadata sets.
    
    rhbz#674843

diff --git a/gfs2/edit/hexedit.c b/gfs2/edit/hexedit.c
index d900c93..467885e 100644
--- a/gfs2/edit/hexedit.c
+++ b/gfs2/edit/hexedit.c
@@ -1792,11 +1792,13 @@ static void read_superblock(int fd)
 	sbd.bsize = sbd.sd_sb.sb_bsize;
 	if (!sbd.bsize)
 		sbd.bsize = GFS2_DEFAULT_BSIZE;
-	if (compute_constants(&sbd)) {
-		fprintf(stderr, "Bad constants (1)\n");
-		exit(-1);
+	compute_constants(&sbd);
+	if (gfs1 || (sbd.sd_sb.sb_header.mh_magic == GFS2_MAGIC &&
+		     sbd.sd_sb.sb_header.mh_type == GFS2_METATYPE_SB))
+		block = 0x10 * (GFS2_DEFAULT_BSIZE / sbd.bsize);
+	else {
+		block = starting_blk = 0;
 	}
-	block = 0x10 * (GFS2_DEFAULT_BSIZE / sbd.bsize);
 	device_geometry(&sbd);
 	if (fix_device_geometry(&sbd)) {
 		fprintf(stderr, "Device is too small (%"PRIu64" bytes)\n",
diff --git a/gfs2/libgfs2/fs_bits.c b/gfs2/libgfs2/fs_bits.c
index c2934a6..7409bed 100644
--- a/gfs2/libgfs2/fs_bits.c
+++ b/gfs2/libgfs2/fs_bits.c
@@ -230,6 +230,8 @@ int gfs2_get_bitmap(struct gfs2_sbd *sdp, uint64_t blkno,
 
 	if (i >= rgd->ri.ri_length)
 		return -1;
+	if (!rgd->bh || !rgd->bh[i])
+		return 0;
 	byte = (unsigned char *)(rgd->bh[i]->b_data + bits->bi_offset) +
 		(rgrp_block/GFS2_NBBY - bits->bi_start);
 	bit = (rgrp_block % GFS2_NBBY) * GFS2_BIT_SIZE;
diff --git a/gfs2/libgfs2/rgrp.c b/gfs2/libgfs2/rgrp.c
index b35c241..0f34e33 100644
--- a/gfs2/libgfs2/rgrp.c
+++ b/gfs2/libgfs2/rgrp.c
@@ -167,8 +167,9 @@ void gfs2_rgrp_relse(struct rgrp_list *rgd)
 	int x, length = rgd->ri.ri_length;
 
 	for (x = 0; x < length; x++) {
-		if (rgd->bh && rgd->bh[x]) {
-			brelse(rgd->bh[x]);
+		if (rgd->bh) {
+			if (rgd->bh[x])
+				brelse(rgd->bh[x]);
 			rgd->bh[x] = NULL;
 		}
 	}