




版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報(bào)或認(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這個(gè)結(jié)構(gòu)的每一個(gè)成員的名字都對應(yīng)著一個(gè)系統(tǒng)這個(gè)結(jié)構(gòu)的每一個(gè)成員的名字都對應(yīng)著一個(gè)系統(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操作時(shí),系統(tǒng)調(diào)用通
4、過設(shè)備文件的操作時(shí),系統(tǒng)調(diào)用通過設(shè)備文件的主設(shè)備號找到相應(yīng)的設(shè)備驅(qū)動程序,然后讀取這主設(shè)備號找到相應(yīng)的設(shè)備驅(qū)動程序,然后讀取這個(gè)數(shù)據(jù)結(jié)構(gòu)相應(yīng)的函數(shù)指針,接著把控制權(quán)交給個(gè)數(shù)據(jù)結(jié)構(gòu)相應(yīng)的函數(shù)指針,接著把控制權(quán)交給該函數(shù)。該函數(shù)。p這是這是linux的設(shè)備驅(qū)動程序工作的基本原理。所的設(shè)備驅(qū)動程序工作的基本原理。所以,編寫設(shè)備驅(qū)動程序的主要工作就是編寫子函以,編寫設(shè)備驅(qū)動程序的主要工作就是編寫子函數(shù),并填充的各個(gè)域。數(shù),并填充的各個(gè)域。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)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 河南省安陽市文峰區(qū)2024-2025學(xué)年九年級上學(xué)期1月期末化學(xué)試題(含答案)
- 2019-2025年軍隊(duì)文職人員招聘之軍隊(duì)文職政治學(xué)能力檢測試卷B卷附答案
- 臨床急救知識培訓(xùn)課件
- 酒吧員工禁止戀愛合同(2篇)
- 2025年反電信網(wǎng)絡(luò)詐騙法測試題庫及參考答案
- 自體輸血知識培訓(xùn)課件
- 農(nóng)資產(chǎn)品經(jīng)銷代理合作協(xié)議
- 共享單車租賃服務(wù)協(xié)議
- 睡前故事故事解讀
- 遼寧省大連市2024-2025學(xué)年高一上學(xué)期1月期末考試生物學(xué)試題(含答案)
- 2024-2025學(xué)年七年級地理下冊 7.4 俄羅斯課時(shí)1說課稿 (新版)新人教版
- 2024年浙江省金華市少年兒童圖書館招聘編外人員1人歷年高頻難、易錯(cuò)點(diǎn)500題模擬試題附帶答案詳解
- 2025年上海市中考語文備考之記敘文十大考點(diǎn)梳理(附??季毩?xí)及參考答案)
- 校園餐專項(xiàng)整治行動工作方案
- DB3417-T 031-2024 學(xué)校食堂場所布局設(shè)置規(guī)范
- 《孤獨(dú)癥譜系障礙:家長及專業(yè)人員指南》筆記
- 2024年全國職業(yè)院校技能大賽高職組(檢驗(yàn)檢疫技術(shù)賽項(xiàng))考試題庫(含答案)
- 博士后研究報(bào)告(出站)
- 2024年單招考試題
- 反賄賂與反腐敗管理制度
- 鄉(xiāng)村振興相關(guān)知識備考試題庫(含答案)
評論
0/150
提交評論