Hanna
Sourcecode Batteriemanagementsystem
Module | Dateien | Datenstrukturen | Makrodefinitionen | Funktionen
FAT support
Zusammengehörigkeiten von FAT support:

Module

 FAT configuration
 
 FAT access
 
 FAT file functions
 
 FAT directory functions
 

Dateien

Datei  fat.c
 SD-Card Reader Bibliothek von Roland Riegel.
 
Datei  fat.h
 SD-Card Reader Bibliothek von Roland Riegel.
 
Datei  fat_config.h
 SD-Card Reader Bibliothek von Roland Riegel.
 

Datenstrukturen

struct  fat_dir_entry_struct
 

Makrodefinitionen

#define fat_delete_dir   fat_delete_file
 
#define fat_move_dir   fat_move_file
 

Funktionen

void fat_close (struct fat_fs_struct *fs)
 
void fat_close_dir (struct fat_dir_struct *dd)
 
void fat_close_file (struct fat_file_struct *fd)
 
uint8_t fat_create_dir (struct fat_dir_struct *parent, const char *dir, struct fat_dir_entry_struct *dir_entry)
 
uint8_t fat_create_file (struct fat_dir_struct *parent, const char *file, struct fat_dir_entry_struct *dir_entry)
 
uint8_t fat_delete_file (struct fat_fs_struct *fs, struct fat_dir_entry_struct *dir_entry)
 
uint8_t fat_get_dir_entry_of_path (struct fat_fs_struct *fs, const char *path, struct fat_dir_entry_struct *dir_entry)
 
void fat_get_file_modification_date (const struct fat_dir_entry_struct *dir_entry, uint16_t *year, uint8_t *month, uint8_t *day)
 
void fat_get_file_modification_time (const struct fat_dir_entry_struct *dir_entry, uint8_t *hour, uint8_t *min, uint8_t *sec)
 
offset_t fat_get_fs_free (const struct fat_fs_struct *fs)
 
offset_t fat_get_fs_size (const struct fat_fs_struct *fs)
 
uint8_t fat_move_file (struct fat_fs_struct *fs, struct fat_dir_entry_struct *dir_entry, struct fat_dir_struct *parent_new, const char *file_new)
 
struct fat_fs_structfat_open (struct partition_struct *partition)
 
struct fat_dir_structfat_open_dir (struct fat_fs_struct *fs, const struct fat_dir_entry_struct *dir_entry)
 
struct fat_file_structfat_open_file (struct fat_fs_struct *fs, const struct fat_dir_entry_struct *dir_entry)
 
uint8_t fat_read_dir (struct fat_dir_struct *dd, struct fat_dir_entry_struct *dir_entry)
 
intptr_t fat_read_file (struct fat_file_struct *fd, uint8_t *buffer, uintptr_t buffer_len)
 
uint8_t fat_reset_dir (struct fat_dir_struct *dd)
 
uint8_t fat_resize_file (struct fat_file_struct *fd, uint32_t size)
 
uint8_t fat_seek_file (struct fat_file_struct *fd, int32_t *offset, uint8_t whence)
 
intptr_t fat_write_file (struct fat_file_struct *fd, const uint8_t *buffer, uintptr_t buffer_len)
 
void get_datetime (uint16_t *year, uint8_t *month, uint8_t *day, uint8_t *hour, uint8_t *min, uint8_t *sec)
 This function is the link between the hardware RTC and the timekeeping function to the sd-reader code. Mehr ...
 

Ausführliche Beschreibung

This module implements FAT16/FAT32 read and write access.

The following features are supported:

Dokumentation der Funktionen

void fat_close ( struct fat_fs_struct fs)

Closes a FAT filesystem.

When this function returns, the given filesystem descriptor will be invalid.

Parameter
[in]fsThe filesystem to close.
Siehe auch
fat_open

Definiert in Zeile 302 der Datei fat.c.

void fat_close_dir ( struct fat_dir_struct dd)

Closes a directory descriptor.

This function destroys a directory descriptor which was previously obtained by calling fat_open_dir(). When this function returns, the given descriptor will be invalid.

Parameter
[in]ddThe directory descriptor to close.
Siehe auch
fat_open_dir

Definiert in Zeile 1363 der Datei fat.c.

Hier ist ein Graph der zeigt, wo diese Funktion aufgerufen wird:

void fat_close_file ( struct fat_file_struct fd)

Closes a file.

Parameter
[in]fdThe file handle of the file to close.
Siehe auch
fat_open_file

Definiert in Zeile 913 der Datei fat.c.

Hier ist ein Graph, der zeigt, was diese Funktion aufruft:

