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

📄 ramdisk.c

📁 ertfs文件系统里面既有完整ucos程序
💻 C
字号:
/* ramdisk.c - Ram disk device driver.

Summary

 Description
    Provides a configurable ram drive capability.

    To use this utility you must provide two constants.

    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.

    THESE CONSTANTS ARE DEFINED IN PCCONF.H


*/

#include <pcdisk.h>

#define NUM_RAMDISK_PAGES    32  /* 32*2 512-byte blocks is a 32K ram disk */
#define RAMDISK_PAGE_SIZE     2

                
BLOCK_ALLOC KS_FAR ram_disk_pages[NUM_RAMDISK_PAGES][RAMDISK_PAGE_SIZE];



/* This routine converts a block offset to a memory pointer to the 512 bytes
   that contain the block */

static byte KS_FAR *ramdisk_block(word block)                                       /*__fn__*/
{
int page_number;
int block_number;
dword ltemp;
    /* Get the page number */
    ltemp = block / RAMDISK_PAGE_SIZE;
    page_number = (word) ltemp;
    /* Check. This shouldn't happen */
    if (page_number >= NUM_RAMDISK_PAGES) 
        return(0);
    /* Get the offset */
    block_number = block % RAMDISK_PAGE_SIZE;
    return((byte KS_FAR *) &ram_disk_pages[page_number][block_number].core[0]);
}

/* BOOLEAN ramdisk_io(BLOCKT block, void *buffer, word count, BOOLEAN 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.
*
*/
BOOLEAN ramdisk_io(int driveno, dword block, void KS_FAR *buffer, word count, BOOLEAN reading) /*__fn__*/
{
    byte KS_FAR *p;
    int i;
    byte KS_FAR *pbuffer;

   
    pbuffer = (byte KS_FAR *)buffer;

    while (count)
    {
        p = ramdisk_block((word)block);

        if (!p)
            return(FALSE);

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




int ramdisk_perform_device_ioctl(int driveno, int opcode, PFVOID pargs)
{
DDRIVE *pdr;
DEV_GEOMETRY gc;        // used by DEVCTL_GET_GEOMETRY

    pdr = pc_drno_to_drive_struct(driveno);
    if (!pdr)
        return (-1);

    switch (opcode)
    {
    /* Get geometry and format share common code */
    case DEVCTL_GET_GEOMETRY:
        pc_memfill(&gc, sizeof(gc), '\0');
        /* Now set the geometry section */

        gc.dev_geometry_heads       = 1;
        gc.dev_geometry_cylinders   = NUM_RAMDISK_PAGES;
        gc.dev_geometry_secptrack   = RAMDISK_PAGE_SIZE;

        copybuff(pargs, &gc, sizeof(gc));
        return (0);

    case DEVCTL_FORMAT:
        {
            byte KS_FAR *p;
            dword block;
            int i;
            for (block = 0; block < (NUM_RAMDISK_PAGES * RAMDISK_PAGE_SIZE); block++)
            {
                p = ramdisk_block((word)block);
                for (i = 0 ; i < 512; i++)
                    *p++ = 0;
            }
        }
        return(0);

    case DEVCTL_CHECKSTATUS:
        // Check device status and return
        //  DEVTEST_NOCHANGE
        //  DEVTEST_NOMEDIA, DEVTEST_UNKMEDIA or DEVTEST_CHANGED
        return(DEVTEST_NOCHANGE);

    case DEVCTL_WARMSTART:
        pdr->drive_flags |= DRIVE_FLAGS_VALID;
        return(0);

    case DEVCTL_POWER_RESTORE:
        /* Fall through */
    case DEVCTL_POWER_LOSS:
        /* Fall through */
    default:
        break;
    }
    return(0);

}

⌨️ 快捷键说明

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