Commit 690ca1ec authored by root's avatar root
Browse files

extractmd_meta_data structre is introduced.

parent 361b8d9b
......@@ -631,6 +631,7 @@ deps_/home/user/Team_Safdar/extractmd/extractmd.o := \
$(wildcard include/config/amd/iommu.h) \
include/linux/pm_wakeup.h \
include/linux/mount.h \
/home/user/Team_Safdar/extractmd/extractmd.h \
/home/user/Team_Safdar/extractmd/linux-4.0.9/fs/ext4/ext4.h \
include/linux/blkdev.h \
$(wildcard include/config/blk/dev/io/trace.h) \
......
11/11/2016 v1.1
in extractmd.h
struct extractmd_meta_data contains extractmd_super_block and extractmd_group_desc.
in extractmd.c
Now, extractmd module will extract extractmd_meta_data(containing super_block and group_desc).
See test.c to know how to use.
11/11/2016 v1.0
in extractmd.h
......
No preview for this file type
......@@ -5,25 +5,25 @@
#include <linux/device.h>
#include <linux/mount.h>
#include "extractmd.h"
#include "linux-4.0.9/fs/ext4/ext4.h"
/* Prototypes */
static int __init init_extractmd(void);
static void __exit cleanup_extractmd(void);
static int extractmd_ioctl(struct inode *, struct file *, struct ext4_super_block *);
static int extractmd_ioctl(struct inode *, struct file *, struct extractmd_meta_data *);
static int device_open(struct inode *, struct file *);
static int device_release(struct inode *, struct file *);
static struct ext4_group_desc *get_group_desc(struct super_block *sb, ext4_group_t block_group);
static int copy_super_block(struct ext4_super_block *, struct ext4_super_block *);
static int copy_group_desc(struct ext4_group_desc *, struct ext4_group_desc *);
#define DEVICE_NAME "extractmd" /* Dev name as it appears in /proc/devices */
#define MAJOR 199 /* Device major number */
#define MAJOR_NUM 199 /* Device MAJOR number */
/* Global variables are declared as static, so are global within the file.*/
static struct class *my_class;
......@@ -39,8 +39,8 @@ 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");
register_chrdev(MAJOR, DEVICE_NAME, &fops);
devt = MKDEV(MAJOR,0);
register_chrdev(MAJOR_NUM, DEVICE_NAME, &fops);
devt = MKDEV(MAJOR_NUM,0);
my_class = class_create(THIS_MODULE, DEVICE_NAME);
device_create(my_class, NULL, devt, NULL, DEVICE_NAME);
......@@ -50,14 +50,14 @@ static int __init init_extractmd(void)
static void __exit cleanup_extractmd(void)
{
/* Unregister the device */
unregister_chrdev(MAJOR, DEVICE_NAME);
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 ext4_super_block *addr)
static int extractmd_ioctl(struct inode *inode, struct file *f, struct extractmd_meta_data *md_user)
{
struct file *fp = filp_open("/mnt", O_RDONLY, 0);
......@@ -67,13 +67,15 @@ static int extractmd_ioctl(struct inode *inode, struct file *f, struct ext4_supe
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 = NULL;
ext4_group_t ngroup = sbi->s_groups_count;
struct ext4_group_desc *gdp = get_group_desc(sb,0);
//ext4_group_t ngroup = sbi->s_groups_count;
//unsigned long i = 0;
int ret = 0;
struct extractmd_meta_data md;
md.md_super_block = *(struct extractmd_super_block *)sbt;
md.md_group_desc = *(struct extractmd_group_desc *)gdp;
// unsigned long tmp = 99;
// int ret = copy_to_user(addr, &tmp, sizeof(unsigned long));
......@@ -105,13 +107,10 @@ static int extractmd_ioctl(struct inode *inode, struct file *f, struct ext4_supe
printk(KERN_INFO "Free inode counts : %lu\n", (unsigned long)gdp->bg_free_inodes_count_lo);
}*/
ret = copy_super_block(addr, sbt);
printk(KERN_INFO "%d left\n", ret);
ret = copy_to_user(md_user, &md, sizeof(struct extractmd_meta_data));
thaw_super(sb);
printk(KERN_INFO "%d left\n", ret);
return 0;
}
......@@ -142,6 +141,12 @@ static int copy_super_block(struct ext4_super_block *dst, struct ext4_super_bloc
return ret;
}
static int copy_group_desc(struct ext4_group_desc *dst, struct ext4_group_desc *src)
{
int ret = copy_to_user(dst, src, sizeof(struct ext4_group_desc));
return ret;
}
module_init(init_extractmd);
module_exit(cleanup_extractmd);
......
......@@ -147,3 +147,8 @@ struct extractmd_group_desc
__le16 bg_inode_bitmap_csum_hi;/* crc32c(s_uuid+grp_num+ibitmap) BE */
__u32 bg_reserved;
};
struct extractmd_meta_data {
struct extractmd_super_block md_super_block;
struct extractmd_group_desc md_group_desc;
};
No preview for this file type
No preview for this file type
......@@ -8,10 +8,14 @@
int main()
{
int fd = open("/dev/extractmd", O_RDWR);
struct extractmd_super_block a;
ioctl(fd, &a);
struct extractmd_meta_data md;
ioctl(fd,&md);
struct extractmd_super_block a = md.md_super_block;
struct extractmd_group_desc b = md.md_group_desc;
printf("%lu\n", (unsigned long)a.s_free_inodes_count);
printf("%lu\n", (unsigned long)b.bg_inode_table_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