fat.h File Reference

FAT services. More...

#include "fs_com.h"

Include dependency graph for fat.h:

This graph shows which files directly or indirectly include this file:

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


Detailed Description

FAT services.

This file is the header for FAT services

Author:
Atmel Corporation: http://www.atmel.com
Support and FAQ: http://support.atmel.no/

Definition in file fat.h.


Define Documentation

#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
    

Definition at line 64 of file fat.h.

#define Is_fat12   (FS_TYPE_FAT_12 == fs_g_nav_fast.u8_type_fat)

Definition at line 75 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 80 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 85 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 92 of file fat.h.

Referenced by fat_entry_longname(), fat_entry_shortname(), nav_dir_name(), nav_file_name(), nav_getcwd(), and nav_setcwd().

#define FS_MBR_OFFSET_PART_ENTRY ( num   )     ((U16)((U16)(0x1BE)+(0x10 * num)))

Position (unit byte) in the MBR of a partition entry.

Definition at line 108 of file fat.h.

Referenced by fat_get_nbpartition(), and fat_mount().

#define LOW_16_BPB_BytsPerSec   fs_g_sector[11]

Definition at line 114 of file fat.h.

#define HIGH_16_BPB_BytsPerSec   fs_g_sector[12]

Definition at line 115 of file fat.h.

Referenced by fat_mount().

#define U8_BPB_SecPerClus   fs_g_sector[13]

Definition at line 116 of file fat.h.

Referenced by fat_mount().

#define LOW_16_BPB_RootEntCnt   fs_g_sector[17]

Definition at line 117 of file fat.h.

Referenced by fat_mount().

#define HIGH_16_BPB_RootEntCnt   fs_g_sector[18]

Definition at line 118 of file fat.h.

Referenced by fat_mount().

#define LOW_16_BPB_FATSz16   fs_g_sector[22]

Definition at line 119 of file fat.h.

Referenced by fat_mount().

#define HIGH_16_BPB_FATSz16   fs_g_sector[23]

Definition at line 120 of file fat.h.

Referenced by fat_mount().

#define LOW0_32_BPB_FATSz32   fs_g_sector[36]

Definition at line 121 of file fat.h.

Referenced by fat_mount().

#define LOW1_32_BPB_FATSz32   fs_g_sector[37]

Definition at line 122 of file fat.h.

Referenced by fat_mount().

#define LOW2_32_BPB_FATSz32   fs_g_sector[38]

Definition at line 123 of file fat.h.

Referenced by fat_mount().

#define LOW3_32_BPB_FATSz32   fs_g_sector[39]

Definition at line 124 of file fat.h.

Referenced by fat_mount().

#define LOW_16_BPB_TotSec16   fs_g_sector[19]

Definition at line 125 of file fat.h.

Referenced by fat_mount().

#define HIGH_16_BPB_TotSec16   fs_g_sector[20]

Definition at line 126 of file fat.h.

Referenced by fat_mount().

#define LOW0_32_BPB_TotSec32   fs_g_sector[32]

Definition at line 127 of file fat.h.

Referenced by fat_mount().

#define LOW1_32_BPB_TotSec32   fs_g_sector[33]

Definition at line 128 of file fat.h.

Referenced by fat_mount().

#define LOW2_32_BPB_TotSec32   fs_g_sector[34]

Definition at line 129 of file fat.h.

Referenced by fat_mount().

#define LOW3_32_BPB_TotSec32   fs_g_sector[35]

Definition at line 130 of file fat.h.

Referenced by fat_mount().

#define LOW_16_BPB_ResvSecCnt   fs_g_sector[14]

Definition at line 131 of file fat.h.

Referenced by fat_mount().

#define HIGH_16_BPB_ResvSecCnt   fs_g_sector[15]

Definition at line 132 of file fat.h.

Referenced by fat_mount().

#define U8_BPB_NumFATs   fs_g_sector[16]

Definition at line 133 of file fat.h.

#define LOW0_32_BPB_RootClus   fs_g_sector[44]

Definition at line 134 of file fat.h.

Referenced by fat_mount().

#define LOW1_32_BPB_RootClus   fs_g_sector[45]

Definition at line 135 of file fat.h.

Referenced by fat_mount().

#define LOW2_32_BPB_RootClus   fs_g_sector[46]

Definition at line 136 of file fat.h.

Referenced by fat_mount().

#define LOW3_32_BPB_RootClus   fs_g_sector[47]

Definition at line 137 of file fat.h.

Referenced by fat_mount().

#define LOW_16_BPB_FSInfo   fs_g_sector[48]

Definition at line 138 of file fat.h.

Referenced by fat_mount().

#define HIGH_16_BPB_FSInfo   fs_g_sector[49]

Definition at line 139 of file fat.h.

#define FS_BR_SIGNATURE_LOW   0x55

Definition at line 145 of file fat.h.

Referenced by fat_get_nbpartition(), and fat_mount().

#define FS_BR_SIGNATURE_HIGH   0xAA

Definition at line 146 of file fat.h.

Referenced by fat_get_nbpartition(), and fat_mount().

#define FS_PART_BOOTABLE   0x80

Definition at line 152 of file fat.h.

Referenced by fat_mount().

#define FS_PART_NO_BOOTABLE   0x00

Definition at line 153 of file fat.h.

Referenced by fat_mount().

#define FS_PART_TYPE_FAT12   0x01

Definition at line 167 of file fat.h.

Referenced by fat_mount().

#define FS_PART_TYPE_FAT16_INF32M   0x04

Definition at line 168 of file fat.h.

Referenced by fat_mount().

#define FS_PART_TYPE_FAT16_SUP32M   0x06

Definition at line 169 of file fat.h.

Referenced by fat_mount().

#define FS_PART_TYPE_FAT16_SUP32M_BIS   0x0E

Definition at line 170 of file fat.h.

Referenced by fat_mount().

#define FS_PART_TYPE_FAT32   0x0B

Definition at line 171 of file fat.h.

Referenced by fat_mount().

#define FS_PART_TYPE_FAT32_BIS   0x0C

Definition at line 172 of file fat.h.

Referenced by fat_mount().

#define FS_PART_REMOVE_MEDIA   0xF0

Definition at line 173 of file fat.h.

#define FS_PART_NO_REMOVE_MEDIA   0xF8

Definition at line 174 of file fat.h.

#define FS_PART_HARD_DISK   0x81

Definition at line 175 of file fat.h.

#define FS_BOOT_SIGN   0x29

Definition at line 176 of file fat.h.

#define FS_FAT12_MAX_CLUSTERS   4085

Definition at line 182 of file fat.h.

Referenced by fat_mount().

#define FS_FAT16_MAX_CLUSTERS   65525

Definition at line 183 of file fat.h.

Referenced by fat_mount().

#define FS_ENTRY_END   0x00

Definition at line 189 of file fat.h.

Referenced by fat_entry_check(), and fat_entry_longname().

#define FS_ENTRY_DEL   0xE5

Definition at line 190 of file fat.h.

Referenced by fat_entry_check(), and fat_entry_longname().

#define FS_ENTRY_LFN_LAST   0x40

Definition at line 191 of file fat.h.

Referenced by fat_entry_longname().

#define FS_SIZE_FILE_ENTRY   32

Definition at line 197 of file fat.h.

Referenced by fat_entry_longname(), fat_get_ptr_entry(), and fat_mount().

#define FS_SHIFT_B_TO_FILE_ENTRY   5

Definition at line 198 of file fat.h.

Referenced by fat_read_dir().

#define FS_SIZE_LFN_ENTRY   13

Definition at line 199 of file fat.h.

Referenced by nav_file_name().

#define FS_SIZE_SFNAME   11

Definition at line 200 of file fat.h.

Referenced by fat_entry_shortname().

#define FS_SIZE_SFNAME_WITHOUT_EXT   8

Definition at line 201 of file fat.h.

Referenced by fat_entry_shortname().

#define FS_SIZE_SFNAME_EXT_ONLY   3

Definition at line 202 of file fat.h.

#define FS_NB_FAT   2

Definition at line 208 of file fat.h.

Referenced by fat_mount().

#define FS_512B   512

Definition at line 216 of file fat.h.

Referenced by fat_mount(), file_read(), and file_read_buf().

#define FS_512B_MASK   (512-1)

Definition at line 217 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 218 of file fat.h.

Referenced by fat_read_dir(), fat_read_file(), file_read(), and nav_file_lgtsector().

#define FS_SIZE_OF_SECTOR   FS_512B

Definition at line 219 of file fat.h.

#define FS_MASK_SIZE_OF_SECTOR   FS_512B_MASK

Definition at line 220 of file fat.h.

#define FS_SHIFT_B_TO_SECTOR   FS_512B_SHIFT_BIT

Definition at line 221 of file fat.h.

#define FS_CACHE_SIZE   512

Definition at line 222 of file fat.h.

Referenced by fat_cluster_readnext(), and fat_cluster_val().

#define FS_BUF_SECTOR_EMPTY   0xFF

Signal that sector cache is not valid.

Definition at line 226 of file fat.h.

Referenced by fat_cache_reset().

#define FS_CLUS_OK   0

Definition at line 231 of file fat.h.

Referenced by fat_checkcluster().

#define FS_CLUS_BAD   1

Definition at line 232 of file fat.h.

Referenced by fat_checkcluster(), and fat_cluster_list().

#define FS_CLUS_END   2

Definition at line 233 of file fat.h.

Referenced by fat_checkcluster(), and fat_cluster_list().

#define FS_CLUST_ACT_SEG   0x01

Definition at line 239 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 240 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

Definition at line 241 of file fat.h.

Referenced by fat_cluster_list(), and fat_read_file().

#define FS_CLUST_VAL_READ   FALSE

Definition at line 246 of file fat.h.

Referenced by fat_cluster_list(), fat_getfreespace(), and fat_getfreespace_percent().

#define FS_CLUST_VAL_WRITE   TRUE

Definition at line 247 of file fat.h.

Referenced by fat_cluster_list().

#define FS_CLUST_VAL_EOL   0x0FFFFFFF

Definition at line 248 of file fat.h.

Referenced by fat_cluster_list().

#define FS_TYPE_FAT_UNM   0

Partition not mounted.

Definition at line 358 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

Definition at line 359 of file fat.h.

Referenced by fat_mount(), and ushell_cmd_ls().

#define FS_TYPE_FAT_16   2

Definition at line 360 of file fat.h.

Referenced by fat_mount(), and ushell_cmd_ls().

#define FS_TYPE_FAT_32   3

Definition at line 361 of file fat.h.

Referenced by fat_mount(), and ushell_cmd_ls().

#define FS_NO_SEL   0xFFFF

Signal that a file entry isn't selected.

Definition at line 367 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 368 of file fat.h.

Referenced by nav_filelist_set().

 
#define Fat_file_is_open (  )     (fs_g_nav_entry.u8_open_mode !=0 )

Definition at line 374 of file fat.h.

Referenced by fat_check_noopen().

 
#define Fat_file_isnot_open (  )     (fs_g_nav_entry.u8_open_mode ==0 )

