Index: asp3_tinet_ecnl_arm/trunk/ntshell/fatfs/ff.c
===================================================================
--- asp3_tinet_ecnl_arm/trunk/ntshell/fatfs/ff.c	(revision 369)
+++ asp3_tinet_ecnl_arm/trunk/ntshell/fatfs/ff.c	(revision 374)
@@ -20,5 +20,5 @@
 #include "ff.h"			/* Declarations of FatFs API */
 #include "diskio.h"		/* Declarations of disk I/O functions */
-#include "util/ntstdio.h"
+#include <stdio.h>
 
 /*--------------------------------------------------------------------------
@@ -34,6 +34,6 @@
 
 /* Reentrancy related */
-#if _FS_REENTRANT
-#if _USE_LFN == 1
+#if FF_FS_REENTRANT
+#if FF_USE_LFN == 1
 #error Static LFN work area cannot be used at thread-safe configuration
 #endif
@@ -49,9 +49,9 @@
 
 /* Definitions of sector size */
-#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)
+#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)
 #error Wrong sector size configuration
 #endif
-#if _MAX_SS == _MIN_SS
-#define	SS(fs)	((UINT)_MAX_SS)	/* Fixed sector size */
+#if FF_MAX_SS == FF_MIN_SS
+#define	SS(fs)	((UINT)FF_MAX_SS)	/* Fixed sector size */
 #else
 #define	SS(fs)	((fs)->ssize)	/* Variable sector size */
@@ -60,9 +60,9 @@
 
 /* Timestamp feature */
-#if _FS_NORTC == 1
-#if _NORTC_YEAR < 1980 || _NORTC_YEAR > 2107 || _NORTC_MON < 1 || _NORTC_MON > 12 || _NORTC_MDAY < 1 || _NORTC_MDAY > 31
-#error Invalid _FS_NORTC settings
-#endif
-#define GET_FATTIME()	((DWORD)(_NORTC_YEAR - 1980) << 25 | (DWORD)_NORTC_MON << 21 | (DWORD)_NORTC_MDAY << 16)
+#if FF_FS_NORTC == 1
+#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
+#error Invalid FF_FS_NORTC settings
+#endif
+#define GET_FATTIME()	((DWORD)(FF_NORTC_YEAR - 1980) << 25 | (DWORD)FF_NORTC_MON << 21 | (DWORD)FF_NORTC_MDAY << 16)
 #else
 #define GET_FATTIME()	get_fattime()
@@ -71,7 +71,7 @@
 
 /* File access control feature */
-#if _FS_LOCK
-#if _FS_READONLY
-#error _FS_LOCK must be 0 at read-only configuration
+#if FF_FS_LOCK != 0
+#if FF_FS_READONLY
+#error FF_FS_LOCK must be 0 at read-only configuration
 #endif
 typedef struct {
@@ -87,5 +87,5 @@
 /* DBCS code ranges and SBCS upper conversion tables */
 
-#if _CODE_PAGE == 932	/* Japanese Shift-JIS */
+#if FF_CODE_PAGE == 932	/* Japanese Shift-JIS */
 #define _DF1S	0x81	/* DBC 1st byte range 1 start */
 #define _DF1E	0x9F	/* DBC 1st byte range 1 end */
@@ -97,5 +97,5 @@
 #define _DS2E	0xFC	/* DBC 2nd byte range 2 end */
 
-#elif _CODE_PAGE == 936	/* Simplified Chinese GBK */
+#elif FF_CODE_PAGE == 936	/* Simplified Chinese GBK */
 #define _DF1S	0x81
 #define _DF1E	0xFE
@@ -105,5 +105,5 @@
 #define _DS2E	0xFE
 
-#elif _CODE_PAGE == 949	/* Korean */
+#elif FF_CODE_PAGE == 949	/* Korean */
 #define _DF1S	0x81
 #define _DF1E	0xFE
@@ -115,5 +115,5 @@
 #define _DS3E	0xFE
 
-#elif _CODE_PAGE == 950	/* Traditional Chinese Big5 */
+#elif FF_CODE_PAGE == 950	/* Traditional Chinese Big5 */
 #define _DF1S	0x81
 #define _DF1E	0xFE
@@ -123,5 +123,5 @@
 #define _DS2E	0xFE
 
-#elif _CODE_PAGE == 437	/* U.S. */
+#elif FF_CODE_PAGE == 437	/* U.S. */
 #define _DF1S	0
 #define _EXCVT {0x80,0x9A,0x45,0x41,0x8E,0x41,0x8F,0x80,0x45,0x45,0x45,0x49,0x49,0x49,0x8E,0x8F, \
@@ -134,5 +134,5 @@
 				0xF0,0xF1,0xF2,0xF3,0xF4,0xF5,0xF6,0xF7,0xF8,0xF9,0xFA,0xFB,0xFC,0xFD,0xFE,0xFF}
 
-#elif _CODE_PAGE == 720	/* Arabic */
+#elif FF_CODE_PAGE == 720	/* Arabic */
 #define _DF1S	0
 #define _EXCVT {0x80,0x81,0x82,0x83,0x84,0x85,0x86,0x87,0x88,0x89,0x8A,0x8B,0x8C,0x8D,0x8E,0x8F, \
@@ -145,5 +145,5 @@
 				0xF0,0xF1,0xF2,0xF3,0xF4,0xF5,0xF6,0xF7,0xF8,0xF9,0xFA,0xFB,0xFC,0xFD,0xFE,0xFF}
 
-#elif _CODE_PAGE == 737	/* Greek */
+#elif FF_CODE_PAGE == 737	/* Greek */
 #define _DF1S	0
 #define _EXCVT {0x80,0x81,0x82,0x83,0x84,0x85,0x86,0x87,0x88,0x89,0x8A,0x8B,0x8C,0x8D,0x8E,0x8F, \
@@ -156,5 +156,5 @@
 				0xF0,0xF1,0xF2,0xF3,0xF4,0xF5,0xF6,0xF7,0xF8,0xF9,0xFA,0xFB,0xFC,0xFD,0xFE,0xFF}
 
-#elif _CODE_PAGE == 771	/* KBL */
+#elif FF_CODE_PAGE == 771	/* KBL */
 #define _DF1S	0
 #define _EXCVT {0x80,0x81,0x82,0x83,0x84,0x85,0x86,0x87,0x88,0x89,0x8A,0x8B,0x8C,0x8D,0x8E,0x8F, \
@@ -167,5 +167,5 @@
 				0xF0,0xF0,0xF2,0xF2,0xF4,0xF4,0xF6,0xF6,0xF8,0xF8,0xFA,0xFA,0xFC,0xFC,0xFE,0xFF}
 
-#elif _CODE_PAGE == 775	/* Baltic */
+#elif FF_CODE_PAGE == 775	/* Baltic */
 #define _DF1S	0
 #define _EXCVT {0x80,0x9A,0x91,0xA0,0x8E,0x95,0x8F,0x80,0xAD,0xED,0x8A,0x8A,0xA1,0x8D,0x8E,0x8F, \
@@ -178,5 +178,5 @@
 				0xF0,0xF1,0xF2,0xF3,0xF4,0xF5,0xF6,0xF7,0xF8,0xF9,0xFA,0xFB,0xFC,0xFD,0xFE,0xFF}
 
-#elif _CODE_PAGE == 850	/* Latin 1 */
+#elif FF_CODE_PAGE == 850	/* Latin 1 */
 #define _DF1S	0
 #define _EXCVT {0x43,0x55,0x45,0x41,0x41,0x41,0x41,0x43,0x45,0x45,0x45,0x49,0x49,0x49,0x41,0x41, \
@@ -189,5 +189,5 @@
 				0xF0,0xF1,0xF2,0xF3,0xF4,0xF5,0xF6,0xF7,0xF8,0xF9,0xFA,0xFB,0xFC,0xFD,0xFE,0xFF}
 
-#elif _CODE_PAGE == 852	/* Latin 2 */
+#elif FF_CODE_PAGE == 852	/* Latin 2 */
 #define _DF1S	0
 #define _EXCVT {0x80,0x9A,0x90,0xB6,0x8E,0xDE,0x8F,0x80,0x9D,0xD3,0x8A,0x8A,0xD7,0x8D,0x8E,0x8F, \
@@ -200,5 +200,5 @@
 				0xF0,0xF1,0xF2,0xF3,0xF4,0xF5,0xF6,0xF7,0xF8,0xF9,0xFA,0xEB,0xFC,0xFC,0xFE,0xFF}
 
-#elif _CODE_PAGE == 855	/* Cyrillic */
+#elif FF_CODE_PAGE == 855	/* Cyrillic */
 #define _DF1S	0
 #define _EXCVT {0x81,0x81,0x83,0x83,0x85,0x85,0x87,0x87,0x89,0x89,0x8B,0x8B,0x8D,0x8D,0x8F,0x8F, \
@@ -211,5 +211,5 @@
 				0xF0,0xF2,0xF2,0xF4,0xF4,0xF6,0xF6,0xF8,0xF8,0xFA,0xFA,0xFC,0xFC,0xFD,0xFE,0xFF}
 
-#elif _CODE_PAGE == 857	/* Turkish */
+#elif FF_CODE_PAGE == 857	/* Turkish */
 #define _DF1S	0
 #define _EXCVT {0x80,0x9A,0x90,0xB6,0x8E,0xB7,0x8F,0x80,0xD2,0xD3,0xD4,0xD8,0xD7,0x49,0x8E,0x8F, \
@@ -222,5 +222,5 @@
 				0xF0,0xF1,0xF2,0xF3,0xF4,0xF5,0xF6,0xF7,0xF8,0xF9,0xFA,0xFB,0xFC,0xFD,0xFE,0xFF}
 
-#elif _CODE_PAGE == 860	/* Portuguese */
+#elif FF_CODE_PAGE == 860	/* Portuguese */
 #define _DF1S	0
 #define _EXCVT {0x80,0x9A,0x90,0x8F,0x8E,0x91,0x86,0x80,0x89,0x89,0x92,0x8B,0x8C,0x98,0x8E,0x8F, \
@@ -233,5 +233,5 @@
 				0xF0,0xF1,0xF2,0xF3,0xF4,0xF5,0xF6,0xF7,0xF8,0xF9,0xFA,0xFB,0xFC,0xFD,0xFE,0xFF}
 
-#elif _CODE_PAGE == 861	/* Icelandic */
+#elif FF_CODE_PAGE == 861	/* Icelandic */
 #define _DF1S	0
 #define _EXCVT {0x80,0x9A,0x90,0x41,0x8E,0x41,0x8F,0x80,0x45,0x45,0x45,0x8B,0x8B,0x8D,0x8E,0x8F, \
@@ -244,5 +244,5 @@
 				0xF0,0xF1,0xF2,0xF3,0xF4,0xF5,0xF6,0xF7,0xF8,0xF9,0xFA,0xFB,0xFC,0xFD,0xFE,0xFF}
 
-#elif _CODE_PAGE == 862	/* Hebrew */
+#elif FF_CODE_PAGE == 862	/* Hebrew */
 #define _DF1S	0
 #define _EXCVT {0x80,0x81,0x82,0x83,0x84,0x85,0x86,0x87,0x88,0x89,0x8A,0x8B,0x8C,0x8D,0x8E,0x8F, \
