Commit 847b6bed authored by root's avatar root
Browse files

remove reserved GDT, file hierarchy

parent 5c4fce24
No preview for this file type
......@@ -73,7 +73,7 @@ static int extractmd_ioctl(struct inode *inode, struct file *f, struct extractmd
char path_block_bitmap[255] = {0};
char path_inode_bitmap[255] = {0};
char path_inode_table[255] = {0};
char path_reserved_gdt[255] = {0};
//char path_reserved_gdt[255] = {0};
char path_journal[255] = {0};
int i = 0;
......@@ -95,13 +95,13 @@ static int extractmd_ioctl(struct inode *inode, struct file *f, struct extractmd
nr_journal_blocks = be32_to_cpu(sbi->s_journal->j_superblock->s_maxlen);
/* set path and filenames */
sprintf(path_super_block, "%s/super_block", p->path);
sprintf(path_group_descriptor, "%s/group_descriptor", p->path);
sprintf(path_block_bitmap, "%s/block_bitmap", p->path);
sprintf(path_inode_bitmap, "%s/inode_bitmap", p->path);
sprintf(path_inode_table, "%s/inode_table", p->path);
sprintf(path_reserved_gdt, "%s/reserved_GDT", p->path);
sprintf(path_journal, "%s/journal", p->path);
sprintf(path_super_block, "%s/sb/sb", p->path);
sprintf(path_group_descriptor, "%s/bd/bd", p->path);
sprintf(path_block_bitmap, "%s/bd/bbitmap", p->path);
sprintf(path_inode_bitmap, "%s/bd/ibitmap", p->path);
sprintf(path_inode_table, "%s/bd/itable", p->path);
//sprintf(path_reserved_gdt, "%s/reserved_GDT", p->path);
sprintf(path_journal, "%s/journal/journal", p->path);
/* sync */
freeze_super(sb);
......@@ -114,7 +114,7 @@ static int extractmd_ioctl(struct inode *inode, struct file *f, struct extractmd
/* super block in Group 0 */
bh_sb = __bread(bdev, 0, EXT4_BLOCK_SIZE(sb));
extractmd_write_file(path_super_block, bh_sb->b_data, EXT4_BLOCK_SIZE(sb));
extractmd_write_file_per_group(path_super_block, bh_sb->b_data, EXT4_BLOCK_SIZE(sb), 0);
//extractmd_write_file_per_group(path_super_block, bh_sb->b_data, EXT4_BLOCK_SIZE(sb), 0);
/* sparse super block v2? */
if((sbi->s_es->s_feature_compat & 0x200) == 1)
......@@ -124,8 +124,8 @@ static int extractmd_ioctl(struct inode *inode, struct file *f, struct extractmd
bh_redundant_sb1 = __bread(bdev, extractmd_group_first_block_no(sb, sbi->s_es->s_backup_bgs[0]), EXT4_BLOCK_SIZE(sb));
bh_redundant_sb2 = __bread(bdev, extractmd_group_first_block_no(sb, sbi->s_es->s_backup_bgs[1]), EXT4_BLOCK_SIZE(sb));
extractmd_write_file_per_group(path_super_block, bh_redundant_sb1->b_data, EXT4_BLOCK_SIZE(sb), 1);
extractmd_write_file_per_group(path_super_block, bh_redundant_sb2->b_data, EXT4_BLOCK_SIZE(sb), 2);
extractmd_append_file(path_super_block, bh_redundant_sb1->b_data, EXT4_BLOCK_SIZE(sb));
extractmd_append_file(path_super_block, bh_redundant_sb2->b_data, EXT4_BLOCK_SIZE(sb));
}
/* sparse super block? Yes -> then sb in group 0 or a power of 3, 5, or 7 */
......@@ -138,20 +138,20 @@ static int extractmd_ioctl(struct inode *inode, struct file *f, struct extractmd
for (x = 1; extractmd_pow(3,x) < nr_group; x++)
{
bh_redundant_sb = __bread(bdev, extractmd_group_first_block_no(sb,extractmd_pow(3,x)), EXT4_BLOCK_SIZE(sb));
extractmd_write_file_per_group(path_super_block, bh_redundant_sb->b_data, EXT4_BLOCK_SIZE(sb),extractmd_pow(3,x));
extractmd_append_file(path_super_block, bh_redundant_sb->b_data, EXT4_BLOCK_SIZE(sb));
}
for (y = 1; extractmd_pow(5,y) < nr_group; y++)
{
bh_redundant_sb = __bread(bdev, extractmd_group_first_block_no(sb,extractmd_pow(5,y)), EXT4_BLOCK_SIZE(sb));
extractmd_write_file_per_group(path_super_block, bh_redundant_sb->b_data, EXT4_BLOCK_SIZE(sb),extractmd_pow(5,y));
extractmd_append_file(path_super_block, bh_redundant_sb->b_data, EXT4_BLOCK_SIZE(sb));
}
for (z = 1; extractmd_pow(7,z) < nr_group; z++)
{
bh_redundant_sb = __bread(bdev, extractmd_group_first_block_no(sb,extractmd_pow(7,z)), EXT4_BLOCK_SIZE(sb));
extractmd_write_file_per_group(path_super_block, bh_redundant_sb->b_data, EXT4_BLOCK_SIZE(sb),extractmd_pow(7,z));
extractmd_append_file(path_super_block, bh_redundant_sb->b_data, EXT4_BLOCK_SIZE(sb));
}
}
......@@ -164,7 +164,7 @@ static int extractmd_ioctl(struct inode *inode, struct file *f, struct extractmd
for (k = 1; k < nr_group; k++)
{
bh_redundant_sb = __bread(bdev, extractmd_group_first_block_no(sb, k), EXT4_BLOCK_SIZE(sb));
extractmd_write_file_per_group(path_super_block, bh_redundant_sb->b_data, EXT4_BLOCK_SIZE(sb), k);
extractmd_append_file(path_super_block, bh_redundant_sb->b_data, EXT4_BLOCK_SIZE(sb));
}
}
......@@ -192,7 +192,7 @@ static int extractmd_ioctl(struct inode *inode, struct file *f, struct extractmd
extractmd_write_file_per_group(path_inode_table , buffer_inode_table, EXT4_BLOCK_SIZE(sb) * nr_inode_table_block, i);
}
/* reserved GDT, if not flexible block group, extract reserved GDT */
/* reserved GDT, if not flexible block group, extract reserved GDT
if ((sbi->s_es->s_feature_incompat & 0x200) != 0x200)
{
unsigned long nr_reserved_gdt = sbi->s_es->s_reserved_gdt_blocks;
......@@ -201,7 +201,7 @@ static int extractmd_ioctl(struct inode *inode, struct file *f, struct extractmd
struct buffer_head *bh_reserved_gdt = __bread(bdev, extractmd_group_first_block_no(sb, i) + 2, EXT4_BLOCK_SIZE(sb) * nr_reserved_gdt);
extractmd_write_file_per_group(path_reserved_gdt, bh_reserved_gdt->b_data, EXT4_BLOCK_SIZE(sb) * nr_reserved_gdt, i);
}
}
} */
/* journal */
for(j = 0; j < nr_journal_blocks; j++)
......@@ -280,13 +280,15 @@ static int device_release(struct inode *inode, struct file *file)
long extractmd_write_file(char *path, char *data, unsigned long size)
{
long ret;
char filename[255] = {0};
struct file *fp;
mm_segment_t fs;
fs = get_fs();
set_fs(KERNEL_DS);
fp = filp_open(path, O_WRONLY | O_CREAT, 0777);
sprintf(filename, "%s.bin", path);
fp = filp_open(filename, O_WRONLY | O_CREAT, 0777);
ret = vfs_write(fp, data, size, &fp->f_pos);
set_fs(fs);
......@@ -304,7 +306,7 @@ long extractmd_write_file_per_group(char *path, char *data, unsigned long size,
fs = get_fs();
set_fs(KERNEL_DS);
sprintf(filename, "%s%d", path, num);
sprintf(filename, "%s%d.bin", path, num);
fp = filp_open(filename, O_WRONLY | O_CREAT, 0777);
ret = vfs_write(fp, data, size, &fp->f_pos);
......@@ -316,13 +318,15 @@ long extractmd_write_file_per_group(char *path, char *data, unsigned long size,
long extractmd_append_file(char *path, char* data, unsigned long size)
{
long ret;
char filename[255] = {0};
struct file *fp;
mm_segment_t fs;
fs = get_fs();
set_fs(KERNEL_DS);
fp = filp_open(path, O_WRONLY | O_APPEND | O_CREAT, 0777);
sprintf(filename, "%s.bin", path);
fp = filp_open(filename, O_WRONLY | O_APPEND | O_CREAT, 0777);
ret = vfs_write(fp, data, size, &fp->f_pos);
set_fs(fs);
......@@ -335,4 +339,4 @@ module_exit(cleanup_extractmd);
MODULE_LICENSE("GPL");
MODULE_AUTHOR("Mincheol Sung <mincheol@vt.edu>");
MODULE_DESCRIPTION("Extract meta data of EXT4 from the device and write it on files.");
\ No newline at end of file
MODULE_DESCRIPTION("Extract meta data of EXT4 from the device and write it on files.");
No preview for this file type
No preview for this file type
......@@ -12,7 +12,7 @@ int main()
struct extractmd_path p;
p.path_device = "/dev/sdb";
p.path_mount_point = "/mnt";
p.path = "/home/user/md";
p.path = "/home/user/sdb";
ioctl(fd,&p);
......
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