Definition at line 375 of file fat.h.

Referenced by fat_check_open().

 
#define Fat_file_close (  )     (fs_g_nav_entry.u8_open_mode =0 )

Definition at line 376 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_disk (  )     (TRUE)

Definition at line 524 of file fat.h.

#define fat_check_nav_access_file (  )     (TRUE)

Definition at line 525 of file fat.h.

Referenced by file_open().

#define fat_invert_nav   ( arg ) (arg++)

Definition at line 536 of file fat.h.

Referenced by nav_select().

#define fat_copy_nav   ( arg ) (arg++)

Definition at line 537 of file fat.h.

Referenced by nav_copy().


Typedef Documentation

typedef U8 _MEM_TYPE_SLOW_* PTR_CACHE

Definition at line 418 of file fat.h.


Function Documentation

Bool fat_check_device ( void   ) 

This function checks device state.

Returns:
TRUE device ready

FALSE otherwise

//! This function updates all navigator datas when the device state change.
//! 

Definition at line 91 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.

00092 {
00093    U8 retry=0;
00094 #if (FS_NB_NAVIGATOR > 1)
00095    U8 i;
00096 #endif
00097    Ctrl_status status;
00098    
00099    // Possibility to ignore the disk check. Used to take time during multi read/write access
00100    if( g_b_no_check_disk )
00101       return TRUE;
00102 
00103    if( 0xFF == fs_g_nav.u8_lun )
00104    {
00105       fs_g_status = FS_ERR_HW;
00106       return FALSE;                                // No device selected
00107    }
00108 
00109    for( retry=0 ; retry<100 ; retry++ )
00110    {
00111       // Check device
00112       status = mem_test_unit_ready( fs_g_nav.u8_lun );
00113       if( CTRL_GOOD       == status )
00114          return TRUE;                              // drive ready
00115 
00116       //* HERE error or state change
00117       // Clean all navigator datas which use this device
00118       fs_g_nav_fast.u8_type_fat = FS_TYPE_FAT_UNM; // By default the fat isn't mounted
00119       Fat_file_close();                            // By default the file is not open
00120 #if (FS_NB_NAVIGATOR > 1)
00121       for( i=0 ; i!=(FS_NB_NAVIGATOR-1) ; i++ )
00122       {
00123          if( fs_g_nav.u8_lun == fs_g_navext[i].u8_lun )
00124          {
00125             fs_g_navext_fast[i].u8_type_fat     = FS_TYPE_FAT_UNM;   // By default the fat isn't mounted
00126             fs_g_navext_entry[i].u8_open_mode   = 0;                 // By default the file is not open
00127          }
00128       }
00129 #endif
00130       // If the internal cache corresponding at device then clean it
00131       if( fs_g_nav.u8_lun == fs_g_sectorcache.u8_lun )
00132       {
00133          fat_cache_reset();
00134       }
00135       fat_cache_clusterlist_reset();
00136 
00137       fs_g_status = FS_ERR_HW;                     // By default HW error
00138       if( CTRL_BUSY == status )
00139          continue;                                 // If device busy then retry
00140 
00141       if( CTRL_NO_PRESENT == status )
00142          fs_g_status = FS_ERR_HW_NO_PRESENT;       // Update error flag
00143       break;                                       // FAIL or NOT PRESENT = fatal error = no retry
00144    }
00145    return FALSE;
00146 }

Here is the call graph for this function:

Bool fat_check_mount ( void   ) 

This function checks if the partition is mounted.

Returns:
TRUE partition mounted

FALSE otherwise

Definition at line 154 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.

00155 {
00156    if( !fat_check_device() )
00157       return FALSE;
00158    if (FS_TYPE_FAT_UNM == fs_g_nav_fast.u8_type_fat)
00159    {
00160       if( !fat_mount() )
00161       {
00162          fs_g_status = FS_ERR_NO_MOUNT;
00163          return FALSE;
00164       }
00165    }
00166    return TRUE;
00167 }

Here is the call graph for this function:

Bool fat_check_noopen ( void   ) 

This function checks if a file is not opened on current navigator.

Returns:
TRUE no file opened

FALSE otherwise

Definition at line 175 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.

00176 {
00177    if( !fat_check_device() )
00178       return TRUE;
00179    if (FS_TYPE_FAT_UNM == fs_g_nav_fast.u8_type_fat)
00180       return TRUE;
00181    if( Fat_file_is_open() )
00182    {
00183       fs_g_status = FS_ERR_TOO_FILE_OPEN;  // The navigation have already open a file
00184       return FALSE;
00185    }
00186    return TRUE;
00187 }

Here is the call graph for this function:

Bool fat_check_open ( void   ) 

This function checks if a file is opened on current navigator.

Returns:
TRUE a file is opened

FALSE otherwise

Definition at line 195 of file fat.c.

References FALSE, Fat_file_isnot_open, FS_ERR_FILE_NO_OPEN, fs_g_status, and TRUE.

00196 {
00197    if( Fat_file_isnot_open() )
00198    {
00199       fs_g_status = FS_ERR_FILE_NO_OPEN;
00200       return FALSE;
00201    }
00202    return TRUE;
00203 }

Bool fat_check_select ( void   ) 

This function checks if a file is selected on current navigator.

Returns:
TRUE a file is selected

FALSE otherwise

Definition at line 211 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.

00212 {
00213    if (FS_NO_SEL == fs_g_nav_fast.u16_entry_pos_sel_file)
00214    {
00215       fs_g_status = FS_ERR_NO_FILE_SEL;
00216       return FALSE;
00217    }
00218    return TRUE;
00219 }

Bool fat_check_mount_noopen ( void   ) 

This function checks if the partition is mounted and no file is opened.

Returns:
TRUE partition mounted and no file is opened

FALSE otherwise

Definition at line 227 of file fat.c.

References FALSE, fat_check_mount(), and fat_check_noopen().

00228 {
00229    if( !fat_check_mount() )
00230       return FALSE;
00231    return fat_check_noopen();
00232 }

Here is the call graph for this function:

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.

Returns:
TRUE partition mounted and no file is opened and a file is selected

FALSE otherwise

Definition at line 240 of file fat.c.

References FALSE, fat_check_mount(), fat_check_noopen(), and fat_check_select().

00241 {
00242    if( !fat_check_mount() )
00243       return FALSE;
00244    if( !fat_check_select() )
00245       return FALSE;
00246    return fat_check_noopen();
00247 }

Here is the call graph for this function:

Bool fat_check_mount_select_open ( void   ) 

This function checks if the partition is mounted and if a file is opened.

Returns:
TRUE partition mounted and a file is opened

FALSE otherwise

Definition at line 255 of file fat.c.

References FALSE, fat_check_mount(), fat_check_open(), and fat_check_select().

00256 {
00257    if( !fat_check_mount() )
00258       return FALSE;
00259    if( !fat_check_select() )
00260       return FALSE;
00261    return fat_check_open();
00262 }

Here is the call graph for this function:

Bool fat_check_mount_select ( void   ) 

This function checks if the partition is mounted and if a file is selected.

Returns:
TRUE partition mounted and a file is selected

FALSE otherwise

Definition at line 270 of file fat.c.

References FALSE, fat_check_mount(), and fat_check_select().

00271 {
00272    if( !fat_check_mount() )
00273       return FALSE;
00274    return fat_check_select();
00275 }

Here is the call graph for this function:

Bool fat_check_is_file ( void   ) 

This function checks if the selected file entry is a file and not a directory.

Returns:
TRUE It is a file and not a directory

FALSE otherwise

Definition at line 283 of file fat.c.

References FALSE, Fat_is_not_a_file, FS_ERR_NO_FILE, fs_g_status, and TRUE.

00284 {
00285    if( Fat_is_not_a_file )
00286    {
00287       fs_g_status = FS_ERR_NO_FILE;   // It isn't a file, it is a directory or a volume id
00288       return FALSE;
00289    }
00290    return TRUE;
00291 }

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.

Returns:
u8_number number of partition

Definition at line 299 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.

00300 {
00301    if( !fat_check_device() )
00302       return 0;
00303 
00304 #warning this routine contains bug, rework it
00305    // Read the first sector of drive
00306    fs_gu32_addrsector = 0;
00307    if( !fat_cache_read_sector( TRUE ))
00308       return FALSE;
00309 
00310    // Check PBR or MBR signature
00311    if ( (fs_g_sector[510] != FS_BR_SIGNATURE_LOW  )
00312    &&   (fs_g_sector[511] != FS_BR_SIGNATURE_HIGH ) )
00313    {
00314       // No MBR
00315       // The sector, is it a PBR ?
00316       if ( (fs_g_sector[0] == 0xEB) &&          // PBR Byte 0
00317            (fs_g_sector[2] == 0x90) &&          // PBR Byte 2
00318            ((fs_g_sector[21] & 0xF0) == 0xF0) ) // PBR Byte 21 : Media byte
00319       {
00320          return 1;   // No MBR but PBR exist then only one partition
00321       } else {
00322          return 0;   // No MBR and no PBR then no partition found
00323       }
00324    }
00325 
00326    number_part = 0;
00327    while( 1 )
00328    {
00329       // The first sector must be a MBR, then check the partition entry in the MBR
00330       if ( ((fs_g_sector[FS_MBR_OFFSET_PART_ENTRY(number_part)+0] != FS_PARTITION_ACTIVE) &&
00331             (fs_g_sector[FS_MBR_OFFSET_PART_ENTRY(number_part)+0] != 0x00))
00332       ||    (fs_g_sector[FS_MBR_OFFSET_PART_ENTRY(number_part)+4] == 0x00) )
00333       {
00334          break;
00335       }
00336       number_part++;
00337    }
00338    return number_part;
00339 }

Here is the call graph for this function:

Bool fat_mount ( void   ) 

This function mounts a partition.

This function mounts a partition.

Returns:
FALSE in case of error, see global value "fs_g_status" for more detail

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 105 of file fat_unusual.c.

Referenced by fat_check_mount(), and nav_partition_mount().

