fat.h File Reference


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.

#include "fs_com.h"

Go to the source code of this file.

Data Structures

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

Variables used to manage the sector cache

typedef U8 _MEM_TYPE_SLOW_ * PTR_CACHE
_GLOBEXT_ _MEM_TYPE_SLOW_ U8 fs_g_sector [FS_CACHE_SIZE]
 Use "FAT sector cache" to store a sector from a file (see file_putc(), file_getc(), file_read_buf(), file_write_buf()).
_GLOBEXT_ _MEM_TYPE_SLOW_
Fs_sector_cache 
fs_g_sectorcache
_GLOBEXT_ _MEM_TYPE_SLOW_ U32 fs_gu32_addrsector
 Store the address of futur cache (unit 512B).

Defines

#define _GLOBEXT_   extern
#define FS_BUF_SECTOR_EMPTY   0xFF
 Signal that sector cache is not valid.
#define FS_MBR_OFFSET_PART_ENTRY(num)   ((U16)((U16)(0x1BE)+(0x10 * num)))
 Position (unit byte) in the MBR of a partition entry.
#define Is_fat12   (FS_TYPE_FAT_12 == fs_g_nav_fast.u8_type_fat)
#define Is_fat16   (FS_TYPE_FAT_16 == fs_g_nav_fast.u8_type_fat)
#define Is_fat32   (FS_TYPE_FAT_32 == fs_g_nav_fast.u8_type_fat)
#define Is_unicode   (g_b_unicode)
Macro to check the file open mode
#define Fat_file_close()   (fs_g_nav_entry.u8_open_mode =0 )
#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 )
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_CACHE_SIZE   512
#define FS_MASK_SIZE_OF_SECTOR   FS_512B_MASK
#define FS_SHIFT_B_TO_SECTOR   FS_512B_SHIFT_BIT
#define FS_SIZE_OF_SECTOR   FS_512B
Constants used in MBR sector
#define FS_BOOT_SIGN   0x29
#define FS_PART_BOOTABLE   0x80
#define FS_PART_HARD_DISK   0x81
#define FS_PART_NO_BOOTABLE   0x00
#define FS_PART_NO_REMOVE_MEDIA   0xF8
#define FS_PART_REMOVE_MEDIA   0xF0
#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
Constante used to sign a MBR or PBR sectors
#define FS_BR_SIGNATURE_HIGH   0xAA
#define FS_BR_SIGNATURE_LOW   0x55
Status of the fat_checkcluster() function
#define FS_CLUS_BAD   1
#define FS_CLUS_END   2
#define FS_CLUS_OK   0
Options of the fat_cluster_list() function
#define FS_CLUST_ACT_CLR   0x03
#define FS_CLUST_ACT_ONE   0x02
#define FS_CLUST_ACT_SEG   0x01
Options of the fat_cluster_val() function
#define FS_CLUST_VAL_EOL   0x0FFFFFFF
#define FS_CLUST_VAL_READ   FALSE
#define FS_CLUST_VAL_WRITE   TRUE
Value used in "Fs_management_fast.u16_entry_pos_sel_file"
#define FS_END_FIND   0xFFFE
 Signal that a file entry is the last file entry accessibled by system.
#define FS_NO_SEL   0xFFFF
 Signal that a file entry isn't selected.
Constants used in the first byte of file entry
#define FS_ENTRY_DEL   0xE5
#define FS_ENTRY_END   0x00
#define FS_ENTRY_LFN_LAST   0x40
Maximum of FAT cluster
#define FS_FAT12_MAX_CLUSTERS   4085
#define FS_FAT16_MAX_CLUSTERS   65525
LIMITATIONS OF FILE SYSTEM
#define FS_NB_FAT   2
Constantes used to manage the file entry
#define FS_SHIFT_B_TO_FILE_ENTRY   5
#define FS_SIZE_FILE_ENTRY   32
#define FS_SIZE_LFN_ENTRY   13
#define FS_SIZE_SFNAME   11
#define FS_SIZE_SFNAME_EXT_ONLY   3
#define FS_SIZE_SFNAME_WITHOUT_EXT   8
FAT type ID, used in "Fs_management_fast.u8_type_fat"
#define FS_TYPE_FAT_12   1
#define FS_TYPE_FAT_16   2
#define FS_TYPE_FAT_32   3
#define FS_TYPE_FAT_UNM   0
 Partition not mounted.
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 HIGH_16_BPB_BytsPerSec   fs_g_sector[12]
#define HIGH_16_BPB_FATSz16   fs_g_sector[23]
#define HIGH_16_BPB_FSInfo   fs_g_sector[49]
#define HIGH_16_BPB_ResvSecCnt   fs_g_sector[15]
#define HIGH_16_BPB_RootEntCnt   fs_g_sector[18]
#define HIGH_16_BPB_TotSec16   fs_g_sector[20]
#define LOW0_32_BPB_FATSz32   fs_g_sector[36]
#define LOW0_32_BPB_RootClus   fs_g_sector[44]
#define LOW0_32_BPB_TotSec32   fs_g_sector[32]
#define LOW1_32_BPB_FATSz32   fs_g_sector[37]
#define LOW1_32_BPB_RootClus   fs_g_sector[45]
#define LOW1_32_BPB_TotSec32   fs_g_sector[33]
#define LOW2_32_BPB_FATSz32   fs_g_sector[38]
#define LOW2_32_BPB_RootClus   fs_g_sector[46]
#define LOW2_32_BPB_TotSec32   fs_g_sector[34]
#define LOW3_32_BPB_FATSz32   fs_g_sector[39]
#define LOW3_32_BPB_RootClus   fs_g_sector[47]
#define LOW3_32_BPB_TotSec32   fs_g_sector[35]
#define LOW_16_BPB_BytsPerSec   fs_g_sector[11]
#define LOW_16_BPB_FATSz16   fs_g_sector[22]
#define LOW_16_BPB_FSInfo   fs_g_sector[48]
#define LOW_16_BPB_ResvSecCnt   fs_g_sector[14]
#define LOW_16_BPB_RootEntCnt   fs_g_sector[17]
#define LOW_16_BPB_TotSec16   fs_g_sector[19]
#define U8_BPB_NumFATs   fs_g_sector[16]
#define U8_BPB_SecPerClus   fs_g_sector[13]

Typedefs

Main sructures
typedef struct st_fs_cluster Fs_cluster

Functions

Bool fat_format (U8 u8_fat_type)
 This function formats the drive.
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_serialnumber (Bool b_action, U8 _MEM_TYPE_SLOW_ *a_u8_sn)
 This function reads or writes a serial number.
Functions to manage the cluster list
Bool fat_allocfreespace (void)
 This function allocs a cluster list.
void fat_cache_clusterlist_reset (void)
 This function resets the cluster list caches.
U8 fat_checkcluster (void)
 This function checks the cluster value.
Bool fat_clear_cluster (void)
 This function clears one cluster.
void fat_clear_info_fat_mod (void)
 This function clears the cache information about FAT modifications.
Bool fat_cluster_list (U8 opt_action, Bool b_for_file)
 This function gets or clears a cluster list.
Bool fat_cluster_readnext (void)
 This function is optimized to read a continue cluster list on FAT16 and FAT32.
Bool fat_cluster_val (Bool b_mode)
 This function returns or modifys a cluster value in FAT.
Bool fat_update_fat2 (void)
 This function copys the modifications of the first FAT to the second FAT.
Functions to manage the cache
void fat_cache_clear (void)
 This function clears the sector cache.
Bool fat_cache_flush (void)
 This function flushs the sector cache on the memory if necessary.
void fat_cache_mark_sector_as_dirty (void)
 This function sets a flag to signal that sector cache is modified.
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.
Functions to verify navigator state
}@

Bool fat_check_device (void)
 This function checks device state.
Bool fat_check_is_file (void)
 This function checks if the selected file entry is a file and not a directory.
Bool fat_check_mount (void)
 This function checks if the partition is mounted.
Bool fat_check_mount_noopen (void)
 This function checks if the partition is mounted and no 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_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_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.
Functions to manage the entry field (fat.c)
Bool fat_check_eof_name (U16 character)
 Check end of name.
void fat_clear_entry_info_and_ptr (void)
 This function resets the selection pointers.
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.
Bool fat_entry_is_dir (void)
 This function checks if the entry file is a directory.
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_entry_shortname (FS_STRING sz_name, U8 u8_size_max, Bool b_mode)
 This function returns or compares the short name entry.
void fat_get_entry_info (void)
 This function reads information about selected file.
PTR_CACHE fat_get_ptr_entry (void)
 This function returns a cache pointer on the current entry.
void fat_write_entry_file (void)
 This function writes the information about selected file.
Functions to control access disk
Bool fat_check_nav_access_disk (void)
 This function checks write access.
Bool fat_check_nav_access_file (Bool mode)
 This function checks all access at current file.
Functions to manage navigator switch
void fat_copy_nav (U8 u8_idnav)
 This function copys the main navigator to another navigator.
void fat_invert_nav (U8 u8_idnav)
 This function inverts the current navigation with another.
Functions to manage the entry field (fat_unusual.c)
Bool fat_create_entry_file_name (FS_STRING sz_name)
 This function creates the short and the long name of a new entry.
Bool fat_delete_file (Bool b_cluster_list)
 This function deletes the file entries and cluster list.
Bool fat_entry_label (Bool b_action, FS_STRING sz_label)
 This function reads or writes a label in the partition.
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)
 This function changes the date information.
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.
U32 fat_read_fat32_FSInfo (void)
 This function returns the space free in the selected FAT32 partition.
Bool fat_write_fat32_FSInfo (U32 u32_nb_free_cluster)
 This function writes the space free number in selected FAT32 partition.
Functions to read or to write a file or a directory
Bool fat_initialize_dir (void)
 This function writes the directory information.
Bool fat_read_dir (void)
 This function fill the internal cache with a sector from current 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)
 This function gets and eventually allocs a cluster list at the current position in the selected file.

Variables

_GLOBEXT_ _MEM_TYPE_FAST_
Fs_cluster 
fs_g_cluster
 To take time in functions: fat_getfreespace, fat_cluster_list, fat_cluster_val, fat_checkcluster.
