版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報或認(rèn)領(lǐng)
文檔簡介
1、1實(shí)驗(yàn)內(nèi)容實(shí)驗(yàn)內(nèi)容編寫設(shè)備驅(qū)動程序編寫設(shè)備驅(qū)動程序2文件操作數(shù)據(jù)結(jié)構(gòu)文件操作數(shù)據(jù)結(jié)構(gòu)struct 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 (*sele
2、ct) (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 (
3、*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); 3相關(guān)說明相關(guān)說明p這個結(jié)構(gòu)的每一個成員的名字都對應(yīng)著一個系統(tǒng)這個結(jié)構(gòu)的每一個成員的名字都對應(yīng)著一個系統(tǒng)調(diào)用。調(diào)用。p用戶進(jìn)程利用系統(tǒng)調(diào)用在對設(shè)備文件進(jìn)行諸如用戶進(jìn)程利用系統(tǒng)調(diào)用在對設(shè)備文件進(jìn)行諸如read/write操作時,系統(tǒng)調(diào)用通
4、過設(shè)備文件的操作時,系統(tǒng)調(diào)用通過設(shè)備文件的主設(shè)備號找到相應(yīng)的設(shè)備驅(qū)動程序,然后讀取這主設(shè)備號找到相應(yīng)的設(shè)備驅(qū)動程序,然后讀取這個數(shù)據(jù)結(jié)構(gòu)相應(yīng)的函數(shù)指針,接著把控制權(quán)交給個數(shù)據(jù)結(jié)構(gòu)相應(yīng)的函數(shù)指針,接著把控制權(quán)交給該函數(shù)。該函數(shù)。p這是這是linux的設(shè)備驅(qū)動程序工作的基本原理。所的設(shè)備驅(qū)動程序工作的基本原理。所以,編寫設(shè)備驅(qū)動程序的主要工作就是編寫子函以,編寫設(shè)備驅(qū)動程序的主要工作就是編寫子函數(shù),并填充的各個域。數(shù),并填充的各個域。4mydevice.c程序示例程序示例unsigned int test_major = 0; static int read_test(struct inode *
5、node,struct file *file, char *buf,int count) int left; if (verify_area(VERIFY_WRITE,buf,count) = -EFAULT ) return -EFAULT; for(left = count ; left 0 ; left-) _put_user(1,buf,1); buf+; return count; static int write_test(struct inode *inode,struct file *file, const char *buf,int count) return count;
6、static int open_test(struct inode *inode,struct file *file ) MOD_INC_USE_COUNT; return 0; static void release_test(struct inode *inode,struct file *file ) MOD_DEC_USE_COUNT; struct test_fops = NULL, read_test, write_test, NULL, /* test_readdir */ NULL, NULL, /* test_ioctl */ NULL, /* test_mmap */ op
7、en_test, release_test, NULL, /* test_fsync */ NULL, /* test_fasync */ /* nothing more, fill with NULLs */ ; 5重新編譯內(nèi)核重新編譯內(nèi)核p把把mydevice.c放在相應(yīng)的字符設(shè)備驅(qū)動程序所放在相應(yīng)的字符設(shè)備驅(qū)動程序所在目錄,并修改該目錄的在目錄,并修改該目錄的Makefile文件。文件。p6添加設(shè)備文件添加設(shè)備文件pmknod /dev/mydevice c 231 07測試測試pmain() int testdev; int i; char buf10; testdev = open(/dev/mydevice,O_RDWR); if ( testdev = -1 ) printf(Cannt
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- Mumeose-K-生命科學(xué)試劑-MCE-2774
- 5-Fluoro-THJ-生命科學(xué)試劑-MCE-6389
- 2025年度環(huán)保型空調(diào)拆卸作業(yè)安全協(xié)議書
- 2025年度文化創(chuàng)意產(chǎn)業(yè)居間代理協(xié)議
- 二零二五年度父母出資購房子女房產(chǎn)份額分配協(xié)議
- 2025年度無房產(chǎn)證房屋買賣風(fēng)險評估合同
- 二零二五年度砍樹承包合同及林業(yè)資源管理實(shí)施協(xié)議
- 二零二五年度企業(yè)食堂檔口租賃合同與員工餐飲補(bǔ)貼協(xié)議
- 高標(biāo)準(zhǔn)實(shí)驗(yàn)環(huán)境下的安全防護(hù)措施探討
- 臨時用電安全合同協(xié)議
- 設(shè)計(jì)單位-質(zhì)量管理體系
- 2024版《供電營業(yè)規(guī)則》學(xué)習(xí)考試題庫500題(含答案)
- 福建省醫(yī)院大全
- GB/T 16659-2024煤中汞的測定方法
- 閃蒸罐計(jì)算完整版本
- (高清版)DZT 0073-2016 電阻率剖面法技術(shù)規(guī)程
- 完整2024年開工第一課課件
- 貨運(yùn)車輛駕駛員安全培訓(xùn)內(nèi)容資料完整
- 高一學(xué)期述職報告
- 風(fēng)神汽車4S店安全生產(chǎn)培訓(xùn)課件
- ICU患者的體位轉(zhuǎn)換與床旁運(yùn)動訓(xùn)練
評論
0/150
提交評論