00106 {
00107    U8  u8_sector_size;
00108    U8  u8_tmp;
00109    U16 u16_tmp;
00110    U32 u32_tmp;
00111 
00112    // Select the root directory
00113    fs_g_nav.u32_cluster_sel_dir   = 0;
00114    // No selected file
00115    fat_clear_entry_info_and_ptr();
00116 
00117    fs_g_nav_fast.u8_type_fat = FS_TYPE_FAT_UNM;
00118    fs_gu32_addrsector = 0;    // Start read at the beginning of memory
00119 
00120    // Check if the drive is availabled
00121    if( !fat_check_device() )
00122       return FALSE;
00123 
00124    while( 1 )  // Search a valid partition
00125    {
00126       // Read one sector
00127       if( !fat_cache_read_sector( TRUE ))
00128          return FALSE;
00129 
00130       // Check PBR/MBR signature
00131       if ( (fs_g_sector[510] != FS_BR_SIGNATURE_LOW  )
00132       &&   (fs_g_sector[511] != FS_BR_SIGNATURE_HIGH ) )
00133       {
00134          fs_g_status = FS_ERR_NO_FORMAT;
00135          return FALSE;
00136       }
00137 
00138       if ( 0 == fs_gu32_addrsector )
00139       {
00140          //** first sector then check a MBR structure
00141          // Search the first partition supported
00142 #if (FS_MULTI_PARTITION == ENABLED)
00143          u16_tmp=0;  // Init to "no valid partition found"
00144 #endif
00145          for( u8_tmp=0 ; u8_tmp!=4 ; u8_tmp++ )
00146          {
00147             // The first sector must be a MBR, then check the partition entry in the MBR
00148             if ( ((fs_g_sector[FS_MBR_OFFSET_PART_ENTRY(u8_tmp)+0] == FS_PART_BOOTABLE             )||
00149                   (fs_g_sector[FS_MBR_OFFSET_PART_ENTRY(u8_tmp)+0] == FS_PART_NO_BOOTABLE          )  )
00150             &&   ((fs_g_sector[FS_MBR_OFFSET_PART_ENTRY(u8_tmp)+4] == FS_PART_TYPE_FAT12           )||
00151                   (fs_g_sector[FS_MBR_OFFSET_PART_ENTRY(u8_tmp)+4] == FS_PART_TYPE_FAT16_INF32M    )||
00152                   (fs_g_sector[FS_MBR_OFFSET_PART_ENTRY(u8_tmp)+4] == FS_PART_TYPE_FAT16_SUP32M    )||
00153                   (fs_g_sector[FS_MBR_OFFSET_PART_ENTRY(u8_tmp)+4] == FS_PART_TYPE_FAT16_SUP32M_BIS)||
00154                   (fs_g_sector[FS_MBR_OFFSET_PART_ENTRY(u8_tmp)+4] == FS_PART_TYPE_FAT32           )||
00155                   (fs_g_sector[FS_MBR_OFFSET_PART_ENTRY(u8_tmp)+4] == FS_PART_TYPE_FAT32_BIS       )) )
00156             {
00157                // A valid partition is found
00158 #if (FS_MULTI_PARTITION == ENABLED)
00159                if( u16_tmp == fs_g_nav.u8_partition )
00160                   break;   // The selected partition is valid
00161                u16_tmp++;
00162 #else
00163                break;
00164 #endif
00165             }
00166          }
00167          if( u8_tmp != 4 )
00168          {
00169             // Partition found -> Get partition position (unit sector) at offset 8
00170             LSB0(fs_gu32_addrsector) = fs_g_sector[FS_MBR_OFFSET_PART_ENTRY(u8_tmp)+8];
00171             LSB1(fs_gu32_addrsector) = fs_g_sector[FS_MBR_OFFSET_PART_ENTRY(u8_tmp)+9];
00172             LSB2(fs_gu32_addrsector) = fs_g_sector[FS_MBR_OFFSET_PART_ENTRY(u8_tmp)+10];
00173             LSB3(fs_gu32_addrsector) = fs_g_sector[FS_MBR_OFFSET_PART_ENTRY(u8_tmp)+11];
00174             fs_gu32_addrsector *= mem_sector_size( fs_g_nav.u8_lun );
00175             continue;   // Go to check PBR of partition
00176          }
00177 
00178          // No MBR found then check PBR
00179 #if (FS_MULTI_PARTITION == ENABLED)
00180          // The device don't have mutli partition, but only one
00181          if ( 0 != fs_g_nav.u8_partition )
00182          {
00183             fs_g_status = FS_ERR_NO_PART;
00184             return FALSE;
00185          }
00186 #endif
00187       }
00188 
00189       //** Check a PBR structure
00190       if ( (fs_g_sector[0] == 0xEB) &&          // PBR Byte 0
00191            (fs_g_sector[2] == 0x90) &&          // PBR Byte 2
00192            ((fs_g_sector[21] & 0xF0) == 0xF0) ) // PBR Byte 21 : Media byte
00193       {
00194          break;   // valid PBR found
00195       }
00196       // PBR not found
00197       fs_g_status = FS_ERR_NO_PART;
00198       return FALSE;
00199    }
00200 
00201    fs_g_status = FS_ERR_NO_SUPPORT_PART;  // by default partition no supported
00202 
00203    // Get sector size of File System (unit 512B)
00204    // To translate from sector disk unit to sector 512B unit
00205    u8_sector_size = HIGH_16_BPB_BytsPerSec/2;
00206 
00207    // Read BPB_SecPerClus (unit sector)
00208    fs_g_nav.u8_BPB_SecPerClus = U8_BPB_SecPerClus * u8_sector_size;
00209 
00210    //** FAT Type determination (algorithm of "Hardware White Paper FAT")
00211    // Get FAT size (unit sector)
00212    LSB( u16_tmp ) = LOW_16_BPB_FATSz16;
00213    MSB( u16_tmp ) = HIGH_16_BPB_FATSz16;
00214    if ( 0==u16_tmp )
00215    {
00216       LSB( u16_tmp ) = LOW0_32_BPB_FATSz32;
00217       MSB( u16_tmp ) = LOW1_32_BPB_FATSz32;
00218       // a large FAT32 isn't supported by this file system
00219       if( (0 != LOW2_32_BPB_FATSz32 )
00220       ||  (0 != LOW3_32_BPB_FATSz32 ) )
00221       {
00222          return FALSE;
00223       }
00224    }
00225    fs_g_nav.u16_fat_size = u16_tmp * u8_sector_size;
00226 
00227    // Get total count of sectors in partition
00228    if ( (0==LOW_16_BPB_TotSec16) && (0==HIGH_16_BPB_TotSec16) )
00229    {
00230       LSB0( u32_tmp ) = LOW0_32_BPB_TotSec32;
00231       LSB1( u32_tmp ) = LOW1_32_BPB_TotSec32;
00232       LSB2( u32_tmp ) = LOW2_32_BPB_TotSec32;
00233       LSB3( u32_tmp ) = LOW3_32_BPB_TotSec32;
00234    }
00235    else
00236    {
00237       LSB0( u32_tmp ) = LOW_16_BPB_TotSec16;
00238       LSB1( u32_tmp ) = HIGH_16_BPB_TotSec16;
00239       LSB2( u32_tmp ) = 0;
00240       LSB3( u32_tmp ) = 0;
00241    }
00242    u32_tmp *= u8_sector_size;   // Translate from sector disk unit to sector 512B unit
00243 
00244    // Compute the offset (unit 512B) between the end of FAT (beginning of root dir in FAT1x) and the beginning of PBR
00245    fs_g_nav.rootdir.seg.u16_pos = FS_NB_FAT * fs_g_nav.u16_fat_size;
00246 
00247    // Compute the root directory size (unit sector), for FAT32 is always 0
00248    LSB( u16_tmp ) = LOW_16_BPB_RootEntCnt;
00249    MSB( u16_tmp ) = HIGH_16_BPB_RootEntCnt;
00250    fs_g_nav.rootdir.seg.u16_size = ((u16_tmp * FS_SIZE_FILE_ENTRY) + ((FS_512B*u8_sector_size)-1)) / (FS_512B*u8_sector_size);
00251    fs_g_nav.rootdir.seg.u16_size *= u8_sector_size;
00252 
00253    // Get number of reserved sector
00254    LSB( u16_tmp ) = LOW_16_BPB_ResvSecCnt;
00255    MSB( u16_tmp ) = HIGH_16_BPB_ResvSecCnt;
00256    // Get FSInfo position
00257    fs_g_nav.u16_offset_FSInfo = (u16_tmp-LOW_16_BPB_FSInfo)*u8_sector_size;
00258    u16_tmp *= u8_sector_size; // number of reserved sector translated in unit 512B
00259 
00260    // Compute the FAT address (unit 512B)
00261    fs_g_nav.u32_ptr_fat = fs_gu32_addrsector + u16_tmp;
00262 
00263    // Compute the offset (unit 512B) between the first data cluster and the FAT beginning
00264    fs_g_nav.u32_offset_data = (FS_NB_FAT * (U32)fs_g_nav.u16_fat_size) + (U32)fs_g_nav.rootdir.seg.u16_size;
00265 
00266    // Compute the data region (clusters space = Total - Sector used) size (unit 512B)
00267    u32_tmp -= ((U32)u16_tmp + fs_g_nav.u32_offset_data);
00268 
00269    // Compute the count of CLUSTER in the data region
00270    // !!!Optimization -> u32_CountofCluster (unit 512B)/ fs_g_nav.u8_BPB_SecPerClus (unit 512B & power of 2)
00271    if (!fs_g_nav.u8_BPB_SecPerClus)
00272      return FALSE;
00273    for( u8_tmp = fs_g_nav.u8_BPB_SecPerClus; u8_tmp!=1 ; u8_tmp >>= 1 )
00274    {
00275      u32_tmp  >>= 1;   // This computation round down
00276    }
00277    fs_g_nav.u32_CountofCluster = u32_tmp+2; // The total of cluster include the two reserved clusters
00278 
00279    // Determine the FAT type
00280    if (u32_tmp < FS_FAT12_MAX_CLUSTERS)
00281    {
00282       // Is FAT 12
00283 #if (FS_FAT_12 == DISABLED)
00284       return FALSE;
00285 #endif
00286       fs_g_nav_fast.u8_type_fat = FS_TYPE_FAT_12;
00287    } else {
00288    if (u32_tmp < FS_FAT16_MAX_CLUSTERS)
00289    {
00290       // Is FAT 16
00291 #if (FS_FAT_16 == DISABLED)
00292       return FS_NO_SUPPORT_PART;
00293 #endif
00294       fs_g_nav_fast.u8_type_fat = FS_TYPE_FAT_16;
00295    } else {
00296       // Is FAT 32
00297 #if (FS_FAT_32 == DISABLED)
00298       return FALSE;
00299 #endif
00300       fs_g_nav_fast.u8_type_fat = FS_TYPE_FAT_32;
00301       // In FAT32, the root dir is like another directory, this one have a cluster list
00302       // Get the first cluster number of root
00303       LSB0( fs_g_nav.rootdir.u32_cluster ) = LOW0_32_BPB_RootClus;
00304       LSB1( fs_g_nav.rootdir.u32_cluster ) = LOW1_32_BPB_RootClus;
00305       LSB2( fs_g_nav.rootdir.u32_cluster ) = LOW2_32_BPB_RootClus;
00306       LSB3( fs_g_nav.rootdir.u32_cluster ) = LOW3_32_BPB_RootClus;
00307    }
00308    }
00309 
00310    return TRUE;
00311 }

Here is the caller graph for this function:

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.

Referenced by nav_partition_serialnumber().

Here is the caller graph for this function:

U32 fat_getfreespace ( void   ) 

This function returns the space free in the partition.

Returns:
the number of sector free
if 0, then error or full

Definition at line 2132 of file fat_unusual.c.

Referenced by fat_getfreespace_percent(), and nav_partition_freespace().

