📄 ramdisk.c
字号:
/************************************************************************
*
* Copyright (c) 2002 by Accelerated Technology, Inc.
*
* PROPRIETARY RIGHTS of Accelerated Technology are involved in
* the subject matter of this material. All manufacturing,
* reproduction, use, and sales rights pertaining to this subject
* matter are governed by the license agreement. The recipient of
* this software implicitly accepts the terms of the license.
*
*
*************************************************************************
*************************************************************************
* FILE NAME VERSION
*
* RAMDISK.C FILE 2.3.2
*
* COMPONENT
*
* Nucleus File
*
* DESCRIPTION
*
* Provides a configurable ram drive capability.
*
* In an earlier version we allocated a linear array. We have
* changed this to a paged approach. This allows us to create
* larger ramdisks on segmented (INTEL) systems. It could even be
* modified to work with EMS or XMS pretty easily now.
*
* To use this utility you must port two functions and provide two
* constants.
*
* DATA STRUCTURES
*
* None.
*
* FUNCTIONS
*
* These three driver entry points are plugged into the pc_bdevsw
* table in devtable.c
*
* pc_rd_raw_open Always fails. No need for it.
* pc_rd_open Open the ram disk. (called
* when a file system is
* mounted.)
* pc_rd_io Ram disk block io routine.
* pc_rd_close Close the ramdisk. Called
* when a file system is
* unmounted.
*
* DEPENDENCIES
*
* nucleus.h System definitions
* pcdisk.h File common definitions
*
* NOTE: This module is linked in with File.lib. After you make *
* changes, you must rebuild File.lib. *
*******************************************************************/
#include "plus\nucleus.h"
#if (0) /* MNT port */
#include <time.h>
#include "hardware.h"
#endif
#include "file\pcdisk.h"
#if (!RAMDISK_FROMPOOL)
/* We will use malloc */
#include <stdio.h>
#include <stdlib.h>
#endif /* !RAMDISK_FROMPOOL */
#if (RAMDISK_FROMPOOL)
NU_PARTITION_POOL NUF_RAMDISK_PARTITION;
#endif
/* Global data definitions. */
UINT8 *rd_pages[NUM_RAMDISK_PAGES] = {0};
UINT16 rd_opencount = 0;
/************************************************************************
* FUNCTION
*
* rd_alloc_page
*
* DESCRIPTION
*
* This function allocates one page of memory from a Nucleus
* fixed partition.
*
* AUTHOR
*
* Takahiro Takahashi
*
* INPUTS
*
* None.
*
* OUTPUTS
*
* Pointer to the page allocated.
*
*************************************************************************/
UINT8 *rd_alloc_page(VOID)
{
STATUS status;
#if (RAMDISK_FROMPOOL)
UINT8 *mem_address;
/* Allocate a page. */
status = NU_Allocate_Partition(&NUF_RAMDISK_PARTITION, (VOID **)&mem_address,
NU_NO_SUSPEND);
if (status == NU_SUCCESS)
return(mem_address);
else
return((UINT8 *)0);
#else /* not RAMDISK_FROMPOOL */
/* Using MALLOC instead of Allocate_Partition */
UINT8 *mem_address;
OPTION preempt_status;
/* Don't let anyone interfere with the malloc. Anticpating DOS non-
reentrancy. */
preempt_status = NU_Change_Preemption(NU_NO_PREEMPT);
/* Get the memory. */
mem_address = (UINT8 *)malloc(NUF_RAMDISK_PARTITION_SIZE);
/* Others can take over now since the malloc is complete. */
NU_Change_Preemption(preempt_status);
return(mem_address);
#endif /* RAMDISK_FROMPOOL */
}
/************************************************************************
* FUNCTION
*
* rd_freec_page
*
* DESCRIPTION
*
* This function deallocates one page of memory from a Nucleus
* fixed partition.
*
* AUTHOR
*
* Takahiro Takahashi
*
* INPUTS
*
* *page Pointer to memory to be
* deallocated.
*
* OUTPUTS
*
* Pointer to the page allocated.
*
*************************************************************************/
VOID rd_free_page(UINT8 *page)
{
#if (RAMDISK_FROMPOOL)
/* If the input parameter is valid, deallocate. */
if (page)
NU_Deallocate_Partition((VOID *)page);
#else
/* Using free() instead of dealloc */
OPTION preempt_status;
/* Don't let anyone interfere with the malloc. Anticpating DOS non-
reentrancy. */
preempt_status = NU_Change_Preemption(NU_NO_PREEMPT);
/* If the input is valid, deallocate the page. */
if (page)
free(page);
/* Others can take over now since the malloc is complete. */
NU_Change_Preemption(preempt_status);
#endif
}
/************************************************************************
* FUNCTION
*
* pc_rd_ioctl
*
* DESCRIPTION
*
* This function doesn't do anything for the RAM Disk. It is
* included for devtable consistency.
*
* AUTHOR
*
* Takahiro Takahashi
*
* INPUTS
*
* None.
*
* OUTPUTS
*
* None.
*
*************************************************************************/
INT pc_rd_ioctl(UINT16 driveno, UINT16 command, VOID *buffer)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -