繁体中文
高级搜索
 
首页 | 电子技术应用 | 行业最新动态 | 行业最新产品 | 软件资料下载 | 电路图纸欣赏 | 博客文章精选 | 电子精品论坛 | 电子技术贴吧

当前位置:首页 >> 博客文章精选 >> 嵌入式系统-博客 >> vxworks基于RAM的文件系统的实现
vxworks基于RAM的文件系统的实现
作者:   来源: 发表时间:2006-12-08  字号:  
基于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 - sizeQ2 ;
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 ;
}


!注意:如果您发现此文章出现影响您的阅读的状况,请从浏览器地址栏里复制本文的链接到留言本报告给站长解决!
  • 上一篇: 2005年HMI行业应用分析[工控网络资料总结和分享]
  • 下一篇: 为arm,51与优盘进行串口通信的东东

  • >> 联系我们请给我们留言·留言本
    本站所有提供的信息软件资料均来自网络,版权及著作权归原作者所有,如果无意中侵犯了您的相关权利或触及法律法规,请给我们留言, 我们将在24小时内删除。
      浙ICP备05071687号  电子技术精品网