實驗七驅(qū)動程序結(jié)構_第1頁
實驗七驅(qū)動程序結(jié)構_第2頁
實驗七驅(qū)動程序結(jié)構_第3頁
實驗七驅(qū)動程序結(jié)構_第4頁
實驗七驅(qū)動程序結(jié)構_第5頁
已閱讀5頁,還剩2頁未讀 繼續(xù)免費閱讀

付費下載

下載本文檔

版權說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權,請進行舉報或認領

文檔簡介

實驗七驅(qū)動程序結(jié)構實驗主要是驅(qū)動程序的增加。雖然Linux內(nèi)核的不斷升級,但驅(qū)動程序的結(jié)構還是相對穩(wěn)定。Linux系統(tǒng)的設備分為字符設備(chardevice),塊設備(blockdevice)和網(wǎng)絡設備(network且塊設備必須能夠隨機存取(randomaccess)。典型的字符設備包括鼠標,鍵盤,串行口等。塊設備主要包括硬盤軟盤設備,CD-ROM等。Linux里做專門的處理。LinuxBSDunixsocket7-1LinuxLinux系統(tǒng)啟動之后能夠動態(tài)進行裝載和卸載,因此不需對內(nèi)核進行重新編譯或重啟系統(tǒng)就可將內(nèi)核的一部分替換掉,Linux內(nèi)核的所有設備驅(qū)動,文件系統(tǒng),網(wǎng)絡協(xié)議等可做成模塊的形式來提供。在所有的模果不一樣就會出錯,當然可以在模塊程序中的include<linux/module.h>之前通過宏定義#defineNO_VERSION表明不定義模塊的版本信息。register_capability(cleanup_module(init_module(unregister_capability(register_capability(cleanup_module(init_module(unregister_capability(....

7-2 Mknod命令必須要有設備名和設備類型,主設備號(MajorNumber,次設備號(Minor個設備驅(qū)動可能控制多個設備。新的設備驅(qū)動要有新的主設備號。在內(nèi)核源代碼的ationdevices.txt中定義了所有設備的主設備號。在創(chuàng)建設備的時候不要與常用的下面/dev/hda1是設備名,b表示block設備(c表示字符設備)。1271是次設備號。次設備號可以是0255之間的值,限制為8bit。[root@localhost]$mknod [root@localhost]$ls–al/dev/hda1 /*/*staticintxxx_open(structinode*inode,structfile{}/*staticintxxx_read(structinode*inode,structfile{}/*staticintxxx_write(structinode*inode,structfile{}/*staticintxxx_ioctl(structinode*inode,structfile{}/*staticvoidxxx_interrupt(intirq,void*dev_id,structpt_regs{/*...}/*staticstructfile_operationsxxx_fops=staticintinitxxx_init_module{/*...}staticvoidexitdemo_cleanup_module{}/*加載驅(qū)動程序模塊 /*卸載驅(qū)動程序模 /*讀設備操作/*寫設備操作/*控制設備操作/*打開設備操作/*.../*釋放設備操作struct{structmoduleloff_t(*llseek)(structfile*,struct{structmoduleloff_t(*llseek)(structfile*,loff_t,ssize_t(*read)(structfile*,char*,size_t,loff_t*);ssize_t(*write)(structfile*,constchar*,size_t,loff_t*);int(*readdir)(structfile*,void*,filldir_t);unsignedint(*poll)(structfile*,structpoll_table_structint(*ioctl)(structinode*,structfile*,unsignedint,unsignedlong);int(*mmap)(structfile*,structvm_area_struct*);int(*open)(structinode*,structfile*);int(*flush)(structfile*);int(*release)(structinode*,structfileint(*fsync)(structfile*,structdentry*,intdatasync);int(*fasync)(int,structfile*,int);int(*lock)(structfile*,int,structfile_lockssize_t(*readv)(structfile*,conststructiovec*,unsignedlong,loff_t*);ssize_t(*writev)(structfile*,conststructiovec*,unsignedlong,loff_t*);ssize_t(*sendpage)(structfile*,structpage*,int,size_t,loff_t*,int);unsignedlong(*get_unmapped_area)(structfile*,unsignedlong,unsignedlong,unsignedlong,unsignedlong);Fileopen時被內(nèi)核創(chuàng)建,并傳遞給在該文件上進行操作的structstructfilestructdentrystructstructfile_operations*f_op; unsigned unsignedlong structfown_struct unsigned f_uid, unsigned /*neededforttydriver,andmaybeothers*/ /*preallocatedhelperkiobuftospeedupO_DIRECT*/structkiobuf intxxx_open(intxxx_open(structinode*inode,structfile*filp);intxxx_release(structinode*inode,strucfile*filp);ssize_txxx_read(structfile*filp,char*buff,size_tcount,loff_t*offp);ssize_txxx_write(structfile*filp,constchar*buff,size_tcount,loff_t*offp);…1Linux操作系統(tǒng)的PC2、XSBase270或XSBase255ARM#include<linux/stringh>#include<linux/stringh>#include<linux/fsh>#include<linux/init.h>#include<linux/typesh>#include<linux/fsh>staticintinit{{printk("Thisisasimpledriver-}staticvoidexit{printk("Goodbyedriver-}CFLAGS=-

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
  • 4. 未經(jīng)權益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責。
  • 6. 下載文件中如有侵權或不適當內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

最新文檔

評論

0/150

提交評論