FAT16 access
[FAT16 support]

Collaboration diagram for FAT16 access:

Functions

struct fat16_fs_structfat16_open (struct partition_struct *partition)
void fat16_close (struct fat16_fs_struct *fs)
static uint8_t fat16_read_header (struct fat16_fs_struct *fs)
static uint16_t fat16_get_next_cluster (const struct fat16_fs_struct *fs, uint16_t cluster_num)
static uint16_t fat16_append_clusters (const struct fat16_fs_struct *fs, uint16_t cluster_num, uint16_t count)
static uint8_t fat16_free_clusters (const struct fat16_fs_struct *fs, uint16_t cluster_num)
static uint8_t fat16_terminate_clusters (const struct fat16_fs_struct *fs, uint16_t cluster_num)
static uint8_t fat16_clear_cluster (const struct fat16_fs_struct *fs, uint16_t cluster_num)
static uint16_t fat16_clear_cluster_callback (uint8_t *buffer, uint32_t offset, void *p)
static uint32_t fat16_cluster_offset (const struct fat16_fs_struct *fs, uint16_t cluster_num)
static uint8_t fat16_dir_entry_read_callback (uint8_t *buffer, uint32_t offset, void *p)
static uint8_t fat16_interpret_dir_entry (struct fat16_dir_entry_struct *dir_entry, const uint8_t *raw_entry)
static uint32_t fat16_find_offset_for_dir_entry (const struct fat16_fs_struct *fs, const struct fat16_dir_struct *parent, const struct fat16_dir_entry_struct *dir_entry)
static uint8_t fat16_write_dir_entry (const struct fat16_fs_struct *fs, 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)
static uint8_t fat16_get_fs_free_callback (uint8_t *buffer, uint32_t offset, void *p)

Detailed Description

Basic functions for handling a FAT16 filesystem.

Function Documentation

uint16_t fat16_append_clusters ( const struct fat16_fs_struct fs,
uint16_t  cluster_num,
uint16_t  count 
) [static]

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.

Definition at line 504 of file fat16.c.

References partition_struct::device_read, partition_struct::device_write, FAT16_CLUSTER_FREE, FAT16_CLUSTER_LAST_MAX, fat16_free_clusters(), fat16_header_struct::fat_offset, fat16_header_struct::fat_size, fat16_fs_struct::header, and fat16_fs_struct::partition.

Referenced by fat16_create_dir(), fat16_find_offset_for_dir_entry(), fat16_resize_file(), and fat16_write_file().

uint8_t fat16_clear_cluster ( const struct fat16_fs_struct fs,
uint16_t  cluster_num 
) [static]

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.

Definition at line 690 of file fat16.c.

References fat16_header_struct::cluster_size, partition_struct::device_write_interval, fat16_clear_cluster_callback(), fat16_cluster_offset(), fat16_fs_struct::header, and fat16_fs_struct::partition.

Referenced by fat16_create_dir(), and fat16_find_offset_for_dir_entry().

uint16_t fat16_clear_cluster_callback ( uint8_t *  buffer,
uint32_t  offset,
void *  p 
) [static]

Callback function for clearing a cluster.

Definition at line 713 of file fat16.c.

Referenced by fat16_clear_cluster().

void fat16_close ( struct fat16_fs_struct fs  ) 

Closes a FAT16 filesystem.

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

Parameters:
[in] fs The filesystem to close.
See also:
fat16_open

Definition at line 275 of file fat16.c.

References fat16_fs_struct::partition.

uint32_t fat16_cluster_offset ( const struct fat16_fs_struct fs,
uint16_t  cluster_num 
) [static]

Calculates the offset of the specified cluster.

Parameters:
[in] fs The filesystem on which to operate.
[in] cluster_num The cluster whose offset to calculate.
Returns:
The cluster offset.

Definition at line 731 of file fat16.c.

References fat16_header_struct::cluster_size, fat16_header_struct::cluster_zero_offset, and fat16_fs_struct::header.

Referenced by fat16_clear_cluster(), fat16_find_offset_for_dir_entry(), fat16_read_dir(), fat16_read_file(), and fat16_write_file().

uint8_t fat16_dir_entry_read_callback ( uint8_t *  buffer,
uint32_t  offset,
void *  p 
) [static]

uint32_t fat16_find_offset_for_dir_entry ( const struct fat16_fs_struct fs,
const struct fat16_dir_struct parent,
const struct fat16_dir_entry_struct dir_entry 
) [static]

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.

Definition at line 1477 of file fat16.c.

References fat16_dir_entry_struct::cluster, fat16_header_struct::cluster_size, fat16_header_struct::cluster_zero_offset, partition_struct::device_read, fat16_dir_struct::dir_entry, fat16_append_clusters(), fat16_clear_cluster(), fat16_cluster_offset(), FAT16_DIRENTRY_DELETED, fat16_get_next_cluster(), 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(), and fat16_create_file().

uint8_t fat16_free_clusters ( const struct fat16_fs_struct fs,
uint16_t  cluster_num 
) [static]

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 fat16_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:
fat16_terminate_clusters

