devio.c

来自「ertfs文件系统里面既有完整ucos程序」· C语言 代码 · 共 152 行

C
152
字号
/* devio functions
*
*
*/
#include "pcdisk.h"


int card_failed_handler(int driveno)    /* __fn__ */
{
int ret_val;

    ret_val = critical_error_handler(driveno,CRERR_CARD_FAILURE, 0);
                
    if (ret_val == CRITICAL_ERROR_ABORT)
    {
        /* Abort the current mount */
        pc_dskfree((int)driveno);
    }
    return(ret_val);
}



BOOLEAN devio_read(int driveno, dword blockno, byte * buf, word n_to_read, BOOLEAN raw) /* __fn__ */
{
DDRIVE *pdr;

    pdr = pc_drno_to_drive_struct(driveno);

    while (1)
    {
        /* Check if disk is accessable and hasn't changed since mounted */
        if (!(pdr->drive_flags & DRIVE_FLAGS_VALID))
            return(FALSE);
        if (!check_media_io(driveno, raw))
            return(FALSE);

        OS_CLAIM_DRIVE_IO(pdr->lock_unit)

        if (pdr->drive_flags & DRIVE_FLAGS_PARTITIONED)
        {
            if (!raw)
                blockno += pdr->partition_base;
        }
        if (pdr->dev_table_drive_io(driveno, blockno, buf, n_to_read, TRUE))
        {
            OS_RELEASE_DRIVE_IO(pdr->lock_unit)
            return(TRUE);
        }
        else
        {
            OS_RELEASE_DRIVE_IO(pdr->lock_unit)
            if (card_failed_handler(driveno) != CRITICAL_ERROR_RETRY)
                break;
        }
    }
    return(FALSE);
}

#if (RTFS_WRITE)

/* This is a special version of devio_write that is used by the format utility
   It is the same as devio_write except that it does not automount the 
   drive or load the partition table. If non-raw IO is requested the 
   caller must first be sure that the partition table is loaded 
*/
 
BOOLEAN devio_write_format(int driveno, dword blockno, byte * buf, word n_to_write, BOOLEAN raw) /* __fn__ */
{
DDRIVE *pdr;

    pdr = pc_drno_to_drive_struct(driveno);

    while (1)
    {
        /* Check if disk is accessable and hasn't changed since mounted */
        if (!check_media_io(driveno, TRUE))
            return(FALSE);

        OS_CLAIM_DRIVE_IO(pdr->lock_unit)
        if (pdr->drive_flags & DRIVE_FLAGS_PARTITIONED)
        {
            if (!raw)
                blockno += pdr->partition_base;
        }
        if (pdr->dev_table_drive_io(driveno, blockno, buf, n_to_write, FALSE))
        {
            OS_RELEASE_DRIVE_IO(pdr->lock_unit)
            return(TRUE);
        }
        else
        {
            OS_RELEASE_DRIVE_IO(pdr->lock_unit)
            if (card_failed_handler(driveno) != CRITICAL_ERROR_RETRY)
                break;
        }
    }
    return(FALSE);
}


BOOLEAN devio_write(int driveno, dword blockno, byte * buf, word n_to_write, BOOLEAN raw) /* __fn__ */
{
DDRIVE *pdr;

    pdr = pc_drno_to_drive_struct(driveno);

    while (1)
    {
        /* Check if disk is accessable and hasn't changed since mounted */
        if (!check_media_io(driveno, raw))
            return(FALSE);

        OS_CLAIM_DRIVE_IO(pdr->lock_unit)
        if (pdr->drive_flags & DRIVE_FLAGS_PARTITIONED)
        {
            if (!raw)
                blockno += pdr->partition_base;
        }
        if (pdr->dev_table_drive_io(driveno, blockno, buf, n_to_write, FALSE))
        {
            OS_RELEASE_DRIVE_IO(pdr->lock_unit)
            return(TRUE);
        }
        else
        {
            OS_RELEASE_DRIVE_IO(pdr->lock_unit)
            if (card_failed_handler(driveno) != CRITICAL_ERROR_RETRY)
                break;
        }
    }
    return(FALSE);
}

#endif


















⌨️ 快捷键说明

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