设为首页 加入收藏

TOP

2.4下内核linux字符驱动模板
2014-11-23 21:57:14 】 浏览:4913
Tags:2.4 内核 linux 字符 驱动 模板

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");


】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇Fedora平台上怎样编译构建一个自.. 下一篇Ubuntu7.04 编译内核2.6.22.1

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目