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

📄 fal.c

📁 NUcleus plus 支持的文件系统。 是学习文件系统的很好参考资料。
💻 C
📖 第 1 页 / 共 4 页
字号:
*
*      Nucleus File
*      NT File System
*
*  INPUTS
*
*      None
*
*  OUTPUTS
*
*      The current drive number.
*
************************************************************************/
INT FAL_Get_Curr_Drive(VOID)
{
#if  NUCLEUS_FILE_INCLUDED
    return (NU_Get_Default_Drive());
#endif

#if  NUCLEUS_FILE2_INCLUDED
    return ((INT)NU_Get_Default_Drive());
#endif

#if NT_FILE_SYSTEM
    return (_getdrive());
#endif

#if IMF_INCLUDED
    return (NU_SUCCESS);
#endif
}

/************************************************************************
*
*  FUNCTION
*
*      FAL_Set_Curr_Drive
*
*  DESCRIPTION
*
*      Sets the current drive.
*
*  SUPPORTED BY
*
*      Nucleus File
*      NT File System
*
*  INPUTS
*
*      drive       The drive number to set as the current drive.
*
*  OUTPUTS
*
*      If Successful   -   NU_SUCCESS
*      If Unsuccessful -   -1
*
************************************************************************/
INT FAL_Set_Curr_Drive(INT drive)
{
    /* Remove Warnings */
#if IMF_INCLUDED
    UNUSED_PARAMETER(drive);
#endif

#if  NUCLEUS_FILE_INCLUDED
    if (NU_Set_Default_Drive ((INT16)drive) == 0)
        return (-1);
    else
        return (NU_SUCCESS);
#endif

#if  NUCLEUS_FILE2_INCLUDED
    if (NU_Set_Default_Drive ((INT16)drive) != NU_SUCCESS)
        return (-1);
    else
        return (NU_SUCCESS);
#endif

#if NT_FILE_SYSTEM
    return (_chdrive (drive));
#endif

#if IMF_INCLUDED
    return (NU_SUCCESS);
#endif
}

/************************************************************************
*
*  FUNCTION
*
*      FAL_Open_Disk
*
*  DESCRIPTION
*
*      Opens the current drive.
*
*  SUPPORTED BY
*
*      Nucleus File
*
*  INPUTS
*
*      drive       The drive number of the drive to open.
*
*  OUTPUTS
*
*      If Successful   -   NU_SUCCESS
*      If Unsuccessful -   -1
*
************************************************************************/
INT FAL_Open_Disk(INT drive)
{
    CHAR     nu_drive[1];

    /* Remove Warnings */
#if (NT_FILE_SYSTEM || IMF_INCLUDED)
    UNUSED_PARAMETER(drive);
    UNUSED_PARAMETER(nu_drive);
#endif

#if  NUCLEUS_FILE_INCLUDED
    nu_drive[0] = (CHAR)(((CHAR) drive + 1) + 'A' - 1);

    if (NU_Open_Disk (nu_drive) == 0)
        return (-1);
    else
        return (NU_SUCCESS);
#endif

#if  NUCLEUS_FILE2_INCLUDED
    nu_drive[0] = (CHAR)(((CHAR) drive + 1) + 'A' - 1);

    if (NU_Open_Disk (nu_drive) != NU_SUCCESS)
        return (-1);
    else
        return (NU_SUCCESS);
#endif

#if NT_FILE_SYSTEM
    return (NU_SUCCESS);
#endif

#if IMF_INCLUDED
    return (NU_SUCCESS);
#endif
}

/************************************************************************
*
*  FUNCTION
*
*      FAL_Close_Disk
*
*  DESCRIPTION
*
*      Closes the current drive.
*
*  SUPPORTED BY
*
*      Nucleus File
*
*  INPUTS
*
*      drive       The drive number of the drive to close.
*
*  OUTPUTS
*
*      If Successful   -   NU_SUCCESS
*      If Unsuccessful -   -1
*
************************************************************************/
INT  FAL_Close_Disk(INT drive)
{
    CHAR nu_drive[1];

    /* Remove Warnings */
#if (NT_FILE_SYSTEM || IMF_INCLUDED)
    UNUSED_PARAMETER(drive);
    UNUSED_PARAMETER(nu_drive);
#endif

#if  NUCLEUS_FILE_INCLUDED
    nu_drive[0] = (CHAR)(((CHAR) drive + 1) + 'A' - 1);

    if (NU_Close_Disk (nu_drive) == 0)
        return (-1);
    else
        return (NU_SUCCESS);
#endif

#if  NUCLEUS_FILE2_INCLUDED
    nu_drive[0] = (CHAR)(((CHAR) drive + 1) + 'A' - 1);

    if (NU_Close_Disk (nu_drive) != NU_SUCCESS)
        return (-1);
    else
        return (NU_SUCCESS);
#endif

#if NT_FILE_SYSTEM
    return (NU_SUCCESS);
#endif

#if IMF_INCLUDED
    return (NU_SUCCESS);
#endif
}

