Microchip® Advanced Software Framework

fat_unusual.c File Reference
#include "conf_explorer.h"
#include "fs_com.h"
#include "fat.h"
#include <string.h>
#include "ctrl_access.h"

Data Structures

struct  st_fs_format_table
 

Functions

bool fat_allocfreespace (void)
 This function allocs a cluster list. More...
 
bool fat_clean_zone (bool b_MBR)
 This function cleans the reserved zone, FAT zone, and root dir zone. More...
 
bool fat_clear_cluster (void)
 This function clears one cluster. More...
 
void fat_clear_info_fat_mod (void)
 This function clears the cache information about FAT modifications. More...
 
bool fat_create_entry_file_name (FS_STRING sz_name)
 This function creates the short and the long name of a new entry. More...
 
bool fat_delete_file (bool b_cluster_list)
 This function deletes the file entries and cluster list. More...
 
bool fat_entry_label (bool b_action, FS_STRING sz_label)
 This function reads or writes a label in the partition. More...
 
void fat_get_date (FS_STRING sz_date, bool type_date)
 This function reads the information about a date. More...
 
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_initialize_dir (void)
 This function writes the directory information. More...
 
bool fat_initialize_fat (void)
 This function initializes the fat one and two. More...
 
bool fat_mount (void)
 This function mounts a partition file system (FAT12, FAT16 or FAT32) of selected drive. More...
 
uint32_t fat_read_fat32_FSInfo (void)
 This function returns the space free in the selected FAT32 partition. More...
 
bool fat_serialnumber (bool b_action, uint8_t _MEM_TYPE_SLOW_ *a_u8_sn)
 This function reads or writes a serial number in the drive. More...
 
void fat_set_date (const FS_STRING sz_date, bool type_date)
 This function changes the date information. More...
 
bool fat_update_fat2 (void)
 This function copies the modifications of the first FAT to the second FAT. More...
 
bool fat_write_fat32_FSInfo (uint32_t u32_nb_free_cluster)
 This function writes the space free number in selected FAT32 partition. More...
 
bool fat_write_PBR (bool b_MBR)
 This function writes the PBR. More...
 
Sub routines used by format routine
bool fat_select_filesystem (uint8_t u8_fat_type, bool b_MBR)
 This function computes the FAT type to use. More...
 
bool fat_write_MBR (void)
 This function writes the MBR. More...
 
Sub routines used by date read-write routines
void fat_translatedate_number_to_ascii (FS_STRING sz_date, PTR_CACHE ptr_date, bool enable_ms)
 This function translates a date FAT value to ascii string. More...
 
void fat_translate_number_to_ascii (FS_STRING sz_ascii_number, uint8_t u8_size_number_ascii, uint8_t u8_nb_increment)
 This function translates a digital number to a ASCII number. More...
 
void fat_translatedate_ascii_to_number (const FS_STRING sz_date, PTR_CACHE ptr_date, bool enable_ms)
 This function translates a date ascii string to date FAT value. More...
 
uint16_t fat_translate_ascii_to_number (const FS_STRING sz_ascii_number, uint8_t u8_size_number_ascii)
 This function translates a ASCII number to a digital number. More...
 
Sub routine used to create a entry file
void fat_create_long_name_entry (FS_STRING sz_name, uint8_t u8_crc, uint8_t u8_id)
 This function creates a long name entry. More...
 
uint8_t fat_create_short_entry_name (FS_STRING sz_name, FS_STRING short_name, uint8_t nb, bool mode)
 This function creates a short name in the internal cache sector OR in a string. More...
 
uint8_t fat_find_short_entry_name (FS_STRING sz_name)
 This function searches an unique short name. More...
 
bool fat_entry_shortname_compare (FS_STRING short_name)
 This function compares a short name with the current entry. More...
 
uint8_t fat_check_name (FS_STRING sz_name)
 This function checks the character in name AND computes the number of entry file to store the name. More...
 
uint8_t fat_translate_char_shortname (uint8_t character)
 This function translates the character to authorized short name character. More...
 
bool fat_alloc_entry_free (uint8_t u8_nb_entry)
 This function allocs a number of entry in a current directory. More...
 
bool fat_garbage_collector_entry (void)
 This function remove the entry selected in the directory to clean it. More...
 

Variables

_CONST_TYPE_ uint8_t fs_s_execption_char [] ={'+',',','.',';','=','[',']'}
 Characters table no supported in a short name. More...
 
_CONST_TYPE_ uint8_t fs_s_tab_incorrect_char [] ={':','*','?','"','<','>','|'}
 Characters table no supported in a file name. More...
 