02133 {
02134    U32 u32_nb_free_cluster = 0;
02135 
02136    // Read ALL FAT1
02137    fs_g_cluster.u32_pos = 2;
02138 
02139    if( Is_fat12 )
02140    {  // FAT12 only
02141       for(
02142       ;     fs_g_cluster.u32_pos < fs_g_nav.u32_CountofCluster
02143       ;     fs_g_cluster.u32_pos++ )
02144       {
02145          // Get the value of the cluster
02146          if ( !fat_cluster_val( FS_CLUST_VAL_READ ) )
02147             return 0;
02148 
02149          if ( 0 == fs_g_cluster.u32_val )
02150             u32_nb_free_cluster++;
02151       }
02152    }
02153    else
02154    {
02155       if( Is_fat32 )
02156       {
02157          u32_nb_free_cluster = fat_read_fat32_FSInfo();
02158          if( 0xFFFFFFFF != u32_nb_free_cluster )
02159             goto endof_fat_getfreespace;
02160          u32_nb_free_cluster = 0;
02161       }
02162       // Speed optimization only for FAT16 and FAT32
02163       // init first value used by fat_cluster_readnext()
02164       if( !fat_cluster_val( FS_CLUST_VAL_READ ))
02165          return FALSE;
02166       for(
02167       ;     fs_g_cluster.u32_pos < fs_g_nav.u32_CountofCluster
02168       ;     fs_g_cluster.u32_pos++ )
02169       {
02170          if ( 0 == fs_g_cluster.u32_val )
02171             u32_nb_free_cluster++;
02172          if( !fat_cluster_readnext() )
02173             return FALSE;
02174       }
02175 #if (FSFEATURE_WRITE_COMPLET == (FS_LEVEL_FEATURES & FSFEATURE_WRITE_COMPLET) )
02176       if( Is_fat32 )
02177       {
02178          // Save value for the future call
02179          fat_write_fat32_FSInfo( u32_nb_free_cluster );
02180       }
02181 #endif
02182    }
02183 endof_fat_getfreespace:
02184    return (u32_nb_free_cluster * fs_g_nav.u8_BPB_SecPerClus);
02185 }

Here is the caller graph for this function:

U8 fat_getfreespace_percent ( void   ) 

This function returns the space free in percent.

Returns:
percent of free space (1 to 100) if 0, then error or full
//! More speed than fat_getfreespace() routine but error delta 1%
//! 

Definition at line 2197 of file fat_unusual.c.

Referenced by nav_partition_freespace_percent().

02198 {
02199    U32 u32_nb_free_cluster = 0;
02200    U16 u16_tmp, u16_pos;
02201 
02202    if( Is_fat12 )
02203    {  // No speed optimization necessary on FAT12
02204       return (((fat_getfreespace()/fs_g_nav.u8_BPB_SecPerClus)*100) / fs_g_nav.u32_CountofCluster);
02205    }
02206 
02207 
02208    fs_g_cluster.u32_pos = 2;
02209    // Init first value used by fat_cluster_readnext()
02210    if( !fat_cluster_val( FS_CLUST_VAL_READ ))
02211       return FALSE;
02212 
02213    // The optimization is to
02214    // - read only the LSB byte of cluster
02215    // - read only 1 cluster for 2 clusters
02216    if( Is_fat32 )
02217    {
02218       u32_nb_free_cluster = fat_read_fat32_FSInfo();
02219       if( 0xFFFFFFFF != u32_nb_free_cluster )
02220          goto endof_fat_getfreespace_percent;
02221       u32_nb_free_cluster = 0;
02222 
02223       u16_pos = 2*4;
02224       for(  u16_tmp = fs_g_nav.u16_fat_size
02225       ;     u16_tmp!=0
02226       ;     u16_tmp-- )
02227       {
02228          for( ; u16_pos < 512 ; u16_pos += (2*4) )
02229          {
02230             if( 0 == fs_g_sector[u16_pos] )
02231                u32_nb_free_cluster+=2;
02232          }
02233          // Read next sector in FAT
02234          u16_pos = 0;
02235          fs_gu32_addrsector++;
02236          if( !fat_cache_read_sector( TRUE ))
02237             return 0;
02238       }
02239    }
02240 
02241    if ( Is_fat16 )
02242    {
02243       u16_pos = 2*2;
02244 
02245       for(  u16_tmp = fs_g_nav.u16_fat_size
02246       ;     u16_tmp!=0
02247       ;     u16_tmp-- )
02248       {
02249          for( ; u16_pos < 512 ; u16_pos += (2*2) )
02250          {
02251             if( 0 == fs_g_sector[u16_pos] )
02252                u32_nb_free_cluster+=2;
02253          }
02254          // Read next sector in FAT
02255          u16_pos = 0;
02256          fs_gu32_addrsector++;
02257          if( !fat_cache_read_sector( TRUE ))
02258             return 0;
02259       }
02260    }
02261 
02262    // Compute percent
02263    if( u32_nb_free_cluster > fs_g_nav.u32_CountofCluster )
02264       return 100;
02265    if( u32_nb_free_cluster > ((fs_g_nav.u32_CountofCluster-u32_nb_free_cluster)/256) )
02266    {
02267       // Compute and add a delta error
02268       u32_nb_free_cluster -= ((fs_g_nav.u32_CountofCluster-u32_nb_free_cluster)/256);
02269    }
02270 endof_fat_getfreespace_percent:
02271    return ((u32_nb_free_cluster * 100) / fs_g_nav.u32_CountofCluster);
02272 }

Here is the caller graph for this function:

Bool fat_write_fat32_FSInfo ( U32  u32_nb_free_cluster  ) 

Referenced by fat_cluster_list(), and fat_getfreespace().

Here is the caller graph for this function:

U32 fat_read_fat32_FSInfo ( void   ) 

Referenced by fat_getfreespace(), and fat_getfreespace_percent().

Here is the caller graph for this function:

Bool fat_cluster_list ( U8  opt_action,
Bool  b_for_file 
)

This function gets or clears a cluster list.

Parameters:
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
Returns:
FALSE in case of error, see global value "fs_g_status" for more detail

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 364 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.

