Atmel Software Framework

fat.h File Reference
#include "fs_com.h"

Data Structures

struct  Fs_clusterlist_cache
 Structure to store the cluster list cache. More...
 
struct  Fs_management
 Structure to save the variables frequently used by file system mounted. More...
 
struct  Fs_management_entry
 Structure to save the frequently variables of file system mounted. More...
 
struct  Fs_management_fast
 Structure to save the variables very frequently used by file system mounted. More...
 
union  Fs_rootdir
 Union to define a root directory. More...
 
struct  Fs_sector_cache
 Structure to store the information about sector cache (=last sector read or write on disk) More...
 
struct  Fs_segment
 Structure to define a segment. More...
 
struct  st_fs_cluster
 Structure to store cluster information. More...
 

Macros

#define _GLOBEXT_   extern
 
#define FS_BUF_SECTOR_EMPTY   0xFF
 Signal that sector cache is not valid. More...
 
#define FS_MBR_OFFSET_PART_ENTRY(num)   ((uint16_t)((uint16_t)(0x1BE)+(0x10 * num)))
 Position (unit byte) in the MBR of a partition entry. More...
 
#define Is_fat12   (FS_TYPE_FAT_12 == fs_g_nav_fast.u8_type_fat)
 
#define Is_fat16   (FS_TYPE_FAT_16 == fs_g_nav_fast.u8_type_fat)
 
#define Is_fat32   (FS_TYPE_FAT_32 == fs_g_nav_fast.u8_type_fat)
 
#define Is_unicode   (g_b_unicode)
 
Macro to access at fields in BPB sector (only used in fat_mount() function)

The name prefixed by "BPB_" are defined in "Hardware White Paper FAT"

#define LOW_16_BPB_BytsPerSec   fs_g_sector[11]
 
#define HIGH_16_BPB_BytsPerSec   fs_g_sector[12]
 
#define U8_BPB_SecPerClus   fs_g_sector[13]
 
#define LOW_16_BPB_RootEntCnt   fs_g_sector[17]
 
#define HIGH_16_BPB_RootEntCnt   fs_g_sector[18]
 
#define LOW_16_BPB_FATSz16   fs_g_sector[22]
 
#define HIGH_16_BPB_FATSz16   fs_g_sector[23]
 
#define LOW0_32_BPB_FATSz32   fs_g_sector[36]
 
#define LOW1_32_BPB_FATSz32   fs_g_sector[37]
 
#define LOW2_32_BPB_FATSz32   fs_g_sector[38]
 
#define LOW3_32_BPB_FATSz32   fs_g_sector[39]
 
#define LOW_16_BPB_TotSec16   fs_g_sector[19]
 
#define HIGH_16_BPB_TotSec16   fs_g_sector[20]
 
#define LOW0_32_BPB_TotSec32   fs_g_sector[32]
 
#define LOW1_32_BPB_TotSec32   fs_g_sector[33]
 
#define LOW2_32_BPB_TotSec32   fs_g_sector[34]
 
#define LOW3_32_BPB_TotSec32   fs_g_sector[35]
 
#define LOW_16_BPB_ResvSecCnt   fs_g_sector[14]
 
#define HIGH_16_BPB_ResvSecCnt   fs_g_sector[15]
 
#define U8_BPB_NumFATs   fs_g_sector[16]
 
#define LOW0_32_BPB_RootClus   fs_g_sector[44]
 
#define LOW1_32_BPB_RootClus   fs_g_sector[45]
 
#define LOW2_32_BPB_RootClus   fs_g_sector[46]
 
#define LOW3_32_BPB_RootClus   fs_g_sector[47]
 
#define LOW_16_BPB_FSInfo   fs_g_sector[48]
 
#define HIGH_16_BPB_FSInfo   fs_g_sector[49]
 
Constants used to sign a MBR or PBR sectors
#define FS_BR_SIGNATURE_LOW   0x55
 
#define FS_BR_SIGNATURE_HIGH   0xAA
 
Constants used in MBR sector
#define FS_PART_BOOTABLE   0x80
 
#define FS_PART_NO_BOOTABLE   0x00
 
#define FS_PART_TYPE_FAT12   0x01
 
#define FS_PART_TYPE_FAT16_INF32M   0x04
 
#define FS_PART_TYPE_FAT16_SUP32M   0x06
 
#define FS_PART_TYPE_FAT16_SUP32M_BIS   0x0E
 
#define FS_PART_TYPE_FAT32   0x0B
 
#define FS_PART_TYPE_FAT32_BIS   0x0C
 
#define FS_PART_REMOVE_MEDIA   0xF0
 
#define FS_PART_NO_REMOVE_MEDIA   0xF8
 
#define FS_PART_HARD_DISK   0x81
 
#define FS_BOOT_SIGN   0x29
 
Maximum of FAT cluster
#define FS_FAT12_MAX_CLUSTERS   4085
 
