⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ramdisk.c

📁 VxWorks下有关创建虚拟磁盘(即划分一块内存空间为虚拟磁盘使用)的源程序和工程文件
💻 C
字号:
/*
-> InitRamFsEnv("ram:/data",3*1024*1024) 
Retrieved old volume params with %33 confidence:
Volume Parameters: FAT type: FAT32, sectors per cluster 0
  0 FAT copies, 0 clusters, 0 sectors per FAT
  Sectors reserved 0, hidden 0, FAT sectors 0
  Root dir entries 0, sysId (null)  , serial number 54f0000
  Label:"           " ...
Disk with 6144 sectors of 512 bytes will be formatted with:
Volume Parameters: FAT type: FAT12, sectors per cluster 2
  2 FAT copies, 3046 clusters, 9 sectors per FAT
  Sectors reserved 1, hidden 0, FAT sectors 18
  Root dir entries 512, sysId VXDOS12 , serial number 54f0000
  Label:"           " ...
value = 3145728 = 0x300000
-> DeleteRamDisk("ram:/data")
value = 0 = 0x0
*/
#include "vxWorks.h"
#include "drv/hdisk/ataDrv.h"
#include "string.h"
#include "stdlib.h"
#include "stdio.h"
#include "ioLib.h"
#include "iosLib.h"

#define CreateRamDiskTest

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);
	/* dosFsLibInit(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)
{

#ifdef CreateRamDiskTest

	STATUS iReturn = CreateRamDisk(name,size) ;
	
	if (ERROR!=iReturn) ioDefPathSet(name) ;
	
	return iReturn ;
#else 
        BLK_DEV *pBlkDev;
        DOS_VOL_DESC *pVolDesc;

        pBlkDev = ramDevCreate (0,  512,  400,  400,  0);
        pVolDesc = dosFsMkfs ("DEV1:", pBlkDev);

        if (NULL==pVolDesc)
	{ 
	    fprintf(stderr,"Can not create ram-dos-fs.\n") ;
	    return ERROR ;
	}

    return TRUE;
#endif

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -