Files | |
file | fat16.c |
file | fat16.h |
file | fat16_config.h |
Modules | |
FAT16 configuration | |
FAT16 access | |
FAT16 file functions | |
FAT16 directory functions | |
Data Structures | |
struct | fat16_dir_entry_struct |
Defines | |
#define | fat16_delete_dir fat16_delete_file |
Functions | |
struct fat16_fs_struct * | fat16_open (struct partition_struct *partition) |
void | fat16_close (struct fat16_fs_struct *fs) |
struct fat16_file_struct * | fat16_open_file (struct fat16_fs_struct *fs, const struct fat16_dir_entry_struct *dir_entry) |
void | fat16_close_file (struct fat16_file_struct *fd) |
int16_t | fat16_read_file (struct fat16_file_struct *fd, uint8_t *buffer, uint16_t buffer_len) |
int16_t | fat16_write_file (struct fat16_file_struct *fd, const uint8_t *buffer, uint16_t buffer_len) |
uint8_t | fat16_seek_file (struct fat16_file_struct *fd, int32_t *offset, uint8_t whence) |
uint8_t | fat16_resize_file (struct fat16_file_struct *fd, uint32_t size) |
struct fat16_dir_struct * | fat16_open_dir (struct fat16_fs_struct *fs, const struct fat16_dir_entry_struct *dir_entry) |
void | fat16_close_dir (struct fat16_dir_struct *dd) |
uint8_t | fat16_read_dir (struct fat16_dir_struct *dd, struct fat16_dir_entry_struct *dir_entry) |
uint8_t | fat16_reset_dir (struct fat16_dir_struct *dd) |
uint8_t | fat16_create_file (struct fat16_dir_struct *parent, const char *file, struct fat16_dir_entry_struct *dir_entry) |
uint8_t | fat16_delete_file (struct fat16_fs_struct *fs, struct fat16_dir_entry_struct *dir_entry) |
uint8_t | fat16_create_dir (struct fat16_dir_struct *parent, const char *dir, struct fat16_dir_entry_struct *dir_entry) |
void | fat16_get_file_modification_date (const struct fat16_dir_entry_struct *dir_entry, uint16_t *year, uint8_t *month, uint8_t *day) |
void | fat16_get_file_modification_time (const struct fat16_dir_entry_struct *dir_entry, uint8_t *hour, uint8_t *min, uint8_t *sec) |
uint8_t | fat16_get_dir_entry_of_path (struct fat16_fs_struct *fs, const char *path, struct fat16_dir_entry_struct *dir_entry) |
uint32_t | fat16_get_fs_size (const struct fat16_fs_struct *fs) |
uint32_t | fat16_get_fs_free (const struct fat16_fs_struct *fs) |
void | get_datetime (uint16_t *year, uint8_t *month, uint8_t *day, uint8_t *hour, uint8_t *min, uint8_t *sec) |
The following features are supported:
void fat16_close | ( | struct fat16_fs_struct * | fs | ) |
Closes a FAT16 filesystem.
When this function returns, the given filesystem descriptor will be invalid.
[in] | fs | The filesystem to close. |
Definition at line 275 of file fat16.c.
References fat16_fs_struct::partition.
void fat16_close_dir | ( | struct fat16_dir_struct * | dd | ) |
Closes a directory descriptor.
This function destroys a directory descriptor which was previously obtained by calling fat16_open_dir(). When this function returns, the given descriptor will be invalid.
[in] | dd | The directory descriptor to close. |
Definition at line 1231 of file fat16.c.
References fat16_dir_struct::fs.
Referenced by fat16_get_dir_entry_of_path().
void fat16_close_file | ( | struct fat16_file_struct * | fd | ) |
Closes a file.
[in] | fd | The file handle of the file to close. |
Definition at line 786 of file fat16.c.
References fat16_file_struct::fs.
Referenced by main().
uint8_t fat16_create_dir | ( | struct fat16_dir_struct * | parent, | |
const char * | dir, | |||
struct fat16_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.
[in] | parent | The handle of the parent directory of the new directory. |
[in] | dir | The name of the directory to create. |
[out] | dir_entry | The directory entry to fill for the new directory. |
Definition at line 1888 of file fat16.c.
References fat16_dir_entry_struct::attributes, fat16_dir_entry_struct::cluster, fat16_header_struct::cluster_size, fat16_header_struct::cluster_zero_offset, fat16_dir_struct::dir_entry, fat16_dir_entry_struct::entry_offset, fat16_append_clusters(), FAT16_ATTRIB_DIR, fat16_clear_cluster(), fat16_find_offset_for_dir_entry(), fat16_free_clusters(), fat16_read_dir(), fat16_reset_dir(), fat16_write_dir_entry(), fat16_dir_struct::fs, fat16_fs_struct::header, and fat16_dir_entry_struct::long_name.
uint8_t fat16_create_file | ( | struct fat16_dir_struct * | parent, | |
const char * | file, | |||
struct fat16_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.
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.
[in] | parent | The handle of the directory in which to create the file. |
[in] | file | The name of the file to create. |
[out] | dir_entry | The directory entry to fill for the new file. |
Definition at line 1775 of file fat16.c.
References fat16_dir_entry_struct::entry_offset, fat16_find_offset_for_dir_entry(), fat16_read_dir(), fat16_reset_dir(), fat16_write_dir_entry(), fat16_dir_struct::fs, and fat16_dir_entry_struct::long_name.
uint8_t fat16_delete_file | ( | struct fat16_fs_struct * | fs, | |
struct fat16_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.
[in] | fs | The filesystem on which to operate. |
[in] | dir_entry | The directory entry of the file to delete. |
Definition at line 1829 of file fat16.c.
References fat16_dir_entry_struct::cluster, partition_struct::device_read, partition_struct::device_write, fat16_dir_entry_struct::entry_offset, FAT16_DIRENTRY_DELETED, fat16_free_clusters(), and fat16_fs_struct::partition.
uint8_t fat16_get_dir_entry_of_path | ( | struct fat16_fs_struct * | fs, | |
const char * | path, | |||
struct fat16_dir_entry_struct * | dir_entry | |||
) |
Retrieves the directory entry of a path.
The given path may both describe a file or a directory.
[in] | fs | The FAT16 filesystem on which to search. |
[in] | path | The path of which to read the directory entry. |
[out] | dir_entry | The directory entry to fill. |
Definition at line 391 of file fat16.c.
References fat16_dir_entry_struct::attributes, FAT16_ATTRIB_DIR, fat16_close_dir(), fat16_open_dir(), fat16_read_dir(), and fat16_dir_entry_struct::long_name.
Referenced by main().
void fat16_get_file_modification_date | ( | const struct fat16_dir_entry_struct * | dir_entry, | |
uint16_t * | year, | |||
uint8_t * | month, | |||
uint8_t * | day | |||
) |
Deletes a directory.
This is just a synonym for fat16_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.
[in] | fs | The filesystem on which to operate. |
[in] | dir_entry | The directory entry of the directory to delete. |
[in] | dir_entry | The directory entry of which to return the modification date. |
[out] | year | The year the file was last modified. |
[out] | month | The month the file was last modified. |
[out] | day | The day the file was last modified. |
void fat16_get_file_modification_time | ( | const struct fat16_dir_entry_struct * | dir_entry, | |
uint8_t * | hour, | |||
uint8_t * | min, | |||
uint8_t * | sec | |||
) |
Returns the modification time of a file.
[in] | dir_entry | The directory entry of which to return the modification time. |
[out] | hour | The hour the file was last modified. |
[out] | min | The min the file was last modified. |
[out] | sec | The sec the file was last modified. |
uint32_t fat16_get_fs_free | ( | const struct fat16_fs_struct * | fs | ) |
Returns the amount of free storage capacity on the filesystem in bytes.
[in] | fs | The filesystem on which to operate. |
Definition at line 2100 of file fat16.c.
References fat16_usage_count_callback_arg::buffer_size, fat16_usage_count_callback_arg::cluster_count, fat16_header_struct::cluster_size, partition_struct::device_read_interval, fat16_get_fs_free_callback(), fat16_header_struct::fat_offset, fat16_header_struct::fat_size, fat16_fs_struct::header, and fat16_fs_struct::partition.
Referenced by print_disk_info().
uint32_t fat16_get_fs_size | ( | const struct fat16_fs_struct * | fs | ) |
Returns the amount of total storage capacity of the filesystem in bytes.
[in] | fs | The filesystem on which to operate. |
Definition at line 2082 of file fat16.c.
References fat16_header_struct::cluster_size, fat16_header_struct::fat_size, and fat16_fs_struct::header.
Referenced by print_disk_info().
struct fat16_fs_struct* fat16_open | ( | struct partition_struct * | partition | ) | [read] |
Opens a FAT16 filesystem.
[in] | partition | Discriptor of partition on which the filesystem resides. |
Definition at line 219 of file fat16.c.
References partition_struct::device_write, partition_struct::device_write_interval, FAT16_FS_COUNT, fat16_fs_handles, fat16_read_header(), FAT16_WRITE_SUPPORT, and fat16_fs_struct::partition.
Referenced by main().
struct fat16_dir_struct* fat16_open_dir | ( | struct fat16_fs_struct * | fs, | |
const struct fat16_dir_entry_struct * | dir_entry | |||
) | [read] |
Opens a directory.
[in] | fs | The filesystem on which the directory to open resides. |
[in] | dir_entry | The directory entry which stands for the directory to open. |
Definition at line 1189 of file fat16.c.
References fat16_dir_entry_struct::attributes, fat16_dir_entry_struct::cluster, fat16_dir_struct::dir_entry, fat16_dir_struct::entry_cluster, fat16_dir_struct::entry_offset, FAT16_ATTRIB_DIR, FAT16_DIR_COUNT, fat16_dir_handles, and fat16_dir_struct::fs.
Referenced by fat16_get_dir_entry_of_path(), and main().
struct fat16_file_struct* fat16_open_file | ( | struct fat16_fs_struct * | fs, | |
const struct fat16_dir_entry_struct * | dir_entry | |||
) | [read] |
Opens a file on a FAT16 filesystem.
[in] | fs | The filesystem on which the file to open lies. |
[in] | dir_entry | The directory entry of the file to open. |
Definition at line 748 of file fat16.c.
References fat16_dir_entry_struct::attributes, fat16_dir_entry_struct::cluster, fat16_file_struct::dir_entry, FAT16_ATTRIB_DIR, FAT16_FILE_COUNT, fat16_file_handles, fat16_file_struct::fs, fat16_file_struct::pos, and fat16_file_struct::pos_cluster.
Referenced by open_file_in_dir().
uint8_t fat16_read_dir | ( | struct fat16_dir_struct * | dd, | |
struct fat16_dir_entry_struct * | dir_entry | |||
) |
Reads the next directory entry contained within a parent directory.
[in] | dd | The descriptor of the parent directory from which to read the entry. |
[out] | dir_entry | Pointer to a buffer into which to write the directory entry information. |
Definition at line 1250 of file fat16.c.
References fat16_read_dir_callback_arg::bytes_read, fat16_dir_entry_struct::cluster, fat16_header_struct::cluster_size, fat16_header_struct::cluster_zero_offset, partition_struct::device_read_interval, fat16_dir_struct::dir_entry, fat16_read_dir_callback_arg::dir_entry, fat16_dir_struct::entry_cluster, fat16_dir_struct::entry_offset, fat16_cluster_offset(), fat16_dir_entry_read_callback(), fat16_get_next_cluster(), fat16_read_dir_callback_arg::finished, fat16_dir_struct::fs, fat16_fs_struct::header, fat16_dir_entry_struct::long_name, fat16_fs_struct::partition, and fat16_header_struct::root_dir_offset.
Referenced by fat16_create_dir(), fat16_create_file(), fat16_get_dir_entry_of_path(), find_file_in_dir(), and main().
int16_t fat16_read_file | ( | struct fat16_file_struct * | fd, | |
uint8_t * | buffer, | |||
uint16_t | buffer_len | |||
) |
Reads data from a file.
The data requested is read from the current file location.
[in] | fd | The file handle of the file from which to read. |
[out] | buffer | The buffer into which to write. |
[in] | buffer_len | The amount of data to read. |
Definition at line 808 of file fat16.c.
References fat16_dir_entry_struct::cluster, fat16_header_struct::cluster_size, partition_struct::device_read, fat16_file_struct::dir_entry, fat16_cluster_offset(), fat16_get_next_cluster(), fat16_dir_entry_struct::file_size, fat16_file_struct::fs, fat16_fs_struct::header, fat16_fs_struct::partition, fat16_file_struct::pos, and fat16_file_struct::pos_cluster.
Referenced by play_song().
uint8_t fat16_reset_dir | ( | struct fat16_dir_struct * | dd | ) |
Resets a directory handle.
Resets the directory handle such that reading restarts with the first directory entry.
[in] | dd | The directory handle to reset. |
Definition at line 1329 of file fat16.c.
References fat16_dir_entry_struct::cluster, fat16_dir_struct::dir_entry, fat16_dir_struct::entry_cluster, and fat16_dir_struct::entry_offset.
Referenced by fat16_create_dir(), fat16_create_file(), and find_file_in_dir().
uint8_t fat16_resize_file | ( | struct fat16_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.
[in] | fd | The file decriptor of the file which to resize. |
[in] | size | The new size of the file. |
Definition at line 1096 of file fat16.c.
References fat16_dir_entry_struct::cluster, fat16_header_struct::cluster_size, fat16_file_struct::dir_entry, fat16_append_clusters(), fat16_free_clusters(), fat16_get_next_cluster(), fat16_terminate_clusters(), fat16_write_dir_entry(), fat16_dir_entry_struct::file_size, fat16_file_struct::fs, fat16_fs_struct::header, fat16_file_struct::pos, and fat16_file_struct::pos_cluster.
Referenced by fat16_seek_file().
uint8_t fat16_seek_file | ( | struct fat16_file_struct * | fd, | |
int32_t * | offset, | |||
uint8_t | whence | |||
) |
Repositions the read/write file offset.
Changes the file offset where the next call to fat16_read_file() or fat16_write_file() starts reading/writing.
If the new offset is beyond the end of the file, fat16_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:
*offset
is relative to the beginning of the file.*offset
is relative to the current file position.*offset
is relative to the end of the file.
The resulting absolute offset is written to the location the offset
parameter points to.
[in] | fd | The file decriptor of the file on which to seek. |
[in,out] | offset | A 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] | whence | Affects the way offset is interpreted, see above. |
Definition at line 1046 of file fat16.c.
References fat16_file_struct::dir_entry, fat16_resize_file(), FAT16_SEEK_CUR, FAT16_SEEK_END, FAT16_SEEK_SET, fat16_dir_entry_struct::file_size, fat16_file_struct::pos, and fat16_file_struct::pos_cluster.
int16_t fat16_write_file | ( | struct fat16_file_struct * | fd, | |
const uint8_t * | buffer, | |||
uint16_t | buffer_len | |||
) |
Writes data to a file.
The data is written to the current file location.
[in] | fd | The file handle of the file to which to write. |
[in] | buffer | The buffer from which to read the data to be written. |
[in] | buffer_len | The amount of data to write. |
Definition at line 902 of file fat16.c.
References fat16_dir_entry_struct::cluster, fat16_header_struct::cluster_size, partition_struct::device_write, fat16_file_struct::dir_entry, fat16_append_clusters(), fat16_cluster_offset(), fat16_get_next_cluster(), fat16_write_dir_entry(), fat16_dir_entry_struct::file_size, fat16_file_struct::fs, fat16_fs_struct::header, fat16_fs_struct::partition, fat16_file_struct::pos, and fat16_file_struct::pos_cluster.
void get_datetime | ( | uint16_t * | year, | |
uint8_t * | month, | |||
uint8_t * | day, | |||
uint8_t * | hour, | |||
uint8_t * | min, | |||
uint8_t * | sec | |||
) |