基于RAM的文件系统的实现
如果的系统上安装有硬盘,则在BSP中装载你的硬盘驱动即可。如果没有,建议建立基于RAM的文件系统。建立RAM文件系统的方式如下:
#ifndef RAMDISK_VERSION
#define RAMDISK_VERSION "1.0 built by tiefeng@vip.sina.com"
#endif // RAMDISK_VERSION
#include
#include
#include
#include
#include
#include
/**********************************************************************
Function: Create a ram disk device
Parameters:
name -> device name, such as "ramdisk0:".
size -> block device size.
Returned:
The actualy disk size. Or ERROR.
**********************************************************************/
STATUS CreateRamDisk(char * name,int size)
{
int nBlock = NULL ;
BLK_DEV * pBlkDev = NULL ;
DOS_VOL_DESC * pVolDesc = NULL ;
// the disksize should be integral multiple of the blocksize.
size = size - size%512 ;
nBlock = size/512 ;
// You can simultaneously open 20 files
dosFsInit(20) ;
// Create a ram-disk.
// The base address is the return value of alloc.
// The block size is 512.
// nBlock blocks per track
// Total nBlock blocks.
// The base address offset is 0.
pBlkDev = ramDevCreate(0,512,nBlock,nBlock,0) ;
if (NULL==pBlkDev)
{
fprintf(stderr,"Can not create ram block device.\n") ;
return ERROR ;
}
// Make DOSFS by a ram block device.
pVolDesc = dosFsMkfs(name,pBlkDev) ;
if (NULL==pVolDesc)
{
fprintf(stderr,"Can not create ram-dos-fs.\n") ;
return ERROR ;
}
// The size is actualy disk size.
return size ;
}
/**********************************************************************
Function: Delete a ram disk device
Parameters:
name -> device name, such as "ramdisk0:".
Returned:
Return OK if the device is removed successfuly.
Otherwise return ERROR.
**********************************************************************/
STATUS DeleteRamDisk(char * name)
{
DEV_HDR * pDevHdr = NULL ;
// Find ram-disk device by name
if ( NULL==(pDevHdr="iosDevFind"(name,NULL)) )
{
fprintf(stderr,"Can not find device (%s).\n",name) ;
return ERROR ;
}
// Delete the device and free the alloced memory
iosDevDelete(pDevHdr) ;
free(pDevHdr) ;
return OK ;
}
/**********************************************************************
Function: Create a ram disk device & set is as default path.
Parameters:
name -> device name, such as "ramdisk0:".
size -> block device size.
Returned:
The actualy disk size. Or ERROR.
**********************************************************************/
STATUS InitRamFsEnv(char * name,int size)
{
STATUS iReturn = CreateRamDisk(name,size) ;
if (ERROR!=iReturn) ioDefPathSet(name) ;
return iReturn ;
}
文章评论(0条评论)
登录后参与讨论