#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <file.h>
#include <assert.h>
#include <std.h>
#include <clk.h>
#include <errno.h>
#include "fatfs.h"
#include "private/fatfs_int.h"
Macros | |
#define | MAX_FILENO 21 |
hardcoded max 21 FDS. TODO - make dynamic... | |
#define | SEC_PER_MIN 60 |
#define | MIN_PER_HOUR 60 |
#define | HOURS_PER_DAY 24 |
#define | DAYS_PER_YEAR 365 |
Functions | |
int | FAT_Get83Extension (char *apBuffer, char *apBasename, char *apExtension) |
Utility to strip 8.3 file name into basename and extension. | |
int | FAT_finddirent (const char *apPath, tsFATDevData *apDevData, uint32_t *apDirStartCluster, uint32_t *apDirEntryCluster, uint32_t *apDirEntryInCluster, tsDirEntry *apFileEntry) |
Given a path, locates parent directory cluster information and directory entry information. | |
int | FAT_createdirent (const char *apNewPath, tsFATDevData *apDevData) |
Given a path to a non-existent entry in a directory, this function creates a new subdirectory at the provided path. | |
int | FAT_GetNextCluster (tsFATDevData *apDevData, int anCluster) |
Find the Next Cluster In the Chain. | |
int | FAT_UpdateDirEntry (tsFATFileData *apFileData) |
Updates Directory Data based on current file structure (cached) information. | |
int | FAT_CountFreeClusters (tsFATDevData *apDevData) |
Count free clusters on the FAT Table. | |
int | FAT_TruncateCluster (tsFATDevData *apDevData, int anCluster) |
Mark the current cluster as the end of chain, and free all following clusters. | |
int | FAT_FreeCluster (tsFATDevData *apDevData, int anCluster) |
Free a chain of clusters in the FAT Table. | |
int | FAT_GetFreeCluster (tsFATDevData *apDevData, int anChainedCluster) |
Find a free cluster on the FAT Table and Mark it used with EOC. | |
int | FAT_open (const char *apPath, unsigned int anFlags, int anFileno, tsFATDevData *apDevData) |
Attempt to open an existing file or create a new file at the given path. | |
int | FAT_close (int anFileno) |
Close a file descriptor assocaited with a FAT device. | |
int | FAT_read (int anFileno, char *apBuffer, unsigned int anCount) |
Read implementation for a FAT filesystem. | |
int | FAT_write (int anFileno, const char *apBuffer, unsigned int anCount) |
Write implementation for a FAT filesystem. | |
off_t | FAT_lseek (int anFileno, off_t anOffset, int aeOrigin) |
FAT driver lseek implementation. | |
int | FAT_unlink (const char *apPath, tsFATDevData *apDevData) |
Delete a file. | |
int | FAT_rename (const char *apOldPath, const char *apNewPath, tsFATDevData *apDevData) |
Rename a file on a FAT device. | |
int | FAT_gettime (unsigned int *apYear, unsigned int *apMonth, unsigned int *apDay, unsigned int *apHours, unsigned int *apMinutes, unsigned int *apSeconds, unsigned int *apHundredths) |
Default time callback, used when access to a RTC device is not provided to the FAT filesystem driver. |
Variables | |
tsFATFileData | gpFileData [MAX_FILENO] |
data needed for each file descriptor | |
static char | FAT_valid_chars [128] |
#define MAX_FILENO 21 |
hardcoded max 21 FDS. TODO - make dynamic...
#define SEC_PER_MIN 60 |
#define MIN_PER_HOUR 60 |
#define HOURS_PER_DAY 24 |
#define DAYS_PER_YEAR 365 |
int FAT_Get83Extension | ( | char * | apBuffer, |
char * | apBasename, | ||
char * | apExtension | ||
) |
Utility to strip 8.3 file name into basename and extension.
[in] | apBuffer | Name to parse. |
[out] | apBasename | Storage for base name |
[out] | apExtension | Storage for file extension |
int FAT_finddirent | ( | const char * | apPath, |
tsFATDevData * | apDevData, | ||
uint32_t * | apDirStartCluster, | ||
uint32_t * | apDirEntryCluster, | ||
uint32_t * | apDirEntryInCluster, | ||
tsDirEntry * | apFileEntry | ||
) |
Given a path, locates parent directory cluster information and directory entry information.
[in] | apPath | pointer to null terminated path to file |
[in] | apDevData | FAT interface device data structure |
[out] | apDirStartCluster | holder for found parent directory starting cluster. This value is set 0xFFFFFFFF if the path was not found. For FAT16 the dir_start_cluster will be 0x00000000 if the path points to the root directory (which is not in the FAT Data Area). |
[out] | apDirEntryCluster | holder for found parent directory cluster containing the entry of the file specified in the path. If the file was not found, then this value is set to 0xFFFFFFF. |
[out] | apDirEntryInCluster | the 32 byte index in the dir_entry_cluster containing the location of the file specified. If the file was not found, then this value is set to 0xFFFFFFFF. |
[out] | apFileEntry | a copy of the file entry infromation from the parent directory file, this information is not modified if the file is not found. |
int FAT_createdirent | ( | const char * | apNewPath, |
tsFATDevData * | apDevData | ||
) |
Given a path to a non-existent entry in a directory, this function creates a new subdirectory at the provided path.
[in] | apNewPath | pointer to null terminated path to the directory |
[in] | apDevData | FAT interface device data structure |
int FAT_GetNextCluster | ( | tsFATDevData * | apDevData, |
int | anCluster | ||
) |
Find the Next Cluster In the Chain.
[in] | apDevData | FAT interface device data structure |
[in] | anCluster | Current cluster number |
int FAT_UpdateDirEntry | ( | tsFATFileData * | apFileData | ) |
Updates Directory Data based on current file structure (cached) information.
[in] | apFileData | Pointer to file data |
int FAT_CountFreeClusters | ( | tsFATDevData * | apDevData | ) |
Count free clusters on the FAT Table.
[in] | apDevData | Pointer to file system driver |
int FAT_TruncateCluster | ( | tsFATDevData * | apDevData, |
int | anCluster | ||
) |
Mark the current cluster as the end of chain, and free all following clusters.
[in] | apDevData | Pointer to file system driver |
[in] | anCluster | The head of the chain of clusters to truncate. |
int FAT_FreeCluster | ( | tsFATDevData * | apDevData, |
int | anCluster | ||
) |
Free a chain of clusters in the FAT Table.
[in] | apDevData | Pointer to file system driver |
[in] | anCluster | The head of the chain of clusters to free. |
int FAT_GetFreeCluster | ( | tsFATDevData * | apDevData, |
int | anChainedCluster | ||
) |
Find a free cluster on the FAT Table and Mark it used with EOC.
[in] | apDevData | Pointer to file system driver |
[in] | anChainedCluster | If non-zero, the cluster entry provided will be linked to the newly found free cluster (for file growth) |
int FAT_open | ( | const char * | apPath, |
unsigned int | anFlags, | ||
int | anFileno, | ||
tsFATDevData * | apDevData | ||
) |
Attempt to open an existing file or create a new file at the given path.
Flags indicate actions to be taken.
[in] | apPath | The complete file path. |
[in] | anFlags | Flags to control actions (O_WRONLY | O_CREAT | O_TRUNC | O_APPEND) |
[in] | anFileno | Internal file descriptor for opened file. |
[in] | apDevData | Pointer to file system driver |
int FAT_close | ( | int | anFileno | ) |
Close a file descriptor assocaited with a FAT device.
[in] | anFileno | Internal file descriptor for opened file. |
int FAT_read | ( | int | anFileno, |
char * | apBuffer, | ||
unsigned int | anCount | ||
) |
Read implementation for a FAT filesystem.
This routine will up to the specified byte count to the provided buffer from the file referenced by the anFileno file descriptor.
[in] | anFileno | Internal file descriptor for opened file. |
[in] | apBuffer | Pointer to data to store read data |
[in] | anCount | Number of bytes to read from device |
int FAT_write | ( | int | anFileno, |
const char * | apBuffer, | ||
unsigned int | anCount | ||
) |
Write implementation for a FAT filesystem.
This routine will write count bytes in buffer to the file reference by the anFileno file descriptor.
[in] | anFileno | Internal file descriptor for opened file. |
[in] | apBuffer | Pointer to data to write. |
[in] | anCount | Number of bytes to write to device |
off_t FAT_lseek | ( | int | anFileno, |
off_t | anOffset, | ||
int | aeOrigin | ||
) |
FAT driver lseek implementation.
[in] | anFileno | Internal file descriptor for opened file. |
[in] | anOffset | Byte offset from provided origin. |
[in] | aeOrigin | SEEK_SET, SEEK_CUR, or SEEK_END. |
int FAT_unlink | ( | const char * | apPath, |
tsFATDevData * | apDevData | ||
) |
Delete a file.
[in] | apPath | Pointer to null terminated path to file |
[in] | apDevData | FAT interface device data structure |
int FAT_rename | ( | const char * | apOldPath, |
const char * | apNewPath, | ||
tsFATDevData * | apDevData | ||
) |
Rename a file on a FAT device.
[in] | apOldPath | Pointer to null terminated path to current file |
[in] | apNewPath | Pointer to null terminated new path for file |
[in] | apDevData | FAT interface device data structure |
int FAT_gettime | ( | unsigned int * | apYear, |
unsigned int * | apMonth, | ||
unsigned int * | apDay, | ||
unsigned int * | apHours, | ||
unsigned int * | apMinutes, | ||
unsigned int * | apSeconds, | ||
unsigned int * | apHundredths | ||
) |
Default time callback, used when access to a RTC device is not provided to the FAT filesystem driver.
It uses the system tick timer to compute a date based on the tick count, offset from midnight on January 1, 2000.
[out] | apYear | Location to store RTC year (1980-20??) |
[out] | apMonth | Location to store RTC month (1-12) |
[out] | apDay | Location to store RTC day (1-31) |
[out] | apHours | Location to store RTC hour (0-23) |
[out] | apMinutes | Location to store RTC minutes (0-59) |
[out] | apSeconds | Location to store RTC seconds (0-59) |
[out] | apHundredths | Location to store RTC 1/100's seconds (0-99) |
tsFATFileData gpFileData[MAX_FILENO] |
data needed for each file descriptor
|
static |