00365 {
00366    _MEM_TYPE_FAST_ U32 u32_tmp;
00367    _MEM_TYPE_FAST_ U8 u8_cluster_status;
00368 
00369    fs_g_status = FS_ERR_FS;      // By default system error
00370 
00371    if(  Is_fat32
00372    &&  (FS_CLUST_ACT_CLR == opt_action) )
00373    {
00374 #if (FSFEATURE_WRITE_COMPLET == (FS_LEVEL_FEATURES & FSFEATURE_WRITE_COMPLET) )
00375       // Clear free space information storage in FAT32
00376       if( !fat_write_fat32_FSInfo( 0xFFFFFFFF ))
00377          return FALSE;
00378 #else
00379       return FALSE;
00380 #endif
00381    }
00382 
00383    if ( 0 == fs_g_seg.u32_addr )
00384    {
00385       // Cluster list of root directory
00386       if( FS_CLUST_ACT_CLR == opt_action )
00387          return FALSE;           // Impossible to erase ROOT DIR
00388 
00389       if ( Is_fat12 || Is_fat16 )
00390       {
00391          // For a FAT 12 & 16, the root dir isn't a cluster list
00392          // Check the position
00393          if ( fs_g_seg.u32_size_or_pos < fs_g_nav.rootdir.seg.u16_size )
00394          {
00395             // Compute the start address and the size
00396             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;
00397             fs_g_seg.u32_size_or_pos = fs_g_nav.rootdir.seg.u16_size - fs_g_seg.u32_size_or_pos;
00398             return TRUE;
00399          } else {
00400             fs_g_status = FS_ERR_OUT_LIST;
00401             return FALSE;        // Position outside the root area
00402          }
00403       }
00404       if ( Is_fat32 )
00405       {
00406          // For FAT 32, the root is a cluster list and the first cluster is reading during the mount
00407          fs_g_cluster.u32_pos = fs_g_nav.rootdir.u32_cluster;
00408       }
00409    } else {
00410       // It is the first cluster of a cluster list
00411       fs_g_cluster.u32_pos = fs_g_seg.u32_addr;
00412    }
00413 
00414    // Management of cluster list caches
00415    if( FS_CLUST_ACT_CLR != opt_action )
00416    {
00417       if( fat_cache_clusterlist_update_read( b_for_file ) )
00418          return TRUE;            // Segment found in cache
00419       // Segment not found & cache ready to update
00420    }else{
00421       fat_cache_clusterlist_reset();   // It is a clear action then clear cluster list caches
00422 #if (FS_LEVEL_FEATURES > FSFEATURE_READ)
00423       fat_clear_info_fat_mod();        // Init cache on fat modification range
00424 #endif  // FS_LEVEL_FEATURES
00425    }
00426 
00427    // Init loop with a start segment no found
00428    MSB0( fs_g_seg.u32_addr ) = 0xFF;
00429 
00430    //**** Loop to read the cluster list
00431    while ( 1 )
00432    {
00433       if ( fs_g_seg.u32_size_or_pos < fs_g_nav.u8_BPB_SecPerClus )
00434       {
00435          // The segment starts in this cluster
00436          // Compute the sector address of this cluster
00437          fs_g_seg.u32_addr = ((fs_g_cluster.u32_pos - 2) * fs_g_nav.u8_BPB_SecPerClus)
00438                            + fs_g_nav.u32_ptr_fat + fs_g_nav.u32_offset_data + fs_g_seg.u32_size_or_pos;
00439 
00440          if ( FS_CLUST_ACT_ONE == opt_action )
00441          {
00442             // Compute the maximum size
00443             fs_g_seg.u32_size_or_pos = fs_g_nav.u8_BPB_SecPerClus-fs_g_seg.u32_size_or_pos;
00444             fat_cache_clusterlist_update_finish();
00445             // Send a size of one sector
00446             fs_g_seg.u32_size_or_pos = 1;
00447             return TRUE;
00448          }
00449          // Update the segment size
00450          fs_g_seg.u32_size_or_pos = fs_g_nav.u8_BPB_SecPerClus - LSB0( fs_g_seg.u32_size_or_pos );
00451 
00452          // Take time, during read cluster list on FAT 16 & 32
00453          if( (FS_CLUST_ACT_SEG == opt_action)
00454          &&  (!Is_fat12) )
00455          {
00456             // Init loop with the current cluster
00457             u32_tmp = fs_g_cluster.u32_pos;
00458             if( !fat_cluster_val( FS_CLUST_VAL_READ ))
00459                return FALSE;
00460             // Read cluster list, while this one is continue
00461             while(1)
00462             {
00463                if ( (++fs_g_cluster.u32_pos) != fs_g_cluster.u32_val )
00464                {
00465                   fs_g_cluster.u32_pos--;                   // Recompute previous value
00466                   u32_tmp = fs_g_cluster.u32_pos - u32_tmp; // Compute the size of cluster list
00467                   fs_g_seg.u32_size_or_pos += u32_tmp * fs_g_nav.u8_BPB_SecPerClus;
00468                   break;
00469                }
00470                if( !fat_cluster_readnext() )
00471                   return FALSE;
00472             }
00473          }
00474       }
00475       // Get the cluster value
00476       if( !fat_cluster_val( FS_CLUST_VAL_READ ))
00477          return FALSE;
00478 
00479       // Read and check the status of the new cluster
00480       u8_cluster_status = fat_checkcluster();
00481       if (FS_CLUS_BAD == u8_cluster_status)
00482          return FALSE; // error, end of cluster list
00483 
00484       if (0xFF == MSB0(fs_g_seg.u32_addr))
00485       {
00486          // The beginning of the segment isn't found
00487          if (FS_CLUS_END == u8_cluster_status)
00488          {
00489             u32_tmp = fs_g_seg.u32_size_or_pos;       // Save number of sector remaining
00490 
00491             // Compute the sector address of this last cluster to take time during a futur request with the same cluster list
00492             fs_g_cache_clusterlist[fs_g_u8_current_cache].u32_start -= fs_g_seg.u32_size_or_pos;
00493             fs_g_seg.u32_addr = ((fs_g_cluster.u32_pos - 2) * fs_g_nav.u8_BPB_SecPerClus)
00494                               + fs_g_nav.u32_ptr_fat + fs_g_nav.u32_offset_data;
00495             fs_g_seg.u32_size_or_pos = fs_g_nav.u8_BPB_SecPerClus;
00496             if (FS_CLUST_ACT_CLR != opt_action)
00497                fat_cache_clusterlist_update_finish();
00498 
00499             // The position is outside the cluster list
00500             fs_g_seg.u32_addr = fs_g_cluster.u32_pos; // Send the last cluster value
00501             fs_g_seg.u32_size_or_pos = u32_tmp;       // Restore number of sector remaining
00502             fs_g_status = FS_ERR_OUT_LIST;
00503             return FALSE;
00504          }
00505          // Good cluster then continue
00506          fs_g_seg.u32_size_or_pos -= fs_g_nav.u8_BPB_SecPerClus;
00507 #if (FS_LEVEL_FEATURES > FSFEATURE_READ)
00508          if (FS_CLUST_ACT_CLR == opt_action)
00509          {
00510             if( fs_g_seg.u32_size_or_pos == 0)
00511             {
00512                // At cluster position, set the flag end of cluster list
00513                fs_g_seg.u32_addr = fs_g_cluster.u32_val; // Save the next cluster
00514                fs_g_cluster.u32_val = FS_CLUST_VAL_EOL;
00515                if( !fat_cluster_val( FS_CLUST_VAL_WRITE ))
00516                   return FALSE;
00517                fs_g_cluster.u32_val = fs_g_seg.u32_addr; // Resotre the next cluster
00518                // !!!! It isn't necessary to reinit MSB0( fs_g_seg.u32_addr ) to 0xFF,
00519                // !!!! fs_g_seg.u32_addr will be modified at the beginning of main loop
00520             }
00521          }
00522 #endif  // FS_LEVEL_FEATURES
00523       }
00524       else
00525       {
00526          // The beginning of segment is found
00527          if (FS_CLUST_ACT_SEG == opt_action)
00528          {
00529             if ( (fs_g_cluster.u32_pos+1) != fs_g_cluster.u32_val )
00530             {
00531                // The cluster is not a continue cluster or a invalid cluster
00532                fat_cache_clusterlist_update_finish();
00533                return TRUE;                              // End of segment
00534             }
00535          }
00536 #if (FS_LEVEL_FEATURES > FSFEATURE_READ)
00537          if (FS_CLUST_ACT_CLR == opt_action)
00538          {
00539             //** Clear cluster position
00540             fs_g_seg.u32_addr = fs_g_cluster.u32_val;    // Save the next cluster
00541             fs_g_cluster.u32_val = 0;                    // by default free cluster
00542             // If it is the first cluster (fs_g_seg.u32_size_or_pos <= fs_g_nav.u8_BPB_SecPerClus)
00543             // and doesn't start at the beginning of cluster (fs_g_seg.u32_size_or_pos != fs_g_nav.u8_BPB_SecPerClus)
00544             if (fs_g_seg.u32_size_or_pos < fs_g_nav.u8_BPB_SecPerClus)
00545             {
00546                fs_g_cluster.u32_val = FS_CLUST_VAL_EOL;  // End of cluster list allocated
00547             }
00548             if( !fat_cluster_val( FS_CLUST_VAL_WRITE ))
00549                return FALSE;
00550             fs_g_cluster.u32_val = fs_g_seg.u32_addr;    // Resotre the next cluster
00551             // !!!! It isn't necessary to reinit MSB0( fs_g_seg.u32_addr ) at 0xFF,
00552             // !!!! because it isn't possible that MSB0( fs_g_cluster.val ) = 0xFF.
00553          }
00554 #endif  // FS_LEVEL_FEATURES
00555 
00556          // Check the end of cluster list
00557          if (FS_CLUS_END == u8_cluster_status)
00558          {
00559 #if (FS_LEVEL_FEATURES > FSFEATURE_READ)
00560             if (FS_CLUST_ACT_CLR == opt_action)
00561             {
00562                return fat_update_fat2();
00563             }
00564 #endif  // FS_LEVEL_FEATURES
00565             fat_cache_clusterlist_update_finish();
00566             return TRUE; // End of segment
00567          }
00568 
00569          // Update the segment size
00570          fs_g_seg.u32_size_or_pos += fs_g_nav.u8_BPB_SecPerClus;
00571       }
00572       // HERE, Continue to read the cluster list
00573       // The next cluster is the value of previous cluster
00574       fs_g_cluster.u32_pos = fs_g_cluster.u32_val;
00575    }  // End of main loop
00576 }

Here is the call graph for this function:

void fat_cache_clusterlist_reset ( void   ) 

This function resets the cluster list caches.

Definition at line 882 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.

00883 {
00884    U8 u8_i;
00885    fs_g_u8_current_cache=0;
00886    for( u8_i=0; u8_i<(FS_NB_CACHE_CLUSLIST*2); u8_i++ )
00887    {
00888       // The cache list is splited in two cache (file cluster list and directory cluster list)
00889       fs_g_cache_clusterlist[u8_i].b_cache_file = (u8_i<FS_NB_CACHE_CLUSLIST)?TRUE:FALSE;
00890       fs_g_cache_clusterlist[u8_i].u8_lun = 0xFF;
00891       fs_g_cache_clusterlist[u8_i].u8_level_use = 0xFF;
00892    }
00893 }

Bool fat_cluster_val ( Bool  b_mode  ) 

This function returns or modifys a cluster value in FAT.

Parameters:
b_mode FALSE, to read a cluster value
TRUE, to write a cluster value
Returns:
FALSE in case of error, see global value "fs_g_status" for more detail

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 603 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.