_GLOBEXT_ _MEM_TYPE_FAST_
Fs_segment 
fs_g_seg
 Variable frequently used by many function (optimization, no parameter in function).
_GLOBEXT_ Bool g_b_no_check_disk
 Variables to enable/disable the disk check before each action on disk.
_GLOBEXT_ Bool g_b_string_length
 Variables to select LENGTH string mode (initialised in nav_reset()).
_GLOBEXT_ Bool g_b_unicode
 Variables to select string format (initialised in nav_reset()).
Variables initialised in drive_mount()
_GLOBEXT_ _MEM_TYPE_SLOW_
Fs_management 
fs_g_nav
_GLOBEXT_ _MEM_TYPE_SLOW_
Fs_management_entry 
fs_g_nav_entry
_GLOBEXT_ _MEM_TYPE_FAST_
Fs_management_fast 
fs_g_nav_fast
Variables used to update the second FAT zone
_GLOBEXT_ _MEM_TYPE_SLOW_ U16 fs_g_u16_first_mod_fat
 Offset (unit 512B) in fat of the first sector (unit 512B).
_GLOBEXT_ _MEM_TYPE_SLOW_ U16 fs_g_u16_last_mod_fat
 Offset (unit 512B) in fat of the last sector (unit 512B).


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 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_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 FS_512B   512

#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(), file_putc(), 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_BOOT_SIGN   0x29

Definition at line 176 of file fat.h.

#define FS_BR_SIGNATURE_HIGH   0xAA

#define FS_BR_SIGNATURE_LOW   0x55

#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_CACHE_SIZE   512

Definition at line 222 of file fat.h.

Referenced by fat_cache_clear(), fat_clean_zone(), fat_cluster_readnext(), and fat_cluster_val().

#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_CLUS_OK   0

Definition at line 231 of file fat.h.

Referenced by fat_checkcluster().

#define FS_CLUST_ACT_CLR   0x03

Definition at line 241 of file fat.h.

Referenced by fat_cluster_list(), fat_delete_file(), fat_read_file(), and file_set_eof().

#define FS_CLUST_ACT_ONE   0x02

#define FS_CLUST_ACT_SEG   0x01

#define FS_CLUST_VAL_EOL   0x0FFFFFFF

Definition at line 248 of file fat.h.

Referenced by fat_allocfreespace(), and fat_cluster_list().

#define FS_CLUST_VAL_READ   FALSE

#define FS_CLUST_VAL_WRITE   TRUE

Definition at line 247 of file fat.h.

Referenced by fat_allocfreespace(), and fat_cluster_list().

#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 FS_ENTRY_DEL   0xE5

#define FS_ENTRY_END   0x00

#define FS_ENTRY_LFN_LAST   0x40

Definition at line 191 of file fat.h.

Referenced by fat_create_entry_file_name(), fat_delete_file(), and fat_entry_longname().

#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_MASK_SIZE_OF_SECTOR   FS_512B_MASK

Definition at line 220 of file fat.h.

#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(), fat_mount(), and fat_write_MBR().

#define FS_NB_FAT   2

Definition at line 208 of file fat.h.

Referenced by fat_mount().

#define FS_NO_SEL   0xFFFF

#define FS_PART_BOOTABLE   0x80

Definition at line 152 of file fat.h.

Referenced by fat_mount().

#define FS_PART_HARD_DISK   0x81

Definition at line 175 of file fat.h.

#define FS_PART_NO_BOOTABLE   0x00

Definition at line 153 of file fat.h.

Referenced by fat_mount(), and fat_write_MBR().

#define FS_PART_NO_REMOVE_MEDIA   0xF8

Definition at line 174 of file fat.h.

#define FS_PART_REMOVE_MEDIA   0xF0

Definition at line 173 of file fat.h.

#define FS_PART_TYPE_FAT12   0x01

Definition at line 167 of file fat.h.

Referenced by fat_mount(), and fat_write_MBR().

#define FS_PART_TYPE_FAT16_INF32M   0x04

Definition at line 168 of file fat.h.

Referenced by fat_mount(), and fat_write_MBR().

#define FS_PART_TYPE_FAT16_SUP32M   0x06

Definition at line 169 of file fat.h.

Referenced by fat_mount(), and fat_write_MBR().

#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(), and fat_write_MBR().

#define FS_PART_TYPE_FAT32_BIS   0x0C

Definition at line 172 of file fat.h.

Referenced by 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_SHIFT_B_TO_SECTOR   FS_512B_SHIFT_BIT

Definition at line 221 of file fat.h.

#define FS_SIZE_FILE_ENTRY   32

#define FS_SIZE_LFN_ENTRY   13

Definition at line 199 of file fat.h.

Referenced by fat_check_name(), fat_create_entry_file_name(), and nav_file_name().

#define FS_SIZE_OF_SECTOR   FS_512B

Definition at line 219 of file fat.h.

Referenced by fsaccess_example_read(), and fsaccess_example_write().

#define FS_SIZE_SFNAME   11

Definition at line 200 of file fat.h.

Referenced by fat_create_short_entry_name(), and fat_entry_shortname().

#define FS_SIZE_SFNAME_EXT_ONLY   3

Definition at line 202 of file fat.h.

#define FS_SIZE_SFNAME_WITHOUT_EXT   8

Definition at line 201 of file fat.h.

Referenced by fat_create_short_entry_name(), and fat_entry_shortname().

#define FS_TYPE_FAT_12   1

Definition at line 359 of file fat.h.

Referenced by fat_mount(), and fat_select_filesystem().

#define FS_TYPE_FAT_16   2

Definition at line 360 of file fat.h.

Referenced by fat_mount(), and fat_select_filesystem().

#define FS_TYPE_FAT_32   3

Definition at line 361 of file fat.h.

Referenced by fat_allocfreespace(), fat_mount(), and fat_select_filesystem().

#define FS_TYPE_FAT_UNM   0

#define HIGH_16_BPB_BytsPerSec   fs_g_sector[12]

Definition at line 115 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(), and fat_write_PBR().

#define HIGH_16_BPB_FSInfo   fs_g_sector[49]

Definition at line 139 of file fat.h.

#define HIGH_16_BPB_ResvSecCnt   fs_g_sector[15]

Definition at line 132 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 HIGH_16_BPB_TotSec16   fs_g_sector[20]

Definition at line 126 of file fat.h.

Referenced by fat_mount().

#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 LOW0_32_BPB_FATSz32   fs_g_sector[36]

Definition at line 121 of file fat.h.

Referenced by fat_mount(), and fat_write_PBR().

#define LOW0_32_BPB_RootClus   fs_g_sector[44]

Definition at line 134 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_FATSz32   fs_g_sector[37]

Definition at line 122 of file fat.h.

Referenced by fat_mount(), and fat_write_PBR().

#define LOW1_32_BPB_RootClus   fs_g_sector[45]

Definition at line 135 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_FATSz32   fs_g_sector[38]

Definition at line 123 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 LOW2_32_BPB_TotSec32   fs_g_sector[34]

Definition at line 129 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 LOW3_32_BPB_RootClus   fs_g_sector[47]

Definition at line 137 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_BytsPerSec   fs_g_sector[11]

Definition at line 114 of file fat.h.

#define LOW_16_BPB_FATSz16   fs_g_sector[22]

Definition at line 119 of file fat.h.

Referenced by fat_mount(), and fat_write_PBR().

#define LOW_16_BPB_FSInfo   fs_g_sector[48]

Definition at line 138 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 LOW_16_BPB_RootEntCnt   fs_g_sector[17]

Definition at line 117 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 U8_BPB_NumFATs   fs_g_sector[16]

Definition at line 133 of file fat.h.

#define U8_BPB_SecPerClus   fs_g_sector[13]

Definition at line 116 of file fat.h.

Referenced by fat_mount().


Typedef Documentation

typedef struct st_fs_cluster Fs_cluster

typedef U8 _MEM_TYPE_SLOW_* PTR_CACHE

Definition at line 418 of file fat.h.


Function Documentation

Bool fat_allocfreespace ( void   ) 

This function allocs a 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          Last cluster value of a cluster list to link with the new cluster list
//!                              If no cluster list to link then set MSB0(fs_g_seg.u32_addr) to 0xFF
//!   fs_g_seg.u32_size_or_pos   Maximum size of cluster list to alloc (unit sector)
//! OUT:
//!   fs_g_seg.u32_addr          Return the first cluster value of the new cluster list
//!   fs_g_seg.u32_size_or_pos   The number of sector remainning (no allocated sectors, because disk fragmented or disk full)
//! 

Definition at line 2294 of file fat_unusual.c.

References fat_clear_info_fat_mod(), fat_cluster_val(), fat_update_fat2(), fat_write_fat32_FSInfo(), FS_CLUST_VAL_EOL, FS_CLUST_VAL_READ, FS_CLUST_VAL_WRITE, FS_ERR_NO_FREE_SPACE, fs_g_cluster, fs_g_nav, fs_g_nav_fast, fs_g_seg, fs_g_status, FS_TYPE_FAT_32, Is_fat32, Fs_management::rootdir, Fs_segment::u32_addr, Fs_rootdir::u32_cluster, Fs_management::u32_CountofCluster, st_fs_cluster::u32_pos, Fs_segment::u32_size_or_pos, st_fs_cluster::u32_val, Fs_management::u8_BPB_SecPerClus, and Fs_management_fast::u8_type_fat.

Referenced by fat_alloc_entry_free(), fat_write_file(), and nav_dir_make().