Constants for fat_write_PBR() routine
_CONST_TYPE_ uint8_t const_header_pbr []
 
_CONST_TYPE_ uint8_t const_tail_pbr []
 
Constants of "FAT32 FSInfo Sector"
_CONST_TYPE_ uint8_t const_FSI_LeadSig []
 
_CONST_TYPE_ uint8_t const_FSI_StrucSig []
 
Constants for fat_initialize_fat() function
_CONST_TYPE_ uint8_t const_header_fat12 []
 
_CONST_TYPE_ uint8_t const_header_fat16 []
 
_CONST_TYPE_ uint8_t const_header_fat32 []
 

Global variable to optimize the footprint of format routines

_MEM_TYPE_SLOW_ uint32_t fs_s_u32_size_partition
 
bool fat_format (uint8_t u8_fat_type)
 This function formats the current drive. More...
 

Structure for the tables format

typedef struct st_fs_format_table Fs_format_table
 
_CONST_TYPE_ Fs_format_table TableFAT12 []
 Table format for FAT12. More...
 
_CONST_TYPE_ Fs_format_table TableFAT16 []
 Table format for FAT16. More...
 
_CONST_TYPE_ Fs_format_table TableFAT32 []
 Table format for FAT32. More...
 

bool fat_alloc_entry_free ( uint8_t  u8_nb_entry)

This function allocs a number of entry in a current directory.

@param     u8_nb_entry    number of entry to alloc

@return    false in case of error, see global value "fs_g_status" for more detail
@return    true otherwise
//! OUT: Initialize the system on the last alloced free entry
//! 

References fat_allocfreespace(), fat_clear_cluster(), fat_garbage_collector_entry(), fat_get_ptr_entry(), fat_read_dir(), FS_ENTRY_END, FS_ERR_NO_FREE_SPACE, FS_ERR_OUT_LIST, fs_g_nav_fast, fs_g_seg, fs_g_status, Fs_management_fast::u16_entry_pos_sel_file, and Fs_segment::u32_size_or_pos.

uint8_t fat_check_name ( FS_STRING  sz_name)

This function checks the character in name AND computes the number of entry file to store the name.

Parameters
sz_nameoriginal name to create
Returns
number of entry file to store the name (short + long name)
if name incorrect then 0 is returned.

References fat_check_eof_name(), FS_ERR_INCORRECT_NAME, FS_ERR_NAME_TOO_LARGE, fs_g_status, fs_s_tab_incorrect_char, FS_SIZE_LFN_ENTRY, and Is_unicode.

bool fat_clean_zone ( bool  b_MBR)

This function cleans the reserved zone, FAT zone, and root dir zone.

Parameters
b_MBRtrue, include a MBR on disk
Returns
false in case of error, see global value "fs_g_status" for more detail
true otherwise

References _MEM_TYPE_SLOW_, fat_cache_clear(), fat_cache_flush(), fat_cache_mark_sector_as_dirty(), fat_cache_read_sector(), FS_CACHE_SIZE, fs_g_nav, fs_g_sector, fs_gu32_addrsector, Is_fat32, Fs_management::u32_fat_size, and Fs_management::u8_BPB_SecPerClus.

Referenced by fat_format().

void fat_create_long_name_entry ( FS_STRING  sz_name,
uint8_t  u8_crc,
uint8_t  u8_id 
)

This function creates a long name entry.

@param     sz_name      name to create (ASCII or UNICODE)
@param     u8_crc       crc corresponding at short name
@param     u8_id        long entry number (1 to n + FS_ENTRY_LFN_LAST)
//! OUT: Update the entry in internal cache sector with a new long name entry
//! 

References fat_cache_mark_sector_as_dirty(), fat_get_ptr_entry(), FS_ATTR_LFN_ENTRY, FS_SIZE_FILE_ENTRY, Is_unicode, LSB, and MSB.

uint8_t fat_create_short_entry_name ( FS_STRING  sz_name,
FS_STRING  short_name,
uint8_t  nb,
bool  mode 
)

This function creates a short name in the internal cache sector OR in a string.

Parameters
sz_namename to create (ASCII or UNICODE)
short_nameshort name in 8.3 format ( = 8+3 Bytes) (used only if mode = true)
nbnumber to add at short name (ex: name~nb)
modetrue to write in a string
false to write in internal cache
Returns
short name CRC

References fat_cache_mark_sector_as_dirty(), fat_check_eof_name(), fat_get_ptr_entry(), fat_translate_char_shortname(), FS_SIZE_SFNAME, FS_SIZE_SFNAME_WITHOUT_EXT, and Is_unicode.

