Emulation of LocalFileSystem with virtual COM.

Dependencies:   USBDevice

Dependents:   KL46Z-lpc81isp lpcterm2

#include "USBLocalFileSystem.h"

int main() {
    USBLocalFileSystem* usb_local = new USBLocalFileSystem(); // RamDisk(64KB)

    while(1) {
        usb_local->lock(true);
        usb_local->remount();
        char filename[32];
        if (usb_local->find(filename, sizeof(filename), "*.TXT")) {
            FILE* fp = fopen(filename, "r");
            if (fp) {
                int c;
                while((c = fgetc(fp)) != EOF) {
                    usb_local->putc(c);
                }
                fclose(fp);
            }
        }    
        usb_local->lock(false);

        wait_ms(1000*5);
    }
}



Sample application:

Import programKL46Z-lpc81isp

ISP example program.

Import programlpcterm2

semihost server example program

Committer:
va009039
Date:
Sat May 03 11:21:37 2014 +0000
Revision:
0:39eb4d5b97df
first commit

Who changed what in which revision?

UserRevisionLine numberNew contents of line
va009039 0:39eb4d5b97df 1 /*---------------------------------------------------------------------------/
va009039 0:39eb4d5b97df 2 / FatFs - FAT file system module include file R0.09a (C)ChaN, 2012
va009039 0:39eb4d5b97df 3 /----------------------------------------------------------------------------/
va009039 0:39eb4d5b97df 4 / FatFs module is a generic FAT file system module for small embedded systems.
va009039 0:39eb4d5b97df 5 / This is a free software that opened for education, research and commercial
va009039 0:39eb4d5b97df 6 / developments under license policy of following terms.
va009039 0:39eb4d5b97df 7 /
va009039 0:39eb4d5b97df 8 / Copyright (C) 2012, ChaN, all right reserved.
va009039 0:39eb4d5b97df 9 /
va009039 0:39eb4d5b97df 10 / * The FatFs module is a free software and there is NO WARRANTY.
va009039 0:39eb4d5b97df 11 / * No restriction on use. You can use, modify and redistribute it for
va009039 0:39eb4d5b97df 12 / personal, non-profit or commercial product UNDER YOUR RESPONSIBILITY.
va009039 0:39eb4d5b97df 13 / * Redistributions of source code must retain the above copyright notice.
va009039 0:39eb4d5b97df 14 /
va009039 0:39eb4d5b97df 15 /----------------------------------------------------------------------------*/
va009039 0:39eb4d5b97df 16
va009039 0:39eb4d5b97df 17 #ifndef _FATFS
va009039 0:39eb4d5b97df 18 #define _FATFS 4004 /* Revision ID */
va009039 0:39eb4d5b97df 19
va009039 0:39eb4d5b97df 20 #ifdef __cplusplus
va009039 0:39eb4d5b97df 21 extern "C" {
va009039 0:39eb4d5b97df 22 #endif
va009039 0:39eb4d5b97df 23
va009039 0:39eb4d5b97df 24 #include "integer.h" /* Basic integer types */
va009039 0:39eb4d5b97df 25 #include "ffconf.h" /* FatFs configuration options */
va009039 0:39eb4d5b97df 26
va009039 0:39eb4d5b97df 27 #if _FATFS != _FFCONF
va009039 0:39eb4d5b97df 28 #error Wrong configuration file (ffconf.h).
va009039 0:39eb4d5b97df 29 #endif
va009039 0:39eb4d5b97df 30
va009039 0:39eb4d5b97df 31
va009039 0:39eb4d5b97df 32
va009039 0:39eb4d5b97df 33 /* Definitions of volume management */
va009039 0:39eb4d5b97df 34
va009039 0:39eb4d5b97df 35 #if _MULTI_PARTITION /* Multiple partition configuration */
va009039 0:39eb4d5b97df 36 typedef struct {
va009039 0:39eb4d5b97df 37 BYTE pd; /* Physical drive number */
va009039 0:39eb4d5b97df 38 BYTE pt; /* Partition: 0:Auto detect, 1-4:Forced partition) */
va009039 0:39eb4d5b97df 39 } PARTITION;
va009039 0:39eb4d5b97df 40 extern PARTITION VolToPart[]; /* Volume - Partition resolution table */
va009039 0:39eb4d5b97df 41 #define LD2PD(vol) (VolToPart[vol].pd) /* Get physical drive number */
va009039 0:39eb4d5b97df 42 #define LD2PT(vol) (VolToPart[vol].pt) /* Get partition index */
va009039 0:39eb4d5b97df 43
va009039 0:39eb4d5b97df 44 #else /* Single partition configuration */
va009039 0:39eb4d5b97df 45 #define LD2PD(vol) (BYTE)(vol) /* Each logical drive is bound to the same physical drive number */
va009039 0:39eb4d5b97df 46 #define LD2PT(vol) 0 /* Always mounts the 1st partition or in SFD */
va009039 0:39eb4d5b97df 47
va009039 0:39eb4d5b97df 48 #endif
va009039 0:39eb4d5b97df 49
va009039 0:39eb4d5b97df 50
va009039 0:39eb4d5b97df 51
va009039 0:39eb4d5b97df 52 /* Type of path name strings on FatFs API */
va009039 0:39eb4d5b97df 53
va009039 0:39eb4d5b97df 54 #if _LFN_UNICODE /* Unicode string */
va009039 0:39eb4d5b97df 55 #if !_USE_LFN
va009039 0:39eb4d5b97df 56 #error _LFN_UNICODE must be 0 in non-LFN cfg.
va009039 0:39eb4d5b97df 57 #endif
va009039 0:39eb4d5b97df 58 #ifndef _INC_TCHAR
va009039 0:39eb4d5b97df 59 typedef WCHAR TCHAR;
va009039 0:39eb4d5b97df 60 #define _T(x) L ## x
va009039 0:39eb4d5b97df 61 #define _TEXT(x) L ## x
va009039 0:39eb4d5b97df 62 #endif
va009039 0:39eb4d5b97df 63
va009039 0:39eb4d5b97df 64 #else /* ANSI/OEM string */
va009039 0:39eb4d5b97df 65 #ifndef _INC_TCHAR
va009039 0:39eb4d5b97df 66 typedef char TCHAR;
va009039 0:39eb4d5b97df 67 #define _T(x) x
va009039 0:39eb4d5b97df 68 #define _TEXT(x) x
va009039 0:39eb4d5b97df 69 #endif
va009039 0:39eb4d5b97df 70
va009039 0:39eb4d5b97df 71 #endif
va009039 0:39eb4d5b97df 72
va009039 0:39eb4d5b97df 73
va009039 0:39eb4d5b97df 74
va009039 0:39eb4d5b97df 75 /* File system object structure (FATFS) */
va009039 0:39eb4d5b97df 76
va009039 0:39eb4d5b97df 77 typedef struct {
va009039 0:39eb4d5b97df 78 BYTE fs_type; /* FAT sub-type (0:Not mounted) */
va009039 0:39eb4d5b97df 79 BYTE drv; /* Physical drive number */
va009039 0:39eb4d5b97df 80 BYTE csize; /* Sectors per cluster (1,2,4...128) */
va009039 0:39eb4d5b97df 81 BYTE n_fats; /* Number of FAT copies (1,2) */
va009039 0:39eb4d5b97df 82 BYTE wflag; /* win[] dirty flag (1:must be written back) */
va009039 0:39eb4d5b97df 83 BYTE fsi_flag; /* fsinfo dirty flag (1:must be written back) */
va009039 0:39eb4d5b97df 84 WORD id; /* File system mount ID */
va009039 0:39eb4d5b97df 85 WORD n_rootdir; /* Number of root directory entries (FAT12/16) */
va009039 0:39eb4d5b97df 86 #if _MAX_SS != 512
va009039 0:39eb4d5b97df 87 WORD ssize; /* Bytes per sector (512, 1024, 2048 or 4096) */
va009039 0:39eb4d5b97df 88 #endif
va009039 0:39eb4d5b97df 89 #if _FS_REENTRANT
va009039 0:39eb4d5b97df 90 _SYNC_t sobj; /* Identifier of sync object */
va009039 0:39eb4d5b97df 91 #endif
va009039 0:39eb4d5b97df 92 #if !_FS_READONLY
va009039 0:39eb4d5b97df 93 DWORD last_clust; /* Last allocated cluster */
va009039 0:39eb4d5b97df 94 DWORD free_clust; /* Number of free clusters */
va009039 0:39eb4d5b97df 95 DWORD fsi_sector; /* fsinfo sector (FAT32) */
va009039 0:39eb4d5b97df 96 #endif
va009039 0:39eb4d5b97df 97 #if _FS_RPATH
va009039 0:39eb4d5b97df 98 DWORD cdir; /* Current directory start cluster (0:root) */
va009039 0:39eb4d5b97df 99 #endif
va009039 0:39eb4d5b97df 100 DWORD n_fatent; /* Number of FAT entries (= number of clusters + 2) */
va009039 0:39eb4d5b97df 101 DWORD fsize; /* Sectors per FAT */
va009039 0:39eb4d5b97df 102 DWORD fatbase; /* FAT start sector */
va009039 0:39eb4d5b97df 103 DWORD dirbase; /* Root directory start sector (FAT32:Cluster#) */
va009039 0:39eb4d5b97df 104 DWORD database; /* Data start sector */
va009039 0:39eb4d5b97df 105 DWORD winsect; /* Current sector appearing in the win[] */
va009039 0:39eb4d5b97df 106 BYTE win[_MAX_SS]; /* Disk access window for Directory, FAT (and Data on tiny cfg) */
va009039 0:39eb4d5b97df 107 } FATFS;
va009039 0:39eb4d5b97df 108
va009039 0:39eb4d5b97df 109
va009039 0:39eb4d5b97df 110
va009039 0:39eb4d5b97df 111 /* File object structure (FIL) */
va009039 0:39eb4d5b97df 112
va009039 0:39eb4d5b97df 113 typedef struct {
va009039 0:39eb4d5b97df 114 FATFS* fs; /* Pointer to the related file system object */
va009039 0:39eb4d5b97df 115 WORD id; /* File system mount ID of the related file system object */
va009039 0:39eb4d5b97df 116 BYTE flag; /* File status flags */
va009039 0:39eb4d5b97df 117 BYTE pad1;
va009039 0:39eb4d5b97df 118 DWORD fptr; /* File read/write pointer (0ed on file open) */
va009039 0:39eb4d5b97df 119 DWORD fsize; /* File size */
va009039 0:39eb4d5b97df 120 DWORD sclust; /* File data start cluster (0:no data cluster, always 0 when fsize is 0) */
va009039 0:39eb4d5b97df 121 DWORD clust; /* Current cluster of fpter */
va009039 0:39eb4d5b97df 122 DWORD dsect; /* Current data sector of fpter */
va009039 0:39eb4d5b97df 123 #if !_FS_READONLY
va009039 0:39eb4d5b97df 124 DWORD dir_sect; /* Sector containing the directory entry */
va009039 0:39eb4d5b97df 125 BYTE* dir_ptr; /* Pointer to the directory entry in the window */
va009039 0:39eb4d5b97df 126 #endif
va009039 0:39eb4d5b97df 127 #if _USE_FASTSEEK
va009039 0:39eb4d5b97df 128 DWORD* cltbl; /* Pointer to the cluster link map table (null on file open) */
va009039 0:39eb4d5b97df 129 #endif
va009039 0:39eb4d5b97df 130 #if _FS_LOCK
va009039 0:39eb4d5b97df 131 UINT lockid; /* File lock ID (index of file semaphore table Files[]) */
va009039 0:39eb4d5b97df 132 #endif
va009039 0:39eb4d5b97df 133 #if !_FS_TINY
va009039 0:39eb4d5b97df 134 BYTE buf[_MAX_SS]; /* File data read/write buffer */
va009039 0:39eb4d5b97df 135 #endif
va009039 0:39eb4d5b97df 136 } FIL;
va009039 0:39eb4d5b97df 137
va009039 0:39eb4d5b97df 138
va009039 0:39eb4d5b97df 139
va009039 0:39eb4d5b97df 140 /* Directory object structure (DIR) */
va009039 0:39eb4d5b97df 141
va009039 0:39eb4d5b97df 142 typedef struct {
va009039 0:39eb4d5b97df 143 FATFS* fs; /* Pointer to the owner file system object */
va009039 0:39eb4d5b97df 144 WORD id; /* Owner file system mount ID */
va009039 0:39eb4d5b97df 145 WORD index; /* Current read/write index number */
va009039 0:39eb4d5b97df 146 DWORD sclust; /* Table start cluster (0:Root dir) */
va009039 0:39eb4d5b97df 147 DWORD clust; /* Current cluster */
va009039 0:39eb4d5b97df 148 DWORD sect; /* Current sector */
va009039 0:39eb4d5b97df 149 BYTE* dir; /* Pointer to the current SFN entry in the win[] */
va009039 0:39eb4d5b97df 150 BYTE* fn; /* Pointer to the SFN (in/out) {file[8],ext[3],status[1]} */
va009039 0:39eb4d5b97df 151 #if _USE_LFN
va009039 0:39eb4d5b97df 152 WCHAR* lfn; /* Pointer to the LFN working buffer */
va009039 0:39eb4d5b97df 153 WORD lfn_idx; /* Last matched LFN index number (0xFFFF:No LFN) */
va009039 0:39eb4d5b97df 154 #endif
va009039 0:39eb4d5b97df 155 } FATFS_DIR;
va009039 0:39eb4d5b97df 156
va009039 0:39eb4d5b97df 157
va009039 0:39eb4d5b97df 158
va009039 0:39eb4d5b97df 159 /* File status structure (FILINFO) */
va009039 0:39eb4d5b97df 160
va009039 0:39eb4d5b97df 161 typedef struct {
va009039 0:39eb4d5b97df 162 DWORD fsize; /* File size */
va009039 0:39eb4d5b97df 163 WORD fdate; /* Last modified date */
va009039 0:39eb4d5b97df 164 WORD ftime; /* Last modified time */
va009039 0:39eb4d5b97df 165 BYTE fattrib; /* Attribute */
va009039 0:39eb4d5b97df 166 TCHAR fname[13]; /* Short file name (8.3 format) */
va009039 0:39eb4d5b97df 167 #if _USE_LFN
va009039 0:39eb4d5b97df 168 TCHAR* lfname; /* Pointer to the LFN buffer */
va009039 0:39eb4d5b97df 169 UINT lfsize; /* Size of LFN buffer in TCHAR */
va009039 0:39eb4d5b97df 170 #endif
va009039 0:39eb4d5b97df 171 } FILINFO;
va009039 0:39eb4d5b97df 172
va009039 0:39eb4d5b97df 173
va009039 0:39eb4d5b97df 174
va009039 0:39eb4d5b97df 175 /* File function return code (FRESULT) */
va009039 0:39eb4d5b97df 176
va009039 0:39eb4d5b97df 177 typedef enum {
va009039 0:39eb4d5b97df 178 FR_OK = 0, /* (0) Succeeded */
va009039 0:39eb4d5b97df 179 FR_DISK_ERR, /* (1) A hard error occurred in the low level disk I/O layer */
va009039 0:39eb4d5b97df 180 FR_INT_ERR, /* (2) Assertion failed */
va009039 0:39eb4d5b97df 181 FR_NOT_READY, /* (3) The physical drive cannot work */
va009039 0:39eb4d5b97df 182 FR_NO_FILE, /* (4) Could not find the file */
va009039 0:39eb4d5b97df 183 FR_NO_PATH, /* (5) Could not find the path */
va009039 0:39eb4d5b97df 184 FR_INVALID_NAME, /* (6) The path name format is invalid */
va009039 0:39eb4d5b97df 185 FR_DENIED, /* (7) Access denied due to prohibited access or directory full */
va009039 0:39eb4d5b97df 186 FR_EXIST, /* (8) Access denied due to prohibited access */
va009039 0:39eb4d5b97df 187 FR_INVALID_OBJECT, /* (9) The file/directory object is invalid */
va009039 0:39eb4d5b97df 188 FR_WRITE_PROTECTED, /* (10) The physical drive is write protected */
va009039 0:39eb4d5b97df 189 FR_INVALID_DRIVE, /* (11) The logical drive number is invalid */
va009039 0:39eb4d5b97df 190 FR_NOT_ENABLED, /* (12) The volume has no work area */
va009039 0:39eb4d5b97df 191 FR_NO_FILESYSTEM, /* (13) There is no valid FAT volume */
va009039 0:39eb4d5b97df 192 FR_MKFS_ABORTED, /* (14) The f_mkfs() aborted due to any parameter error */
va009039 0:39eb4d5b97df 193 FR_TIMEOUT, /* (15) Could not get a grant to access the volume within defined period */
va009039 0:39eb4d5b97df 194 FR_LOCKED, /* (16) The operation is rejected according to the file sharing policy */
va009039 0:39eb4d5b97df 195 FR_NOT_ENOUGH_CORE, /* (17) LFN working buffer could not be allocated */
va009039 0:39eb4d5b97df 196 FR_TOO_MANY_OPEN_FILES, /* (18) Number of open files > _FS_SHARE */
va009039 0:39eb4d5b97df 197 FR_INVALID_PARAMETER /* (19) Given parameter is invalid */
va009039 0:39eb4d5b97df 198 } FRESULT;
va009039 0:39eb4d5b97df 199
va009039 0:39eb4d5b97df 200
va009039 0:39eb4d5b97df 201
va009039 0:39eb4d5b97df 202 /*--------------------------------------------------------------*/
va009039 0:39eb4d5b97df 203 /* FatFs module application interface */
va009039 0:39eb4d5b97df 204
va009039 0:39eb4d5b97df 205 FRESULT f_mount (BYTE, FATFS*); /* Mount/Unmount a logical drive */
va009039 0:39eb4d5b97df 206 FRESULT f_open (FIL*, const TCHAR*, BYTE); /* Open or create a file */
va009039 0:39eb4d5b97df 207 FRESULT f_read (FIL*, void*, UINT, UINT*); /* Read data from a file */
va009039 0:39eb4d5b97df 208 FRESULT f_lseek (FIL*, DWORD); /* Move file pointer of a file object */
va009039 0:39eb4d5b97df 209 FRESULT f_close (FIL*); /* Close an open file object */
va009039 0:39eb4d5b97df 210 FRESULT f_opendir (FATFS_DIR*, const TCHAR*); /* Open an existing directory */
va009039 0:39eb4d5b97df 211 FRESULT f_readdir (FATFS_DIR*, FILINFO*); /* Read a directory item */
va009039 0:39eb4d5b97df 212 FRESULT f_stat (const TCHAR*, FILINFO*); /* Get file status */
va009039 0:39eb4d5b97df 213 FRESULT f_write (FIL*, const void*, UINT, UINT*); /* Write data to a file */
va009039 0:39eb4d5b97df 214 FRESULT f_getfree (const TCHAR*, DWORD*, FATFS**); /* Get number of free clusters on the drive */
va009039 0:39eb4d5b97df 215 FRESULT f_truncate (FIL*); /* Truncate file */
va009039 0:39eb4d5b97df 216 FRESULT f_sync (FIL*); /* Flush cached data of a writing file */
va009039 0:39eb4d5b97df 217 FRESULT f_unlink (const TCHAR*); /* Delete an existing file or directory */
va009039 0:39eb4d5b97df 218 FRESULT f_mkdir (const TCHAR*); /* Create a new directory */
va009039 0:39eb4d5b97df 219 FRESULT f_chmod (const TCHAR*, BYTE, BYTE); /* Change attribute of the file/dir */
va009039 0:39eb4d5b97df 220 FRESULT f_utime (const TCHAR*, const FILINFO*); /* Change times-tamp of the file/dir */
va009039 0:39eb4d5b97df 221 FRESULT f_rename (const TCHAR*, const TCHAR*); /* Rename/Move a file or directory */
va009039 0:39eb4d5b97df 222 FRESULT f_chdrive (BYTE); /* Change current drive */
va009039 0:39eb4d5b97df 223 FRESULT f_chdir (const TCHAR*); /* Change current directory */
va009039 0:39eb4d5b97df 224 FRESULT f_getcwd (TCHAR*, UINT); /* Get current directory */
va009039 0:39eb4d5b97df 225 FRESULT f_forward (FIL*, UINT(*)(const BYTE*,UINT), UINT, UINT*); /* Forward data to the stream */
va009039 0:39eb4d5b97df 226 FRESULT f_mkfs (BYTE, BYTE, UINT); /* Create a file system on the drive */
va009039 0:39eb4d5b97df 227 FRESULT f_fdisk (BYTE, const DWORD[], void*); /* Divide a physical drive into some partitions */
va009039 0:39eb4d5b97df 228 int f_putc (TCHAR, FIL*); /* Put a character to the file */
va009039 0:39eb4d5b97df 229 int f_puts (const TCHAR*, FIL*); /* Put a string to the file */
va009039 0:39eb4d5b97df 230 int f_printf (FIL*, const TCHAR*, ...); /* Put a formatted string to the file */
va009039 0:39eb4d5b97df 231 TCHAR* f_gets (TCHAR*, int, FIL*); /* Get a string from the file */
va009039 0:39eb4d5b97df 232
va009039 0:39eb4d5b97df 233 #define f_eof(fp) (((fp)->fptr == (fp)->fsize) ? 1 : 0)
va009039 0:39eb4d5b97df 234 #define f_error(fp) (((fp)->flag & FA__ERROR) ? 1 : 0)
va009039 0:39eb4d5b97df 235 #define f_tell(fp) ((fp)->fptr)
va009039 0:39eb4d5b97df 236 #define f_size(fp) ((fp)->fsize)
va009039 0:39eb4d5b97df 237
va009039 0:39eb4d5b97df 238 #ifndef EOF
va009039 0:39eb4d5b97df 239 #define EOF (-1)
va009039 0:39eb4d5b97df 240 #endif
va009039 0:39eb4d5b97df 241
va009039 0:39eb4d5b97df 242
va009039 0:39eb4d5b97df 243
va009039 0:39eb4d5b97df 244
va009039 0:39eb4d5b97df 245 /*--------------------------------------------------------------*/
va009039 0:39eb4d5b97df 246 /* Additional user defined functions */
va009039 0:39eb4d5b97df 247
va009039 0:39eb4d5b97df 248 /* RTC function */
va009039 0:39eb4d5b97df 249 #if !_FS_READONLY
va009039 0:39eb4d5b97df 250 DWORD get_fattime (void);
va009039 0:39eb4d5b97df 251 #endif
va009039 0:39eb4d5b97df 252
va009039 0:39eb4d5b97df 253 /* Unicode support functions */
va009039 0:39eb4d5b97df 254 #if _USE_LFN /* Unicode - OEM code conversion */
va009039 0:39eb4d5b97df 255 WCHAR ff_convert (WCHAR, UINT); /* OEM-Unicode bidirectional conversion */
va009039 0:39eb4d5b97df 256 WCHAR ff_wtoupper (WCHAR); /* Unicode upper-case conversion */
va009039 0:39eb4d5b97df 257 #if _USE_LFN == 3 /* Memory functions */
va009039 0:39eb4d5b97df 258 void* ff_memalloc (UINT); /* Allocate memory block */
va009039 0:39eb4d5b97df 259 void ff_memfree (void*); /* Free memory block */
va009039 0:39eb4d5b97df 260 #endif
va009039 0:39eb4d5b97df 261 #endif
va009039 0:39eb4d5b97df 262
va009039 0:39eb4d5b97df 263 /* Sync functions */
va009039 0:39eb4d5b97df 264 #if _FS_REENTRANT
va009039 0:39eb4d5b97df 265 int ff_cre_syncobj (BYTE, _SYNC_t*);/* Create a sync object */
va009039 0:39eb4d5b97df 266 int ff_req_grant (_SYNC_t); /* Lock sync object */
va009039 0:39eb4d5b97df 267 void ff_rel_grant (_SYNC_t); /* Unlock sync object */
va009039 0:39eb4d5b97df 268 int ff_del_syncobj (_SYNC_t); /* Delete a sync object */
va009039 0:39eb4d5b97df 269 #endif
va009039 0:39eb4d5b97df 270
va009039 0:39eb4d5b97df 271
va009039 0:39eb4d5b97df 272
va009039 0:39eb4d5b97df 273
va009039 0:39eb4d5b97df 274 /*--------------------------------------------------------------*/
va009039 0:39eb4d5b97df 275 /* Flags and offset address */
va009039 0:39eb4d5b97df 276
va009039 0:39eb4d5b97df 277
va009039 0:39eb4d5b97df 278 /* File access control and file status flags (FIL.flag) */
va009039 0:39eb4d5b97df 279
va009039 0:39eb4d5b97df 280 #define FA_READ 0x01
va009039 0:39eb4d5b97df 281 #define FA_OPEN_EXISTING 0x00
va009039 0:39eb4d5b97df 282 #define FA__ERROR 0x80
va009039 0:39eb4d5b97df 283
va009039 0:39eb4d5b97df 284 #if !_FS_READONLY
va009039 0:39eb4d5b97df 285 #define FA_WRITE 0x02
va009039 0:39eb4d5b97df 286 #define FA_CREATE_NEW 0x04
va009039 0:39eb4d5b97df 287 #define FA_CREATE_ALWAYS 0x08
va009039 0:39eb4d5b97df 288 #define FA_OPEN_ALWAYS 0x10
va009039 0:39eb4d5b97df 289 #define FA__WRITTEN 0x20
va009039 0:39eb4d5b97df 290 #define FA__DIRTY 0x40
va009039 0:39eb4d5b97df 291 #endif
va009039 0:39eb4d5b97df 292
va009039 0:39eb4d5b97df 293
va009039 0:39eb4d5b97df 294 /* FAT sub type (FATFS.fs_type) */
va009039 0:39eb4d5b97df 295
va009039 0:39eb4d5b97df 296 #define FS_FAT12 1
va009039 0:39eb4d5b97df 297 #define FS_FAT16 2
va009039 0:39eb4d5b97df 298 #define FS_FAT32 3
va009039 0:39eb4d5b97df 299
va009039 0:39eb4d5b97df 300
va009039 0:39eb4d5b97df 301 /* File attribute bits for directory entry */
va009039 0:39eb4d5b97df 302
va009039 0:39eb4d5b97df 303 #define AM_RDO 0x01 /* Read only */
va009039 0:39eb4d5b97df 304 #define AM_HID 0x02 /* Hidden */
va009039 0:39eb4d5b97df 305 #define AM_SYS 0x04 /* System */
va009039 0:39eb4d5b97df 306 #define AM_VOL 0x08 /* Volume label */
va009039 0:39eb4d5b97df 307 #define AM_LFN 0x0F /* LFN entry */
va009039 0:39eb4d5b97df 308 #define AM_DIR 0x10 /* Directory */
va009039 0:39eb4d5b97df 309 #define AM_ARC 0x20 /* Archive */
va009039 0:39eb4d5b97df 310 #define AM_MASK 0x3F /* Mask of defined bits */
va009039 0:39eb4d5b97df 311
va009039 0:39eb4d5b97df 312
va009039 0:39eb4d5b97df 313 /* Fast seek feature */
va009039 0:39eb4d5b97df 314 #define CREATE_LINKMAP 0xFFFFFFFF
va009039 0:39eb4d5b97df 315
va009039 0:39eb4d5b97df 316
va009039 0:39eb4d5b97df 317
va009039 0:39eb4d5b97df 318 /*--------------------------------*/
va009039 0:39eb4d5b97df 319 /* Multi-byte word access macros */
va009039 0:39eb4d5b97df 320
va009039 0:39eb4d5b97df 321 #if _WORD_ACCESS == 1 /* Enable word access to the FAT structure */
va009039 0:39eb4d5b97df 322 #define LD_WORD(ptr) (WORD)(*(WORD*)(BYTE*)(ptr))
va009039 0:39eb4d5b97df 323 #define LD_DWORD(ptr) (DWORD)(*(DWORD*)(BYTE*)(ptr))
va009039 0:39eb4d5b97df 324 #define ST_WORD(ptr,val) *(WORD*)(BYTE*)(ptr)=(WORD)(val)
va009039 0:39eb4d5b97df 325 #define ST_DWORD(ptr,val) *(DWORD*)(BYTE*)(ptr)=(DWORD)(val)
va009039 0:39eb4d5b97df 326 #else /* Use byte-by-byte access to the FAT structure */
va009039 0:39eb4d5b97df 327 #define LD_WORD(ptr) (WORD)(((WORD)*((BYTE*)(ptr)+1)<<8)|(WORD)*(BYTE*)(ptr))
va009039 0:39eb4d5b97df 328 #define LD_DWORD(ptr) (DWORD)(((DWORD)*((BYTE*)(ptr)+3)<<24)|((DWORD)*((BYTE*)(ptr)+2)<<16)|((WORD)*((BYTE*)(ptr)+1)<<8)|*(BYTE*)(ptr))
va009039 0:39eb4d5b97df 329 #define ST_WORD(ptr,val) *(BYTE*)(ptr)=(BYTE)(val); *((BYTE*)(ptr)+1)=(BYTE)((WORD)(val)>>8)
va009039 0:39eb4d5b97df 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)
va009039 0:39eb4d5b97df 331 #endif
va009039 0:39eb4d5b97df 332
va009039 0:39eb4d5b97df 333 #ifdef __cplusplus
va009039 0:39eb4d5b97df 334 }
va009039 0:39eb4d5b97df 335 #endif
va009039 0:39eb4d5b97df 336
va009039 0:39eb4d5b97df 337 #endif /* _FATFS */