#define FS_FAT16_MAX_CLUSTERS   65525
 
Constants used in the first byte of file entry
#define FS_ENTRY_END   0x00
 
#define FS_ENTRY_DEL   0xE5
 
#define FS_ENTRY_LFN_LAST   0x40
 
Constantes used to manage the file entry
#define FS_SIZE_FILE_ENTRY   32
 
#define FS_SHIFT_B_TO_FILE_ENTRY   5
 
#define FS_SIZE_LFN_ENTRY   13
 
#define FS_SIZE_SFNAME   11
 
#define FS_SIZE_SFNAME_WITHOUT_EXT   8
 
#define FS_SIZE_SFNAME_EXT_ONLY   3
 
LIMITATIONS OF FILE SYSTEM
#define FS_NB_FAT   2
 
The unit sector of 512B is many used in file System stack
#define FS_512B   512
 
#define FS_512B_MASK   (512-1)
 
#define FS_512B_SHIFT_BIT   9
 
#define FS_SIZE_OF_SECTOR   FS_512B
 
#define FS_MASK_SIZE_OF_SECTOR   FS_512B_MASK
 
#define FS_SHIFT_B_TO_SECTOR   FS_512B_SHIFT_BIT
 
#define FS_CACHE_SIZE   512
 
Status of the fat_checkcluster() function
#define FS_CLUS_OK   0
 
#define FS_CLUS_BAD   1
 
#define FS_CLUS_END   2
 
Options of the fat_cluster_list() function
#define FS_CLUST_ACT_SEG   0x01
 
#define FS_CLUST_ACT_ONE   0x02
 
#define FS_CLUST_ACT_CLR   0x03
 
Options of the fat_cluster_val() function
#define FS_CLUST_VAL_READ   false
 
#define FS_CLUST_VAL_WRITE   true
 
#define FS_CLUST_VAL_EOL   0x0FFFFFFF
 
FAT type ID, used in "Fs_management_fast.u8_type_fat"
#define FS_TYPE_FAT_UNM   0
 Partition not mounted. More...
 
#define FS_TYPE_FAT_12   1
 
#define FS_TYPE_FAT_16   2
 
#define FS_TYPE_FAT_32   3
 
Value used in "Fs_management_fast.u16_entry_pos_sel_file"
#define FS_NO_SEL   0xFFFF
 Signal that a file entry isn't selected. More...
 
#define FS_END_FIND   0xFFFE
 Signal that a file entry is the last file entry accessible by system. More...
 
Macro to check the file open mode
#define Fat_file_is_open()   (fs_g_nav_entry.u8_open_mode !=0 )
 
#define Fat_file_isnot_open()   (fs_g_nav_entry.u8_open_mode ==0 )
 
#define Fat_file_close()   (fs_g_nav_entry.u8_open_mode =0 )
 
Functions to control access disk
#define fat_check_nav_access_disk(b)   (true)
 
#define fat_check_nav_access_file(b)   (true)
 
Functions to manage navigator switch
#define fat_invert_nav   ( arg ) (arg++)
 
#define fat_copy_nav   ( arg ) (arg++)
 

Typedefs

Main structures
typedef struct st_fs_cluster Fs_cluster
 Structure to store cluster information. More...
 

Functions

bool fat_format (uint8_t u8_fat_type)
 This function formats the drive. More...
 
uint8_t fat_get_nbpartition (void)
 This function returns the number of partition present on selected drive. More...
 
bool fat_mount (void)
 This function mounts a partition. More...
 
bool fat_serialnumber (bool b_action, uint8_t _MEM_TYPE_SLOW_ *a_u8_sn)
 This function reads or writes a serial number. More...
 
Functions to verify navigator state

}@

bool fat_check_device (void)
 This function checks device state. More...
 
bool fat_check_mount (void)
 This function checks if the partition is mounted. More...
 
bool fat_check_noopen (void)
 This function checks if a file is not opened on current navigator. More...
 
bool fat_check_open (void)
 This function checks if a file is opened on current navigator. More...
 
bool fat_check_select (void)
 This function checks if a file is selected on current navigator. More...
 
bool fat_check_mount_noopen (void)
 This function checks if the partition is mounted and no file is opened. More...
 
bool fat_check_mount_select_noopen (void)
 This function checks if the partition is mounted and if no file is opened and a file is selected. More...
 
bool fat_check_mount_select_open (void)
 This function checks if the partition is mounted and if a file is opened. More...
 
bool fat_check_mount_select (void)
 This function checks if the partition is mounted and if a file is selected. More...
 
bool fat_check_is_file (void)
 This function checks if the selected file entry is a file and not a directory. More...
 
Functions to compute free space on a partition
uint32_t fat_getfreespace (void)
 This function returns the space free in the partition. More...
 
uint8_t fat_getfreespace_percent (void)
 This function returns the space free in percent. More...
 
bool fat_write_fat32_FSInfo (uint32_t u32_nb_free_cluster)
 