02294 {
02295    // Flag to signal the first step which search the first free cluster of the new list
02296    Bool first_cluster_free_is_found = FALSE;
02297    // If TRUE then use a quick procedure but don't scan all FAT else use a slow proceudre but scan all FAT
02298    Bool b_quick_find = TRUE;
02299 
02300    if( Is_fat32 )
02301    {
02302       // Clear info about free space
02303       if( !fat_write_fat32_FSInfo( 0xFFFFFFFF ))
02304          return FALSE;
02305    }
02306 
02307    if( 0xFF == MSB0(fs_g_seg.u32_addr) )
02308    {
02309 fat_allocfreespace_start:
02310       // New cluster list, then research at the beginning of FAT
02311       fs_g_cluster.u32_pos = 2;
02312    }else{
02313       // Continue the cluster list then start after the end of the cluster list
02314       fs_g_cluster.u32_pos = fs_g_seg.u32_addr+1;
02315    }
02316 
02317    fat_clear_info_fat_mod();
02318 
02319    // Read ALL FAT1
02320    for(
02321    ;     fs_g_cluster.u32_pos < fs_g_nav.u32_CountofCluster
02322    ;     fs_g_cluster.u32_pos++ )
02323    {
02324       // Get the value of the cluster
02325       if ( !fat_cluster_val( FS_CLUST_VAL_READ ) )
02326          return FALSE;
02327 
02328       if ( 0 == fs_g_cluster.u32_val )
02329       {
02330          // A free cluster is found
02331          fs_g_cluster.u32_val = fs_g_cluster.u32_pos;    // value of the cluster is the new free cluster
02332          if( TRUE == first_cluster_free_is_found )
02333          {
02334             // Link the new cluster with previous cluster
02335             fs_g_cluster.u32_pos--;                      // select the previous cluster
02336             if ( !fat_cluster_val( FS_CLUST_VAL_WRITE ) )
02337                return FALSE;
02338          }
02339          else
02340          {
02341             // It is the first cluster of the new list
02342             first_cluster_free_is_found = TRUE;
02343 
02344             if( 0xFF != MSB0(fs_g_seg.u32_addr) )
02345             {
02346                // Link this new cluster with the current cluster list
02347                // Select the last cluster of the current list
02348                if( 0 == fs_g_seg.u32_addr )
02349                {  // The current cluster list is the cluster list of root directory
02350                   if( FS_TYPE_FAT_32 != fs_g_nav_fast.u8_type_fat )
02351                   {
02352                      // Impossible to increment ROOT DIR size of FAT12 or FAT16
02353                      fs_g_status = FS_ERR_NO_FREE_SPACE;
02354                      return FALSE;
02355                   }
02356                   fs_g_cluster.u32_pos = fs_g_nav.rootdir.u32_cluster;
02357                }
02358                else
02359                {
02360                   fs_g_cluster.u32_pos = fs_g_seg.u32_addr;
02361                }
02362                if ( !fat_cluster_val( FS_CLUST_VAL_WRITE ) )
02363                   return FALSE;
02364             }  // else no writing the first cluster value in FAT because no current cluster list
02365             fs_g_seg.u32_addr = fs_g_cluster.u32_val;    // save the first cluster value
02366          }
02367 
02368          // At the new cluster position, set the flag end of list
02369          fs_g_cluster.u32_pos = fs_g_cluster.u32_val;    // Select the new cluster
02370          fs_g_cluster.u32_val = FS_CLUST_VAL_EOL;        // Cluster value is the flag end of list
02371          if ( !fat_cluster_val( FS_CLUST_VAL_WRITE ) )
02372             return FALSE;
02373 
02374          // Compute the remaining sectors
02375          if ( fs_g_seg.u32_size_or_pos <= fs_g_nav.u8_BPB_SecPerClus )
02376          {
02377             fs_g_seg.u32_size_or_pos = 0; // All space found
02378             break;                        // Stop loop
02379          }
02380          fs_g_seg.u32_size_or_pos -= fs_g_nav.u8_BPB_SecPerClus;
02381       }
02382       else
02383       {
02384          // The next cluster is not free
02385          if( TRUE == first_cluster_free_is_found )
02386          {
02387             // To have a segment memory continue, the cluster list must be continue
02388             // then stop allocation
02389             break;
02390          }
02391          else
02392          {
02393             // It is the first step to search the first free cluster
02394             // then ignore this cluster no free and continue search
02395             if( b_quick_find )
02396             {
02397                fs_g_cluster.u32_pos += 500;
02398             }
02399          }
02400       }
02401    }
02402 
02403    // End of alloc
02404    if( FALSE == first_cluster_free_is_found )
02405    {
02406       if( b_quick_find )
02407       {
02408          // Retry in normal mode to scann all FAT (= no quick mode)
02409          b_quick_find = FALSE;
02410          goto fat_allocfreespace_start;
02411       }
02412       fs_g_status = FS_ERR_NO_FREE_SPACE; // NO FREE CLUSTER FIND
02413       return FALSE;
02414    }
02415 
02416    return fat_update_fat2();
02417 }
02418 #endif  // FS_LEVEL_FEATURES

void fat_cache_clear ( void   ) 

This function clears the sector cache.

Definition at line 1840 of file fat.c.

References FS_CACHE_SIZE, and fs_g_sector.

Referenced by fat_clean_zone(), fat_clear_cluster(), fat_write_fat32_FSInfo(), fat_write_MBR(), and fat_write_PBR().

01841 {
01842    memset( fs_g_sector , 0 , FS_CACHE_SIZE );
01843 }

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, fs_g_cache_clusterlist, fs_g_u8_current_cache, FS_NB_CACHE_CLUSLIST, Fs_clusterlist_cache::u8_level_use, and Fs_clusterlist_cache::u8_lun.

Referenced by fat_check_device(), fat_cluster_list(), and nav_reset().

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_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, FS_ERR_HW, fs_g_sector, fs_g_sectorcache, fs_g_status, FS_LUN_WP, mem_wr_protect(), ram_2_memory(), Fs_sector_cache::u32_addr, Fs_sector_cache::u8_dirty, and Fs_sector_cache::u8_lun.

Referenced by fat_cache_read_sector(), fat_clean_zone(), fat_entry_label(), fat_format(), fat_serialnumber(), file_close(), file_set_eof(), nav_dir_make(), nav_exit(), nav_file_attributset(), nav_file_create(), nav_file_dateset(), nav_file_del(), and nav_file_rename().

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 }

void fat_cache_mark_sector_as_dirty ( void   ) 

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, 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(), Fs_sector_cache::u32_addr, Fs_management::u8_lun, and Fs_sector_cache::u8_lun.

Referenced by fat_clean_zone(), fat_clear_cluster(), fat_cluster_readnext(), fat_cluster_val(), fat_get_nbpartition(), fat_getfreespace_percent(), fat_initialize_fat(), fat_mount(), fat_read_dir(), fat_read_fat32_FSInfo(), fat_read_file(), fat_serialnumber(), fat_update_fat2(), fat_write_fat32_FSInfo(), fat_write_MBR(), fat_write_PBR(), and file_write_buf().

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 }

void fat_cache_reset ( void   ) 

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, 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_navext, fs_g_navext_entry, fs_g_navext_fast, fs_g_sectorcache, fs_g_status, FS_NB_NAVIGATOR, FS_TYPE_FAT_UNM, g_b_no_check_disk, mem_test_unit_ready(), Fs_sector_cache::u8_lun, Fs_management::u8_lun, Fs_management_entry::u8_open_mode, and Fs_management_fast::u8_type_fat.

Referenced by fat_check_mount(), fat_check_noopen(), fat_get_nbpartition(), fat_mount(), nav_partition_freespace(), nav_partition_freespace_percent(), nav_partition_space(), and nav_partition_type().

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 }

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.

Referenced by fat_check_name(), fat_create_short_entry_name(), and fat_entry_longname().

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

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 Fat_is_not_a_file, FS_ERR_NO_FILE, and fs_g_status.

Referenced by file_ispresent(), and file_open().

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 }

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 fat_check_device(), fat_mount(), FS_ERR_NO_MOUNT, fs_g_nav_fast, fs_g_status, FS_TYPE_FAT_UNM, and Fs_management_fast::u8_type_fat.

Referenced by fat_check_mount_noopen(), fat_check_mount_select(), fat_check_mount_select_noopen(), fat_check_mount_select_open(), and nav_partition_serialnumber().

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 }

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 fat_check_mount(), and fat_check_noopen().

Referenced by nav_dir_gotoparent(), nav_dir_is_root(), nav_dir_make(), nav_dir_name(), nav_filelist_reset(), nav_filelist_set(), nav_filterlist_gotoparent(), and nav_getcwd().

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

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 fat_check_mount(), and fat_check_select().

Referenced by file_ispresent(), nav_file_attributset(), nav_file_checkext(), nav_file_dateget(), nav_file_dateset(), nav_file_isreadonly(), and nav_file_name().

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

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 fat_check_mount(), fat_check_noopen(), and fat_check_select().

Referenced by file_open(), nav_dir_cd(), nav_file_del(), nav_file_rename(), and nav_filelist_validpos().

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

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 fat_check_mount(), fat_check_open(), and fat_check_select().

Referenced by file_bof(), file_close(), file_eof(), file_getpos(), file_putc(), file_read(), file_read_buf(), file_seek(), file_set_eof(), file_write(), and file_write_buf().

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

Bool fat_check_nav_access_disk ( void   ) 

This function checks write access.

Returns:
TRUE, write access on disk possibled

FALSE, File open then write access not possibled

Definition at line 1888 of file fat.c.

References FS_ERR_FILE_OPEN, fs_g_nav, fs_g_navext, fs_g_navext_entry, fs_g_navext_fast, fs_g_status, FS_NB_NAVIGATOR, FS_TYPE_FAT_UNM, and Fs_management::u8_lun.

Referenced by nav_drive_format().

01889 {
01890    U8 i;
01891 
01892    // For each navigators
01893    for( i=0 ; i!=(FS_NB_NAVIGATOR-1) ; i++ )
01894    {
01895       // Disk mounted ?
01896       if( FS_TYPE_FAT_UNM != fs_g_navext_fast[i].u8_type_fat )
01897       // Is it the same disk ?
01898       if( fs_g_nav.u8_lun == fs_g_navext[i].u8_lun )
01899       // Is it access file ?
01900       if( fs_g_navext_entry[i].u8_open_mode!=0 )
01901       {
01902          fs_g_status = FS_ERR_FILE_OPEN;
01903          return FALSE;  // File opened then write access not possibled
01904       }
01905    }
01906    return TRUE;
01907 }

Bool fat_check_nav_access_file ( Bool  mode  ) 

This function checks all access at current file.

Parameters:
mode TRUE, check to write access
FALSE, check to read access
Returns:
FALSE in case of error, see global value "fs_g_status" for more detail :
mode TRUE, File opened then write access not possibles
mode FALSE, File opened in write mode then read access not possibles

TRUE, access file possibles

Definition at line 1920 of file fat.c.

