|
Functions | |
| __PFILE | __fileOpen (__CONST __PSTRING file, u8 mode) |
| Opens a file. | |
| u32 | __fileRead (__PFILE file, __PVOID buf, u32 qty) |
| Reads file content. | |
| __FILE_RES | __fileSeek (__PFILE file, u32 offs) |
| Seeks to an absolute offset. | |
| __FILE_RES | __fileClose (__PFILE file) |
| __FILE_RES | __fileGetStatus (__CONST __PSTRING file, __PFILEINFO fi) |
| Get the file status. | |
| u32 | __fileWrite (__PFILE file, __PVOID buf, u32 qty) |
| Writes data to a file. | |
| __FILE_RES | __fileFlush (__PFILE file) |
| Flushes unwritten data. | |
| __FILE_RES | __fileTruncate (__PFILE file) |
| Truncates the file size. | |
| __FILE_RES | __fileDelete (__CONST __PSTRING file) |
| Deletes a file. | |
| __FILE_RES | __fileChmod (__CONST __PSTRING file, u8 value, u8 mask) |
| Changes the attributes of a file or directory. | |
| __FILE_RES | __fileChangeTime (__CONST __PSTRING file, __CONST __PFILEINFO fi) |
| Changes the timestamp of a file or directory. | |
| __FILE_RES | __fileRename (__CONST __PSTRING name1, __CONST __PSTRING name2) |
| Renames a file or directory. | |
File/Directory functions.
| __PFILE __fileOpen | ( | __CONST __PSTRING | file, |
| u8 | mode | ||
| ) |
Opens a file.
The pointer returned is dynamically allocated, and it will be destroyed in __fileClose().
| file | File name. |
| mode | Open mode.
|
Definition at line 470 of file fat.c.
{
__PFILE ptr;
ptr = (__PFILE) __heapAllocZero(sizeof(__FILE));
if (!ptr) return __NULL;
if (f_open(ptr, file, mode) != FR_OK)
{
__heapFree(ptr);
return __NULL;
}
return ptr;
}

| u32 __fileRead | ( | __PFILE | file, |
| __PVOID | buf, | ||
| u32 | qty | ||
| ) |
Reads file content.
| file | File opened with __fileOpen(). |
| buf | Buffer to receive the read data. |
| qty | Quantity of bytes to read. |
qty. Definition at line 496 of file fat.c.
{
UINT ret = 0;
f_read(file, buf, qty, &ret);
return ret;
}
| __FILE_RES __fileSeek | ( | __PFILE | file, |
| u32 | offs | ||
| ) |
Seeks to an absolute offset.
From FatFS documentation: The f_lseek function moves the file read/write pointer of an open file. The offset can be specified in only origin from top of the file. When an offset above the file size is specified in write mode, the file size is increased and the data in the expanded area is undefined. This is suitable to create a large file quickly, for fast write operation. After the f_lseek function succeeded, member fptr in the file object should be checked in order to make sure the read/write pointer has been moved correctly. In case of fptr is not the expected value, either of followings has been occurred. End of file. The specified Offset was clipped at the file size because the file has been opened in read-only mode. Disk full. There is insufficient free space on the volume to expand the file size.
When _USE_FASTSEEK is set to 1 and cltbl member in the file object is not NULL, the fast seek feature is enabled. This feature enables fast backward/long seek operations without FAT access by cluster link information stored on the user defined table. The cluster link information must be created prior to do the fast seek. The required size of the table is (number of fragments + 1) * 2 items. For example, when the file is fragmented in 5, 12 items will be required to store the cluster link information. The file size cannot be expanded when the fast seek feature is enabled.
| file | File opened with __fileOpen(). |
| offs | Offset |
Definition at line 538 of file fat.c.
{
return f_lseek(file, offs);
}
| __FILE_RES __fileClose | ( | __PFILE | file | ) |
Closes a opened file.
From FatFS documentation: The f_close function closes an open file object. If any data has been written to the file, the cached information of the file is written back to the disk. After the function succeeded, the file object is no longer valid and it can be discarded.
| file | Pointer to a file created with __fileOpen(). |
Definition at line 560 of file fat.c.
{
__FILE_RES ret;
ret = f_close(file);
if (ret == FR_OK) {
__heapFree(file);
}
return ret;
}

