#include "fs_com.h"
Go to the source code of this file.
Data Structures | |
| union | Fs_rootdir |
| Union to define a root directory. More... | |
| struct | Fs_management |
| Struture to save the variables frequently used by file system mounted. More... | |
| struct | Fs_management_fast |
| Struture to save the variables very frequently used by file system mounted. More... | |
| struct | Fs_management_entry |
| Struture to save the frequently variables of file system mounted. More... | |
| struct | Fs_segment |
| Struture to define a segment. More... | |
| struct | Fs_cluster |
| Struture to store cluster information. More... | |
| struct | Fs_clusterlist_cache |
| Struture to store the cluster list cache. More... | |
| struct | Fs_sector_cache |
| Struture to store the information about sector cache (=last sector read or write on disk). More... | |
Variables used to manage the sector cache | |
| _MEM_TYPE_SLOW_ U8 | fs_g_sector [512] |
| _MEM_TYPE_SLOW_ Fs_sector_cache | fs_g_sectorcache |
| _MEM_TYPE_SLOW_ U32 | fs_gu32_addrsector |
| Store the address of futur cache (unit 512B). | |
| typedef U8 _MEM_TYPE_SLOW_ * | PTR_CACHE |
Defines | |
| #define | _GLOBEXT_ extern |
- File system vocabulary :
MBR : Master Boot Record (constains four PE)
PE : Partition Entry (constains a location informations about PBR)
PBR : Partition Boot Record
BPB : BIOS Parameter Block (see Hardware White Paper FAT)
PBR = BPB
FAT : File Allocation Table
| |
| #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) |
| #define | FS_MBR_OFFSET_PART_ENTRY(num) ((U16)((U16)(0x1BE)+(0x10 * num))) |
| Position (unit byte) in the MBR of a partition entry. | |
| #define | FS_BUF_SECTOR_EMPTY 0xFF |
| Signal that sector cache is not valid. | |
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] |
Constante 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. | |
| #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. | |
| #define | FS_END_FIND 0xFFFE |
| Signal that a file entry is the last file entry accessibled by system. | |
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++) |
Functions | |
| U8 | fat_get_nbpartition (void) |
| This function returns the number of partition present on selected drive. | |
| Bool | fat_mount (void) |
| This function mounts a partition. | |
| Bool | fat_format (U8 u8_fat_type) |
| This function formats the drive. | |
| Bool | fat_serialnumber (Bool b_action, U8 _MEM_TYPE_SLOW_ *a_u8_sn) |
| This function reads or writes a serial number. | |
Functions to verify navigator state | |
}@ | |
| Bool | fat_check_device (void) |
| This function checks device state. | |
| Bool | fat_check_mount (void) |
| This function checks if the partition is mounted. | |
| Bool | fat_check_noopen (void) |
| This function checks if a file is not opened on current navigator. | |
| Bool | fat_check_open (void) |
| This function checks if a file is opened on current navigator. | |
| Bool | fat_check_select (void) |
| This function checks if a file is selected on current navigator. | |
| Bool | fat_check_mount_noopen (void) |
| This function checks if the partition is mounted and no file is opened. | |
| 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. | |
| Bool | fat_check_mount_select_open (void) |
| This function checks if the partition is mounted and if a file is opened. | |
| Bool | fat_check_mount_select (void) |
| This function checks if the partition is mounted and if a file is selected. | |
| Bool | fat_check_is_file (void) |
| This function checks if the selected file entry is a file and not a directory. | |
Functions to compute free space on a partition | |
| U32 | fat_getfreespace (void) |
| This function returns the space free in the partition. | |
| U8 | fat_getfreespace_percent (void) |
| This function returns the space free in percent. | |
| Bool | fat_write_fat32_FSInfo (U32 u32_nb_free_cluster) |
| U32 | fat_read_fat32_FSInfo (void) |
Functions to manage the cluster list | |
| Bool | fat_cluster_list (U8 opt_action, Bool b_for_file) |
| This function gets or clears a cluster list. | |
| void | fat_cache_clusterlist_reset (void) |
| This function resets the cluster list caches. | |
| Bool | fat_cluster_val (Bool b_mode) |
| This function returns or modifys a cluster value in FAT. | |
| Bool | fat_cluster_readnext (void) |
| This function is optimized to read a continue cluster list on FAT16 and FAT32. | |
| U8 | fat_checkcluster (void) |
| This function checks the cluster value. | |
| 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 (U8 mode) |
| This function gets or clears a cluster list at the current position in the selected file. | |
| Bool | fat_write_file (U8 mode, U32 u32_nb_sector_write) |
| Bool | fat_read_dir (void) |
| This function fill the internal cache with a sector from current directory. | |
| 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. | |
| Bool | fat_entry_checkext (FS_STRING sz_filter) |
| This function checks the file extension. | |
| void | fat_get_entry_info (void) |
| This function reads information about selected file. | |
| Bool | fat_entry_is_dir (void) |
| This function checks if the entry file is a directory. | |
| void | fat_clear_entry_info_and_ptr (void) |
| This function resets the selection pointers. | |
| void | fat_write_entry_file (void) |
| Bool | fat_entry_shortname (FS_STRING sz_name, U8 u8_size_max, Bool b_mode) |
| This function returns or compares the short name entry. | |
| Bool | fat_entry_longname (FS_STRING sz_name, U8 u8_size_max, Bool b_mode, Bool b_match_case) |
| This function returns or compares the long name entry. | |
| Bool | fat_check_eof_name (U16 character) |
| Check end of name. | |
| PTR_CACHE | fat_get_ptr_entry (void) |
| This function returns a cache pointer on the current entry. | |
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. | |
| 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. | |
| void | fat_cache_reset (void) |
| This function resets the sector cache. | |
| void | fat_cache_clear (void) |
| void | fat_cache_mark_sector_as_dirty (void) |
| Bool | fat_cache_flush (void) |
| This function flushs the sector cache on the memory if necessary. | |
Variables | |
| Bool | g_b_unicode |
| Variables to select string format (initialised in nav_reset()). | |
| Bool | g_b_string_length |
| Variables to select LENGTH string mode (initialised in nav_reset()). | |
| Bool | g_b_no_check_disk |
| Variables to enable/disable the disk check before each action on disk. | |
| _MEM_TYPE_FAST_ Fs_segment | fs_g_seg |
| Variable frequently used by many function (optimization, no parameter in function). | |
| _MEM_TYPE_FAST_ Fs_cluster | fs_g_cluster |
| To take time in functions: fat_getfreespace, fat_cluster_list, fat_cluster_val, fat_checkcluster. | |
Variables initialised in drive_mount() | |
| _MEM_TYPE_SLOW_ Fs_management | fs_g_nav |
| _MEM_TYPE_FAST_ Fs_management_fast | fs_g_nav_fast |
| _MEM_TYPE_SLOW_ Fs_management_entry | fs_g_nav_entry |
This file is the header for FAT services
Definition in file fat.h.
| #define _GLOBEXT_ extern |
| #define Is_fat12 (FS_TYPE_FAT_12 == fs_g_nav_fast.u8_type_fat) |
Definition at line 72 of file fat.h.
Referenced by fat_checkcluster(), fat_cluster_list(), fat_cluster_val(), fat_getfreespace(), and fat_getfreespace_percent().
| #define Is_fat16 (FS_TYPE_FAT_16 == fs_g_nav_fast.u8_type_fat) |
Definition at line 77 of file fat.h.
Referenced by fat_checkcluster(), fat_cluster_list(), fat_cluster_val(), and fat_getfreespace_percent().
| #define Is_fat32 (FS_TYPE_FAT_32 == fs_g_nav_fast.u8_type_fat) |
Definition at line 82 of file fat.h.
Referenced by fat_checkcluster(), fat_cluster_list(), fat_cluster_readnext(), fat_cluster_val(), fat_getfreespace(), and fat_getfreespace_percent().
| #define Is_unicode (g_b_unicode) |
Definition at line 89 of file fat.h.
Referenced by fat_entry_longname(), fat_entry_shortname(), nav_dir_name(), nav_file_name(), nav_getcwd(), and nav_setcwd().
Position (unit byte) in the MBR of a partition entry.
Definition at line 105 of file fat.h.
Referenced by fat_get_nbpartition(), and fat_mount().
| #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] |
| #define FS_BR_SIGNATURE_LOW 0x55 |
| #define FS_BR_SIGNATURE_HIGH 0xAA |
| #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_FAT12_MAX_CLUSTERS 4085 |
| #define FS_FAT16_MAX_CLUSTERS 65525 |
| #define FS_ENTRY_END 0x00 |
| #define FS_ENTRY_DEL 0xE5 |
| #define FS_ENTRY_LFN_LAST 0x40 |
| #define FS_SIZE_FILE_ENTRY 32 |
Definition at line 194 of file fat.h.
Referenced by fat_entry_longname(), fat_get_ptr_entry(), and fat_mount().
| #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_NB_FAT 2 |
| #define FS_512B 512 |
| #define FS_512B_MASK (512-1) |
Definition at line 214 of file fat.h.
Referenced by fat_get_ptr_entry(), fat_read_file(), file_getc(), and file_read().
| #define FS_512B_SHIFT_BIT 9 |
Definition at line 215 of file fat.h.
Referenced by fat_read_dir(), fat_read_file(), file_read(), and nav_file_lgtsector().
| #define FS_SHIFT_B_TO_SECTOR FS_512B_SHIFT_BIT |
| #define FS_CACHE_SIZE 512 |
| #define FS_BUF_SECTOR_EMPTY 0xFF |
Signal that sector cache is not valid.
Definition at line 223 of file fat.h.
Referenced by fat_cache_reset().
| #define FS_CLUS_OK 0 |
| #define FS_CLUS_BAD 1 |
| #define FS_CLUS_END 2 |
| #define FS_CLUST_ACT_SEG 0x01 |
Definition at line 236 of file fat.h.
Referenced by fat_cluster_list(), fat_read_file(), file_read(), and file_read_buf().
| #define FS_CLUST_ACT_ONE 0x02 |
Definition at line 237 of file fat.h.
Referenced by fat_cluster_list(), fat_read_dir(), fat_read_file(), file_getc(), and file_read_buf().
| #define FS_CLUST_ACT_CLR 0x03 |
| #define FS_CLUST_VAL_READ FALSE |
Definition at line 243 of file fat.h.
Referenced by fat_cluster_list(), fat_getfreespace(), and fat_getfreespace_percent().
| #define FS_CLUST_VAL_WRITE TRUE |
| #define FS_CLUST_VAL_EOL 0x0FFFFFFF |
| #define FS_TYPE_FAT_UNM 0 |
Partition not mounted.
Definition at line 355 of file fat.h.
Referenced by fat_check_device(), fat_check_mount(), fat_check_noopen(), fat_mount(), nav_drive_set(), nav_partition_freespace(), nav_partition_freespace_percent(), nav_partition_mount(), nav_partition_set(), nav_partition_space(), nav_partition_type(), and nav_reset().
| #define FS_TYPE_FAT_12 1 |
| #define FS_TYPE_FAT_16 2 |
| #define FS_TYPE_FAT_32 3 |
| #define FS_NO_SEL 0xFFFF |
Signal that a file entry isn't selected.
Definition at line 364 of file fat.h.
Referenced by fat_check_select(), fat_clear_entry_info_and_ptr(), nav_filelist_eol(), nav_filelist_exist(), nav_filelist_goto(), nav_filelist_nb(), and nav_filelist_set().
| #define FS_END_FIND 0xFFFE |
Signal that a file entry is the last file entry accessibled by system.
Definition at line 365 of file fat.h.
Referenced by nav_filelist_set().
| #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 ) |
Definition at line 373 of file fat.h.
Referenced by fat_check_device(), fat_clear_entry_info_and_ptr(), file_close(), and nav_reset().
| #define fat_check_nav_access_file | ( | b | ) | (TRUE) |
| #define fat_invert_nav ( arg ) (arg++) |
| #define fat_copy_nav ( arg ) (arg++) |
| Bool fat_check_device | ( | void | ) |
This function checks device state.
FALSE otherwise
//! This function updates all navigator datas when the device state change. //!
Definition at line 88 of file fat.c.
References CTRL_BUSY, CTRL_GOOD, CTRL_NO_PRESENT, FALSE, fat_cache_clusterlist_reset(), fat_cache_reset(), Fat_file_close, FS_ERR_HW, FS_ERR_HW_NO_PRESENT, fs_g_nav, fs_g_nav_fast, fs_g_sectorcache, fs_g_status, FS_NB_NAVIGATOR, FS_TYPE_FAT_UNM, g_b_no_check_disk, i, mem_test_unit_ready(), TRUE, Fs_sector_cache::u8_lun, Fs_management::u8_lun, and Fs_management_fast::u8_type_fat.
00089 { 00090 U8 retry=0; 00091 #if (FS_NB_NAVIGATOR > 1) 00092 U8 i; 00093 #endif 00094 Ctrl_status status; 00095 00096 // Possibility to ignore the disk check. Used to take time during multi read/write access 00097 if( g_b_no_check_disk ) 00098 return TRUE; 00099 00100 if( 0xFF == fs_g_nav.u8_lun ) 00101 { 00102 fs_g_status = FS_ERR_HW; 00103 return FALSE; // No device selected 00104 } 00105 00106 for( retry=0 ; retry<100 ; retry++ ) 00107 { 00108 // Check device 00109 status = mem_test_unit_ready( fs_g_nav.u8_lun ); 00110 if( CTRL_GOOD == status ) 00111 return TRUE; // drive ready 00112 00113 //* HERE error or state change 00114 // Clean all navigator datas which use this device 00115 fs_g_nav_fast.u8_type_fat = FS_TYPE_FAT_UNM; // By default the fat isn't mounted 00116 Fat_file_close(); // By default the file is not open 00117 #if (FS_NB_NAVIGATOR > 1) 00118 for( i=0 ; i!=(FS_NB_NAVIGATOR-1) ; i++ ) 00119 { 00120 if( fs_g_nav.u8_lun == fs_g_navext[i].u8_lun ) 00121 { 00122 fs_g_navext_fast[i].u8_type_fat = FS_TYPE_FAT_UNM; // By default the fat isn't mounted 00123 fs_g_navext_entry[i].u8_open_mode = 0; // By default the file is not open 00124 } 00125 } 00126 #endif 00127 // If the internal cache corresponding at device then clean it 00128 if( fs_g_nav.u8_lun == fs_g_sectorcache.u8_lun ) 00129 { 00130 fat_cache_reset(); 00131 } 00132 fat_cache_clusterlist_reset(); 00133 00134 fs_g_status = FS_ERR_HW; // By default HW error 00135 if( CTRL_BUSY == status ) 00136 continue; // If device busy then retry 00137 00138 if( CTRL_NO_PRESENT == status ) 00139 fs_g_status = FS_ERR_HW_NO_PRESENT; // Update error flag 00140 break; // FAIL or NOT PRESENT = fatal error = no retry 00141 } 00142 return FALSE; 00143 }
| Bool fat_check_mount | ( | void | ) |
This function checks if the partition is mounted.
FALSE otherwise
Definition at line 151 of file fat.c.
References FALSE, fat_check_device(), fat_mount(), FS_ERR_NO_MOUNT, fs_g_nav_fast, fs_g_status, FS_TYPE_FAT_UNM, TRUE, and Fs_management_fast::u8_type_fat.
00152 { 00153 if( !fat_check_device() ) 00154 return FALSE; 00155 if (FS_TYPE_FAT_UNM == fs_g_nav_fast.u8_type_fat) 00156 { 00157 if( !fat_mount() ) 00158 { 00159 fs_g_status = FS_ERR_NO_MOUNT; 00160 return FALSE; 00161 } 00162 } 00163 return TRUE; 00164 }
| Bool fat_check_noopen | ( | void | ) |
This function checks if a file is not opened on current navigator.
FALSE otherwise
Definition at line 172 of file fat.c.
References FALSE, fat_check_device(), Fat_file_is_open, FS_ERR_TOO_FILE_OPEN, fs_g_nav_fast, fs_g_status, FS_TYPE_FAT_UNM, TRUE, and Fs_management_fast::u8_type_fat.
00173 { 00174 if( !fat_check_device() ) 00175 return TRUE; 00176 if (FS_TYPE_FAT_UNM == fs_g_nav_fast.u8_type_fat) 00177 return TRUE; 00178 if( Fat_file_is_open() ) 00179 { 00180 fs_g_status = FS_ERR_TOO_FILE_OPEN; // The navigation have already open a file 00181 return FALSE; 00182 } 00183 return TRUE; 00184 }
| Bool fat_check_open | ( | void | ) |
This function checks if a file is opened on current navigator.
FALSE otherwise
Definition at line 192 of file fat.c.
References FALSE, Fat_file_isnot_open, FS_ERR_FILE_NO_OPEN, fs_g_status, and TRUE.
00193 { 00194 if( Fat_file_isnot_open() ) 00195 { 00196 fs_g_status = FS_ERR_FILE_NO_OPEN; 00197 return FALSE; 00198 } 00199 return TRUE; 00200 }
| Bool fat_check_select | ( | void | ) |
This function checks if a file is selected on current navigator.
FALSE otherwise
Definition at line 208 of file fat.c.
References FALSE, FS_ERR_NO_FILE_SEL, fs_g_nav_fast, fs_g_status, FS_NO_SEL, TRUE, and Fs_management_fast::u16_entry_pos_sel_file.
00209 { 00210 if (FS_NO_SEL == fs_g_nav_fast.u16_entry_pos_sel_file) 00211 { 00212 fs_g_status = FS_ERR_NO_FILE_SEL; 00213 return FALSE; 00214 } 00215 return TRUE; 00216 }
| Bool fat_check_mount_noopen | ( | void | ) |
This function checks if the partition is mounted and no file is opened.
FALSE otherwise
Definition at line 224 of file fat.c.
References FALSE, fat_check_mount(), and fat_check_noopen().
00225 { 00226 if( !fat_check_mount() ) 00227 return FALSE; 00228 return fat_check_noopen(); 00229 }
| 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.
FALSE otherwise
Definition at line 237 of file fat.c.
References FALSE, fat_check_mount(), fat_check_noopen(), and fat_check_select().
00238 { 00239 if( !fat_check_mount() ) 00240 return FALSE; 00241 if( !fat_check_select() ) 00242 return FALSE; 00243 return fat_check_noopen(); 00244 }
| Bool fat_check_mount_select_open | ( | void | ) |
This function checks if the partition is mounted and if a file is opened.
FALSE otherwise
Definition at line 252 of file fat.c.
References FALSE, fat_check_mount(), fat_check_open(), and fat_check_select().
00253 { 00254 if( !fat_check_mount() ) 00255 return FALSE; 00256 if( !fat_check_select() ) 00257 return FALSE; 00258 return fat_check_open(); 00259 }
| Bool fat_check_mount_select | ( | void | ) |
This function checks if the partition is mounted and if a file is selected.
FALSE otherwise
Definition at line 267 of file fat.c.
References FALSE, fat_check_mount(), and fat_check_select().
00268 { 00269 if( !fat_check_mount() ) 00270 return FALSE; 00271 return fat_check_select(); 00272 }
| Bool fat_check_is_file | ( | void | ) |
This function checks if the selected file entry is a file and not a directory.
FALSE otherwise
Definition at line 280 of file fat.c.
References FALSE, Fat_is_not_a_file, FS_ERR_NO_FILE, fs_g_status, and TRUE.
00281 { 00282 if( Fat_is_not_a_file ) 00283 { 00284 fs_g_status = FS_ERR_NO_FILE; // It isn't a file, it is a directory or a volume id 00285 return FALSE; 00286 } 00287 return TRUE; 00288 }
| U8 fat_get_nbpartition | ( | void | ) |
This function returns the number of partition present on selected drive.
This function returns the number of partition present on selected drive.
Definition at line 296 of file fat.c.
References FALSE, fat_cache_read_sector(), fat_check_device(), FS_BR_SIGNATURE_HIGH, FS_BR_SIGNATURE_LOW, fs_g_sector, fs_gu32_addrsector, FS_MBR_OFFSET_PART_ENTRY, and TRUE.
00297 { 00298 if( !fat_check_device() ) 00299 return 0; 00300 00301 #warning this routine contains bug, rework it 00302 // Read the first sector of drive 00303 fs_gu32_addrsector = 0; 00304 if( !fat_cache_read_sector( TRUE )) 00305 return FALSE; 00306 00307 // Check PBR or MBR signature 00308 if ( (fs_g_sector[510] != FS_BR_SIGNATURE_LOW ) 00309 && (fs_g_sector[511] != FS_BR_SIGNATURE_HIGH ) ) 00310 { 00311 // No MBR 00312 // The sector, is it a PBR ? 00313 if ( (fs_g_sector[0] == 0xEB) && // PBR Byte 0 00314 (fs_g_sector[2] == 0x90) && // PBR Byte 2 00315 ((fs_g_sector[21] & 0xF0) == 0xF0) ) // PBR Byte 21 : Media byte 00316 { 00317 return 1; // No MBR but PBR exist then only one partition 00318 } else { 00319 return 0; // No MBR and no PBR then no partition found 00320 } 00321 } 00322 00323 number_part = 0; 00324 while( 1 ) 00325 { 00326 // The first sector must be a MBR, then check the partition entry in the MBR 00327 if ( ((fs_g_sector[FS_MBR_OFFSET_PART_ENTRY(number_part)+0] != FS_PARTITION_ACTIVE) && 00328 (fs_g_sector[FS_MBR_OFFSET_PART_ENTRY(number_part)+0] != 0x00)) 00329 || (fs_g_sector[FS_MBR_OFFSET_PART_ENTRY(number_part)+4] == 0x00) ) 00330 { 00331 break; 00332 } 00333 number_part++; 00334 } 00335 return number_part; 00336 }
| Bool fat_mount | ( | void | ) |
This function mounts a partition.
This function mounts a partition.
TRUE otherwise
//! Global variables used //! IN : //! fs_g_nav.u8_lun Indicate the drive to mount //! fs_g_nav.u8_partition Indicate the partition to mount (if FS_MULTI_PARTITION = ENABLED ) //! OUT: //! fs_g_nav update structure //! If the FS_MULTI_PARTITION option is disabled //! then the mount routine selects the first partition supported by file system. <br> //!
Definition at line 102 of file fat_unusual.c.
Referenced by fat_check_mount(), and nav_partition_mount().
00103 { 00104 U8 u8_sector_size; 00105 U8 u8_tmp; 00106 U16 u16_tmp; 00107 U32 u32_tmp; 00108 00109 // Select the root directory 00110 fs_g_nav.u32_cluster_sel_dir = 0; 00111 // No selected file 00112 fat_clear_entry_info_and_ptr(); 00113 00114 fs_g_nav_fast.u8_type_fat = FS_TYPE_FAT_UNM; 00115 fs_gu32_addrsector = 0; // Start read at the beginning of memory 00116 00117 // Check if the drive is availabled 00118 if( !fat_check_device() ) 00119 return FALSE; 00120 00121 while( 1 ) // Search a valid partition 00122 { 00123 // Read one sector 00124 if( !fat_cache_read_sector( TRUE )) 00125 return FALSE; 00126 00127 // Check PBR/MBR signature 00128 if ( (fs_g_sector[510] != FS_BR_SIGNATURE_LOW ) 00129 && (fs_g_sector[511] != FS_BR_SIGNATURE_HIGH ) ) 00130 { 00131 fs_g_status = FS_ERR_NO_FORMAT; 00132 return FALSE; 00133 } 00134 00135 if ( 0 == fs_gu32_addrsector ) 00136 { 00137 //** first sector then check a MBR structure 00138 // Search the first partition supported 00139 #if (FS_MULTI_PARTITION == ENABLED) 00140 u16_tmp=0; // Init to "no valid partition found" 00141 #endif 00142 for( u8_tmp=0 ; u8_tmp!=4 ; u8_tmp++ ) 00143 { 00144 // The first sector must be a MBR, then check the partition entry in the MBR 00145 if ( ((fs_g_sector[FS_MBR_OFFSET_PART_ENTRY(u8_tmp)+0] == FS_PART_BOOTABLE )|| 00146 (fs_g_sector[FS_MBR_OFFSET_PART_ENTRY(u8_tmp)+0] == FS_PART_NO_BOOTABLE ) ) 00147 && ((fs_g_sector[FS_MBR_OFFSET_PART_ENTRY(u8_tmp)+4] == FS_PART_TYPE_FAT12 )|| 00148 (fs_g_sector[FS_MBR_OFFSET_PART_ENTRY(u8_tmp)+4] == FS_PART_TYPE_FAT16_INF32M )|| 00149 (fs_g_sector[FS_MBR_OFFSET_PART_ENTRY(u8_tmp)+4] == FS_PART_TYPE_FAT16_SUP32M )|| 00150 (fs_g_sector[FS_MBR_OFFSET_PART_ENTRY(u8_tmp)+4] == FS_PART_TYPE_FAT16_SUP32M_BIS)|| 00151 (fs_g_sector[FS_MBR_OFFSET_PART_ENTRY(u8_tmp)+4] == FS_PART_TYPE_FAT32 )|| 00152 (fs_g_sector[FS_MBR_OFFSET_PART_ENTRY(u8_tmp)+4] == FS_PART_TYPE_FAT32_BIS )) ) 00153 { 00154 // A valid partition is found 00155 #if (FS_MULTI_PARTITION == ENABLED) 00156 if( u16_tmp == fs_g_nav.u8_partition ) 00157 break; // The selected partition is valid 00158 u16_tmp++; 00159 #else 00160 break; 00161 #endif 00162 } 00163 } 00164 if( u8_tmp != 4 ) 00165 { 00166 // Partition found -> Get partition position (unit sector) at offset 8 00167 LSB0(fs_gu32_addrsector) = fs_g_sector[FS_MBR_OFFSET_PART_ENTRY(u8_tmp)+8]; 00168 LSB1(fs_gu32_addrsector) = fs_g_sector[FS_MBR_OFFSET_PART_ENTRY(u8_tmp)+9]; 00169 LSB2(fs_gu32_addrsector) = fs_g_sector[FS_MBR_OFFSET_PART_ENTRY(u8_tmp)+10]; 00170 LSB3(fs_gu32_addrsector) = fs_g_sector[FS_MBR_OFFSET_PART_ENTRY(u8_tmp)+11]; 00171 fs_gu32_addrsector *= mem_sector_size( fs_g_nav.u8_lun ); 00172 continue; // Go to check PBR of partition 00173 } 00174 00175 // No MBR found then check PBR 00176 #if (FS_MULTI_PARTITION == ENABLED) 00177 // The device don't have mutli partition, but only one 00178 if ( 0 != fs_g_nav.u8_partition ) 00179 { 00180 fs_g_status = FS_ERR_NO_PART; 00181 return FALSE; 00182 } 00183 #endif 00184 } 00185 00186 //** Check a PBR structure 00187 if ( (fs_g_sector[0] == 0xEB) && // PBR Byte 0 00188 (fs_g_sector[2] == 0x90) && // PBR Byte 2 00189 ((fs_g_sector[21] & 0xF0) == 0xF0) ) // PBR Byte 21 : Media byte 00190 { 00191 break; // valid PBR found 00192 } 00193 // PBR not found 00194 fs_g_status = FS_ERR_NO_PART; 00195 return FALSE; 00196 } 00197 00198 fs_g_status = FS_ERR_NO_SUPPORT_PART; // by default partition no supported 00199 00200 // Get sector size of File System (unit 512B) 00201 // To translate from sector disk unit to sector 512B unit 00202 u8_sector_size = HIGH_16_BPB_BytsPerSec/2; 00203 00204 // Read BPB_SecPerClus (unit sector) 00205 fs_g_nav.u8_BPB_SecPerClus = U8_BPB_SecPerClus * u8_sector_size; 00206 00207 //** FAT Type determination (algorithm of "Hardware White Paper FAT") 00208 // Get FAT size (unit sector) 00209 LSB( u16_tmp ) = LOW_16_BPB_FATSz16; 00210 MSB( u16_tmp ) = HIGH_16_BPB_FATSz16; 00211 if ( 0==u16_tmp ) 00212 { 00213 LSB( u16_tmp ) = LOW0_32_BPB_FATSz32; 00214 MSB( u16_tmp ) = LOW1_32_BPB_FATSz32; 00215 // a large FAT32 isn't supported by this file system 00216 if( (0 != LOW2_32_BPB_FATSz32 ) 00217 || (0 != LOW3_32_BPB_FATSz32 ) ) 00218 { 00219 return FALSE; 00220 } 00221 } 00222 fs_g_nav.u16_fat_size = u16_tmp * u8_sector_size; 00223 00224 // Get total count of sectors in partition 00225 if ( (0==LOW_16_BPB_TotSec16) && (0==HIGH_16_BPB_TotSec16) ) 00226 { 00227 LSB0( u32_tmp ) = LOW0_32_BPB_TotSec32; 00228 LSB1( u32_tmp ) = LOW1_32_BPB_TotSec32; 00229 LSB2( u32_tmp ) = LOW2_32_BPB_TotSec32; 00230 LSB3( u32_tmp ) = LOW3_32_BPB_TotSec32; 00231 } 00232 else 00233 { 00234 LSB0( u32_tmp ) = LOW_16_BPB_TotSec16; 00235 LSB1( u32_tmp ) = HIGH_16_BPB_TotSec16; 00236 LSB2( u32_tmp ) = 0; 00237 LSB3( u32_tmp ) = 0; 00238 } 00239 u32_tmp *= u8_sector_size; // Translate from sector disk unit to sector 512B unit 00240 00241 // Compute the offset (unit 512B) between the end of FAT (beginning of root dir in FAT1x) and the beginning of PBR 00242 fs_g_nav.rootdir.seg.u16_pos = FS_NB_FAT * fs_g_nav.u16_fat_size; 00243 00244 // Compute the root directory size (unit sector), for FAT32 is always 0 00245 LSB( u16_tmp ) = LOW_16_BPB_RootEntCnt; 00246 MSB( u16_tmp ) = HIGH_16_BPB_RootEntCnt; 00247 fs_g_nav.rootdir.seg.u16_size = ((u16_tmp * FS_SIZE_FILE_ENTRY) + ((FS_512B*u8_sector_size)-1)) / (FS_512B*u8_sector_size); 00248 fs_g_nav.rootdir.seg.u16_size *= u8_sector_size; 00249 00250 // Get number of reserved sector 00251 LSB( u16_tmp ) = LOW_16_BPB_ResvSecCnt; 00252 MSB( u16_tmp ) = HIGH_16_BPB_ResvSecCnt; 00253 // Get FSInfo position 00254 fs_g_nav.u16_offset_FSInfo = (u16_tmp-LOW_16_BPB_FSInfo)*u8_sector_size; 00255 u16_tmp *= u8_sector_size; // number of reserved sector translated in unit 512B 00256 00257 // Compute the FAT address (unit 512B) 00258 fs_g_nav.u32_ptr_fat = fs_gu32_addrsector + u16_tmp; 00259 00260 // Compute the offset (unit 512B) between the first data cluster and the FAT beginning 00261 fs_g_nav.u32_offset_data = (FS_NB_FAT * (U32)fs_g_nav.u16_fat_size) + (U32)fs_g_nav.rootdir.seg.u16_size; 00262 00263 // Compute the data region (clusters space = Total - Sector used) size (unit 512B) 00264 u32_tmp -= ((U32)u16_tmp + fs_g_nav.u32_offset_data); 00265 00266 // Compute the count of CLUSTER in the data region 00267 // !!!Optimization -> u32_CountofCluster (unit 512B)/ fs_g_nav.u8_BPB_SecPerClus (unit 512B & power of 2) 00268 for( u8_tmp = fs_g_nav.u8_BPB_SecPerClus; u8_tmp!=1 ; u8_tmp >>= 1 ) 00269 { 00270 u32_tmp >>= 1; // This computation round down 00271 } 00272 fs_g_nav.u32_CountofCluster = u32_tmp+2; // The total of cluster include the two reserved clusters 00273 00274 // Determine the FAT type 00275 if (u32_tmp < FS_FAT12_MAX_CLUSTERS) 00276 { 00277 // Is FAT 12 00278 #if (FS_FAT_12 == DISABLED) 00279 return FALSE; 00280 #endif 00281 fs_g_nav_fast.u8_type_fat = FS_TYPE_FAT_12; 00282 } else { 00283 if (u32_tmp < FS_FAT16_MAX_CLUSTERS) 00284 { 00285 // Is FAT 16 00286 #if (FS_FAT_16 == DISABLED) 00287 return FS_NO_SUPPORT_PART; 00288 #endif 00289 fs_g_nav_fast.u8_type_fat = FS_TYPE_FAT_16; 00290 } else { 00291 // Is FAT 32 00292 #if (FS_FAT_32 == DISABLED) 00293 return FALSE; 00294 #endif 00295 fs_g_nav_fast.u8_type_fat = FS_TYPE_FAT_32; 00296 // In FAT32, the root dir is like another directory, this one have a cluster list 00297 // Get the first cluster number of root 00298 LSB0( fs_g_nav.rootdir.u32_cluster ) = LOW0_32_BPB_RootClus; 00299 LSB1( fs_g_nav.rootdir.u32_cluster ) = LOW1_32_BPB_RootClus; 00300 LSB2( fs_g_nav.rootdir.u32_cluster ) = LOW2_32_BPB_RootClus; 00301 LSB3( fs_g_nav.rootdir.u32_cluster ) = LOW3_32_BPB_RootClus; 00302 } 00303 } 00304 00305 return TRUE; 00306 }
This function reads or writes a serial number.
Referenced by nav_partition_serialnumber().
| U32 fat_getfreespace | ( | void | ) |
This function returns the space free in the partition.
Definition at line 2107 of file fat_unusual.c.
Referenced by fat_getfreespace_percent(), and nav_partition_freespace().
02108 { 02109 U32 u32_nb_free_cluster = 0; 02110 02111 // Read ALL FAT1 02112 fs_g_cluster.u32_pos = 2; 02113 02114 if( Is_fat12 ) 02115 { // FAT12 only 02116 for( 02117 ; fs_g_cluster.u32_pos < fs_g_nav.u32_CountofCluster 02118 ; fs_g_cluster.u32_pos++ ) 02119 { 02120 // Get the value of the cluster 02121 if ( !fat_cluster_val( FS_CLUST_VAL_READ ) ) 02122 return 0; 02123 02124 if ( 0 == fs_g_cluster.u32_val ) 02125 u32_nb_free_cluster++; 02126 } 02127 } 02128 else 02129 { 02130 if( Is_fat32 ) 02131 { 02132 u32_nb_free_cluster = fat_read_fat32_FSInfo(); 02133 if( 0xFFFFFFFF != u32_nb_free_cluster ) 02134 goto endof_fat_getfreespace; 02135 u32_nb_free_cluster = 0; 02136 } 02137 // Speed optimization only for FAT16 and FAT32 02138 // init first value used by fat_cluster_readnext() 02139 if( !fat_cluster_val( FS_CLUST_VAL_READ )) 02140 return FALSE; 02141 for( 02142 ; fs_g_cluster.u32_pos < fs_g_nav.u32_CountofCluster 02143 ; fs_g_cluster.u32_pos++ ) 02144 { 02145 if ( 0 == fs_g_cluster.u32_val ) 02146 u32_nb_free_cluster++; 02147 if( !fat_cluster_readnext() ) 02148 return FALSE; 02149 } 02150 #if (FSFEATURE_WRITE_COMPLET == (FS_LEVEL_FEATURES & FSFEATURE_WRITE_COMPLET) ) 02151 if( Is_fat32 ) 02152 { 02153 // Save value for the future call 02154 fat_write_fat32_FSInfo( u32_nb_free_cluster ); 02155 } 02156 #endif 02157 } 02158 endof_fat_getfreespace: 02159 return (u32_nb_free_cluster * fs_g_nav.u8_BPB_SecPerClus); 02160 }
| U8 fat_getfreespace_percent | ( | void | ) |
This function returns the space free in percent.
//! More speed than fat_getfreespace() routine but error delta 1% //!
Definition at line 2172 of file fat_unusual.c.
Referenced by nav_partition_freespace_percent().
02173 { 02174 U32 u32_nb_free_cluster = 0; 02175 U16 u16_tmp, u16_pos; 02176 02177 if( Is_fat12 ) 02178 { // No speed optimization necessary on FAT12 02179 return (((fat_getfreespace()/fs_g_nav.u8_BPB_SecPerClus)*100) / fs_g_nav.u32_CountofCluster); 02180 } 02181 02182 02183 fs_g_cluster.u32_pos = 2; 02184 // Init first value used by fat_cluster_readnext() 02185 if( !fat_cluster_val( FS_CLUST_VAL_READ )) 02186 return FALSE; 02187 02188 // The optimization is to 02189 // - read only the LSB byte of cluster 02190 // - read only 1 cluster for 2 clusters 02191 if( Is_fat32 ) 02192 { 02193 u32_nb_free_cluster = fat_read_fat32_FSInfo(); 02194 if( 0xFFFFFFFF != u32_nb_free_cluster ) 02195 goto endof_fat_getfreespace_percent; 02196 u32_nb_free_cluster = 0; 02197 02198 u16_pos = 2*4; 02199 for( u16_tmp = fs_g_nav.u16_fat_size 02200 ; u16_tmp!=0 02201 ; u16_tmp-- ) 02202 { 02203 for( ; u16_pos < 512 ; u16_pos += (2*4) ) 02204 { 02205 if( 0 == fs_g_sector[u16_pos] ) 02206 u32_nb_free_cluster+=2; 02207 } 02208 // Read next sector in FAT 02209 u16_pos = 0; 02210 fs_gu32_addrsector++; 02211 if( !fat_cache_read_sector( TRUE )) 02212 return 0; 02213 } 02214 } 02215 02216 if ( Is_fat16 ) 02217 { 02218 u16_pos = 2*2; 02219 02220 for( u16_tmp = fs_g_nav.u16_fat_size 02221 ; u16_tmp!=0 02222 ; u16_tmp-- ) 02223 { 02224 for( ; u16_pos < 512 ; u16_pos += (2*2) ) 02225 { 02226 if( 0 == fs_g_sector[u16_pos] ) 02227 u32_nb_free_cluster+=2; 02228 } 02229 // Read next sector in FAT 02230 u16_pos = 0; 02231 fs_gu32_addrsector++; 02232 if( !fat_cache_read_sector( TRUE )) 02233 return 0; 02234 } 02235 } 02236 02237 // Compute percent 02238 if( u32_nb_free_cluster > fs_g_nav.u32_CountofCluster ) 02239 return 100; 02240 if( u32_nb_free_cluster > ((fs_g_nav.u32_CountofCluster-u32_nb_free_cluster)/256) ) 02241 { 02242 // Compute and add a delta error 02243 u32_nb_free_cluster -= ((fs_g_nav.u32_CountofCluster-u32_nb_free_cluster)/256); 02244 } 02245 endof_fat_getfreespace_percent: 02246 return ((u32_nb_free_cluster * 100) / fs_g_nav.u32_CountofCluster); 02247 }
Referenced by fat_cluster_list(), and fat_getfreespace().
| U32 fat_read_fat32_FSInfo | ( | void | ) |
Referenced by fat_getfreespace(), and fat_getfreespace_percent().
This function gets or clears a cluster list.
| b_for_file | If TRUE then it is a file cluster list else a directory cluster list | |
| opt_action | Choose action on the cluster list FS_CLUST_ACT_SEG Get continue memory segment corresponding at cluster list FS_CLUST_ACT_ONE Get only one memory sector (512B) corresponding at cluster list FS_CLUST_ACT_CLR Clear the cluster list |
TRUE otherwise
//! Global variables used //! IN : //! fs_g_seg.u32_addr The first cluster of the cluster list //! fs_g_seg.u32_size_or_pos Start position in the cluster list (unit 512B) //! OUT: //! fs_g_seg.u32_addr The memory segment address corresponding at the beginning of cluster list (only for action FS_CLUST_ACT_SEG & FS_CLUST_ACT_ONE) //! fs_g_seg.u32_size_or_pos The memory segment size corresponding at cluster list readed or cleared (unit 512B) //!
Definition at line 361 of file fat.c.
References _MEM_TYPE_FAST_, FALSE, fat_cache_clusterlist_reset(), fat_cache_clusterlist_update_finish(), fat_cache_clusterlist_update_read(), fat_checkcluster(), fat_clear_info_fat_mod(), fat_cluster_readnext(), fat_cluster_val(), fat_update_fat2(), fat_write_fat32_FSInfo(), FS_CLUS_BAD, FS_CLUS_END, FS_CLUST_ACT_CLR, FS_CLUST_ACT_ONE, FS_CLUST_ACT_SEG, FS_CLUST_VAL_EOL, FS_CLUST_VAL_READ, FS_CLUST_VAL_WRITE, FS_ERR_FS, FS_ERR_OUT_LIST, fs_g_cache_clusterlist, fs_g_cluster, fs_g_nav, fs_g_seg, fs_g_status, fs_g_u8_current_cache, Is_fat12, Is_fat16, Is_fat32, LSB0, MSB0, Fs_management::rootdir, Fs_rootdir::seg, TRUE, Fs_rootdir::u16_pos, Fs_rootdir::u16_size, Fs_segment::u32_addr, Fs_rootdir::u32_cluster, Fs_management::u32_offset_data, Fs_cluster::u32_pos, Fs_management::u32_ptr_fat, Fs_segment::u32_size_or_pos, Fs_clusterlist_cache::u32_start, Fs_cluster::u32_val, and Fs_management::u8_BPB_SecPerClus.
00362 { 00363 _MEM_TYPE_FAST_ U32 u32_tmp; 00364 _MEM_TYPE_FAST_ U8 u8_cluster_status; 00365 00366 fs_g_status = FS_ERR_FS; // By default system error 00367 00368 if( Is_fat32 00369 && (FS_CLUST_ACT_CLR == opt_action) ) 00370 { 00371 #if (FSFEATURE_WRITE_COMPLET == (FS_LEVEL_FEATURES & FSFEATURE_WRITE_COMPLET) ) 00372 // Clear free space information storage in FAT32 00373 if( !fat_write_fat32_FSInfo( 0xFFFFFFFF )) 00374 return FALSE; 00375 #else 00376 return FALSE; 00377 #endif 00378 } 00379 00380 if ( 0 == fs_g_seg.u32_addr ) 00381 { 00382 // Cluster list of root directory 00383 if( FS_CLUST_ACT_CLR == opt_action ) 00384 return FALSE; // Impossible to erase ROOT DIR 00385 00386 if ( Is_fat12 || Is_fat16 ) 00387 { 00388 // For a FAT 12 & 16, the root dir isn't a cluster list 00389 // Check the position 00390 if ( fs_g_seg.u32_size_or_pos < fs_g_nav.rootdir.seg.u16_size ) 00391 { 00392 // Compute the start address and the size 00393 fs_g_seg.u32_addr = fs_g_nav.u32_ptr_fat + fs_g_nav.rootdir.seg.u16_pos + fs_g_seg.u32_size_or_pos; 00394 fs_g_seg.u32_size_or_pos = fs_g_nav.rootdir.seg.u16_size - fs_g_seg.u32_size_or_pos; 00395 return TRUE; 00396 } else { 00397 fs_g_status = FS_ERR_OUT_LIST; 00398 return FALSE; // Position outside the root area 00399 } 00400 } 00401 if ( Is_fat32 ) 00402 { 00403 // For FAT 32, the root is a cluster list and the first cluster is reading during the mount 00404 fs_g_cluster.u32_pos = fs_g_nav.rootdir.u32_cluster; 00405 } 00406 } else { 00407 // It is the first cluster of a cluster list 00408 fs_g_cluster.u32_pos = fs_g_seg.u32_addr; 00409 } 00410 00411 // Management of cluster list caches 00412 if( FS_CLUST_ACT_CLR != opt_action ) 00413 { 00414 if( fat_cache_clusterlist_update_read( b_for_file ) ) 00415 return TRUE; // Segment found in cache 00416 // Segment not found & cache ready to update 00417 }else{ 00418 fat_cache_clusterlist_reset(); // It is a clear action then clear cluster list caches 00419 #if (FS_LEVEL_FEATURES > FSFEATURE_READ) 00420 fat_clear_info_fat_mod(); // Init cache on fat modification range 00421 #endif // FS_LEVEL_FEATURES 00422 } 00423 00424 // Init loop with a start segment no found 00425 MSB0( fs_g_seg.u32_addr ) = 0xFF; 00426 00427 //**** Loop to read the cluster list 00428 while ( 1 ) 00429 { 00430 if ( fs_g_seg.u32_size_or_pos < fs_g_nav.u8_BPB_SecPerClus ) 00431 { 00432 // The segment starts in this cluster 00433 // Compute the sector address of this cluster 00434 fs_g_seg.u32_addr = ((fs_g_cluster.u32_pos - 2) * fs_g_nav.u8_BPB_SecPerClus) 00435 + fs_g_nav.u32_ptr_fat + fs_g_nav.u32_offset_data + fs_g_seg.u32_size_or_pos; 00436 00437 if ( FS_CLUST_ACT_ONE == opt_action ) 00438 { 00439 // Compute the maximum size 00440 fs_g_seg.u32_size_or_pos = fs_g_nav.u8_BPB_SecPerClus-fs_g_seg.u32_size_or_pos; 00441 fat_cache_clusterlist_update_finish(); 00442 // Send a size of one sector 00443 fs_g_seg.u32_size_or_pos = 1; 00444 return TRUE; 00445 } 00446 // Update the segment size 00447 fs_g_seg.u32_size_or_pos = fs_g_nav.u8_BPB_SecPerClus - LSB0( fs_g_seg.u32_size_or_pos ); 00448 00449 // Take time, during read cluster list on FAT 16 & 32 00450 if( (FS_CLUST_ACT_SEG == opt_action) 00451 && (!Is_fat12) ) 00452 { 00453 // Init loop with the current cluster 00454 u32_tmp = fs_g_cluster.u32_pos; 00455 if( !fat_cluster_val( FS_CLUST_VAL_READ )) 00456 return FALSE; 00457 // Read cluster list, while this one is continue 00458 while(1) 00459 { 00460 if ( (++fs_g_cluster.u32_pos) != fs_g_cluster.u32_val ) 00461 { 00462 fs_g_cluster.u32_pos--; // Recompute previous value 00463 u32_tmp = fs_g_cluster.u32_pos - u32_tmp; // Compute the size of cluster list 00464 fs_g_seg.u32_size_or_pos += u32_tmp * fs_g_nav.u8_BPB_SecPerClus; 00465 break; 00466 } 00467 if( !fat_cluster_readnext() ) 00468 return FALSE; 00469 } 00470 } 00471 } 00472 // Get the cluster value 00473 if( !fat_cluster_val( FS_CLUST_VAL_READ )) 00474 return FALSE; 00475 00476 // Read and check the status of the new cluster 00477 u8_cluster_status = fat_checkcluster(); 00478 if (FS_CLUS_BAD == u8_cluster_status) 00479 return FALSE; // error, end of cluster list 00480 00481 if (0xFF == MSB0(fs_g_seg.u32_addr)) 00482 { 00483 // The beginning of the segment isn't found 00484 if (FS_CLUS_END == u8_cluster_status) 00485 { 00486 u32_tmp = fs_g_seg.u32_size_or_pos; // Save number of sector remaining 00487 00488 // Compute the sector address of this last cluster to take time during a futur request with the same cluster list 00489 fs_g_cache_clusterlist[fs_g_u8_current_cache].u32_start -= fs_g_seg.u32_size_or_pos; 00490 fs_g_seg.u32_addr = ((fs_g_cluster.u32_pos - 2) * fs_g_nav.u8_BPB_SecPerClus) 00491 + fs_g_nav.u32_ptr_fat + fs_g_nav.u32_offset_data; 00492 fs_g_seg.u32_size_or_pos = fs_g_nav.u8_BPB_SecPerClus; 00493 if (FS_CLUST_ACT_CLR != opt_action) 00494 fat_cache_clusterlist_update_finish(); 00495 00496 // The position is outside the cluster list 00497 fs_g_seg.u32_addr = fs_g_cluster.u32_pos; // Send the last cluster value 00498 fs_g_seg.u32_size_or_pos = u32_tmp; // Restore number of sector remaining 00499 fs_g_status = FS_ERR_OUT_LIST; 00500 return FALSE; 00501 } 00502 // Good cluster then continue 00503 fs_g_seg.u32_size_or_pos -= fs_g_nav.u8_BPB_SecPerClus; 00504 #if (FS_LEVEL_FEATURES > FSFEATURE_READ) 00505 if (FS_CLUST_ACT_CLR == opt_action) 00506 { 00507 if( fs_g_seg.u32_size_or_pos == 0) 00508 { 00509 // At cluster position, set the flag end of cluster list 00510 fs_g_seg.u32_addr = fs_g_cluster.u32_val; // Save the next cluster 00511 fs_g_cluster.u32_val = FS_CLUST_VAL_EOL; 00512 if( !fat_cluster_val( FS_CLUST_VAL_WRITE )) 00513 return FALSE; 00514 fs_g_cluster.u32_val = fs_g_seg.u32_addr; // Resotre the next cluster 00515 // !!!! It isn't necessary to reinit MSB0( fs_g_seg.u32_addr ) to 0xFF, 00516 // !!!! fs_g_seg.u32_addr will be modified at the beginning of main loop 00517 } 00518 } 00519 #endif // FS_LEVEL_FEATURES 00520 } 00521 else 00522 { 00523 // The beginning of segment is found 00524 if (FS_CLUST_ACT_SEG == opt_action) 00525 { 00526 if ( (fs_g_cluster.u32_pos+1) != fs_g_cluster.u32_val ) 00527 { 00528 // The cluster is not a continue cluster or a invalid cluster 00529 fat_cache_clusterlist_update_finish(); 00530 return TRUE; // End of segment 00531 } 00532 } 00533 #if (FS_LEVEL_FEATURES > FSFEATURE_READ) 00534 if (FS_CLUST_ACT_CLR == opt_action) 00535 { 00536 //** Clear cluster position 00537 fs_g_seg.u32_addr = fs_g_cluster.u32_val; // Save the next cluster 00538 fs_g_cluster.u32_val = 0; // by default free cluster 00539 // If it is the first cluster (fs_g_seg.u32_size_or_pos <= fs_g_nav.u8_BPB_SecPerClus) 00540 // and doesn't start at the beginning of cluster (fs_g_seg.u32_size_or_pos != fs_g_nav.u8_BPB_SecPerClus) 00541 if (fs_g_seg.u32_size_or_pos < fs_g_nav.u8_BPB_SecPerClus) 00542 { 00543 fs_g_cluster.u32_val = FS_CLUST_VAL_EOL; // End of cluster list allocated 00544 } 00545 if( !fat_cluster_val( FS_CLUST_VAL_WRITE )) 00546 return FALSE; 00547 fs_g_cluster.u32_val = fs_g_seg.u32_addr; // Resotre the next cluster 00548 // !!!! It isn't necessary to reinit MSB0( fs_g_seg.u32_addr ) at 0xFF, 00549 // !!!! because it isn't possible that MSB0( fs_g_cluster.val ) = 0xFF. 00550 } 00551 #endif // FS_LEVEL_FEATURES 00552 00553 // Check the end of cluster list 00554 if (FS_CLUS_END == u8_cluster_status) 00555 { 00556 #if (FS_LEVEL_FEATURES > FSFEATURE_READ) 00557 if (FS_CLUST_ACT_CLR == opt_action) 00558 { 00559 return fat_update_fat2(); 00560 } 00561 #endif // FS_LEVEL_FEATURES 00562 fat_cache_clusterlist_update_finish(); 00563 return TRUE; // End of segment 00564 } 00565 00566 // Update the segment size 00567 fs_g_seg.u32_size_or_pos += fs_g_nav.u8_BPB_SecPerClus; 00568 } 00569 // HERE, Continue to read the cluster list 00570 // The next cluster is the value of previous cluster 00571 fs_g_cluster.u32_pos = fs_g_cluster.u32_val; 00572 } // End of main loop 00573 }
| void fat_cache_clusterlist_reset | ( | void | ) |
This function resets the cluster list caches.
Definition at line 878 of file fat.c.
References Fs_clusterlist_cache::b_cache_file, FALSE, fs_g_cache_clusterlist, fs_g_u8_current_cache, FS_NB_CACHE_CLUSLIST, TRUE, Fs_clusterlist_cache::u8_level_use, and Fs_clusterlist_cache::u8_lun.
00879 { 00880 U8 u8_i; 00881 fs_g_u8_current_cache=0; 00882 for( u8_i=0; u8_i<(FS_NB_CACHE_CLUSLIST*2); u8_i++ ) 00883 { 00884 // The cache list is splited in two cache (file cluster list and directory cluster list) 00885 fs_g_cache_clusterlist[u8_i].b_cache_file = (u8_i<FS_NB_CACHE_CLUSLIST)?TRUE:FALSE; 00886 fs_g_cache_clusterlist[u8_i].u8_lun = 0xFF; 00887 fs_g_cache_clusterlist[u8_i].u8_level_use = 0xFF; 00888 } 00889 }
This function returns or modifys a cluster value in FAT.
| b_mode | FALSE, to read a cluster value TRUE, to write a cluster value |
TRUE otherwise
//! Global variables used //! IN : //! fs_g_cluster.u32_pos cluster number to read or write //! fs_g_cluster.u32_val value to write //! OUT: //! fs_g_cluster.u32_val value readed //! fs_g_u16_pos_fat position in FAT of the cluster to read or write //! value init in case of the fat_cluster_readnext() routine is used after //!
Definition at line 600 of file fat.c.
References _MEM_TYPE_FAST_, FALSE, fat_cache_mark_sector_as_dirty(), fat_cache_read_sector(), FS_CACHE_SIZE, FS_ERR_COMMAND, fs_g_cluster, fs_g_nav, fs_g_sector, fs_g_status, fs_g_u16_pos_fat, fs_gu32_addrsector, Is_fat12, Is_fat16, Is_fat32, LSB0, LSB1, LSB2, LSB3, MSB, TRUE, Fs_cluster::u32_pos, Fs_management::u32_ptr_fat, Fs_cluster::u32_val, u8_data3, and u8_data4.
00601 { 00602 _MEM_TYPE_FAST_ U16 u16_offset_fat; 00603 _MEM_TYPE_FAST_ U8 u8_data1, u8_data2; 00604 #define u8_data3 (LSB(u16_offset_fat)) // Manual overlay 00605 #define u8_data4 (MSB(u16_offset_fat)) // Manual overlay 00606 _MEM_TYPE_FAST_ PTR_CACHE u8_ptr_cluster; 00607 00608 //**** Compute the cluster position in FAT (sector address & position in sector) 00609 if ( Is_fat32 ) 00610 { 00611 // FAT 32 00612 // Optimization of -> u16_offset_fat = fs_g_cluster.pos * 4 / FS_CACHE_SIZE; 00613 // Optimization of -> u16_offset_fat = fs_g_cluster.pos / 128 00614 u16_offset_fat = fs_g_cluster.u32_pos >> (8-1); 00615 00616 // Optimization of -> fs_g_u16_pos_fat = (fs_g_cluster.u32_pos * 4) % FS_CACHE_SIZE; 00617 // Optimization of -> fs_g_u16_pos_fat = (fs_g_cluster.u32_pos % 128) * 4 00618 fs_g_u16_pos_fat = ((U16)(LSB0(fs_g_cluster.u32_pos) & 0x7F))<< 2; 00619 } 00620 else if ( Is_fat16 ) 00621 { 00622 // FAT 16 00623 // Optimization of -> u16_offset_fat = fs_g_cluster.u32_pos * 2 / FS_CACHE_SIZE = fs_g_cluster.u32_pos / 256; 00624 u16_offset_fat = LSB1(fs_g_cluster.u32_pos); 00625 // Optimization of -> fs_g_u16_pos_fat = (fs_g_cluster.u32_pos * 2) % FS_CACHE_SIZE; 00626 // Optimization of -> fs_g_u16_pos_fat = (fs_g_cluster.u32_pos % 256) * 2 00627 fs_g_u16_pos_fat = ((U16)LSB0(fs_g_cluster.u32_pos)) <<1; 00628 } 00629 else if ( Is_fat12 ) 00630 { 00631 // FAT 12 00632 // Optimization of -> fs_g_u16_pos_fat = fs_g_cluster.u32_pos + (fs_g_cluster.u32_pos/ 2) 00633 fs_g_u16_pos_fat = (U16)fs_g_cluster.u32_pos + ((U16)fs_g_cluster.u32_pos >>1); 00634 // Optimization of -> u16_offset_fat = fs_g_cluster.u32_pos / FS_CACHE_SIZE 00635 u16_offset_fat = MSB(fs_g_u16_pos_fat) >> 1; 00636 // Optimization of -> fs_g_u16_pos_fat = fs_g_u16_pos_fat % FS_CACHE_SIZE 00637 MSB( fs_g_u16_pos_fat ) &= 0x01; 00638 } 00639 00640 #if (FS_LEVEL_FEATURES > FSFEATURE_READ) 00641 if (b_mode) 00642 { 00643 // Update information about FAT modification 00644 if( fs_g_u16_first_mod_fat > u16_offset_fat ) 00645 { 00646 fs_g_u16_first_mod_fat = u16_offset_fat; 00647 } 00648 if( fs_g_u16_last_mod_fat < u16_offset_fat ) 00649 { 00650 fs_g_u16_last_mod_fat = u16_offset_fat; 00651 } 00652 if ( Is_fat12 ) 00653 { // A cluster may be stored on two sectors 00654 if( fs_g_u16_pos_fat == (FS_CACHE_SIZE-1) ) 00655 { // Count the next FAT sector 00656 if( fs_g_u16_last_mod_fat < (u16_offset_fat+1) ) 00657 { 00658 fs_g_u16_last_mod_fat = (u16_offset_fat+1); 00659 } 00660 } 00661 } 00662 } 00663 #endif // FS_LEVEL_FEATURES 00664 00665 //**** Read cluster sector in FAT 00666 fs_gu32_addrsector = fs_g_nav.u32_ptr_fat + u16_offset_fat; // Computed logical sector address 00667 if( !fat_cache_read_sector( TRUE )) 00668 return FALSE; 00669 00670 // Read cluster information 00671 u8_ptr_cluster = &fs_g_sector[fs_g_u16_pos_fat]; 00672 u8_data1 = u8_ptr_cluster[0]; 00673 // Remark: if (fs_g_u16_pos_fat+1)=512 then it isn't a mistake, because this value will be erase in next lines 00674 u8_data2 = u8_ptr_cluster[1]; 00675 u8_data3 = u8_ptr_cluster[2]; 00676 u8_data4 = u8_ptr_cluster[3]; 00677 00678 if ( Is_fat12 ) 00679 { // A cluster may be stored on two sectors 00680 if( fs_g_u16_pos_fat == (FS_CACHE_SIZE-1) ) 00681 { // Go to next sector 00682 fs_gu32_addrsector++; 00683 if( !fat_cache_read_sector( TRUE )) 00684 return FALSE; 00685 u8_data2 = fs_g_sector[0]; 00686 } 00687 } 00688 00689 if (FALSE == b_mode) 00690 { 00691 //**** Read the cluster value 00692 LSB0( fs_g_cluster.u32_val ) = u8_data1; // FAT 12,16,32 00693 LSB1( fs_g_cluster.u32_val ) = u8_data2; // FAT 12,16,32 00694 00695 if ( Is_fat32 ) 00696 { // FAT 32 00697 LSB2( fs_g_cluster.u32_val ) = u8_data3; 00698 LSB3( fs_g_cluster.u32_val ) = u8_data4 & 0x0F; // The high 4 bits are reserved 00699 } 00700 else 00701 { // FAT 12 & 16 don't use the high bytes 00702 LSB2( fs_g_cluster.u32_val ) = 0; 00703 LSB3( fs_g_cluster.u32_val ) = 0; 00704 00705 // FAT 12 translate 16bits value to 12bits 00706 if ( Is_fat12 ) 00707 { 00708 if ( 0x01 & LSB0(fs_g_cluster.u32_pos) ) 00709 { // Readed cluster is ODD 00710 LSB0( fs_g_cluster.u32_val ) = (LSB1( fs_g_cluster.u32_val ) <<4 ) + (LSB0( fs_g_cluster.u32_val ) >>4 ); 00711 LSB1( fs_g_cluster.u32_val ) = LSB1( fs_g_cluster.u32_val ) >>4 ; 00712 } 00713 else 00714 { // Readed cluster is EVEN 00715 LSB1( fs_g_cluster.u32_val ) &= 0x0F; 00716 } 00717 } 00718 } 00719 } else { 00720 #if (FS_LEVEL_FEATURES > FSFEATURE_READ) 00721 //**** Write the cluster value 00722 if ( Is_fat12 ) 00723 { 00724 // FAT 12, translate cluster value 00725 if ( 0x01 & LSB0(fs_g_cluster.u32_pos) ) 00726 { // Cluster writing is ODD 00727 u8_data1 = (u8_data1 & 0x0F) + (LSB0( fs_g_cluster.u32_val )<<4); 00728 u8_data2 = (LSB1( fs_g_cluster.u32_val )<<4) + (LSB0( fs_g_cluster.u32_val )>>4) ; 00729 } else { 00730 // Cluster writing is EVEN 00731 u8_data1 = LSB0( fs_g_cluster.u32_val ); 00732 u8_data2 = (u8_data2 & 0xF0) + (LSB1( fs_g_cluster.u32_val ) & 0x0F) ; 00733 } 00734 00735 // A cluster may be stored on two sectors 00736 if( fs_g_u16_pos_fat == (FS_CACHE_SIZE-1) ) 00737 { 00738 fs_g_sector[0] = u8_data2; 00739 fat_cache_mark_sector_as_dirty(); 00740 // Go to previous sector 00741 fs_gu32_addrsector--; 00742 if( !fat_cache_read_sector( TRUE )) 00743 return FALSE; 00744 // Modify the previous sector 00745 fs_g_sector[ FS_CACHE_SIZE-1 ] = u8_data1; 00746 fat_cache_mark_sector_as_dirty(); 00747 return TRUE; 00748 } 00749 } 00750 else 00751 { 00752 // FAT 16 & 32 00753 u8_data1 = LSB0( fs_g_cluster.u32_val ); 00754 u8_data2 = LSB1( fs_g_cluster.u32_val ); 00755 if ( Is_fat32 ) 00756 { // FAT 32 00757 u8_ptr_cluster[2] = LSB2( fs_g_cluster.u32_val ); 00758 u8_ptr_cluster[3] = LSB3( fs_g_cluster.u32_val ) + (u8_data4 & 0xF0); // The high 4 bits are reserved 00759 } 00760 } 00761 // Here for FAT 32, 16 & 12 (only if the cluster values are in the same sector) 00762 u8_ptr_cluster[0] = u8_data1; 00763 u8_ptr_cluster[1] = u8_data2; 00764 fat_cache_mark_sector_as_dirty(); 00765 #else 00766 fs_g_status = FS_ERR_COMMAND; 00767 return FALSE; 00768 #endif // FS_LEVEL_FEATURES 00769 } 00770 00771 return TRUE; 00772 #undef u8_data3 // end of Manual overlay 00773 #undef u8_data4 // end of Manual overlay 00774 }
| Bool fat_cluster_readnext | ( | void | ) |
This function is optimized to read a continue cluster list on FAT16 and FAT32.
Read global value "fs_g_status" in case of error : FS_ERR_HW Hardware driver error FS_LUN_WP Drive is read only
TRUE otherwise
//! Global variables used //! IN : //! fs_g_u16_pos_fat previous cluster position in FAT //! OUT: //! fs_g_u16_pos_fat readed cluster position in FAT //! fs_g_cluster.u32_val value of cluster readed //!
Definition at line 795 of file fat.c.
References FALSE, fat_cache_read_sector(), FS_CACHE_SIZE, fs_g_cluster, fs_g_sector, fs_g_u16_pos_fat, fs_gu32_addrsector, Is_fat32, LSB0, LSB1, LSB2, LSB3, TRUE, and Fs_cluster::u32_val.
00796 { 00797 // Compute the next cluster position in FAT 00798 if ( Is_fat32 ) 00799 { 00800 fs_g_u16_pos_fat += 4; 00801 }else{ 00802 // Is_fat16 00803 fs_g_u16_pos_fat += 2; 00804 } 00805 00806 // Check if next cluster is in internal cache 00807 if( FS_CACHE_SIZE == fs_g_u16_pos_fat ) 00808 { 00809 // Update cache 00810 fs_g_u16_pos_fat = 0; 00811 fs_gu32_addrsector++; 00812 if( !fat_cache_read_sector( TRUE )) 00813 return FALSE; 00814 } 00815 00816 //**** Read the cluster value 00817 LSB0( fs_g_cluster.u32_val ) = fs_g_sector[fs_g_u16_pos_fat+0]; // FAT 16,32 00818 LSB1( fs_g_cluster.u32_val ) = fs_g_sector[fs_g_u16_pos_fat+1]; // FAT 16,32 00819 00820 if ( Is_fat32 ) 00821 { // FAT 32 00822 LSB2( fs_g_cluster.u32_val ) = fs_g_sector[fs_g_u16_pos_fat+2]; 00823 LSB3( fs_g_cluster.u32_val ) = fs_g_sector[fs_g_u16_pos_fat+3]; 00824 } 00825 return TRUE; 00826 }
| U8 fat_checkcluster | ( | void | ) |
This function checks the cluster value.
//! Global variable used //! IN : //! fs_g_cluster.u32_val value to check //!
Definition at line 842 of file fat.c.
References FS_CLUS_BAD, FS_CLUS_END, FS_CLUS_OK, fs_g_cluster, Is_fat12, Is_fat16, Is_fat32, and Fs_cluster::u32_val.
00843 { 00844 if ( !fs_g_cluster.u32_val ) 00845 return FS_CLUS_BAD; 00846 00847 // Cluster bad if (FAT12 > 0x0FF6) (FAT16 > 0xFFF6) (FAT32 > 0x0FFFFFF6) or cluster null 00848 if ( Is_fat32 ) 00849 { 00850 if (fs_g_cluster.u32_val <= 0x0FFFFFF6) 00851 return FS_CLUS_OK; 00852 else if (fs_g_cluster.u32_val == 0x0FFFFFFF) 00853 return FS_CLUS_END; 00854 } 00855 else if ( Is_fat16 ) 00856 { 00857 if (fs_g_cluster.u32_val <= 0xFFF6) 00858 return FS_CLUS_OK; 00859 else if (fs_g_cluster.u32_val == 0xFFFF) 00860 return FS_CLUS_END; 00861 } 00862 else if ( Is_fat12 ) 00863 { 00864 if (fs_g_cluster.u32_val <= 0x0FF6) 00865 return FS_CLUS_OK; 00866 else if (fs_g_cluster.u32_val == 0x0FFF) 00867 return FS_CLUS_END; 00868 } 00869 00870 return FS_CLUS_BAD; 00871 }
| Bool fat_allocfreespace | ( | void | ) |
| void fat_clear_info_fat_mod | ( | void | ) |
| Bool fat_clear_cluster | ( | void | ) |
| Bool fat_update_fat2 | ( | void | ) |
This function gets or clears a cluster list at the current position in the selected file.
| mode | Choose action FS_CLUST_ACT_SEG Get memory segment corresponding at the position in selected file FS_CLUST_ACT_ONE Store in internal cache the sector corresponding at the position in selected file FS_CLUST_ACT_CLR Clear the cluster list corresponding at the position in selected file |
TRUE otherwise
//! Global variable used //! IN : //! fs_g_nav_entry.u32_cluster First cluster of selected file //! fs_g_nav_entry.u32_pos_in_file Position in file (unit byte) //!
Definition at line 1031 of file fat.c.
References FALSE, fat_cache_read_sector(), fat_cluster_list(), FS_512B_MASK, FS_512B_SHIFT_BIT, FS_CLUST_ACT_CLR, FS_CLUST_ACT_ONE, FS_CLUST_ACT_SEG, FS_ERR_OUT_LIST, fs_g_nav, fs_g_nav_entry, fs_g_sectorcache, fs_g_seg, fs_g_status, fs_gu32_addrsector, TRUE, Fs_segment::u32_addr, Fs_management_entry::u32_cluster, Fs_sector_cache::u32_clusterlist_pos, Fs_sector_cache::u32_clusterlist_start, Fs_management_entry::u32_pos_in_file, Fs_segment::u32_size_or_pos, Fs_management::u8_lun, and Fs_sector_cache::u8_lun.
01032 { 01033 U32 u32_sector_pos; 01034 01035 // Compute sector position 01036 u32_sector_pos = fs_g_nav_entry.u32_pos_in_file >> FS_512B_SHIFT_BIT; 01037 01038 if(FS_CLUST_ACT_ONE == mode) 01039 { 01040 if( (fs_g_sectorcache.u8_lun == fs_g_nav.u8_lun ) 01041 && (fs_g_sectorcache.u32_clusterlist_start == fs_g_nav_entry.u32_cluster ) 01042 && (fs_g_sectorcache.u32_clusterlist_pos == u32_sector_pos ) ) 01043 { 01044 return TRUE; // The internal cache contains the sector ascked 01045 } 01046 } 01047 else 01048 { 01049 if( FS_CLUST_ACT_CLR == mode ) 01050 { 01051 // Clear cluster list 01052 if( 0 == fs_g_nav_entry.u32_cluster ) 01053 return TRUE; // No cluster list is linked with the file, then no clear is necessary 01054 01055 if(0 != (fs_g_nav_entry.u32_pos_in_file & FS_512B_MASK) ) 01056 { 01057 // The actual sector is used, then start clear on the next sector 01058 u32_sector_pos++; 01059 } 01060 } 01061 } 01062 01063 // Get the segment which start at the current position 01064 fs_g_seg.u32_addr = fs_g_nav_entry.u32_cluster; 01065 fs_g_seg.u32_size_or_pos = u32_sector_pos; 01066 if( FS_CLUST_ACT_ONE != mode ) 01067 { 01068 if( fat_cluster_list( mode, TRUE ) ) 01069 return TRUE; // Get or clear segment OK 01070 } 01071 else 01072 { 01073 if( fat_cluster_list( FS_CLUST_ACT_SEG, TRUE ) ) // Read all segment 01074 { 01075 // Read the sector corresponding at the position file (= first sector of segment) 01076 fs_gu32_addrsector = fs_g_seg.u32_addr ; 01077 if( fat_cache_read_sector( TRUE ) ) 01078 { 01079 fs_g_sectorcache.u32_clusterlist_start = fs_g_nav_entry.u32_cluster; 01080 fs_g_sectorcache.u32_clusterlist_pos = u32_sector_pos; 01081 return TRUE; 01082 } 01083 } 01084 } 01085 if( (FS_CLUST_ACT_CLR == mode ) 01086 && (FS_ERR_OUT_LIST == fs_g_status) ) 01087 { 01088 // It is possible to clear nothing 01089 return TRUE; 01090 } 01091 return FALSE; 01092 }
| Bool fat_read_dir | ( | void | ) |
This function fill the internal cache with a sector from current directory.
TRUE otherwise
//! Global variable used //! IN : //! fs_g_nav.u32_cluster_sel_dir First cluster of current directory //! fs_g_nav_fast.u16_entry_pos_sel_file Position in directory (unit entry) //!
Definition at line 1191 of file fat.c.
References FALSE, fat_cache_read_sector(), fat_cluster_list(), FS_512B_SHIFT_BIT, FS_CLUST_ACT_ONE, fs_g_nav, fs_g_nav_fast, fs_g_sectorcache, fs_g_seg, fs_gu32_addrsector, FS_SHIFT_B_TO_FILE_ENTRY, TRUE, Fs_management_fast::u16_entry_pos_sel_file, Fs_segment::u32_addr, Fs_management::u32_cluster_sel_dir, Fs_sector_cache::u32_clusterlist_pos, Fs_sector_cache::u32_clusterlist_start, Fs_segment::u32_size_or_pos, Fs_management::u8_lun, and Fs_sector_cache::u8_lun.
01192 { 01193 U32 u32_cluster_pos; 01194 01195 // Compute the cluster list position corresponding of the current entry 01196 u32_cluster_pos = fs_g_nav_fast.u16_entry_pos_sel_file >> (FS_512B_SHIFT_BIT - FS_SHIFT_B_TO_FILE_ENTRY); 01197 01198 if( (fs_g_sectorcache.u8_lun == fs_g_nav.u8_lun ) 01199 && (fs_g_sectorcache.u32_clusterlist_start == fs_g_nav.u32_cluster_sel_dir ) 01200 && (fs_g_sectorcache.u32_clusterlist_pos == u32_cluster_pos ) ) 01201 { 01202 return TRUE; // The internal cache contains the sector ascked 01203 } 01204 01205 // Get sector address corresponding at cluster list position 01206 fs_g_seg.u32_addr = fs_g_nav.u32_cluster_sel_dir; 01207 fs_g_seg.u32_size_or_pos = u32_cluster_pos; 01208 if( fat_cluster_list( FS_CLUST_ACT_ONE, FALSE ) ) 01209 { 01210 // Read the sector 01211 fs_gu32_addrsector = fs_g_seg.u32_addr; 01212 if( fat_cache_read_sector( TRUE ) ) 01213 { 01214 // Update information about internal sector cache 01215 fs_g_sectorcache.u32_clusterlist_start = fs_g_nav.u32_cluster_sel_dir; 01216 fs_g_sectorcache.u32_clusterlist_pos = u32_cluster_pos; 01217 return TRUE; 01218 } 01219 } 01220 return FALSE; 01221 }
| Bool fat_initialize_dir | ( | void | ) |
This function checks the entry.
| b_type | entry type to compare (FS_FILE or FS_DIR) |
FALSE, otherwise
//! Global variable used //! IN : //! fs_g_sector The directory sector corresponding at the current position //! fs_g_nav_fast.u16_entry_pos_sel_file Position in directory of the entry file (unit entry) //!
Definition at line 1239 of file fat.c.
References FALSE, fat_get_ptr_entry(), FS_ATTR_DIRECTORY, FS_ATTR_VOLUME_ID, FS_DIR, FS_ENTRY_DEL, FS_ENTRY_END, FS_ERR_ENTRY_BAD, FS_ERR_ENTRY_EMPTY, FS_FILE, and fs_g_status.
01240 { 01241 PTR_CACHE u8_ptr_entry; 01242 U8 u8_first_byte, u8_seconde_byte; 01243 U8 u8_attribut; 01244 01245 u8_ptr_entry = fat_get_ptr_entry(); 01246 01247 u8_first_byte = u8_ptr_entry[0]; 01248 if ( FS_ENTRY_END == u8_first_byte ) 01249 { 01250 fs_g_status = FS_ERR_ENTRY_EMPTY; // end of directory 01251 return FALSE; 01252 } 01253 fs_g_status = FS_ERR_ENTRY_BAD; // by default BAD ENTRY 01254 if ( FS_ENTRY_DEL == u8_first_byte ) { return FALSE; } // entry deleted 01255 if ( '.' == u8_first_byte ) { return FALSE; } // current dir "." 01256 u8_seconde_byte = u8_ptr_entry[1]; 01257 if ( ('.' == u8_first_byte) 01258 && ('.' == u8_seconde_byte) ) { return FALSE; } // current dir ".." 01259 01260 // Check attribut 01261 u8_attribut = u8_ptr_entry[11]; 01262 if ( FS_ATTR_VOLUME_ID & u8_attribut ) { return FALSE; } // volume id 01263 // Optimization, this line isn't necessary because the next test control this case 01264 // if ( FS_ATTR_LFN_ENTRY == *u8_ptr_entry) { return FALSE; } // long file name 01265 01266 // Check entry type 01267 if( FS_ATTR_DIRECTORY & u8_attribut ) 01268 { 01269 return (FS_DIR == b_type); 01270 }else{ 01271 return (FS_FILE == b_type); 01272 } 01273 }
This function checks the file extension.
| sz_filter | extension filter is a ASCII string (ex: "mp3,w*" ) |
FALSE, otherwise
//! Global variable used //! IN : //! fs_g_sector The directory sector corresponding at the current position //! fs_g_nav_fast.u16_entry_pos_sel_file Position in directory of the entry file (unit entry) //!
Definition at line 1290 of file fat.c.
References FALSE, fat_get_ptr_entry(), and TRUE.
01291 { 01292 PTR_CACHE u8_ptr_entry; 01293 U8 u8_i, u8_filter_char, u8_entry_char; 01294 01295 u8_ptr_entry = fat_get_ptr_entry(); 01296 01297 // Compare the extension with filter 01298 for( u8_i=0 ; u8_i<3 ; u8_i++) 01299 { 01300 u8_filter_char = *sz_filter; 01301 if ('*' == u8_filter_char) 01302 break; // All extension is good 01303 01304 u8_entry_char = u8_ptr_entry[8+u8_i]; 01305 01306 // Compare the extension filter to extension file (this one ignore the case) 01307 if( (u8_filter_char!= u8_entry_char ) 01308 && (u8_filter_char!= (u8_entry_char+('a'-'A'))) ) 01309 { 01310 if ( (',' == u8_filter_char) 01311 || ( 0 == u8_filter_char) ) 01312 { 01313 // It is the end of filter 01314 if (' ' == u8_entry_char) 01315 break; // it is the end of extension file -> extension good 01316 } 01317 // here, bad extension 01318 01319 // Search the next filter 01320 while( ',' != u8_filter_char ) 01321 { 01322 if (0 == u8_filter_char) 01323 { 01324 return FALSE; // it is the last filter 01325 } 01326 sz_filter++; 01327 u8_filter_char = *sz_filter; 01328 } 01329 u8_i = 0xFF; // restart loop compare 01330 } 01331 sz_filter++; // go to next char of filter 01332 } 01333 01334 return TRUE; // It is a good extension 01335 }
| void fat_get_entry_info | ( | void | ) |
This function reads information about selected file.
//! Global variable used //! IN : //! fs_g_sector The directory sector corresponding at the current position //! fs_g_nav_fast.u16_entry_pos_sel_file Position in directory of the entry file (unit entry) //! OUT: //! fs_g_nav_entry. u32_cluster, u8_attr, u32_size //!
Definition at line 1349 of file fat.c.
References fat_get_ptr_entry(), fs_g_nav_entry, LSB0, LSB1, LSB2, LSB3, Fs_management_entry::u32_cluster, Fs_management_entry::u32_size, and Fs_management_entry::u8_attr.
01350 { 01351 PTR_CACHE ptr_entry; 01352 01353 ptr_entry = fat_get_ptr_entry(); 01354 01355 // Get attribut 01356 ptr_entry+= 11; 01357 fs_g_nav_entry.u8_attr = ptr_entry[0]; 01358 01359 // Get the first cluster of the file cluster list 01360 ptr_entry += (20-11); 01361 LSB2(fs_g_nav_entry.u32_cluster) = ptr_entry[0]; 01362 LSB3(fs_g_nav_entry.u32_cluster) = ptr_entry[1]; 01363 ptr_entry += (26-20); 01364 LSB0(fs_g_nav_entry.u32_cluster) = ptr_entry[0]; 01365 LSB1(fs_g_nav_entry.u32_cluster) = ptr_entry[1]; 01366 01367 // Get the size of file 01368 ptr_entry += (28-26); 01369 LSB0(fs_g_nav_entry.u32_size) = ptr_entry[0]; 01370 LSB1(fs_g_nav_entry.u32_size) = ptr_entry[1]; 01371 LSB2(fs_g_nav_entry.u32_size) = ptr_entry[2]; 01372 LSB3(fs_g_nav_entry.u32_size) = ptr_entry[3]; 01373 }
| Bool fat_entry_is_dir | ( | void | ) |
This function checks if the entry file is a directory.
FALSE, otherwise
Definition at line 1381 of file fat.c.
References FS_ATTR_DIRECTORY, FS_ERR_NO_DIR, fs_g_nav_entry, fs_g_status, and Fs_management_entry::u8_attr.
01382 { 01383 fs_g_status = FS_ERR_NO_DIR; 01384 return (FS_ATTR_DIRECTORY & fs_g_nav_entry.u8_attr); 01385 }
| void fat_clear_entry_info_and_ptr | ( | void | ) |
This function resets the selection pointers.
Definition at line 1390 of file fat.c.
References Fs_management::b_mode_nav, Fs_management::b_mode_nav_single, Fat_file_close, FS_DIR, fs_g_nav, fs_g_nav_entry, fs_g_nav_fast, FS_NO_SEL, Fs_management_fast::u16_entry_pos_sel_file, Fs_management::u16_pos_sel_file, Fs_management_entry::u32_cluster, Fs_management_entry::u32_size, and Fs_management_entry::u8_attr.
01391 { 01392 fs_g_nav_fast.u16_entry_pos_sel_file= FS_NO_SEL; 01393 fs_g_nav.u16_pos_sel_file = FS_NO_SEL; 01394 if( !fs_g_nav.b_mode_nav_single ) 01395 { 01396 fs_g_nav.b_mode_nav = FS_DIR; 01397 } 01398 fs_g_nav_entry.u8_attr = 0; 01399 fs_g_nav_entry.u32_cluster = 0; 01400 fs_g_nav_entry.u32_size = 0; 01401 Fat_file_close(); 01402 }
| void fat_write_entry_file | ( | void | ) |
This function returns or compares the short name entry.
| b_mode | action mode: FS_NAME_GET to get the short name of selected file FS_NAME_CHECK to compare the short name of selected file | |
| sz_name | if FS_NAME_GET then buffer to store the short name file (ASCII or UNICODE ) if FS_NAME_CHECK then name to compare with short name (ASCII or UNICODE), it must be terminate by NULL or '*' value | |
| u8_size_max | buffer size (unit ASCII or UNICODE ) (ignored in "FS_NAME_CHECK" mode) |
TRUE, the name is correct or read OK
//! Global variable used //! IN : //! fs_g_sector The directory sector corresponding at the current position //! fs_g_nav_fast.u16_entry_pos_sel_file Position in directory of the entry file (unit entry) //!
Definition at line 1472 of file fat.c.
References FALSE, fat_get_ptr_entry(), FS_ERR_NAME_INCORRECT, fs_g_status, FS_NAME_GET, FS_SIZE_SFNAME, FS_SIZE_SFNAME_WITHOUT_EXT, g_b_string_length, Is_unicode, MSB, and TRUE.
01473 { 01474 Bool b_extension_nostart = TRUE; 01475 U8 u8_pos_name; 01476 U8 u8_entry_char, u8_szname_char; 01477 PTR_CACHE ptr_entry; 01478 U8 u8_pos_entry; 01479 01480 fs_g_status = FS_ERR_NAME_INCORRECT; // by default the name don't corresponding at filter name 01481 01482 u8_pos_name = 0; 01483 u8_pos_entry = 0; 01484 ptr_entry = fat_get_ptr_entry(); 01485 01486 // for each characters of short name 01487 while( 1 ) 01488 { 01489 if( FS_SIZE_SFNAME == u8_pos_entry ) 01490 { 01491 u8_entry_char = 0; // end of name 01492 } 01493 else 01494 { 01495 u8_entry_char = ptr_entry[ u8_pos_entry ]; 01496 if( ((FS_SIZE_SFNAME_WITHOUT_EXT == u8_pos_entry) && b_extension_nostart) // end of name and '.' character no writed 01497 || ( ' ' == u8_entry_char) ) 01498 { 01499 // end of name or extension 01500 if( (FS_SIZE_SFNAME_WITHOUT_EXT >= u8_pos_entry) // End of name without extension 01501 && (' ' != ptr_entry[ FS_SIZE_SFNAME_WITHOUT_EXT ]) ) // extension exists 01502 { 01503 // go to extension position 01504 b_extension_nostart = FALSE; 01505 u8_pos_entry = FS_SIZE_SFNAME_WITHOUT_EXT-1; 01506 u8_entry_char = '.'; 01507 } 01508 else 01509 { 01510 u8_entry_char = 0; // end of name 01511 } 01512 } 01513 } 01514 01515 if( FS_NAME_GET == b_mode ) 01516 { 01517 if( !g_b_string_length ) 01518 { 01519 if(u8_pos_name >= (u8_size_max-1)) 01520 u8_entry_char = 0; // buffer full then force end of string 01521 01522 if( ('A'<=u8_entry_char) && (u8_entry_char<='Z')) 01523 u8_entry_char += ('a'-'A'); // display short name in down case 01524 01525 if( Is_unicode ) 01526 { 01527 ((FS_STR_UNICODE)sz_name)[0] = u8_entry_char; 01528 }else{ 01529 sz_name[0] = u8_entry_char; 01530 } 01531 } 01532 } 01533 else 01534 { 01535 // Compare the name 01536 if( Is_unicode 01537 && (0 != MSB(((FS_STR_UNICODE)sz_name)[0])) ) 01538 { 01539 // The UNICODE is not possibled in short name 01540 return FALSE; 01541 } 01542 01543 if( Is_unicode ) 01544 { 01545 u8_szname_char = ((FS_STR_UNICODE)sz_name)[0]; 01546 }else{ 01547 u8_szname_char = sz_name[0]; 01548 } 01549 if ('*' == u8_szname_char) 01550 { // end of filter name which autorise all next character 01551 return TRUE; //*** The name is correct *** 01552 } 01553 01554 if( (0 != u8_entry_char) || (('\\' != u8_szname_char) && ('/' != u8_szname_char)) ) 01555 { 01556 if((u8_szname_char != u8_entry_char) 01557 && (u8_szname_char != (u8_entry_char+('a'-'A'))) ) // no case sensitive 01558 return FALSE; // short name not equal 01559 } 01560 } 01561 01562 // For each characters 01563 if (0 == u8_entry_char) 01564 { 01565 if( g_b_string_length ) 01566 { 01567 ((FS_STR_UNICODE)sz_name)[0] = u8_pos_name+1; // Get length name 01568 } 01569 return TRUE; // End of test correct or end of get name 01570 } 01571 if( !g_b_string_length ) 01572 { 01573 sz_name += (Is_unicode? 2 : 1 ); 01574 } 01575 u8_pos_name++; 01576 u8_pos_entry++; 01577 } 01578 }
This function returns or compares the long name entry.
| b_mode | action mode: FS_NAME_GET to get the long name of selected file FS_NAME_CHECK to compare the long name of selected file | |
| sz_name | if FS_NAME_GET then buffer to store the long name file (ASCII or UNICODE ) if FS_NAME_CHECK then name to compare with long name (ASCII or UNICODE), it must be terminate by NULL or '*' value | |
| b_match_case | FALSE, ignore the case (only used in "FS_NAME_CHECK" action mode) | |
| u8_size_max | buffer size (unit ASCII or UNICODE ) (ignored in "FS_NAME_CHECK" mode) |
TRUE, the name is correct or read is finish
//! Global variable used //! IN : //! fs_g_sector The directory sector corresponding at the current position //! fs_g_nav_fast.u16_entry_pos_sel_file Position in directory of the entry file (unit entry) //!
Definition at line 1603 of file fat.c.
References FALSE, fat_check_eof_name(), fat_get_ptr_entry(), FS_ATTR_LFN_ENTRY, FS_ENTRY_DEL, FS_ENTRY_END, FS_ENTRY_LFN_LAST, FS_ERR_ENTRY_BAD, FS_ERR_NAME_INCORRECT, fs_g_status, FS_NAME_GET, FS_NO_LAST_LFN_ENTRY, FS_SIZE_FILE_ENTRY, g_b_string_length, Is_unicode, LSB, MSB, and TRUE.
01604 { 01605 U8 u8_pos_name; 01606 PTR_CACHE ptr_entry; 01607 U16 u16_unicode_entry; 01608 U16 u16_unicode_szname; 01609 01610 ptr_entry = fat_get_ptr_entry(); 01611 01612 if( (FS_ENTRY_END == *ptr_entry ) // end of directory 01613 || (FS_ENTRY_DEL == *ptr_entry ) // entry deleted 01614 || (FS_ATTR_LFN_ENTRY != ptr_entry[11]) ) // no long name 01615 { 01616 fs_g_status = FS_ERR_ENTRY_BAD; 01617 return FALSE; 01618 } 01619 01620 if( g_b_string_length ) 01621 { 01622 if ( 0 == (FS_ENTRY_LFN_LAST & *ptr_entry)) 01623 { 01624 // no necessary -> ((FS_STR_UNICODE)sz_name)[0] = FS_SIZE_LFN_ENTRY; 01625 fs_g_status = FS_NO_LAST_LFN_ENTRY; 01626 return FALSE; // Other entry long name 01627 } 01628 } 01629 01630 ptr_entry++; // The long name start at offset 1 of the entry file 01631 01632 u8_pos_name=0; 01633 while( 1 ) 01634 { 01635 LSB(u16_unicode_entry) = ptr_entry[0]; 01636 MSB(u16_unicode_entry) = ptr_entry[1]; 01637 if( FS_NAME_GET == b_mode ) 01638 { 01639 if( !g_b_string_length ) 01640 { 01641 // Check the end of buffer 01642 if( u8_pos_name>=(u8_size_max-1) ) 01643 { 01644 // Write end of string 01645 if( Is_unicode ) 01646 { 01647 ((FS_STR_UNICODE)sz_name)[0] = 0; 01648 }else{ 01649 sz_name[0] = 0; 01650 } 01651 return TRUE; // the buffer is full 01652 } 01653 // Read and store the long name 01654 if( Is_unicode ) 01655 { 01656 ((FS_STR_UNICODE)sz_name)[0] = u16_unicode_entry; 01657 }else{ 01658 sz_name[0] = (U8)u16_unicode_entry; 01659 } 01660 } 01661 } 01662 else 01663 { 01664 if( Is_unicode ) 01665 { 01666 u16_unicode_szname = ((FS_STR_UNICODE)sz_name)[0]; 01667 }else{ 01668 u16_unicode_szname = sz_name[0]; 01669 } 01670 // Check the name 01671 if( '*' == u16_unicode_szname ) 01672 { // end of filter name which autorise all next character 01673 return TRUE; //*** The name is correct *** 01674 } 01675 01676 if( ((0 != u16_unicode_entry ) || (( '\\' != u16_unicode_szname) && ( '/' != u16_unicode_szname)) ) 01677 && ((u16_unicode_szname != (u16_unicode_entry+('a'-'A'))) || b_match_case) 01678 && ((u16_unicode_szname != (u16_unicode_entry-('a'-'A'))) || b_match_case) 01679 && (u16_unicode_szname != u16_unicode_entry) ) 01680 { 01681 fs_g_status = FS_ERR_NAME_INCORRECT; // The name don't corresponding at filter name 01682 return FALSE; 01683 } 01684 } 01685 01686 if( 0 == u16_unicode_entry) 01687 { 01688 if( g_b_string_length ) 01689 { 01690 ((FS_STR_UNICODE)sz_name)[0] = u8_pos_name+1; 01691 } 01692 return TRUE; // Last long name entry 01693 } 01694 if( 4 == u8_pos_name ) 01695 ptr_entry += 3; // Go to second character 01696 01697 if( 10 == u8_pos_name ) 01698 ptr_entry += 2; // Go to third character 01699 01700 if( 12 == u8_pos_name ) 01701 { // End of entry long name 01702 ptr_entry -= (FS_SIZE_FILE_ENTRY-2); // Go to the first byte of the file entry 01703 if ( 0 == (FS_ENTRY_LFN_LAST & ptr_entry[0])) 01704 { 01705 fs_g_status = FS_NO_LAST_LFN_ENTRY; 01706 return FALSE; // Other long name entry is present 01707 } 01708 else 01709 { // It is the last long name entry 01710 // then it is the end of name 01711 if( (FS_NAME_GET == b_mode) && g_b_string_length ) 01712 { 01713 ((FS_STR_UNICODE)sz_name)[0] = 14; 01714 return TRUE; 01715 } 01716 sz_name += (Is_unicode? 2 : 1 ); 01717 if( FS_NAME_GET == b_mode ) 01718 { 01719 // Write end of string UNICODE 01720 if( Is_unicode ) 01721 { 01722 ((FS_STR_UNICODE)sz_name)[0] = 0; 01723 }else{ 01724 sz_name[0] = 0; 01725 } 01726 return TRUE; 01727 } 01728 else 01729 { 01730 // if it is the end of filter 01731 if( Is_unicode ) 01732 { 01733 u16_unicode_szname = ((FS_STR_UNICODE)sz_name)[0]; 01734 }else{ 01735 u16_unicode_szname = sz_name[0]; 01736 } 01737 return fat_check_eof_name(u16_unicode_szname); 01738 } 01739 } 01740 } 01741 01742 if( !g_b_string_length ) 01743 { 01744 sz_name += (Is_unicode? 2 : 1 ); 01745 } 01746 u8_pos_name++; 01747 ptr_entry+=2; 01748 } 01749 }
| PTR_CACHE fat_get_ptr_entry | ( | void | ) |
This function returns a cache pointer on the current entry.
Definition at line 1769 of file fat.c.
References FS_512B_MASK, fs_g_nav_fast, fs_g_sector, FS_SIZE_FILE_ENTRY, and Fs_management_fast::u16_entry_pos_sel_file.
01770 { 01771 return &fs_g_sector[(fs_g_nav_fast.u16_entry_pos_sel_file * FS_SIZE_FILE_ENTRY) & FS_512B_MASK]; 01772 }
This function reads the information about a date.
| type_date | choose the date type (FS_DATE_LAST_WRITE or FS_DATE_CREATION) | |
| sz_date | table to store the date storage format (ASCII) = "YYYYMMDDHHMMSSMS" = year, month, day, hour, minute, seconde, miliseconde |
Definition at line 1196 of file fat_unusual.c.
Referenced by nav_file_dateget().
01197 { 01198 PTR_CACHE ptr_entry; 01199 01200 ptr_entry = fat_get_ptr_entry(); 01201 if( FS_DATE_LAST_WRITE == type_date ) 01202 { 01203 fat_translatedate_number_to_ascii( sz_date , &ptr_entry[22] , FALSE ); 01204 } 01205 else 01206 { 01207 fat_translatedate_number_to_ascii( sz_date , &ptr_entry[13] , TRUE ); 01208 } 01209 }
This function loads a memory sector in internal cache sector.
| b_load | TRUE, load the cache with the memory sector corresponding FALSE, Don't change the sector cache but change the memory address of cache |
TRUE otherwise
//! Global variable used //! IN : //! fs_g_nav.u8_lun drive number to read //! fs_gu32_addrsector address to read (unit sector) //!
Definition at line 1790 of file fat.c.
References CTRL_GOOD, FALSE, fat_cache_flush(), fat_cache_reset(), FS_ERR_HW, fs_g_nav, fs_g_sector, fs_g_sectorcache, fs_g_status, fs_gu32_addrsector, memory_2_ram(), TRUE, Fs_sector_cache::u32_addr, Fs_management::u8_lun, and Fs_sector_cache::u8_lun.
01791 { 01792 // Check if the sector asked is the same in cache 01793 if( (fs_g_sectorcache.u8_lun == fs_g_nav.u8_lun ) 01794 && (fs_g_sectorcache.u32_addr == fs_gu32_addrsector ) ) 01795 { 01796 return TRUE; 01797 } 01798 01799 // Write previous cache before fill cache with a new sector 01800 if( !fat_cache_flush()) 01801 return FALSE; 01802 01803 // Delete informations about the caches 01804 fat_cache_reset(); 01805 01806 // Init sector cache 01807 fs_g_sectorcache.u32_addr = fs_gu32_addrsector; 01808 if( b_load ) 01809 { 01810 // Load the sector from memory 01811 if( CTRL_GOOD != memory_2_ram( fs_g_nav.u8_lun , fs_g_sectorcache.u32_addr, fs_g_sector)) 01812 { 01813 fs_g_status = FS_ERR_HW; 01814 return FALSE; 01815 } 01816 } 01817 // Valid sector cache 01818 fs_g_sectorcache.u8_lun = fs_g_nav.u8_lun; 01819 return TRUE; 01820 }
| void fat_cache_reset | ( | void | ) |
This function resets the sector cache.
Definition at line 1825 of file fat.c.
References FALSE, FS_BUF_SECTOR_EMPTY, fs_g_sectorcache, Fs_sector_cache::u32_clusterlist_start, Fs_sector_cache::u8_dirty, and Fs_sector_cache::u8_lun.
01826 { 01827 fs_g_sectorcache.u8_lun = FS_BUF_SECTOR_EMPTY; 01828 fs_g_sectorcache.u8_dirty = FALSE; 01829 fs_g_sectorcache.u32_clusterlist_start = 0xFFFFFFFF; 01830 }
| void fat_cache_clear | ( | void | ) |
| void fat_cache_mark_sector_as_dirty | ( | void | ) |
| Bool fat_cache_flush | ( | void | ) |
This function flushs the sector cache on the memory if necessary.
TRUE otherwise
Definition at line 1856 of file fat.c.
References CTRL_GOOD, FALSE, FS_ERR_HW, fs_g_sector, fs_g_sectorcache, fs_g_status, FS_LUN_WP, mem_wr_protect(), ram_2_memory(), TRUE, Fs_sector_cache::u32_addr, Fs_sector_cache::u8_dirty, and Fs_sector_cache::u8_lun.
01857 { 01858 // If the cache is modified, then write the sector cache on the device 01859 if ( TRUE == fs_g_sectorcache.u8_dirty ) 01860 { 01861 fs_g_sectorcache.u8_dirty = FALSE; // Always clear, although an error occur 01862 if( mem_wr_protect( fs_g_sectorcache.u8_lun )) 01863 { 01864 fs_g_status = FS_LUN_WP; 01865 return FALSE; 01866 } 01867 if (CTRL_GOOD != ram_2_memory( fs_g_sectorcache.u8_lun , fs_g_sectorcache.u32_addr , fs_g_sector )) 01868 { 01869 fs_g_status = FS_ERR_HW; 01870 return FALSE; 01871 } 01872 } 01873 return TRUE; 01874 }
Variables to select string format (initialised in nav_reset()).
Referenced by nav_reset(), nav_string_ascii(), and nav_string_unicode().
Variables to select LENGTH string mode (initialised in nav_reset()).
Referenced by fat_entry_longname(), fat_entry_shortname(), nav_dir_name(), nav_file_name(), nav_getcwd(), nav_reset(), nav_string_length_disable(), and nav_string_length_enable().
Variables to enable/disable the disk check before each action on disk.
Referenced by fat_check_device(), nav_checkdisk_disable(), nav_checkdisk_enable(), and nav_reset().
| _MEM_TYPE_SLOW_ Fs_management fs_g_nav |
Referenced by fat_cache_clusterlist_update_finish(), fat_cache_clusterlist_update_read(), fat_cache_read_sector(), fat_check_device(), fat_clear_entry_info_and_ptr(), fat_cluster_list(), fat_cluster_val(), fat_getfreespace(), fat_getfreespace_percent(), fat_mount(), fat_read_dir(), fat_read_file(), file_load_segment_value(), file_open(), file_read(), file_read_buf(), nav_dir_cd(), nav_dir_gotoparent(), nav_dir_is_root(), nav_dir_name(), nav_drive_get(), nav_drive_getname(), nav_drive_set(), nav_file_isreadonly(), nav_filelist_eol(), nav_filelist_exist(), nav_filelist_first(), nav_filelist_get(), nav_filelist_nb(), nav_filelist_set(), nav_filelist_single_disable(), nav_filelist_single_enable(), nav_getindex(), nav_gotoindex(), nav_partition_cluster_size(), nav_partition_mount(), nav_partition_set(), nav_partition_space(), and nav_reset().
| _MEM_TYPE_FAST_ Fs_management_fast fs_g_nav_fast |
Referenced by fat_check_device(), fat_check_mount(), fat_check_noopen(), fat_check_select(), fat_clear_entry_info_and_ptr(), fat_get_ptr_entry(), fat_mount(), fat_read_dir(), nav_dir_cd(), nav_dir_gotoparent(), nav_dir_name(), nav_drive_set(), nav_file_name(), nav_filelist_eol(), nav_filelist_set(), nav_getindex(), nav_gotoindex(), nav_partition_freespace(), nav_partition_freespace_percent(), nav_partition_label(), nav_partition_mount(), nav_partition_set(), nav_partition_space(), nav_partition_type(), and nav_reset().
| _MEM_TYPE_SLOW_ Fs_management_entry fs_g_nav_entry |
Referenced by fat_clear_entry_info_and_ptr(), fat_entry_is_dir(), fat_get_entry_info(), fat_read_file(), file_bof(), file_close(), file_eof(), file_flush(), file_getc(), file_getpos(), file_open(), file_read(), file_read_buf(), file_seek(), nav_dir_cd(), nav_dir_gotoparent(), nav_dir_name(), nav_file_attributget(), nav_file_isreadonly(), nav_file_lgt(), and nav_file_lgtsector().
| _MEM_TYPE_FAST_ Fs_segment fs_g_seg |
Variable frequently used by many function (optimization, no parameter in function).
Referenced by fat_cache_clusterlist_update_finish(), fat_cache_clusterlist_update_read(), fat_cache_clusterlist_update_start(), fat_cluster_list(), fat_read_dir(), fat_read_file(), file_load_segment_value(), file_read(), and file_read_buf().
| _MEM_TYPE_FAST_ Fs_cluster fs_g_cluster |
To take time in functions: fat_getfreespace, fat_cluster_list, fat_cluster_val, fat_checkcluster.
Referenced by fat_cache_clusterlist_update_read(), fat_cache_clusterlist_update_start(), fat_checkcluster(), fat_cluster_list(), fat_cluster_readnext(), fat_cluster_val(), fat_getfreespace(), and fat_getfreespace_percent().
| _MEM_TYPE_SLOW_ U8 fs_g_sector[512] |
| _MEM_TYPE_SLOW_ Fs_sector_cache fs_g_sectorcache |
Referenced by fat_cache_flush(), fat_cache_read_sector(), fat_cache_reset(), fat_check_device(), fat_read_dir(), and fat_read_file().
| _MEM_TYPE_SLOW_ U32 fs_gu32_addrsector |
Store the address of futur cache (unit 512B).
Referenced by fat_cache_read_sector(), fat_cluster_readnext(), fat_cluster_val(), fat_get_nbpartition(), fat_getfreespace_percent(), fat_mount(), fat_read_dir(), and fat_read_file().
1.5.3