References FOPEN_WRITE_ACCESS, FS_ERR_FILE_OPEN, FS_ERR_FILE_OPEN_WR, fs_g_nav, fs_g_nav_fast, fs_g_navext, fs_g_navext_entry, fs_g_navext_fast, fs_g_status, FS_NB_NAVIGATOR, FS_TYPE_FAT_UNM, Fs_management_fast::u16_entry_pos_sel_file, Fs_management::u32_cluster_sel_dir, Fs_management::u8_lun, and Fs_management::u8_partition.

Referenced by file_open(), nav_file_del(), and nav_file_rename().

01921 {
01922    U8 i;
01923 
01924    // For each navigators
01925    for( i=0 ; i!=(FS_NB_NAVIGATOR-1) ; i++ )
01926    {
01927       // Disk mounted ?
01928       if( FS_TYPE_FAT_UNM != fs_g_navext_fast[i].u8_type_fat )
01929       // Is it the same disk ?
01930       if( fs_g_nav.u8_lun == fs_g_navext[i].u8_lun )
01931 #if (FS_MULTI_PARTITION == ENABLED)
01932       // Is it the same partition ?
01933       if( fs_g_nav.u8_partition == fs_g_navext[i].u8_partition )
01934 #endif
01935       // Is it the same directory ?
01936       if( fs_g_nav.u32_cluster_sel_dir == fs_g_navext[i].u32_cluster_sel_dir )
01937       // Is it the same file ?
01938       if( fs_g_nav_fast.u16_entry_pos_sel_file == fs_g_navext_fast[i].u16_entry_pos_sel_file )
01939       {
01940          if( mode )
01941          {
01942             // Is it open ?
01943             if( fs_g_navext_entry[i].u8_open_mode!=0 )
01944             {
01945                fs_g_status = FS_ERR_FILE_OPEN;
01946                return FALSE;  // File opened then write access not possibled
01947             }
01948          }
01949          else
01950          {
01951             // Is it open in write mode ?
01952             if( fs_g_navext_entry[i].u8_open_mode & FOPEN_WRITE_ACCESS )
01953             {
01954                fs_g_status = FS_ERR_FILE_OPEN_WR;
01955                return FALSE;  // File opened in write mode then read access not possibled
01956             }
01957          }
01958       }
01959    }
01960    return TRUE;
01961 }

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 fat_check_device(), Fat_file_is_open, FS_ERR_TOO_FILE_OPEN, fs_g_nav_fast, fs_g_status, FS_TYPE_FAT_UNM, and Fs_management_fast::u8_type_fat.

Referenced by fat_check_mount_noopen(), fat_check_mount_select_noopen(), nav_drive_format(), nav_drive_set(), nav_filelist_fileisnotopen(), nav_partition_mount(), nav_partition_set(), and nav_setcwd().

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 }

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 Fat_file_isnot_open, FS_ERR_FILE_NO_OPEN, and fs_g_status.

Referenced by fat_check_mount_select_open().

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 FS_ERR_NO_FILE_SEL, fs_g_nav_fast, fs_g_status, FS_NO_SEL, and Fs_management_fast::u16_entry_pos_sel_file.

Referenced by fat_check_mount_select(), fat_check_mount_select_noopen(), fat_check_mount_select_open(), and nav_getcwd().

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 }

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 st_fs_cluster::u32_val.

Referenced by fat_cluster_list().

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_clear_cluster ( void   ) 

This function clears one cluster.

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          Cluster value to clear
//! 

Definition at line 2474 of file fat_unusual.c.

References fat_cache_clear(), fat_cache_mark_sector_as_dirty(), fat_cache_read_sector(), fat_cluster_list(), FS_CLUST_ACT_ONE, fs_g_nav, fs_g_seg, fs_gu32_addrsector, Fs_segment::u32_addr, Fs_segment::u32_size_or_pos, and Fs_management::u8_BPB_SecPerClus.

Referenced by fat_alloc_entry_free(), and fat_initialize_dir().

02474 {
02475    U8 u8_loop;
02476 
02477    // Compute the cluster sector address
02478    fs_g_seg.u32_size_or_pos  = 0;   // Select the beginning of cluster
02479    if( !fat_cluster_list( FS_CLUST_ACT_ONE, FALSE ))
02480       return FALSE;
02481 
02482    // Loop in the cluster (start at the end of cluster)
02483    fs_gu32_addrsector = fs_g_seg.u32_addr + (fs_g_nav.u8_BPB_SecPerClus -1);
02484    for(  u8_loop = 0
02485    ;     fs_g_nav.u8_BPB_SecPerClus != u8_loop
02486    ;     u8_loop++ )
02487    {
02488       // Update internal cache with cluster sector inforamtion but don't read data from memory
02489       if( !fat_cache_read_sector( FALSE ))
02490          return FALSE;
02491 
02492       if(0 == u8_loop)
02493       {  // Clean internal cache (just for the sector)
02494          fat_cache_clear();
02495       }
02496       fat_cache_mark_sector_as_dirty();
02497       fs_gu32_addrsector--;         // go to previous sector
02498    }
02499    return TRUE;
02500 }
02501 #endif  // FS_LEVEL_FEATURES

void fat_clear_entry_info_and_ptr ( void   ) 

void fat_clear_info_fat_mod ( void   ) 

This function clears the cache information about FAT modifications.

Definition at line 2425 of file fat_unusual.c.

References fs_g_u16_first_mod_fat, and fs_g_u16_last_mod_fat.

Referenced by fat_allocfreespace(), and fat_cluster_list().

02425 {
02426    fs_g_u16_first_mod_fat = 0xFFFF;
02427    fs_g_u16_last_mod_fat = 0;
02428 }
02429 #endif  // FS_LEVEL_FEATURES

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 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, Fs_management::rootdir, Fs_rootdir::seg, Fs_rootdir::u16_pos, Fs_rootdir::u16_size, Fs_segment::u32_addr, Fs_rootdir::u32_cluster, Fs_management::u32_offset_data, st_fs_cluster::u32_pos, Fs_management::u32_ptr_fat, Fs_segment::u32_size_or_pos, Fs_clusterlist_cache::u32_start, st_fs_cluster::u32_val, and Fs_management::u8_BPB_SecPerClus.

Referenced by fat_clear_cluster(), fat_read_dir(), and fat_read_file().

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 }

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 fat_cache_read_sector(), FS_CACHE_SIZE, fs_g_cluster, fs_g_sector, fs_g_u16_pos_fat, fs_gu32_addrsector, Is_fat32, and st_fs_cluster::u32_val.

Referenced by fat_cluster_list(), and fat_getfreespace().

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 }

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 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_first_mod_fat, fs_g_u16_last_mod_fat, fs_g_u16_pos_fat, fs_gu32_addrsector, Is_fat12, Is_fat16, Is_fat32, st_fs_cluster::u32_pos, Fs_management::u32_ptr_fat, st_fs_cluster::u32_val, u8_data3, and u8_data4.

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

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 }

void fat_copy_nav ( U8  u8_idnav  ) 

This function copys the main navigator to another navigator.

Parameters:
u8_idnav Id navigator to fill

Definition at line 1994 of file fat.c.

References fs_g_nav, fs_g_nav_entry, fs_g_nav_fast, fs_g_navext, fs_g_navext_entry, fs_g_navext_fast, and Fs_management_entry::u8_open_mode.

Referenced by nav_copy().

01995 {
01996    if( 0 != u8_idnav)
01997    {
01998       u8_idnav--;
01999       memcpy_ram2ram((U8*)&fs_g_navext[u8_idnav],       (U8*)&fs_g_nav       , sizeof(Fs_management) );
02000       memcpy_ram2ram((U8*)&fs_g_navext_entry[u8_idnav], (U8*)&fs_g_nav_entry , sizeof(Fs_management_entry) );
02001       memcpy_ram2ram((U8*)&fs_g_navext_fast[u8_idnav],  (U8*)&fs_g_nav_fast  , sizeof(Fs_management_fast) );
02002       fs_g_navext_entry[u8_idnav].u8_open_mode=0;   // Clear open file flag
02003    }
02004 }

Bool fat_create_entry_file_name ( FS_STRING  sz_name  ) 

This function creates the short and the long name of a new entry.

Parameters:
sz_name name to create (ASCII or UNICODE)
Returns:
FALSE in case of error, see global value "fs_g_status" for more detail

TRUE otherwise

//! IN:
//! b_unicode is a global flag to select UNICODE or ASCII
//! The name must be terminated by NULL and it can't have two dot characters.
//! 

Definition at line 1500 of file fat_unusual.c.

References fat_alloc_entry_free(), fat_check_name(), fat_create_long_name_entry(), fat_create_short_entry_name(), fat_find_short_entry_name(), fat_read_dir(), FS_ENTRY_LFN_LAST, FS_ERR_FILE_EXIST, fs_g_nav_fast, fs_g_status, FS_SIZE_LFN_ENTRY, Is_unicode, and Fs_management_fast::u16_entry_pos_sel_file.

Referenced by nav_file_create().

01500 {
01501    U8 u8_i, u8_nb;
01502    U8 u8_crc, u8_nb_entry;
01503 
01504    // Compute the number of entry for this name
01505    u8_nb_entry = fat_check_name( sz_name  );
01506    if( 0 == u8_nb_entry )
01507       return FALSE;
01508 
01509    // Search a unik short entry
01510    u8_nb = fat_find_short_entry_name( sz_name  );
01511    if( 0 == u8_nb )
01512    {
01513       fs_g_status = FS_ERR_FILE_EXIST;
01514       return FALSE;  // All short name exist
01515    }
01516    
01517    // Alloc a space for entrys
01518    if( !fat_alloc_entry_free( u8_nb_entry ))
01519       return FALSE;
01520    // Remark: here the pointer of entry is on the last free entry of new space allocated
01521 
01522    // Add short name entry
01523    u8_crc = fat_create_short_entry_name( sz_name , 0 , u8_nb, FALSE  );
01524    u8_nb_entry--;
01525 
01526    // For each long name entry
01527    for( u8_i=1 ; u8_i<=u8_nb_entry ; u8_i++ )
01528    {
01529       // Go to previous entry
01530       fs_g_nav_fast.u16_entry_pos_sel_file--;
01531       if( !fat_read_dir())
01532          return FALSE;
01533       // Write a long name entry
01534       if( u8_i == u8_nb_entry )
01535       {
01536          u8_i += FS_ENTRY_LFN_LAST;
01537       }
01538       fat_create_long_name_entry( sz_name , u8_crc , u8_i );
01539       sz_name += FS_SIZE_LFN_ENTRY*(Is_unicode? 2 : 1 );
01540   }
01541   // Go back to the short name entry
01542   fs_g_nav_fast.u16_entry_pos_sel_file += u8_nb_entry;
01543   return TRUE;
01544 }
01545 

