gfs2-utils: master - gfs2_edit: handle corrupt file systems better
Bob Peterson
rpeterso at fedoraproject.org
Thu Feb 3 17:09:42 UTC 2011
Gitweb: http://git.fedorahosted.org/git/gfs2-utils.git?p=gfs2-utils.git;a=commitdiff;h=5c35d4c605b171c8e431990ac137816ac65f2b0f
Commit: 5c35d4c605b171c8e431990ac137816ac65f2b0f
Parent: d8c8af9612e2e00b8d8739a3d72ca9669a593878
Author: Bob Peterson <rpeterso at redhat.com>
AuthorDate: Wed Feb 2 15:49:22 2011 -0600
Committer: Bob Peterson <rpeterso at redhat.com>
CommitterDate: 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#656371
---
gfs2/edit/hexedit.c | 10 ++++++----
gfs2/libgfs2/fs_bits.c | 2 ++
gfs2/libgfs2/rgrp.c | 5 +++--
3 files changed, 11 insertions(+), 6 deletions(-)
diff --git a/gfs2/edit/hexedit.c b/gfs2/edit/hexedit.c
index 2472bbf..cdcdecd 100644
--- a/gfs2/edit/hexedit.c
+++ b/gfs2/edit/hexedit.c
@@ -1793,11 +1793,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 (%llu bytes)\n",
diff --git a/gfs2/libgfs2/fs_bits.c b/gfs2/libgfs2/fs_bits.c
index 6f096f3..7d37d57 100644
--- a/gfs2/libgfs2/fs_bits.c
+++ b/gfs2/libgfs2/fs_bits.c
@@ -232,6 +232,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 2a6fa3f..2ec55b5 100644
--- a/gfs2/libgfs2/rgrp.c
+++ b/gfs2/libgfs2/rgrp.c
@@ -169,8 +169,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;
}
}
More information about the cluster-commits
mailing list