分页: 1 / 1

Ubuntu10.10下的模块编程

发表于 : 2010-12-30 0:03
poweryuai
testmodule.c文件:
#include // 在内核模块中共享
#include // 一个模块
//处理CONFIG_MODVERSIONS
#if CONFIG_MODVERSIONS == 1
#define MODVERSIONS
#include
#endif
int init_module() //初始化模块
{
120
printk("Hello! This is a testing module! \n");
return 0;
}
void cleanup_module() //取消init_module()函数所做的打印功能操作
{
printk("Sorry! The testing module is unloading now! \n");
}

向模块中添加新函数
向testmodule模块中添加新函数open(),release(),write()和read().
一.函数open( )
int open(struct inode *inode,struct file *filp) {
MOD_INC_USE_COUNT; // 增加该模块的用户数目
printk("This module is in open!\n");
return 0;
}
二.函数release( )
void release(struct inode *inode,struct file *filp) {
MOD_DEC_USE_COUNT; //该模块的用户数目减1
printk("This module is in release!\n");
return 0;
#ifdef DEBUG
printk("release(%p,%p)\n",inode,filp);
#endif
}
三.函数 read()
int read(struct inode *inode,struct file *filp,char *buf,int count) {
123
int leave;
if(verify_area(VERIFY_WRITE,buf,count) == DEFAULT)
return DEFAULT;
for(leave=count;leave>0;leave --) {
__put_user(1,buf,1);
buf ++;
}
return count;
}
四.函数write()
int write(struct inode *inode,struct file *filp,const char *buf,int count) {
return count;
}

小弟初学linux,请问这个模块实验怎么做呀,网上都很少资料的,找到的都是只有这个题目的,根本做不下去,请各位大大帮帮忙~~感激不尽~~