Bool fat_delete_file ( Bool  b_cluster_list  ) 

This function deletes the file entries and cluster list.

Parameters:
b_cluster_list TRUE, delete file entries and cluster list FALSE, delete only file entries
Returns:
FALSE in case of error, see global value "fs_g_status" for more detail

TRUE otherwise

Definition at line 2074 of file fat_unusual.c.

References fat_cache_mark_sector_as_dirty(), fat_get_ptr_entry(), fat_read_dir(), fat_read_file(), FS_ATTR_LFN_ENTRY, FS_CLUST_ACT_CLR, FS_ENTRY_DEL, FS_ENTRY_LFN_LAST, fs_g_nav_entry, fs_g_nav_fast, Fs_management_fast::u16_entry_pos_sel_file, and Fs_management_entry::u32_pos_in_file.

Referenced by nav_dir_make(), nav_file_del(), and nav_file_rename().

02074 {
02075    PTR_CACHE ptr_entry;
02076    U8 u8_tmp;
02077    Bool b_short_del = FALSE;
02078 
02079    // loop in directory
02080    while( 1 )
02081    {
02082       // Fill internal cache with a sector from directory
02083       if( !fat_read_dir() )
02084          return FALSE;
02085 
02086       // Get pointer on the current entry
02087       ptr_entry = fat_get_ptr_entry();
02088       u8_tmp = ptr_entry[0];
02089 
02090       if( (FS_ATTR_LFN_ENTRY != ptr_entry[11])
02091       &&  (b_short_del) )
02092       {
02093          // no long entry exist, then only a short entry to delete
02094          break;   // Go to delete cluster list
02095       }
02096 
02097       // Delete entry
02098       b_short_del = TRUE;
02099       ptr_entry[0] = FS_ENTRY_DEL;
02100       fat_cache_mark_sector_as_dirty();
02101 
02102       if( (FS_ATTR_LFN_ENTRY == ptr_entry[11])
02103       &&  ( 0 != (FS_ENTRY_LFN_LAST & u8_tmp)) )
02104       {
02105          // It is the last entry of long name
02106          break;   // Go to delete cluster list
02107       }
02108 
02109       // Go to previous entry
02110       fs_g_nav_fast.u16_entry_pos_sel_file--;
02111    }  // end of while(1)
02112 
02113    if( b_cluster_list )
02114    {
02115       // Delete cluster list
02116       fs_g_nav_entry.u32_pos_in_file=0;      // Delete ALL list (start at begining)
02117       if( !fat_read_file( FS_CLUST_ACT_CLR ))
02118          return FALSE;
02119    }
02120 
02121    return TRUE;
02122 }
02123 #endif  // FS_LEVEL_FEATURES

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

Referenced by nav_filelist_set().

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 }

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

Referenced by nav_file_checkext().

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 }

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.

Referenced by nav_dir_cd(), nav_file_isdir(), and nav_setcwd().

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

Bool fat_entry_label ( Bool  b_action,
FS_STRING  sz_label 
)

This function reads or writes a label in the partition.

Parameters:
b_action choose action (FS_LABEL_READ or FS_LABEL_WRITE)
sz_label string ASCII to store label (11B min) or to get new label (11B max)
Returns:
FALSE in case of error, see global value "fs_g_status" for more detail

TRUE otherwise

Definition at line 1088 of file fat_unusual.c.

References fat_cache_flush(), fat_cache_mark_sector_as_dirty(), fat_get_ptr_entry(), FS_ATTR_VOLUME_ID, FS_ENTRY_END, FS_ERR_ENTRY_BAD, FS_ERR_ENTRY_EMPTY, FS_ERR_NAME_INCORRECT, fs_g_status, FS_LABEL_READ, and FS_LABEL_WRITE.

Referenced by nav_partition_label().

01088 {
01089    PTR_CACHE ptr_entry;
01090    U8 u8_pos_name;
01091    U8 u8_char;
01092 
01093    ptr_entry = fat_get_ptr_entry();
01094 
01095    if( FS_LABEL_READ == b_action)
01096    {
01097       if( FS_ENTRY_END == ptr_entry[0] )           // end of directory
01098       {
01099          fs_g_status = FS_ERR_ENTRY_EMPTY;
01100          return FALSE;
01101       }
01102       if( FS_ATTR_VOLUME_ID != ptr_entry[11])      // no system label
01103       {
01104          fs_g_status = FS_ERR_ENTRY_BAD;
01105          return FALSE;
01106       }
01107       if( NULL == sz_label )
01108          return TRUE;
01109       for( u8_pos_name=0; u8_pos_name<11; u8_pos_name++ )
01110       {
01111          u8_char = *ptr_entry;
01112          if( 0x20 == u8_char )
01113             u8_char = 0;
01114          *sz_label = u8_char;
01115          if( 0 == u8_char )
01116             return TRUE;                           // Label readed
01117          ptr_entry++;
01118          sz_label++;
01119       }
01120       *sz_label = 0;
01121       return TRUE;
01122    }
01123 
01124    if( FS_LABEL_WRITE == b_action)
01125    {
01126       // Autorize to write the label only on an empty entry or the system label entry
01127       if( FS_ENTRY_END != ptr_entry[0] )           // end of directory
01128       {
01129          if( FS_ATTR_VOLUME_ID != ptr_entry[11])   // no system label
01130          {
01131             fs_g_status = FS_ERR_ENTRY_BAD;
01132             return FALSE;
01133          }
01134       }
01135       if( 0 == *sz_label )
01136       {
01137          fs_g_status = FS_ERR_NAME_INCORRECT;
01138          return FALSE;
01139       }
01140       ptr_entry[11] = FS_ATTR_VOLUME_ID;
01141       for( u8_pos_name=0; u8_pos_name<11; u8_pos_name++ )
01142       {
01143          u8_char = *sz_label;
01144          if( ('a'<=u8_char) && (u8_char<='z') )
01145          {
01146             u8_char -= ('a'-'A');                  // Change to upper case
01147          }
01148          if( 0 == u8_char )
01149          {
01150             u8_char = 0x20;
01151          }
01152          *ptr_entry = u8_char;
01153          ptr_entry++;
01154          if( 0x20 == u8_char )
01155             continue;
01156          sz_label++;
01157       }
01158       fat_cache_mark_sector_as_dirty();
01159       return fat_cache_flush();
01160    }
01161    return FALSE;                                   // To delete the compilation warning
01162 }
01163 #endif  // FS_LEVEL_FEATURES

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 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, and Is_unicode.

Referenced by nav_file_name().

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 }

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 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, and Is_unicode.

Referenced by nav_file_name().

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 }

Bool fat_format ( U8  u8_fat_type  ) 

This function formats the drive.

This function formats the drive.

Parameters:
u8_fat_type Select the type of format
FS_FORMAT_DEFAULT, The file system module choose the better FAT format for the drive space
FS_FORMAT_FAT, The FAT12 or FAT16 is used to format the drive, if possible (disk space <2GB)
FS_FORMAT_FAT32, The FAT32 is used to format the drive, if possible (disk space >32MB)
FS_FORMAT_NOMBR_FLAG if you don't want a MRB in disk then add this flag (e.g. FAT format on a CD support)
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 format
//!
//! This routine can't format a multi-partiton, if the disk contains a multi-partition area
//! then the multi-partition will be erased and replaced by a single partition on all disk space.
//! 

Definition at line 341 of file fat_unusual.c.

References fat_cache_flush(), fat_clean_zone(), fat_initialize_fat(), fat_select_filesystem(), fat_write_MBR(), fat_write_PBR(), FS_FORMAT_NOMBR_FLAG, fs_g_nav, fs_s_u32_size_partition, mem_read_capacity(), Fs_management::u8_lun, and Fs_management::u8_partition.

Referenced by nav_drive_format().

00341 {
00342    Bool b_MBR;
00343 #if (FS_MULTI_PARTITION == ENABLED)
00344 #error NOT SUPPORTED
00345    fs_g_nav.u8_partition = 0;
00346 #endif
00347 
00348 
00349    // Get drive capacity (= last LBA)
00350    mem_read_capacity( fs_g_nav.u8_lun , &fs_s_u32_size_partition );
00351 
00352    if( u8_fat_type & FS_FORMAT_NOMBR_FLAG )
00353    {
00354       b_MBR = FALSE;
00355       u8_fat_type &= ~FS_FORMAT_NOMBR_FLAG;
00356       // partition size = disk size = last LBA + 1
00357       fs_s_u32_size_partition++;
00358    }else{
00359       b_MBR = TRUE;
00360       // partition size = size disk -1 = last LBA
00361    }
00362 
00363    // Compute the FAT type for the device
00364    if( !fat_select_filesystem( u8_fat_type , b_MBR ))
00365       return FALSE;
00366 
00367    // Write the MBR sector (first sector)
00368    if( b_MBR )
00369       if( !fat_write_MBR())
00370          return FALSE;
00371 
00372    // Write the PBR sector
00373    if( !fat_write_PBR( b_MBR ))
00374       return FALSE;
00375 
00376    // Clear reserved zone, FAT zone, and Root dir zone
00377    // Remark: the reserved zone of FAT32 isn't initialized, because BPB_FSInfo is equal to 0
00378    if( !fat_clean_zone( b_MBR ))
00379       return FALSE;
00380 
00381    // Initialization of the FAT 1 and 2
00382    if( !fat_initialize_fat())
00383       return FALSE;
00384 
00385    return fat_cache_flush();
00386 }
00387 

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

References fat_get_ptr_entry(), fat_translatedate_number_to_ascii(), and FS_DATE_LAST_WRITE.

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 }
01235 

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, Fs_management_entry::u32_cluster, Fs_management_entry::u32_size, and Fs_management_entry::u8_attr.

