Commit 77177720 authored by root's avatar root
Browse files

tt

parent dae6da31
/home/user/Team_Safdar/extractmd/extractmd.ko
/home/user/Team_Safdar/extractmd/extractmd.o
No preview for this file type
......@@ -21,7 +21,9 @@ static int extractmd_get_inode_loc(struct inode *, struct ext4_iloc *);
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 *);
__u32 extractmd_itable_unused_count(struct super_block *, struct ext4_group_desc *);
static struct ext4_inode *extractmd_get_ext4_inode(struct super_block *, unsigned long);
static struct extractmd_group_desc_list *make_group_desc_list(struct super_block);
static int copy_group_desc_list(struct extractmd_group_desc_list *, struct extractmd_group_desc_list *, ext4_group_t);
#define DEVICE_NAME "extractmd" /* Dev name as it appears in /proc/devices */
#define MAJOR_NUM 199 /* Device MAJOR number */
......@@ -38,9 +40,7 @@ static struct file_operations fops = {
static int __init init_extractmd(void)
{
printk(KERN_INFO "extractmd is registered in /proc/devices\n");
printk(KERN_INFO "/dev/extractmd is maked.\n");
printk(KERN_INFO "create class\n");
printk(KERN_INFO "Init module\n");
register_chrdev(MAJOR_NUM, DEVICE_NAME, &fops);
devt = MKDEV(MAJOR_NUM,0);
my_class = class_create(THIS_MODULE, DEVICE_NAME);
......@@ -55,38 +55,63 @@ static void __exit cleanup_extractmd(void)
unregister_chrdev(MAJOR_NUM, DEVICE_NAME);
device_destroy(my_class, devt);
class_destroy(my_class);
printk(KERN_INFO "unregister extractmd, destroy dev node and class\n");
printk(KERN_INFO "Cleaning up module.\n");
}
static int extractmd_ioctl(struct inode *inode, struct file *f, struct extractmd_meta_data *md_user)
{
unsigned int i = 0;
unsigned int k = 0;
struct file *fp = filp_open(md_user->md_path, O_RDONLY, 0);
/*
* Super block part.
*/
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
struct ext4_super_block *sbt = sbi->s_es; // get ext4_super_block
struct ext4_group_desc *gdp = extractmd_get_group_desc(sb,0);
struct ext4_iloc iloc;
extractmd_get_inode_loc(fp->f_inode, &iloc);
struct ext4_inode *raw_inode = ext4_raw_inode(&iloc);
//ext4_group_t ngroup = sbi->s_groups_count;
int ret = 0; // Result for extracing. If ret != 0, some data is not extract.
/*
* Goup desc part.
*/
//struct ext4_group_desc *gdp = extractmd_get_group_desc(sb,0);
ext4_group_t nr_group = sbi->s_groups_count;
/*
* Inode part.
*/
//struct ext4_iloc iloc;
//extractmd_get_inode_loc(fp->f_inode, &iloc);
//struct ext4_inode *raw_inode = ext4_raw_inode(&iloc);
struct extractmd_meta_data md;
md.md_super_block = *(struct extractmd_super_block *)sbt;
md.md_group_desc = *(struct extractmd_group_desc *)gdp;
md.md_inode = *(struct extractmd_inode *)raw_inode;
md.gd_list = make_group_desc_list(sb);
//md.md_super_block = *(struct extractmd_super_block *)sbt;
//md.md_inode = *(struct extractmd_inode *)extractmd_get_ext4_inode(sb, md_user->md_ino);
/*
* EXCTRACTING SECTION!
*/
printk(KERN_INFO "Extractmd start!\n");
int ret = 0; // Result for extracing. If ret != 0, some data is not extract.
freeze_super(sb);
freeze_super(sb);
ret = copy_to_user(md_user, &md, sizeof(struct extractmd_meta_data));
//ret += copy_group_desc_list(md_user->gd_list, md.gd_list, nr_group);
//ret += copy_to_user(md_user, &md, sizeof(struct extractmd_meta_data));
thaw_super(sb);
printk(KERN_INFO "%d left\n", ret);
return 0;
}
......@@ -262,6 +287,71 @@ static int device_release(struct inode *inode, struct file *file)
return 0;
}
static struct ext4_inode *extractmd_get_ext4_inode(struct super_block *sb, unsigned long ino)
{
struct inode *inode = ilookup(sb, ino);
struct ext4_iloc iloc;
extractmd_get_inode_loc(inode, &iloc);
struct ext4_inode *ret = ext4_raw_inode(&iloc);
return ret;
}
// static struct ext4_group_desc *extractmd_get_group_desc_list(struct super_block *sb)
// {
// ext4_group_t i = 0;
// struct ext4_sb_info *sbi = EXT4_SB(sb);
// ext4_group_t group_count = sbi->s_groups_count;
// struct ext4_group_desc ret[group_count];
// for(i=0; i < group_count; i++)
// {
// ret[i] = *extractmd_get_group_desc(sb,i);
// }
// return ret;
// }
static struct extractmd_group_desc_list *make_group_desc_list(struct super_block *sb)
{
unsigned int i = 0;
struct ext4_sb_info *sbi = EXT4_SB(sb);
ext4_group_t nr_group = sbi->s_groups_count;
struct extractmd_group_desc_list *ret = (struct extractmd_group_desc_list *)kmalloc(sizeof(struct extractmd_group_desc_list), GFP_KERNEL);
ret->group_desc = *(struct extractmd_group_desc *)extractmd_get_group_desc(sb,0);
ret->group = 0;
struct extractmd_group_desc_list *p = ret;
for(i = 1; i < nr_group; i++)
{
p = p->next;
p = (struct extractmd_group_desc_list *)kmalloc(sizeof(struct extractmd_group_desc_list), GFP_KERNEL);
p->group_desc = *(struct extractmd_group_desc *)extractmd_get_group_desc(sb, i);
p->group = i;
}
return ret;
}
static int copy_group_desc_list(struct extractmd_group_desc_list *dst, struct extractmd_group_desc_list *src, ext4_group_t nr_group)
{
int ret = 0;
unsigned int i = 0;
struct extractmd_group_desc_list *current_dst = dst;
struct extractmd_group_desc_list *current_src = src;
for (i = 0; i < nr_group; i++)
{
ret += copy_to_user(current_dst, current_src, sizeof(struct extractmd_group_desc_list));
current_dst = current_dst->next;
current_src = current_src->next;
}
return ret;
}
module_init(init_extractmd);
module_exit(cleanup_extractmd);
......
#include <linux/types.h>
typedef unsigned int ext4_group_t;
/*
* Structure of the super block
*/
......@@ -208,11 +209,21 @@ struct extractmd_inode {
__le32 i_version_hi; /* high 32 bits for 64-bit version */
};
struct extractmd_group_desc_list {
ext4_group_t group;
struct extractmd_group_desc group_desc;
struct extractmd_group_desc *next;
};
struct extractmd_meta_data {
char *md_path;
struct extractmd_super_block md_super_block;
struct extractmd_group_desc md_group_desc;
struct extractmd_inode md_inode;
struct extractmd_group_desc_list *gd_list;
struct extractmd_super_block_list *sb_list;
struct extractmd_inode_list *i_list;
//char *md_path;
//unsigned long md_ino;
//struct extractmd_super_block md_super_block;
//struct extractmd_inode md_inode;
};
\ No newline at end of file
No preview for this file type
......@@ -8,25 +8,17 @@
int main()
{
int fd = open("/dev/extractmd", O_RDWR);
int i = 0;
struct extractmd_meta_data md;
md.md_path = "/mnt/testE";
ioctl(fd,&md);
printf("%lu\n", (unsigned long)md.md_super_block.s_free_inodes_count);
printf("%lu\n", (unsigned long)md.md_group_desc.bg_inode_table_lo);
printf("%lu\n", (unsigned long)md.md_inode.i_size_lo);
md.md_path = "/mnt/testF";
//md.md_path = "/mnt";
//md.md_ino = 393217; // testE
ioctl(fd,&md);
printf("%lu\n", (unsigned long)md.md_super_block.s_free_inodes_count);
printf("%lu\n", (unsigned long)md.md_group_desc.bg_inode_table_lo);
printf("%lu\n", (unsigned long)md.md_inode.i_size_lo);
// printf("%lu\n", (unsigned long)md.md_super_block.s_block_group_nr);
//printf("%lu\n", (unsigned long)md.md_group_desc_list[0].bg_inode_table_lo);
// printf("%lu\n", (unsigned long)md.md_inode.i_size_lo);
close(fd);
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