Commit 0f3a0a70 authored by root's avatar root
Browse files

make the code concise and add author, description.

parent 1ec4eee1
......@@ -26,8 +26,6 @@ static struct ext4_group_desc *extractmd_get_group_desc(struct super_block *sb,
ext4_fsblk_t extractmd_block_bitmap(struct super_block *, struct ext4_group_desc *);
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);
long extractmd_write_file(char *, char *, unsigned long);
long extractmd_write_file_per_group(char *, char*, unsigned long, int);
......@@ -71,19 +69,12 @@ static int extractmd_ioctl(struct inode *inode, struct file *f, struct extractmd
struct file *fp = filp_open(p->path_mount_point, O_RDONLY, 0);
struct file *fp_dev = filp_open(p->path_device, O_RDONLY, 0);
// set path and filenames
char path_super_block[255] = {0};
char path_group_descriptor[255] = {0};
char path_block_bitmap[255] = {0};
char path_inode_bitmap[255] = {0};
char path_inode_table[255] = {0};
sprintf(path_super_block, "%s/super_block", p->path);
sprintf(path_group_descriptor, "%s/group_descriptor", p->path);
sprintf(path_block_bitmap, "%s/block_bitmap", p->path);
sprintf(path_inode_bitmap, "%s/inode_bitmap", p->path);
sprintf(path_inode_table, "%s/inode_table", p->path);
int i = 0;
unsigned long nr_gd; // number of groupd descriptors
unsigned long nr_inode_table_block; // number of inode table blocks
......@@ -91,13 +82,21 @@ static int extractmd_ioctl(struct inode *inode, struct file *f, struct extractmd
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_sb_info *sbi = EXT4_SB(sb); // get ext4_sb_info
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;
/* set path and filenames */
sprintf(path_super_block, "%s/super_block", p->path);
sprintf(path_group_descriptor, "%s/group_descriptor", p->path);
sprintf(path_block_bitmap, "%s/block_bitmap", p->path);
sprintf(path_inode_bitmap, "%s/inode_bitmap", p->path);
sprintf(path_inode_table, "%s/inode_table", p->path);
/* sync */
freeze_super(sb);
thaw_super(sb);
......@@ -105,7 +104,6 @@ static int extractmd_ioctl(struct inode *inode, struct file *f, struct extractmd
/*
* EXCTRACTING SECTION!
*/
printk(KERN_INFO "Extractmd start!\n");
/* super block in Group 0 */
bh_sb = __bread(bdev, 0, EXT4_BLOCK_SIZE(sb));
......@@ -144,141 +142,6 @@ static struct ext4_group_desc *extractmd_get_group_desc(struct super_block *sb,
return (struct ext4_group_desc *)((__u8 *)sbi->s_group_desc[group_desc]->b_data + offset * EXT4_DESC_SIZE(sb));
}
// static int extractmd_get_inode_loc(struct inode *inode, struct ext4_iloc *iloc)
// {
// int in_mem = !ext4_test_inode_state(inode, EXT4_STATE_XATTR);
// struct ext4_group_desc *gdp;
// struct buffer_head *bh;
// struct super_block *sb = inode->i_sb;
// ext4_fsblk_t block;
// int inodes_per_block, inode_offset;
// iloc->bh = NULL;
// if (!ext4_valid_inum(sb, inode->i_ino))
// return -EIO;
// iloc->block_group = (inode->i_ino - 1) / EXT4_INODES_PER_GROUP(sb);
// gdp = extractmd_get_group_desc(sb, iloc->block_group);
// if (!gdp)
// return -EIO;
// /*
// * Figure out the offset within the block group inode table
// */
// inodes_per_block = EXT4_SB(sb)->s_inodes_per_block;
// inode_offset = ((inode->i_ino - 1) %
// EXT4_INODES_PER_GROUP(sb));
// block = extractmd_inode_table(sb, gdp) + (inode_offset / inodes_per_block);
// iloc->offset = (inode_offset % inodes_per_block) * EXT4_INODE_SIZE(sb);
// bh = sb_getblk(sb, block);
// if (unlikely(!bh))
// return -ENOMEM;
// if (!buffer_uptodate(bh)) {
// lock_buffer(bh);
// /*
// * If the buffer has the write error flag, we have failed
// * to write out another inode in the same block. In this
// * case, we don't have to read the block because we may
// * read the old inode data successfully.
// */
// if (buffer_write_io_error(bh) && !buffer_uptodate(bh))
// set_buffer_uptodate(bh);
// if (buffer_uptodate(bh)) {
// /* someone brought it uptodate while we waited */
// unlock_buffer(bh);
// goto has_buffer;
// }
// /*
// * If we have all information of the inode in memory and this
// * is the only valid inode in the block, we need not read the
// * block.
// */
// if (in_mem) {
// struct buffer_head *bitmap_bh;
// int i, start;
// start = inode_offset & ~(inodes_per_block - 1);
// /* Is the inode bitmap in cache? */
// bitmap_bh = sb_getblk(sb, extractmd_inode_bitmap(sb, gdp));
// if (unlikely(!bitmap_bh))
// goto make_io;
// /*
// * If the inode bitmap isn't in cache then the
// * optimisation may end up performing two reads instead
// * of one, so skip it.
// */
// if (!buffer_uptodate(bitmap_bh)) {
// brelse(bitmap_bh);
// goto make_io;
// }
// for (i = start; i < start + inodes_per_block; i++) {
// if (i == inode_offset)
// continue;
// if (ext4_test_bit(i, bitmap_bh->b_data))
// break;
// }
// brelse(bitmap_bh);
// if (i == start + inodes_per_block) {
// /* all other inodes are free, so skip I/O */
// memset(bh->b_data, 0, bh->b_size);
// set_buffer_uptodate(bh);
// unlock_buffer(bh);
// goto has_buffer;
// }
// }
// make_io:
// /*
// * If we need to do any I/O, try to pre-readahead extra
// * blocks from the inode table.
// */
// if (EXT4_SB(sb)->s_inode_readahead_blks) {
// ext4_fsblk_t b, end, table;
// unsigned num;
// __u32 ra_blks = EXT4_SB(sb)->s_inode_readahead_blks;
// table = extractmd_inode_table(sb, gdp);
// /* s_inode_readahead_blks is always a power of 2 */
// b = block & ~((ext4_fsblk_t) ra_blks - 1);
// if (table > b)
// b = table;
// end = b + ra_blks;
// num = EXT4_INODES_PER_GROUP(sb);
// if (ext4_has_group_desc_csum(sb))
// num -= extractmd_itable_unused_count(sb, gdp);
// table += num / inodes_per_block;
// if (end > table)
// end = table;
// while (b <= end)
// sb_breadahead(sb, b++);
// }
// /*
// * There are other valid inodes in the buffer, this inode
// * has in-inode xattrs, or we don't have this inode in memory.
// * Read the block from disk.
// */
// //trace_ext4_load_inode(inode);
// get_bh(bh);
// bh->b_end_io = end_buffer_read_sync;
// submit_bh(READ | REQ_META | REQ_PRIO, bh);
// wait_on_buffer(bh);
// if (!buffer_uptodate(bh)) {
// brelse(bh);
// return -EIO;
// }
// }
// has_buffer:
// iloc->bh = bh;
// return 0;
// }
ext4_fsblk_t extractmd_block_bitmap(struct super_block *sb, struct ext4_group_desc *bg)
{
return le32_to_cpu(bg->bg_block_bitmap_lo) | (EXT4_DESC_SIZE(sb) >= EXT4_MIN_DESC_SIZE_64BIT ? (ext4_fsblk_t)le32_to_cpu(bg->bg_block_bitmap_hi) << 32 : 0);
......@@ -294,11 +157,6 @@ ext4_fsblk_t extractmd_inode_bitmap(struct super_block *sb, struct ext4_group_de
return le32_to_cpu(bg->bg_inode_bitmap_lo) | (EXT4_DESC_SIZE(sb) >= EXT4_MIN_DESC_SIZE_64BIT ? (ext4_fsblk_t)le32_to_cpu(bg->bg_inode_bitmap_hi) << 32 : 0);
}
__u32 extractmd_itable_unused_count(struct super_block *sb, struct ext4_group_desc *bg)
{
return le16_to_cpu(bg->bg_itable_unused_lo) | (EXT4_DESC_SIZE(sb) >= EXT4_MIN_DESC_SIZE_64BIT ? (__u32)le16_to_cpu(bg->bg_itable_unused_hi) << 16 : 0);
}
/* Called when a process tries to open the device file */
static int device_open(struct inode *inode, struct file *file)
{
......@@ -311,17 +169,6 @@ 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;
}*/
long extractmd_write_file(char *path, char* data, unsigned long size)
{
long ret;
......@@ -366,3 +213,5 @@ module_init(init_extractmd);
module_exit(cleanup_extractmd);
MODULE_LICENSE("GPL");
MODULE_AUTHOR("Mincheol Sung <mincheol@vt.edu>");
MODULE_DESCRIPTION("Extract meta data of EXT4 from the device and write it on files.");
\ No newline at end of file
No preview for this file type
No preview for this file type
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