/************************************************************************
*
*  FUNCTION
*
*      FAL_Release_File_User
*
*  DESCRIPTION
*
*      Releases the current task as a file user.
*
*  SUPPORTED BY
*
*      Nucleus File
*
*  INPUTS
*
*      None
*
*  OUTPUTS
*
*      NU_SUCCESS
*
************************************************************************/
INT  FAL_Release_File_User(VOID)
{
#if  (NUCLEUS_FILE_INCLUDED || NUCLEUS_FILE2_INCLUDED)
    NU_Release_File_User();
    return (NU_SUCCESS);
#endif

#if NT_FILE_SYSTEM
    return (NU_SUCCESS);
#endif

#if IMF_INCLUDED
    return (NU_SUCCESS);
#endif
}

/************************************************************************
*
*  FUNCTION
*
*      FAL_Become_File_User
*
*  DESCRIPTION
*
*      Registers the current task as a file user.
*
*  SUPPORTED BY
*
*      Nucleus File
*
*  INPUTS
*
*      None
*
*  OUTPUTS
*
*      If Successful   -   NU_SUCCESS
*      If Unsuccessful -   -1
*
************************************************************************/
INT FAL_Become_File_User(VOID)
{
#if NUCLEUS_FILE_INCLUDED
    if (NU_Become_File_User() == 0)
         return (-1);
    else
    {
        if (NU_Set_Default_Drive((INT16)Default_Drive) == 0)
            return (-1);
        else
            return (NU_SUCCESS);
    }
#endif

#if NUCLEUS_FILE2_INCLUDED
    if (NU_Become_File_User() == 0)
         return (-1);
    else
    {
        if (NU_Set_Default_Drive((UINT16)Default_Drive) != NU_SUCCESS)
            return (-1);
        else
            return (NU_SUCCESS);
    }
#endif

#if NT_FILE_SYSTEM
    return (NU_SUCCESS);
#endif

#if IMF_INCLUDED
    return (NU_SUCCESS);
#endif
}

/************************************************************************
*
*  FUNCTION
*
*      FAL_Get_Attribute
*
*  DESCRIPTION
*
*      Returns the "attribute" value of an FAL_DIR variable.
*
*  SUPPORTED BY
*
*      Nucleus File
*      NT File System
*
*  INPUTS
*
*      statobj         The file of which we want to get the attribute.
*
*  OUTPUTS
*
*      The Attribute of the Object
*
************************************************************************/
signed char FAL_Get_Attribute(FAL_DIR statobj)
{
    /* Remove Warnings */
#if IMF_INCLUDED
    UNUSED_PARAMETER(statobj.length);
#endif

#if (NUCLEUS_FILE_INCLUDED || NUCLEUS_FILE2_INCLUDED)
    return (statobj.fattribute);
#endif

#if NT_FILE_SYSTEM
    return ((CHAR)statobj.attrib);
#endif

#if IMF_INCLUDED
    p_errno = NU_UNAVAILABLE;
    return (-1);
#endif
}

/************************************************************************
*
*  FUNCTION
*
*      FAL_Get_Last_Error
*
*  DESCRIPTION
*
*      Returns the last error code.
*
*  SUPPORTED BY
*
*      Nucleus File
*      NT File System
*      In-Memory File System
*
*  INPUTS
*
*      None
*
*  OUTPUTS
*
*      The Last FAL Error Generated
*
************************************************************************/
INT FAL_Get_Last_Error(VOID)
{
#if (NUCLEUS_FILE_INCLUDED || NUCLEUS_FILE2_INCLUDED)
    return (fs_user->p_errno);
#endif

#if NT_FILE_SYSTEM
    return (GetLastError());
#endif

#if IMF_INCLUDED
    return (p_errno);
#endif
}

