红联Linux门户
Linux帮助

linux字符驱动模板

发布时间:2007-06-19 00:31:49来源:红联作者:RoadCloud
linux 字符驱动模板 2.4以下的内核适用。

#include
#include
#include
#include
#include
#include
#include


#define MAJOR_NUM 125
#define DEVICE_NAME "emptychr"

static ssize_t test_read(struct file *file,char *buf,size_t count,loff_t *f_pos)
{
return count;
}
static ssize_t test_write(struct file *file, const char *buf, size_t count, loff_t *f_pos)
{
return count;
}
static int test_open(struct inode *inode,struct file *file )
{
MOD_INC_USE_COUNT;
return 0;
}
static int test_release(struct inode *inode,struct file *file )
{
MOD_DEC_USE_COUNT;
return 0;
}
static int test_ioctl(struct inode *inode, struct file *file, unsigned int cmd, unsigned long arg)
{
return 0;
}
struct file_operations test_fops = {
read:test_read,
write:test_write,
open: test_open,
release:test_release,
ioctl:test_ioctl
};
int test_init(void)
{
int result;
result = register_chrdev(MAJOR_NUM, DEVICE_NAME, &test_fops);
if (result < 0) {
printk(KERN_INFO "test: can't get major number\n");
return result;
}

printk("init module\n");
return 0;

}
void test_exit(void)
{
unregister_chrdev(MAJOR_NUM,DEVICE_NAME);
printk("cleanup_module\n");
}


module_init(test_init);
module_exit(test_exit);

MODULE_LICENSE("GPL");
MODULE_AUTHOR("huangxb");
文章评论

共有 13 条评论

  1. 83.39.228.* 于 2007-07-18 17:53:09发表:

    http://e3b844f31fee15de38005a5d356cb4bd-t.xkktxb.org e3b844f31fee15de38005a5d356cb4bd http://e3b844f31fee15de38005a5d356cb4bd-b1.xkktxb.org e3b844f31fee15de38005a5d356cb4bd http://e3b844f31fee15de38005a5d356cb4bd-b3.xkktxb.org 8d1f2bfe3cbc5359328d95464cab8b7c

  2. 81.220.229.* 于 2007-07-06 00:44:52发表:

    http://51ff3b98695782f4a3f5201fdd1e828e-t.lwgmrw.org 51ff3b98695782f4a3f5201fdd1e828e http://51ff3b98695782f4a3f5201fdd1e828e-b1.lwgmrw.org 51ff3b98695782f4a3f5201fdd1e828e http://51ff3b98695782f4a3f5201fdd1e828e-b3.lwgmrw.org 7323937625928ec2c2b389a5c949efe8