Referenced by nav_dir_gotoparent(), nav_filelist_set(), and nav_filterlist_gotoparent().

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 }

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 fat_cache_read_sector(), fat_check_device(), FS_BR_SIGNATURE_HIGH, FS_BR_SIGNATURE_LOW, fs_g_sector, fs_gu32_addrsector, and FS_MBR_OFFSET_PART_ENTRY.

Referenced by nav_partition_nb().

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 }

PTR_CACHE fat_get_ptr_entry ( void   ) 

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

References fat_cluster_readnext(), fat_cluster_val(), fat_read_fat32_FSInfo(), fat_write_fat32_FSInfo(), FS_CLUST_VAL_READ, fs_g_cluster, fs_g_nav, Is_fat12, Is_fat32, Fs_management::u32_CountofCluster, st_fs_cluster::u32_pos, st_fs_cluster::u32_val, and Fs_management::u8_BPB_SecPerClus.

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 }
02186 

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

References fat_cache_read_sector(), fat_cluster_val(), fat_getfreespace(), fat_read_fat32_FSInfo(), FS_CLUST_VAL_READ, fs_g_cluster, fs_g_nav, fs_g_sector, fs_gu32_addrsector, Is_fat12, Is_fat16, Is_fat32, Fs_management::u16_fat_size, Fs_management::u32_CountofCluster, st_fs_cluster::u32_pos, and Fs_management::u8_BPB_SecPerClus.

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 }
02273 

Bool fat_initialize_dir ( void   ) 

This function writes the directory information.

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          cluster value of a directory
//! OUT:
//!   update the sector cache with init directory datas
//! 

Definition at line 1181 of file fat_unusual.c.

References fat_cache_mark_sector_as_dirty(), fat_clear_cluster(), FS_ATTR_DIRECTORY, fs_g_nav, fs_g_nav_entry, fs_g_sector, FS_SIZE_FILE_ENTRY, Fs_management_entry::u32_cluster, and Fs_management::u32_cluster_sel_dir.

Referenced by nav_dir_make().

01181 {
01182    U8 u8_i;
01183 
01184    // Clear the cluster corresponding at directory
01185    if( !fat_clear_cluster())
01186       return FALSE;
01187    fat_cache_mark_sector_as_dirty();
01188    // here, the internal cache is the first sector of the cluster
01189 
01190    // Create the dot "." entry, this one is a directory that points to itself
01191    fs_g_sector[0]='.';
01192    for( u8_i=1 ; u8_i<11 ; u8_i++ )
01193       fs_g_sector[u8_i]=' ';
01194    fs_g_sector[11]=FS_ATTR_DIRECTORY;
01195    fs_g_sector[26]= LSB0( fs_g_nav_entry.u32_cluster );
01196    fs_g_sector[27]= LSB1( fs_g_nav_entry.u32_cluster );
01197    fs_g_sector[20]= LSB2( fs_g_nav_entry.u32_cluster );
01198    fs_g_sector[21]= LSB3( fs_g_nav_entry.u32_cluster );
01199    // Create the dotdot ".." entry, this one points to the starting cluster of the parent directory
01200    fs_g_sector[FS_SIZE_FILE_ENTRY+0]='.';
01201    fs_g_sector[FS_SIZE_FILE_ENTRY+1]='.';
01202    for( u8_i=2 ; u8_i<11 ; u8_i++ )
01203       fs_g_sector[FS_SIZE_FILE_ENTRY+u8_i]=' ';
01204    fs_g_sector[FS_SIZE_FILE_ENTRY+11]=FS_ATTR_DIRECTORY;
01205    fs_g_sector[FS_SIZE_FILE_ENTRY+26]= LSB0( fs_g_nav.u32_cluster_sel_dir );
01206    fs_g_sector[FS_SIZE_FILE_ENTRY+27]= LSB1( fs_g_nav.u32_cluster_sel_dir );
01207    fs_g_sector[FS_SIZE_FILE_ENTRY+20]= LSB2( fs_g_nav.u32_cluster_sel_dir );
01208    fs_g_sector[FS_SIZE_FILE_ENTRY+21]= LSB3( fs_g_nav.u32_cluster_sel_dir );
01209 
01210    return TRUE;
01211 }
01212 #endif  // FS_LEVEL_FEATURES

void fat_invert_nav ( U8  u8_idnav  ) 

This function inverts the current navigation with another.

Parameters:
u8_idnav Id navigator to invert

Definition at line 1968 of file fat.c.

References fs_g_nav, fs_g_nav_entry, fs_g_nav_fast, fs_g_navext, fs_g_navext_entry, and fs_g_navext_fast.

Referenced by nav_select().

01969 {
01970    _MEM_TYPE_SLOW_ U8 Temp[Max(Max(sizeof(Fs_management),sizeof(Fs_management_entry)),sizeof(Fs_management_fast))];
01971 
01972    if( u8_idnav == 0 )
01973       return;
01974    u8_idnav--;
01975 
01976    memcpy_ram2ram(Temp,                              (U8*)&fs_g_nav,                     sizeof(Fs_management));
01977    memcpy_ram2ram((U8*)&fs_g_nav,                    (U8*)&fs_g_navext[u8_idnav],        sizeof(Fs_management));
01978    memcpy_ram2ram((U8*)&fs_g_navext[u8_idnav],       Temp,                               sizeof(Fs_management));
01979 
01980    memcpy_ram2ram(Temp,                              (U8*)&fs_g_nav_entry,               sizeof(Fs_management_entry));
01981    memcpy_ram2ram((U8*)&fs_g_nav_entry,              (U8*)&fs_g_navext_entry[u8_idnav],  sizeof(Fs_management_entry));
01982    memcpy_ram2ram((U8*)&fs_g_navext_entry[u8_idnav], Temp,                               sizeof(Fs_management_entry));
01983 
01984    memcpy_ram2ram(Temp,                              (U8*)&fs_g_nav_fast,                sizeof(Fs_management_fast));
01985    memcpy_ram2ram((U8*)&fs_g_nav_fast,               (U8*)&fs_g_navext_fast[u8_idnav],   sizeof(Fs_management_fast));
01986    memcpy_ram2ram((U8*)&fs_g_navext_fast[u8_idnav],  Temp,                               sizeof(Fs_management_fast));
01987 }

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.

References fat_cache_read_sector(), fat_check_device(), fat_clear_entry_info_and_ptr(), FS_512B, FS_BR_SIGNATURE_HIGH, FS_BR_SIGNATURE_LOW, FS_ERR_NO_FORMAT, FS_ERR_NO_PART, FS_ERR_NO_SUPPORT_PART, FS_FAT12_MAX_CLUSTERS, FS_FAT16_MAX_CLUSTERS, fs_g_nav, fs_g_nav_fast, fs_g_sector, fs_g_status, fs_gu32_addrsector, FS_MBR_OFFSET_PART_ENTRY, FS_NB_FAT, FS_PART_BOOTABLE, FS_PART_NO_BOOTABLE, FS_PART_TYPE_FAT12, FS_PART_TYPE_FAT16_INF32M, FS_PART_TYPE_FAT16_SUP32M, FS_PART_TYPE_FAT16_SUP32M_BIS, FS_PART_TYPE_FAT32, FS_PART_TYPE_FAT32_BIS, FS_SIZE_FILE_ENTRY, FS_TYPE_FAT_12, FS_TYPE_FAT_16, FS_TYPE_FAT_32, FS_TYPE_FAT_UNM, HIGH_16_BPB_BytsPerSec, HIGH_16_BPB_FATSz16, HIGH_16_BPB_ResvSecCnt, HIGH_16_BPB_RootEntCnt, HIGH_16_BPB_TotSec16, LOW0_32_BPB_FATSz32, LOW0_32_BPB_RootClus, LOW0_32_BPB_TotSec32, LOW1_32_BPB_FATSz32, LOW1_32_BPB_RootClus, LOW1_32_BPB_TotSec32, LOW2_32_BPB_FATSz32, LOW2_32_BPB_RootClus, LOW2_32_BPB_TotSec32, LOW3_32_BPB_FATSz32, LOW3_32_BPB_RootClus, LOW3_32_BPB_TotSec32, LOW_16_BPB_FATSz16, LOW_16_BPB_FSInfo, LOW_16_BPB_ResvSecCnt, LOW_16_BPB_RootEntCnt, LOW_16_BPB_TotSec16, mem_sector_size(), Fs_management::rootdir, Fs_rootdir::seg, Fs_management::u16_fat_size, Fs_management::u16_offset_FSInfo, Fs_rootdir::u16_pos, Fs_rootdir::u16_size, Fs_rootdir::u32_cluster, Fs_management::u32_cluster_sel_dir, Fs_management::u32_CountofCluster, Fs_management::u32_offset_data, Fs_management::u32_ptr_fat, U8_BPB_SecPerClus, Fs_management::u8_BPB_SecPerClus, Fs_management::u8_lun, Fs_management::u8_partition, and Fs_management_fast::u8_type_fat.

Referenced by fat_check_mount(), nav_drive_format(), 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 }
00312 

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

Referenced by fat_alloc_entry_free(), fat_create_entry_file_name(), fat_delete_file(), fat_find_short_entry_name(), fat_garbage_collector_entry(), file_close(), nav_dir_gotoparent(), nav_dir_make(), nav_file_attributset(), nav_file_checkext(), nav_file_dateget(), nav_file_dateset(), nav_file_name(), nav_file_rename(), nav_filelist_set(), nav_filterlist_gotoparent(), and nav_partition_label().

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 }

U32 fat_read_fat32_FSInfo ( void   ) 

This function returns the space free in the selected FAT32 partition.

Returns:
the number of sector free (if 0xFFFFFFFF, then no value available in FSInfo Sector)

Definition at line 888 of file fat_unusual.c.

References const_FSI_LeadSig, const_FSI_StrucSig, fat_cache_read_sector(), FS_BR_SIGNATURE_HIGH, FS_BR_SIGNATURE_LOW, fs_g_nav, fs_g_sector, fs_gu32_addrsector, Fs_management::u16_offset_FSInfo, and Fs_management::u32_ptr_fat.

Referenced by fat_getfreespace(), and fat_getfreespace_percent().

