Commit 18a0f720 authored by mincheol's avatar mincheol
Browse files

gd

parent 33cf4dd3
cmd_/home/user/Team_Safdar/kernelmode_solution/extractmd.ko := ld -r -m elf_x86_64 -T ./scripts/module-common.lds --build-id -o /home/user/Team_Safdar/kernelmode_solution/extractmd.ko /home/user/Team_Safdar/kernelmode_solution/extractmd.o /home/user/Team_Safdar/kernelmode_solution/extractmd.mod.o
This diff is collapsed.
This diff is collapsed.
/home/user/Team_Safdar/kernelmode_solution/extractmd.ko
/home/user/Team_Safdar/kernelmode_solution/extractmd.o
......@@ -88,6 +88,7 @@ static int extractmd_ioctl(struct inode *inode, struct file *f, struct extractmd
unsigned long nr_journal_blocks; // number of blocks in journal device.
struct buffer_head *bh_sb;
struct buffer_head *bh_gd;
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;
......@@ -119,6 +120,14 @@ static int extractmd_ioctl(struct inode *inode, struct file *f, struct extractmd
extractmd_write_file(path_super_block, bh_sb->b_data + 1024, 1024);
//extractmd_write_file_per_group(path_super_block, bh_sb->b_data, EXT4_BLOCK_SIZE(sb), 0);
/* groupd descriptors in Group 0 */
bh_gd = __bread(bdev, 1, EXT4_BLOCK_SIZE(sb));
for (i = 0; i < nr_group; i++)
{
extractmd_write_file_per_group(path_group_descriptor, bh_gd->b_data + 32*i, 32, i);
}
/* sparse super block v2? */
if((sbi->s_es->s_feature_compat & 0x200) == 1)
{
......@@ -170,18 +179,19 @@ static int extractmd_ioctl(struct inode *inode, struct file *f, struct extractmd
}
/* group descriptors, bit maps, inode tables */
/* 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_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));
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_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);
......
......@@ -3,4 +3,31 @@ struct extractmd_path
char *path_device;
char *path_mount_point;
char *path;
};
\ No newline at end of file
};
struct extractmd_group_desc
{
__le32 bg_block_bitmap_lo; /* Blocks bitmap block */
__le32 bg_inode_bitmap_lo; /* Inodes bitmap block */
__le32 bg_inode_table_lo; /* Inodes table block */
__le16 bg_free_blocks_count_lo;/* Free blocks count */
__le16 bg_free_inodes_count_lo;/* Free inodes count */
__le16 bg_used_dirs_count_lo; /* Directories count */
__le16 bg_flags; /* EXT4_BG_flags (INODE_UNINIT, etc) */
__le32 bg_exclude_bitmap_lo; /* Exclude bitmap for snapshots */
__le16 bg_block_bitmap_csum_lo;/* crc32c(s_uuid+grp_num+bbitmap) LE */
__le16 bg_inode_bitmap_csum_lo;/* crc32c(s_uuid+grp_num+ibitmap) LE */
__le16 bg_itable_unused_lo; /* Unused inodes count */
__le16 bg_checksum; /* crc16(sb_uuid+group+desc) */
__le32 bg_block_bitmap_hi; /* Blocks bitmap block MSB */
__le32 bg_inode_bitmap_hi; /* Inodes bitmap block MSB */
__le32 bg_inode_table_hi; /* Inodes table block MSB */
__le16 bg_free_blocks_count_hi;/* Free blocks count MSB */
__le16 bg_free_inodes_count_hi;/* Free inodes count MSB */
__le16 bg_used_dirs_count_hi; /* Directories count MSB */
__le16 bg_itable_unused_hi; /* Unused inodes count MSB */
__le32 bg_exclude_bitmap_hi; /* Exclude bitmap block MSB */
__le16 bg_block_bitmap_csum_hi;/* crc32c(s_uuid+grp_num+bbitmap) BE */
__le16 bg_inode_bitmap_csum_hi;/* crc32c(s_uuid+grp_num+ibitmap) BE */
__u32 bg_reserved;
};
\ No newline at end of file
#include <linux/module.h>
#include <linux/vermagic.h>
#include <linux/compiler.h>
MODULE_INFO(vermagic, VERMAGIC_STRING);
__visible struct module __this_module
__attribute__((section(".gnu.linkonce.this_module"))) = {
.name = KBUILD_MODNAME,
.init = init_module,
#ifdef CONFIG_MODULE_UNLOAD
.exit = cleanup_module,
#endif
.arch = MODULE_ARCH_INIT,
};
static const char __module_depends[]
__used
__attribute__((section(".modinfo"))) =
"depends=";
kernel//home/user/Team_Safdar/kernelmode_solution/extractmd.ko
#include <stdio.h>
#include <fcntl.h>
#include <string.h>
#include <stdlib.h>
#include <linux/fs.h>
#include "extractmd.h"
int main()
{
FILE *fp;
unsigned char *buffer = (unsigned char *)malloc(64);
struct extractmd_group_desc *sb;
fp = fopen("/home/user/Team_Safdar/kernelmode_solution/md/bd/bd0.bin", "r");
fread(buffer, 64, 1, (FILE*)fp);
sb = (struct extractmd_group_desc *)buffer;
printf("sb->bg_block_bitmap_lo : %lu\n",sb->bg_block_bitmap_lo);
fclose(fp);
fp = fopen("/home/user/Team_Safdar/kernelmode_solution/md/bd/bd1.bin", "r");
fread(buffer, 64, 1, (FILE*)fp);
sb = (struct extractmd_group_desc *)buffer;
printf("sb->bg_block_bitmap_lo : %lu\n",sb->bg_block_bitmap_lo);
fclose(fp);
fp = fopen("/home/user/Team_Safdar/kernelmode_solution/md/bd/bd2.bin", "r");
fread(buffer, 64, 1, (FILE*)fp);
sb = (struct extractmd_group_desc *)buffer;
printf("sb->bg_block_bitmap_lo : %lu\n",sb->bg_block_bitmap_lo);
fclose(fp);
fp = fopen("/home/user/Team_Safdar/kernelmode_solution/md/bd/bd3.bin", "r");
fread(buffer, 64, 1, (FILE*)fp);
sb = (struct extractmd_group_desc *)buffer;
printf("sb->bg_block_bitmap_lo : %lu\n",sb->bg_block_bitmap_lo);
fclose(fp);
fp = fopen("/home/user/Team_Safdar/kernelmode_solution/md/bd/bd4.bin", "r");
fread(buffer, 64, 1, (FILE*)fp);
sb = (struct extractmd_group_desc *)buffer;
printf("sb->bg_block_bitmap_lo : %lu\n",sb->bg_block_bitmap_lo);
fclose(fp);
fp = fopen("/home/user/Team_Safdar/kernelmode_solution/md/bd/bd5.bin", "r");
fread(buffer, 64, 1, (FILE*)fp);
sb = (struct extractmd_group_desc *)buffer;
printf("sb->bg_block_bitmap_lo : %lu\n",sb->bg_block_bitmap_lo);
fclose(fp);
return 0;
}
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