如何编写Linux设备驱动程序
日期:2007年11月4日 作者: 查看:[大字体 中字体 小字体]-
#include <linux/modules.h>
#include <linux/version.h>char kernel_version [] = UTS_RELEASE;
这一段定义了一些版本信息,虽然用处不是很大,但也必不可少.Johnsonm说所有的驱动程序的开头都要包含<linux/config.h>,但我看倒是未必.
由于用户进程是通过设备文件同硬件打交道,对设备文件的操作方式不外乎就是一些系统调用,如 open,read,write,close...., 注意,不是fopen, fread,但是如何把系统调用和驱动程序关联起来呢?这需要了解一个非常关键的数据结构:
strUCt file_operations {
int (*seek) (struct inode * ,struct file *, off_t ,int);
int (*read) (struct inode * ,struct file *, char ,int);
int (*write) (struct inode * ,struct file *, off_t ,int);
int (*readdir) (struct inode * ,struct file *, struct dirent * ,int);
int (*select) (struct inode * ,struct file *, int ,select_table *);
int (*ioctl) (struct inode * ,struct file *, unsined int ,unsigned long);
int (*mmap) (struct inode * ,struct file *, struct vm_area_struct *);
int (*open) (struct inode * ,struct file *);
int (*release) (struct inode * ,struct file *);
int (*fsync) (struct inode * ,struct file *);
int (*fasync) (struct inode * ,struct file *,int);
int (*check_media_change) (struct inode * ,struct file *);
int (*revalidate) (dev_t dev);
}
这个结构的每一个成员的名字都对应着一个系统调用.用户进程利用系统调用在对设备文件进行诸如read/write操作时,系统调用通过设备文件的主设备号找到相应的设备驱动程序,然后读取这个数据结构相应的函数指针,接着把控制权交给该函数.这是linux的设备驱动程序工作的基本原理.既然是这样,则编写设备驱动程序的主要工作就是编写子函数,并填充file_operations的各个域.
相当简单,不是吗?
下面就开始写子程序.
#include <linux/types.h>
#include <linux/fs.h>
#include <linux/mm.h>
#include <linux/errno.h>
#include <asm/segment.h>
unsigned int test_major = 0;static int read_test(struct inode *node,struct file *file,
char *buf,int count)
{int left;
if (verify_area(VERIFY_WRITE,buf,count) == -EFAULT )
- 上一页 [1] [2] [3] [4] [5] 下一页
-
- 如何编写Linux设备驱动程序 相关文章:
- ·Java编写的计算器程序及源代码(1)
- ·C#编写的windows计算器-源代码
- ·Windows下C语言网络编程快速入门
- ·VBA编程简化Excel操作的两个实例
- ·ASP.NET2.0下含有DropDownList的GridView编辑、删除的完整例子!
- ·Windows编程基础 - 概述
- ·深入浅出.NET泛型编程
- ·WINDOWS编程基础
- ·linux内核编译详解
- ·剪辑数字影像 影像编辑软件大荟萃
- 如何编写Linux设备驱动程序 相关软件
- ·C语言编程宝典之一
- ·《雅奇MIS》可视化自动编程系统 V10.0
- ·MathType 数学公式编辑器 V5.2 汉化版
- ·delphi编程手册 V3.0
- ·Lrc歌词编辑器2006 V12.26
- ·Autop+线切割编程系统 V4.47
- ·vc-mfc编程实例
- ·姑妄言汇编
- ·ICO图标提取编辑专家 V4.7
- ·JP-Word简谱编辑 V3.0
- 特别声明:本站除部分特别声明禁止转载的专稿外的其他文章可以自由转载,但请务必注明出处和原始作
- 者.文章版权归文章原始作者所有.对于被本站转载文章的个人和网站,我们表示深深的谢意。如果本站转
- 载的文章有版权问题请联系编辑人员,我们尽快予以更正. 转载请注明来源:http://www.hackhome.com
上一篇:用注册表修改2k/XP默认刷新率
下一篇:Linux内核模块和驱动的编写
精品推荐
热点TOP10
- ·什么是MIS
- ·BIOS知识大全
- ·Linux操作系统源代码详细分析
- ·Linux学习手册
- ·linux知识大全
- ·Vi命令一览表
- ·Linux/Unix环境下的make命令详解
- ·Linux循序渐进(19):shell
- ·LINUX 常见问题1000个详细解答
- ·RPM命令大全
- ·Linux中QQ的配置
- ·Linux主要shell命令详解
- ·常见端口表汇总
- ·最新linux iso光盘下载点
- ·Linux发行版图标大全
- ·linux内核编译详解
- ·Linux From Scratch安装学习笔记
- ·万能声卡驱动(Alsa)的安装方法
- ·Linux下用pptp连接VPN服务器
- ·Bourne shell编程入门及脚本测试
特别推荐
- ·BIOS知识大全
- ·如何编写Linux设备驱动程序
- ·Linux管理工具介绍
- ·Linux操作系统源代码详细分析
- ·Linux下用pptp连接VPN服务器
- ·在linux7.1上安装jdk+tomcat+oracle9i笔记
- ·Linux学习手册
- ·学习Linux的八点忠告
- ·深入分析Linux防火墙
- ·UNIX系统后门的安放和日志的擦除
- ·揭开Expect的神秘面纱
- ·万能声卡驱动(Alsa)的安装方法
- ·长篇连载--arm linux演艺---序
- ·为CanonPIXMAiP1000喷墨打印机安装驱动程序
- ·详细讲解Linux系统下ADSL拨号上网方法
- ·使用ImageMagick 的提示与技巧
- ·轻松实现 Linux系统下互联网过滤功能
- ·Linux下一些故障现象以及解决的相关资源
- ·重安装gentoo 2005.1 for AMD64版经验
- ·Linux/Unix环境下的make命令详解