uint8_t fat_create_dir ( struct fat_dir_struct parent,
const char *  dir,
struct fat_dir_entry_struct dir_entry 
)

Creates a directory.

Creates a directory and obtains its directory entry. If the directory to create already exists, its directory entry will be returned within the dir_entry parameter.

Zu beachten
The notes which apply to fat_create_file() also apply to this function.
Parameter
[in]parentThe handle of the parent directory of the new directory.
[in]dirThe name of the directory to create.
[out]dir_entryThe directory entry to fill for the new directory.
Rückgabe
0 on failure, 1 on success.
Siehe auch
fat_delete_dir

Definiert in Zeile 2139 der Datei fat.c.

Hier ist ein Graph, der zeigt, was diese Funktion aufruft:

uint8_t fat_create_file ( struct fat_dir_struct parent,
const char *  file,
struct fat_dir_entry_struct dir_entry 
)

Creates a file.

Creates a file and obtains the directory entry of the new file. If the file to create already exists, the directory entry of the existing file will be returned within the dir_entry parameter.

Zu beachten
The file name is not checked for invalid characters.
The generation of the short 8.3 file name is quite simple. The first eight characters are used for the filename. The extension, if any, is made up of the first three characters following the last dot within the long filename. If the filename (without the extension) is longer than eight characters, the lower byte of the cluster number replaces the last two characters to avoid name clashes. In any other case, it is your responsibility to avoid name clashes.
Parameter
[in]parentThe handle of the directory in which to create the file.
[in]fileThe name of the file to create.
[out]dir_entryThe directory entry to fill for the new (or existing) file.
Rückgabe
0 on failure, 1 on success, 2 if the file already existed.
Siehe auch
fat_delete_file

Definiert in Zeile 1971 der Datei fat.c.

Hier ist ein Graph, der zeigt, was diese Funktion aufruft:

Hier ist ein Graph der zeigt, wo diese Funktion aufgerufen wird:

uint8_t fat_delete_file ( struct fat_fs_struct fs,
struct fat_dir_entry_struct dir_entry 
)

Deletes a file or directory.

If a directory is deleted without first deleting its subdirectories and files, disk space occupied by these files will get wasted as there is no chance to release it and mark it as free.

Parameter
[in]fsThe filesystem on which to operate.
[in]dir_entryThe directory entry of the file to delete.
Rückgabe
0 on failure, 1 on success.
Siehe auch
fat_create_file

Definiert in Zeile 2018 der Datei fat.c.

Hier ist ein Graph, der zeigt, was diese Funktion aufruft:

Hier ist ein Graph der zeigt, wo diese Funktion aufgerufen wird:

uint8_t fat_get_dir_entry_of_path ( struct fat_fs_struct fs,
const char *  path,
struct fat_dir_entry_struct dir_entry 
)

Retrieves the directory entry of a path.

The given path may both describe a file or a directory.

Parameter
[in]fsThe FAT filesystem on which to search.
[in]pathThe path of which to read the directory entry.
[out]dir_entryThe directory entry to fill.
Rückgabe
0 on failure, 1 on success.
Siehe auch
fat_read_dir

Definiert in Zeile 808 der Datei fat.c.

Hier ist ein Graph, der zeigt, was diese Funktion aufruft:

void fat_get_file_modification_date ( const struct fat_dir_entry_struct dir_entry,
uint16_t *  year,
uint8_t *  month,
uint8_t *  day 
)

Deletes a directory.

This is just a synonym for fat_delete_file(). If a directory is deleted without first deleting its subdirectories and files, disk space occupied by these files will get wasted as there is no chance to release it and mark it as free.

Parameter
[in]fsThe filesystem on which to operate.
[in]dir_entryThe directory entry of the directory to delete.
Rückgabe
0 on failure, 1 on success.
Siehe auch
fat_create_dir

Moves or renames a directory.

This is just a synonym for fat_move_file().

Parameter
[in]fsThe filesystem on which to operate.
[in,out]dir_entryThe directory entry of the directory to move.
[in]parent_newThe handle of the new parent directory.
[in]dir_newThe directory's new name.
Rückgabe
0 on failure, 1 on success.
Siehe auch
fat_create_dir, fat_delete_dir, fat_move_file

Returns the modification date of a file.

Parameter
[in]dir_entryThe directory entry of which to return the modification date.
[out]yearThe year the file was last modified.
[out]monthThe month the file was last modified.
[out]dayThe day the file was last modified.

Definiert in Zeile 2253 der Datei fat.c.

void fat_get_file_modification_time ( const struct fat_dir_entry_struct dir_entry,
uint8_t *  hour,
uint8_t *  min,
uint8_t *  sec 
)