00604 {
00605    _MEM_TYPE_FAST_ U16   u16_offset_fat;
00606    _MEM_TYPE_FAST_ U8    u8_data1, u8_data2;
00607 #define  u8_data3    (LSB(u16_offset_fat)) // Manual overlay
00608 #define  u8_data4    (MSB(u16_offset_fat)) // Manual overlay
00609    _MEM_TYPE_FAST_ PTR_CACHE u8_ptr_cluster;
00610 
00611    //**** Compute the cluster position in FAT (sector address & position in sector)
00612    if ( Is_fat32 )
00613    {
00614       // FAT 32
00615       // Optimization of -> u16_offset_fat = fs_g_cluster.pos * 4 / FS_CACHE_SIZE;
00616       // Optimization of -> u16_offset_fat = fs_g_cluster.pos / 128
00617       u16_offset_fat = fs_g_cluster.u32_pos >> (8-1);
00618 
00619       // Optimization of -> fs_g_u16_pos_fat = (fs_g_cluster.u32_pos * 4) % FS_CACHE_SIZE;
00620       // Optimization of -> fs_g_u16_pos_fat = (fs_g_cluster.u32_pos % 128) * 4
00621       fs_g_u16_pos_fat = ((U16)(LSB0(fs_g_cluster.u32_pos) & 0x7F))<< 2;
00622    }
00623    else if ( Is_fat16 )
00624    {
00625       // FAT 16
00626       // Optimization of -> u16_offset_fat = fs_g_cluster.u32_pos * 2 / FS_CACHE_SIZE = fs_g_cluster.u32_pos / 256;
00627       u16_offset_fat = LSB1(fs_g_cluster.u32_pos);
00628       // Optimization of -> fs_g_u16_pos_fat = (fs_g_cluster.u32_pos * 2) % FS_CACHE_SIZE;
00629       // Optimization of -> fs_g_u16_pos_fat = (fs_g_cluster.u32_pos % 256) * 2
00630       fs_g_u16_pos_fat = ((U16)LSB0(fs_g_cluster.u32_pos)) <<1;
00631    }
00632    else if ( Is_fat12 )
00633    {
00634       // FAT 12
00635       // Optimization of -> fs_g_u16_pos_fat = fs_g_cluster.u32_pos + (fs_g_cluster.u32_pos/ 2)
00636       fs_g_u16_pos_fat = (U16)fs_g_cluster.u32_pos + ((U16)fs_g_cluster.u32_pos >>1);
00637       // Optimization of -> u16_offset_fat = fs_g_cluster.u32_pos / FS_CACHE_SIZE
00638       u16_offset_fat = MSB(fs_g_u16_pos_fat) >> 1;
00639       // Optimization of -> fs_g_u16_pos_fat = fs_g_u16_pos_fat % FS_CACHE_SIZE
00640       MSB( fs_g_u16_pos_fat ) &= 0x01;
00641    }
00642 
00643 #if (FS_LEVEL_FEATURES > FSFEATURE_READ)
00644    if (b_mode)
00645    {
00646       // Update information about FAT modification
00647       if( fs_g_u16_first_mod_fat > u16_offset_fat )
00648       {
00649          fs_g_u16_first_mod_fat = u16_offset_fat;
00650       }
00651       if( fs_g_u16_last_mod_fat < u16_offset_fat )
00652       {
00653          fs_g_u16_last_mod_fat = u16_offset_fat;
00654       }
00655       if ( Is_fat12 )
00656       {  // A cluster may be stored on two sectors
00657          if( fs_g_u16_pos_fat == (FS_CACHE_SIZE-1) )
00658          {  // Count the next FAT sector
00659             if( fs_g_u16_last_mod_fat < (u16_offset_fat+1) )
00660             {
00661                fs_g_u16_last_mod_fat = (u16_offset_fat+1);
00662             }
00663          }
00664       }
00665    }
00666 #endif  // FS_LEVEL_FEATURES
00667 
00668    //**** Read cluster sector in FAT
00669    fs_gu32_addrsector = fs_g_nav.u32_ptr_fat + u16_offset_fat;   // Computed logical sector address
00670    if( !fat_cache_read_sector( TRUE ))
00671       return FALSE;
00672 
00673    // Read cluster information
00674    u8_ptr_cluster = &fs_g_sector[fs_g_u16_pos_fat];
00675    u8_data1 = u8_ptr_cluster[0];
00676    // Remark: if (fs_g_u16_pos_fat+1)=512 then it isn't a mistake, because this value will be erase in next lines
00677    u8_data2 = u8_ptr_cluster[1];
00678    u8_data3 = u8_ptr_cluster[2];
00679    u8_data4 = u8_ptr_cluster[3];
00680 
00681    if ( Is_fat12 )
00682    {   // A cluster may be stored on two sectors
00683       if(  fs_g_u16_pos_fat == (FS_CACHE_SIZE-1) )
00684       {  // Go to next sector
00685          fs_gu32_addrsector++;
00686          if( !fat_cache_read_sector( TRUE ))
00687            return FALSE;
00688          u8_data2 = fs_g_sector[0];
00689       }
00690    }
00691 
00692    if (FALSE == b_mode)
00693    {
00694       //**** Read the cluster value
00695       LSB0( fs_g_cluster.u32_val ) = u8_data1;  // FAT 12,16,32
00696       LSB1( fs_g_cluster.u32_val ) = u8_data2;  // FAT 12,16,32
00697 
00698       if ( Is_fat32 )
00699       {  // FAT 32
00700          LSB2( fs_g_cluster.u32_val ) = u8_data3;
00701          LSB3( fs_g_cluster.u32_val ) = u8_data4 & 0x0F; // The high 4 bits are reserved
00702       }
00703       else
00704       {  // FAT 12 & 16 don't use the high bytes
00705          LSB2( fs_g_cluster.u32_val ) = 0;
00706          LSB3( fs_g_cluster.u32_val ) = 0;
00707 
00708          // FAT 12 translate 16bits value to 12bits
00709          if ( Is_fat12 )
00710          {
00711             if ( 0x01 & LSB0(fs_g_cluster.u32_pos) )
00712             {  // Readed cluster is ODD
00713                LSB0( fs_g_cluster.u32_val ) = (LSB1( fs_g_cluster.u32_val ) <<4 ) + (LSB0( fs_g_cluster.u32_val ) >>4 );
00714                LSB1( fs_g_cluster.u32_val ) =  LSB1( fs_g_cluster.u32_val ) >>4 ;
00715             }
00716             else
00717             {  // Readed cluster is EVEN
00718                LSB1( fs_g_cluster.u32_val ) &= 0x0F;
00719             }
00720          }
00721       }
00722    } else {
00723 #if (FS_LEVEL_FEATURES > FSFEATURE_READ)
00724       //**** Write the cluster value
00725       if ( Is_fat12 )
00726       {
00727          // FAT 12, translate cluster value
00728          if ( 0x01 & LSB0(fs_g_cluster.u32_pos) )
00729          {  // Cluster writing is ODD
00730             u8_data1 = (u8_data1 & 0x0F) + (LSB0( fs_g_cluster.u32_val )<<4);
00731             u8_data2 = (LSB1( fs_g_cluster.u32_val )<<4) + (LSB0( fs_g_cluster.u32_val )>>4) ;
00732          } else {
00733             // Cluster writing is EVEN
00734             u8_data1 = LSB0( fs_g_cluster.u32_val );
00735             u8_data2 = (u8_data2 & 0xF0) + (LSB1( fs_g_cluster.u32_val ) & 0x0F) ;
00736          }
00737 
00738          // A cluster may be stored on two sectors
00739          if( fs_g_u16_pos_fat == (FS_CACHE_SIZE-1) )
00740          {
00741             fs_g_sector[0] = u8_data2;
00742             fat_cache_mark_sector_as_dirty();
00743             // Go to previous sector
00744             fs_gu32_addrsector--;
00745             if( !fat_cache_read_sector( TRUE ))
00746               return FALSE;
00747             // Modify the previous sector
00748             fs_g_sector[ FS_CACHE_SIZE-1 ] = u8_data1;
00749             fat_cache_mark_sector_as_dirty();
00750             return TRUE;
00751          }
00752       }
00753       else
00754       {
00755          // FAT 16 & 32
00756          u8_data1 = LSB0( fs_g_cluster.u32_val );
00757          u8_data2 = LSB1( fs_g_cluster.u32_val );
00758          if ( Is_fat32 )
00759          {  // FAT 32
00760             u8_ptr_cluster[2] = LSB2( fs_g_cluster.u32_val );
00761             u8_ptr_cluster[3] = LSB3( fs_g_cluster.u32_val ) + (u8_data4 & 0xF0); // The high 4 bits are reserved
00762          }
00763       }
00764       // Here for FAT 32, 16 & 12 (only if the cluster values are in the same sector)
00765       u8_ptr_cluster[0] = u8_data1;
00766       u8_ptr_cluster[1] = u8_data2;
00767       fat_cache_mark_sector_as_dirty();
00768 #else
00769       fs_g_status = FS_ERR_COMMAND;
00770       return FALSE;
00771 #endif  // FS_LEVEL_FEATURES
00772    }
00773 
00774    return TRUE;
00775 #undef  u8_data3    // end of Manual overlay
00776 #undef  u8_data4    // end of Manual overlay
00777 }

Here is the call graph for this function:

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

Returns:
FALSE in case of error, see global value "fs_g_status" for more detail

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 798 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.

00799 {
00800    // Compute the next cluster position in FAT
00801    if ( Is_fat32 )
00802    {
00803       fs_g_u16_pos_fat += 4;
00804    }else{
00805       // Is_fat16
00806       fs_g_u16_pos_fat += 2;
00807    }
00808 
00809    // Check if next cluster is in internal cache
00810    if( FS_CACHE_SIZE == fs_g_u16_pos_fat )
00811    {
00812       // Update cache
00813       fs_g_u16_pos_fat = 0;
00814       fs_gu32_addrsector++;
00815       if( !fat_cache_read_sector( TRUE ))
00816          return FALSE;
00817    }
00818 
00819    //**** Read the cluster value
00820    LSB0( fs_g_cluster.u32_val ) = fs_g_sector[fs_g_u16_pos_fat+0];  // FAT 16,32
00821    LSB1( fs_g_cluster.u32_val ) = fs_g_sector[fs_g_u16_pos_fat+1];  // FAT 16,32
00822 
00823    if ( Is_fat32 )
00824    {  // FAT 32
00825       LSB2( fs_g_cluster.u32_val ) = fs_g_sector[fs_g_u16_pos_fat+2];
00826       LSB3( fs_g_cluster.u32_val ) = fs_g_sector[fs_g_u16_pos_fat+3];
00827    }
00828    return TRUE;
00829 }

Here is the call graph for this function:

U8 fat_checkcluster ( void   ) 

This function checks the cluster value.

Returns:
value status
FS_CLUS_OK Value correct
FS_CLUS_BAD Value bad
FS_CLUS_END It is a end of list
//! Global variable used
//! IN :
//!   fs_g_cluster.u32_val       value to check
//! 

Definition at line 845 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.

00846 {
00847   if ( !fs_g_cluster.u32_val )
00848     return FS_CLUS_BAD;
00849 
00850   // Cluster bad if (FAT12 == 0x0FF7) (FAT16 == 0xFFF7) (FAT32 == 0x0FFFFFF7)
00851   // Last cluster if (FAT12 > 0x0FF7) (FAT16 > 0xFFF7) (FAT32 > 0x0FFFFFF7)
00852   if ( Is_fat32 )
00853   {
00854     if (fs_g_cluster.u32_val >= 0x0FFFFFF8)
00855       return FS_CLUS_END;
00856     else if (fs_g_cluster.u32_val == 0x0FFFFFF7)
00857       return FS_CLUS_BAD;
00858   }
00859   else if ( Is_fat16 )
00860   {
00861     if (fs_g_cluster.u32_val >= 0xFFF8)
00862       return FS_CLUS_END;
00863     else if (fs_g_cluster.u32_val == 0xFFF7)
00864       return FS_CLUS_BAD;
00865   }
00866   else if ( Is_fat12 )
00867   {
00868     if (fs_g_cluster.u32_val >= 0xFF8)
00869       return FS_CLUS_END;
00870     else if (fs_g_cluster.u32_val == 0xFF7)
00871       return FS_CLUS_BAD;
00872   }
00873 
00874   return FS_CLUS_OK;
00875 }

Bool fat_allocfreespace ( void   ) 

void fat_clear_info_fat_mod ( void   ) 

Referenced by fat_cluster_list().

Here is the caller graph for this function:

Bool fat_clear_cluster ( void   ) 

Bool fat_update_fat2 ( void   ) 

Referenced by fat_cluster_list().

Here is the caller graph for this function:

Bool fat_read_file ( U8  mode  ) 

This function gets or clears a cluster list at the current position in the selected file.

Parameters:
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
Returns:
FALSE in case of error, see global value "fs_g_status" for more detail

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 1035 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.

01036 {
01037    U32   u32_sector_pos;
01038 
01039    // Compute sector position
01040    u32_sector_pos = fs_g_nav_entry.u32_pos_in_file >> FS_512B_SHIFT_BIT;
01041 
01042    if(FS_CLUST_ACT_ONE  == mode)
01043    {
01044       if( (fs_g_sectorcache.u8_lun                 == fs_g_nav.u8_lun )
01045       &&  (fs_g_sectorcache.u32_clusterlist_start  == fs_g_nav_entry.u32_cluster )
01046       &&  (fs_g_sectorcache.u32_clusterlist_pos    == u32_sector_pos ) )
01047       {
01048          return TRUE;      // The internal cache contains the sector ascked
01049       }
01050    }
01051    else
01052    {
01053       if( FS_CLUST_ACT_CLR == mode )
01054       {
01055          // Clear cluster list
01056          if( 0 == fs_g_nav_entry.u32_cluster )
01057             return TRUE;   // No cluster list is linked with the file, then no clear is necessary
01058 
01059          if(0 != (fs_g_nav_entry.u32_pos_in_file & FS_512B_MASK) )
01060          {
01061             // The actual sector is used, then start clear on the next sector
01062             u32_sector_pos++;
01063          }
01064       }
01065    }
01066 
01067    // Get the segment which start at the current position
01068    fs_g_seg.u32_addr = fs_g_nav_entry.u32_cluster;
01069    fs_g_seg.u32_size_or_pos = u32_sector_pos;
01070    if( FS_CLUST_ACT_ONE != mode )
01071    {
01072       if( fat_cluster_list( mode, TRUE ) )
01073          return TRUE;      // Get or clear segment OK
01074    }
01075    else
01076    {
01077       if( fat_cluster_list( FS_CLUST_ACT_SEG, TRUE ) )   // Read all segment
01078       {
01079          // Read the sector corresponding at the position file (= first sector of segment)
01080          fs_gu32_addrsector = fs_g_seg.u32_addr ;
01081          if( fat_cache_read_sector( TRUE ) )
01082          {
01083             fs_g_sectorcache.u32_clusterlist_start  = fs_g_nav_entry.u32_cluster;
01084             fs_g_sectorcache.u32_clusterlist_pos    = u32_sector_pos;
01085             return TRUE;
01086          }
01087       }
01088    }
01089    if( (FS_CLUST_ACT_CLR == mode       )
01090    &&  (FS_ERR_OUT_LIST  == fs_g_status) )
01091    {
01092       // It is possible to clear nothing
01093       return TRUE;
01094    }
01095    return FALSE;
01096 }

