fat.h

Go to the documentation of this file.
00001 /*This file has been prepared for Doxygen automatic documentation generation.*/
00014 /* Copyright (C) 2006-2008, Atmel Corporation All rights reserved.
00015  *
00016  * Redistribution and use in source and binary forms, with or without
00017  * modification, are permitted provided that the following conditions are met:
00018  *
00019  * 1. Redistributions of source code must retain the above copyright notice,
00020  * this list of conditions and the following disclaimer.
00021  *
00022  * 2. Redistributions in binary form must reproduce the above copyright notice,
00023  * this list of conditions and the following disclaimer in the documentation
00024  * and/or other materials provided with the distribution.
00025  *
00026  * 3. The name of ATMEL may not be used to endorse or promote products derived
00027  * from this software without specific prior written permission.
00028  *
00029  * THIS SOFTWARE IS PROVIDED BY ATMEL ``AS IS'' AND ANY EXPRESS OR IMPLIED
00030  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
00031  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE EXPRESSLY AND
00032  * SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT,
00033  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
00034  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00035  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
00036  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00037  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
00038  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00039  */
00040 
00041 #ifndef _FAT_H_
00042 #define _FAT_H_
00043 
00044 #include "fs_com.h"
00045 
00055 
00056 
00057 #undef _GLOBEXT_
00058 #if (defined _fat_c_)
00059 #  define _GLOBEXT_
00060 #else
00061 #  define _GLOBEXT_ extern
00062 #endif
00063 
00064 //_____ I N C L U D E S ____________________________________________________
00065 
00066 
00067 //_____ M A C R O S ________________________________________________________
00068 
00069 
00070 // To optimize the code
00071 #if (FS_FAT_12 == ENABLED)
00072 #  define   Is_fat12    (FS_TYPE_FAT_12 == fs_g_nav_fast.u8_type_fat)
00073 #else
00074 #  define   Is_fat12    (0)
00075 #endif
00076 #if (FS_FAT_16 == ENABLED)
00077 #  define   Is_fat16    (FS_TYPE_FAT_16 == fs_g_nav_fast.u8_type_fat)
00078 #else
00079 #  define   Is_fat16    (0)
00080 #endif
00081 #if (FS_FAT_32 == ENABLED)
00082 #  define   Is_fat32    (FS_TYPE_FAT_32 == fs_g_nav_fast.u8_type_fat)
00083 #else
00084 #  define   Is_fat32    (0)
00085 #endif
00086 
00087 // Tor optimize the code
00088 #if ( (FS_ASCII   == ENABLED) && (FS_UNICODE == ENABLED))
00089 #  define   Is_unicode  (g_b_unicode)
00090 #elif (FS_ASCII   == ENABLED)
00091 #  define   Is_unicode  (0)
00092 #elif (FS_UNICODE == ENABLED)
00093 #  define   Is_unicode  (1)
00094 #else
00095 #  error You must define FS_ASCII or/and FS_UNICODE enable in conf_explorer.h
00096 #endif
00097 
00098 
00099 //_____ D E F I N I T I O N S ______________________________________________
00100 
00101 
00102 //**** Definitions corresponding at the FAT norm ****
00103 
00105 #define  FS_MBR_OFFSET_PART_ENTRY( num )  ((U16)((U16)(0x1BE)+(0x10 * num)))  // Partition entry num (0 to 4)
00106 
00107 
00111 #define  LOW_16_BPB_BytsPerSec   fs_g_sector[11]
00112 #define  HIGH_16_BPB_BytsPerSec  fs_g_sector[12]
00113 #define  U8_BPB_SecPerClus       fs_g_sector[13]
00114 #define  LOW_16_BPB_RootEntCnt   fs_g_sector[17]
00115 #define  HIGH_16_BPB_RootEntCnt  fs_g_sector[18]
00116 #define  LOW_16_BPB_FATSz16      fs_g_sector[22]
00117 #define  HIGH_16_BPB_FATSz16     fs_g_sector[23]
00118 #define  LOW0_32_BPB_FATSz32     fs_g_sector[36]
00119 #define  LOW1_32_BPB_FATSz32     fs_g_sector[37]
00120 #define  LOW2_32_BPB_FATSz32     fs_g_sector[38]
00121 #define  LOW3_32_BPB_FATSz32     fs_g_sector[39]
00122 #define  LOW_16_BPB_TotSec16     fs_g_sector[19]
00123 #define  HIGH_16_BPB_TotSec16    fs_g_sector[20]
00124 #define  LOW0_32_BPB_TotSec32    fs_g_sector[32]
00125 #define  LOW1_32_BPB_TotSec32    fs_g_sector[33]
00126 #define  LOW2_32_BPB_TotSec32    fs_g_sector[34]
00127 #define  LOW3_32_BPB_TotSec32    fs_g_sector[35]
00128 #define  LOW_16_BPB_ResvSecCnt   fs_g_sector[14]
00129 #define  HIGH_16_BPB_ResvSecCnt  fs_g_sector[15]
00130 #define  U8_BPB_NumFATs          fs_g_sector[16]
00131 #define  LOW0_32_BPB_RootClus    fs_g_sector[44]
00132 #define  LOW1_32_BPB_RootClus    fs_g_sector[45]
00133 #define  LOW2_32_BPB_RootClus    fs_g_sector[46]
00134 #define  LOW3_32_BPB_RootClus    fs_g_sector[47]
00136 
00137 
00140 #define  FS_BR_SIGNATURE_LOW     0x55
00141 #define  FS_BR_SIGNATURE_HIGH    0xAA
00143 
00144 
00147 #define  FS_PART_BOOTABLE           0x80
00148 #define  FS_PART_NO_BOOTABLE        0x00
00149 /*
00150    Partition  Fdisk                                               Démarrage dans
00151    Type       Rapports      Taille                 Type de FAT    version
00152    -----------------------------------------------------------------------------
00153    01         PRI DOS       0-15 Mo                12 bits        MS-DOS 2.0
00154    04         PRI DOS       16-32 Mo               16 bits        MS-DOS 3.0
00155    05         EXT DOS       0-2 Go                 n/a            MS-DOS 3.3
00156    06         PRI DOS       32 Mo-2 Go             16 bits        MS-DOS 4.0
00157    0E         PRI DOS       32 Mo-2 Go             16 bits        Windows 95
00158    0F         EXT DOS       0-2 Go                 n/a            Windows 95
00159    0B         PRI DOS       512 Mo - 2 téraoctets  32 bits        OSR2
00160    0C         EXT DOS       512 Mo - 2 téraoctets  32 bits        OSR2
00161 */
00162 #define  FS_PART_TYPE_FAT12         0x01
00163 #define  FS_PART_TYPE_FAT16_INF32M  0x04
00164 #define  FS_PART_TYPE_FAT16_SUP32M  0x06
00165 #define  FS_PART_TYPE_FAT16_SUP32M_BIS  0x0E
00166 #define  FS_PART_TYPE_FAT32         0x0B
00167 #define  FS_PART_TYPE_FAT32_BIS     0x0C
00168 #define  FS_PART_REMOVE_MEDIA       0xF0     // removal media
00169 #define  FS_PART_NO_REMOVE_MEDIA    0xF8     // no removal media
00170 #define  FS_PART_HARD_DISK          0x81     // hard disk
00171 #define  FS_BOOT_SIGN               0x29     // Boot signature
00173 
00174 
00177 #define  FS_FAT12_MAX_CLUSTERS      4085     // Maximum of cluster for FAT 12
00178 #define  FS_FAT16_MAX_CLUSTERS      65525    // Maximum of cluster for FAT 16
00180 
00181 
00184 #define  FS_ENTRY_END               0x00     // end of directory
00185 #define  FS_ENTRY_DEL               0xE5     // deleted entry
00186 #define  FS_ENTRY_LFN_LAST          0x40     // mask to detect the last long name entry
00188 
00189 
00192 #define  FS_SIZE_FILE_ENTRY         32       // Size of the file entry
00193 #define  FS_SHIFT_B_TO_FILE_ENTRY    5       // Shift a unit byte to unit entry file (32,<<5) to unit sector 512B (512,>>9)
00194 #define  FS_SIZE_LFN_ENTRY          13       // Size of name stored in the file entry "long file name" (unit UNICODE = 2bytes)
00195 #define  FS_SIZE_SFNAME             11       // Size of name stored in the file entry "short file name" (unit byte)
00196 #define  FS_SIZE_SFNAME_WITHOUT_EXT  8       // Size of name (without extension) stored in the file entry "short file name" (unit byte)
00197 #define  FS_SIZE_SFNAME_EXT_ONLY     3       // Size of extension name stored in the file entry "short file name" (unit byte)
00199 
00200 
00203 #define  FS_NB_FAT                  2        // This file system managed only 2 FAT
00205 
00206 
00207 //**** Definitions of function configurations
00208 
00211 #define  FS_512B                    512
00212 #define  FS_512B_MASK               (512-1)
00213 #define  FS_512B_SHIFT_BIT          9        // Shift a unit byte to unit sector (512,>>9)
00214 #define  FS_SIZE_OF_SECTOR          FS_512B           // For compliance with old FileSystem module
00215 #define  FS_MASK_SIZE_OF_SECTOR     FS_512B_MASK      // For compliance with old FileSystem module
00216 #define  FS_SHIFT_B_TO_SECTOR       FS_512B_SHIFT_BIT // For compliance with old FileSystem module
00217 #define  FS_CACHE_SIZE              512      // Cache size used by module (unit 512B)
00219 
00221 #define  FS_BUF_SECTOR_EMPTY        0xFF
00222 
00223 
00226 #define  FS_CLUS_OK                 0        // Value correct
00227 #define  FS_CLUS_BAD                1        // Value bad
00228 #define  FS_CLUS_END                2        // It is the end of cluster list
00230 
00231 
00234 #define  FS_CLUST_ACT_SEG           0x01     // Get the sector address and size of the cluster list
00235 #define  FS_CLUST_ACT_ONE           0x02     // Get the sector address of the cluster list
00236 #define  FS_CLUST_ACT_CLR           0x03     // Clear the cluster list
00238 
00239 
00241 #define  FS_CLUST_VAL_READ          FALSE      // Mode read
00242 #define  FS_CLUST_VAL_WRITE         TRUE       // Mode write
00243 #define  FS_CLUST_VAL_EOL           0x0FFFFFFF // Value to signal the end of cluster list
00245 
00246 
00249 
00251 typedef union
00252 {
00253    U32  u32_cluster;                   
00254    struct
00255    {
00256       U16  u16_pos;                    
00257       U16  u16_size;                   
00258    } seg;                              
00259 } Fs_rootdir;
00260 
00262 typedef struct
00263 {
00264    U8    u8_lun;                       
00265 #if (FS_MULTI_PARTITION == ENABLED)
00266    U8    u8_partition;                 
00267 #endif
00268    U8    u8_BPB_SecPerClus;            
00269    // The pointers start at beginning of the memory, and unit = 512B
00270    U16   u16_fat_size;                 
00271    U32   u32_CountofCluster;           
00272    U32   u32_ptr_fat;                  
00273    U32   u32_offset_data;              
00274    Fs_rootdir     rootdir;             
00275    U16   u16_entry_pos_sel_dir;        
00276    U32   u32_cluster_sel_dir;          
00277    U16   u16_pos_sel_file;             
00278    U16   u16_pos_filterlist;           
00279    FS_STRING sz_filterext;             
00280    U8    b_mode_nav;                   
00281    U8    b_mode_nav_single;            
00282    U8    u8_flat_dir_level;            
00283    U16   u16_flat_pos_offset;          
00284 } Fs_management;
00285 
00287 typedef struct
00288 {
00289    U8    u8_type_fat;                  
00290    U16   u16_entry_pos_sel_file;       
00291 } Fs_management_fast;
00292 
00294 typedef struct
00295 {
00296    U8    u8_open_mode;                 
00297    U8    u8_txt_format;                
00298    U8    u8_attr;                      
00299    U32   u32_cluster;                  
00300    U32   u32_size;                     
00301    U32   u32_pos_in_file;              
00302 } Fs_management_entry;
00304 
00305 
00308 
00310 typedef struct {
00311    U32  u32_addr;                      
00312    U32  u32_size_or_pos;               
00313 } Fs_segment;
00314 
00316 typedef struct st_fs_cluster
00317 {
00318    U32   u32_pos;                      
00319    U32   u32_val;                      
00320 } Fs_cluster;
00321 
00323 
00324 
00326 typedef struct {
00327    Bool  b_cache_file;                 
00328    U8    u8_level_use;                 
00329    U8    u8_lun;                       
00330    U32   u32_cluster;                  
00331    U32   u32_start;                    
00332    U32   u32_addr;                     
00333    U32   u32_size;                     
00334 } Fs_clusterlist_cache;
00335 
00336 
00338 typedef struct {
00339    U8    u8_lun;                       
00340    U32   u32_addr;                     
00341    U8    u8_dirty;                     
00342 
00343    U32   u32_clusterlist_start;        
00344    U32   u32_clusterlist_pos;          
00345 } Fs_sector_cache;
00346 
00347 
00348 //**** Definition of value used by the STRUCTURES of communication
00349 
00352 #define  FS_TYPE_FAT_UNM   0           
00353 #define  FS_TYPE_FAT_12    1
00354 #define  FS_TYPE_FAT_16    2
00355 #define  FS_TYPE_FAT_32    3
00357 
00358 
00361 #define  FS_NO_SEL         0xFFFF      
00362 #define  FS_END_FIND       0xFFFE      
00363 
00364 
00365 
00368 #define  Fat_file_is_open()     (fs_g_nav_entry.u8_open_mode !=0 )
00369 #define  Fat_file_isnot_open()  (fs_g_nav_entry.u8_open_mode ==0 )
00370 #define  Fat_file_close()       (fs_g_nav_entry.u8_open_mode  =0 )
00372 
00373 
00374 //_____ D E C L A R A T I O N S ____________________________________________
00375 
00376 //**** Global file system variables
00377 
00379 _GLOBEXT_                     Bool                 g_b_unicode;
00381 _GLOBEXT_                     Bool                 g_b_string_length;
00382 
00384 _GLOBEXT_                     Bool                 g_b_no_check_disk;
00385 
00388 _GLOBEXT_   _MEM_TYPE_SLOW_   Fs_management        fs_g_nav;
00389 _GLOBEXT_   _MEM_TYPE_FAST_   Fs_management_fast   fs_g_nav_fast;
00390 _GLOBEXT_   _MEM_TYPE_SLOW_   Fs_management_entry  fs_g_nav_entry;
00392 
00394 _GLOBEXT_   _MEM_TYPE_FAST_   Fs_segment           fs_g_seg;
00395 
00397 _GLOBEXT_   _MEM_TYPE_FAST_   Fs_cluster           fs_g_cluster;
00398 
00399 #if (FS_LEVEL_FEATURES > FSFEATURE_READ)
00402 _GLOBEXT_   _MEM_TYPE_SLOW_   U16                  fs_g_u16_first_mod_fat; 
00403 _GLOBEXT_   _MEM_TYPE_SLOW_   U16                  fs_g_u16_last_mod_fat;  
00404 
00405 #endif  // FS_LEVEL_FEATURES
00406 
00409 _GLOBEXT_   _MEM_TYPE_SLOW_   U8                   fs_g_sector[ FS_CACHE_SIZE ];
00410 _GLOBEXT_   _MEM_TYPE_SLOW_   Fs_sector_cache      fs_g_sectorcache;
00411 _GLOBEXT_   _MEM_TYPE_SLOW_   U32                  fs_gu32_addrsector;     
00412 typedef U8  _MEM_TYPE_SLOW_   * PTR_CACHE;
00414 
00415 
00416 
00417 
00420 Bool        fat_check_device              ( void );
00421 Bool        fat_check_mount               ( void );
00422 Bool        fat_check_noopen              ( void );
00423 Bool        fat_check_open                ( void );
00424 Bool        fat_check_select              ( void );
00425 Bool        fat_check_mount_noopen        ( void );
00426 Bool        fat_check_mount_select_noopen ( void );
00427 Bool        fat_check_mount_select_open   ( void );
00428 Bool        fat_check_mount_select        ( void );
00429 Bool        fat_check_is_file             ( void );
00431 
00433 U8          fat_get_nbpartition           ( void );
00434 
00436 Bool        fat_mount                     ( void );
00437 
00439 Bool        fat_format                    ( U8 u8_fat_type );
00440 
00442 Bool        fat_serialnumber              ( Bool b_action , U8 _MEM_TYPE_SLOW_ *a_u8_sn );
00443 
00444 
00447 U32         fat_getfreespace              ( void );
00448 U8          fat_getfreespace_percent      ( void );
00449 Bool        fat_write_fat32_FSInfo        ( U32 u32_nb_free_cluster );
00450 U32         fat_read_fat32_FSInfo         ( void );
00452 
00453 
00456 Bool        fat_cluster_list              ( U8 opt_action, Bool b_for_file );
00457 void        fat_cache_clusterlist_reset   ( void );
00458 Bool        fat_cluster_val               ( Bool b_mode );
00459 Bool        fat_cluster_readnext          ( void );
00460 U8          fat_checkcluster              ( void );
00461 Bool        fat_allocfreespace            ( void );
00462 void        fat_clear_info_fat_mod        ( void );
00463 Bool        fat_clear_cluster             ( void );
00464 Bool        fat_update_fat2               ( void );
00466 
00467 
00470 Bool        fat_read_file                 ( U8 mode );
00471 Bool        fat_write_file                ( U8 mode , U32 u32_nb_sector_write );
00472 Bool        fat_read_dir                  ( void );
00473 Bool        fat_initialize_dir            ( void );
00475 
00476 
00479 Bool        fat_entry_check               ( Bool b_type );
00480 Bool        fat_entry_checkext            ( FS_STRING sz_filter );
00481 void        fat_get_entry_info            ( void );
00482 Bool        fat_entry_is_dir              ( void );
00483 void        fat_clear_entry_info_and_ptr  ( void );
00484 void        fat_write_entry_file          ( void );
00485 Bool        fat_entry_shortname           ( FS_STRING sz_name , U8 u8_size_max , Bool b_mode );
00486 Bool        fat_entry_longname            ( FS_STRING sz_name , U8 u8_size_max , Bool b_mode , Bool b_match_case );
00487 Bool        fat_check_eof_name            ( U16 character );
00488 PTR_CACHE   fat_get_ptr_entry             ( void );
00490 
00491 
00494 Bool        fat_create_entry_file_name    ( FS_STRING sz_name );
00495 void        fat_get_date                  ( FS_STRING sz_date , Bool type_date );
00496 void        fat_set_date                  ( const FS_STRING sz_date , Bool type_date );
00497 Bool        fat_delete_file               ( Bool b_cluster_list );
00498 Bool        fat_entry_label               ( Bool b_action , FS_STRING sz_label );
00500 
00501 
00504 Bool        fat_cache_read_sector         ( Bool b_load );
00505 void        fat_cache_reset               ( void );
00506 void        fat_cache_clear               ( void );
00507 void        fat_cache_mark_sector_as_dirty( void );
00508 Bool        fat_cache_flush               ( void );
00510 
00511 
00514 #if (FS_NB_NAVIGATOR > 1)
00515    Bool     fat_check_nav_access_disk     ( void );
00516    Bool     fat_check_nav_access_file     ( Bool mode );
00517 #else
00518 # define    fat_check_nav_access_disk(b)  (TRUE)            
00519 # define    fat_check_nav_access_file(b)  (TRUE)            
00520 #endif
00522 
00523 
00526 #if (FS_NB_NAVIGATOR > 1)
00527    void     fat_invert_nav                ( U8 u8_idnav );
00528    void     fat_copy_nav                  ( U8 u8_idnav );
00529 #else
00530 # define    fat_invert_nav                ( arg )  (arg++)  
00531 # define    fat_copy_nav                  ( arg )  (arg++)  
00532 #endif
00534 
00535 #endif  // _FAT_H_

Generated on Fri Oct 31 16:13:16 2008 for ATMEL by  doxygen 1.5.3