commit c6b18e82311206fb9beca7c7e33dbeed4d60c71d Author: Bob Peterson <rpeterso@redhat.com> Date: Mon Jun 15 14:59:20 2009 -0500 GFS2: gfs2_edit savemeta wasn't saving indirect eattribute blocks Normal eattribute blocks were being saved, but dinodes that had an eattribute pointer that leads to an indirect block (GFS2_METATYPE_IN) weren't being handled properly and saving off the sub-blocks. This adds that capability. rhbz#527770 diff --git a/gfs2/edit/savemeta.c b/gfs2/edit/savemeta.c index d2fca05..55e1b29 100644 --- a/gfs2/edit/savemeta.c +++ b/gfs2/edit/savemeta.c @@ -303,6 +303,35 @@ void save_indirect_blocks(int out_fd, osi_list_t *cur_list, } /* + * save_ea_block - save off an extended attribute block + */ +void save_ea_block(int out_fd, struct gfs2_buffer_head *metabh) +{ + int i, e, ea_len = sbd.bsize; + struct gfs2_ea_header ea; + + for (e = sizeof(struct gfs2_meta_header); e < sbd.bsize; e += ea_len) { + uint64_t blk, *b; + int charoff; + + gfs2_ea_header_in(&ea, metabh->b_data + e); + for (i = 0; i < ea.ea_num_ptrs; i++) { + charoff = e + ea.ea_name_len + + sizeof(struct gfs2_ea_header) + + sizeof(uint64_t) - 1; + charoff /= sizeof(uint64_t); + b = (uint64_t *)(metabh->b_data); + b += charoff + i; + blk = be64_to_cpu(*b); + save_block(sbd.device_fd, out_fd, blk); + } + if (!ea.ea_rec_len) + break; + ea_len = ea.ea_rec_len; + } +} + +/* * save_inode_data - save off important data associated with an inode * * out_fd - destination file descriptor @@ -371,36 +400,27 @@ void save_inode_data(int out_fd) } } if (inode->i_di.di_eattr) { /* if this inode has extended attributes */ - struct gfs2_ea_header ea; struct gfs2_meta_header mh; - int e; metabh = 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); - if (mh.mh_magic == GFS2_MAGIC) { - for (e = sizeof(struct gfs2_meta_header); - e < sbd.bsize; e += ea.ea_rec_len) { - uint64_t blk, *b; - int charoff; - - gfs2_ea_header_in(&ea, metabh->b_data + e); - for (i = 0; i < ea.ea_num_ptrs; i++) { - charoff = e + ea.ea_name_len + - sizeof(struct gfs2_ea_header) + - sizeof(uint64_t) - 1; - charoff /= sizeof(uint64_t); - b = (uint64_t *)(metabh->b_data); - b += charoff + i; - blk = be64_to_cpu(*b); - save_block(sbd.device_fd, out_fd, blk); - } - if (!ea.ea_rec_len) - break; - } - } else { - fprintf(stderr, "\nWarning: corrupt extended attribute" - " at block %llu (0x%llx) detected.\n", + if (mh.mh_magic == GFS2_MAGIC && + mh.mh_type == GFS2_METATYPE_EA) + save_ea_block(out_fd, metabh); + else if (mh.mh_magic == GFS2_MAGIC && + mh.mh_type == GFS2_METATYPE_IN) + save_indirect_blocks(out_fd, cur_list, metabh, 2, 2); + else { + if (mh.mh_magic == GFS2_MAGIC) /* if it's metadata */ + save_block(sbd.device_fd, out_fd, + inode->i_di.di_eattr); + fprintf(stderr, + "\nWarning: corrupt extended " + "attribute at block %llu (0x%llx) " + "detected in inode %lld (0x%llx).\n", + (unsigned long long)inode->i_di.di_eattr, + (unsigned long long)inode->i_di.di_eattr, (unsigned long long)block, (unsigned long long)block); }