Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions Project/ddk_fs.c
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ static struct file_operations dfs_fops =
};
static struct file_operations dfs_dops =
{
//readdir: dfs_readdir // TODO: Uncomment on completing dfs_readdir's implementation
readdir: dfs_readdir // TODO: Uncomment on completing dfs_readdir's implementation
};

static int dfs_get_block(struct inode *inode, sector_t iblock, struct buffer_head *bh_result, int create)
Expand Down Expand Up @@ -258,7 +258,7 @@ static int dfs_inode_create(struct inode *parent_inode, struct dentry *dentry, u

return 0;
}
#if 0

static int dfs_inode_unlink(struct inode *parent_inode, struct dentry *dentry)
{
char fn[dentry->d_name.len + 1];
Expand Down Expand Up @@ -296,14 +296,14 @@ static int dfs_inode_rename(struct inode *old_dir, struct dentry *old_dentry, st
else
return 0;
}
#endif

static struct inode_operations dfs_iops =
{
// TODO: Uncomment below once the corresponding function's implementation is complete
//lookup: dfs_inode_lookup, /* TODO: Try first */
//create: dfs_inode_create, /* TODO: Try next */
//unlink: dfs_inode_unlink, /* TODO: Now try removing the files */
//rename: dfs_inode_rename /* TODO: Now try renaming the files */
lookup: dfs_inode_lookup, /* TODO: Try first */
create: dfs_inode_create, /* TODO: Try next */
unlink: dfs_inode_unlink, /* TODO: Now try removing the files */
rename: dfs_inode_rename /* TODO: Now try renaming the files */
};

/*
Expand All @@ -321,7 +321,7 @@ static void dfs_put_super(struct super_block *sb)
sb->s_fs_info = NULL;
}
}
#if 0

static int dfs_statfs(struct dentry *dentry, struct kstatfs *buf)
{
struct super_block *sb = dentry->d_sb;
Expand All @@ -345,7 +345,7 @@ static int dfs_statfs(struct dentry *dentry, struct kstatfs *buf)
buf->f_namelen = DDK_FS_FILENAME_LEN;
return 0;
}
#endif

#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,34))
static int dfs_write_inode(struct inode *inode, int do_sync)
#else
Expand Down Expand Up @@ -376,8 +376,8 @@ static struct super_operations dfs_sops =
{
// TODO: Uncomment write_inode once dfs_write_inode's implementation is complete
put_super: dfs_put_super,
//statfs: dfs_statfs, /* used by df to show it up */ /* TODO: Now try getting the stats */
//write_inode: dfs_write_inode
statfs: dfs_statfs, /* used by df to show it up */ /* TODO: Now try getting the stats */
write_inode: dfs_write_inode
};

/*
Expand Down
31 changes: 18 additions & 13 deletions Project/ram_block.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ static struct rb_device
struct request_queue *rb_queue;
/* This is kernel's representation of an individual disk device */
struct gendisk *rb_disk;
u8 *data;
} rb_dev;

static int rb_open(struct block_device *bdev, fmode_t mode)
Expand Down Expand Up @@ -66,7 +67,7 @@ static int rb_transfer(struct request *req)

int dir = rq_data_dir(req);
sector_t start_sector = blk_rq_pos(req);
unsigned int sector_cnt = blk_rq_sectors(req);
unsigned int sector_cnt = blk_rq_cur_sectors(req);

struct bio_vec *bv;
struct req_iterator iter;
Expand Down Expand Up @@ -138,6 +139,10 @@ static void rb_request(struct request_queue *q)
continue;
}
#endif
if (req == NULL || (req->cmd_type != REQ_TYPE_FS)) {
__blk_end_request_all(req, -EIO);
continue;
}
ret = rb_transfer(req);
__blk_end_request_all(req, ret);
//__blk_end_request(req, ret, blk_rq_bytes(req));
Expand Down Expand Up @@ -170,26 +175,26 @@ static int __init rb_init(void)
}
rb_dev.size = ret;

/* Get Registered */
rb_major = register_blkdev(rb_major, "rb");
if (rb_major <= 0)
{
printk(KERN_ERR "rb: Unable to get Major Number\n");
ramdevice_cleanup();
return -EBUSY;
}

/* Get a request queue (here queue is created) */
spin_lock_init(&rb_dev.lock);
rb_dev.rb_queue = blk_init_queue(rb_request, &rb_dev.lock);
rb_dev.data = dev_data;
rb_dev.rb_queue = blk_init_queue(rb_request, &rb_dev.lock);
if (rb_dev.rb_queue == NULL)
{
printk(KERN_ERR "rb: blk_init_queue failure\n");
unregister_blkdev(rb_major, "rb");
ramdevice_cleanup();
return -ENOMEM;
}

blk_queue_logical_block_size(rb_dev.rb_queue, RB_SECTOR_SIZE);
/* Get Registered */
rb_major = register_blkdev(rb_major, "rb");
if (rb_major <= 0)
{
printk(KERN_ERR "rb: Unable to get Major Number\n");
ramdevice_cleanup();
return -EBUSY;
}
/*
* Add the gendisk structure
* By using this memory allocation is involved,
Expand Down Expand Up @@ -222,7 +227,7 @@ static int __init rb_init(void)
//rb_dev.rb_disk->flags = GENHD_FL_SUPPRESS_PARTITION_INFO;
sprintf(rb_dev.rb_disk->disk_name, "rb");
/* Setting the capacity of the device in its gendisk structure */
set_capacity(rb_dev.rb_disk, rb_dev.size);
set_capacity(rb_dev.rb_disk, RB_DEVICE_SIZE);

/* Adding the disk to the system */
add_disk(rb_dev.rb_disk);
Expand Down
8 changes: 1 addition & 7 deletions Project/ram_device.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,14 @@
#include "ram_device.h"
#include "partition.h"

#define RB_DEVICE_SIZE 1024 /* sectors */
/* So, total device size = 1024 * 512 bytes = 512 KiB */

/* Array where the disk stores its data */
static u8 *dev_data;

int ramdevice_init(void)
{
dev_data = vmalloc(RB_DEVICE_SIZE * RB_SECTOR_SIZE);
if (dev_data == NULL)
return -ENOMEM;
/* Setup its partition table */
copy_mbr_n_br(dev_data);
return RB_DEVICE_SIZE;
return (RB_DEVICE_SIZE * RB_SECTOR_SIZE);
}

void ramdevice_cleanup(void)
Expand Down
3 changes: 3 additions & 0 deletions Project/ram_device.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
#define RAMDEVICE_H

#define RB_SECTOR_SIZE 512
#define RB_DEVICE_SIZE 1024 /* sectors */
/* Array where the disk stores its data */
static u8 *dev_data;

extern int ramdevice_init(void);
extern void ramdevice_cleanup(void);
Expand Down