Definition at line 596 of file fat16.c.

References partition_struct::device_read, partition_struct::device_write, FAT16_CLUSTER_BAD, FAT16_CLUSTER_FREE, FAT16_CLUSTER_LAST_MAX, FAT16_CLUSTER_LAST_MIN, FAT16_CLUSTER_RESERVED_MAX, FAT16_CLUSTER_RESERVED_MIN, fat16_header_struct::fat_offset, fat16_fs_struct::header, and fat16_fs_struct::partition.

Referenced by fat16_append_clusters(), fat16_create_dir(), fat16_delete_file(), fat16_resize_file(), and fat16_terminate_clusters().

uint32_t fat16_get_fs_free ( const struct fat16_fs_struct fs  ) 

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

Note:
As the FAT16 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.

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().

uint8_t fat16_get_fs_free_callback ( uint8_t *  buffer,
uint32_t  offset,
void *  p 
) [static]

Callback function used for counting free clusters.

Definition at line 2139 of file fat16.c.

References fat16_usage_count_callback_arg::buffer_size, fat16_usage_count_callback_arg::cluster_count, and FAT16_CLUSTER_FREE.

Referenced by fat16_get_fs_free().

uint32_t fat16_get_fs_size ( const struct fat16_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.

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().

uint16_t fat16_get_next_cluster ( const struct fat16_fs_struct fs,
uint16_t  cluster_num 
) [static]

Retrieves the next following cluster of a given cluster.

Using the filesystem file allocation table, this function returns the number of the cluster containing the data directly following the data within the cluster with the given number.

Parameters:
[in] fs The filesystem for which to determine the next cluster.
[in] cluster_num The number of the cluster for which to determine its successor.
Returns:
The wanted cluster number, or 0 on error.

Definition at line 470 of file fat16.c.

References partition_struct::device_read, FAT16_CLUSTER_BAD, FAT16_CLUSTER_FREE, FAT16_CLUSTER_LAST_MAX, FAT16_CLUSTER_LAST_MIN, FAT16_CLUSTER_RESERVED_MAX, FAT16_CLUSTER_RESERVED_MIN, fat16_header_struct::fat_offset, fat16_fs_struct::header, and fat16_fs_struct::partition.

Referenced by fat16_find_offset_for_dir_entry(), fat16_read_dir(), fat16_read_file(), fat16_resize_file(), fat16_terminate_clusters(), and fat16_write_file().

uint8_t fat16_interpret_dir_entry ( struct fat16_dir_entry_struct dir_entry,
const uint8_t *  raw_entry 
) [static]

Interprets a raw directory entry and puts the contained information into the directory entry.

For a single file there may exist multiple directory entries. All except the last one are lfn entries, which contain parts of the long filename. The last directory entry is a traditional 8.3 style one. It contains all other information like size, cluster, date and time.

Parameters:
[in,out] dir_entry The directory entry to fill.
[in] raw_entry A pointer to 32 bytes of raw data.
Returns:
0 on failure, 1 on success and 2 if the directory entry is complete.

Definition at line 1393 of file fat16.c.

References fat16_dir_entry_struct::attributes, fat16_dir_entry_struct::cluster, FAT16_DIRENTRY_DELETED, fat16_dir_entry_struct::file_size, and fat16_dir_entry_struct::long_name.

Referenced by fat16_dir_entry_read_callback().

struct fat16_fs_struct* fat16_open ( struct partition_struct partition  )  [read]

Opens a FAT16 filesystem.

Parameters:
[in] partition Discriptor of partition on which the filesystem resides.
Returns:
0 on error, a FAT16 filesystem descriptor on success.
See also:
fat16_open

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().

uint8_t fat16_read_header ( struct fat16_fs_struct fs  )  [static]

uint8_t fat16_terminate_clusters ( const struct fat16_fs_struct fs,
uint16_t  cluster_num 
) [static]

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:
fat16_free_clusters

Definition at line 654 of file fat16.c.

References partition_struct::device_write, FAT16_CLUSTER_LAST_MAX, fat16_free_clusters(), fat16_get_next_cluster(), fat16_header_struct::fat_offset, fat16_fs_struct::header, and fat16_fs_struct::partition.

Referenced by fat16_resize_file().

uint8_t fat16_write_dir_entry ( const struct fat16_fs_struct fs,
struct fat16_dir_entry_struct dir_entry 
) [static]

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.

Definition at line 1589 of file fat16.c.

References fat16_dir_entry_struct::attributes, fat16_dir_entry_struct::cluster, partition_struct::device_write, fat16_dir_entry_struct::entry_offset, FAT16_DIRENTRY_DELETED, FAT16_DIRENTRY_LFNLAST, fat16_get_datetime, fat16_set_file_modification_date(), fat16_set_file_modification_time(), fat16_dir_entry_struct::file_size, fat16_dir_entry_struct::long_name, and fat16_fs_struct::partition.

Referenced by fat16_create_dir(), fat16_create_file(), fat16_resize_file(), and fat16_write_file().


Generated on Wed Sep 17 19:31:52 2008 for mptry by  doxygen 1.5.5