Returns the modification time of a file.

Parameter
[in]dir_entryThe directory entry of which to return the modification time.
[out]hourThe hour the file was last modified.
[out]minThe min the file was last modified.
[out]secThe sec the file was last modified.

Definiert in Zeile 2273 der Datei fat.c.

offset_t fat_get_fs_free ( const struct fat_fs_struct fs)

Returns the amount of free storage capacity on the filesystem in bytes.

Zu beachten
As the FAT filesystem is cluster based, this function does not return continuous values but multiples of the cluster size.
Parameter
[in]fsThe filesystem on which to operate.
Rückgabe
0 on failure, the free filesystem space in bytes otherwise.

Definiert in Zeile 2348 der Datei fat.c.

Hier ist ein Graph, der zeigt, was diese Funktion aufruft:

offset_t fat_get_fs_size ( const struct fat_fs_struct fs)

Returns the amount of total storage capacity of the filesystem in bytes.

Parameter
[in]fsThe filesystem on which to operate.
Rückgabe
0 on failure, the filesystem size in bytes otherwise.

Definiert in Zeile 2326 der Datei fat.c.

uint8_t fat_move_file ( struct fat_fs_struct fs,
struct fat_dir_entry_struct dir_entry,
struct fat_dir_struct parent_new,
const char *  file_new 
)

Moves or renames a file.

Changes a file's name, optionally moving it into another directory as well. Before calling this function, the target file name must not exist. Moving a file to a different filesystem (i.e. parent_new doesn't lie on fs) is not supported.

After successfully renaming (and moving) the file, the given directory entry is updated such that it points to the file's new location.

Zu beachten
The notes which apply to fat_create_file() also apply to this function.
Parameter
[in]fsThe filesystem on which to operate.
[in,out]dir_entryThe directory entry of the file to move.
[in]parent_newThe handle of the new parent directory of the file.
[in]file_newThe file's new name.
Rückgabe
0 on failure, 1 on success.
Siehe auch
fat_create_file, fat_delete_file, fat_move_dir

Definiert in Zeile 2083 der Datei fat.c.

Hier ist ein Graph, der zeigt, was diese Funktion aufruft:

struct fat_fs_struct* fat_open ( struct partition_struct partition)

Opens a FAT filesystem.

Parameter
[in]partitionDiscriptor of partition on which the filesystem resides.
Rückgabe
0 on error, a FAT filesystem descriptor on success.
Siehe auch
fat_close

Definiert in Zeile 250 der Datei fat.c.

Hier ist ein Graph, der zeigt, was diese Funktion aufruft:

struct fat_dir_struct* fat_open_dir ( struct fat_fs_struct fs,
const struct fat_dir_entry_struct dir_entry 
)

Opens a directory.

Parameter
[in]fsThe filesystem on which the directory to open resides.
[in]dir_entryThe directory entry which stands for the directory to open.
Rückgabe
An opaque directory descriptor on success, 0 on failure.
Siehe auch
fat_close_dir

Definiert in Zeile 1324 der Datei fat.c.

Hier ist ein Graph der zeigt, wo diese Funktion aufgerufen wird:

struct fat_file_struct* fat_open_file ( struct fat_fs_struct fs,
const struct fat_dir_entry_struct dir_entry 
)

Opens a file on a FAT filesystem.

Parameter
[in]fsThe filesystem on which the file to open lies.
[in]dir_entryThe directory entry of the file to open.
Rückgabe
The file handle, or 0 on failure.
Siehe auch
fat_close_file

Definiert in Zeile 878 der Datei fat.c.

uint8_t fat_read_dir ( struct fat_dir_struct dd,
struct fat_dir_entry_struct dir_entry 
)

Reads the next directory entry contained within a parent directory.

Parameter
[in]ddThe descriptor of the parent directory from which to read the entry.
[out]dir_entryPointer to a buffer into which to write the directory entry information.
Rückgabe
0 on failure, 1 on success.
Siehe auch
fat_reset_dir

Definiert in Zeile 1382 der Datei fat.c.

Hier ist ein Graph, der zeigt, was diese Funktion aufruft:

Hier ist ein Graph der zeigt, wo diese Funktion aufgerufen wird:

intptr_t fat_read_file ( struct fat_file_struct fd,
uint8_t *  buffer,
uintptr_t  buffer_len 
)

Reads data from a file.

The data requested is read from the current file location.

Parameter
[in]fdThe file handle of the file from which to read.
[out]bufferThe buffer into which to write.
[in]buffer_lenThe amount of data to read.
Rückgabe
The number of bytes read, 0 on end of file, or -1 on failure.
Siehe auch
fat_write_file