00888 {
00889    U32 u32_nb_free_cluster;
00890 
00891    // Read FAT32 FSInfo Sector
00892    fs_gu32_addrsector = fs_g_nav.u32_ptr_fat - fs_g_nav.u16_offset_FSInfo;
00893    if( !fat_cache_read_sector( TRUE ))
00894       return 0xFFFFFFFF;
00895 
00896    //* Check signature
00897    // offset 510-511, Signature
00898    if( fs_g_sector[510] != FS_BR_SIGNATURE_LOW )
00899       return 0xFFFFFFFF;
00900    if( fs_g_sector[511] != FS_BR_SIGNATURE_HIGH)
00901       return 0xFFFFFFFF;
00902    // offset 00-04, This lead signature
00903    if( 0 != memcmp_code2ram( &fs_g_sector[0], const_FSI_LeadSig, sizeof(const_FSI_LeadSig) ))
00904       return 0xFFFFFFFF;
00905    // offset 004-483, reserved (fill with 0)
00906    // offset 484-487, signature
00907    if( 0 != memcmp_code2ram( &fs_g_sector[484], const_FSI_StrucSig, sizeof(const_FSI_StrucSig)) )
00908       return 0xFFFFFFFF;
00909 
00910    //* Read value
00911    // offset 488-491, free cluster count
00912    LSB0(u32_nb_free_cluster) = fs_g_sector[488];
00913    LSB1(u32_nb_free_cluster) = fs_g_sector[489];
00914    LSB2(u32_nb_free_cluster) = fs_g_sector[490];
00915    LSB3(u32_nb_free_cluster) = fs_g_sector[491];
00916    return u32_nb_free_cluster;
00917 }
00918 #endif  // FS_FAT_32

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

Referenced by fat_delete_file(), fat_write_file(), file_getc(), file_read(), file_read_buf(), and file_set_eof().

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 }

Bool fat_serialnumber ( Bool  b_action,
U8 _MEM_TYPE_SLOW_ *  a_u8_sn 
)

This function reads or writes a serial number.

This function reads or writes a serial number.

Parameters:
b_action choose action (FS_SN_READ or FS_SN_WRITE)
a_u8_sn array to store or get the serial number (U8[4])
Returns:
FALSE in case of error, see global value "fs_g_status" for more detail

TRUE otherwise

Definition at line 1044 of file fat_unusual.c.

References fat_cache_flush(), fat_cache_mark_sector_as_dirty(), fat_cache_read_sector(), fs_g_nav, fs_g_sector, fs_gu32_addrsector, FS_SN_READ, Is_fat12, Is_fat16, and Fs_management::u32_ptr_fat.

Referenced by nav_partition_serialnumber().

01044 {
01045    // Compute PBR address
01046    if ( Is_fat12 || Is_fat16 )
01047    {  // FAT 12 & 16 (BPB_ResvSecCnt must be ega to 1)
01048       fs_gu32_addrsector = fs_g_nav.u32_ptr_fat-1;
01049    }
01050    else
01051    {  // FAT 32 (BPB_ResvSecCnt must be ega to 32)
01052       fs_gu32_addrsector = fs_g_nav.u32_ptr_fat-32;
01053    }
01054    // Read PBR
01055    if( !fat_cache_read_sector( TRUE ))
01056       return FALSE;
01057 
01058    // The serial is storaged at invert
01059    if( b_action == FS_SN_READ )
01060    {
01061       // Read serial number
01062       a_u8_sn[0] = fs_g_sector[42];
01063       a_u8_sn[1] = fs_g_sector[41];
01064       a_u8_sn[2] = fs_g_sector[40];
01065       a_u8_sn[3] = fs_g_sector[39];
01066       return TRUE;
01067    }else{
01068       // Write serial number
01069       fs_g_sector[42] = a_u8_sn[0];
01070       fs_g_sector[41] = a_u8_sn[1];
01071       fs_g_sector[40] = a_u8_sn[2];
01072       fs_g_sector[39] = a_u8_sn[3];
01073       fat_cache_mark_sector_as_dirty();
01074       return fat_cache_flush();
01075    }
01076 }
01077 

void fat_set_date ( const FS_STRING  sz_date,
Bool  type_date 
)

This function changes the date information.

Parameters:
type_date choose date field (FS_DATE_LAST_WRITE or FS_DATE_CREATION)
sz_date table with date information
storage format (ASCII) = "YYYYMMDDHHMMSSMS" = year, month, day, hour, minute, seconde, miliseconde
//! OUT, update cache sector with the new date
//! 

Definition at line 1349 of file fat_unusual.c.

References fat_cache_mark_sector_as_dirty(), fat_get_ptr_entry(), fat_translatedate_ascii_to_number(), and FS_DATE_LAST_WRITE.

Referenced by nav_file_dateset().

01349 {
01350    PTR_CACHE ptr_entry;
01351 
01352    fat_cache_mark_sector_as_dirty();
01353    ptr_entry = fat_get_ptr_entry();
01354 
01355    if( FS_DATE_LAST_WRITE == type_date )
01356    {
01357       fat_translatedate_ascii_to_number( sz_date , &ptr_entry[22] , FALSE );
01358    }
01359    else
01360    {
01361       fat_translatedate_ascii_to_number( sz_date , &ptr_entry[13] , TRUE );
01362    }
01363 }
01364 

Bool fat_update_fat2 ( void   ) 

This function copys the modifications of the first FAT to the second FAT.

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

TRUE otherwise

Definition at line 2439 of file fat_unusual.c.

References fat_cache_mark_sector_as_dirty(), fat_cache_read_sector(), fs_g_nav, fs_g_u16_first_mod_fat, fs_g_u16_last_mod_fat, fs_gu32_addrsector, Fs_management::u16_fat_size, and Fs_management::u32_ptr_fat.

Referenced by fat_allocfreespace(), and fat_cluster_list().

02439 {
02440   while( fs_g_u16_first_mod_fat <= fs_g_u16_last_mod_fat )
02441   {
02442      // Compute the modification position of FAT 1
02443      fs_gu32_addrsector = fs_g_nav.u32_ptr_fat + fs_g_u16_first_mod_fat;
02444      // Read FAT1
02445       if( !fat_cache_read_sector( TRUE ))
02446          return FALSE;
02447      // Compute the modification position of FAT 2
02448      fs_gu32_addrsector = fs_g_nav.u32_ptr_fat + ((U32)fs_g_u16_first_mod_fat + fs_g_nav.u16_fat_size);
02449      // Init the sector FAT2 with the previous sector of the FAT1
02450      if( !fat_cache_read_sector( FALSE ))
02451          return FALSE;
02452      // Flag the sector FAT2 like modify
02453      fat_cache_mark_sector_as_dirty();
02454      fs_g_u16_first_mod_fat++;
02455   }
02456   return TRUE;
02457 }
02458 #endif  // FS_LEVEL_FEATURES

void fat_write_entry_file ( void   ) 

This function writes the 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_sector    Updated
//! 

Write the attribut

Write the size of file

Definition at line 1421 of file fat.c.

References fat_cache_mark_sector_as_dirty(), fat_get_ptr_entry(), FS_ATTR_DIRECTORY, fs_g_nav_entry, Fs_management_entry::u32_cluster, Fs_management_entry::u32_size, and Fs_management_entry::u8_attr.

Referenced by file_close(), nav_dir_make(), nav_file_attributset(), and nav_file_rename().

01422 {
01423    PTR_CACHE ptr_entry;
01424 
01425    fat_cache_mark_sector_as_dirty();
01426    ptr_entry = fat_get_ptr_entry();
01427 
01428    if( !(FS_ATTR_DIRECTORY | fs_g_nav_entry.u8_attr))
01429    {
01430       if( 0 == fs_g_nav_entry.u32_size )
01431          fs_g_nav_entry.u32_cluster = 0;
01432    }
01433 
01435    ptr_entry+= 11;
01436    ptr_entry[0] = fs_g_nav_entry.u8_attr;
01437 
01438    // Write the first cluster of file cluster list
01439    ptr_entry += (20-11);
01440    ptr_entry[0] = LSB2(fs_g_nav_entry.u32_cluster);
01441    ptr_entry[1] = LSB3(fs_g_nav_entry.u32_cluster);
01442    ptr_entry += (26-20);
01443    ptr_entry[0] = LSB0(fs_g_nav_entry.u32_cluster);
01444    ptr_entry[1] = LSB1(fs_g_nav_entry.u32_cluster);
01445 
01447    ptr_entry += (28-26);
01448    ptr_entry[0] = LSB0(fs_g_nav_entry.u32_size);
01449    ptr_entry[1] = LSB1(fs_g_nav_entry.u32_size);
01450    ptr_entry[2] = LSB2(fs_g_nav_entry.u32_size);
01451    ptr_entry[3] = LSB3(fs_g_nav_entry.u32_size);
01452 }

Bool fat_write_fat32_FSInfo ( U32  u32_nb_free_cluster  ) 

This function writes the space free number in selected FAT32 partition.

Read global value "fs_g_status" in case of error : FS_ERR_HW Hardware driver error FS_ERR_HW_NO_PRESENT Device not present FS_LUN_WP Drive is read only

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

TRUE otherwise

Definition at line 853 of file fat_unusual.c.

References const_FSI_LeadSig, const_FSI_StrucSig, fat_cache_clear(), fat_cache_mark_sector_as_dirty(), fat_cache_read_sector(), FS_BR_SIGNATURE_HIGH, FS_BR_SIGNATURE_LOW, fs_g_nav, fs_g_sector, fs_gu32_addrsector, Fs_management::u16_offset_FSInfo, and Fs_management::u32_ptr_fat.

Referenced by fat_allocfreespace(), fat_cluster_list(), fat_getfreespace(), and fat_write_PBR().

