open系统调用在内核中的流程分析.doc

open系统调用在内核中的流程分析.doc

ID:57672201

大小:32.00 KB

页数:7页

时间:2020-08-31

open系统调用在内核中的流程分析.doc_第1页
open系统调用在内核中的流程分析.doc_第2页
open系统调用在内核中的流程分析.doc_第3页
open系统调用在内核中的流程分析.doc_第4页
open系统调用在内核中的流程分析.doc_第5页
资源描述:

《open系统调用在内核中的流程分析.doc》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库

1、一)驱动注册open函数都干了些什么?register_chrdev->cdev_add->kobj_mapfile:fs/char_dev.cintregister_chrdev(unsignedintmajor,constchar*name,conststructfile_operations*fops){structchar_device_struct*cd;structcdev*cdev;char*s;interr=-ENOMEM;cd=__register_chrdev_region(major,0,256,name);if(IS

2、_ERR(cd))returnPTR_ERR(cd);cdev=cdev_alloc();if(!cdev)gotoout2;cdev->owner=fops->owner;cdev->ops=fops;//注意,在后面的chrdev_open会从cdev再得到fops...}file:fs/char_dev.cintcdev_add(structcdev*p,dev_tdev,unsignedcount){p->dev=dev;p->count=count;returnkobj_map(cdev_map,dev,count,NULL,ex

3、act_match,exact_lock,p);}file:fs/char_dev.cstaticstructkobject*exact_match(dev_tdev,int*part,void*data){structcdev*p=data;return&p->kobj;}file:drivers/base/map.cintkobj_map(structkobj_map*domain,dev_tdev,unsignedlongrange,structmodule*module,kobj_probe_t*probe,int(*lock)(d

4、ev_t,void*),void*data){unsignedn=MAJOR(dev+range-1)-MAJOR(dev)+1;unsignedindex=MAJOR(dev);unsignedi;structprobe*p;if(n>255)n=255;p=kmalloc(sizeof(structprobe)*n,GFP_KERNEL);if(p==NULL)return-ENOMEM;for(i=0;iowner=module;p->get=probe;//此处其实就是exact_matchp->loc

5、k=lock;p->dev=dev;p->range=range;p->data=data;}mutex_lock(domain->lock);for(i=0,p-=n;iprobes[index%255];while(*s&&(*s)->rangenext;p->next=*s;*s=p;}mutex_unlock(domain->lock);return0;}【参考UnderstandingTheLinuxKernel

6、13.5.CharacterDeviceDrivers】Thedevicedrivermodeldefinesakobjectmappingdomainforthecharacterdevices,whichisrepresentedbyadescriptoroftypekobj_mapandisreferencedbythecdev_mapglobalvariable.Thekobj_mapdescriptorincludesahashtableof255entriesindexedbythemajornumberoftheinterva

7、ls.Thehashtablestoresobjectsoftypeprobe,oneforeachregisteredrangeofmajorandminornumbers,whosefieldsarelistedinTable13-9.Whenthekobj_map()functionisinvoked,thespecifiedintervalofdevicenumbersisaddedtothehashtable.Thedatafieldofthecorrespondingprobeobjectpointstothecdevdescr

8、iptorofthedevicedriver.Thevalueofthisfieldispassedtothegetandlockmethodswhentheyareexecut

当前文档最多预览五页,下载文档查看全文

此文档下载收益归作者所有

当前文档最多预览五页,下载文档查看全文
温馨提示:
1. 部分包含数学公式或PPT动画的文件,查看预览时可能会显示错乱或异常,文件下载后无此问题,请放心下载。
2. 本文档由用户上传,版权归属用户,天天文库负责整理代发布。如果您对本文档版权有争议请及时联系客服。
3. 下载前请仔细阅读文档内容,确认文档内容符合您的需求后进行下载,若出现内容与标题不符可向本站投诉处理。
4. 下载文档时可能由于网络波动等原因无法下载或下载错误,付费完成后未能成功下载的用户请联系客服处理。