Basic functions for handling a FAT filesystem.
More...
Functions |
struct fat_fs_struct * | fat_open (struct partition_struct *partition) |
| Opens a FAT filesystem.
|
void | fat_close (struct fat_fs_struct *fs) |
| Closes a FAT filesystem.
|
cluster_t | fat_append_clusters (struct fat_fs_struct *fs, cluster_t cluster_num, cluster_t count) |
| Appends a new cluster chain to an existing one.
|
uint8_t | fat_free_clusters (struct fat_fs_struct *fs, cluster_t cluster_num) |
| Frees a cluster chain, or a part thereof.
|
uint8_t | fat_terminate_clusters (struct fat_fs_struct *fs, cluster_t cluster_num) |
| Frees a part of a cluster chain and correctly terminates the rest.
|
uint8_t | fat_clear_cluster (const struct fat_fs_struct *fs, cluster_t cluster_num) |
| Clears a single cluster.
|
uintptr_t | fat_clear_cluster_callback (uint8_t *buffer, offset_t offset, void *p) |
| Callback function for clearing a cluster.
|
uint8_t | fat_calc_83_checksum (const uint8_t *file_name_83) |
| Calculates the checksum for 8.3 names used within the corresponding lfn directory entries.
|
offset_t | fat_find_offset_for_dir_entry (struct fat_fs_struct *fs, const struct fat_dir_struct *parent, const struct fat_dir_entry_struct *dir_entry) |
| Searches for space where to store a directory entry.
|
uint8_t | fat_write_dir_entry (const struct fat_fs_struct *fs, struct fat_dir_entry_struct *dir_entry) |
| Writes a directory entry to disk.
|
offset_t | fat_get_fs_size (const struct fat_fs_struct *fs) |
| Returns the amount of total storage capacity of the filesystem in bytes.
|
offset_t | fat_get_fs_free (const struct fat_fs_struct *fs) |
| Returns the amount of free storage capacity on the filesystem in bytes.
|
uint8_t | fat_get_fs_free_32_callback (uint8_t *buffer, offset_t offset, void *p) |
| Callback function used for counting free clusters in a FAT32.
|
Detailed Description
Basic functions for handling a FAT filesystem.
Function Documentation
cluster_t fat_append_clusters |
( |
struct fat_fs_struct * |
fs, |
|
|
cluster_t |
cluster_num, |
|
|
cluster_t |
count | |
|
) |
| | |
Appends a new cluster chain to an existing one.
Set cluster_num to zero to create a completely new one.
- Parameters:
-
[in] | fs | The file system on which to operate. |
[in] | cluster_num | The cluster to which to append the new chain. |
[in] | count | The number of clusters to allocate. |
- Returns:
- 0 on failure, the number of the first new cluster on success.
uint8_t fat_calc_83_checksum |
( |
const uint8_t * |
file_name_83 |
) |
|
Calculates the checksum for 8.3 names used within the corresponding lfn directory entries.
- Parameters:
-
[in] | file_name_83 | The 11-byte file name buffer. |
- Returns:
- The checksum of the given file name.
uint8_t fat_clear_cluster |
( |
const struct fat_fs_struct * |
fs, |
|
|
cluster_t |
cluster_num | |
|
) |
| | |
Clears a single cluster.
The complete cluster is filled with zeros.
- Parameters:
-
[in] | fs | The filesystem on which to operate. |
[in] | cluster_num | The cluster to clear. |
- Returns:
- 0 on failure, 1 on success.
void fat_close |
( |
struct fat_fs_struct * |
fs |
) |
|
Closes a FAT filesystem.
When this function returns, the given filesystem descriptor will be invalid.
- Parameters:
-
[in] | fs | The filesystem to close. |
- See also:
- fat_open
offset_t fat_find_offset_for_dir_entry |
( |
struct fat_fs_struct * |
fs, |
|
|
const struct fat_dir_struct * |
parent, |
|
|
const struct fat_dir_entry_struct * |
dir_entry | |
|
) |
| | |
Searches for space where to store a directory entry.
- Parameters:
-
[in] | fs | The filesystem on which to operate. |
[in] | parent | The directory in which to search. |
[in] | dir_entry | The directory entry for which to search space. |
- Returns:
- 0 on failure, a device offset on success.
uint8_t fat_free_clusters |
( |
struct fat_fs_struct * |
fs, |
|
|
cluster_t |
cluster_num | |
|
) |
| | |
Frees a cluster chain, or a part thereof.
Marks the specified cluster and all clusters which are sequentially referenced by it as free. They may then be used again for future file allocations.
- Note:
- If this function is used for freeing just a part of a cluster chain, the new end of the chain is not correctly terminated within the FAT. Use fat_terminate_clusters() instead.
- Parameters:
-
[in] | fs | The filesystem on which to operate. |
[in] | cluster_num | The starting cluster of the chain which to free. |
- Returns:
- 0 on failure, 1 on success.
- See also:
- fat_terminate_clusters
offset_t fat_get_fs_free |
( |
const struct fat_fs_struct * |
fs |
) |
|
Returns the amount of free storage capacity on the filesystem in bytes.
- Note:
- As the FAT filesystem is cluster based, this function does not return continuous values but multiples of the cluster size.
- Parameters:
-
[in] | fs | The filesystem on which to operate. |
- Returns:
- 0 on failure, the free filesystem space in bytes otherwise.
offset_t fat_get_fs_size |
( |
const struct fat_fs_struct * |
fs |
) |
|
Returns the amount of total storage capacity of the filesystem in bytes.
- Parameters:
-
[in] | fs | The filesystem on which to operate. |
- Returns:
- 0 on failure, the filesystem size in bytes otherwise.
Opens a FAT filesystem.
- Parameters:
-
[in] | partition | Discriptor of partition on which the filesystem resides. |
- Returns:
- 0 on error, a FAT filesystem descriptor on success.
- See also:
- fat_close
uint8_t fat_terminate_clusters |
( |
struct fat_fs_struct * |
fs, |
|
|
cluster_t |
cluster_num | |
|
) |
| | |
Frees a part of a cluster chain and correctly terminates the rest.
Marks the specified cluster as the new end of a cluster chain and frees all following clusters.
- Parameters:
-
[in] | fs | The filesystem on which to operate. |
[in] | cluster_num | The new end of the cluster chain. |
- Returns:
- 0 on failure, 1 on success.
- See also:
- fat_free_clusters
uint8_t fat_write_dir_entry |
( |
const struct fat_fs_struct * |
fs, |
|
|
struct fat_dir_entry_struct * |
dir_entry | |
|
) |
| | |
Writes a directory entry to disk.
- Note:
- 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.
- Parameters:
-
[in] | fs | The filesystem on which to operate. |
[in] | dir_entry | The directory entry to write. |
- Returns:
- 0 on failure, 1 on success.