Commit 5c4fce24 authored by root's avatar root
Browse files

Now can extract reserved GDT, journal

parent 8686b96f
11/27/2016 v4.0
Now can extract reserved GDT, journal
How to use?
#make // compile the module
#insmod extractmd.ko // load the module
#./a.out // trigger extraction
#rmmod extractmd // this will unload the module
Look test.c and specify target device, and the path where to store files.
For journal, the module append data on a file. So, never mind journal.
11/25/2016 v3.0
Specifiy path : 1.mount point(e.q., "/mnt"), 2.target device(e.q., "/dev/sdb"), 3.where to store extracted meta data(e.q., "/home/user/md").
Specify path : 1.mount point(e.q., "/mnt"), 2.target device(e.q., "/dev/sdb"), 3.where to store extracted meta data(e.q., "/home/user/md").
Example code : test.c
11/15/2016 v2.0
......
......@@ -27,7 +27,8 @@ ext4_fsblk_t extractmd_inode_table(struct super_block *, struct ext4_group_desc
ext4_fsblk_t extractmd_inode_bitmap(struct super_block *, struct ext4_group_desc *);
long extractmd_write_file(char *, char *, unsigned long);
long extractmd_write_file_per_group(char *, char*, unsigned long, int);
long extractmd_write_file_per_group(char *, char *, unsigned long, int);
long extractmd_append_file(char *, char *, unsigned long);
#define DEVICE_NAME "extractmd" /* Dev name as it appears in /proc/devices */
#define MAJOR_NUM 199 /* Device MAJOR number */
......@@ -73,12 +74,16 @@ static int extractmd_ioctl(struct inode *inode, struct file *f, struct extractmd
char path_inode_bitmap[255] = {0};
char path_inode_table[255] = {0};
char path_reserved_gdt[255] = {0};
char path_journal[255] = {0};
int i = 0;
int j = 0;
unsigned long nr_gd; // number of groupd descriptors
unsigned long nr_inode_table_block; // number of inode table blocks
unsigned long nr_journal_blocks; // number of blocks in journal device.
struct buffer_head *bh_sb;
struct buffer_head *bh_journal;
struct super_block *sb = fp->f_inode->i_sb; // get super_block of vfs
//struct super_block *sb = fp->f_path.mnt->mnt_sb;
struct ext4_sb_info *sbi = EXT4_SB(sb); // get ext4_sb_info
......@@ -87,6 +92,7 @@ static int extractmd_ioctl(struct inode *inode, struct file *f, struct extractmd
bdev = I_BDEV(fp_dev->f_mapping->host);
nr_gd = sbi->s_gdb_count * sbi->s_desc_per_block;
nr_inode_table_block = sbi->s_itb_per_group;
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);
......@@ -95,6 +101,7 @@ static int extractmd_ioctl(struct inode *inode, struct file *f, struct extractmd
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);
/* sync */
freeze_super(sb);
......@@ -165,16 +172,24 @@ static int extractmd_ioctl(struct inode *inode, struct file *f, struct extractmd
/* group descriptors, bit maps, inode tables */
for(i = 0; i < nr_group; i++)
{
int h;
char *buffer_inode_table = kmalloc(EXT4_BLOCK_SIZE(sb) * nr_inode_table_block, GFP_KERNEL);
struct ext4_group_desc *group = extractmd_get_group_desc(sb, i);
struct buffer_head *bh_group_descriptor = __bread(bdev, extractmd_group_first_block_no(sb, i) + 1, EXT4_DESC_SIZE(sb) * nr_gd);
struct buffer_head *bh_block_bitmap = __bread(bdev, extractmd_block_bitmap(sb, group), EXT4_BLOCK_SIZE(sb));
struct buffer_head *bh_inode_bitmap = __bread(bdev, extractmd_inode_bitmap(sb, group), EXT4_BLOCK_SIZE(sb));
struct buffer_head *bh_inode_table = __bread(bdev, extractmd_inode_table(sb, group), EXT4_BLOCK_SIZE(sb) * nr_inode_table_block);
extractmd_write_file_per_group(path_group_descriptor, bh_group_descriptor->b_data, EXT4_DESC_SIZE(sb) * nr_gd, i);
extractmd_write_file_per_group(path_block_bitmap, bh_block_bitmap->b_data, EXT4_BLOCK_SIZE(sb), i);
extractmd_write_file_per_group(path_inode_bitmap, bh_inode_bitmap->b_data, EXT4_BLOCK_SIZE(sb), i);
extractmd_write_file_per_group(path_inode_table , bh_inode_table->b_data, EXT4_BLOCK_SIZE(sb) * nr_inode_table_block, i);
for (h = 0; h < nr_inode_table_block; h++)
{
struct buffer_head *bh_inode_table = __bread(bdev, extractmd_inode_table(sb, group) + h, EXT4_BLOCK_SIZE(sb));
memcpy(buffer_inode_table + EXT4_BLOCK_SIZE(sb) * h, bh_inode_table->b_data, EXT4_BLOCK_SIZE(sb));
}
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 */
......@@ -189,29 +204,12 @@ static int extractmd_ioctl(struct inode *inode, struct file *f, struct extractmd
}
/* journal */
/*
* external journal : On the journal device there will be an ext4 super block in the usual place, with a matching UUID.
* this module extracts uuid of the journal devices and write them on a file name "external_journal".
*/
if ((sbi->s_es->s_journal_inum | 0x0) == 0x0)
for(j = 0; j < nr_journal_blocks; j++)
{
int u;
unsigned long j_buff[16];
char path_external_journal[255] = {0};
sprintf(path_external_journal, "%s/external_journal", p->path);
for (u = 0; u < 16; u ++)
j_buff[u] = sbi->s_es->s_journal_uuid[u];
extractmd_write_file(path_external_journal, (char *)j_buff, sizeof(unsigned long) * 16);
bh_journal = __bread(sbi->s_journal->j_dev, j, EXT4_BLOCK_SIZE(sb));
extractmd_append_file(path_journal, bh_journal->b_data, EXT4_BLOCK_SIZE(sb));
}
filp_close(fp, NULL);
filp_close(fp_dev, NULL);
......@@ -279,7 +277,7 @@ static int device_release(struct inode *inode, struct file *file)
}
long extractmd_write_file(char *path, char* data, unsigned long size)
long extractmd_write_file(char *path, char *data, unsigned long size)
{
long ret;
struct file *fp;
......@@ -296,7 +294,7 @@ long extractmd_write_file(char *path, char* data, unsigned long size)
return ret;
}
long extractmd_write_file_per_group(char * path, char* data, unsigned long size, int num)
long extractmd_write_file_per_group(char *path, char *data, unsigned long size, int num)
{
long ret;
char filename[255] = {0};
......@@ -324,7 +322,7 @@ long extractmd_append_file(char *path, char* data, unsigned long size)
fs = get_fs();
set_fs(KERNEL_DS);
fp = filp_open(path, O_APPEND | O_CREAT, 0777);
fp = filp_open(path, O_WRONLY | O_APPEND | O_CREAT, 0777);
ret = vfs_write(fp, data, size, &fp->f_pos);
set_fs(fs);
......@@ -332,8 +330,6 @@ long extractmd_append_file(char *path, char* data, unsigned long size)
return ret;
}
module_init(init_extractmd);
module_exit(cleanup_extractmd);
......
No preview for this file type
No preview for this file type
No preview for this file type
......@@ -19,149 +19,151 @@ int main()
sb = (struct extractmd_super_block *)buffer;
printf("META_BG: %lu\n",sb->s_feature_incompat & 0x10);
printf("s_first_meta_bg : %lu\n",sb->s_first_meta_bg);
printf("s_inodes_count : %lu\n",sb->s_inodes_count);
printf("s_blocks_count_lo : %lu\n",sb->s_blocks_count_lo);
printf("s_r_blocks_count_lo : %lu\n",sb->s_r_blocks_count_lo);
printf("s_free_blocks_count_lo : %lu\n",sb->s_free_blocks_count_lo);
printf("s_free_inodes_count : %lu\n",sb->s_free_inodes_count);
printf("s_first_data_block : %lu\n",sb->s_first_data_block);
// printf("s_inodes_count : %lu\n",sb->s_inodes_count);
// printf("s_blocks_count_lo : %lu\n",sb->s_blocks_count_lo);
// printf("s_r_blocks_count_lo : %lu\n",sb->s_r_blocks_count_lo);
// printf("s_free_blocks_count_lo : %lu\n",sb->s_free_blocks_count_lo);
// printf("s_free_inodes_count : %lu\n",sb->s_free_inodes_count);
// printf("s_first_data_block : %lu\n",sb->s_first_data_block);
fclose(fp);
fp = fopen("/home/user/md/super_block0", "r");
fread(buffer, 4096, 1, (FILE*)fp);
// fp = fopen("/home/user/md/super_block0", "r");
// fread(buffer, 4096, 1, (FILE*)fp);
sb2 = (struct extractmd_super_block *)buffer;
// sb2 = (struct extractmd_super_block *)buffer;
printf("s_inodes_count : %lu\n",sb2->s_inodes_count);
printf("s_blocks_count_lo : %lu\n",sb2->s_blocks_count_lo);
printf("s_r_blocks_count_lo : %lu\n",sb2->s_r_blocks_count_lo);
printf("s_free_blocks_count_lo : %lu\n",sb2->s_free_blocks_count_lo);
printf("s_free_inodes_count : %lu\n",sb2->s_free_inodes_count);
printf("s_first_data_block : %lu\n",sb2->s_first_data_block);
// printf("s_inodes_count : %lu\n",sb2->s_inodes_count);
// printf("s_blocks_count_lo : %lu\n",sb2->s_blocks_count_lo);
// printf("s_r_blocks_count_lo : %lu\n",sb2->s_r_blocks_count_lo);
// printf("s_free_blocks_count_lo : %lu\n",sb2->s_free_blocks_count_lo);
// printf("s_free_inodes_count : %lu\n",sb2->s_free_inodes_count);
// printf("s_first_data_block : %lu\n",sb2->s_first_data_block);
fclose(fp);
// fclose(fp);
fp = fopen("/home/user/md/super_block25", "r");
fread(buffer, 4096, 1, (FILE*)fp);
// fp = fopen("/home/user/md/super_block25", "r");
// fread(buffer, 4096, 1, (FILE*)fp);
rsb = (struct extractmd_redundant_super_block *)buffer;
// rsb = (struct extractmd_redundant_super_block *)buffer;
printf("s_inodes_count : %lu\n",rsb->s_inodes_count);
printf("s_blocks_count_lo : %lu\n",rsb->s_blocks_count_lo);
printf("s_r_blocks_count_lo : %lu\n",rsb->s_r_blocks_count_lo);
printf("s_free_blocks_count_lo : %lu\n",rsb->s_free_blocks_count_lo);
printf("s_free_inodes_count : %lu\n",rsb->s_free_inodes_count);
printf("s_first_data_block : %lu\n",rsb->s_first_data_block);
// printf("s_inodes_count : %lu\n",rsb->s_inodes_count);
// printf("s_blocks_count_lo : %lu\n",rsb->s_blocks_count_lo);
// printf("s_r_blocks_count_lo : %lu\n",rsb->s_r_blocks_count_lo);
// printf("s_free_blocks_count_lo : %lu\n",rsb->s_free_blocks_count_lo);
// printf("s_free_inodes_count : %lu\n",rsb->s_free_inodes_count);
// printf("s_first_data_block : %lu\n",rsb->s_first_data_block);
fclose(fp);
// fclose(fp);
fp = fopen("/home/user/md/super_block27", "r");
fread(buffer, 4096, 1, (FILE*)fp);
// fp = fopen("/home/user/md/super_block27", "r");
// fread(buffer, 4096, 1, (FILE*)fp);
rsb = (struct extractmd_redundant_super_block *)buffer;
// rsb = (struct extractmd_redundant_super_block *)buffer;
printf("s_inodes_count : %lu\n",rsb->s_inodes_count);
printf("s_blocks_count_lo : %lu\n",rsb->s_blocks_count_lo);
printf("s_r_blocks_count_lo : %lu\n",rsb->s_r_blocks_count_lo);
printf("s_free_blocks_count_lo : %lu\n",rsb->s_free_blocks_count_lo);
printf("s_free_inodes_count : %lu\n",rsb->s_free_inodes_count);
printf("s_first_data_block : %lu\n",rsb->s_first_data_block);
// printf("s_inodes_count : %lu\n",rsb->s_inodes_count);
// printf("s_blocks_count_lo : %lu\n",rsb->s_blocks_count_lo);
// printf("s_r_blocks_count_lo : %lu\n",rsb->s_r_blocks_count_lo);
// printf("s_free_blocks_count_lo : %lu\n",rsb->s_free_blocks_count_lo);
// printf("s_free_inodes_count : %lu\n",rsb->s_free_inodes_count);
// printf("s_first_data_block : %lu\n",rsb->s_first_data_block);
fclose(fp);
// fclose(fp);
fp = fopen("/home/user/md/super_block3", "r");
fread(buffer, 4096, 1, (FILE*)fp);
// fp = fopen("/home/user/md/super_block3", "r");
// fread(buffer, 4096, 1, (FILE*)fp);
rsb = (struct extractmd_redundant_super_block *)buffer;
// rsb = (struct extractmd_redundant_super_block *)buffer;
printf("s_inodes_count : %lu\n",rsb->s_inodes_count);
printf("s_blocks_count_lo : %lu\n",rsb->s_blocks_count_lo);
printf("s_r_blocks_count_lo : %lu\n",rsb->s_r_blocks_count_lo);
printf("s_free_blocks_count_lo : %lu\n",rsb->s_free_blocks_count_lo);
printf("s_free_inodes_count : %lu\n",rsb->s_free_inodes_count);
printf("s_first_data_block : %lu\n",rsb->s_first_data_block);
// printf("s_inodes_count : %lu\n",rsb->s_inodes_count);
// printf("s_blocks_count_lo : %lu\n",rsb->s_blocks_count_lo);
// printf("s_r_blocks_count_lo : %lu\n",rsb->s_r_blocks_count_lo);
// printf("s_free_blocks_count_lo : %lu\n",rsb->s_free_blocks_count_lo);
// printf("s_free_inodes_count : %lu\n",rsb->s_free_inodes_count);
// printf("s_first_data_block : %lu\n",rsb->s_first_data_block);
fclose(fp);
// fclose(fp);
fp = fopen("/home/user/md/super_block49", "r");
fread(buffer, 4096, 1, (FILE*)fp);
// fp = fopen("/home/user/md/super_block49", "r");
// fread(buffer, 4096, 1, (FILE*)fp);
rsb = (struct extractmd_redundant_super_block *)buffer;
// rsb = (struct extractmd_redundant_super_block *)buffer;
printf("s_inodes_count : %lu\n",rsb->s_inodes_count);
printf("s_blocks_count_lo : %lu\n",rsb->s_blocks_count_lo);
printf("s_r_blocks_count_lo : %lu\n",rsb->s_r_blocks_count_lo);
printf("s_free_blocks_count_lo : %lu\n",rsb->s_free_blocks_count_lo);
printf("s_free_inodes_count : %lu\n",rsb->s_free_inodes_count);
printf("s_first_data_block : %lu\n",rsb->s_first_data_block);
// printf("s_inodes_count : %lu\n",rsb->s_inodes_count);
// printf("s_blocks_count_lo : %lu\n",rsb->s_blocks_count_lo);
// printf("s_r_blocks_count_lo : %lu\n",rsb->s_r_blocks_count_lo);
// printf("s_free_blocks_count_lo : %lu\n",rsb->s_free_blocks_count_lo);
// printf("s_free_inodes_count : %lu\n",rsb->s_free_inodes_count);
// printf("s_first_data_block : %lu\n",rsb->s_first_data_block);
fclose(fp);
// fclose(fp);
fp = fopen("/home/user/md/super_block5", "r");
fread(buffer, 4096, 1, (FILE*)fp);
// fp = fopen("/home/user/md/super_block5", "r");
// fread(buffer, 4096, 1, (FILE*)fp);
rsb = (struct extractmd_redundant_super_block *)buffer;
// rsb = (struct extractmd_redundant_super_block *)buffer;
printf("s_inodes_count : %lu\n",rsb->s_inodes_count);
printf("s_blocks_count_lo : %lu\n",rsb->s_blocks_count_lo);
printf("s_r_blocks_count_lo : %lu\n",rsb->s_r_blocks_count_lo);
printf("s_free_blocks_count_lo : %lu\n",rsb->s_free_blocks_count_lo);
printf("s_free_inodes_count : %lu\n",rsb->s_free_inodes_count);
printf("s_first_data_block : %lu\n",rsb->s_first_data_block);
// printf("s_inodes_count : %lu\n",rsb->s_inodes_count);
// printf("s_blocks_count_lo : %lu\n",rsb->s_blocks_count_lo);
// printf("s_r_blocks_count_lo : %lu\n",rsb->s_r_blocks_count_lo);
// printf("s_free_blocks_count_lo : %lu\n",rsb->s_free_blocks_count_lo);
// printf("s_free_inodes_count : %lu\n",rsb->s_free_inodes_count);
// printf("s_first_data_block : %lu\n",rsb->s_first_data_block);
fclose(fp);
// fclose(fp);
fp = fopen("/home/user/md/super_block7", "r");
fread(buffer, 4096, 1, (FILE*)fp);
// fp = fopen("/home/user/md/super_block7", "r");
// fread(buffer, 4096, 1, (FILE*)fp);
rsb = (struct extractmd_redundant_super_block *)buffer;
// rsb = (struct extractmd_redundant_super_block *)buffer;
printf("s_inodes_count : %lu\n",rsb->s_inodes_count);
printf("s_blocks_count_lo : %lu\n",rsb->s_blocks_count_lo);
printf("s_r_blocks_count_lo : %lu\n",rsb->s_r_blocks_count_lo);
printf("s_free_blocks_count_lo : %lu\n",rsb->s_free_blocks_count_lo);
printf("s_free_inodes_count : %lu\n",rsb->s_free_inodes_count);
printf("s_first_data_block : %lu\n",rsb->s_first_data_block);
// printf("s_inodes_count : %lu\n",rsb->s_inodes_count);
// printf("s_blocks_count_lo : %lu\n",rsb->s_blocks_count_lo);
// printf("s_r_blocks_count_lo : %lu\n",rsb->s_r_blocks_count_lo);
// printf("s_free_blocks_count_lo : %lu\n",rsb->s_free_blocks_count_lo);
// printf("s_free_inodes_count : %lu\n",rsb->s_free_inodes_count);
// printf("s_first_data_block : %lu\n",rsb->s_first_data_block);
fclose(fp);
// fclose(fp);
fp = fopen("/home/user/md/super_block9", "r");
fread(buffer, 4096, 1, (FILE*)fp);
// fp = fopen("/home/user/md/super_block9", "r");
// fread(buffer, 4096, 1, (FILE*)fp);
rsb = (struct extractmd_redundant_super_block *)buffer;
// rsb = (struct extractmd_redundant_super_block *)buffer;
printf("s_inodes_count : %lu\n",rsb->s_inodes_count);
printf("s_blocks_count_lo : %lu\n",rsb->s_blocks_count_lo);
printf("s_r_blocks_count_lo : %lu\n",rsb->s_r_blocks_count_lo);
printf("s_free_blocks_count_lo : %lu\n",rsb->s_free_blocks_count_lo);
printf("s_free_inodes_count : %lu\n",rsb->s_free_inodes_count);
printf("s_first_data_block : %lu\n",rsb->s_first_data_block);
// printf("s_inodes_count : %lu\n",rsb->s_inodes_count);
// printf("s_blocks_count_lo : %lu\n",rsb->s_blocks_count_lo);
// printf("s_r_blocks_count_lo : %lu\n",rsb->s_r_blocks_count_lo);
// printf("s_free_blocks_count_lo : %lu\n",rsb->s_free_blocks_count_lo);
// printf("s_free_inodes_count : %lu\n",rsb->s_free_inodes_count);
// printf("s_first_data_block : %lu\n",rsb->s_first_data_block);
fclose(fp);
// fclose(fp);
// fp = fopen("/home/user/md/external_journal", "r");
......
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