Commit 571e8da8 authored by mincheol's avatar mincheol
Browse files

tt

parent e0547221
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
......@@ -9,8 +9,8 @@ Kernel module tutorial
3. Start extraction
#./start [device] [mount point] [path-to-store-files]
For example : #./start /dev/sdb /mnt ./md
#./start [device] [mount point] [path-to-store-files] [realtime 0 or 1]
For example : #./start /dev/sdb /mnt ./md 0
This will extract metadata of target device and store files on ./md
......
......@@ -82,7 +82,7 @@ static int extractmd_ioctl(struct inode *inode, struct file *f, struct extractmd
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.
......@@ -95,7 +95,6 @@ static int extractmd_ioctl(struct inode *inode, struct file *f, struct extractmd
ext4_group_t nr_group = sbi->s_groups_count;
struct block_device *bdev;
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);
......@@ -108,7 +107,10 @@ static int extractmd_ioctl(struct inode *inode, struct file *f, struct extractmd
sprintf(path_journal, "%s/journal/journal", p->path);
/* freeze */
freeze_super(sb);
if(!p->realtime)
freeze_super(sb);
/*
* EXCTRACTING SECTION!
......@@ -178,27 +180,56 @@ static int extractmd_ioctl(struct inode *inode, struct file *f, struct extractmd
}
char *buffer_ibitmaps = kmalloc((sbi->s_inodes_per_group)/8, GFP_KERNEL);
char *buffer_bbitmaps = kmalloc((sbi->s_clusters_per_group)/8, GFP_KERNEL);
char *buffer_inode_table = kmalloc(EXT4_BLOCK_SIZE(sb) * nr_inode_table_block, GFP_KERNEL);
/* 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_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_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, 1024, i);
for (h = 0; h < nr_inode_table_block; h++)
struct ext4_group_desc *group = extractmd_get_group_desc(sb, i);
if(group->bg_flags & 0x1)
{
memset(buffer_ibitmaps, 0x0,(sbi->s_inodes_per_group)/8);
extractmd_write_file_per_group(path_inode_bitmap, buffer_ibitmaps, (sbi->s_inodes_per_group)/8, i);
}
else {
struct buffer_head *bh_inode_bitmap = __bread(bdev, extractmd_inode_bitmap(sb, group), EXT4_BLOCK_SIZE(sb));
extractmd_write_file_per_group(path_inode_bitmap, bh_inode_bitmap->b_data, (sbi->s_inodes_per_group)/8, i);
}
if(group->bg_flags & 0x2)
{
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));
memset(buffer_bbitmaps, 0x0,(sbi->s_clusters_per_group)/8);
extractmd_write_file_per_group(path_block_bitmap, buffer_bbitmaps, (sbi->s_clusters_per_group)/8, i);
}
else {
struct buffer_head *bh_block_bitmap = __bread(bdev, extractmd_block_bitmap(sb, group), EXT4_BLOCK_SIZE(sb));
extractmd_write_file_per_group(path_block_bitmap, bh_block_bitmap->b_data, (sbi->s_clusters_per_group)/8, i);
}
extractmd_write_file_per_group(path_inode_table , buffer_inode_table, EXT4_BLOCK_SIZE(sb) * nr_inode_table_block, i);
kfree(buffer_inode_table);
if(group->bg_flags & 0x4)
{
memset(buffer_inode_table, 0x0, EXT4_BLOCK_SIZE(sb) * nr_inode_table_block);
extractmd_write_file_per_group(path_inode_table, buffer_inode_table, EXT4_BLOCK_SIZE(sb) * nr_inode_table_block, i);
}
else {
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);
}
}
kfree(buffer_inode_table);
kfree(buffer_ibitmaps);
kfree(buffer_bbitmaps);
/* journal */
for(j = 0; j < nr_journal_blocks; j++)
......@@ -211,7 +242,9 @@ static int extractmd_ioctl(struct inode *inode, struct file *f, struct extractmd
}
/* unfreeze */
thaw_super(sb);
if(!p->realtime)
thaw_super(sb);
filp_close(fp, NULL);
filp_close(fp_dev, NULL);
......
......@@ -3,31 +3,6 @@ struct extractmd_path
char *path_device;
char *path_mount_point;
char *path;
int realtime;
};
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;
}
......@@ -14,9 +14,9 @@ int main(int argc, char *argv[])
char dir_bd[255] = {0};
char dir_journal[255] = {0};
if (argc != 4)
if (argc != 5)
{
printf("usage : ./start [device] [mount point] [path-you-want] (e.q., #./start /dev/sdb /mnt ./md)\n");
printf("usage : ./start [device] [mount point] [path-you-want] [realtime 0 or 1] (e.q., #./start /dev/sdb /mnt ./md 0)\n");
return 0;
}
......@@ -32,7 +32,8 @@ int main(int argc, char *argv[])
p.path_device = argv[1]; // Device
p.path_mount_point = argv[2]; // Mount point
p.path = argv[3]; // Where to store files of metadata
p.realtime = atoi(argv[4]);
ioctl(fd,&p); // Syscall
close(fd);
......
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