Ignore:
Timestamp:
Apr 5, 2019, 9:26:53 PM (5 years ago)
Author:
coas-nagasima
Message:

mbed関連を更新
シリアルドライバをmbedのHALを使うよう変更
ファイルディスクリプタの処理を更新

File:
1 edited

Legend:

Unmodified
Added
Removed
  • asp3_tinet_ecnl_arm/trunk/ntshell/fatfs/ff.c

    r369 r374  
    2020#include "ff.h"                 /* Declarations of FatFs API */
    2121#include "diskio.h"             /* Declarations of disk I/O functions */
    22 #include "util/ntstdio.h"
     22#include <stdio.h>
    2323
    2424/*--------------------------------------------------------------------------
     
    3434
    3535/* Reentrancy related */
    36 #if _FS_REENTRANT
    37 #if _USE_LFN == 1
     36#if FF_FS_REENTRANT
     37#if FF_USE_LFN == 1
    3838#error Static LFN work area cannot be used at thread-safe configuration
    3939#endif
     
    4949
    5050/* Definitions of sector size */
    51 #if (_MAX_SS < _MIN_SS) || (_MAX_SS != 512 && _MAX_SS != 1024 && _MAX_SS != 2048 && _MAX_SS != 4096) || (_MIN_SS != 512 && _MIN_SS != 1024 && _MIN_SS != 2048 && _MIN_SS != 4096)
     51#if (FF_MAX_SS < FF_MIN_SS) || (FF_MAX_SS != 512 && FF_MAX_SS != 1024 && FF_MAX_SS != 2048 && FF_MAX_SS != 4096) || (FF_MIN_SS != 512 && FF_MIN_SS != 1024 && FF_MIN_SS != 2048 && FF_MIN_SS != 4096)
    5252#error Wrong sector size configuration
    5353#endif
    54 #if _MAX_SS == _MIN_SS
    55 #define SS(fs)  ((UINT)_MAX_SS) /* Fixed sector size */
     54#if FF_MAX_SS == FF_MIN_SS
     55#define SS(fs)  ((UINT)FF_MAX_SS)       /* Fixed sector size */
    5656#else
    5757#define SS(fs)  ((fs)->ssize)   /* Variable sector size */
     
    6060
    6161/* Timestamp feature */
    62 #if _FS_NORTC == 1
    63 #if _NORTC_YEAR < 1980 || _NORTC_YEAR > 2107 || _NORTC_MON < 1 || _NORTC_MON > 12 || _NORTC_MDAY < 1 || _NORTC_MDAY > 31
    64 #error Invalid _FS_NORTC settings
    65 #endif
    66 #define GET_FATTIME()   ((DWORD)(_NORTC_YEAR - 1980) << 25 | (DWORD)_NORTC_MON << 21 | (DWORD)_NORTC_MDAY << 16)
     62#if FF_FS_NORTC == 1
     63#if FF_NORTC_YEAR < 1980 || FF_NORTC_YEAR > 2107 || FF_NORTC_MON < 1 || FF_NORTC_MON > 12 || FF_NORTC_MDAY < 1 || FF_NORTC_MDAY > 31
     64#error Invalid FF_FS_NORTC settings
     65#endif
     66#define GET_FATTIME()   ((DWORD)(FF_NORTC_YEAR - 1980) << 25 | (DWORD)FF_NORTC_MON << 21 | (DWORD)FF_NORTC_MDAY << 16)
    6767#else
    6868#define GET_FATTIME()   get_fattime()
     
    7171
    7272/* File access control feature */
    73 #if _FS_LOCK
    74 #if _FS_READONLY
    75 #error _FS_LOCK must be 0 at read-only configuration
     73#if FF_FS_LOCK != 0
     74#if FF_FS_READONLY
     75#error FF_FS_LOCK must be 0 at read-only configuration
    7676#endif
    7777typedef struct {
     
    8787/* DBCS code ranges and SBCS upper conversion tables */
    8888
    89 #if _CODE_PAGE == 932   /* Japanese Shift-JIS */
     89#if FF_CODE_PAGE == 932 /* Japanese Shift-JIS */
    9090#define _DF1S   0x81    /* DBC 1st byte range 1 start */
    9191#define _DF1E   0x9F    /* DBC 1st byte range 1 end */
     
    9797#define _DS2E   0xFC    /* DBC 2nd byte range 2 end */
    9898
    99 #elif _CODE_PAGE == 936 /* Simplified Chinese GBK */
     99#elif FF_CODE_PAGE == 936       /* Simplified Chinese GBK */
    100100#define _DF1S   0x81
    101101#define _DF1E   0xFE
     
    105105#define _DS2E   0xFE
    106106
    107 #elif _CODE_PAGE == 949 /* Korean */
     107#elif FF_CODE_PAGE == 949       /* Korean */
    108108#define _DF1S   0x81
    109109#define _DF1E   0xFE
     
    115115#define _DS3E   0xFE
    116116
    117 #elif _CODE_PAGE == 950 /* Traditional Chinese Big5 */
     117#elif FF_CODE_PAGE == 950       /* Traditional Chinese Big5 */
    118118#define _DF1S   0x81
    119119#define _DF1E   0xFE
     
    123123#define _DS2E   0xFE
    124124
    125 #elif _CODE_PAGE == 437 /* U.S. */
     125#elif FF_CODE_PAGE == 437       /* U.S. */
    126126#define _DF1S   0
    127127#define _EXCVT {0x80,0x9A,0x45,0x41,0x8E,0x41,0x8F,0x80,0x45,0x45,0x45,0x49,0x49,0x49,0x8E,0x8F, \
     
    134134                                0xF0,0xF1,0xF2,0xF3,0xF4,0xF5,0xF6,0xF7,0xF8,0xF9,0xFA,0xFB,0xFC,0xFD,0xFE,0xFF}
    135135
    136 #elif _CODE_PAGE == 720 /* Arabic */
     136#elif FF_CODE_PAGE == 720       /* Arabic */
    137137#define _DF1S   0
    138138#define _EXCVT {0x80,0x81,0x82,0x83,0x84,0x85,0x86,0x87,0x88,0x89,0x8A,0x8B,0x8C,0x8D,0x8E,0x8F, \
     
    145145                                0xF0,0xF1,0xF2,0xF3,0xF4,0xF5,0xF6,0xF7,0xF8,0xF9,0xFA,0xFB,0xFC,0xFD,0xFE,0xFF}
    146146
    147 #elif _CODE_PAGE == 737 /* Greek */
     147#elif FF_CODE_PAGE == 737       /* Greek */
    148148#define _DF1S   0
    149149#define _EXCVT {0x80,0x81,0x82,0x83,0x84,0x85,0x86,0x87,0x88,0x89,0x8A,0x8B,0x8C,0x8D,0x8E,0x8F, \
     
    156156                                0xF0,0xF1,0xF2,0xF3,0xF4,0xF5,0xF6,0xF7,0xF8,0xF9,0xFA,0xFB,0xFC,0xFD,0xFE,0xFF}
    157157
    158 #elif _CODE_PAGE == 771 /* KBL */
     158#elif FF_CODE_PAGE == 771       /* KBL */
    159159#define _DF1S   0
    160160#define _EXCVT {0x80,0x81,0x82,0x83,0x84,0x85,0x86,0x87,0x88,0x89,0x8A,0x8B,0x8C,0x8D,0x8E,0x8F, \
     
    167167                                0xF0,0xF0,0xF2,0xF2,0xF4,0xF4,0xF6,0xF6,0xF8,0xF8,0xFA,0xFA,0xFC,0xFC,0xFE,0xFF}
    168168
    169 #elif _CODE_PAGE == 775 /* Baltic */
     169#elif FF_CODE_PAGE == 775       /* Baltic */
    170170#define _DF1S   0
    171171#define _EXCVT {0x80,0x9A,0x91,0xA0,0x8E,0x95,0x8F,0x80,0xAD,0xED,0x8A,0x8A,0xA1,0x8D,0x8E,0x8F, \
     
    178178                                0xF0,0xF1,0xF2,0xF3,0xF4,0xF5,0xF6,0xF7,0xF8,0xF9,0xFA,0xFB,0xFC,0xFD,0xFE,0xFF}
    179179
    180 #elif _CODE_PAGE == 850 /* Latin 1 */
     180#elif FF_CODE_PAGE == 850       /* Latin 1 */
    181181#define _DF1S   0
    182182#define _EXCVT {0x43,0x55,0x45,0x41,0x41,0x41,0x41,0x43,0x45,0x45,0x45,0x49,0x49,0x49,0x41,0x41, \
     
    189189                                0xF0,0xF1,0xF2,0xF3,0xF4,0xF5,0xF6,0xF7,0xF8,0xF9,0xFA,0xFB,0xFC,0xFD,0xFE,0xFF}
    190190
    191 #elif _CODE_PAGE == 852 /* Latin 2 */
     191#elif FF_CODE_PAGE == 852       /* Latin 2 */
    192192#define _DF1S   0
    193193#define _EXCVT {0x80,0x9A,0x90,0xB6,0x8E,0xDE,0x8F,0x80,0x9D,0xD3,0x8A,0x8A,0xD7,0x8D,0x8E,0x8F, \
     
    200200                                0xF0,0xF1,0xF2,0xF3,0xF4,0xF5,0xF6,0xF7,0xF8,0xF9,0xFA,0xEB,0xFC,0xFC,0xFE,0xFF}
    201201
    202 #elif _CODE_PAGE == 855 /* Cyrillic */
     202#elif FF_CODE_PAGE == 855       /* Cyrillic */
    203203#define _DF1S   0
    204204#define _EXCVT {0x81,0x81,0x83,0x83,0x85,0x85,0x87,0x87,0x89,0x89,0x8B,0x8B,0x8D,0x8D,0x8F,0x8F, \
     
    211211                                0xF0,0xF2,0xF2,0xF4,0xF4,0xF6,0xF6,0xF8,0xF8,0xFA,0xFA,0xFC,0xFC,0xFD,0xFE,0xFF}
    212212
    213 #elif _CODE_PAGE == 857 /* Turkish */
     213#elif FF_CODE_PAGE == 857       /* Turkish */
    214214#define _DF1S   0
    215215#define _EXCVT {0x80,0x9A,0x90,0xB6,0x8E,0xB7,0x8F,0x80,0xD2,0xD3,0xD4,0xD8,0xD7,0x49,0x8E,0x8F, \
     
    222222                                0xF0,0xF1,0xF2,0xF3,0xF4,0xF5,0xF6,0xF7,0xF8,0xF9,0xFA,0xFB,0xFC,0xFD,0xFE,0xFF}
    223223
    224 #elif _CODE_PAGE == 860 /* Portuguese */
     224#elif FF_CODE_PAGE == 860       /* Portuguese */
    225225#define _DF1S   0
    226226#define _EXCVT {0x80,0x9A,0x90,0x8F,0x8E,0x91,0x86,0x80,0x89,0x89,0x92,0x8B,0x8C,0x98,0x8E,0x8F, \
     
    233233                                0xF0,0xF1,0xF2,0xF3,0xF4,0xF5,0xF6,0xF7,0xF8,0xF9,0xFA,0xFB,0xFC,0xFD,0xFE,0xFF}
    234234
    235 #elif _CODE_PAGE == 861 /* Icelandic */
     235#elif FF_CODE_PAGE == 861       /* Icelandic */
    236236#define _DF1S   0
    237237#define _EXCVT {0x80,0x9A,0x90,0x41,0x8E,0x41,0x8F,0x80,0x45,0x45,0x45,0x8B,0x8B,0x8D,0x8E,0x8F, \
     
    244244                                0xF0,0xF1,0xF2,0xF3,0xF4,0xF5,0xF6,0xF7,0xF8,0xF9,0xFA,0xFB,0xFC,0xFD,0xFE,0xFF}
    245245
    246 #elif _CODE_PAGE == 862 /* Hebrew */
     246#elif FF_CODE_PAGE == 862       /* Hebrew */
    247247#define _DF1S   0
    248248#define _EXCVT {0x80,0x81,0x82,0x83,0x84,0x85,0x86,0x87,0x88,0x89,0x8A,0x8B,0x8C,0x8D,0x8E,0x8F, \
     
    255255                                0xF0,0xF1,0xF2,0xF3,0xF4,0xF5,0xF6,0xF7,0xF8,0xF9,0xFA,0xFB,0xFC,0xFD,0xFE,0xFF}
    256256
    257 #elif _CODE_PAGE == 863 /* Canadian-French */
     257#elif FF_CODE_PAGE == 863       /* Canadian-French */
    258258#define _DF1S   0
    259259#define _EXCVT {0x43,0x55,0x45,0x41,0x41,0x41,0x86,0x43,0x45,0x45,0x45,0x49,0x49,0x8D,0x41,0x8F, \
     
    266266                                0xF0,0xF1,0xF2,0xF3,0xF4,0xF5,0xF6,0xF7,0xF8,0xF9,0xFA,0xFB,0xFC,0xFD,0xFE,0xFF}
    267267
    268 #elif _CODE_PAGE == 864 /* Arabic */
     268#elif FF_CODE_PAGE == 864       /* Arabic */
    269269#define _DF1S   0
    270270#define _EXCVT {0x80,0x9A,0x45,0x41,0x8E,0x41,0x8F,0x80,0x45,0x45,0x45,0x49,0x49,0x49,0x8E,0x8F, \
     
    277277                                0xF0,0xF1,0xF2,0xF3,0xF4,0xF5,0xF6,0xF7,0xF8,0xF9,0xFA,0xFB,0xFC,0xFD,0xFE,0xFF}
    278278
    279 #elif _CODE_PAGE == 865 /* Nordic */
     279#elif FF_CODE_PAGE == 865       /* Nordic */
    280280#define _DF1S   0
    281281#define _EXCVT {0x80,0x9A,0x90,0x41,0x8E,0x41,0x8F,0x80,0x45,0x45,0x45,0x49,0x49,0x49,0x8E,0x8F, \
     
    288288                                0xF0,0xF1,0xF2,0xF3,0xF4,0xF5,0xF6,0xF7,0xF8,0xF9,0xFA,0xFB,0xFC,0xFD,0xFE,0xFF}
    289289
    290 #elif _CODE_PAGE == 866 /* Russian */
     290#elif FF_CODE_PAGE == 866       /* Russian */
    291291#define _DF1S   0
    292292#define _EXCVT {0x80,0x81,0x82,0x83,0x84,0x85,0x86,0x87,0x88,0x89,0x8A,0x8B,0x8C,0x8D,0x8E,0x8F, \
     
    299299                                0xF0,0xF0,0xF2,0xF2,0xF4,0xF4,0xF6,0xF6,0xF8,0xF9,0xFA,0xFB,0xFC,0xFD,0xFE,0xFF}
    300300
    301 #elif _CODE_PAGE == 869 /* Greek 2 */
     301#elif FF_CODE_PAGE == 869       /* Greek 2 */
    302302#define _DF1S   0
    303303#define _EXCVT {0x80,0x81,0x82,0x83,0x84,0x85,0x86,0x87,0x88,0x89,0x8A,0x8B,0x8C,0x8D,0x8E,0x8F, \
     
    310310                                0xF0,0xF1,0xD1,0xD2,0xD3,0xF5,0xD4,0xF7,0xF8,0xF9,0xD5,0x96,0x95,0x98,0xFE,0xFF}
    311311
    312 #elif _CODE_PAGE == 1   /* ASCII (for only non-LFN cfg) */
    313 #if _USE_LFN
     312#elif FF_CODE_PAGE == 1 /* ASCII (for only non-LFN cfg) */
     313#if FF_USE_LFN
    314314#error Cannot use LFN feature without valid code page.
    315315#endif
    316316#define _DF1S   0
    317317
    318 #elif _CODE_PAGE == 65001 /* UTF-8 */
    319 #if _LFN_UNICODE
     318#elif FF_CODE_PAGE == 65001 /* UTF-8 */
     319#if FF_LFN_UNICODE
    320320#error Cannot use LFN_UNICODE feature without valid code page.
    321321#endif
     
    532532*/
    533533
    534 #if _VOLUMES < 1 || _VOLUMES > 9
    535 #error Wrong _VOLUMES setting
    536 #endif
    537 static FATFS *FatFs[_VOLUMES];  /* Pointer to the file system objects (logical drives) */
     534#if FF_VOLUMES < 1 || FF_VOLUMES > 9
     535#error Wrong FF_VOLUMES setting
     536#endif
     537static FATFS *FatFs[FF_VOLUMES];        /* Pointer to the file system objects (logical drives) */
    538538static WORD Fsid;                               /* File system mount ID */
    539539
    540 #if _FS_RPATH && _VOLUMES >= 2
     540#if FF_FS_RPATH && FF_VOLUMES >= 2
    541541static BYTE CurrVol;                    /* Current drive */
    542542#endif
    543543
    544 #if _FS_LOCK
    545 static FILESEM Files[_FS_LOCK]; /* Open object lock semaphores */
    546 #endif
    547 
    548 #if _USE_LFN == 0                       /* Non LFN feature */
     544#if FF_FS_LOCK != 0
     545static FILESEM Files[FF_FS_LOCK];       /* Open object lock semaphores */
     546#endif
     547
     548#if FF_USE_LFN == 0                     /* Non LFN feature */
    549549#define DEFINE_NAMEBUF          BYTE sfn[12]
    550550#define INIT_BUF(dobj)          (dobj).fn = sfn
    551551#define FREE_BUF()
    552552#else
    553 #if _MAX_LFN < 12 || _MAX_LFN > 255
    554 #error Wrong _MAX_LFN setting
    555 #endif
    556 #if _USE_LFN == 1                       /* LFN feature with static working buffer */
    557 static WCHAR LfnBuf[_MAX_LFN + 1];
     553#if FF_MAX_LFN < 12 || FF_MAX_LFN > 255
     554#error Wrong FF_MAX_LFN setting
     555#endif
     556#if FF_USE_LFN == 1                     /* LFN feature with static working buffer */
     557static WCHAR LfnBuf[FF_MAX_LFN + 1];
    558558#define DEFINE_NAMEBUF          BYTE sfn[12]
    559559#define INIT_BUF(dobj)          { (dobj).fn = sfn; (dobj).lfn = LfnBuf; }
    560560#define FREE_BUF()
    561 #elif _USE_LFN == 2             /* LFN feature with dynamic working buffer on the stack */
    562 #define DEFINE_NAMEBUF          BYTE sfn[12]; WCHAR lbuf[_MAX_LFN + 1]
     561#elif FF_USE_LFN == 2           /* LFN feature with dynamic working buffer on the stack */
     562#define DEFINE_NAMEBUF          BYTE sfn[12]; WCHAR lbuf[FF_MAX_LFN + 1]
    563563#define INIT_BUF(dobj)          { (dobj).fn = sfn; (dobj).lfn = lbuf; }
    564564#define FREE_BUF()
    565 #elif _USE_LFN == 3             /* LFN feature with dynamic working buffer on the heap */
     565#elif FF_USE_LFN == 3           /* LFN feature with dynamic working buffer on the heap */
    566566#define DEFINE_NAMEBUF          BYTE sfn[12]; WCHAR *lfn
    567 #define INIT_BUF(dobj)          { lfn = ff_memalloc((_MAX_LFN + 1) * 2); if (!lfn) LEAVE_FF((dobj).fs, FR_NOT_ENOUGH_CORE); (dobj).lfn = lfn; (dobj).fn = sfn; }
     567#define INIT_BUF(dobj)          { lfn = ff_memalloc((FF_MAX_LFN + 1) * 2); if (!lfn) LEAVE_FF((dobj).fs, FR_NOT_ENOUGH_CORE); (dobj).lfn = lfn; (dobj).fn = sfn; }
    568568#define FREE_BUF()                      ff_memfree(lfn)
    569569#else
    570 #error Wrong _USE_LFN setting
     570#error Wrong FF_USE_LFN setting
    571571#endif
    572572#endif
     
    598598        const BYTE *s = (const BYTE*)src;
    599599
    600 #if _WORD_ACCESS == 1
     600#if FF_WORD_ACCESS == 1
    601601        while (cnt >= sizeof (int)) {
    602602                *(int*)d = *(int*)s;
     
    641641/* Request/Release grant to access the volume                            */
    642642/*-----------------------------------------------------------------------*/
    643 #if _FS_REENTRANT
     643#if FF_FS_REENTRANT
    644644static
    645645int lock_fs (
     
    673673/* File lock control functions                                           */
    674674/*-----------------------------------------------------------------------*/
    675 #if _FS_LOCK
     675#if FF_FS_LOCK != 0
    676676
    677677static
    678678FRESULT chk_lock (      /* Check if the file can be accessed */
    679         DIR* dp,                /* Directory object pointing the file to be checked */
     679        FATFS_DIR* dp,          /* Directory object pointing the file to be checked */
    680680        int acc                 /* Desired access type (0:Read, 1:Write, 2:Delete/Rename) */
    681681)
     
    684684
    685685        /* Search file semaphore table */
    686         for (i = be = 0; i < _FS_LOCK; i++) {
     686        for (i = be = 0; i < FF_FS_LOCK; i++) {
    687687                if (Files[i].fs) {      /* Existing entry */
    688688                        if (Files[i].fs == dp->fs &&            /* Check if the object matched with an open object */
     
    693693                }
    694694        }
    695         if (i == _FS_LOCK)      /* The object is not opened */
     695        if (i == FF_FS_LOCK)    /* The object is not opened */
    696696                return (be || acc == 2) ? FR_OK : FR_TOO_MANY_OPEN_FILES;       /* Is there a blank entry for new object? */
    697697
     
    706706        UINT i;
    707707
    708         for (i = 0; i < _FS_LOCK && Files[i].fs; i++) ;
    709         return (i == _FS_LOCK) ? 0 : 1;
     708        for (i = 0; i < FF_FS_LOCK && Files[i].fs; i++) ;
     709        return (i == FF_FS_LOCK) ? 0 : 1;
    710710}
    711711
     
    713713static
    714714UINT inc_lock ( /* Increment object open counter and returns its index (0:Internal error) */
    715         DIR* dp,        /* Directory object pointing the file to register or increment */
     715        FATFS_DIR* dp,  /* Directory object pointing the file to register or increment */
    716716        int acc         /* Desired access (0:Read, 1:Write, 2:Delete/Rename) */
    717717)
     
    720720
    721721
    722         for (i = 0; i < _FS_LOCK; i++) {        /* Find the object */
     722        for (i = 0; i < FF_FS_LOCK; i++) {      /* Find the object */
    723723                if (Files[i].fs == dp->fs &&
    724724                        Files[i].clu == dp->sclust &&
     
    726726        }
    727727
    728         if (i == _FS_LOCK) {                            /* Not opened. Register it as new. */
    729                 for (i = 0; i < _FS_LOCK && Files[i].fs; i++) ;
    730                 if (i == _FS_LOCK) return 0;    /* No free entry to register (int err) */
     728        if (i == FF_FS_LOCK) {                          /* Not opened. Register it as new. */
     729                for (i = 0; i < FF_FS_LOCK && Files[i].fs; i++) ;
     730                if (i == FF_FS_LOCK) return 0;  /* No free entry to register (int err) */
    731731                Files[i].fs = dp->fs;
    732732                Files[i].clu = dp->sclust;
     
    752752
    753753
    754         if (--i < _FS_LOCK) {   /* Shift index number origin from 0 */
     754        if (--i < FF_FS_LOCK) { /* Shift index number origin from 0 */
    755755                n = Files[i].ctr;
    756756                if (n == 0x100) n = 0;          /* If write mode open, delete the entry */
     
    773773        UINT i;
    774774
    775         for (i = 0; i < _FS_LOCK; i++) {
     775        for (i = 0; i < FF_FS_LOCK; i++) {
    776776                if (Files[i].fs == fs) Files[i].fs = 0;
    777777        }
     
    785785/* Move/Flush disk access window in the file system object               */
    786786/*-----------------------------------------------------------------------*/
    787 #if !_FS_READONLY
     787#if !FF_FS_READONLY
    788788static
    789789FRESULT sync_window (   /* FR_OK:succeeded, !=0:error */
     
    825825
    826826        if (sector != fs->winsect) {    /* Window offset changed? */
    827 #if !_FS_READONLY
     827#if !FF_FS_READONLY
    828828                res = sync_window(fs);          /* Write-back changes */
    829829#endif
     
    845845/* Synchronize file system and strage device                             */
    846846/*-----------------------------------------------------------------------*/
    847 #if !_FS_READONLY
     847#if !FF_FS_READONLY
    848848static
    849849FRESULT sync_fs (       /* FR_OK:succeeded, !=0:error */
     
    959959/* Hidden API for hacks and disk tools */
    960960
    961 #if !_FS_READONLY
     961#if !FF_FS_READONLY
    962962FRESULT put_fat (       /* FR_OK(0):succeeded, !=0:error */
    963963        FATFS* fs,              /* File system object */
     
    10141014        return res;
    10151015}
    1016 #endif /* !_FS_READONLY */
     1016#endif /* !FF_FS_READONLY */
    10171017
    10181018
     
    10221022/* FAT handling - Remove a cluster chain                                 */
    10231023/*-----------------------------------------------------------------------*/
    1024 #if !_FS_READONLY
     1024#if !FF_FS_READONLY
    10251025static
    10261026FRESULT remove_chain (  /* FR_OK(0):succeeded, !=0:error */
     
    10311031        FRESULT res;
    10321032        DWORD nxt;
    1033 #if _USE_TRIM
     1033#if FF_USE_TRIM
    10341034        DWORD scl = clst, ecl = clst, rt[2];
    10351035#endif
     
    10511051                                fs->fsi_flag |= 1;
    10521052                        }
    1053 #if _USE_TRIM
     1053#if FF_USE_TRIM
    10541054                        if (ecl + 1 == nxt) {   /* Is next cluster contiguous? */
    10551055                                ecl = nxt;
     
    10751075/* FAT handling - Stretch or Create a cluster chain                      */
    10761076/*-----------------------------------------------------------------------*/
    1077 #if !_FS_READONLY
     1077#if !FF_FS_READONLY
    10781078static
    10791079DWORD create_chain (    /* 0:No free cluster, 1:Internal error, 0xFFFFFFFF:Disk error, >=2:New cluster# */
     
    11281128        return ncl;             /* Return new cluster number or error code */
    11291129}
    1130 #endif /* !_FS_READONLY */
     1130#endif /* !FF_FS_READONLY */
    11311131
    11321132
     
    11371137/*-----------------------------------------------------------------------*/
    11381138
    1139 #if _USE_FASTSEEK
     1139#if FF_USE_FASTSEEK
    11401140static
    11411141DWORD clmt_clust (      /* <2:Error, >=2:Cluster number */
     
    11571157        return cl + *tbl;       /* Return the cluster number */
    11581158}
    1159 #endif  /* _USE_FASTSEEK */
     1159#endif  /* FF_USE_FASTSEEK */
    11601160
    11611161
     
    11681168static
    11691169FRESULT dir_sdi (       /* FR_OK(0):succeeded, !=0:error */
    1170         DIR* dp,                /* Pointer to directory object */
     1170        FATFS_DIR* dp,          /* Pointer to directory object */
    11711171        UINT idx                /* Index of directory table */
    11721172)
     
    12161216static
    12171217FRESULT dir_next (      /* FR_OK(0):succeeded, FR_NO_FILE:End of table, FR_DENIED:Could not stretch */
    1218         DIR* dp,                /* Pointer to the directory object */
     1218        FATFS_DIR* dp,          /* Pointer to the directory object */
    12191219        int stretch             /* 0: Do not stretch table, 1: Stretch table if needed */
    12201220)
     
    12221222        DWORD clst;
    12231223        UINT i;
    1224 #if !_FS_READONLY
     1224#if !FF_FS_READONLY
    12251225        UINT c;
    12261226#endif
     
    12441244                                if (clst == 0xFFFFFFFF) return FR_DISK_ERR;
    12451245                                if (clst >= dp->fs->n_fatent) {                                 /* If it reached end of dynamic table, */
    1246 #if !_FS_READONLY
     1246#if !FF_FS_READONLY
    12471247                                        if (!stretch) return FR_NO_FILE;                        /* If do not stretch, report EOT */
    12481248                                        clst = create_chain(dp->fs, dp->clust);         /* Stretch cluster chain */
     
    12841284/*-----------------------------------------------------------------------*/
    12851285
    1286 #if !_FS_READONLY
     1286#if !FF_FS_READONLY
    12871287static
    12881288FRESULT dir_alloc (     /* FR_OK(0):succeeded, !=0:error */
    1289         DIR* dp,                /* Pointer to the directory object */
     1289        FATFS_DIR* dp,          /* Pointer to the directory object */
    12901290        UINT nent               /* Number of contiguous entries to allocate (1-21) */
    12911291)
     
    13371337
    13381338
    1339 #if !_FS_READONLY
     1339#if !FF_FS_READONLY
    13401340static
    13411341void st_clust (
     
    13551355/* LFN handling - Test/Pick/Fit an LFN segment from/to directory entry   */
    13561356/*-----------------------------------------------------------------------*/
    1357 #if _USE_LFN
     1357#if FF_USE_LFN
    13581358static
    13591359const BYTE LfnOfs[] = {1,3,5,7,9,14,16,18,20,22,24,28,30};      /* Offset of LFN characters in the directory entry */
     
    13771377                uc = LD_WORD(dir + LfnOfs[s]);          /* Pick an LFN character */
    13781378                if (wc) {
    1379                         if (i >= _MAX_LFN || ff_wtoupper(uc) != ff_wtoupper(lfnbuf[i++]))       /* Compare it */
     1379                        if (i >= FF_MAX_LFN || ff_wtoupper(uc) != ff_wtoupper(lfnbuf[i++]))     /* Compare it */
    13801380                                return 0;                                       /* Not matched */
    13811381                        wc = uc;
     
    14101410                uc = LD_WORD(dir + LfnOfs[s]);          /* Pick an LFN character */
    14111411                if (wc) {
    1412                         if (i >= _MAX_LFN) return 0;    /* Buffer overflow? */
     1412                        if (i >= FF_MAX_LFN) return 0;  /* Buffer overflow? */
    14131413                        lfnbuf[i++] = wc = uc;                  /* Store it */
    14141414                } else {
     
    14181418
    14191419        if (dir[LDIR_Ord] & LLEF) {                             /* Put terminator if it is the last LFN part */
    1420                 if (i >= _MAX_LFN) return 0;            /* Buffer overflow? */
     1420                if (i >= FF_MAX_LFN) return 0;          /* Buffer overflow? */
    14211421                lfnbuf[i] = 0;
    14221422        }
     
    14261426
    14271427
    1428 #if !_FS_READONLY
     1428#if !FF_FS_READONLY
    14291429static
    14301430void fit_lfn (
     
    14641464/* Create numbered name                                                  */
    14651465/*-----------------------------------------------------------------------*/
    1466 #if _USE_LFN
     1466#if FF_USE_LFN
    14671467static
    14681468void gen_numname (
     
    15231523/* Calculate checksum of an SFN entry                                    */
    15241524/*-----------------------------------------------------------------------*/
    1525 #if _USE_LFN
     1525#if FF_USE_LFN
    15261526static
    15271527BYTE sum_sfn (
     
    15461546static
    15471547FRESULT dir_find (      /* FR_OK(0):succeeded, !=0:error */
    1548         DIR* dp                 /* Pointer to the directory object linked to the file name */
     1548        FATFS_DIR* dp                   /* Pointer to the directory object linked to the file name */
    15491549)
    15501550{
    15511551        FRESULT res;
    15521552        BYTE c, *dir;
    1553 #if _USE_LFN
     1553#if FF_USE_LFN
    15541554        BYTE a, ord, sum;
    15551555#endif
     
    15581558        if (res != FR_OK) return res;
    15591559
    1560 #if _USE_LFN
     1560#if FF_USE_LFN
    15611561        ord = sum = 0xFF; dp->lfn_idx = 0xFFFF; /* Reset LFN sequence */
    15621562#endif
     
    15671567                c = dir[DIR_Name];
    15681568                if (c == 0) { res = FR_NO_FILE; break; }        /* Reached to end of table */
    1569 #if _USE_LFN    /* LFN configuration */
     1569#if FF_USE_LFN  /* LFN configuration */
    15701570                a = dir[DIR_Attr] & AM_MASK;
    15711571                if (c == DDEM || ((a & AM_VOL) && a != AM_LFN)) {       /* An entry without valid data */
     
    16041604/* Read an object from the directory                                     */
    16051605/*-----------------------------------------------------------------------*/
    1606 #if _FS_MINIMIZE <= 1 || _USE_LABEL || _FS_RPATH >= 2
     1606#if FF_FS_MINIMIZE <= 1 || FF_USE_LABEL || FF_FS_RPATH >= 2
    16071607static
    16081608FRESULT dir_read (
    1609         DIR* dp,                /* Pointer to the directory object */
     1609        FATFS_DIR* dp,          /* Pointer to the directory object */
    16101610        int vol                 /* Filtered by 0:file/directory or 1:volume label */
    16111611)
     
    16131613        FRESULT res;
    16141614        BYTE a, c, *dir;
    1615 #if _USE_LFN
     1615#if FF_USE_LFN
    16161616        BYTE ord = 0xFF, sum = 0xFF;
    16171617#endif
     
    16251625                if (c == 0) { res = FR_NO_FILE; break; }        /* Reached to end of table */
    16261626                a = dir[DIR_Attr] & AM_MASK;
    1627 #if _USE_LFN    /* LFN configuration */
    1628                 if (c == DDEM || (!_FS_RPATH && c == '.') || (int)((a & ~AM_ARC) == AM_VOL) != vol) {   /* An entry without valid data */
     1627#if FF_USE_LFN  /* LFN configuration */
     1628                if (c == DDEM || (!FF_FS_RPATH && c == '.') || (int)((a & ~AM_ARC) == AM_VOL) != vol) { /* An entry without valid data */
    16291629                        ord = 0xFF;
    16301630                } else {
     
    16441644                }
    16451645#else           /* Non LFN configuration */
    1646                 if (c != DDEM && (_FS_RPATH || c != '.') && a != AM_LFN && (int)((a & ~AM_ARC) == AM_VOL) == vol)       /* Is it a valid entry? */
     1646                if (c != DDEM && (FF_FS_RPATH || c != '.') && a != AM_LFN && (int)((a & ~AM_ARC) == AM_VOL) == vol)     /* Is it a valid entry? */
    16471647                        break;
    16481648#endif
     
    16551655        return res;
    16561656}
    1657 #endif  /* _FS_MINIMIZE <= 1 || _USE_LABEL || _FS_RPATH >= 2 */
     1657#endif  /* FF_FS_MINIMIZE <= 1 || FF_USE_LABEL || FF_FS_RPATH >= 2 */
    16581658
    16591659
     
    16631663/* Register an object to the directory                                   */
    16641664/*-----------------------------------------------------------------------*/
    1665 #if !_FS_READONLY
     1665#if !FF_FS_READONLY
    16661666static
    16671667FRESULT dir_register (  /* FR_OK:succeeded, FR_DENIED:no free entry or too many SFN collision, FR_DISK_ERR:disk error */
    1668         DIR* dp                         /* Target directory with object name to be created */
     1668        FATFS_DIR* dp                           /* Target directory with object name to be created */
    16691669)
    16701670{
    16711671        FRESULT res;
    1672 #if _USE_LFN    /* LFN configuration */
     1672#if FF_USE_LFN  /* LFN configuration */
    16731673        UINT n, nent;
    16741674        BYTE sn[12], *fn, sum;
     
    16791679        mem_cpy(sn, fn, 12);
    16801680
    1681         if (_FS_RPATH && (sn[NSFLAG] & NS_DOT))         /* Cannot create dot entry */
     1681        if (FF_FS_RPATH && (sn[NSFLAG] & NS_DOT))               /* Cannot create dot entry */
    16821682                return FR_INVALID_NAME;
    16831683
     
    17241724                        mem_set(dp->dir, 0, SZ_DIRE);   /* Clean the entry */
    17251725                        mem_cpy(dp->dir, dp->fn, 11);   /* Put SFN */
    1726 #if _USE_LFN
     1726#if FF_USE_LFN
    17271727                        dp->dir[DIR_NTres] = dp->fn[NSFLAG] & (NS_BODY | NS_EXT);       /* Put NT flag */
    17281728#endif
     
    17331733        return res;
    17341734}
    1735 #endif /* !_FS_READONLY */
     1735#endif /* !FF_FS_READONLY */
    17361736
    17371737
     
    17411741/* Remove an object from the directory                                   */
    17421742/*-----------------------------------------------------------------------*/
    1743 #if !_FS_READONLY && !_FS_MINIMIZE
     1743#if !FF_FS_READONLY && !FF_FS_MINIMIZE
    17441744static
    17451745FRESULT dir_remove (    /* FR_OK:Succeeded, FR_DISK_ERR:A disk error */
    1746         DIR* dp                         /* Directory object pointing the entry to be removed */
     1746        FATFS_DIR* dp                           /* Directory object pointing the entry to be removed */
    17471747)
    17481748{
    17491749        FRESULT res;
    1750 #if _USE_LFN    /* LFN configuration */
     1750#if FF_USE_LFN  /* LFN configuration */
    17511751        UINT i;
    17521752
     
    17801780        return res;
    17811781}
    1782 #endif /* !_FS_READONLY */
     1782#endif /* !FF_FS_READONLY */
    17831783
    17841784
     
    17881788/* Get file information from directory entry                             */
    17891789/*-----------------------------------------------------------------------*/
    1790 #if _FS_MINIMIZE <= 1 || _FS_RPATH >= 2
     1790#if FF_FS_MINIMIZE <= 1 || FF_FS_RPATH >= 2
    17911791static
    17921792void get_fileinfo (             /* No return code */
    1793         DIR* dp,                        /* Pointer to the directory object */
     1793        FATFS_DIR* dp,                  /* Pointer to the directory object */
    17941794        FILINFO* fno            /* Pointer to the file information to be filled */
    17951795)
     
    17981798        TCHAR *p, c;
    17991799        BYTE *dir;
    1800 #if _USE_LFN
     1800#if FF_USE_LFN
    18011801        WCHAR w, *lfn;
    18021802#endif
    1803 #if _CODE_PAGE == 65001
     1803#if FF_CODE_PAGE == 65001
    18041804        unsigned char utf8_code[6];
    18051805        int code_size;
     
    18151815                        if (c == RDDEM) c = (TCHAR)DDEM;        /* Restore replaced DDEM character */
    18161816                        if (i == 9) *p++ = '.';                         /* Insert a . if extension is exist */
    1817 #if _USE_LFN
     1817#if FF_USE_LFN
    18181818                        if (IsUpper(c) && (dir[DIR_NTres] & (i >= 9 ? NS_EXT : NS_BODY)))
    18191819                                c += 0x20;                      /* To lower */
    1820 #if _LFN_UNICODE
     1820#if FF_LFN_UNICODE
    18211821                        if (IsDBCS1(c) && i != 8 && i != 11 && IsDBCS2(dir[i]))
    18221822                                c = c << 8 | dir[i++];
     
    18341834        *p = 0;         /* Terminate SFN string by a \0 */
    18351835
    1836 #if _USE_LFN
     1836#if FF_USE_LFN
    18371837        if (fno->lfname) {
    18381838                i = 0; p = fno->lfname;
     
    18401840                        lfn = dp->lfn;
    18411841                        while ((w = *lfn++) != 0) {             /* Get an LFN character */
    1842 #if !_LFN_UNICODE
    1843 #if _CODE_PAGE == 65001
     1842#if !FF_LFN_UNICODE
     1843#if FF_CODE_PAGE == 65001
    18441844                                Utf16_to_Utf8(utf8_code, &code_size, w);
    18451845                                for (int j = 0; j < code_size - 1; j++) {
     
    18621862#endif
    18631863}
    1864 #endif /* _FS_MINIMIZE <= 1 || _FS_RPATH >= 2 */
     1864#endif /* FF_FS_MINIMIZE <= 1 || FF_FS_RPATH >= 2 */
    18651865
    18661866
     
    18701870/* Pattern matching                                                      */
    18711871/*-----------------------------------------------------------------------*/
    1872 #if _USE_FIND && _FS_MINIMIZE <= 1
     1872#if FF_USE_FIND && FF_FS_MINIMIZE <= 1
    18731873static
    18741874WCHAR get_achar (               /* Get a character and advances ptr 1 or 2 */
     
    18781878        WCHAR chr;
    18791879
    1880 #if !_LFN_UNICODE
    1881 #if _CODE_PAGE == 65001
     1880#if !FF_LFN_UNICODE
     1881#if FF_CODE_PAGE == 65001
    18821882        int code_size;
    18831883        chr = Utf8_to_Utf16(*ptr, &code_size);
     
    19381938        return 0;
    19391939}
    1940 #endif /* _USE_FIND && _FS_MINIMIZE <= 1 */
     1940#endif /* FF_USE_FIND && FF_FS_MINIMIZE <= 1 */
    19411941
    19421942
     
    19491949static
    19501950FRESULT create_name (   /* FR_OK: successful, FR_INVALID_NAME: could not create */
    1951         DIR* dp,                        /* Pointer to the directory object */
     1951        FATFS_DIR* dp,                  /* Pointer to the directory object */
    19521952        const TCHAR** path      /* Pointer to pointer to the segment in the path string */
    19531953)
    19541954{
    1955 #if _USE_LFN    /* LFN configuration */
     1955#if FF_USE_LFN  /* LFN configuration */
    19561956        BYTE b, cf;
    19571957        WCHAR w, *lfn;
    19581958        UINT i, ni, si, di;
    19591959        const TCHAR *p;
    1960 #if _CODE_PAGE == 65001
     1960#if FF_CODE_PAGE == 65001
    19611961        unsigned char utf8_code[6];
    19621962        int code_size;
     
    19691969                w = p[si++];                                    /* Get a character */
    19701970                if (w < ' ' || w == '/' || w == '\\') break;    /* Break on end of segment */
    1971                 if (di >= _MAX_LFN)                             /* Reject too long name */
     1971                if (di >= FF_MAX_LFN)                           /* Reject too long name */
    19721972                        return FR_INVALID_NAME;
    1973 #if !_LFN_UNICODE
    1974 #if _CODE_PAGE == 65001
     1973#if !FF_LFN_UNICODE
     1974#if FF_CODE_PAGE == 65001
    19751975                w = Utf8_to_Utf16(&p[si - 1], &code_size);
    19761976                si += code_size - 1;
     
    19931993        *path = &p[si];                                         /* Return pointer to the next segment */
    19941994        cf = (w < ' ') ? NS_LAST : 0;           /* Set last segment flag if end of path */
    1995 #if _FS_RPATH
     1995#if FF_FS_RPATH
    19961996        if ((di == 1 && lfn[di - 1] == '.') ||
    19971997                (di == 2 && lfn[di - 1] == '.' && lfn[di - 2] == '.')) {        /* Is this segment a dot entry? */
     
    20402040                        if (w) w = ExCvt[w - 0x80];     /* Convert extended character to upper (SBCS) */
    20412041#else
    2042 #if _CODE_PAGE == 65001
     2042#if FF_CODE_PAGE == 65001
    20432043                        Utf16_to_Utf8(utf8_code, &code_size, ff_wtoupper(w));
    20442044#else
     
    20482048                        cf |= NS_LFN;                           /* Force create LFN entry */
    20492049                }
    2050 #if _CODE_PAGE == 65001
     2050#if FF_CODE_PAGE == 65001
    20512051                else
    20522052                        code_size = 1;
    20532053#endif
    20542054
    2055 #if _CODE_PAGE == 65001
     2055#if FF_CODE_PAGE == 65001
    20562056                if (code_size > 1) {            /* Is this DBC? (always false at SBCS cfg) */
    20572057                        if (i >= ni - 1) {
     
    21262126        mem_set(sfn, ' ', 11);
    21272127        si = i = b = 0; ni = 8;
    2128 #if _FS_RPATH
     2128#if FF_FS_RPATH
    21292129        if (p[si] == '.') { /* Is this a dot entry? */
    21302130                for (;;) {
     
    22012201static
    22022202FRESULT follow_path (   /* FR_OK(0): successful, !=0: error code */
    2203         DIR* dp,                        /* Directory object to return last directory and found object */
     2203        FATFS_DIR* dp,                  /* Directory object to return last directory and found object */
    22042204        const TCHAR* path       /* Full-path string to find a file or directory */
    22052205)
     
    22092209
    22102210
    2211 #if _FS_RPATH
     2211#if FF_FS_RPATH
    22122212        if (*path == '/' || *path == '\\') {    /* There is a heading separator */
    22132213                path++; dp->sclust = 0;                         /* Strip it and start from the root directory */
     
    22322232                        if (res != FR_OK) {                             /* Failed to find the object */
    22332233                                if (res == FR_NO_FILE) {        /* Object is not found */
    2234                                         if (_FS_RPATH && (ns & NS_DOT)) {       /* If dot entry is not exist, */
     2234                                        if (FF_FS_RPATH && (ns & NS_DOT)) {     /* If dot entry is not exist, */
    22352235                                                dp->sclust = 0; dp->dir = 0;    /* it is the root directory and stay there */
    22362236                                                if (!(ns & NS_LAST)) continue;  /* Continue to follow if not last segment */
     
    22692269        UINT i;
    22702270        int vol = -1;
    2271 #if _STR_VOLUME_ID              /* Find string drive id */
    2272         static const char* const str[] = {_VOLUME_STRS};
     2271#if FF_STR_VOLUME_ID            /* Find string drive id */
     2272        static const char* const str[] = {FF_VOLUME_STRS};
    22732273        const char *sp;
    22742274        char c;
     
    22782278
    22792279        if (*path) {    /* If the pointer is not a null */
    2280                 for (tt = *path; (UINT)*tt >= (_USE_LFN ? ' ' : '!') && *tt != ':'; tt++) ;     /* Find ':' in the path */
     2280                for (tt = *path; (UINT)*tt >= (FF_USE_LFN ? ' ' : '!') && *tt != ':'; tt++) ;   /* Find ':' in the path */
    22812281                if (*tt == ':') {       /* If a ':' is exist in the path name */
    22822282                        tp = *path;
    22832283                        i = *tp++ - '0';
    22842284                        if (i < 10 && tp == tt) {       /* Is there a numeric drive id? */
    2285                                 if (i < _VOLUMES) {     /* If a drive id is found, get the value and strip it */
     2285                                if (i < FF_VOLUMES) {   /* If a drive id is found, get the value and strip it */
    22862286                                        vol = (int)i;
    22872287                                        *path = ++tt;
    22882288                                }
    22892289                        }
    2290 #if _STR_VOLUME_ID
     2290#if FF_STR_VOLUME_ID
    22912291                         else { /* No numeric drive number, find string drive id */
    22922292                                i = 0; tt++;
     
    22972297                                                if (IsLower(tc)) tc -= 0x20;
    22982298                                        } while (c && (TCHAR)c == tc);
    2299                                 } while ((c || tp != tt) && ++i < _VOLUMES);    /* Repeat for each id until pattern match */
    2300                                 if (i < _VOLUMES) {     /* If a drive id is found, get the value and strip it */
     2299                                } while ((c || tp != tt) && ++i < FF_VOLUMES);  /* Repeat for each id until pattern match */
     2300                                if (i < FF_VOLUMES) {   /* If a drive id is found, get the value and strip it */
    23012301                                        vol = (int)i;
    23022302                                        *path = tt;
     
    23062306                        return vol;
    23072307                }
    2308 #if _FS_RPATH && _VOLUMES >= 2
     2308#if FF_FS_RPATH && FF_VOLUMES >= 2
    23092309                vol = CurrVol;  /* Current drive */
    23102310#else
     
    23812381                stat = disk_status(fs->drv);
    23822382                if (!(stat & STA_NOINIT)) {             /* and the physical drive is kept initialized */
    2383                         if (!_FS_READONLY && wmode && (stat & STA_PROTECT))     /* Check write protection if needed */
     2383                        if (!FF_FS_READONLY && wmode && (stat & STA_PROTECT))   /* Check write protection if needed */
    23842384                                return FR_WRITE_PROTECTED;
    23852385                        return FR_OK;                           /* The file system object is valid */
     
    23952395        if (stat & STA_NOINIT)                          /* Check if the initialization succeeded */
    23962396                return FR_NOT_READY;                    /* Failed to initialize due to no medium or hard error */
    2397         if (!_FS_READONLY && wmode && (stat & STA_PROTECT))     /* Check disk write protection if needed */
     2397        if (!FF_FS_READONLY && wmode && (stat & STA_PROTECT))   /* Check disk write protection if needed */
    23982398                return FR_WRITE_PROTECTED;
    2399 #if _MAX_SS != _MIN_SS                                          /* Get sector size (multiple sector size cfg only) */
     2399#if FF_MAX_SS != FF_MIN_SS                                              /* Get sector size (multiple sector size cfg only) */
    24002400        if (disk_ioctl(fs->drv, GET_SECTOR_SIZE, &SS(fs)) != RES_OK
    2401                 || SS(fs) < _MIN_SS || SS(fs) > _MAX_SS) return FR_DISK_ERR;
     2401                || SS(fs) < FF_MIN_SS || SS(fs) > FF_MAX_SS) return FR_DISK_ERR;
    24022402#endif
    24032403        /* Find an FAT partition on the drive. Supports only generic partitioning, FDISK and SFD. */
     
    24482448
    24492449        /* Determine the FAT sub type */
    2450         sysect = nrsv + fasize + fs->n_rootdir / (SS(fs) / SZ_DIRE);    /* RSV + FAT + DIR */
     2450        sysect = nrsv + fasize + fs->n_rootdir / (SS(fs) / SZ_DIRE);    /* RSV + FAT + FATFS_DIR */
    24512451        if (tsect < sysect) return FR_NO_FILESYSTEM;            /* (Invalid volume size) */
    24522452        nclst = (tsect - sysect) / fs->csize;                           /* Number of clusters */
     
    24742474                return FR_NO_FILESYSTEM;
    24752475
    2476 #if !_FS_READONLY
     2476#if !FF_FS_READONLY
    24772477        /* Initialize cluster allocation information */
    24782478        fs->last_clust = fs->free_clust = 0xFFFFFFFF;
     
    24802480        /* Get fsinfo if available */
    24812481        fs->fsi_flag = 0x80;
    2482 #if (_FS_NOFSINFO & 3) != 3
     2482#if (FF_FS_NOFSINFO & 3) != 3
    24832483        if (fmt == FS_FAT32                             /* Enable FSINFO only if FAT32 and BPB_FSInfo == 1 */
    24842484                && LD_WORD(fs->win + BPB_FSInfo) == 1
     
    24902490                        && LD_DWORD(fs->win + FSI_StrucSig) == 0x61417272)
    24912491                {
    2492 #if (_FS_NOFSINFO & 1) == 0
     2492#if (FF_FS_NOFSINFO & 1) == 0
    24932493                        fs->free_clust = LD_DWORD(fs->win + FSI_Free_Count);
    24942494#endif
    2495 #if (_FS_NOFSINFO & 2) == 0
     2495#if (FF_FS_NOFSINFO & 2) == 0
    24962496                        fs->last_clust = LD_DWORD(fs->win + FSI_Nxt_Free);
    24972497#endif
     
    25022502        fs->fs_type = fmt;      /* FAT sub-type */
    25032503        fs->id = ++Fsid;        /* File system mount ID */
    2504 #if _FS_RPATH
     2504#if FF_FS_RPATH
    25052505        fs->cdir = 0;           /* Set current directory to root */
    25062506#endif
    2507 #if _FS_LOCK                    /* Clear file lock semaphores */
     2507#if FF_FS_LOCK != 0                     /* Clear file lock semaphores */
    25082508        clear_lock(fs);
    25092509#endif
     
    25212521static
    25222522FRESULT validate (      /* FR_OK(0): The object is valid, !=0: Invalid */
    2523         void* obj               /* Pointer to the object FIL/DIR to check validity */
    2524 )
    2525 {
    2526         FIL *fil = (FIL*)obj;   /* Assuming offset of .fs and .id in the FIL/DIR structure is identical */
     2523        void* obj               /* Pointer to the object FIL/FATFS_DIR to check validity */
     2524)
     2525{
     2526        FIL *fil = (FIL*)obj;   /* Assuming offset of .fs and .id in the FIL/FATFS_DIR structure is identical */
    25272527
    25282528
     
    25672567
    25682568        if (cfs) {
    2569 #if _FS_LOCK
     2569#if FF_FS_LOCK != 0
    25702570                clear_lock(cfs);
    25712571#endif
    2572 #if _FS_REENTRANT                                               /* Discard sync object of the current volume */
     2572#if FF_FS_REENTRANT                                             /* Discard sync object of the current volume */
    25732573                if (!ff_del_syncobj(cfs->sobj)) return FR_INT_ERR;
    25742574#endif
     
    25782578        if (fs) {
    25792579                fs->fs_type = 0;                                /* Clear new fs object */
    2580 #if _FS_REENTRANT                                               /* Create sync object for the new volume */
     2580#if FF_FS_REENTRANT                                             /* Create sync object for the new volume */
    25812581                if (!ff_cre_syncobj((BYTE)vol, &fs->sobj)) return FR_INT_ERR;
    25822582#endif
     
    26042604{
    26052605        FRESULT res;
    2606         DIR dj;
     2606        FATFS_DIR dj;
    26072607        BYTE *dir;
    26082608        DEFINE_NAMEBUF;
    2609 #if !_FS_READONLY
     2609#if !FF_FS_READONLY
    26102610        DWORD dw, cl;
    26112611#endif
     
    26162616
    26172617        /* Get logical drive number */
    2618 #if !_FS_READONLY
    2619         mode &= FA_READ | FA_WRITE | FA_CREATE_ALWAYS | FA_OPEN_ALWAYS | FA_CREATE_NEW;
     2618#if !FF_FS_READONLY
     2619        mode &= FA_READ | FA_WRITE | FA_CREATE_ALWAYS | FA_OPEN_ALWAYS | FA_CREATE_NEW | FA_OPEN_APPEND;
    26202620        res = find_volume(&dj.fs, &path, (BYTE)(mode & ~FA_READ));
    26212621#else
     
    26272627                res = follow_path(&dj, path);   /* Follow the file path */
    26282628                dir = dj.dir;
    2629 #if !_FS_READONLY       /* R/W configuration */
     2629#if !FF_FS_READONLY     /* R/W configuration */
    26302630                if (res == FR_OK) {
    26312631                        if (!dir)       /* Default directory itself */
    26322632                                res = FR_INVALID_NAME;
    2633 #if _FS_LOCK
     2633#if FF_FS_LOCK != 0
    26342634                        else
    26352635                                res = chk_lock(&dj, (mode & ~FA_READ) ? 1 : 0);
     
    26402640                        if (res != FR_OK) {                                     /* No file, create new */
    26412641                                if (res == FR_NO_FILE)                  /* There is no file to open, create a new entry */
    2642 #if _FS_LOCK
     2642#if FF_FS_LOCK != 0
    26432643                                        res = enq_lock() ? dir_register(&dj) : FR_TOO_MANY_OPEN_FILES;
    26442644#else
     
    26492649                        }
    26502650                        else {                                                          /* Any object is already existing */
    2651                                 if (dir[DIR_Attr] & (AM_RDO | AM_DIR)) {        /* Cannot overwrite it (R/O or DIR) */
     2651                                if (dir[DIR_Attr] & (AM_RDO | AM_DIR)) {        /* Cannot overwrite it (R/O or FATFS_DIR) */
    26522652                                        res = FR_DENIED;
    26532653                                } else {
     
    26872687                if (res == FR_OK) {
    26882688                        if (mode & FA_CREATE_ALWAYS)            /* Set file change flag if created or overwritten */
    2689                                 mode |= FA__WRITTEN;
     2689                                mode |= FA_MODIFIED;
    26902690                        fp->dir_sect = dj.fs->winsect;          /* Pointer to the directory entry */
    26912691                        fp->dir_ptr = dir;
    2692 #if _FS_LOCK
     2692#if FF_FS_LOCK != 0
    26932693                        fp->lockid = inc_lock(&dj, (mode & ~FA_READ) ? 1 : 0);
    26942694                        if (!fp->lockid) res = FR_INT_ERR;
     
    27162716                        fp->fptr = 0;                                           /* File pointer */
    27172717                        fp->dsect = 0;
    2718 #if _USE_FASTSEEK
     2718#if FF_USE_FASTSEEK
    27192719                        fp->cltbl = 0;                                          /* Normal seek mode */
    27202720#endif
     
    27662766                                        clst = fp->sclust;                      /* Follow from the origin */
    27672767                                } else {                                                /* Middle or end of the file */
    2768 #if _USE_FASTSEEK
     2768#if FF_USE_FASTSEEK
    27692769                                        if (fp->cltbl)
    27702770                                                clst = clmt_clust(fp, fp->fptr);        /* Get cluster# from the CLMT */
     
    27862786                                if (disk_read(fp->fs->drv, rbuff, sect, cc) != RES_OK)
    27872787                                        ABORT(fp->fs, FR_DISK_ERR);
    2788 #if !_FS_READONLY && _FS_MINIMIZE <= 2                  /* Replace one of the read sectors with cached data if it contains a dirty sector */
    2789 #if _FS_TINY
     2788#if !FF_FS_READONLY && FF_FS_MINIMIZE <= 2                      /* Replace one of the read sectors with cached data if it contains a dirty sector */
     2789#if FF_FS_TINY
    27902790                                if (fp->fs->wflag && fp->fs->winsect - sect < cc)
    27912791                                        mem_cpy(rbuff + ((fp->fs->winsect - sect) * SS(fp->fs)), fp->fs->win, SS(fp->fs));
    27922792#else
    2793                                 if ((fp->flag & FA__DIRTY) && fp->dsect - sect < cc)
     2793                                if ((fp->flag & FA_DIRTY) && fp->dsect - sect < cc)
    27942794                                        mem_cpy(rbuff + ((fp->dsect - sect) * SS(fp->fs)), fp->buf, SS(fp->fs));
    27952795#endif
     
    27982798                                continue;
    27992799                        }
    2800 #if !_FS_TINY
     2800#if !FF_FS_TINY
    28012801                        if (fp->dsect != sect) {                        /* Load data sector if not in cache */
    2802 #if !_FS_READONLY
    2803                                 if (fp->flag & FA__DIRTY) {             /* Write-back dirty sector cache */
     2802#if !FF_FS_READONLY
     2803                                if (fp->flag & FA_DIRTY) {              /* Write-back dirty sector cache */
    28042804                                        if (disk_write(fp->fs->drv, fp->buf, fp->dsect, 1) != RES_OK)
    28052805                                                ABORT(fp->fs, FR_DISK_ERR);
    2806                                         fp->flag &= ~FA__DIRTY;
     2806                                        fp->flag &= ~FA_DIRTY;
    28072807                                }
    28082808#endif
     
    28152815                rcnt = SS(fp->fs) - ((UINT)fp->fptr % SS(fp->fs));      /* Get partial sector data from sector buffer */
    28162816                if (rcnt > btr) rcnt = btr;
    2817 #if _FS_TINY
     2817#if FF_FS_TINY
    28182818                if (move_window(fp->fs, fp->dsect) != FR_OK)            /* Move sector window */
    28192819                        ABORT(fp->fs, FR_DISK_ERR);
     
    28302830
    28312831
    2832 #if !_FS_READONLY
     2832#if !FF_FS_READONLY
    28332833/*-----------------------------------------------------------------------*/
    28342834/* Write File                                                            */
     
    28692869                                                clst = create_chain(fp->fs, 0); /* Create a new cluster chain */
    28702870                                } else {                                        /* Middle or end of the file */
    2871 #if _USE_FASTSEEK
     2871#if FF_USE_FASTSEEK
    28722872                                        if (fp->cltbl)
    28732873                                                clst = clmt_clust(fp, fp->fptr);        /* Get cluster# from the CLMT */
     
    28822882                                if (fp->sclust == 0) fp->sclust = clst; /* Set start cluster if the first write */
    28832883                        }
    2884 #if _FS_TINY
     2884#if FF_FS_TINY
    28852885                        if (fp->fs->winsect == fp->dsect && sync_window(fp->fs))        /* Write-back sector cache */
    28862886                                ABORT(fp->fs, FR_DISK_ERR);
    28872887#else
    2888                         if (fp->flag & FA__DIRTY) {             /* Write-back sector cache */
     2888                        if (fp->flag & FA_DIRTY) {              /* Write-back sector cache */
    28892889                                if (disk_write(fp->fs->drv, fp->buf, fp->dsect, 1) != RES_OK)
    28902890                                        ABORT(fp->fs, FR_DISK_ERR);
    2891                                 fp->flag &= ~FA__DIRTY;
     2891                                fp->flag &= ~FA_DIRTY;
    28922892                        }
    28932893#endif
     
    29012901                                if (disk_write(fp->fs->drv, wbuff, sect, cc) != RES_OK)
    29022902                                        ABORT(fp->fs, FR_DISK_ERR);
    2903 #if _FS_MINIMIZE <= 2
    2904 #if _FS_TINY
     2903#if FF_FS_MINIMIZE <= 2
     2904#if FF_FS_TINY
    29052905                                if (fp->fs->winsect - sect < cc) {      /* Refill sector cache if it gets invalidated by the direct write */
    29062906                                        mem_cpy(fp->fs->win, wbuff + ((fp->fs->winsect - sect) * SS(fp->fs)), SS(fp->fs));
     
    29102910                                if (fp->dsect - sect < cc) { /* Refill sector cache if it gets invalidated by the direct write */
    29112911                                        mem_cpy(fp->buf, wbuff + ((fp->dsect - sect) * SS(fp->fs)), SS(fp->fs));
    2912                                         fp->flag &= ~FA__DIRTY;
     2912                                        fp->flag &= ~FA_DIRTY;
    29132913                                }
    29142914#endif
     
    29172917                                continue;
    29182918                        }
    2919 #if _FS_TINY
     2919#if FF_FS_TINY
    29202920                        if (fp->fptr >= fp->fsize) {    /* Avoid silly cache filling at growing edge */
    29212921                                if (sync_window(fp->fs)) ABORT(fp->fs, FR_DISK_ERR);
     
    29332933                wcnt = SS(fp->fs) - ((UINT)fp->fptr % SS(fp->fs));/* Put partial sector into file I/O buffer */
    29342934                if (wcnt > btw) wcnt = btw;
    2935 #if _FS_TINY
     2935#if FF_FS_TINY
    29362936                if (move_window(fp->fs, fp->dsect) != FR_OK)    /* Move sector window */
    29372937                        ABORT(fp->fs, FR_DISK_ERR);
     
    29402940#else
    29412941                mem_cpy(&fp->buf[fp->fptr % SS(fp->fs)], wbuff, wcnt);  /* Fit partial sector */
    2942                 fp->flag |= FA__DIRTY;
     2942                fp->flag |= FA_DIRTY;
    29432943#endif
    29442944        }
    29452945
    29462946        if (fp->fptr > fp->fsize) fp->fsize = fp->fptr; /* Update file size if needed */
    2947         fp->flag |= FA__WRITTEN;                                                /* Set file change flag */
     2947        fp->flag |= FA_MODIFIED;                                                /* Set file change flag */
    29482948
    29492949        LEAVE_FF(fp->fs, FR_OK);
     
    29682968        res = validate(fp);                                     /* Check validity of the object */
    29692969        if (res == FR_OK) {
    2970                 if (fp->flag & FA__WRITTEN) {   /* Is there any change to the file? */
    2971 #if !_FS_TINY
    2972                         if (fp->flag & FA__DIRTY) {     /* Write-back cached data if needed */
     2970                if (fp->flag & FA_MODIFIED) {   /* Is there any change to the file? */
     2971#if !FF_FS_TINY
     2972                        if (fp->flag & FA_DIRTY) {      /* Write-back cached data if needed */
    29732973                                if (disk_write(fp->fs->drv, fp->buf, fp->dsect, 1) != RES_OK)
    29742974                                        LEAVE_FF(fp->fs, FR_DISK_ERR);
    2975                                 fp->flag &= ~FA__DIRTY;
     2975                                fp->flag &= ~FA_DIRTY;
    29762976                        }
    29772977#endif
     
    29862986                                ST_DWORD(dir + DIR_WrtTime, tm);
    29872987                                ST_WORD(dir + DIR_LstAccDate, 0);
    2988                                 fp->flag &= ~FA__WRITTEN;
     2988                                fp->flag &= ~FA_MODIFIED;
    29892989                                fp->fs->wflag = 1;
    29902990                                res = sync_fs(fp->fs);
     
    29962996}
    29972997
    2998 #endif /* !_FS_READONLY */
     2998#endif /* !FF_FS_READONLY */
    29992999
    30003000
     
    30123012
    30133013
    3014 #if !_FS_READONLY
     3014#if !FF_FS_READONLY
    30153015        res = f_sync(fp);                                       /* Flush cached data */
    30163016        if (res == FR_OK)
     
    30193019                res = validate(fp);                             /* Lock volume */
    30203020                if (res == FR_OK) {
    3021 #if _FS_REENTRANT
     3021#if FF_FS_REENTRANT
    30223022                        FATFS *fs = fp->fs;
    30233023#endif
    3024 #if _FS_LOCK
     3024#if FF_FS_LOCK != 0
    30253025                        res = dec_lock(fp->lockid);     /* Decrement file open counter */
    30263026                        if (res == FR_OK)
    30273027#endif
    30283028                                fp->fs = 0;                             /* Invalidate file object */
    3029 #if _FS_REENTRANT
     3029#if FF_FS_REENTRANT
    30303030                        unlock_fs(fs, FR_OK);           /* Unlock volume */
    30313031#endif
     
    30423042/*-----------------------------------------------------------------------*/
    30433043
    3044 #if _FS_RPATH >= 1
    3045 #if _VOLUMES >= 2
     3044#if FF_FS_RPATH >= 1
     3045#if FF_VOLUMES >= 2
    30463046FRESULT f_chdrive (
    30473047        const TCHAR* path               /* Drive number */
     
    30663066{
    30673067        FRESULT res;
    3068         DIR dj;
     3068        FATFS_DIR dj;
    30693069        DEFINE_NAMEBUF;
    30703070
     
    30933093
    30943094
    3095 #if _FS_RPATH >= 2
     3095#if FF_FS_RPATH >= 2
    30963096FRESULT f_getcwd (
    30973097        TCHAR* buff,    /* Pointer to the directory path */
     
    31003100{
    31013101        FRESULT res;
    3102         DIR dj;
     3102        FATFS_DIR dj;
    31033103        UINT i, n;
    31043104        DWORD ccl;
     
    31313131                        if (res == FR_NO_FILE) res = FR_INT_ERR;/* It cannot be 'not found'. */
    31323132                        if (res != FR_OK) break;
    3133 #if _USE_LFN
     3133#if FF_USE_LFN
    31343134                        fno.lfname = buff;
    31353135                        fno.lfsize = i;
     
    31373137                        get_fileinfo(&dj, &fno);                /* Get the directory name and push it to the buffer */
    31383138                        tp = fno.fname;
    3139 #if _USE_LFN
     3139#if FF_USE_LFN
    31403140                        if (*buff) tp = buff;
    31413141#endif
     
    31493149                tp = buff;
    31503150                if (res == FR_OK) {
    3151 #if _VOLUMES >= 2
     3151#if FF_VOLUMES >= 2
    31523152                        *tp++ = '0' + CurrVol;                  /* Put drive number */
    31533153                        *tp++ = ':';
     
    31673167        LEAVE_FF(dj.fs, res);
    31683168}
    3169 #endif /* _FS_RPATH >= 2 */
    3170 #endif /* _FS_RPATH >= 1 */
    3171 
    3172 
    3173 
    3174 #if _FS_MINIMIZE <= 2
     3169#endif /* FF_FS_RPATH >= 2 */
     3170#endif /* FF_FS_RPATH >= 1 */
     3171
     3172
     3173
     3174#if FF_FS_MINIMIZE <= 2
    31753175/*-----------------------------------------------------------------------*/
    31763176/* Seek File R/W Pointer                                                 */
     
    31843184        FRESULT res;
    31853185        DWORD clst, bcs, nsect, ifptr;
    3186 #if _USE_FASTSEEK
     3186#if FF_USE_FASTSEEK
    31873187        DWORD cl, pcl, ncl, tcl, dsc, tlen, ulen, *tbl;
    31883188#endif
     
    31943194                LEAVE_FF(fp->fs, (FRESULT)fp->err);
    31953195
    3196 #if _USE_FASTSEEK
     3196#if FF_USE_FASTSEEK
    31973197        if (fp->cltbl) {        /* Fast seek */
    31983198                if (ofs == CREATE_LINKMAP) {    /* Create CLMT */
     
    32313231                                dsc += (ofs - 1) / SS(fp->fs) & (fp->fs->csize - 1);
    32323232                                if (fp->fptr % SS(fp->fs) && dsc != fp->dsect) {        /* Refill sector cache if needed */
    3233 #if !_FS_TINY
    3234 #if !_FS_READONLY
    3235                                         if (fp->flag & FA__DIRTY) {             /* Write-back dirty sector cache */
     3233#if !FF_FS_TINY
     3234#if !FF_FS_READONLY
     3235                                        if (fp->flag & FA_DIRTY) {              /* Write-back dirty sector cache */
    32363236                                                if (disk_write(fp->fs->drv, fp->buf, fp->dsect, 1) != RES_OK)
    32373237                                                        ABORT(fp->fs, FR_DISK_ERR);
    3238                                                 fp->flag &= ~FA__DIRTY;
     3238                                                fp->flag &= ~FA_DIRTY;
    32393239                                        }
    32403240#endif
     
    32523252        {
    32533253                if (ofs > fp->fsize                                     /* In read-only mode, clip offset with the file size */
    3254 #if !_FS_READONLY
     3254#if !FF_FS_READONLY
    32553255                         && !(fp->flag & FA_WRITE)
    32563256#endif
     
    32683268                        } else {                                                                        /* When seek to back cluster, */
    32693269                                clst = fp->sclust;                                              /* start from the first cluster */
    3270 #if !_FS_READONLY
     3270#if !FF_FS_READONLY
    32713271                                if (clst == 0) {                                                /* If no cluster chain, create a new chain */
    32723272                                        clst = create_chain(fp->fs, 0);
     
    32803280                        if (clst != 0) {
    32813281                                while (ofs > bcs) {                                             /* Cluster following loop */
    3282 #if !_FS_READONLY
     3282#if !FF_FS_READONLY
    32833283                                        if (fp->flag & FA_WRITE) {                      /* Check if in write mode or not */
    32843284                                                clst = create_chain(fp->fs, clst);      /* Force stretch if in write mode */
     
    33043304                }
    33053305                if (fp->fptr % SS(fp->fs) && nsect != fp->dsect) {      /* Fill sector cache if needed */
    3306 #if !_FS_TINY
    3307 #if !_FS_READONLY
    3308                         if (fp->flag & FA__DIRTY) {                     /* Write-back dirty sector cache */
     3306#if !FF_FS_TINY
     3307#if !FF_FS_READONLY
     3308                        if (fp->flag & FA_DIRTY) {                      /* Write-back dirty sector cache */
    33093309                                if (disk_write(fp->fs->drv, fp->buf, fp->dsect, 1) != RES_OK)
    33103310                                        ABORT(fp->fs, FR_DISK_ERR);
    3311                                 fp->flag &= ~FA__DIRTY;
     3311                                fp->flag &= ~FA_DIRTY;
    33123312                        }
    33133313#endif
     
    33173317                        fp->dsect = nsect;
    33183318                }
    3319 #if !_FS_READONLY
     3319#if !FF_FS_READONLY
    33203320                if (fp->fptr > fp->fsize) {                     /* Set file change flag if the file size is extended */
    33213321                        fp->fsize = fp->fptr;
    3322                         fp->flag |= FA__WRITTEN;
     3322                        fp->flag |= FA_MODIFIED;
    33233323                }
    33243324#endif
     
    33423342}
    33433343
    3344 #if _FS_MINIMIZE <= 1
     3344#if FF_FS_MINIMIZE <= 1
    33453345/*-----------------------------------------------------------------------*/
    33463346/* Create a Directory Object                                             */
     
    33483348
    33493349FRESULT f_opendir (
    3350         DIR* dp,                        /* Pointer to directory object to create */
     3350        FATFS_DIR* dp,                  /* Pointer to directory object to create */
    33513351        const TCHAR* path       /* Pointer to the directory path */
    33523352)
     
    33763376                                dp->id = fs->id;
    33773377                                res = dir_sdi(dp, 0);                   /* Rewind directory */
    3378 #if _FS_LOCK
     3378#if FF_FS_LOCK != 0
    33793379                                if (res == FR_OK) {
    33803380                                        if (dp->sclust) {
     
    34043404
    34053405FRESULT f_closedir (
    3406         DIR *dp         /* Pointer to the directory object to be closed */
     3406        FATFS_DIR *dp           /* Pointer to the directory object to be closed */
    34073407)
    34083408{
     
    34123412        res = validate(dp);
    34133413        if (res == FR_OK) {
    3414 #if _FS_REENTRANT
     3414#if FF_FS_REENTRANT
    34153415                FATFS *fs = dp->fs;
    34163416#endif
    3417 #if _FS_LOCK
     3417#if FF_FS_LOCK != 0
    34183418                if (dp->lockid)                         /* Decrement sub-directory open counter */
    34193419                        res = dec_lock(dp->lockid);
     
    34213421#endif
    34223422                        dp->fs = 0;                             /* Invalidate directory object */
    3423 #if _FS_REENTRANT
     3423#if FF_FS_REENTRANT
    34243424                unlock_fs(fs, FR_OK);           /* Unlock volume */
    34253425#endif
     
    34363436
    34373437FRESULT f_readdir (
    3438         DIR* dp,                        /* Pointer to the open directory object */
     3438        FATFS_DIR* dp,                  /* Pointer to the open directory object */
    34393439        FILINFO* fno            /* Pointer to file information to return */
    34403440)
     
    34723472
    34733473
    3474 #if _USE_FIND
     3474#if FF_USE_FIND
    34753475/*-----------------------------------------------------------------------*/
    34763476/* Find next file                                                        */
     
    34783478
    34793479FRESULT f_findnext (
    3480         DIR* dp,                /* Pointer to the open directory object */
     3480        FATFS_DIR* dp,          /* Pointer to the open directory object */
    34813481        FILINFO* fno    /* Pointer to the file information structure */
    34823482)
     
    34883488                res = f_readdir(dp, fno);               /* Get a directory item */
    34893489                if (res != FR_OK || !fno || !fno->fname[0]) break;      /* Terminate if any error or end of directory */
    3490 #if _USE_LFN
     3490#if FF_USE_LFN
    34913491                if (fno->lfname && pattern_matching(dp->pat, fno->lfname, 0, 0)) break; /* Test for LFN if exist */
    34923492#endif
     
    35043504
    35053505FRESULT f_findfirst (
    3506         DIR* dp,                                /* Pointer to the blank directory object */
     3506        FATFS_DIR* dp,                          /* Pointer to the blank directory object */
    35073507        FILINFO* fno,                   /* Pointer to the file information structure */
    35083508        const TCHAR* path,              /* Pointer to the directory to open */
     
    35203520}
    35213521
    3522 #endif  /* _USE_FIND */
    3523 
    3524 
    3525 
    3526 #if _FS_MINIMIZE == 0
     3522#endif  /* FF_USE_FIND */
     3523
     3524
     3525
     3526#if FF_FS_MINIMIZE == 0
    35273527/*-----------------------------------------------------------------------*/
    35283528/* Get File Status                                                       */
     
    35353535{
    35363536        FRESULT res;
    3537         DIR dj;
     3537        FATFS_DIR dj;
    35383538        DEFINE_NAMEBUF;
    35393539
     
    35593559
    35603560
    3561 #if !_FS_READONLY
     3561#if !FF_FS_READONLY
    35623562/*-----------------------------------------------------------------------*/
    35633563/* Get Number of Free Clusters                                           */
     
    36503650                if (fp->fsize > fp->fptr) {
    36513651                        fp->fsize = fp->fptr;   /* Set file size to current R/W point */
    3652                         fp->flag |= FA__WRITTEN;
     3652                        fp->flag |= FA_MODIFIED;
    36533653                        if (fp->fptr == 0) {    /* When set file size to zero, remove entire cluster chain */
    36543654                                res = remove_chain(fp->fs, fp->sclust);
     
    36643664                                }
    36653665                        }
    3666 #if !_FS_TINY
    3667                         if (res == FR_OK && (fp->flag & FA__DIRTY)) {
     3666#if !FF_FS_TINY
     3667                        if (res == FR_OK && (fp->flag & FA_DIRTY)) {
    36683668                                if (disk_write(fp->fs->drv, fp->buf, fp->dsect, 1) != RES_OK)
    36693669                                        res = FR_DISK_ERR;
    36703670                                else
    3671                                         fp->flag &= ~FA__DIRTY;
     3671                                        fp->flag &= ~FA_DIRTY;
    36723672                        }
    36733673#endif
     
    36913691{
    36923692        FRESULT res;
    3693         DIR dj, sdj;
     3693        FATFS_DIR dj, sdj;
    36943694        BYTE *dir;
    36953695        DWORD dclst = 0;
     
    37023702                INIT_BUF(dj);
    37033703                res = follow_path(&dj, path);           /* Follow the file path */
    3704                 if (_FS_RPATH && res == FR_OK && (dj.fn[NSFLAG] & NS_DOT))
     3704                if (FF_FS_RPATH && res == FR_OK && (dj.fn[NSFLAG] & NS_DOT))
    37053705                        res = FR_INVALID_NAME;                  /* Cannot remove dot entry */
    3706 #if _FS_LOCK
     3706#if FF_FS_LOCK != 0
    37073707                if (res == FR_OK) res = chk_lock(&dj, 2);       /* Cannot remove open object */
    37083708#endif
     
    37183718                                dclst = ld_clust(dj.fs, dir);
    37193719                                if (dclst && (dir[DIR_Attr] & AM_DIR)) {        /* Is it a sub-directory ? */
    3720 #if _FS_RPATH
     3720#if FF_FS_RPATH
    37213721                                        if (dclst == dj.fs->cdir) {                             /* Is it the current directory? */
    37223722                                                res = FR_DENIED;
     
    37243724#endif
    37253725                                        {
    3726                                                 mem_cpy(&sdj, &dj, sizeof (DIR));       /* Open the sub-directory */
     3726                                                mem_cpy(&sdj, &dj, sizeof (FATFS_DIR)); /* Open the sub-directory */
    37273727                                                sdj.sclust = dclst;
    37283728                                                res = dir_sdi(&sdj, 2);
     
    37603760{
    37613761        FRESULT res;
    3762         DIR dj;
     3762        FATFS_DIR dj;
    37633763        BYTE *dir, n;
    37643764        DWORD dsc, dcl, pcl, tm = GET_FATTIME();
     
    37723772                res = follow_path(&dj, path);                   /* Follow the file path */
    37733773                if (res == FR_OK) res = FR_EXIST;               /* Any object with same name is already existing */
    3774                 if (_FS_RPATH && res == FR_NO_FILE && (dj.fn[NSFLAG] & NS_DOT))
     3774                if (FF_FS_RPATH && res == FR_NO_FILE && (dj.fn[NSFLAG] & NS_DOT))
    37753775                        res = FR_INVALID_NAME;
    37763776                if (res == FR_NO_FILE) {                                /* Can create a new directory */
     
    38363836{
    38373837        FRESULT res;
    3838         DIR dj;
     3838        FATFS_DIR dj;
    38393839        BYTE *dir;
    38403840        DEFINE_NAMEBUF;
     
    38463846                res = follow_path(&dj, path);           /* Follow the file path */
    38473847                FREE_BUF();
    3848                 if (_FS_RPATH && res == FR_OK && (dj.fn[NSFLAG] & NS_DOT))
     3848                if (FF_FS_RPATH && res == FR_OK && (dj.fn[NSFLAG] & NS_DOT))
    38493849                        res = FR_INVALID_NAME;
    38503850                if (res == FR_OK) {
     
    38773877{
    38783878        FRESULT res;
    3879         DIR djo, djn;
     3879        FATFS_DIR djo, djn;
    38803880        BYTE buf[21], *dir;
    38813881        DWORD dw;
     
    38903890                INIT_BUF(djo);
    38913891                res = follow_path(&djo, path_old);              /* Check old object */
    3892                 if (_FS_RPATH && res == FR_OK && (djo.fn[NSFLAG] & NS_DOT))
     3892                if (FF_FS_RPATH && res == FR_OK && (djo.fn[NSFLAG] & NS_DOT))
    38933893                        res = FR_INVALID_NAME;
    3894 #if _FS_LOCK
     3894#if FF_FS_LOCK != 0
    38953895                if (res == FR_OK) res = chk_lock(&djo, 2);
    38963896#endif
     
    39003900                        } else {
    39013901                                mem_cpy(buf, djo.dir + DIR_Attr, 21);   /* Save information about object except name */
    3902                                 mem_cpy(&djn, &djo, sizeof (DIR));              /* Duplicate the directory object */
     3902                                mem_cpy(&djn, &djo, sizeof (FATFS_DIR));                /* Duplicate the directory object */
    39033903                                if (get_ldnumber(&path_new) >= 0)               /* Snip drive number off and ignore it */
    39043904                                        res = follow_path(&djn, path_new);      /* and make sure if new object name is not conflicting */
     
    39093909                                        dir = djn.dir;
    39103910                                        if (dir[DIR_Attr] & AM_DIR) {   /* The new object is a directory */
    3911                                                 temp_new_path = (TCHAR *)ff_memalloc((_MAX_LFN + 1) * sizeof(WCHAR));
    3912                                                 ntstdio_snprintf(temp_new_path, _MAX_LFN, "%s/%s", path_new, basename((char *)path_old));
     3911                                                temp_new_path = (TCHAR *)ff_memalloc((FF_MAX_LFN + 1) * sizeof(WCHAR));
     3912                                                snprintf(temp_new_path, FF_MAX_LFN, "%s/%s", path_new, basename((char *)path_old));
    39133913                                                res = follow_path(&djn, temp_new_path);
    39143914                                        }
     
    39663966{
    39673967        FRESULT res;
    3968         DIR dj;
     3968        FATFS_DIR dj;
    39693969        BYTE *dir;
    39703970        DEFINE_NAMEBUF;
     
    39773977                res = follow_path(&dj, path);   /* Follow the file path */
    39783978                FREE_BUF();
    3979                 if (_FS_RPATH && res == FR_OK && (dj.fn[NSFLAG] & NS_DOT))
     3979                if (FF_FS_RPATH && res == FR_OK && (dj.fn[NSFLAG] & NS_DOT))
    39803980                        res = FR_INVALID_NAME;
    39813981                if (res == FR_OK) {
     
    39953995}
    39963996
    3997 #endif /* !_FS_READONLY */
    3998 #endif /* _FS_MINIMIZE == 0 */
    3999 #endif /* _FS_MINIMIZE <= 1 */
    4000 #endif /* _FS_MINIMIZE <= 2 */
    4001 
    4002 
    4003 
    4004 
    4005 #if _USE_LABEL
     3997#endif /* !FF_FS_READONLY */
     3998#endif /* FF_FS_MINIMIZE == 0 */
     3999#endif /* FF_FS_MINIMIZE <= 1 */
     4000#endif /* FF_FS_MINIMIZE <= 2 */
     4001
     4002
     4003
     4004
     4005#if FF_USE_LABEL
    40064006/*-----------------------------------------------------------------------*/
    40074007/* Get volume label                                                      */
     
    40154015{
    40164016        FRESULT res;
    4017         DIR dj;
     4017        FATFS_DIR dj;
    40184018        UINT i, j;
    4019 #if _USE_LFN && _LFN_UNICODE
     4019#if FF_USE_LFN && FF_LFN_UNICODE
    40204020        WCHAR w;
    40214021#endif
     
    40324032                        res = dir_read(&dj, 1);         /* Get an entry with AM_VOL */
    40334033                        if (res == FR_OK) {                     /* A volume label is exist */
    4034 #if _USE_LFN && _LFN_UNICODE
     4034#if FF_USE_LFN && FF_LFN_UNICODE
    40354035                                i = j = 0;
    40364036                                do {
     
    40704070
    40714071
    4072 #if !_FS_READONLY
     4072#if !FF_FS_READONLY
    40734073/*-----------------------------------------------------------------------*/
    40744074/* Set volume label                                                      */
     
    40804080{
    40814081        FRESULT res;
    4082         DIR dj;
     4082        FATFS_DIR dj;
    40834083        BYTE vn[11];
    40844084        UINT i, j, sl;
    40854085        WCHAR w;
    40864086        DWORD tm;
    4087 #if _CODE_PAGE == 65001
     4087#if FF_CODE_PAGE == 65001
    40884088        int code_size;
    40894089        unsigned char utf8_code[6];
     
    41014101                i = j = 0;
    41024102                do {
    4103 #if _CODE_PAGE == 65001
     4103#if FF_CODE_PAGE == 65001
    41044104                        w = ff_wtoupper(Utf8_to_Utf16(&label[i], &code_size));
    41054105                        i += code_size;
     
    41104110                                vn[j++] = utf8_code[k];
    41114111#else
    4112 #if _USE_LFN && _LFN_UNICODE
     4112#if FF_USE_LFN && FF_LFN_UNICODE
    41134113                        w = ff_convert(ff_wtoupper(label[i++]), 0);
    41144114#else
     
    41164116                        if (IsDBCS1(w))
    41174117                                w = (j < 10 && i < sl && IsDBCS2(label[i])) ? w << 8 | (BYTE)label[i++] : 0;
    4118 #if _USE_LFN
     4118#if FF_USE_LFN
    41194119                        w = ff_convert(ff_wtoupper(ff_convert(w, 1)), 0);
    41204120#else
     
    41744174}
    41754175
    4176 #endif /* !_FS_READONLY */
    4177 #endif /* _USE_LABEL */
     4176#endif /* !FF_FS_READONLY */
     4177#endif /* FF_USE_LABEL */
    41784178
    41794179
     
    41824182/* Forward data to the stream directly (available on only tiny cfg)      */
    41834183/*-----------------------------------------------------------------------*/
    4184 #if _USE_FORWARD && _FS_TINY
     4184#if FF_USE_FORWARD && FF_FS_TINY
    41854185
    41864186FRESULT f_forward (
     
    42354235        LEAVE_FF(fp->fs, FR_OK);
    42364236}
    4237 #endif /* _USE_FORWARD */
    4238 
    4239 
    4240 
    4241 #if _USE_MKFS && !_FS_READONLY
     4237#endif /* FF_USE_FORWARD */
     4238
     4239
     4240
     4241#if FF_USE_MKFS && !FF_FS_READONLY
    42424242/*-----------------------------------------------------------------------*/
    42434243/* Create file system on the logical drive                               */
     
    42634263        FATFS *fs;
    42644264        DSTATUS stat;
    4265 #if _USE_TRIM
     4265#if FF_USE_TRIM
    42664266        DWORD eb[2];
    42674267#endif
     
    42824282        if (stat & STA_NOINIT) return FR_NOT_READY;
    42834283        if (stat & STA_PROTECT) return FR_WRITE_PROTECTED;
    4284 #if _MAX_SS != _MIN_SS          /* Get disk sector size */
    4285         if (disk_ioctl(pdrv, GET_SECTOR_SIZE, &SS(fs)) != RES_OK || SS(fs) > _MAX_SS || SS(fs) < _MIN_SS)
     4284#if FF_MAX_SS != FF_MIN_SS              /* Get disk sector size */
     4285        if (disk_ioctl(pdrv, GET_SECTOR_SIZE, &SS(fs)) != RES_OK || SS(fs) > FF_MAX_SS || SS(fs) < FF_MIN_SS)
    42864286                return FR_DISK_ERR;
    42874287#endif
    4288         if (_MULTI_PARTITION && part) {
     4288        if (FF_MULTI_PARTITION && part) {
    42894289                /* Get partition information from partition table in the MBR */
    42904290                if (disk_read(pdrv, fs->win, 0, 1) != RES_OK) return FR_DISK_ERR;
     
    43084308                au = cst[i];
    43094309        }
    4310         if (au >= _MIN_SS) au /= SS(fs);        /* Number of sectors per cluster */
     4310        if (au >= FF_MIN_SS) au /= SS(fs);      /* Number of sectors per cluster */
    43114311        if (!au) au = 1;
    43124312        if (au > 128) au = 128;
     
    43624362        }
    43634363
    4364         if (_MULTI_PARTITION && part) {
     4364        if (FF_MULTI_PARTITION && part) {
    43654365                /* Update system ID in the partition table */
    43664366                tbl = &fs->win[MBR_Table + (part - 1) * SZ_PTE];
     
    44654465        } while (--i);
    44664466
    4467 #if _USE_TRIM   /* Erase data area if needed */
     4467#if FF_USE_TRIM /* Erase data area if needed */
    44684468        {
    44694469                eb[0] = wsect; eb[1] = wsect + (n_clst - ((fmt == FS_FAT32) ? 1 : 0)) * au - 1;
     
    44884488
    44894489
    4490 #if _MULTI_PARTITION
     4490#if FF_MULTI_PARTITION
    44914491/*-----------------------------------------------------------------------*/
    44924492/* Create partition table on the physical drive                          */
     
    45184518
    45194519        /* Create partition table */
    4520         mem_set(buf, 0, _MAX_SS);
     4520        mem_set(buf, 0, FF_MAX_SS);
    45214521        p = buf + MBR_Table; b_cyl = 0;
    45224522        for (i = 0; i < 4; i++, p += SZ_PTE) {
     
    45554555
    45564556
    4557 #endif /* _MULTI_PARTITION */
    4558 #endif /* _USE_MKFS && !_FS_READONLY */
    4559 
    4560 
    4561 
    4562 
    4563 #if _USE_STRFUNC
     4557#endif /* FF_MULTI_PARTITION */
     4558#endif /* FF_USE_MKFS && !FF_FS_READONLY */
     4559
     4560
     4561
     4562
     4563#if FF_USE_STRFUNC
    45644564/*-----------------------------------------------------------------------*/
    45654565/* Get a string from the file                                            */
     
    45794579
    45804580        while (n < len - 1) {   /* Read characters until buffer gets filled */
    4581 #if _USE_LFN && _LFN_UNICODE
    4582 #if _STRF_ENCODE == 3           /* Read a character in UTF-8 */
     4581#if FF_USE_LFN && FF_LFN_UNICODE
     4582#if FF_STRF_ENCODE == 3         /* Read a character in UTF-8 */
    45834583                f_read(fp, s, 1, &rc);
    45844584                if (rc != 1) break;
     
    46024602                        }
    46034603                }
    4604 #elif _STRF_ENCODE == 2         /* Read a character in UTF-16BE */
     4604#elif FF_STRF_ENCODE == 2               /* Read a character in UTF-16BE */
    46054605                f_read(fp, s, 2, &rc);
    46064606                if (rc != 2) break;
    46074607                c = s[1] + (s[0] << 8);
    4608 #elif _STRF_ENCODE == 1         /* Read a character in UTF-16LE */
     4608#elif FF_STRF_ENCODE == 1               /* Read a character in UTF-16LE */
    46094609                f_read(fp, s, 2, &rc);
    46104610                if (rc != 2) break;
     
    46274627                c = s[0];
    46284628#endif
    4629                 if (_USE_STRFUNC == 2 && c == '\r') continue;   /* Strip '\r' */
     4629                if (FF_USE_STRFUNC == 2 && c == '\r') continue; /* Strip '\r' */
    46304630                *p++ = c;
    46314631                n++;
     
    46394639
    46404640
    4641 #if !_FS_READONLY
     4641#if !FF_FS_READONLY
    46424642/*-----------------------------------------------------------------------*/
    46434643/* Put a character to the file                                           */
     
    46614661
    46624662
    4663         if (_USE_STRFUNC == 2 && c == '\n')      /* LF -> CRLF conversion */
     4663        if (FF_USE_STRFUNC == 2 && c == '\n')    /* LF -> CRLF conversion */
    46644664                putc_bfd(pb, '\r');
    46654665
     
    46674667        if (i < 0) return;
    46684668
    4669 #if _USE_LFN && _LFN_UNICODE
    4670 #if _STRF_ENCODE == 3                   /* Write a character in UTF-8 */
     4669#if FF_USE_LFN && FF_LFN_UNICODE
     4670#if FF_STRF_ENCODE == 3                 /* Write a character in UTF-8 */
    46714671        if (c < 0x80) {                         /* 7-bit */
    46724672                pb->buf[i++] = (BYTE)c;
     
    46804680                pb->buf[i++] = (BYTE)(0x80 | (c & 0x3F));
    46814681        }
    4682 #elif _STRF_ENCODE == 2                 /* Write a character in UTF-16BE */
     4682#elif FF_STRF_ENCODE == 2                       /* Write a character in UTF-16BE */
    46834683        pb->buf[i++] = (BYTE)(c >> 8);
    46844684        pb->buf[i++] = (BYTE)c;
    4685 #elif _STRF_ENCODE == 1                 /* Write a character in UTF-16LE */
     4685#elif FF_STRF_ENCODE == 1                       /* Write a character in UTF-16LE */
    46864686        pb->buf[i++] = (BYTE)c;
    46874687        pb->buf[i++] = (BYTE)(c >> 8);
     
    48664866        ret = f_vprintf(fp, fmt, arp);
    48674867        va_end(arp);
    4868 
     4868       
    48694869        return ret;
    48704870}
    48714871
    4872 #endif /* !_FS_READONLY */
    4873 #endif /* _USE_STRFUNC */
     4872#endif /* !FF_FS_READONLY */
     4873#endif /* FF_USE_STRFUNC */
Note: See TracChangeset for help on using the changeset viewer.