00853 {
00854    // Init sector
00855    fs_gu32_addrsector = fs_g_nav.u32_ptr_fat - fs_g_nav.u16_offset_FSInfo;
00856 
00857    if( !fat_cache_read_sector( FALSE ))
00858       return FALSE;
00859    fat_cache_mark_sector_as_dirty();
00860    fat_cache_clear();
00861 
00862    // Fill sector
00863    // offset 00-04, This lead signature
00864    memcpy_code2ram( &fs_g_sector[0], const_FSI_LeadSig, sizeof(const_FSI_LeadSig) );
00865    // offset 004-483, reserved (fill with 0)
00866    // offset 484-487, signature
00867    memcpy_code2ram( &fs_g_sector[484], const_FSI_StrucSig, sizeof(const_FSI_StrucSig) );
00868    // offset 488-491, free cluster count (by default NO value)
00869    fs_g_sector[488] = LSB0(u32_nb_free_cluster);
00870    fs_g_sector[489] = LSB1(u32_nb_free_cluster);
00871    fs_g_sector[490] = LSB2(u32_nb_free_cluster);
00872    fs_g_sector[491] = LSB3(u32_nb_free_cluster);
00873    // offset 492-495, indicates the cluster number at which the driver should start looking for free clusters (by default NO value)
00874    memset( &fs_g_sector[492] , 0xFF , 4 );
00875    // offset 496-509, reserved (fill with 0)
00876    // offset 510-511, Signature
00877    fs_g_sector[510] = FS_BR_SIGNATURE_LOW;
00878    fs_g_sector[511] = FS_BR_SIGNATURE_HIGH;
00879    return TRUE;
00880 }
00881 

Bool fat_write_file ( U8  mode,
U32  u32_nb_sector_write 
)

This function gets and eventually allocs a cluster list at the current position in the selected file.

Parameters:
mode Choose action
FS_CLUST_ACT_SEG Get and eventuelly alloc a cluster list
FS_CLUST_ACT_ONE Get and eventually alloc a cluster list for one sector, and load this sector in internal cache
u32_nb_sector_write maximum number of sector to get and eventually to alloc for the selected file (ignored if mode = FS_CLUST_ACT_ONE)
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 the file (unit byte)
//! 

Definition at line 1117 of file fat.c.

References fat_allocfreespace(), fat_cache_clusterlist_update_finish(), fat_cache_clusterlist_update_start(), fat_read_file(), FS_CLUST_ACT_SEG, FS_ERR_OUT_LIST, fs_g_cache_clusterlist, fs_g_nav, fs_g_nav_entry, fs_g_seg, fs_g_status, fs_g_u8_current_cache, Fs_segment::u32_addr, Fs_clusterlist_cache::u32_cluster, Fs_management_entry::u32_cluster, Fs_management::u32_offset_data, Fs_management::u32_ptr_fat, Fs_segment::u32_size_or_pos, Fs_clusterlist_cache::u32_start, Fs_management::u8_BPB_SecPerClus, and Fs_clusterlist_cache::u8_lun.

Referenced by file_putc(), file_write(), and file_write_buf().

01118 {
01119    if( 0 == fs_g_nav_entry.u32_cluster )
01120    {
01121       // File don't have a cluster list, then alloc the first cluster list of the file
01122       MSB0(fs_g_seg.u32_addr)    = 0xFF;     // It is a new cluster list
01123       // Update cluster list caches
01124       // fs_g_cluster.u32_pos    = ?         // To fill after alloc
01125       fs_g_seg.u32_size_or_pos   = 0;
01126       fat_cache_clusterlist_update_start(TRUE);
01127    }
01128    else
01129    {
01130       if( fat_read_file( mode ) )
01131          return TRUE;      // A segment is availabled (no alloc necessary)
01132 
01133       if( FS_ERR_OUT_LIST != fs_g_status )
01134       {
01135          return FALSE;     // Error system
01136       }
01137       // fat_read_file is outsize the list then the current cluster list cache contains the last cluster
01138 
01139       // Initialize cluster list caches before alloc routine
01140       fs_g_cache_clusterlist[fs_g_u8_current_cache].u8_lun       = 0xFF;                     // unvalid cache
01141       // fs_g_cache_clusterlist[fs_g_u8_current_cache].u32_cluster  = fs_g_cluster.u32_pos;  // it is the same
01142       fs_g_cache_clusterlist[fs_g_u8_current_cache].u32_start += fs_g_nav.u8_BPB_SecPerClus; // Position of next cluster (the first new)
01143    }
01144 
01145    // Alloc a cluster list
01146    if( FS_CLUST_ACT_SEG == mode )
01147    {
01148       fs_g_seg.u32_size_or_pos = u32_nb_sector_write;
01149    }else{
01150       fs_g_seg.u32_size_or_pos = 1;                                                          // only one sector
01151    }
01152 
01153    //note: fs_g_seg.u32_addr is already initialized with the last cluster value (see fat_cluster_list())
01154    if( !fat_allocfreespace())
01155       return FALSE;
01156    //note: fs_g_seg.u32_addr is the first cluster of the cluster list allocated by alloc_free_space()
01157    //note: fs_g_seg.u32_size_or_pos = number of sectors remaining
01158 
01159    if( 0 == fs_g_nav_entry.u32_cluster )
01160    {
01161       // It is the first cluster list of file, then update following values in cluster list cache
01162       // fs_g_seg.u32_addr = already contzins the first cluster of the file (see alloc_free_space())
01163       fs_g_cache_clusterlist[fs_g_u8_current_cache].u32_cluster = fs_g_seg.u32_addr;
01164       // Update file entry
01165       fs_g_nav_entry.u32_cluster = fs_g_seg.u32_addr;
01166    }
01167 
01168    // Update cluster list cache
01169    if( FS_CLUST_ACT_SEG == mode )
01170    {
01171       fs_g_seg.u32_size_or_pos = u32_nb_sector_write - fs_g_seg.u32_size_or_pos;
01172    }else{
01173       fs_g_seg.u32_size_or_pos = 1 - fs_g_seg.u32_size_or_pos;
01174    }
01175    fs_g_seg.u32_addr = ((fs_g_seg.u32_addr - 2) * fs_g_nav.u8_BPB_SecPerClus)
01176                      + fs_g_nav.u32_ptr_fat + fs_g_nav.u32_offset_data;
01177    fat_cache_clusterlist_update_finish();
01178 
01179    return fat_read_file( mode );    // load the new cluster list
01180 }


Variable Documentation

_GLOBEXT_ _MEM_TYPE_FAST_ Fs_cluster fs_g_cluster

To take time in functions: fat_getfreespace, fat_cluster_list, fat_cluster_val, fat_checkcluster.

Definition at line 403 of file fat.h.

Referenced by fat_allocfreespace(), 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().

_GLOBEXT_ _MEM_TYPE_SLOW_ Fs_management fs_g_nav

Definition at line 394 of file fat.h.

Referenced by fat_allocfreespace(), fat_cache_clusterlist_update_finish(), fat_cache_clusterlist_update_read(), fat_cache_read_sector(), fat_check_device(), fat_check_nav_access_disk(), fat_check_nav_access_file(), fat_clean_zone(), fat_clear_cluster(), fat_clear_entry_info_and_ptr(), fat_cluster_list(), fat_cluster_val(), fat_copy_nav(), fat_format(), fat_getfreespace(), fat_getfreespace_percent(), fat_initialize_dir(), fat_initialize_fat(), fat_invert_nav(), fat_mount(), fat_read_dir(), fat_read_fat32_FSInfo(), fat_read_file(), fat_select_filesystem(), fat_serialnumber(), fat_update_fat2(), fat_write_fat32_FSInfo(), fat_write_file(), fat_write_PBR(), file_load_segment_value(), file_open(), file_read(), file_read_buf(), file_write_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_create(), nav_file_isreadonly(), nav_file_rename(), 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_filterflat_cd(), nav_filterflat_get(), nav_filterflat_gotoparent(), nav_filterflat_mount(), nav_filterflat_next(), nav_filterflat_previous(), nav_filterflat_reset(), nav_filterflat_root(), nav_filterlist_cd(), nav_filterlist_get(), nav_filterlist_goto(), nav_filterlist_gotoindex(), nav_filterlist_gotoparent(), nav_filterlist_mount(), nav_filterlist_nb_ex(), nav_filterlist_next(), nav_filterlist_previous(), nav_filterlist_reset(), nav_filterlist_root(), nav_filterlist_setfilter(), nav_flat_cd(), nav_flat_get(), nav_flat_gotoparent(), nav_flat_mount(), nav_flat_next(), nav_flat_previous(), nav_flat_reset(), nav_flat_root(), nav_getindex(), nav_gotoindex(), nav_partition_cluster_size(), nav_partition_mount(), nav_partition_set(), nav_partition_space(), and nav_reset().

_GLOBEXT_ _MEM_TYPE_SLOW_ Fs_management_entry fs_g_nav_entry

_GLOBEXT_ _MEM_TYPE_FAST_ Fs_management_fast fs_g_nav_fast

_GLOBEXT_ _MEM_TYPE_SLOW_ U8 fs_g_sector[FS_CACHE_SIZE]

_GLOBEXT_ _MEM_TYPE_SLOW_ Fs_sector_cache fs_g_sectorcache

_GLOBEXT_ _MEM_TYPE_FAST_ Fs_segment fs_g_seg

_GLOBEXT_ _MEM_TYPE_SLOW_ U16 fs_g_u16_first_mod_fat

Offset (unit 512B) in fat of the first sector (unit 512B).

Definition at line 408 of file fat.h.

Referenced by fat_clear_info_fat_mod(), fat_cluster_val(), and fat_update_fat2().

_GLOBEXT_ _MEM_TYPE_SLOW_ U16 fs_g_u16_last_mod_fat

Offset (unit 512B) in fat of the last sector (unit 512B).

Definition at line 409 of file fat.h.

Referenced by fat_clear_info_fat_mod(), fat_cluster_val(), and fat_update_fat2().

_GLOBEXT_ _MEM_TYPE_SLOW_ U32 fs_gu32_addrsector

_GLOBEXT_ Bool g_b_no_check_disk

Variables to enable/disable the disk check before each action on disk.

Definition at line 390 of file fat.h.

Referenced by fat_check_device(), nav_checkdisk_disable(), nav_checkdisk_enable(), and nav_reset().

_GLOBEXT_ Bool g_b_string_length

Variables to select LENGTH string mode (initialised in nav_reset()).

Definition at line 387 of file fat.h.

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

_GLOBEXT_ Bool g_b_unicode

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

Definition at line 385 of file fat.h.

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


Generated on Fri Feb 19 02:29:43 2010 for AVR32 UC3 - FSACCESS Services by  doxygen 1.5.5