ATMEL: fat.h Source File

- Main Page
- Modules
- Data Structures
- Files
- Related Pages

# fat.h

Go to the documentation of this file.

    00001 /*This file is 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  * 4. This software may only be redistributed and used in connection with an Atmel
    00030  * AVR product.
    00031  *
    00032  * THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR IMPLIED
    00033  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
    00034  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE EXPRESSLY AND
    00035  * SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT,
    00036  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
    00037  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
    00038  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
    00039  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
    00040  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
    00041  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    00042  */
    00043
    00044 #ifndef _FAT_H_
    00045 #define _FAT_H_
    00046
    00047 #include "fs_com.h"
    00048
    00058
    00059
    00060 #undef _GLOBEXT_
    00061 #if (defined _fat_c_)
    00062 #  define _GLOBEXT_
    00063 #else
    00064 #  define _GLOBEXT_ extern
    00065 #endif
    00066
    00067 //_____ I N C L U D E S ____________________________________________________
    00068
    00069
    00070 //_____ M A C R O S ________________________________________________________
    00071
    00072
    00073 // To optimize the code
    00074 #if (FS_FAT_12 == ENABLED)
    00075 #  define   Is_fat12    (FS_TYPE_FAT_12 == fs_g_nav_fast.u8_type_fat)
    00076 #else
    00077 #  define   Is_fat12    (0)
    00078 #endif
    00079 #if (FS_FAT_16 == ENABLED)
    00080 #  define   Is_fat16    (FS_TYPE_FAT_16 == fs_g_nav_fast.u8_type_fat)
    00081 #else
    00082 #  define   Is_fat16    (0)
    00083 #endif
    00084 #if (FS_FAT_32 == ENABLED)
    00085 #  define   Is_fat32    (FS_TYPE_FAT_32 == fs_g_nav_fast.u8_type_fat)
    00086 #else
    00087 #  define   Is_fat32    (0)
    00088 #endif
    00089
    00090 // Tor optimize the code
    00091 #if ( (FS_ASCII   == ENABLED) && (FS_UNICODE == ENABLED))
    00092 #  define   Is_unicode  (g_b_unicode)
    00093 #elif (FS_ASCII   == ENABLED)
    00094 #  define   Is_unicode  (0)
    00095 #elif (FS_UNICODE == ENABLED)
    00096 #  define   Is_unicode  (1)
    00097 #else
    00098 #  error You must define FS_ASCII or/and FS_UNICODE enable in conf_explorer.h
    00099 #endif
    00100
    00101
    00102 //_____ D E F I N I T I O N S ______________________________________________
    00103
    00104
    00105 //**** Definitions corresponding at the FAT norm ****
    00106
    00108 #define  FS_MBR_OFFSET_PART_ENTRY( num )  ((U16)((U16)(0x1BE)+(0x10 * num)))  // Partition entry num (0 to 4)
    00109
    00110
    00114 #define  LOW_16_BPB_BytsPerSec   fs_g_sector[11]
    00115 #define  HIGH_16_BPB_BytsPerSec  fs_g_sector[12]
    00116 #define  U8_BPB_SecPerClus       fs_g_sector[13]
    00117 #define  LOW_16_BPB_RootEntCnt   fs_g_sector[17]
    00118 #define  HIGH_16_BPB_RootEntCnt  fs_g_sector[18]
    00119 #define  LOW_16_BPB_FATSz16      fs_g_sector[22]
    00120 #define  HIGH_16_BPB_FATSz16     fs_g_sector[23]
    00121 #define  LOW0_32_BPB_FATSz32     fs_g_sector[36]
    00122 #define  LOW1_32_BPB_FATSz32     fs_g_sector[37]
    00123 #define  LOW2_32_BPB_FATSz32     fs_g_sector[38]
    00124 #define  LOW3_32_BPB_FATSz32     fs_g_sector[39]
    00125 #define  LOW_16_BPB_TotSec16     fs_g_sector[19]
    00126 #define  HIGH_16_BPB_TotSec16    fs_g_sector[20]
    00127 #define  LOW0_32_BPB_TotSec32    fs_g_sector[32]
    00128 #define  LOW1_32_BPB_TotSec32    fs_g_sector[33]
    00129 #define  LOW2_32_BPB_TotSec32    fs_g_sector[34]
    00130 #define  LOW3_32_BPB_TotSec32    fs_g_sector[35]
    00131 #define  LOW_16_BPB_ResvSecCnt   fs_g_sector[14]
    00132 #define  HIGH_16_BPB_ResvSecCnt  fs_g_sector[15]
    00133 #define  U8_BPB_NumFATs          fs_g_sector[16]
    00134 #define  LOW0_32_BPB_RootClus    fs_g_sector[44]
    00135 #define  LOW1_32_BPB_RootClus    fs_g_sector[45]
    00136 #define  LOW2_32_BPB_RootClus    fs_g_sector[46]
    00137 #define  LOW3_32_BPB_RootClus    fs_g_sector[47]
    00138 #define  LOW_16_BPB_FSInfo       fs_g_sector[48]
    00139 #define  HIGH_16_BPB_FSInfo      fs_g_sector[49]
    00141
    00142
    00145 #define  FS_BR_SIGNATURE_LOW     0x55
    00146 #define  FS_BR_SIGNATURE_HIGH    0xAA
    00148
    00149
    00152 #define  FS_PART_BOOTABLE           0x80
    00153 #define  FS_PART_NO_BOOTABLE        0x00
    00154 /*
    00155    Partition  Fdisk                                               Démarrage dans
    00156    Type       Rapports      Taille                 Type de FAT    version
    00157    -----------------------------------------------------------------------------
    00158    01         PRI DOS       0-15 Mo                12 bits        MS-DOS 2.0
    00159    04         PRI DOS       16-32 Mo               16 bits        MS-DOS 3.0
    00160    05         EXT DOS       0-2 Go                 n/a            MS-DOS 3.3
    00161    06         PRI DOS       32 Mo-2 Go             16 bits        MS-DOS 4.0
    00162    0E         PRI DOS       32 Mo-2 Go             16 bits        Windows 95
    00163    0F         EXT DOS       0-2 Go                 n/a            Windows 95
    00164    0B         PRI DOS       512 Mo - 2 téraoctets  32 bits        OSR2
    00165    0C         EXT DOS       512 Mo - 2 téraoctets  32 bits        OSR2
    00166 */
    00167 #define  FS_PART_TYPE_FAT12         0x01
    00168 #define  FS_PART_TYPE_FAT16_INF32M  0x04
    00169 #define  FS_PART_TYPE_FAT16_SUP32M  0x06
    00170 #define  FS_PART_TYPE_FAT16_SUP32M_BIS  0x0E
    00171 #define  FS_PART_TYPE_FAT32         0x0B
    00172 #define  FS_PART_TYPE_FAT32_BIS     0x0C
    00173 #define  FS_PART_REMOVE_MEDIA       0xF0     // removal media
    00174 #define  FS_PART_NO_REMOVE_MEDIA    0xF8     // no removal media
    00175 #define  FS_PART_HARD_DISK          0x81     // hard disk
    00176 #define  FS_BOOT_SIGN               0x29     // Boot signature
    00178
    00179
    00182 #define  FS_FAT12_MAX_CLUSTERS      4085     // Maximum of cluster for FAT 12
    00183 #define  FS_FAT16_MAX_CLUSTERS      65525    // Maximum of cluster for FAT 16
    00185
    00186
    00189 #define  FS_ENTRY_END               0x00     // end of directory
    00190 #define  FS_ENTRY_DEL               0xE5     // deleted entry
    00191 #define  FS_ENTRY_LFN_LAST          0x40     // mask to detect the last long name entry
    00193
    00194
    00197 #define  FS_SIZE_FILE_ENTRY         32       // Size of the file entry
    00198 #define  FS_SHIFT_B_TO_FILE_ENTRY    5       // Shift a unit byte to unit entry file (32,<<5) to unit sector 512B (512,>>9)
    00199 #define  FS_SIZE_LFN_ENTRY          13       // Size of name stored in the file entry "long file name" (unit UNICODE = 2bytes)
    00200 #define  FS_SIZE_SFNAME             11       // Size of name stored in the file entry "short file name" (unit byte)
    00201 #define  FS_SIZE_SFNAME_WITHOUT_EXT  8       // Size of name (without extension) stored in the file entry "short file name" (unit byte)
    00202 #define  FS_SIZE_SFNAME_EXT_ONLY     3       // Size of extension name stored in the file entry "short file name" (unit byte)
    00204
    00205
    00208 #define  FS_NB_FAT                  2        // This file system managed only 2 FAT
    00210
    00211
    00212 //**** Definitions of function configurations
    00213
    00216 #define  FS_512B                    512
    00217 #define  FS_512B_MASK               (512-1)
    00218 #define  FS_512B_SHIFT_BIT          9        // Shift a unit byte to unit sector (512,>>9)
    00219 #define  FS_SIZE_OF_SECTOR          FS_512B           // For compliance with old FileSystem module
    00220 #define  FS_MASK_SIZE_OF_SECTOR     FS_512B_MASK      // For compliance with old FileSystem module
    00221 #define  FS_SHIFT_B_TO_SECTOR       FS_512B_SHIFT_BIT // For compliance with old FileSystem module
    00222 #define  FS_CACHE_SIZE              512      // Cache size used by module (unit 512B)
    00224
    00226 #define  FS_BUF_SECTOR_EMPTY        0xFF
    00227
    00228
    00231 #define  FS_CLUS_OK                 0        // Value correct
    00232 #define  FS_CLUS_BAD                1        // Value bad
    00233 #define  FS_CLUS_END                2        // It is the end of cluster list
    00235
    00236
    00239 #define  FS_CLUST_ACT_SEG           0x01     // Get the sector address and size of the cluster list
    00240 #define  FS_CLUST_ACT_ONE           0x02     // Get the sector address of the cluster list
    00241 #define  FS_CLUST_ACT_CLR           0x03     // Clear the cluster list
    00243
    00244
    00246 #define  FS_CLUST_VAL_READ          FALSE      // Mode read
    00247 #define  FS_CLUST_VAL_WRITE         TRUE       // Mode write
    00248 #define  FS_CLUST_VAL_EOL           0x0FFFFFFF // Value to signal the end of cluster list
    00250
    00251
    00254
    00256 typedef union
    00257 {
    00258    U32  u32_cluster;
    00259    struct
    00260    {
    00261       U16  u16_pos;
    00262       U16  u16_size;
    00263    } seg;
    00264 } Fs_rootdir;
    00265
    00267 typedef struct
    00268 {
    00269    U8    u8_lun;
    00270 #if (FS_MULTI_PARTITION == ENABLED)
    00271    U8    u8_partition;
    00272 #endif
    00273    U8    u8_BPB_SecPerClus;
    00274    // The pointers start at beginning of the memory, and unit = 512B
    00275    U16   u16_fat_size;
    00276    U16   u16_offset_FSInfo;
    00277    U32   u32_CountofCluster;
    00278    U32   u32_ptr_fat;
    00279    U32   u32_offset_data;
    00280    Fs_rootdir     rootdir;
    00281    U16   u16_entry_pos_sel_dir;
    00282    U32   u32_cluster_sel_dir;
    00283    U16   u16_pos_sel_file;
    00284    U16   u16_pos_filterlist;
    00285    FS_STRING sz_filterext;
    00286    U8    b_mode_nav;
    00287    U8    b_mode_nav_single;
    00288    U8    u8_flat_dir_level;
    00289    U16   u16_flat_pos_offset;
    00290 } Fs_management;
    00291
    00293 typedef struct
    00294 {
    00295    U8    u8_type_fat;
    00296    U16   u16_entry_pos_sel_file;
    00297 } Fs_management_fast;
    00298
    00300 typedef struct
    00301 {
    00302    U8    u8_open_mode;
    00303    U8    u8_txt_format;
    00304    U8    u8_attr;
    00305    U32   u32_cluster;
    00306    U32   u32_size;
    00307    U32   u32_pos_in_file;
    00308 } Fs_management_entry;
    00310
    00311
    00314
    00316 typedef struct {
    00317    U32  u32_addr;
    00318    U32  u32_size_or_pos;
    00319 } Fs_segment;
    00320
    00322 typedef struct st_fs_cluster
    00323 {
    00324    U32   u32_pos;
    00325    U32   u32_val;
    00326 } Fs_cluster;
    00327
    00329
    00330
    00332 typedef struct {
    00333    Bool  b_cache_file;
    00334    U8    u8_level_use;
    00335    U8    u8_lun;
    00336    U32   u32_cluster;
    00337    U32   u32_start;
    00338    U32   u32_addr;
    00339    U32   u32_size;
    00340 } Fs_clusterlist_cache;
    00341
    00342
    00344 typedef struct {
    00345    U8    u8_lun;
    00346    U32   u32_addr;
    00347    U8    u8_dirty;
    00348
    00349    U32   u32_clusterlist_start;
    00350    U32   u32_clusterlist_pos;
    00351 } Fs_sector_cache;
    00352
    00353
    00354 //**** Definition of value used by the STRUCTURES of communication
    00355
    00358 #define  FS_TYPE_FAT_UNM   0
    00359 #define  FS_TYPE_FAT_12    1
    00360 #define  FS_TYPE_FAT_16    2
    00361 #define  FS_TYPE_FAT_32    3
    00363
    00364
    00367 #define  FS_NO_SEL         0xFFFF
    00368 #define  FS_END_FIND       0xFFFE
    00369
    00370
    00371
    00374 #define  Fat_file_is_open()     (fs_g_nav_entry.u8_open_mode !=0 )
    00375 #define  Fat_file_isnot_open()  (fs_g_nav_entry.u8_open_mode ==0 )
    00376 #define  Fat_file_close()       (fs_g_nav_entry.u8_open_mode  =0 )
    00378
    00379
    00380 //_____ D E C L A R A T I O N S ____________________________________________
    00381
    00382 //**** Global file system variables
    00383
    00385 _GLOBEXT_                     Bool                 g_b_unicode;
    00387 _GLOBEXT_                     Bool                 g_b_string_length;
    00388
    00390 _GLOBEXT_                     Bool                 g_b_no_check_disk;
    00391
    00394 _GLOBEXT_   _MEM_TYPE_SLOW_   Fs_management        fs_g_nav;
    00395 _GLOBEXT_   _MEM_TYPE_FAST_   Fs_management_fast   fs_g_nav_fast;
    00396 _GLOBEXT_   _MEM_TYPE_SLOW_   Fs_management_entry  fs_g_nav_entry;
    00398
    00400 _GLOBEXT_   _MEM_TYPE_FAST_   Fs_segment           fs_g_seg;
    00401
    00403 _GLOBEXT_   _MEM_TYPE_FAST_   Fs_cluster           fs_g_cluster;
    00404
    00405 #if (FS_LEVEL_FEATURES > FSFEATURE_READ)
    00408 _GLOBEXT_   _MEM_TYPE_SLOW_   U16                  fs_g_u16_first_mod_fat;
    00409 _GLOBEXT_   _MEM_TYPE_SLOW_   U16                  fs_g_u16_last_mod_fat;
    00410
    00411 #endif  // FS_LEVEL_FEATURES
    00412
    00415 _GLOBEXT_   _MEM_TYPE_SLOW_   U8                   fs_g_sector[ FS_CACHE_SIZE ];
    00416 _GLOBEXT_   _MEM_TYPE_SLOW_   Fs_sector_cache      fs_g_sectorcache;
    00417 _GLOBEXT_   _MEM_TYPE_SLOW_   U32                  fs_gu32_addrsector;
    00418 typedef U8  _MEM_TYPE_SLOW_   * PTR_CACHE;
    00420
    00421
    00422
    00423
    00426 Bool        fat_check_device              ( void );
    00427 Bool        fat_check_mount               ( void );
    00428 Bool        fat_check_noopen              ( void );
    00429 Bool        fat_check_open                ( void );
    00430 Bool        fat_check_select              ( void );
    00431 Bool        fat_check_mount_noopen        ( void );
    00432 Bool        fat_check_mount_select_noopen ( void );
    00433 Bool        fat_check_mount_select_open   ( void );
    00434 Bool        fat_check_mount_select        ( void );
    00435 Bool        fat_check_is_file             ( void );
    00437
    00439 U8          fat_get_nbpartition           ( void );
    00440
    00442 Bool        fat_mount                     ( void );
    00443
    00445 Bool        fat_format                    ( U8 u8_fat_type );
    00446
    00448 Bool        fat_serialnumber              ( Bool b_action , U8 _MEM_TYPE_SLOW_ *a_u8_sn );
    00449
    00450
    00453 U32         fat_getfreespace              ( void );
    00454 U8          fat_getfreespace_percent      ( void );
    00455 Bool        fat_write_fat32_FSInfo        ( U32 u32_nb_free_cluster );
    00456 U32         fat_read_fat32_FSInfo         ( void );
    00458
    00459
    00462 Bool        fat_cluster_list              ( U8 opt_action, Bool b_for_file );
    00463 void        fat_cache_clusterlist_reset   ( void );
    00464 Bool        fat_cluster_val               ( Bool b_mode );
    00465 Bool        fat_cluster_readnext          ( void );
    00466 U8          fat_checkcluster              ( void );
    00467 Bool        fat_allocfreespace            ( void );
    00468 void        fat_clear_info_fat_mod        ( void );
    00469 Bool        fat_clear_cluster             ( void );
    00470 Bool        fat_update_fat2               ( void );
    00472
    00473
    00476 Bool        fat_read_file                 ( U8 mode );
    00477 Bool        fat_write_file                ( U8 mode , U32 u32_nb_sector_write );
    00478 Bool        fat_read_dir                  ( void );
    00479 Bool        fat_initialize_dir            ( void );
    00481
    00482
    00485 Bool        fat_entry_check               ( Bool b_type );
    00486 Bool        fat_entry_checkext            ( FS_STRING sz_filter );
    00487 void        fat_get_entry_info            ( void );
    00488 Bool        fat_entry_is_dir              ( void );
    00489 void        fat_clear_entry_info_and_ptr  ( void );
    00490 void        fat_write_entry_file          ( void );
    00491 Bool        fat_entry_shortname           ( FS_STRING sz_name , U8 u8_size_max , Bool b_mode );
    00492 Bool        fat_entry_longname            ( FS_STRING sz_name , U8 u8_size_max , Bool b_mode , Bool b_match_case );
    00493 Bool        fat_check_eof_name            ( U16 character );
    00494 PTR_CACHE   fat_get_ptr_entry             ( void );
    00496
    00497
    00500 Bool        fat_create_entry_file_name    ( FS_STRING sz_name );
    00501 void        fat_get_date                  ( FS_STRING sz_date , Bool type_date );
    00502 void        fat_set_date                  ( const FS_STRING sz_date , Bool type_date );
    00503 Bool        fat_delete_file               ( Bool b_cluster_list );
    00504 Bool        fat_entry_label               ( Bool b_action , FS_STRING sz_label );
    00506
    00507
    00510 Bool        fat_cache_read_sector         ( Bool b_load );
    00511 void        fat_cache_reset               ( void );
    00512 void        fat_cache_clear               ( void );
    00513 void        fat_cache_mark_sector_as_dirty( void );
    00514 Bool        fat_cache_flush               ( void );
    00516
    00517
    00520 #if (FS_NB_NAVIGATOR > 1)
    00521    Bool     fat_check_nav_access_disk     ( void );
    00522    Bool     fat_check_nav_access_file     ( Bool mode );
    00523 #else
    00524 # define    fat_check_nav_access_disk(b)  (TRUE)
    00525 # define    fat_check_nav_access_file(b)  (TRUE)
    00526 #endif
    00528
    00529
    00532 #if (FS_NB_NAVIGATOR > 1)
    00533    void     fat_invert_nav                ( U8 u8_idnav );
    00534    void     fat_copy_nav                  ( U8 u8_idnav );
    00535 #else
    00536 # define    fat_invert_nav                ( arg )  (arg++)
    00537 # define    fat_copy_nav                  ( arg )  (arg++)
    00538 #endif
    00540
    00541 #endif  // _FAT_H_