00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 #ifndef _FATFS
00018 #define _FATFS  6502    
00019 
00020 #ifdef __cplusplus
00021 extern "C" {
00022 #endif
00023 
00024 #include "integer.h"    
00025 #include "ffconf.h"             
00026 
00027 #if _FATFS != _FFCONF
00028 #error Wrong configuration file (ffconf.h).
00029 #endif
00030 
00031 
00032 
00033 
00034 
00035 #if _MULTI_PARTITION            
00036 typedef struct {
00037         BYTE pd;        
00038         BYTE pt;        
00039 } PARTITION;
00040 extern PARTITION VolToPart[];   
00041 #define LD2PD(vol) (VolToPart[vol].pd)  
00042 #define LD2PT(vol) (VolToPart[vol].pt)  
00043 
00044 #else                                           
00045 #define LD2PD(vol) (vol)        
00046 #define LD2PT(vol) 0            
00047 
00048 #endif
00049 
00050 
00051 
00052 
00053 
00054 #if _LFN_UNICODE                        
00055 #if !_USE_LFN
00056 #error _LFN_UNICODE must be 0 in non-LFN cfg.
00057 #endif
00058 #ifndef _INC_TCHAR
00059 typedef WCHAR TCHAR;
00060 #define _T(x) L ## x
00061 #define _TEXT(x) L ## x
00062 #endif
00063 
00064 #else                                           
00065 #ifndef _INC_TCHAR
00066 typedef char TCHAR;
00067 #define _T(x) x
00068 #define _TEXT(x) x
00069 #endif
00070 
00071 #endif
00072 
00073 
00074 
00075 
00076 
00077 typedef struct {
00078         BYTE    fs_type;                
00079         BYTE    drv;                    
00080         BYTE    csize;                  
00081         BYTE    n_fats;                 
00082         BYTE    wflag;                  
00083         BYTE    fsi_flag;               
00084         WORD    id;                             
00085         WORD    n_rootdir;              
00086 #if _MAX_SS != 512
00087         WORD    ssize;                  
00088 #endif
00089 #if _FS_REENTRANT
00090         _SYNC_t sobj;                   
00091 #endif
00092 #if !_FS_READONLY
00093         DWORD   last_clust;             
00094         DWORD   free_clust;             
00095         DWORD   fsi_sector;             
00096 #endif
00097 #if _FS_RPATH
00098         DWORD   cdir;                   
00099 #endif
00100         DWORD   n_fatent;               
00101         DWORD   fsize;                  
00102         DWORD   fatbase;                
00103         DWORD   dirbase;                
00104         DWORD   database;               
00105         DWORD   winsect;                
00106         BYTE    win[_MAX_SS];   
00107 } FATFS;
00108 
00109 
00110 
00111 
00112 
00113 typedef struct {
00114         FATFS*  fs;                             
00115         WORD    id;                             
00116         BYTE    flag;                   
00117         BYTE    pad1;
00118         DWORD   fptr;                   
00119         DWORD   fsize;                  
00120         DWORD   sclust;                 
00121         DWORD   clust;                  
00122         DWORD   dsect;                  
00123 #if !_FS_READONLY
00124         DWORD   dir_sect;               
00125         BYTE*   dir_ptr;                
00126 #endif
00127 #if _USE_FASTSEEK
00128         DWORD*  cltbl;                  
00129 #endif
00130 #if _FS_SHARE
00131         UINT    lockid;                 
00132 #endif
00133 #if !_FS_TINY
00134         BYTE    buf[_MAX_SS];   
00135 #endif
00136 } FIL;
00137 
00138 
00139 
00140 
00141 
00142 typedef struct {
00143         FATFS*  fs;                             
00144         WORD    id;                             
00145         WORD    index;                  
00146         DWORD   sclust;                 
00147         DWORD   clust;                  
00148         DWORD   sect;                   
00149         BYTE*   dir;                    
00150         BYTE*   fn;                             
00151 #if _USE_LFN
00152         WCHAR*  lfn;                    
00153         WORD    lfn_idx;                
00154 #endif
00155 } DIR;
00156 
00157 
00158 
00159 
00160 
00161 typedef struct {
00162         DWORD   fsize;                  
00163         WORD    fdate;                  
00164         WORD    ftime;                  
00165         BYTE    fattrib;                
00166         TCHAR   fname[13];              
00167 #if _USE_LFN
00168         TCHAR*  lfname;                 
00169         UINT    lfsize;                 
00170 #endif
00171 } FILINFO;
00172 
00173 
00174 
00175 
00176 
00177 typedef enum {
00178         FR_OK = 0,                              
00179         FR_DISK_ERR,                    
00180         FR_INT_ERR,                             
00181         FR_NOT_READY,                   
00182         FR_NO_FILE,                             
00183         FR_NO_PATH,                             
00184         FR_INVALID_NAME,                
00185         FR_DENIED,                              
00186         FR_EXIST,                               
00187         FR_INVALID_OBJECT,              
00188         FR_WRITE_PROTECTED,             
00189         FR_INVALID_DRIVE,               
00190         FR_NOT_ENABLED,                 
00191         FR_NO_FILESYSTEM,               
00192         FR_MKFS_ABORTED,                
00193         FR_TIMEOUT,                             
00194         FR_LOCKED,                              
00195         FR_NOT_ENOUGH_CORE,             
00196         FR_TOO_MANY_OPEN_FILES, 
00197         FR_INVALID_PARAMETER    
00198 } FRESULT;
00199 
00200 
00201 
00202 
00203 
00204 
00205 FRESULT f_mount (BYTE, FATFS*);                                         
00206 FRESULT f_open (FIL*, const TCHAR*, BYTE);                      
00207 FRESULT f_read (FIL*, void*, UINT, UINT*);                      
00208 FRESULT f_lseek (FIL*, DWORD);                                          
00209 FRESULT f_close (FIL*);                                                         
00210 FRESULT f_opendir (DIR*, const TCHAR*);                         
00211 FRESULT f_readdir (DIR*, FILINFO*);                                     
00212 FRESULT f_stat (const TCHAR*, FILINFO*);                        
00213 FRESULT f_write (FIL*, const void*, UINT, UINT*);       
00214 FRESULT f_getfree (const TCHAR*, DWORD*, FATFS**);      
00215 FRESULT f_truncate (FIL*);                                                      
00216 FRESULT f_sync (FIL*);                                                          
00217 FRESULT f_unlink (const TCHAR*);                                        
00218 FRESULT f_mkdir (const TCHAR*);                                         
00219 FRESULT f_chmod (const TCHAR*, BYTE, BYTE);                     
00220 FRESULT f_utime (const TCHAR*, const FILINFO*);         
00221 FRESULT f_rename (const TCHAR*, const TCHAR*);          
00222 FRESULT f_chdrive (BYTE);                                                       
00223 FRESULT f_chdir (const TCHAR*);                                         
00224 FRESULT f_getcwd (TCHAR*, UINT);                                        
00225 FRESULT f_forward (FIL*, UINT(*)(const BYTE*,UINT), UINT, UINT*);       
00226 FRESULT f_mkfs (BYTE, BYTE, UINT);                                      
00227 FRESULT f_fdisk (BYTE, const DWORD[], void*);           
00228 int f_putc (TCHAR, FIL*);                                                       
00229 int f_puts (const TCHAR*, FIL*);                                        
00230 int f_printf (FIL*, const TCHAR*, ...);                         
00231 TCHAR* f_gets (TCHAR*, int, FIL*);                                      
00232 
00233 #define f_eof(fp) (((fp)->fptr == (fp)->fsize) ? 1 : 0)
00234 #define f_error(fp) (((fp)->flag & FA__ERROR) ? 1 : 0)
00235 #define f_tell(fp) ((fp)->fptr)
00236 #define f_size(fp) ((fp)->fsize)
00237 
00238 #ifndef EOF
00239 #define EOF (-1)
00240 #endif
00241 
00242 
00243 
00244 
00245 
00246 
00247 
00248 
00249 #if !_FS_READONLY
00250 DWORD get_fattime (void);
00251 #endif
00252 
00253 
00254 #if _USE_LFN                                            
00255 WCHAR ff_convert (WCHAR, UINT);         
00256 WCHAR ff_wtoupper (WCHAR);                      
00257 #if _USE_LFN == 3                                       
00258 void* ff_memalloc (UINT);                       
00259 void ff_memfree (void*);                        
00260 #endif
00261 #endif
00262 
00263 
00264 #if _FS_REENTRANT
00265 int ff_cre_syncobj (BYTE, _SYNC_t*);
00266 int ff_req_grant (_SYNC_t);                     
00267 void ff_rel_grant (_SYNC_t);            
00268 int ff_del_syncobj (_SYNC_t);           
00269 #endif
00270 
00271 
00272 
00273 
00274 
00275 
00276 
00277 
00278 
00279 
00280 #define FA_READ                         0x01
00281 #define FA_OPEN_EXISTING        0x00
00282 #define FA__ERROR                       0x80
00283 
00284 #if !_FS_READONLY
00285 #define FA_WRITE                        0x02
00286 #define FA_CREATE_NEW           0x04
00287 #define FA_CREATE_ALWAYS        0x08
00288 #define FA_OPEN_ALWAYS          0x10
00289 #define FA__WRITTEN                     0x20
00290 #define FA__DIRTY                       0x40
00291 #endif
00292 
00293 
00294 
00295 
00296 #define FS_FAT12        1
00297 #define FS_FAT16        2
00298 #define FS_FAT32        3
00299 
00300 
00301 
00302 
00303 #define AM_RDO  0x01    
00304 #define AM_HID  0x02    
00305 #define AM_SYS  0x04    
00306 #define AM_VOL  0x08    
00307 #define AM_LFN  0x0F    
00308 #define AM_DIR  0x10    
00309 #define AM_ARC  0x20    
00310 #define AM_MASK 0x3F    
00311 
00312 
00313 
00314 #define CREATE_LINKMAP  0xFFFFFFFF
00315 
00316 
00317 
00318 
00319 
00320 
00321 #if _WORD_ACCESS == 1   
00322 #define LD_WORD(ptr)            (WORD)(*(WORD*)(BYTE*)(ptr))
00323 #define LD_DWORD(ptr)           (DWORD)(*(DWORD*)(BYTE*)(ptr))
00324 #define ST_WORD(ptr,val)        *(WORD*)(BYTE*)(ptr)=(WORD)(val)
00325 #define ST_DWORD(ptr,val)       *(DWORD*)(BYTE*)(ptr)=(DWORD)(val)
00326 #else                                   
00327 #define LD_WORD(ptr)            (WORD)(((WORD)*((BYTE*)(ptr)+1)<<8)|(WORD)*(BYTE*)(ptr))
00328 #define LD_DWORD(ptr)           (DWORD)(((DWORD)*((BYTE*)(ptr)+3)<<24)|((DWORD)*((BYTE*)(ptr)+2)<<16)|((WORD)*((BYTE*)(ptr)+1)<<8)|*(BYTE*)(ptr))
00329 #define ST_WORD(ptr,val)        *(BYTE*)(ptr)=(BYTE)(val); *((BYTE*)(ptr)+1)=(BYTE)((WORD)(val)>>8)
00330 #define ST_DWORD(ptr,val)       *(BYTE*)(ptr)=(BYTE)(val); *((BYTE*)(ptr)+1)=(BYTE)((WORD)(val)>>8); *((BYTE*)(ptr)+2)=(BYTE)((DWORD)(val)>>16); *((BYTE*)(ptr)+3)=(BYTE)((DWORD)(val)>>24)
00331 #endif
00332 
00333 #ifdef __cplusplus
00334 }
00335 #endif
00336 
00337 #endif