欢迎来到天天文库
浏览记录
ID:10334800
大小:57.00 KB
页数:4页
时间:2018-07-06
《基于ram的文件系统的实现》由会员上传分享,免费在线阅读,更多相关内容在工程资料-天天文库。
1、基于RAM的文件系统的实现
2、第1内容显示中如果的系统上安装有硬盘,则在BSP中装载你的硬盘驱动即可。如果没有,建议建立基于RAM的文件系统。建立RAM文件系统的方式如下:#ifndefRAMDISK_VERSION#defineRAMDISK_VERSION"1.0builtbytiefengvip.sina."#endif//RAMDISK_VERSION#include#include#include#include/**********************************************************************Function:Creat
3、earamdiskdeviceParameters:name->devicename,suchas"ramdisk0:".size->blockdevicesize.Returned:Theactualydisksize.OrERROR.**********************************************************************/STATUSCreateRamDisk(char*name,intsize){intnBlock=NULL;BLK_DEV*pBlkDev=NULL;DOS_VOL_DESC*pVolDesc=NULL
4、;//thedisksizeshouldbeintegralmultipleoftheblocksize.size=size-size%512;nBlock=size/512;//Youcansimultaneouslyopen20filesdosFsInit(20);//Createaram-disk.//Thebaseaddressisthereturnvalueofalloc.//Theblocksizeis512.//nBlockblockspertrack//TotalnBlockblocks.//Thebaseaddressoffsetis0.pBlkDev=ramDevCr
5、eate(0,512,nBlock,nBlock,0);if(NULL==pBlkDev){fprintf(stderr,"Cannotcreateramblockdevice./n");returnERROR;}//MakeDOSFSbyaramblockdevice.pVolDesc=dosFsMkfs(name,pBlkDev);if(NULL==pVolDesc){fprintf(stderr,"Cannotcreateram-dos-fs./n");returnERROR;}//Thesizeisactualydisksize.returnsize;}/************
6、**********************************************************Function:DeletearamdiskdeviceParameters:name->devicename,suchas"ramdisk0:".Returned:ReturnOKifthedeviceisremovedsuccessfuly.OtherDisk(char*name){DEV_HDR*pDevHdr=NULL;//Findram-diskdevicebynameif(NULL==(pDevHdr=iosDevFind(name,NULL))){fp
7、rintf(stderr,"Cannotfinddevice(%s)./n",name);returnERROR;}//DeletethedeviceandfreetheallocedmemoryiosDevDelete(pDevHdr);free(pDevHdr);returnOK;}/**********************************************************************Function:Createaramdiskdevicesetisasdefaultpath.Parameters:name->devicename,suc
8、has"ramdisk0:".size->blockdevicesize.Returned:Theactualydisksize.OrERROR.**********************************************************************/STATUSInitRamFsEnv(char*name,intsize){STATUSiReturn=CreateRamDisk(name,
此文档下载收益归作者所有