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, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT 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]
00135 #define  LOW_16_BPB_FSInfo       fs_g_sector[48]
00136 #define  HIGH_16_BPB_FSInfo      fs_g_sector[49]
00138 
00139 
00142 #define  FS_BR_SIGNATURE_LOW     0x55
00143 #define  FS_BR_SIGNATURE_HIGH    0xAA
00145 
00146 
00149 #define  FS_PART_BOOTABLE           0x80
00150 #define  FS_PART_NO_BOOTABLE        0x00
00151 /*
00152    Partition  Fdisk                                               Démarrage dans
00153    Type       Rapports      Taille                 Type de FAT    version
00154    -----------------------------------------------------------------------------
00155    01         PRI DOS       0-15 Mo                12 bits        MS-DOS 2.0
00156    04         PRI DOS       16-32 Mo               16 bits        MS-DOS 3.0
00157    05         EXT DOS       0-2 Go                 n/a            MS-DOS 3.3
00158    06         PRI DOS       32 Mo-2 Go             16 bits        MS-DOS 4.0
00159    0E         PRI DOS       32 Mo-2 Go             16 bits        Windows 95
00160    0F         EXT DOS       0-2 Go                 n/a            Windows 95
00161    0B         PRI DOS       512 Mo - 2 téraoctets  32 bits        OSR2
00162    0C         EXT DOS       512 Mo - 2 téraoctets  32 bits        OSR2
00163 */
00164 #define  FS_PART_TYPE_FAT12         0x01
00165 #define  FS_PART_TYPE_FAT16_INF32M  0x04
00166 #define  FS_PART_TYPE_FAT16_SUP32M  0x06
00167 #define  FS_PART_TYPE_FAT16_SUP32M_BIS  0x0E
00168 #define  FS_PART_TYPE_FAT32         0x0B
00169 #define  FS_PART_TYPE_FAT32_BIS     0x0C
00170 #define  FS_PART_REMOVE_MEDIA       0xF0     // removal media
00171 #define  FS_PART_NO_REMOVE_MEDIA    0xF8     // no removal media
00172 #define  FS_PART_HARD_DISK          0x81     // hard disk
00173 #define  FS_BOOT_SIGN               0x29     // Boot signature
00175 
00176 
00179 #define  FS_FAT12_MAX_CLUSTERS      4085     // Maximum of cluster for FAT 12
00180 #define  FS_FAT16_MAX_CLUSTERS      65525    // Maximum of cluster for FAT 16
00182 
00183 
00186 #define  FS_ENTRY_END               0x00     // end of directory
00187 #define  FS_ENTRY_DEL               0xE5     // deleted entry
00188 #define  FS_ENTRY_LFN_LAST          0x40     // mask to detect the last long name entry
00190 
00191 
00194 #define  FS_SIZE_FILE_ENTRY         32       // Size of the file entry
00195 #define  FS_SHIFT_B_TO_FILE_ENTRY    5       // Shift a unit byte to unit entry file (32,<<5) to unit sector 512B (512,>>9)
00196 #define  FS_SIZE_LFN_ENTRY          13       // Size of name stored in the file entry "long file name" (unit UNICODE = 2bytes)
00197 #define  FS_SIZE_SFNAME             11       // Size of name stored in the file entry "short file name" (unit byte)
00198 #define  FS_SIZE_SFNAME_WITHOUT_EXT  8       // Size of name (without extension) stored in the file entry "short file name" (unit byte)
00199 #define  FS_SIZE_SFNAME_EXT_ONLY     3       // Size of extension name stored in the file entry "short file name" (unit byte)
00201 
00202 
00205 #define  FS_NB_FAT                  2        // This file system managed only 2 FAT
00207 
00208 
00209 //**** Definitions of function configurations
00210 
00213 #define  FS_512B                    512
00214 #define  FS_512B_MASK               (512-1)
00215 #define  FS_512B_SHIFT_BIT          9        // Shift a unit byte to unit sector (512,>>9)
00216 #define  FS_SIZE_OF_SECTOR          FS_512B           // For compliance with old FileSystem module
00217 #define  FS_MASK_SIZE_OF_SECTOR     FS_512B_MASK      // For compliance with old FileSystem module
00218 #define  FS_SHIFT_B_TO_SECTOR       FS_512B_SHIFT_BIT // For compliance with old FileSystem module
00219 #define  FS_CACHE_SIZE              512      // Cache size used by module (unit 512B)
00221 
00223 #define  FS_BUF_SECTOR_EMPTY        0xFF
00224 
00225 
00228 #define  FS_CLUS_OK                 0        // Value correct
00229 #define  FS_CLUS_BAD                1        // Value bad
00230 #define  FS_CLUS_END                2        // It is the end of cluster list
00232 
00233 
00236 #define  FS_CLUST_ACT_SEG           0x01     // Get the sector address and size of the cluster list
00237 #define  FS_CLUST_ACT_ONE           0x02     // Get the sector address of the cluster list
00238 #define  FS_CLUST_ACT_CLR           0x03     // Clear the cluster list
00240 
00241 
00243 #define  FS_CLUST_VAL_READ          FALSE      // Mode read
00244 #define  FS_CLUST_VAL_WRITE         TRUE       // Mode write
00245 #define  FS_CLUST_VAL_EOL           0x0FFFFFFF // Value to signal the end of cluster list
00247 
00248 
00251 
00253 typedef union
00254 {
00255    U32  u32_cluster;                   
00256    struct
00257    {
00258       U16  u16_pos;                    
00259       U16  u16_size;                   
00260    } seg;                              
00261 } Fs_rootdir;
00262 
00264 typedef struct
00265 {
00266    U8    u8_lun;                       
00267 #if (FS_MULTI_PARTITION == ENABLED)
00268    U8    u8_partition;                 
00269 #endif
00270    U8    u8_BPB_SecPerClus;            
00271    // The pointers start at beginning of the memory, and unit = 512B
00272    U16   u16_fat_size;                 
00273    U16   u16_offset_FSInfo;            
00274    U32   u32_CountofCluster;           
00275    U32   u32_ptr_fat;                  
00276    U32   u32_offset_data;              
00277    Fs_rootdir     rootdir;             
00278    U16   u16_entry_pos_sel_dir;        
00279    U32   u32_cluster_sel_dir;          
00280    U16   u16_pos_sel_file;             
00281    U16   u16_pos_filterlist;           
00282    FS_STRING sz_filterext;             
00283    U8    b_mode_nav;                   
00284    U8    b_mode_nav_single;            
00285    U8    u8_flat_dir_level;            
00286    U16   u16_flat_pos_offset;          
00287 } Fs_management;
00288 
00290 typedef struct
00291 {
00292    U8    u8_type_fat;                  
00293    U16   u16_entry_pos_sel_file;       
00294 } Fs_management_fast;
00295 
00297 typedef struct
00298 {
00299    U8    u8_open_mode;                 
00300    U8    u8_txt_format;                
00301    U8    u8_attr;                      
00302    U32   u32_cluster;                  
00303    U32   u32_size;                     
00304    U32   u32_pos_in_file;              
00305 } Fs_management_entry;
00307 
00308 
00311 
00313 typedef struct {
00314    U32  u32_addr;                      
00315    U32  u32_size_or_pos;               
00316 } Fs_segment;
00317 
00319 typedef struct st_fs_cluster
00320 {
00321    U32   u32_pos;                      
00322    U32   u32_val;                      
00323 } Fs_cluster;
00324 
00326 
00327 
00329 typedef struct {
00330    Bool  b_cache_file;                 
00331    U8    u8_level_use;                 
00332    U8    u8_lun;                       
00333    U32   u32_cluster;                  
00334    U32   u32_start;                    
00335    U32   u32_addr;                     
00336    U32   u32_size;                     
00337 } Fs_clusterlist_cache;
00338 
00339 
00341 typedef struct {
00342    U8    u8_lun;                       
00343    U32   u32_addr;                     
00344    U8    u8_dirty;                     
00345 
00346    U32   u32_clusterlist_start;        
00347    U32   u32_clusterlist_pos;          
00348 } Fs_sector_cache;
00349 
00350 
00351 //**** Definition of value used by the STRUCTURES of communication
00352 
00355 #define  FS_TYPE_FAT_UNM   0           
00356 #define  FS_TYPE_FAT_12    1
00357 #define  FS_TYPE_FAT_16    2
00358 #define  FS_TYPE_FAT_32    3
00360 
00361 
00364 #define  FS_NO_SEL         0xFFFF      
00365 #define  FS_END_FIND       0xFFFE      
00366 
00367 
00368 
00371 #define  Fat_file_is_open()     (fs_g_nav_entry.u8_open_mode !=0 )
00372 #define  Fat_file_isnot_open()  (fs_g_nav_entry.u8_open_mode ==0 )
00373 #define  Fat_file_close()       (fs_g_nav_entry.u8_open_mode  =0 )
00375 
00376 
00377 //_____ D E C L A R A T I O N S ____________________________________________
00378 
00379 //**** Global file system variables
00380 
00382 _GLOBEXT_                     Bool                 g_b_unicode;
00384 _GLOBEXT_                     Bool                 g_b_string_length;
00385 
00387 _GLOBEXT_                     Bool                 g_b_no_check_disk;
00388 
00391 _GLOBEXT_   _MEM_TYPE_SLOW_   Fs_management        fs_g_nav;
00392 _GLOBEXT_   _MEM_TYPE_FAST_   Fs_management_fast   fs_g_nav_fast;
00393 _GLOBEXT_   _MEM_TYPE_SLOW_   Fs_management_entry  fs_g_nav_entry;
00395 
00397 _GLOBEXT_   _MEM_TYPE_FAST_   Fs_segment           fs_g_seg;
00398 
00400 _GLOBEXT_   _MEM_TYPE_FAST_   Fs_cluster           fs_g_cluster;
00401 
00402 #if (FS_LEVEL_FEATURES > FSFEATURE_READ)
00405 _GLOBEXT_   _MEM_TYPE_SLOW_   U16                  fs_g_u16_first_mod_fat; 
00406 _GLOBEXT_   _MEM_TYPE_SLOW_   U16                  fs_g_u16_last_mod_fat;  
00407 
00408 #endif  // FS_LEVEL_FEATURES
00409 
00412 _GLOBEXT_   _MEM_TYPE_SLOW_   U8                   fs_g_sector[ FS_CACHE_SIZE ];
00413 _GLOBEXT_   _MEM_TYPE_SLOW_   Fs_sector_cache      fs_g_sectorcache;
00414 _GLOBEXT_   _MEM_TYPE_SLOW_   U32                  fs_gu32_addrsector;     
00415 typedef U8  _MEM_TYPE_SLOW_   * PTR_CACHE;
00417 
00418 
00419 
00420 
00423 Bool        fat_check_device              ( void );
00424 Bool        fat_check_mount               ( void );
00425 Bool        fat_check_noopen              ( void );
00426 Bool        fat_check_open                ( void );
00427 Bool        fat_check_select              ( void );
00428 Bool        fat_check_mount_noopen        ( void );
00429 Bool        fat_check_mount_select_noopen ( void );
00430 Bool        fat_check_mount_select_open   ( void );
00431 Bool        fat_check_mount_select        ( void );
00432 Bool        fat_check_is_file             ( void );
00434 
00436 U8          fat_get_nbpartition           ( void );
00437 
00439 Bool        fat_mount                     ( void );
00440 
00442 Bool        fat_format                    ( U8 u8_fat_type );
00443 
00445 Bool        fat_serialnumber              ( Bool b_action , U8 _MEM_TYPE_SLOW_ *a_u8_sn );
00446 
00447 
00450 U32         fat_getfreespace              ( void );
00451 U8          fat_getfreespace_percent      ( void );
00452 Bool        fat_write_fat32_FSInfo        ( U32 u32_nb_free_cluster );
00453 U32         fat_read_fat32_FSInfo         ( void );
00455 
00456 
00459 Bool        fat_cluster_list              ( U8 opt_action, Bool b_for_file );
00460 void        fat_cache_clusterlist_reset   ( void );
00461 Bool        fat_cluster_val               ( Bool b_mode );
00462 Bool        fat_cluster_readnext          ( void );
00463 U8          fat_checkcluster              ( void );
00464 Bool        fat_allocfreespace            ( void );
00465 void        fat_clear_info_fat_mod        ( void );
00466 Bool        fat_clear_cluster             ( void );
00467 Bool        fat_update_fat2               ( void );
00469 
00470 
00473 Bool        fat_read_file                 ( U8 mode );
00474 Bool        fat_write_file                ( U8 mode , U32 u32_nb_sector_write );
00475 Bool        fat_read_dir                  ( void );
00476 Bool        fat_initialize_dir            ( void );
00478 
00479 
00482 Bool        fat_entry_check               ( Bool b_type );
00483 Bool        fat_entry_checkext            ( FS_STRING sz_filter );
00484 void        fat_get_entry_info            ( void );
00485 Bool        fat_entry_is_dir              ( void );
00486 void        fat_clear_entry_info_and_ptr  ( void );
00487 void        fat_write_entry_file          ( void );
00488 Bool        fat_entry_shortname           ( FS_STRING sz_name , U8 u8_size_max , Bool b_mode );
00489 Bool        fat_entry_longname            ( FS_STRING sz_name , U8 u8_size_max , Bool b_mode , Bool b_match_case );
00490 Bool        fat_check_eof_name            ( U16 character );
00491 PTR_CACHE   fat_get_ptr_entry             ( void );
00493 
00494 
00497 Bool        fat_create_entry_file_name    ( FS_STRING sz_name );
00498 void        fat_get_date                  ( FS_STRING sz_date , Bool type_date );
00499 void        fat_set_date                  ( const FS_STRING sz_date , Bool type_date );
00500 Bool        fat_delete_file               ( Bool b_cluster_list );
00501 Bool        fat_entry_label               ( Bool b_action , FS_STRING sz_label );
00503 
00504 
00507 Bool        fat_cache_read_sector         ( Bool b_load );
00508 void        fat_cache_reset               ( void );
00509 void        fat_cache_clear               ( void );
00510 void        fat_cache_mark_sector_as_dirty( void );
00511 Bool        fat_cache_flush               ( void );
00513 
00514 
00517 #if (FS_NB_NAVIGATOR > 1)
00518    Bool     fat_check_nav_access_disk     ( void );
00519    Bool     fat_check_nav_access_file     ( Bool mode );
00520 #else
00521 # define    fat_check_nav_access_disk(b)  (TRUE)            
00522 # define    fat_check_nav_access_file(b)  (TRUE)            
00523 #endif
00525 
00526 
00529 #if (FS_NB_NAVIGATOR > 1)
00530    void     fat_invert_nav                ( U8 u8_idnav );
00531    void     fat_copy_nav                  ( U8 u8_idnav );
00532 #else
00533 # define    fat_invert_nav                ( arg )  (arg++)  
00534 # define    fat_copy_nav                  ( arg )  (arg++)  
00535 #endif
00537 
00538 #endif  // _FAT_H_

Generated on Fri May 15 15:41:36 2009 for ATMEL by  doxygen 1.5.3