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

📄 ramdisk.c

📁 nucleus 文件系统,内核和彩色图形系统,在小系统上非常好用
💻 C
📖 第 1 页 / 共 3 页
字号:
/*                                                                       */
/* OUTPUTS                                                               */
/*                                                                       */
/*      YES - Successful Completion                                      */
/*      NO  - Couldn't allocate all of the pages                         */
/*                                                                       */
/* HISTORY                                                               */
/*                                                                       */
/*         NAME            DATE                    REMARKS               */
/*                                                                       */
/*         P. Van Oudenaren                        Initial Version       */
/*         N. Henderson    02/18/94                Cleanup               */
/*************************************************************************/
BOOL pc_rd_open(UCOUNT driveno)                                       /*__fn__*/
{
UCOUNT i;
UCOUNT j;

    /* We don't use drive no. You could have multiple drives if wanted */
    driveno = driveno;

    /* If the ramdisk is not initialized, do it now */
    if (!rd_pages[0])
    {
        for (i = 0 ; i < NUM_RAMDISK_PAGES; i++)
        {
            rd_pages[i] = rd_alloc_page();
            if (!rd_pages[i])
            {
                for (j = 0; j < i; j++)
                {
                    rd_free_page(rd_pages[j]);
                    rd_pages[j] = 0;
                }
                return(NO);
            }
        }
    }
    rd_opencount += 1;
    return(YES);
}


/*************************************************************************/
/*                                                                       */
/* FUNCTION                                      pc_rd_close             */
/*                                                                       */
/* DESCRIPTION                                                           */
/*                                                                       */
/*      This function deallocates all of the pages associated with the   */
/*      RAM Disk.  The actual code here is commented out since we        */
/*      probably don't want to loose the data on a close.                */
/*                                                                       */
/* AUTHOR                                                                */
/*                                                                       */
/*      Peter Van Oudenaren                                              */
/*                                                                       */
/* CALLED BY                                                             */
/*                                                                       */
/*      Nucleus FILE                                                     */
/*                                                                       */
/* CALLS                                                                 */
/*                                                                       */
/*      rd_free_page                                                     */
/*                                                                       */
/* INPUTS                                                                */
/*                                                                       */
/*      driveno - the number assigned to the RAM Disk (not used)         */
/*                                                                       */
/* OUTPUTS                                                               */
/*                                                                       */
/*      YES - Successful Completion                                      */
/*      NO  - Couldn't allocate all of the pages                         */
/*                                                                       */
/* HISTORY                                                               */
/*                                                                       */
/*         NAME            DATE                    REMARKS               */
/*                                                                       */
/*         P. Van Oudenaren                        Initial Version       */
/*         N. Henderson    02/18/94                Cleanup               */
/*************************************************************************/
BOOL pc_rd_close(UCOUNT driveno)                                     /*__fn__*/
{
    if (rd_opencount)
        --rd_opencount;

#if (RELEASE)  /*  Not normally.  */
    if (!rd_open)
    {
         for (i = 0 ; i < NUM_RAMDISK_PAGES; i+++)
        {  rd_free_page(rd_pages[i]); rd_pages[i] = 0;}
    }
#endif /*  RELEASE  */

    driveno = driveno;
    return(YES);
}

/* B.OOL pc_rd_io(BLOCKT block, VOID *buffer, UCOUNT count, BOOL reading)
*
*   Perform io to and from the ramdisk. 
*
*   If the reading flag is true copy data from the ramdisk (read).
*   else copy to the ramdisk. (write). called by pc_gblock and pc_pblock
*   
*   This routine is called by pc_rdblock.
*
*/

/*************************************************************************/
/*                                                                       */
/* FUNCTION                                      pc_rd_io                */
/*                                                                       */
/* DESCRIPTION                                                           */
/*                                                                       */
/*      This function reads or writes data from and to the RAM Disk      */
/*      based on the 'reading' parameter.                                */
/*                                                                       */
/* AUTHOR                                                                */
/*                                                                       */
/*      Peter Van Oudenaren                                              */
/*                                                                       */
/* CALLED BY                                                             */
/*                                                                       */
/*      pc_gblock  (read)                                                */
/*      pc_pblock  (write)                                               */
/*                                                                       */
/* CALLS                                                                 */
/*                                                                       */
/*      none                                                             */
/*                                                                       */
/* INPUTS                                                                */
/*                                                                       */
/*      driveno - the number assigned to the RAM Disk (not used)         */
/*      block - the block number to read or write                        */
/*      buffer - pointer to the data to be placed from a read or stored  */
/*               on a write                                              */
/*      count - number of bytes to be read or written                    */
/*      reading - indicates whether or not we are reading or writing     */
/*                                                                       */
/* OUTPUTS                                                               */
/*                                                                       */
/*      YES - Successful Completion                                      */
/*      NO  - block number is out of range                               */
/*                                                                       */
/* HISTORY                                                               */
/*                                                                       */
/*         NAME            DATE                    REMARKS               */
/*                                                                       */
/*         P. Van Oudenaren                        Initial Version       */
/*         N. Henderson    02/18/94                Cleanup               */
/*************************************************************************/
BOOL pc_rd_io(UCOUNT driveno, ULONG block, VOID FAR *buffer, UCOUNT count,
              BOOL reading) /*__fn__*/
{
    UTINY FAR *p;
    ULONG ltemp;
    UCOUNT page_number;
    UCOUNT byte_number;
    COUNT i;
    UTINY FAR *pbuffer;
   
    /* We don't use drive no. You could have multiple drives if wanted */
    driveno = driveno;
    pbuffer = (UTINY FAR *)buffer;

    while (count)
    {
        /* Get the page number */
        ltemp = block / RAMDISK_PAGE_SIZE;
        page_number = (UCOUNT) ltemp;

        /* Check. This shouldn't happen */
        if ( (page_number >= NUM_RAMDISK_PAGES) || !rd_pages[page_number])
            return(NO);

        /* Get the offset */
        ltemp = block % RAMDISK_PAGE_SIZE;
        byte_number = (UCOUNT) (ltemp*512);

        p = rd_pages[page_number];
        p += byte_number;

        if (reading)
        {
            for (i = 0; i < 512; i++)
                *pbuffer++ = *p++;
        }
        else
        {
            for (i = 0; i < 512; i++)
                *p++ = *pbuffer++;
        }
        count--;
        block++;
    }
    return(YES);
}


⌨️ 快捷键说明

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