Referenced by fat_find_short_entry_name().

bool fat_entry_shortname_compare ( FS_STRING  short_name)

This function compares a short name with the current entry.

Parameters
short_nameshort name to compare (format entry = 8+3 Bytes)
Returns
true it is the same
false in case of error, see global value "fs_g_status" for more detail

References fat_get_ptr_entry(), FS_ATTR_LFN_ENTRY, FS_ENTRY_DEL, FS_ENTRY_END, FS_ERR_ENTRY_BAD, FS_ERR_ENTRY_EMPTY, fs_g_status, and memcmp_ram2ram.

Referenced by fat_find_short_entry_name().

uint8_t fat_find_short_entry_name ( FS_STRING  sz_name)

This function searches an unique short name.

Parameters
sz_nameoriginal name
Returns
the number used to create the short name
0 in case of error

References _MEM_TYPE_SLOW_, fat_create_short_entry_name(), fat_entry_shortname_compare(), fat_read_dir(), FS_ERR_ENTRY_EMPTY, FS_ERR_OUT_LIST, fs_g_nav_fast, fs_g_status, and Fs_management_fast::u16_entry_pos_sel_file.

bool fat_garbage_collector_entry ( void  )

This function remove the entry selected in the directory to clean it.

Returns
false in case of error, see global value "fs_g_status" for more detail
true otherwise

References _MEM_TYPE_SLOW_, fat_cache_mark_sector_as_dirty(), fat_get_ptr_entry(), fat_read_dir(), FS_ENTRY_DEL, FS_ENTRY_END, FS_ERR_OUT_LIST, fs_g_nav_fast, fs_g_status, FS_SIZE_FILE_ENTRY, memcpy_ram2ram, and Fs_management_fast::u16_entry_pos_sel_file.

Referenced by fat_alloc_entry_free().

bool fat_initialize_fat ( void  )

This function initializes the fat one and two.

Returns
false in case of error, see global value "fs_g_status" for more detail
true otherwise

References fat_cache_mark_sector_as_dirty(), fat_cache_read_sector(), fs_g_nav, fs_g_sector, fs_gu32_addrsector, Is_fat12, Is_fat16, Is_fat32, memcpy_code2ram, Fs_management::u32_fat_size, and Fs_management::u32_ptr_fat.

Referenced by fat_format().

bool fat_select_filesystem ( uint8_t  u8_fat_type,
bool  b_MBR 
)

This function computes the FAT type to use.

@param     u8_fat_type          Select the type of format <br>
           FS_FORMAT_DEFAULT,   The file system module chooses the better FAT format for the drive space <br>
           FS_FORMAT_FAT,       The FAT12 or FAT16 is used to format the drive, if possible (disk space <2GB) <br>
           FS_FORMAT_FAT32,     The FAT32 is used to format the drive, if possible (disk space >32MB) <br>
@param     b_MBR          true, include a MBR on disk

@return    false in case of error, see global value "fs_g_status" for more detail
@return    true otherwise
//! Compute the fat type, fat position and fat size.
//! 

References _CONST_TYPE_, FS_512B, FS_ERR_BAD_SIZE_FAT, FS_ERR_DEVICE_TOO_SMALL, FS_FORMAT_FAT, FS_FORMAT_FAT32, fs_g_nav, fs_g_nav_fast, fs_g_status, fs_s_u32_size_partition, FS_TYPE_FAT_12, FS_TYPE_FAT_16, FS_TYPE_FAT_32, Is_fat12, Is_fat16, Is_fat32, LSB, MSB, TableFAT12, TableFAT16, TableFAT32, Fs_management::u32_fat_size, Fs_management::u32_ptr_fat, Fs_management::u8_BPB_SecPerClus, and Fs_management_fast::u8_type_fat.

Referenced by fat_format().

uint16_t fat_translate_ascii_to_number ( const FS_STRING  sz_ascii_number,
uint8_t  u8_size_number_ascii 
)

This function translates a ASCII number to a digital number.

@param     sz_ascii_number         ascii number (ex:"1907")
@param     u8_size_number_ascii    number of digit (ex:4)

@return    the digital number
//! OUT, update sz_ascii_number
//! 

References _MEM_TYPE_FAST_.

Referenced by fat_translatedate_ascii_to_number().

uint8_t fat_translate_char_shortname ( uint8_t  character)

This function translates the character to authorized short name character.

Parameters
charactercharacter to translate
Returns
character translated
if no supported then 0

References fs_s_execption_char.

Referenced by fat_create_short_entry_name().

void fat_translate_number_to_ascii ( FS_STRING  sz_ascii_number,
uint8_t  u8_size_number_ascii,
uint8_t  u8_nb_increment 
)