Here is the call graph for this function:

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.

Returns:
FALSE in case of error, see global value "fs_g_status" for more detail

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 1195 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.

01196 {
01197    U32 u32_cluster_pos;
01198 
01199    // Compute the cluster list position corresponding of the current entry
01200    u32_cluster_pos = fs_g_nav_fast.u16_entry_pos_sel_file >> (FS_512B_SHIFT_BIT - FS_SHIFT_B_TO_FILE_ENTRY);
01201 
01202    if( (fs_g_sectorcache.u8_lun                 == fs_g_nav.u8_lun )
01203    &&  (fs_g_sectorcache.u32_clusterlist_start  == fs_g_nav.u32_cluster_sel_dir )
01204    &&  (fs_g_sectorcache.u32_clusterlist_pos    == u32_cluster_pos ) )
01205    {
01206          return TRUE;      // The internal cache contains the sector ascked
01207    }
01208 
01209    // Get sector address corresponding at cluster list position
01210    fs_g_seg.u32_addr = fs_g_nav.u32_cluster_sel_dir;
01211    fs_g_seg.u32_size_or_pos = u32_cluster_pos;
01212    if( fat_cluster_list( FS_CLUST_ACT_ONE, FALSE ) )
01213    {
01214       // Read the sector
01215       fs_gu32_addrsector = fs_g_seg.u32_addr;
01216       if( fat_cache_read_sector( TRUE ) )
01217       {
01218          // Update information about internal sector cache
01219          fs_g_sectorcache.u32_clusterlist_start  = fs_g_nav.u32_cluster_sel_dir;
01220          fs_g_sectorcache.u32_clusterlist_pos    = u32_cluster_pos;
01221          return TRUE;
01222       }
01223    }
01224    return FALSE;
01225 }

Here is the call graph for this function:

Bool fat_initialize_dir ( void   ) 

Bool fat_entry_check ( Bool  b_type  ) 

This function checks the entry.

Parameters:
b_type entry type to compare (FS_FILE or FS_DIR)
Returns:
TRUE, the entry is a short entry and correspond to b_type

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 1243 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.

01244 {
01245    PTR_CACHE u8_ptr_entry;
01246    U8 u8_first_byte, u8_seconde_byte;
01247    U8 u8_attribut;
01248 
01249    u8_ptr_entry = fat_get_ptr_entry();
01250 
01251    u8_first_byte = u8_ptr_entry[0];
01252    if ( FS_ENTRY_END == u8_first_byte )
01253    {
01254       fs_g_status = FS_ERR_ENTRY_EMPTY;   // end of directory
01255       return FALSE;
01256    }
01257    fs_g_status = FS_ERR_ENTRY_BAD;        // by default BAD ENTRY
01258    if ( FS_ENTRY_DEL == u8_first_byte )      { return FALSE;   } // entry deleted
01259    if (   '.'  == u8_first_byte )            { return FALSE;   } // current dir "."
01260    u8_seconde_byte = u8_ptr_entry[1];
01261    if ( ('.'  == u8_first_byte)
01262    &&   ('.'  == u8_seconde_byte) )          { return FALSE;   } // current dir ".."
01263 
01264    // Check attribut
01265    u8_attribut = u8_ptr_entry[11];
01266    if ( FS_ATTR_VOLUME_ID & u8_attribut )    { return FALSE;   } // volume id
01267    // Optimization, this line isn't necessary because the next test control this case
01268    // if ( FS_ATTR_LFN_ENTRY == *u8_ptr_entry) { return FALSE;   } // long file name
01269 
01270    // Check entry type
01271    if( FS_ATTR_DIRECTORY & u8_attribut )
01272    {
01273       return (FS_DIR == b_type);
01274    }else{
01275       return (FS_FILE == b_type);
01276    }
01277 }

Here is the call graph for this function:

Bool fat_entry_checkext ( FS_STRING  sz_filter  ) 

This function checks the file extension.

Parameters:
sz_filter extension filter is a ASCII string (ex: "mp3,w*" )
Returns:
TRUE, the file name have a good extension

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 1294 of file fat.c.

References FALSE, fat_get_ptr_entry(), and TRUE.

01295 {
01296    PTR_CACHE u8_ptr_entry;
01297    U8 u8_i, u8_filter_char, u8_entry_char;
01298 
01299    u8_ptr_entry = fat_get_ptr_entry();
01300 
01301    // Compare the extension with filter
01302    for( u8_i=0 ; u8_i<3 ; u8_i++)
01303    {
01304       u8_filter_char = *sz_filter;
01305       if ('*' == u8_filter_char)
01306          break; // All extension is good
01307 
01308       u8_entry_char = u8_ptr_entry[8+u8_i];
01309 
01310       // Compare the extension filter to extension file (this one ignore the case)
01311       if( (u8_filter_char!=  u8_entry_char     )
01312       &&  (u8_filter_char!= (u8_entry_char+('a'-'A'))) )
01313       {
01314          if ( (',' == u8_filter_char)
01315          ||   ( 0  == u8_filter_char) )
01316          {
01317            // It is the end of filter
01318            if (' ' == u8_entry_char)
01319               break; // it is the end of extension file -> extension good
01320          }
01321          // here, bad extension
01322 
01323          // Search the next filter
01324          while( ',' != u8_filter_char )
01325          {
01326             if (0  == u8_filter_char)
01327             {
01328                return FALSE;   // it is the last filter
01329             }
01330             sz_filter++;
01331             u8_filter_char = *sz_filter;
01332          }
01333          u8_i = 0xFF;          // restart loop compare
01334       }
01335       sz_filter++; // go to next char of filter
01336    }
01337 
01338    return TRUE; // It is a good extension
01339 }

Here is the call graph for this function:

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 1353 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.

01354 {
01355    PTR_CACHE ptr_entry;
01356 
01357    ptr_entry = fat_get_ptr_entry();
01358 
01359    // Get attribut
01360    ptr_entry+= 11;
01361    fs_g_nav_entry.u8_attr = ptr_entry[0];
01362 
01363    // Get the first cluster of the file cluster list
01364    ptr_entry += (20-11);
01365    LSB2(fs_g_nav_entry.u32_cluster) = ptr_entry[0];
01366    LSB3(fs_g_nav_entry.u32_cluster) = ptr_entry[1];
01367    ptr_entry += (26-20);
01368    LSB0(fs_g_nav_entry.u32_cluster) = ptr_entry[0];
01369    LSB1(fs_g_nav_entry.u32_cluster) = ptr_entry[1];
01370 
01371    // Get the size of file
01372    ptr_entry += (28-26);
01373    LSB0(fs_g_nav_entry.u32_size) = ptr_entry[0];
01374    LSB1(fs_g_nav_entry.u32_size) = ptr_entry[1];
01375    LSB2(fs_g_nav_entry.u32_size) = ptr_entry[2];
01376    LSB3(fs_g_nav_entry.u32_size) = ptr_entry[3];
01377 }

Here is the call graph for this function:

Bool fat_entry_is_dir ( void   ) 

This function checks if the entry file is a directory.

Returns:
TRUE, this entry is a directory

FALSE, otherwise

Definition at line 1385 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.

01386 {
01387    fs_g_status = FS_ERR_NO_DIR;
01388    return (FS_ATTR_DIRECTORY & fs_g_nav_entry.u8_attr);
01389 }

void fat_clear_entry_info_and_ptr ( void   ) 

This function resets the selection pointers.

Definition at line 1394 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.

void fat_write_entry_file ( void   ) 

Referenced by file_close().

Here is the caller graph for this function:

Bool fat_entry_shortname ( FS_STRING  sz_name,
U8  u8_size_max,
Bool  b_mode 
)

This function returns or compares the short name entry.

Parameters:
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)
Returns:
FALSE, in case of error, see global value "fs_g_status" for more detail

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 1476 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.

01477 {
01478    Bool b_extension_nostart = TRUE;
01479    U8 u8_pos_name;
01480    U8 u8_entry_char, u8_szname_char;
01481    PTR_CACHE ptr_entry;
01482    U8 u8_pos_entry;
01483 
01484    fs_g_status = FS_ERR_NAME_INCORRECT;  // by default the name don't corresponding at filter name
01485 
01486    u8_pos_name = 0;
01487    u8_pos_entry = 0;
01488    ptr_entry = fat_get_ptr_entry();
01489 
01490    // for each characters of short name
01491    while( 1 )
01492    {
01493       if( FS_SIZE_SFNAME == u8_pos_entry )
01494       {
01495          u8_entry_char = 0;   // end of name
01496       }
01497       else
01498       {
01499          u8_entry_char = ptr_entry[ u8_pos_entry ];
01500          if( ((FS_SIZE_SFNAME_WITHOUT_EXT == u8_pos_entry) && b_extension_nostart)  // end of name and '.' character no writed
01501          ||  ( ' ' == u8_entry_char) )
01502          {
01503             // end of name or extension
01504             if( (FS_SIZE_SFNAME_WITHOUT_EXT >= u8_pos_entry)         // End of name without extension
01505             &&  (' ' != ptr_entry[ FS_SIZE_SFNAME_WITHOUT_EXT ]) )   // extension exists
01506             {
01507                // go to extension position
01508                b_extension_nostart = FALSE;
01509                u8_pos_entry = FS_SIZE_SFNAME_WITHOUT_EXT-1;
01510                u8_entry_char = '.';
01511             }
01512             else
01513             {
01514                u8_entry_char = 0;                                    // end of name
01515             }
01516          }
01517       }
01518 
01519       if( FS_NAME_GET == b_mode )
01520       {
01521          if( !g_b_string_length )
01522          {
01523             if(u8_pos_name >= (u8_size_max-1))
01524                u8_entry_char = 0;                                    // buffer full then force end of string
01525 
01526             if( ('A'<=u8_entry_char) && (u8_entry_char<='Z'))
01527                u8_entry_char += ('a'-'A');                           // display short name in down case
01528 
01529             if( Is_unicode )
01530             {
01531                ((FS_STR_UNICODE)sz_name)[0] = u8_entry_char;
01532             }else{
01533                sz_name[0] = u8_entry_char;
01534             }
01535          }
01536       }
01537       else
01538       {
01539          // Compare the name
01540          if( Is_unicode
01541          && (0 != MSB(((FS_STR_UNICODE)sz_name)[0])) )
01542          {
01543             // The UNICODE is not possibled in short name
01544             return FALSE;
01545          }
01546 
01547          if( Is_unicode )
01548          {
01549             u8_szname_char = ((FS_STR_UNICODE)sz_name)[0];
01550          }else{
01551             u8_szname_char = sz_name[0];
01552          }
01553          if ('*' == u8_szname_char)
01554          {  // end of filter name which autorise all next character
01555             return TRUE;   //*** The name is correct ***
01556          }
01557 
01558          if( (0 != u8_entry_char) || (('\\' != u8_szname_char) && ('/' != u8_szname_char)) )
01559          {
01560             if((u8_szname_char != u8_entry_char)
01561             && (u8_szname_char != (u8_entry_char+('a'-'A'))) )  // no case sensitive
01562                return FALSE;  // short name not equal
01563          }
01564       }
01565 
01566       // For each characters
01567       if (0 == u8_entry_char)
01568       {
01569          if( g_b_string_length )
01570          {
01571             ((FS_STR_UNICODE)sz_name)[0] = u8_pos_name+1;      // Get length name
01572          }
01573          return TRUE;   // End of test correct or end of get name
01574       }
01575       if( !g_b_string_length )
01576       {
01577          sz_name += (Is_unicode? 2 : 1 );
01578       }
01579       u8_pos_name++;
01580       u8_pos_entry++;
01581    }
01582 }