@@ -255,5 +255,5 @@
 				0xF0,0xF1,0xF2,0xF3,0xF4,0xF5,0xF6,0xF7,0xF8,0xF9,0xFA,0xFB,0xFC,0xFD,0xFE,0xFF}
 
-#elif _CODE_PAGE == 863	/* Canadian-French */
+#elif FF_CODE_PAGE == 863	/* Canadian-French */
 #define _DF1S	0
 #define _EXCVT {0x43,0x55,0x45,0x41,0x41,0x41,0x86,0x43,0x45,0x45,0x45,0x49,0x49,0x8D,0x41,0x8F, \
@@ -266,5 +266,5 @@
 				0xF0,0xF1,0xF2,0xF3,0xF4,0xF5,0xF6,0xF7,0xF8,0xF9,0xFA,0xFB,0xFC,0xFD,0xFE,0xFF}
 
-#elif _CODE_PAGE == 864	/* Arabic */
+#elif FF_CODE_PAGE == 864	/* Arabic */
 #define _DF1S	0
 #define _EXCVT {0x80,0x9A,0x45,0x41,0x8E,0x41,0x8F,0x80,0x45,0x45,0x45,0x49,0x49,0x49,0x8E,0x8F, \
@@ -277,5 +277,5 @@
 				0xF0,0xF1,0xF2,0xF3,0xF4,0xF5,0xF6,0xF7,0xF8,0xF9,0xFA,0xFB,0xFC,0xFD,0xFE,0xFF}
 
-#elif _CODE_PAGE == 865	/* Nordic */
+#elif FF_CODE_PAGE == 865	/* Nordic */
 #define _DF1S	0
 #define _EXCVT {0x80,0x9A,0x90,0x41,0x8E,0x41,0x8F,0x80,0x45,0x45,0x45,0x49,0x49,0x49,0x8E,0x8F, \
@@ -288,5 +288,5 @@
 				0xF0,0xF1,0xF2,0xF3,0xF4,0xF5,0xF6,0xF7,0xF8,0xF9,0xFA,0xFB,0xFC,0xFD,0xFE,0xFF}
 
-#elif _CODE_PAGE == 866	/* Russian */
+#elif FF_CODE_PAGE == 866	/* Russian */
 #define _DF1S	0
 #define _EXCVT {0x80,0x81,0x82,0x83,0x84,0x85,0x86,0x87,0x88,0x89,0x8A,0x8B,0x8C,0x8D,0x8E,0x8F, \
@@ -299,5 +299,5 @@
 				0xF0,0xF0,0xF2,0xF2,0xF4,0xF4,0xF6,0xF6,0xF8,0xF9,0xFA,0xFB,0xFC,0xFD,0xFE,0xFF}
 
-#elif _CODE_PAGE == 869	/* Greek 2 */
+#elif FF_CODE_PAGE == 869	/* Greek 2 */
 #define _DF1S	0
 #define _EXCVT {0x80,0x81,0x82,0x83,0x84,0x85,0x86,0x87,0x88,0x89,0x8A,0x8B,0x8C,0x8D,0x8E,0x8F, \
@@ -310,12 +310,12 @@
 				0xF0,0xF1,0xD1,0xD2,0xD3,0xF5,0xD4,0xF7,0xF8,0xF9,0xD5,0x96,0x95,0x98,0xFE,0xFF}
 
-#elif _CODE_PAGE == 1	/* ASCII (for only non-LFN cfg) */
-#if _USE_LFN
+#elif FF_CODE_PAGE == 1	/* ASCII (for only non-LFN cfg) */
+#if FF_USE_LFN
 #error Cannot use LFN feature without valid code page.
 #endif
 #define _DF1S	0
 
-#elif _CODE_PAGE == 65001 /* UTF-8 */
-#if _LFN_UNICODE
+#elif FF_CODE_PAGE == 65001 /* UTF-8 */
+#if FF_LFN_UNICODE
 #error Cannot use LFN_UNICODE feature without valid code page.
 #endif
@@ -532,41 +532,41 @@
 */
 
-#if _VOLUMES < 1 || _VOLUMES > 9
-#error Wrong _VOLUMES setting
-#endif
-static FATFS *FatFs[_VOLUMES];	/* Pointer to the file system objects (logical drives) */
+#if FF_VOLUMES < 1 || FF_VOLUMES > 9
+#error Wrong FF_VOLUMES setting
+#endif
+static FATFS *FatFs[FF_VOLUMES];	/* Pointer to the file system objects (logical drives) */
 static WORD Fsid;				/* File system mount ID */
 
-#if _FS_RPATH && _VOLUMES >= 2
+#if FF_FS_RPATH && FF_VOLUMES >= 2
 static BYTE CurrVol;			/* Current drive */
 #endif
 
-#if _FS_LOCK
-static FILESEM Files[_FS_LOCK];	/* Open object lock semaphores */
-#endif
-
-#if _USE_LFN == 0			/* Non LFN feature */
+#if FF_FS_LOCK != 0
+static FILESEM Files[FF_FS_LOCK];	/* Open object lock semaphores */
+#endif
+
+#if FF_USE_LFN == 0			/* Non LFN feature */
 #define	DEFINE_NAMEBUF		BYTE sfn[12]
 #define INIT_BUF(dobj)		(dobj).fn = sfn
 #define	FREE_BUF()
 #else
-#if _MAX_LFN < 12 || _MAX_LFN > 255
-#error Wrong _MAX_LFN setting
-#endif
-#if _USE_LFN == 1			/* LFN feature with static working buffer */
-static WCHAR LfnBuf[_MAX_LFN + 1];
+#if FF_MAX_LFN < 12 || FF_MAX_LFN > 255
+#error Wrong FF_MAX_LFN setting
+#endif
+#if FF_USE_LFN == 1			/* LFN feature with static working buffer */
+static WCHAR LfnBuf[FF_MAX_LFN + 1];
 #define	DEFINE_NAMEBUF		BYTE sfn[12]
 #define INIT_BUF(dobj)		{ (dobj).fn = sfn; (dobj).lfn = LfnBuf; }
 #define	FREE_BUF()
-#elif _USE_LFN == 2 		/* LFN feature with dynamic working buffer on the stack */
-#define	DEFINE_NAMEBUF		BYTE sfn[12]; WCHAR lbuf[_MAX_LFN + 1]
+#elif FF_USE_LFN == 2 		/* LFN feature with dynamic working buffer on the stack */
+#define	DEFINE_NAMEBUF		BYTE sfn[12]; WCHAR lbuf[FF_MAX_LFN + 1]
 #define INIT_BUF(dobj)		{ (dobj).fn = sfn; (dobj).lfn = lbuf; }
 #define	FREE_BUF()
-#elif _USE_LFN == 3 		/* LFN feature with dynamic working buffer on the heap */
+#elif FF_USE_LFN == 3 		/* LFN feature with dynamic working buffer on the heap */
 #define	DEFINE_NAMEBUF		BYTE sfn[12]; WCHAR *lfn
-#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; }
+#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; }
 #define	FREE_BUF()			ff_memfree(lfn)
 #else
-#error Wrong _USE_LFN setting
+#error Wrong FF_USE_LFN setting
 #endif
 #endif
@@ -598,5 +598,5 @@
 	const BYTE *s = (const BYTE*)src;
 