#if NUCLEUS_FILE_INCLUDED
/***********************************************************************
*
*  FUNCTION                           "RAM_disk_init"
*
*
*  DESCRIPTION
*
*      This routine low level formats the disk, opens the disk for
*      Nucleus FILE usage, and high level formats the disk.
*
*  INPUTS
*
*       NONE
*
*  OUTPUTS
*
*       NONE
*
***********************************************************************/
BOOL RAM_disk_init(VOID)
{
    IMPORT      _PC_BDEVSW pc_bdevsw[];
    FMTPARMS    fmt;
    BOOL        ret_val;
    OPTION      preempt_status;

    /*  Don't allow other tasks to start until we are done.  */
    preempt_status = NU_Change_Preemption(NU_NO_PREEMPT);

    /*  Initialize return value.  */
    ret_val = NO;

    /*  Build the format table.  This table is used by NU_Format to
        write the boot block, fat, and main directory to the disk.  */

    /*  The name in the boot block will be NUFILE to identify this disk
        as one formatted by Nucleus FILE.  */
    strcpy(&fmt.oemname[0], "NUFILE");
    fmt.secpalloc =      (UINT8)  2;   /* must be a multiple of 2.  This
                                          number indicates the number of
                                          sectors (blocks) per cluster.
                                          This value is the minimum number
                                          of bytes that are written to or
                                          read from the disk at a time.  */
    fmt.secreserved =    (UINT16) 1;
    fmt.numfats     =    (UINT8)  1;   /* since redundant fats aren't used
                                          only have one fat.  */
    fmt.secpfat     =    (UINT16) 1;
    fmt.numroot     =    (UINT16) 16;
    fmt.mediadesc =      (UINT8)  0xFD;

    fmt.secptrk     =    (UINT16) (UINT16) NRAMDISKBLOCKS/4;


    fmt.numhead     =    (UINT16) 2;
    fmt.numcyl     =     (UINT16) 2;
    fmt.physical_drive_no =   0;
    fmt.binary_volume_label = 0x12345678L;
    strcpy(fmt.text_volume_label, "VOLUMELABE");


    /*  This function actually opens the disk and must be done before any
        other activities are performed.  */
    if (pc_bdevsw[(INT16)Default_Drive].open_proc((UINT16)Default_Drive))
    {

        /*  The device opened successfully, so format it.  */
        if (NU_Format((INT16)Default_Drive, &fmt ))
            ret_val = YES;
    }

    /*  Let other tasks run again.  */
    NU_Change_Preemption(preempt_status);

    return(ret_val);
}
#endif



/***********************************************************************
*
*  FUNCTION
*
*      FAL_Object_Mod_Time
*
*  DESCRIPTION
*
*      Returns the date and time that a file was last modified.
*
*  INPUTS
*
*      FAL_DIR *file   The file information structure.
*
*  OUTPUTS
*
*      tm_time         All time fields in a standard tm_time structure.
*
***********************************************************************/
tm_time FAL_Object_Mod_Time(FAL_DIR *file)
{
    tm_time     fal_time;

#if  (NUCLEUS_FILE_INCLUDED)
    /* Extract time information. */
    fal_time.tm_year = ((file->fdate & YEARMASK) >> 9) + 1980;
    fal_time.tm_mon = ((file->fdate & MONTHMASK) >> 5);
    fal_time.tm_mday = (file->fdate & DAYMASK);
    fal_time.tm_hour = ((file->ftime & HOURMASK) >> 11);
    fal_time.tm_min = ((file->ftime & MINMASK) >> 5);
    fal_time.tm_sec = (file->ftime & SECMASK);
#endif

#if  (NUCLEUS_FILE2_INCLUDED)
    /* Extract time information. */
    fal_time.tm_year = ((file->fupdate & YEARMASK) >> 9) + 1980;
    fal_time.tm_mon = ((file->fupdate & MONTHMASK) >> 5);
    fal_time.tm_mday = (file->fupdate & DAYMASK);
    fal_time.tm_hour = ((file->fuptime & HOURMASK) >> 11);
    fal_time.tm_min = ((file->fuptime & MINMASK) >> 5);
    fal_time.tm_sec = (file->fuptime & SECMASK);
#endif    

#if NT_FILE_SYSTEM

    FAL_LOCAL   tm = *localtime(&file->time_write);

    /* Get date and time from NT. */
    fal_time.tm_year = tm.tm_year + 1900;
    fal_time.tm_mon = tm.tm_mon;
    fal_time.tm_mday = tm.tm_mday;
    fal_time.tm_hour = tm.tm_hour;
    fal_time.tm_min = tm.tm_min;
    fal_time.tm_sec = tm.tm_sec;
#endif

#if IMF_INCLUDED

    UINT16 pd_time;
    UINT16 pd_date;

    /* REPLACE THESE LINES WITH A CALL TO YOUR FUNCTION   */
    /* THAT RETRIEVES FILE TIME INTO FILE COMPATIBLE FORMAT. */
    UNUSED_PARAMETER(file);
    pd_time = 0x0000;  /* Until then, use Jan. 1, 1980 at 12:00am */
    pd_date = 0x0000;

    /* Extract time information. */
    fal_time.tm_year = ((pd_date & YEARMASK) >> 9) + 1980;
    fal_time.tm_mon = ((pd_date & MONTHMASK) >> 5);
    fal_time.tm_mday = (pd_date & DAYMASK);
    fal_time.tm_hour = ((pd_time & HOURMASK) >> 11);
    fal_time.tm_min = ((pd_time & MINMASK) >> 5);
    fal_time.tm_sec = (pd_time & SECMASK);
#endif

    return fal_time;
}

⌨️ 快捷键说明

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