📄 filesys.c
字号:
#endif
#ifdef RAMDISK_ID
if (ffres->ff_drive == RAMDISK_ID)
{
result = RD_findnext(ffres);
FileSys_Errno = RDerrno;
return result;
}
#endif
#ifdef FAT_ID
if (ffres->ff_drive == FAT_ID)
{
result = FAT_findnext(ffres);
FileSys_Errno = FATErrno;
return result;
}
#endif
FileSys_Errno = ERROR_INVALID_DEVICE;
return -1;
}
/*************************************************************
Function : findclose
Description:
clean up the memory occupied by the previous search
Input:
ffres - a structure that holds the results of the previous search
Output:
0 SUCCESS
-1 FAILURE
**************************************************************/
int fs_findclose(struct ffblk *ffres)
{
int result;
if (FileSys_Running == 0)
{
FileSys_Errno = ERROR_FILE_SYSTEM_NOT_INIT;
return -1;
}
/**** added by chilong 12/7/2001 ****/
if (ffres == NULL)
return -1;
/**** added by chilong 12/7/2001 ****/
FileSys_Errno = 0;
#ifdef NOR_FLASH_DISK_ID
if (ffres->ff_drive == NOR_FLASH_DISK_ID)
{
result = NOR_FFS_findclose(ffres);
FileSys_Errno = NOR_FFS_Errno;
return result;
}
#endif
#ifdef NAND_FLASH_DISK_ID
if (ffres->ff_drive == NAND_FLASH_DISK_ID)
{
result = NAND_FFS_findclose(ffres);
FileSys_Errno = NAND_FFS_Errno;
return result;
}
#endif
#ifdef RAMDISK_ID
if (ffres->ff_drive == RAMDISK_ID)
{
result = RD_findclose(ffres);
FileSys_Errno = RDerrno;
return result;
}
#endif
#ifdef FAT_ID
if (ffres->ff_drive == FAT_ID)
{
result = FAT_findclose(ffres);
FileSys_Errno = FATErrno;
return result;
}
#endif
FileSys_Errno = ERROR_INVALID_DEVICE;
return -1;
}
/*************************************************************
Function: eof
Description:
determine if the end-of-file has been reached
Input:
handle: file handle
Output:
1: file end
0: not file end
-1: invalid file handle
**************************************************************/
int fs_eof(int handle)
{
int result;
if (FileSys_Running == 0)
{
FileSys_Errno = ERROR_FILE_SYSTEM_NOT_INIT;
return -1;
}
if ((handle < 0) || (handle >= MAX_OPEN_FILE) || (FileSysHandleTable[handle] == NULL))
{
FileSys_Errno = ERROR_INVALID_HANDLE;
return -1;
}
#ifdef NOR_FLASH_DISK_ID
if (*(FileSysHandleTable[handle]) == NOR_FLASH_DISK_ID)
{
result = NOR_FFS_eof(handle);
FileSys_Errno = NOR_FFS_Errno;
return result;
}
#endif
#ifdef NAND_FLASH_DISK_ID
if (*(FileSysHandleTable[handle]) == NAND_FLASH_DISK_ID)
{
result = NAND_FFS_eof(handle);
FileSys_Errno = NAND_FFS_Errno;
return result;
}
#endif
#ifdef RAMDISK_ID
if (*(FileSysHandleTable[handle]) == RAMDISK_ID)
{
result = RD_eof(handle);
FileSys_Errno = RDerrno;
return result;
}
#endif
#ifdef FAT_ID
if (*(FileSysHandleTable[handle]) == FAT_ID)
{
result = FAT_eof(handle);
FileSys_Errno = FATErrno;
return result;
}
#endif
FileSys_Errno = ERROR_INVALID_DEVICE;
return -1;
}
/*************************************************************
Function: dup
Description:
open another file handle for the old file handle
Input:
handle: file handle
Output:
new handle
-1: FAILURE
**************************************************************/
int fs_dup(int handle)
{
int result;
if (FileSys_Running == 0)
{
FileSys_Errno = ERROR_FILE_SYSTEM_NOT_INIT;
return -1;
}
if ((handle < 0) || (handle >= MAX_OPEN_FILE) || (FileSysHandleTable[handle] == NULL))
{
FileSys_Errno = ERROR_INVALID_HANDLE;
return -1;
}
#ifdef NOR_FLASH_DISK_ID
if (*(FileSysHandleTable[handle]) == NOR_FLASH_DISK_ID)
{
result = NOR_FFS_dup(handle);
FileSys_Errno = NOR_FFS_Errno;
return result;
}
#endif
#ifdef NAND_FLASH_DISK_ID
if (*(FileSysHandleTable[handle]) == NAND_FLASH_DISK_ID)
{
result = NAND_FFS_dup(handle);
FileSys_Errno = NAND_FFS_Errno;
return result;
}
#endif
#ifdef RAMDISK_ID
if (*(FileSysHandleTable[handle]) == RAMDISK_ID)
{
result = RD_dup(handle);
FileSys_Errno = RDerrno;
return result;
}
#endif
#ifdef FAT_ID
if (*(FileSysHandleTable[handle]) == FAT_ID)
{
result = FAT_dup(handle);
FileSys_Errno = FATErrno;
return result;
}
#endif
FileSys_Errno = ERROR_INVALID_DEVICE;
return -1;
}
/*************************************************************
Function: dup2
Description:
open another specified new file handle for the old file handle
Input:
oldHandle: old file handle
newHandle: new file handle
Output:
0: SUCCESS
-1: FAILURE
Notes:
If newHandle is already opened, it will be closed even
if the operation fails!
**************************************************************/
int fs_dup2(int oldHandle, int newHandle)
{
int result;
short *pfile;
if (FileSys_Running == 0)
{
FileSys_Errno = ERROR_FILE_SYSTEM_NOT_INIT;
return -1;
}
if ((oldHandle < 0) || (oldHandle >= MAX_OPEN_FILE) || (FileSysHandleTable[oldHandle] == NULL))
{
FileSys_Errno = ERROR_INVALID_HANDLE;
return -1;
}
if ((newHandle < 0) || (newHandle >= MAX_OPEN_FILE))
{
FileSys_Errno = ERROR_INVALID_HANDLE;
return -1;
}
pfile = FileSysHandleTable[newHandle];
if (pfile != NULL)
{
#ifdef NOR_FLASH_DISK_ID
if (*pfile == NOR_FLASH_DISK_ID)
{
result = NOR_FFS_close(newHandle);
FileSys_Errno = NOR_FFS_Errno;
if (result == -1)
return -1;
}
#endif
#ifdef NAND_FLASH_DISK_ID
if (*pfile == NAND_FLASH_DISK_ID)
{
result = NAND_FFS_close(newHandle);
FileSys_Errno = NAND_FFS_Errno;
if (result == -1)
return -1;
}
#endif
#ifdef RAMDISK_ID
if (*pfile == RAMDISK_ID)
{
result = RD_close(newHandle);
FileSys_Errno = RDerrno;
if (result == -1)
return -1;
}
#endif
#ifdef FAT_ID
if (*pfile == FAT_ID)
{
result = FAT_close(newHandle);
FileSys_Errno = FATErrno;
if (result == -1)
return -1;
}
#endif
}
#ifdef NOR_FLASH_DISK_ID
if (*(FileSysHandleTable[oldHandle]) == NOR_FLASH_DISK_ID)
{
result = NOR_FFS_dup2(oldHandle, newHandle);
FileSys_Errno = NOR_FFS_Errno;
return result;
}
#endif
#ifdef NAND_FLASH_DISK_ID
if (*(FileSysHandleTable[oldHandle]) == NAND_FLASH_DISK_ID)
{
result = NAND_FFS_dup2(oldHandle, newHandle);
FileSys_Errno = NAND_FFS_Errno;
return result;
}
#endif
#ifdef RAMDISK_ID
if (*(FileSysHandleTable[oldHandle]) == RAMDISK_ID)
{
result = RD_dup2(oldHandle, newHandle);
FileSys_Errno = RDerrno;
return result;
}
#endif
#ifdef FAT_ID
if (*(FileSysHandleTable[oldHandle]) == FAT_ID)
{
result = FAT_dup2(oldHandle, newHandle);
FileSys_Errno = FATErrno;
return result;
}
#endif
FileSys_Errno = ERROR_INVALID_DEVICE;
return -1;
}
/*************************************************************
Function: mkdir
Description:
Make directory
Input:
name - directory name
Output:
0 SUCCESS
-1 FAILURE
Note:
Do nothing since the current system doesn't support
directory.
**************************************************************/
// chilong: we should add access-right to directories, too
int fs_mkdir(char *name)
{
int result;
short driveNO;
/**** added by chilong 01/15/2002 ****/
//unsigned char *Pathname1;
char *Pathname1; // by zhang xue ping
/**** added by chilong 01/15/2002 ****/
if (FileSys_Running == 0)
{
FileSys_Errno = ERROR_FILE_SYSTEM_NOT_INIT;
return -1;
}
/**** added by chilong 12/7/2001 ****/
if (name == NULL)
return -1;
/**** added by chilong 12/7/2001 ****/
/**** added by chilong 01/15/2002 ****/
if ((Pathname1 = (char *)ap_malloc(MAX_PATHNAME_LEN + 2)) == NULL)
{
FileSys_Errno = ERROR_ALLOC_MEM;
return -1;
}
/**** added by chilong 01/15/2002 ****/
FileSys_Errno = 0;
/**** modified by chilong ****/
// moved up from the end of the function
FileSys_Errno = ERROR_INVALID_DEVICE;
/**** modified by chilong ****/
driveNO = getDriveNO(name, Pathname1);
if (driveNO == -1)
{
ap_free(Pathname1);
return -1;
}
#ifdef NOR_FLASH_DISK_ID
if (driveNO == NOR_FLASH_DISK_ID)
{
result = NOR_FFS_mkdir(Pathname1);
FileSys_Errno = NOR_FFS_Errno;
// return result;
}
#endif
#ifdef NAND_FLASH_DISK_ID
if (driveNO == NAND_FLASH_DISK_ID)
{
result = NAND_FFS_mkdir((unsigned char *)Pathname1);
FileSys_Errno = NAND_FFS_Errno;
// return result;
}
#endif
#ifdef RAMDISK_ID
if (driveNO == RAMDISK_ID)
{
result = RD_mkdir((unsigned char *)Pathname1);
FileSys_Errno = RDerrno;
// return result;
}
#endif
#ifdef FAT_ID
if (driveNO == FAT_ID)
{
result = FAT_mkdir((unsigned char *)Pathname1);
FileSys_Errno = FATErrno;
// return result;
}
#endif
// FileSys_Errno = ERROR_INVALID_DEVICE;
// return -1;
ap_free(Pathname1);
/**** modified by chilong ****/
return result;
/**** modified by chilong ****/
}
/*************************************************************
Function: rmdir
Description:
Remove directory
Input:
name - directory name
Output:
0 SUCCESS
-1 FAILURE
Note:
Do nothing since the current system doesn't support
directory.
**************************************************************/
// chilong: we should add access-right to directories, too
int fs_rmdir(char *name)
{
int result;
short driveNO;
/**** added by chilong 01/15/2002 ****/
//unsigned char *Pathname1;
char *Pathname1; // by zhang xue ping
/**** added by chilong 01/15/2002 ****/
// unsigned char *name2;
if (FileSys_Running == 0)
{
FileSys_Errno = ERROR_FILE_SYSTEM_NOT_INIT;
return -1;
}
/**** added by chilong 12/7/2001 ****/
if (name == NULL)
return -1;
/**** added by chilong 12/7/2001 ****/
/**** added by chilong 01/15/2002 ****/
if ((Pathname1 = (char *)ap_malloc(MAX_PATHNAME_LEN + 2)) == NULL)
{
FileSys_Errno = ERROR_ALLOC_MEM;
return -1;
}
/**** added by chilong 01/15/2002 ****/
FileSys_Errno = 0;
driveNO = getDriveNO(name, Pathname1);
if (driveNO == -1)
{
ap_free(Pathname1);
return -1;
}
#ifdef NOR_FLASH_DISK_ID
if (driveNO == NOR_FLASH_DISK_ID)
{
result = NOR_FFS_rmdir(Pathname1);
FileSys_Errno = NOR_FFS_Errno;
ap_free(Pathname1);
return result;
}
#endif
#ifdef NAND_FLASH_DISK_ID
if (driveNO == NAND_FLASH_DISK_ID)
{
result = NAND_FFS_rmdir((unsigned char *)Pathname1);
FileSys_Errno = NAND_FFS_Errno;
ap_free(Pathname1);
return result;
}
#endif
#ifdef RAMDISK_ID
if (driveNO == RAMDISK_ID)
{
result = RD_rmdir((unsigned char *)Pathname1);
FileSys_Errno = RDerrno;
ap_free(Pathname1);
return result;
}
#endif
#ifdef FAT_ID
if (driveNO == FAT_ID)
{
result = FAT_rmdir((unsigned char *)Pathname1);
FileSys_Errno = FATErrno;
ap_free(Pathname1);
return result;
}
#endif
FileSys_Errno = ERROR_INVALID_DEVICE;
ap_free(Pathname1);
return -1;
}
/*************************************************************
Fuction : getFSVersionString
Get the version string
Output:
the version string
**************************************************************/
const char *getFSVersionString(void)
{
#ifdef NOR_FLASH_DISK_ID
if (CurrentDrive == NOR_FLASH_DISK_ID)
{
return NOR_FFS_getFSVersionString();
}
#endif
#ifdef NAND_FLASH_DISK_ID
if (CurrentDrive == NAND_FLASH_DISK_ID)
{
return NAND_FFS_getFSVersionString();
}
#endif
#ifdef RAMDISK_ID
if (CurrentDrive == RAMDISK_ID)
{
return RD_getFSVersionString();
}
#endif
#ifdef FAT_ID
if (CurrentDrive == FAT_ID)
{
return FAT_getFSVersionString();
}
#endif
return NO_FS;
}
/*************************************************************
Fuction : scanDisk
Scan the disk for errors
Input:
interactive - ECHO_ON: show progress during scanning
ECHO_OFF: show nothing during scanning
fix - 1: automatically fix error
0: report only, don't fix
Output:
0: no error is found
-1: system error (check RDerrno)
Otherwise:
bit 0: File/Dir error
bit 1: Disk space inconsistent
**************************************************************/
char fs
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -