内核直接读取硬盘固定扇区的代码Linux认证考试
文章作者 100test 发表时间 2009:12:24 16:21:17
来源 100Test.Com百考试题网
块缓存 struct buffer_head 用来保存从磁盘读取到的数据,而 struct page 是文件的缓存,在文件层面上的数据会缓存到page里,所以内核里直接读取某个固定的扇区可以利用 struct buffer_head,读取的速度会快一些;以下是实现的代码:
#include <.linux/module.h>.
#include <.linux/init.h>.
#include <.linux/sched.h>.
#include <.linux/kernel.h>.
#include <.linux/fs.h>.
#include <.linux/types.h>.
#include <.linux/buffer_head.h>.
#include <.linux/blkdev.h>.
#include <.linux/msdos_fs.h>.
#include <.linux/fcntl.h>.
#include <.linux/delay.h>.
static int set_size = 512.
static int nr = -1.
static char *devn = "/dev/sda".
module_param(set_size,int,S_IRUGO).
MODULE_Parm_DESC(set_size,"how many bytes you want to read,not more than 4096").
module_param(nr,long,S_IRUGO).
MODULE_Parm_DESC(nr,"which sectors you want to read").
module_param(devn,charp,S_IRUGO).
MODULE_Parm_DESC(devn,"which device").
MODULE_LICENSE("GPL").
static struct block_device *bdev.
static char *usage = "You can change the value:set_size nr devn".