Definiert in Zeile 942 der Datei fat.c.

Hier ist ein Graph, der zeigt, was diese Funktion aufruft:

uint8_t fat_reset_dir ( struct fat_dir_struct dd)

Resets a directory handle.

Resets the directory handle such that reading restarts with the first directory entry.

Parameter
[in]ddThe directory handle to reset.
Rückgabe
0 on failure, 1 on success.
Siehe auch
fat_read_dir

Definiert in Zeile 1487 der Datei fat.c.

Hier ist ein Graph der zeigt, wo diese Funktion aufgerufen wird:

uint8_t fat_resize_file ( struct fat_file_struct fd,
uint32_t  size 
)

Resizes a file to have a specific size.

Enlarges or shrinks the file pointed to by the file descriptor to have exactly the specified size.

If the file is truncated, all bytes having an equal or larger offset than the given size are lost. If the file is expanded, the additional bytes are allocated.

Zu beachten
Please be aware that this function just allocates or deallocates disk space, it does not explicitely clear it. To avoid data leakage, this must be done manually.
Parameter
[in]fdThe file decriptor of the file which to resize.
[in]sizeThe new size of the file.
Rückgabe
0 on failure, 1 on success.

Definiert in Zeile 1239 der Datei fat.c.

Hier ist ein Graph, der zeigt, was diese Funktion aufruft:

Hier ist ein Graph der zeigt, wo diese Funktion aufgerufen wird:

uint8_t fat_seek_file ( struct fat_file_struct fd,
int32_t *  offset,
uint8_t  whence 
)

Repositions the read/write file offset.

Changes the file offset where the next call to fat_read_file() or fat_write_file() starts reading/writing.

If the new offset is beyond the end of the file, fat_resize_file() is implicitly called, i.e. the file is expanded.

The new offset can be given in different ways determined by the whence parameter:

  • FAT_SEEK_SET: *offset is relative to the beginning of the file.
  • FAT_SEEK_CUR: *offset is relative to the current file position.
  • FAT_SEEK_END: *offset is relative to the end of the file.

The resulting absolute offset is written to the location the offset parameter points to.

Calling this function can also be used to retrieve the current file position:

1 int32_t file_pos = 0;
2 if(!fat_seek_file(fd, &file_pos, FAT_SEEK_CUR))
3 {
4 // error
5 }
6 // file_pos now contains the absolute file position
Parameter
[in]fdThe file decriptor of the file on which to seek.
[in,out]offsetA pointer to the new offset, as affected by the whence parameter. The function writes the new absolute offset to this location before it returns.
[in]whenceAffects the way offset is interpreted, see above.
Rückgabe
0 on failure, 1 on success.

Definiert in Zeile 1186 der Datei fat.c.

Hier ist ein Graph, der zeigt, was diese Funktion aufruft:

intptr_t fat_write_file ( struct fat_file_struct fd,
const uint8_t *  buffer,
uintptr_t  buffer_len 
)

Writes data to a file.

The data is written to the current file location.

Parameter
[in]fdThe file handle of the file to which to write.
[in]bufferThe buffer from which to read the data to be written.
[in]buffer_lenThe amount of data to write.
Rückgabe
The number of bytes written (0 or something less than buffer_len on disk full) or -1 on failure.
Siehe auch
fat_read_file

Definiert in Zeile 1032 der Datei fat.c.

Hier ist ein Graph, der zeigt, was diese Funktion aufruft:

void get_datetime ( uint16_t *  year,
uint8_t *  month,
uint8_t *  day,
uint8_t *  hour,
uint8_t *  min,
uint8_t *  sec 
)

This function is the link between the hardware RTC and the timekeeping function to the sd-reader code.

Parameter
yearPointer to year
monthPointer to month
dayPointer to day
hourPointer to hour
minPointer to min
secPointer to sec


This function is the link between the hardware RTC and the timekeeping function to the sd-reader code.

To enable access time stamping in the application, set

1 #define FAT_DATETIME_SUPPORT 1

in fat_config.h.

The documentation indicates that functions fat_set_file_modification_date() and fat_set_file_modification_time() are available, but in fact they’re not.
The way to get time stamps to work is to define a function:

1 void get_datetime(uint16_t* year, uint8_t* month, uint8_t* day, uint8_t* hour, uint8_t* min, uint8_t* sec);

which is also defined in fat_config.h and gets called by the sd-reader code.
You write this function so that your timekeeping code fills in the values.

Definiert in Zeile 2452 der Datei fat.c.

Hier ist ein Graph, der zeigt, was diese Funktion aufruft: