📄 fat.h
字号:
/*-----------------------------------------------------------------
FAT_FindFirstFileLFN
Gets the long file name of the first directory entry and resets
the count (can be a file or subdirectory)
char* lfn: OUT long file name, must be at least 256 chars long
FILE_TYPE return: OUT returns FT_NONE if failed,
FT_FILE if it found a file and FT_DIR if it found a directory
-----------------------------------------------------------------*/
FILE_TYPE FAT_FindFirstFileLFN(char* lfn);
/*-----------------------------------------------------------------
FAT_FindNextFileLFN
Gets the long file name of the next directory entry
(can be a file or subdirectory)
char* lfn: OUT long file name, must be at least 256 chars long
FILE_TYPE return: OUT returns FT_NONE if failed,
FT_FILE if it found a file and FT_DIR if it found a directory
-----------------------------------------------------------------*/
FILE_TYPE FAT_FindNextFileLFN(char* lfn);
/*-----------------------------------------------------------------
FAT_FileExists
Returns the type of file
char* filename: IN filename of the file to look for
FILE_TYPE return: OUT returns FT_NONE if there is now file with
that name, FT_FILE if it is a file and FT_DIR if it is a directory
-----------------------------------------------------------------*/
FILE_TYPE FAT_FileExists (const char* filename);
/*-----------------------------------------------------------------
FAT_GetFileSystemType
FS_TYPE return: OUT returns the current file system type
-----------------------------------------------------------------*/
FS_TYPE FAT_GetFileSystemType (void);
/*-----------------------------------------------------------------
FAT_GetFileSystemTotalSize
unsigned int return: OUT returns the total disk space (used + free)
-----------------------------------------------------------------*/
unsigned int FAT_GetFileSystemTotalSize (void);
/*-----------------------------------------------------------------
FAT_chdir
Changes the current working directory
const char* path: IN null terminated string of directory separated by
forward slashes, / is root
unsigned char return: OUT returns true if successful
-----------------------------------------------------------------*/
char FAT_chdir (const char* path);
//-----------------------------------------------------------------
// File functions
/*-----------------------------------------------------------------
FAT_fopen(filename, mode)
Opens a file
const char* path: IN null terminated string of filename and path
separated by forward slashes, / is root
const char* mode: IN mode to open file in
Supported modes: "r", "r+", "w", "w+", "a", "a+", don't use
"b" or "t" in any mode, as all files are openned in binary mode
FAT_FILE* return: OUT handle to open file, returns -1 if the file
couldn't be openned
-----------------------------------------------------------------*/
FAT_FILE* FAT_fopen(const char* path, const char* mode);
/*-----------------------------------------------------------------
FAT_fclose(file)
Closes a file
FAT_FILE* file: IN handle of the file to close
unsigned char return OUT: true if successful, false if not
-----------------------------------------------------------------*/
char FAT_fclose (FAT_FILE* file);
/*-----------------------------------------------------------------
FAT_ftell(file)
Returns the current position in a file
FAT_FILE* file: IN handle of an open file
unsigned int OUT: Current position
-----------------------------------------------------------------*/
int FAT_ftell (FAT_FILE* file);
/*-----------------------------------------------------------------
FAT_fseek(file, offset, origin)
Seeks to specified byte position in file
int file: IN handle of an open file
unsigned int offset IN: position to seek to, relative to origin
int origin IN: origin to seek from
int OUT: Returns 0 if successful, -1 if not
-----------------------------------------------------------------*/
int FAT_fseek(FAT_FILE* file, int offset, int origin);
/*-----------------------------------------------------------------
FAT_fread(buffer, size, count, file)
Reads in length number of bytes into buffer from file, starting
from current position. It then sets the current position to the
byte after the last byte read. If it reaches the end of file
before filling the buffer then it stops reading.
void* buffer OUT: Pointer to buffer to fill. Should be at least as
big as the number of bytes required
unsigned int size IN: size of each item to read
unsigned int count IN: number of items to read
FAT_FILE* file IN: Handle of an open file
unsigned int OUT: returns the actual number of bytes read
-----------------------------------------------------------------*/
unsigned int FAT_fread (void* buffer, unsigned int size, unsigned int count, FAT_FILE* file);
#ifdef CAN_WRITE_TO_DISC
/*-----------------------------------------------------------------
FAT_fwrite(buffer, size, count, file)
Writes size * count bytes into file from buffer, starting
from current position. It then sets the current position to the
byte after the last byte written. If the file was openned in
append mode it always writes to the end of the file.
const void* buffer IN: Pointer to buffer containing data. Should be
at least as big as the number of bytes to be written.
unsigned int size IN: size of each item to write
unsigned int count IN: number of items to write
FAT_FILE* file IN: Handle of an open file
unsigned int OUT: returns the actual number of bytes written
-----------------------------------------------------------------*/
unsigned int FAT_fwrite (const void* buffer, unsigned int size, unsigned int count, FAT_FILE* file);
#endif
/*-----------------------------------------------------------------
FAT_feof(file)
Returns true if the end of file has been reached
FAT_FILE* file IN: Handle of an open file
unsigned char return OUT: true if EOF, false if not
-----------------------------------------------------------------*/
char FAT_feof(FAT_FILE* file);
#ifdef CAN_WRITE_TO_DISC
/*-----------------------------------------------------------------
FAT_remove (path)
Deletes the file or empty directory sepecified in path
const char* path IN: Path of item to delete
int return OUT: zero if successful, non-zero if not
-----------------------------------------------------------------*/
int FAT_remove (const char* path);
#endif
#ifdef CAN_WRITE_TO_DISC
/*-----------------------------------------------------------------
FAT_mkdir (path)
Makes a new directory, so long as no other directory or file has
the same name.
const char* path IN: Path and filename of directory to make
int return OUT: zero if successful, non-zero if not
-----------------------------------------------------------------*/
int FAT_mkdir (const char* path);
#endif
/*-----------------------------------------------------------------
FAT_fgetc (handle)
Gets the next character in the file
FAT_FILE* file IN: Handle of open file
unsigned char return OUT: character if successful, EOF if not
-----------------------------------------------------------------*/
char FAT_fgetc (FAT_FILE* file);
#ifdef CAN_WRITE_TO_DISC
/*-----------------------------------------------------------------
FAT_fputc (character, handle)
Writes the given character into the file
char c IN: Character to be written
FAT_FILE* handle IN: Handle of open file
unsigned char return OUT: character if successful, EOF if not
-----------------------------------------------------------------*/
char FAT_fputc (char c, FAT_FILE* file);
#endif
/*-----------------------------------------------------------------
FAT_fgets (char *tgtBuffer, int num, FAT_FILE* file)
Gets a up to num bytes from file, stopping at the first
newline.
CAUTION: does not do strictly streaming. I.e. it's
reading more then needed bytes and seeking back.
shouldn't matter for random access
char *tgtBuffer OUT: buffer to write to
int num IN: size of target buffer
FAT_FILE* file IN: Handle of open file
unsigned char return OUT: character if successful, EOF if not
Written by MightyMax
Modified by Chishm - 2005-11-17
* Added check for unix style text files
* Removed seek when no newline is found, since it isn't necessary
-------------------------------------------------------------------*/
char *FAT_fgets(char *tgtBuffer, int num, FAT_FILE* file) ;
#ifdef CAN_WRITE_TO_DISC
/*-----------------------------------------------------------------
FAT_fputs (const char *string, FAT_FILE* file)
Writes string to file, excluding end of string character
const char *string IN: string to write
FAT_FILE* file IN: Handle of open file
unsigned char return OUT: number of characters written if successful,
EOF if not
Written by MightyMax
Modified by Chishm - 2005-11-17
* Uses FAT_FILE instead of int
* writtenBytes is now unsigned int instead of int
-------------------------------------------------------------------*/
int FAT_fputs (const char *string, FAT_FILE* file);
#endif
//------------------------------------------------------------------
#ifdef __cplusplus
} // extern "C"
#endif
//------------------------------------------------------------------
#endif // ifndef _GBA_NDS_FAT
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -