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

📄 ramdisk.c

📁 嵌入式操作系统Nucleus Plus中使用的文件系统
💻 C
📖 第 1 页 / 共 3 页
字号:
/*
* EBS - RTFS (Real Time File Manager)
*
* Copyright Peter Van Oudenaren , 1993
* All rights reserved.
* This code may not be redistributed in source or linkable object form
* without the consent of its author.
*/
/*************************************************************************/
/*                                                                       */
/*            Copyright (c) 1999 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  RAMDISK.C                                VERSION 1.0       */
/*                                                                       */
/*                                                                       */
/* COMPONENT                                                             */
/*                                                                       */
/* 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.                                                           */
/*                                                                       */
/*  The functions are:                                                   */
/*                                                                       */
/*      1. UTINY FAR * rd_alloc_page()                                   */
/*                                                                       */
/*      2. VOID rd_free_page(UTINY FAR *page)                            */
/*                                                                       */
/*      Porting them is very straightfoward.                             */
/*                                                                       */
/*  The constants are:                                                   */
/*                                                                       */
/*  NUM_RAMDISK_PAGES - Number of pages of memory to allocate            */
/*  RAMDISK_PAGE_SIZE - Page size in 512 bytes blocks. On INTEL this     */
/*                      may not exceed 128.                              */
/*                                                                       */
/*  The operation NUM_RAMDISK_PAGES * RAMDISK_PAGE_SIZE determines the   */
/*  number of blocks total in the ramdisk.                               */
/*                                                                       */
/*    THESE CONSTANTS ARE DEFINED IN PCDISK.H                            */
/*                                                                       */
/*                                                                       */
/* AUTHOR                                                                */
/*                                                                       */
/*  Peter Van Oudenaren                                                  */
/*                                                                       */
/* DATA STRUCTURES                                                       */
/*                                                                       */
/*      None                                                             */
/*                                                                       */
/* FUNCTIONS                                                             */
/*                                                                       */
/*  These three driver entry points are plugged into the pc_bdevsw table */
/*    in devtable.c                                                      */
/*                                                                       */
/*  BOOL pc_rd_raw_open(UCOUNT driveno)- Always fails. No need for it.   */
/*                                                                       */
/*  BOOL pc_rd_open(UCOUNT driveno)   - Open the ram disk. (called when a*/
/*                                        file system is mounted.)       */
/*                                                                       */
/*  BOOL pc_rd_io(UCOUNT driveno, ULONG block, VOID *buffer, UCOUNT count*/
/*                BOOL reading)       - ram disk block io routine.       */
/*                                                                       */
/*  VOID pc_rd_close(UCOUNT driveno)  - Close the ramdisk. Called when a */
/*                                        file system is unmounted.      */
/*                                                                       */
/* DEPENDENCIES                                                          */
/*                                                                       */
/* HISTORY                                                               */
/*                                                                       */
/*         NAME            DATE                    REMARKS               */
/*                                                                       */
/*                                                                       */
/*************************************************************************/

#include "pcdisk.h"

#if  (PLUS)
#include "nucleus.h"

#if (!RAMDISK_FROMPOOL)
/* We will use malloc */
#include <stdio.h>
#include <stdlib.h>
#endif  /* !RAMDISK_FROMPOOL */

#else   /*  RTX */
#include "nu_defs.h"
#include "nu_proto.h"
#endif  /*  PLUS  */

/*  Internal Prototypes.  */
BOOL        pc_rd_ioctl(UCOUNT driveno, UCOUNT command, VOID *buffer);
BOOL        pc_rd_raw_open(UCOUNT driveno);
BOOL        pc_rd_open(UCOUNT driveno);
BOOL        pc_rd_close(UCOUNT driveno);
BOOL        pc_rd_block_io(UCOUNT driveno, ULONG block, void FAR *buffer,
                           UCOUNT count, BOOL reading);

UTINY FAR   *rd_alloc_page(VOID);
VOID        rd_free_page(UTINY FAR *page);

/*  Global data definitions.  */
UTINY FAR   *rd_pages[NUM_RAMDISK_PAGES] = {0};
COUNT       rd_opencount = 0;


/*************************************************************************/
/*                                                                       */
/* FUNCTION                                      rd_alloc_page           */
/*                                                                       */
/* DESCRIPTION                                                           */
/*                                                                       */
/*      This function allocates one page of memory from a Nucleus        */
/*      fixed partition.                                                 */
/*                                                                       */
/* AUTHOR                                                                */
/*                                                                       */
/*      Peter Van Oudenaren                                              */
/*                                                                       */
/* CALLED BY                                                             */
/*                                                                       */
/*      pc_rd_open                                                       */
/*                                                                       */
/* CALLS                                                                 */
/*                                                                       */
/*      NU_Allocate_Partition (PLUS)                                     */
/*      NU_Change_Preemption (PLUS)                                      */
/*      malloc                                                           */
/*      NU_Alloc_Partition (RTX)                                         */
/*                                                                       */
/* INPUTS                                                                */
/*                                                                       */
/*      none                                                             */
/*                                                                       */
/* OUTPUTS                                                               */
/*                                                                       */
/*      pointer to the page allocated                                    */
/*                                                                       */
/* HISTORY                                                               */
/*                                                                       */
/*         NAME            DATE                    REMARKS               */
/*                                                                       */
/*         P. Van Oudenaren                        Initial Version       */
/*         N. Henderson    02/18/94                Cleanup               */
/*************************************************************************/

UTINY FAR *rd_alloc_page()                      /* __fn__ */
{
    int status;
#if  (PLUS)

#if (RAMDISK_FROMPOOL)

    UCOUNT *mem_address;

    /*  Allocate a page.  */
    status = NU_Allocate_Partition(&NUF_RAMDISK_PARTITION, (VOID **)&mem_address,
                          NU_NO_SUSPEND);

    if (status == NU_SUCCESS)
        return ((UTINY FAR *) mem_address);
    else
        return((UTINY FAR *)0);

#else  /*  not RAMDISK_FROMPOOL  */
	
    /* Using MALLOC instead of Allocate_Partition */
    UTINY FAR   *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 = 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  */

#else  /* RTX */

⌨️ 快捷键说明

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