uint32_t fat_read_fat32_FSInfo (void)
 
Functions to manage the cluster list
bool fat_cluster_list (uint8_t opt_action, bool b_for_file)
 This function gets or clears a cluster list. More...
 
void fat_cache_clusterlist_reset (void)
 This function resets the cluster list caches. More...
 
bool fat_cluster_val (bool b_mode)
 This function returns or modifies a cluster value in FAT. More...
 
bool fat_cluster_readnext (void)
 This function is optimized to read a continue cluster list on FAT16 and FAT32. More...
 
uint8_t fat_checkcluster (void)
 This function checks the cluster value. More...
 
bool fat_allocfreespace (void)
 
void fat_clear_info_fat_mod (void)
 
bool fat_clear_cluster (void)
 
bool fat_update_fat2 (void)
 
Functions to read or to write a file or a directory
bool fat_read_file (uint8_t mode)
 This function gets or clears a cluster list at the current position in the selected file. More...
 
bool fat_write_file (uint8_t mode, uint32_t u32_nb_sector_write)
 
bool fat_read_dir (void)
 This function fill the internal cache with a sector from current directory. More...
 
bool fat_initialize_dir (void)
 
Functions to manage the entry field (fat.c)
bool fat_entry_check (bool b_type)
 This function checks the entry. More...
 
bool fat_entry_checkext (FS_STRING sz_filter)
 This function checks the file extension. More...
 
void fat_get_entry_info (void)
 This function reads information about selected file. More...
 
bool fat_entry_is_dir (void)
 This function checks if the entry file is a directory. More...
 
void fat_clear_entry_info_and_ptr (void)
 This function resets the selection pointers. More...
 
void fat_write_entry_file (void)
 
bool fat_entry_shortname (FS_STRING sz_name, uint8_t u8_size_max, bool b_mode)
 This function returns or compares the short name entry. More...
 
bool fat_entry_longname (FS_STRING sz_name, uint8_t u8_size_max, bool b_mode, bool b_match_case)
 This function returns or compares the long name entry. More...
 
bool fat_check_eof_name (uint16_t character)
 Check end of name. More...
 
PTR_CACHE fat_get_ptr_entry (void)
 This function returns a cache pointer on the current entry. More...
 
Functions to manage the entry field (fat_unusual.c)
bool fat_create_entry_file_name (FS_STRING sz_name)
 
void fat_get_date (FS_STRING sz_date, bool type_date)
 This function reads the information about a date. More...
 
void fat_set_date (const FS_STRING sz_date, bool type_date)
 
bool fat_delete_file (bool b_cluster_list)
 
bool fat_entry_label (bool b_action, FS_STRING sz_label)
 
Functions to manage the cache
bool fat_cache_read_sector (bool b_load)
 This function loads a memory sector in internal cache sector. More...
 
void fat_cache_reset (void)
 This function resets the sector cache. More...
 
void fat_cache_clear (void)
 
void fat_cache_mark_sector_as_dirty (void)
 
bool fat_cache_flush (void)
 This function flushes the sector cache on the memory if necessary. More...
 

Variables

_GLOBEXT_ _MEM_TYPE_FAST_
Fs_cluster 
fs_g_cluster
 To take time in functions: fat_getfreespace, fat_cluster_list, fat_cluster_val, fat_checkcluster. More...
 
_GLOBEXT_ _MEM_TYPE_FAST_
Fs_segment 
fs_g_seg
 Variable frequently used by many function (optimization, no parameter in function) More...
 
_GLOBEXT_ bool g_b_no_check_disk
 Variables to enable/disable the disk check before each action on disk. More...
 
_GLOBEXT_ bool g_b_string_length
 Variables to select LENGTH string mode (initialised in nav_reset()) More...
 
_GLOBEXT_ bool g_b_unicode
 Variables to select string format (initialised in nav_reset()) More...
 
Variables initialized in drive_mount()
_GLOBEXT_ _MEM_TYPE_SLOW_
Fs_management 
fs_g_nav
 
_GLOBEXT_ _MEM_TYPE_FAST_
Fs_management_fast 
fs_g_nav_fast
 
_GLOBEXT_ _MEM_TYPE_SLOW_
Fs_management_entry 
fs_g_nav_entry
 

Variables used to manage the sector cache

typedef uint8_t _MEM_TYPE_SLOW_PTR_CACHE
 
_GLOBEXT_ _MEM_TYPE_SLOW_ uint8_t fs_g_sector [FS_CACHE_SIZE]
 Use "FAT sector cache" to store a sector from a file (see file_putc(), file_getc(), file_read_buf(), file_write_buf()) More...
 
_GLOBEXT_ _MEM_TYPE_SLOW_
Fs_sector_cache 
fs_g_sectorcache
 
_GLOBEXT_ _MEM_TYPE_SLOW_ uint32_t fs_gu32_addrsector
 Store the address of future cache (unit 512B) More...