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

📄 ramdisk.c

📁 在VxWorks 5.5环境创建Ram Disk文件系统!
💻 C
字号:

#ifndef RAMDISK_VERSION
#define RAMDISK_VERSION "1.01 Built By GongHuiBin"
#endif // RAMDISK_VERSION

#include "vxWorks.h"
#include "stdio.h"
#include "ramDrv.h"
#include "iosLib.h"
#include "dosFsLib.h"
/*#include <alloc.h>*/


/**********************************************************************
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 = 0;
	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;
}



⌨️ 快捷键说明

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