| __FILE_RES __fileGetStatus | ( | __CONST __PSTRING | file, |
| __PFILEINFO | fi | ||
| ) |
Get the file status.
From FatFS documentation: The f_stat gets the information of a file or directory. For details of the information, refer to the FILINFO structure and f_readdir function. This function is not supported in minimization level of >= 1.
| file | File name. |
| fi | Pointer to a __FILEINFO structure to receive the file information. |
Definition at line 595 of file fat.c.
{
return f_stat(file, fi);
}
| u32 __fileWrite | ( | __PFILE | file, |
| __PVOID | buf, | ||
| u32 | qty | ||
| ) |
Writes data to a file.
From FatFS documentation: The read/write pointer in the file object is increased in number of bytes written. After the function succeeded, *ByteWritten should be checked to detect the disk full. In case of *ByteWritten < ByteToWrite, it means the volume got full during the write operation. The function can take a time when the volume is full or close to full.
| file | Pointer to a opened file. |
| buf | Pointer to the buffer to write. |
| qty | Quantity to write, in bytes. |
Definition at line 616 of file fat.c.
{
UINT ret;
f_write(file, buf, qty, &ret);
return ret;
}
| __FILE_RES __fileFlush | ( | __PFILE | file | ) |
Flushes unwritten data.
From FatFS documentation: The __fileFlush (f_sync) function performs the same process as __fileClose (f_close) function but the file is left opened and can continue read/write/seek operations to the file. This is suitable for the applications that open files for a long time in write mode, such as data logger. Performing f_sync of periodic or immediately after __fileFlush (f_write) can minimize the risk of data loss due to a sudden blackout or an unintentional disk removal. However f_sync immediately before f_close has no advantage because f_close performs f_sync in it. In other words, the difference between those functions is that the file object is invalidated or not.
| file | Pointer to opened file. |
Definition at line 644 of file fat.c.
{
return f_sync(file);
}
| __FILE_RES __fileTruncate | ( | __PFILE | file | ) |
Truncates the file size.
From FatFS documentation The f_truncate function truncates the file size to the current file read/write point. This function has no effect if the file read/write pointer is already pointing end of the file.
| file | Pointer to an opened file. |
Definition at line 666 of file fat.c.
{
return f_truncate(file);
}
| __FILE_RES __fileDelete | ( | __CONST __PSTRING | file | ) |
Deletes a file.
From FatFS documentation: The f_unlink function removes an object. Do not remove open objects.
| file | Pointer to a null-terminated string containing the file name. |
Definition at line 697 of file fat.c.
{
return f_unlink(file);
}
| __FILE_RES __fileChmod | ( | __CONST __PSTRING | file, |
| u8 | value, | ||
| u8 | mask | ||
| ) |
Changes the attributes of a file or directory.
| file | Pointer to a null-terminated string containing the file name. |
| value | A combination of the following flags:
|
| mask | Attribute mask that specifies which attribute is changed. The specified attributes are set or cleared. |
Definition at line 728 of file fat.c.
{
return f_chmod(file, value, mask);
}
| __FILE_RES __fileChangeTime | ( | __CONST __PSTRING | file, |
| __CONST __PFILEINFO | fi | ||
| ) |
Changes the timestamp of a file or directory.
| file | Pointer to a null-terminated string containing the file name. |
| fi | Pointer to the file information structure that has a timestamp to be set in member fdate and ftime. Other members will be ignored. |
Definition at line 754 of file fat.c.
{
return f_utime(file, fi);
}
| __FILE_RES __fileRename | ( | __CONST __PSTRING | name1, |
| __CONST __PSTRING | name2 | ||
| ) |
Renames a file or directory.
| name1 | Pointer to a null-terminated string containing the new file name. |
| name2 | Pointer to a null-terminated string containing the old file name. |