Class that combined FATFileSystem with a USBMSD device, similar to LocalFileSystem
Dependents: SD_USB_FS_HelloWorld S25FL216K_USBFileSystem USBFileSystem_RAMDISK_HelloWorld
Introduction
USBFileSystem is a combination of FATFileSystem and USB-MSD (Mass-Storage Device). This way it allows you to create a filesystem that is both accessible on your PC with the USB cable plugged in, and on the device itself. This is very similar to LocalFileSystem, only you can use any Serial Flash, SD, etc as storage medium.
If your code works with either FATFileSystem or USBMSD it will with very little modification also work with USBFileSystem.
Basic functionality
Since both FATFileSystem and USBMSD write binary data to a the storage medium, if both are writing somewhere at the same time we have a problem. This library makes the medium read only for the local side, if USB is writing, and vice versa. Local is considered to be writing as long as you have opened a file for write. USB is considered writing as soon as a write command comes from USB, and this continues for a short time after the last write command. This is needed because I cannot know when the last sector is written by USB, so I have to wait a little while to see if more data is written.
Reading
You can still read when the other one is writing. This can result in issues. Using the functions given you can easily make sure that won't happen. However regardless if you do that or not, it is a good idea to make sure your program can handle unexpected situations. For example if you open a file locally, and you get a NULL pointer, do not immediatly go into an error condition, but just try it again.
USB MSD on your PC
When you write to / read from a USB drive Windows (and I expect other OS's too) will cache everything. The result is that once you read a file on your PC, it will never change, even if your mbed does change the data. And if you write/delete a file when the mbed is locally using the file system, it will be read only, however your PC will tell you data was succesfully written/removed.
If this is a problem for your device, you can disconnect the USB part when the mbed is writing to the storage medium locally. The library can do this automatically for you.
Required code
The virtual functions that need to be implemented by you are:
virtual int disk_initialize() { return 0; } virtual int _disk_status() { return 0; } virtual int disk_read(uint8_t * buffer, uint64_t sector) { return 0;} virtual int _disk_write(const uint8_t * buffer, uint64_t sector) = 0; virtual int disk_sync() { return 0; } virtual uint64_t disk_sectors() = 0;
Some of those are optional, but disk_read, _disk_write and disk_sectors have to be defined in the child class.
Sector size
The sector size must be 512 bytes. In USBMSD this requirement isn't present, but FATFileSystem has this requirement!
Function name
Note the '_' at the beginning of _disk_status and _disk_write. You may not inherit it without the '_', that will break the library. Since the parent libraries made it virtual I cannot block it from happening, so just watch out.
Available functions for the user
The USBFileSystem library allows for some extra functions the user can use. The API documentation lists them, but summarized: You can attach functions which are called once either USB is writing to the storage medium, or when this is done locally. There are two functions which will tell you if currently USB/local is writing to the storage medium, and you can set the usbMode. Set it to mode 0 and USB is read only when the storage is used locally, set it to mode 1 and it is disconnected (default and recommended).
Besides that there are of course the standard USB functions (connect/disconnect for example), and you can use 'fopen', 'mkdir', etc similar to FATFileSystem.
Hello World
Currently available:
RAM-disk for KL25Z and LPC1768 (this one disappeared for some reason, I re-published it, should still work):
Import programUSBFileSystem_RAMDISK_HelloWorld
RAMDisk example for the USBFileSystem
Wi-Go serial flash:
Import programS25FL216K_HelloWorld
Helloworld program for the S25FL216K flash memory in combination with USBFileSystem
SD card (different from others):
Import programSD_USB_FS_HelloWorld
SD USB MSD helloworld
Note that this one is not mine, if you have problems with it check if there are updates for the library.
FATFileSystem/ChaN/ff.h@2:9af05743d551, 2013-10-23 (annotated)
- Committer:
- Sissors
- Date:
- Wed Oct 23 20:32:07 2013 +0000
- Revision:
- 2:9af05743d551
FATFileSystem 'Tiny' option enabled -> Primary to solve a buffering issue when USB writes a file, also reduces RAM consumed
;
; USBDevice back to main branch
;
; USBMode 1 is default now
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Sissors | 2:9af05743d551 | 1 | /*---------------------------------------------------------------------------/ |
Sissors | 2:9af05743d551 | 2 | / FatFs - FAT file system module include file R0.09a (C)ChaN, 2012 |
Sissors | 2:9af05743d551 | 3 | /----------------------------------------------------------------------------/ |
Sissors | 2:9af05743d551 | 4 | / FatFs module is a generic FAT file system module for small embedded systems. |
Sissors | 2:9af05743d551 | 5 | / This is a free software that opened for education, research and commercial |
Sissors | 2:9af05743d551 | 6 | / developments under license policy of following terms. |
Sissors | 2:9af05743d551 | 7 | / |
Sissors | 2:9af05743d551 | 8 | / Copyright (C) 2012, ChaN, all right reserved. |
Sissors | 2:9af05743d551 | 9 | / |
Sissors | 2:9af05743d551 | 10 | / * The FatFs module is a free software and there is NO WARRANTY. |
Sissors | 2:9af05743d551 | 11 | / * No restriction on use. You can use, modify and redistribute it for |
Sissors | 2:9af05743d551 | 12 | / personal, non-profit or commercial product UNDER YOUR RESPONSIBILITY. |
Sissors | 2:9af05743d551 | 13 | / * Redistributions of source code must retain the above copyright notice. |
Sissors | 2:9af05743d551 | 14 | / |
Sissors | 2:9af05743d551 | 15 | /----------------------------------------------------------------------------*/ |
Sissors | 2:9af05743d551 | 16 | |
Sissors | 2:9af05743d551 | 17 | #ifndef _FATFS |
Sissors | 2:9af05743d551 | 18 | #define _FATFS 4004 /* Revision ID */ |
Sissors | 2:9af05743d551 | 19 | |
Sissors | 2:9af05743d551 | 20 | #ifdef __cplusplus |
Sissors | 2:9af05743d551 | 21 | extern "C" { |
Sissors | 2:9af05743d551 | 22 | #endif |
Sissors | 2:9af05743d551 | 23 | |
Sissors | 2:9af05743d551 | 24 | #include "integer.h" /* Basic integer types */ |
Sissors | 2:9af05743d551 | 25 | #include "ffconf.h" /* FatFs configuration options */ |
Sissors | 2:9af05743d551 | 26 | |
Sissors | 2:9af05743d551 | 27 | #if _FATFS != _FFCONF |
Sissors | 2:9af05743d551 | 28 | #error Wrong configuration file (ffconf.h). |
Sissors | 2:9af05743d551 | 29 | #endif |
Sissors | 2:9af05743d551 | 30 | |
Sissors | 2:9af05743d551 | 31 | |
Sissors | 2:9af05743d551 | 32 | |
Sissors | 2:9af05743d551 | 33 | /* Definitions of volume management */ |
Sissors | 2:9af05743d551 | 34 | |
Sissors | 2:9af05743d551 | 35 | #if _MULTI_PARTITION /* Multiple partition configuration */ |
Sissors | 2:9af05743d551 | 36 | typedef struct { |
Sissors | 2:9af05743d551 | 37 | BYTE pd; /* Physical drive number */ |
Sissors | 2:9af05743d551 | 38 | BYTE pt; /* Partition: 0:Auto detect, 1-4:Forced partition) */ |
Sissors | 2:9af05743d551 | 39 | } PARTITION; |
Sissors | 2:9af05743d551 | 40 | extern PARTITION VolToPart[]; /* Volume - Partition resolution table */ |
Sissors | 2:9af05743d551 | 41 | #define LD2PD(vol) (VolToPart[vol].pd) /* Get physical drive number */ |
Sissors | 2:9af05743d551 | 42 | #define LD2PT(vol) (VolToPart[vol].pt) /* Get partition index */ |
Sissors | 2:9af05743d551 | 43 | |
Sissors | 2:9af05743d551 | 44 | #else /* Single partition configuration */ |
Sissors | 2:9af05743d551 | 45 | #define LD2PD(vol) (BYTE)(vol) /* Each logical drive is bound to the same physical drive number */ |
Sissors | 2:9af05743d551 | 46 | #define LD2PT(vol) 0 /* Always mounts the 1st partition or in SFD */ |
Sissors | 2:9af05743d551 | 47 | |
Sissors | 2:9af05743d551 | 48 | #endif |
Sissors | 2:9af05743d551 | 49 | |
Sissors | 2:9af05743d551 | 50 | |
Sissors | 2:9af05743d551 | 51 | |
Sissors | 2:9af05743d551 | 52 | /* Type of path name strings on FatFs API */ |
Sissors | 2:9af05743d551 | 53 | |
Sissors | 2:9af05743d551 | 54 | #if _LFN_UNICODE /* Unicode string */ |
Sissors | 2:9af05743d551 | 55 | #if !_USE_LFN |
Sissors | 2:9af05743d551 | 56 | #error _LFN_UNICODE must be 0 in non-LFN cfg. |
Sissors | 2:9af05743d551 | 57 | #endif |
Sissors | 2:9af05743d551 | 58 | #ifndef _INC_TCHAR |
Sissors | 2:9af05743d551 | 59 | typedef WCHAR TCHAR; |
Sissors | 2:9af05743d551 | 60 | #define _T(x) L ## x |
Sissors | 2:9af05743d551 | 61 | #define _TEXT(x) L ## x |
Sissors | 2:9af05743d551 | 62 | #endif |
Sissors | 2:9af05743d551 | 63 | |
Sissors | 2:9af05743d551 | 64 | #else /* ANSI/OEM string */ |
Sissors | 2:9af05743d551 | 65 | #ifndef _INC_TCHAR |
Sissors | 2:9af05743d551 | 66 | typedef char TCHAR; |
Sissors | 2:9af05743d551 | 67 | #define _T(x) x |
Sissors | 2:9af05743d551 | 68 | #define _TEXT(x) x |
Sissors | 2:9af05743d551 | 69 | #endif |
Sissors | 2:9af05743d551 | 70 | |
Sissors | 2:9af05743d551 | 71 | #endif |
Sissors | 2:9af05743d551 | 72 | |
Sissors | 2:9af05743d551 | 73 | |
Sissors | 2:9af05743d551 | 74 | |
Sissors | 2:9af05743d551 | 75 | /* File system object structure (FATFS) */ |
Sissors | 2:9af05743d551 | 76 | |
Sissors | 2:9af05743d551 | 77 | typedef struct { |
Sissors | 2:9af05743d551 | 78 | BYTE fs_type; /* FAT sub-type (0:Not mounted) */ |
Sissors | 2:9af05743d551 | 79 | BYTE drv; /* Physical drive number */ |
Sissors | 2:9af05743d551 | 80 | BYTE csize; /* Sectors per cluster (1,2,4...128) */ |
Sissors | 2:9af05743d551 | 81 | BYTE n_fats; /* Number of FAT copies (1,2) */ |
Sissors | 2:9af05743d551 | 82 | BYTE wflag; /* win[] dirty flag (1:must be written back) */ |
Sissors | 2:9af05743d551 | 83 | BYTE fsi_flag; /* fsinfo dirty flag (1:must be written back) */ |
Sissors | 2:9af05743d551 | 84 | WORD id; /* File system mount ID */ |
Sissors | 2:9af05743d551 | 85 | WORD n_rootdir; /* Number of root directory entries (FAT12/16) */ |
Sissors | 2:9af05743d551 | 86 | #if _MAX_SS != 512 |
Sissors | 2:9af05743d551 | 87 | WORD ssize; /* Bytes per sector (512, 1024, 2048 or 4096) */ |
Sissors | 2:9af05743d551 | 88 | #endif |
Sissors | 2:9af05743d551 | 89 | #if _FS_REENTRANT |
Sissors | 2:9af05743d551 | 90 | _SYNC_t sobj; /* Identifier of sync object */ |
Sissors | 2:9af05743d551 | 91 | #endif |
Sissors | 2:9af05743d551 | 92 | #if !_FS_READONLY |
Sissors | 2:9af05743d551 | 93 | DWORD last_clust; /* Last allocated cluster */ |
Sissors | 2:9af05743d551 | 94 | DWORD free_clust; /* Number of free clusters */ |
Sissors | 2:9af05743d551 | 95 | DWORD fsi_sector; /* fsinfo sector (FAT32) */ |
Sissors | 2:9af05743d551 | 96 | #endif |
Sissors | 2:9af05743d551 | 97 | #if _FS_RPATH |
Sissors | 2:9af05743d551 | 98 | DWORD cdir; /* Current directory start cluster (0:root) */ |
Sissors | 2:9af05743d551 | 99 | #endif |
Sissors | 2:9af05743d551 | 100 | DWORD n_fatent; /* Number of FAT entries (= number of clusters + 2) */ |
Sissors | 2:9af05743d551 | 101 | DWORD fsize; /* Sectors per FAT */ |
Sissors | 2:9af05743d551 | 102 | DWORD fatbase; /* FAT start sector */ |
Sissors | 2:9af05743d551 | 103 | DWORD dirbase; /* Root directory start sector (FAT32:Cluster#) */ |
Sissors | 2:9af05743d551 | 104 | DWORD database; /* Data start sector */ |
Sissors | 2:9af05743d551 | 105 | DWORD winsect; /* Current sector appearing in the win[] */ |
Sissors | 2:9af05743d551 | 106 | BYTE win[_MAX_SS]; /* Disk access window for Directory, FAT (and Data on tiny cfg) */ |
Sissors | 2:9af05743d551 | 107 | } FATFS; |
Sissors | 2:9af05743d551 | 108 | |
Sissors | 2:9af05743d551 | 109 | |
Sissors | 2:9af05743d551 | 110 | |
Sissors | 2:9af05743d551 | 111 | /* File object structure (FIL) */ |
Sissors | 2:9af05743d551 | 112 | |
Sissors | 2:9af05743d551 | 113 | typedef struct { |
Sissors | 2:9af05743d551 | 114 | FATFS* fs; /* Pointer to the related file system object */ |
Sissors | 2:9af05743d551 | 115 | WORD id; /* File system mount ID of the related file system object */ |
Sissors | 2:9af05743d551 | 116 | BYTE flag; /* File status flags */ |
Sissors | 2:9af05743d551 | 117 | BYTE pad1; |
Sissors | 2:9af05743d551 | 118 | DWORD fptr; /* File read/write pointer (0ed on file open) */ |
Sissors | 2:9af05743d551 | 119 | DWORD fsize; /* File size */ |
Sissors | 2:9af05743d551 | 120 | DWORD sclust; /* File data start cluster (0:no data cluster, always 0 when fsize is 0) */ |
Sissors | 2:9af05743d551 | 121 | DWORD clust; /* Current cluster of fpter */ |
Sissors | 2:9af05743d551 | 122 | DWORD dsect; /* Current data sector of fpter */ |
Sissors | 2:9af05743d551 | 123 | #if !_FS_READONLY |
Sissors | 2:9af05743d551 | 124 | DWORD dir_sect; /* Sector containing the directory entry */ |
Sissors | 2:9af05743d551 | 125 | BYTE* dir_ptr; /* Pointer to the directory entry in the window */ |
Sissors | 2:9af05743d551 | 126 | #endif |
Sissors | 2:9af05743d551 | 127 | #if _USE_FASTSEEK |
Sissors | 2:9af05743d551 | 128 | DWORD* cltbl; /* Pointer to the cluster link map table (null on file open) */ |
Sissors | 2:9af05743d551 | 129 | #endif |
Sissors | 2:9af05743d551 | 130 | #if _FS_LOCK |
Sissors | 2:9af05743d551 | 131 | UINT lockid; /* File lock ID (index of file semaphore table Files[]) */ |
Sissors | 2:9af05743d551 | 132 | #endif |
Sissors | 2:9af05743d551 | 133 | #if !_FS_TINY |
Sissors | 2:9af05743d551 | 134 | BYTE buf[_MAX_SS]; /* File data read/write buffer */ |
Sissors | 2:9af05743d551 | 135 | #endif |
Sissors | 2:9af05743d551 | 136 | } FIL; |
Sissors | 2:9af05743d551 | 137 | |
Sissors | 2:9af05743d551 | 138 | |
Sissors | 2:9af05743d551 | 139 | |
Sissors | 2:9af05743d551 | 140 | /* Directory object structure (DIR) */ |
Sissors | 2:9af05743d551 | 141 | |
Sissors | 2:9af05743d551 | 142 | typedef struct { |
Sissors | 2:9af05743d551 | 143 | FATFS* fs; /* Pointer to the owner file system object */ |
Sissors | 2:9af05743d551 | 144 | WORD id; /* Owner file system mount ID */ |
Sissors | 2:9af05743d551 | 145 | WORD index; /* Current read/write index number */ |
Sissors | 2:9af05743d551 | 146 | DWORD sclust; /* Table start cluster (0:Root dir) */ |
Sissors | 2:9af05743d551 | 147 | DWORD clust; /* Current cluster */ |
Sissors | 2:9af05743d551 | 148 | DWORD sect; /* Current sector */ |
Sissors | 2:9af05743d551 | 149 | BYTE* dir; /* Pointer to the current SFN entry in the win[] */ |
Sissors | 2:9af05743d551 | 150 | BYTE* fn; /* Pointer to the SFN (in/out) {file[8],ext[3],status[1]} */ |
Sissors | 2:9af05743d551 | 151 | #if _USE_LFN |
Sissors | 2:9af05743d551 | 152 | WCHAR* lfn; /* Pointer to the LFN working buffer */ |
Sissors | 2:9af05743d551 | 153 | WORD lfn_idx; /* Last matched LFN index number (0xFFFF:No LFN) */ |
Sissors | 2:9af05743d551 | 154 | #endif |
Sissors | 2:9af05743d551 | 155 | } FATFS_DIR; |
Sissors | 2:9af05743d551 | 156 | |
Sissors | 2:9af05743d551 | 157 | |
Sissors | 2:9af05743d551 | 158 | |
Sissors | 2:9af05743d551 | 159 | /* File status structure (FILINFO) */ |
Sissors | 2:9af05743d551 | 160 | |
Sissors | 2:9af05743d551 | 161 | typedef struct { |
Sissors | 2:9af05743d551 | 162 | DWORD fsize; /* File size */ |
Sissors | 2:9af05743d551 | 163 | WORD fdate; /* Last modified date */ |
Sissors | 2:9af05743d551 | 164 | WORD ftime; /* Last modified time */ |
Sissors | 2:9af05743d551 | 165 | BYTE fattrib; /* Attribute */ |
Sissors | 2:9af05743d551 | 166 | TCHAR fname[13]; /* Short file name (8.3 format) */ |
Sissors | 2:9af05743d551 | 167 | #if _USE_LFN |
Sissors | 2:9af05743d551 | 168 | TCHAR* lfname; /* Pointer to the LFN buffer */ |
Sissors | 2:9af05743d551 | 169 | UINT lfsize; /* Size of LFN buffer in TCHAR */ |
Sissors | 2:9af05743d551 | 170 | #endif |
Sissors | 2:9af05743d551 | 171 | } FILINFO; |
Sissors | 2:9af05743d551 | 172 | |
Sissors | 2:9af05743d551 | 173 | |
Sissors | 2:9af05743d551 | 174 | |
Sissors | 2:9af05743d551 | 175 | /* File function return code (FRESULT) */ |
Sissors | 2:9af05743d551 | 176 | |
Sissors | 2:9af05743d551 | 177 | typedef enum { |
Sissors | 2:9af05743d551 | 178 | FR_OK = 0, /* (0) Succeeded */ |
Sissors | 2:9af05743d551 | 179 | FR_DISK_ERR, /* (1) A hard error occurred in the low level disk I/O layer */ |
Sissors | 2:9af05743d551 | 180 | FR_INT_ERR, /* (2) Assertion failed */ |
Sissors | 2:9af05743d551 | 181 | FR_NOT_READY, /* (3) The physical drive cannot work */ |
Sissors | 2:9af05743d551 | 182 | FR_NO_FILE, /* (4) Could not find the file */ |
Sissors | 2:9af05743d551 | 183 | FR_NO_PATH, /* (5) Could not find the path */ |
Sissors | 2:9af05743d551 | 184 | FR_INVALID_NAME, /* (6) The path name format is invalid */ |
Sissors | 2:9af05743d551 | 185 | FR_DENIED, /* (7) Access denied due to prohibited access or directory full */ |
Sissors | 2:9af05743d551 | 186 | FR_EXIST, /* (8) Access denied due to prohibited access */ |
Sissors | 2:9af05743d551 | 187 | FR_INVALID_OBJECT, /* (9) The file/directory object is invalid */ |
Sissors | 2:9af05743d551 | 188 | FR_WRITE_PROTECTED, /* (10) The physical drive is write protected */ |
Sissors | 2:9af05743d551 | 189 | FR_INVALID_DRIVE, /* (11) The logical drive number is invalid */ |
Sissors | 2:9af05743d551 | 190 | FR_NOT_ENABLED, /* (12) The volume has no work area */ |
Sissors | 2:9af05743d551 | 191 | FR_NO_FILESYSTEM, /* (13) There is no valid FAT volume */ |
Sissors | 2:9af05743d551 | 192 | FR_MKFS_ABORTED, /* (14) The f_mkfs() aborted due to any parameter error */ |
Sissors | 2:9af05743d551 | 193 | FR_TIMEOUT, /* (15) Could not get a grant to access the volume within defined period */ |
Sissors | 2:9af05743d551 | 194 | FR_LOCKED, /* (16) The operation is rejected according to the file sharing policy */ |
Sissors | 2:9af05743d551 | 195 | FR_NOT_ENOUGH_CORE, /* (17) LFN working buffer could not be allocated */ |
Sissors | 2:9af05743d551 | 196 | FR_TOO_MANY_OPEN_FILES, /* (18) Number of open files > _FS_SHARE */ |
Sissors | 2:9af05743d551 | 197 | FR_INVALID_PARAMETER /* (19) Given parameter is invalid */ |
Sissors | 2:9af05743d551 | 198 | } FRESULT; |
Sissors | 2:9af05743d551 | 199 | |
Sissors | 2:9af05743d551 | 200 | |
Sissors | 2:9af05743d551 | 201 | |
Sissors | 2:9af05743d551 | 202 | /*--------------------------------------------------------------*/ |
Sissors | 2:9af05743d551 | 203 | /* FatFs module application interface */ |
Sissors | 2:9af05743d551 | 204 | |
Sissors | 2:9af05743d551 | 205 | FRESULT f_mount (BYTE, FATFS*); /* Mount/Unmount a logical drive */ |
Sissors | 2:9af05743d551 | 206 | FRESULT f_open (FIL*, const TCHAR*, BYTE); /* Open or create a file */ |
Sissors | 2:9af05743d551 | 207 | FRESULT f_read (FIL*, void*, UINT, UINT*); /* Read data from a file */ |
Sissors | 2:9af05743d551 | 208 | FRESULT f_lseek (FIL*, DWORD); /* Move file pointer of a file object */ |
Sissors | 2:9af05743d551 | 209 | FRESULT f_close (FIL*); /* Close an open file object */ |
Sissors | 2:9af05743d551 | 210 | FRESULT f_opendir (FATFS_DIR*, const TCHAR*); /* Open an existing directory */ |
Sissors | 2:9af05743d551 | 211 | FRESULT f_readdir (FATFS_DIR*, FILINFO*); /* Read a directory item */ |
Sissors | 2:9af05743d551 | 212 | FRESULT f_stat (const TCHAR*, FILINFO*); /* Get file status */ |
Sissors | 2:9af05743d551 | 213 | FRESULT f_write (FIL*, const void*, UINT, UINT*); /* Write data to a file */ |
Sissors | 2:9af05743d551 | 214 | FRESULT f_getfree (const TCHAR*, DWORD*, FATFS**); /* Get number of free clusters on the drive */ |
Sissors | 2:9af05743d551 | 215 | FRESULT f_truncate (FIL*); /* Truncate file */ |
Sissors | 2:9af05743d551 | 216 | FRESULT f_sync (FIL*); /* Flush cached data of a writing file */ |
Sissors | 2:9af05743d551 | 217 | FRESULT f_unlink (const TCHAR*); /* Delete an existing file or directory */ |
Sissors | 2:9af05743d551 | 218 | FRESULT f_mkdir (const TCHAR*); /* Create a new directory */ |
Sissors | 2:9af05743d551 | 219 | FRESULT f_chmod (const TCHAR*, BYTE, BYTE); /* Change attribute of the file/dir */ |
Sissors | 2:9af05743d551 | 220 | FRESULT f_utime (const TCHAR*, const FILINFO*); /* Change times-tamp of the file/dir */ |
Sissors | 2:9af05743d551 | 221 | FRESULT f_rename (const TCHAR*, const TCHAR*); /* Rename/Move a file or directory */ |
Sissors | 2:9af05743d551 | 222 | FRESULT f_chdrive (BYTE); /* Change current drive */ |
Sissors | 2:9af05743d551 | 223 | FRESULT f_chdir (const TCHAR*); /* Change current directory */ |
Sissors | 2:9af05743d551 | 224 | FRESULT f_getcwd (TCHAR*, UINT); /* Get current directory */ |
Sissors | 2:9af05743d551 | 225 | FRESULT f_forward (FIL*, UINT(*)(const BYTE*,UINT), UINT, UINT*); /* Forward data to the stream */ |
Sissors | 2:9af05743d551 | 226 | FRESULT f_mkfs (BYTE, BYTE, UINT); /* Create a file system on the drive */ |
Sissors | 2:9af05743d551 | 227 | FRESULT f_fdisk (BYTE, const DWORD[], void*); /* Divide a physical drive into some partitions */ |
Sissors | 2:9af05743d551 | 228 | int f_putc (TCHAR, FIL*); /* Put a character to the file */ |
Sissors | 2:9af05743d551 | 229 | int f_puts (const TCHAR*, FIL*); /* Put a string to the file */ |
Sissors | 2:9af05743d551 | 230 | int f_printf (FIL*, const TCHAR*, ...); /* Put a formatted string to the file */ |
Sissors | 2:9af05743d551 | 231 | TCHAR* f_gets (TCHAR*, int, FIL*); /* Get a string from the file */ |
Sissors | 2:9af05743d551 | 232 | |
Sissors | 2:9af05743d551 | 233 | #define f_eof(fp) (((fp)->fptr == (fp)->fsize) ? 1 : 0) |
Sissors | 2:9af05743d551 | 234 | #define f_error(fp) (((fp)->flag & FA__ERROR) ? 1 : 0) |
Sissors | 2:9af05743d551 | 235 | #define f_tell(fp) ((fp)->fptr) |
Sissors | 2:9af05743d551 | 236 | #define f_size(fp) ((fp)->fsize) |
Sissors | 2:9af05743d551 | 237 | |
Sissors | 2:9af05743d551 | 238 | #ifndef EOF |
Sissors | 2:9af05743d551 | 239 | #define EOF (-1) |
Sissors | 2:9af05743d551 | 240 | #endif |
Sissors | 2:9af05743d551 | 241 | |
Sissors | 2:9af05743d551 | 242 | |
Sissors | 2:9af05743d551 | 243 | |
Sissors | 2:9af05743d551 | 244 | |
Sissors | 2:9af05743d551 | 245 | /*--------------------------------------------------------------*/ |
Sissors | 2:9af05743d551 | 246 | /* Additional user defined functions */ |
Sissors | 2:9af05743d551 | 247 | |
Sissors | 2:9af05743d551 | 248 | /* RTC function */ |
Sissors | 2:9af05743d551 | 249 | #if !_FS_READONLY |
Sissors | 2:9af05743d551 | 250 | DWORD get_fattime (void); |
Sissors | 2:9af05743d551 | 251 | #endif |
Sissors | 2:9af05743d551 | 252 | |
Sissors | 2:9af05743d551 | 253 | /* Unicode support functions */ |
Sissors | 2:9af05743d551 | 254 | #if _USE_LFN /* Unicode - OEM code conversion */ |
Sissors | 2:9af05743d551 | 255 | WCHAR ff_convert (WCHAR, UINT); /* OEM-Unicode bidirectional conversion */ |
Sissors | 2:9af05743d551 | 256 | WCHAR ff_wtoupper (WCHAR); /* Unicode upper-case conversion */ |
Sissors | 2:9af05743d551 | 257 | #if _USE_LFN == 3 /* Memory functions */ |
Sissors | 2:9af05743d551 | 258 | void* ff_memalloc (UINT); /* Allocate memory block */ |
Sissors | 2:9af05743d551 | 259 | void ff_memfree (void*); /* Free memory block */ |
Sissors | 2:9af05743d551 | 260 | #endif |
Sissors | 2:9af05743d551 | 261 | #endif |
Sissors | 2:9af05743d551 | 262 | |
Sissors | 2:9af05743d551 | 263 | /* Sync functions */ |
Sissors | 2:9af05743d551 | 264 | #if _FS_REENTRANT |
Sissors | 2:9af05743d551 | 265 | int ff_cre_syncobj (BYTE, _SYNC_t*);/* Create a sync object */ |
Sissors | 2:9af05743d551 | 266 | int ff_req_grant (_SYNC_t); /* Lock sync object */ |
Sissors | 2:9af05743d551 | 267 | void ff_rel_grant (_SYNC_t); /* Unlock sync object */ |
Sissors | 2:9af05743d551 | 268 | int ff_del_syncobj (_SYNC_t); /* Delete a sync object */ |
Sissors | 2:9af05743d551 | 269 | #endif |
Sissors | 2:9af05743d551 | 270 | |
Sissors | 2:9af05743d551 | 271 | |
Sissors | 2:9af05743d551 | 272 | |
Sissors | 2:9af05743d551 | 273 | |
Sissors | 2:9af05743d551 | 274 | /*--------------------------------------------------------------*/ |
Sissors | 2:9af05743d551 | 275 | /* Flags and offset address */ |
Sissors | 2:9af05743d551 | 276 | |
Sissors | 2:9af05743d551 | 277 | |
Sissors | 2:9af05743d551 | 278 | /* File access control and file status flags (FIL.flag) */ |
Sissors | 2:9af05743d551 | 279 | |
Sissors | 2:9af05743d551 | 280 | #define FA_READ 0x01 |
Sissors | 2:9af05743d551 | 281 | #define FA_OPEN_EXISTING 0x00 |
Sissors | 2:9af05743d551 | 282 | #define FA__ERROR 0x80 |
Sissors | 2:9af05743d551 | 283 | |
Sissors | 2:9af05743d551 | 284 | #if !_FS_READONLY |
Sissors | 2:9af05743d551 | 285 | #define FA_WRITE 0x02 |
Sissors | 2:9af05743d551 | 286 | #define FA_CREATE_NEW 0x04 |
Sissors | 2:9af05743d551 | 287 | #define FA_CREATE_ALWAYS 0x08 |
Sissors | 2:9af05743d551 | 288 | #define FA_OPEN_ALWAYS 0x10 |
Sissors | 2:9af05743d551 | 289 | #define FA__WRITTEN 0x20 |
Sissors | 2:9af05743d551 | 290 | #define FA__DIRTY 0x40 |
Sissors | 2:9af05743d551 | 291 | #endif |
Sissors | 2:9af05743d551 | 292 | |
Sissors | 2:9af05743d551 | 293 | |
Sissors | 2:9af05743d551 | 294 | /* FAT sub type (FATFS.fs_type) */ |
Sissors | 2:9af05743d551 | 295 | |
Sissors | 2:9af05743d551 | 296 | #define FS_FAT12 1 |
Sissors | 2:9af05743d551 | 297 | #define FS_FAT16 2 |
Sissors | 2:9af05743d551 | 298 | #define FS_FAT32 3 |
Sissors | 2:9af05743d551 | 299 | |
Sissors | 2:9af05743d551 | 300 | |
Sissors | 2:9af05743d551 | 301 | /* File attribute bits for directory entry */ |
Sissors | 2:9af05743d551 | 302 | |
Sissors | 2:9af05743d551 | 303 | #define AM_RDO 0x01 /* Read only */ |
Sissors | 2:9af05743d551 | 304 | #define AM_HID 0x02 /* Hidden */ |
Sissors | 2:9af05743d551 | 305 | #define AM_SYS 0x04 /* System */ |
Sissors | 2:9af05743d551 | 306 | #define AM_VOL 0x08 /* Volume label */ |
Sissors | 2:9af05743d551 | 307 | #define AM_LFN 0x0F /* LFN entry */ |
Sissors | 2:9af05743d551 | 308 | #define AM_DIR 0x10 /* Directory */ |
Sissors | 2:9af05743d551 | 309 | #define AM_ARC 0x20 /* Archive */ |
Sissors | 2:9af05743d551 | 310 | #define AM_MASK 0x3F /* Mask of defined bits */ |
Sissors | 2:9af05743d551 | 311 | |
Sissors | 2:9af05743d551 | 312 | |
Sissors | 2:9af05743d551 | 313 | /* Fast seek feature */ |
Sissors | 2:9af05743d551 | 314 | #define CREATE_LINKMAP 0xFFFFFFFF |
Sissors | 2:9af05743d551 | 315 | |
Sissors | 2:9af05743d551 | 316 | |
Sissors | 2:9af05743d551 | 317 | |
Sissors | 2:9af05743d551 | 318 | /*--------------------------------*/ |
Sissors | 2:9af05743d551 | 319 | /* Multi-byte word access macros */ |
Sissors | 2:9af05743d551 | 320 | |
Sissors | 2:9af05743d551 | 321 | #if _WORD_ACCESS == 1 /* Enable word access to the FAT structure */ |
Sissors | 2:9af05743d551 | 322 | #define LD_WORD(ptr) (WORD)(*(WORD*)(BYTE*)(ptr)) |
Sissors | 2:9af05743d551 | 323 | #define LD_DWORD(ptr) (DWORD)(*(DWORD*)(BYTE*)(ptr)) |
Sissors | 2:9af05743d551 | 324 | #define ST_WORD(ptr,val) *(WORD*)(BYTE*)(ptr)=(WORD)(val) |
Sissors | 2:9af05743d551 | 325 | #define ST_DWORD(ptr,val) *(DWORD*)(BYTE*)(ptr)=(DWORD)(val) |
Sissors | 2:9af05743d551 | 326 | #else /* Use byte-by-byte access to the FAT structure */ |
Sissors | 2:9af05743d551 | 327 | #define LD_WORD(ptr) (WORD)(((WORD)*((BYTE*)(ptr)+1)<<8)|(WORD)*(BYTE*)(ptr)) |
Sissors | 2:9af05743d551 | 328 | #define LD_DWORD(ptr) (DWORD)(((DWORD)*((BYTE*)(ptr)+3)<<24)|((DWORD)*((BYTE*)(ptr)+2)<<16)|((WORD)*((BYTE*)(ptr)+1)<<8)|*(BYTE*)(ptr)) |
Sissors | 2:9af05743d551 | 329 | #define ST_WORD(ptr,val) *(BYTE*)(ptr)=(BYTE)(val); *((BYTE*)(ptr)+1)=(BYTE)((WORD)(val)>>8) |
Sissors | 2:9af05743d551 | 330 | #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) |
Sissors | 2:9af05743d551 | 331 | #endif |
Sissors | 2:9af05743d551 | 332 | |
Sissors | 2:9af05743d551 | 333 | #ifdef __cplusplus |
Sissors | 2:9af05743d551 | 334 | } |
Sissors | 2:9af05743d551 | 335 | #endif |
Sissors | 2:9af05743d551 | 336 | |
Sissors | 2:9af05743d551 | 337 | #endif /* _FATFS */ |