Here is the call graph for this function:

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.

Parameters:
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)
Returns:
FALSE is not the end of long name, or in case of error, see global value "fs_g_status" for more detail

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 1607 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.

01608 {
01609    U8 u8_pos_name;
01610    PTR_CACHE ptr_entry;
01611    U16 u16_unicode_entry;
01612    U16 u16_unicode_szname;
01613 
01614    ptr_entry = fat_get_ptr_entry();
01615 
01616    if( (FS_ENTRY_END == *ptr_entry )            // end of directory
01617    ||  (FS_ENTRY_DEL == *ptr_entry )            // entry deleted
01618    ||  (FS_ATTR_LFN_ENTRY != ptr_entry[11]) )   // no long name
01619    {
01620       fs_g_status = FS_ERR_ENTRY_BAD;
01621       return FALSE;
01622    }
01623 
01624    if( g_b_string_length )
01625    {
01626       if ( 0 == (FS_ENTRY_LFN_LAST & *ptr_entry))
01627       {
01628          // no necessary -> ((FS_STR_UNICODE)sz_name)[0] = FS_SIZE_LFN_ENTRY;
01629          fs_g_status = FS_NO_LAST_LFN_ENTRY;
01630          return FALSE;                          // Other entry long name
01631       }
01632    }
01633 
01634    ptr_entry++;                                 // The long name start at offset 1 of the entry file
01635 
01636    u8_pos_name=0;
01637    while( 1 )
01638    {
01639       LSB(u16_unicode_entry) = ptr_entry[0];
01640       MSB(u16_unicode_entry) = ptr_entry[1];
01641       if( FS_NAME_GET == b_mode )
01642       {
01643          if( !g_b_string_length )
01644          {
01645             // Check the end of buffer
01646             if( u8_pos_name>=(u8_size_max-1) )
01647             {
01648                // Write end of string
01649                if( Is_unicode )
01650                {
01651                   ((FS_STR_UNICODE)sz_name)[0] = 0;
01652                }else{
01653                   sz_name[0] = 0;
01654                }
01655                return TRUE;                     // the buffer is full
01656             }
01657             // Read and store the long name
01658             if( Is_unicode )
01659             {
01660                ((FS_STR_UNICODE)sz_name)[0] = u16_unicode_entry;
01661             }else{
01662                sz_name[0] = (U8)u16_unicode_entry;
01663             }
01664          }
01665       }
01666       else
01667       {
01668          if( Is_unicode )
01669          {
01670             u16_unicode_szname = ((FS_STR_UNICODE)sz_name)[0];
01671          }else{
01672             u16_unicode_szname = sz_name[0];
01673          }
01674          // Check the name
01675          if( '*' == u16_unicode_szname )
01676          {  // end of filter name which autorise all next character
01677             return TRUE;   //*** The name is correct ***
01678          }
01679 
01680          if( ((0 != u16_unicode_entry ) || (( '\\' != u16_unicode_szname) && ( '/' != u16_unicode_szname)) )
01681          &&  ((u16_unicode_szname != (u16_unicode_entry+('a'-'A'))) || b_match_case)
01682          &&  ((u16_unicode_szname != (u16_unicode_entry-('a'-'A'))) || b_match_case)
01683          &&  (u16_unicode_szname != u16_unicode_entry) )
01684          {
01685            fs_g_status = FS_ERR_NAME_INCORRECT; //  The name don't corresponding at filter name
01686            return FALSE;
01687          }
01688       }
01689 
01690       if( 0 == u16_unicode_entry)
01691       {
01692          if( g_b_string_length )
01693          {
01694             ((FS_STR_UNICODE)sz_name)[0] = u8_pos_name+1;
01695          }
01696          return TRUE;                           // Last long name entry
01697       }
01698       if( 4 == u8_pos_name )
01699          ptr_entry += 3;                        // Go to second character
01700 
01701       if( 10 == u8_pos_name )
01702          ptr_entry += 2;                        // Go to third character
01703 
01704       if( 12 == u8_pos_name )
01705       {  // End of entry long name
01706          ptr_entry -= (FS_SIZE_FILE_ENTRY-2);   // Go to the first byte of the file entry
01707          if ( 0 == (FS_ENTRY_LFN_LAST & ptr_entry[0]))
01708          {
01709             fs_g_status = FS_NO_LAST_LFN_ENTRY;
01710             return FALSE;                       // Other long name entry is present
01711          }
01712          else
01713          {  // It is the last long name entry
01714             // then it is the end of name
01715             if( (FS_NAME_GET == b_mode) && g_b_string_length )
01716             {
01717                ((FS_STR_UNICODE)sz_name)[0] = 14;
01718                return TRUE;
01719             }
01720             sz_name += (Is_unicode? 2 : 1 );
01721             if( FS_NAME_GET == b_mode )
01722             {
01723                // Write end of string UNICODE
01724                if( Is_unicode )
01725                {
01726                   ((FS_STR_UNICODE)sz_name)[0] = 0;
01727                }else{
01728                   sz_name[0] = 0;
01729                }
01730                return TRUE;
01731             }
01732             else
01733             {
01734                // if it is the end of filter
01735                if( Is_unicode )
01736                {
01737                   u16_unicode_szname = ((FS_STR_UNICODE)sz_name)[0];
01738                }else{
01739                   u16_unicode_szname = sz_name[0];
01740                }
01741                return fat_check_eof_name(u16_unicode_szname);
01742             }
01743          }
01744       }
01745 
01746       if( !g_b_string_length )
01747       {
01748          sz_name += (Is_unicode? 2 : 1 );
01749       }
01750       u8_pos_name++;
01751       ptr_entry+=2;
01752    }
01753 }

Here is the call graph for this function:

Bool fat_check_eof_name ( U16  character  ) 

Check end of name.

Parameters:
character value of character to check
Returns:
TRUE, it is a character to signal a end of name (0,'\','/')

FALSE, otherwise

Definition at line 1763 of file fat.c.

01764 {
01765    return (('\0'==character)||('\\'==character)||('/'==character));
01766 }

PTR_CACHE fat_get_ptr_entry ( void   ) 

This function returns a cache pointer on the current entry.

Returns:
a pointer on the internal cache

Definition at line 1773 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.

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.

Parameters:
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 1221 of file fat_unusual.c.

Referenced by nav_file_dateget().

01222 {
01223    PTR_CACHE ptr_entry;
01224 
01225    ptr_entry = fat_get_ptr_entry();
01226    if( FS_DATE_LAST_WRITE == type_date )
01227    {
01228       fat_translatedate_number_to_ascii( sz_date , &ptr_entry[22] , FALSE );
01229    }
01230    else
01231    {
01232       fat_translatedate_number_to_ascii( sz_date , &ptr_entry[13] , TRUE );
01233    }
01234 }

Here is the caller graph for this function:

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 
)

Referenced by nav_partition_label().

Here is the caller graph for this function:

Bool fat_cache_read_sector ( Bool  b_load  ) 

This function loads a memory sector in internal cache sector.

Parameters:
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
Returns:
FALSE in case of error, see global value "fs_g_status" for more detail

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 1794 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.

01795 {
01796    // Check if the sector asked is the same in cache
01797    if( (fs_g_sectorcache.u8_lun     == fs_g_nav.u8_lun )
01798    &&  (fs_g_sectorcache.u32_addr   == fs_gu32_addrsector ) )
01799    {
01800       return TRUE;
01801    }
01802 
01803    // Write previous cache before fill cache with a new sector
01804    if( !fat_cache_flush())
01805       return FALSE;
01806 
01807    // Delete informations about the caches
01808    fat_cache_reset();
01809 
01810    // Init sector cache
01811    fs_g_sectorcache.u32_addr = fs_gu32_addrsector;
01812    if( b_load )
01813    {
01814       // Load the sector from memory
01815       if( CTRL_GOOD != memory_2_ram( fs_g_nav.u8_lun  , fs_g_sectorcache.u32_addr, fs_g_sector))
01816       {
01817          fs_g_status = FS_ERR_HW;
01818          return FALSE;
01819       }
01820    }
01821    // Valid sector cache
01822    fs_g_sectorcache.u8_lun = fs_g_nav.u8_lun;
01823    return TRUE;
01824 }

Here is the call graph for this function:

void fat_cache_reset ( void   ) 

This function resets the sector cache.

Definition at line 1829 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.

void fat_cache_clear ( void   ) 

void fat_cache_mark_sector_as_dirty ( void   ) 

Referenced by fat_cluster_val().

Here is the caller graph for this function:

Bool fat_cache_flush ( void   ) 

This function flushs the sector cache on the memory if necessary.

Returns:
FALSE in case of error, see global value "fs_g_status" for more detail

TRUE otherwise

Definition at line 1860 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.

01861 {
01862    // If the cache is modified, then write the sector cache on the device
01863    if ( TRUE == fs_g_sectorcache.u8_dirty )
01864    {
01865       fs_g_sectorcache.u8_dirty = FALSE; // Always clear, although an error occur
01866       if( mem_wr_protect( fs_g_sectorcache.u8_lun  ))
01867       {
01868          fs_g_status = FS_LUN_WP;
01869          return FALSE;
01870       }
01871       if (CTRL_GOOD != ram_2_memory( fs_g_sectorcache.u8_lun , fs_g_sectorcache.u32_addr , fs_g_sector ))
01872       {
01873          fs_g_status = FS_ERR_HW;
01874          return FALSE;
01875       }
01876    }
01877    return TRUE;
01878 }

Here is the call graph for this function:


Variable Documentation

Bool g_b_unicode

Variables to select string format (initialised in nav_reset()).

Referenced by nav_reset(), nav_string_ascii(), and nav_string_unicode().

Bool g_b_string_length

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

Bool g_b_no_check_disk

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]

Referenced by fat_cache_flush(), fat_cache_read_sector(), fat_cluster_readnext(), fat_cluster_val(), fat_get_nbpartition(), fat_get_ptr_entry(), fat_getfreespace_percent(), fat_mount(), stream_mem_to_mem(), and ushell_cmd_perform_access().

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


Generated on Wed Sep 23 09:17:06 2009 for ATMEL by  doxygen 1.5.3