Commit 7776ec1d authored by Tigerly's avatar Tigerly
Browse files

read redundant super block

parent 9cc957f2
......@@ -422,10 +422,21 @@ static void do_write_bd(struct ext4_group_desc *buf, FILE *fd) {
fprintf(fd," reserved %u \n",buf->bg_reserved);
}
static void do_write_sb (struct ext2_super_block *sb, FILE *fd) {
// now just use the existing function
// will modify it and add more features we needed.
list_super2(sb, fd);
static void do_write_sb(struct ext2_super_block *sb, FILE *fd, int redundant) {
if (redundant == 0) {
fprintf(fd, "**********************\n");
fprintf(fd, "*original super block*\n");
fprintf(fd, "**********************\n");
list_super2(sb, fd);
} else if (redundant == 1) {
fprintf(fd, "***********************\n");
fprintf(fd, "*redundant super block*\n");
fprintf(fd, "***********************\n");
list_super2(sb, fd);
}
}
static void do_write_inode(struct ext2_inode *inode, FILE *fd) {
......@@ -597,8 +608,22 @@ void do_analyze_meta_data(int argc, char *argv[]) {
*/
}
else if(sb_loop){
// write super block
do_write_sb ((struct ext2_super_block *)buf, nfd);
printf("lSize = %d", lSize);
if (lSize < 1024) {
fputs("super block size shouldn't < 1024 KB", stderr);
exit(2);
}
// write original super block
do_write_sb ((struct ext2_super_block *)buf, nfd, 0);
int *next_buf;
for(int i = 0; i < lSize/1024; i++){
// write redundant super blocks
next_buf = buf + 1024;
do_write_sb ((struct ext2_super_block *) next_buf, nfd, 1);
}
}
else if(journal_loop){
// write journal
......@@ -707,7 +732,9 @@ void do_extract_meta_data(int argc, char *argv[])
fp = fopen(suffix, "wb");
fwrite(desc, sizeof(struct ext4_group_desc), 1, fp);
//fwrite(desc, sizeof(struct ext4_group_desc), 1, fp);
//if after 32 bytes then ignore
fwrite(desc, sizeof(struct ext4_group_desc) / 2, 1, fp);
fclose(fp);
......
......@@ -422,10 +422,21 @@ static void do_write_bd(struct ext4_group_desc *buf, FILE *fd) {
fprintf(fd," reserved %u \n",buf->bg_reserved);
}
static void do_write_sb (struct ext2_super_block *sb, FILE *fd) {
// now just use the existing function
// will modify it and add more features we needed.
list_super2(sb, fd);
static void do_write_sb(struct ext2_super_block *sb, FILE *fd, int redundant) {
if (redundant == 0) {
fprintf(fd, "**********************\n");
fprintf(fd, "*original super block*\n");
fprintf(fd, "**********************\n");
list_super2(sb, fd);
} else if (redundant == 1) {
fprintf(fd, "***********************\n");
fprintf(fd, "*redundant super block*\n");
fprintf(fd, "***********************\n");
list_super2(sb, fd);
}
}
static void do_write_inode(struct ext2_inode *inode, FILE *fd) {
......@@ -597,8 +608,22 @@ void do_analyze_meta_data(int argc, char *argv[]) {
*/
}
else if(sb_loop){
// write super block
do_write_sb ((struct ext2_super_block *)buf, nfd);
printf("lSize = %d", lSize);
if (lSize < 1024) {
fputs("super block size shouldn't < 1024 KB", stderr);
exit(2);
}
// write original super block
do_write_sb ((struct ext2_super_block *)buf, nfd, 0);
int *next_buf;
for(int i = 0; i < lSize/1024; i++){
// write redundant super blocks
next_buf = buf + 1024;
do_write_sb ((struct ext2_super_block *) next_buf, nfd, 1);
}
}
else if(journal_loop){
// write journal
......@@ -707,7 +732,9 @@ void do_extract_meta_data(int argc, char *argv[])
fp = fopen(suffix, "wb");
fwrite(desc, sizeof(struct ext4_group_desc), 1, fp);
//fwrite(desc, sizeof(struct ext4_group_desc), 1, fp);
//if after 32 bytes then ignore
fwrite(desc, sizeof(struct ext4_group_desc) / 2, 1, fp);
fclose(fp);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment