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

📄 fal.c

📁 NUcleus plus 支持的文件系统。 是学习文件系统的很好参考资料。
💻 C
📖 第 1 页 / 共 4 页
字号:
{
    /* Remove Warnings */
#if (IMF_INCLUDED || NUCLEUS_FILE_INCLUDED || NUCLEUS_FILE2_INCLUDED)
    UNUSED_PARAMETER(hfile);
#endif
#if (IMF_INCLUDED || NT_FILE_SYSTEM)
    UNUSED_PARAMETER(statobj);
#endif

#if (NUCLEUS_FILE_INCLUDED || NUCLEUS_FILE2_INCLUDED)
   NU_Done (statobj);
   return (NU_SUCCESS);
#endif

#if NT_FILE_SYSTEM
    if (_findclose (hfile) == NU_SUCCESS)
        return (NU_SUCCESS);
    else
        return (-1);
#endif

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

/************************************************************************
*
*  FUNCTION
*
*      FAL_Fwrite
*
*  DESCRIPTION
*
*      Function to write a number of bytes to a file.
*      The file is size times count.
*
*  SUPPORTED BY
*
*      Nucleus File
*      NT File System
*      In-Memory File System
*
*  INPUTS
*
*      *buf            Pointer to the buffer of data to write to the
*                      file.
*      size            Number of bytes to write to the file.
*      file            File descriptor associated with the file to write
*                      to.
*
*  OUTPUTS
*
*      The Number of Bytes Written
*
************************************************************************/
UINT32 FAL_Fwrite(CHAR *buf, UINT16 size, FAL_FILE file)
{
    INT32   bytes_written;

#if NUCLEUS_FILE_INCLUDED
    if ( (bytes_written = (INT32)(NU_Write (file, (UINT8 *)buf, size))) < 0)
        bytes_written = 0;

   return ((UINT32)bytes_written);
#endif

#if NUCLEUS_FILE2_INCLUDED
   if ( (bytes_written = NU_Write (file, buf, (INT32)size)) < 0)
        bytes_written = 0;

   return ((UINT32)bytes_written);
#endif

#if NT_FILE_SYSTEM
   if ( (bytes_written = _write (file, (CONST VOID *)buf, (UINT32)size)) < 0)
       bytes_written = 0;

   return ((UINT32)bytes_written);
#endif

#if IMF_INCLUDED
   if ( (bytes_written = IMF_Write (buf, (INT)size, file)) < 0)
       bytes_written = 0;

   return ((UINT32)bytes_written);
#endif
}

/************************************************************************
*
*  FUNCTION
*
*      FAL_Fread
*
*  DESCRIPTION
*
*      Function to read a number of bytes from a file.
*      The file is size times count.
*
*  SUPPORTED BY
*
*      Nucleus File
*      NT File System
*      In-Memory File System
*
*  INPUTS
*
*      *buf            Pointer to the buffer of data to fill.
*      size            Number of bytes to read from the file.
*      file            File descriptor associated with the file to
*                      read from.
*
*  OUTPUTS
*
*      The Number of Bytes Read
*
************************************************************************/
UINT32 FAL_Fread(CHAR *buf, UINT16 size, FAL_FILE file)
{
    INT32   bytes_read;

#if NUCLEUS_FILE_INCLUDED
   if ( (bytes_read = (INT32)(NU_Read (file, (UINT8 *)buf, size))) < 0)
       bytes_read = 0;

   return ((UINT32)bytes_read);
#endif

#if NUCLEUS_FILE2_INCLUDED
   if ( (bytes_read = (NU_Read (file, buf, (INT32)size))) < 0)
       bytes_read = 0;

   return ((UINT32)bytes_read);
#endif

#if NT_FILE_SYSTEM
   if ( (bytes_read = (INT32)(_read (file, (VOID *)buf, size))) < 0)
       bytes_read = 0;

   return ((UINT32)bytes_read);
#endif

#if IMF_INCLUDED
    if ( (bytes_read = IMF_Read (buf, (INT)size, file)) < 0)
        bytes_read = 0;

    return ((UINT32)bytes_read);
#endif
}

/************************************************************************
*
*  FUNCTION
*
*      FAL_Mk_Dir
*
*  DESCRIPTION
*
*      Creates a directory with the specified path.
*
*  SUPPORTED BY
*
*      Nucleus File
*      NT File System
*
*  INPUTS
*
*      *mb             Name of the new directory to create.
*
*  OUTPUTS
*
*      If Successful   -   NU_SUCCESS
*      If Unsuccessful -   -1
*
************************************************************************/
INT FAL_Mk_Dir(CHAR *mb)
{
    /* Remove Warnings */
#if IMF_INCLUDED
    UNUSED_PARAMETER(mb);
#endif

#if NUCLEUS_FILE_INCLUDED
    if (NU_Make_Dir (mb) == 0)
        return (-1);
    else
        return (NU_SUCCESS);
#endif

#if NUCLEUS_FILE2_INCLUDED
    if (NU_Make_Dir (mb) != NU_SUCCESS)
        return (-1);
    else
        return (NU_SUCCESS);
#endif

#if NT_FILE_SYSTEM
    if (_access ((CONST CHAR *)mb, 0) == -1 )
        return (_mkdir ((CONST CHAR *)mb));
    else
        return (NU_SUCCESS);
#endif

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

/************************************************************************
*
*  FUNCTION
*
*      FAL_Rmv_Dir
*
*  DESCRIPTION
*
*      Removes a directory with the specified path.
*
*  SUPPORTED BY
*
*      Nucleus File
*      NT File System
*
*  INPUTS
*
*      *path           Name of the directory to remove.
*
*  OUTPUTS
*
*      If Successful   -   NU_SUCCESS
*      If Unsuccessful -   -1
*
************************************************************************/
INT FAL_Rmv_Dir(CHAR *path)
{
    /* Remove Warnings */
#if IMF_INCLUDED
    UNUSED_PARAMETER(path);
#endif

#if NUCLEUS_FILE_INCLUDED
    if ((INT)NU_Remove_Dir (path) == 0)
        return (-1);
    else
        return (NU_SUCCESS);
#endif

#if NUCLEUS_FILE2_INCLUDED
    if (NU_Remove_Dir (path) != NU_SUCCESS)
        return (-1);
    else
        return (NU_SUCCESS);
#endif

#if NT_FILE_SYSTEM
    return (_rmdir ((CONST CHAR *)path));
#endif

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

/************************************************************************
*
*  FUNCTION
*
*      FAL_Is_Dir
*
*  CALLED BY
*
*      Application
*
*  SUPPORTED BY
*
*      Nucleus File
*      NT File System
*
*  INPUTS
*
*      *path           Directory path to verify.
*
*  OUTPUTS
*
*      If Successful   -   NU_SUCCESS
*      If Unsuccessful -   -1
*
************************************************************************/
INT FAL_Is_Dir(CHAR *path)
{
    CHAR    current_dir[25];
    INT     drive = 'A';

    /* Remove Warnings */
#if (NUCLEUS_FILE_INCLUDED || NUCLEUS_FILE2_INCLUDED || IMF_INCLUDED)
    UNUSED_PARAMETER(drive);
    current_dir[0] = 'A';
#if IMF_INCLUDED
    UNUSED_PARAMETER(path);
    UNUSED_PARAMETER(current_dir);
#endif
#endif

#if NUCLEUS_FILE_INCLUDED
    if ((INT)NU_Is_Dir (path) == 0)
        return (-1);
    else
        return (NU_SUCCESS);
#endif

#if NUCLEUS_FILE2_INCLUDED
    drive = FAL_Get_Curr_Drive();
    FAL_Current_Dir (drive, current_dir);

    if (NU_Set_Current_Dir (path) == NU_SUCCESS)
    {
        NU_Set_Current_Dir(current_dir);
        return (NU_SUCCESS);
    }
    else
        return (-1);

#endif

#if NT_FILE_SYSTEM
    drive = FAL_Get_Curr_Drive();
    FAL_Current_Dir (drive, current_dir);

    if (_chdir ((CONST CHAR *)path) == NU_SUCCESS)
    {
        _chdir ((CONST CHAR *)current_dir);
        return (NU_SUCCESS);
    }
    else
        return (-1);

#endif

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

/************************************************************************
*
*  FUNCTION
*
*      FAL_Set_Curr_Dir
*
*  DESCRIPTION
*
*      Sets the directory path to the current directory.
*
*  SUPPORTED BY
*
*      Nucleus File
*      NT File System
*
*  INPUTS
*
*      *path           Path of the directory to set as current.
*
*  OUTPUTS
*
*      If Successful   -   NU_SUCCESS
*      If Unsuccessful -   -1
*
************************************************************************/
INT FAL_Set_Curr_Dir(CHAR *path)
{
    /* Remove Warnings */
#if IMF_INCLUDED
    UNUSED_PARAMETER(path);
#endif

#if NUCLEUS_FILE_INCLUDED
    if ((INT)NU_Set_Current_Dir (path) == 0)
        return (-1);
    else
        return (NU_SUCCESS);
#endif

#if NUCLEUS_FILE2_INCLUDED
    if (NU_Set_Current_Dir (path) != NU_SUCCESS)
        return (-1);
    else
        return (NU_SUCCESS);
#endif

#if NT_FILE_SYSTEM
    return (_chdir ((CONST CHAR *)path));
#endif

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

/************************************************************************
*
*  FUNCTION
*
*      FAL_Current_Dir
*
*  DESCRIPTION
*
*      Finds the current working directory and places it in the path
*      variable.
*
*  SUPPORTED BY
*
*      Nucleus File
*      NT File System
*
*  INPUTS
*
*      drive           Current drive number.
*      *path           Pointer to a buffer that will be filled in with
*                      the current path.
*
*  OUTPUTS
*
*      If Successful   -   NU_SUCCESS
*      If Unsuccessful -   -1
*
************************************************************************/
INT FAL_Current_Dir(INT drive, CHAR *path)
{
    CHAR    nu_drive = 'A';

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

#if NUCLEUS_FILE_INCLUDED
    nu_drive = (CHAR)('A' + drive);

    if ((INT32)NU_Current_Dir (&nu_drive, path) == 0)
        return (-1);
    else
        return (NU_SUCCESS);
#endif

#if NUCLEUS_FILE2_INCLUDED
    nu_drive = (CHAR)('A' + drive);

    if (NU_Current_Dir ((UINT8*)&nu_drive, path) != NU_SUCCESS)
        return (-1);
    else
        return (NU_SUCCESS);
#endif

#if NT_FILE_SYSTEM
    if (_getdcwd (drive, (CHAR *)path, MAX_PATH) == NU_NULL)
        return (-1);
    else
        return (NU_SUCCESS);
#endif

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

/************************************************************************
*
*  FUNCTION
*
*      FAL_Rename_File
*
*  DESCRIPTION
*
*      Renames the file in the current name to a new name given in
*      rename path.
*
*  SUPPORTED BY
*
*      Nucleus File
*      NT File System
*      In-Memory File System
*
*  INPUTS
*
*      *rename_path    The new name of the file.
*      *curr_name      The current name of the file.
*
*  OUTPUTS
*
*      If Successful   -   NU_SUCCESS
*      If Unsuccessful -   -1
*
************************************************************************/
INT FAL_Rename_File(CHAR *rename_path, CHAR *curr_name)
{
#if NUCLEUS_FILE_INCLUDED
    if ((INT)NU_Rename (curr_name, rename_path) == 0)
        return (-1);
    else
        return (NU_SUCCESS);
#endif

#if NUCLEUS_FILE2_INCLUDED
    if (NU_Rename (curr_name, rename_path) != NU_SUCCESS)
        return (-1);
    else
        return (NU_SUCCESS);
#endif

#if NT_FILE_SYSTEM
    return (rename ((CONST CHAR *)curr_name, (CONST CHAR *)rename_path));
#endif

#if IMF_INCLUDED
    return (IMF_Rename (rename_path, curr_name));
#endif
}

/************************************************************************
*
*  FUNCTION
*
*      FAL_Time
*
*  DESCRIPTION
*
*      Time function-  The user will have to implement their own time
*      data functions.
*
*  INPUTS
*
*      *ltime      Pointer to the storage location of the time to be
*                  filled in by the function.
*
************************************************************************/
INT FAL_Time(FAL_TIME *ltime)
{
#if (NUCLEUS_FILE_INCLUDED || NUCLEUS_FILE2_INCLUDED || IMF_INCLUDED)
    UNUSED_PARAMETER(ltime);
#endif

#if (NUCLEUS_FILE_INCLUDED || NUCLEUS_FILE2_INCLUDED)
    /*  User must implement time functions for his particular platform */
    fs_user->p_errno = NU_UNAVAILABLE;

⌨️ 快捷键说明

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