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,请问这个模块实验怎么做呀,网上都很少资料的,找到的都是只有这个题目的,根本做不下去,请各位大大帮帮忙~~感激不尽~~
Ubuntu10.10下的模块编程
内核编译和嵌入式产品的设计与开发
前往
- 公告/注意事项
- ↳ 新闻和通知
- ↳ 软件推荐
- 系统安装
- ↳ 教学和常见问答
- ↳ 系统安装和升级
- ↳ 启动和引导
- ↳ 网卡无线拨号
- ↳ 硬件与内核
- ↳ 笔记本及便携设备
- ↳ Ubuntu衍生版
- ↳ 其他类Unix OS发行版
- ↳ Debian发行版
- 配置美化
- ↳ 中文显示和输入法
- ↳ 个人配置文件存放点
- ↳ 软件文档翻译
- ↳ 窗口管理器及美化
- ↳ 桌面展示
- 软件使用
- ↳ 办公、图像、机械电子设计等
- ↳ Vim和Emacs
- ↳ 开源模板库
- ↳ 互联网相关软件
- ↳ 影音多媒体
- ↳ 游戏和模拟器
- ↳ 虚拟机和虚拟化
- ↳ Wine及其分支
- ↳ 其它类软件
- 服务器管理
- ↳ 服务器运维
- ↳ 云计算和容器(K8S/KVM/Docker/WSL等)
- ↳ Ubuntu VPS
- 程序设计与开发
- ↳ Shell脚本
- ↳ 软件/网站开发
- ↳ 内核及嵌入式开发
- ↳ Ubuntu编译和打包
- ↳ 开源小工具
- ↳ 挑战任务
- 感想与交流
- ↳ 深度PK版
- ↳ Ubuntu故事和感慨
- ↳ 同城交流
- ↳ 校园社团
- ↳ 港澳台校区
- ↳ 国外校区
- 站务区
- ↳ 论坛管理
- ↳ Ubuntu中文网上商店