-#if _WORD_ACCESS == 1
+#if FF_WORD_ACCESS == 1
 	while (cnt >= sizeof (int)) {
 		*(int*)d = *(int*)s;
@@ -641,5 +641,5 @@
 /* Request/Release grant to access the volume                            */
 /*-----------------------------------------------------------------------*/
-#if _FS_REENTRANT
+#if FF_FS_REENTRANT
 static
 int lock_fs (
@@ -673,9 +673,9 @@
 /* File lock control functions                                           */
 /*-----------------------------------------------------------------------*/
-#if _FS_LOCK
+#if FF_FS_LOCK != 0
 
 static
 FRESULT chk_lock (	/* Check if the file can be accessed */
-	DIR* dp,		/* Directory object pointing the file to be checked */
+	FATFS_DIR* dp,		/* Directory object pointing the file to be checked */
 	int acc			/* Desired access type (0:Read, 1:Write, 2:Delete/Rename) */
 )
@@ -684,5 +684,5 @@
 
 	/* Search file semaphore table */
-	for (i = be = 0; i < _FS_LOCK; i++) {
+	for (i = be = 0; i < FF_FS_LOCK; i++) {
 		if (Files[i].fs) {	/* Existing entry */
 			if (Files[i].fs == dp->fs &&	 	/* Check if the object matched with an open object */
@@ -693,5 +693,5 @@
 		}
 	}
-	if (i == _FS_LOCK)	/* The object is not opened */
+	if (i == FF_FS_LOCK)	/* The object is not opened */
 		return (be || acc == 2) ? FR_OK : FR_TOO_MANY_OPEN_FILES;	/* Is there a blank entry for new object? */
 
@@ -706,6 +706,6 @@
 	UINT i;
 
-	for (i = 0; i < _FS_LOCK && Files[i].fs; i++) ;
-	return (i == _FS_LOCK) ? 0 : 1;
+	for (i = 0; i < FF_FS_LOCK && Files[i].fs; i++) ;
+	return (i == FF_FS_LOCK) ? 0 : 1;
 }
 
@@ -713,5 +713,5 @@
 static
 UINT inc_lock (	/* Increment object open counter and returns its index (0:Internal error) */
-	DIR* dp,	/* Directory object pointing the file to register or increment */
+	FATFS_DIR* dp,	/* Directory object pointing the file to register or increment */
 	int acc		/* Desired access (0:Read, 1:Write, 2:Delete/Rename) */
 )
@@ -720,5 +720,5 @@
 
 
-	for (i = 0; i < _FS_LOCK; i++) {	/* Find the object */
+	for (i = 0; i < FF_FS_LOCK; i++) {	/* Find the object */
 		if (Files[i].fs == dp->fs &&
 			Files[i].clu == dp->sclust &&
@@ -726,7 +726,7 @@
 	}
 
-	if (i == _FS_LOCK) {				/* Not opened. Register it as new. */
-		for (i = 0; i < _FS_LOCK && Files[i].fs; i++) ;
-		if (i == _FS_LOCK) return 0;	/* No free entry to register (int err) */
+	if (i == FF_FS_LOCK) {				/* Not opened. Register it as new. */
+		for (i = 0; i < FF_FS_LOCK && Files[i].fs; i++) ;
+		if (i == FF_FS_LOCK) return 0;	/* No free entry to register (int err) */
 		Files[i].fs = dp->fs;
 		Files[i].clu = dp->sclust;
@@ -752,5 +752,5 @@
 
 
-	if (--i < _FS_LOCK) {	/* Shift index number origin from 0 */
+	if (--i < FF_FS_LOCK) {	/* Shift index number origin from 0 */
 		n = Files[i].ctr;
 		if (n == 0x100) n = 0;		/* If write mode open, delete the entry */
@@ -773,5 +773,5 @@
 	UINT i;
 
-	for (i = 0; i < _FS_LOCK; i++) {
+	for (i = 0; i < FF_FS_LOCK; i++) {
 		if (Files[i].fs == fs) Files[i].fs = 0;
 	}
@@ -785,5 +785,5 @@
 /* Move/Flush disk access window in the file system object               */
 /*-----------------------------------------------------------------------*/
-#if !_FS_READONLY
+#if !FF_FS_READONLY
 static
 FRESULT sync_window (	/* FR_OK:succeeded, !=0:error */
@@ -825,5 +825,5 @@
 
 	if (sector != fs->winsect) {	/* Window offset changed? */
-#if !_FS_READONLY
+#if !FF_FS_READONLY
 		res = sync_window(fs);		/* Write-back changes */
 #endif
@@ -845,5 +845,5 @@
 /* Synchronize file system and strage device                             */
 /*-----------------------------------------------------------------------*/
-#if !_FS_READONLY
+#if !FF_FS_READONLY
 static
 FRESULT sync_fs (	/* FR_OK:succeeded, !=0:error */
@@ -959,5 +959,5 @@
 /* Hidden API for hacks and disk tools */
 
-#if !_FS_READONLY
+#if !FF_FS_READONLY
 FRESULT put_fat (	/* FR_OK(0):succeeded, !=0:error */
 	FATFS* fs,		/* File system object */
@@ -1014,5 +1014,5 @@
 	return res;
 }
-#endif /* !_FS_READONLY */
+#endif /* !FF_FS_READONLY */
 
 
@@ -1022,5 +1022,5 @@
 /* FAT handling - Remove a cluster chain                                 */
 /*-----------------------------------------------------------------------*/
-#if !_FS_READONLY
+#if !FF_FS_READONLY
 static
 FRESULT remove_chain (	/* FR_OK(0):succeeded, !=0:error */
@@ -1031,5 +1031,5 @@
 	FRESULT res;
 	DWORD nxt;
-#if _USE_TRIM
+#if FF_USE_TRIM
 	DWORD scl = clst, ecl = clst, rt[2];
 #endif
@@ -1051,5 +1051,5 @@
 				fs->fsi_flag |= 1;
 			}
-#if _USE_TRIM
+#if FF_USE_TRIM
 			if (ecl + 1 == nxt) {	/* Is next cluster contiguous? */
 				ecl = nxt;
@@ -1075,5 +1075,5 @@
 /* FAT handling - Stretch or Create a cluster chain                      */
 /*-----------------------------------------------------------------------*/
-#if !_FS_READONLY
+#if !FF_FS_READONLY
 static
 DWORD create_chain (	/* 0:No free cluster, 1:Internal error, 0xFFFFFFFF:Disk error, >=2:New cluster# */
@@ -1128,5 +1128,5 @@
 	return ncl;		/* Return new cluster number or error code */
 }
-#endif /* !_FS_READONLY */
+#endif /* !FF_FS_READONLY */
 
 
@@ -1137,5 +1137,5 @@
 /*-----------------------------------------------------------------------*/
 
-#if _USE_FASTSEEK
+#if FF_USE_FASTSEEK
 static
 DWORD clmt_clust (	/* <2:Error, >=2:Cluster number */
@@ -1157,5 +1157,5 @@
 	return cl + *tbl;	/* Return the cluster number */
 }
-#endif	/* _USE_FASTSEEK */
+#endif	/* FF_USE_FASTSEEK */
 
 
@@ -1168,5 +1168,5 @@
 static
 FRESULT dir_sdi (	/* FR_OK(0):succeeded, !=0:error */
-	DIR* dp,		/* Pointer to directory object */
+	FATFS_DIR* dp,		/* Pointer to directory object */
 	UINT idx		/* Index of directory table */
 )
@@ -1216,5 +1216,5 @@
 static
 FRESULT dir_next (	/* FR_OK(0):succeeded, FR_NO_FILE:End of table, FR_DENIED:Could not stretch */
-	DIR* dp,		/* Pointer to the directory object */
+	FATFS_DIR* dp,		/* Pointer to the directory object */
 	int stretch		/* 0: Do not stretch table, 1: Stretch table if needed */
 )
@@ -1222,5 +1222,5 @@
 	DWORD clst;
 	UINT i;
-#if !_FS_READONLY
+#if !FF_FS_READONLY
 	UINT c;
 #endif
@@ -1244,5 +1244,5 @@
 				if (clst == 0xFFFFFFFF) return FR_DISK_ERR;
 				if (clst >= dp->fs->n_fatent) {					/* If it reached end of dynamic table, */
-#if !_FS_READONLY
+#if !FF_FS_READONLY
 					if (!stretch) return FR_NO_FILE;			/* If do not stretch, report EOT */
 					clst = create_chain(dp->fs, dp->clust);		/* Stretch cluster chain */
@@ -1284,8 +1284,8 @@
 /*-----------------------------------------------------------------------*/
 
-#if !_FS_READONLY
+#if !FF_FS_READONLY
 static
 FRESULT dir_alloc (	/* FR_OK(0):succeeded, !=0:error */
-	DIR* dp,		/* Pointer to the directory object */
+	FATFS_DIR* dp,		/* Pointer to the directory object */
 	UINT nent		/* Number of contiguous entries to allocate (1-21) */
 )
@@ -1337,5 +1337,5 @@
 
 
-#if !_FS_READONLY
+#if !FF_FS_READONLY
 static
 void st_clust (
@@ -1355,5 +1355,5 @@
 /* LFN handling - Test/Pick/Fit an LFN segment from/to directory entry   */
 /*-----------------------------------------------------------------------*/
-#if _USE_LFN
+#if FF_USE_LFN
 static
 const BYTE LfnOfs[] = {1,3,5,7,9,14,16,18,20,22,24,28,30};	/* Offset of LFN characters in the directory entry */
@@ -1377,5 +1377,5 @@
 		uc = LD_WORD(dir + LfnOfs[s]);		/* Pick an LFN character */
 		if (wc) {
-			if (i >= _MAX_LFN || ff_wtoupper(uc) != ff_wtoupper(lfnbuf[i++]))	/* Compare it */
+			if (i >= FF_MAX_LFN || ff_wtoupper(uc) != ff_wtoupper(lfnbuf[i++]))	/* Compare it */
 				return 0;					/* Not matched */
 			wc = uc;
@@ -1410,5 +1410,5 @@
 		uc = LD_WORD(dir + LfnOfs[s]);		/* Pick an LFN character */
 		if (wc) {
-			if (i >= _MAX_LFN) return 0;	/* Buffer overflow? */
+			if (i >= FF_MAX_LFN) return 0;	/* Buffer overflow? */
 			lfnbuf[i++] = wc = uc;			/* Store it */
 		} else {
@@ -1418,5 +1418,5 @@
 
 	if (dir[LDIR_Ord] & LLEF) {				/* Put terminator if it is the last LFN part */
-		if (i >= _MAX_LFN) return 0;		/* Buffer overflow? */
+		if (i >= FF_MAX_LFN) return 0;		/* Buffer overflow? */
 		lfnbuf[i] = 0;
 	}
@@ -1426,5 +1426,5 @@
 
 
-#if !_FS_READONLY
+#if !FF_FS_READONLY
 static
 void fit_lfn (
@@ -1464,5 +1464,5 @@
 /* Create numbered name                                                  */
 /*-----------------------------------------------------------------------*/
-#if _USE_LFN
+#if FF_USE_LFN
 static
 void gen_numname (
@@ -1523,5 +1523,5 @@
 /* Calculate checksum of an SFN entry                                    */
 /*-----------------------------------------------------------------------*/
-#if _USE_LFN
+#if FF_USE_LFN
 static
 BYTE sum_sfn (
@@ -1546,10 +1546,10 @@
 static
 FRESULT dir_find (	/* FR_OK(0):succeeded, !=0:error */
-	DIR* dp			/* Pointer to the directory object linked to the file name */
+	FATFS_DIR* dp			/* Pointer to the directory object linked to the file name */
 )
 {
 	FRESULT res;
 	BYTE c, *dir;
-#if _USE_LFN
+#if FF_USE_LFN
 	BYTE a, ord, sum;
 #endif
@@ -1558,5 +1558,5 @@
 	if (res != FR_OK) return res;
 
-#if _USE_LFN
+#if FF_USE_LFN
 	ord = sum = 0xFF; dp->lfn_idx = 0xFFFF;	/* Reset LFN sequence */
 #endif
@@ -1567,5 +1567,5 @@
 		c = dir[DIR_Name];
 		if (c == 0) { res = FR_NO_FILE; break; }	/* Reached to end of table */
-#if _USE_LFN	/* LFN configuration */
+#if FF_USE_LFN	/* LFN configuration */
 		a = dir[DIR_Attr] & AM_MASK;
 		if (c == DDEM || ((a & AM_VOL) && a != AM_LFN)) {	/* An entry without valid data */
@@ -1604,8 +1604,8 @@
 /* Read an object from the directory                                     */
 /*-----------------------------------------------------------------------*/
-#if _FS_MINIMIZE <= 1 || _USE_LABEL || _FS_RPATH >= 2
+#if FF_FS_MINIMIZE <= 1 || FF_USE_LABEL || FF_FS_RPATH >= 2
 static
 FRESULT dir_read (
-	DIR* dp,		/* Pointer to the directory object */
+	FATFS_DIR* dp,		/* Pointer to the directory object */
 	int vol			/* Filtered by 0:file/directory or 1:volume label */
 )
@@ -1613,5 +1613,5 @@
 	FRESULT res;
 	BYTE a, c, *dir;
-#if _USE_LFN
+#if FF_USE_LFN
 	BYTE ord = 0xFF, sum = 0xFF;
 #endif
@@ -1625,6 +1625,6 @@
 		if (c == 0) { res = FR_NO_FILE; break; }	/* Reached to end of table */
 		a = dir[DIR_Attr] & AM_MASK;
-#if _USE_LFN	/* LFN configuration */
-		if (c == DDEM || (!_FS_RPATH && c == '.') || (int)((a & ~AM_ARC) == AM_VOL) != vol) {	/* An entry without valid data */
+#if FF_USE_LFN	/* LFN configuration */
+		if (c == DDEM || (!FF_FS_RPATH && c == '.') || (int)((a & ~AM_ARC) == AM_VOL) != vol) {	/* An entry without valid data */
 			ord = 0xFF;
 		} else {
@@ -1644,5 +1644,5 @@
 		}
 #else		/* Non LFN configuration */
-		if (c != DDEM && (_FS_RPATH || c != '.') && a != AM_LFN && (int)((a & ~AM_ARC) == AM_VOL) == vol)	/* Is it a valid entry? */
+		if (c != DDEM && (FF_FS_RPATH || c != '.') && a != AM_LFN && (int)((a & ~AM_ARC) == AM_VOL) == vol)	/* Is it a valid entry? */
 			break;
 #endif
@@ -1655,5 +1655,5 @@
 	return res;
 }
-#endif	/* _FS_MINIMIZE <= 1 || _USE_LABEL || _FS_RPATH >= 2 */
+#endif	/* FF_FS_MINIMIZE <= 1 || FF_USE_LABEL || FF_FS_RPATH >= 2 */
 
 
@@ -1663,12 +1663,12 @@
 /* Register an object to the directory                                   */
 /*-----------------------------------------------------------------------*/
-#if !_FS_READONLY
+#if !FF_FS_READONLY
 static
 FRESULT dir_register (	/* FR_OK:succeeded, FR_DENIED:no free entry or too many SFN collision, FR_DISK_ERR:disk error */
-	DIR* dp				/* Target directory with object name to be created */
+	FATFS_DIR* dp				/* Target directory with object name to be created */
 )
 {
 	FRESULT res;
-#if _USE_LFN	/* LFN configuration */
+#if FF_USE_LFN	/* LFN configuration */
 	UINT n, nent;
 	BYTE sn[12], *fn, sum;
@@ -1679,5 +1679,5 @@
 	mem_cpy(sn, fn, 12);
 
-	if (_FS_RPATH && (sn[NSFLAG] & NS_DOT))		/* Cannot create dot entry */
+	if (FF_FS_RPATH && (sn[NSFLAG] & NS_DOT))		/* Cannot create dot entry */
 		return FR_INVALID_NAME;
 
@@ -1724,5 +1724,5 @@
 			mem_set(dp->dir, 0, SZ_DIRE);	/* Clean the entry */
 			mem_cpy(dp->dir, dp->fn, 11);	/* Put SFN */
-#if _USE_LFN
+#if FF_USE_LFN
 			dp->dir[DIR_NTres] = dp->fn[NSFLAG] & (NS_BODY | NS_EXT);	/* Put NT flag */
 #endif
@@ -1733,5 +1733,5 @@
 	return res;
 }
-#endif /* !_FS_READONLY */
+#endif /* !FF_FS_READONLY */
 
 
@@ -1741,12 +1741,12 @@
 /* Remove an object from the directory                                   */
 /*-----------------------------------------------------------------------*/
-#if !_FS_READONLY && !_FS_MINIMIZE
+#if !FF_FS_READONLY && !FF_FS_MINIMIZE
 static
 FRESULT dir_remove (	/* FR_OK:Succeeded, FR_DISK_ERR:A disk error */
-	DIR* dp				/* Directory object pointing the entry to be removed */
+	FATFS_DIR* dp				/* Directory object pointing the entry to be removed */
 )
 {
 	FRESULT res;
-#if _USE_LFN	/* LFN configuration */
+#if FF_USE_LFN	/* LFN configuration */
 	UINT i;
 
@@ -1780,5 +1780,5 @@
 	return res;
 }
-#endif /* !_FS_READONLY */
+#endif /* !FF_FS_READONLY */
 
 
@@ -1788,8 +1788,8 @@
 /* Get file information from directory entry                             */
 /*-----------------------------------------------------------------------*/
-#if _FS_MINIMIZE <= 1 || _FS_RPATH >= 2
+#if FF_FS_MINIMIZE <= 1 || FF_FS_RPATH >= 2
 static
 void get_fileinfo (		/* No return code */
-	DIR* dp,			/* Pointer to the directory object */
+	FATFS_DIR* dp,			/* Pointer to the directory object */
 	FILINFO* fno	 	/* Pointer to the file information to be filled */
 )
@@ -1798,8 +1798,8 @@
 	TCHAR *p, c;
 	BYTE *dir;
-#if _USE_LFN
+#if FF_USE_LFN
 	WCHAR w, *lfn;
 #endif
-#if _CODE_PAGE == 65001
+#if FF_CODE_PAGE == 65001
 	unsigned char utf8_code[6];
 	int code_size;
@@ -1815,8 +1815,8 @@
 			if (c == RDDEM) c = (TCHAR)DDEM;	/* Restore replaced DDEM character */
 			if (i == 9) *p++ = '.';				/* Insert a . if extension is exist */
-#if _USE_LFN
+#if FF_USE_LFN
 			if (IsUpper(c) && (dir[DIR_NTres] & (i >= 9 ? NS_EXT : NS_BODY)))
 				c += 0x20;			/* To lower */
-#if _LFN_UNICODE
+#if FF_LFN_UNICODE
 			if (IsDBCS1(c) && i != 8 && i != 11 && IsDBCS2(dir[i]))
 				c = c << 8 | dir[i++];
@@ -1834,5 +1834,5 @@
 	*p = 0;		/* Terminate SFN string by a \0 */
 
-#if _USE_LFN
+#if FF_USE_LFN
 	if (fno->lfname) {
 		i = 0; p = fno->lfname;
@@ -1840,6 +1840,6 @@
 			lfn = dp->lfn;
 			while ((w = *lfn++) != 0) {		/* Get an LFN character */
-#if !_LFN_UNICODE
-#if _CODE_PAGE == 65001
+#if !FF_LFN_UNICODE
+#if FF_CODE_PAGE == 65001
 				Utf16_to_Utf8(utf8_code, &code_size, w);
 				for (int j = 0; j < code_size - 1; j++) {
@@ -1862,5 +1862,5 @@
 #endif
 }
-#endif /* _FS_MINIMIZE <= 1 || _FS_RPATH >= 2 */
+#endif /* FF_FS_MINIMIZE <= 1 || FF_FS_RPATH >= 2 */
 
 
@@ -1870,5 +1870,5 @@
 /* Pattern matching                                                      */
 /*-----------------------------------------------------------------------*/
-#if _USE_FIND && _FS_MINIMIZE <= 1
+#if FF_USE_FIND && FF_FS_MINIMIZE <= 1
 static
 WCHAR get_achar (		/* Get a character and advances ptr 1 or 2 */
@@ -1878,6 +1878,6 @@
 	WCHAR chr;
 
-#if !_LFN_UNICODE
-#if _CODE_PAGE == 65001
+#if !FF_LFN_UNICODE
+#if FF_CODE_PAGE == 65001
 	int code_size;
 	chr = Utf8_to_Utf16(*ptr, &code_size);
@@ -1938,5 +1938,5 @@
 	return 0;
 }
-#endif /* _USE_FIND && _FS_MINIMIZE <= 1 */
+#endif /* FF_USE_FIND && FF_FS_MINIMIZE <= 1 */
 
 
@@ -1949,14 +1949,14 @@
 static
 FRESULT create_name (	/* FR_OK: successful, FR_INVALID_NAME: could not create */
-	DIR* dp,			/* Pointer to the directory object */
+	FATFS_DIR* dp,			/* Pointer to the directory object */
 	const TCHAR** path	/* Pointer to pointer to the segment in the path string */
 )
 {
-#if _USE_LFN	/* LFN configuration */
+#if FF_USE_LFN	/* LFN configuration */
 	BYTE b, cf;
 	WCHAR w, *lfn;
 	UINT i, ni, si, di;
 	const TCHAR *p;
-#if _CODE_PAGE == 65001
+#if FF_CODE_PAGE == 65001
 	unsigned char utf8_code[6];
 	int code_size;
@@ -1969,8 +1969,8 @@
 		w = p[si++];					/* Get a character */
 		if (w < ' ' || w == '/' || w == '\\') break;	/* Break on end of segment */
-		if (di >= _MAX_LFN)				/* Reject too long name */
+		if (di >= FF_MAX_LFN)				/* Reject too long name */
 			return FR_INVALID_NAME;
-#if !_LFN_UNICODE
-#if _CODE_PAGE == 65001
+#if !FF_LFN_UNICODE
+#if FF_CODE_PAGE == 65001
 		w = Utf8_to_Utf16(&p[si - 1], &code_size);
 		si += code_size - 1;
@@ -1993,5 +1993,5 @@
 	*path = &p[si];						/* Return pointer to the next segment */
 	cf = (w < ' ') ? NS_LAST : 0;		/* Set last segment flag if end of path */
-#if _FS_RPATH
+#if FF_FS_RPATH
 	if ((di == 1 && lfn[di - 1] == '.') ||
 		(di == 2 && lfn[di - 1] == '.' && lfn[di - 2] == '.')) {	/* Is this segment a dot entry? */
@@ -2040,5 +2040,5 @@
 			if (w) w = ExCvt[w - 0x80];	/* Convert extended character to upper (SBCS) */
 #else
-#if _CODE_PAGE == 65001
+#if FF_CODE_PAGE == 65001
 			Utf16_to_Utf8(utf8_code, &code_size, ff_wtoupper(w));
 #else
@@ -2048,10 +2048,10 @@
 			cf |= NS_LFN;				/* Force create LFN entry */
 		}
-#if _CODE_PAGE == 65001
+#if FF_CODE_PAGE == 65001
 		else
 			code_size = 1;
 #endif
 
-#if _CODE_PAGE == 65001
+#if FF_CODE_PAGE == 65001
 		if (code_size > 1) {		/* Is this DBC? (always false at SBCS cfg) */
 			if (i >= ni - 1) {
@@ -2126,5 +2126,5 @@
 	mem_set(sfn, ' ', 11);
 	si = i = b = 0; ni = 8;
-#if _FS_RPATH
+#if FF_FS_RPATH
 	if (p[si] == '.') { /* Is this a dot entry? */
 		for (;;) {
@@ -2201,5 +2201,5 @@
 static
 FRESULT follow_path (	/* FR_OK(0): successful, !=0: error code */
-	DIR* dp,			/* Directory object to return last directory and found object */
+	FATFS_DIR* dp,			/* Directory object to return last directory and found object */
 	const TCHAR* path	/* Full-path string to find a file or directory */
 )
@@ -2209,5 +2209,5 @@
 
 
-#if _FS_RPATH
+#if FF_FS_RPATH
 	if (*path == '/' || *path == '\\') {	/* There is a heading separator */
 		path++;	dp->sclust = 0;				/* Strip it and start from the root directory */
@@ -2232,5 +2232,5 @@
 			if (res != FR_OK) {				/* Failed to find the object */
 				if (res == FR_NO_FILE) {	/* Object is not found */
-					if (_FS_RPATH && (ns & NS_DOT)) {	/* If dot entry is not exist, */
+					if (FF_FS_RPATH && (ns & NS_DOT)) {	/* If dot entry is not exist, */
 						dp->sclust = 0; dp->dir = 0;	/* it is the root directory and stay there */
 						if (!(ns & NS_LAST)) continue;	/* Continue to follow if not last segment */
@@ -2269,6 +2269,6 @@
 	UINT i;
 	int vol = -1;
-#if _STR_VOLUME_ID		/* Find string drive id */
-	static const char* const str[] = {_VOLUME_STRS};
+#if FF_STR_VOLUME_ID		/* Find string drive id */
+	static const char* const str[] = {FF_VOLUME_STRS};
 	const char *sp;
 	char c;
@@ -2278,15 +2278,15 @@
 
 	if (*path) {	/* If the pointer is not a null */
-		for (tt = *path; (UINT)*tt >= (_USE_LFN ? ' ' : '!') && *tt != ':'; tt++) ;	/* Find ':' in the path */
+		for (tt = *path; (UINT)*tt >= (FF_USE_LFN ? ' ' : '!') && *tt != ':'; tt++) ;	/* Find ':' in the path */
 		if (*tt == ':') {	/* If a ':' is exist in the path name */
 			tp = *path;
 			i = *tp++ - '0'; 
 			if (i < 10 && tp == tt) {	/* Is there a numeric drive id? */
-				if (i < _VOLUMES) {	/* If a drive id is found, get the value and strip it */
+				if (i < FF_VOLUMES) {	/* If a drive id is found, get the value and strip it */
 					vol = (int)i;
 					*path = ++tt;
 				}
 			}
-#if _STR_VOLUME_ID
+#if FF_STR_VOLUME_ID
 			 else {	/* No numeric drive number, find string drive id */
 				i = 0; tt++;
@@ -2297,6 +2297,6 @@
 						if (IsLower(tc)) tc -= 0x20;
 					} while (c && (TCHAR)c == tc);
-				} while ((c || tp != tt) && ++i < _VOLUMES);	/* Repeat for each id until pattern match */
-				if (i < _VOLUMES) {	/* If a drive id is found, get the value and strip it */
+				} while ((c || tp != tt) && ++i < FF_VOLUMES);	/* Repeat for each id until pattern match */
+				if (i < FF_VOLUMES) {	/* If a drive id is found, get the value and strip it */
 					vol = (int)i;
 					*path = tt;
@@ -2306,5 +2306,5 @@
 			return vol;
 		}
-#if _FS_RPATH && _VOLUMES >= 2
+#if FF_FS_RPATH && FF_VOLUMES >= 2
 		vol = CurrVol;	/* Current drive */
 #else
@@ -2381,5 +2381,5 @@
 		stat = disk_status(fs->drv);
 		if (!(stat & STA_NOINIT)) {		/* and the physical drive is kept initialized */
-			if (!_FS_READONLY && wmode && (stat & STA_PROTECT))	/* Check write protection if needed */
+			if (!FF_FS_READONLY && wmode && (stat & STA_PROTECT))	/* Check write protection if needed */
 				return FR_WRITE_PROTECTED;
 			return FR_OK;				/* The file system object is valid */
@@ -2395,9 +2395,9 @@
 	if (stat & STA_NOINIT)				/* Check if the initialization succeeded */
 		return FR_NOT_READY;			/* Failed to initialize due to no medium or hard error */
-	if (!_FS_READONLY && wmode && (stat & STA_PROTECT))	/* Check disk write protection if needed */
+	if (!FF_FS_READONLY && wmode && (stat & STA_PROTECT))	/* Check disk write protection if needed */
 		return FR_WRITE_PROTECTED;
-#if _MAX_SS != _MIN_SS						/* Get sector size (multiple sector size cfg only) */
+#if FF_MAX_SS != FF_MIN_SS						/* Get sector size (multiple sector size cfg only) */
 	if (disk_ioctl(fs->drv, GET_SECTOR_SIZE, &SS(fs)) != RES_OK
-		|| SS(fs) < _MIN_SS || SS(fs) > _MAX_SS) return FR_DISK_ERR;
+		|| SS(fs) < FF_MIN_SS || SS(fs) > FF_MAX_SS) return FR_DISK_ERR;
 #endif
 	/* Find an FAT partition on the drive. Supports only generic partitioning, FDISK and SFD. */
@@ -2448,5 +2448,5 @@
 
 	/* Determine the FAT sub type */
-	sysect = nrsv + fasize + fs->n_rootdir / (SS(fs) / SZ_DIRE);	/* RSV + FAT + DIR */
+	sysect = nrsv + fasize + fs->n_rootdir / (SS(fs) / SZ_DIRE);	/* RSV + FAT + FATFS_DIR */
 	if (tsect < sysect) return FR_NO_FILESYSTEM;		/* (Invalid volume size) */
 	nclst = (tsect - sysect) / fs->csize;				/* Number of clusters */
@@ -2474,5 +2474,5 @@
 		return FR_NO_FILESYSTEM;
 
-#if !_FS_READONLY
+#if !FF_FS_READONLY
 	/* Initialize cluster allocation information */
 	fs->last_clust = fs->free_clust = 0xFFFFFFFF;
@@ -2480,5 +2480,5 @@
 	/* Get fsinfo if available */
 	fs->fsi_flag = 0x80;
-#if (_FS_NOFSINFO & 3) != 3
+#if (FF_FS_NOFSINFO & 3) != 3
 	if (fmt == FS_FAT32				/* Enable FSINFO only if FAT32 and BPB_FSInfo == 1 */
 		&& LD_WORD(fs->win + BPB_FSInfo) == 1
@@ -2490,8 +2490,8 @@
 			&& LD_DWORD(fs->win + FSI_StrucSig) == 0x61417272)
 		{
-#if (_FS_NOFSINFO & 1) == 0
+#if (FF_FS_NOFSINFO & 1) == 0
 			fs->free_clust = LD_DWORD(fs->win + FSI_Free_Count);
 #endif
-#if (_FS_NOFSINFO & 2) == 0
+#if (FF_FS_NOFSINFO & 2) == 0
 			fs->last_clust = LD_DWORD(fs->win + FSI_Nxt_Free);
 #endif
@@ -2502,8 +2502,8 @@
 	fs->fs_type = fmt;	/* FAT sub-type */
 	fs->id = ++Fsid;	/* File system mount ID */
-#if _FS_RPATH
+#if FF_FS_RPATH
 	fs->cdir = 0;		/* Set current directory to root */
 #endif
-#if _FS_LOCK			/* Clear file lock semaphores */
+#if FF_FS_LOCK != 0			/* Clear file lock semaphores */
 	clear_lock(fs);
 #endif
@@ -2521,8 +2521,8 @@
 static
 FRESULT validate (	/* FR_OK(0): The object is valid, !=0: Invalid */
-	void* obj		/* Pointer to the object FIL/DIR to check validity */
-)
-{
-	FIL *fil = (FIL*)obj;	/* Assuming offset of .fs and .id in the FIL/DIR structure is identical */
+	void* obj		/* Pointer to the object FIL/FATFS_DIR to check validity */
+)
+{
+	FIL *fil = (FIL*)obj;	/* Assuming offset of .fs and .id in the FIL/FATFS_DIR structure is identical */
 
 
@@ -2567,8 +2567,8 @@
 
 	if (cfs) {
-#if _FS_LOCK
+#if FF_FS_LOCK != 0
 		clear_lock(cfs);
 #endif
-#if _FS_REENTRANT						/* Discard sync object of the current volume */
+#if FF_FS_REENTRANT						/* Discard sync object of the current volume */
 		if (!ff_del_syncobj(cfs->sobj)) return FR_INT_ERR;
 #endif
@@ -2578,5 +2578,5 @@
 	if (fs) {
 		fs->fs_type = 0;				/* Clear new fs object */
-#if _FS_REENTRANT						/* Create sync object for the new volume */
+#if FF_FS_REENTRANT						/* Create sync object for the new volume */
 		if (!ff_cre_syncobj((BYTE)vol, &fs->sobj)) return FR_INT_ERR;
 #endif
@@ -2604,8 +2604,8 @@
 {
 	FRESULT res;
-	DIR dj;
+	FATFS_DIR dj;
 	BYTE *dir;
 	DEFINE_NAMEBUF;
-#if !_FS_READONLY
+#if !FF_FS_READONLY
 	DWORD dw, cl;
 #endif
@@ -2616,6 +2616,6 @@
 
 	/* Get logical drive number */
-#if !_FS_READONLY
-	mode &= FA_READ | FA_WRITE | FA_CREATE_ALWAYS | FA_OPEN_ALWAYS | FA_CREATE_NEW;
+#if !FF_FS_READONLY
+	mode &= FA_READ | FA_WRITE | FA_CREATE_ALWAYS | FA_OPEN_ALWAYS | FA_CREATE_NEW | FA_OPEN_APPEND;
 	res = find_volume(&dj.fs, &path, (BYTE)(mode & ~FA_READ));
 #else
@@ -2627,9 +2627,9 @@
 		res = follow_path(&dj, path);	/* Follow the file path */
 		dir = dj.dir;
-#if !_FS_READONLY	/* R/W configuration */
+#if !FF_FS_READONLY	/* R/W configuration */
 		if (res == FR_OK) {
 			if (!dir)	/* Default directory itself */
 				res = FR_INVALID_NAME;
-#if _FS_LOCK
+#if FF_FS_LOCK != 0
 			else
 				res = chk_lock(&dj, (mode & ~FA_READ) ? 1 : 0);
@@ -2640,5 +2640,5 @@
 			if (res != FR_OK) {					/* No file, create new */
 				if (res == FR_NO_FILE)			/* There is no file to open, create a new entry */
-#if _FS_LOCK
+#if FF_FS_LOCK != 0
 					res = enq_lock() ? dir_register(&dj) : FR_TOO_MANY_OPEN_FILES;
 #else
@@ -2649,5 +2649,5 @@
 			}
 			else {								/* Any object is already existing */
-				if (dir[DIR_Attr] & (AM_RDO | AM_DIR)) {	/* Cannot overwrite it (R/O or DIR) */
+				if (dir[DIR_Attr] & (AM_RDO | AM_DIR)) {	/* Cannot overwrite it (R/O or FATFS_DIR) */
 					res = FR_DENIED;
 				} else {
@@ -2687,8 +2687,8 @@
 		if (res == FR_OK) {
 			if (mode & FA_CREATE_ALWAYS)		/* Set file change flag if created or overwritten */
-				mode |= FA__WRITTEN;
+				mode |= FA_MODIFIED;
 			fp->dir_sect = dj.fs->winsect;		/* Pointer to the directory entry */
 			fp->dir_ptr = dir;
-#if _FS_LOCK
+#if FF_FS_LOCK != 0
 			fp->lockid = inc_lock(&dj, (mode & ~FA_READ) ? 1 : 0);
 			if (!fp->lockid) res = FR_INT_ERR;
@@ -2716,5 +2716,5 @@
 			fp->fptr = 0;						/* File pointer */
 			fp->dsect = 0;
-#if _USE_FASTSEEK
+#if FF_USE_FASTSEEK
 			fp->cltbl = 0;						/* Normal seek mode */
 #endif
@@ -2766,5 +2766,5 @@
 					clst = fp->sclust;			/* Follow from the origin */
 				} else {						/* Middle or end of the file */
-#if _USE_FASTSEEK
+#if FF_USE_FASTSEEK
 					if (fp->cltbl)
 						clst = clmt_clust(fp, fp->fptr);	/* Get cluster# from the CLMT */
@@ -2786,10 +2786,10 @@
 				if (disk_read(fp->fs->drv, rbuff, sect, cc) != RES_OK)
 					ABORT(fp->fs, FR_DISK_ERR);
-#if !_FS_READONLY && _FS_MINIMIZE <= 2			/* Replace one of the read sectors with cached data if it contains a dirty sector */
-#if _FS_TINY
+#if !FF_FS_READONLY && FF_FS_MINIMIZE <= 2			/* Replace one of the read sectors with cached data if it contains a dirty sector */
+#if FF_FS_TINY
 				if (fp->fs->wflag && fp->fs->winsect - sect < cc)
 					mem_cpy(rbuff + ((fp->fs->winsect - sect) * SS(fp->fs)), fp->fs->win, SS(fp->fs));
 #else
-				if ((fp->flag & FA__DIRTY) && fp->dsect - sect < cc)
+				if ((fp->flag & FA_DIRTY) && fp->dsect - sect < cc)
 					mem_cpy(rbuff + ((fp->dsect - sect) * SS(fp->fs)), fp->buf, SS(fp->fs));
 #endif
@@ -2798,11 +2798,11 @@
 				continue;
 			}
-#if !_FS_TINY
+#if !FF_FS_TINY
 			if (fp->dsect != sect) {			/* Load data sector if not in cache */
-#if !_FS_READONLY
-				if (fp->flag & FA__DIRTY) {		/* Write-back dirty sector cache */
+#if !FF_FS_READONLY
+				if (fp->flag & FA_DIRTY) {		/* Write-back dirty sector cache */
 					if (disk_write(fp->fs->drv, fp->buf, fp->dsect, 1) != RES_OK)
 						ABORT(fp->fs, FR_DISK_ERR);
-					fp->flag &= ~FA__DIRTY;
+					fp->flag &= ~FA_DIRTY;
 				}
 #endif
@@ -2815,5 +2815,5 @@
 		rcnt = SS(fp->fs) - ((UINT)fp->fptr % SS(fp->fs));	/* Get partial sector data from sector buffer */
 		if (rcnt > btr) rcnt = btr;
-#if _FS_TINY
+#if FF_FS_TINY
 		if (move_window(fp->fs, fp->dsect) != FR_OK)		/* Move sector window */
 			ABORT(fp->fs, FR_DISK_ERR);
@@ -2830,5 +2830,5 @@
 
 
-#if !_FS_READONLY
+#if !FF_FS_READONLY
 /*-----------------------------------------------------------------------*/
 /* Write File                                                            */
@@ -2869,5 +2869,5 @@
 						clst = create_chain(fp->fs, 0);	/* Create a new cluster chain */
 				} else {					/* Middle or end of the file */
-#if _USE_FASTSEEK
+#if FF_USE_FASTSEEK
 					if (fp->cltbl)
 						clst = clmt_clust(fp, fp->fptr);	/* Get cluster# from the CLMT */
@@ -2882,12 +2882,12 @@
 				if (fp->sclust == 0) fp->sclust = clst;	/* Set start cluster if the first write */
 			}
-#if _FS_TINY
+#if FF_FS_TINY
 			if (fp->fs->winsect == fp->dsect && sync_window(fp->fs))	/* Write-back sector cache */
 				ABORT(fp->fs, FR_DISK_ERR);
 #else
-			if (fp->flag & FA__DIRTY) {		/* Write-back sector cache */
+			if (fp->flag & FA_DIRTY) {		/* Write-back sector cache */
 				if (disk_write(fp->fs->drv, fp->buf, fp->dsect, 1) != RES_OK)
 					ABORT(fp->fs, FR_DISK_ERR);
-				fp->flag &= ~FA__DIRTY;
+				fp->flag &= ~FA_DIRTY;
 			}
 #endif
@@ -2901,6 +2901,6 @@
 				if (disk_write(fp->fs->drv, wbuff, sect, cc) != RES_OK)
 					ABORT(fp->fs, FR_DISK_ERR);
-#if _FS_MINIMIZE <= 2
-#if _FS_TINY
+#if FF_FS_MINIMIZE <= 2
+#if FF_FS_TINY
 				if (fp->fs->winsect - sect < cc) {	/* Refill sector cache if it gets invalidated by the direct write */
 					mem_cpy(fp->fs->win, wbuff + ((fp->fs->winsect - sect) * SS(fp->fs)), SS(fp->fs));
@@ -2910,5 +2910,5 @@
 				if (fp->dsect - sect < cc) { /* Refill sector cache if it gets invalidated by the direct write */
 					mem_cpy(fp->buf, wbuff + ((fp->dsect - sect) * SS(fp->fs)), SS(fp->fs));
-					fp->flag &= ~FA__DIRTY;
+					fp->flag &= ~FA_DIRTY;
 				}
 #endif
@@ -2917,5 +2917,5 @@
 				continue;
 			}
-#if _FS_TINY
+#if FF_FS_TINY
 			if (fp->fptr >= fp->fsize) {	/* Avoid silly cache filling at growing edge */
 				if (sync_window(fp->fs)) ABORT(fp->fs, FR_DISK_ERR);
@@ -2933,5 +2933,5 @@
 		wcnt = SS(fp->fs) - ((UINT)fp->fptr % SS(fp->fs));/* Put partial sector into file I/O buffer */
 		if (wcnt > btw) wcnt = btw;
-#if _FS_TINY
+#if FF_FS_TINY
 		if (move_window(fp->fs, fp->dsect) != FR_OK)	/* Move sector window */
 			ABORT(fp->fs, FR_DISK_ERR);
@@ -2940,10 +2940,10 @@
 #else
 		mem_cpy(&fp->buf[fp->fptr % SS(fp->fs)], wbuff, wcnt);	/* Fit partial sector */
-		fp->flag |= FA__DIRTY;
+		fp->flag |= FA_DIRTY;
 #endif
 	}
 
 	if (fp->fptr > fp->fsize) fp->fsize = fp->fptr;	/* Update file size if needed */
-	fp->flag |= FA__WRITTEN;						/* Set file change flag */
+	fp->flag |= FA_MODIFIED;						/* Set file change flag */
 
 	LEAVE_FF(fp->fs, FR_OK);
@@ -2968,10 +2968,10 @@
 	res = validate(fp);					/* Check validity of the object */
 	if (res == FR_OK) {
-		if (fp->flag & FA__WRITTEN) {	/* Is there any change to the file? */
-#if !_FS_TINY
-			if (fp->flag & FA__DIRTY) {	/* Write-back cached data if needed */
+		if (fp->flag & FA_MODIFIED) {	/* Is there any change to the file? */
+#if !FF_FS_TINY
+			if (fp->flag & FA_DIRTY) {	/* Write-back cached data if needed */
 				if (disk_write(fp->fs->drv, fp->buf, fp->dsect, 1) != RES_OK)
 					LEAVE_FF(fp->fs, FR_DISK_ERR);
-				fp->flag &= ~FA__DIRTY;
+				fp->flag &= ~FA_DIRTY;
 			}
 #endif
@@ -2986,5 +2986,5 @@
 				ST_DWORD(dir + DIR_WrtTime, tm);
 				ST_WORD(dir + DIR_LstAccDate, 0);
-				fp->flag &= ~FA__WRITTEN;
+				fp->flag &= ~FA_MODIFIED;
 				fp->fs->wflag = 1;
 				res = sync_fs(fp->fs);
@@ -2996,5 +2996,5 @@
 }
 
-#endif /* !_FS_READONLY */
+#endif /* !FF_FS_READONLY */
 
 
@@ -3012,5 +3012,5 @@
 
 
-#if !_FS_READONLY
+#if !FF_FS_READONLY
 	res = f_sync(fp);					/* Flush cached data */
 	if (res == FR_OK)
@@ -3019,13 +3019,13 @@
 		res = validate(fp);				/* Lock volume */
 		if (res == FR_OK) {
-#if _FS_REENTRANT
+#if FF_FS_REENTRANT
 			FATFS *fs = fp->fs;
 #endif
-#if _FS_LOCK
+#if FF_FS_LOCK != 0
 			res = dec_lock(fp->lockid);	/* Decrement file open counter */
 			if (res == FR_OK)
 #endif
 				fp->fs = 0;				/* Invalidate file object */
-#if _FS_REENTRANT
+#if FF_FS_REENTRANT
 			unlock_fs(fs, FR_OK);		/* Unlock volume */
 #endif
@@ -3042,6 +3042,6 @@
 /*-----------------------------------------------------------------------*/
 
-#if _FS_RPATH >= 1
-#if _VOLUMES >= 2
+#if FF_FS_RPATH >= 1
+#if FF_VOLUMES >= 2
 FRESULT f_chdrive (
 	const TCHAR* path		/* Drive number */
@@ -3066,5 +3066,5 @@
 {
 	FRESULT res;
-	DIR dj;
+	FATFS_DIR dj;
 	DEFINE_NAMEBUF;
 
@@ -3093,5 +3093,5 @@
 
 
-#if _FS_RPATH >= 2
+#if FF_FS_RPATH >= 2
 FRESULT f_getcwd (
 	TCHAR* buff,	/* Pointer to the directory path */
@@ -3100,5 +3100,5 @@
 {
 	FRESULT res;
-	DIR dj;
+	FATFS_DIR dj;
 	UINT i, n;
 	DWORD ccl;
@@ -3131,5 +3131,5 @@
 			if (res == FR_NO_FILE) res = FR_INT_ERR;/* It cannot be 'not found'. */
 			if (res != FR_OK) break;
-#if _USE_LFN
+#if FF_USE_LFN
 			fno.lfname = buff;
 			fno.lfsize = i;
@@ -3137,5 +3137,5 @@
 			get_fileinfo(&dj, &fno);		/* Get the directory name and push it to the buffer */
 			tp = fno.fname;
-#if _USE_LFN
+#if FF_USE_LFN
 			if (*buff) tp = buff;
 #endif
@@ -3149,5 +3149,5 @@
 		tp = buff;
 		if (res == FR_OK) {
-#if _VOLUMES >= 2
+#if FF_VOLUMES >= 2
 			*tp++ = '0' + CurrVol;			/* Put drive number */
 			*tp++ = ':';
@@ -3167,10 +3167,10 @@
 	LEAVE_FF(dj.fs, res);
 }
-#endif /* _FS_RPATH >= 2 */
-#endif /* _FS_RPATH >= 1 */
-
-
-
-#if _FS_MINIMIZE <= 2
+#endif /* FF_FS_RPATH >= 2 */
+#endif /* FF_FS_RPATH >= 1 */
+
+
+
+#if FF_FS_MINIMIZE <= 2
 /*-----------------------------------------------------------------------*/
 /* Seek File R/W Pointer                                                 */
@@ -3184,5 +3184,5 @@
 	FRESULT res;
 	DWORD clst, bcs, nsect, ifptr;
-#if _USE_FASTSEEK
+#if FF_USE_FASTSEEK
 	DWORD cl, pcl, ncl, tcl, dsc, tlen, ulen, *tbl;
 #endif
@@ -3194,5 +3194,5 @@
 		LEAVE_FF(fp->fs, (FRESULT)fp->err);
 
-#if _USE_FASTSEEK
+#if FF_USE_FASTSEEK
 	if (fp->cltbl) {	/* Fast seek */
 		if (ofs == CREATE_LINKMAP) {	/* Create CLMT */
@@ -3231,10 +3231,10 @@
 				dsc += (ofs - 1) / SS(fp->fs) & (fp->fs->csize - 1);
 				if (fp->fptr % SS(fp->fs) && dsc != fp->dsect) {	/* Refill sector cache if needed */
-#if !_FS_TINY
-#if !_FS_READONLY
-					if (fp->flag & FA__DIRTY) {		/* Write-back dirty sector cache */
+#if !FF_FS_TINY
+#if !FF_FS_READONLY
+					if (fp->flag & FA_DIRTY) {		/* Write-back dirty sector cache */
 						if (disk_write(fp->fs->drv, fp->buf, fp->dsect, 1) != RES_OK)
 							ABORT(fp->fs, FR_DISK_ERR);
-						fp->flag &= ~FA__DIRTY;
+						fp->flag &= ~FA_DIRTY;
 					}
 #endif
@@ -3252,5 +3252,5 @@
 	{
 		if (ofs > fp->fsize					/* In read-only mode, clip offset with the file size */
-#if !_FS_READONLY
+#if !FF_FS_READONLY
 			 && !(fp->flag & FA_WRITE)
 #endif
@@ -3268,5 +3268,5 @@
 			} else {									/* When seek to back cluster, */
 				clst = fp->sclust;						/* start from the first cluster */
-#if !_FS_READONLY
+#if !FF_FS_READONLY
 				if (clst == 0) {						/* If no cluster chain, create a new chain */
 					clst = create_chain(fp->fs, 0);
@@ -3280,5 +3280,5 @@
 			if (clst != 0) {
 				while (ofs > bcs) {						/* Cluster following loop */
-#if !_FS_READONLY
+#if !FF_FS_READONLY
 					if (fp->flag & FA_WRITE) {			/* Check if in write mode or not */
 						clst = create_chain(fp->fs, clst);	/* Force stretch if in write mode */
@@ -3304,10 +3304,10 @@
 		}
 		if (fp->fptr % SS(fp->fs) && nsect != fp->dsect) {	/* Fill sector cache if needed */
-#if !_FS_TINY
-#if !_FS_READONLY
-			if (fp->flag & FA__DIRTY) {			/* Write-back dirty sector cache */
+#if !FF_FS_TINY
+#if !FF_FS_READONLY
+			if (fp->flag & FA_DIRTY) {			/* Write-back dirty sector cache */
 				if (disk_write(fp->fs->drv, fp->buf, fp->dsect, 1) != RES_OK)
 					ABORT(fp->fs, FR_DISK_ERR);
-				fp->flag &= ~FA__DIRTY;
+				fp->flag &= ~FA_DIRTY;
 			}
 #endif
@@ -3317,8 +3317,8 @@
 			fp->dsect = nsect;
 		}
-#if !_FS_READONLY
+#if !FF_FS_READONLY
 		if (fp->fptr > fp->fsize) {			/* Set file change flag if the file size is extended */
 			fp->fsize = fp->fptr;
-			fp->flag |= FA__WRITTEN;
+			fp->flag |= FA_MODIFIED;
 		}
 #endif
@@ -3342,5 +3342,5 @@
 }
 
-#if _FS_MINIMIZE <= 1
+#if FF_FS_MINIMIZE <= 1
 /*-----------------------------------------------------------------------*/
 /* Create a Directory Object                                             */
@@ -3348,5 +3348,5 @@
 
 FRESULT f_opendir (
-	DIR* dp,			/* Pointer to directory object to create */
+	FATFS_DIR* dp,			/* Pointer to directory object to create */
 	const TCHAR* path	/* Pointer to the directory path */
 )
@@ -3376,5 +3376,5 @@
 				dp->id = fs->id;
 				res = dir_sdi(dp, 0);			/* Rewind directory */
-#if _FS_LOCK
+#if FF_FS_LOCK != 0
 				if (res == FR_OK) {
 					if (dp->sclust) {
@@ -3404,5 +3404,5 @@
 
 FRESULT f_closedir (
-	DIR *dp		/* Pointer to the directory object to be closed */
+	FATFS_DIR *dp		/* Pointer to the directory object to be closed */
 )
 {
@@ -3412,8 +3412,8 @@
 	res = validate(dp);
 	if (res == FR_OK) {
-#if _FS_REENTRANT
+#if FF_FS_REENTRANT
 		FATFS *fs = dp->fs;
 #endif
-#if _FS_LOCK
+#if FF_FS_LOCK != 0
 		if (dp->lockid)				/* Decrement sub-directory open counter */
 			res = dec_lock(dp->lockid);
@@ -3421,5 +3421,5 @@
 #endif
 			dp->fs = 0;				/* Invalidate directory object */
-#if _FS_REENTRANT
+#if FF_FS_REENTRANT
 		unlock_fs(fs, FR_OK);		/* Unlock volume */
 #endif
@@ -3436,5 +3436,5 @@
 
 FRESULT f_readdir (
-	DIR* dp,			/* Pointer to the open directory object */
+	FATFS_DIR* dp,			/* Pointer to the open directory object */
 	FILINFO* fno		/* Pointer to file information to return */
 )
@@ -3472,5 +3472,5 @@
 
 
-#if _USE_FIND
+#if FF_USE_FIND
 /*-----------------------------------------------------------------------*/
 /* Find next file                                                        */
@@ -3478,5 +3478,5 @@
 
 FRESULT f_findnext (
-	DIR* dp,		/* Pointer to the open directory object */
+	FATFS_DIR* dp,		/* Pointer to the open directory object */
 	FILINFO* fno	/* Pointer to the file information structure */
 )
@@ -3488,5 +3488,5 @@
 		res = f_readdir(dp, fno);		/* Get a directory item */
 		if (res != FR_OK || !fno || !fno->fname[0]) break;	/* Terminate if any error or end of directory */
-#if _USE_LFN
+#if FF_USE_LFN
 		if (fno->lfname && pattern_matching(dp->pat, fno->lfname, 0, 0)) break;	/* Test for LFN if exist */
 #endif
@@ -3504,5 +3504,5 @@
 
 FRESULT f_findfirst (
-	DIR* dp,				/* Pointer to the blank directory object */
+	FATFS_DIR* dp,				/* Pointer to the blank directory object */
 	FILINFO* fno,			/* Pointer to the file information structure */
 	const TCHAR* path,		/* Pointer to the directory to open */
@@ -3520,9 +3520,9 @@
 }
 
-#endif	/* _USE_FIND */
-
-
-
-#if _FS_MINIMIZE == 0
+#endif	/* FF_USE_FIND */
+
+
+
+#if FF_FS_MINIMIZE == 0
 /*-----------------------------------------------------------------------*/
 /* Get File Status                                                       */
@@ -3535,5 +3535,5 @@
 {
 	FRESULT res;
-	DIR dj;
+	FATFS_DIR dj;
 	DEFINE_NAMEBUF;
 
@@ -3559,5 +3559,5 @@
 
 
-#if !_FS_READONLY
+#if !FF_FS_READONLY
 /*-----------------------------------------------------------------------*/
 /* Get Number of Free Clusters                                           */
@@ -3650,5 +3650,5 @@
 		if (fp->fsize > fp->fptr) {
 			fp->fsize = fp->fptr;	/* Set file size to current R/W point */
-			fp->flag |= FA__WRITTEN;
+			fp->flag |= FA_MODIFIED;
 			if (fp->fptr == 0) {	/* When set file size to zero, remove entire cluster chain */
 				res = remove_chain(fp->fs, fp->sclust);
@@ -3664,10 +3664,10 @@
 				}
 			}
-#if !_FS_TINY
-			if (res == FR_OK && (fp->flag & FA__DIRTY)) {
+#if !FF_FS_TINY
+			if (res == FR_OK && (fp->flag & FA_DIRTY)) {
 				if (disk_write(fp->fs->drv, fp->buf, fp->dsect, 1) != RES_OK)
 					res = FR_DISK_ERR;
 				else
-					fp->flag &= ~FA__DIRTY;
+					fp->flag &= ~FA_DIRTY;
 			}
 #endif
@@ -3691,5 +3691,5 @@
 {
 	FRESULT res;
-	DIR dj, sdj;
+	FATFS_DIR dj, sdj;
 	BYTE *dir;
 	DWORD dclst = 0;
@@ -3702,7 +3702,7 @@
 		INIT_BUF(dj);
 		res = follow_path(&dj, path);		/* Follow the file path */
-		if (_FS_RPATH && res == FR_OK && (dj.fn[NSFLAG] & NS_DOT))
+		if (FF_FS_RPATH && res == FR_OK && (dj.fn[NSFLAG] & NS_DOT))
 			res = FR_INVALID_NAME;			/* Cannot remove dot entry */
-#if _FS_LOCK
+#if FF_FS_LOCK != 0
 		if (res == FR_OK) res = chk_lock(&dj, 2);	/* Cannot remove open object */
 #endif
@@ -3718,5 +3718,5 @@
 				dclst = ld_clust(dj.fs, dir);
 				if (dclst && (dir[DIR_Attr] & AM_DIR)) {	/* Is it a sub-directory ? */
-#if _FS_RPATH
+#if FF_FS_RPATH
 					if (dclst == dj.fs->cdir) {		 		/* Is it the current directory? */
 						res = FR_DENIED;
@@ -3724,5 +3724,5 @@
 #endif
 					{
-						mem_cpy(&sdj, &dj, sizeof (DIR));	/* Open the sub-directory */
+						mem_cpy(&sdj, &dj, sizeof (FATFS_DIR));	/* Open the sub-directory */
 						sdj.sclust = dclst;
 						res = dir_sdi(&sdj, 2);
@@ -3760,5 +3760,5 @@
 {
 	FRESULT res;
-	DIR dj;
+	FATFS_DIR dj;
 	BYTE *dir, n;
 	DWORD dsc, dcl, pcl, tm = GET_FATTIME();
@@ -3772,5 +3772,5 @@
 		res = follow_path(&dj, path);			/* Follow the file path */
 		if (res == FR_OK) res = FR_EXIST;		/* Any object with same name is already existing */
-		if (_FS_RPATH && res == FR_NO_FILE && (dj.fn[NSFLAG] & NS_DOT))
+		if (FF_FS_RPATH && res == FR_NO_FILE && (dj.fn[NSFLAG] & NS_DOT))
 			res = FR_INVALID_NAME;
 		if (res == FR_NO_FILE) {				/* Can create a new directory */
@@ -3836,5 +3836,5 @@
 {
 	FRESULT res;
-	DIR dj;
+	FATFS_DIR dj;
 	BYTE *dir;
 	DEFINE_NAMEBUF;
@@ -3846,5 +3846,5 @@
 		res = follow_path(&dj, path);		/* Follow the file path */
 		FREE_BUF();
-		if (_FS_RPATH && res == FR_OK && (dj.fn[NSFLAG] & NS_DOT))
+		if (FF_FS_RPATH && res == FR_OK && (dj.fn[NSFLAG] & NS_DOT))
 			res = FR_INVALID_NAME;
 		if (res == FR_OK) {
@@ -3877,5 +3877,5 @@
 {
 	FRESULT res;
-	DIR djo, djn;
+	FATFS_DIR djo, djn;
 	BYTE buf[21], *dir;
 	DWORD dw;
@@ -3890,7 +3890,7 @@
 		INIT_BUF(djo);
 		res = follow_path(&djo, path_old);		/* Check old object */
-		if (_FS_RPATH && res == FR_OK && (djo.fn[NSFLAG] & NS_DOT))
+		if (FF_FS_RPATH && res == FR_OK && (djo.fn[NSFLAG] & NS_DOT))
 			res = FR_INVALID_NAME;
-#if _FS_LOCK
+#if FF_FS_LOCK != 0
 		if (res == FR_OK) res = chk_lock(&djo, 2);
 #endif
@@ -3900,5 +3900,5 @@
 			} else {
 				mem_cpy(buf, djo.dir + DIR_Attr, 21);	/* Save information about object except name */
-				mem_cpy(&djn, &djo, sizeof (DIR));		/* Duplicate the directory object */
+				mem_cpy(&djn, &djo, sizeof (FATFS_DIR));		/* Duplicate the directory object */
 				if (get_ldnumber(&path_new) >= 0)		/* Snip drive number off and ignore it */
 					res = follow_path(&djn, path_new);	/* and make sure if new object name is not conflicting */
@@ -3909,6 +3909,6 @@
 					dir = djn.dir;
 					if (dir[DIR_Attr] & AM_DIR) {	/* The new object is a directory */
-						temp_new_path = (TCHAR *)ff_memalloc((_MAX_LFN + 1) * sizeof(WCHAR));
-						ntstdio_snprintf(temp_new_path, _MAX_LFN, "%s/%s", path_new, basename((char *)path_old));
+						temp_new_path = (TCHAR *)ff_memalloc((FF_MAX_LFN + 1) * sizeof(WCHAR));
+						snprintf(temp_new_path, FF_MAX_LFN, "%s/%s", path_new, basename((char *)path_old));
 						res = follow_path(&djn, temp_new_path);
 					}
@@ -3966,5 +3966,5 @@
 {
 	FRESULT res;
-	DIR dj;
+	FATFS_DIR dj;
 	BYTE *dir;
 	DEFINE_NAMEBUF;
@@ -3977,5 +3977,5 @@
 		res = follow_path(&dj, path);	/* Follow the file path */
 		FREE_BUF();
-		if (_FS_RPATH && res == FR_OK && (dj.fn[NSFLAG] & NS_DOT))
+		if (FF_FS_RPATH && res == FR_OK && (dj.fn[NSFLAG] & NS_DOT))
 			res = FR_INVALID_NAME;
 		if (res == FR_OK) {
@@ -3995,13 +3995,13 @@
 }
 
-#endif /* !_FS_READONLY */
-#endif /* _FS_MINIMIZE == 0 */
-#endif /* _FS_MINIMIZE <= 1 */
-#endif /* _FS_MINIMIZE <= 2 */
-
-
-
-
-#if _USE_LABEL
+#endif /* !FF_FS_READONLY */
+#endif /* FF_FS_MINIMIZE == 0 */
+#endif /* FF_FS_MINIMIZE <= 1 */
+#endif /* FF_FS_MINIMIZE <= 2 */
+
+
+
+
+#if FF_USE_LABEL
 /*-----------------------------------------------------------------------*/
 /* Get volume label                                                      */
@@ -4015,7 +4015,7 @@
 {
 	FRESULT res;
-	DIR dj;
+	FATFS_DIR dj;
 	UINT i, j;
-#if _USE_LFN && _LFN_UNICODE
+#if FF_USE_LFN && FF_LFN_UNICODE
 	WCHAR w;
 #endif
@@ -4032,5 +4032,5 @@
 			res = dir_read(&dj, 1);		/* Get an entry with AM_VOL */
 			if (res == FR_OK) {			/* A volume label is exist */
-#if _USE_LFN && _LFN_UNICODE
+#if FF_USE_LFN && FF_LFN_UNICODE
 				i = j = 0;
 				do {
@@ -4070,5 +4070,5 @@
 
 
-#if !_FS_READONLY
+#if !FF_FS_READONLY
 /*-----------------------------------------------------------------------*/
 /* Set volume label                                                      */
@@ -4080,10 +4080,10 @@
 {
 	FRESULT res;
-	DIR dj;
+	FATFS_DIR dj;
 	BYTE vn[11];
 	UINT i, j, sl;
 	WCHAR w;
 	DWORD tm;
-#if _CODE_PAGE == 65001
+#if FF_CODE_PAGE == 65001
 	int code_size;
 	unsigned char utf8_code[6];
@@ -4101,5 +4101,5 @@
 		i = j = 0;
 		do {
-#if _CODE_PAGE == 65001
+#if FF_CODE_PAGE == 65001
 			w = ff_wtoupper(Utf8_to_Utf16(&label[i], &code_size));
 			i += code_size;
@@ -4110,5 +4110,5 @@
 				vn[j++] = utf8_code[k];
 #else
-#if _USE_LFN && _LFN_UNICODE
+#if FF_USE_LFN && FF_LFN_UNICODE
 			w = ff_convert(ff_wtoupper(label[i++]), 0);
 #else
@@ -4116,5 +4116,5 @@
 			if (IsDBCS1(w))
 				w = (j < 10 && i < sl && IsDBCS2(label[i])) ? w << 8 | (BYTE)label[i++] : 0;
-#if _USE_LFN
+#if FF_USE_LFN
 			w = ff_convert(ff_wtoupper(ff_convert(w, 1)), 0);
 #else
@@ -4174,6 +4174,6 @@
 }
 
-#endif /* !_FS_READONLY */
-#endif /* _USE_LABEL */
+#endif /* !FF_FS_READONLY */
+#endif /* FF_USE_LABEL */
 
 
@@ -4182,5 +4182,5 @@
 /* Forward data to the stream directly (available on only tiny cfg)      */
 /*-----------------------------------------------------------------------*/
-#if _USE_FORWARD && _FS_TINY
+#if FF_USE_FORWARD && FF_FS_TINY
 
 FRESULT f_forward (
@@ -4235,9 +4235,9 @@
 	LEAVE_FF(fp->fs, FR_OK);
 }
-#endif /* _USE_FORWARD */
-
-
-
-#if _USE_MKFS && !_FS_READONLY
+#endif /* FF_USE_FORWARD */
+
+
+
+#if FF_USE_MKFS && !FF_FS_READONLY
 /*-----------------------------------------------------------------------*/
 /* Create file system on the logical drive                               */
@@ -4263,5 +4263,5 @@
 	FATFS *fs;
 	DSTATUS stat;
-#if _USE_TRIM
+#if FF_USE_TRIM
 	DWORD eb[2];
 #endif
@@ -4282,9 +4282,9 @@
 	if (stat & STA_NOINIT) return FR_NOT_READY;
 	if (stat & STA_PROTECT) return FR_WRITE_PROTECTED;
-#if _MAX_SS != _MIN_SS		/* Get disk sector size */
-	if (disk_ioctl(pdrv, GET_SECTOR_SIZE, &SS(fs)) != RES_OK || SS(fs) > _MAX_SS || SS(fs) < _MIN_SS)
+#if FF_MAX_SS != FF_MIN_SS		/* Get disk sector size */
+	if (disk_ioctl(pdrv, GET_SECTOR_SIZE, &SS(fs)) != RES_OK || SS(fs) > FF_MAX_SS || SS(fs) < FF_MIN_SS)
 		return FR_DISK_ERR;
 #endif
-	if (_MULTI_PARTITION && part) {
+	if (FF_MULTI_PARTITION && part) {
 		/* Get partition information from partition table in the MBR */
 		if (disk_read(pdrv, fs->win, 0, 1) != RES_OK) return FR_DISK_ERR;
@@ -4308,5 +4308,5 @@
 		au = cst[i];
 	}
-	if (au >= _MIN_SS) au /= SS(fs);	/* Number of sectors per cluster */
+	if (au >= FF_MIN_SS) au /= SS(fs);	/* Number of sectors per cluster */
 	if (!au) au = 1;
 	if (au > 128) au = 128;
@@ -4362,5 +4362,5 @@
 	}
 
-	if (_MULTI_PARTITION && part) {
+	if (FF_MULTI_PARTITION && part) {
 		/* Update system ID in the partition table */
 		tbl = &fs->win[MBR_Table + (part - 1) * SZ_PTE];
@@ -4465,5 +4465,5 @@
 	} while (--i);
 
-#if _USE_TRIM	/* Erase data area if needed */
+#if FF_USE_TRIM	/* Erase data area if needed */
 	{
 		eb[0] = wsect; eb[1] = wsect + (n_clst - ((fmt == FS_FAT32) ? 1 : 0)) * au - 1;
@@ -4488,5 +4488,5 @@
 
 
-#if _MULTI_PARTITION
+#if FF_MULTI_PARTITION
 /*-----------------------------------------------------------------------*/
 /* Create partition table on the physical drive                          */
@@ -4518,5 +4518,5 @@
 
 	/* Create partition table */
-	mem_set(buf, 0, _MAX_SS);
+	mem_set(buf, 0, FF_MAX_SS);
 	p = buf + MBR_Table; b_cyl = 0;
 	for (i = 0; i < 4; i++, p += SZ_PTE) {
@@ -4555,11 +4555,11 @@
 
 
-#endif /* _MULTI_PARTITION */
-#endif /* _USE_MKFS && !_FS_READONLY */
-
-
-
-
-#if _USE_STRFUNC
+#endif /* FF_MULTI_PARTITION */
+#endif /* FF_USE_MKFS && !FF_FS_READONLY */
+
+
+
+
+#if FF_USE_STRFUNC
 /*-----------------------------------------------------------------------*/
 /* Get a string from the file                                            */
@@ -4579,6 +4579,6 @@
 
 	while (n < len - 1) {	/* Read characters until buffer gets filled */
-#if _USE_LFN && _LFN_UNICODE
-#if _STRF_ENCODE == 3		/* Read a character in UTF-8 */
+#if FF_USE_LFN && FF_LFN_UNICODE
+#if FF_STRF_ENCODE == 3		/* Read a character in UTF-8 */
 		f_read(fp, s, 1, &rc);
 		if (rc != 1) break;
@@ -4602,9 +4602,9 @@
 			}
 		}
-#elif _STRF_ENCODE == 2		/* Read a character in UTF-16BE */
+#elif FF_STRF_ENCODE == 2		/* Read a character in UTF-16BE */
 		f_read(fp, s, 2, &rc);
 		if (rc != 2) break;
 		c = s[1] + (s[0] << 8);
-#elif _STRF_ENCODE == 1		/* Read a character in UTF-16LE */
+#elif FF_STRF_ENCODE == 1		/* Read a character in UTF-16LE */
 		f_read(fp, s, 2, &rc);
 		if (rc != 2) break;
@@ -4627,5 +4627,5 @@
 		c = s[0];
 #endif
-		if (_USE_STRFUNC == 2 && c == '\r') continue;	/* Strip '\r' */
+		if (FF_USE_STRFUNC == 2 && c == '\r') continue;	/* Strip '\r' */
 		*p++ = c;
 		n++;
@@ -4639,5 +4639,5 @@
 
 
-#if !_FS_READONLY
+#if !FF_FS_READONLY
 /*-----------------------------------------------------------------------*/
 /* Put a character to the file                                           */
@@ -4661,5 +4661,5 @@
 
 
-	if (_USE_STRFUNC == 2 && c == '\n')	 /* LF -> CRLF conversion */
+	if (FF_USE_STRFUNC == 2 && c == '\n')	 /* LF -> CRLF conversion */
 		putc_bfd(pb, '\r');
 
@@ -4667,6 +4667,6 @@
 	if (i < 0) return;
 
-#if _USE_LFN && _LFN_UNICODE
-#if _STRF_ENCODE == 3			/* Write a character in UTF-8 */
+#if FF_USE_LFN && FF_LFN_UNICODE
+#if FF_STRF_ENCODE == 3			/* Write a character in UTF-8 */
 	if (c < 0x80) {				/* 7-bit */
 		pb->buf[i++] = (BYTE)c;
@@ -4680,8 +4680,8 @@
 		pb->buf[i++] = (BYTE)(0x80 | (c & 0x3F));
 	}
-#elif _STRF_ENCODE == 2			/* Write a character in UTF-16BE */
+#elif FF_STRF_ENCODE == 2			/* Write a character in UTF-16BE */
 	pb->buf[i++] = (BYTE)(c >> 8);
 	pb->buf[i++] = (BYTE)c;
-#elif _STRF_ENCODE == 1			/* Write a character in UTF-16LE */
+#elif FF_STRF_ENCODE == 1			/* Write a character in UTF-16LE */
 	pb->buf[i++] = (BYTE)c;
 	pb->buf[i++] = (BYTE)(c >> 8);
@@ -4866,8 +4866,8 @@
 	ret = f_vprintf(fp, fmt, arp);
 	va_end(arp);
-
+	
 	return ret;
 }
 
-#endif /* !_FS_READONLY */
-#endif /* _USE_STRFUNC */
+#endif /* !FF_FS_READONLY */
+#endif /* FF_USE_STRFUNC */
