[FATTEN]
authorDavid Quintana <gigaherz@gmail.com>
Tue, 8 Sep 2015 22:01:05 +0000 (22:01 +0000)
committerDavid Quintana <gigaherz@gmail.com>
Tue, 8 Sep 2015 22:01:05 +0000 (22:01 +0000)
In a failed attempt at getting 7-zip to recognize the fat images,
* Updated the fatfs backing library to v0.11a,
* Changed the default cluster size to 1 for floppy-sized images (< 4096 sectors) and 8 otherwise (4096 was an invalid value), and
* Changed the fatfs formatting code to generate FAT12 filesystems more windows-like.
I see no reason to discard the changes, so here they are.

svn path=/trunk/; revision=69131

reactos/tools/fatten/fatfs/diskio.c
reactos/tools/fatten/fatfs/ff.c
reactos/tools/fatten/fatfs/ff.h
reactos/tools/fatten/fatfs/ffconf.h
reactos/tools/fatten/fatfs/option/ccsbcs.c
reactos/tools/fatten/fatten.c

index aebb761..c90c65e 100644 (file)
@@ -9,7 +9,7 @@
 #include "diskio.h"
 #include <stdio.h>
 
-extern char* imageFileName;
+extern char* g_imageFileName;
 
 /*-----------------------------------------------------------------------*/
 /* Correspondence between physical drive number and image file handles.  */
@@ -30,10 +30,10 @@ DSTATUS disk_initialize(
         if (driveHandle[0] != NULL)
             return 0;
 
-        driveHandle[0] = fopen(imageFileName, "r+b");
+        driveHandle[0] = fopen(g_imageFileName, "r+b");
         if(!driveHandle[0])
         {
-            driveHandle[0] = fopen(imageFileName, "w+");
+            driveHandle[0] = fopen(g_imageFileName, "w+");
         }
 
         if (driveHandle[0] != NULL)
index d5a4a51..88eb953 100644 (file)
 /*----------------------------------------------------------------------------/
-/  FatFs - FAT file system module  R0.10a                (C)ChaN, 2014
+/  FatFs - FAT file system module  R0.11a                (C)ChaN, 2015        /
 /-----------------------------------------------------------------------------/
-/ FatFs module is a generic FAT file system module for small embedded systems.
-/ This is a free software that opened for education, research and commercial
-/ developments under license policy of following terms.
+/ FatFs module is a free software that opened under license policy of
+/ following conditions.
 /
-/  Copyright (C) 2014, ChaN, all right reserved.
+/ Copyright (C) 2015, ChaN, all right reserved.
 /
-/ * The FatFs module is a free software and there is NO WARRANTY.
-/ * No restriction on use. You can use, modify and redistribute it for
-/   personal, non-profit or commercial products UNDER YOUR RESPONSIBILITY.
-/ * Redistributions of source code must retain the above copyright notice.
+/ 1. Redistributions of source code must retain the above copyright notice,
+/    this condition and the following disclaimer.
 /
-/-----------------------------------------------------------------------------/
-/ Feb 26,'06 R0.00  Prototype.
-/
-/ Apr 29,'06 R0.01  First stable version.
-/
-/ Jun 01,'06 R0.02  Added FAT12 support.
-/                   Removed unbuffered mode.
-/                   Fixed a problem on small (<32M) partition.
-/ Jun 10,'06 R0.02a Added a configuration option (_FS_MINIMUM).
-/
-/ Sep 22,'06 R0.03  Added f_rename().
-/                   Changed option _FS_MINIMUM to _FS_MINIMIZE.
-/ Dec 11,'06 R0.03a Improved cluster scan algorithm to write files fast.
-/                   Fixed f_mkdir() creates incorrect directory on FAT32.
-/
-/ Feb 04,'07 R0.04  Supported multiple drive system.
-/                   Changed some interfaces for multiple drive system.
-/                   Changed f_mountdrv() to f_mount().
-/                   Added f_mkfs().
-/ Apr 01,'07 R0.04a Supported multiple partitions on a physical drive.
-/                   Added a capability of extending file size to f_lseek().
-/                   Added minimization level 3.
-/                   Fixed an endian sensitive code in f_mkfs().
-/ May 05,'07 R0.04b Added a configuration option _USE_NTFLAG.
-/                   Added FSINFO support.
-/                   Fixed DBCS name can result FR_INVALID_NAME.
-/                   Fixed short seek (<= csize) collapses the file object.
-/
-/ Aug 25,'07 R0.05  Changed arguments of f_read(), f_write() and f_mkfs().
-/                   Fixed f_mkfs() on FAT32 creates incorrect FSINFO.
-/                   Fixed f_mkdir() on FAT32 creates incorrect directory.
-/ Feb 03,'08 R0.05a Added f_truncate() and f_utime().
-/                   Fixed off by one error at FAT sub-type determination.
-/                   Fixed btr in f_read() can be mistruncated.
-/                   Fixed cached sector is not flushed when create and close without write.
-/
-/ Apr 01,'08 R0.06  Added fputc(), fputs(), fprintf() and fgets().
-/                   Improved performance of f_lseek() on moving to the same or following cluster.
-/
-/ Apr 01,'09 R0.07  Merged Tiny-FatFs as a configuration option. (_FS_TINY)
-/                   Added long file name feature.
-/                   Added multiple code page feature.
-/                   Added re-entrancy for multitask operation.
-/                   Added auto cluster size selection to f_mkfs().
-/                   Added rewind option to f_readdir().
-/                   Changed result code of critical errors.
-/                   Renamed string functions to avoid name collision.
-/ Apr 14,'09 R0.07a Separated out OS dependent code on reentrant cfg.
-/                   Added multiple sector size feature.
-/ Jun 21,'09 R0.07c Fixed f_unlink() can return FR_OK on error.
-/                   Fixed wrong cache control in f_lseek().
-/                   Added relative path feature.
-/                   Added f_chdir() and f_chdrive().
-/                   Added proper case conversion to extended character.
-/ Nov 03,'09 R0.07e Separated out configuration options from ff.h to ffconf.h.
-/                   Fixed f_unlink() fails to remove a sub-directory on _FS_RPATH.
-/                   Fixed name matching error on the 13 character boundary.
-/                   Added a configuration option, _LFN_UNICODE.
-/                   Changed f_readdir() to return the SFN with always upper case on non-LFN cfg.
-/
-/ May 15,'10 R0.08  Added a memory configuration option. (_USE_LFN = 3)
-/                   Added file lock feature. (_FS_SHARE)
-/                   Added fast seek feature. (_USE_FASTSEEK)
-/                   Changed some types on the API, XCHAR->TCHAR.
-/                   Changed .fname in the FILINFO structure on Unicode cfg.
-/                   String functions support UTF-8 encoding files on Unicode cfg.
-/ Aug 16,'10 R0.08a Added f_getcwd().
-/                   Added sector erase feature. (_USE_ERASE)
-/                   Moved file lock semaphore table from fs object to the bss.
-/                   Fixed a wrong directory entry is created on non-LFN cfg when the given name contains ';'.
-/                   Fixed f_mkfs() creates wrong FAT32 volume.
-/ Jan 15,'11 R0.08b Fast seek feature is also applied to f_read() and f_write().
-/                   f_lseek() reports required table size on creating CLMP.
-/                   Extended format syntax of f_printf().
-/                   Ignores duplicated directory separators in given path name.
-/
-/ Sep 06,'11 R0.09  f_mkfs() supports multiple partition to complete the multiple partition feature.
-/                   Added f_fdisk().
-/ Aug 27,'12 R0.09a Changed f_open() and f_opendir() reject null object pointer to avoid crash.
-/                   Changed option name _FS_SHARE to _FS_LOCK.
-/                   Fixed assertion failure due to OS/2 EA on FAT12/16 volume.
-/ Jan 24,'13 R0.09b Added f_setlabel() and f_getlabel().
-/
-/ Oct 02,'13 R0.10  Added selection of character encoding on the file. (_STRF_ENCODE)
-/                   Added f_closedir().
-/                   Added forced full FAT scan for f_getfree(). (_FS_NOFSINFO)
-/                   Added forced mount feature with changes of f_mount().
-/                   Improved behavior of volume auto detection.
-/                   Improved write throughput of f_puts() and f_printf().
-/                   Changed argument of f_chdrive(), f_mkfs(), disk_read() and disk_write().
-/                   Fixed f_write() can be truncated when the file size is close to 4GB.
-/                   Fixed f_open(), f_mkdir() and f_setlabel() can return incorrect error code.
-/ Jan 15,'14 R0.10a Added arbitrary strings as drive number in the path name. (_STR_VOLUME_ID)
-/                   Added a configuration option of minimum sector size. (_MIN_SS)
-/                   2nd argument of f_rename() can have a drive number and it will be ignored.
-/                   Fixed f_mount() with forced mount fails when drive number is >= 1.
-/                   Fixed f_close() invalidates the file object without volume lock.
-/                   Fixed f_closedir() returns but the volume lock is left acquired.
-/                   Fixed creation of an entry with LFN fails on too many SFN collisions.
-/---------------------------------------------------------------------------*/
+/ This software is provided by the copyright holder and contributors "AS IS"
+/ and any warranties related to this software are DISCLAIMED.
+/ The copyright owner or contributors be NOT LIABLE for any damages caused
+/ by use of this software.
+/----------------------------------------------------------------------------*/
+
 
 #include "ff.h"                        /* Declarations of FatFs API */
 #include "diskio.h"            /* Declarations of disk I/O functions */
 
 
-
-
 /*--------------------------------------------------------------------------
 
    Module Private Definitions
 
 ---------------------------------------------------------------------------*/
 
-#if _FATFS != 29000    /* Revision ID */
+#if _FATFS != 64180    /* Revision ID */
 #error Wrong include file (ff.h).
 #endif
 
 /* Reentrancy related */
 #if _FS_REENTRANT
 #if _USE_LFN == 1
-#error Static LFN work area cannot be used at thread-safe configuration.
+#error Static LFN work area cannot be used at thread-safe configuration
 #endif
 #define        ENTER_FF(fs)            { if (!lock_fs(fs)) return FR_TIMEOUT; }
 #define        LEAVE_FF(fs, res)       { unlock_fs(fs, res); return res; }
 
 /* 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)
-#error Wrong sector size configuration.
+#error Wrong sector size configuration
 #endif
 #if _MAX_SS == _MIN_SS
-#define        SS(fs)  ((UINT)_MIN_SS) /* Fixed sector size */
+#define        SS(fs)  ((UINT)_MAX_SS) /* Fixed sector size */
 #else
 #define        SS(fs)  ((fs)->ssize)   /* Variable sector size */
 #endif
 
 
+/* 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)
+#else
+#define GET_FATTIME()  get_fattime()
+#endif
+
+
 /* File access control feature */
 #if _FS_LOCK
 #if _FS_READONLY
-#error _FS_LOCK must be 0 at read-only cfg.
+#error _FS_LOCK must be 0 at read-only configuration
 #endif
 typedef struct {
-       FATFS *fs;                              /* Object ID 1, volume (NULL:blank entry) */
-       DWORD clu;                              /* Object ID 2, directory */
-       WORD idx;                               /* Object ID 3, directory index */
-       WORD ctr;                               /* Object open counter, 0:none, 0x01..0xFF:read mode open count, 0x100:write mode */
+       FATFS *fs;              /* Object ID 1, volume (NULL:blank entry) */
+       DWORD clu;              /* Object ID 2, directory (0:root) */
+       WORD idx;               /* Object ID 3, directory index */
+       WORD ctr;               /* Object open counter, 0:none, 0x01..0xFF:read mode open count, 0x100:write mode */
 } FILESEM;
 #endif
 
 
 
-/* DBCS code ranges and SBCS extend character conversion table */
+/* DBCS code ranges and SBCS upper conversion tables */
 
 #if _CODE_PAGE == 932  /* Japanese Shift-JIS */
 #define _DF1S  0x81    /* DBC 1st byte range 1 start */
@@ -209,152 +121,192 @@ typedef struct {
 #define _DS2S  0xA1
 #define _DS2E  0xFE
 
-#elif _CODE_PAGE == 437        /* U.S. (OEM) */
-#define _DF1S  0
-#define _EXCVT {0x80,0x9A,0x90,0x41,0x8E,0x41,0x8F,0x80,0x45,0x45,0x45,0x49,0x49,0x49,0x8E,0x8F,0x90,0x92,0x92,0x4F,0x99,0x4F,0x55,0x55,0x59,0x99,0x9A,0x9B,0x9C,0x9D,0x9E,0x9F, \
-                               0x41,0x49,0x4F,0x55,0xA5,0xA5,0xA6,0xA7,0xA8,0xA9,0xAA,0xAB,0xAC,0x21,0xAE,0xAF,0xB0,0xB1,0xB2,0xB3,0xB4,0xB5,0xB6,0xB7,0xB8,0xB9,0xBA,0xBB,0xBC,0xBD,0xBE,0xBF, \
-                               0xC0,0xC1,0xC2,0xC3,0xC4,0xC5,0xC6,0xC7,0xC8,0xC9,0xCA,0xCB,0xCC,0xCD,0xCE,0xCF,0xD0,0xD1,0xD2,0xD3,0xD4,0xD5,0xD6,0xD7,0xD8,0xD9,0xDA,0xDB,0xDC,0xDD,0xDE,0xDF, \
-                               0xE0,0xE1,0xE2,0xE3,0xE4,0xE5,0xE6,0xE7,0xE8,0xE9,0xEA,0xEB,0xEC,0xED,0xEE,0xEF,0xF0,0xF1,0xF2,0xF3,0xF4,0xF5,0xF6,0xF7,0xF8,0xF9,0xFA,0xFB,0xFC,0xFD,0xFE,0xFF}
-
-#elif _CODE_PAGE == 720        /* Arabic (OEM) */
+#elif _CODE_PAGE == 437        /* U.S. */
 #define _DF1S  0
-#define _EXCVT {0x80,0x81,0x45,0x41,0x84,0x41,0x86,0x43,0x45,0x45,0x45,0x49,0x49,0x8D,0x8E,0x8F,0x90,0x92,0x92,0x93,0x94,0x95,0x49,0x49,0x98,0x99,0x9A,0x9B,0x9C,0x9D,0x9E,0x9F, \
-                               0xA0,0xA1,0xA2,0xA3,0xA4,0xA5,0xA6,0xA7,0xA8,0xA9,0xAA,0xAB,0xAC,0xAD,0xAE,0xAF,0xB0,0xB1,0xB2,0xB3,0xB4,0xB5,0xB6,0xB7,0xB8,0xB9,0xBA,0xBB,0xBC,0xBD,0xBE,0xBF, \
-                               0xC0,0xC1,0xC2,0xC3,0xC4,0xC5,0xC6,0xC7,0xC8,0xC9,0xCA,0xCB,0xCC,0xCD,0xCE,0xCF,0xD0,0xD1,0xD2,0xD3,0xD4,0xD5,0xD6,0xD7,0xD8,0xD9,0xDA,0xDB,0xDC,0xDD,0xDE,0xDF, \
-                               0xE0,0xE1,0xE2,0xE3,0xE4,0xE5,0xE6,0xE7,0xE8,0xE9,0xEA,0xEB,0xEC,0xED,0xEE,0xEF,0xF0,0xF1,0xF2,0xF3,0xF4,0xF5,0xF6,0xF7,0xF8,0xF9,0xFA,0xFB,0xFC,0xFD,0xFE,0xFF}
-
-#elif _CODE_PAGE == 737        /* Greek (OEM) */
+#define _EXCVT {0x80,0x9A,0x45,0x41,0x8E,0x41,0x8F,0x80,0x45,0x45,0x45,0x49,0x49,0x49,0x8E,0x8F, \
+                               0x90,0x92,0x92,0x4F,0x99,0x4F,0x55,0x55,0x59,0x99,0x9A,0x9B,0x9C,0x9D,0x9E,0x9F, \
+                               0x41,0x49,0x4F,0x55,0xA5,0xA5,0xA6,0xA7,0xA8,0xA9,0xAA,0xAB,0xAC,0xAD,0xAE,0xAF, \
+                               0xB0,0xB1,0xB2,0xB3,0xB4,0xB5,0xB6,0xB7,0xB8,0xB9,0xBA,0xBB,0xBC,0xBD,0xBE,0xBF, \
+                               0xC0,0xC1,0xC2,0xC3,0xC4,0xC5,0xC6,0xC7,0xC8,0xC9,0xCA,0xCB,0xCC,0xCD,0xCE,0xCF, \
+                               0xD0,0xD1,0xD2,0xD3,0xD4,0xD5,0xD6,0xD7,0xD8,0xD9,0xDA,0xDB,0xDC,0xDD,0xDE,0xDF, \
+                               0xE0,0xE1,0xE2,0xE3,0xE4,0xE5,0xE6,0xE7,0xE8,0xE9,0xEA,0xEB,0xEC,0xED,0xEE,0xEF, \
+                               0xF0,0xF1,0xF2,0xF3,0xF4,0xF5,0xF6,0xF7,0xF8,0xF9,0xFA,0xFB,0xFC,0xFD,0xFE,0xFF}
+
+#elif _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,0x90,0x92,0x92,0x93,0x94,0x95,0x96,0x97,0x80,0x81,0x82,0x83,0x84,0x85,0x86,0x87, \
-                               0x88,0x89,0x8A,0x8B,0x8C,0x8D,0x8E,0x8F,0x90,0x91,0xAA,0x92,0x93,0x94,0x95,0x96,0xB0,0xB1,0xB2,0xB3,0xB4,0xB5,0xB6,0xB7,0xB8,0xB9,0xBA,0xBB,0xBC,0xBD,0xBE,0xBF, \
-                               0xC0,0xC1,0xC2,0xC3,0xC4,0xC5,0xC6,0xC7,0xC8,0xC9,0xCA,0xCB,0xCC,0xCD,0xCE,0xCF,0xD0,0xD1,0xD2,0xD3,0xD4,0xD5,0xD6,0xD7,0xD8,0xD9,0xDA,0xDB,0xDC,0xDD,0xDE,0xDF, \
-                               0x97,0xEA,0xEB,0xEC,0xE4,0xED,0xEE,0xE7,0xE8,0xF1,0xEA,0xEB,0xEC,0xED,0xEE,0xEF,0xF0,0xF1,0xF2,0xF3,0xF4,0xF5,0xF6,0xF7,0xF8,0xF9,0xFA,0xFB,0xFC,0xFD,0xFE,0xFF}
-
-#elif _CODE_PAGE == 775        /* Baltic (OEM) */
-#define _DF1S  0
-#define _EXCVT {0x80,0x9A,0x91,0xA0,0x8E,0x95,0x8F,0x80,0xAD,0xED,0x8A,0x8A,0xA1,0x8D,0x8E,0x8F,0x90,0x92,0x92,0xE2,0x99,0x95,0x96,0x97,0x97,0x99,0x9A,0x9D,0x9C,0x9D,0x9E,0x9F, \
-                               0xA0,0xA1,0xE0,0xA3,0xA3,0xA5,0xA6,0xA7,0xA8,0xA9,0xAA,0xAB,0xAC,0xAD,0xAE,0xAF,0xB0,0xB1,0xB2,0xB3,0xB4,0xB5,0xB6,0xB7,0xB8,0xB9,0xBA,0xBB,0xBC,0xBD,0xBE,0xBF, \
-                               0xC0,0xC1,0xC2,0xC3,0xC4,0xC5,0xC6,0xC7,0xC8,0xC9,0xCA,0xCB,0xCC,0xCD,0xCE,0xCF,0xB5,0xB6,0xB7,0xB8,0xBD,0xBE,0xC6,0xC7,0xA5,0xD9,0xDA,0xDB,0xDC,0xDD,0xDE,0xDF, \
-                               0xE0,0xE1,0xE2,0xE3,0xE5,0xE5,0xE6,0xE3,0xE8,0xE8,0xEA,0xEA,0xEE,0xED,0xEE,0xEF,0xF0,0xF1,0xF2,0xF3,0xF4,0xF5,0xF6,0xF7,0xF8,0xF9,0xFA,0xFB,0xFC,0xFD,0xFE,0xFF}
-
-#elif _CODE_PAGE == 850        /* Multilingual Latin 1 (OEM) */
+#define _EXCVT {0x80,0x81,0x82,0x83,0x84,0x85,0x86,0x87,0x88,0x89,0x8A,0x8B,0x8C,0x8D,0x8E,0x8F, \
+                               0x90,0x91,0x92,0x93,0x94,0x95,0x96,0x97,0x98,0x99,0x9A,0x9B,0x9C,0x9D,0x9E,0x9F, \
+                               0xA0,0xA1,0xA2,0xA3,0xA4,0xA5,0xA6,0xA7,0xA8,0xA9,0xAA,0xAB,0xAC,0xAD,0xAE,0xAF, \
+                               0xB0,0xB1,0xB2,0xB3,0xB4,0xB5,0xB6,0xB7,0xB8,0xB9,0xBA,0xBB,0xBC,0xBD,0xBE,0xBF, \
+                               0xC0,0xC1,0xC2,0xC3,0xC4,0xC5,0xC6,0xC7,0xC8,0xC9,0xCA,0xCB,0xCC,0xCD,0xCE,0xCF, \
+                               0xD0,0xD1,0xD2,0xD3,0xD4,0xD5,0xD6,0xD7,0xD8,0xD9,0xDA,0xDB,0xDC,0xDD,0xDE,0xDF, \
+                               0xE0,0xE1,0xE2,0xE3,0xE4,0xE5,0xE6,0xE7,0xE8,0xE9,0xEA,0xEB,0xEC,0xED,0xEE,0xEF, \
+                               0xF0,0xF1,0xF2,0xF3,0xF4,0xF5,0xF6,0xF7,0xF8,0xF9,0xFA,0xFB,0xFC,0xFD,0xFE,0xFF}
+
+#elif _CODE_PAGE == 737        /* Greek */
 #define _DF1S  0
-#define _EXCVT {0x80,0x9A,0x90,0xB6,0x8E,0xB7,0x8F,0x80,0xD2,0xD3,0xD4,0xD8,0xD7,0xDE,0x8E,0x8F,0x90,0x92,0x92,0xE2,0x99,0xE3,0xEA,0xEB,0x59,0x99,0x9A,0x9D,0x9C,0x9D,0x9E,0x9F, \
-                               0xB5,0xD6,0xE0,0xE9,0xA5,0xA5,0xA6,0xA7,0xA8,0xA9,0xAA,0xAB,0xAC,0x21,0xAE,0xAF,0xB0,0xB1,0xB2,0xB3,0xB4,0xB5,0xB6,0xB7,0xB8,0xB9,0xBA,0xBB,0xBC,0xBD,0xBE,0xBF, \
-                               0xC0,0xC1,0xC2,0xC3,0xC4,0xC5,0xC7,0xC7,0xC8,0xC9,0xCA,0xCB,0xCC,0xCD,0xCE,0xCF,0xD0,0xD1,0xD2,0xD3,0xD4,0xD5,0xD6,0xD7,0xD8,0xD9,0xDA,0xDB,0xDC,0xDD,0xDE,0xDF, \
-                               0xE0,0xE1,0xE2,0xE3,0xE5,0xE5,0xE6,0xE7,0xE7,0xE9,0xEA,0xEB,0xED,0xED,0xEE,0xEF,0xF0,0xF1,0xF2,0xF3,0xF4,0xF5,0xF6,0xF7,0xF8,0xF9,0xFA,0xFB,0xFC,0xFD,0xFE,0xFF}
-
-#elif _CODE_PAGE == 852        /* Latin 2 (OEM) */
+#define _EXCVT {0x80,0x81,0x82,0x83,0x84,0x85,0x86,0x87,0x88,0x89,0x8A,0x8B,0x8C,0x8D,0x8E,0x8F, \
+                               0x90,0x92,0x92,0x93,0x94,0x95,0x96,0x97,0x80,0x81,0x82,0x83,0x84,0x85,0x86,0x87, \
+                               0x88,0x89,0x8A,0x8B,0x8C,0x8D,0x8E,0x8F,0x90,0x91,0xAA,0x92,0x93,0x94,0x95,0x96, \
+                               0xB0,0xB1,0xB2,0xB3,0xB4,0xB5,0xB6,0xB7,0xB8,0xB9,0xBA,0xBB,0xBC,0xBD,0xBE,0xBF, \
+                               0xC0,0xC1,0xC2,0xC3,0xC4,0xC5,0xC6,0xC7,0xC8,0xC9,0xCA,0xCB,0xCC,0xCD,0xCE,0xCF, \
+                               0xD0,0xD1,0xD2,0xD3,0xD4,0xD5,0xD6,0xD7,0xD8,0xD9,0xDA,0xDB,0xDC,0xDD,0xDE,0xDF, \
+                               0x97,0xEA,0xEB,0xEC,0xE4,0xED,0xEE,0xEF,0xF5,0xF0,0xEA,0xEB,0xEC,0xED,0xEE,0xEF, \
+                               0xF0,0xF1,0xF2,0xF3,0xF4,0xF5,0xF6,0xF7,0xF8,0xF9,0xFA,0xFB,0xFC,0xFD,0xFE,0xFF}
+
+#elif _CODE_PAGE == 771        /* KBL */
 #define _DF1S  0
-#define _EXCVT {0x80,0x9A,0x90,0xB6,0x8E,0xDE,0x8F,0x80,0x9D,0xD3,0x8A,0x8A,0xD7,0x8D,0x8E,0x8F,0x90,0x91,0x91,0xE2,0x99,0x95,0x95,0x97,0x97,0x99,0x9A,0x9B,0x9B,0x9D,0x9E,0x9F, \
-                               0xB5,0xD6,0xE0,0xE9,0xA4,0xA4,0xA6,0xA6,0xA8,0xA8,0xAA,0x8D,0xAC,0xB8,0xAE,0xAF,0xB0,0xB1,0xB2,0xB3,0xB4,0xB5,0xB6,0xB7,0xB8,0xB9,0xBA,0xBB,0xBC,0xBD,0xBD,0xBF, \
-                               0xC0,0xC1,0xC2,0xC3,0xC4,0xC5,0xC6,0xC6,0xC8,0xC9,0xCA,0xCB,0xCC,0xCD,0xCE,0xCF,0xD1,0xD1,0xD2,0xD3,0xD2,0xD5,0xD6,0xD7,0xB7,0xD9,0xDA,0xDB,0xDC,0xDD,0xDE,0xDF, \
-                               0xE0,0xE1,0xE2,0xE3,0xE3,0xD5,0xE6,0xE6,0xE8,0xE9,0xE8,0xEB,0xED,0xED,0xDD,0xEF,0xF0,0xF1,0xF2,0xF3,0xF4,0xF5,0xF6,0xF7,0xF8,0xF9,0xFA,0xEB,0xFC,0xFC,0xFE,0xFF}
-
-#elif _CODE_PAGE == 855        /* Cyrillic (OEM) */
+#define _EXCVT {0x80,0x81,0x82,0x83,0x84,0x85,0x86,0x87,0x88,0x89,0x8A,0x8B,0x8C,0x8D,0x8E,0x8F, \
+                               0x90,0x91,0x92,0x93,0x94,0x95,0x96,0x97,0x98,0x99,0x9A,0x9B,0x9C,0x9D,0x9E,0x9F, \
+                               0x80,0x81,0x82,0x83,0x84,0x85,0x86,0x87,0x88,0x89,0x8A,0x8B,0x8C,0x8D,0x8E,0x8F, \
+                               0xB0,0xB1,0xB2,0xB3,0xB4,0xB5,0xB6,0xB7,0xB8,0xB9,0xBA,0xBB,0xBC,0xBD,0xBE,0xBF, \
+                               0xC0,0xC1,0xC2,0xC3,0xC4,0xC5,0xC6,0xC7,0xC8,0xC9,0xCA,0xCB,0xCC,0xCD,0xCE,0xCF, \
+                               0xD0,0xD1,0xD2,0xD3,0xD4,0xD5,0xD6,0xD7,0xD8,0xD9,0xDA,0xDB,0xDC,0xDC,0xDE,0xDE, \
+                               0x90,0x91,0x92,0x93,0x94,0x95,0x96,0x97,0x98,0x99,0x9A,0x9B,0x9C,0x9D,0x9E,0x9F, \
+                               0xF0,0xF0,0xF2,0xF2,0xF4,0xF4,0xF6,0xF6,0xF8,0xF8,0xFA,0xFA,0xFC,0xFC,0xFE,0xFF}
+
+#elif _CODE_PAGE == 775        /* Baltic */
 #define _DF1S  0
-#define _EXCVT {0x81,0x81,0x83,0x83,0x85,0x85,0x87,0x87,0x89,0x89,0x8B,0x8B,0x8D,0x8D,0x8F,0x8F,0x91,0x91,0x93,0x93,0x95,0x95,0x97,0x97,0x99,0x99,0x9B,0x9B,0x9D,0x9D,0x9F,0x9F, \
-                               0xA1,0xA1,0xA3,0xA3,0xA5,0xA5,0xA7,0xA7,0xA9,0xA9,0xAB,0xAB,0xAD,0xAD,0xAE,0xAF,0xB0,0xB1,0xB2,0xB3,0xB4,0xB6,0xB6,0xB8,0xB8,0xB9,0xBA,0xBB,0xBC,0xBE,0xBE,0xBF, \
-                               0xC0,0xC1,0xC2,0xC3,0xC4,0xC5,0xC7,0xC7,0xC8,0xC9,0xCA,0xCB,0xCC,0xCD,0xCE,0xCF,0xD1,0xD1,0xD3,0xD3,0xD5,0xD5,0xD7,0xD7,0xDD,0xD9,0xDA,0xDB,0xDC,0xDD,0xE0,0xDF, \
-                               0xE0,0xE2,0xE2,0xE4,0xE4,0xE6,0xE6,0xE8,0xE8,0xEA,0xEA,0xEC,0xEC,0xEE,0xEE,0xEF,0xF0,0xF2,0xF2,0xF4,0xF4,0xF6,0xF6,0xF8,0xF8,0xFA,0xFA,0xFC,0xFC,0xFD,0xFE,0xFF}
-
-#elif _CODE_PAGE == 857        /* Turkish (OEM) */
+#define _EXCVT {0x80,0x9A,0x91,0xA0,0x8E,0x95,0x8F,0x80,0xAD,0xED,0x8A,0x8A,0xA1,0x8D,0x8E,0x8F, \
+                               0x90,0x92,0x92,0xE2,0x99,0x95,0x96,0x97,0x97,0x99,0x9A,0x9D,0x9C,0x9D,0x9E,0x9F, \
+                               0xA0,0xA1,0xE0,0xA3,0xA3,0xA5,0xA6,0xA7,0xA8,0xA9,0xAA,0xAB,0xAC,0xAD,0xAE,0xAF, \
+                               0xB0,0xB1,0xB2,0xB3,0xB4,0xB5,0xB6,0xB7,0xB8,0xB9,0xBA,0xBB,0xBC,0xBD,0xBE,0xBF, \
+                               0xC0,0xC1,0xC2,0xC3,0xC4,0xC5,0xC6,0xC7,0xC8,0xC9,0xCA,0xCB,0xCC,0xCD,0xCE,0xCF, \
+                               0xB5,0xB6,0xB7,0xB8,0xBD,0xBE,0xC6,0xC7,0xA5,0xD9,0xDA,0xDB,0xDC,0xDD,0xDE,0xDF, \
+                               0xE0,0xE1,0xE2,0xE3,0xE5,0xE5,0xE6,0xE3,0xE8,0xE8,0xEA,0xEA,0xEE,0xED,0xEE,0xEF, \
+                               0xF0,0xF1,0xF2,0xF3,0xF4,0xF5,0xF6,0xF7,0xF8,0xF9,0xFA,0xFB,0xFC,0xFD,0xFE,0xFF}
+
+#elif _CODE_PAGE == 850        /* Latin 1 */
 #define _DF1S  0
-#define _EXCVT {0x80,0x9A,0x90,0xB6,0x8E,0xB7,0x8F,0x80,0xD2,0xD3,0xD4,0xD8,0xD7,0x98,0x8E,0x8F,0x90,0x92,0x92,0xE2,0x99,0xE3,0xEA,0xEB,0x98,0x99,0x9A,0x9D,0x9C,0x9D,0x9E,0x9E, \
-                               0xB5,0xD6,0xE0,0xE9,0xA5,0xA5,0xA6,0xA6,0xA8,0xA9,0xAA,0xAB,0xAC,0x21,0xAE,0xAF,0xB0,0xB1,0xB2,0xB3,0xB4,0xB5,0xB6,0xB7,0xB8,0xB9,0xBA,0xBB,0xBC,0xBD,0xBE,0xBF, \
-                               0xC0,0xC1,0xC2,0xC3,0xC4,0xC5,0xC7,0xC7,0xC8,0xC9,0xCA,0xCB,0xCC,0xCD,0xCE,0xCF,0xD0,0xD1,0xD2,0xD3,0xD4,0xD5,0xD6,0xD7,0xD8,0xD9,0xDA,0xDB,0xDC,0xDD,0xDE,0xDF, \
-                               0xE0,0xE1,0xE2,0xE3,0xE5,0xE5,0xE6,0xE7,0xE8,0xE9,0xEA,0xEB,0xDE,0x59,0xEE,0xEF,0xF0,0xF1,0xF2,0xF3,0xF4,0xF5,0xF6,0xF7,0xF8,0xF9,0xFA,0xFB,0xFC,0xFD,0xFE,0xFF}
-
-#elif _CODE_PAGE == 858        /* Multilingual Latin 1 + Euro (OEM) */
+#define _EXCVT {0x43,0x55,0x45,0x41,0x41,0x41,0x41,0x43,0x45,0x45,0x45,0x49,0x49,0x49,0x41,0x41, \
+                               0x45,0x92,0x92,0x4F,0x4F,0x4F,0x55,0x55,0x59,0x4F,0x55,0x4F,0x9C,0x4F,0x9E,0x9F, \
+                               0x41,0x49,0x4F,0x55,0xA5,0xA5,0xA6,0xA7,0xA8,0xA9,0xAA,0xAB,0xAC,0xAD,0xAE,0xAF, \
+                               0xB0,0xB1,0xB2,0xB3,0xB4,0x41,0x41,0x41,0xB8,0xB9,0xBA,0xBB,0xBC,0xBD,0xBE,0xBF, \
+                               0xC0,0xC1,0xC2,0xC3,0xC4,0xC5,0x41,0x41,0xC8,0xC9,0xCA,0xCB,0xCC,0xCD,0xCE,0xCF, \
+                               0xD1,0xD1,0x45,0x45,0x45,0x49,0x49,0x49,0x49,0xD9,0xDA,0xDB,0xDC,0xDD,0x49,0xDF, \
+                               0x4F,0xE1,0x4F,0x4F,0x4F,0x4F,0xE6,0xE8,0xE8,0x55,0x55,0x55,0x59,0x59,0xEE,0xEF, \
+                               0xF0,0xF1,0xF2,0xF3,0xF4,0xF5,0xF6,0xF7,0xF8,0xF9,0xFA,0xFB,0xFC,0xFD,0xFE,0xFF}
+
+#elif _CODE_PAGE == 852        /* Latin 2 */
 #define _DF1S  0
-#define _EXCVT {0x80,0x9A,0x90,0xB6,0x8E,0xB7,0x8F,0x80,0xD2,0xD3,0xD4,0xD8,0xD7,0xDE,0x8E,0x8F,0x90,0x92,0x92,0xE2,0x99,0xE3,0xEA,0xEB,0x59,0x99,0x9A,0x9D,0x9C,0x9D,0x9E,0x9F, \
-                               0xB5,0xD6,0xE0,0xE9,0xA5,0xA5,0xA6,0xA7,0xA8,0xA9,0xAA,0xAB,0xAC,0x21,0xAE,0xAF,0xB0,0xB1,0xB2,0xB3,0xB4,0xB5,0xB6,0xB7,0xB8,0xB9,0xBA,0xBB,0xBC,0xBD,0xBE,0xBF, \
-                               0xC0,0xC1,0xC2,0xC3,0xC4,0xC5,0xC7,0xC7,0xC8,0xC9,0xCA,0xCB,0xCC,0xCD,0xCE,0xCF,0xD1,0xD1,0xD2,0xD3,0xD4,0xD5,0xD6,0xD7,0xD8,0xD9,0xDA,0xDB,0xDC,0xDD,0xDE,0xDF, \
-                               0xE0,0xE1,0xE2,0xE3,0xE5,0xE5,0xE6,0xE7,0xE7,0xE9,0xEA,0xEB,0xED,0xED,0xEE,0xEF,0xF0,0xF1,0xF2,0xF3,0xF4,0xF5,0xF6,0xF7,0xF8,0xF9,0xFA,0xFB,0xFC,0xFD,0xFE,0xFF}
-
-#elif _CODE_PAGE == 862        /* Hebrew (OEM) */
+#define _EXCVT {0x80,0x9A,0x90,0xB6,0x8E,0xDE,0x8F,0x80,0x9D,0xD3,0x8A,0x8A,0xD7,0x8D,0x8E,0x8F, \
+                               0x90,0x91,0x91,0xE2,0x99,0x95,0x95,0x97,0x97,0x99,0x9A,0x9B,0x9B,0x9D,0x9E,0xAC, \
+                               0xB5,0xD6,0xE0,0xE9,0xA4,0xA4,0xA6,0xA6,0xA8,0xA8,0xAA,0x8D,0xAC,0xB8,0xAE,0xAF, \
+                               0xB0,0xB1,0xB2,0xB3,0xB4,0xB5,0xB6,0xB7,0xB8,0xB9,0xBA,0xBB,0xBC,0xBD,0xBD,0xBF, \
+                               0xC0,0xC1,0xC2,0xC3,0xC4,0xC5,0xC6,0xC6,0xC8,0xC9,0xCA,0xCB,0xCC,0xCD,0xCE,0xCF, \
+                               0xD1,0xD1,0xD2,0xD3,0xD2,0xD5,0xD6,0xD7,0xB7,0xD9,0xDA,0xDB,0xDC,0xDD,0xDE,0xDF, \
+                               0xE0,0xE1,0xE2,0xE3,0xE3,0xD5,0xE6,0xE6,0xE8,0xE9,0xE8,0xEB,0xED,0xED,0xDD,0xEF, \
+                               0xF0,0xF1,0xF2,0xF3,0xF4,0xF5,0xF6,0xF7,0xF8,0xF9,0xFA,0xEB,0xFC,0xFC,0xFE,0xFF}
+
+#elif _CODE_PAGE == 855        /* Cyrillic */
 #define _DF1S  0
-#define _EXCVT {0x80,0x81,0x82,0x83,0x84,0x85,0x86,0x87,0x88,0x89,0x8A,0x8B,0x8C,0x8D,0x8E,0x8F,0x90,0x91,0x92,0x93,0x94,0x95,0x96,0x97,0x98,0x99,0x9A,0x9B,0x9C,0x9D,0x9E,0x9F, \
-                               0x41,0x49,0x4F,0x55,0xA5,0xA5,0xA6,0xA7,0xA8,0xA9,0xAA,0xAB,0xAC,0x21,0xAE,0xAF,0xB0,0xB1,0xB2,0xB3,0xB4,0xB5,0xB6,0xB7,0xB8,0xB9,0xBA,0xBB,0xBC,0xBD,0xBE,0xBF, \
-                               0xC0,0xC1,0xC2,0xC3,0xC4,0xC5,0xC6,0xC7,0xC8,0xC9,0xCA,0xCB,0xCC,0xCD,0xCE,0xCF,0xD0,0xD1,0xD2,0xD3,0xD4,0xD5,0xD6,0xD7,0xD8,0xD9,0xDA,0xDB,0xDC,0xDD,0xDE,0xDF, \
-                               0xE0,0xE1,0xE2,0xE3,0xE4,0xE5,0xE6,0xE7,0xE8,0xE9,0xEA,0xEB,0xEC,0xED,0xEE,0xEF,0xF0,0xF1,0xF2,0xF3,0xF4,0xF5,0xF6,0xF7,0xF8,0xF9,0xFA,0xFB,0xFC,0xFD,0xFE,0xFF}
-
-#elif _CODE_PAGE == 866        /* Russian (OEM) */
+#define _EXCVT {0x81,0x81,0x83,0x83,0x85,0x85,0x87,0x87,0x89,0x89,0x8B,0x8B,0x8D,0x8D,0x8F,0x8F, \
+                               0x91,0x91,0x93,0x93,0x95,0x95,0x97,0x97,0x99,0x99,0x9B,0x9B,0x9D,0x9D,0x9F,0x9F, \
+                               0xA1,0xA1,0xA3,0xA3,0xA5,0xA5,0xA7,0xA7,0xA9,0xA9,0xAB,0xAB,0xAD,0xAD,0xAE,0xAF, \
+                               0xB0,0xB1,0xB2,0xB3,0xB4,0xB6,0xB6,0xB8,0xB8,0xB9,0xBA,0xBB,0xBC,0xBE,0xBE,0xBF, \
+                               0xC0,0xC1,0xC2,0xC3,0xC4,0xC5,0xC7,0xC7,0xC8,0xC9,0xCA,0xCB,0xCC,0xCD,0xCE,0xCF, \
+                               0xD1,0xD1,0xD3,0xD3,0xD5,0xD5,0xD7,0xD7,0xDD,0xD9,0xDA,0xDB,0xDC,0xDD,0xE0,0xDF, \
+                               0xE0,0xE2,0xE2,0xE4,0xE4,0xE6,0xE6,0xE8,0xE8,0xEA,0xEA,0xEC,0xEC,0xEE,0xEE,0xEF, \
+                               0xF0,0xF2,0xF2,0xF4,0xF4,0xF6,0xF6,0xF8,0xF8,0xFA,0xFA,0xFC,0xFC,0xFD,0xFE,0xFF}
+
+#elif _CODE_PAGE == 857        /* Turkish */
 #define _DF1S  0
-#define _EXCVT {0x80,0x81,0x82,0x83,0x84,0x85,0x86,0x87,0x88,0x89,0x8A,0x8B,0x8C,0x8D,0x8E,0x8F,0x90,0x91,0x92,0x93,0x94,0x95,0x96,0x97,0x98,0x99,0x9A,0x9B,0x9C,0x9D,0x9E,0x9F, \
-                               0x80,0x81,0x82,0x83,0x84,0x85,0x86,0x87,0x88,0x89,0x8A,0x8B,0x8C,0x8D,0x8E,0x8F,0xB0,0xB1,0xB2,0xB3,0xB4,0xB5,0xB6,0xB7,0xB8,0xB9,0xBA,0xBB,0xBC,0xBD,0xBE,0xBF, \
-                               0xC0,0xC1,0xC2,0xC3,0xC4,0xC5,0xC6,0xC7,0xC8,0xC9,0xCA,0xCB,0xCC,0xCD,0xCE,0xCF,0xD0,0xD1,0xD2,0xD3,0xD4,0xD5,0xD6,0xD7,0xD8,0xD9,0xDA,0xDB,0xDC,0xDD,0xDE,0xDF, \
-                               0x90,0x91,0x92,0x93,0x9d,0x95,0x96,0x97,0x98,0x99,0x9A,0x9B,0x9C,0x9D,0x9E,0x9F,0xF0,0xF0,0xF2,0xF2,0xF4,0xF4,0xF6,0xF6,0xF8,0xF9,0xFA,0xFB,0xFC,0xFD,0xFE,0xFF}
-
-#elif _CODE_PAGE == 874        /* Thai (OEM, Windows) */
+#define _EXCVT {0x80,0x9A,0x90,0xB6,0x8E,0xB7,0x8F,0x80,0xD2,0xD3,0xD4,0xD8,0xD7,0x49,0x8E,0x8F, \
+                               0x90,0x92,0x92,0xE2,0x99,0xE3,0xEA,0xEB,0x98,0x99,0x9A,0x9D,0x9C,0x9D,0x9E,0x9E, \
+                               0xB5,0xD6,0xE0,0xE9,0xA5,0xA5,0xA6,0xA6,0xA8,0xA9,0xAA,0xAB,0xAC,0xAD,0xAE,0xAF, \
+                               0xB0,0xB1,0xB2,0xB3,0xB4,0xB5,0xB6,0xB7,0xB8,0xB9,0xBA,0xBB,0xBC,0xBD,0xBE,0xBF, \
+                               0xC0,0xC1,0xC2,0xC3,0xC4,0xC5,0xC7,0xC7,0xC8,0xC9,0xCA,0xCB,0xCC,0xCD,0xCE,0xCF, \
+                               0xD0,0xD1,0xD2,0xD3,0xD4,0x49,0xD6,0xD7,0xD8,0xD9,0xDA,0xDB,0xDC,0xDD,0xDE,0xDF, \
+                               0xE0,0xE1,0xE2,0xE3,0xE5,0xE5,0xE6,0xE7,0xE8,0xE9,0xEA,0xEB,0xDE,0xED,0xEE,0xEF, \
+                               0xF0,0xF1,0xF2,0xF3,0xF4,0xF5,0xF6,0xF7,0xF8,0xF9,0xFA,0xFB,0xFC,0xFD,0xFE,0xFF}
+
+#elif _CODE_PAGE == 860        /* Portuguese */
 #define _DF1S  0
-#define _EXCVT {0x80,0x81,0x82,0x83,0x84,0x85,0x86,0x87,0x88,0x89,0x8A,0x8B,0x8C,0x8D,0x8E,0x8F,0x90,0x91,0x92,0x93,0x94,0x95,0x96,0x97,0x98,0x99,0x9A,0x9B,0x9C,0x9D,0x9E,0x9F, \
-                               0xA0,0xA1,0xA2,0xA3,0xA4,0xA5,0xA6,0xA7,0xA8,0xA9,0xAA,0xAB,0xAC,0xAD,0xAE,0xAF,0xB0,0xB1,0xB2,0xB3,0xB4,0xB5,0xB6,0xB7,0xB8,0xB9,0xBA,0xBB,0xBC,0xBD,0xBE,0xBF, \
-                               0xC0,0xC1,0xC2,0xC3,0xC4,0xC5,0xC6,0xC7,0xC8,0xC9,0xCA,0xCB,0xCC,0xCD,0xCE,0xCF,0xD0,0xD1,0xD2,0xD3,0xD4,0xD5,0xD6,0xD7,0xD8,0xD9,0xDA,0xDB,0xDC,0xDD,0xDE,0xDF, \
-                               0xE0,0xE1,0xE2,0xE3,0xE4,0xE5,0xE6,0xE7,0xE8,0xE9,0xEA,0xEB,0xEC,0xED,0xEE,0xEF,0xF0,0xF1,0xF2,0xF3,0xF4,0xF5,0xF6,0xF7,0xF8,0xF9,0xFA,0xFB,0xFC,0xFD,0xFE,0xFF}
-
-#elif _CODE_PAGE == 1250 /* Central Europe (Windows) */
+#define _EXCVT {0x80,0x9A,0x90,0x8F,0x8E,0x91,0x86,0x80,0x89,0x89,0x92,0x8B,0x8C,0x98,0x8E,0x8F, \
+                               0x90,0x91,0x92,0x8C,0x99,0xA9,0x96,0x9D,0x98,0x99,0x9A,0x9B,0x9C,0x9D,0x9E,0x9F, \
+                               0x86,0x8B,0x9F,0x96,0xA5,0xA5,0xA6,0xA7,0xA8,0xA9,0xAA,0xAB,0xAC,0xAD,0xAE,0xAF, \
+                               0xB0,0xB1,0xB2,0xB3,0xB4,0xB5,0xB6,0xB7,0xB8,0xB9,0xBA,0xBB,0xBC,0xBD,0xBE,0xBF, \
+                               0xC0,0xC1,0xC2,0xC3,0xC4,0xC5,0xC6,0xC7,0xC8,0xC9,0xCA,0xCB,0xCC,0xCD,0xCE,0xCF, \
+                               0xD0,0xD1,0xD2,0xD3,0xD4,0xD5,0xD6,0xD7,0xD8,0xD9,0xDA,0xDB,0xDC,0xDD,0xDE,0xDF, \
+                               0xE0,0xE1,0xE2,0xE3,0xE4,0xE5,0xE6,0xE7,0xE8,0xE9,0xEA,0xEB,0xEC,0xED,0xEE,0xEF, \
+                               0xF0,0xF1,0xF2,0xF3,0xF4,0xF5,0xF6,0xF7,0xF8,0xF9,0xFA,0xFB,0xFC,0xFD,0xFE,0xFF}
+
+#elif _CODE_PAGE == 861        /* Icelandic */
 #define _DF1S  0
-#define _EXCVT {0x80,0x81,0x82,0x83,0x84,0x85,0x86,0x87,0x88,0x89,0x8A,0x8B,0x8C,0x8D,0x8E,0x8F,0x90,0x91,0x92,0x93,0x94,0x95,0x96,0x97,0x98,0x99,0x8A,0x9B,0x8C,0x8D,0x8E,0x8F, \
-                               0xA0,0xA1,0xA2,0xA3,0xA4,0xA5,0xA6,0xA7,0xA8,0xA9,0xAA,0xAB,0xAC,0xAD,0xAE,0xAF,0xB0,0xB1,0xB2,0xA3,0xB4,0xB5,0xB6,0xB7,0xB8,0xA5,0xAA,0xBB,0xBC,0xBD,0xBC,0xAF, \
-                               0xC0,0xC1,0xC2,0xC3,0xC4,0xC5,0xC6,0xC7,0xC8,0xC9,0xCA,0xCB,0xCC,0xCD,0xCE,0xCF,0xD0,0xD1,0xD2,0xD3,0xD4,0xD5,0xD6,0xD7,0xD8,0xD9,0xDA,0xDB,0xDC,0xDD,0xDE,0xDF, \
-                               0xC0,0xC1,0xC2,0xC3,0xC4,0xC5,0xC6,0xC7,0xC8,0xC9,0xCA,0xCB,0xCC,0xCD,0xCE,0xCF,0xD0,0xD1,0xD2,0xD3,0xD4,0xD5,0xD6,0xF7,0xD8,0xD9,0xDA,0xDB,0xDC,0xDD,0xDE,0xFF}
-
-#elif _CODE_PAGE == 1251 /* Cyrillic (Windows) */
+#define _EXCVT {0x80,0x9A,0x90,0x41,0x8E,0x41,0x8F,0x80,0x45,0x45,0x45,0x8B,0x8B,0x8D,0x8E,0x8F, \
+                               0x90,0x92,0x92,0x4F,0x99,0x8D,0x55,0x97,0x97,0x99,0x9A,0x9D,0x9C,0x9D,0x9E,0x9F, \
+                               0xA4,0xA5,0xA6,0xA7,0xA4,0xA5,0xA6,0xA7,0xA8,0xA9,0xAA,0xAB,0xAC,0xAD,0xAE,0xAF, \
+                               0xB0,0xB1,0xB2,0xB3,0xB4,0xB5,0xB6,0xB7,0xB8,0xB9,0xBA,0xBB,0xBC,0xBD,0xBE,0xBF, \
+                               0xC0,0xC1,0xC2,0xC3,0xC4,0xC5,0xC6,0xC7,0xC8,0xC9,0xCA,0xCB,0xCC,0xCD,0xCE,0xCF, \
+                               0xD0,0xD1,0xD2,0xD3,0xD4,0xD5,0xD6,0xD7,0xD8,0xD9,0xDA,0xDB,0xDC,0xDD,0xDE,0xDF, \
+                               0xE0,0xE1,0xE2,0xE3,0xE4,0xE5,0xE6,0xE7,0xE8,0xE9,0xEA,0xEB,0xEC,0xED,0xEE,0xEF, \
+                               0xF0,0xF1,0xF2,0xF3,0xF4,0xF5,0xF6,0xF7,0xF8,0xF9,0xFA,0xFB,0xFC,0xFD,0xFE,0xFF}
+
+#elif _CODE_PAGE == 862        /* Hebrew */
 #define _DF1S  0
-#define _EXCVT {0x80,0x81,0x82,0x82,0x84,0x85,0x86,0x87,0x88,0x89,0x8A,0x8B,0x8C,0x8D,0x8E,0x8F,0x80,0x91,0x92,0x93,0x94,0x95,0x96,0x97,0x98,0x99,0x8A,0x9B,0x8C,0x8D,0x8E,0x8F, \
-                               0xA0,0xA2,0xA2,0xA3,0xA4,0xA5,0xA6,0xA7,0xA8,0xA9,0xAA,0xAB,0xAC,0xAD,0xAE,0xAF,0xB0,0xB1,0xB2,0xB2,0xA5,0xB5,0xB6,0xB7,0xA8,0xB9,0xAA,0xBB,0xA3,0xBD,0xBD,0xAF, \
-                               0xC0,0xC1,0xC2,0xC3,0xC4,0xC5,0xC6,0xC7,0xC8,0xC9,0xCA,0xCB,0xCC,0xCD,0xCE,0xCF,0xD0,0xD1,0xD2,0xD3,0xD4,0xD5,0xD6,0xD7,0xD8,0xD9,0xDA,0xDB,0xDC,0xDD,0xDE,0xDF, \
-                               0xC0,0xC1,0xC2,0xC3,0xC4,0xC5,0xC6,0xC7,0xC8,0xC9,0xCA,0xCB,0xCC,0xCD,0xCE,0xCF,0xD0,0xD1,0xD2,0xD3,0xD4,0xD5,0xD6,0xD7,0xD8,0xD9,0xDA,0xDB,0xDC,0xDD,0xDE,0xDF}
-
-#elif _CODE_PAGE == 1252 /* Latin 1 (Windows) */
+#define _EXCVT {0x80,0x81,0x82,0x83,0x84,0x85,0x86,0x87,0x88,0x89,0x8A,0x8B,0x8C,0x8D,0x8E,0x8F, \
+                               0x90,0x91,0x92,0x93,0x94,0x95,0x96,0x97,0x98,0x99,0x9A,0x9B,0x9C,0x9D,0x9E,0x9F, \
+                               0x41,0x49,0x4F,0x55,0xA5,0xA5,0xA6,0xA7,0xA8,0xA9,0xAA,0xAB,0xAC,0xAD,0xAE,0xAF, \
+                               0xB0,0xB1,0xB2,0xB3,0xB4,0xB5,0xB6,0xB7,0xB8,0xB9,0xBA,0xBB,0xBC,0xBD,0xBE,0xBF, \
+                               0xC0,0xC1,0xC2,0xC3,0xC4,0xC5,0xC6,0xC7,0xC8,0xC9,0xCA,0xCB,0xCC,0xCD,0xCE,0xCF, \
+                               0xD0,0xD1,0xD2,0xD3,0xD4,0xD5,0xD6,0xD7,0xD8,0xD9,0xDA,0xDB,0xDC,0xDD,0xDE,0xDF, \
+                               0xE0,0xE1,0xE2,0xE3,0xE4,0xE5,0xE6,0xE7,0xE8,0xE9,0xEA,0xEB,0xEC,0xED,0xEE,0xEF, \
+                               0xF0,0xF1,0xF2,0xF3,0xF4,0xF5,0xF6,0xF7,0xF8,0xF9,0xFA,0xFB,0xFC,0xFD,0xFE,0xFF}
+
+#elif _CODE_PAGE == 863        /* Canadian-French */
 #define _DF1S  0
-#define _EXCVT {0x80,0x81,0x82,0x83,0x84,0x85,0x86,0x87,0x88,0x89,0x8A,0x8B,0x8C,0x8D,0x8E,0x8F,0x90,0x91,0x92,0x93,0x94,0x95,0x96,0x97,0x98,0x99,0xAd,0x9B,0x8C,0x9D,0xAE,0x9F, \
-                               0xA0,0x21,0xA2,0xA3,0xA4,0xA5,0xA6,0xA7,0xA8,0xA9,0xAA,0xAB,0xAC,0xAD,0xAE,0xAF,0xB0,0xB1,0xB2,0xB3,0xB4,0xB5,0xB6,0xB7,0xB8,0xB9,0xBA,0xBB,0xBC,0xBD,0xBE,0xBF, \
-                               0xC0,0xC1,0xC2,0xC3,0xC4,0xC5,0xC6,0xC7,0xC8,0xC9,0xCA,0xCB,0xCC,0xCD,0xCE,0xCF,0xD0,0xD1,0xD2,0xD3,0xD4,0xD5,0xD6,0xD7,0xD8,0xD9,0xDA,0xDB,0xDC,0xDD,0xDE,0xDF, \
-                               0xC0,0xC1,0xC2,0xC3,0xC4,0xC5,0xC6,0xC7,0xC8,0xC9,0xCA,0xCB,0xCC,0xCD,0xCE,0xCF,0xD0,0xD1,0xD2,0xD3,0xD4,0xD5,0xD6,0xF7,0xD8,0xD9,0xDA,0xDB,0xDC,0xDD,0xDE,0x9F}
-
-#elif _CODE_PAGE == 1253 /* Greek (Windows) */
+#define _EXCVT {0x43,0x55,0x45,0x41,0x41,0x41,0x86,0x43,0x45,0x45,0x45,0x49,0x49,0x8D,0x41,0x8F, \
+                               0x45,0x45,0x45,0x4F,0x45,0x49,0x55,0x55,0x98,0x4F,0x55,0x9B,0x9C,0x55,0x55,0x9F, \
+                               0xA0,0xA1,0x4F,0x55,0xA4,0xA5,0xA6,0xA7,0x49,0xA9,0xAA,0xAB,0xAC,0xAD,0xAE,0xAF, \
+                               0xB0,0xB1,0xB2,0xB3,0xB4,0xB5,0xB6,0xB7,0xB8,0xB9,0xBA,0xBB,0xBC,0xBD,0xBE,0xBF, \
+                               0xC0,0xC1,0xC2,0xC3,0xC4,0xC5,0xC6,0xC7,0xC8,0xC9,0xCA,0xCB,0xCC,0xCD,0xCE,0xCF, \
+                               0xD0,0xD1,0xD2,0xD3,0xD4,0xD5,0xD6,0xD7,0xD8,0xD9,0xDA,0xDB,0xDC,0xDD,0xDE,0xDF, \
+                               0xE0,0xE1,0xE2,0xE3,0xE4,0xE5,0xE6,0xE7,0xE8,0xE9,0xEA,0xEB,0xEC,0xED,0xEE,0xEF, \
+                               0xF0,0xF1,0xF2,0xF3,0xF4,0xF5,0xF6,0xF7,0xF8,0xF9,0xFA,0xFB,0xFC,0xFD,0xFE,0xFF}
+
+#elif _CODE_PAGE == 864        /* Arabic */
 #define _DF1S  0
-#define _EXCVT {0x80,0x81,0x82,0x83,0x84,0x85,0x86,0x87,0x88,0x89,0x8A,0x8B,0x8C,0x8D,0x8E,0x8F,0x90,0x91,0x92,0x93,0x94,0x95,0x96,0x97,0x98,0x99,0x9A,0x9B,0x9C,0x9D,0x9E,0x9F, \
-                               0xA0,0xA1,0xA2,0xA3,0xA4,0xA5,0xA6,0xA7,0xA8,0xA9,0xAA,0xAB,0xAC,0xAD,0xAE,0xAF,0xB0,0xB1,0xB2,0xB3,0xB4,0xB5,0xB6,0xB7,0xB8,0xB9,0xBA,0xBB,0xBC,0xBD,0xBE,0xBF, \
-                               0xC0,0xC1,0xC2,0xC3,0xC4,0xC5,0xC6,0xC7,0xC8,0xC9,0xCA,0xCB,0xCC,0xCD,0xCE,0xCF,0xD0,0xD1,0xD2,0xD3,0xD4,0xD5,0xD6,0xD7,0xD8,0xD9,0xDA,0xDB,0xA2,0xB8,0xB9,0xBA, \
-                               0xE0,0xC1,0xC2,0xC3,0xC4,0xC5,0xC6,0xC7,0xC8,0xC9,0xCA,0xCB,0xCC,0xCD,0xCE,0xCF,0xD0,0xD1,0xF2,0xD3,0xD4,0xD5,0xD6,0xD7,0xD8,0xD9,0xDA,0xFB,0xBC,0xFD,0xBF,0xFF}
-
-#elif _CODE_PAGE == 1254 /* Turkish (Windows) */
+#define _EXCVT {0x80,0x9A,0x45,0x41,0x8E,0x41,0x8F,0x80,0x45,0x45,0x45,0x49,0x49,0x49,0x8E,0x8F, \
+                               0x90,0x92,0x92,0x4F,0x99,0x4F,0x55,0x55,0x59,0x99,0x9A,0x9B,0x9C,0x9D,0x9E,0x9F, \
+                               0x41,0x49,0x4F,0x55,0xA5,0xA5,0xA6,0xA7,0xA8,0xA9,0xAA,0xAB,0xAC,0xAD,0xAE,0xAF, \
+                               0xB0,0xB1,0xB2,0xB3,0xB4,0xB5,0xB6,0xB7,0xB8,0xB9,0xBA,0xBB,0xBC,0xBD,0xBE,0xBF, \
+                               0xC0,0xC1,0xC2,0xC3,0xC4,0xC5,0xC6,0xC7,0xC8,0xC9,0xCA,0xCB,0xCC,0xCD,0xCE,0xCF, \
+                               0xD0,0xD1,0xD2,0xD3,0xD4,0xD5,0xD6,0xD7,0xD8,0xD9,0xDA,0xDB,0xDC,0xDD,0xDE,0xDF, \
+                               0xE0,0xE1,0xE2,0xE3,0xE4,0xE5,0xE6,0xE7,0xE8,0xE9,0xEA,0xEB,0xEC,0xED,0xEE,0xEF, \
+                               0xF0,0xF1,0xF2,0xF3,0xF4,0xF5,0xF6,0xF7,0xF8,0xF9,0xFA,0xFB,0xFC,0xFD,0xFE,0xFF}
+
+#elif _CODE_PAGE == 865        /* Nordic */
 #define _DF1S  0
-#define _EXCVT {0x80,0x81,0x82,0x83,0x84,0x85,0x86,0x87,0x88,0x89,0x8A,0x8B,0x8C,0x8D,0x8E,0x8F,0x90,0x91,0x92,0x93,0x94,0x95,0x96,0x97,0x98,0x99,0x8A,0x9B,0x8C,0x9D,0x9E,0x9F, \
-                               0xA0,0x21,0xA2,0xA3,0xA4,0xA5,0xA6,0xA7,0xA8,0xA9,0xAA,0xAB,0xAC,0xAD,0xAE,0xAF,0xB0,0xB1,0xB2,0xB3,0xB4,0xB5,0xB6,0xB7,0xB8,0xB9,0xBA,0xBB,0xBC,0xBD,0xBE,0xBF, \
-                               0xC0,0xC1,0xC2,0xC3,0xC4,0xC5,0xC6,0xC7,0xC8,0xC9,0xCA,0xCB,0xCC,0xCD,0xCE,0xCF,0xD0,0xD1,0xD2,0xD3,0xD4,0xD5,0xD6,0xD7,0xD8,0xD9,0xDA,0xDB,0xDC,0xDD,0xDE,0xDF, \
-                               0xC0,0xC1,0xC2,0xC3,0xC4,0xC5,0xC6,0xC7,0xC8,0xC9,0xCA,0xCB,0xCC,0xCD,0xCE,0xCF,0xD0,0xD1,0xD2,0xD3,0xD4,0xD5,0xD6,0xF7,0xD8,0xD9,0xDA,0xDB,0xDC,0xDD,0xDE,0x9F}
-
-#elif _CODE_PAGE == 1255 /* Hebrew (Windows) */
+#define _EXCVT {0x80,0x9A,0x90,0x41,0x8E,0x41,0x8F,0x80,0x45,0x45,0x45,0x49,0x49,0x49,0x8E,0x8F, \
+                               0x90,0x92,0x92,0x4F,0x99,0x4F,0x55,0x55,0x59,0x99,0x9A,0x9B,0x9C,0x9D,0x9E,0x9F, \
+                               0x41,0x49,0x4F,0x55,0xA5,0xA5,0xA6,0xA7,0xA8,0xA9,0xAA,0xAB,0xAC,0xAD,0xAE,0xAF, \
+                               0xB0,0xB1,0xB2,0xB3,0xB4,0xB5,0xB6,0xB7,0xB8,0xB9,0xBA,0xBB,0xBC,0xBD,0xBE,0xBF, \
+                               0xC0,0xC1,0xC2,0xC3,0xC4,0xC5,0xC6,0xC7,0xC8,0xC9,0xCA,0xCB,0xCC,0xCD,0xCE,0xCF, \
+                               0xD0,0xD1,0xD2,0xD3,0xD4,0xD5,0xD6,0xD7,0xD8,0xD9,0xDA,0xDB,0xDC,0xDD,0xDE,0xDF, \
+                               0xE0,0xE1,0xE2,0xE3,0xE4,0xE5,0xE6,0xE7,0xE8,0xE9,0xEA,0xEB,0xEC,0xED,0xEE,0xEF, \
+                               0xF0,0xF1,0xF2,0xF3,0xF4,0xF5,0xF6,0xF7,0xF8,0xF9,0xFA,0xFB,0xFC,0xFD,0xFE,0xFF}
+
+#elif _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,0x90,0x91,0x92,0x93,0x94,0x95,0x96,0x97,0x98,0x99,0x9A,0x9B,0x9C,0x9D,0x9E,0x9F, \
-                               0xA0,0x21,0xA2,0xA3,0xA4,0xA5,0xA6,0xA7,0xA8,0xA9,0xAA,0xAB,0xAC,0xAD,0xAE,0xAF,0xB0,0xB1,0xB2,0xB3,0xB4,0xB5,0xB6,0xB7,0xB8,0xB9,0xBA,0xBB,0xBC,0xBD,0xBE,0xBF, \
-                               0xC0,0xC1,0xC2,0xC3,0xC4,0xC5,0xC6,0xC7,0xC8,0xC9,0xCA,0xCB,0xCC,0xCD,0xCE,0xCF,0xD0,0xD1,0xD2,0xD3,0xD4,0xD5,0xD6,0xD7,0xD8,0xD9,0xDA,0xDB,0xDC,0xDD,0xDE,0xDF, \
-                               0xE0,0xE1,0xE2,0xE3,0xE4,0xE5,0xE6,0xE7,0xE8,0xE9,0xEA,0xEB,0xEC,0xED,0xEE,0xEF,0xF0,0xF1,0xF2,0xF3,0xF4,0xF5,0xF6,0xF7,0xF8,0xF9,0xFA,0xFB,0xFC,0xFD,0xFE,0xFF}
-
-#elif _CODE_PAGE == 1256 /* Arabic (Windows) */
+#define _EXCVT {0x80,0x81,0x82,0x83,0x84,0x85,0x86,0x87,0x88,0x89,0x8A,0x8B,0x8C,0x8D,0x8E,0x8F, \
+                               0x90,0x91,0x92,0x93,0x94,0x95,0x96,0x97,0x98,0x99,0x9A,0x9B,0x9C,0x9D,0x9E,0x9F, \
+                               0x80,0x81,0x82,0x83,0x84,0x85,0x86,0x87,0x88,0x89,0x8A,0x8B,0x8C,0x8D,0x8E,0x8F, \
+                               0xB0,0xB1,0xB2,0xB3,0xB4,0xB5,0xB6,0xB7,0xB8,0xB9,0xBA,0xBB,0xBC,0xBD,0xBE,0xBF, \
+                               0xC0,0xC1,0xC2,0xC3,0xC4,0xC5,0xC6,0xC7,0xC8,0xC9,0xCA,0xCB,0xCC,0xCD,0xCE,0xCF, \
+                               0xD0,0xD1,0xD2,0xD3,0xD4,0xD5,0xD6,0xD7,0xD8,0xD9,0xDA,0xDB,0xDC,0xDD,0xDE,0xDF, \
+                               0x90,0x91,0x92,0x93,0x9d,0x95,0x96,0x97,0x98,0x99,0x9A,0x9B,0x9C,0x9D,0x9E,0x9F, \
+                               0xF0,0xF0,0xF2,0xF2,0xF4,0xF4,0xF6,0xF6,0xF8,0xF9,0xFA,0xFB,0xFC,0xFD,0xFE,0xFF}
+
+#elif _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,0x90,0x91,0x92,0x93,0x94,0x95,0x96,0x97,0x98,0x99,0x9A,0x9B,0x8C,0x9D,0x9E,0x9F, \
-                               0xA0,0xA1,0xA2,0xA3,0xA4,0xA5,0xA6,0xA7,0xA8,0xA9,0xAA,0xAB,0xAC,0xAD,0xAE,0xAF,0xB0,0xB1,0xB2,0xB3,0xB4,0xB5,0xB6,0xB7,0xB8,0xB9,0xBA,0xBB,0xBC,0xBD,0xBE,0xBF, \
-                               0xC0,0xC1,0xC2,0xC3,0xC4,0xC5,0xC6,0xC7,0xC8,0xC9,0xCA,0xCB,0xCC,0xCD,0xCE,0xCF,0xD0,0xD1,0xD2,0xD3,0xD4,0xD5,0xD6,0xD7,0xD8,0xD9,0xDA,0xDB,0xDC,0xDD,0xDE,0xDF, \
-                               0x41,0xE1,0x41,0xE3,0xE4,0xE5,0xE6,0x43,0x45,0x45,0x45,0x45,0xEC,0xED,0x49,0x49,0xF0,0xF1,0xF2,0xF3,0x4F,0xF5,0xF6,0xF7,0xF8,0x55,0xFA,0x55,0x55,0xFD,0xFE,0xFF}
-
-#elif _CODE_PAGE == 1257 /* Baltic (Windows) */
-#define _DF1S  0
-#define _EXCVT {0x80,0x81,0x82,0x83,0x84,0x85,0x86,0x87,0x88,0x89,0x8A,0x8B,0x8C,0x8D,0x8E,0x8F,0x90,0x91,0x92,0x93,0x94,0x95,0x96,0x97,0x98,0x99,0x9A,0x9B,0x9C,0x9D,0x9E,0x9F, \
-                               0xA0,0xA1,0xA2,0xA3,0xA4,0xA5,0xA6,0xA7,0xA8,0xA9,0xAA,0xAB,0xAC,0xAD,0xAE,0xAF,0xB0,0xB1,0xB2,0xB3,0xB4,0xB5,0xB6,0xB7,0xA8,0xB9,0xAA,0xBB,0xBC,0xBD,0xBE,0xAF, \
-                               0xC0,0xC1,0xC2,0xC3,0xC4,0xC5,0xC6,0xC7,0xC8,0xC9,0xCA,0xCB,0xCC,0xCD,0xCE,0xCF,0xD0,0xD1,0xD2,0xD3,0xD4,0xD5,0xD6,0xD7,0xD8,0xD9,0xDA,0xDB,0xDC,0xDD,0xDE,0xDF, \
-                               0xC0,0xC1,0xC2,0xC3,0xC4,0xC5,0xC6,0xC7,0xC8,0xC9,0xCA,0xCB,0xCC,0xCD,0xCE,0xCF,0xD0,0xD1,0xD2,0xD3,0xD4,0xD5,0xD6,0xF7,0xD8,0xD9,0xDA,0xDB,0xDC,0xDD,0xDE,0xFF}
-
-#elif _CODE_PAGE == 1258 /* Vietnam (OEM, Windows) */
-#define _DF1S  0
-#define _EXCVT {0x80,0x81,0x82,0x83,0x84,0x85,0x86,0x87,0x88,0x89,0x8A,0x8B,0x8C,0x8D,0x8E,0x8F,0x90,0x91,0x92,0x93,0x94,0x95,0x96,0x97,0x98,0x99,0x9A,0x9B,0xAC,0x9D,0x9E,0x9F, \
-                               0xA0,0x21,0xA2,0xA3,0xA4,0xA5,0xA6,0xA7,0xA8,0xA9,0xAA,0xAB,0xAC,0xAD,0xAE,0xAF,0xB0,0xB1,0xB2,0xB3,0xB4,0xB5,0xB6,0xB7,0xB8,0xB9,0xBA,0xBB,0xBC,0xBD,0xBE,0xBF, \
-                               0xC0,0xC1,0xC2,0xC3,0xC4,0xC5,0xC6,0xC7,0xC8,0xC9,0xCA,0xCB,0xCC,0xCD,0xCE,0xCF,0xD0,0xD1,0xD2,0xD3,0xD4,0xD5,0xD6,0xD7,0xD8,0xD9,0xDA,0xDB,0xDC,0xDD,0xDE,0xDF, \
-                               0xC0,0xC1,0xC2,0xC3,0xC4,0xC5,0xC6,0xC7,0xC8,0xC9,0xCA,0xCB,0xEC,0xCD,0xCE,0xCF,0xD0,0xD1,0xF2,0xD3,0xD4,0xD5,0xD6,0xF7,0xD8,0xD9,0xDA,0xDB,0xDC,0xDD,0xFE,0x9F}
+#define _EXCVT {0x80,0x81,0x82,0x83,0x84,0x85,0x86,0x87,0x88,0x89,0x8A,0x8B,0x8C,0x8D,0x8E,0x8F, \
+                               0x90,0x91,0x92,0x93,0x94,0x95,0x96,0x97,0x98,0x99,0x9A,0x86,0x9C,0x8D,0x8F,0x90, \
+                               0x91,0x90,0x92,0x95,0xA4,0xA5,0xA6,0xA7,0xA8,0xA9,0xAA,0xAB,0xAC,0xAD,0xAE,0xAF, \
+                               0xB0,0xB1,0xB2,0xB3,0xB4,0xB5,0xB6,0xB7,0xB8,0xB9,0xBA,0xBB,0xBC,0xBD,0xBE,0xBF, \
+                               0xC0,0xC1,0xC2,0xC3,0xC4,0xC5,0xC6,0xC7,0xC8,0xC9,0xCA,0xCB,0xCC,0xCD,0xCE,0xCF, \
+                               0xD0,0xD1,0xD2,0xD3,0xD4,0xD5,0xA4,0xA5,0xA6,0xD9,0xDA,0xDB,0xDC,0xA7,0xA8,0xDF, \
+                               0xA9,0xAA,0xAC,0xAD,0xB5,0xB6,0xB7,0xB8,0xBD,0xBE,0xC6,0xC7,0xCF,0xCF,0xD0,0xEF, \
+                               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
@@ -396,7 +348,7 @@ typedef struct {
 
 
 /* Name status flags */
-#define NS                     11              /* Index of name status byte in fn[] */
+#define NSFLAG         11              /* Index of name status byte in fn[] */
 #define NS_LOSS                0x01    /* Out of 8.3 format */
 #define NS_LFN         0x02    /* Force to create LFN entry */
 #define NS_LAST                0x04    /* Last segment */
@@ -405,138 +357,133 @@ typedef struct {
 #define NS_DOT         0x20    /* Dot entry */
 
 
-/* FAT sub-type boundaries */
-#define MIN_FAT16      4086U   /* Minimum number of clusters for FAT16 */
-#define        MIN_FAT32       65526U  /* Minimum number of clusters for FAT32 */
+/* FAT sub-type boundaries (Differ from specs but correct for real DOS/Windows) */
+#define MIN_FAT16      4086U   /* Minimum number of clusters of FAT16 */
+#define        MIN_FAT32       65526U  /* Minimum number of clusters of FAT32 */
 
 
 /* FatFs refers the members in the FAT structures as byte array instead of
-/ structure member because the structure is not binary compatible between
+/ structure members because the structure is not binary compatible between
 / different platforms */
 
-#define BS_jmpBoot                     0       /* Jump instruction (3) */
-#define BS_OEMName                     3       /* OEM name (8) */
-#define BPB_BytsPerSec         11      /* Sector size [byte] (2) */
-#define BPB_SecPerClus         13      /* Cluster size [sector] (1) */
-#define BPB_RsvdSecCnt         14      /* Size of reserved area [sector] (2) */
-#define BPB_NumFATs                    16      /* Number of FAT copies (1) */
-#define BPB_RootEntCnt         17      /* Number of root directory entries for FAT12/16 (2) */
-#define BPB_TotSec16           19      /* Volume size [sector] (2) */
-#define BPB_Media                      21      /* Media descriptor (1) */
-#define BPB_FATSz16                    22      /* FAT size [sector] (2) */
-#define BPB_SecPerTrk          24      /* Track size [sector] (2) */
-#define BPB_NumHeads           26      /* Number of heads (2) */
-#define BPB_HiddSec                    28      /* Number of special hidden sectors (4) */
-#define BPB_TotSec32           32      /* Volume size [sector] (4) */
-#define BS_DrvNum                      36      /* Physical drive number (2) */
-#define BS_BootSig                     38      /* Extended boot signature (1) */
-#define BS_VolID                       39      /* Volume serial number (4) */
-#define BS_VolLab                      43      /* Volume label (8) */
-#define BS_FilSysType          54      /* File system type (1) */
-#define BPB_FATSz32                    36      /* FAT size [sector] (4) */
-#define BPB_ExtFlags           40      /* Extended flags (2) */
-#define BPB_FSVer                      42      /* File system version (2) */
-#define BPB_RootClus           44      /* Root directory first cluster (4) */
-#define BPB_FSInfo                     48      /* Offset of FSINFO sector (2) */
-#define BPB_BkBootSec          50      /* Offset of backup boot sector (2) */
-#define BS_DrvNum32                    64      /* Physical drive number (2) */
-#define BS_BootSig32           66      /* Extended boot signature (1) */
-#define BS_VolID32                     67      /* Volume serial number (4) */
-#define BS_VolLab32                    71      /* Volume label (8) */
-#define BS_FilSysType32                82      /* File system type (1) */
-#define        FSI_LeadSig                     0       /* FSI: Leading signature (4) */
-#define        FSI_StrucSig            484     /* FSI: Structure signature (4) */
-#define        FSI_Free_Count          488     /* FSI: Number of free clusters (4) */
-#define        FSI_Nxt_Free            492     /* FSI: Last allocated cluster (4) */
-#define MBR_Table                      446     /* MBR: Partition table offset (2) */
-#define        SZ_PTE                          16      /* MBR: Size of a partition table entry */
-#define BS_55AA                                510     /* Boot sector signature (2) */
-
-#define        DIR_Name                        0       /* Short file name (11) */
-#define        DIR_Attr                        11      /* Attribute (1) */
-#define        DIR_NTres                       12      /* NT flag (1) */
-#define DIR_CrtTimeTenth       13      /* Created time sub-second (1) */
-#define        DIR_CrtTime                     14      /* Created time (2) */
-#define        DIR_CrtDate                     16      /* Created date (2) */
-#define DIR_LstAccDate         18      /* Last accessed date (2) */
-#define        DIR_FstClusHI           20      /* Higher 16-bit of first cluster (2) */
-#define        DIR_WrtTime                     22      /* Modified time (2) */
-#define        DIR_WrtDate                     24      /* Modified date (2) */
-#define        DIR_FstClusLO           26      /* Lower 16-bit of first cluster (2) */
-#define        DIR_FileSize            28      /* File size (4) */
-#define        LDIR_Ord                        0       /* LFN entry order and LLE flag (1) */
-#define        LDIR_Attr                       11      /* LFN attribute (1) */
-#define        LDIR_Type                       12      /* LFN type (1) */
-#define        LDIR_Chksum                     13      /* Sum of corresponding SFN entry */
-#define        LDIR_FstClusLO          26      /* Filled by zero (0) */
-#define        SZ_DIR                          32              /* Size of a directory entry */
-#define        LLE                                     0x40    /* Last long entry flag in LDIR_Ord */
-#define        DDE                                     0xE5    /* Deleted directory entry mark in DIR_Name[0] */
-#define        NDDE                            0x05    /* Replacement of the character collides with DDE */
-
-
-
-
-/*------------------------------------------------------------*/
-/* Module private work area                                   */
-/*------------------------------------------------------------*/
-/* Note that uninitialized variables with static duration are
-/  guaranteed zero/null as initial value. If not, either the
-/  compiler or start-up routine is out of ANSI-C standard.
+#define BS_jmpBoot                     0               /* x86 jump instruction (3) */
+#define BS_OEMName                     3               /* OEM name (8) */
+#define BPB_BytsPerSec         11              /* Sector size [byte] (2) */
+#define BPB_SecPerClus         13              /* Cluster size [sector] (1) */
+#define BPB_RsvdSecCnt         14              /* Size of reserved area [sector] (2) */
+#define BPB_NumFATs                    16              /* Number of FAT copies (1) */
+#define BPB_RootEntCnt         17              /* Number of root directory entries for FAT12/16 (2) */
+#define BPB_TotSec16           19              /* Volume size [sector] (2) */
+#define BPB_Media                      21              /* Media descriptor (1) */
+#define BPB_FATSz16                    22              /* FAT size [sector] (2) */
+#define BPB_SecPerTrk          24              /* Track size [sector] (2) */
+#define BPB_NumHeads           26              /* Number of heads (2) */
+#define BPB_HiddSec                    28              /* Number of special hidden sectors (4) */
+#define BPB_TotSec32           32              /* Volume size [sector] (4) */
+#define BS_DrvNum                      36              /* Physical drive number (1) */
+#define BS_NTres                       37              /* Error flag (1) */
+#define BS_BootSig                     38              /* Extended boot signature (1) */
+#define BS_VolID                       39              /* Volume serial number (4) */
+#define BS_VolLab                      43              /* Volume label (8) */
+#define BS_FilSysType          54              /* File system type (1) */
+#define BPB_FATSz32                    36              /* FAT size [sector] (4) */
+#define BPB_ExtFlags           40              /* Extended flags (2) */
+#define BPB_FSVer                      42              /* File system version (2) */
+#define BPB_RootClus           44              /* Root directory first cluster (4) */
+#define BPB_FSInfo                     48              /* Offset of FSINFO sector (2) */
+#define BPB_BkBootSec          50              /* Offset of backup boot sector (2) */
+#define BS_DrvNum32                    64              /* Physical drive number (1) */
+#define BS_NTres32                     65              /* Error flag (1) */
+#define BS_BootSig32           66              /* Extended boot signature (1) */
+#define BS_VolID32                     67              /* Volume serial number (4) */
+#define BS_VolLab32                    71              /* Volume label (8) */
+#define BS_FilSysType32                82              /* File system type (1) */
+#define        FSI_LeadSig                     0               /* FSI: Leading signature (4) */
+#define        FSI_StrucSig            484             /* FSI: Structure signature (4) */
+#define        FSI_Free_Count          488             /* FSI: Number of free clusters (4) */
+#define        FSI_Nxt_Free            492             /* FSI: Last allocated cluster (4) */
+#define MBR_Table                      446             /* MBR: Partition table offset (2) */
+#define        SZ_PTE                          16              /* MBR: Size of a partition table entry */
+#define BS_55AA                                510             /* Signature word (2) */
+
+#define        DIR_Name                        0               /* Short file name (11) */
+#define        DIR_Attr                        11              /* Attribute (1) */
+#define        DIR_NTres                       12              /* Lower case flag (1) */
+#define DIR_CrtTimeTenth       13              /* Created time sub-second (1) */
+#define        DIR_CrtTime                     14              /* Created time (2) */
+#define        DIR_CrtDate                     16              /* Created date (2) */
+#define DIR_LstAccDate         18              /* Last accessed date (2) */
+#define        DIR_FstClusHI           20              /* Higher 16-bit of first cluster (2) */
+#define        DIR_WrtTime                     22              /* Modified time (2) */
+#define        DIR_WrtDate                     24              /* Modified date (2) */
+#define        DIR_FstClusLO           26              /* Lower 16-bit of first cluster (2) */
+#define        DIR_FileSize            28              /* File size (4) */
+#define        LDIR_Ord                        0               /* LFN entry order and LLE flag (1) */
+#define        LDIR_Attr                       11              /* LFN attribute (1) */
+#define        LDIR_Type                       12              /* LFN type (1) */
+#define        LDIR_Chksum                     13              /* Checksum of corresponding SFN entry */
+#define        LDIR_FstClusLO          26              /* Must be zero (0) */
+#define        SZ_DIRE                         32              /* Size of a directory entry */
+#define        LLEF                            0x40    /* Last long entry flag in LDIR_Ord */
+#define        DDEM                            0xE5    /* Deleted directory entry mark at DIR_Name[0] */
+#define        RDDEM                           0x05    /* Replacement of the character collides with DDEM */
+
+
+
+
+/*--------------------------------------------------------------------------
+
+   Module Private Work Area
+
+---------------------------------------------------------------------------*/
+
+/* Remark: Uninitialized variables with static duration are guaranteed
+/  zero/null at start-up. If not, either the linker or start-up routine
+/  being used is not compliance with ANSI-C standard.
 */
 
-#if _VOLUMES >= 1 || _VOLUMES <= 10
-static
-FATFS *FatFs[_VOLUMES];                /* Pointer to the file system objects (logical drives) */
-#else
-#error Number of volumes must be 1 to 10.
+#if _VOLUMES < 1 || _VOLUMES > 9
+#error Wrong _VOLUMES setting
 #endif
-
-static
-WORD Fsid;                                     /* File system mount ID */
+static FATFS *FatFs[_VOLUMES]; /* Pointer to the file system objects (logical drives) */
+static WORD Fsid;                              /* File system mount ID */
 
 #if _FS_RPATH && _VOLUMES >= 2
-static
-BYTE CurrVol;                          /* Current drive */
+static BYTE CurrVol;                   /* Current drive */
 #endif
 
 #if _FS_LOCK
-static
-FILESEM        Files[_FS_LOCK];        /* Open object lock semaphores */
+static FILESEM Files[_FS_LOCK];        /* Open object lock semaphores */
 #endif
 
-#if _USE_LFN == 0                      /* No LFN feature */
-#define        DEF_NAMEBUF                     BYTE sfn[12]
+#if _USE_LFN == 0                      /* Non LFN feature */
+#define        DEFINE_NAMEBUF          BYTE sfn[12]
 #define INIT_BUF(dobj)         (dobj).fn = sfn
 #define        FREE_BUF()
-
-#elif _USE_LFN == 1                    /* LFN feature with static working buffer */
-static
-WCHAR LfnBuf[_MAX_LFN+1];
-#define        DEF_NAMEBUF                     BYTE sfn[12]
+#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];
+#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        DEF_NAMEBUF                     BYTE sfn[12]; WCHAR lbuf[_MAX_LFN+1]
+#define        DEFINE_NAMEBUF          BYTE sfn[12]; WCHAR lbuf[_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 */
-#define        DEF_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        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        FREE_BUF()                      ff_memfree(lfn)
-
 #else
-#error Wrong LFN configuration.
+#error Wrong _USE_LFN setting
+#endif
 #endif
-
 
 #ifdef _EXCVT
-static
-const BYTE ExCvt[] = _EXCVT;   /* Upper conversion table for extended characters */
+static const BYTE ExCvt[] = _EXCVT;    /* Upper conversion table for SBCS extended characters */
 #endif
 
 
@@ -641,7 +588,7 @@ void unlock_fs (
 static
 FRESULT chk_lock (     /* Check if the file can be accessed */
        DIR* dp,                /* Directory object pointing the file to be checked */
-       int acc                 /* Desired access (0:Read, 1:Write, 2:Delete/Rename) */
+       int acc                 /* Desired access type (0:Read, 1:Write, 2:Delete/Rename) */
 )
 {
        UINT i, be;
@@ -750,48 +697,56 @@ void clear_lock ( /* Clear lock entries of the volume */
 /*-----------------------------------------------------------------------*/
 #if !_FS_READONLY
 static
-FRESULT sync_window (
+FRESULT sync_window (  /* FR_OK:succeeded, !=0:error */
        FATFS* fs               /* File system object */
 )
 {
        DWORD wsect;
        UINT nf;
+       FRESULT res = FR_OK;
 
 
        if (fs->wflag) {        /* Write back the sector if it is dirty */
                wsect = fs->winsect;    /* Current sector number */
-               if (disk_write(fs->drv, fs->win, wsect, 1))
-                       return FR_DISK_ERR;
-               fs->wflag = 0;
-               if (wsect - fs->fatbase < fs->fsize) {          /* Is it in the FAT area? */
-                       for (nf = fs->n_fats; nf >= 2; nf--) {  /* Reflect the change to all FAT copies */
-                               wsect += fs->fsize;
-                               disk_write(fs->drv, fs->win, wsect, 1);
+               if (disk_write(fs->drv, fs->win, wsect, 1) != RES_OK) {
+                       res = FR_DISK_ERR;
+               } else {
+                       fs->wflag = 0;
+                       if (wsect - fs->fatbase < fs->fsize) {          /* Is it in the FAT area? */
+                               for (nf = fs->n_fats; nf >= 2; nf--) {  /* Reflect the change to all FAT copies */
+                                       wsect += fs->fsize;
+                                       disk_write(fs->drv, fs->win, wsect, 1);
+                               }
                        }
                }
        }
-       return FR_OK;
+       return res;
 }
 #endif
 
 
 static
-FRESULT move_window (
+FRESULT move_window (  /* FR_OK(0):succeeded, !=0:error */
        FATFS* fs,              /* File system object */
        DWORD sector    /* Sector number to make appearance in the fs->win[] */
 )
 {
-       if (sector != fs->winsect) {    /* Changed current window */
+       FRESULT res = FR_OK;
+
+
+       if (sector != fs->winsect) {    /* Window offset changed? */
 #if !_FS_READONLY
-               if (sync_window(fs) != FR_OK)
-                       return FR_DISK_ERR;
+               res = sync_window(fs);          /* Write-back changes */
 #endif
-               if (disk_read(fs->drv, fs->win, sector, 1))
-                       return FR_DISK_ERR;
-               fs->winsect = sector;
+               if (res == FR_OK) {                     /* Fill sector window with new data */
+                       if (disk_read(fs->drv, fs->win, sector, 1) != RES_OK) {
+                               sector = 0xFFFFFFFF;    /* Invalidate window if data is not reliable */
+                               res = FR_DISK_ERR;
+                       }
+                       fs->winsect = sector;
+               }
        }
-
-       return FR_OK;
+       return res;
 }
 
 
@@ -802,7 +757,7 @@ FRESULT move_window (
 /*-----------------------------------------------------------------------*/
 #if !_FS_READONLY
 static
-FRESULT sync_fs (      /* FR_OK: successful, FR_DISK_ERR: failed */
+FRESULT sync_fs (      /* FR_OK:succeeded, !=0:error */
        FATFS* fs               /* File system object */
 )
 {
@@ -811,16 +766,16 @@ FRESULT sync_fs ( /* FR_OK: successful, FR_DISK_ERR: failed */
 
        res = sync_window(fs);
        if (res == FR_OK) {
-               /* Update FSINFO sector if needed */
+               /* Update FSInfo sector if needed */
                if (fs->fs_type == FS_FAT32 && fs->fsi_flag == 1) {
-                       /* Create FSINFO structure */
+                       /* Create FSInfo structure */
                        mem_set(fs->win, 0, SS(fs));
-                       ST_WORD(fs->win+BS_55AA, 0xAA55);
-                       ST_DWORD(fs->win+FSI_LeadSig, 0x41615252);
-                       ST_DWORD(fs->win+FSI_StrucSig, 0x61417272);
-                       ST_DWORD(fs->win+FSI_Free_Count, fs->free_clust);
-                       ST_DWORD(fs->win+FSI_Nxt_Free, fs->last_clust);
-                       /* Write it into the FSINFO sector */
+                       ST_WORD(fs->win + BS_55AA, 0xAA55);
+                       ST_DWORD(fs->win + FSI_LeadSig, 0x41615252);
+                       ST_DWORD(fs->win + FSI_StrucSig, 0x61417272);
+                       ST_DWORD(fs->win + FSI_Free_Count, fs->free_clust);
+                       ST_DWORD(fs->win + FSI_Nxt_Free, fs->last_clust);
+                       /* Write it into the FSInfo sector */
                        fs->winsect = fs->volbase + 1;
                        disk_write(fs->drv, fs->win, fs->winsect, 1);
                        fs->fsi_flag = 0;
@@ -840,15 +795,15 @@ FRESULT sync_fs ( /* FR_OK: successful, FR_DISK_ERR: failed */
 /*-----------------------------------------------------------------------*/
 /* Get sector# from cluster#                                             */
 /*-----------------------------------------------------------------------*/
+/* Hidden API for hacks and disk tools */
 
-
-DWORD clust2sect (     /* !=0: Sector number, 0: Failed - invalid cluster# */
+DWORD clust2sect (     /* !=0:Sector number, 0:Failed (invalid cluster#) */
        FATFS* fs,              /* File system object */
        DWORD clst              /* Cluster# to be converted */
 )
 {
        clst -= 2;
-       if (clst >= (fs->n_fatent - 2)) return 0;               /* Invalid cluster# */
+       if (clst >= fs->n_fatent - 2) return 0;         /* Invalid cluster# */
        return clst * fs->csize + fs->database;
 }
 
@@ -858,44 +813,52 @@ DWORD clust2sect (        /* !=0: Sector number, 0: Failed - invalid cluster# */
 /*-----------------------------------------------------------------------*/
 /* FAT access - Read value of a FAT entry                                */
 /*-----------------------------------------------------------------------*/
+/* Hidden API for hacks and disk tools */
 
-
-DWORD get_fat (        /* 0xFFFFFFFF:Disk error, 1:Internal error, Else:Cluster status */
+DWORD get_fat (        /* 0xFFFFFFFF:Disk error, 1:Internal error, 2..0x0FFFFFFF:Cluster status */
        FATFS* fs,      /* File system object */
-       DWORD clst      /* Cluster# to get the link information */
+       DWORD clst      /* FAT index number (cluster number) to get the value */
 )
 {
        UINT wc, bc;
        BYTE *p;
+       DWORD val;
+
 
+       if (clst < 2 || clst >= fs->n_fatent) { /* Check if in valid range */
+               val = 1;        /* Internal error */
 
-       if (clst < 2 || clst >= fs->n_fatent)   /* Check range */
-               return 1;
+       } else {
+               val = 0xFFFFFFFF;       /* Default value falls on disk error */
 
-       switch (fs->fs_type) {
-       case FS_FAT12 :
-               bc = (UINT)clst; bc += bc / 2;
-               if (move_window(fs, fs->fatbase + (bc / SS(fs)))) break;
-               wc = fs->win[bc % SS(fs)]; bc++;
-               if (move_window(fs, fs->fatbase + (bc / SS(fs)))) break;
-               wc |= fs->win[bc % SS(fs)] << 8;
-               return clst & 1 ? wc >> 4 : (wc & 0xFFF);
+               switch (fs->fs_type) {
+               case FS_FAT12 :
+                       bc = (UINT)clst; bc += bc / 2;
+                       if (move_window(fs, fs->fatbase + (bc / SS(fs))) != FR_OK) break;
+                       wc = fs->win[bc++ % SS(fs)];
+                       if (move_window(fs, fs->fatbase + (bc / SS(fs))) != FR_OK) break;
+                       wc |= fs->win[bc % SS(fs)] << 8;
+                       val = clst & 1 ? wc >> 4 : (wc & 0xFFF);
+                       break;
 
-       case FS_FAT16 :
-               if (move_window(fs, fs->fatbase + (clst / (SS(fs) / 2)))) break;
-               p = &fs->win[clst * 2 % SS(fs)];
-               return LD_WORD(p);
+               case FS_FAT16 :
+                       if (move_window(fs, fs->fatbase + (clst / (SS(fs) / 2))) != FR_OK) break;
+                       p = &fs->win[clst * 2 % SS(fs)];
+                       val = LD_WORD(p);
+                       break;
 
-       case FS_FAT32 :
-               if (move_window(fs, fs->fatbase + (clst / (SS(fs) / 4)))) break;
-               p = &fs->win[clst * 4 % SS(fs)];
-               return LD_DWORD(p) & 0x0FFFFFFF;
+               case FS_FAT32 :
+                       if (move_window(fs, fs->fatbase + (clst / (SS(fs) / 4))) != FR_OK) break;
+                       p = &fs->win[clst * 4 % SS(fs)];
+                       val = LD_DWORD(p) & 0x0FFFFFFF;
+                       break;
 
-       default:
-               return 1;
+               default:
+                       val = 1;        /* Internal error */
+               }
        }
 
-       return 0xFFFFFFFF;      /* An error occurred at the disk I/O layer */
+       return val;
 }
 
 
@@ -904,12 +867,13 @@ DWORD get_fat (   /* 0xFFFFFFFF:Disk error, 1:Internal error, Else:Cluster status
 /*-----------------------------------------------------------------------*/
 /* FAT access - Change value of a FAT entry                              */
 /*-----------------------------------------------------------------------*/
-#if !_FS_READONLY
+/* Hidden API for hacks and disk tools */
 
-FRESULT put_fat (
-       FATFS* fs,      /* File system object */
-       DWORD clst,     /* Cluster# to be changed in range of 2 to fs->n_fatent - 1 */
-       DWORD val       /* New value to mark the cluster */
+#if !_FS_READONLY
+FRESULT put_fat (      /* FR_OK(0):succeeded, !=0:error */
+       FATFS* fs,              /* File system object */
+       DWORD clst,             /* FAT index number (cluster number) to be changed */
+       DWORD val               /* New value to be set to the entry */
 )
 {
        UINT bc;
@@ -917,7 +881,7 @@ FRESULT put_fat (
        FRESULT res;
 
 
-       if (clst < 2 || clst >= fs->n_fatent) { /* Check range */
+       if (clst < 2 || clst >= fs->n_fatent) { /* Check if in valid range */
                res = FR_INT_ERR;
 
        } else {
@@ -926,14 +890,14 @@ FRESULT put_fat (
                        bc = (UINT)clst; bc += bc / 2;
                        res = move_window(fs, fs->fatbase + (bc / SS(fs)));
                        if (res != FR_OK) break;
-                       p = &fs->win[bc % SS(fs)];
+                       p = &fs->win[bc++ % SS(fs)];
                        *p = (clst & 1) ? ((*p & 0x0F) | ((BYTE)val << 4)) : (BYTE)val;
-                       bc++;
                        fs->wflag = 1;
                        res = move_window(fs, fs->fatbase + (bc / SS(fs)));
                        if (res != FR_OK) break;
                        p = &fs->win[bc % SS(fs)];
                        *p = (clst & 1) ? (BYTE)(val >> 4) : ((*p & 0xF0) | ((BYTE)(val >> 8) & 0x0F));
+                       fs->wflag = 1;
                        break;
 
                case FS_FAT16 :
@@ -941,6 +905,7 @@ FRESULT put_fat (
                        if (res != FR_OK) break;
                        p = &fs->win[clst * 2 % SS(fs)];
                        ST_WORD(p, (WORD)val);
+                       fs->wflag = 1;
                        break;
 
                case FS_FAT32 :
@@ -949,12 +914,12 @@ FRESULT put_fat (
                        p = &fs->win[clst * 4 % SS(fs)];
                        val |= LD_DWORD(p) & 0xF0000000;
                        ST_DWORD(p, val);
+                       fs->wflag = 1;
                        break;
 
                default :
                        res = FR_INT_ERR;
                }
-               fs->wflag = 1;
        }
 
        return res;
@@ -969,18 +934,18 @@ FRESULT put_fat (
 /*-----------------------------------------------------------------------*/
 #if !_FS_READONLY
 static
-FRESULT remove_chain (
+FRESULT remove_chain ( /* FR_OK(0):succeeded, !=0:error */
        FATFS* fs,                      /* File system object */
        DWORD clst                      /* Cluster# to remove a chain from */
 )
 {
        FRESULT res;
        DWORD nxt;
-#if _USE_ERASE
+#if _USE_TRIM
        DWORD scl = clst, ecl = clst, rt[2];
 #endif
 
-       if (clst < 2 || clst >= fs->n_fatent) { /* Check range */
+       if (clst < 2 || clst >= fs->n_fatent) { /* Check if in valid range */
                res = FR_INT_ERR;
 
        } else {
@@ -996,13 +961,13 @@ FRESULT remove_chain (
                                fs->free_clust++;
                                fs->fsi_flag |= 1;
                        }
-#if _USE_ERASE
+#if _USE_TRIM
                        if (ecl + 1 == nxt) {   /* Is next cluster contiguous? */
                                ecl = nxt;
                        } else {                                /* End of contiguous clusters */ 
                                rt[0] = clust2sect(fs, scl);                                    /* Start sector */
                                rt[1] = clust2sect(fs, ecl) + fs->csize - 1;    /* End sector */
-                               disk_ioctl(fs->drv, CTRL_ERASE_SECTOR, rt);             /* Erase the block */
+                               disk_ioctl(fs->drv, CTRL_TRIM, rt);                             /* Erase the block */
                                scl = ecl = nxt;
                        }
 #endif
@@ -1024,7 +989,7 @@ FRESULT remove_chain (
 static
 DWORD create_chain (   /* 0:No free cluster, 1:Internal error, 0xFFFFFFFF:Disk error, >=2:New cluster# */
        FATFS* fs,                      /* File system object */
-       DWORD clst                      /* Cluster# to stretch. 0 means create a new chain. */
+       DWORD clst                      /* Cluster# to stretch, 0:Create a new chain */
 )
 {
        DWORD cs, ncl, scl;
@@ -1112,7 +1077,7 @@ DWORD clmt_clust (        /* <2:Error, >=2:Cluster number */
 /*-----------------------------------------------------------------------*/
 
 static
-FRESULT dir_sdi (
+FRESULT dir_sdi (      /* FR_OK(0):succeeded, !=0:error */
        DIR* dp,                /* Pointer to directory object */
        UINT idx                /* Index of directory table */
 )
@@ -1134,7 +1099,7 @@ FRESULT dir_sdi (
                sect = dp->fs->dirbase;
        }
        else {                          /* Dynamic table (root-directory in FAT32 or sub-directory) */
-               ic = SS(dp->fs) / SZ_DIR * dp->fs->csize;       /* Entries per cluster */
+               ic = SS(dp->fs) / SZ_DIRE * dp->fs->csize;      /* Entries per cluster */
                while (idx >= ic) {     /* Follow cluster chain */
                        clst = get_fat(dp->fs, clst);                           /* Get next cluster */
                        if (clst == 0xFFFFFFFF) return FR_DISK_ERR;     /* Disk error */
@@ -1146,8 +1111,8 @@ FRESULT dir_sdi (
        }
        dp->clust = clst;       /* Current cluster# */
        if (!sect) return FR_INT_ERR;
-       dp->sect = sect + idx / (SS(dp->fs) / SZ_DIR);                                  /* Sector# of the directory entry */
-       dp->dir = dp->fs->win + (idx % (SS(dp->fs) / SZ_DIR)) * SZ_DIR; /* Ptr to the entry in the sector */
+       dp->sect = sect + idx / (SS(dp->fs) / SZ_DIRE);                                 /* Sector# of the directory entry */
+       dp->dir = dp->fs->win + (idx % (SS(dp->fs) / SZ_DIRE)) * SZ_DIRE;       /* Ptr to the entry in the sector */
 
        return FR_OK;
 }
@@ -1160,20 +1125,23 @@ FRESULT dir_sdi (
 /*-----------------------------------------------------------------------*/
 
 static
-FRESULT dir_next (     /* FR_OK:Succeeded, FR_NO_FILE:End of table, FR_DENIED:Could not stretch */
+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 */
        int stretch             /* 0: Do not stretch table, 1: Stretch table if needed */
 )
 {
        DWORD clst;
        UINT i;
+#if !_FS_READONLY
+       UINT c;
+#endif
 
 
        i = dp->index + 1;
        if (!(i & 0xFFFF) || !dp->sect) /* Report EOT when index has reached 65535 */
                return FR_NO_FILE;
 
-       if (!(i % (SS(dp->fs) / SZ_DIR))) {     /* Sector changed? */
+       if (!(i % (SS(dp->fs) / SZ_DIRE))) {    /* Sector changed? */
                dp->sect++;                                     /* Next sector */
 
                if (!dp->clust) {               /* Static table */
@@ -1181,13 +1149,12 @@ FRESULT dir_next (      /* FR_OK:Succeeded, FR_NO_FILE:End of table, FR_DENIED:Could
                                return FR_NO_FILE;
                }
                else {                                  /* Dynamic table */
-                       if (((i / (SS(dp->fs) / SZ_DIR)) & (dp->fs->csize - 1)) == 0) { /* Cluster changed? */
+                       if (((i / (SS(dp->fs) / SZ_DIRE)) & (dp->fs->csize - 1)) == 0) {        /* Cluster changed? */
                                clst = get_fat(dp->fs, dp->clust);                              /* Get next cluster */
                                if (clst <= 1) return FR_INT_ERR;
                                if (clst == 0xFFFFFFFF) return FR_DISK_ERR;
                                if (clst >= dp->fs->n_fatent) {                                 /* If it reached end of dynamic table, */
 #if !_FS_READONLY
-                                       UINT c;
                                        if (!stretch) return FR_NO_FILE;                        /* If do not stretch, report EOT */
                                        clst = create_chain(dp->fs, dp->clust);         /* Stretch cluster chain */
                                        if (clst == 0) return FR_DENIED;                        /* No free cluster */
@@ -1215,7 +1182,7 @@ FRESULT dir_next (        /* FR_OK:Succeeded, FR_NO_FILE:End of table, FR_DENIED:Could
        }
 
        dp->index = (WORD)i;    /* Current index */
-       dp->dir = dp->fs->win + (i % (SS(dp->fs) / SZ_DIR)) * SZ_DIR;   /* Current entry in the window */
+       dp->dir = dp->fs->win + (i % (SS(dp->fs) / SZ_DIRE)) * SZ_DIRE; /* Current entry in the window */
 
        return FR_OK;
 }
@@ -1229,9 +1196,9 @@ FRESULT dir_next (        /* FR_OK:Succeeded, FR_NO_FILE:End of table, FR_DENIED:Could
 
 #if !_FS_READONLY
 static
-FRESULT dir_alloc (
-       DIR* dp,        /* Pointer to the directory object */
-       UINT nent       /* Number of contiguous entries to allocate (1-21) */
+FRESULT dir_alloc (    /* FR_OK(0):succeeded, !=0:error */
+       DIR* dp,                /* Pointer to the directory object */
+       UINT nent               /* Number of contiguous entries to allocate (1-21) */
 )
 {
        FRESULT res;
@@ -1244,8 +1211,8 @@ FRESULT dir_alloc (
                do {
                        res = move_window(dp->fs, dp->sect);
                        if (res != FR_OK) break;
-                       if (dp->dir[0] == DDE || dp->dir[0] == 0) {     /* Is it a blank entry? */
-                               if (++n == nent) break; /* A block of contiguous entries is found */
+                       if (dp->dir[0] == DDEM || dp->dir[0] == 0) {    /* Is it a free entry? */
+                               if (++n == nent) break; /* A block of contiguous free entries is found */
                        } else {
                                n = 0;                                  /* Not a blank entry. Restart to search */
                        }
@@ -1265,16 +1232,16 @@ FRESULT dir_alloc (
 /*-----------------------------------------------------------------------*/
 
 static
-DWORD ld_clust (
-       FATFS* fs,      /* Pointer to the fs object */
-       BYTE* dir       /* Pointer to the directory entry */
+DWORD ld_clust (       /* Returns the top cluster value of the SFN entry */
+       FATFS* fs,              /* Pointer to the fs object */
+       const BYTE* dir /* Pointer to the SFN entry */
 )
 {
        DWORD cl;
 
-       cl = LD_WORD(dir+DIR_FstClusLO);
+       cl = LD_WORD(dir + DIR_FstClusLO);
        if (fs->fs_type == FS_FAT32)
-               cl |= (DWORD)LD_WORD(dir+DIR_FstClusHI) << 16;
+               cl |= (DWORD)LD_WORD(dir + DIR_FstClusHI) << 16;
 
        return cl;
 }
@@ -1283,12 +1250,12 @@ DWORD ld_clust (
 #if !_FS_READONLY
 static
 void st_clust (
-       BYTE* dir,      /* Pointer to the directory entry */
+       BYTE* dir,      /* Pointer to the SFN entry */
        DWORD cl        /* Value to be set */
 )
 {
-       ST_WORD(dir+DIR_FstClusLO, cl);
-       ST_WORD(dir+DIR_FstClusHI, cl >> 16);
+       ST_WORD(dir + DIR_FstClusLO, cl);
+       ST_WORD(dir + DIR_FstClusHI, cl >> 16);
 }
 #endif
 
@@ -1304,94 +1271,97 @@ const BYTE LfnOfs[] = {1,3,5,7,9,14,16,18,20,22,24,28,30};      /* Offset of LFN char
 
 
 static
-int cmp_lfn (                  /* 1:Matched, 0:Not matched */
-       WCHAR* lfnbuf,          /* Pointer to the LFN to be compared */
-       BYTE* dir                       /* Pointer to the directory entry containing a part of LFN */
+int cmp_lfn (                  /* 1:matched, 0:not matched */
+       WCHAR* lfnbuf,          /* Pointer to the LFN working buffer to be compared */
+       BYTE* dir                       /* Pointer to the directory entry containing the part of LFN */
 )
 {
        UINT i, s;
        WCHAR wc, uc;
 
 
-       i = ((dir[LDIR_Ord] & ~LLE) - 1) * 13;  /* Get offset in the LFN buffer */
-       s = 0; wc = 1;
-       do {
-               uc = LD_WORD(dir+LfnOfs[s]);    /* Pick an LFN character from the entry */
-               if (wc) {       /* Last character has not been processed */
-                       wc = ff_wtoupper(uc);           /* Convert it to upper case */
-                       if (i >= _MAX_LFN || wc != ff_wtoupper(lfnbuf[i++]))    /* Compare it */
-                               return 0;                               /* Not matched */
+       if (LD_WORD(dir + LDIR_FstClusLO) != 0) return 0;       /* Check LDIR_FstClusLO */
+
+       i = ((dir[LDIR_Ord] & 0x3F) - 1) * 13;  /* Offset in the LFN buffer */
+
+       for (wc = 1, s = 0; s < 13; s++) {              /* Process all characters in the entry */
+               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 */
+                               return 0;                                       /* Not matched */
+                       wc = uc;
                } else {
-                       if (uc != 0xFFFF) return 0;     /* Check filler */
+                       if (uc != 0xFFFF) return 0;             /* Check filler */
                }
-       } while (++s < 13);                             /* Repeat until all characters in the entry are checked */
+       }
 
-       if ((dir[LDIR_Ord] & LLE) && wc && lfnbuf[i])   /* Last segment matched but different length */
+       if ((dir[LDIR_Ord] & LLEF) && wc && lfnbuf[i])  /* Last segment matched but different length */
                return 0;
 
-       return 1;                                               /* The part of LFN matched */
+       return 1;               /* The part of LFN matched */
 }
 
 
 
 static
-int pick_lfn (                 /* 1:Succeeded, 0:Buffer overflow */
-       WCHAR* lfnbuf,          /* Pointer to the Unicode-LFN buffer */
-       BYTE* dir                       /* Pointer to the directory entry */
+int pick_lfn (                 /* 1:succeeded, 0:buffer overflow or invalid LFN entry */
+       WCHAR* lfnbuf,          /* Pointer to the LFN working buffer */
+       BYTE* dir                       /* Pointer to the LFN entry */
 )
 {
        UINT i, s;
        WCHAR wc, uc;
 
 
+       if (LD_WORD(dir + LDIR_FstClusLO) != 0) return 0;       /* Check LDIR_FstClusLO */
+
        i = ((dir[LDIR_Ord] & 0x3F) - 1) * 13;  /* Offset in the LFN buffer */
 
-       s = 0; wc = 1;
-       do {
-               uc = LD_WORD(dir+LfnOfs[s]);            /* Pick an LFN character from the entry */
-               if (wc) {       /* Last character has not been processed */
+       for (wc = 1, s = 0; s < 13; s++) {              /* Process all characters in the entry */
+               uc = LD_WORD(dir + LfnOfs[s]);          /* Pick an LFN character */
+               if (wc) {
                        if (i >= _MAX_LFN) return 0;    /* Buffer overflow? */
                        lfnbuf[i++] = wc = uc;                  /* Store it */
                } else {
                        if (uc != 0xFFFF) return 0;             /* Check filler */
                }
-       } while (++s < 13);                                             /* Read all character in the entry */
+       }
 
-       if (dir[LDIR_Ord] & LLE) {                              /* Put terminator if it is the last LFN part */
+       if (dir[LDIR_Ord] & LLEF) {                             /* Put terminator if it is the last LFN part */
                if (i >= _MAX_LFN) return 0;            /* Buffer overflow? */
                lfnbuf[i] = 0;
        }
 
-       return 1;
+       return 1;               /* The part of LFN is valid */
 }
 
 
 #if !_FS_READONLY
 static
 void fit_lfn (
-       const WCHAR* lfnbuf,    /* Pointer to the LFN buffer */
-       BYTE* dir,                              /* Pointer to the directory entry */
+       const WCHAR* lfnbuf,    /* Pointer to the LFN working buffer */
+       BYTE* dir,                              /* Pointer to the LFN entry to be processed */
        BYTE ord,                               /* LFN order (1-20) */
-       BYTE sum                                /* SFN sum */
+       BYTE sum                                /* Checksum of the corresponding SFN */
 )
 {
        UINT i, s;
        WCHAR wc;
 
 
-       dir[LDIR_Chksum] = sum;                 /* Set check sum */
+       dir[LDIR_Chksum] = sum;                 /* Set checksum */
        dir[LDIR_Attr] = AM_LFN;                /* Set attribute. LFN entry */
        dir[LDIR_Type] = 0;
-       ST_WORD(dir+LDIR_FstClusLO, 0);
+       ST_WORD(dir + LDIR_FstClusLO, 0);
 
-       i = (ord - 1) * 13;                             /* Get offset in the LFN buffer */
+       i = (ord - 1) * 13;                             /* Get offset in the LFN working buffer */
        s = wc = 0;
        do {
                if (wc != 0xFFFF) wc = lfnbuf[i++];     /* Get an effective character */
                ST_WORD(dir+LfnOfs[s], wc);     /* Put it */
                if (!wc) wc = 0xFFFF;           /* Padding characters following last character */
        } while (++s < 13);
-       if (wc == 0xFFFF || !lfnbuf[i]) ord |= LLE    /* Bottom LFN part is the start of LFN sequence */
+       if (wc == 0xFFFF || !lfnbuf[i]) ord |= LLEF;    /* Bottom LFN part is the start of LFN sequence */
        dir[LDIR_Ord] = ord;                    /* Set the LFN order */
 }
 
@@ -1415,14 +1385,14 @@ void gen_numname (
 {
        BYTE ns[8], c;
        UINT i, j;
+       WCHAR wc;
+       DWORD sr;
 
 
        mem_cpy(dst, src, 11);
 
        if (seq > 5) {  /* On many collisions, generate a hash number instead of sequential number */
-               WCHAR wc;
-               DWORD sr = seq;
-
+               sr = seq;
                while (*lfn) {  /* Create a CRC */
                        wc = *lfn++;
                        for (i = 0; i < 16; i++) {
@@ -1461,7 +1431,7 @@ void gen_numname (
 
 
 /*-----------------------------------------------------------------------*/
-/* Calculate sum of an SFN                                               */
+/* Calculate checksum of an SFN entry                                    */
 /*-----------------------------------------------------------------------*/
 #if _USE_LFN
 static
@@ -1485,7 +1455,7 @@ BYTE sum_sfn (
 /*-----------------------------------------------------------------------*/
 
 static
-FRESULT dir_find (
+FRESULT dir_find (     /* FR_OK(0):succeeded, !=0:error */
        DIR* dp                 /* Pointer to the directory object linked to the file name */
 )
 {
@@ -1499,7 +1469,7 @@ FRESULT dir_find (
        if (res != FR_OK) return res;
 
 #if _USE_LFN
-       ord = sum = 0xFF;
+       ord = sum = 0xFF; dp->lfn_idx = 0xFFFF; /* Reset LFN sequence */
 #endif
        do {
                res = move_window(dp->fs, dp->sect);
@@ -1509,23 +1479,23 @@ FRESULT dir_find (
                if (c == 0) { res = FR_NO_FILE; break; }        /* Reached to end of table */
 #if _USE_LFN   /* LFN configuration */
                a = dir[DIR_Attr] & AM_MASK;
-               if (c == DDE || ((a & AM_VOL) && a != AM_LFN)) {        /* An entry without valid data */
-                       ord = 0xFF;
+               if (c == DDEM || ((a & AM_VOL) && a != AM_LFN)) {       /* An entry without valid data */
+                       ord = 0xFF; dp->lfn_idx = 0xFFFF;       /* Reset LFN sequence */
                } else {
                        if (a == AM_LFN) {                      /* An LFN entry is found */
                                if (dp->lfn) {
-                                       if (c & LLE) {          /* Is it start of LFN sequence? */
+                                       if (c & LLEF) {         /* Is it start of LFN sequence? */
                                                sum = dir[LDIR_Chksum];
-                                               c &= ~LLE; ord = c;     /* LFN start order */
-                                               dp->lfn_idx = dp->index;
+                                               c &= ~LLEF; ord = c;    /* LFN start order */
+                                               dp->lfn_idx = dp->index;        /* Start index of LFN */
                                        }
                                        /* Check validity of the LFN entry and compare it with given name */
                                        ord = (c == ord && sum == dir[LDIR_Chksum] && cmp_lfn(dp->lfn, dir)) ? ord - 1 : 0xFF;
                                }
                        } else {                                        /* An SFN entry is found */
                                if (!ord && sum == sum_sfn(dir)) break; /* LFN matched? */
+                               if (!(dp->fn[NSFLAG] & NS_LOSS) && !mem_cmp(dir, dp->fn, 11)) break;    /* SFN matched? */
                                ord = 0xFF; dp->lfn_idx = 0xFFFF;       /* Reset LFN sequence */
-                               if (!(dp->fn[NS] & NS_LOSS) && !mem_cmp(dir, dp->fn, 11)) break;        /* SFN matched? */
                        }
                }
 #else          /* Non LFN configuration */
@@ -1566,13 +1536,13 @@ FRESULT dir_read (
                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 == DDE || (!_FS_RPATH && c == '.') || (int)(a == AM_VOL) != vol) {        /* An entry without valid data */
+               if (c == DDEM || (!_FS_RPATH && c == '.') || (int)((a & ~AM_ARC) == AM_VOL) != vol) {   /* An entry without valid data */
                        ord = 0xFF;
                } else {
                        if (a == AM_LFN) {                      /* An LFN entry is found */
-                               if (c & LLE) {                  /* Is it start of LFN sequence? */
+                               if (c & LLEF) {                 /* Is it start of LFN sequence? */
                                        sum = dir[LDIR_Chksum];
-                                       c &= ~LLE; ord = c;
+                                       c &= ~LLEF; ord = c;
                                        dp->lfn_idx = dp->index;
                                }
                                /* Check LFN validity and capture it */
@@ -1584,7 +1554,7 @@ FRESULT dir_read (
                        }
                }
 #else          /* Non LFN configuration */
-               if (c != DDE && (_FS_RPATH || c != '.') && a != AM_LFN && (int)(a == AM_VOL) == vol)    /* Is it a valid entry? */
+               if (c != DDEM && (_FS_RPATH || c != '.') && a != AM_LFN && (int)((a & ~AM_ARC) == AM_VOL) == vol)       /* Is it a valid entry? */
                        break;
 #endif
                res = dir_next(dp, 0);                          /* Next entry */
@@ -1605,7 +1575,7 @@ FRESULT dir_read (
 /*-----------------------------------------------------------------------*/
 #if !_FS_READONLY
 static
-FRESULT dir_register ( /* FR_OK:Successful, FR_DENIED:No free entry or too many SFN collision, FR_DISK_ERR:Disk error */
+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 */
 )
 {
@@ -1619,11 +1589,11 @@ FRESULT dir_register (  /* FR_OK:Successful, FR_DENIED:No free entry or too many
        fn = dp->fn; lfn = dp->lfn;
        mem_cpy(sn, fn, 12);
 
-       if (_FS_RPATH && (sn[NS] & NS_DOT))             /* Cannot create dot entry */
+       if (_FS_RPATH && (sn[NSFLAG] & NS_DOT))         /* Cannot create dot entry */
                return FR_INVALID_NAME;
 
-       if (sn[NS] & NS_LOSS) {                 /* When LFN is out of 8.3 format, generate a numbered name */
-               fn[NS] = 0; dp->lfn = 0;                        /* Find only SFN */
+       if (sn[NSFLAG] & NS_LOSS) {                     /* When LFN is out of 8.3 format, generate a numbered name */
+               fn[NSFLAG] = 0; dp->lfn = 0;                    /* Find only SFN */
                for (n = 1; n < 100; n++) {
                        gen_numname(fn, sn, lfn, n);    /* Generate a numbered name */
                        res = dir_find(dp);                             /* Check if the name collides with existing SFN */
@@ -1631,10 +1601,10 @@ FRESULT dir_register (  /* FR_OK:Successful, FR_DENIED:No free entry or too many
                }
                if (n == 100) return FR_DENIED;         /* Abort if too many collisions */
                if (res != FR_NO_FILE) return res;      /* Abort if the result is other than 'not collided' */
-               fn[NS] = sn[NS]; dp->lfn = lfn;
+               fn[NSFLAG] = sn[NSFLAG]; dp->lfn = lfn;
        }
 
-       if (sn[NS] & NS_LFN) {                  /* When LFN is to be created, allocate entries for an SFN + LFNs. */
+       if (sn[NSFLAG] & NS_LFN) {                      /* When LFN is to be created, allocate entries for an SFN + LFNs. */
                for (n = 0; lfn[n]; n++) ;
                nent = (n + 25) / 13;
        } else {                                                /* Otherwise allocate an entry for an SFN  */
@@ -1645,7 +1615,7 @@ FRESULT dir_register (    /* FR_OK:Successful, FR_DENIED:No free entry or too many
        if (res == FR_OK && --nent) {   /* Set LFN entry if needed */
                res = dir_sdi(dp, dp->index - nent);
                if (res == FR_OK) {
-                       sum = sum_sfn(dp->fn);  /* Sum value of the SFN tied to the LFN */
+                       sum = sum_sfn(dp->fn);  /* Checksum value of the SFN tied to the LFN */
                        do {                                    /* Store LFN entries in bottom first */
                                res = move_window(dp->fs, dp->sect);
                                if (res != FR_OK) break;
@@ -1662,10 +1632,10 @@ FRESULT dir_register (  /* FR_OK:Successful, FR_DENIED:No free entry or too many
        if (res == FR_OK) {                             /* Set SFN entry */
                res = move_window(dp->fs, dp->sect);
                if (res == FR_OK) {
-                       mem_set(dp->dir, 0, SZ_DIR);    /* Clean the entry */
+                       mem_set(dp->dir, 0, SZ_DIRE);   /* Clean the entry */
                        mem_cpy(dp->dir, dp->fn, 11);   /* Put SFN */
 #if _USE_LFN
-                       dp->dir[DIR_NTres] = dp->fn[NS] & (NS_BODY | NS_EXT);   /* Put NT flag */
+                       dp->dir[DIR_NTres] = dp->fn[NSFLAG] & (NS_BODY | NS_EXT);       /* Put NT flag */
 #endif
                        dp->fs->wflag = 1;
                }
@@ -1683,7 +1653,7 @@ FRESULT dir_register (    /* FR_OK:Successful, FR_DENIED:No free entry or too many
 /*-----------------------------------------------------------------------*/
 #if !_FS_READONLY && !_FS_MINIMIZE
 static
-FRESULT dir_remove (   /* FR_OK: Successful, FR_DISK_ERR: A disk error */
+FRESULT dir_remove (   /* FR_OK:Succeeded, FR_DISK_ERR:A disk error */
        DIR* dp                         /* Directory object pointing the entry to be removed */
 )
 {
@@ -1697,8 +1667,8 @@ FRESULT dir_remove (      /* FR_OK: Successful, FR_DISK_ERR: A disk error */
                do {
                        res = move_window(dp->fs, dp->sect);
                        if (res != FR_OK) break;
-                       mem_set(dp->dir, 0, SZ_DIR);    /* Clear and mark the entry "deleted" */
-                       *dp->dir = DDE;
+                       mem_set(dp->dir, 0, SZ_DIRE);   /* Clear and mark the entry "deleted" */
+                       *dp->dir = DDEM;
                        dp->fs->wflag = 1;
                        if (dp->index >= i) break;      /* When reached SFN, all entries of the object has been deleted. */
                        res = dir_next(dp, 0);          /* Next entry */
@@ -1711,8 +1681,8 @@ FRESULT dir_remove (      /* FR_OK: Successful, FR_DISK_ERR: A disk error */
        if (res == FR_OK) {
                res = move_window(dp->fs, dp->sect);
                if (res == FR_OK) {
-                       mem_set(dp->dir, 0, SZ_DIR);    /* Clear and mark the entry "deleted" */
-                       *dp->dir = DDE;
+                       mem_set(dp->dir, 0, SZ_DIRE);   /* Clear and mark the entry "deleted" */
+                       *dp->dir = DDEM;
                        dp->fs->wflag = 1;
                }
        }
@@ -1737,18 +1707,20 @@ void get_fileinfo (             /* No return code */
 {
        UINT i;
        TCHAR *p, c;
-
+       BYTE *dir;
+#if _USE_LFN
+       WCHAR w, *lfn;
+#endif
 
        p = fno->fname;
        if (dp->sect) {         /* Get SFN */
-               BYTE *dir = dp->dir;
-
+               dir = dp->dir;
                i = 0;
                while (i < 11) {                /* Copy name body and extension */
                        c = (TCHAR)dir[i++];
-                       if (c == ' ') continue;                 /* Skip padding spaces */
-                       if (c == NDDE) c = (TCHAR)DDE;  /* Restore replaced DDE character */
-                       if (i == 9) *p++ = '.';                 /* Insert a . if extension is exist */
+                       if (c == ' ') continue;                         /* Skip padding spaces */
+                       if (c == RDDEM) c = (TCHAR)DDEM;        /* Restore replaced DDEM character */
+                       if (i == 9) *p++ = '.';                         /* Insert a . if extension is exist */
 #if _USE_LFN
                        if (IsUpper(c) && (dir[DIR_NTres] & (i >= 9 ? NS_EXT : NS_BODY)))
                                c += 0x20;                      /* To lower */
@@ -1762,16 +1734,14 @@ void get_fileinfo (             /* No return code */
                        *p++ = c;
                }
                fno->fattrib = dir[DIR_Attr];                           /* Attribute */
-               fno->fsize = LD_DWORD(dir+DIR_FileSize);        /* Size */
-               fno->fdate = LD_WORD(dir+DIR_WrtDate);          /* Date */
-               fno->ftime = LD_WORD(dir+DIR_WrtTime);          /* Time */
+               fno->fsize = LD_DWORD(dir + DIR_FileSize);      /* Size */
+               fno->fdate = LD_WORD(dir + DIR_WrtDate);        /* Date */
+               fno->ftime = LD_WORD(dir + DIR_WrtTime);        /* Time */
        }
        *p = 0;         /* Terminate SFN string by a \0 */
 
 #if _USE_LFN
        if (fno->lfname) {
-               WCHAR w, *lfn;
-
                i = 0; p = fno->lfname;
                if (dp->sect && fno->lfsize && dp->lfn_idx != 0xFFFF) { /* Get LFN if available */
                        lfn = dp->lfn;
@@ -1790,17 +1760,87 @@ void get_fileinfo (             /* No return code */
        }
 #endif
 }
-#endif /* _FS_MINIMIZE <= 1 || _FS_RPATH >= 2*/
+#endif /* _FS_MINIMIZE <= 1 || _FS_RPATH >= 2 */
 
 
 
 
 /*-----------------------------------------------------------------------*/
-/* Pick a segment and create the object name in directory form           */
+/* Pattern matching                                                      */
 /*-----------------------------------------------------------------------*/
+#if _USE_FIND && _FS_MINIMIZE <= 1
+static
+WCHAR get_achar (              /* Get a character and advances ptr 1 or 2 */
+       const TCHAR** ptr       /* Pointer to pointer to the SBCS/DBCS/Unicode string */
+)
+{
+       WCHAR chr;
+
+#if !_LFN_UNICODE
+       chr = (BYTE)*(*ptr)++;                                  /* Get a byte */
+       if (IsLower(chr)) chr -= 0x20;                  /* To upper ASCII char */
+       if (IsDBCS1(chr) && IsDBCS2(**ptr))             /* Get DBC 2nd byte if needed */
+               chr = chr << 8 | (BYTE)*(*ptr)++;
+#ifdef _EXCVT
+       if (chr >= 0x80) chr = ExCvt[chr - 0x80];       /* To upper SBCS extended char */
+#endif
+#else
+       chr = ff_wtoupper(*(*ptr)++);                   /* Get a word and to upper */
+#endif
+       return chr;
+}
+
 
 static
-FRESULT create_name (
+int pattern_matching ( /* 0:mismatched, 1:matched */
+       const TCHAR* pat,       /* Matching pattern */
+       const TCHAR* nam,       /* String to be tested */
+       int skip,                       /* Number of pre-skip chars (number of ?s) */
+       int inf                         /* Infinite search (* specified) */
+)
+{
+       const TCHAR *pp, *np;
+       WCHAR pc, nc;
+       int nm, nx;
+
+
+       while (skip--) {                                /* Pre-skip name chars */
+               if (!get_achar(&nam)) return 0; /* Branch mismatched if less name chars */
+       }
+       if (!*pat && inf) return 1;             /* (short circuit) */
+
+       do {
+               pp = pat; np = nam;                     /* Top of pattern and name to match */
+               for (;;) {
+                       if (*pp == '?' || *pp == '*') { /* Wildcard? */
+                               nm = nx = 0;
+                               do {                            /* Analyze the wildcard chars */
+                                       if (*pp++ == '?') nm++; else nx = 1;
+                               } while (*pp == '?' || *pp == '*');
+                               if (pattern_matching(pp, np, nm, nx)) return 1; /* Test new branch (recurs upto number of wildcard blocks in the pattern) */
+                               nc = *np; break;        /* Branch mismatched */
+                       }
+                       pc = get_achar(&pp);    /* Get a pattern char */
+                       nc = get_achar(&np);    /* Get a name char */
+                       if (pc != nc) break;    /* Branch mismatched? */
+                       if (!pc) return 1;              /* Branch matched? (matched at end of both strings) */
+               }
+               get_achar(&nam);                        /* nam++ */
+       } while (inf && nc);                    /* Retry until end of name if infinite search is specified */
+
+       return 0;
+}
+#endif /* _USE_FIND && _FS_MINIMIZE <= 1 */
+
+
+
+
+/*-----------------------------------------------------------------------*/
+/* Pick a top segment and create the object name in directory form       */
+/*-----------------------------------------------------------------------*/
+
+static
+FRESULT create_name (  /* FR_OK: successful, FR_INVALID_NAME: could not create */
        DIR* dp,                        /* Pointer to the directory object */
        const TCHAR** path      /* Pointer to pointer to the segment in the path string */
 )
@@ -1824,9 +1864,9 @@ FRESULT create_name (
                w &= 0xFF;
                if (IsDBCS1(w)) {                               /* Check if it is a DBC 1st byte (always false on SBCS cfg) */
                        b = (BYTE)p[si++];                      /* Get 2nd byte */
+                       w = (w << 8) + b;                       /* Create a DBC */
                        if (!IsDBCS2(b))
                                return FR_INVALID_NAME; /* Reject invalid sequence */
-                       w = (w << 8) + b;                       /* Create a DBC */
                }
                w = ff_convert(w, 1);                   /* Convert ANSI/OEM to Unicode */
                if (!w) return FR_INVALID_NAME; /* Reject invalid code */
@@ -1838,22 +1878,21 @@ FRESULT create_name (
        *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 ((di == 1 && lfn[di-1] == '.') || /* Is this a dot entry? */
-               (di == 2 && lfn[di-1] == '.' && lfn[di-2] == '.')) {
+       if ((di == 1 && lfn[di - 1] == '.') ||
+               (di == 2 && lfn[di - 1] == '.' && lfn[di - 2] == '.')) {        /* Is this segment a dot entry? */
                lfn[di] = 0;
-               for (i = 0; i < 11; i++)
+               for (i = 0; i < 11; i++)                /* Create dot name for SFN entry */
                        dp->fn[i] = (i < di) ? '.' : ' ';
                dp->fn[i] = cf | NS_DOT;                /* This is a dot entry */
                return FR_OK;
        }
 #endif
-       while (di) {                                            /* Strip trailing spaces and dots */
-               w = lfn[di-1];
+       while (di) {                                            /* Snip off trailing spaces and dots if exist */
+               w = lfn[di - 1];
                if (w != ' ' && w != '.') break;
                di--;
        }
        if (!di) return FR_INVALID_NAME;        /* Reject nul string */
-
        lfn[di] = 0;                                            /* LFN is created */
 
        /* Create SFN in directory form */
@@ -1890,12 +1929,12 @@ FRESULT create_name (
                        cf |= NS_LFN;                           /* Force create LFN entry */
                }
 
-               if (_DF1S && w >= 0x100) {              /* Double byte character (always false on SBCS cfg) */
+               if (_DF1S && w >= 0x100) {              /* Is this DBC? (always false at SBCS cfg) */
                        if (i >= ni - 1) {
                                cf |= NS_LOSS | NS_LFN; i = ni; continue;
                        }
                        dp->fn[i++] = (BYTE)(w >> 8);
-               } else {                                                /* Single byte character */
+               } else {                                                /* SBC */
                        if (!w || chk_chr("+,;=[]", w)) {       /* Replace illegal characters for SFN */
                                w = '_'; cf |= NS_LOSS | NS_LFN;/* Lossy conversion */
                        } else {
@@ -1911,7 +1950,7 @@ FRESULT create_name (
                dp->fn[i++] = (BYTE)w;
        }
 
-       if (dp->fn[0] == DDE) dp->fn[0] = NDDE; /* If the first character collides with deleted mark, replace it with 0x05 */
+       if (dp->fn[0] == DDEM) dp->fn[0] = RDDEM;       /* If the first character collides with DDEM, replace it with RDDEM */
 
        if (ni == 8) b <<= 2;
        if ((b & 0x0C) == 0x0C || (b & 0x03) == 0x03)   /* Create LFN entry when there are composite capitals */
@@ -1921,7 +1960,7 @@ FRESULT create_name (
                if ((b & 0x0C) == 0x04) cf |= NS_BODY;  /* NT flag (Filename has only small capital) */
        }
 
-       dp->fn[NS] = cf;        /* SFN is created */
+       dp->fn[NSFLAG] = cf;    /* SFN is created */
 
        return FR_OK;
 
@@ -1932,7 +1971,7 @@ FRESULT create_name (
        const char *p;
 
        /* Create file name in directory form */
-       for (p = *path; *p == '/' || *p == '\\'; p++) ; /* Strip duplicated separator */
+       for (p = *path; *p == '/' || *p == '\\'; p++) ; /* Skip duplicated separator */
        sfn = dp->fn;
        mem_set(sfn, ' ', 11);
        si = i = b = 0; ni = 8;
@@ -1945,7 +1984,7 @@ FRESULT create_name (
                }
                if (c != '/' && c != '\\' && c > ' ') return FR_INVALID_NAME;
                *path = &p[si];                                                                 /* Return pointer to the next segment */
-               sfn[NS] = (c <= ' ') ? NS_LAST | NS_DOT : NS_DOT;       /* Set last segment flag if end of path */
+               sfn[NSFLAG] = (c <= ' ') ? NS_LAST | NS_DOT : NS_DOT;   /* Set last segment flag if end of path */
                return FR_OK;
        }
 #endif
@@ -1967,13 +2006,13 @@ FRESULT create_name (
 #endif
 #endif
                }
-               if (IsDBCS1(c)) {                               /* Check if it is a DBC 1st byte (always false on SBCS cfg) */
+               if (IsDBCS1(c)) {                               /* Check if it is a DBC 1st byte (always false at SBCS cfg.) */
                        d = (BYTE)p[si++];                      /* Get 2nd byte */
                        if (!IsDBCS2(d) || i >= ni - 1) /* Reject invalid DBC */
                                return FR_INVALID_NAME;
                        sfn[i++] = c;
                        sfn[i++] = d;
-               } else {                                                /* Single byte code */
+               } else {                                                /* SBC */
                        if (chk_chr("\"*+,:;<=>\?[]|\x7F", c))  /* Reject illegal chrs for SFN */
                                return FR_INVALID_NAME;
                        if (IsUpper(c)) {                       /* ASCII large capital? */
@@ -1990,13 +2029,13 @@ FRESULT create_name (
        c = (c <= ' ') ? NS_LAST : 0;           /* Set last segment flag if end of path */
 
        if (!i) return FR_INVALID_NAME;         /* Reject nul string */
-       if (sfn[0] == DDE) sfn[0] = NDDE;       /* When first character collides with DDE, replace it with 0x05 */
+       if (sfn[0] == DDEM) sfn[0] = RDDEM;     /* When first character collides with DDEM, replace it with RDDEM */
 
        if (ni == 8) b <<= 2;
        if ((b & 0x03) == 0x01) c |= NS_EXT;    /* NT flag (Name extension has only small capital) */
        if ((b & 0x0C) == 0x04) c |= NS_BODY;   /* NT flag (Name body has only small capital) */
 
-       sfn[NS] = c;            /* Store NT flag, File name is created */
+       sfn[NSFLAG] = c;                /* Store NT flag, File name is created */
 
        return FR_OK;
 #endif
@@ -2039,7 +2078,7 @@ FRESULT follow_path (     /* FR_OK(0): successful, !=0: error code */
                        res = create_name(dp, &path);   /* Get a segment name of the path */
                        if (res != FR_OK) break;
                        res = dir_find(dp);                             /* Find an object with the sagment name */
-                       ns = dp->fn[NS];
+                       ns = dp->fn[NSFLAG];
                        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, */
@@ -2079,6 +2118,12 @@ int get_ldnumber (               /* Returns logical drive number (-1:invalid drive) */
        const TCHAR *tp, *tt;
        UINT i;
        int vol = -1;
+#if _STR_VOLUME_ID             /* Find string drive id */
+       static const char* const str[] = {_VOLUME_STRS};
+       const char *sp;
+       char c;
+       TCHAR tc;
+#endif
 
 
        if (*path) {    /* If the pointer is not a null */
@@ -2091,13 +2136,9 @@ int get_ldnumber (               /* Returns logical drive number (-1:invalid drive) */
                                        vol = (int)i;
                                        *path = ++tt;
                                }
-                       } else {        /* No numeric drive number */
-#if _STR_VOLUME_ID             /* Find string drive id */
-                               static const char* const str[] = {_VOLUME_STRS};
-                               const char *sp;
-                               char c;
-                               TCHAR tc;
-
+                       }
+#if _STR_VOLUME_ID
+                        else { /* No numeric drive number, find string drive id */
                                i = 0; tt++;
                                do {
                                        sp = str[i]; tp = *path;
@@ -2110,8 +2151,8 @@ int get_ldnumber (                /* Returns logical drive number (-1:invalid drive) */
                                        vol = (int)i;
                                        *path = tt;
                                }
-#endif
                        }
+#endif
                        return vol;
                }
 #if _FS_RPATH && _VOLUMES >= 2
@@ -2131,7 +2172,7 @@ int get_ldnumber (                /* Returns logical drive number (-1:invalid drive) */
 /*-----------------------------------------------------------------------*/
 
 static
-BYTE check_fs (        /* 0:FAT boor sector, 1:Valid boor sector but not FAT, 2:Not a boot sector, 3:Disk error */
+BYTE check_fs (        /* 0:Valid FAT-BS, 1:Valid BS but not FAT, 2:Not a BS, 3:Disk error */
        FATFS* fs,      /* File system object */
        DWORD sect      /* Sector# (lba) to check if it is an FAT boot record or not */
 )
@@ -2165,12 +2206,13 @@ FRESULT find_volume (   /* FR_OK(0): successful, !=0: any error occurred */
        BYTE wmode                      /* !=0: Check write protection for write access */
 )
 {
-       BYTE fmt;
+       BYTE fmt, *pt;
        int vol;
        DSTATUS stat;
-       DWORD bsect, fasize, tsect, sysect, nclst, szbfat;
+       DWORD bsect, fasize, tsect, sysect, nclst, szbfat, br[4];
        WORD nrsv;
        FATFS *fs;
+       UINT i;
 
 
        /* Get logical drive number from the path name */
@@ -2212,11 +2254,8 @@ FRESULT find_volume (    /* FR_OK(0): successful, !=0: any error occurred */
        bsect = 0;
        fmt = check_fs(fs, bsect);                                      /* Load sector 0 and check if it is an FAT boot sector as SFD */
        if (fmt == 1 || (!fmt && (LD2PT(vol)))) {       /* Not an FAT boot sector or forced partition number */
-               UINT i;
-               DWORD br[4];
-
                for (i = 0; i < 4; i++) {                       /* Get partition offset */
-                       BYTE *pt = fs->win+MBR_Table + i * SZ_PTE;
+                       pt = fs->win + MBR_Table + i * SZ_PTE;
                        br[i] = pt[4] ? LD_DWORD(&pt[8]) : 0;
                }
                i = LD2PT(vol);                                         /* Partition number: 0:auto, 1-4:forced */
@@ -2231,11 +2270,11 @@ FRESULT find_volume (   /* FR_OK(0): successful, !=0: any error occurred */
 
        /* An FAT volume is found. Following code initializes the file system object */
 
-       if (LD_WORD(fs->win+BPB_BytsPerSec) != SS(fs))          /* (BPB_BytsPerSec must be equal to the physical sector size) */
+       if (LD_WORD(fs->win + BPB_BytsPerSec) != SS(fs))        /* (BPB_BytsPerSec must be equal to the physical sector size) */
                return FR_NO_FILESYSTEM;
 
-       fasize = LD_WORD(fs->win+BPB_FATSz16);                          /* Number of sectors per FAT */
-       if (!fasize) fasize = LD_DWORD(fs->win+BPB_FATSz32);
+       fasize = LD_WORD(fs->win + BPB_FATSz16);                        /* Number of sectors per FAT */
+       if (!fasize) fasize = LD_DWORD(fs->win + BPB_FATSz32);
        fs->fsize = fasize;
 
        fs->n_fats = fs->win[BPB_NumFATs];                                      /* Number of FAT copies */
@@ -2247,18 +2286,18 @@ FRESULT find_volume (   /* FR_OK(0): successful, !=0: any error occurred */
        if (!fs->csize || (fs->csize & (fs->csize - 1)))        /* (Must be power of 2) */
                return FR_NO_FILESYSTEM;
 
-       fs->n_rootdir = LD_WORD(fs->win+BPB_RootEntCnt);        /* Number of root directory entries */
-       if (fs->n_rootdir % (SS(fs) / SZ_DIR))                          /* (Must be sector aligned) */
+       fs->n_rootdir = LD_WORD(fs->win + BPB_RootEntCnt);      /* Number of root directory entries */
+       if (fs->n_rootdir % (SS(fs) / SZ_DIRE))                         /* (Must be sector aligned) */
                return FR_NO_FILESYSTEM;
 
-       tsect = LD_WORD(fs->win+BPB_TotSec16);                          /* Number of sectors on the volume */
-       if (!tsect) tsect = LD_DWORD(fs->win+BPB_TotSec32);
+       tsect = LD_WORD(fs->win + BPB_TotSec16);                        /* Number of sectors on the volume */
+       if (!tsect) tsect = LD_DWORD(fs->win + BPB_TotSec32);
 
-       nrsv = LD_WORD(fs->win+BPB_RsvdSecCnt);                         /* Number of reserved sectors */
+       nrsv = LD_WORD(fs->win + BPB_RsvdSecCnt);                       /* Number of reserved sectors */
        if (!nrsv) return FR_NO_FILESYSTEM;                                     /* (Must not be 0) */
 
        /* Determine the FAT sub type */
-       sysect = nrsv + fasize + fs->n_rootdir / (SS(fs) / SZ_DIR);     /* RSV+FAT+DIR */
+       sysect = nrsv + fasize + fs->n_rootdir / (SS(fs) / SZ_DIRE);    /* RSV + FAT + DIR */
        if (tsect < sysect) return FR_NO_FILESYSTEM;            /* (Invalid volume size) */
        nclst = (tsect - sysect) / fs->csize;                           /* Number of clusters */
        if (!nclst) return FR_NO_FILESYSTEM;                            /* (Invalid volume size) */
@@ -2273,7 +2312,7 @@ FRESULT find_volume (     /* FR_OK(0): successful, !=0: any error occurred */
        fs->database = bsect + sysect;                                          /* Data start sector */
        if (fmt == FS_FAT32) {
                if (fs->n_rootdir) return FR_NO_FILESYSTEM;             /* (BPB_RootEntCnt must be 0) */
-               fs->dirbase = LD_DWORD(fs->win+BPB_RootClus);   /* Root directory start cluster */
+               fs->dirbase = LD_DWORD(fs->win + BPB_RootClus); /* Root directory start cluster */
                szbfat = fs->n_fatent * 4;                                              /* (Needed FAT size) */
        } else {
                if (!fs->n_rootdir)     return FR_NO_FILESYSTEM;        /* (BPB_RootEntCnt must not be 0) */
@@ -2281,7 +2320,7 @@ FRESULT find_volume (     /* FR_OK(0): successful, !=0: any error occurred */
                szbfat = (fmt == FS_FAT16) ?                                    /* (Needed FAT size) */
                        fs->n_fatent * 2 : fs->n_fatent * 3 / 2 + (fs->n_fatent & 1);
        }
-       if (fs->fsize < (szbfat + (SS(fs) - 1)) / SS(fs))       /* (BPB_FATSz must not be less than needed) */
+       if (fs->fsize < (szbfat + (SS(fs) - 1)) / SS(fs))       /* (BPB_FATSz must not be less than the size needed) */
                return FR_NO_FILESYSTEM;
 
 #if !_FS_READONLY
@@ -2291,20 +2330,20 @@ FRESULT find_volume (   /* FR_OK(0): successful, !=0: any error occurred */
        /* Get fsinfo if available */
        fs->fsi_flag = 0x80;
 #if (_FS_NOFSINFO & 3) != 3
-       if (fmt == FS_FAT32                             /* Enable FSINFO only if FAT32 and BPB_FSInfo is 1 */
-               && LD_WORD(fs->win+BPB_FSInfo) == 1
+       if (fmt == FS_FAT32                             /* Enable FSINFO only if FAT32 and BPB_FSInfo == 1 */
+               && LD_WORD(fs->win + BPB_FSInfo) == 1
                && move_window(fs, bsect + 1) == FR_OK)
        {
                fs->fsi_flag = 0;
-               if (LD_WORD(fs->win+BS_55AA) == 0xAA55  /* Load FSINFO data if available */
-                       && LD_DWORD(fs->win+FSI_LeadSig) == 0x41615252
-                       && LD_DWORD(fs->win+FSI_StrucSig) == 0x61417272)
+               if (LD_WORD(fs->win + BS_55AA) == 0xAA55        /* Load FSINFO data if available */
+                       && LD_DWORD(fs->win + FSI_LeadSig) == 0x41615252
+                       && LD_DWORD(fs->win + FSI_StrucSig) == 0x61417272)
                {
 #if (_FS_NOFSINFO & 1) == 0
-                       fs->free_clust = LD_DWORD(fs->win+FSI_Free_Count);
+                       fs->free_clust = LD_DWORD(fs->win + FSI_Free_Count);
 #endif
 #if (_FS_NOFSINFO & 2) == 0
-                       fs->last_clust = LD_DWORD(fs->win+FSI_Nxt_Free);
+                       fs->last_clust = LD_DWORD(fs->win + FSI_Nxt_Free);
 #endif
                }
        }
@@ -2337,14 +2376,11 @@ FRESULT validate (      /* FR_OK(0): The object is valid, !=0: Invalid */
        FIL *fil = (FIL*)obj;   /* Assuming offset of .fs and .id in the FIL/DIR structure is identical */
 
 
-       if (!fil || !fil->fs || !fil->fs->fs_type || fil->fs->id != fil->id)
+       if (!fil || !fil->fs || !fil->fs->fs_type || fil->fs->id != fil->id || (disk_status(fil->fs->drv) & STA_NOINIT))
                return FR_INVALID_OBJECT;
 
        ENTER_FF(fil->fs);              /* Lock file system */
 
-       if (disk_status(fil->fs->drv) & STA_NOINIT)
-               return FR_NOT_READY;
-
        return FR_OK;
 }
 
@@ -2355,7 +2391,7 @@ FRESULT validate (        /* FR_OK(0): The object is valid, !=0: Invalid */
 
    Public Functions
 
---------------------------------------------------------------------------*/
+---------------------------------------------------------------------------*/
 
 
 
@@ -2366,7 +2402,7 @@ FRESULT validate (        /* FR_OK(0): The object is valid, !=0: Invalid */
 FRESULT f_mount (
        FATFS* fs,                      /* Pointer to the file system object (NULL:unmount)*/
        const TCHAR* path,      /* Logical drive number to be mounted/unmounted */
-       UINT opt                        /* 0:Do not mount (delayed mount), 1:Mount immediately */
+       BYTE opt                        /* 0:Do not mount (delayed mount), 1:Mount immediately */
 )
 {
        FATFS *cfs;
@@ -2419,7 +2455,10 @@ FRESULT f_open (
        FRESULT res;
        DIR dj;
        BYTE *dir;
-       DEF_NAMEBUF;
+       DEFINE_NAMEBUF;
+#if !_FS_READONLY
+       DWORD dw, cl;
+#endif
 
 
        if (!fp) return FR_INVALID_OBJECT;
@@ -2448,8 +2487,6 @@ FRESULT f_open (
                }
                /* Create or Open a file */
                if (mode & (FA_CREATE_ALWAYS | FA_OPEN_ALWAYS | FA_CREATE_NEW)) {
-                       DWORD dw, cl;
-
                        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
@@ -2469,12 +2506,13 @@ FRESULT f_open (
                                }
                        }
                        if (res == FR_OK && (mode & FA_CREATE_ALWAYS)) {        /* Truncate it if overwrite mode */
-                               dw = get_fattime();                             /* Created time */
-                               ST_DWORD(dir+DIR_CrtTime, dw);
+                               dw = GET_FATTIME();
+                               ST_DWORD(dir + DIR_CrtTime, dw);/* Set created time */
+                               ST_DWORD(dir + DIR_WrtTime, dw);/* Set modified time */
                                dir[DIR_Attr] = 0;                              /* Reset attribute */
-                               ST_DWORD(dir+DIR_FileSize, 0);  /* size = 0 */
-                               cl = ld_clust(dj.fs, dir);              /* Get start cluster */
-                               st_clust(dir, 0);                               /* cluster = 0 */
+                               ST_DWORD(dir + DIR_FileSize, 0);/* Reset file size */
+                               cl = ld_clust(dj.fs, dir);              /* Get cluster chain */
+                               st_clust(dir, 0);                               /* Reset cluster */
                                dj.fs->wflag = 1;
                                if (cl) {                                               /* Remove the cluster chain if exist */
                                        dw = dj.fs->winsect;
@@ -2487,7 +2525,7 @@ FRESULT f_open (
                        }
                }
                else {  /* Open an existing file */
-                       if (res == FR_OK) {                                     /* Follow succeeded */
+                       if (res == FR_OK) {                                     /* Following succeeded */
                                if (dir[DIR_Attr] & AM_DIR) {   /* It is a directory */
                                        res = FR_NO_FILE;
                                } else {
@@ -2524,7 +2562,7 @@ FRESULT f_open (
                        fp->flag = mode;                                        /* File access mode */
                        fp->err = 0;                                            /* Clear error flag */
                        fp->sclust = ld_clust(dj.fs, dir);      /* File start cluster */
-                       fp->fsize = LD_DWORD(dir+DIR_FileSize); /* File size */
+                       fp->fsize = LD_DWORD(dir + DIR_FileSize);       /* File size */
                        fp->fptr = 0;                                           /* File pointer */
                        fp->dsect = 0;
 #if _USE_FASTSEEK
@@ -2595,7 +2633,7 @@ FRESULT f_read (
                        if (cc) {                                                       /* Read maximum contiguous sectors directly */
                                if (csect + cc > fp->fs->csize) /* Clip at cluster boundary */
                                        cc = fp->fs->csize - csect;
-                               if (disk_read(fp->fs->drv, rbuff, sect, cc))
+                               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
@@ -2613,12 +2651,12 @@ FRESULT f_read (
                        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 (disk_write(fp->fs->drv, fp->buf, fp->dsect, 1))
+                                       if (disk_write(fp->fs->drv, fp->buf, fp->dsect, 1) != RES_OK)
                                                ABORT(fp->fs, FR_DISK_ERR);
                                        fp->flag &= ~FA__DIRTY;
                                }
 #endif
-                               if (disk_read(fp->fs->drv, fp->buf, sect, 1))   /* Fill sector cache */
+                               if (disk_read(fp->fs->drv, fp->buf, sect, 1) != RES_OK) /* Fill sector cache */
                                        ABORT(fp->fs, FR_DISK_ERR);
                        }
 #endif
@@ -2627,7 +2665,7 @@ FRESULT f_read (
                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 (move_window(fp->fs, fp->dsect)            /* Move sector window */
+               if (move_window(fp->fs, fp->dsect) != FR_OK)            /* Move sector window */
                        ABORT(fp->fs, FR_DISK_ERR);
                mem_cpy(rbuff, &fp->fs->win[fp->fptr % SS(fp->fs)], rcnt);      /* Pick partial sector */
 #else
@@ -2678,7 +2716,7 @@ FRESULT f_write (
                                if (fp->fptr == 0) {            /* On the top of the file? */
                                        clst = fp->sclust;              /* Follow from the origin */
                                        if (clst == 0)                  /* When no cluster is allocated, */
-                                               fp->sclust = clst = create_chain(fp->fs, 0);    /* Create a new cluster chain */
+                                               clst = create_chain(fp->fs, 0); /* Create a new cluster chain */
                                } else {                                        /* Middle or end of the file */
 #if _USE_FASTSEEK
                                        if (fp->cltbl)
@@ -2691,13 +2729,14 @@ FRESULT f_write (
                                if (clst == 1) ABORT(fp->fs, FR_INT_ERR);
                                if (clst == 0xFFFFFFFF) ABORT(fp->fs, FR_DISK_ERR);
                                fp->clust = clst;                       /* Update current cluster */
+                               if (fp->sclust == 0) fp->sclust = clst; /* Set start cluster if the first write */
                        }
 #if _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 (disk_write(fp->fs->drv, fp->buf, fp->dsect, 1))
+                               if (disk_write(fp->fs->drv, fp->buf, fp->dsect, 1) != RES_OK)
                                        ABORT(fp->fs, FR_DISK_ERR);
                                fp->flag &= ~FA__DIRTY;
                        }
@@ -2709,7 +2748,7 @@ FRESULT f_write (
                        if (cc) {                                               /* Write maximum contiguous sectors directly */
                                if (csect + cc > fp->fs->csize) /* Clip at cluster boundary */
                                        cc = fp->fs->csize - csect;
-                               if (disk_write(fp->fs->drv, wbuff, sect, cc))
+                               if (disk_write(fp->fs->drv, wbuff, sect, cc) != RES_OK)
                                        ABORT(fp->fs, FR_DISK_ERR);
 #if _FS_MINIMIZE <= 2
 #if _FS_TINY
@@ -2735,7 +2774,7 @@ FRESULT f_write (
 #else
                        if (fp->dsect != sect) {                /* Fill sector cache with file data */
                                if (fp->fptr < fp->fsize &&
-                                       disk_read(fp->fs->drv, fp->buf, sect, 1))
+                                       disk_read(fp->fs->drv, fp->buf, sect, 1) != RES_OK)
                                                ABORT(fp->fs, FR_DISK_ERR);
                        }
 #endif
@@ -2744,7 +2783,7 @@ FRESULT f_write (
                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 (move_window(fp->fs, fp->dsect)    /* Move sector window */
+               if (move_window(fp->fs, fp->dsect) != FR_OK)    /* Move sector window */
                        ABORT(fp->fs, FR_DISK_ERR);
                mem_cpy(&fp->fs->win[fp->fptr % SS(fp->fs)], wbuff, wcnt);      /* Fit partial sector */
                fp->fs->wflag = 1;
@@ -2778,11 +2817,10 @@ FRESULT f_sync (
 
        res = validate(fp);                                     /* Check validity of the object */
        if (res == FR_OK) {
-               if (fp->flag & FA__WRITTEN) {   /* Has the file been written? */
-                       /* Write-back dirty buffer */
+               if (fp->flag & FA__WRITTEN) {   /* Is there any change to the file? */
 #if !_FS_TINY
-                       if (fp->flag & FA__DIRTY) {
-                               if (disk_write(fp->fs->drv, fp->buf, fp->dsect, 1))
+                       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;
                        }
@@ -2792,11 +2830,11 @@ FRESULT f_sync (
                        if (res == FR_OK) {
                                dir = fp->dir_ptr;
                                dir[DIR_Attr] |= AM_ARC;                                        /* Set archive bit */
-                               ST_DWORD(dir+DIR_FileSize, fp->fsize);          /* Update file size */
+                               ST_DWORD(dir + DIR_FileSize, fp->fsize);        /* Update file size */
                                st_clust(dir, fp->sclust);                                      /* Update start cluster */
-                               tm = get_fattime();                                                     /* Update updated time */
-                               ST_DWORD(dir+DIR_WrtTime, tm);
-                               ST_WORD(dir+DIR_LstAccDate, 0);
+                               tm = GET_FATTIME();                                                     /* Update modified time */
+                               ST_DWORD(dir + DIR_WrtTime, tm);
+                               ST_WORD(dir + DIR_LstAccDate, 0);
                                fp->flag &= ~FA__WRITTEN;
                                fp->fs->wflag = 1;
                                res = sync_fs(fp->fs);
@@ -2878,7 +2916,7 @@ FRESULT f_chdir (
 {
        FRESULT res;
        DIR dj;
-       DEF_NAMEBUF;
+       DEFINE_NAMEBUF;
 
 
        /* Get logical drive number */
@@ -2916,7 +2954,7 @@ FRESULT f_getcwd (
        DWORD ccl;
        TCHAR *tp;
        FILINFO fno;
-       DEF_NAMEBUF;
+       DEFINE_NAMEBUF;
 
 
        *buff = 0;
@@ -2994,6 +3032,10 @@ FRESULT f_lseek (
 )
 {
        FRESULT res;
+       DWORD clst, bcs, nsect, ifptr;
+#if _USE_FASTSEEK
+       DWORD cl, pcl, ncl, tcl, dsc, tlen, ulen, *tbl;
+#endif
 
 
        res = validate(fp);                                     /* Check validity of the object */
@@ -3003,8 +3045,6 @@ FRESULT f_lseek (
 
 #if _USE_FASTSEEK
        if (fp->cltbl) {        /* Fast seek */
-               DWORD cl, pcl, ncl, tcl, dsc, tlen, ulen, *tbl;
-
                if (ofs == CREATE_LINKMAP) {    /* Create CLMT */
                        tbl = fp->cltbl;
                        tlen = *tbl++; ulen = 2;        /* Given table size and required table size */
@@ -3043,12 +3083,12 @@ FRESULT f_lseek (
 #if !_FS_TINY
 #if !_FS_READONLY
                                        if (fp->flag & FA__DIRTY) {             /* Write-back dirty sector cache */
-                                               if (disk_write(fp->fs->drv, fp->buf, fp->dsect, 1))
+                                               if (disk_write(fp->fs->drv, fp->buf, fp->dsect, 1) != RES_OK)
                                                        ABORT(fp->fs, FR_DISK_ERR);
                                                fp->flag &= ~FA__DIRTY;
                                        }
 #endif
-                                       if (disk_read(fp->fs->drv, fp->buf, dsc, 1))    /* Load current sector */
+                                       if (disk_read(fp->fs->drv, fp->buf, dsc, 1) != RES_OK)  /* Load current sector */
                                                ABORT(fp->fs, FR_DISK_ERR);
 #endif
                                        fp->dsect = dsc;
@@ -3060,8 +3100,6 @@ FRESULT f_lseek (
 
        /* Normal Seek */
        {
-               DWORD clst, bcs, nsect, ifptr;
-
                if (ofs > fp->fsize                                     /* In read-only mode, clip offset with the file size */
 #if !_FS_READONLY
                         && !(fp->flag & FA_WRITE)
@@ -3118,12 +3156,12 @@ FRESULT f_lseek (
 #if !_FS_TINY
 #if !_FS_READONLY
                        if (fp->flag & FA__DIRTY) {                     /* Write-back dirty sector cache */
-                               if (disk_write(fp->fs->drv, fp->buf, fp->dsect, 1))
+                               if (disk_write(fp->fs->drv, fp->buf, fp->dsect, 1) != RES_OK)
                                        ABORT(fp->fs, FR_DISK_ERR);
                                fp->flag &= ~FA__DIRTY;
                        }
 #endif
-                       if (disk_read(fp->fs->drv, fp->buf, nsect, 1))  /* Fill sector cache */
+                       if (disk_read(fp->fs->drv, fp->buf, nsect, 1) != RES_OK)        /* Fill sector cache */
                                ABORT(fp->fs, FR_DISK_ERR);
 #endif
                        fp->dsect = nsect;
@@ -3153,7 +3191,7 @@ FRESULT f_opendir (
 {
        FRESULT res;
        FATFS* fs;
-       DEF_NAMEBUF;
+       DEFINE_NAMEBUF;
 
 
        if (!dp) return FR_INVALID_OBJECT;
@@ -3240,7 +3278,7 @@ FRESULT f_readdir (
 )
 {
        FRESULT res;
-       DEF_NAMEBUF;
+       DEFINE_NAMEBUF;
 
 
        res = validate(dp);                                             /* Check validity of the object */
@@ -3271,6 +3309,58 @@ FRESULT f_readdir (
 
 
 
+#if _USE_FIND
+/*-----------------------------------------------------------------------*/
+/* Find next file                                                        */
+/*-----------------------------------------------------------------------*/
+
+FRESULT f_findnext (
+       DIR* dp,                /* Pointer to the open directory object */
+       FILINFO* fno    /* Pointer to the file information structure */
+)
+{
+       FRESULT res;
+
+
+       for (;;) {
+               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 (fno->lfname && pattern_matching(dp->pat, fno->lfname, 0, 0)) break; /* Test for LFN if exist */
+#endif
+               if (pattern_matching(dp->pat, fno->fname, 0, 0)) break; /* Test for SFN */
+       }
+       return res;
+
+}
+
+
+
+/*-----------------------------------------------------------------------*/
+/* Find first file                                                       */
+/*-----------------------------------------------------------------------*/
+
+FRESULT f_findfirst (
+       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 */
+       const TCHAR* pattern    /* Pointer to the matching pattern */
+)
+{
+       FRESULT res;
+
+
+       dp->pat = pattern;              /* Save pointer to pattern string */
+       res = f_opendir(dp, path);              /* Open the target directory */
+       if (res == FR_OK)
+               res = f_findnext(dp, fno);      /* Find the first item */
+       return res;
+}
+
+#endif /* _USE_FIND */
+
+
+
 #if _FS_MINIMIZE == 0
 /*-----------------------------------------------------------------------*/
 /* Get File Status                                                       */
@@ -3283,7 +3373,7 @@ FRESULT f_stat (
 {
        FRESULT res;
        DIR dj;
-       DEF_NAMEBUF;
+       DEFINE_NAMEBUF;
 
 
        /* Get logical drive number */
@@ -3319,7 +3409,7 @@ FRESULT f_getfree (
 {
        FRESULT res;
        FATFS *fs;
-       DWORD n, clst, sect, stat;
+       DWORD nfree, clst, sect, stat;
        UINT i;
        BYTE fat, *p;
 
@@ -3334,18 +3424,17 @@ FRESULT f_getfree (
                } else {
                        /* Get number of free clusters */
                        fat = fs->fs_type;
-                       n = 0;
-                       if (fat == FS_FAT12) {
+                       nfree = 0;
+                       if (fat == FS_FAT12) {  /* Sector unalighed entries: Search FAT via regular routine. */
                                clst = 2;
                                do {
                                        stat = get_fat(fs, clst);
                                        if (stat == 0xFFFFFFFF) { res = FR_DISK_ERR; break; }
                                        if (stat == 1) { res = FR_INT_ERR; break; }
-                                       if (stat == 0) n++;
+                                       if (stat == 0) nfree++;
                                } while (++clst < fs->n_fatent);
-                       } else {
-                               clst = fs->n_fatent;
-                               sect = fs->fatbase;
+                       } else {                                /* Sector alighed entries: Accelerate the FAT search. */
+                               clst = fs->n_fatent; sect = fs->fatbase;
                                i = 0; p = 0;
                                do {
                                        if (!i) {
@@ -3355,17 +3444,17 @@ FRESULT f_getfree (
                                                i = SS(fs);
                                        }
                                        if (fat == FS_FAT16) {
-                                               if (LD_WORD(p) == 0) n++;
+                                               if (LD_WORD(p) == 0) nfree++;
                                                p += 2; i -= 2;
                                        } else {
-                                               if ((LD_DWORD(p) & 0x0FFFFFFF) == 0) n++;
+                                               if ((LD_DWORD(p) & 0x0FFFFFFF) == 0) nfree++;
                                                p += 4; i -= 4;
                                        }
                                } while (--clst);
                        }
-                       fs->free_clust = n;
-                       fs->fsi_flag |= 1;
-                       *nclst = n;
+                       fs->free_clust = nfree; /* free_clust is valid */
+                       fs->fsi_flag |= 1;              /* FSInfo is to be updated */
+                       *nclst = nfree;                 /* Return the free clusters */
                }
        }
        LEAVE_FF(fs, res);
@@ -3414,7 +3503,7 @@ FRESULT f_truncate (
                        }
 #if !_FS_TINY
                        if (res == FR_OK && (fp->flag & FA__DIRTY)) {
-                               if (disk_write(fp->fs->drv, fp->buf, fp->dsect, 1))
+                               if (disk_write(fp->fs->drv, fp->buf, fp->dsect, 1) != RES_OK)
                                        res = FR_DISK_ERR;
                                else
                                        fp->flag &= ~FA__DIRTY;
@@ -3441,8 +3530,8 @@ FRESULT f_unlink (
        FRESULT res;
        DIR dj, sdj;
        BYTE *dir;
-       DWORD dclst;
-       DEF_NAMEBUF;
+       DWORD dclst = 0;
+       DEFINE_NAMEBUF;
 
 
        /* Get logical drive number */
@@ -3450,45 +3539,44 @@ FRESULT f_unlink (
        if (res == FR_OK) {
                INIT_BUF(dj);
                res = follow_path(&dj, path);           /* Follow the file path */
-               if (_FS_RPATH && res == FR_OK && (dj.fn[NS] & NS_DOT))
+               if (_FS_RPATH && res == FR_OK && (dj.fn[NSFLAG] & NS_DOT))
                        res = FR_INVALID_NAME;                  /* Cannot remove dot entry */
 #if _FS_LOCK
-               if (res == FR_OK) res = chk_lock(&dj, 2);       /* Cannot remove open file */
+               if (res == FR_OK) res = chk_lock(&dj, 2);       /* Cannot remove open object */
 #endif
                if (res == FR_OK) {                                     /* The object is accessible */
                        dir = dj.dir;
                        if (!dir) {
-                               res = FR_INVALID_NAME;          /* Cannot remove the start directory */
+                               res = FR_INVALID_NAME;          /* Cannot remove the origin directory */
                        } else {
                                if (dir[DIR_Attr] & AM_RDO)
                                        res = FR_DENIED;                /* Cannot remove R/O object */
                        }
-                       dclst = ld_clust(dj.fs, dir);
-                       if (res == FR_OK && (dir[DIR_Attr] & AM_DIR)) { /* Is it a sub-dir? */
-                               if (dclst < 2) {
-                                       res = FR_INT_ERR;
-                               } else {
-                                       mem_cpy(&sdj, &dj, sizeof (DIR));       /* Check if the sub-directory is empty or not */
-                                       sdj.sclust = dclst;
-                                       res = dir_sdi(&sdj, 2);         /* Exclude dot entries */
-                                       if (res == FR_OK) {
-                                               res = dir_read(&sdj, 0);        /* Read an item */
-                                               if (res == FR_OK                /* Not empty directory */
+                       if (res == FR_OK) {
+                               dclst = ld_clust(dj.fs, dir);
+                               if (dclst && (dir[DIR_Attr] & AM_DIR)) {        /* Is it a sub-directory ? */
 #if _FS_RPATH
-                                               || dclst == dj.fs->cdir /* Current directory */
+                                       if (dclst == dj.fs->cdir) {                             /* Is it the current directory? */
+                                               res = FR_DENIED;
+                                       } else
 #endif
-                                               ) res = FR_DENIED;
-                                               if (res == FR_NO_FILE) res = FR_OK;     /* Empty */
+                                       {
+                                               mem_cpy(&sdj, &dj, sizeof (DIR));       /* Open the sub-directory */
+                                               sdj.sclust = dclst;
+                                               res = dir_sdi(&sdj, 2);
+                                               if (res == FR_OK) {
+                                                       res = dir_read(&sdj, 0);                        /* Read an item (excluding dot entries) */
+                                                       if (res == FR_OK) res = FR_DENIED;      /* Not empty? (cannot remove) */
+                                                       if (res == FR_NO_FILE) res = FR_OK;     /* Empty? (can remove) */
+                                               }
                                        }
                                }
                        }
                        if (res == FR_OK) {
                                res = dir_remove(&dj);          /* Remove the directory entry */
-                               if (res == FR_OK) {
-                                       if (dclst)                              /* Remove the cluster chain if exist */
-                                               res = remove_chain(dj.fs, dclst);
-                                       if (res == FR_OK) res = sync_fs(dj.fs);
-                               }
+                               if (res == FR_OK && dclst)      /* Remove the cluster chain if exist */
+                                       res = remove_chain(dj.fs, dclst);
+                               if (res == FR_OK) res = sync_fs(dj.fs);
                        }
                }
                FREE_BUF();
@@ -3511,8 +3599,8 @@ FRESULT f_mkdir (
        FRESULT res;
        DIR dj;
        BYTE *dir, n;
-       DWORD dsc, dcl, pcl, tm = get_fattime();
-       DEF_NAMEBUF;
+       DWORD dsc, dcl, pcl, tm = GET_FATTIME();
+       DEFINE_NAMEBUF;
 
 
        /* Get logical drive number */
@@ -3521,7 +3609,7 @@ FRESULT f_mkdir (
                INIT_BUF(dj);
                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[NS] & NS_DOT))
+               if (_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 */
                        dcl = create_chain(dj.fs, 0);           /* Allocate a cluster for the new directory table */
@@ -3535,16 +3623,16 @@ FRESULT f_mkdir (
                                dsc = clust2sect(dj.fs, dcl);
                                dir = dj.fs->win;
                                mem_set(dir, 0, SS(dj.fs));
-                               mem_set(dir+DIR_Name, ' ', 11); /* Create "." entry */
+                               mem_set(dir + DIR_Name, ' ', 11);       /* Create "." entry */
                                dir[DIR_Name] = '.';
                                dir[DIR_Attr] = AM_DIR;
-                               ST_DWORD(dir+DIR_WrtTime, tm);
+                               ST_DWORD(dir + DIR_WrtTime, tm);
                                st_clust(dir, dcl);
-                               mem_cpy(dir+SZ_DIR, dir, SZ_DIR);       /* Create ".." entry */
-                               dir[SZ_DIR+1] = '.'; pcl = dj.sclust;
+                               mem_cpy(dir + SZ_DIRE, dir, SZ_DIRE);   /* Create ".." entry */
+                               dir[SZ_DIRE + 1] = '.'; pcl = dj.sclust;
                                if (dj.fs->fs_type == FS_FAT32 && pcl == dj.fs->dirbase)
                                        pcl = 0;
-                               st_clust(dir+SZ_DIR, pcl);
+                               st_clust(dir + SZ_DIRE, pcl);
                                for (n = dj.fs->csize; n; n--) {        /* Write dot entries and clear following sectors */
                                        dj.fs->winsect = dsc++;
                                        dj.fs->wflag = 1;
@@ -3559,7 +3647,7 @@ FRESULT f_mkdir (
                        } else {
                                dir = dj.dir;
                                dir[DIR_Attr] = AM_DIR;                         /* Attribute */
-                               ST_DWORD(dir+DIR_WrtTime, tm);          /* Created time */
+                               ST_DWORD(dir + DIR_WrtTime, tm);        /* Created time */
                                st_clust(dir, dcl);                                     /* Table start cluster */
                                dj.fs->wflag = 1;
                                res = sync_fs(dj.fs);
@@ -3580,23 +3668,22 @@ FRESULT f_mkdir (
 
 FRESULT f_chmod (
        const TCHAR* path,      /* Pointer to the file path */
-       BYTE value,                     /* Attribute bits */
+       BYTE attr,                      /* Attribute bits */
        BYTE mask                       /* Attribute mask to change */
 )
 {
        FRESULT res;
        DIR dj;
        BYTE *dir;
-       DEF_NAMEBUF;
+       DEFINE_NAMEBUF;
 
 
-       /* Get logical drive number */
-       res = find_volume(&dj.fs, &path, 1);
+       res = find_volume(&dj.fs, &path, 1);    /* Get logical drive number */
        if (res == FR_OK) {
                INIT_BUF(dj);
                res = follow_path(&dj, path);           /* Follow the file path */
                FREE_BUF();
-               if (_FS_RPATH && res == FR_OK && (dj.fn[NS] & NS_DOT))
+               if (_FS_RPATH && res == FR_OK && (dj.fn[NSFLAG] & NS_DOT))
                        res = FR_INVALID_NAME;
                if (res == FR_OK) {
                        dir = dj.dir;
@@ -3604,49 +3691,7 @@ FRESULT f_chmod (
                                res = FR_INVALID_NAME;
                        } else {                                                /* File or sub directory */
                                mask &= AM_RDO|AM_HID|AM_SYS|AM_ARC;    /* Valid attribute mask */
-                               dir[DIR_Attr] = (value & mask) | (dir[DIR_Attr] & (BYTE)~mask); /* Apply attribute change */
-                               dj.fs->wflag = 1;
-                               res = sync_fs(dj.fs);
-                       }
-               }
-       }
-
-       LEAVE_FF(dj.fs, res);
-}
-
-
-
-
-/*-----------------------------------------------------------------------*/
-/* Change Timestamp                                                      */
-/*-----------------------------------------------------------------------*/
-
-FRESULT f_utime (
-       const TCHAR* path,      /* Pointer to the file/directory name */
-       const FILINFO* fno      /* Pointer to the time stamp to be set */
-)
-{
-       FRESULT res;
-       DIR dj;
-       BYTE *dir;
-       DEF_NAMEBUF;
-
-
-       /* Get logical drive number */
-       res = find_volume(&dj.fs, &path, 1);
-       if (res == FR_OK) {
-               INIT_BUF(dj);
-               res = follow_path(&dj, path);   /* Follow the file path */
-               FREE_BUF();
-               if (_FS_RPATH && res == FR_OK && (dj.fn[NS] & NS_DOT))
-                       res = FR_INVALID_NAME;
-               if (res == FR_OK) {
-                       dir = dj.dir;
-                       if (!dir) {                                     /* Root directory */
-                               res = FR_INVALID_NAME;
-                       } else {                                        /* File or sub-directory */
-                               ST_WORD(dir+DIR_WrtTime, fno->ftime);
-                               ST_WORD(dir+DIR_WrtDate, fno->fdate);
+                               dir[DIR_Attr] = (attr & mask) | (dir[DIR_Attr] & (BYTE)~mask);  /* Apply attribute change */
                                dj.fs->wflag = 1;
                                res = sync_fs(dj.fs);
                        }
@@ -3672,7 +3717,7 @@ FRESULT f_rename (
        DIR djo, djn;
        BYTE buf[21], *dir;
        DWORD dw;
-       DEF_NAMEBUF;
+       DEFINE_NAMEBUF;
 
 
        /* Get logical drive number of the source object */
@@ -3681,7 +3726,7 @@ FRESULT f_rename (
                djn.fs = djo.fs;
                INIT_BUF(djo);
                res = follow_path(&djo, path_old);              /* Check old object */
-               if (_FS_RPATH && res == FR_OK && (djo.fn[NS] & NS_DOT))
+               if (_FS_RPATH && res == FR_OK && (djo.fn[NSFLAG] & NS_DOT))
                        res = FR_INVALID_NAME;
 #if _FS_LOCK
                if (res == FR_OK) res = chk_lock(&djo, 2);
@@ -3690,31 +3735,30 @@ FRESULT f_rename (
                        if (!djo.dir) {                                         /* Is root dir? */
                                res = FR_NO_FILE;
                        } else {
-                               mem_cpy(buf, djo.dir+DIR_Attr, 21);             /* Save the object information except name */
+                               mem_cpy(buf, djo.dir + DIR_Attr, 21);   /* Save information about object except name */
                                mem_cpy(&djn, &djo, sizeof (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 check if new object is exist */
+                                       res = follow_path(&djn, path_new);      /* and make sure if new object name is not conflicting */
                                else
                                        res = FR_INVALID_DRIVE;
                                if (res == FR_OK) res = FR_EXIST;               /* The new object name is already existing */
-                               if (res == FR_NO_FILE) {                                /* Is it a valid path and no name collision? */
-/* Start critical section that any interruption can cause a cross-link */
+                               if (res == FR_NO_FILE) {                                /* It is a valid path and no name collision */
                                        res = dir_register(&djn);                       /* Register the new entry */
                                        if (res == FR_OK) {
-                                               dir = djn.dir;                                  /* Copy object information except name */
-                                               mem_cpy(dir+13, buf+2, 19);
+/* Start of critical section where any interruption can cause a cross-link */
+                                               dir = djn.dir;                                  /* Copy information about object except name */
+                                               mem_cpy(dir + 13, buf + 2, 19);
                                                dir[DIR_Attr] = buf[0] | AM_ARC;
                                                djo.fs->wflag = 1;
-                                               if (djo.sclust != djn.sclust && (dir[DIR_Attr] & AM_DIR)) {             /* Update .. entry in the directory if needed */
+                                               if ((dir[DIR_Attr] & AM_DIR) && djo.sclust != djn.sclust) {     /* Update .. entry in the sub-directory if needed */
                                                        dw = clust2sect(djo.fs, ld_clust(djo.fs, dir));
                                                        if (!dw) {
                                                                res = FR_INT_ERR;
                                                        } else {
                                                                res = move_window(djo.fs, dw);
-                                                               dir = djo.fs->win+SZ_DIR;       /* .. entry */
+                                                               dir = djo.fs->win + SZ_DIRE * 1;        /* Ptr to .. entry */
                                                                if (res == FR_OK && dir[1] == '.') {
-                                                                       dw = (djo.fs->fs_type == FS_FAT32 && djn.sclust == djo.fs->dirbase) ? 0 : djn.sclust;
-                                                                       st_clust(dir, dw);
+                                                                       st_clust(dir, djn.sclust);
                                                                        djo.fs->wflag = 1;
                                                                }
                                                        }
@@ -3724,8 +3768,8 @@ FRESULT f_rename (
                                                        if (res == FR_OK)
                                                                res = sync_fs(djo.fs);
                                                }
+/* End of critical section */
                                        }
-/* End critical section */
                                }
                        }
                }
@@ -3735,6 +3779,48 @@ FRESULT f_rename (
        LEAVE_FF(djo.fs, res);
 }
 
+
+
+
+/*-----------------------------------------------------------------------*/
+/* Change Timestamp                                                      */
+/*-----------------------------------------------------------------------*/
+
+FRESULT f_utime (
+       const TCHAR* path,      /* Pointer to the file/directory name */
+       const FILINFO* fno      /* Pointer to the time stamp to be set */
+)
+{
+       FRESULT res;
+       DIR dj;
+       BYTE *dir;
+       DEFINE_NAMEBUF;
+
+
+       /* Get logical drive number */
+       res = find_volume(&dj.fs, &path, 1);
+       if (res == FR_OK) {
+               INIT_BUF(dj);
+               res = follow_path(&dj, path);   /* Follow the file path */
+               FREE_BUF();
+               if (_FS_RPATH && res == FR_OK && (dj.fn[NSFLAG] & NS_DOT))
+                       res = FR_INVALID_NAME;
+               if (res == FR_OK) {
+                       dir = dj.dir;
+                       if (!dir) {                                     /* Root directory */
+                               res = FR_INVALID_NAME;
+                       } else {                                        /* File or sub-directory */
+                               ST_WORD(dir + DIR_WrtTime, fno->ftime);
+                               ST_WORD(dir + DIR_WrtDate, fno->fdate);
+                               dj.fs->wflag = 1;
+                               res = sync_fs(dj.fs);
+                       }
+               }
+       }
+
+       LEAVE_FF(dj.fs, res);
+}
+
 #endif /* !_FS_READONLY */
 #endif /* _FS_MINIMIZE == 0 */
 #endif /* _FS_MINIMIZE <= 1 */
@@ -3742,6 +3828,7 @@ FRESULT f_rename (
 
 
 
+
 #if _USE_LABEL
 /*-----------------------------------------------------------------------*/
 /* Get volume label                                                      */
@@ -3750,12 +3837,15 @@ FRESULT f_rename (
 FRESULT f_getlabel (
        const TCHAR* path,      /* Path name of the logical drive number */
        TCHAR* label,           /* Pointer to a buffer to return the volume label */
-       DWORD* sn                       /* Pointer to a variable to return the volume serial number */
+       DWORD* vsn                      /* Pointer to a variable to return the volume serial number */
 )
 {
        FRESULT res;
        DIR dj;
        UINT i, j;
+#if _USE_LFN && _LFN_UNICODE
+       WCHAR w;
+#endif
 
 
        /* Get logical drive number */
@@ -3769,7 +3859,6 @@ FRESULT f_getlabel (
                        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
-                               WCHAR w;
                                i = j = 0;
                                do {
                                        w = (i < 11) ? dj.dir[i++] : ' ';
@@ -3794,11 +3883,11 @@ FRESULT f_getlabel (
        }
 
        /* Get volume serial number */
-       if (res == FR_OK && sn) {
+       if (res == FR_OK && vsn) {
                res = move_window(dj.fs, dj.fs->volbase);
                if (res == FR_OK) {
                        i = dj.fs->fs_type == FS_FAT32 ? BS_VolID32 : BS_VolID;
-                       *sn = LD_DWORD(&dj.fs->win[i]);
+                       *vsn = LD_DWORD(&dj.fs->win[i]);
                }
        }
 
@@ -3831,7 +3920,7 @@ FRESULT f_setlabel (
        /* Create a volume label in directory form */
        vn[0] = 0;
        for (sl = 0; label[sl]; sl++) ;                         /* Get name length */
-       for ( ; sl && label[sl-1] == ' '; sl--) ;       /* Remove trailing spaces */
+       for ( ; sl && label[sl - 1] == ' '; sl--) ;     /* Remove trailing spaces */
        if (sl) {       /* Create volume label in directory form */
                i = j = 0;
                do {
@@ -3857,7 +3946,8 @@ FRESULT f_setlabel (
                        if (w >= 0x100) vn[j++] = (BYTE)(w >> 8);
                        vn[j++] = (BYTE)w;
                } while (i < sl);
-               while (j < 11) vn[j++] = ' ';
+               while (j < 11) vn[j++] = ' ';   /* Fill remaining name field */
+               if (vn[0] == DDEM) LEAVE_FF(dj.fs, FR_INVALID_NAME);    /* Reject illegal name (heading DDEM) */
        }
 
        /* Set volume label */
@@ -3868,10 +3958,10 @@ FRESULT f_setlabel (
                if (res == FR_OK) {                     /* A volume label is found */
                        if (vn[0]) {
                                mem_cpy(dj.dir, vn, 11);        /* Change the volume label name */
-                               tm = get_fattime();
-                               ST_DWORD(dj.dir+DIR_WrtTime, tm);
+                               tm = GET_FATTIME();
+                               ST_DWORD(dj.dir + DIR_WrtTime, tm);
                        } else {
-                               dj.dir[0] = DDE                       /* Remove the volume label */
+                               dj.dir[0] = DDEM;                       /* Remove the volume label */
                        }
                        dj.fs->wflag = 1;
                        res = sync_fs(dj.fs);
@@ -3881,11 +3971,11 @@ FRESULT f_setlabel (
                                if (vn[0]) {                            /* Create volume label as new */
                                        res = dir_alloc(&dj, 1);        /* Allocate an entry for volume label */
                                        if (res == FR_OK) {
-                                               mem_set(dj.dir, 0, SZ_DIR);     /* Set volume label */
+                                               mem_set(dj.dir, 0, SZ_DIRE);    /* Set volume label */
                                                mem_cpy(dj.dir, vn, 11);
                                                dj.dir[DIR_Attr] = AM_VOL;
-                                               tm = get_fattime();
-                                               ST_DWORD(dj.dir+DIR_WrtTime, tm);
+                                               tm = GET_FATTIME();
+                                               ST_DWORD(dj.dir + DIR_WrtTime, tm);
                                                dj.fs->wflag = 1;
                                                res = sync_fs(dj.fs);
                                        }
@@ -3947,7 +4037,7 @@ FRESULT f_forward (
                sect = clust2sect(fp->fs, fp->clust);           /* Get current data sector */
                if (!sect) ABORT(fp->fs, FR_INT_ERR);
                sect += csect;
-               if (move_window(fp->fs, sect))                          /* Move sector window */
+               if (move_window(fp->fs, sect) != FR_OK)         /* Move sector window */
                        ABORT(fp->fs, FR_DISK_ERR);
                fp->dsect = sect;
                rcnt = SS(fp->fs) - (WORD)(fp->fptr % SS(fp->fs));      /* Forward data from sector window */
@@ -3964,16 +4054,17 @@ FRESULT f_forward (
 
 #if _USE_MKFS && !_FS_READONLY
 /*-----------------------------------------------------------------------*/
-/* Create File System on the Drive                                       */
+/* Create file system on the logical drive                               */
 /*-----------------------------------------------------------------------*/
-#define N_ROOTDIR      512             /* Number of root directory entries for FAT12/16 */
-#define N_FATS         1               /* Number of FAT copies (1 or 2) */
+#define N_ROOTDIR12    224             /* Number of root directory entries for FAT12/16 */
+#define N_ROOTDIR16    512             /* Number of root directory entries for FAT12/16 */
+#define N_FATS         1               /* Number of FATs (1 or 2) */
 
 
 FRESULT f_mkfs (
        const TCHAR* path,      /* Logical drive number */
        BYTE sfd,                       /* Partitioning rule 0:FDISK, 1:SFD */
-       UINT au                         /* Allocation unit [bytes] */
+       UINT au                         /* Size of allocation unit in unit of byte or sector */
 )
 {
        static const WORD vst[] = { 1024,   512,  256,  128,   64,    32,   16,    8,    4,    2,   0};
@@ -3986,13 +4077,15 @@ FRESULT f_mkfs (
        DWORD n_vol, n_rsv, n_fat, n_dir;       /* Size */
        FATFS *fs;
        DSTATUS stat;
+#if _USE_TRIM
+       DWORD eb[2];
+#endif
 
 
        /* Check mounted drive and clear work area */
+       if (sfd > 1) return FR_INVALID_PARAMETER;
        vol = get_ldnumber(&path);
        if (vol < 0) return FR_INVALID_DRIVE;
-       if (sfd > 1) return FR_INVALID_PARAMETER;
-       if (au & (au - 1)) return FR_INVALID_PARAMETER;
        fs = FatFs[vol];
        if (!fs) return FR_NOT_ENABLED;
        fs->fs_type = 0;
@@ -4009,12 +4102,12 @@ FRESULT f_mkfs (
 #endif
        if (_MULTI_PARTITION && part) {
                /* Get partition information from partition table in the MBR */
-               if (disk_read(pdrv, fs->win, 0, 1)) return FR_DISK_ERR;
-               if (LD_WORD(fs->win+BS_55AA) != 0xAA55) return FR_MKFS_ABORTED;
+               if (disk_read(pdrv, fs->win, 0, 1) != RES_OK) return FR_DISK_ERR;
+               if (LD_WORD(fs->win + BS_55AA) != 0xAA55) return FR_MKFS_ABORTED;
                tbl = &fs->win[MBR_Table + (part - 1) * SZ_PTE];
                if (!tbl[4]) return FR_MKFS_ABORTED;    /* No partition? */
-               b_vol = LD_DWORD(tbl+8);        /* Volume start sector */
-               n_vol = LD_DWORD(tbl+12);       /* Volume size */
+               b_vol = LD_DWORD(tbl + 8);      /* Volume start sector */
+               n_vol = LD_DWORD(tbl + 12);     /* Volume size */
        } else {
                /* Create a partition in this function */
                if (disk_ioctl(pdrv, GET_SECTOR_COUNT, &n_vol) != RES_OK || n_vol < 128)
@@ -4023,13 +4116,14 @@ FRESULT f_mkfs (
                n_vol -= b_vol;                         /* Volume size */
        }
 
-       if (!au) {                              /* AU auto selection */
+       if (au & (au - 1)) au = 0;
+       if (!au) {                                              /* AU auto selection */
                vs = n_vol / (2000 / (SS(fs) / 512));
                for (i = 0; vs < vst[i]; i++) ;
                au = cst[i];
        }
-       au /= SS(fs);           /* Number of sectors per cluster */
-       if (au == 0) au = 1;
+       if (au >= _MIN_SS) au /= SS(fs);        /* Number of sectors per cluster */
+       if (!au) au = 1;
        if (au > 128) au = 128;
 
        /* Pre-compute number of clusters and FAT sub-type */
@@ -4047,7 +4141,10 @@ FRESULT f_mkfs (
                n_fat = (fmt == FS_FAT12) ? (n_clst * 3 + 1) / 2 + 3 : (n_clst * 2) + 4;
                n_fat = (n_fat + SS(fs) - 1) / SS(fs);
                n_rsv = 1;
-               n_dir = (DWORD)N_ROOTDIR * SZ_DIR / SS(fs);
+        if(fmt == FS_FAT12)
+                   n_dir = (DWORD)N_ROOTDIR12 * SZ_DIRE / SS(fs);
+        else
+            n_dir = (DWORD)N_ROOTDIR16 * SZ_DIRE / SS(fs);
        }
        b_fat = b_vol + n_rsv;                          /* FAT area start sector */
        b_dir = b_fat + n_fat * N_FATS;         /* Directory area start sector */
@@ -4086,7 +4183,7 @@ FRESULT f_mkfs (
                /* Update system ID in the partition table */
                tbl = &fs->win[MBR_Table + (part - 1) * SZ_PTE];
                tbl[4] = sys;
-               if (disk_write(pdrv, fs->win, 0, 1))    /* Write it to teh MBR */
+               if (disk_write(pdrv, fs->win, 0, 1) != RES_OK)  /* Write it to teh MBR */
                        return FR_DISK_ERR;
                md = 0xF8;
        } else {
@@ -4094,7 +4191,7 @@ FRESULT f_mkfs (
                        md = 0xF0;
                } else {        /* Create partition table (FDISK) */
                        mem_set(fs->win, 0, SS(fs));
-                       tbl = fs->win+MBR_Table;        /* Create partition table for single partition in the drive */
+                       tbl = fs->win + MBR_Table;      /* Create partition table for single partition in the drive */
                        tbl[1] = 1;                                             /* Partition start head */
                        tbl[2] = 1;                                             /* Partition start sector */
                        tbl[3] = 0;                                             /* Partition start cylinder */
@@ -4103,10 +4200,10 @@ FRESULT f_mkfs (
                        n = (b_vol + n_vol) / 63 / 255;
                        tbl[6] = (BYTE)(n >> 2 | 63);   /* Partition end sector */
                        tbl[7] = (BYTE)n;                               /* End cylinder */
-                       ST_DWORD(tbl+8, 63);                    /* Partition start in LBA */
-                       ST_DWORD(tbl+12, n_vol);                /* Partition size in LBA */
-                       ST_WORD(fs->win+BS_55AA, 0xAA55);       /* MBR signature */
-                       if (disk_write(pdrv, fs->win, 0, 1))    /* Write it to the MBR */
+                       ST_DWORD(tbl + 8, 63);                  /* Partition start in LBA */
+                       ST_DWORD(tbl + 12, n_vol);              /* Partition size in LBA */
+                       ST_WORD(fs->win + BS_55AA, 0xAA55);     /* MBR signature */
+                       if (disk_write(pdrv, fs->win, 0, 1) != RES_OK)  /* Write it to the MBR */
                                return FR_DISK_ERR;
                        md = 0xF8;
                }
@@ -4117,42 +4214,53 @@ FRESULT f_mkfs (
        mem_set(tbl, 0, SS(fs));
        mem_cpy(tbl, "\xEB\xFE\x90" "MSDOS5.0", 11);/* Boot jump code, OEM name */
        i = SS(fs);                                                             /* Sector size */
-       ST_WORD(tbl+BPB_BytsPerSec, i);
+       ST_WORD(tbl + BPB_BytsPerSec, i);
        tbl[BPB_SecPerClus] = (BYTE)au;                 /* Sectors per cluster */
-       ST_WORD(tbl+BPB_RsvdSecCnt, n_rsv);             /* Reserved sectors */
+       ST_WORD(tbl + BPB_RsvdSecCnt, n_rsv);   /* Reserved sectors */
        tbl[BPB_NumFATs] = N_FATS;                              /* Number of FATs */
-       i = (fmt == FS_FAT32) ? 0 : N_ROOTDIR;  /* Number of root directory entries */
-       ST_WORD(tbl+BPB_RootEntCnt, i);
+       i = (fmt == FS_FAT32) ? 0 : (fmt == FS_FAT12 ? N_ROOTDIR12 : N_ROOTDIR16);      /* Number of root directory entries */
+       ST_WORD(tbl + BPB_RootEntCnt, i);
        if (n_vol < 0x10000) {                                  /* Number of total sectors */
-               ST_WORD(tbl+BPB_TotSec16, n_vol);
+               ST_WORD(tbl + BPB_TotSec16, n_vol);
        } else {
-               ST_DWORD(tbl+BPB_TotSec32, n_vol);
+               ST_DWORD(tbl + BPB_TotSec32, n_vol);
        }
        tbl[BPB_Media] = md;                                    /* Media descriptor */
-       ST_WORD(tbl+BPB_SecPerTrk, 63);                 /* Number of sectors per track */
-       ST_WORD(tbl+BPB_NumHeads, 255);                 /* Number of heads */
-       ST_DWORD(tbl+BPB_HiddSec, b_vol);               /* Hidden sectors */
-       n = get_fattime();                                              /* Use current time as VSN */
-       if (fmt == FS_FAT32) {
-               ST_DWORD(tbl+BS_VolID32, n);            /* VSN */
-               ST_DWORD(tbl+BPB_FATSz32, n_fat);       /* Number of sectors per FAT */
-               ST_DWORD(tbl+BPB_RootClus, 2);          /* Root directory start cluster (2) */
-               ST_WORD(tbl+BPB_FSInfo, 1);                     /* FSINFO record offset (VBR+1) */
-               ST_WORD(tbl+BPB_BkBootSec, 6);          /* Backup boot record offset (VBR+6) */
+    ST_DWORD(tbl + BPB_HiddSec, b_vol);                /* Hidden sectors */
+       n = GET_FATTIME();                                              /* Use current time as VSN */
+    if (fmt == FS_FAT12) {
+        /* Assume floppy characteristics */
+        ST_WORD(tbl + BPB_SecPerTrk, 0x12);    /* Number of sectors per track */
+        ST_WORD(tbl + BPB_NumHeads, 0x02);     /* Number of heads */
+        ST_DWORD(tbl + BS_VolID, n);           /* VSN */
+        ST_WORD(tbl + BPB_FATSz16, n_fat);     /* Number of sectors per FAT */
+        tbl[BS_DrvNum] = 0x00;                         /* Drive number */
+        tbl[BS_BootSig] = 0x29;                                /* Extended boot signature */
+        mem_cpy(tbl + BS_VolLab, "NO NAME    " "FAT12   ", 19);        /* Volume label, FAT signature */
+    } else if (fmt == FS_FAT32) {
+        ST_WORD(tbl + BPB_SecPerTrk, 63);      /* Number of sectors per track */
+        ST_WORD(tbl + BPB_NumHeads, 255);      /* Number of heads */
+               ST_DWORD(tbl + BS_VolID32, n);          /* VSN */
+               ST_DWORD(tbl + BPB_FATSz32, n_fat);     /* Number of sectors per FAT */
+               ST_DWORD(tbl + BPB_RootClus, 2);        /* Root directory start cluster (2) */
+               ST_WORD(tbl + BPB_FSInfo, 1);           /* FSINFO record offset (VBR + 1) */
+               ST_WORD(tbl + BPB_BkBootSec, 6);        /* Backup boot record offset (VBR + 6) */
                tbl[BS_DrvNum32] = 0x80;                        /* Drive number */
                tbl[BS_BootSig32] = 0x29;                       /* Extended boot signature */
-               mem_cpy(tbl+BS_VolLab32, "NO NAME    " "FAT32   ", 19); /* Volume label, FAT signature */
+               mem_cpy(tbl + BS_VolLab32, "NO NAME    " "FAT32   ", 19);       /* Volume label, FAT signature */
        } else {
-               ST_DWORD(tbl+BS_VolID, n);                      /* VSN */
-               ST_WORD(tbl+BPB_FATSz16, n_fat);        /* Number of sectors per FAT */
-               tbl[BS_DrvNum] = 0x80;                          /* Drive number */
-               tbl[BS_BootSig] = 0x29;                         /* Extended boot signature */
-               mem_cpy(tbl+BS_VolLab, "NO NAME    " "FAT     ", 19);   /* Volume label, FAT signature */
-       }
-       ST_WORD(tbl+BS_55AA, 0xAA55);                   /* Signature (Offset is fixed here regardless of sector size) */
-       if (disk_write(pdrv, tbl, b_vol, 1))    /* Write it to the VBR sector */
+        ST_WORD(tbl + BPB_SecPerTrk, 63);      /* Number of sectors per track */
+        ST_WORD(tbl + BPB_NumHeads, 255);      /* Number of heads */
+        ST_DWORD(tbl + BS_VolID, n);           /* VSN */
+        ST_WORD(tbl + BPB_FATSz16, n_fat);     /* Number of sectors per FAT */
+        tbl[BS_DrvNum] = 0x80;                         /* Drive number */
+        tbl[BS_BootSig] = 0x29;                                /* Extended boot signature */
+        mem_cpy(tbl + BS_VolLab, "NO NAME    " "FAT     ", 19);        /* Volume label, FAT signature */
+    }
+       ST_WORD(tbl + BS_55AA, 0xAA55);                 /* Signature (Offset is fixed here regardless of sector size) */
+       if (disk_write(pdrv, tbl, b_vol, 1) != RES_OK)  /* Write it to the VBR sector */
                return FR_DISK_ERR;
-       if (fmt == FS_FAT32)                                    /* Write backup VBR if needed (VBR+6) */
+       if (fmt == FS_FAT32)                                    /* Write it to the backup VBR if needed (VBR + 6) */
                disk_write(pdrv, tbl, b_vol + 6, 1);
 
        /* Initialize FAT area */
@@ -4162,18 +4270,18 @@ FRESULT f_mkfs (
                n = md;                                                         /* Media descriptor byte */
                if (fmt != FS_FAT32) {
                        n |= (fmt == FS_FAT12) ? 0x00FFFF00 : 0xFFFFFF00;
-                       ST_DWORD(tbl+0, n);                             /* Reserve cluster #0-1 (FAT12/16) */
+                       ST_DWORD(tbl + 0, n);                   /* Reserve cluster #0-1 (FAT12/16) */
                } else {
                        n |= 0xFFFFFF00;
-                       ST_DWORD(tbl+0, n);                             /* Reserve cluster #0-1 (FAT32) */
-                       ST_DWORD(tbl+4, 0xFFFFFFFF);
-                       ST_DWORD(tbl+8, 0x0FFFFFFF);    /* Reserve cluster #2 for root directory */
+                       ST_DWORD(tbl + 0, n);                   /* Reserve cluster #0-1 (FAT32) */
+                       ST_DWORD(tbl + 4, 0xFFFFFFFF);
+                       ST_DWORD(tbl + 8, 0x0FFFFFFF);  /* Reserve cluster #2 for root directory */
                }
-               if (disk_write(pdrv, tbl, wsect++, 1))
+               if (disk_write(pdrv, tbl, wsect++, 1) != RES_OK)
                        return FR_DISK_ERR;
                mem_set(tbl, 0, SS(fs));                        /* Fill following FAT entries with zero */
                for (n = 1; n < n_fat; n++) {           /* This loop may take a time on FAT32 volume due to many single sector writes */
-                       if (disk_write(pdrv, tbl, wsect++, 1))
+                       if (disk_write(pdrv, tbl, wsect++, 1) != RES_OK)
                                return FR_DISK_ERR;
                }
        }
@@ -4181,28 +4289,26 @@ FRESULT f_mkfs (
        /* Initialize root directory */
        i = (fmt == FS_FAT32) ? au : (UINT)n_dir;
        do {
-               if (disk_write(pdrv, tbl, wsect++, 1))
+               if (disk_write(pdrv, tbl, wsect++, 1) != RES_OK)
                        return FR_DISK_ERR;
        } while (--i);
 
-#if _USE_ERASE /* Erase data area if needed */
+#if _USE_TRIM  /* Erase data area if needed */
        {
-               DWORD eb[2];
-
                eb[0] = wsect; eb[1] = wsect + (n_clst - ((fmt == FS_FAT32) ? 1 : 0)) * au - 1;
-               disk_ioctl(pdrv, CTRL_ERASE_SECTOR, eb);
+               disk_ioctl(pdrv, CTRL_TRIM, eb);
        }
 #endif
 
        /* Create FSINFO if needed */
        if (fmt == FS_FAT32) {
-               ST_DWORD(tbl+FSI_LeadSig, 0x41615252);
-               ST_DWORD(tbl+FSI_StrucSig, 0x61417272);
-               ST_DWORD(tbl+FSI_Free_Count, n_clst - 1);       /* Number of free clusters */
-               ST_DWORD(tbl+FSI_Nxt_Free, 2);                          /* Last allocated cluster# */
-               ST_WORD(tbl+BS_55AA, 0xAA55);
-               disk_write(pdrv, tbl, b_vol + 1, 1);    /* Write original (VBR+1) */
-               disk_write(pdrv, tbl, b_vol + 7, 1);    /* Write backup (VBR+7) */
+               ST_DWORD(tbl + FSI_LeadSig, 0x41615252);
+               ST_DWORD(tbl + FSI_StrucSig, 0x61417272);
+               ST_DWORD(tbl + FSI_Free_Count, n_clst - 1);     /* Number of free clusters */
+               ST_DWORD(tbl + FSI_Nxt_Free, 2);                        /* Last allocated cluster# */
+               ST_WORD(tbl + BS_55AA, 0xAA55);
+               disk_write(pdrv, tbl, b_vol + 1, 1);    /* Write original (VBR + 1) */
+               disk_write(pdrv, tbl, b_vol + 7, 1);    /* Write backup (VBR + 7) */
        }
 
        return (disk_ioctl(pdrv, CTRL_SYNC, 0) == RES_OK) ? FR_OK : FR_DISK_ERR;
@@ -4212,7 +4318,7 @@ FRESULT f_mkfs (
 
 #if _MULTI_PARTITION
 /*-----------------------------------------------------------------------*/
-/* Divide Physical Drive                                                 */
+/* Create partition table on the physical drive                          */
 /*-----------------------------------------------------------------------*/
 
 FRESULT f_fdisk (
@@ -4273,7 +4379,7 @@ FRESULT f_fdisk (
        ST_WORD(p, 0xAA55);
 
        /* Write it to the MBR */
-       return (disk_write(pdrv, buf, 0, 1) || disk_ioctl(pdrv, CTRL_SYNC, 0)) ? FR_DISK_ERR : FR_OK;
+       return (disk_write(pdrv, buf, 0, 1) != RES_OK || disk_ioctl(pdrv, CTRL_SYNC, 0) != RES_OK) ? FR_DISK_ERR : FR_OK;
 }
 
 
@@ -4360,6 +4466,7 @@ TCHAR* f_gets (
 
 
 
+
 #if !_FS_READONLY
 #include <stdarg.h>
 /*-----------------------------------------------------------------------*/
index 9b47225..94440db 100644 (file)
@@ -1,21 +1,23 @@
 /*---------------------------------------------------------------------------/
-/  FatFs - FAT file system module include file  R0.10a    (C)ChaN, 2014
+/  FatFs - FAT file system module include R0.11a    (C)ChaN, 2015
 /----------------------------------------------------------------------------/
-/ FatFs module is a generic FAT file system module for small embedded systems.
-/ This is a free software that opened for education, research and commercial
-/ developments under license policy of following terms.
+/ FatFs module is a free software that opened under license policy of
+/ following conditions.
 /
-/  Copyright (C) 2014, ChaN, all right reserved.
+/ Copyright (C) 2015, ChaN, all right reserved.
 /
-/ * The FatFs module is a free software and there is NO WARRANTY.
-/ * No restriction on use. You can use, modify and redistribute it for
-/   personal, non-profit or commercial product UNDER YOUR RESPONSIBILITY.
-/ * Redistributions of source code must retain the above copyright notice.
+/ 1. Redistributions of source code must retain the above copyright notice,
+/    this condition and the following disclaimer.
 /
-/----------------------------------------------------------------------------*/
+/ This software is provided by the copyright holder and contributors "AS IS"
+/ and any warranties related to this software are DISCLAIMED.
+/ The copyright owner or contributors be NOT LIABLE for any damages caused
+/ by use of this software.
+/---------------------------------------------------------------------------*/
+
 
 #ifndef _FATFS
-#define _FATFS 29000   /* Revision ID */
+#define _FATFS 64180   /* Revision ID */
 
 #ifdef __cplusplus
 extern "C" {
@@ -23,7 +25,6 @@ extern "C" {
 
 #include <typedefs.h>  /* Basic integer types */
 #include "ffconf.h"            /* FatFs configuration options */
-
 #if _FATFS != _FFCONF
 #error Wrong configuration file (ffconf.h).
 #endif
@@ -53,7 +54,7 @@ extern PARTITION VolToPart[]; /* Volume - Partition resolution table */
 
 #if _LFN_UNICODE                       /* Unicode string */
 #if !_USE_LFN
-#error _LFN_UNICODE must be 0 in non-LFN cfg.
+#error _LFN_UNICODE must be 0 at non-LFN cfg.
 #endif
 #ifndef _INC_TCHAR
 typedef WCHAR TCHAR;
@@ -96,7 +97,7 @@ typedef struct {
 #if _FS_RPATH
        DWORD   cdir;                   /* Current directory start cluster (0:root) */
 #endif
-       DWORD   n_fatent;               /* Number of FAT entries (= number of clusters + 2) */
+       DWORD   n_fatent;               /* Number of FAT entries, = number of clusters + 2 */
        DWORD   fsize;                  /* Sectors per FAT */
        DWORD   volbase;                /* Volume start sector */
        DWORD   fatbase;                /* FAT start sector */
@@ -113,25 +114,25 @@ typedef struct {
 typedef struct {
        FATFS*  fs;                             /* Pointer to the related file system object (**do not change order**) */
        WORD    id;                             /* Owner file system mount ID (**do not change order**) */
-       BYTE    flag;                   /* File status flags */
+       BYTE    flag;                   /* Status flags */
        BYTE    err;                    /* Abort flag (error code) */
        DWORD   fptr;                   /* File read/write pointer (Zeroed on file open) */
        DWORD   fsize;                  /* File size */
-       DWORD   sclust;                 /* File data start cluster (0:no data cluster, always 0 when fsize is 0) */
-       DWORD   clust;                  /* Current cluster of fpter */
-       DWORD   dsect;                  /* Current data sector of fpter */
+       DWORD   sclust;                 /* File start cluster (0:no cluster chain, always 0 when fsize is 0) */
+       DWORD   clust;                  /* Current cluster of fpter (not valid when fprt is 0) */
+       DWORD   dsect;                  /* Sector number appearing in buf[] (0:invalid) */
 #if !_FS_READONLY
-       DWORD   dir_sect;               /* Sector containing the directory entry */
-       BYTE*   dir_ptr;                /* Pointer to the directory entry in the window */
+       DWORD   dir_sect;               /* Sector number containing the directory entry */
+       BYTE*   dir_ptr;                /* Pointer to the directory entry in the win[] */
 #endif
 #if _USE_FASTSEEK
        DWORD*  cltbl;                  /* Pointer to the cluster link map table (Nulled on file open) */
 #endif
 #if _FS_LOCK
-       UINT    lockid;                 /* File lock ID (index of file semaphore table Files[]) */
+       UINT    lockid;                 /* File lock ID origin from 1 (index of file semaphore table Files[]) */
 #endif
 #if !_FS_TINY
-       BYTE    buf[_MAX_SS];   /* File data read/write buffer */
+       BYTE    buf[_MAX_SS];   /* File private data read/write window */
 #endif
 } FIL;
 
@@ -155,11 +156,14 @@ typedef struct {
        WCHAR*  lfn;                    /* Pointer to the LFN working buffer */
        WORD    lfn_idx;                /* Last matched LFN index number (0xFFFF:No LFN) */
 #endif
+#if _USE_FIND
+       const TCHAR*    pat;    /* Pointer to the name matching pattern */
+#endif
 } DIR;
 
 
 
-/* File status structure (FILINFO) */
+/* File information structure (FILINFO) */
 
 typedef struct {
        DWORD   fsize;                  /* File size */
@@ -196,7 +200,7 @@ typedef enum {
        FR_TIMEOUT,                             /* (15) Could not get a grant to access the volume within defined period */
        FR_LOCKED,                              /* (16) The operation is rejected according to the file sharing policy */
        FR_NOT_ENOUGH_CORE,             /* (17) LFN working buffer could not be allocated */
-       FR_TOO_MANY_OPEN_FILES, /* (18) Number of open files > _FS_SHARE */
+       FR_TOO_MANY_OPEN_FILES, /* (18) Number of open files > _FS_LOCK */
        FR_INVALID_PARAMETER    /* (19) Given parameter is invalid */
 } FRESULT;
 
@@ -216,19 +220,21 @@ FRESULT f_sync (FIL* fp);                                                                                 /* Flush cached data of a writing file */
 FRESULT f_opendir (DIR* dp, const TCHAR* path);                                                /* Open a directory */
 FRESULT f_closedir (DIR* dp);                                                                          /* Close an open directory */
 FRESULT f_readdir (DIR* dp, FILINFO* fno);                                                     /* Read a directory item */
+FRESULT f_findfirst (DIR* dp, FILINFO* fno, const TCHAR* path, const TCHAR* pattern);  /* Find first file */
+FRESULT f_findnext (DIR* dp, FILINFO* fno);                                                    /* Find next file */
 FRESULT f_mkdir (const TCHAR* path);                                                           /* Create a sub directory */
 FRESULT f_unlink (const TCHAR* path);                                                          /* Delete an existing file or directory */
 FRESULT f_rename (const TCHAR* path_old, const TCHAR* path_new);       /* Rename/Move a file or directory */
 FRESULT f_stat (const TCHAR* path, FILINFO* fno);                                      /* Get file status */
-FRESULT f_chmod (const TCHAR* path, BYTE value, BYTE mask);                    /* Change attribute of the file/dir */
+FRESULT f_chmod (const TCHAR* path, BYTE attr, BYTE mask);                     /* Change attribute of the file/dir */
 FRESULT f_utime (const TCHAR* path, const FILINFO* fno);                       /* Change times-tamp of the file/dir */
 FRESULT f_chdir (const TCHAR* path);                                                           /* Change current directory */
 FRESULT f_chdrive (const TCHAR* path);                                                         /* Change current drive */
 FRESULT f_getcwd (TCHAR* buff, UINT len);                                                      /* Get current directory */
 FRESULT f_getfree (const TCHAR* path, DWORD* nclst, FATFS** fatfs);    /* Get number of free clusters on the drive */
-FRESULT f_getlabel (const TCHAR* path, TCHAR* label, DWORD* sn);       /* Get volume label */
+FRESULT f_getlabel (const TCHAR* path, TCHAR* label, DWORD* vsn);      /* Get volume label */
 FRESULT f_setlabel (const TCHAR* label);                                                       /* Set volume label */
-FRESULT f_mount (FATFS* fs, const TCHAR* path, UINT opt);                      /* Mount/Unmount a logical drive */
+FRESULT f_mount (FATFS* fs, const TCHAR* path, BYTE opt);                      /* Mount/Unmount a logical drive */
 FRESULT f_mkfs (const TCHAR* path, BYTE sfd, UINT au);                         /* Create a file system on the volume */
 FRESULT f_fdisk (BYTE pdrv, const DWORD szt[], void* work);                    /* Divide a physical drive into some partitions */
 int f_putc (TCHAR c, FIL* fp);                                                                         /* Put a character to the file */
@@ -236,10 +242,12 @@ int f_puts (const TCHAR* str, FIL* cp);                                                           /* Put a string to the file */
 int f_printf (FIL* fp, const TCHAR* str, ...);                                         /* Put a formatted string to the file */
 TCHAR* f_gets (TCHAR* buff, int len, FIL* fp);                                         /* Get a string from the file */
 
-#define f_eof(fp) (((fp)->fptr == (fp)->fsize) ? 1 : 0)
+#define f_eof(fp) ((int)((fp)->fptr == (fp)->fsize))
 #define f_error(fp) ((fp)->err)
 #define f_tell(fp) ((fp)->fptr)
 #define f_size(fp) ((fp)->fsize)
+#define f_rewind(fp) f_lseek((fp), 0)
+#define f_rewinddir(dp) f_readdir((dp), 0)
 
 #ifndef EOF
 #define EOF (-1)
@@ -252,7 +260,7 @@ TCHAR* f_gets (TCHAR* buff, int len, FIL* fp);                                              /* Get a string from the fil
 /* Additional user defined functions                            */
 
 /* RTC function */
-#if !_FS_READONLY
+#if !_FS_READONLY && !_FS_NORTC
 DWORD get_fattime (void);
 #endif
 
index 23d4429..3f3513a 100644 (file)
@@ -1,30 +1,22 @@
 /*---------------------------------------------------------------------------/
-/  FatFs - FAT file system module configuration file  R0.10a (C)ChaN, 2014
+/  FatFs - FAT file system module configuration file  R0.11a (C)ChaN, 2015
 /---------------------------------------------------------------------------*/
 
-#ifndef _FFCONF
-#define _FFCONF 29000  /* Revision ID */
-
+#define _FFCONF 64180  /* Revision ID */
 
 /*---------------------------------------------------------------------------/
-/ Functions and Buffer Configurations
+/ Function Configurations
 /---------------------------------------------------------------------------*/
 
-#define        _FS_TINY                0       /* 0:Normal or 1:Tiny */
-/* When _FS_TINY is set to 1, it reduces memory consumption _MAX_SS bytes each
-/  file object. For file data transfer, FatFs uses the common sector buffer in
-/  the file system object (FATFS) instead of private sector buffer eliminated
-/  from the file object (FIL). */
-
+#define _FS_READONLY   0
+/* This option switches read-only configuration. (0:Read/Write or 1:Read-only)
+/  Read-only configuration removes writing API functions, f_write(), f_sync(),
+/  f_unlink(), f_mkdir(), f_chmod(), f_rename(), f_truncate(), f_getfree()
+/  and optional writing functions as well. */
 
-#define _FS_READONLY   0       /* 0:Read/Write or 1:Read only */
-/* Setting _FS_READONLY to 1 defines read only configuration. This removes
-/  writing functions, f_write(), f_sync(), f_unlink(), f_mkdir(), f_chmod(),
-/  f_rename(), f_truncate() and useless f_getfree(). */
 
-
-#define _FS_MINIMIZE   0       /* 0 to 3 */
-/* The _FS_MINIMIZE option defines minimization level to remove API functions.
+#define _FS_MINIMIZE   0
+/* This option defines minimization level to remove some basic API functions.
 /
 /   0: All basic functions are enabled.
 /   1: f_stat(), f_getfree(), f_unlink(), f_mkdir(), f_chmod(), f_utime(),
 /   3: f_lseek() function is removed in addition to 2. */
 
 
-#define        _USE_STRFUNC    2       /* 0:Disable or 1-2:Enable */
-/* To enable string functions, set _USE_STRFUNC to 1 or 2. */
+#define        _USE_STRFUNC    0
+/* This option switches string functions, f_gets(), f_putc(), f_puts() and
+/  f_printf().
+/
+/  0: Disable string functions.
+/  1: Enable without LF-CRLF conversion.
+/  2: Enable with LF-CRLF conversion. */
+
+
+#define _USE_FIND              0
+/* This option switches filtered directory read feature and related functions,
+/  f_findfirst() and f_findnext(). (0:Disable or 1:Enable) */
 
 
-#define        _USE_MKFS               1       /* 0:Disable or 1:Enable */
-/* To enable f_mkfs() function, set _USE_MKFS to 1 and set _FS_READONLY to 0 */
+#define        _USE_MKFS               1
+/* This option switches f_mkfs() function. (0:Disable or 1:Enable) */
 
 
-#define        _USE_FASTSEEK   0       /* 0:Disable or 1:Enable */
-/* To enable fast seek feature, set _USE_FASTSEEK to 1. */
+#define        _USE_FASTSEEK   0
+/* This option switches fast seek feature. (0:Disable or 1:Enable) */
 
 
-#define _USE_LABEL             1       /* 0:Disable or 1:Enable */
-/* To enable volume label functions, set _USE_LAVEL to 1 */
+#define _USE_LABEL             1
+/* This option switches volume label functions, f_getlabel() and f_setlabel().
+/  (0:Disable or 1:Enable) */
 
 
-#define        _USE_FORWARD    0       /* 0:Disable or 1:Enable */
-/* To enable f_forward() function, set _USE_FORWARD to 1 and set _FS_TINY to 1. */
+#define        _USE_FORWARD    0
+/* This option switches f_forward() function. (0:Disable or 1:Enable)
+/  To enable it, also _FS_TINY need to be set to 1. */
 
 
 /*---------------------------------------------------------------------------/
 / Locale and Namespace Configurations
 /---------------------------------------------------------------------------*/
 
-#define _CODE_PAGE     1252
-/* The _CODE_PAGE specifies the OEM code page to be used on the target system.
+#define _CODE_PAGE     437
+/* This option specifies the OEM code page to be used on the target system.
 /  Incorrect setting of the code page can cause a file open failure.
 /
-/   932  - Japanese Shift-JIS (DBCS, OEM, Windows)
-/   936  - Simplified Chinese GBK (DBCS, OEM, Windows)
-/   949  - Korean (DBCS, OEM, Windows)
-/   950  - Traditional Chinese Big5 (DBCS, OEM, Windows)
-/   1250 - Central Europe (Windows)
-/   1251 - Cyrillic (Windows)
-/   1252 - Latin 1 (Windows)
-/   1253 - Greek (Windows)
-/   1254 - Turkish (Windows)
-/   1255 - Hebrew (Windows)
-/   1256 - Arabic (Windows)
-/   1257 - Baltic (Windows)
-/   1258 - Vietnam (OEM, Windows)
-/   437  - U.S. (OEM)
-/   720  - Arabic (OEM)
-/   737  - Greek (OEM)
-/   775  - Baltic (OEM)
-/   850  - Multilingual Latin 1 (OEM)
-/   858  - Multilingual Latin 1 + Euro (OEM)
-/   852  - Latin 2 (OEM)
-/   855  - Cyrillic (OEM)
-/   866  - Russian (OEM)
-/   857  - Turkish (OEM)
-/   862  - Hebrew (OEM)
-/   874  - Thai (OEM, Windows)
-/   1    - ASCII (Valid for only non-LFN cfg.) */
-
-
-#define        _USE_LFN        2               /* 0 to 3 */
-#define        _MAX_LFN        255             /* Maximum LFN length to handle (12 to 255) */
+/   1   - ASCII (No extended character. Non-LFN cfg. only)
+/   437 - U.S.
+/   720 - Arabic
+/   737 - Greek
+/   771 - KBL
+/   775 - Baltic
+/   850 - Latin 1
+/   852 - Latin 2
+/   855 - Cyrillic
+/   857 - Turkish
+/   860 - Portuguese
+/   861 - Icelandic
+/   862 - Hebrew
+/   863 - Canadian French
+/   864 - Arabic
+/   865 - Nordic
+/   866 - Russian
+/   869 - Greek 2
+/   932 - Japanese (DBCS)
+/   936 - Simplified Chinese (DBCS)
+/   949 - Korean (DBCS)
+/   950 - Traditional Chinese (DBCS)
+*/
+
+
+#define        _USE_LFN        2
+#define        _MAX_LFN        255
 /* The _USE_LFN option switches the LFN feature.
 /
-/   0: Disable LFN feature. _MAX_LFN and _LFN_UNICODE have no effect.
+/   0: Disable LFN feature. _MAX_LFN has no effect.
 /   1: Enable LFN with static working buffer on the BSS. Always NOT thread-safe.
 /   2: Enable LFN with dynamic working buffer on the STACK.
 /   3: Enable LFN with dynamic working buffer on the HEAP.
 /
-/  When enable LFN feature, Unicode handling functions ff_convert() and ff_wtoupper()
-/  function must be added to the project.
-/  The LFN working buffer occupies (_MAX_LFN + 1) * 2 bytes. When use stack for the
-/  working buffer, take care on stack overflow. When use heap memory for the working
-/  buffer, memory management functions, ff_memalloc() and ff_memfree(), must be added
-/  to the project. */
+/  When enable the LFN feature, Unicode handling functions (option/unicode.c) must
+/  be added to the project. The LFN working buffer occupies (_MAX_LFN + 1) * 2 bytes.
+/  When use stack for the working buffer, take care on stack overflow. When use heap
+/  memory for the working buffer, memory management functions, ff_memalloc() and
+/  ff_memfree(), must be added to the project. */
 
 
-#define        _LFN_UNICODE    0       /* 0:ANSI/OEM or 1:Unicode */
-/* To switch the character encoding on the FatFs API (TCHAR) to Unicode, enable LFN
-/  feature and set _LFN_UNICODE to 1. This option affects behavior of string I/O
-/  functions. */
+#define        _LFN_UNICODE    0
+/* This option switches character encoding on the API. (0:ANSI/OEM or 1:Unicode)
+/  To use Unicode string for the path name, enable LFN feature and set _LFN_UNICODE
+/  to 1. This option also affects behavior of string I/O functions. */
 
 
-#define _STRF_ENCODE   3       /* 0:ANSI/OEM, 1:UTF-16LE, 2:UTF-16BE, 3:UTF-8 */
-/* When Unicode API is enabled by _LFN_UNICODE option, this option selects the character
-/  encoding on the file to be read/written via string I/O functions, f_gets(), f_putc(),
-/  f_puts and f_printf(). This option has no effect when Unicode API is not enabled. */
+#define _STRF_ENCODE   3
+/* When _LFN_UNICODE is 1, this option selects the character encoding on the file to
+/  be read/written via string I/O functions, f_gets(), f_putc(), f_puts and f_printf().
+/
+/  0: ANSI/OEM
+/  1: UTF-16LE
+/  2: UTF-16BE
+/  3: UTF-8
+/
+/  When _LFN_UNICODE is 0, this option has no effect. */
 
 
-#define _FS_RPATH              0       /* 0 to 2 */
-/* The _FS_RPATH option configures relative path feature.
+#define _FS_RPATH      0
+/* This option configures relative path feature.
 /
 /   0: Disable relative path feature and remove related functions.
-/   1: Enable relative path. f_chdrive() and f_chdir() function are available.
+/   1: Enable relative path feature. f_chdir() and f_chdrive() are available.
 /   2: f_getcwd() function is available in addition to 1.
 /
-/  Note that output of the f_readdir() fnction is affected by this option. */
+/  Note that directory items read via f_readdir() are affected by this option. */
 
 
 /*---------------------------------------------------------------------------/
 /* Number of volumes (logical drives) to be used. */
 
 
-#define _STR_VOLUME_ID 0       /* 0:Use only 0-9 for drive ID, 1:Use strings for drive ID */
+#define _STR_VOLUME_ID 0
 #define _VOLUME_STRS   "RAM","NAND","CF","SD1","SD2","USB1","USB2","USB3"
-/* When _STR_VOLUME_ID is set to 1, also pre-defined string can be used as drive number
-/  in the path name. _VOLUME_STRS defines the drive ID strings for each logical drives.
-/  Number of items must be equal to _VOLUMES. Valid characters for the drive ID strings
-/  are: 0-9 and A-Z. */
+/* _STR_VOLUME_ID option switches string volume ID feature.
+/  When _STR_VOLUME_ID is set to 1, also pre-defined strings can be used as drive
+/  number in the path name. _VOLUME_STRS defines the drive ID strings for each
+/  logical drives. Number of items must be equal to _VOLUMES. Valid characters for
+/  the drive ID strings are: A-Z and 0-9. */
 
 
-#define        _MULTI_PARTITION        0       /* 0:Single partition, 1:Enable multiple partition */
-/* By default(0), each logical drive number is bound to the same physical drive number
-/  and only a FAT volume found on the physical drive is mounted. When it is set to 1,
-/  each logical drive number is bound to arbitrary drive/partition listed in VolToPart[].
-*/
+#define        _MULTI_PARTITION        0
+/* This option switches multi-partition feature. By default (0), each logical drive
+/  number is bound to the same physical drive number and only an FAT volume found on
+/  the physical drive will be mounted. When multi-partition feature is enabled (1),
+/  each logical drive number is bound to arbitrary physical drive and partition
+/  listed in the VolToPart[]. Also f_fdisk() funciton will be available. */
 
 
 #define        _MIN_SS         512
 #define        _MAX_SS         512
-/* These options configure the sector size to be supported. (512, 1024, 2048 or 4096)
-/  Always set both 512 for most systems, all memory card and hard disk. But a larger
-/  value may be required for on-board flash memory and some type of optical media.
-/  When _MIN_SS != _MAX_SS, FatFs is configured to multiple sector size and
-/  GET_SECTOR_SIZE command must be implemented to the disk_ioctl() function. */
+/* These options configure the range of sector size to be supported. (512, 1024,
+/  2048 or 4096) Always set both 512 for most systems, all type of memory cards and
+/  harddisk. But a larger value may be required for on-board flash memory and some
+/  type of optical media. When _MAX_SS is larger than _MIN_SS, FatFs is configured
+/  to variable sector size and GET_SECTOR_SIZE command must be implemented to the
+/  disk_ioctl() function. */
 
 
-#define        _USE_ERASE      0       /* 0:Disable or 1:Enable */
-/* To enable sector erase feature, set _USE_ERASE to 1. Also CTRL_ERASE_SECTOR command
-/  should be added to the disk_ioctl() function. */
+#define        _USE_TRIM       0
+/* This option switches ATA-TRIM feature. (0:Disable or 1:Enable)
+/  To enable Trim feature, also CTRL_TRIM command should be implemented to the
+/  disk_ioctl() function. */
 
 
-#define _FS_NOFSINFO   0       /* 0 to 3 */
+#define _FS_NOFSINFO   0
 /* If you need to know correct free space on the FAT32 volume, set bit 0 of this
-/  option and f_getfree() function at first time after volume mount will force
-/  a full FAT scan. Bit 1 controls the last allocated cluster number as bit 0.
+/  option, and f_getfree() function at first time after volume mount will force
+/  a full FAT scan. Bit 1 controls the use of last allocated cluster number.
 /
 /  bit0=0: Use free cluster count in the FSINFO if available.
 /  bit0=1: Do not trust free cluster count in the FSINFO.
 / System Configurations
 /---------------------------------------------------------------------------*/
 
-#define _WORD_ACCESS   1       /* 0 or 1 */
+#define        _FS_TINY        0
+/* This option switches tiny buffer configuration. (0:Normal or 1:Tiny)
+/  At the tiny configuration, size of the file object (FIL) is reduced _MAX_SS
+/  bytes. Instead of private sector buffer eliminated from the file object,
+/  common sector buffer in the file system object (FATFS) is used for the file
+/  data transfer. */
+
+
+#define _FS_NORTC      0
+#define _NORTC_MON     1
+#define _NORTC_MDAY    1
+#define _NORTC_YEAR    2015
+/* The _FS_NORTC option switches timestamp feature. If the system does not have
+/  an RTC function or valid timestamp is not needed, set _FS_NORTC to 1 to disable
+/  the timestamp feature. All objects modified by FatFs will have a fixed timestamp
+/  defined by _NORTC_MON, _NORTC_MDAY and _NORTC_YEAR.
+/  When timestamp feature is enabled (_FS_NORTC == 0), get_fattime() function need
+/  to be added to the project to read current time form RTC. _NORTC_MON,
+/  _NORTC_MDAY and _NORTC_YEAR have no effect. 
+/  These options have no effect at read-only configuration (_FS_READONLY == 1). */
+
+
+#define        _FS_LOCK        0
+/* The _FS_LOCK option switches file lock feature to control duplicated file open
+/  and illegal operation to open objects. This option must be 0 when _FS_READONLY
+/  is 1.
+/
+/  0:  Disable file lock feature. To avoid volume corruption, application program
+/      should avoid illegal open, remove and rename to the open objects.
+/  >0: Enable file lock feature. The value defines how many files/sub-directories
+/      can be opened simultaneously under file lock control. Note that the file
+/      lock feature is independent of re-entrancy. */
+
+
+#define _FS_REENTRANT  0
+#define _FS_TIMEOUT            1000
+#define        _SYNC_t                 HANDLE
+/* The _FS_REENTRANT option switches the re-entrancy (thread safe) of the FatFs
+/  module itself. Note that regardless of this option, file access to different
+/  volume is always re-entrant and volume control functions, f_mount(), f_mkfs()
+/  and f_fdisk() function, are always not re-entrant. Only file/directory access
+/  to the same volume is under control of this feature.
+/
+/   0: Disable re-entrancy. _FS_TIMEOUT and _SYNC_t have no effect.
+/   1: Enable re-entrancy. Also user provided synchronization handlers,
+/      ff_req_grant(), ff_rel_grant(), ff_del_syncobj() and ff_cre_syncobj()
+/      function, must be added to the project. Samples are available in
+/      option/syscall.c.
+/
+/  The _FS_TIMEOUT defines timeout period in unit of time tick.
+/  The _SYNC_t defines O/S dependent sync object type. e.g. HANDLE, ID, OS_EVENT*,
+/  SemaphoreHandle_t and etc.. A header file for O/S definitions needs to be
+/  included somewhere in the scope of ff.c. */
+
+
+#define _WORD_ACCESS   0
 /* The _WORD_ACCESS option is an only platform dependent option. It defines
 /  which access method is used to the word data on the FAT volume.
 /
 /   0: Byte-by-byte access. Always compatible with all platforms.
 /   1: Word access. Do not choose this unless under both the following conditions.
 /
-/  * Address misaligned memory access is always allowed for all instructions.
+/  * Address misaligned memory access is always allowed to ALL instructions.
 /  * Byte order on the memory is little-endian.
 /
-/  If it is the case, _WORD_ACCESS can also be set to 1 to improve performance
-/  and reduce code size.
-*/
-
-
-#define        _FS_LOCK        0       /* 0:Disable or >=1:Enable */
-/* To enable file lock control feature, set _FS_LOCK to 1 or greater.
-/  The value defines how many files/sub-directories can be opened simultaneously.
-/  This feature consumes _FS_LOCK * 12 bytes of bss area. */
-
-
-#define _FS_REENTRANT  0               /* 0:Disable or 1:Enable */
-#define _FS_TIMEOUT            1000    /* Timeout period in unit of time ticks */
-#define        _SYNC_t                 HANDLE  /* O/S dependent sync object type. e.g. HANDLE, OS_EVENT*, ID and etc.. */
-/*#include <windows.h>*/
-
-/* A header file that defines sync object types on the O/S, such as windows.h,
-/  ucos_ii.h and semphr.h, should be included here when enable this option.
-/  The _FS_REENTRANT option switches the re-entrancy (thread safe) of the FatFs module.
+/  If it is the case, _WORD_ACCESS can also be set to 1 to reduce code size.
+/  Following table shows allowable settings of some type of processors.
 /
-/   0: Disable re-entrancy. _FS_TIMEOUT and _SYNC_t have no effect.
-/   1: Enable re-entrancy. Also user provided synchronization handlers,
-/      ff_req_grant(), ff_rel_grant(), ff_del_syncobj() and ff_cre_syncobj()
-/      function must be added to the project.
+/  ARM7TDMI   0   *2          ColdFire   0    *1         V850E      0    *2
+/  Cortex-M3  0   *3          Z80        0/1             V850ES     0/1
+/  Cortex-M0  0   *2          x86        0/1             TLCS-870   0/1
+/  AVR        0/1             RX600(LE)  0/1             TLCS-900   0/1
+/  AVR32      0   *1          RL78       0    *2         R32C       0    *2
+/  PIC18      0/1             SH-2       0    *1         M16C       0/1
+/  PIC24      0   *2          H8S        0    *1         MSP430     0    *2
+/  PIC32      0   *1          H8/300H    0    *1         8051       0/1
+/
+/  *1:Big-endian.
+/  *2:Unaligned memory access is not supported.
+/  *3:Some compilers generate LDM/STM for mem_cpy function.
 */
 
-
-#endif /* _FFCONFIG */
index 8aa71b2..23ef651 100644 (file)
@@ -1,28 +1,24 @@
 /*------------------------------------------------------------------------*/
-/* Unicode - Local code bidirectional converter  (C)ChaN, 2012            */
+/* Unicode - Local code bidirectional converter  (C)ChaN, 2015            */
 /* (SBCS code pages)                                                      */
 /*------------------------------------------------------------------------*/
-/*  437   U.S. (OEM)
-/   720   Arabic (OEM)
-/   1256  Arabic (Windows)
-/   737   Greek (OEM)
-/   1253  Greek (Windows)
-/   1250  Central Europe (Windows)
-/   775   Baltic (OEM)
-/   1257  Baltic (Windows)
-/   850   Multilingual Latin 1 (OEM)
-/   852   Latin 2 (OEM)
-/   1252  Latin 1 (Windows)
-/   855   Cyrillic (OEM)
-/   1251  Cyrillic (Windows)
-/   866   Russian (OEM)
-/   857   Turkish (OEM)
-/   1254  Turkish (Windows)
-/   858   Multilingual Latin 1 + Euro (OEM)
-/   862   Hebrew (OEM)
-/   1255  Hebrew (Windows)
-/   874   Thai (OEM, Windows)
-/   1258  Vietnam (OEM, Windows)
+/*  437   U.S.
+/   720   Arabic
+/   737   Greek
+/   771   KBL
+/   775   Baltic
+/   850   Latin 1
+/   852   Latin 2
+/   855   Cyrillic
+/   857   Turkish
+/   860   Portuguese
+/   861   Icelandic
+/   862   Hebrew
+/   863   Canadian French
+/   864   Arabic
+/   865   Nordic
+/   866   Russian
+/   869   Greek 2
 */
 
 #include "../ff.h"
 #define _TBLDEF 1
 static
 const WCHAR Tbl[] = {  /*  CP437(0x80-0xFF) to Unicode conversion table */
-       0x00C7, 0x00FC, 0x00E9, 0x00E2, 0x00E4, 0x00E0, 0x00E5, 0x00E7,
-       0x00EA, 0x00EB, 0x00E8, 0x00EF, 0x00EE, 0x00EC, 0x00C4, 0x00C5,
-       0x00C9, 0x00E6, 0x00C6, 0x00F4, 0x00F6, 0x00F2, 0x00FB, 0x00F9,
-       0x00FF, 0x00D6, 0x00DC, 0x00A2, 0x00A3, 0x00A5, 0x20A7, 0x0192,
-       0x00E1, 0x00ED, 0x00F3, 0x00FA, 0x00F1, 0x00D1, 0x00AA, 0x00BA,
-       0x00BF, 0x2310, 0x00AC, 0x00BD, 0x00BC, 0x00A1, 0x00AB, 0x00BB,
-       0x2591, 0x2592, 0x2593, 0x2502, 0x2524, 0x2561, 0x2562, 0x2556,
-       0x2555, 0x2563, 0x2551, 0x2557, 0x255D, 0x255C, 0x255B, 0x2510,
-       0x2514, 0x2534, 0x252C, 0x251C, 0x2500, 0x253C, 0x255E, 0x255F,
-       0x255A, 0x2554, 0x2569, 0x2566, 0x2560, 0x2550, 0x256C, 0x2567,
-       0x2568, 0x2564, 0x2565, 0x2559, 0x2558, 0x2552, 0x2553, 0x256B,
-       0x256A, 0x2518, 0x250C, 0x2588, 0x2584, 0x258C, 0x2590, 0x2580,
-       0x03B1, 0x00DF, 0x0393, 0x03C0, 0x03A3, 0x03C3, 0x00B5, 0x03C4,
-       0x03A6, 0x0398, 0x03A9, 0x03B4, 0x221E, 0x03C6, 0x03B5, 0x2229,
-       0x2261, 0x00B1, 0x2265, 0x2264, 0x2320, 0x2321, 0x00F7, 0x2248,
-       0x00B0, 0x2219, 0x00B7, 0x221A, 0x207F, 0x00B2, 0x25A0, 0x00A0
+       0x00C7, 0x00FC, 0x00E9, 0x00E2, 0x00E4, 0x00E0, 0x00E5, 0x00E7, 0x00EA, 0x00EB, 0x00E8, 0x00EF, 0x00EE, 0x00EC, 0x00C4, 0x00C5,
+       0x00C9, 0x00E6, 0x00C6, 0x00F4, 0x00F6, 0x00F2, 0x00FB, 0x00F9, 0x00FF, 0x00D6, 0x00DC, 0x00A2, 0x00A3, 0x00A5, 0x20A7, 0x0192,
+       0x00E1, 0x00ED, 0x00F3, 0x00FA, 0x00F1, 0x00D1, 0x00AA, 0x00BA, 0x00BF, 0x2310, 0x00AC, 0x00BD, 0x00BC, 0x00A1, 0x00AB, 0x00BB,
+       0x2591, 0x2592, 0x2593, 0x2502, 0x2524, 0x2561, 0x2562, 0x2556, 0x2555, 0x2563, 0x2551, 0x2557, 0x255D, 0x255C, 0x255B, 0x2510,
+       0x2514, 0x2534, 0x252C, 0x251C, 0x2500, 0x253C, 0x255E, 0x255F, 0x255A, 0x2554, 0x2569, 0x2566, 0x2560, 0x2550, 0x256C, 0x2567,
+       0x2568, 0x2564, 0x2565, 0x2559, 0x2558, 0x2552, 0x2553, 0x256B, 0x256A, 0x2518, 0x250C, 0x2588, 0x2584, 0x258C, 0x2590, 0x2580,
+       0x03B1, 0x00DF, 0x0393, 0x03C0, 0x03A3, 0x03C3, 0x00B5, 0x03C4, 0x03A6, 0x0398, 0x03A9, 0x03B4, 0x221E, 0x03C6, 0x03B5, 0x2229,
+       0x2261, 0x00B1, 0x2265, 0x2264, 0x2320, 0x2321, 0x00F7, 0x2248, 0x00B0, 0x2219, 0x00B7, 0x221A, 0x207F, 0x00B2, 0x25A0, 0x00A0
 };
 
 #elif _CODE_PAGE == 720
 #define _TBLDEF 1
 static
 const WCHAR Tbl[] = {  /*  CP720(0x80-0xFF) to Unicode conversion table */
-       0x0000, 0x0000, 0x00E9, 0x00E2, 0x0000, 0x00E0, 0x0000, 0x00E7,
-       0x00EA, 0x00EB, 0x00E8, 0x00EF, 0x00EE, 0x0000, 0x0000, 0x0000,
-       0x0000, 0x0651, 0x0652, 0x00F4, 0x00A4, 0x0640, 0x00FB, 0x00F9,
-       0x0621, 0x0622, 0x0623, 0x0624, 0x00A3, 0x0625, 0x0626, 0x0627,
-       0x0628, 0x0629, 0x062A, 0x062B, 0x062C, 0x062D, 0x062E, 0x062F,
-       0x0630, 0x0631, 0x0632, 0x0633, 0x0634, 0x0635, 0x00AB, 0x00BB,
-       0x2591, 0x2592, 0x2593, 0x2502, 0x2524, 0x2561, 0x2562, 0x2556,
-       0x2555, 0x2563, 0x2551, 0x2557, 0x255D, 0x255C, 0x255B, 0x2510,
-       0x2514, 0x2534, 0x252C, 0x251C, 0x2500, 0x253C, 0x255E, 0x255F,
-       0x255A, 0x2554, 0x2569, 0x2566, 0x2560, 0x2550, 0x256C, 0x2567,
-       0x2568, 0x2564, 0x2565, 0x2559, 0x2558, 0x2552, 0x2553, 0x256B,
-       0x256A, 0x2518, 0x250C, 0x2588, 0x2584, 0x258C, 0x2590, 0x2580,
-       0x0636, 0x0637, 0x0638, 0x0639, 0x063A, 0x0641, 0x00B5, 0x0642,
-       0x0643, 0x0644, 0x0645, 0x0646, 0x0647, 0x0648, 0x0649, 0x064A,
-       0x2261, 0x064B, 0x064C, 0x064D, 0x064E, 0x064F, 0x0650, 0x2248,
-       0x00B0, 0x2219, 0x00B7, 0x221A, 0x207F, 0x00B2, 0x25A0, 0x00A0
+       0x0000, 0x0000, 0x00E9, 0x00E2, 0x0000, 0x00E0, 0x0000, 0x00E7, 0x00EA, 0x00EB, 0x00E8, 0x00EF, 0x00EE, 0x0000, 0x0000, 0x0000,
+       0x0000, 0x0651, 0x0652, 0x00F4, 0x00A4, 0x0640, 0x00FB, 0x00F9, 0x0621, 0x0622, 0x0623, 0x0624, 0x00A3, 0x0625, 0x0626, 0x0627,
+       0x0628, 0x0629, 0x062A, 0x062B, 0x062C, 0x062D, 0x062E, 0x062F, 0x0630, 0x0631, 0x0632, 0x0633, 0x0634, 0x0635, 0x00AB, 0x00BB,
+       0x2591, 0x2592, 0x2593, 0x2502, 0x2524, 0x2561, 0x2562, 0x2556, 0x2555, 0x2563, 0x2551, 0x2557, 0x255D, 0x255C, 0x255B, 0x2510,
+       0x2514, 0x2534, 0x252C, 0x251C, 0x2500, 0x253C, 0x255E, 0x255F, 0x255A, 0x2554, 0x2569, 0x2566, 0x2560, 0x2550, 0x256C, 0x2567,
+       0x2568, 0x2564, 0x2565, 0x2559, 0x2558, 0x2552, 0x2553, 0x256B, 0x256A, 0x2518, 0x250C, 0x2588, 0x2584, 0x258C, 0x2590, 0x2580,
+       0x0636, 0x0637, 0x0638, 0x0639, 0x063A, 0x0641, 0x00B5, 0x0642, 0x0643, 0x0644, 0x0645, 0x0646, 0x0647, 0x0648, 0x0649, 0x064A,
+       0x2261, 0x064B, 0x064C, 0x064D, 0x064E, 0x064F, 0x0650, 0x2248, 0x00B0, 0x2219, 0x00B7, 0x221A, 0x207F, 0x00B2, 0x25A0, 0x00A0
 };
 
 #elif _CODE_PAGE == 737
 #define _TBLDEF 1
 static
 const WCHAR Tbl[] = {  /*  CP737(0x80-0xFF) to Unicode conversion table */
-       0x0391, 0x0392, 0x0393, 0x0394, 0x0395, 0x0396, 0x0397, 0x0398,
-       0x0399, 0x039A, 0x039B, 0x039C, 0x039D, 0x039E, 0x039F, 0x03A0,
-       0x03A1, 0x03A3, 0x03A4, 0x03A5, 0x03A6, 0x03A7, 0x03A8, 0x03A9,
-       0x03B1, 0x03B2, 0x03B3, 0x03B4, 0x03B5, 0x03B6, 0x03B7, 0x03B8,
-       0x03B9, 0x03BA, 0x03BB, 0x03BC, 0x03BD, 0x03BE, 0x03BF, 0x03C0,
-       0x03C1, 0x03C3, 0x03C2, 0x03C4, 0x03C5, 0x03C6, 0x03C7, 0x03C8,
-       0x2591, 0x2592, 0x2593, 0x2502, 0x2524, 0x2561, 0x2562, 0x2556,
-       0x2555, 0x2563, 0x2551, 0x2557, 0x255D, 0x255C, 0x255B, 0x2510,
-       0x2514, 0x2534, 0x252C, 0x251C, 0x2500, 0x253C, 0x255E, 0x255F,
-       0x255A, 0x2554, 0x2569, 0x2566, 0x2560, 0x2550, 0x256C, 0x2567,
-       0x2568, 0x2564, 0x2565, 0x2559, 0x2558, 0x2552, 0x2553, 0x256B,
-       0x256A, 0x2518, 0x250C, 0x2588, 0x2584, 0x258C, 0x2590, 0x2580,
-       0x03C9, 0x03AC, 0x03AD, 0x03AE, 0x03CA, 0x03AF, 0x03CC, 0x03CD,
-       0x03CB, 0x03CE, 0x0386, 0x0388, 0x0389, 0x038A, 0x038C, 0x038E,
-       0x038F, 0x00B1, 0x2265, 0x2264, 0x03AA, 0x03AB, 0x00F7, 0x2248,
-       0x00B0, 0x2219, 0x00B7, 0x221A, 0x207F, 0x00B2, 0x25A0, 0x00A0
+       0x0391, 0x0392, 0x0393, 0x0394, 0x0395, 0x0396, 0x0397, 0x0398, 0x0399, 0x039A, 0x039B, 0x039C, 0x039D, 0x039E, 0x039F, 0x03A0,
+       0x03A1, 0x03A3, 0x03A4, 0x03A5, 0x03A6, 0x03A7, 0x03A8, 0x03A9, 0x03B1, 0x03B2, 0x03B3, 0x03B4, 0x03B5, 0x03B6, 0x03B7, 0x03B8,
+       0x03B9, 0x03BA, 0x03BB, 0x03BC, 0x03BD, 0x03BE, 0x03BF, 0x03C0, 0x03C1, 0x03C3, 0x03C2, 0x03C4, 0x03C5, 0x03C6, 0x03C7, 0x03C8,
+       0x2591, 0x2592, 0x2593, 0x2502, 0x2524, 0x2561, 0x2562, 0x2556, 0x2555, 0x2563, 0x2551, 0x2557, 0x255D, 0x255C, 0x255B, 0x2510,
+       0x2514, 0x2534, 0x252C, 0x251C, 0x2500, 0x253C, 0x255E, 0x255F, 0x255A, 0x2554, 0x2569, 0x2566, 0x2560, 0x2550, 0x256C, 0x2567,
+       0x2568, 0x2564, 0x2565, 0x2559, 0x2558, 0x2552, 0x2553, 0x256B, 0x256A, 0x2518, 0x250C, 0x2588, 0x2584, 0x258C, 0x2590, 0x2580,
+       0x03C9, 0x03AC, 0x03AD, 0x03AE, 0x03CA, 0x03AF, 0x03CC, 0x03CD, 0x03CB, 0x03CE, 0x0386, 0x0388, 0x0389, 0x038A, 0x038C, 0x038E,
+       0x038F, 0x00B1, 0x2265, 0x2264, 0x03AA, 0x03AB, 0x00F7, 0x2248, 0x00B0, 0x2219, 0x00B7, 0x221A, 0x207F, 0x00B2, 0x25A0, 0x00A0
+};
+
+#elif _CODE_PAGE == 771
+#define _TBLDEF 1
+static
+const WCHAR Tbl[] = {  /*  CP771(0x80-0xFF) to Unicode conversion table */
+       0x0410, 0x0411, 0x0412, 0x0413, 0x0414, 0x0415, 0x0416, 0x0417, 0x0418, 0x0419, 0x041A, 0x041B, 0x041C, 0x041D, 0x041E, 0x041F,
+       0x0420, 0x0421, 0x0422, 0x0423, 0x0424, 0x0425, 0x0426, 0x0427, 0x0428, 0x0429, 0x042A, 0x042B, 0x042C, 0x042D, 0x042E, 0x042F,
+       0x0430, 0x0431, 0x0432, 0x0433, 0x0434, 0x0435, 0x0436, 0x0437, 0x0438, 0x0439, 0x043A, 0x043B, 0x043C, 0x043D, 0x043E, 0x043F,
+       0x2591, 0x2592, 0x2593, 0x2502, 0x2524, 0x2561, 0x2562, 0x2556, 0x2555, 0x2563, 0x2551, 0x2557, 0x255D, 0x255C, 0x2558, 0x2510,
+       0x2514, 0x2534, 0x252C, 0x251C, 0x2500, 0x253C, 0x255E, 0x255F, 0x255A, 0x2554, 0x2569, 0x2566, 0x2560, 0x2550, 0x256C, 0x2567,
+       0x2568, 0x2564, 0x2565, 0x2559, 0x2558, 0x2552, 0x2553, 0x256B, 0x256A, 0x2518, 0x250C, 0x2588, 0x0104, 0x0105, 0x010C, 0x010D,
+       0x0440, 0x0441, 0x0442, 0x0443, 0x0444, 0x0445, 0x0446, 0x0447, 0x0448, 0x0449, 0x044A, 0x044B, 0x044C, 0x044D, 0x044E, 0x044F,
+       0x0118, 0x0119, 0x0116, 0x0117, 0x012E, 0x012F, 0x0160, 0x0161, 0x0172, 0x0173, 0x016A, 0x016B, 0x017D, 0x017E, 0x25A0, 0x00A0
 };
 
 #elif _CODE_PAGE == 775
 #define _TBLDEF 1
 static
 const WCHAR Tbl[] = {  /*  CP775(0x80-0xFF) to Unicode conversion table */
-       0x0106, 0x00FC, 0x00E9, 0x0101, 0x00E4, 0x0123, 0x00E5, 0x0107,
-       0x0142, 0x0113, 0x0156, 0x0157, 0x012B, 0x0179, 0x00C4, 0x00C5,
-       0x00C9, 0x00E6, 0x00C6, 0x014D, 0x00F6, 0x0122, 0x00A2, 0x015A,
-       0x015B, 0x00D6, 0x00DC, 0x00F8, 0x00A3, 0x00D8, 0x00D7, 0x00A4,
-       0x0100, 0x012A, 0x00F3, 0x017B, 0x017C, 0x017A, 0x201D, 0x00A6,
-       0x00A9, 0x00AE, 0x00AC, 0x00BD, 0x00BC, 0x0141, 0x00AB, 0x00BB,
-       0x2591, 0x2592, 0x2593, 0x2502, 0x2524, 0x0104, 0x010C, 0x0118,
-       0x0116, 0x2563, 0x2551, 0x2557, 0x255D, 0x012E, 0x0160, 0x2510,
-       0x2514, 0x2534, 0x252C, 0x251C, 0x2500, 0x253C, 0x0172, 0x016A,
-       0x255A, 0x2554, 0x2569, 0x2566, 0x2560, 0x2550, 0x256C, 0x017D,
-       0x0105, 0x010D, 0x0119, 0x0117, 0x012F, 0x0161, 0x0173, 0x016B,
-       0x017E, 0x2518, 0x250C, 0x2588, 0x2584, 0x258C, 0x2590, 0x2580,
-       0x00D3, 0x00DF, 0x014C, 0x0143, 0x00F5, 0x00D5, 0x00B5, 0x0144,
-       0x0136, 0x0137, 0x013B, 0x013C, 0x0146, 0x0112, 0x0145, 0x2019,
-       0x00AD, 0x00B1, 0x201C, 0x00BE, 0x00B6, 0x00A7, 0x00F7, 0x201E,
-       0x00B0, 0x2219, 0x00B7, 0x00B9, 0x00B3, 0x00B2, 0x25A0, 0x00A0
+       0x0106, 0x00FC, 0x00E9, 0x0101, 0x00E4, 0x0123, 0x00E5, 0x0107, 0x0142, 0x0113, 0x0156, 0x0157, 0x012B, 0x0179, 0x00C4, 0x00C5,
+       0x00C9, 0x00E6, 0x00C6, 0x014D, 0x00F6, 0x0122, 0x00A2, 0x015A, 0x015B, 0x00D6, 0x00DC, 0x00F8, 0x00A3, 0x00D8, 0x00D7, 0x00A4,
+       0x0100, 0x012A, 0x00F3, 0x017B, 0x017C, 0x017A, 0x201D, 0x00A6, 0x00A9, 0x00AE, 0x00AC, 0x00BD, 0x00BC, 0x0141, 0x00AB, 0x00BB,
+       0x2591, 0x2592, 0x2593, 0x2502, 0x2524, 0x0104, 0x010C, 0x0118, 0x0116, 0x2563, 0x2551, 0x2557, 0x255D, 0x012E, 0x0160, 0x2510,
+       0x2514, 0x2534, 0x252C, 0x251C, 0x2500, 0x253C, 0x0172, 0x016A, 0x255A, 0x2554, 0x2569, 0x2566, 0x2560, 0x2550, 0x256C, 0x017D,
+       0x0105, 0x010D, 0x0119, 0x0117, 0x012F, 0x0161, 0x0173, 0x016B, 0x017E, 0x2518, 0x250C, 0x2588, 0x2584, 0x258C, 0x2590, 0x2580,
+       0x00D3, 0x00DF, 0x014C, 0x0143, 0x00F5, 0x00D5, 0x00B5, 0x0144, 0x0136, 0x0137, 0x013B, 0x013C, 0x0146, 0x0112, 0x0145, 0x2019,
+       0x00AD, 0x00B1, 0x201C, 0x00BE, 0x00B6, 0x00A7, 0x00F7, 0x201E, 0x00B0, 0x2219, 0x00B7, 0x00B9, 0x00B3, 0x00B2, 0x25A0, 0x00A0
 };
 
 #elif _CODE_PAGE == 850
 #define _TBLDEF 1
 static
 const WCHAR Tbl[] = {  /*  CP850(0x80-0xFF) to Unicode conversion table */
-       0x00C7, 0x00FC, 0x00E9, 0x00E2, 0x00E4, 0x00E0, 0x00E5, 0x00E7,
-       0x00EA, 0x00EB, 0x00E8, 0x00EF, 0x00EE, 0x00EC, 0x00C4, 0x00C5,
-       0x00C9, 0x00E6, 0x00C6, 0x00F4, 0x00F6, 0x00F2, 0x00FB, 0x00F9,
-       0x00FF, 0x00D6, 0x00DC, 0x00F8, 0x00A3, 0x00D8, 0x00D7, 0x0192,
-       0x00E1, 0x00ED, 0x00F3, 0x00FA, 0x00F1, 0x00D1, 0x00AA, 0x00BA,
-       0x00BF, 0x00AE, 0x00AC, 0x00BD, 0x00BC, 0x00A1, 0x00AB, 0x00BB,
-       0x2591, 0x2592, 0x2593, 0x2502, 0x2524, 0x00C1, 0x00C2, 0x00C0,
-       0x00A9, 0x2563, 0x2551, 0x2557, 0x255D, 0x00A2, 0x00A5, 0x2510,
-       0x2514, 0x2534, 0x252C, 0x251C, 0x2500, 0x253C, 0x00E3, 0x00C3,
-       0x255A, 0x2554, 0x2569, 0x2566, 0x2560, 0x2550, 0x256C, 0x00A4,
-       0x00F0, 0x00D0, 0x00CA, 0x00CB, 0x00C8, 0x0131, 0x00CD, 0x00CE,
-       0x00CF, 0x2518, 0x250C, 0x2588, 0x2584, 0x00A6, 0x00CC, 0x2580,
-       0x00D3, 0x00DF, 0x00D4, 0x00D2, 0x00F5, 0x00D5, 0x00B5, 0x00FE,
-       0x00DE, 0x00DA, 0x00DB, 0x00D9, 0x00FD, 0x00DD, 0x00AF, 0x00B4,
-       0x00AD, 0x00B1, 0x2017, 0x00BE, 0x00B6, 0x00A7, 0x00F7, 0x00B8,
-       0x00B0, 0x00A8, 0x00B7, 0x00B9, 0x00B3, 0x00B2, 0x25A0, 0x00A0
+       0x00C7, 0x00FC, 0x00E9, 0x00E2, 0x00E4, 0x00E0, 0x00E5, 0x00E7, 0x00EA, 0x00EB, 0x00E8, 0x00EF, 0x00EE, 0x00EC, 0x00C4, 0x00C5,
+       0x00C9, 0x00E6, 0x00C6, 0x00F4, 0x00F6, 0x00F2, 0x00FB, 0x00F9, 0x00FF, 0x00D6, 0x00DC, 0x00F8, 0x00A3, 0x00D8, 0x00D7, 0x0192,
+       0x00E1, 0x00ED, 0x00F3, 0x00FA, 0x00F1, 0x00D1, 0x00AA, 0x00BA, 0x00BF, 0x00AE, 0x00AC, 0x00BD, 0x00BC, 0x00A1, 0x00AB, 0x00BB,
+       0x2591, 0x2592, 0x2593, 0x2502, 0x2524, 0x00C1, 0x00C2, 0x00C0, 0x00A9, 0x2563, 0x2551, 0x2557, 0x255D, 0x00A2, 0x00A5, 0x2510,
+       0x2514, 0x2534, 0x252C, 0x251C, 0x2500, 0x253C, 0x00E3, 0x00C3, 0x255A, 0x2554, 0x2569, 0x2566, 0x2560, 0x2550, 0x256C, 0x00A4,
+       0x00F0, 0x00D0, 0x00CA, 0x00CB, 0x00C8, 0x0131, 0x00CD, 0x00CE, 0x00CF, 0x2518, 0x250C, 0x2588, 0x2584, 0x00A6, 0x00CC, 0x2580,
+       0x00D3, 0x00DF, 0x00D4, 0x00D2, 0x00F5, 0x00D5, 0x00B5, 0x00FE, 0x00DE, 0x00DA, 0x00DB, 0x00D9, 0x00FD, 0x00DD, 0x00AF, 0x00B4,
+       0x00AD, 0x00B1, 0x2017, 0x00BE, 0x00B6, 0x00A7, 0x00F7, 0x00B8, 0x00B0, 0x00A8, 0x00B7, 0x00B9, 0x00B3, 0x00B2, 0x25A0, 0x00A0
 };
 
 #elif _CODE_PAGE == 852
 #define _TBLDEF 1
 static
 const WCHAR Tbl[] = {  /*  CP852(0x80-0xFF) to Unicode conversion table */
-       0x00C7, 0x00FC, 0x00E9, 0x00E2, 0x00E4, 0x016F, 0x0107, 0x00E7,
-       0x0142, 0x00EB, 0x0150, 0x0151, 0x00EE, 0x0179, 0x00C4, 0x0106,
-       0x00C9, 0x0139, 0x013A, 0x00F4, 0x00F6, 0x013D, 0x013E, 0x015A,
-       0x015B, 0x00D6, 0x00DC, 0x0164, 0x0165, 0x0141, 0x00D7, 0x010D,
-       0x00E1, 0x00ED, 0x00F3, 0x00FA, 0x0104, 0x0105, 0x017D, 0x017E,
-       0x0118, 0x0119, 0x00AC, 0x017A, 0x010C, 0x015F, 0x00AB, 0x00BB,
-       0x2591, 0x2592, 0x2593, 0x2502, 0x2524, 0x00C1, 0x00C2, 0x011A,
-       0x015E, 0x2563, 0x2551, 0x2557, 0x255D, 0x017B, 0x017C, 0x2510,
-       0x2514, 0x2534, 0x252C, 0x251C, 0x2500, 0x253C, 0x0102, 0x0103,
-       0x255A, 0x2554, 0x2569, 0x2566, 0x2560, 0x2550, 0x256C, 0x00A4,
-       0x0111, 0x0110, 0x010E, 0x00CB, 0x010F, 0x0147, 0x00CD, 0x00CE,
-       0x011B, 0x2518, 0x250C, 0x2588, 0x2584, 0x0162, 0x016E, 0x2580,
-       0x00D3, 0x00DF, 0x00D4, 0x0143, 0x0144, 0x0148, 0x0160, 0x0161,
-       0x0154, 0x00DA, 0x0155, 0x0170, 0x00FD, 0x00DD, 0x0163, 0x00B4,
-       0x00AD, 0x02DD, 0x02DB, 0x02C7, 0x02D8, 0x00A7, 0x00F7, 0x00B8,
-       0x00B0, 0x00A8, 0x02D9, 0x0171, 0x0158, 0x0159, 0x25A0, 0x00A0
+       0x00C7, 0x00FC, 0x00E9, 0x00E2, 0x00E4, 0x016F, 0x0107, 0x00E7, 0x0142, 0x00EB, 0x0150, 0x0151, 0x00EE, 0x0179, 0x00C4, 0x0106,
+       0x00C9, 0x0139, 0x013A, 0x00F4, 0x00F6, 0x013D, 0x013E, 0x015A, 0x015B, 0x00D6, 0x00DC, 0x0164, 0x0165, 0x0141, 0x00D7, 0x010D,
+       0x00E1, 0x00ED, 0x00F3, 0x00FA, 0x0104, 0x0105, 0x017D, 0x017E, 0x0118, 0x0119, 0x00AC, 0x017A, 0x010C, 0x015F, 0x00AB, 0x00BB,
+       0x2591, 0x2592, 0x2593, 0x2502, 0x2524, 0x00C1, 0x00C2, 0x011A, 0x015E, 0x2563, 0x2551, 0x2557, 0x255D, 0x017B, 0x017C, 0x2510,
+       0x2514, 0x2534, 0x252C, 0x251C, 0x2500, 0x253C, 0x0102, 0x0103, 0x255A, 0x2554, 0x2569, 0x2566, 0x2560, 0x2550, 0x256C, 0x00A4,
+       0x0111, 0x0110, 0x010E, 0x00CB, 0x010F, 0x0147, 0x00CD, 0x00CE, 0x011B, 0x2518, 0x250C, 0x2588, 0x2584, 0x0162, 0x016E, 0x2580,
+       0x00D3, 0x00DF, 0x00D4, 0x0143, 0x0144, 0x0148, 0x0160, 0x0161, 0x0154, 0x00DA, 0x0155, 0x0170, 0x00FD, 0x00DD, 0x0163, 0x00B4,
+       0x00AD, 0x02DD, 0x02DB, 0x02C7, 0x02D8, 0x00A7, 0x00F7, 0x00B8, 0x00B0, 0x00A8, 0x02D9, 0x0171, 0x0158, 0x0159, 0x25A0, 0x00A0
 };
 
 #elif _CODE_PAGE == 855
 #define _TBLDEF 1
 static
 const WCHAR Tbl[] = {  /*  CP855(0x80-0xFF) to Unicode conversion table */
-       0x0452, 0x0402, 0x0453, 0x0403, 0x0451, 0x0401, 0x0454, 0x0404,
-       0x0455, 0x0405, 0x0456, 0x0406, 0x0457, 0x0407, 0x0458, 0x0408,
-       0x0459, 0x0409, 0x045A, 0x040A, 0x045B, 0x040B, 0x045C, 0x040C,
-       0x045E, 0x040E, 0x045F, 0x040F, 0x044E, 0x042E, 0x044A, 0x042A,
-       0x0430, 0x0410, 0x0431, 0x0411, 0x0446, 0x0426, 0x0434, 0x0414,
-       0x0435, 0x0415, 0x0444, 0x0424, 0x0433, 0x0413, 0x00AB, 0x00BB,
-       0x2591, 0x2592, 0x2593, 0x2502, 0x2524, 0x0445, 0x0425, 0x0438,
-       0x0418, 0x2563, 0x2551, 0x2557, 0x255D, 0x0439, 0x0419, 0x2510,
-       0x2514, 0x2534, 0x252C, 0x251C, 0x2500, 0x253C, 0x043A, 0x041A,
-       0x255A, 0x2554, 0x2569, 0x2566, 0x2560, 0x2550, 0x256C, 0x00A4,
-       0x043B, 0x041B, 0x043C, 0x041C, 0x043D, 0x041D, 0x043E, 0x041E,
-       0x043F, 0x2518, 0x250C, 0x2588, 0x2584, 0x041F, 0x044F, 0x2580,
-       0x042F, 0x0440, 0x0420, 0x0441, 0x0421, 0x0442, 0x0422, 0x0443,
-       0x0423, 0x0436, 0x0416, 0x0432, 0x0412, 0x044C, 0x042C, 0x2116,
-       0x00AD, 0x044B, 0x042B, 0x0437, 0x0417, 0x0448, 0x0428, 0x044D,
-       0x042D, 0x0449, 0x0429, 0x0447, 0x0427, 0x00A7, 0x25A0, 0x00A0
+       0x0452, 0x0402, 0x0453, 0x0403, 0x0451, 0x0401, 0x0454, 0x0404, 0x0455, 0x0405, 0x0456, 0x0406, 0x0457, 0x0407, 0x0458, 0x0408,
+       0x0459, 0x0409, 0x045A, 0x040A, 0x045B, 0x040B, 0x045C, 0x040C, 0x045E, 0x040E, 0x045F, 0x040F, 0x044E, 0x042E, 0x044A, 0x042A,
+       0x0430, 0x0410, 0x0431, 0x0411, 0x0446, 0x0426, 0x0434, 0x0414, 0x0435, 0x0415, 0x0444, 0x0424, 0x0433, 0x0413, 0x00AB, 0x00BB,
+       0x2591, 0x2592, 0x2593, 0x2502, 0x2524, 0x0445, 0x0425, 0x0438, 0x0418, 0x2563, 0x2551, 0x2557, 0x255D, 0x0439, 0x0419, 0x2510,
+       0x2514, 0x2534, 0x252C, 0x251C, 0x2500, 0x253C, 0x043A, 0x041A, 0x255A, 0x2554, 0x2569, 0x2566, 0x2560, 0x2550, 0x256C, 0x00A4,
+       0x043B, 0x041B, 0x043C, 0x041C, 0x043D, 0x041D, 0x043E, 0x041E, 0x043F, 0x2518, 0x250C, 0x2588, 0x2584, 0x041F, 0x044F, 0x2580,
+       0x042F, 0x0440, 0x0420, 0x0441, 0x0421, 0x0442, 0x0422, 0x0443, 0x0423, 0x0436, 0x0416, 0x0432, 0x0412, 0x044C, 0x042C, 0x2116,
+       0x00AD, 0x044B, 0x042B, 0x0437, 0x0417, 0x0448, 0x0428, 0x044D, 0x042D, 0x0449, 0x0429, 0x0447, 0x0427, 0x00A7, 0x25A0, 0x00A0
 };
 
 #elif _CODE_PAGE == 857
 #define _TBLDEF 1
 static
 const WCHAR Tbl[] = {  /*  CP857(0x80-0xFF) to Unicode conversion table */
-       0x00C7, 0x00FC, 0x00E9, 0x00E2, 0x00E4, 0x00E0, 0x00E5, 0x00E7,
-       0x00EA, 0x00EB, 0x00E8, 0x00EF, 0x00EE, 0x0131, 0x00C4, 0x00C5,
-       0x00C9, 0x00E6, 0x00C6, 0x00F4, 0x00F6, 0x00F2, 0x00FB, 0x00F9,
-       0x0130, 0x00D6, 0x00DC, 0x00F8, 0x00A3, 0x00D8, 0x015E, 0x015F,
-       0x00E1, 0x00ED, 0x00F3, 0x00FA, 0x00F1, 0x00D1, 0x011E, 0x011F,
-       0x00BF, 0x00AE, 0x00AC, 0x00BD, 0x00BC, 0x00A1, 0x00AB, 0x00BB,
-       0x2591, 0x2592, 0x2593, 0x2502, 0x2524, 0x00C1, 0x00C2, 0x00C0,
-       0x00A9, 0x2563, 0x2551, 0x2557, 0x255D, 0x00A2, 0x00A5, 0x2510,
-       0x2514, 0x2534, 0x252C, 0x251C, 0x2500, 0x253C, 0x00E3, 0x00C3,
-       0x255A, 0x2554, 0x2569, 0x2566, 0x2560, 0x2550, 0x256C, 0x00A4,
-       0x00BA, 0x00AA, 0x00CA, 0x00CB, 0x00C8, 0x0000, 0x00CD, 0x00CE,
-       0x00CF, 0x2518, 0x250C, 0x2588, 0x2584, 0x00A6, 0x00CC, 0x2580,
-       0x00D3, 0x00DF, 0x00D4, 0x00D2, 0x00F5, 0x00D5, 0x00B5, 0x0000,
-       0x00D7, 0x00DA, 0x00DB, 0x00D9, 0x00EC, 0x00FF, 0x00AF, 0x00B4,
-       0x00AD, 0x00B1, 0x0000, 0x00BE, 0x00B6, 0x00A7, 0x00F7, 0x00B8,
-       0x00B0, 0x00A8, 0x00B7, 0x00B9, 0x00B3, 0x00B2, 0x25A0, 0x00A0
-};
-
-#elif _CODE_PAGE == 858
-#define _TBLDEF 1
-static
-const WCHAR Tbl[] = {  /*  CP858(0x80-0xFF) to Unicode conversion table */
-       0x00C7, 0x00FC, 0x00E9, 0x00E2, 0x00E4, 0x00E0, 0x00E5, 0x00E7,
-       0x00EA, 0x00EB, 0x00E8, 0x00EF, 0x00EE, 0x00EC, 0x00C4, 0x00C5,
-       0x00C9, 0x00E6, 0x00C6, 0x00F4, 0x00F6, 0x00F2, 0x00FB, 0x00F9,
-       0x00FF, 0x00D6, 0x00DC, 0x00F8, 0x00A3, 0x00D8, 0x00D7, 0x0192,
-       0x00E1, 0x00ED, 0x00F3, 0x00FA, 0x00F1, 0x00D1, 0x00AA, 0x00BA,
-       0x00BF, 0x00AE, 0x00AC, 0x00BD, 0x00BC, 0x00A1, 0x00AB, 0x00BB,
-       0x2591, 0x2592, 0x2593, 0x2502, 0x2524, 0x00C1, 0x00C2, 0x00C0,
-       0x00A9, 0x2563, 0x2551, 0x2557, 0x2550, 0x00A2, 0x00A5, 0x2510,
-       0x2514, 0x2534, 0x252C, 0x251C, 0x2500, 0x253C, 0x00E3, 0x00C3,
-       0x255A, 0x2554, 0x2569, 0x2566, 0x2560, 0x2550, 0x256C, 0x00A4,
-       0x00F0, 0x00D0, 0x00CA, 0x00CB, 0x00C8, 0x20AC, 0x00CD, 0x00CE,
-       0x00CF, 0x2518, 0x250C, 0x2588, 0x2584, 0x00C6, 0x00CC, 0x2580,
-       0x00D3, 0x00DF, 0x00D4, 0x00D2, 0x00F5, 0x00D5, 0x00B5, 0x00FE,
-       0x00DE, 0x00DA, 0x00DB, 0x00D9, 0x00FD, 0x00DD, 0x00AF, 0x00B4,
-       0x00AD, 0x00B1, 0x2017, 0x00BE, 0x00B6, 0x00A7, 0x00F7, 0x00B8,
-       0x00B0, 0x00A8, 0x00B7, 0x00B9, 0x00B3, 0x00B2, 0x25A0, 0x00A0
-};
-
-#elif _CODE_PAGE == 862
-#define _TBLDEF 1
-static
-const WCHAR Tbl[] = {  /*  CP862(0x80-0xFF) to Unicode conversion table */
-       0x05D0, 0x05D1, 0x05D2, 0x05D3, 0x05D4, 0x05D5, 0x05D6, 0x05D7,
-       0x05D8, 0x05D9, 0x05DA, 0x05DB, 0x05DC, 0x05DD, 0x05DE, 0x05DF,
-       0x05E0, 0x05E1, 0x05E2, 0x05E3, 0x05E4, 0x05E5, 0x05E6, 0x05E7,
-       0x05E8, 0x05E9, 0x05EA, 0x00A2, 0x00A3, 0x00A5, 0x20A7, 0x0192,
-       0x00E1, 0x00ED, 0x00F3, 0x00FA, 0x00F1, 0x00D1, 0x00AA, 0x00BA,
-       0x00BF, 0x2310, 0x00AC, 0x00BD, 0x00BC, 0x00A1, 0x00AB, 0x00BB,
-       0x2591, 0x2592, 0x2593, 0x2502, 0x2524, 0x2561, 0x2562, 0x2556,
-       0x2555, 0x2563, 0x2551, 0x2557, 0x255D, 0x255C, 0x255B, 0x2510,
-       0x2514, 0x2534, 0x252C, 0x251C, 0x2500, 0x253C, 0x255E, 0x255F,
-       0x255A, 0x2554, 0x2569, 0x2566, 0x2560, 0x2550, 0x256C, 0x2567,
-       0x2568, 0x2564, 0x2565, 0x2559, 0x2558, 0x2552, 0x2553, 0x256B,
-       0x256A, 0x2518, 0x250C, 0x2588, 0x2584, 0x258C, 0x2590, 0x2580,
-       0x03B1, 0x00DF, 0x0393, 0x03C0, 0x03A3, 0x03C3, 0x00B5, 0x03C4,
-       0x03A6, 0x0398, 0x03A9, 0x03B4, 0x221E, 0x03C6, 0x03B5, 0x2229,
-       0x2261, 0x00B1, 0x2265, 0x2264, 0x2320, 0x2321, 0x00F7, 0x2248,
-       0x00B0, 0x2219, 0x00B7, 0x221A, 0x207F, 0x00B2, 0x25A0, 0x00A0
-};
-
-#elif _CODE_PAGE == 866
-#define _TBLDEF 1
-static
-const WCHAR Tbl[] = {  /*  CP866(0x80-0xFF) to Unicode conversion table */
-       0x0410, 0x0411, 0x0412, 0x0413, 0x0414, 0x0415, 0x0416, 0x0417,
-       0x0418, 0x0419, 0x041A, 0x041B, 0x041C, 0x041D, 0x041E, 0x041F,
-       0x0420, 0x0421, 0x0422, 0x0423, 0x0424, 0x0425, 0x0426, 0x0427,
-       0x0428, 0x0429, 0x042A, 0x042B, 0x042C, 0x042D, 0x042E, 0x042F,
-       0x0430, 0x0431, 0x0432, 0x0433, 0x0434, 0x0435, 0x0436, 0x0437,
-       0x0438, 0x0439, 0x043A, 0x043B, 0x043C, 0x043D, 0x043E, 0x043F,
-       0x2591, 0x2592, 0x2593, 0x2502, 0x2524, 0x2561, 0x2562, 0x2556,
-       0x2555, 0x2563, 0x2551, 0x2557, 0x255D, 0x255C, 0x255B, 0x2510,
-       0x2514, 0x2534, 0x252C, 0x251C, 0x2500, 0x253C, 0x255E, 0x255F,
-       0x255A, 0x2554, 0x2569, 0x2566, 0x2560, 0x2550, 0x256C, 0x2567,
-       0x2568, 0x2564, 0x2565, 0x2559, 0x2558, 0x2552, 0x2553, 0x256B,
-       0x256A, 0x2518, 0x250C, 0x2588, 0x2584, 0x258C, 0x2590, 0x2580,
-       0x0440, 0x0441, 0x0442, 0x0443, 0x0444, 0x0445, 0x0446, 0x0447,
-       0x0448, 0x0449, 0x044A, 0x044B, 0x044C, 0x044D, 0x044E, 0x044F,
-       0x0401, 0x0451, 0x0404, 0x0454, 0x0407, 0x0457, 0x040E, 0x045E,
-       0x00B0, 0x2219, 0x00B7, 0x221A, 0x2116, 0x00A4, 0x25A0, 0x00A0
+       0x00C7, 0x00FC, 0x00E9, 0x00E2, 0x00E4, 0x00E0, 0x00E5, 0x00E7, 0x00EA, 0x00EB, 0x00E8, 0x00EF, 0x00EE, 0x0131, 0x00C4, 0x00C5,
+       0x00C9, 0x00E6, 0x00C6, 0x00F4, 0x00F6, 0x00F2, 0x00FB, 0x00F9, 0x0130, 0x00D6, 0x00DC, 0x00F8, 0x00A3, 0x00D8, 0x015E, 0x015F,
+       0x00E1, 0x00ED, 0x00F3, 0x00FA, 0x00F1, 0x00D1, 0x011E, 0x011F, 0x00BF, 0x00AE, 0x00AC, 0x00BD, 0x00BC, 0x00A1, 0x00AB, 0x00BB,
+       0x2591, 0x2592, 0x2593, 0x2502, 0x2524, 0x00C1, 0x00C2, 0x00C0, 0x00A9, 0x2563, 0x2551, 0x2557, 0x255D, 0x00A2, 0x00A5, 0x2510,
+       0x2514, 0x2534, 0x252C, 0x251C, 0x2500, 0x253C, 0x00E3, 0x00C3, 0x255A, 0x2554, 0x2569, 0x2566, 0x2560, 0x2550, 0x256C, 0x00A4,
+       0x00BA, 0x00AA, 0x00CA, 0x00CB, 0x00C8, 0x0000, 0x00CD, 0x00CE, 0x00CF, 0x2518, 0x250C, 0x2588, 0x2584, 0x00A6, 0x00CC, 0x2580,
+       0x00D3, 0x00DF, 0x00D4, 0x00D2, 0x00F5, 0x00D5, 0x00B5, 0x0000, 0x00D7, 0x00DA, 0x00DB, 0x00D9, 0x00EC, 0x00FF, 0x00AF, 0x00B4,
+       0x00AD, 0x00B1, 0x0000, 0x00BE, 0x00B6, 0x00A7, 0x00F7, 0x00B8, 0x00B0, 0x00A8, 0x00B7, 0x00B9, 0x00B3, 0x00B2, 0x25A0, 0x00A0
 };
 
-#elif _CODE_PAGE == 874
+#elif _CODE_PAGE == 860
 #define _TBLDEF 1
 static
-const WCHAR Tbl[] = {  /*  CP874(0x80-0xFF) to Unicode conversion table */
-       0x20AC, 0x0000, 0x0000, 0x0000, 0x0000, 0x2026, 0x0000, 0x0000,
-       0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
-       0x0000, 0x2018, 0x2019, 0x201C, 0x201D, 0x2022, 0x2013, 0x2014,
-       0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
-       0x00A0, 0x0E01, 0x0E02, 0x0E03, 0x0E04, 0x0E05, 0x0E06, 0x0E07,
-       0x0E08, 0x0E09, 0x0E0A, 0x0E0B, 0x0E0C, 0x0E0D, 0x0E0E, 0x0E0F,
-       0x0E10, 0x0E11, 0x0E12, 0x0E13, 0x0E14, 0x0E15, 0x0E16, 0x0E17,
-       0x0E18, 0x0E19, 0x0E1A, 0x0E1B, 0x0E1C, 0x0E1D, 0x0E1E, 0x0E1F,
-       0x0E20, 0x0E21, 0x0E22, 0x0E23, 0x0E24, 0x0E25, 0x0E26, 0x0E27,
-       0x0E28, 0x0E29, 0x0E2A, 0x0E2B, 0x0E2C, 0x0E2D, 0x0E2E, 0x0E2F,
-       0x0E30, 0x0E31, 0x0E32, 0x0E33, 0x0E34, 0x0E35, 0x0E36, 0x0E37,
-       0x0E38, 0x0E39, 0x0E3A, 0x0000, 0x0000, 0x0000, 0x0000, 0x0E3F,
-       0x0E40, 0x0E41, 0x0E42, 0x0E43, 0x0E44, 0x0E45, 0x0E46, 0x0E47,
-       0x0E48, 0x0E49, 0x0E4A, 0x0E4B, 0x0E4C, 0x0E4D, 0x0E4E, 0x0E4F,
-       0x0E50, 0x0E51, 0x0E52, 0x0E53, 0x0E54, 0x0E55, 0x0E56, 0x0E57,
-       0x0E58, 0x0E59, 0x0E5A, 0x0E5B, 0x0000, 0x0000, 0x0000, 0x0000
+const WCHAR Tbl[] = {  /*  CP860(0x80-0xFF) to Unicode conversion table */
+       0x00C7, 0x00FC, 0x00E9, 0x00E2, 0x00E3, 0x00E0, 0x00C1, 0x00E7, 0x00EA, 0x00CA, 0x00E8, 0x00CD, 0x00D4, 0x00EC, 0x00C3, 0x00C2,
+       0x00C9, 0x00C0, 0x00C8, 0x00F4, 0x00F5, 0x00F2, 0x00DA, 0x00F9, 0x00CC, 0x00D5, 0x00DC, 0x00A2, 0x00A3, 0x00D9, 0x20A7, 0x00D3,
+       0x00E1, 0x00ED, 0x00F3, 0x00FA, 0x00F1, 0x00D1, 0x00AA, 0x00BA, 0x00BF, 0x00D2, 0x00AC, 0x00BD, 0x00BC, 0x00A1, 0x00AB, 0x00BB,
+       0x2591, 0x2592, 0x2593, 0x2502, 0x2524, 0x2561, 0x2562, 0x2556, 0x2555, 0x2563, 0x2551, 0x2557, 0x255D, 0x255C, 0x2558, 0x2510,
+       0x2514, 0x2534, 0x252C, 0x251C, 0x2500, 0x253C, 0x255E, 0x255F, 0x255A, 0x2554, 0x2569, 0x2566, 0x2560, 0x2550, 0x256C, 0x2567,
+       0x2568, 0x2564, 0x2565, 0x2559, 0x2558, 0x2552, 0x2553, 0x256B, 0x256A, 0x2518, 0x250C, 0x2588, 0x2584, 0x258C, 0x2590, 0x2580,
+       0x03B1, 0x00DF, 0x0393, 0x03C0, 0x03A3, 0x03C3, 0x00B5, 0x03C4, 0x03A6, 0x0398, 0x03A9, 0x03B4, 0x221E, 0x03C6, 0x03B5, 0x2229,
+       0x2261, 0x00B1, 0x2265, 0x2264, 0x2320, 0x2321, 0x00F7, 0x2248, 0x00B0, 0x2219, 0x00B7, 0x221A, 0x207F, 0x00B2, 0x25A0, 0x00A0
 };
 
-#elif _CODE_PAGE == 1250
+#elif _CODE_PAGE == 861
 #define _TBLDEF 1
 static
-const WCHAR Tbl[] = {  /*  CP1250(0x80-0xFF) to Unicode conversion table */
-       0x20AC, 0x0000, 0x201A, 0x0000, 0x201E, 0x2026, 0x2020, 0x2021,
-       0x0000, 0x2030, 0x0160, 0x2039, 0x015A, 0x0164, 0x017D, 0x0179,
-       0x0000, 0x2018, 0x2019, 0x201C, 0x201D, 0x2022, 0x2013, 0x2014,
-       0x0000, 0x2122, 0x0161, 0x203A, 0x015B, 0x0165, 0x017E, 0x017A,
-       0x00A0, 0x02C7, 0x02D8, 0x0141, 0x00A4, 0x0104, 0x00A6, 0x00A7,
-       0x00A8, 0x00A9, 0x015E, 0x00AB, 0x00AC, 0x00AD, 0x00AE, 0x017B,
-       0x00B0, 0x00B1, 0x02DB, 0x0142, 0x00B4, 0x00B5, 0x00B6, 0x00B7,
-       0x00B8, 0x0105, 0x015F, 0x00BB, 0x013D, 0x02DD, 0x013E, 0x017C,
-       0x0154, 0x00C1, 0x00C2, 0x0102, 0x00C4, 0x0139, 0x0106, 0x00C7,
-       0x010C, 0x00C9, 0x0118, 0x00CB, 0x011A, 0x00CD, 0x00CE, 0x010E,
-       0x0110, 0x0143, 0x0147, 0x00D3, 0x00D4, 0x0150, 0x00D6, 0x00D7,
-       0x0158, 0x016E, 0x00DA, 0x0170, 0x00DC, 0x00DD, 0x0162, 0x00DF,
-       0x0155, 0x00E1, 0x00E2, 0x0103, 0x00E4, 0x013A, 0x0107, 0x00E7,
-       0x010D, 0x00E9, 0x0119, 0x00EB, 0x011B, 0x00ED, 0x00EE, 0x010F,
-       0x0111, 0x0144, 0x0148, 0x00F3, 0x00F4, 0x0151, 0x00F6, 0x00F7,
-       0x0159, 0x016F, 0x00FA, 0x0171, 0x00FC, 0x00FD, 0x0163, 0x02D9
+const WCHAR Tbl[] = {  /*  CP861(0x80-0xFF) to Unicode conversion table */
+       0x00C7, 0x00FC, 0x00E9, 0x00E2, 0x00E4, 0x00E0, 0x00E6, 0x00E7, 0x00EA, 0x00EB, 0x00E8, 0x00D0, 0x00F0, 0x00DE, 0x00C4, 0x00C5,
+       0x00C9, 0x00E6, 0x00C6, 0x00F4, 0x00F6, 0x00FE, 0x00FB, 0x00DD, 0x00FD, 0x00D6, 0x00DC, 0x00F8, 0x00A3, 0x00D8, 0x20A7, 0x0192,
+       0x00E1, 0x00ED, 0x00F3, 0x00FA, 0x00C1, 0x00CD, 0x00D3, 0x00DA, 0x00BF, 0x2310, 0x00AC, 0x00BD, 0x00BC, 0x00A1, 0x00AB, 0x00BB,
+       0x2591, 0x2592, 0x2593, 0x2502, 0x2524, 0x2561, 0x2562, 0x2556, 0x2555, 0x2563, 0x2551, 0x2557, 0x255D, 0x255C, 0x255B, 0x2510,
+       0x2514, 0x2534, 0x252C, 0x251C, 0x2500, 0x253C, 0x255E, 0x255F, 0x255A, 0x2554, 0x2569, 0x2566, 0x2560, 0x2550, 0x256C, 0x2567,
+       0x2568, 0x2564, 0x2565, 0x2559, 0x2558, 0x2552, 0x2553, 0x256B, 0x256A, 0x2518, 0x250C, 0x2588, 0x2584, 0x258C, 0x2590, 0x2580,
+       0x03B1, 0x00DF, 0x0393, 0x03C0, 0x03A3, 0x03C3, 0x00B5, 0x03C4, 0x03A6, 0x0398, 0x03A9, 0x03B4, 0x221E, 0x03C6, 0x03B5, 0x2229,
+       0x2261, 0x00B1, 0x2265, 0x2264, 0x2320, 0x2321, 0x00F7, 0x2248, 0x00B0, 0x2219, 0x00B7, 0x221A, 0x207F, 0x00B2, 0x25A0, 0x00A0
 };
 
-#elif _CODE_PAGE == 1251
-#define _TBLDEF 1
-static
-const WCHAR Tbl[] = {  /*  CP1251(0x80-0xFF) to Unicode conversion table */
-       0x0402, 0x0403, 0x201A, 0x0453, 0x201E, 0x2026, 0x2020, 0x2021,
-       0x20AC, 0x2030, 0x0409, 0x2039, 0x040A, 0x040C, 0x040B, 0x040F,
-       0x0452, 0x2018, 0x2019, 0x201C, 0x201D, 0x2022, 0x2013, 0x2014,
-       0x0000, 0x2111, 0x0459, 0x203A, 0x045A, 0x045C, 0x045B, 0x045F,
-       0x00A0, 0x040E, 0x045E, 0x0408, 0x00A4, 0x0490, 0x00A6, 0x00A7,
-       0x0401, 0x00A9, 0x0404, 0x00AB, 0x00AC, 0x00AD, 0x00AE, 0x0407,
-       0x00B0, 0x00B1, 0x0406, 0x0456, 0x0491, 0x00B5, 0x00B6, 0x00B7,
-       0x0451, 0x2116, 0x0454, 0x00BB, 0x0458, 0x0405, 0x0455, 0x0457,
-       0x0410, 0x0411, 0x0412, 0x0413, 0x0414, 0x0415, 0x0416, 0x0417,
-       0x0418, 0x0419, 0x041A, 0x041B, 0x041C, 0x041D, 0x041E, 0x041F,
-       0x0420, 0x0421, 0x0422, 0x0423, 0x0424, 0x0425, 0x0426, 0x0427,
-       0x0428, 0x0429, 0x042A, 0x042B, 0x042C, 0x042D, 0x042E, 0x042F,
-       0x0430, 0x0431, 0x0432, 0x0433, 0x0434, 0x0435, 0x0436, 0x0437,
-       0x0438, 0x0439, 0x043A, 0x043B, 0x043C, 0x043D, 0x043E, 0x043F,
-       0x0440, 0x0441, 0x0442, 0x0443, 0x0444, 0x0445, 0x0446, 0x0447,
-       0x0448, 0x0449, 0x044A, 0x044B, 0x044C, 0x044D, 0x044E, 0x044F
-};
-
-#elif _CODE_PAGE == 1252
+#elif _CODE_PAGE == 862
 #define _TBLDEF 1
 static
-const WCHAR Tbl[] = {  /*  CP1252(0x80-0xFF) to Unicode conversion table */
-       0x20AC, 0x0000, 0x201A, 0x0192, 0x201E, 0x2026, 0x2020, 0x2021,
-       0x02C6, 0x2030, 0x0160, 0x2039, 0x0152, 0x0000, 0x017D, 0x0000,
-       0x0000, 0x2018, 0x2019, 0x201C, 0x201D, 0x2022, 0x2013, 0x2014,
-       0x02DC, 0x2122, 0x0161, 0x203A, 0x0153, 0x0000, 0x017E, 0x0178,
-       0x00A0, 0x00A1, 0x00A2, 0x00A3, 0x00A4, 0x00A5, 0x00A6, 0x00A7,
-       0x00A8, 0x00A9, 0x00AA, 0x00AB, 0x00AC, 0x00AD, 0x00AE, 0x00AF,
-       0x00B0, 0x00B1, 0x00B2, 0x00B3, 0x00B4, 0x00B5, 0x00B6, 0x00B7,
-       0x00B8, 0x00B9, 0x00BA, 0x00BB, 0x00BC, 0x00BD, 0x00BE, 0x00BF,
-       0x00C0, 0x00C1, 0x00C2, 0x00C3, 0x00C4, 0x00C5, 0x00C6, 0x00C7,
-       0x00C8, 0x00C9, 0x00CA, 0x00CB, 0x00CC, 0x00CD, 0x00CE, 0x00CF,
-       0x00D0, 0x00D1, 0x00D2, 0x00D3, 0x00D4, 0x00D5, 0x00D6, 0x00D7,
-       0x00D8, 0x00D9, 0x00DA, 0x00DB, 0x00DC, 0x00DD, 0x00DE, 0x00DF,
-       0x00E0, 0x00E1, 0x00E2, 0x00E3, 0x00E4, 0x00E5, 0x00E6, 0x00E7,
-       0x00E8, 0x00E9, 0x00EA, 0x00EB, 0x00EC, 0x00ED, 0x00EE, 0x00EF,
-       0x00F0, 0x00F1, 0x00F2, 0x00F3, 0x00F4, 0x00F5, 0x00F6, 0x00F7,
-       0x00F8, 0x00F9, 0x00FA, 0x00FB, 0x00FC, 0x00FD, 0x00FE, 0x00FF
+const WCHAR Tbl[] = {  /*  CP862(0x80-0xFF) to Unicode conversion table */
+       0x05D0, 0x05D1, 0x05D2, 0x05D3, 0x05D4, 0x05D5, 0x05D6, 0x05D7, 0x05D8, 0x05D9, 0x05DA, 0x05DB, 0x05DC, 0x05DD, 0x05DE, 0x05DF,
+       0x05E0, 0x05E1, 0x05E2, 0x05E3, 0x05E4, 0x05E5, 0x05E6, 0x05E7, 0x05E8, 0x05E9, 0x05EA, 0x00A2, 0x00A3, 0x00A5, 0x20A7, 0x0192,
+       0x00E1, 0x00ED, 0x00F3, 0x00FA, 0x00F1, 0x00D1, 0x00AA, 0x00BA, 0x00BF, 0x2310, 0x00AC, 0x00BD, 0x00BC, 0x00A1, 0x00AB, 0x00BB,
+       0x2591, 0x2592, 0x2593, 0x2502, 0x2524, 0x2561, 0x2562, 0x2556, 0x2555, 0x2563, 0x2551, 0x2557, 0x255D, 0x255C, 0x255B, 0x2510,
+       0x2514, 0x2534, 0x252C, 0x251C, 0x2500, 0x253C, 0x255E, 0x255F, 0x255A, 0x2554, 0x2569, 0x2566, 0x2560, 0x2550, 0x256C, 0x2567,
+       0x2568, 0x2564, 0x2565, 0x2559, 0x2558, 0x2552, 0x2553, 0x256B, 0x256A, 0x2518, 0x250C, 0x2588, 0x2584, 0x258C, 0x2590, 0x2580,
+       0x03B1, 0x00DF, 0x0393, 0x03C0, 0x03A3, 0x03C3, 0x00B5, 0x03C4, 0x03A6, 0x0398, 0x03A9, 0x03B4, 0x221E, 0x03C6, 0x03B5, 0x2229,
+       0x2261, 0x00B1, 0x2265, 0x2264, 0x2320, 0x2321, 0x00F7, 0x2248, 0x00B0, 0x2219, 0x00B7, 0x221A, 0x207F, 0x00B2, 0x25A0, 0x00A0
 };
 
-#elif _CODE_PAGE == 1253
+#elif _CODE_PAGE == 863
 #define _TBLDEF 1
 static
-const WCHAR Tbl[] = {  /*  CP1253(0x80-0xFF) to Unicode conversion table */
-       0x20AC, 0x0000, 0x201A, 0x0192, 0x201E, 0x2026, 0x2020, 0x2021,
-       0x0000, 0x2030, 0x0000, 0x2039, 0x000C, 0x0000, 0x0000, 0x0000,
-       0x0000, 0x2018, 0x2019, 0x201C, 0x201D, 0x2022, 0x2013, 0x2014,
-       0x0000, 0x2122, 0x0000, 0x203A, 0x0000, 0x0000, 0x0000, 0x0000,
-       0x00A0, 0x0385, 0x0386, 0x00A3, 0x00A4, 0x00A5, 0x00A6, 0x00A7,
-       0x00A8, 0x00A9, 0x0000, 0x00AB, 0x00AC, 0x00AD, 0x00AE, 0x2015,
-       0x00B0, 0x00B1, 0x00B2, 0x00B3, 0x0384, 0x00B5, 0x00B6, 0x00B7,
-       0x0388, 0x0389, 0x038A, 0x00BB, 0x038C, 0x00BD, 0x038E, 0x038F,
-       0x0390, 0x0391, 0x0392, 0x0393, 0x0394, 0x0395, 0x0396, 0x0397,
-       0x0398, 0x0399, 0x039A, 0x039B, 0x039C, 0x039D, 0x039E, 0x039F,
-       0x03A0, 0x03A1, 0x0000, 0x03A3, 0x03A4, 0x03A5, 0x03A6, 0x03A7,
-       0x03A8, 0x03A9, 0x03AA, 0x03AD, 0x03AC, 0x03AD, 0x03AE, 0x03AF,
-       0x03B0, 0x03B1, 0x03B2, 0x03B3, 0x03B4, 0x03B5, 0x03B6, 0x03B7,
-       0x03B8, 0x03B9, 0x03BA, 0x03BB, 0x03BC, 0x03BD, 0x03BE, 0x03BF,
-       0x03C0, 0x03C1, 0x03C2, 0x03C3, 0x03C4, 0x03C5, 0x03C6, 0x03C7,
-       0x03C8, 0x03C9, 0x03CA, 0x03CB, 0x03CC, 0x03CD, 0x03CE, 0x0000
+const WCHAR Tbl[] = {  /*  CP863(0x80-0xFF) to Unicode conversion table */
+       0x00C7, 0x00FC, 0x00E9, 0x00E2, 0x00C2, 0x00E0, 0x00B6, 0x00E7, 0x00EA, 0x00EB, 0x00E8, 0x00EF, 0x00EE, 0x00EC, 0x2017, 0x00C0,
+       0x00C9, 0x00C8, 0x00CA, 0x00F4, 0x00CB, 0x00CF, 0x00FB, 0x00F9, 0x00A4, 0x00D4, 0x00DC, 0x00A2, 0x00A3, 0x00D9, 0x00DB, 0x0192,
+       0x00A6, 0x00B4, 0x00F3, 0x00FA, 0x00A8, 0x00BB, 0x00B3, 0x00AF, 0x00CE, 0x3210, 0x00AC, 0x00BD, 0x00BC, 0x00BE, 0x00AB, 0x00BB,
+       0x2591, 0x2592, 0x2593, 0x2502, 0x2524, 0x2561, 0x2562, 0x2556, 0x2555, 0x2563, 0x2551, 0x2557, 0x255D, 0x255C, 0x255B, 0x2510,
+       0x2514, 0x2534, 0x252C, 0x251C, 0x2500, 0x253C, 0x255E, 0x255F, 0x255A, 0x2554, 0x2569, 0x2566, 0x2560, 0x2550, 0x256C, 0x2567,
+       0x2568, 0x2564, 0x2565, 0x2559, 0x2558, 0x2552, 0x2553, 0x256B, 0x256A, 0x2518, 0x250C, 0x2588, 0x2584, 0x258C, 0x2590, 0x2580,
+       0x03B1, 0x00DF, 0x0393, 0x03C0, 0x03A3, 0x03C3, 0x00B5, 0x03C4, 0x03A6, 0x0398, 0x03A9, 0x03B4, 0x221E, 0x03C6, 0x03B5, 0x2219,
+       0x2261, 0x00B1, 0x2265, 0x2264, 0x2320, 0x2321, 0x00F7, 0x2248, 0x00B0, 0x2219, 0x00B7, 0x221A, 0x207F, 0x00B2, 0x25A0, 0x00A0
 };
 
-#elif _CODE_PAGE == 1254
+#elif _CODE_PAGE == 864
 #define _TBLDEF 1
 static
-const WCHAR Tbl[] = {  /*  CP1254(0x80-0xFF) to Unicode conversion table */
-       0x20AC, 0x0000, 0x210A, 0x0192, 0x201E, 0x2026, 0x2020, 0x2021,
-       0x02C6, 0x2030, 0x0160, 0x2039, 0x0152, 0x0000, 0x0000, 0x0000,
-       0x0000, 0x2018, 0x2019, 0x201C, 0x201D, 0x2022, 0x2013, 0x2014,
-       0x02DC, 0x2122, 0x0161, 0x203A, 0x0153, 0x0000, 0x0000, 0x0178,
-       0x00A0, 0x00A1, 0x00A2, 0x00A3, 0x00A4, 0x00A5, 0x00A6, 0x00A7,
-       0x00A8, 0x00A9, 0x00AA, 0x00AB, 0x00AC, 0x00AD, 0x00AE, 0x00AF,
-       0x00B0, 0x00B1, 0x00B2, 0x00B3, 0x00B4, 0x00B5, 0x00B6, 0x00B7,
-       0x00B8, 0x00B9, 0x00BA, 0x00BB, 0x00BC, 0x00BD, 0x00BE, 0x00BF,
-       0x00C0, 0x00C1, 0x00C2, 0x00C3, 0x00C4, 0x00C5, 0x00C6, 0x00C7,
-       0x00C8, 0x00C9, 0x00CA, 0x00CB, 0x00CC, 0x00CD, 0x00CE, 0x00CF,
-       0x011E, 0x00D1, 0x00D2, 0x00D3, 0x00D4, 0x00D5, 0x00D6, 0x00D7,
-       0x00D8, 0x00D9, 0x00DA, 0x00BD, 0x00DC, 0x0130, 0x015E, 0x00DF,
-       0x00E0, 0x00E1, 0x00E2, 0x00E3, 0x00E4, 0x00E5, 0x00E6, 0x00E7,
-       0x00E8, 0x00E9, 0x00EA, 0x00EB, 0x00EC, 0x00ED, 0x00EE, 0x00EF,
-       0x011F, 0x00F1, 0x00F2, 0x00F3, 0x00F4, 0x00F5, 0x00F6, 0x00F7,
-       0x00F8, 0x00F9, 0x00FA, 0x00FB, 0x00FC, 0x0131, 0x015F, 0x00FF
+const WCHAR Tbl[] = {  /*  CP864(0x80-0xFF) to Unicode conversion table */
+       0x00B0, 0x00B7, 0x2219, 0x221A, 0x2592, 0x2500, 0x2502, 0x253C, 0x2524, 0x252C, 0x251C, 0x2534, 0x2510, 0x250C, 0x2514, 0x2518,
+       0x03B2, 0x221E, 0x03C6, 0x00B1, 0x00BD, 0x00BC, 0x2248, 0x00AB, 0x00BB, 0xFEF7, 0xFEF8, 0x0000, 0x0000, 0xFEFB, 0xFEFC, 0x0000,
+       0x00A0, 0x00AD, 0xFE82, 0x00A3, 0x00A4, 0xFE84, 0x0000, 0x20AC, 0xFE8E, 0xFE8F, 0xFE95, 0xFE99, 0x060C, 0xFE9D, 0xFEA1, 0xFEA5,
+       0x0660, 0x0661, 0x0662, 0x0663, 0x0664, 0x0665, 0x0666, 0x0667, 0x0668, 0x0669, 0xFED1, 0x061B, 0xFEB1, 0xFEB5, 0xFEB9, 0x061F,
+       0x00A2, 0xFE80, 0xFE81, 0xFE83, 0xFE85, 0xFECA, 0xFE8B, 0xFE8D, 0xFE91, 0xFE93, 0xFE97, 0xFE9B, 0xFE9F, 0xFEA3, 0xFEA7, 0xFEA9,
+       0xFEAB, 0xFEAD, 0xFEAF, 0xFEB3, 0xFEB7, 0xFEBB, 0xFEBF, 0xFEC1, 0xFEC5, 0xFECB, 0xFECF, 0x00A6, 0x00AC, 0x00F7, 0x00D7, 0xFEC9,
+       0x0640, 0xFED3, 0xFED7, 0xFEDB, 0xFEDF, 0xFEE3, 0xFEE7, 0xFEEB, 0xFEED, 0xFEEF, 0xFEF3, 0xFEBD, 0xFECC, 0xFECE, 0xFECD, 0xFEE1,
+       0xFE7D, 0x0651, 0xFEE5, 0xFEE9, 0xFEEC, 0xFEF0, 0xFEF2, 0xFED0, 0xFED5, 0xFEF5, 0xFEF6, 0xFEDD, 0xFED9, 0xFEF1, 0x25A0, 0x0000
 };
 
-#elif _CODE_PAGE == 1255
+#elif _CODE_PAGE == 865
 #define _TBLDEF 1
 static
-const WCHAR Tbl[] = {  /*  CP1255(0x80-0xFF) to Unicode conversion table */
-       0x20AC, 0x0000, 0x201A, 0x0192, 0x201E, 0x2026, 0x2020, 0x2021,
-       0x02C6, 0x2030, 0x0000, 0x2039, 0x0000, 0x0000, 0x0000, 0x0000,
-       0x0000, 0x2018, 0x2019, 0x201C, 0x201D, 0x2022, 0x2013, 0x2014,
-       0x02DC, 0x2122, 0x0000, 0x203A, 0x0000, 0x0000, 0x0000, 0x0000,
-       0x00A0, 0x00A1, 0x00A2, 0x00A3, 0x00A4, 0x00A5, 0x00A6, 0x00A7,
-       0x00A8, 0x00A9, 0x00D7, 0x00AB, 0x00AC, 0x00AD, 0x00AE, 0x00AF,
-       0x00B0, 0x00B1, 0x00B2, 0x00B3, 0x00B4, 0x00B5, 0x00B6, 0x00B7,
-       0x00B8, 0x00B9, 0x00F7, 0x00BB, 0x00BC, 0x00BD, 0x00BE, 0x00BF,
-       0x05B0, 0x05B1, 0x05B2, 0x05B3, 0x05B4, 0x05B5, 0x05B6, 0x05B7,
-       0x05B8, 0x05B9, 0x0000, 0x05BB, 0x05BC, 0x05BD, 0x05BE, 0x05BF,
-       0x05C0, 0x05C1, 0x05C2, 0x05C3, 0x05F0, 0x05F1, 0x05F2, 0x05F3,
-       0x05F4, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
-       0x05D0, 0x05D1, 0x05D2, 0x05D3, 0x05D4, 0x05D5, 0x05D6, 0x05D7,
-       0x05D8, 0x05D9, 0x05DA, 0x05DB, 0x05DC, 0x05DD, 0x05DE, 0x05DF,
-       0x05E0, 0x05E1, 0x05E2, 0x05E3, 0x05E4, 0x05E5, 0x05E6, 0x05E7,
-       0x05E8, 0x05E9, 0x05EA, 0x0000, 0x0000, 0x200E, 0x200F, 0x0000
+const WCHAR Tbl[] = {  /*  CP865(0x80-0xFF) to Unicode conversion table */
+       0x00C7, 0x00FC, 0x00E9, 0x00E2, 0x00E4, 0x00E0, 0x00E5, 0x00E7, 0x00EA, 0x00EB, 0x00E8, 0x00EF, 0x00EE, 0x00EC, 0x00C4, 0x00C5,
+       0x00C5, 0x00E6, 0x00C6, 0x00F4, 0x00F6, 0x00F2, 0x00FB, 0x00F9, 0x00FF, 0x00D6, 0x00DC, 0x00F8, 0x00A3, 0x00D8, 0x20A7, 0x0192,
+       0x00E1, 0x00ED, 0x00F3, 0x00FA, 0x00F1, 0x00D1, 0x00AA, 0x00BA, 0x00BF, 0x2310, 0x00AC, 0x00BD, 0x00BC, 0x00A1, 0x00AB, 0x00A4,
+       0x2591, 0x2592, 0x2593, 0x2502, 0x2524, 0x2561, 0x2562, 0x2556, 0x2555, 0x2563, 0x2551, 0x2557, 0x255D, 0x255C, 0x2558, 0x2510,
+       0x2514, 0x2534, 0x252C, 0x251C, 0x2500, 0x253C, 0x255E, 0x255F, 0x255A, 0x2554, 0x2569, 0x2566, 0x2560, 0x2550, 0x256C, 0x2567,
+       0x2568, 0x2564, 0x2565, 0x2559, 0x2558, 0x2552, 0x2553, 0x256B, 0x256A, 0x2518, 0x250C, 0x2588, 0x2584, 0x258C, 0x2590, 0x2580,
+       0x03B1, 0x00DF, 0x0393, 0x03C0, 0x03A3, 0x03C3, 0x00B5, 0x03C4, 0x03A6, 0x0398, 0x03A9, 0x03B4, 0x221E, 0x03C6, 0x03B5, 0x2229,
+       0x2261, 0x00B1, 0x2265, 0x2264, 0x2320, 0x2321, 0x00F7, 0x2248, 0x00B0, 0x2219, 0x00B7, 0x221A, 0x207F, 0x00B2, 0x25A0, 0x00A0
 };
 
-#elif _CODE_PAGE == 1256
-#define _TBLDEF 1
-static
-const WCHAR Tbl[] = {  /*  CP1256(0x80-0xFF) to Unicode conversion table */
-       0x20AC, 0x067E, 0x201A, 0x0192, 0x201E, 0x2026, 0x2020, 0x2021,
-       0x02C6, 0x2030, 0x0679, 0x2039, 0x0152, 0x0686, 0x0698, 0x0688,
-       0x06AF, 0x2018, 0x2019, 0x201C, 0x201D, 0x2022, 0x2013, 0x2014,
-       0x06A9, 0x2122, 0x0691, 0x203A, 0x0153, 0x200C, 0x200D, 0x06BA,
-       0x00A0, 0x060C, 0x00A2, 0x00A3, 0x00A4, 0x00A5, 0x00A6, 0x00A7,
-       0x00A8, 0x00A9, 0x06BE, 0x00AB, 0x00AC, 0x00AD, 0x00AE, 0x00AF,
-       0x00B0, 0x00B1, 0x00B2, 0x00B3, 0x00B4, 0x00B5, 0x00B6, 0x00B7,
-       0x00B8, 0x00B9, 0x061B, 0x00BB, 0x00BC, 0x00BD, 0x00BE, 0x061F,
-       0x06C1, 0x0621, 0x0622, 0x0623, 0x0624, 0x0625, 0x0626, 0x0627,
-       0x0628, 0x0629, 0x062A, 0x062B, 0x062C, 0x062D, 0x062E, 0x062F,
-       0x0630, 0x0631, 0x0632, 0x0633, 0x0634, 0x0635, 0x0636, 0x00D7,
-       0x0637, 0x0638, 0x0639, 0x063A, 0x0640, 0x0640, 0x0642, 0x0643,
-       0x00E0, 0x0644, 0x00E2, 0x0645, 0x0646, 0x0647, 0x0648, 0x00E7,
-       0x00E8, 0x00E9, 0x00EA, 0x00EB, 0x0649, 0x064A, 0x00EE, 0x00EF,
-       0x064B, 0x064C, 0x064D, 0x064E, 0x00F4, 0x064F, 0x0650, 0x00F7,
-       0x0651, 0x00F9, 0x0652, 0x00FB, 0x00FC, 0x200E, 0x200F, 0x06D2
-}
-
-#elif _CODE_PAGE == 1257
+#elif _CODE_PAGE == 866
 #define _TBLDEF 1
 static
-const WCHAR Tbl[] = {  /*  CP1257(0x80-0xFF) to Unicode conversion table */
-       0x20AC, 0x0000, 0x201A, 0x0000, 0x201E, 0x2026, 0x2020, 0x2021,
-       0x0000, 0x2030, 0x0000, 0x2039, 0x0000, 0x00A8, 0x02C7, 0x00B8,
-       0x0000, 0x2018, 0x2019, 0x201C, 0x201D, 0x2022, 0x2013, 0x2014,
-       0x0000, 0x2122, 0x0000, 0x203A, 0x0000, 0x00AF, 0x02DB, 0x0000,
-       0x00A0, 0x0000, 0x00A2, 0x00A3, 0x00A4, 0x0000, 0x00A6, 0x00A7,
-       0x00D8, 0x00A9, 0x0156, 0x00AB, 0x00AC, 0x00AD, 0x00AE, 0x00AF,
-       0x00B0, 0x00B1, 0x00B2, 0x00B3, 0x00B4, 0x00B5, 0x00B6, 0x00B7,
-       0x00B8, 0x00B9, 0x0157, 0x00BB, 0x00BC, 0x00BD, 0x00BE, 0x00E6,
-       0x0104, 0x012E, 0x0100, 0x0106, 0x00C4, 0x00C5, 0x0118, 0x0112,
-       0x010C, 0x00C9, 0x0179, 0x0116, 0x0122, 0x0136, 0x012A, 0x013B,
-       0x0160, 0x0143, 0x0145, 0x00D3, 0x014C, 0x00D5, 0x00D6, 0x00D7,
-       0x0172, 0x0141, 0x015A, 0x016A, 0x00DC, 0x017B, 0x017D, 0x00DF,
-       0x0105, 0x012F, 0x0101, 0x0107, 0x00E4, 0x00E5, 0x0119, 0x0113,
-       0x010D, 0x00E9, 0x017A, 0x0117, 0x0123, 0x0137, 0x012B, 0x013C,
-       0x0161, 0x0144, 0x0146, 0x00F3, 0x014D, 0x00F5, 0x00F6, 0x00F7,
-       0x0173, 0x014E, 0x015B, 0x016B, 0x00FC, 0x017C, 0x017E, 0x02D9
+const WCHAR Tbl[] = {  /*  CP866(0x80-0xFF) to Unicode conversion table */
+       0x0410, 0x0411, 0x0412, 0x0413, 0x0414, 0x0415, 0x0416, 0x0417, 0x0418, 0x0419, 0x041A, 0x041B, 0x041C, 0x041D, 0x041E, 0x041F,
+       0x0420, 0x0421, 0x0422, 0x0423, 0x0424, 0x0425, 0x0426, 0x0427, 0x0428, 0x0429, 0x042A, 0x042B, 0x042C, 0x042D, 0x042E, 0x042F,
+       0x0430, 0x0431, 0x0432, 0x0433, 0x0434, 0x0435, 0x0436, 0x0437, 0x0438, 0x0439, 0x043A, 0x043B, 0x043C, 0x043D, 0x043E, 0x043F,
+       0x2591, 0x2592, 0x2593, 0x2502, 0x2524, 0x2561, 0x2562, 0x2556, 0x2555, 0x2563, 0x2551, 0x2557, 0x255D, 0x255C, 0x255B, 0x2510,
+       0x2514, 0x2534, 0x252C, 0x251C, 0x2500, 0x253C, 0x255E, 0x255F, 0x255A, 0x2554, 0x2569, 0x2566, 0x2560, 0x2550, 0x256C, 0x2567,
+       0x2568, 0x2564, 0x2565, 0x2559, 0x2558, 0x2552, 0x2553, 0x256B, 0x256A, 0x2518, 0x250C, 0x2588, 0x2584, 0x258C, 0x2590, 0x2580,
+       0x0440, 0x0441, 0x0442, 0x0443, 0x0444, 0x0445, 0x0446, 0x0447, 0x0448, 0x0449, 0x044A, 0x044B, 0x044C, 0x044D, 0x044E, 0x044F,
+       0x0401, 0x0451, 0x0404, 0x0454, 0x0407, 0x0457, 0x040E, 0x045E, 0x00B0, 0x2219, 0x00B7, 0x221A, 0x2116, 0x00A4, 0x25A0, 0x00A0
 };
 
-#elif _CODE_PAGE == 1258
+#elif _CODE_PAGE == 869
 #define _TBLDEF 1
 static
-const WCHAR Tbl[] = {  /*  CP1258(0x80-0xFF) to Unicode conversion table */
-       0x20AC, 0x0000, 0x201A, 0x0192, 0x201E, 0x2026, 0x2020, 0x2021,
-       0x02C6, 0x2030, 0x0000, 0x2039, 0x0152, 0x0000, 0x0000, 0x0000,
-       0x0000, 0x2018, 0x2019, 0x201C, 0x201D, 0x2022, 0x2013, 0x2014,
-       0x02DC, 0x2122, 0x0000, 0x203A, 0x0153, 0x0000, 0x0000, 0x0178,
-       0x00A0, 0x00A1, 0x00A2, 0x00A3, 0x00A4, 0x00A5, 0x00A6, 0x00A7,
-       0x00A8, 0x00A9, 0x00AA, 0x00AB, 0x00AC, 0x00AD, 0x00AE, 0x00AF,
-       0x00B0, 0x00B1, 0x00B2, 0x00B3, 0x00B4, 0x00B5, 0x00B6, 0x00B7,
-       0x00B8, 0x00B9, 0x00BA, 0x00BB, 0x00BC, 0x00BD, 0x00BE, 0x00BF,
-       0x00C0, 0x00C1, 0x00C2, 0x0102, 0x00C4, 0x00C5, 0x00C6, 0x00C7,
-       0x00C8, 0x00C9, 0x00CA, 0x00CB, 0x0300, 0x00CD, 0x00CE, 0x00CF,
-       0x0110, 0x00D1, 0x0309, 0x00D3, 0x00D4, 0x01A0, 0x00D6, 0x00D7,
-       0x00D8, 0x00D9, 0x00DA, 0x00DB, 0x00DC, 0x01AF, 0x0303, 0x00DF,
-       0x00E0, 0x00E1, 0x00E2, 0x0103, 0x00E4, 0x00E5, 0x00E6, 0x00E7,
-       0x00E8, 0x00E9, 0x00EA, 0x00EB, 0x0301, 0x00ED, 0x00EE, 0x00EF,
-       0x0111, 0x00F1, 0x0323, 0x00F3, 0x00F4, 0x01A1, 0x00F6, 0x00F7,
-       0x00F8, 0x00F9, 0x00FA, 0x00FB, 0x00FC, 0x01B0, 0x20AB, 0x00FF
+const WCHAR Tbl[] = {  /*  CP869(0x80-0xFF) to Unicode conversion table */
+       0x00B7, 0x00B7, 0x00B7, 0x00B7, 0x00B7, 0x00B7, 0x0386, 0x00B7, 0x00B7, 0x00AC, 0x00A6, 0x2018, 0x2019, 0x0388, 0x2015, 0x0389,
+       0x038A, 0x03AA, 0x038C, 0x00B7, 0x00B7, 0x038E, 0x03AB, 0x00A9, 0x038F, 0x00B2, 0x00B3, 0x03AC, 0x00A3, 0x03AD, 0x03AE, 0x03AF,
+       0x03CA, 0x0390, 0x03CC, 0x03CD, 0x0391, 0x0392, 0x0393, 0x0394, 0x0395, 0x0396, 0x0397, 0x00BD, 0x0398, 0x0399, 0x00AB, 0x00BB,
+       0x2591, 0x2592, 0x2593, 0x2502, 0x2524, 0x039A, 0x039B, 0x039C, 0x039D, 0x2563, 0x2551, 0x2557, 0x255D, 0x039E, 0x039F, 0x2510,
+       0x2514, 0x2534, 0x252C, 0x251C, 0x2500, 0x253C, 0x0A30, 0x03A1, 0x255A, 0x2554, 0x2569, 0x2566, 0x2560, 0x2550, 0x256C, 0x03A3,
+       0x03A4, 0x03A5, 0x03A6, 0x03A7, 0x03A8, 0x03A9, 0x03B1, 0x03B2, 0x03B3, 0x2518, 0x250C, 0x2588, 0x2584, 0x03B4, 0x03B5, 0x2580,
+       0x03B6, 0x03B7, 0x03B8, 0x03B9, 0x03BA, 0x03BB, 0x03BC, 0x03BD, 0x03BE, 0x03BF, 0x03C0, 0x03C1, 0x03C3, 0x03C2, 0x03C4, 0x0384,
+       0x00AD, 0x00B1, 0x03C5, 0x03C6, 0x03C7, 0x00A7, 0x03C8, 0x0385, 0x00B0, 0x00A8, 0x03C9, 0x03CB, 0x03B0, 0x03CE, 0x25A0, 0x00A0
 };
 
 #endif
 
 
 #if !_TBLDEF || !_USE_LFN
-#error This file is not needed in current configuration. Remove from the project.
+#error This file is not needed at current configuration. Remove from the project.
 #endif
 
 
+
+
 WCHAR ff_convert (     /* Converted character, Returns zero on error */
        WCHAR   chr,    /* Character code to be converted */
-       UINT    dir             /* 0: Unicode to OEMCP, 1: OEMCP to Unicode */
+       UINT    dir             /* 0: Unicode to OEM code, 1: OEM code to Unicode */
 )
 {
        WCHAR c;
@@ -510,10 +284,10 @@ WCHAR ff_convert (        /* Converted character, Returns zero on error */
                c = chr;
 
        } else {
-               if (dir) {              /* OEMCP to Unicode */
+               if (dir) {              /* OEM code to Unicode */
                        c = (chr >= 0x100) ? 0 : Tbl[chr - 0x80];
 
-               } else {                /* Unicode to OEMCP */
+               } else {                /* Unicode to OEM code */
                        for (c = 0; c < 0x80; c++) {
                                if (chr == Tbl[c]) break;
                        }
@@ -525,16 +299,50 @@ WCHAR ff_convert (        /* Converted character, Returns zero on error */
 }
 
 
-WCHAR ff_wtoupper (    /* Upper converted character */
-       WCHAR chr               /* Input character */
-)
-{
-       static const WCHAR tbl_lower[] = { 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6A, 0x6B, 0x6C, 0x6D, 0x6E, 0x6F, 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7A, 0xA1, 0x00A2, 0x00A3, 0x00A5, 0x00AC, 0x00AF, 0xE0, 0xE1, 0xE2, 0xE3, 0xE4, 0xE5, 0xE6, 0xE7, 0xE8, 0xE9, 0xEA, 0xEB, 0xEC, 0xED, 0xEE, 0xEF, 0xF0, 0xF1, 0xF2, 0xF3, 0xF4, 0xF5, 0xF6, 0xF8, 0xF9, 0xFA, 0xFB, 0xFC, 0xFD, 0xFE, 0x0FF, 0x101, 0x103, 0x105, 0x107, 0x109, 0x10B, 0x10D, 0x10F, 0x111, 0x113, 0x115, 0x117, 0x119, 0x11B, 0x11D, 0x11F, 0x121, 0x123, 0x125, 0x127, 0x129, 0x12B, 0x12D, 0x12F, 0x131, 0x133, 0x135, 0x137, 0x13A, 0x13C, 0x13E, 0x140, 0x142, 0x144, 0x146, 0x148, 0x14B, 0x14D, 0x14F, 0x151, 0x153, 0x155, 0x157, 0x159, 0x15B, 0x15D, 0x15F, 0x161, 0x163, 0x165, 0x167, 0x169, 0x16B, 0x16D, 0x16F, 0x171, 0x173, 0x175, 0x177, 0x17A, 0x17C, 0x17E, 0x192, 0x3B1, 0x3B2, 0x3B3, 0x3B4, 0x3B5, 0x3B6, 0x3B7, 0x3B8, 0x3B9, 0x3BA, 0x3BB, 0x3BC, 0x3BD, 0x3BE, 0x3BF, 0x3C0, 0x3C1, 0x3C3, 0x3C4, 0x3C5, 0x3C6, 0x3C7, 0x3C8, 0x3C9, 0x3CA, 0x430, 0x431, 0x432, 0x433, 0x434, 0x435, 0x436, 0x437, 0x438, 0x439, 0x43A, 0x43B, 0x43C, 0x43D, 0x43E, 0x43F, 0x440, 0x441, 0x442, 0x443, 0x444, 0x445, 0x446, 0x447, 0x448, 0x449, 0x44A, 0x44B, 0x44C, 0x44D, 0x44E, 0x44F, 0x451, 0x452, 0x453, 0x454, 0x455, 0x456, 0x457, 0x458, 0x459, 0x45A, 0x45B, 0x45C, 0x45E, 0x45F, 0x2170, 0x2171, 0x2172, 0x2173, 0x2174, 0x2175, 0x2176, 0x2177, 0x2178, 0x2179, 0x217A, 0x217B, 0x217C, 0x217D, 0x217E, 0x217F, 0xFF41, 0xFF42, 0xFF43, 0xFF44, 0xFF45, 0xFF46, 0xFF47, 0xFF48, 0xFF49, 0xFF4A, 0xFF4B, 0xFF4C, 0xFF4D, 0xFF4E, 0xFF4F, 0xFF50, 0xFF51, 0xFF52, 0xFF53, 0xFF54, 0xFF55, 0xFF56, 0xFF57, 0xFF58, 0xFF59, 0xFF5A, 0 };
-       static const WCHAR tbl_upper[] = { 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4A, 0x4B, 0x4C, 0x4D, 0x4E, 0x4F, 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5A, 0x21, 0xFFE0, 0xFFE1, 0xFFE5, 0xFFE2, 0xFFE3, 0xC0, 0xC1, 0xC2, 0xC3, 0xC4, 0xC5, 0xC6, 0xC7, 0xC8, 0xC9, 0xCA, 0xCB, 0xCC, 0xCD, 0xCE, 0xCF, 0xD0, 0xD1, 0xD2, 0xD3, 0xD4, 0xD5, 0xD6, 0xD8, 0xD9, 0xDA, 0xDB, 0xDC, 0xDD, 0xDE, 0x178, 0x100, 0x102, 0x104, 0x106, 0x108, 0x10A, 0x10C, 0x10E, 0x110, 0x112, 0x114, 0x116, 0x118, 0x11A, 0x11C, 0x11E, 0x120, 0x122, 0x124, 0x126, 0x128, 0x12A, 0x12C, 0x12E, 0x130, 0x132, 0x134, 0x136, 0x139, 0x13B, 0x13D, 0x13F, 0x141, 0x143, 0x145, 0x147, 0x14A, 0x14C, 0x14E, 0x150, 0x152, 0x154, 0x156, 0x158, 0x15A, 0x15C, 0x15E, 0x160, 0x162, 0x164, 0x166, 0x168, 0x16A, 0x16C, 0x16E, 0x170, 0x172, 0x174, 0x176, 0x179, 0x17B, 0x17D, 0x191, 0x391, 0x392, 0x393, 0x394, 0x395, 0x396, 0x397, 0x398, 0x399, 0x39A, 0x39B, 0x39C, 0x39D, 0x39E, 0x39F, 0x3A0, 0x3A1, 0x3A3, 0x3A4, 0x3A5, 0x3A6, 0x3A7, 0x3A8, 0x3A9, 0x3AA, 0x410, 0x411, 0x412, 0x413, 0x414, 0x415, 0x416, 0x417, 0x418, 0x419, 0x41A, 0x41B, 0x41C, 0x41D, 0x41E, 0x41F, 0x420, 0x421, 0x422, 0x423, 0x424, 0x425, 0x426, 0x427, 0x428, 0x429, 0x42A, 0x42B, 0x42C, 0x42D, 0x42E, 0x42F, 0x401, 0x402, 0x403, 0x404, 0x405, 0x406, 0x407, 0x408, 0x409, 0x40A, 0x40B, 0x40C, 0x40E, 0x40F, 0x2160, 0x2161, 0x2162, 0x2163, 0x2164, 0x2165, 0x2166, 0x2167, 0x2168, 0x2169, 0x216A, 0x216B, 0x216C, 0x216D, 0x216E, 0x216F, 0xFF21, 0xFF22, 0xFF23, 0xFF24, 0xFF25, 0xFF26, 0xFF27, 0xFF28, 0xFF29, 0xFF2A, 0xFF2B, 0xFF2C, 0xFF2D, 0xFF2E, 0xFF2F, 0xFF30, 0xFF31, 0xFF32, 0xFF33, 0xFF34, 0xFF35, 0xFF36, 0xFF37, 0xFF38, 0xFF39, 0xFF3A, 0 };
-       int i;
 
 
-       for (i = 0; tbl_lower[i] && chr != tbl_lower[i]; i++) ;
+WCHAR ff_wtoupper (    /* Returns upper converted character */
+       WCHAR chr               /* Unicode character to be upper converted */
+)
+{
+       static const WCHAR lower[] = {  /* Lower case characters to be converted */
+       /* Latin Supplement */                  0xE0,0xE1,0xE2,0xE3,0xE4,0xE5,0xE6,0xE7,0xE8,0xE9,0xEA,0xEB,0xEC,0xED,0xEE,0xEF,0xF0,0xF1,0xF2,0xF3,0xF4,0xF5,0xF6,0xF8,0xF9,0xFA,0xFB,0xFC,0xFD,0xFE,0xFF,
+       /* Latin Extended-A */                  0x101,0x103,0x105,0x107,0x109,0x10B,0x10D,0x10F,0x111,0x113,0x115,0x117,0x119,0x11B,0x11D,0x11F,0x121,0x123,0x125,0x127,0x129,0x12B,0x12D,0x12F,0x131,0x133,0x135,0x137,0x13A,0x13C,0x13E,0x140,0x142,0x144,0x146,0x148,0x14B,0x14D,0x14F,0x151,0x153,0x155,0x157,0x159,0x15B,0x15D,0x15F,0x161,0x163,0x165,0x167,0x169,0x16B,0x16D,0x16F,0x171,0x173,0x175,0x177,0x17A,0x17C,0x17E,
+       /* Latin Extended-B */                  0x183,0x185,0x188,0x18C,0x192,0x199,0x1A1,0x1A3,0x1A8,0x1AD,0x1B0,0x1B4,0x1B6,0x1B9,0x1BD,0x1C6,0x1C9,0x1CC,0x1CE,0x1D0,0x1D2,0x1D4,0x1D6,0x1D8,0x1DA,0x1DC,0x1DD,0x1DF,0x1E1,0x1E3,0x1E5,0x1E7,0x1E9,0x1EB,0x1ED,0x1EF,0x1F3,0x1F5,0x1FB,0x1FD,0x1FF,0x201,0x203,0x205,0x207,0x209,0x20B,0x20D,0x20F,0x211,0x213,0x215,0x217,
+       /* Greek, Coptic */                             0x3B1,0x3B2,0x3B3,0x3B4,0x3B5,0x3B6,0x3B7,0x3B8,0x3B9,0x3BA,0x3BB,0x3BC,0x3BD,0x3BE,0x3BF,0x3C0,0x3C1,0x3C3,0x3C4,0x3C5,0x3C6,0x3C7,0x3C8,0x3C9,0x3CA,0x3CB,0x3CC,0x3CD,0x3CE,0x3E3,0x3E5,0x3E7,0x3E9,0x3EB,
+       /* Cyrillic */                                  0x430,0x431,0x432,0x433,0x434,0x435,0x436,0x437,0x438,0x439,0x43A,0x43B,0x43C,0x43D,0x43E,0x43F,0x440,0x441,0x442,0x443,0x444,0x445,0x446,0x447,0x448,0x449,0x44A,0x44B,0x44C,0x44D,0x44E,0x44F,0x452,0x453,0x454,0x455,0x456,0x457,0x458,0x459,0x45A,0x45B,0x45C,0x45E,0x45F,0x461,0x463,0x465,0x467,0x469,0x46B,0x46D,0x46F,0x471,0x473,0x475,0x477,0x479,0x47B,0x47D,0x47F,0x481,0x491,0x493,0x495,0x497,0x499,0x49B,0x49D,0x49F,0x4A1,0x4A3,0x4A5,0x4A7,0x4A9,0x4AB,0x4AD,0x4AF,0x4B1,0x4B3,0x4B5,0x4B7,0x4B9,0x4BB,0x4BD,0x4BF,0x4C2,0x4C4,0x4C8,0x4D1,0x4D3,0x4D5,0x4D7,0x4D9,0x4DB,0x4DD,0x4DF,0x4E1,0x4E3,0x4E5,0x4E7,0x4E9,0x4EB,0x4ED,0x4EF,0x4F1,0x4F3,0x4F5,0x4F9,
+       /* Armenian */                                  0x561,0x562,0x563,0x564,0x565,0x566,0x567,0x568,0x569,0x56A,0x56B,0x56C,0x56D,0x56E,0x56F,0x570,0x571,0x572,0x573,0x574,0x575,0x576,0x577,0x578,0x579,0x57A,0x57B,0x57C,0x57D,0x57E,0x57F,0x580,0x581,0x582,0x583,0x584,0x585,0x586,
+       /* Latin Extended Additional */ 0x1E01,0x1E03,0x1E05,0x1E07,0x1E09,0x1E0B,0x1E0D,0x1E0F,0x1E11,0x1E13,0x1E15,0x1E17,0x1E19,0x1E1B,0x1E1D,0x1E1F,0x1E21,0x1E23,0x1E25,0x1E27,0x1E29,0x1E2B,0x1E2D,0x1E2F,0x1E31,0x1E33,0x1E35,0x1E37,0x1E39,0x1E3B,0x1E3D,0x1E3F,0x1E41,0x1E43,0x1E45,0x1E47,0x1E49,0x1E4B,0x1E4D,0x1E4F,0x1E51,0x1E53,0x1E55,0x1E57,0x1E59,0x1E5B,0x1E5D,0x1E5F,0x1E61,0x1E63,0x1E65,0x1E67,0x1E69,0x1E6B,0x1E6D,0x1E6F,0x1E71,0x1E73,0x1E75,0x1E77,0x1E79,0x1E7B,0x1E7D,0x1E7F,0x1E81,0x1E83,0x1E85,0x1E87,0x1E89,0x1E8B,0x1E8D,0x1E8F,0x1E91,0x1E93,0x1E95,0x1E97,0x1E99,0x1E9B,0x1E9D,0x1E9F,0x1EA1,0x1EA3,0x1EA5,0x1EA7,0x1EA9,0x1EAB,0x1EAD,0x1EAF,0x1EB1,0x1EB3,0x1EB5,0x1EB7,0x1EB9,0x1EBB,0x1EBD,0x1EBF,0x1EC1,0x1EC3,0x1EC5,0x1EC7,0x1EC9,0x1ECB,0x1ECD,0x1ECF,0x1ED1,0x1ED3,0x1ED5,0x1ED7,0x1ED9,0x1EDB,0x1EDD,0x1EDF,0x1EE1,0x1EE3,0x1EE5,0x1EE7,0x1EE9,0x1EEB,0x1EED,0x1EEF,0x1EF1,0x1EF3,0x1EF5,0x1EF7,0x1EF9,
+       /* Number forms */                              0x2170,0x2171,0x2172,0x2173,0x2174,0x2175,0x2176,0x2177,0x2178,0x2179,0x217A,0x217B,0x217C,0x217D,0x217E,0x217F,
+       /* Full-width */                                0xFF41,0xFF42,0xFF43,0xFF44,0xFF45,0xFF46,0xFF47,0xFF48,0xFF49,0xFF4A,0xFF4B,0xFF4C,0xFF4D,0xFF4E,0xFF4F,0xFF50,0xFF51,0xFF52,0xFF53,0xFF54,0xFF55,0xFF56,0xFF57,0xFF58,0xFF59,0xFF5A
+       };
+       static const WCHAR upper[] = {  /* Upper case characters correspond to lower[] */
+                                                                       0xC0,0xC1,0xC2,0xC3,0xC4,0xC5,0xC6,0xC7,0xC8,0xC9,0xCA,0xCB,0xCC,0xCD,0xCE,0xCF,0xD0,0xD1,0xD2,0xD3,0xD4,0xD5,0xD6,0xD8,0xD9,0xDA,0xDB,0xDC,0xDD,0xDE,0x178,
+                                                                       0x100,0x102,0x104,0x106,0x108,0x10A,0x10C,0x10E,0x110,0x112,0x114,0x116,0x118,0x11A,0x11C,0x11E,0x120,0x122,0x124,0x126,0x128,0x12A,0x12C,0x12E,0x130,0x132,0x134,0x136,0x139,0x13B,0x13D,0x13F,0x141,0x143,0x145,0x147,0x14A,0x14C,0x14E,0x150,0x152,0x154,0x156,0x158,0x15A,0x15C,0x15E,0x160,0x162,0x164,0x166,0x168,0x16A,0x16C,0x16E,0x170,0x172,0x174,0x176,0x179,0x17B,0x17D,
+                                                                       0x182,0x184,0x187,0x18B,0x191,0x198,0x1A0,0x1A2,0x1A7,0x1AC,0x1AF,0x1B3,0x1B5,0x1B8,0x1BC,0x1C4,0x1C7,0x1CA,0x1CD,0x1CF,0x1D1,0x1D3,0x1D5,0x1D7,0x1D9,0x1DB,0x18E,0x1DE,0x1E0,0x1E2,0x1E4,0x1E6,0x1E8,0x1EA,0x1EC,0x1EE,0x1F1,0x1F4,0x1FA,0x1FC,0x1FE,0x200,0x202,0x204,0x206,0x208,0x20A,0x20C,0x20E,0x210,0x212,0x214,0x216,
+                                                                       0x391,0x392,0x393,0x394,0x395,0x396,0x397,0x398,0x399,0x39A,0x39B,0x39C,0x39D,0x39E,0x39F,0x3A0,0x3A1,0x3A3,0x3A4,0x3A5,0x3A6,0x3A7,0x3A8,0x3A9,0x3AA,0x3AB,0x38C,0x38E,0x38F,0x3E2,0x3E4,0x3E6,0x3E8,0x3EA,
+                                                                       0x410,0x411,0x412,0x413,0x414,0x415,0x416,0x417,0x418,0x419,0x41A,0x41B,0x41C,0x41D,0x41E,0x41F,0x420,0x421,0x422,0x423,0x424,0x425,0x426,0x427,0x428,0x429,0x42A,0x42B,0x42C,0x42D,0x42E,0x42F,0x402,0x403,0x404,0x405,0x406,0x407,0x408,0x409,0x40A,0x40B,0x40C,0x40E,0x40F,0x460,0x462,0x464,0x466,0x468,0x46A,0x46C,0x46E,0x470,0x472,0x474,0x476,0x478,0x47A,0x47C,0x47E,0x480,0x490,0x492,0x494,0x496,0x498,0x49A,0x49C,0x49E,0x4A0,0x4A2,0x4A4,0x4A6,0x4A8,0x4AA,0x4AC,0x4AE,0x4B0,0x4B2,0x4B4,0x4B6,0x4B8,0x4BA,0x4BC,0x4BE,0x4C1,0x4C3,0x5C7,0x4D0,0x4D2,0x4D4,0x4D6,0x4D8,0x4DA,0x4DC,0x4DE,0x4E0,0x4E2,0x4E4,0x4E6,0x4E8,0x4EA,0x4EC,0x4EE,0x4F0,0x4F2,0x4F4,0x4F8,
+                                                                       0x531,0x532,0x533,0x534,0x535,0x536,0x537,0x538,0x539,0x53A,0x53B,0x53C,0x53D,0x53E,0x53F,0x540,0x541,0x542,0x543,0x544,0x545,0x546,0x547,0x548,0x549,0x54A,0x54B,0x54C,0x54D,0x54E,0x54F,0x550,0x551,0x552,0x553,0x554,0x555,0x556,
+                                                                       0x1E00,0x1E02,0x1E04,0x1E06,0x1E08,0x1E0A,0x1E0C,0x1E0E,0x1E10,0x1E12,0x1E14,0x1E16,0x1E18,0x1E1A,0x1E1C,0x1E1E,0x1E20,0x1E22,0x1E24,0x1E26,0x1E28,0x1E2A,0x1E2C,0x1E2E,0x1E30,0x1E32,0x1E34,0x1E36,0x1E38,0x1E3A,0x1E3C,0x1E3E,0x1E40,0x1E42,0x1E44,0x1E46,0x1E48,0x1E4A,0x1E4C,0x1E4E,0x1E50,0x1E52,0x1E54,0x1E56,0x1E58,0x1E5A,0x1E5C,0x1E5E,0x1E60,0x1E62,0x1E64,0x1E66,0x1E68,0x1E6A,0x1E6C,0x1E6E,0x1E70,0x1E72,0x1E74,0x1E76,0x1E78,0x1E7A,0x1E7C,0x1E7E,0x1E80,0x1E82,0x1E84,0x1E86,0x1E88,0x1E8A,0x1E8C,0x1E8E,0x1E90,0x1E92,0x1E94,0x1E96,0x1E98,0x1E9A,0x1E9C,0x1E9E,0x1EA0,0x1EA2,0x1EA4,0x1EA6,0x1EA8,0x1EAA,0x1EAC,0x1EAE,0x1EB0,0x1EB2,0x1EB4,0x1EB6,0x1EB8,0x1EBA,0x1EBC,0x1EBE,0x1EC0,0x1EC2,0x1EC4,0x1EC6,0x1EC8,0x1ECA,0x1ECC,0x1ECE,0x1ED0,0x1ED2,0x1ED4,0x1ED6,0x1ED8,0x1EDA,0x1EDC,0x1EDE,0x1EE0,0x1EE2,0x1EE4,0x1EE6,0x1EE8,0x1EEA,0x1EEC,0x1EEE,0x1EF0,0x1EF2,0x1EF4,0x1EF6,0x1EF8,
+                                                                       0x2160,0x2161,0x2162,0x2163,0x2164,0x2165,0x2166,0x2167,0x2168,0x2169,0x216A,0x216B,0x216C,0x216D,0x216E,0x216F,
+                                                                       0xFF21,0xFF22,0xFF23,0xFF24,0xFF25,0xFF26,0xFF27,0xFF28,0xFF29,0xFF2A,0xFF2B,0xFF2C,0xFF2D,0xFF2E,0xFF2F,0xFF30,0xFF31,0xFF32,0xFF33,0xFF34,0xFF35,0xFF36,0xFF37,0xFF38,0xFF39,0xFF3A
+       };
+       UINT i, n, hi, li;
+
+
+       if (chr < 0x80) {       /* ASCII characters (acceleration) */
+               if (chr >= 0x61 && chr <= 0x7A) chr -= 0x20;
+
+       } else {                        /* Non ASCII characters (table search) */
+               n = 12; li = 0; hi = sizeof lower / sizeof lower[0];
+               do {
+                       i = li + (hi - li) / 2;
+                       if (chr == lower[i]) break;
+                       if (chr > lower[i]) li = i; else hi = i;
+               } while (--n);
+               if (n) chr = upper[i];
+       }
 
-       return tbl_lower[i] ? tbl_upper[i] : chr;
+       return chr;
 }
+
index 306f785..a9121ff 100644 (file)
@@ -11,7 +11,7 @@
 #include "fatfs/ff.h"
 #include "fatfs/diskio.h"
 
-char* imageFileName;
+char* g_imageFileName;
 
 FATFS g_Filesystem;
 
@@ -89,7 +89,7 @@ int need_mount()
 #define NEED_MOUNT() \
     do { ret = need_mount(); if(ret) \
     {\
-        printf("Error: could not mount image file '%s' (%d). \n", imageFileName, ret); \
+        printf("Error: could not mount image file '%s' (%d). \n", g_imageFileName, ret); \
         PRINT_HELP_AND_QUIT(); \
     } } while(0)
 
@@ -136,13 +136,7 @@ int main(int oargc, char* oargv[])
         PRINT_HELP_AND_QUIT();
     }
 
-    imageFileName = argv[0];
-
-    if (disk_initialize(0))
-    {
-        printf("Error: could not open image file '%s'. \n", imageFileName);
-        PRINT_HELP_AND_QUIT();
-    }
+    g_imageFileName = argv[0];
 
     argc--;
     argv++;
@@ -188,7 +182,7 @@ int main(int oargc, char* oargv[])
 
             disk_ioctl(0, SET_SECTOR_COUNT, &sectors);
 
-            ret = f_mkfs("0:", 1, 4096);
+            ret = f_mkfs("0:", 1, sectors < 4096 ? 1 : 8);
             if (ret)
             {
                 printf("ERROR: Formatting drive: %d.\n", ret);