This function translates a digital number to a ASCII number.

@param     sz_ascii_number         ascii string to increment (ex:"1907")
@param     u8_size_number_ascii    number of digit (ex:4)
@param     u8_nb_increment         number to add (ex:"102")
//! OUT, Update sz_ascii_number (ex:"2009")
//! 

Referenced by fat_translatedate_number_to_ascii().

void fat_translatedate_ascii_to_number ( const FS_STRING  sz_date,
PTR_CACHE  ptr_date,
bool  enable_ms 
)

This function translates a date ascii string to date FAT value.

@param     sz_date        table with date information  <br>
                          storage format (ASCII) = "YYYYMMDDHHMMSSMS" = year, month, day, hour, minute, second, millisecond
@param     ptr_date       pointer on date in internal cache
@param     enable_ms      true, translate the millisecond field
//! OUT, write the date field at ptr_date
//! 

References fat_translate_ascii_to_number().

void fat_translatedate_number_to_ascii ( FS_STRING  sz_date,
PTR_CACHE  ptr_date,
bool  enable_ms 
)

This function translates a date FAT value to ascii string.

Parameters
sz_datetable to store the date information
storage format (ASCII) = "YYYYMMDDHHMMSSMS" = year, month, day, hour, minute, second, millisecond
ptr_datepointer on date in internal cache
enable_mstrue, translate the millisecond field

References fat_translate_number_to_ascii().

Referenced by fat_get_date().

_CONST_TYPE_ uint8_t const_FSI_LeadSig[]
Initial value:
= {
0x52,0x52,0x61,0x41
}

Referenced by fat_read_fat32_FSInfo().

_CONST_TYPE_ uint8_t const_FSI_StrucSig[]
Initial value:
= {
0x72,0x72,0x41,0x61
}

Referenced by fat_read_fat32_FSInfo().

_CONST_TYPE_ uint8_t const_header_fat12[]
Initial value:
= {
0xF8,0xFF,0xFF
}
_CONST_TYPE_ uint8_t const_header_fat16[]
Initial value:
= {
0xF8,0xFF,0xFF,0xFF
}
_CONST_TYPE_ uint8_t const_header_fat32[]
Initial value:
= {
0xF8,0xFF,0xFF,0x0F,0xFF,0xFF,0xFF,0x0F
,0xFF,0xFF,0xFF,0x0F
}
_CONST_TYPE_ uint8_t const_header_pbr[]
Initial value:
= {
0xEB,0,0x90,
'M','S','W','I','N','4','.','1',
FS_512B & 0xFF, FS_512B >>8,
0,
0,0,
2,
0,0,
0,0,
0,0,
0x3F,0,
0,0,
1
}
#define FS_PART_NO_REMOVE_MEDIA
Definition: fat.h:178
#define FS_512B
Definition: fat.h:220

Referenced by fat_write_PBR().

_CONST_TYPE_ uint8_t const_tail_pbr[]
Initial value:
= {
0,
0,0,0,0,
'N','O',' ','N','A','M','E',' ',' ',' ',' ',
'F','A','T',' ',' ',' ',' ',' ',
}
#define FS_PART_HARD_DISK
Definition: fat.h:179
#define FS_BOOT_SIGN
Definition: fat.h:180

Referenced by fat_write_PBR().

_CONST_TYPE_ uint8_t fs_s_execption_char[] ={'+',',','.',';','=','[',']'}

Characters table no supported in a short name.

Referenced by fat_translate_char_shortname().

_CONST_TYPE_ uint8_t fs_s_tab_incorrect_char[] ={':','*','?','"','<','>','|'}

Characters table no supported in a file name.

Referenced by fat_check_name().

_MEM_TYPE_SLOW_ uint32_t fs_s_u32_size_partition
Initial value:
= {
{ 4096, 1},
{ 8192, 2},
{ 16384, 4},
{ 32680, 8},
}

Table format for FAT12.

Referenced by fat_select_filesystem().

Initial value:
= {
{ 8400, 0},
{ 32680, 2},
{ 262144, 4},
{ 524288, 8},
{ 1048576, 16},
{ 2097152, 32},
{ 4194304, 64},
{ 0xFFFFFFFF, 0}
}

Table format for FAT16.

Referenced by fat_select_filesystem().

Initial value:
= {
{ 66600, 0},
{ 532480, 1},
{ 16777216, 8},
{ 33554432, 16},
{ 67108864, 32},
{ 0xFFFFFFFF, 64}
}

Table format for FAT32.

Referenced by fat_select_filesystem().