Index: asp3_tinet_ecnl_arm/trunk/ntshell/fatfs/ccsbcs.c
===================================================================
--- asp3_tinet_ecnl_arm/trunk/ntshell/fatfs/ccsbcs.c	(revision 369)
+++ asp3_tinet_ecnl_arm/trunk/ntshell/fatfs/ccsbcs.c	(revision 374)
@@ -25,5 +25,5 @@
 
 
-#if _CODE_PAGE == 437
+#if FF_CODE_PAGE == 437
 #define _TBLDEF 1
 static
@@ -39,5 +39,5 @@
 };
 
-#elif _CODE_PAGE == 720
+#elif FF_CODE_PAGE == 720
 #define _TBLDEF 1
 static
@@ -53,5 +53,5 @@
 };
 
-#elif _CODE_PAGE == 737
+#elif FF_CODE_PAGE == 737
 #define _TBLDEF 1
 static
@@ -67,5 +67,5 @@
 };
 
-#elif _CODE_PAGE == 771
+#elif FF_CODE_PAGE == 771
 #define _TBLDEF 1
 static
@@ -81,5 +81,5 @@
 };
 
-#elif _CODE_PAGE == 775
+#elif FF_CODE_PAGE == 775
 #define _TBLDEF 1
 static
@@ -95,5 +95,5 @@
 };
 
-#elif _CODE_PAGE == 850
+#elif FF_CODE_PAGE == 850
 #define _TBLDEF 1
 static
@@ -109,5 +109,5 @@
 };
 
-#elif _CODE_PAGE == 852
+#elif FF_CODE_PAGE == 852
 #define _TBLDEF 1
 static
@@ -123,5 +123,5 @@
 };
 
-#elif _CODE_PAGE == 855
+#elif FF_CODE_PAGE == 855
 #define _TBLDEF 1
 static
@@ -137,5 +137,5 @@
 };
 
-#elif _CODE_PAGE == 857
+#elif FF_CODE_PAGE == 857
 #define _TBLDEF 1
 static
@@ -151,5 +151,5 @@
 };
 
-#elif _CODE_PAGE == 860
+#elif FF_CODE_PAGE == 860
 #define _TBLDEF 1
 static
@@ -165,5 +165,5 @@
 };
 
-#elif _CODE_PAGE == 861
+#elif FF_CODE_PAGE == 861
 #define _TBLDEF 1
 static
@@ -179,5 +179,5 @@
 };
 
-#elif _CODE_PAGE == 862
+#elif FF_CODE_PAGE == 862
 #define _TBLDEF 1
 static
@@ -193,5 +193,5 @@
 };
 
-#elif _CODE_PAGE == 863
+#elif FF_CODE_PAGE == 863
 #define _TBLDEF 1
 static
@@ -207,5 +207,5 @@
 };
 
-#elif _CODE_PAGE == 864
+#elif FF_CODE_PAGE == 864
 #define _TBLDEF 1
 static
@@ -221,5 +221,5 @@
 };
 
-#elif _CODE_PAGE == 865
+#elif FF_CODE_PAGE == 865
 #define _TBLDEF 1
 static
@@ -235,5 +235,5 @@
 };
 
-#elif _CODE_PAGE == 866
+#elif FF_CODE_PAGE == 866
 #define _TBLDEF 1
 static
@@ -249,5 +249,5 @@
 };
 
-#elif _CODE_PAGE == 869
+#elif FF_CODE_PAGE == 869
 #define _TBLDEF 1
 static
@@ -266,5 +266,5 @@
 
 
-#if _CODE_PAGE != 65001 && (!_TBLDEF || !_USE_LFN)
+#if FF_CODE_PAGE != 65001 && (!_TBLDEF || !FF_USE_LFN)
 #error This file is not needed at current configuration. Remove from the project.
 #endif
@@ -272,5 +272,5 @@
 
 
-#if _CODE_PAGE != 65001
+#if FF_CODE_PAGE != 65001
 WCHAR ff_convert (	/* Converted character, Returns zero on error */
 	WCHAR	chr,	/* Character code to be converted */
Index: asp3_tinet_ecnl_arm/trunk/ntshell/fatfs/diskio.c
===================================================================
--- asp3_tinet_ecnl_arm/trunk/ntshell/fatfs/diskio.c	(revision 369)
+++ asp3_tinet_ecnl_arm/trunk/ntshell/fatfs/diskio.c	(revision 374)
@@ -34,5 +34,5 @@
 int get_status(volatile RD_STAT *stat) {
 	stat->sz_sector = SS_RAMDISK;
-	if(stat->sz_sector < _MIN_SS || stat->sz_sector > _MAX_SS) return 0;
+	if(stat->sz_sector < FF_MIN_SS || stat->sz_sector > FF_MAX_SS) return 0;
 	stat->n_sectors = SZ_RAMDISK * 1024 / SS_RAMDISK;
 	stat->status = 0;
Index: asp3_tinet_ecnl_arm/trunk/ntshell/fatfs/diskio.h
===================================================================
--- asp3_tinet_ecnl_arm/trunk/ntshell/fatfs/diskio.h	(revision 369)
+++ asp3_tinet_ecnl_arm/trunk/ntshell/fatfs/diskio.h	(revision 374)
@@ -60,9 +60,9 @@
 
 /* Generic command (Used by FatFs) */
-#define CTRL_SYNC			0	/* Complete pending write process (needed at _FS_READONLY == 0) */
-#define GET_SECTOR_COUNT	1	/* Get media size (needed at _USE_MKFS == 1) */
-#define GET_SECTOR_SIZE		2	/* Get sector size (needed at _MAX_SS != _MIN_SS) */
-#define GET_BLOCK_SIZE		3	/* Get erase block size (needed at _USE_MKFS == 1) */
-#define CTRL_TRIM			4	/* Inform device that the data on the block of sectors is no longer used (needed at _USE_TRIM == 1) */
+#define CTRL_SYNC			0	/* Complete pending write process (needed at FF_FS_READONLY == 0) */
+#define GET_SECTOR_COUNT	1	/* Get media size (needed at FF_USE_MKFS == 1) */
+#define GET_SECTOR_SIZE		2	/* Get sector size (needed at FF_MAX_SS != FF_MIN_SS) */
+#define GET_BLOCK_SIZE		3	/* Get erase block size (needed at FF_USE_MKFS == 1) */
+#define CTRL_TRIM			4	/* Inform device that the data on the block of sectors is no longer used (needed at FF_USE_TRIM == 1) */
 
 /* Generic command (Not used by FatFs) */
Index: asp3_tinet_ecnl_arm/trunk/ntshell/fatfs/ff.c
===================================================================
--- asp3_tinet_ecnl_arm/trunk/ntshell/fatfs/ff.c	(revision 369)
+++ asp3_tinet_ecnl_arm/trunk/ntshell/fatfs/ff.c	(revision 374)
@@ -20,5 +20,5 @@
 #include "ff.h"			/* Declarations of FatFs API */
 #include "diskio.h"		/* Declarations of disk I/O functions */
-#include "util/ntstdio.h"
+#include <stdio.h>
 
 /*--------------------------------------------------------------------------
@@ -34,6 +34,6 @@
 
 /* Reentrancy related */
-#if _FS_REENTRANT
-#if _USE_LFN == 1
+#if FF_FS_REENTRANT
+#if FF_USE_LFN == 1
 #error Static LFN work area cannot be used at thread-safe configuration
 #endif
@@ -49,9 +49,9 @@
 
 /* Definitions of sector size */
-#if (_MAX_SS < _MIN_SS) || (_MAX_SS != 512 && _MAX_SS != 1024 && _MAX_SS != 2048 && _MAX_SS != 4096) || (_MIN_SS != 512 && _MIN_SS != 1024 && _MIN_SS != 2048 && _MIN_SS != 4096)
+#if (FF_MAX_SS < FF_MIN_SS) || (FF_MAX_SS != 512 && FF_MAX_SS != 1024 && FF_MAX_SS != 2048 && FF_MAX_SS != 4096) || (FF_MIN_SS != 512 && FF_MIN_SS != 1024 && FF_MIN_SS != 2048 && FF_MIN_SS != 4096)
 #error Wrong sector size configuration
 #endif
-#if _MAX_SS == _MIN_SS
-#define	SS(fs)	((UINT)_MAX_SS)	/* Fixed sector size */
+#if FF_MAX_SS == FF_MIN_SS
+#define	SS(fs)	((UINT)FF_MAX_SS)	/* Fixed sector size */
 #else
 #define	SS(fs)	((fs)->ssize)	/* Variable sector size */
@@ -60,9 +60,9 @@
 
 /* Timestamp feature */
-#if _FS_NORTC == 1
-#if _NORTC_YEAR < 1980 || _NORTC_YEAR > 2107 || _NORTC_MON < 1 || _NORTC_MON > 12 || _NORTC_MDAY < 1 || _NORTC_MDAY > 31
-#error Invalid _FS_NORTC settings
-#endif
-#define GET_FATTIME()	((DWORD)(_NORTC_YEAR - 1980) << 25 | (DWORD)_NORTC_MON << 21 | (DWORD)_NORTC_MDAY << 16)
+#if FF_FS_NORTC == 1
+#if FF_NORTC_YEAR < 1980 || FF_NORTC_YEAR > 2107 || FF_NORTC_MON < 1 || FF_NORTC_MON > 12 || FF_NORTC_MDAY < 1 || FF_NORTC_MDAY > 31
+#error Invalid FF_FS_NORTC settings
+#endif
+#define GET_FATTIME()	((DWORD)(FF_NORTC_YEAR - 1980) << 25 | (DWORD)FF_NORTC_MON << 21 | (DWORD)FF_NORTC_MDAY << 16)
 #else
 #define GET_FATTIME()	get_fattime()
@@ -71,7 +71,7 @@
 
 /* File access control feature */
-#if _FS_LOCK
-#if _FS_READONLY
-#error _FS_LOCK must be 0 at read-only configuration
+#if FF_FS_LOCK != 0
+#if FF_FS_READONLY
+#error FF_FS_LOCK must be 0 at read-only configuration
 #endif
 typedef struct {
@@ -87,5 +87,5 @@
 /* DBCS code ranges and SBCS upper conversion tables */
 
-#if _CODE_PAGE == 932	/* Japanese Shift-JIS */
+#if FF_CODE_PAGE == 932	/* Japanese Shift-JIS */
 #define _DF1S	0x81	/* DBC 1st byte range 1 start */
 #define _DF1E	0x9F	/* DBC 1st byte range 1 end */
@@ -97,5 +97,5 @@
 #define _DS2E	0xFC	/* DBC 2nd byte range 2 end */
 
-#elif _CODE_PAGE == 936	/* Simplified Chinese GBK */
+#elif FF_CODE_PAGE == 936	/* Simplified Chinese GBK */
 #define _DF1S	0x81
 #define _DF1E	0xFE
@@ -105,5 +105,5 @@
 #define _DS2E	0xFE
 
-#elif _CODE_PAGE == 949	/* Korean */
+#elif FF_CODE_PAGE == 949	/* Korean */
 #define _DF1S	0x81
 #define _DF1E	0xFE
@@ -115,5 +115,5 @@
 #define _DS3E	0xFE
 
-#elif _CODE_PAGE == 950	/* Traditional Chinese Big5 */
+#elif FF_CODE_PAGE == 950	/* Traditional Chinese Big5 */
 #define _DF1S	0x81
 #define _DF1E	0xFE
@@ -123,5 +123,5 @@
 #define _DS2E	0xFE
 
-#elif _CODE_PAGE == 437	/* U.S. */
+#elif FF_CODE_PAGE == 437	/* U.S. */
 #define _DF1S	0
 #define _EXCVT {0x80,0x9A,0x45,0x41,0x8E,0x41,0x8F,0x80,0x45,0x45,0x45,0x49,0x49,0x49,0x8E,0x8F, \
@@ -134,5 +134,5 @@
 				0xF0,0xF1,0xF2,0xF3,0xF4,0xF5,0xF6,0xF7,0xF8,0xF9,0xFA,0xFB,0xFC,0xFD,0xFE,0xFF}
 
-#elif _CODE_PAGE == 720	/* Arabic */
+#elif FF_CODE_PAGE == 720	/* Arabic */
 #define _DF1S	0
 #define _EXCVT {0x80,0x81,0x82,0x83,0x84,0x85,0x86,0x87,0x88,0x89,0x8A,0x8B,0x8C,0x8D,0x8E,0x8F, \
@@ -145,5 +145,5 @@
 				0xF0,0xF1,0xF2,0xF3,0xF4,0xF5,0xF6,0xF7,0xF8,0xF9,0xFA,0xFB,0xFC,0xFD,0xFE,0xFF}
 
-#elif _CODE_PAGE == 737	/* Greek */
+#elif FF_CODE_PAGE == 737	/* Greek */
 #define _DF1S	0
 #define _EXCVT {0x80,0x81,0x82,0x83,0x84,0x85,0x86,0x87,0x88,0x89,0x8A,0x8B,0x8C,0x8D,0x8E,0x8F, \
@@ -156,5 +156,5 @@
 				0xF0,0xF1,0xF2,0xF3,0xF4,0xF5,0xF6,0xF7,0xF8,0xF9,0xFA,0xFB,0xFC,0xFD,0xFE,0xFF}
 
-#elif _CODE_PAGE == 771	/* KBL */
+#elif FF_CODE_PAGE == 771	/* KBL */
 #define _DF1S	0
 #define _EXCVT {0x80,0x81,0x82,0x83,0x84,0x85,0x86,0x87,0x88,0x89,0x8A,0x8B,0x8C,0x8D,0x8E,0x8F, \
@@ -167,5 +167,5 @@
 				0xF0,0xF0,0xF2,0xF2,0xF4,0xF4,0xF6,0xF6,0xF8,0xF8,0xFA,0xFA,0xFC,0xFC,0xFE,0xFF}
 
-#elif _CODE_PAGE == 775	/* Baltic */
+#elif FF_CODE_PAGE == 775	/* Baltic */
 #define _DF1S	0
 #define _EXCVT {0x80,0x9A,0x91,0xA0,0x8E,0x95,0x8F,0x80,0xAD,0xED,0x8A,0x8A,0xA1,0x8D,0x8E,0x8F, \
@@ -178,5 +178,5 @@
 				0xF0,0xF1,0xF2,0xF3,0xF4,0xF5,0xF6,0xF7,0xF8,0xF9,0xFA,0xFB,0xFC,0xFD,0xFE,0xFF}
 
-#elif _CODE_PAGE == 850	/* Latin 1 */
+#elif FF_CODE_PAGE == 850	/* Latin 1 */
 #define _DF1S	0
 #define _EXCVT {0x43,0x55,0x45,0x41,0x41,0x41,0x41,0x43,0x45,0x45,0x45,0x49,0x49,0x49,0x41,0x41, \
@@ -189,5 +189,5 @@
 				0xF0,0xF1,0xF2,0xF3,0xF4,0xF5,0xF6,0xF7,0xF8,0xF9,0xFA,0xFB,0xFC,0xFD,0xFE,0xFF}
 
-#elif _CODE_PAGE == 852	/* Latin 2 */
+#elif FF_CODE_PAGE == 852	/* Latin 2 */
 #define _DF1S	0
 #define _EXCVT {0x80,0x9A,0x90,0xB6,0x8E,0xDE,0x8F,0x80,0x9D,0xD3,0x8A,0x8A,0xD7,0x8D,0x8E,0x8F, \
@@ -200,5 +200,5 @@
 				0xF0,0xF1,0xF2,0xF3,0xF4,0xF5,0xF6,0xF7,0xF8,0xF9,0xFA,0xEB,0xFC,0xFC,0xFE,0xFF}
 
-#elif _CODE_PAGE == 855	/* Cyrillic */
+#elif FF_CODE_PAGE == 855	/* Cyrillic */
 #define _DF1S	0
 #define _EXCVT {0x81,0x81,0x83,0x83,0x85,0x85,0x87,0x87,0x89,0x89,0x8B,0x8B,0x8D,0x8D,0x8F,0x8F, \
@@ -211,5 +211,5 @@
 				0xF0,0xF2,0xF2,0xF4,0xF4,0xF6,0xF6,0xF8,0xF8,0xFA,0xFA,0xFC,0xFC,0xFD,0xFE,0xFF}
 
-#elif _CODE_PAGE == 857	/* Turkish */
+#elif FF_CODE_PAGE == 857	/* Turkish */
 #define _DF1S	0
 #define _EXCVT {0x80,0x9A,0x90,0xB6,0x8E,0xB7,0x8F,0x80,0xD2,0xD3,0xD4,0xD8,0xD7,0x49,0x8E,0x8F, \
@@ -222,5 +222,5 @@
 				0xF0,0xF1,0xF2,0xF3,0xF4,0xF5,0xF6,0xF7,0xF8,0xF9,0xFA,0xFB,0xFC,0xFD,0xFE,0xFF}
 
-#elif _CODE_PAGE == 860	/* Portuguese */
+#elif FF_CODE_PAGE == 860	/* Portuguese */
 #define _DF1S	0
 #define _EXCVT {0x80,0x9A,0x90,0x8F,0x8E,0x91,0x86,0x80,0x89,0x89,0x92,0x8B,0x8C,0x98,0x8E,0x8F, \
@@ -233,5 +233,5 @@
 				0xF0,0xF1,0xF2,0xF3,0xF4,0xF5,0xF6,0xF7,0xF8,0xF9,0xFA,0xFB,0xFC,0xFD,0xFE,0xFF}
 
-#elif _CODE_PAGE == 861	/* Icelandic */
+#elif FF_CODE_PAGE == 861	/* Icelandic */
 #define _DF1S	0
 #define _EXCVT {0x80,0x9A,0x90,0x41,0x8E,0x41,0x8F,0x80,0x45,0x45,0x45,0x8B,0x8B,0x8D,0x8E,0x8F, \
@@ -244,5 +244,5 @@
 				0xF0,0xF1,0xF2,0xF3,0xF4,0xF5,0xF6,0xF7,0xF8,0xF9,0xFA,0xFB,0xFC,0xFD,0xFE,0xFF}
 
-#elif _CODE_PAGE == 862	/* Hebrew */
+#elif FF_CODE_PAGE == 862	/* Hebrew */
 #define _DF1S	0
 #define _EXCVT {0x80,0x81,0x82,0x83,0x84,0x85,0x86,0x87,0x88,0x89,0x8A,0x8B,0x8C,0x8D,0x8E,0x8F, \
@@ -255,5 +255,5 @@
 				0xF0,0xF1,0xF2,0xF3,0xF4,0xF5,0xF6,0xF7,0xF8,0xF9,0xFA,0xFB,0xFC,0xFD,0xFE,0xFF}
 
-#elif _CODE_PAGE == 863	/* Canadian-French */
+#elif FF_CODE_PAGE == 863	/* Canadian-French */
 #define _DF1S	0
 #define _EXCVT {0x43,0x55,0x45,0x41,0x41,0x41,0x86,0x43,0x45,0x45,0x45,0x49,0x49,0x8D,0x41,0x8F, \
@@ -266,5 +266,5 @@
 				0xF0,0xF1,0xF2,0xF3,0xF4,0xF5,0xF6,0xF7,0xF8,0xF9,0xFA,0xFB,0xFC,0xFD,0xFE,0xFF}
 
-#elif _CODE_PAGE == 864	/* Arabic */
+#elif FF_CODE_PAGE == 864	/* Arabic */
 #define _DF1S	0
 #define _EXCVT {0x80,0x9A,0x45,0x41,0x8E,0x41,0x8F,0x80,0x45,0x45,0x45,0x49,0x49,0x49,0x8E,0x8F, \
@@ -277,5 +277,5 @@
 				0xF0,0xF1,0xF2,0xF3,0xF4,0xF5,0xF6,0xF7,0xF8,0xF9,0xFA,0xFB,0xFC,0xFD,0xFE,0xFF}
 
-#elif _CODE_PAGE == 865	/* Nordic */
+#elif FF_CODE_PAGE == 865	/* Nordic */
 #define _DF1S	0
 #define _EXCVT {0x80,0x9A,0x90,0x41,0x8E,0x41,0x8F,0x80,0x45,0x45,0x45,0x49,0x49,0x49,0x8E,0x8F, \
@@ -288,5 +288,5 @@
 				0xF0,0xF1,0xF2,0xF3,0xF4,0xF5,0xF6,0xF7,0xF8,0xF9,0xFA,0xFB,0xFC,0xFD,0xFE,0xFF}
 
-#elif _CODE_PAGE == 866	/* Russian */
+#elif FF_CODE_PAGE == 866	/* Russian */
 #define _DF1S	0
 #define _EXCVT {0x80,0x81,0x82,0x83,0x84,0x85,0x86,0x87,0x88,0x89,0x8A,0x8B,0x8C,0x8D,0x8E,0x8F, \
@@ -299,5 +299,5 @@
 				0xF0,0xF0,0xF2,0xF2,0xF4,0xF4,0xF6,0xF6,0xF8,0xF9,0xFA,0xFB,0xFC,0xFD,0xFE,0xFF}
 
-#elif _CODE_PAGE == 869	/* Greek 2 */
+#elif FF_CODE_PAGE == 869	/* Greek 2 */
 #define _DF1S	0
 #define _EXCVT {0x80,0x81,0x82,0x83,0x84,0x85,0x86,0x87,0x88,0x89,0x8A,0x8B,0x8C,0x8D,0x8E,0x8F, \
@@ -310,12 +310,12 @@
 				0xF0,0xF1,0xD1,0xD2,0xD3,0xF5,0xD4,0xF7,0xF8,0xF9,0xD5,0x96,0x95,0x98,0xFE,0xFF}
 
-#elif _CODE_PAGE == 1	/* ASCII (for only non-LFN cfg) */
-#if _USE_LFN
+#elif FF_CODE_PAGE == 1	/* ASCII (for only non-LFN cfg) */
+#if FF_USE_LFN
 #error Cannot use LFN feature without valid code page.
 #endif
 #define _DF1S	0
 
-#elif _CODE_PAGE == 65001 /* UTF-8 */
-#if _LFN_UNICODE
+#elif FF_CODE_PAGE == 65001 /* UTF-8 */
+#if FF_LFN_UNICODE
 #error Cannot use LFN_UNICODE feature without valid code page.
 #endif
@@ -532,41 +532,41 @@
 */
 
-#if _VOLUMES < 1 || _VOLUMES > 9
-#error Wrong _VOLUMES setting
-#endif
-static FATFS *FatFs[_VOLUMES];	/* Pointer to the file system objects (logical drives) */
+#if FF_VOLUMES < 1 || FF_VOLUMES > 9
+#error Wrong FF_VOLUMES setting
+#endif
+static FATFS *FatFs[FF_VOLUMES];	/* Pointer to the file system objects (logical drives) */
 static WORD Fsid;				/* File system mount ID */
 
-#if _FS_RPATH && _VOLUMES >= 2
+#if FF_FS_RPATH && FF_VOLUMES >= 2
 static BYTE CurrVol;			/* Current drive */
 #endif
 
-#if _FS_LOCK
-static FILESEM Files[_FS_LOCK];	/* Open object lock semaphores */
-#endif
-
-#if _USE_LFN == 0			/* Non LFN feature */
+#if FF_FS_LOCK != 0
+static FILESEM Files[FF_FS_LOCK];	/* Open object lock semaphores */
+#endif
+
+#if FF_USE_LFN == 0			/* Non LFN feature */
 #define	DEFINE_NAMEBUF		BYTE sfn[12]
 #define INIT_BUF(dobj)		(dobj).fn = sfn
 #define	FREE_BUF()
 #else
-#if _MAX_LFN < 12 || _MAX_LFN > 255
-#error Wrong _MAX_LFN setting
-#endif
-#if _USE_LFN == 1			/* LFN feature with static working buffer */
-static WCHAR LfnBuf[_MAX_LFN + 1];
+#if FF_MAX_LFN < 12 || FF_MAX_LFN > 255
+#error Wrong FF_MAX_LFN setting
+#endif
+#if FF_USE_LFN == 1			/* LFN feature with static working buffer */
+static WCHAR LfnBuf[FF_MAX_LFN + 1];
 #define	DEFINE_NAMEBUF		BYTE sfn[12]
 #define INIT_BUF(dobj)		{ (dobj).fn = sfn; (dobj).lfn = LfnBuf; }
 #define	FREE_BUF()
-#elif _USE_LFN == 2 		/* LFN feature with dynamic working buffer on the stack */
-#define	DEFINE_NAMEBUF		BYTE sfn[12]; WCHAR lbuf[_MAX_LFN + 1]
+#elif FF_USE_LFN == 2 		/* LFN feature with dynamic working buffer on the stack */
+#define	DEFINE_NAMEBUF		BYTE sfn[12]; WCHAR lbuf[FF_MAX_LFN + 1]
 #define INIT_BUF(dobj)		{ (dobj).fn = sfn; (dobj).lfn = lbuf; }
 #define	FREE_BUF()
-#elif _USE_LFN == 3 		/* LFN feature with dynamic working buffer on the heap */
+#elif FF_USE_LFN == 3 		/* LFN feature with dynamic working buffer on the heap */
 #define	DEFINE_NAMEBUF		BYTE sfn[12]; WCHAR *lfn
-#define INIT_BUF(dobj)		{ lfn = ff_memalloc((_MAX_LFN + 1) * 2); if (!lfn) LEAVE_FF((dobj).fs, FR_NOT_ENOUGH_CORE); (dobj).lfn = lfn; (dobj).fn = sfn; }
+#define INIT_BUF(dobj)		{ lfn = ff_memalloc((FF_MAX_LFN + 1) * 2); if (!lfn) LEAVE_FF((dobj).fs, FR_NOT_ENOUGH_CORE); (dobj).lfn = lfn; (dobj).fn = sfn; }
 #define	FREE_BUF()			ff_memfree(lfn)
 #else
-#error Wrong _USE_LFN setting
+#error Wrong FF_USE_LFN setting
 #endif
 #endif
@@ -598,5 +598,5 @@
 	const BYTE *s = (const BYTE*)src;
 
-#if _WORD_ACCESS == 1
+#if FF_WORD_ACCESS == 1
 	while (cnt >= sizeof (int)) {
 		*(int*)d = *(int*)s;
@@ -641,5 +641,5 @@
 /* Request/Release grant to access the volume                            */
 /*-----------------------------------------------------------------------*/
-#if _FS_REENTRANT
+#if FF_FS_REENTRANT
 static
 int lock_fs (
@@ -673,9 +673,9 @@
 /* File lock control functions                                           */
 /*-----------------------------------------------------------------------*/
-#if _FS_LOCK
+#if FF_FS_LOCK != 0
 
 static
 FRESULT chk_lock (	/* Check if the file can be accessed */
-	DIR* dp,		/* Directory object pointing the file to be checked */
+	FATFS_DIR* dp,		/* Directory object pointing the file to be checked */
 	int acc			/* Desired access type (0:Read, 1:Write, 2:Delete/Rename) */
 )
@@ -684,5 +684,5 @@
 
 	/* Search file semaphore table */
-	for (i = be = 0; i < _FS_LOCK; i++) {
+	for (i = be = 0; i < FF_FS_LOCK; i++) {
 		if (Files[i].fs) {	/* Existing entry */
 			if (Files[i].fs == dp->fs &&	 	/* Check if the object matched with an open object */
@@ -693,5 +693,5 @@
 		}
 	}
-	if (i == _FS_LOCK)	/* The object is not opened */
+	if (i == FF_FS_LOCK)	/* The object is not opened */
 		return (be || acc == 2) ? FR_OK : FR_TOO_MANY_OPEN_FILES;	/* Is there a blank entry for new object? */
 
@@ -706,6 +706,6 @@
 	UINT i;
 
-	for (i = 0; i < _FS_LOCK && Files[i].fs; i++) ;
-	return (i == _FS_LOCK) ? 0 : 1;
+	for (i = 0; i < FF_FS_LOCK && Files[i].fs; i++) ;
+	return (i == FF_FS_LOCK) ? 0 : 1;
 }
 
@@ -713,5 +713,5 @@
 static
 UINT inc_lock (	/* Increment object open counter and returns its index (0:Internal error) */
-	DIR* dp,	/* Directory object pointing the file to register or increment */
+	FATFS_DIR* dp,	/* Directory object pointing the file to register or increment */
 	int acc		/* Desired access (0:Read, 1:Write, 2:Delete/Rename) */
 )
@@ -720,5 +720,5 @@
 
 
-	for (i = 0; i < _FS_LOCK; i++) {	/* Find the object */
+	for (i = 0; i < FF_FS_LOCK; i++) {	/* Find the object */
 		if (Files[i].fs == dp->fs &&
 			Files[i].clu == dp->sclust &&
@@ -726,7 +726,7 @@
 	}
 
-	if (i == _FS_LOCK) {				/* Not opened. Register it as new. */
-		for (i = 0; i < _FS_LOCK && Files[i].fs; i++) ;
-		if (i == _FS_LOCK) return 0;	/* No free entry to register (int err) */
+	if (i == FF_FS_LOCK) {				/* Not opened. Register it as new. */
+		for (i = 0; i < FF_FS_LOCK && Files[i].fs; i++) ;
+		if (i == FF_FS_LOCK) return 0;	/* No free entry to register (int err) */
 		Files[i].fs = dp->fs;
 		Files[i].clu = dp->sclust;
@@ -752,5 +752,5 @@
 
 
-	if (--i < _FS_LOCK) {	/* Shift index number origin from 0 */
+	if (--i < FF_FS_LOCK) {	/* Shift index number origin from 0 */
 		n = Files[i].ctr;
 		if (n == 0x100) n = 0;		/* If write mode open, delete the entry */
@@ -773,5 +773,5 @@
 	UINT i;
 
-	for (i = 0; i < _FS_LOCK; i++) {
+	for (i = 0; i < FF_FS_LOCK; i++) {
 		if (Files[i].fs == fs) Files[i].fs = 0;
 	}
@@ -785,5 +785,5 @@
 /* Move/Flush disk access window in the file system object               */
 /*-----------------------------------------------------------------------*/
-#if !_FS_READONLY
+#if !FF_FS_READONLY
 static
 FRESULT sync_window (	/* FR_OK:succeeded, !=0:error */
@@ -825,5 +825,5 @@
 
 	if (sector != fs->winsect) {	/* Window offset changed? */
-#if !_FS_READONLY
+#if !FF_FS_READONLY
 		res = sync_window(fs);		/* Write-back changes */
 #endif
@@ -845,5 +845,5 @@
 /* Synchronize file system and strage device                             */
 /*-----------------------------------------------------------------------*/
-#if !_FS_READONLY
+#if !FF_FS_READONLY
 static
 FRESULT sync_fs (	/* FR_OK:succeeded, !=0:error */
@@ -959,5 +959,5 @@
 /* Hidden API for hacks and disk tools */
 
-#if !_FS_READONLY
+#if !FF_FS_READONLY
 FRESULT put_fat (	/* FR_OK(0):succeeded, !=0:error */
 	FATFS* fs,		/* File system object */
@@ -1014,5 +1014,5 @@
 	return res;
 }
-#endif /* !_FS_READONLY */
+#endif /* !FF_FS_READONLY */
 
 
@@ -1022,5 +1022,5 @@
 /* FAT handling - Remove a cluster chain                                 */
 /*-----------------------------------------------------------------------*/
-#if !_FS_READONLY
+#if !FF_FS_READONLY
 static
 FRESULT remove_chain (	/* FR_OK(0):succeeded, !=0:error */
@@ -1031,5 +1031,5 @@
 	FRESULT res;
 	DWORD nxt;
-#if _USE_TRIM
+#if FF_USE_TRIM
 	DWORD scl = clst, ecl = clst, rt[2];
 #endif
@@ -1051,5 +1051,5 @@
 				fs->fsi_flag |= 1;
 			}
-#if _USE_TRIM
+#if FF_USE_TRIM
 			if (ecl + 1 == nxt) {	/* Is next cluster contiguous? */
 				ecl = nxt;
@@ -1075,5 +1075,5 @@
 /* FAT handling - Stretch or Create a cluster chain                      */
 /*-----------------------------------------------------------------------*/
-#if !_FS_READONLY
+#if !FF_FS_READONLY
 static
 DWORD create_chain (	/* 0:No free cluster, 1:Internal error, 0xFFFFFFFF:Disk error, >=2:New cluster# */
@@ -1128,5 +1128,5 @@
 	return ncl;		/* Return new cluster number or error code */
 }
-#endif /* !_FS_READONLY */
+#endif /* !FF_FS_READONLY */
 
 
@@ -1137,5 +1137,5 @@
 /*-----------------------------------------------------------------------*/
 
-#if _USE_FASTSEEK
+#if FF_USE_FASTSEEK
 static
 DWORD clmt_clust (	/* <2:Error, >=2:Cluster number */
@@ -1157,5 +1157,5 @@
 	return cl + *tbl;	/* Return the cluster number */
 }
-#endif	/* _USE_FASTSEEK */
+#endif	/* FF_USE_FASTSEEK */
 
 
@@ -1168,5 +1168,5 @@
 static
 FRESULT dir_sdi (	/* FR_OK(0):succeeded, !=0:error */
-	DIR* dp,		/* Pointer to directory object */
+	FATFS_DIR* dp,		/* Pointer to directory object */
 	UINT idx		/* Index of directory table */
 )
@@ -1216,5 +1216,5 @@
 static
 FRESULT dir_next (	/* FR_OK(0):succeeded, FR_NO_FILE:End of table, FR_DENIED:Could not stretch */
-	DIR* dp,		/* Pointer to the directory object */
+	FATFS_DIR* dp,		/* Pointer to the directory object */
 	int stretch		/* 0: Do not stretch table, 1: Stretch table if needed */
 )
@@ -1222,5 +1222,5 @@
 	DWORD clst;
 	UINT i;
-#if !_FS_READONLY
+#if !FF_FS_READONLY
 	UINT c;
 #endif
@@ -1244,5 +1244,5 @@
 				if (clst == 0xFFFFFFFF) return FR_DISK_ERR;
 				if (clst >= dp->fs->n_fatent) {					/* If it reached end of dynamic table, */
-#if !_FS_READONLY
+#if !FF_FS_READONLY
 					if (!stretch) return FR_NO_FILE;			/* If do not stretch, report EOT */
 					clst = create_chain(dp->fs, dp->clust);		/* Stretch cluster chain */
@@ -1284,8 +1284,8 @@
 /*-----------------------------------------------------------------------*/
 
-#if !_FS_READONLY
+#if !FF_FS_READONLY
 static
 FRESULT dir_alloc (	/* FR_OK(0):succeeded, !=0:error */
-	DIR* dp,		/* Pointer to the directory object */
+	FATFS_DIR* dp,		/* Pointer to the directory object */
 	UINT nent		/* Number of contiguous entries to allocate (1-21) */
 )
@@ -1337,5 +1337,5 @@
 
 
-#if !_FS_READONLY
+#if !FF_FS_READONLY
 static
 void st_clust (
@@ -1355,5 +1355,5 @@
 /* LFN handling - Test/Pick/Fit an LFN segment from/to directory entry   */
 /*-----------------------------------------------------------------------*/
-#if _USE_LFN
+#if FF_USE_LFN
 static
 const BYTE LfnOfs[] = {1,3,5,7,9,14,16,18,20,22,24,28,30};	/* Offset of LFN characters in the directory entry */
@@ -1377,5 +1377,5 @@
 		uc = LD_WORD(dir + LfnOfs[s]);		/* Pick an LFN character */
 		if (wc) {
-			if (i >= _MAX_LFN || ff_wtoupper(uc) != ff_wtoupper(lfnbuf[i++]))	/* Compare it */
+			if (i >= FF_MAX_LFN || ff_wtoupper(uc) != ff_wtoupper(lfnbuf[i++]))	/* Compare it */
 				return 0;					/* Not matched */
 			wc = uc;
@@ -1410,5 +1410,5 @@
 		uc = LD_WORD(dir + LfnOfs[s]);		/* Pick an LFN character */
 		if (wc) {
-			if (i >= _MAX_LFN) return 0;	/* Buffer overflow? */
+			if (i >= FF_MAX_LFN) return 0;	/* Buffer overflow? */
 			lfnbuf[i++] = wc = uc;			/* Store it */
 		} else {
@@ -1418,5 +1418,5 @@
 
 	if (dir[LDIR_Ord] & LLEF) {				/* Put terminator if it is the last LFN part */
-		if (i >= _MAX_LFN) return 0;		/* Buffer overflow? */
+		if (i >= FF_MAX_LFN) return 0;		/* Buffer overflow? */
 		lfnbuf[i] = 0;
 	}
@@ -1426,5 +1426,5 @@
 
 
-#if !_FS_READONLY
+#if !FF_FS_READONLY
 static
 void fit_lfn (
@@ -1464,5 +1464,5 @@
 /* Create numbered name                                                  */
 /*-----------------------------------------------------------------------*/
-#if _USE_LFN
+#if FF_USE_LFN
 static
 void gen_numname (
@@ -1523,5 +1523,5 @@
 /* Calculate checksum of an SFN entry                                    */
 /*-----------------------------------------------------------------------*/
-#if _USE_LFN
+#if FF_USE_LFN
 static
 BYTE sum_sfn (
@@ -1546,10 +1546,10 @@
 static
 FRESULT dir_find (	/* FR_OK(0):succeeded, !=0:error */
-	DIR* dp			/* Pointer to the directory object linked to the file name */
+	FATFS_DIR* dp			/* Pointer to the directory object linked to the file name */
 )
 {
 	FRESULT res;
 	BYTE c, *dir;
-#if _USE_LFN
+#if FF_USE_LFN
 	BYTE a, ord, sum;
 #endif
@@ -1558,5 +1558,5 @@
 	if (res != FR_OK) return res;
 
-#if _USE_LFN
+#if FF_USE_LFN
 	ord = sum = 0xFF; dp->lfn_idx = 0xFFFF;	/* Reset LFN sequence */
 #endif
@@ -1567,5 +1567,5 @@
 		c = dir[DIR_Name];
 		if (c == 0) { res = FR_NO_FILE; break; }	/* Reached to end of table */
-#if _USE_LFN	/* LFN configuration */
+#if FF_USE_LFN	/* LFN configuration */
 		a = dir[DIR_Attr] & AM_MASK;
 		if (c == DDEM || ((a & AM_VOL) && a != AM_LFN)) {	/* An entry without valid data */
@@ -1604,8 +1604,8 @@
 /* Read an object from the directory                                     */
 /*-----------------------------------------------------------------------*/
-#if _FS_MINIMIZE <= 1 || _USE_LABEL || _FS_RPATH >= 2
+#if FF_FS_MINIMIZE <= 1 || FF_USE_LABEL || FF_FS_RPATH >= 2
 static
 FRESULT dir_read (
-	DIR* dp,		/* Pointer to the directory object */
+	FATFS_DIR* dp,		/* Pointer to the directory object */
 	int vol			/* Filtered by 0:file/directory or 1:volume label */
 )
@@ -1613,5 +1613,5 @@
 	FRESULT res;
 	BYTE a, c, *dir;
-#if _USE_LFN
+#if FF_USE_LFN
 	BYTE ord = 0xFF, sum = 0xFF;
 #endif
@@ -1625,6 +1625,6 @@
 		if (c == 0) { res = FR_NO_FILE; break; }	/* Reached to end of table */
 		a = dir[DIR_Attr] & AM_MASK;
-#if _USE_LFN	/* LFN configuration */
-		if (c == DDEM || (!_FS_RPATH && c == '.') || (int)((a & ~AM_ARC) == AM_VOL) != vol) {	/* An entry without valid data */
+#if FF_USE_LFN	/* LFN configuration */
+		if (c == DDEM || (!FF_FS_RPATH && c == '.') || (int)((a & ~AM_ARC) == AM_VOL) != vol) {	/* An entry without valid data */
 			ord = 0xFF;
 		} else {
@@ -1644,5 +1644,5 @@
 		}
 #else		/* Non LFN configuration */
-		if (c != DDEM && (_FS_RPATH || c != '.') && a != AM_LFN && (int)((a & ~AM_ARC) == AM_VOL) == vol)	/* Is it a valid entry? */
+		if (c != DDEM && (FF_FS_RPATH || c != '.') && a != AM_LFN && (int)((a & ~AM_ARC) == AM_VOL) == vol)	/* Is it a valid entry? */
 			break;
 #endif
@@ -1655,5 +1655,5 @@
 	return res;
 }
-#endif	/* _FS_MINIMIZE <= 1 || _USE_LABEL || _FS_RPATH >= 2 */
+#endif	/* FF_FS_MINIMIZE <= 1 || FF_USE_LABEL || FF_FS_RPATH >= 2 */
 
 
@@ -1663,12 +1663,12 @@
 /* Register an object to the directory                                   */
 /*-----------------------------------------------------------------------*/
-#if !_FS_READONLY
+#if !FF_FS_READONLY
 static
 FRESULT dir_register (	/* FR_OK:succeeded, FR_DENIED:no free entry or too many SFN collision, FR_DISK_ERR:disk error */
-	DIR* dp				/* Target directory with object name to be created */
+	FATFS_DIR* dp				/* Target directory with object name to be created */
 )
 {
 	FRESULT res;
-#if _USE_LFN	/* LFN configuration */
+#if FF_USE_LFN	/* LFN configuration */
 	UINT n, nent;
 	BYTE sn[12], *fn, sum;
@@ -1679,5 +1679,5 @@
 	mem_cpy(sn, fn, 12);
 
-	if (_FS_RPATH && (sn[NSFLAG] & NS_DOT))		/* Cannot create dot entry */
+	if (FF_FS_RPATH && (sn[NSFLAG] & NS_DOT))		/* Cannot create dot entry */
 		return FR_INVALID_NAME;
 
@@ -1724,5 +1724,5 @@
 			mem_set(dp->dir, 0, SZ_DIRE);	/* Clean the entry */
 			mem_cpy(dp->dir, dp->fn, 11);	/* Put SFN */
-#if _USE_LFN
+#if FF_USE_LFN
 			dp->dir[DIR_NTres] = dp->fn[NSFLAG] & (NS_BODY | NS_EXT);	/* Put NT flag */
 #endif
@@ -1733,5 +1733,5 @@
 	return res;
 }
-#endif /* !_FS_READONLY */
+#endif /* !FF_FS_READONLY */
 
 
@@ -1741,12 +1741,12 @@
 /* Remove an object from the directory                                   */
 /*-----------------------------------------------------------------------*/
-#if !_FS_READONLY && !_FS_MINIMIZE
+#if !FF_FS_READONLY && !FF_FS_MINIMIZE
 static
 FRESULT dir_remove (	/* FR_OK:Succeeded, FR_DISK_ERR:A disk error */
-	DIR* dp				/* Directory object pointing the entry to be removed */
+	FATFS_DIR* dp				/* Directory object pointing the entry to be removed */
 )
 {
 	FRESULT res;
-#if _USE_LFN	/* LFN configuration */
+#if FF_USE_LFN	/* LFN configuration */
 	UINT i;
 
@@ -1780,5 +1780,5 @@
 	return res;
 }
-#endif /* !_FS_READONLY */
+#endif /* !FF_FS_READONLY */
 
 
@@ -1788,8 +1788,8 @@
 /* Get file information from directory entry                             */
 /*-----------------------------------------------------------------------*/
-#if _FS_MINIMIZE <= 1 || _FS_RPATH >= 2
+#if FF_FS_MINIMIZE <= 1 || FF_FS_RPATH >= 2
 static
 void get_fileinfo (		/* No return code */
-	DIR* dp,			/* Pointer to the directory object */
+	FATFS_DIR* dp,			/* Pointer to the directory object */
 	FILINFO* fno	 	/* Pointer to the file information to be filled */
 )
@@ -1798,8 +1798,8 @@
 	TCHAR *p, c;
 	BYTE *dir;
-#if _USE_LFN
+#if FF_USE_LFN
 	WCHAR w, *lfn;
 #endif
-#if _CODE_PAGE == 65001
+#if FF_CODE_PAGE == 65001
 	unsigned char utf8_code[6];
 	int code_size;
@@ -1815,8 +1815,8 @@
 			if (c == RDDEM) c = (TCHAR)DDEM;	/* Restore replaced DDEM character */
 			if (i == 9) *p++ = '.';				/* Insert a . if extension is exist */
-#if _USE_LFN
+#if FF_USE_LFN
 			if (IsUpper(c) && (dir[DIR_NTres] & (i >= 9 ? NS_EXT : NS_BODY)))
 				c += 0x20;			/* To lower */
-#if _LFN_UNICODE
+#if FF_LFN_UNICODE
 			if (IsDBCS1(c) && i != 8 && i != 11 && IsDBCS2(dir[i]))
 				c = c << 8 | dir[i++];
@@ -1834,5 +1834,5 @@
 	*p = 0;		/* Terminate SFN string by a \0 */
 
-#if _USE_LFN
+#if FF_USE_LFN
 	if (fno->lfname) {
 		i = 0; p = fno->lfname;
@@ -1840,6 +1840,6 @@
 			lfn = dp->lfn;
 			while ((w = *lfn++) != 0) {		/* Get an LFN character */
-#if !_LFN_UNICODE
-#if _CODE_PAGE == 65001
+#if !FF_LFN_UNICODE
+#if FF_CODE_PAGE == 65001
 				Utf16_to_Utf8(utf8_code, &code_size, w);
 				for (int j = 0; j < code_size - 1; j++) {
@@ -1862,5 +1862,5 @@
 #endif
 }
-#endif /* _FS_MINIMIZE <= 1 || _FS_RPATH >= 2 */
+#endif /* FF_FS_MINIMIZE <= 1 || FF_FS_RPATH >= 2 */
 
 
@@ -1870,5 +1870,5 @@
 /* Pattern matching                                                      */
 /*-----------------------------------------------------------------------*/
-#if _USE_FIND && _FS_MINIMIZE <= 1
+#if FF_USE_FIND && FF_FS_MINIMIZE <= 1
 static
 WCHAR get_achar (		/* Get a character and advances ptr 1 or 2 */
@@ -1878,6 +1878,6 @@
 	WCHAR chr;
 
-#if !_LFN_UNICODE
-#if _CODE_PAGE == 65001
+#if !FF_LFN_UNICODE
+#if FF_CODE_PAGE == 65001
 	int code_size;
 	chr = Utf8_to_Utf16(*ptr, &code_size);
@@ -1938,5 +1938,5 @@
 	return 0;
 }
-#endif /* _USE_FIND && _FS_MINIMIZE <= 1 */
+#endif /* FF_USE_FIND && FF_FS_MINIMIZE <= 1 */
 
 
@@ -1949,14 +1949,14 @@
 static
 FRESULT create_name (	/* FR_OK: successful, FR_INVALID_NAME: could not create */
-	DIR* dp,			/* Pointer to the directory object */
+	FATFS_DIR* dp,			/* Pointer to the directory object */
 	const TCHAR** path	/* Pointer to pointer to the segment in the path string */
 )
 {
-#if _USE_LFN	/* LFN configuration */
+#if FF_USE_LFN	/* LFN configuration */
 	BYTE b, cf;
 	WCHAR w, *lfn;
 	UINT i, ni, si, di;
 	const TCHAR *p;
-#if _CODE_PAGE == 65001
+#if FF_CODE_PAGE == 65001
 	unsigned char utf8_code[6];
 	int code_size;
@@ -1969,8 +1969,8 @@
 		w = p[si++];					/* Get a character */
 		if (w < ' ' || w == '/' || w == '\\') break;	/* Break on end of segment */
-		if (di >= _MAX_LFN)				/* Reject too long name */
+		if (di >= FF_MAX_LFN)				/* Reject too long name */
 			return FR_INVALID_NAME;
-#if !_LFN_UNICODE
-#if _CODE_PAGE == 65001
+#if !FF_LFN_UNICODE
+#if FF_CODE_PAGE == 65001
 		w = Utf8_to_Utf16(&p[si - 1], &code_size);
 		si += code_size - 1;
@@ -1993,5 +1993,5 @@
 	*path = &p[si];						/* Return pointer to the next segment */
 	cf = (w < ' ') ? NS_LAST : 0;		/* Set last segment flag if end of path */
-#if _FS_RPATH
+#if FF_FS_RPATH
 	if ((di == 1 && lfn[di - 1] == '.') ||
 		(di == 2 && lfn[di - 1] == '.' && lfn[di - 2] == '.')) {	/* Is this segment a dot entry? */
@@ -2040,5 +2040,5 @@
 			if (w) w = ExCvt[w - 0x80];	/* Convert extended character to upper (SBCS) */
 #else
-#if _CODE_PAGE == 65001
+#if FF_CODE_PAGE == 65001
 			Utf16_to_Utf8(utf8_code, &code_size, ff_wtoupper(w));
 #else
@@ -2048,10 +2048,10 @@
 			cf |= NS_LFN;				/* Force create LFN entry */
 		}
-#if _CODE_PAGE == 65001
+#if FF_CODE_PAGE == 65001
 		else
 			code_size = 1;
 #endif
 
-#if _CODE_PAGE == 65001
+#if FF_CODE_PAGE == 65001
 		if (code_size > 1) {		/* Is this DBC? (always false at SBCS cfg) */
 			if (i >= ni - 1) {
@@ -2126,5 +2126,5 @@
 	mem_set(sfn, ' ', 11);
 	si = i = b = 0; ni = 8;
-#if _FS_RPATH
+#if FF_FS_RPATH
 	if (p[si] == '.') { /* Is this a dot entry? */
 		for (;;) {
@@ -2201,5 +2201,5 @@
 static
 FRESULT follow_path (	/* FR_OK(0): successful, !=0: error code */
-	DIR* dp,			/* Directory object to return last directory and found object */
+	FATFS_DIR* dp,			/* Directory object to return last directory and found object */
 	const TCHAR* path	/* Full-path string to find a file or directory */
 )
@@ -2209,5 +2209,5 @@
 
 
-#if _FS_RPATH
+#if FF_FS_RPATH
 	if (*path == '/' || *path == '\\') {	/* There is a heading separator */
 		path++;	dp->sclust = 0;				/* Strip it and start from the root directory */
@@ -2232,5 +2232,5 @@
 			if (res != FR_OK) {				/* Failed to find the object */
 				if (res == FR_NO_FILE) {	/* Object is not found */
-					if (_FS_RPATH && (ns & NS_DOT)) {	/* If dot entry is not exist, */
+					if (FF_FS_RPATH && (ns & NS_DOT)) {	/* If dot entry is not exist, */
 						dp->sclust = 0; dp->dir = 0;	/* it is the root directory and stay there */
 						if (!(ns & NS_LAST)) continue;	/* Continue to follow if not last segment */
@@ -2269,6 +2269,6 @@
 	UINT i;
 	int vol = -1;
-#if _STR_VOLUME_ID		/* Find string drive id */
-	static const char* const str[] = {_VOLUME_STRS};
+#if FF_STR_VOLUME_ID		/* Find string drive id */
+	static const char* const str[] = {FF_VOLUME_STRS};
 	const char *sp;
 	char c;
@@ -2278,15 +2278,15 @@
 
 	if (*path) {	/* If the pointer is not a null */
-		for (tt = *path; (UINT)*tt >= (_USE_LFN ? ' ' : '!') && *tt != ':'; tt++) ;	/* Find ':' in the path */
+		for (tt = *path; (UINT)*tt >= (FF_USE_LFN ? ' ' : '!') && *tt != ':'; tt++) ;	/* Find ':' in the path */
 		if (*tt == ':') {	/* If a ':' is exist in the path name */
 			tp = *path;
 			i = *tp++ - '0'; 
 			if (i < 10 && tp == tt) {	/* Is there a numeric drive id? */
-				if (i < _VOLUMES) {	/* If a drive id is found, get the value and strip it */
+				if (i < FF_VOLUMES) {	/* If a drive id is found, get the value and strip it */
 					vol = (int)i;
 					*path = ++tt;
 				}
 			}
-#if _STR_VOLUME_ID
+#if FF_STR_VOLUME_ID
 			 else {	/* No numeric drive number, find string drive id */
 				i = 0; tt++;
@@ -2297,6 +2297,6 @@
 						if (IsLower(tc)) tc -= 0x20;
 					} while (c && (TCHAR)c == tc);
-				} while ((c || tp != tt) && ++i < _VOLUMES);	/* Repeat for each id until pattern match */
-				if (i < _VOLUMES) {	/* If a drive id is found, get the value and strip it */
+				} while ((c || tp != tt) && ++i < FF_VOLUMES);	/* Repeat for each id until pattern match */
+				if (i < FF_VOLUMES) {	/* If a drive id is found, get the value and strip it */
 					vol = (int)i;
 					*path = tt;
@@ -2306,5 +2306,5 @@
 			return vol;
 		}
-#if _FS_RPATH && _VOLUMES >= 2
+#if FF_FS_RPATH && FF_VOLUMES >= 2
 		vol = CurrVol;	/* Current drive */
 #else
@@ -2381,5 +2381,5 @@
 		stat = disk_status(fs->drv);
 		if (!(stat & STA_NOINIT)) {		/* and the physical drive is kept initialized */
-			if (!_FS_READONLY && wmode && (stat & STA_PROTECT))	/* Check write protection if needed */
+			if (!FF_FS_READONLY && wmode && (stat & STA_PROTECT))	/* Check write protection if needed */
 				return FR_WRITE_PROTECTED;
 			return FR_OK;				/* The file system object is valid */
@@ -2395,9 +2395,9 @@
 	if (stat & STA_NOINIT)				/* Check if the initialization succeeded */
 		return FR_NOT_READY;			/* Failed to initialize due to no medium or hard error */
-	if (!_FS_READONLY && wmode && (stat & STA_PROTECT))	/* Check disk write protection if needed */
+	if (!FF_FS_READONLY && wmode && (stat & STA_PROTECT))	/* Check disk write protection if needed */
 		return FR_WRITE_PROTECTED;
-#if _MAX_SS != _MIN_SS						/* Get sector size (multiple sector size cfg only) */
+#if FF_MAX_SS != FF_MIN_SS						/* Get sector size (multiple sector size cfg only) */
 	if (disk_ioctl(fs->drv, GET_SECTOR_SIZE, &SS(fs)) != RES_OK
-		|| SS(fs) < _MIN_SS || SS(fs) > _MAX_SS) return FR_DISK_ERR;
+		|| SS(fs) < FF_MIN_SS || SS(fs) > FF_MAX_SS) return FR_DISK_ERR;
 #endif
 	/* Find an FAT partition on the drive. Supports only generic partitioning, FDISK and SFD. */
@@ -2448,5 +2448,5 @@
 
 	/* Determine the FAT sub type */
-	sysect = nrsv + fasize + fs->n_rootdir / (SS(fs) / SZ_DIRE);	/* RSV + FAT + DIR */
+	sysect = nrsv + fasize + fs->n_rootdir / (SS(fs) / SZ_DIRE);	/* RSV + FAT + FATFS_DIR */
 	if (tsect < sysect) return FR_NO_FILESYSTEM;		/* (Invalid volume size) */
 	nclst = (tsect - sysect) / fs->csize;				/* Number of clusters */
@@ -2474,5 +2474,5 @@
 		return FR_NO_FILESYSTEM;
 
-#if !_FS_READONLY
+#if !FF_FS_READONLY
 	/* Initialize cluster allocation information */
 	fs->last_clust = fs->free_clust = 0xFFFFFFFF;
@@ -2480,5 +2480,5 @@
 	/* Get fsinfo if available */
 	fs->fsi_flag = 0x80;
-#if (_FS_NOFSINFO & 3) != 3
+#if (FF_FS_NOFSINFO & 3) != 3
 	if (fmt == FS_FAT32				/* Enable FSINFO only if FAT32 and BPB_FSInfo == 1 */
 		&& LD_WORD(fs->win + BPB_FSInfo) == 1
@@ -2490,8 +2490,8 @@
 			&& LD_DWORD(fs->win + FSI_StrucSig) == 0x61417272)
 		{
-#if (_FS_NOFSINFO & 1) == 0
+#if (FF_FS_NOFSINFO & 1) == 0
 			fs->free_clust = LD_DWORD(fs->win + FSI_Free_Count);
 #endif
-#if (_FS_NOFSINFO & 2) == 0
+#if (FF_FS_NOFSINFO & 2) == 0
 			fs->last_clust = LD_DWORD(fs->win + FSI_Nxt_Free);
 #endif
@@ -2502,8 +2502,8 @@
 	fs->fs_type = fmt;	/* FAT sub-type */
 	fs->id = ++Fsid;	/* File system mount ID */
-#if _FS_RPATH
+#if FF_FS_RPATH
 	fs->cdir = 0;		/* Set current directory to root */
 #endif
-#if _FS_LOCK			/* Clear file lock semaphores */
+#if FF_FS_LOCK != 0			/* Clear file lock semaphores */
 	clear_lock(fs);
 #endif
@@ -2521,8 +2521,8 @@
 static
 FRESULT validate (	/* FR_OK(0): The object is valid, !=0: Invalid */
-	void* obj		/* Pointer to the object FIL/DIR to check validity */
-)
-{
-	FIL *fil = (FIL*)obj;	/* Assuming offset of .fs and .id in the FIL/DIR structure is identical */
+	void* obj		/* Pointer to the object FIL/FATFS_DIR to check validity */
+)
+{
+	FIL *fil = (FIL*)obj;	/* Assuming offset of .fs and .id in the FIL/FATFS_DIR structure is identical */
 
 
@@ -2567,8 +2567,8 @@
 
 	if (cfs) {
-#if _FS_LOCK
+#if FF_FS_LOCK != 0
 		clear_lock(cfs);
 #endif
-#if _FS_REENTRANT						/* Discard sync object of the current volume */
+#if FF_FS_REENTRANT						/* Discard sync object of the current volume */
 		if (!ff_del_syncobj(cfs->sobj)) return FR_INT_ERR;
 #endif
@@ -2578,5 +2578,5 @@
 	if (fs) {
 		fs->fs_type = 0;				/* Clear new fs object */
-#if _FS_REENTRANT						/* Create sync object for the new volume */
+#if FF_FS_REENTRANT						/* Create sync object for the new volume */
 		if (!ff_cre_syncobj((BYTE)vol, &fs->sobj)) return FR_INT_ERR;
 #endif
@@ -2604,8 +2604,8 @@
 {
 	FRESULT res;
-	DIR dj;
+	FATFS_DIR dj;
 	BYTE *dir;
 	DEFINE_NAMEBUF;
-#if !_FS_READONLY
+#if !FF_FS_READONLY
 	DWORD dw, cl;
 #endif
@@ -2616,6 +2616,6 @@
 
 	/* Get logical drive number */
-#if !_FS_READONLY
-	mode &= FA_READ | FA_WRITE | FA_CREATE_ALWAYS | FA_OPEN_ALWAYS | FA_CREATE_NEW;
+#if !FF_FS_READONLY
+	mode &= FA_READ | FA_WRITE | FA_CREATE_ALWAYS | FA_OPEN_ALWAYS | FA_CREATE_NEW | FA_OPEN_APPEND;
 	res = find_volume(&dj.fs, &path, (BYTE)(mode & ~FA_READ));
 #else
@@ -2627,9 +2627,9 @@
 		res = follow_path(&dj, path);	/* Follow the file path */
 		dir = dj.dir;
-#if !_FS_READONLY	/* R/W configuration */
+#if !FF_FS_READONLY	/* R/W configuration */
 		if (res == FR_OK) {
 			if (!dir)	/* Default directory itself */
 				res = FR_INVALID_NAME;
-#if _FS_LOCK
+#if FF_FS_LOCK != 0
 			else
 				res = chk_lock(&dj, (mode & ~FA_READ) ? 1 : 0);
@@ -2640,5 +2640,5 @@
 			if (res != FR_OK) {					/* No file, create new */
 				if (res == FR_NO_FILE)			/* There is no file to open, create a new entry */
-#if _FS_LOCK
+#if FF_FS_LOCK != 0
 					res = enq_lock() ? dir_register(&dj) : FR_TOO_MANY_OPEN_FILES;
 #else
@@ -2649,5 +2649,5 @@
 			}
 			else {								/* Any object is already existing */
-				if (dir[DIR_Attr] & (AM_RDO | AM_DIR)) {	/* Cannot overwrite it (R/O or DIR) */
+				if (dir[DIR_Attr] & (AM_RDO | AM_DIR)) {	/* Cannot overwrite it (R/O or FATFS_DIR) */
 					res = FR_DENIED;
 				} else {
@@ -2687,8 +2687,8 @@
 		if (res == FR_OK) {
 			if (mode & FA_CREATE_ALWAYS)		/* Set file change flag if created or overwritten */
-				mode |= FA__WRITTEN;
+				mode |= FA_MODIFIED;
 			fp->dir_sect = dj.fs->winsect;		/* Pointer to the directory entry */
 			fp->dir_ptr = dir;
-#if _FS_LOCK
+#if FF_FS_LOCK != 0
 			fp->lockid = inc_lock(&dj, (mode & ~FA_READ) ? 1 : 0);
 			if (!fp->lockid) res = FR_INT_ERR;
@@ -2716,5 +2716,5 @@
 			fp->fptr = 0;						/* File pointer */
 			fp->dsect = 0;
-#if _USE_FASTSEEK
+#if FF_USE_FASTSEEK
 			fp->cltbl = 0;						/* Normal seek mode */
 #endif
@@ -2766,5 +2766,5 @@
 					clst = fp->sclust;			/* Follow from the origin */
 				} else {						/* Middle or end of the file */
-#if _USE_FASTSEEK
+#if FF_USE_FASTSEEK
 					if (fp->cltbl)
 						clst = clmt_clust(fp, fp->fptr);	/* Get cluster# from the CLMT */
@@ -2786,10 +2786,10 @@
 				if (disk_read(fp->fs->drv, rbuff, sect, cc) != RES_OK)
 					ABORT(fp->fs, FR_DISK_ERR);
-#if !_FS_READONLY && _FS_MINIMIZE <= 2			/* Replace one of the read sectors with cached data if it contains a dirty sector */
-#if _FS_TINY
+#if !FF_FS_READONLY && FF_FS_MINIMIZE <= 2			/* Replace one of the read sectors with cached data if it contains a dirty sector */
+#if FF_FS_TINY
 				if (fp->fs->wflag && fp->fs->winsect - sect < cc)
 					mem_cpy(rbuff + ((fp->fs->winsect - sect) * SS(fp->fs)), fp->fs->win, SS(fp->fs));
 #else
-				if ((fp->flag & FA__DIRTY) && fp->dsect - sect < cc)
+				if ((fp->flag & FA_DIRTY) && fp->dsect - sect < cc)
 					mem_cpy(rbuff + ((fp->dsect - sect) * SS(fp->fs)), fp->buf, SS(fp->fs));
 #endif
@@ -2798,11 +2798,11 @@
 				continue;
 			}
-#if !_FS_TINY
+#if !FF_FS_TINY
 			if (fp->dsect != sect) {			/* Load data sector if not in cache */
-#if !_FS_READONLY
-				if (fp->flag & FA__DIRTY) {		/* Write-back dirty sector cache */
+#if !FF_FS_READONLY
+				if (fp->flag & FA_DIRTY) {		/* Write-back dirty sector cache */
 					if (disk_write(fp->fs->drv, fp->buf, fp->dsect, 1) != RES_OK)
 						ABORT(fp->fs, FR_DISK_ERR);
-					fp->flag &= ~FA__DIRTY;
+					fp->flag &= ~FA_DIRTY;
 				}
 #endif
@@ -2815,5 +2815,5 @@
 		rcnt = SS(fp->fs) - ((UINT)fp->fptr % SS(fp->fs));	/* Get partial sector data from sector buffer */
 		if (rcnt > btr) rcnt = btr;
-#if _FS_TINY
+#if FF_FS_TINY
 		if (move_window(fp->fs, fp->dsect) != FR_OK)		/* Move sector window */
 			ABORT(fp->fs, FR_DISK_ERR);
@@ -2830,5 +2830,5 @@
 
 
-#if !_FS_READONLY
+#if !FF_FS_READONLY
 /*-----------------------------------------------------------------------*/
 /* Write File                                                            */
@@ -2869,5 +2869,5 @@
 						clst = create_chain(fp->fs, 0);	/* Create a new cluster chain */
 				} else {					/* Middle or end of the file */
-#if _USE_FASTSEEK
+#if FF_USE_FASTSEEK
 					if (fp->cltbl)
 						clst = clmt_clust(fp, fp->fptr);	/* Get cluster# from the CLMT */
@@ -2882,12 +2882,12 @@
 				if (fp->sclust == 0) fp->sclust = clst;	/* Set start cluster if the first write */
 			}
-#if _FS_TINY
+#if FF_FS_TINY
 			if (fp->fs->winsect == fp->dsect && sync_window(fp->fs))	/* Write-back sector cache */
 				ABORT(fp->fs, FR_DISK_ERR);
 #else
-			if (fp->flag & FA__DIRTY) {		/* Write-back sector cache */
+			if (fp->flag & FA_DIRTY) {		/* Write-back sector cache */
 				if (disk_write(fp->fs->drv, fp->buf, fp->dsect, 1) != RES_OK)
 					ABORT(fp->fs, FR_DISK_ERR);
-				fp->flag &= ~FA__DIRTY;
+				fp->flag &= ~FA_DIRTY;
 			}
 #endif
@@ -2901,6 +2901,6 @@
 				if (disk_write(fp->fs->drv, wbuff, sect, cc) != RES_OK)
 					ABORT(fp->fs, FR_DISK_ERR);
-#if _FS_MINIMIZE <= 2
-#if _FS_TINY
+#if FF_FS_MINIMIZE <= 2
+#if FF_FS_TINY
 				if (fp->fs->winsect - sect < cc) {	/* Refill sector cache if it gets invalidated by the direct write */
 					mem_cpy(fp->fs->win, wbuff + ((fp->fs->winsect - sect) * SS(fp->fs)), SS(fp->fs));
@@ -2910,5 +2910,5 @@
 				if (fp->dsect - sect < cc) { /* Refill sector cache if it gets invalidated by the direct write */
 					mem_cpy(fp->buf, wbuff + ((fp->dsect - sect) * SS(fp->fs)), SS(fp->fs));
-					fp->flag &= ~FA__DIRTY;
+					fp->flag &= ~FA_DIRTY;
 				}
 #endif
@@ -2917,5 +2917,5 @@
 				continue;
 			}
-#if _FS_TINY
+#if FF_FS_TINY
 			if (fp->fptr >= fp->fsize) {	/* Avoid silly cache filling at growing edge */
 				if (sync_window(fp->fs)) ABORT(fp->fs, FR_DISK_ERR);
@@ -2933,5 +2933,5 @@
 		wcnt = SS(fp->fs) - ((UINT)fp->fptr % SS(fp->fs));/* Put partial sector into file I/O buffer */
 		if (wcnt > btw) wcnt = btw;
-#if _FS_TINY
+#if FF_FS_TINY
 		if (move_window(fp->fs, fp->dsect) != FR_OK)	/* Move sector window */
 			ABORT(fp->fs, FR_DISK_ERR);
@@ -2940,10 +2940,10 @@
 #else
 		mem_cpy(&fp->buf[fp->fptr % SS(fp->fs)], wbuff, wcnt);	/* Fit partial sector */
-		fp->flag |= FA__DIRTY;
+		fp->flag |= FA_DIRTY;
 #endif
 	}
 
 	if (fp->fptr > fp->fsize) fp->fsize = fp->fptr;	/* Update file size if needed */
-	fp->flag |= FA__WRITTEN;						/* Set file change flag */
+	fp->flag |= FA_MODIFIED;						/* Set file change flag */
 
 	LEAVE_FF(fp->fs, FR_OK);
@@ -2968,10 +2968,10 @@
 	res = validate(fp);					/* Check validity of the object */
 	if (res == FR_OK) {
-		if (fp->flag & FA__WRITTEN) {	/* Is there any change to the file? */
-#if !_FS_TINY
-			if (fp->flag & FA__DIRTY) {	/* Write-back cached data if needed */
+		if (fp->flag & FA_MODIFIED) {	/* Is there any change to the file? */
+#if !FF_FS_TINY
+			if (fp->flag & FA_DIRTY) {	/* Write-back cached data if needed */
 				if (disk_write(fp->fs->drv, fp->buf, fp->dsect, 1) != RES_OK)
 					LEAVE_FF(fp->fs, FR_DISK_ERR);
-				fp->flag &= ~FA__DIRTY;
+				fp->flag &= ~FA_DIRTY;
 			}
 #endif
@@ -2986,5 +2986,5 @@
 				ST_DWORD(dir + DIR_WrtTime, tm);
 				ST_WORD(dir + DIR_LstAccDate, 0);
-				fp->flag &= ~FA__WRITTEN;
+				fp->flag &= ~FA_MODIFIED;
 				fp->fs->wflag = 1;
 				res = sync_fs(fp->fs);
@@ -2996,5 +2996,5 @@
 }
 
-#endif /* !_FS_READONLY */
+#endif /* !FF_FS_READONLY */
 
 
@@ -3012,5 +3012,5 @@
 
 
-#if !_FS_READONLY
+#if !FF_FS_READONLY
 	res = f_sync(fp);					/* Flush cached data */
 	if (res == FR_OK)
@@ -3019,13 +3019,13 @@
 		res = validate(fp);				/* Lock volume */
 		if (res == FR_OK) {
-#if _FS_REENTRANT
+#if FF_FS_REENTRANT
 			FATFS *fs = fp->fs;
 #endif
-#if _FS_LOCK
+#if FF_FS_LOCK != 0
 			res = dec_lock(fp->lockid);	/* Decrement file open counter */
 			if (res == FR_OK)
 #endif
 				fp->fs = 0;				/* Invalidate file object */
-#if _FS_REENTRANT
+#if FF_FS_REENTRANT
 			unlock_fs(fs, FR_OK);		/* Unlock volume */
 #endif
@@ -3042,6 +3042,6 @@
 /*-----------------------------------------------------------------------*/
 
-#if _FS_RPATH >= 1
-#if _VOLUMES >= 2
+#if FF_FS_RPATH >= 1
+#if FF_VOLUMES >= 2
 FRESULT f_chdrive (
 	const TCHAR* path		/* Drive number */
@@ -3066,5 +3066,5 @@
 {
 	FRESULT res;
-	DIR dj;
+	FATFS_DIR dj;
 	DEFINE_NAMEBUF;
 
@@ -3093,5 +3093,5 @@
 
 
-#if _FS_RPATH >= 2
+#if FF_FS_RPATH >= 2
 FRESULT f_getcwd (
 	TCHAR* buff,	/* Pointer to the directory path */
@@ -3100,5 +3100,5 @@
 {
 	FRESULT res;
-	DIR dj;
+	FATFS_DIR dj;
 	UINT i, n;
 	DWORD ccl;
@@ -3131,5 +3131,5 @@
 			if (res == FR_NO_FILE) res = FR_INT_ERR;/* It cannot be 'not found'. */
 			if (res != FR_OK) break;
-#if _USE_LFN
+#if FF_USE_LFN
 			fno.lfname = buff;
 			fno.lfsize = i;
@@ -3137,5 +3137,5 @@
 			get_fileinfo(&dj, &fno);		/* Get the directory name and push it to the buffer */
 			tp = fno.fname;
-#if _USE_LFN
+#if FF_USE_LFN
 			if (*buff) tp = buff;
 #endif
@@ -3149,5 +3149,5 @@
 		tp = buff;
 		if (res == FR_OK) {
-#if _VOLUMES >= 2
+#if FF_VOLUMES >= 2
 			*tp++ = '0' + CurrVol;			/* Put drive number */
 			*tp++ = ':';
@@ -3167,10 +3167,10 @@
 	LEAVE_FF(dj.fs, res);
 }
-#endif /* _FS_RPATH >= 2 */
-#endif /* _FS_RPATH >= 1 */
-
-
-
-#if _FS_MINIMIZE <= 2
+#endif /* FF_FS_RPATH >= 2 */
+#endif /* FF_FS_RPATH >= 1 */
+
+
+
+#if FF_FS_MINIMIZE <= 2
 /*-----------------------------------------------------------------------*/
 /* Seek File R/W Pointer                                                 */
@@ -3184,5 +3184,5 @@
 	FRESULT res;
 	DWORD clst, bcs, nsect, ifptr;
-#if _USE_FASTSEEK
+#if FF_USE_FASTSEEK
 	DWORD cl, pcl, ncl, tcl, dsc, tlen, ulen, *tbl;
 #endif
@@ -3194,5 +3194,5 @@
 		LEAVE_FF(fp->fs, (FRESULT)fp->err);
 
-#if _USE_FASTSEEK
+#if FF_USE_FASTSEEK
 	if (fp->cltbl) {	/* Fast seek */
 		if (ofs == CREATE_LINKMAP) {	/* Create CLMT */
@@ -3231,10 +3231,10 @@
 				dsc += (ofs - 1) / SS(fp->fs) & (fp->fs->csize - 1);
 				if (fp->fptr % SS(fp->fs) && dsc != fp->dsect) {	/* Refill sector cache if needed */
-#if !_FS_TINY
-#if !_FS_READONLY
-					if (fp->flag & FA__DIRTY) {		/* Write-back dirty sector cache */
+#if !FF_FS_TINY
+#if !FF_FS_READONLY
+					if (fp->flag & FA_DIRTY) {		/* Write-back dirty sector cache */
 						if (disk_write(fp->fs->drv, fp->buf, fp->dsect, 1) != RES_OK)
 							ABORT(fp->fs, FR_DISK_ERR);
-						fp->flag &= ~FA__DIRTY;
+						fp->flag &= ~FA_DIRTY;
 					}
 #endif
@@ -3252,5 +3252,5 @@
 	{
 		if (ofs > fp->fsize					/* In read-only mode, clip offset with the file size */
-#if !_FS_READONLY
+#if !FF_FS_READONLY
 			 && !(fp->flag & FA_WRITE)
 #endif
@@ -3268,5 +3268,5 @@
 			} else {									/* When seek to back cluster, */
 				clst = fp->sclust;						/* start from the first cluster */
-#if !_FS_READONLY
+#if !FF_FS_READONLY
 				if (clst == 0) {						/* If no cluster chain, create a new chain */
 					clst = create_chain(fp->fs, 0);
@@ -3280,5 +3280,5 @@
 			if (clst != 0) {
 				while (ofs > bcs) {						/* Cluster following loop */
-#if !_FS_READONLY
+#if !FF_FS_READONLY
 					if (fp->flag & FA_WRITE) {			/* Check if in write mode or not */
 						clst = create_chain(fp->fs, clst);	/* Force stretch if in write mode */
@@ -3304,10 +3304,10 @@
 		}
 		if (fp->fptr % SS(fp->fs) && nsect != fp->dsect) {	/* Fill sector cache if needed */
-#if !_FS_TINY
-#if !_FS_READONLY
-			if (fp->flag & FA__DIRTY) {			/* Write-back dirty sector cache */
+#if !FF_FS_TINY
+#if !FF_FS_READONLY
+			if (fp->flag & FA_DIRTY) {			/* Write-back dirty sector cache */
 				if (disk_write(fp->fs->drv, fp->buf, fp->dsect, 1) != RES_OK)
 					ABORT(fp->fs, FR_DISK_ERR);
-				fp->flag &= ~FA__DIRTY;
+				fp->flag &= ~FA_DIRTY;
 			}
 #endif
@@ -3317,8 +3317,8 @@
 			fp->dsect = nsect;
 		}
-#if !_FS_READONLY
+#if !FF_FS_READONLY
 		if (fp->fptr > fp->fsize) {			/* Set file change flag if the file size is extended */
 			fp->fsize = fp->fptr;
-			fp->flag |= FA__WRITTEN;
+			fp->flag |= FA_MODIFIED;
 		}
 #endif
@@ -3342,5 +3342,5 @@
 }
 
-#if _FS_MINIMIZE <= 1
+#if FF_FS_MINIMIZE <= 1
 /*-----------------------------------------------------------------------*/
 /* Create a Directory Object                                             */
@@ -3348,5 +3348,5 @@
 
 FRESULT f_opendir (
-	DIR* dp,			/* Pointer to directory object to create */
+	FATFS_DIR* dp,			/* Pointer to directory object to create */
 	const TCHAR* path	/* Pointer to the directory path */
 )
@@ -3376,5 +3376,5 @@
 				dp->id = fs->id;
 				res = dir_sdi(dp, 0);			/* Rewind directory */
-#if _FS_LOCK
+#if FF_FS_LOCK != 0
 				if (res == FR_OK) {
 					if (dp->sclust) {
@@ -3404,5 +3404,5 @@
 
 FRESULT f_closedir (
-	DIR *dp		/* Pointer to the directory object to be closed */
+	FATFS_DIR *dp		/* Pointer to the directory object to be closed */
 )
 {
@@ -3412,8 +3412,8 @@
 	res = validate(dp);
 	if (res == FR_OK) {
-#if _FS_REENTRANT
+#if FF_FS_REENTRANT
 		FATFS *fs = dp->fs;
 #endif
-#if _FS_LOCK
+#if FF_FS_LOCK != 0
 		if (dp->lockid)				/* Decrement sub-directory open counter */
 			res = dec_lock(dp->lockid);
@@ -3421,5 +3421,5 @@
 #endif
 			dp->fs = 0;				/* Invalidate directory object */
-#if _FS_REENTRANT
+#if FF_FS_REENTRANT
 		unlock_fs(fs, FR_OK);		/* Unlock volume */
 #endif
@@ -3436,5 +3436,5 @@
 
 FRESULT f_readdir (
-	DIR* dp,			/* Pointer to the open directory object */
+	FATFS_DIR* dp,			/* Pointer to the open directory object */
 	FILINFO* fno		/* Pointer to file information to return */
 )
@@ -3472,5 +3472,5 @@
 
 
-#if _USE_FIND
+#if FF_USE_FIND
 /*-----------------------------------------------------------------------*/
 /* Find next file                                                        */
@@ -3478,5 +3478,5 @@
 
 FRESULT f_findnext (
-	DIR* dp,		/* Pointer to the open directory object */
+	FATFS_DIR* dp,		/* Pointer to the open directory object */
 	FILINFO* fno	/* Pointer to the file information structure */
 )
@@ -3488,5 +3488,5 @@
 		res = f_readdir(dp, fno);		/* Get a directory item */
 		if (res != FR_OK || !fno || !fno->fname[0]) break;	/* Terminate if any error or end of directory */
-#if _USE_LFN
+#if FF_USE_LFN
 		if (fno->lfname && pattern_matching(dp->pat, fno->lfname, 0, 0)) break;	/* Test for LFN if exist */
 #endif
@@ -3504,5 +3504,5 @@
 
 FRESULT f_findfirst (
-	DIR* dp,				/* Pointer to the blank directory object */
+	FATFS_DIR* dp,				/* Pointer to the blank directory object */
 	FILINFO* fno,			/* Pointer to the file information structure */
 	const TCHAR* path,		/* Pointer to the directory to open */
@@ -3520,9 +3520,9 @@
 }
 
-#endif	/* _USE_FIND */
-
-
-
-#if _FS_MINIMIZE == 0
+#endif	/* FF_USE_FIND */
+
+
+
+#if FF_FS_MINIMIZE == 0
 /*-----------------------------------------------------------------------*/
 /* Get File Status                                                       */
@@ -3535,5 +3535,5 @@
 {
 	FRESULT res;
-	DIR dj;
+	FATFS_DIR dj;
 	DEFINE_NAMEBUF;
 
@@ -3559,5 +3559,5 @@
 
 
-#if !_FS_READONLY
+#if !FF_FS_READONLY
 /*-----------------------------------------------------------------------*/
 /* Get Number of Free Clusters                                           */
@@ -3650,5 +3650,5 @@
 		if (fp->fsize > fp->fptr) {
 			fp->fsize = fp->fptr;	/* Set file size to current R/W point */
-			fp->flag |= FA__WRITTEN;
+			fp->flag |= FA_MODIFIED;
 			if (fp->fptr == 0) {	/* When set file size to zero, remove entire cluster chain */
 				res = remove_chain(fp->fs, fp->sclust);
@@ -3664,10 +3664,10 @@
 				}
 			}
-#if !_FS_TINY
-			if (res == FR_OK && (fp->flag & FA__DIRTY)) {
+#if !FF_FS_TINY
+			if (res == FR_OK && (fp->flag & FA_DIRTY)) {
 				if (disk_write(fp->fs->drv, fp->buf, fp->dsect, 1) != RES_OK)
 					res = FR_DISK_ERR;
 				else
-					fp->flag &= ~FA__DIRTY;
+					fp->flag &= ~FA_DIRTY;
 			}
 #endif
@@ -3691,5 +3691,5 @@
 {
 	FRESULT res;
-	DIR dj, sdj;
+	FATFS_DIR dj, sdj;
 	BYTE *dir;
 	DWORD dclst = 0;
@@ -3702,7 +3702,7 @@
 		INIT_BUF(dj);
 		res = follow_path(&dj, path);		/* Follow the file path */
-		if (_FS_RPATH && res == FR_OK && (dj.fn[NSFLAG] & NS_DOT))
+		if (FF_FS_RPATH && res == FR_OK && (dj.fn[NSFLAG] & NS_DOT))
 			res = FR_INVALID_NAME;			/* Cannot remove dot entry */
-#if _FS_LOCK
+#if FF_FS_LOCK != 0
 		if (res == FR_OK) res = chk_lock(&dj, 2);	/* Cannot remove open object */
 #endif
@@ -3718,5 +3718,5 @@
 				dclst = ld_clust(dj.fs, dir);
 				if (dclst && (dir[DIR_Attr] & AM_DIR)) {	/* Is it a sub-directory ? */
-#if _FS_RPATH
+#if FF_FS_RPATH
 					if (dclst == dj.fs->cdir) {		 		/* Is it the current directory? */
 						res = FR_DENIED;
@@ -3724,5 +3724,5 @@
 #endif
 					{
-						mem_cpy(&sdj, &dj, sizeof (DIR));	/* Open the sub-directory */
+						mem_cpy(&sdj, &dj, sizeof (FATFS_DIR));	/* Open the sub-directory */
 						sdj.sclust = dclst;
 						res = dir_sdi(&sdj, 2);
@@ -3760,5 +3760,5 @@
 {
 	FRESULT res;
-	DIR dj;
+	FATFS_DIR dj;
 	BYTE *dir, n;
 	DWORD dsc, dcl, pcl, tm = GET_FATTIME();
@@ -3772,5 +3772,5 @@
 		res = follow_path(&dj, path);			/* Follow the file path */
 		if (res == FR_OK) res = FR_EXIST;		/* Any object with same name is already existing */
-		if (_FS_RPATH && res == FR_NO_FILE && (dj.fn[NSFLAG] & NS_DOT))
+		if (FF_FS_RPATH && res == FR_NO_FILE && (dj.fn[NSFLAG] & NS_DOT))
 			res = FR_INVALID_NAME;
 		if (res == FR_NO_FILE) {				/* Can create a new directory */
@@ -3836,5 +3836,5 @@
 {
 	FRESULT res;
-	DIR dj;
+	FATFS_DIR dj;
 	BYTE *dir;
 	DEFINE_NAMEBUF;
@@ -3846,5 +3846,5 @@
 		res = follow_path(&dj, path);		/* Follow the file path */
 		FREE_BUF();
-		if (_FS_RPATH && res == FR_OK && (dj.fn[NSFLAG] & NS_DOT))
+		if (FF_FS_RPATH && res == FR_OK && (dj.fn[NSFLAG] & NS_DOT))
 			res = FR_INVALID_NAME;
 		if (res == FR_OK) {
@@ -3877,5 +3877,5 @@
 {
 	FRESULT res;
-	DIR djo, djn;
+	FATFS_DIR djo, djn;
 	BYTE buf[21], *dir;
 	DWORD dw;
@@ -3890,7 +3890,7 @@
 		INIT_BUF(djo);
 		res = follow_path(&djo, path_old);		/* Check old object */
-		if (_FS_RPATH && res == FR_OK && (djo.fn[NSFLAG] & NS_DOT))
+		if (FF_FS_RPATH && res == FR_OK && (djo.fn[NSFLAG] & NS_DOT))
 			res = FR_INVALID_NAME;
-#if _FS_LOCK
+#if FF_FS_LOCK != 0
 		if (res == FR_OK) res = chk_lock(&djo, 2);
 #endif
@@ -3900,5 +3900,5 @@
 			} else {
 				mem_cpy(buf, djo.dir + DIR_Attr, 21);	/* Save information about object except name */
-				mem_cpy(&djn, &djo, sizeof (DIR));		/* Duplicate the directory object */
+				mem_cpy(&djn, &djo, sizeof (FATFS_DIR));		/* Duplicate the directory object */
 				if (get_ldnumber(&path_new) >= 0)		/* Snip drive number off and ignore it */
 					res = follow_path(&djn, path_new);	/* and make sure if new object name is not conflicting */
@@ -3909,6 +3909,6 @@
 					dir = djn.dir;
 					if (dir[DIR_Attr] & AM_DIR) {	/* The new object is a directory */
-						temp_new_path = (TCHAR *)ff_memalloc((_MAX_LFN + 1) * sizeof(WCHAR));
-						ntstdio_snprintf(temp_new_path, _MAX_LFN, "%s/%s", path_new, basename((char *)path_old));
+						temp_new_path = (TCHAR *)ff_memalloc((FF_MAX_LFN + 1) * sizeof(WCHAR));
+						snprintf(temp_new_path, FF_MAX_LFN, "%s/%s", path_new, basename((char *)path_old));
 						res = follow_path(&djn, temp_new_path);
 					}
@@ -3966,5 +3966,5 @@
 {
 	FRESULT res;
-	DIR dj;
+	FATFS_DIR dj;
 	BYTE *dir;
 	DEFINE_NAMEBUF;
@@ -3977,5 +3977,5 @@
 		res = follow_path(&dj, path);	/* Follow the file path */
 		FREE_BUF();
-		if (_FS_RPATH && res == FR_OK && (dj.fn[NSFLAG] & NS_DOT))
+		if (FF_FS_RPATH && res == FR_OK && (dj.fn[NSFLAG] & NS_DOT))
 			res = FR_INVALID_NAME;
 		if (res == FR_OK) {
@@ -3995,13 +3995,13 @@
 }
 
-#endif /* !_FS_READONLY */
-#endif /* _FS_MINIMIZE == 0 */
-#endif /* _FS_MINIMIZE <= 1 */
-#endif /* _FS_MINIMIZE <= 2 */
-
-
-
-
-#if _USE_LABEL
+#endif /* !FF_FS_READONLY */
+#endif /* FF_FS_MINIMIZE == 0 */
+#endif /* FF_FS_MINIMIZE <= 1 */
+#endif /* FF_FS_MINIMIZE <= 2 */
+
+
+
+
+#if FF_USE_LABEL
 /*-----------------------------------------------------------------------*/
 /* Get volume label                                                      */
@@ -4015,7 +4015,7 @@
 {
 	FRESULT res;
-	DIR dj;
+	FATFS_DIR dj;
 	UINT i, j;
-#if _USE_LFN && _LFN_UNICODE
+#if FF_USE_LFN && FF_LFN_UNICODE
 	WCHAR w;
 #endif
@@ -4032,5 +4032,5 @@
 			res = dir_read(&dj, 1);		/* Get an entry with AM_VOL */
 			if (res == FR_OK) {			/* A volume label is exist */
-#if _USE_LFN && _LFN_UNICODE
+#if FF_USE_LFN && FF_LFN_UNICODE
 				i = j = 0;
 				do {
@@ -4070,5 +4070,5 @@
 
 
-#if !_FS_READONLY
+#if !FF_FS_READONLY
 /*-----------------------------------------------------------------------*/
 /* Set volume label                                                      */
@@ -4080,10 +4080,10 @@
 {
 	FRESULT res;
-	DIR dj;
+	FATFS_DIR dj;
 	BYTE vn[11];
 	UINT i, j, sl;
 	WCHAR w;
 	DWORD tm;
-#if _CODE_PAGE == 65001
+#if FF_CODE_PAGE == 65001
 	int code_size;
 	unsigned char utf8_code[6];
@@ -4101,5 +4101,5 @@
 		i = j = 0;
 		do {
-#if _CODE_PAGE == 65001
+#if FF_CODE_PAGE == 65001
 			w = ff_wtoupper(Utf8_to_Utf16(&label[i], &code_size));
 			i += code_size;
@@ -4110,5 +4110,5 @@
 				vn[j++] = utf8_code[k];
 #else
-#if _USE_LFN && _LFN_UNICODE
+#if FF_USE_LFN && FF_LFN_UNICODE
 			w = ff_convert(ff_wtoupper(label[i++]), 0);
 #else
@@ -4116,5 +4116,5 @@
 			if (IsDBCS1(w))
 				w = (j < 10 && i < sl && IsDBCS2(label[i])) ? w << 8 | (BYTE)label[i++] : 0;
-#if _USE_LFN
+#if FF_USE_LFN
 			w = ff_convert(ff_wtoupper(ff_convert(w, 1)), 0);
 #else
@@ -4174,6 +4174,6 @@
 }
 
-#endif /* !_FS_READONLY */
-#endif /* _USE_LABEL */
+#endif /* !FF_FS_READONLY */
+#endif /* FF_USE_LABEL */
 
 
@@ -4182,5 +4182,5 @@
 /* Forward data to the stream directly (available on only tiny cfg)      */
 /*-----------------------------------------------------------------------*/
-#if _USE_FORWARD && _FS_TINY
+#if FF_USE_FORWARD && FF_FS_TINY
 
 FRESULT f_forward (
@@ -4235,9 +4235,9 @@
 	LEAVE_FF(fp->fs, FR_OK);
 }
-#endif /* _USE_FORWARD */
-
-
-
-#if _USE_MKFS && !_FS_READONLY
+#endif /* FF_USE_FORWARD */
+
+
+
+#if FF_USE_MKFS && !FF_FS_READONLY
 /*-----------------------------------------------------------------------*/
 /* Create file system on the logical drive                               */
@@ -4263,5 +4263,5 @@
 	FATFS *fs;
 	DSTATUS stat;
-#if _USE_TRIM
+#if FF_USE_TRIM
 	DWORD eb[2];
 #endif
@@ -4282,9 +4282,9 @@
 	if (stat & STA_NOINIT) return FR_NOT_READY;
 	if (stat & STA_PROTECT) return FR_WRITE_PROTECTED;
-#if _MAX_SS != _MIN_SS		/* Get disk sector size */
-	if (disk_ioctl(pdrv, GET_SECTOR_SIZE, &SS(fs)) != RES_OK || SS(fs) > _MAX_SS || SS(fs) < _MIN_SS)
+#if FF_MAX_SS != FF_MIN_SS		/* Get disk sector size */
+	if (disk_ioctl(pdrv, GET_SECTOR_SIZE, &SS(fs)) != RES_OK || SS(fs) > FF_MAX_SS || SS(fs) < FF_MIN_SS)
 		return FR_DISK_ERR;
 #endif
-	if (_MULTI_PARTITION && part) {
+	if (FF_MULTI_PARTITION && part) {
 		/* Get partition information from partition table in the MBR */
 		if (disk_read(pdrv, fs->win, 0, 1) != RES_OK) return FR_DISK_ERR;
@@ -4308,5 +4308,5 @@
 		au = cst[i];
 	}
-	if (au >= _MIN_SS) au /= SS(fs);	/* Number of sectors per cluster */
+	if (au >= FF_MIN_SS) au /= SS(fs);	/* Number of sectors per cluster */
 	if (!au) au = 1;
 	if (au > 128) au = 128;
@@ -4362,5 +4362,5 @@
 	}
 
-	if (_MULTI_PARTITION && part) {
+	if (FF_MULTI_PARTITION && part) {
 		/* Update system ID in the partition table */
 		tbl = &fs->win[MBR_Table + (part - 1) * SZ_PTE];
@@ -4465,5 +4465,5 @@
 	} while (--i);
 
-#if _USE_TRIM	/* Erase data area if needed */
+#if FF_USE_TRIM	/* Erase data area if needed */
 	{
 		eb[0] = wsect; eb[1] = wsect + (n_clst - ((fmt == FS_FAT32) ? 1 : 0)) * au - 1;
@@ -4488,5 +4488,5 @@
 
 
-#if _MULTI_PARTITION
+#if FF_MULTI_PARTITION
 /*-----------------------------------------------------------------------*/
 /* Create partition table on the physical drive                          */
@@ -4518,5 +4518,5 @@
 
 	/* Create partition table */
-	mem_set(buf, 0, _MAX_SS);
+	mem_set(buf, 0, FF_MAX_SS);
 	p = buf + MBR_Table; b_cyl = 0;
 	for (i = 0; i < 4; i++, p += SZ_PTE) {
@@ -4555,11 +4555,11 @@
 
 
-#endif /* _MULTI_PARTITION */
-#endif /* _USE_MKFS && !_FS_READONLY */
-
-
-
-
-#if _USE_STRFUNC
+#endif /* FF_MULTI_PARTITION */
+#endif /* FF_USE_MKFS && !FF_FS_READONLY */
+
+
+
+
+#if FF_USE_STRFUNC
 /*-----------------------------------------------------------------------*/
 /* Get a string from the file                                            */
@@ -4579,6 +4579,6 @@
 
 	while (n < len - 1) {	/* Read characters until buffer gets filled */
-#if _USE_LFN && _LFN_UNICODE
-#if _STRF_ENCODE == 3		/* Read a character in UTF-8 */
+#if FF_USE_LFN && FF_LFN_UNICODE
+#if FF_STRF_ENCODE == 3		/* Read a character in UTF-8 */
 		f_read(fp, s, 1, &rc);
 		if (rc != 1) break;
@@ -4602,9 +4602,9 @@
 			}
 		}
-#elif _STRF_ENCODE == 2		/* Read a character in UTF-16BE */
+#elif FF_STRF_ENCODE == 2		/* Read a character in UTF-16BE */
 		f_read(fp, s, 2, &rc);
 		if (rc != 2) break;
 		c = s[1] + (s[0] << 8);
-#elif _STRF_ENCODE == 1		/* Read a character in UTF-16LE */
+#elif FF_STRF_ENCODE == 1		/* Read a character in UTF-16LE */
 		f_read(fp, s, 2, &rc);
 		if (rc != 2) break;
@@ -4627,5 +4627,5 @@
 		c = s[0];
 #endif
-		if (_USE_STRFUNC == 2 && c == '\r') continue;	/* Strip '\r' */
+		if (FF_USE_STRFUNC == 2 && c == '\r') continue;	/* Strip '\r' */
 		*p++ = c;
 		n++;
@@ -4639,5 +4639,5 @@
 
 
-#if !_FS_READONLY
+#if !FF_FS_READONLY
 /*-----------------------------------------------------------------------*/
 /* Put a character to the file                                           */
@@ -4661,5 +4661,5 @@
 
 
-	if (_USE_STRFUNC == 2 && c == '\n')	 /* LF -> CRLF conversion */
+	if (FF_USE_STRFUNC == 2 && c == '\n')	 /* LF -> CRLF conversion */
 		putc_bfd(pb, '\r');
 
@@ -4667,6 +4667,6 @@
 	if (i < 0) return;
 
-#if _USE_LFN && _LFN_UNICODE
-#if _STRF_ENCODE == 3			/* Write a character in UTF-8 */
+#if FF_USE_LFN && FF_LFN_UNICODE
+#if FF_STRF_ENCODE == 3			/* Write a character in UTF-8 */
 	if (c < 0x80) {				/* 7-bit */
 		pb->buf[i++] = (BYTE)c;
@@ -4680,8 +4680,8 @@
 		pb->buf[i++] = (BYTE)(0x80 | (c & 0x3F));
 	}
-#elif _STRF_ENCODE == 2			/* Write a character in UTF-16BE */
+#elif FF_STRF_ENCODE == 2			/* Write a character in UTF-16BE */
 	pb->buf[i++] = (BYTE)(c >> 8);
 	pb->buf[i++] = (BYTE)c;
-#elif _STRF_ENCODE == 1			/* Write a character in UTF-16LE */
+#elif FF_STRF_ENCODE == 1			/* Write a character in UTF-16LE */
 	pb->buf[i++] = (BYTE)c;
 	pb->buf[i++] = (BYTE)(c >> 8);
@@ -4866,8 +4866,8 @@
 	ret = f_vprintf(fp, fmt, arp);
 	va_end(arp);
-
+	
 	return ret;
 }
 
-#endif /* !_FS_READONLY */
-#endif /* _USE_STRFUNC */
+#endif /* !FF_FS_READONLY */
+#endif /* FF_USE_STRFUNC */
Index: asp3_tinet_ecnl_arm/trunk/ntshell/fatfs/ff.h
===================================================================
--- asp3_tinet_ecnl_arm/trunk/ntshell/fatfs/ff.h	(revision 369)
+++ asp3_tinet_ecnl_arm/trunk/ntshell/fatfs/ff.h	(revision 374)
@@ -28,5 +28,5 @@
 #include "ffconf.h"		/* FatFs configuration options */
 #include "diskio.h"
-#if _FATFS != _FFCONF
+#if _FATFS != FFCONF_DEF
 #error Wrong configuration file (ffconf.h).
 #endif
@@ -36,5 +36,5 @@
 /* Definitions of volume management */
 
-#if _MULTI_PARTITION		/* Multiple partition configuration */
+#if FF_MULTI_PARTITION		/* Multiple partition configuration */
 typedef struct {
 	BYTE pd;	/* Physical drive number */
@@ -55,7 +55,7 @@
 /* Type of path name strings on FatFs API */
 
-#if _LFN_UNICODE			/* Unicode string */
-#if !_USE_LFN
-#error _LFN_UNICODE must be 0 at non-LFN cfg.
+#if FF_LFN_UNICODE			/* Unicode string */
+#if !FF_USE_LFN
+#error FF_LFN_UNICODE must be 0 at non-LFN cfg.
 #endif
 #ifndef _INC_TCHAR
@@ -87,15 +87,15 @@
 	WORD	id;				/* File system mount ID */
 	WORD	n_rootdir;		/* Number of root directory entries (FAT12/16) */
-#if _MAX_SS != _MIN_SS
+#if FF_MAX_SS != FF_MIN_SS
 	WORD	ssize;			/* Bytes per sector (512, 1024, 2048 or 4096) */
 #endif
-#if _FS_REENTRANT
-	_SYNC_t	sobj;			/* Identifier of sync object */
-#endif
-#if !_FS_READONLY
+#if FF_FS_REENTRANT
+	FF_SYNC_t	sobj;			/* Identifier of sync object */
+#endif
+#if !FF_FS_READONLY
 	DWORD	last_clust;		/* Last allocated cluster */
 	DWORD	free_clust;		/* Number of free clusters */
 #endif
-#if _FS_RPATH
+#if FF_FS_RPATH
 	DWORD	cdir;			/* Current directory start cluster (0:root) */
 #endif
@@ -107,5 +107,5 @@
 	DWORD	database;		/* Data start sector */
 	DWORD	winsect;		/* Current sector appearing in the win[] */
-	BYTE	win[_MAX_SS];	/* Disk access window for Directory, FAT (and file data at tiny cfg) */
+	BYTE	win[FF_MAX_SS];	/* Disk access window for Directory, FAT (and file data at tiny cfg) */
 } FATFS;
 
@@ -124,16 +124,16 @@
 	DWORD	clust;			/* Current cluster of fpter (not valid when fprt is 0) */
 	DWORD	dsect;			/* Sector number appearing in buf[] (0:invalid) */
-#if !_FS_READONLY
+#if !FF_FS_READONLY
 	DWORD	dir_sect;		/* Sector number containing the directory entry */
 	BYTE*	dir_ptr;		/* Pointer to the directory entry in the win[] */
 #endif
-#if _USE_FASTSEEK
+#if FF_USE_FASTSEEK
 	DWORD*	cltbl;			/* Pointer to the cluster link map table (Nulled on file open) */
 #endif
-#if _FS_LOCK
+#if FF_FS_LOCK != 0
 	UINT	lockid;			/* File lock ID origin from 1 (index of file semaphore table Files[]) */
 #endif
-#if !_FS_TINY
-	BYTE	buf[_MAX_SS];	/* File private data read/write window */
+#if !FF_FS_TINY
+	BYTE	buf[FF_MAX_SS];	/* File private data read/write window */
 #endif
 } FIL;
@@ -141,5 +141,5 @@
 
 
-/* Directory object structure (DIR) */
+/* Directory object structure (FATFS_DIR) */
 
 typedef struct __dirstream {
@@ -152,15 +152,15 @@
 	BYTE*	dir;			/* Pointer to the current SFN entry in the win[] */
 	BYTE*	fn;				/* Pointer to the SFN (in/out) {file[8],ext[3],status[1]} */
-#if _FS_LOCK
+#if FF_FS_LOCK != 0
 	UINT	lockid;			/* File lock ID (index of file semaphore table Files[]) */
 #endif
-#if _USE_LFN
+#if FF_USE_LFN
 	WCHAR*	lfn;			/* Pointer to the LFN working buffer */
 	WORD	lfn_idx;		/* Last matched LFN index number (0xFFFF:No LFN) */
 #endif
-#if _USE_FIND
+#if FF_USE_FIND
 	const TCHAR*	pat;	/* Pointer to the name matching pattern */
 #endif
-} DIR;
+} FATFS_DIR;
 
 
@@ -174,5 +174,5 @@
 	BYTE	fattrib;		/* Attribute */
 	TCHAR	fname[13];		/* Short file name (8.3 format) */
-#if _USE_LFN
+#if FF_USE_LFN
 	TCHAR*	lfname;			/* Pointer to the LFN buffer */
 	UINT 	lfsize;			/* Size of LFN buffer in TCHAR */
@@ -203,5 +203,5 @@
 	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_LOCK */
+	FR_TOO_MANY_OPEN_FILES,	/* (18) Number of open files > FF_FS_LOCK */
 	FR_INVALID_PARAMETER	/* (19) Given parameter is invalid */
 } FRESULT;
@@ -220,9 +220,9 @@
 FRESULT f_truncate (FIL* fp);										/* Truncate file */
 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_opendir (FATFS_DIR* dp, const TCHAR* path);						/* Open a directory */
+FRESULT f_closedir (FATFS_DIR* dp);										/* Close an open directory */
+FRESULT f_readdir (FATFS_DIR* dp, FILINFO* fno);							/* Read a directory item */
+FRESULT f_findfirst (FATFS_DIR* dp, FILINFO* fno, const TCHAR* path, const TCHAR* pattern);	/* Find first file */
+FRESULT f_findnext (FATFS_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 */
@@ -270,13 +270,13 @@
 
 /* RTC function */
-#if !_FS_READONLY && !_FS_NORTC
+#if !FF_FS_READONLY && !FF_FS_NORTC
 DWORD get_fattime (void);
 #endif
 
 /* Unicode support functions */
-#if _USE_LFN							/* Unicode - OEM code conversion */
+#if FF_USE_LFN							/* Unicode - OEM code conversion */
 WCHAR ff_convert (WCHAR chr, UINT dir);	/* OEM-Unicode bidirectional conversion */
 WCHAR ff_wtoupper (WCHAR chr);			/* Unicode upper-case conversion */
-#if _USE_LFN == 3						/* Memory functions */
+#if FF_USE_LFN == 3						/* Memory functions */
 void* ff_memalloc (UINT msize);			/* Allocate memory block */
 void ff_memfree (void* mblock);			/* Free memory block */
@@ -285,9 +285,9 @@
 
 /* Sync functions */
-#if _FS_REENTRANT
-int ff_cre_syncobj (BYTE vol, _SYNC_t* sobj);	/* Create a sync object */
-int ff_req_grant (_SYNC_t sobj);				/* Lock sync object */
-void ff_rel_grant (_SYNC_t sobj);				/* Unlock sync object */
-int ff_del_syncobj (_SYNC_t sobj);				/* Delete a sync object */
+#if FF_FS_REENTRANT
+int ff_cre_syncobj (BYTE vol, FF_SYNC_t* sobj);	/* Create a sync object */
+int ff_req_grant (FF_SYNC_t sobj);				/* Lock sync object */
+void ff_rel_grant (FF_SYNC_t sobj);				/* Unlock sync object */
+int ff_del_syncobj (FF_SYNC_t sobj);				/* Delete a sync object */
 #endif
 
@@ -304,11 +304,12 @@
 #define	FA_OPEN_EXISTING	0x00
 
-#if !_FS_READONLY
+#if !FF_FS_READONLY
 #define	FA_WRITE			0x02
 #define	FA_CREATE_NEW		0x04
 #define	FA_CREATE_ALWAYS	0x08
 #define	FA_OPEN_ALWAYS		0x10
-#define FA__WRITTEN			0x20
-#define FA__DIRTY			0x40
+#define	FA_OPEN_APPEND		0x30
+#define FA_MODIFIED			0x20
+#define FA_DIRTY			0x40
 #endif
 
@@ -341,5 +342,5 @@
 /* Multi-byte word access macros  */
 
-#if _WORD_ACCESS == 1	/* Enable word access to the FAT structure */
+#if FF_WORD_ACCESS == 1	/* Enable word access to the FAT structure */
 #define	LD_WORD(ptr)		(WORD)(*(WORD*)(BYTE*)(ptr))
 #define	LD_DWORD(ptr)		(DWORD)(*(DWORD*)(BYTE*)(ptr))
Index: asp3_tinet_ecnl_arm/trunk/ntshell/fatfs/ffarch.c
===================================================================
--- asp3_tinet_ecnl_arm/trunk/ntshell/fatfs/ffarch.c	(revision 369)
+++ asp3_tinet_ecnl_arm/trunk/ntshell/fatfs/ffarch.c	(revision 374)
@@ -51,7 +51,7 @@
 #include "sdfs.h"
 #include "ff.h"
-#include "util/ntstdio.h"
-
-extern ntstdio_t ntstdio;
+#include <stdio.h>
+#include "hal/rtc_api.h"
+#include "ffarch.h"
 
 enum ffarch_state_t {
@@ -80,5 +80,5 @@
 	ret2 = get_tim(&now);
 	if (ret2 != E_OK){
-		ntstdio_printf(&ntstdio, "[ffarch] get_tim error: %s",
+		printf("[ffarch] get_tim error: %s",
 			itron_strerror(ret2));
 		return;
@@ -94,5 +94,5 @@
 		ret = tslp_tsk(timer);
 		if ((ret != E_OK) && (ret != E_TMOUT)) {
-			ntstdio_printf(&ntstdio, "[ffarch] tslp_tsk error: %s %d",
+			printf("[ffarch] tslp_tsk error: %s %d",
 				itron_strerror(ret), timer);
 			break;
@@ -101,5 +101,5 @@
 		ret2 = get_tim(&now);
 		if (ret2 != E_OK) {
-			ntstdio_printf(&ntstdio, "[ffarch] get_tim error: %s",
+			printf("[ffarch] get_tim error: %s",
 				itron_strerror(ret2));
 			break;
@@ -150,11 +150,9 @@
 
 	if (romdisk_init()) {
-		ntstdio_printf(&ntstdio, "ROM disk (0:) OK!\n");
+		printf("ROM disk (0:) OK!\n");
 	}
 	else {
-		ntstdio_printf(&ntstdio, "ROM disk (0:) NG!\n");
-	}
-
-	serial_ctl_por(SIO_PORTID, IOCTL_FCSND | IOCTL_FCRCV);
+		printf("ROM disk (0:) NG!\n");
+	}
 }
 
@@ -272,5 +270,5 @@
 {
 	DRESULT res;
-	uint32_t *dp = (uint32_t *)buff, st, ed;
+	uint32_t *dp = (uint32_t *)buff;
 	uint8_t *ptr = (uint8_t *)buff;
 
@@ -333,5 +331,5 @@
 {
 	BYTE s = 0;
-
+             
 	/* Write protected */
 	if (WP())
@@ -377,5 +375,5 @@
 	case FFS_RETRY_WAIT:
 		if (ffarch_retry_count == 0) {
-			ntstdio_printf(&ntstdio, "SD card (1:) initialize tired...\n");
+			printf("SD card (1:) initialize tired...\n");
 
 			ffarch_state = FFS_IDLE;
@@ -390,8 +388,8 @@
  		if ((sdfs._is_initialized & STA_NOINIT)
  			|| (((sdfs_prev_status & STA_NODISK) != 0) && ((sdfs_new_status & STA_NODISK) == 0))) {
-			ntstdio_printf(&ntstdio, "SD card initializing ...\n");
+			printf("SD card initializing ...\n");
 
 			if (SD_begin()) {
-				ntstdio_printf(&ntstdio, "SD card (1:) OK!\n");
+				printf("SD card (1:) OK!\n");
 
 				/* uploadディレクトリを作成しておく */
@@ -403,5 +401,5 @@
 			}
 			else {
-				ntstdio_printf(&ntstdio, "SD card (1:) NG!\n");
+				printf("SD card (1:) NG!\n");
 				ffarch_state = FFS_RETRY_WAIT;
 				ffarch_timer = 1000 * 1000;
@@ -410,5 +408,5 @@
 		/* SDカードが抜かれた場合 */
 		else if (((sdfs_prev_status & STA_NODISK) == 0) && ((sdfs_new_status & STA_NODISK) != 0)) {
-			ntstdio_printf(&ntstdio, "SD card unmount\n");
+			printf("SD card unmount\n");
 
 			f_mount(&Sd.FatFs, "1:", 0);
@@ -428,10 +426,10 @@
 }
 
-int ff_cre_syncobj(BYTE vol, _SYNC_t* sobj)
+int ff_cre_syncobj(BYTE vol, FF_SYNC_t* sobj)
 {
 	return 1;
 }
 
-int ff_req_grant(_SYNC_t sobj)
+int ff_req_grant(FF_SYNC_t sobj)
 {
 	ER ret;
@@ -440,10 +438,10 @@
 }
 
-void ff_rel_grant(_SYNC_t sobj)
+void ff_rel_grant(FF_SYNC_t sobj)
 {
 	sig_sem(SEM_FILESYSTEM);
 }
 
-int ff_del_syncobj(_SYNC_t sobj)
+int ff_del_syncobj(FF_SYNC_t sobj)
 {
 	return 1;
Index: asp3_tinet_ecnl_arm/trunk/ntshell/fatfs/ffconf.h
===================================================================
--- asp3_tinet_ecnl_arm/trunk/ntshell/fatfs/ffconf.h	(revision 369)
+++ asp3_tinet_ecnl_arm/trunk/ntshell/fatfs/ffconf.h	(revision 374)
@@ -3,5 +3,7 @@
 /---------------------------------------------------------------------------*/
 
-#define _FFCONF 64180	/* Revision ID */
+#define FFCONF_DEF 64180	/* Revision ID */
+
+#define FFS_DBG			0
 
 /*---------------------------------------------------------------------------/
@@ -9,5 +11,5 @@
 /---------------------------------------------------------------------------*/
 
-#define _FS_READONLY	0
+#define FF_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(),
@@ -16,5 +18,5 @@
 
 
-#define _FS_MINIMIZE	0
+#define FF_FS_MINIMIZE	0
 /* This option defines minimization level to remove some basic API functions.
 /
@@ -26,5 +28,5 @@
 
 
-#define	_USE_STRFUNC	1
+#define	FF_USE_STRFUNC	1
 /* This option switches string functions, f_gets(), f_putc(), f_puts() and
 /  f_printf().
@@ -35,25 +37,25 @@
 
 
-#define _USE_FIND		1
+#define FF_USE_FIND		1
 /* This option switches filtered directory read feature and related functions,
 /  f_findfirst() and f_findnext(). (0:Disable or 1:Enable) */
 
 
-#define	_USE_MKFS		1
+#define	FF_USE_MKFS		1
 /* This option switches f_mkfs() function. (0:Disable or 1:Enable) */
 
 
-#define	_USE_FASTSEEK	0
+#define	FF_USE_FASTSEEK	0
 /* This option switches fast seek feature. (0:Disable or 1:Enable) */
 
 
-#define _USE_LABEL		1
+#define FF_USE_LABEL		1
 /* This option switches volume label functions, f_getlabel() and f_setlabel().
 /  (0:Disable or 1:Enable) */
 
 
-#define	_USE_FORWARD	1
+#define	FF_USE_FORWARD	1
 /* This option switches f_forward() function. (0:Disable or 1:Enable)
-/  To enable it, also _FS_TINY need to be set to 1. */
+/  To enable it, also FF_FS_TINY need to be set to 1. */
 
 
@@ -62,5 +64,5 @@
 /---------------------------------------------------------------------------*/
 
-#define _CODE_PAGE 65001
+#define FF_CODE_PAGE 65001
 /* 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.
@@ -91,9 +93,9 @@
 
 
-#define	_USE_LFN	3
-#define	_MAX_LFN	255
-/* The _USE_LFN option switches the LFN feature.
-/
-/   0: Disable LFN feature. _MAX_LFN has no effect.
+#define	FF_USE_LFN	3
+#define	FF_MAX_LFN	255
+/* The FF_USE_LFN option switches the LFN feature.
+/
+/   0: Disable LFN feature. FF_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.
@@ -101,5 +103,5 @@
 /
 /  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.
+/  be added to the project. The LFN working buffer occupies (FF_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
@@ -107,12 +109,12 @@
 
 
-#define	_LFN_UNICODE	0
+#define	FF_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 use Unicode string for the path name, enable LFN feature and set FF_LFN_UNICODE
 /  to 1. This option also affects behavior of string I/O functions. */
 
 
-#define _STRF_ENCODE	3
-/* When _LFN_UNICODE is 1, this option selects the character encoding on the file to
+#define FF_STRF_ENCODE	3
+/* When FF_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().
 /
@@ -122,8 +124,16 @@
 /  3: UTF-8
 /
-/  When _LFN_UNICODE is 0, this option has no effect. */
-
-
-#define _FS_RPATH	2
+/  When FF_LFN_UNICODE is 0, this option has no effect. */
+
+
+#define FF_LFN_BUF		255
+#define FF_SFN_BUF		12
+/* This set of options defines size of file name members in the FILINFO structure
+/  which is used to read out directory items. These values should be suffcient for
+/  the file names to read. The maximum possible length of the read file name depends
+/  on character encoding. When LFN is not enabled, these options have no effect. */
+
+
+#define FF_FS_RPATH	2
 /* This option configures relative path feature.
 /
@@ -139,18 +149,18 @@
 /---------------------------------------------------------------------------*/
 
-#define _VOLUMES	2
+#define FF_VOLUMES	4
 /* Number of volumes (logical drives) to be used. */
 
 
-#define _STR_VOLUME_ID	0
-#define _VOLUME_STRS	"RAM","NAND","CF","SD1","SD2","USB1","USB2","USB3"
-/* _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
+#define FF_STR_VOLUME_ID	0
+#define FF_VOLUME_STRS	"RAM","NAND","CF","SD1","SD2","USB1","USB2","USB3"
+/* FF_STR_VOLUME_ID option switches string volume ID feature.
+/  When FF_STR_VOLUME_ID is set to 1, also pre-defined strings can be used as drive
+/  number in the path name. FF_VOLUME_STRS defines the drive ID strings for each
+/  logical drives. Number of items must be equal to FF_VOLUMES. Valid characters for
 /  the drive ID strings are: A-Z and 0-9. */
 
 
-#define	_MULTI_PARTITION	0
+#define	FF_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
@@ -160,15 +170,15 @@
 
 
-#define	_MIN_SS		512
-#define	_MAX_SS		512
+#define	FF_MIN_SS		512
+#define	FF_MAX_SS		512
 /* 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
+/  type of optical media. When FF_MAX_SS is larger than FF_MIN_SS, FatFs is configured
 /  to variable sector size and GET_SECTOR_SIZE command must be implemented to the
 /  disk_ioctl() function. */
 
 
-#define	_USE_TRIM	0
+#define	FF_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
@@ -176,5 +186,5 @@
 
 
-#define _FS_NOFSINFO	0
+#define FF_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
@@ -193,7 +203,7 @@
 /---------------------------------------------------------------------------*/
 
-#define	_FS_TINY	1
+#define	FF_FS_TINY	1
 /* 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
+/  At the tiny configuration, size of the file object (FIL) is reduced FF_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
@@ -201,21 +211,21 @@
 
 
-#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
+#define FF_FS_NORTC	0
+#define FF_NORTC_MON	1
+#define FF_NORTC_MDAY	1
+#define FF_NORTC_YEAR	2015
+/* The FF_FS_NORTC option switches timestamp feature. If the system does not have
+/  an RTC function or valid timestamp is not needed, set FF_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
+/  defined by FF_NORTC_MON, FF_NORTC_MDAY and FF_NORTC_YEAR.
+/  When timestamp feature is enabled (FF_FS_NORTC == 0), get_fattime() function need
+/  to be added to the project to read current time form RTC. FF_NORTC_MON,
+/  FF_NORTC_MDAY and FF_NORTC_YEAR have no effect. 
+/  These options have no effect at read-only configuration (FF_FS_READONLY == 1). */
+
+
+#define	FF_FS_LOCK	0
+/* The FF_FS_LOCK option switches file lock feature to control duplicated file open
+/  and illegal operation to open objects. This option must be 0 when FF_FS_READONLY
 /  is 1.
 /
@@ -227,8 +237,8 @@
 
 
-#define _FS_REENTRANT	1
-#define _FS_TIMEOUT		1000
-#define	_SYNC_t			unsigned int
-/* The _FS_REENTRANT option switches the re-entrancy (thread safe) of the FatFs
+#define FF_FS_REENTRANT	1
+#define FF_FS_TIMEOUT		1000
+#define	FF_SYNC_t			unsigned int
+/* The FF_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()
@@ -236,5 +246,5 @@
 /  to the same volume is under control of this feature.
 /
-/   0: Disable re-entrancy. _FS_TIMEOUT and _SYNC_t have no effect.
+/   0: Disable re-entrancy. FF_FS_TIMEOUT and FF_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()
@@ -242,12 +252,12 @@
 /      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*,
+/  The FF_FS_TIMEOUT defines timeout period in unit of time tick.
+/  The FF_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	1
-/* The _WORD_ACCESS option is an only platform dependent option. It defines
+#define FF_WORD_ACCESS	1
+/* The FF_WORD_ACCESS option is an only platform dependent option. It defines
 /  which access method is used to the word data on the FAT volume.
 /
@@ -258,5 +268,5 @@
 /  * Byte order on the memory is little-endian.
 /
-/  If it is the case, _WORD_ACCESS can also be set to 1 to reduce code size.
+/  If it is the case, FF_WORD_ACCESS can also be set to 1 to reduce code size.
 /  Following table shows allowable settings of some type of processors.
 /
Index: asp3_tinet_ecnl_arm/trunk/ntshell/fatfs/sdfs.c
===================================================================
--- asp3_tinet_ecnl_arm/trunk/ntshell/fatfs/sdfs.c	(revision 369)
+++ asp3_tinet_ecnl_arm/trunk/ntshell/fatfs/sdfs.c	(revision 374)
@@ -118,9 +118,8 @@
 //#include "mbed_debug.h"
 #include "mbed_wait_api.h"
-#include "util/ntstdio.h"
-
-extern ntstdio_t ntstdio;
-#define debug(...) ntstdio_printf(&ntstdio, __VA_ARGS__)
-#define debug_if(cond, ...) if(cond){ ntstdio_printf(&ntstdio, __VA_ARGS__); }
+#include <stdio.h>
+
+#define debug(...) printf(__VA_ARGS__)
+#define debug_if(cond, ...) if(cond){ printf(__VA_ARGS__); }
 
 static int sdfs_initialise_card_v1(sdfs_t *obj);
@@ -137,5 +136,5 @@
 #define SD_DBG             0
 
-sdfs_init(sdfs_t *obj, PinName mosi, PinName miso, PinName sclk, PinName cs, const char* name)
+void sdfs_init(sdfs_t *obj, PinName mosi, PinName miso, PinName sclk, PinName cs, const char* name)
 {
 	obj->name = name;
Index: asp3_tinet_ecnl_arm/trunk/ntshell/fatfs/sdfs.h
===================================================================
--- asp3_tinet_ecnl_arm/trunk/ntshell/fatfs/sdfs.h	(revision 369)
+++ asp3_tinet_ecnl_arm/trunk/ntshell/fatfs/sdfs.h	(revision 374)
@@ -80,5 +80,5 @@
 	* @param name The name used to access the virtual filesystem
 	*/
-sdfs_init(sdfs_t *obj, PinName mosi, PinName miso, PinName sclk, PinName cs, const char* name);
+void sdfs_init(sdfs_t *obj, PinName mosi, PinName miso, PinName sclk, PinName cs, const char* name);
 
 int sdfs_initialize(sdfs_t *obj);
Index: asp3_tinet_ecnl_arm/trunk/ntshell/ntshell/usrcmd.c
===================================================================
--- asp3_tinet_ecnl_arm/trunk/ntshell/ntshell/usrcmd.c	(revision 369)
+++ asp3_tinet_ecnl_arm/trunk/ntshell/ntshell/usrcmd.c	(revision 374)
@@ -47,122 +47,8 @@
 #include "core/ntshell.h"
 #include "core/ntlibc.h"
-#include "util/ntstdio.h"
-
-extern ntstdio_t ntstdio;
+#include <stdio.h>
+#include <getopt.h>
+
 extern int ntshell_exit;
-
-extern int mbtowc(wchar_t *__restrict wc, const char *__restrict src, size_t n);
-
-/* musl_getopt from msul */
-char *optarg;
-int optind=1, opterr=1, optopt, optpos, optreset=0;
-extern int optind, opterr;
-
-static void ntstdio_write(ntstdio_t *handle, const char *str, int l)
-{
-	for (; *str && l >= 0; l--) {
-		ntstdio_putc(handle, *str++);
-	}
-}
-
-static void __getopt_msg(const char *a, const char *b, const char *c, size_t l)
-{
-	ntstdio_puts(&ntstdio, a);
-	ntstdio_write(&ntstdio, b, strlen(b));
-	ntstdio_write(&ntstdio, c, l);
-	ntstdio_putc(&ntstdio, '\n');
-}
-
-static int musl_getopt(int argc, char * const argv[], const char *optstring)
-{
-	int i;
-	wchar_t c, d;
-	int k, l;
-	char *optchar;
-
-	if (!optind || optreset) {
-		optreset = 0;
-		optpos = 0;
-		optind = 1;
-	}
-
-	if (optind >= argc || !argv[optind])
-		return -1;
-
-	if (argv[optind][0] != '-') {
-		if (optstring[0] == '-') {
-			optarg = argv[optind++];
-			return 1;
-		}
-		return -1;
-	}
-
-	if (!argv[optind][1])
-		return -1;
-
-	if (argv[optind][1] == '-' && !argv[optind][2])
-		return optind++, -1;
-
-	if (!optpos) optpos++;
-	if ((k = mbtowc(&c, argv[optind]+optpos, MB_LEN_MAX)) < 0) {
-		k = 1;
-		c = 0xfffd; /* replacement char */
-	}
-	optchar = argv[optind]+optpos;
-	optopt = c;
-	optpos += k;
-
-	if (!argv[optind][optpos]) {
-		optind++;
-		optpos = 0;
-	}
-
-	if (optstring[0] == '-' || optstring[0] == '+')
-		optstring++;
-
-	i = 0;
-	d = 0;
-	do {
-		l = mbtowc(&d, optstring+i, MB_LEN_MAX);
-		if (l>0) i+=l; else i++;
-	} while (l && d != c);
-
-	if (d != c) {
-		if (optstring[0] != ':' && opterr)
-			__getopt_msg(argv[0], ": unrecognized option: ", optchar, k);
-		return '?';
-	}
-	if (optstring[i] == ':') {
-		if (optstring[i+1] == ':') optarg = 0;
-		else if (optind >= argc) {
-			if (optstring[0] == ':') return ':';
-			if (opterr) __getopt_msg(argv[0],
-				": option requires an argument: ",
-				optchar, k);
-			return '?';
-		}
-		if (optstring[i+1] != ':' || optpos) {
-			optarg = argv[optind++] + optpos;
-			optpos = 0;
-		}
-	}
-	return c;
-}
-
-int shell_kill(int pid, int sig)
-{
-	DebugBreak();
-	return -1;
-}
-
-int shell_gettimeofday(struct timeval *tv, void *tzvp)
-{
-	SYSTIM time;
-	if (!tv) return 0;
-	get_tim(&time);
-	tv->tv_sec = time / 1000000;
-	tv->tv_usec = time - (tv->tv_sec * 1000000);
-	return 0;
-}
 
 void put_rc(const char *func, FRESULT rc)
@@ -178,5 +64,5 @@
 		while (*p++);
 	}
-	ntstdio_printf(&ntstdio, "%s() =>%u FR_%s\n", func, (UINT)rc, p);
+	printf("%s() =>%u FR_%s\n", func, (UINT)rc, p);
 }
 
@@ -190,5 +76,5 @@
 		while (*p++);
 	}
-	ntstdio_printf(&ntstdio, "%s() =>%u %s\n", func, (UINT)rc, p);
+	printf("%s() =>%u %s\n", func, (UINT)rc, p);
 }
 
@@ -240,5 +126,5 @@
 
 	ntlibc_strlcat(path, "\n", sizeof(path));
-	ntstdio_printf(&ntstdio, path);
+	printf(path);
 
 	return 0;
@@ -252,5 +138,5 @@
 	char *fn;
 
-#if _USE_LFN
+#if FF_USE_LFN
 	fn = *fno->lfname ? fno->lfname : fno->fname;
 #else
@@ -263,5 +149,5 @@
 
 	if (list_option & LS_LONG) {
-		ntstdio_printf(&ntstdio, "%c%c%c%c%c %04d/%02d/%02d %02d:%02d:%02d ",
+		printf("%c%c%c%c%c %04d/%02d/%02d %02d:%02d:%02d ",
 			(fno->fattrib & AM_DIR) ? 'd' : '-',
 			(fno->fattrib & AM_RDO) ? 'r' : '-',
@@ -277,20 +163,20 @@
 
 		if (fno->fattrib & AM_DIR) {                    /* It is a directory */
-			ntstdio_printf(&ntstdio, "%10S ", " ");
+			printf("%10s ", " ");
 		}
 		else {
-			ntstdio_printf(&ntstdio, "%10d ", fno->fsize);
+			printf("%10lu ", fno->fsize);
 		}
 	}
 
 	if (fno->fattrib & AM_DIR) {                    /* It is a directory */
-		ntstdio_printf(&ntstdio, "\x1B[32m%s\x1B[0m\n", fn);
+		printf("\x1B[32m%s\x1B[0m\n", fn);
 	}
 	else {
-		ntstdio_printf(&ntstdio, "%s\n", fn);
-	}
-}
-
-#define LFN_BUF_SIZE (_MAX_LFN + 1)
+		printf("%s\n", fn);
+	}
+}
+
+#define LFN_BUF_SIZE (FF_MAX_LFN + 1)
 /* lsコマンド dir内 表示 */
 void print_ls(char *path_p, char *pattern_p, BYTE list_option)
@@ -298,5 +184,5 @@
 	FRESULT res;
 	FILINFO fno;
-	DIR dir;
+	FATFS_DIR dir;
 	char *fn;   /* This function assumes non-Unicode configuration */
 
@@ -307,13 +193,13 @@
 	path_backup = ff_memalloc(LFN_BUF_SIZE);
 	if (path_backup == NULL) {
-		ntstdio_printf(&ntstdio, "ff_memalloc err.\n");
+		printf("ff_memalloc err.\n");
 		return;
 	}
 
-#if _USE_LFN
+#if FF_USE_LFN
 	char *lfn = NULL;
 	lfn = ff_memalloc(LFN_BUF_SIZE);
 	if (lfn == NULL) {
-		ntstdio_printf(&ntstdio, "ff_memalloc err.\n");
+		printf("ff_memalloc err.\n");
 		ff_memfree(path_backup);
 		return;
@@ -333,6 +219,6 @@
 
 	while ((res == FR_OK) && (fno.fname[0] != 0)) {
-		if (pattern_p != NULL && (fno.fattrib & AM_DIR) && ((fno.fname[0] == '.') ? (pattern_p[0] == '.') : 1)) {/* DIR とパターンマッチしている場合は DIR 内部を ls する */
-#if _USE_LFN
+		if (pattern_p != NULL && (fno.fattrib & AM_DIR) && ((fno.fname[0] == '.') ? (pattern_p[0] == '.') : 1)) {/* FATFS_DIR とパターンマッチしている場合は FATFS_DIR 内部を ls する */
+#if FF_USE_LFN
 			fn = *fno.lfname ? fno.lfname : fno.fname;
 #else
@@ -351,9 +237,9 @@
 			}
 
-			ntstdio_printf(&ntstdio, "\n%s/%s:\n", path_p, fn);
+			printf("\n%s/%s:\n", path_p, fn);
 
 			print_ls(fn, NULL, list_option);
 
-			ntstdio_printf(&ntstdio, "\n");
+			printf("\n");
 
 			if ((res = f_chdrive(path_backup)) != FR_OK) {
@@ -384,9 +270,9 @@
 {
 	char *pattern_p = NULL, *basename_p = NULL, *dirname_p = NULL;
-	char default_pattern[_MAX_LFN] = "";
+	char default_pattern[FF_MAX_LFN] = "";
 	int c;
 	BYTE list_option = 0;
 
-	while ((c = musl_getopt(argc, argv, "al")) != -1) {
+	while ((c = getopt(argc, argv, "al")) != -1) {
 		switch (c) {
 		case 'a':
@@ -446,9 +332,9 @@
 		return 0;
 
-#if _USE_LFN
+#if FF_USE_LFN
 	/* LFN buffer alloc */
 	lfn = ff_memalloc(LFN_BUF_SIZE);
 	if (lfn == NULL) {
-		ntstdio_printf(&ntstdio, "alloc err.\n");
+		printf("alloc err.\n");
 		goto cp_end;
 	}
@@ -460,5 +346,5 @@
 	local_buff = ff_memalloc(64);
 	if (local_buff == NULL) {
-		ntstdio_printf(&ntstdio, "alloc err.\n");
+		printf("alloc err.\n");
 		goto cp_end;
 	}
@@ -470,7 +356,7 @@
 	if (res != FR_OK) {
 		if (res == FR_NO_FILE)
-			ntstdio_printf(&ntstdio, "src no file.\n", res);
+			printf("src no file.\n");
 		else
-			ntstdio_printf(&ntstdio, "src stat err(%d).\n", res);
+			printf("src stat err(%d).\n", res);
 		goto cp_end;
 	}
@@ -481,5 +367,5 @@
 		res = f_open(&src_fp, src_str_p, (FA_OPEN_EXISTING | FA_READ));
 		if (res != FR_OK) {
-			ntstdio_printf(&ntstdio, "src open err(%d).\n", res);
+			printf("src open err(%d).\n", res);
 			goto cp_end;
 		}
@@ -496,17 +382,17 @@
 				dst_mod_str_p = ff_memalloc(LFN_BUF_SIZE);
 				if (dst_mod_str_p == NULL) {
-					ntstdio_printf(&ntstdio, "alloc err.\n");
+					printf("alloc err.\n");
 					goto cp_end;
 				}
-				ntstdio_snprintf(dst_mod_str_p, LFN_BUF_SIZE, "%s/%s\0", dst_str_p, src_basename_p);
+				snprintf(dst_mod_str_p, LFN_BUF_SIZE, "%s/%s\0", dst_str_p, src_basename_p);
 				dst_str_p = dst_mod_str_p;
 			}
 			else {
-				ntstdio_printf(&ntstdio, "dst file exists.\n");
+				printf("dst file exists.\n");
 				goto cp_end_1;
 			}
 		}
 		else {
-			ntstdio_printf(&ntstdio, "src stat err(%d).\n", res);
+			printf("src stat err(%d).\n", res);
 			goto cp_end_1;
 		}
@@ -514,5 +400,5 @@
 	res = f_open(&dst_fp, dst_str_p, (FA_CREATE_NEW | FA_WRITE));
 	if (res != FR_OK) {
-		ntstdio_printf(&ntstdio, "dst open err(%d).\n", res);
+		printf("dst open err(%d).\n", res);
 		goto cp_end_1;
 	}
@@ -525,5 +411,5 @@
 		res = f_read(&src_fp, local_buff, sizeof(local_buff), &read_size);
 		if (res != FR_OK) {
-			ntstdio_printf(&ntstdio, "src read err(%d).\n", res);
+			printf("src read err(%d).\n", res);
 			goto cp_end_2;
 		}
@@ -532,9 +418,9 @@
 		res = f_write(&dst_fp, local_buff, read_size, &write_size);
 		if (res != FR_OK) {
-			ntstdio_printf(&ntstdio, "dst write err(%d).\n", res);
+			printf("dst write err(%d).\n", res);
 			goto cp_end_2;
 		}
 		if (read_size != write_size) {
-			ntstdio_printf(&ntstdio, "dst write err(disk full).\n", res);
+			printf("dst write err(disk full).\n");
 			goto cp_end_2;
 		}
@@ -622,13 +508,13 @@
 	unsigned int op_offset = 0, op_size = 0, op_end = 0;
 
-	while ((op = musl_getopt(argc, argv, "hduos0123456789xX")) != -1) {
+	while ((op = getopt(argc, argv, "hduos0123456789xX")) != -1) {
 		switch (op) {
 		case 'h': /* help */
-			ntstdio_printf(&ntstdio, " hexdump [OPTION] file\n");
-			ntstdio_printf(&ntstdio, "  -h : help\n");
-			ntstdio_printf(&ntstdio, "  -d : print all byte with convert and color [in character area] (default)\n");
-			ntstdio_printf(&ntstdio, "  -u : try print UTF-8 code [in character area]\n");
-			ntstdio_printf(&ntstdio, "  -oOFFSET : print start offset address from top\n");
-			ntstdio_printf(&ntstdio, "  -sSIZE   : print size\n");
+			printf(" hexdump [OPTION] file\n");
+			printf("  -h : help\n");
+			printf("  -d : print all byte with convert and color [in character area] (default)\n");
+			printf("  -u : try print UTF-8 code [in character area]\n");
+			printf("  -oOFFSET : print start offset address from top\n");
+			printf("  -sSIZE   : print size\n");
 			break;
 		case 'd': /* print one byte character [in character area] (default) */
@@ -661,5 +547,5 @@
 	/* position adjusting */
 	if (op_offset >= fsrc.fsize) {
-		ntstdio_printf(&ntstdio, "error : input offset is bigger than file size(0x%X).\n", fsrc.fsize);
+		printf("error : input offset is bigger than file size(0x%lX).\n", fsrc.fsize);
 		return 0;
 	}
@@ -674,5 +560,5 @@
 		char *pos = line;
 		int rst = sizeof(line);
-		int len = ntstdio_snprintf(pos, rst, "%08X: ", i);
+		int len = snprintf(pos, rst, "%08X: ", i);
 		pos += len;
 		rst -= len;
@@ -693,7 +579,7 @@
 			char c = data[j];
 			if (j != 7)
-				len = ntstdio_snprintf(pos, rst, "%02X ", c);
+				len = snprintf(pos, rst, "%02X ", c);
 			else
-				len = ntstdio_snprintf(pos, rst, "%02X-", c);
+				len = snprintf(pos, rst, "%02X-", c);
 			pos += len;
 			rst -= len;
@@ -723,7 +609,7 @@
 								break;
 							if (j + k != 7)
-								len = ntstdio_snprintf(pos, rst, "%02X ", data[j + k]);
+								len = snprintf(pos, rst, "%02X ", data[j + k]);
 							else
-								len = ntstdio_snprintf(pos, rst, "%02X-", data[j + k]);
+								len = snprintf(pos, rst, "%02X-", data[j + k]);
 							pos += len;
 							rst -= len;
@@ -743,5 +629,5 @@
 				apos += len;
 				arst -= len;
-				len = ntstdio_snprintf(apos, arst, "\x1B[%dm%c\x1B[0m", CCOLOR_RESET, ' ');
+				len = snprintf(apos, arst, "\x1B[%dm%c\x1B[0m", CCOLOR_RESET, ' ');
 				utf8_odd_bytes--;
 			}
@@ -763,5 +649,5 @@
 					c = '?';
 				}
-				len = ntstdio_snprintf(apos, arst, "\x1B[%dm%c\x1B[0m", ccolor, c);
+				len = snprintf(apos, arst, "\x1B[%dm%c\x1B[0m", ccolor, c);
 			}
 
@@ -772,16 +658,16 @@
 		for (int j = br; j < 16; j++) {
 			if (j != 7)
-				len = ntstdio_snprintf(pos, rst, "   ");
+				len = snprintf(pos, rst, "   ");
 			else
-				len = ntstdio_snprintf(pos, rst, "  -");
+				len = snprintf(pos, rst, "  -");
 			pos += len;
 			rst -= len;
 		}
 
-		len = ntstdio_snprintf(pos, rst, ": %s\n", ascii);
+		len = snprintf(pos, rst, ": %s\n", ascii);
 		pos += len;
 		rst -= len;
 
-		ntstdio_puts(&ntstdio, line);
+		puts(line);
 	}
 
@@ -796,7 +682,7 @@
 	char buf[30];
 
-	ret = shell_clock_gettime(CLOCK_REALTIME, &tp);
+	ret = clock_gettime(CLOCK_REALTIME, &tp);
 	if (ret != 0) {
-		ntstdio_printf(&ntstdio, "clock_gettime error %d", ret);
+		printf("clock_gettime error %d", ret);
 		return 0;
 	}
@@ -804,5 +690,5 @@
 	memset(buf, 0, sizeof(buf));
 	if (ctime_r(&tp.tv_sec, buf) == NULL) {
-		ntstdio_printf(&ntstdio, "ctime_r error");
+		printf("ctime_r error");
 		return 0;
 	}
@@ -812,5 +698,5 @@
 	buf[ret - 1] = '\0';
 
-	ntstdio_printf(&ntstdio, "%s .%09u\n", buf, tp.tv_nsec);
+	printf("%s .%09ld\n", buf, tp.tv_nsec);
 	return 0;
 }
@@ -819,10 +705,10 @@
 {
 	if (argc != 2) {
-		ntstdio_printf(&ntstdio, "info sys\n");
-		ntstdio_printf(&ntstdio, "info ver\n");
+		printf("info sys\n");
+		printf("info ver\n");
 		return 0;
 	}
 	if (strcmp(argv[1], "sys") == 0) {
-		ntstdio_printf(&ntstdio, TARGET_NAME" Monitor\n");
+		printf(TARGET_NAME" Monitor\n");
 		return 0;
 	}
@@ -830,8 +716,8 @@
 		int mj, mn, bd;
 		ntshell_version(&mj, &mn, &bd);
-		ntstdio_printf(&ntstdio, "Version %d.%d.%d\n", mj, mn, bd);
-		return 0;
-	}
-	ntstdio_printf(&ntstdio, "Unknown sub command found\n");
+		printf("Version %d.%d.%d\n", mj, mn, bd);
+		return 0;
+	}
+	printf("Unknown sub command found\n");
 	return -1;
 }
Index: asp3_tinet_ecnl_arm/trunk/ntshell/ntshell/usrcmd.h
===================================================================
--- asp3_tinet_ecnl_arm/trunk/ntshell/ntshell/usrcmd.h	(revision 369)
+++ asp3_tinet_ecnl_arm/trunk/ntshell/ntshell/usrcmd.h	(revision 374)
@@ -56,8 +56,4 @@
 int usrcmd_exit(int argc, char **argv);
 
-void shell_abort();
-void shell_exit(int exitcd);
-int shell_kill(int pid, int sig);
-
 #endif
 
Index: asp3_tinet_ecnl_arm/trunk/ntshell/ntshell/util/ntstdio.h
===================================================================
--- asp3_tinet_ecnl_arm/trunk/ntshell/ntshell/util/ntstdio.h	(revision 369)
+++ asp3_tinet_ecnl_arm/trunk/ntshell/ntshell/util/ntstdio.h	(revision 374)
@@ -78,4 +78,5 @@
 	int pos;
 	unsigned int option;
+	void *exinf;
 } ntstdio_t;
 
Index: asp3_tinet_ecnl_arm/trunk/ntshell/src/fdtable.c
===================================================================
--- asp3_tinet_ecnl_arm/trunk/ntshell/src/fdtable.c	(revision 369)
+++ asp3_tinet_ecnl_arm/trunk/ntshell/src/fdtable.c	(revision 374)
@@ -68,50 +68,213 @@
 #include "kernel_cfg.h"
 #include <string.h>
-
-#define IO_TYPE_FREE	0
-#define IO_TYPE_SIO		1
-#define IO_TYPE_FILE	2
-#define IO_TYPE_DIR		3
-#define IO_TYPE_TCP		4
-#define IO_TYPE_UDP	5
-
-static struct _IO_FILE fd_table[8 * sizeof(FLGPTN)] = {
-	{ 0, IO_TYPE_SIO, 0, stdio_close, stdin_read, stdio_write, sio_seek, sio_ioctl },
-	{ 1, IO_TYPE_SIO, 0, stdio_close, stdio_read, stdout_write, sio_seek, sio_ioctl },
-	{ 2, IO_TYPE_SIO, 0, stdio_close, stdio_read, stderr_write, sio_seek, sio_ioctl },
+#include "util/ntstdio.h"
+#include "hal/serial_api.h"
+
+#ifdef _DEBUG
+static const char THIS_FILE[] = __FILE__;
+#endif
+
+static int stdio_close(struct SHELL_FILE *fp);
+static size_t stdio_read(struct SHELL_FILE *fp, unsigned char *data, size_t len);
+static size_t stdio_write(struct SHELL_FILE *fp, const unsigned char *data, size_t len);
+static size_t stdin_read(struct SHELL_FILE *fp, unsigned char *data, size_t len);
+static size_t stdout_write(struct SHELL_FILE *fp, const unsigned char *data, size_t len);
+static size_t stderr_write(struct SHELL_FILE *fp, const unsigned char *data, size_t len);
+static void stdio_delete(struct SHELL_FILE *fp);
+
+static int sio_close(struct SHELL_FILE *fp);
+static size_t sio_read(struct SHELL_FILE *fp, unsigned char *data, size_t len);
+static size_t sio_write(struct SHELL_FILE *fp, const unsigned char *data, size_t len);
+static off_t sio_seek(struct SHELL_FILE *fp, off_t ofs, int org);
+static int sio_ioctl(struct SHELL_FILE *fp, int req, void *arg);
+static bool_t sio_readable(struct SHELL_FILE *fp);
+static void sio_delete(struct SHELL_FILE *fp);
+
+IO_TYPE IO_TYPE_STDIN = { stdio_close, stdin_read, stdio_write, sio_seek, sio_ioctl, sio_readable, stdio_delete };
+IO_TYPE IO_TYPE_STDOUT = { stdio_close, stdio_read, stdout_write, sio_seek, sio_ioctl, sio_readable, stdio_delete };
+IO_TYPE IO_TYPE_STDERR = { stdio_close, stdio_read, stderr_write, sio_seek, sio_ioctl, sio_readable, stdio_delete };
+IO_TYPE IO_TYPE_SIO = { sio_close, sio_read, sio_write, sio_seek, sio_ioctl, sio_readable, sio_delete };
+ntstdio_t ntstdio;
+
+static struct SHELL_FILE fd_table[8 * sizeof(FLGPTN)] = {
+	{ 0, &IO_TYPE_STDIN, 0, .exinf = &ntstdio },
+	{ 1, &IO_TYPE_STDOUT, 0, .exinf = &ntstdio },
+	{ 2, &IO_TYPE_STDERR, 0,.exinf = &ntstdio },
 };
 #define fd_table_count (sizeof(fd_table) / sizeof(fd_table[0]))
 
-static int new_fd(int type, int id)
-{
+extern ntstdio_t ntstdio;
+extern serial_t stdio_uart;
+
+unsigned char ntstdio_xi(struct ntstdio_t *handle)
+{
+	return serial_getc((serial_t *)handle->exinf);
+}
+
+void ntstdio_xo(struct ntstdio_t *handle, unsigned char c)
+{
+	serial_putc((serial_t *)handle->exinf, c);
+}
+
+void sys_init(intptr_t exinf)
+{
+	ntstdio_init(&ntstdio, NTSTDIO_OPTION_LINE_ECHO | NTSTDIO_OPTION_CANON | NTSTDIO_OPTION_LF_CRLF | NTSTDIO_OPTION_LF_CR, ntstdio_xi, ntstdio_xo);
+	ntstdio.exinf = (void *)&stdio_uart;
+}
+
+int stdio_close(struct SHELL_FILE *fp)
+{
+	return -EPERM;
+}
+
+size_t stdio_read(struct SHELL_FILE *fp, unsigned char *data, size_t len)
+{
+	return -EPERM;
+}
+
+size_t stdio_write(struct SHELL_FILE *fp, const unsigned char *data, size_t len)
+{
+	return -EPERM;
+}
+
+size_t stdin_read(struct SHELL_FILE *fp, unsigned char *data, size_t len)
+{
+	int i = 0;
+	while (i < len) {
+		int c = ntstdio_getc((struct ntstdio_t *)fp->exinf);
+		data[i++] = c;
+		if ((c == EOF) || (c == '\n'))
+			break;
+	}
+	return i;
+}
+
+size_t stdout_write(struct SHELL_FILE *fp, const unsigned char *data, size_t len)
+{
+	for (int i = 0; i < len; i++) {
+		ntstdio_putc((struct ntstdio_t *)fp->exinf, data[i]);
+	}
+	return len;
+}
+
+size_t stderr_write(struct SHELL_FILE *fp, const unsigned char *data, size_t len)
+{
+	for (int i = 0; i < len; i++) {
+		ntstdio_putc((struct ntstdio_t *)fp->exinf, data[i]);
+	}
+	return len;
+}
+
+void stdio_delete(struct SHELL_FILE *fp)
+{
+}
+
+int sio_close(struct SHELL_FILE *fp)
+{
+	return -EPERM;
+}
+
+size_t sio_read(struct SHELL_FILE *fp, unsigned char *data, size_t len)
+{
+	return -EPERM;
+}
+
+size_t sio_write(struct SHELL_FILE *fp, const unsigned char *data, size_t len)
+{
+	return -EPERM;
+}
+
+off_t sio_seek(struct SHELL_FILE *fp, off_t ofs, int org)
+{
+	return -EPERM;
+}
+
+int sio_ioctl(struct SHELL_FILE *fp, int request, void *arg)
+{
+	switch (request) {
+	case TIOCGWINSZ:
+		return 0;
+	case TCGETS:
+		return sio_tcgetattr(fp->fd, (struct termios *)arg);
+	case TCSETS + TCSANOW:
+	case TCSETS + TCSADRAIN:
+	case TCSETS + TCSAFLUSH:
+		return sio_tcsetattr(fp->fd, request - TCSETS, (const struct termios *)arg);
+	}
+
+	return -EINVAL;
+}
+
+bool_t sio_readable(struct SHELL_FILE *fp)
+{
+	return fp->readevt_w != fp->readevt_r;
+}
+
+void sio_delete(struct SHELL_FILE *fp)
+{
+	free((serial_t *)((struct ntstdio_t *)fp->exinf)->exinf);
+	((struct ntstdio_t *)fp->exinf)->exinf = NULL;
+	free((struct ntstdio_t *)fp->exinf);
+	fp->exinf = NULL;
+}
+
+struct SHELL_FILE *new_fp(IO_TYPE *type, int id, int writable)
+{
+	struct SHELL_FILE *fp = NULL;
+	ER ret;
+
+	ret = wai_sem(SEM_FILEDESC);
+	if (ret < 0) {
+		syslog(LOG_ERROR, "wai_sem => %d", ret);
+	}
+
 	for (int fd = 3; fd < fd_table_count; fd++) {
-		struct _IO_FILE *fp = &fd_table[fd];
-		if (fp->type != IO_TYPE_FREE)
+		fp = &fd_table[fd];
+		if (fp->type != NULL)
 			continue;
 
-		memset(fp, 0, sizeof(struct _IO_FILE));
+		memset(fp, 0, sizeof(struct SHELL_FILE));
 		fp->fd = fd;
 		fp->type = type;
 		fp->handle = id;
-		return fd;
-	}
-
-	return -ENOMEM;
-}
-
-static struct _IO_FILE *id_to_fd(int type, int id)
-{
+		fp->writable = writable;
+		break;
+	}
+
+	ret = sig_sem(SEM_FILEDESC);
+	if (ret < 0) {
+		syslog(LOG_ERROR, "sig_sem => %d", ret);
+	}
+
+	return fp;
+}
+
+struct SHELL_FILE *id_to_fd(IO_TYPE *type, int id)
+{
+	struct SHELL_FILE *fp = NULL;
+	ER ret;
+
+	ret = wai_sem(SEM_FILEDESC);
+	if (ret < 0) {
+		syslog(LOG_ERROR, "wai_sem => %d", ret);
+	}
+
 	for (int fd = 3; fd < fd_table_count; fd++) {
-		struct _IO_FILE *fp = &fd_table[fd];
+		fp = &fd_table[fd];
 		if ((fp->type == type) && (fp->handle == id))
-			return fp;
-	}
-
-	return NULL;
-}
-
-static int delete_fd(int type, int id)
-{
-	struct _IO_FILE *fp = id_to_fd(type, id);
+			break;
+	}
+
+	ret = sig_sem(SEM_FILEDESC);
+	if (ret < 0) {
+		syslog(LOG_ERROR, "sig_sem => %d", ret);
+	}
+
+	return fp;
+}
+
+int delete_fd_by_id(IO_TYPE *type, int id)
+{
+	struct SHELL_FILE *fp = id_to_fd(type, id);
 	if (fp == NULL)
 		return -EBADF;
@@ -120,18 +283,26 @@
 }
 
-int delete_fp(struct _IO_FILE *fp)
-{
-	free(fp->pfile);
-	fp->pfile = NULL;
-	free(fp->pdir);
-	fp->pdir = NULL;
-	free(fp->psock);
-	fp->psock = NULL;
-	memset(fp, 0, sizeof(struct _IO_FILE));
+int delete_fp(struct SHELL_FILE *fp)
+{
+	ER ret;
+
+	fp->type->delete(fp);
+
+	ret = wai_sem(SEM_FILEDESC);
+	if (ret < 0) {
+		syslog(LOG_ERROR, "wai_sem => %d", ret);
+	}
+
+	memset(fp, 0, sizeof(struct SHELL_FILE));
+
+	ret = sig_sem(SEM_FILEDESC);
+	if (ret < 0) {
+		syslog(LOG_ERROR, "sig_sem => %d", ret);
+	}
 
 	return 0;
 }
 
-struct _IO_FILE *fd_to_fp(int fd)
+struct SHELL_FILE *fd_to_fp(int fd)
 {
 	if ((fd < 0) || (fd >= fd_table_count))
@@ -140,151 +311,5 @@
 }
 
-struct _IO_FILE *new_sio_fd(int sioid)
-{
-	int fd = new_fd(IO_TYPE_SIO, sioid);
-	if ((fd < 0) || (fd >= fd_table_count))
-		return NULL;
-
-	struct _IO_FILE *fp = &fd_table[fd];
-	fp->close = sio_close;
-	fp->read = sio_read;
-	fp->write = sio_write;
-	fp->seek = sio_seek;
-	fp->ioctl = sio_ioctl;
-	fp->writable = 1;
-
-	return fp;
-}
-
-int delete_sio_fd(int sioid)
-{
-	return delete_fd(IO_TYPE_SIO, sioid);
-}
-
-struct _IO_FILE *sioid_to_fd(int sioid)
-{
-	return id_to_fd(IO_TYPE_SIO, sioid);
-}
-
-struct _IO_FILE *new_file_fd(int fileid)
-{
-	int fd = new_fd(IO_TYPE_FILE, fileid);
-	if ((fd < 0) || (fd >= fd_table_count))
-		return NULL;
-
-	struct _IO_FILE *fp = &fd_table[fd];
-	fp->close = file_close;
-	fp->read = file_read;
-	fp->write = file_write;
-	fp->seek = file_seek;
-	fp->ioctl = file_ioctl;
-	fp->writable = 1;
-	fp->pfile = malloc(sizeof(FIL));
-	memset(fp->pfile, 0, sizeof(FIL));
-
-	return fp;
-}
-
-int delete_file_fd(int fileid)
-{
-	return delete_fd(IO_TYPE_FILE, fileid);
-}
-
-struct _IO_FILE *fileid_to_fd(int fileid)
-{
-	return id_to_fd(IO_TYPE_FILE, fileid);
-}
-
-struct _IO_FILE *new_dir_fd(int fileid)
-{
-	int fd = new_fd(IO_TYPE_DIR, fileid);
-	if ((fd < 0) || (fd >= fd_table_count))
-		return NULL;
-
-	struct _IO_FILE *fp = &fd_table[fd];
-	fp->close = dir_close;
-	fp->read = dir_read;
-	fp->write = dir_write;
-	fp->seek = dir_seek;
-	fp->ioctl = dir_ioctl;
-	fp->writable = 0;
-	fp->pdir = malloc(sizeof(struct _IO_DIR));
-	memset(fp->pdir, 0, sizeof(struct _IO_DIR));
-
-	return fp;
-}
-
-int delete_dir_fd(int dirid)
-{
-	return delete_fd(IO_TYPE_DIR, dirid);
-}
-
-struct _IO_FILE *dirid_to_fd(int dirid)
-{
-	return id_to_fd(IO_TYPE_DIR, dirid);
-}
-
-#ifndef NTSHELL_NO_SOCKET
-struct _IO_FILE *new_tcp_fd(int tcpid)
-{
-	int fd = new_fd(IO_TYPE_TCP, tcpid);
-	if ((fd < 0) || (fd >= fd_table_count))
-		return NULL;
-
-	struct _IO_FILE *fp = &fd_table[fd];
-	fp->close = tcp_fd_close;
-	fp->read = tcp_fd_read;
-	fp->write = tcp_fd_write;
-	fp->seek = tcp_fd_seek;
-	fp->ioctl = tcp_fd_ioctl;
-	fp->writable = 0;
-	fp->psock = malloc(sizeof(socket_t));
-	memset(fp->psock, 0, sizeof(socket_t));
-
-	return fp;
-}
-
-int delete_tcp_fd(int tcpid)
-{
-	return delete_fd(IO_TYPE_TCP, tcpid);
-}
-
-struct _IO_FILE *tcpid_to_fd(int tcpid)
-{
-	return id_to_fd(IO_TYPE_TCP, tcpid);
-}
-
-struct _IO_FILE *new_udp_fd(int udpid)
-{
-	int fd = new_fd(IO_TYPE_UDP, udpid);
-	if ((fd < 0) || (fd >= fd_table_count))
-		return NULL;
-
-	struct _IO_FILE *fp = &fd_table[fd];
-	fp->close = udp_fd_close;
-	fp->read = udp_fd_read;
-	fp->write = udp_fd_write;
-	fp->seek = udp_fd_seek;
-	fp->ioctl = udp_fd_ioctl;
-	fp->writable = 1;
-	fp->psock = malloc(sizeof(socket_t));
-	memset(fp->psock, 0, sizeof(socket_t));
-
-	return fp;
-}
-
-int delete_udp_fd(int udpid)
-{
-	return delete_fd(IO_TYPE_UDP, udpid);
-}
-
-struct _IO_FILE *udpid_to_fd(int udpid)
-{
-	return id_to_fd(IO_TYPE_UDP, udpid);
-}
-
-#endif
-
-void memor(void *dst, void *src, size_t len)
+void memand(void *dst, void *src, size_t len)
 {
 	uint8_t *d = (uint8_t *)dst;
@@ -293,5 +318,5 @@
 
 	while (s < e) {
-		*d++ |= *s++;
+		*d++ &= *s++;
 	}
 }
@@ -336,20 +361,20 @@
 
 	ret = shell_get_evts(&evts, tmout);
-	if (rfds != NULL)
-		memset(rfds, 0, sizeof(fd_set));
-	if (wfds != NULL)
-		memset(wfds, 0, sizeof(fd_set));
-	if (efds != NULL)
-		memset(efds, 0, sizeof(fd_set));
 	if (ret == E_OK) {
 		if (rfds != NULL)
-			memor(rfds, &evts.readfds, sizeof(fd_set));
+			memand(rfds, &evts.readfds, sizeof(fd_set));
 		if (wfds != NULL)
-			memor(wfds, &evts.writefds, sizeof(fd_set));
+			memand(wfds, &evts.writefds, sizeof(fd_set));
 		if (efds != NULL)
-			memor(efds, &evts.errorfds, sizeof(fd_set));
+			memand(efds, &evts.errorfds, sizeof(fd_set));
 		return evts.count;
 	}
 	if (ret == E_TMOUT) {
+		if (rfds != NULL)
+			memset(rfds, 0, sizeof(fd_set));
+		if (wfds != NULL)
+			memset(wfds, 0, sizeof(fd_set));
+		if (efds != NULL)
+			memset(efds, 0, sizeof(fd_set));
 		return 0;
 	}
@@ -419,18 +444,13 @@
 {
 	int fd = STDIN_FILENO;
-	struct _IO_FILE *fp = &fd_table[fd];
-	T_SERIAL_RPOR rpor;
+	struct SHELL_FILE *fp = &fd_table[fd];
 	FLGPTN flgptn = 0;
 
-	ER ret = serial_ref_por(SIO_PORTID, &rpor);
-	if (ret != E_OK)
-		return;
-
-	if (rpor.reacnt != 0) {
+	if (serial_readable((serial_t *)((struct ntstdio_t *)fp->exinf)->exinf)) {
 		if (fp->readevt_w == fp->readevt_r) fp->readevt_w++;
 
 		FD_SET(fd, (fd_set *)&flgptn);
 	}
-	if (rpor.wricnt != 0) {
+	if (serial_writable((serial_t *)((struct ntstdio_t *)fp->exinf)->exinf)) {
 		if (fp->writeevt_w == fp->writeevt_r) fp->writeevt_w++;
 
@@ -447,18 +467,13 @@
 {
 	int fd = STDIN_FILENO;
-	struct _IO_FILE *fp = &fd_table[fd];
-	T_SERIAL_RPOR rpor;
+	struct SHELL_FILE *fp = &fd_table[fd];
 	*flgptn = 0;
 
-	ER ret = serial_ref_por(SIO_PORTID, &rpor);
-	if (ret != E_OK)
-		return;
-
-	if (rpor.reacnt != 0) {
+	if (serial_readable((serial_t *)((struct ntstdio_t *)fp->exinf)->exinf)) {
 		if (fp->readevt_w == fp->readevt_r) fp->readevt_w++;
 
 		FD_SET(fd, (fd_set *)flgptn);
 	}
-	if (rpor.wricnt != 0) {
+	if (serial_writable((serial_t *)((struct ntstdio_t *)fp->exinf)->exinf)) {
 		if (fp->writeevt_w == fp->writeevt_r) fp->writeevt_w++;
 
@@ -466,169 +481,4 @@
 	}
 }
-
-#ifndef NTSHELL_NO_SOCKET
-
-ER socket_tcp_callback(ID cepid, FN fncd, void *p_parblk)
-{
-	struct _IO_FILE *fp = tcpid_to_fd(cepid);
-	FLGPTN flgptn = 0;
-	ER ret;
-	int len;
-
-	if (fp == NULL)
-		return E_PAR;
-
-	int fd = fp->fd;
-	FD_SET(fd, (fd_set *)&flgptn);
-
-	switch (fncd) {
-	case TFN_TCP_RCV_BUF:
-		len = *(int *)p_parblk;
-		if (len <= 0)
-			return E_OK;
-
-		ret = wai_sem(SEM_FILEDESC);
-		if (ret < 0) {
-			syslog(LOG_ERROR, "wai_sem => %d", ret);
-		}
-		fp->psock->len += len;
-		ret = sig_sem(SEM_FILEDESC);
-		if (ret < 0) {
-			syslog(LOG_ERROR, "sig_sem => %d", ret);
-		}
-
-		if (fp->readevt_w == fp->readevt_r) fp->readevt_w++;
-
-		set_flg(FLG_SELECT_WAIT, flgptn);
-		return E_OK;
-
-	case TFN_TCP_RCV_DAT:
-		len = *(int *)p_parblk;
-		if (len <= 0)
-			return E_OK;
-
-		ret = wai_sem(SEM_FILEDESC);
-		if (ret < 0) {
-			syslog(LOG_ERROR, "wai_sem => %d", ret);
-		}
-		fp->psock->len += len;
-		ret = sig_sem(SEM_FILEDESC);
-		if (ret < 0) {
-			syslog(LOG_ERROR, "sig_sem => %d", ret);
-		}
-
-		if (fp->readevt_w == fp->readevt_r) fp->readevt_w++;
-
-		set_flg(FLG_SELECT_WAIT, flgptn);
-		return E_OK;
-
-	case TFN_TCP_SND_DAT:
-		if (fp->writeevt_w == fp->writeevt_r) fp->writeevt_w++;
-
-		set_flg(FLG_SELECT_WAIT, flgptn);
-		return E_OK;
-
-	case TFN_TCP_CAN_CEP:
-		if (fp->errorevt_w == fp->errorevt_r) fp->errorevt_w++;
-
-		set_flg(FLG_SELECT_WAIT, flgptn);
-		return E_OK;
-
-	case TFN_TCP_DEL_REP:
-		delete_tcp_rep(cepid);
-		return E_OK;
-
-	case TFN_TCP_DEL_CEP:
-		delete_tcp_fd(cepid);
-		return E_OK;
-
-	default:
-		return E_OK;
-	}
-}
-
-ER socket_udp_callback(ID cepid, FN fncd, void *p_parblk)
-{
-	struct _IO_FILE *fp = udpid_to_fd(cepid);
-	FLGPTN flgptn = 0;
-	int len;
-
-	if (fp == NULL)
-		return E_PAR;
-
-	int fd = fp->fd;
-	FD_SET(fd, (fd_set *)&flgptn);
-
-	switch (fncd) {
-	case TEV_UDP_RCV_DAT:
-	{
-		T_UDP_RCV_DAT_PARA *udppara = (T_UDP_RCV_DAT_PARA *)p_parblk;
-		len = udppara->len;
-		if (len <= 0)
-			return E_OK;
-
-		ER ret = wai_sem(SEM_FILEDESC);
-		if (ret < 0) {
-			syslog(LOG_ERROR, "wai_sem => %d", ret);
-		}
-		fp->psock->len = len;
-		if (fp->psock->input != NULL) {
-			ret = rel_net_buf(fp->psock->input);
-			if (ret < 0) {
-				syslog(LOG_ERROR, "rel_net_buf => %d", ret);
-			}
-		}
-		fp->psock->input = udppara->input;
-		fp->psock->buf = GET_UDP_SDU(udppara->input, udppara->off);
-		memset(&fp->psock->raddr4, 0, sizeof(fp->psock->raddr4));
-		fp->psock->raddr4.sin_family = AF_INET;
-		fp->psock->raddr4.sin_port = htons(udppara->rep4.portno);
-		fp->psock->raddr4.sin_addr.s_addr = htonl(udppara->rep4.ipaddr);
-		udppara->input->flags |= NB_FLG_NOREL_IFOUT;
-		ret = sig_sem(SEM_FILEDESC);
-		if (ret < 0) {
-			syslog(LOG_ERROR, "sig_sem => %d", ret);
-		}
-
-		if (fp->readevt_w == fp->readevt_r) fp->readevt_w++;
-
-		set_flg(FLG_SELECT_WAIT, flgptn);
-		return E_OK;
-	}
-	case TFN_UDP_CRE_CEP:
-		return E_OK;
-
-	case TFN_UDP_RCV_DAT:
-		len = *(int *)p_parblk;
-		if (len <= 0)
-			return E_OK;
-
-		if (fp->readevt_w == fp->readevt_r) fp->readevt_w++;
-
-		set_flg(FLG_SELECT_WAIT, flgptn);
-		return E_OK;
-
-	case TFN_UDP_SND_DAT:
-		if (fp->writeevt_w == fp->writeevt_r) fp->writeevt_w++;
-
-		set_flg(FLG_SELECT_WAIT, flgptn);
-		return E_OK;
-
-	case TFN_UDP_CAN_CEP:
-		if (fp->errorevt_w == fp->errorevt_r) fp->errorevt_w++;
-
-		set_flg(FLG_SELECT_WAIT, flgptn);
-		return E_OK;
-
-	case TFN_UDP_DEL_CEP:
-		delete_udp_fd(cepid);
-		return E_OK;
-
-	default:
-		return E_OK;
-	}
-}
-
-#endif
 
 ER shell_get_evts(struct fd_events *evts, TMO tmout)
@@ -642,5 +492,5 @@
 		ER ret;
 		FLGPTN waitptn, flgptn, readfds = 0, writefds = 0;
-		struct _IO_FILE *fp = NULL;
+		struct SHELL_FILE *fp = NULL;
 
 		stdio_update_evts();
@@ -656,36 +506,8 @@
 #ifndef NTSHELL_NO_SOCKET
 			if (FD_ISSET(fd, &evts->readfds)) {
-				if ((fp->type == IO_TYPE_TCP) && (fp->psock->cepid != 0)) {
-					if (fp->psock->len == 0) {
-						ret = tcp_rcv_buf(fp->psock->cepid, &fp->psock->input, TMO_NBLK);
-						if ((ret != E_WBLK) && (ret != E_OBJ) && (ret < 0)) {
-							syslog(LOG_ERROR, "tcp_rcv_buf => %d", ret);
-							//return ret;
-						}
-						if (ret > 0) {
-							ret = wai_sem(SEM_FILEDESC);
-							if (ret < 0) {
-								syslog(LOG_ERROR, "wai_sem => %d", ret);
-							}
-							fp->psock->len += ret;
-							ret = sig_sem(SEM_FILEDESC);
-							if (ret < 0) {
-								syslog(LOG_ERROR, "sig_sem => %d", ret);
-							}
-						}
-					}
-					else ret = 1;
-					if (ret > 0) {
-						FD_SET(fd, (fd_set *)&readfds);
-						count++;
-						if (fp->readevt_w == fp->readevt_r) fp->readevt_r--;
-					}
-				}
-				else if ((fp->type == IO_TYPE_UDP) && (fp->psock->cepid != 0)) {
-					if (fp->psock->input != NULL) {
-						FD_SET(fd, (fd_set *)&readfds);
-						count++;
-						if (fp->readevt_w == fp->readevt_r) fp->readevt_r--;
-					}
+				if (fp->type->readable(fp)) {
+					FD_SET(fd, (fd_set *)&readfds);
+					count++;
+					if (fp->readevt_w == fp->readevt_r) fp->readevt_r--;
 				}
 				else {
@@ -786,5 +608,5 @@
 void clean_fd()
 {
-	struct _IO_FILE *fp = NULL;
+	struct SHELL_FILE *fp = NULL;
 	for (int fd = 3; fd < fd_table_count; fd++) {
 		fp = &fd_table[fd];
@@ -792,5 +614,5 @@
 			continue;
 
-		fp->close(fp);
+		fp->type->close(fp);
 
 		delete_fp(fp);
@@ -800,9 +622,9 @@
 int shell_ioctl(int fd, int request, void *arg)
 {
-	struct _IO_FILE *fp = fd_to_fp(fd);
+	struct SHELL_FILE *fp = fd_to_fp(fd);
 	if (fp == NULL)
 		return -EBADF;
 
-	return fp->ioctl(fp, request, arg);
+	return fp->type->ioctl(fp, request, arg);
 }
 
Index: asp3_tinet_ecnl_arm/trunk/ntshell/src/io_stub.c
===================================================================
--- asp3_tinet_ecnl_arm/trunk/ntshell/src/io_stub.c	(revision 369)
+++ asp3_tinet_ecnl_arm/trunk/ntshell/src/io_stub.c	(revision 374)
@@ -1,7 +1,7 @@
 /*
  *  TOPPERS ECHONET Lite Communication Middleware
- * 
+ *
  *  Copyright (C) 2017 Cores Co., Ltd. Japan
- * 
+ *
  *  上記著作権者は，以下の(1)～(4)の条件を満たす場合に限り，本ソフトウェ
  *  ア（本ソフトウェアを改変したものを含む．以下同じ）を使用・複製・改
@@ -26,5 +26,5 @@
  *      由に基づく請求からも，上記著作権者およびTOPPERSプロジェクトを
  *      免責すること．
- * 
+ *
  *  本ソフトウェアは，無保証で提供されているものである．上記著作権者お
  *  よびTOPPERSプロジェクトは，本ソフトウェアに関して，特定の使用目的
@@ -32,5 +32,5 @@
  *  アの利用により直接的または間接的に生じたいかなる損害に関しても，そ
  *  の責任を負わない．
- * 
+ *
  *  @(#) $Id$
  */
@@ -43,4 +43,5 @@
 #include <sil.h>
 #include <string.h>
+#include "syssvc/serial.h"
 #include "syssvc/syslog.h"
 #include "socket_stub.h"
@@ -49,4 +50,5 @@
 #include "core/ntlibc.h"
 #include "kernel_cfg.h"
+#include "target_syssvc.h"
 
 int fresult2errno(FRESULT res)
@@ -77,15 +79,37 @@
 }
 
-int shell_open(const char * path, int flags, void *arg)
-{
-	FRESULT res;
-	struct _IO_FILE *fp;
+static int file_close(struct SHELL_FILE *fp);
+static size_t file_read(struct SHELL_FILE *fp, unsigned char *data, size_t len);
+static size_t file_write(struct SHELL_FILE *fp, const unsigned char *data, size_t len);
+static off_t file_seek(struct SHELL_FILE *fp, off_t ofs, int org);
+static int file_ioctl(struct SHELL_FILE *fp, int req, void *arg);
+static bool_t file_readable(struct SHELL_FILE *fp);
+static void file_delete(struct SHELL_FILE *fp);
+
+static int dir_close(struct SHELL_FILE *fp);
+static size_t dir_read(struct SHELL_FILE *fp, unsigned char *data, size_t len);
+static size_t dir_write(struct SHELL_FILE *fp, const unsigned char *data, size_t len);
+static off_t dir_seek(struct SHELL_FILE *fp, off_t ofs, int org);
+static int dir_ioctl(struct SHELL_FILE *fp, int req, void *arg);
+static bool_t dir_readable(struct SHELL_FILE *fp);
+static void dir_delete(struct SHELL_FILE *fp);
+
+IO_TYPE IO_TYPE_FILE = { file_close, file_read, file_write, file_seek, file_ioctl, file_readable, file_delete };
+IO_TYPE IO_TYPE_DIR = { dir_close, dir_read, dir_write, dir_seek, dir_ioctl, dir_readable, dir_delete };
+
+int shell_open(const char *path, int flags, void *arg)
+{
+	FRESULT res;
+	struct SHELL_FILE *fp;
 
 	if (flags & O_DIRECTORY) {
-		fp = new_dir_fd(0);
+		fp = new_fp(&IO_TYPE_DIR, 0, 0);
 		if (fp == NULL)
 			return -ENOMEM;
 
-		DIR *dir = &fp->pdir->dir;
+		fp->exinf = malloc(sizeof(struct SHELL_DIR));
+		memset(fp->exinf, 0, sizeof(struct SHELL_DIR));
+
+		FATFS_DIR *dir = &((struct SHELL_DIR *)fp->exinf)->dir;
 		FRESULT res;
 		if ((res = f_opendir(dir, path)) != FR_OK) {
@@ -95,7 +119,10 @@
 	}
 
-	fp = new_file_fd(0);
+	fp = new_fp(&IO_TYPE_FILE, 0, 1);
 	if (fp == NULL)
 		return -ENOMEM;
+
+	fp->exinf = malloc(sizeof(FIL));
+	memset(fp->exinf, 0, sizeof(FIL));
 
 	BYTE fmd = 0;
@@ -133,5 +160,5 @@
 	}
 
-	if ((res = f_open(fp->pfile, path, fmd)) == FR_OK) {
+	if ((res = f_open((FIL *)fp->exinf, path, fmd)) == FR_OK) {
 		fp->handle = fp->fd;
 		return fp->fd;
@@ -141,9 +168,9 @@
 }
 
-int file_close(struct _IO_FILE *fp)
-{
-	FRESULT res;
-
-	if ((res = f_close(fp->pfile)) == FR_OK) {
+int file_close(struct SHELL_FILE *fp)
+{
+	FRESULT res;
+
+	if ((res = f_close((FIL *)fp->exinf)) == FR_OK) {
 		return 0;
 	}
@@ -152,10 +179,10 @@
 }
 
-size_t file_read(struct _IO_FILE *fp, unsigned char *data, size_t len)
+size_t file_read(struct SHELL_FILE *fp, unsigned char *data, size_t len)
 {
 	unsigned int ret = 0;
 	FRESULT res;
 
-	if ((res = f_read(fp->pfile, data, len, &ret)) != FR_OK)
+	if ((res = f_read((FIL *)fp->exinf, data, len, &ret)) != FR_OK)
 		return -EIO;
 
@@ -163,10 +190,10 @@
 }
 
-size_t file_write(struct _IO_FILE *fp, const unsigned char *data, size_t len)
+size_t file_write(struct SHELL_FILE *fp, const unsigned char *data, size_t len)
 {
 	unsigned int ret = 0;
 	FRESULT res;
 
-	if ((res = f_write(fp->pfile, data, len, &ret)) != FR_OK)
+	if ((res = f_write((FIL *)fp->exinf, data, len, &ret)) != FR_OK)
 		return -EIO;
 
@@ -174,5 +201,5 @@
 }
 
-off_t file_seek(struct _IO_FILE *fp, off_t ptr, int dir)
+off_t file_seek(struct SHELL_FILE *fp, off_t ptr, int dir)
 {
 	switch (dir) {
@@ -191,15 +218,15 @@
 
 	FRESULT res;
-	if ((res = f_seek(fp->pfile, ptr, dir)) != FR_OK)
+	if ((res = f_seek((FIL *)fp->exinf, ptr, dir)) != FR_OK)
 		return -EIO;
 
-	return fp->pfile->fptr;
-}
-
-int file_ioctl(struct _IO_FILE *fp, int req, void *arg)
+	return ((FIL *)fp->exinf)->fptr;
+}
+
+int file_ioctl(struct SHELL_FILE *fp, int req, void *arg)
 {
 	DRESULT res;
 
-	if ((res = disk_ioctl(fp->pfile->fs->drv, req, arg) != RES_OK))
+	if ((res = disk_ioctl(((FIL *)fp->exinf)->fs->drv, req, arg) != RES_OK))
 		return -EINVAL;
 
@@ -207,11 +234,22 @@
 }
 
+bool_t file_readable(struct SHELL_FILE *fp)
+{
+	return fp->readevt_w != fp->readevt_r;
+}
+
+void file_delete(struct SHELL_FILE *fp)
+{
+	free((FIL *)fp->exinf);
+	fp->exinf = NULL;
+}
+
 int shell_close(int fd)
 {
-	struct _IO_FILE *fp = fd_to_fp(fd);
-	if (fp == NULL)
-		return -EBADF;
-
-	int ret = fp->close(fp);
+	struct SHELL_FILE *fp = fd_to_fp(fd);
+	if (fp == NULL)
+		return -EBADF;
+
+	int ret = fp->type->close(fp);
 
 	delete_fp(fp);
@@ -222,9 +260,9 @@
 ssize_t shell_read(int fd, void *data, size_t len)
 {
-	struct _IO_FILE *fp = fd_to_fp(fd);
-	if (fp == NULL)
-		return -EBADF;
-
-	return fp->read(fp, (unsigned char *)data, len);
+	struct SHELL_FILE *fp = fd_to_fp(fd);
+	if (fp == NULL)
+		return -EBADF;
+
+	return fp->type->read(fp, (unsigned char *)data, len);
 }
 
@@ -232,5 +270,5 @@
 {
 	int result = 0;
-	struct _IO_FILE *fp = fd_to_fp(fd);
+	struct SHELL_FILE *fp = fd_to_fp(fd);
 	if (fp == NULL)
 		return -EBADF;
@@ -238,5 +276,5 @@
 	const struct iovec *end = &iov[iovcnt];
 	for (; iov < end; iov++) {
-		result += fp->read(fp, (unsigned char *)iov->iov_base, iov->iov_len);
+		result += fp->type->read(fp, (unsigned char *)iov->iov_base, iov->iov_len);
 	}
 
@@ -246,9 +284,9 @@
 ssize_t shell_write(int fd, const void *data, size_t len)
 {
-	struct _IO_FILE *fp = fd_to_fp(fd);
-	if (fp == NULL)
-		return -EBADF;
-
-	return fp->write(fp, (unsigned char *)data, len);
+	struct SHELL_FILE *fp = fd_to_fp(fd);
+	if (fp == NULL)
+		return -EBADF;
+
+	return fp->type->write(fp, (unsigned char *)data, len);
 }
 
@@ -256,5 +294,5 @@
 {
 	int result = 0;
-	struct _IO_FILE *fp = fd_to_fp(fd);
+	struct SHELL_FILE *fp = fd_to_fp(fd);
 	if (fp == NULL)
 		return -EBADF;
@@ -262,5 +300,5 @@
 	const struct iovec *end = &iov[iovcnt];
 	for (; iov < end; iov++) {
-		result += fp->write(fp, (unsigned char *)iov->iov_base, iov->iov_len);
+		result += fp->type->write(fp, (unsigned char *)iov->iov_base, iov->iov_len);
 	}
 
@@ -270,9 +308,9 @@
 int shell_llseek(int fd, off_t ptr, off_t *result, int dir)
 {
-	struct _IO_FILE *fp = fd_to_fp(fd);
-	if (fp == NULL)
-		return -EBADF;
-
-	off_t ret = fp->seek(fp, ptr, dir);
+	struct SHELL_FILE *fp = fd_to_fp(fd);
+	if (fp == NULL)
+		return -EBADF;
+
+	off_t ret = fp->type->seek(fp, ptr, dir);
 	if (ret < 0)
 		return ret;
@@ -284,5 +322,5 @@
 int shell_fstat(int fd, struct stat * st)
 {
-	struct _IO_FILE *fp = fd_to_fp(fd);
+	struct SHELL_FILE *fp = fd_to_fp(fd);
 	if (fp == NULL)
 		return -EBADF;
@@ -296,5 +334,5 @@
 int shell_fsync(int fd)
 {
-	struct _IO_FILE *fp = fd_to_fp(fd);
+	struct SHELL_FILE *fp = fd_to_fp(fd);
 	if (fp == NULL)
 		return -EBADF;
@@ -304,10 +342,10 @@
 int shell_ftruncate(int fd, off_t length)
 {
-	struct _IO_FILE *fp = fd_to_fp(fd);
-	if (fp == NULL)
-		return -EBADF;
-
-	FRESULT res;
-	if ((res = f_truncate(fp->pfile)) != FR_OK)
+	struct SHELL_FILE *fp = fd_to_fp(fd);
+	if (fp == NULL)
+		return -EBADF;
+
+	FRESULT res;
+	if ((res = f_truncate((FIL *)fp->exinf)) != FR_OK)
 		return fresult2errno(res);
 
@@ -320,72 +358,80 @@
 }
 
+extern IO_TYPE IO_TYPE_SIO;
+
 int sio_tcgetattr(int fd, struct termios *termios)
 {
-	extern ntstdio_t ntstdio;
-
-	if (fd == STDIN_FILENO) {
-		memset(termios, 0, sizeof(*termios));
-
-		if (ntstdio.option & NTSTDIO_OPTION_LINE_ECHO) {
-			termios->c_lflag |= ECHO;
+	struct SHELL_FILE *fp = fd_to_fp(fd);
+	if ((fp == NULL) || (fp->type != &IO_TYPE_SIO))
+		return -EBADF;
+
+	ntstdio_t *ntstdio = (ntstdio_t *)fp->exinf;
+
+	memset(termios, 0, sizeof(*termios));
+
+	if (ntstdio->option & NTSTDIO_OPTION_LINE_ECHO) {
+		termios->c_lflag |= ECHO;
+	}
+	else {
+		termios->c_lflag &= ~ECHO;
+	}
+	if (ntstdio->option & NTSTDIO_OPTION_CANON) {
+		termios->c_lflag |= ICANON;
+	}
+	else {
+		termios->c_lflag &= ~ICANON;
+	}
+	if (ntstdio->option & NTSTDIO_OPTION_LF_CR) {
+		termios->c_iflag |= INLCR;
+	}
+	else {
+		termios->c_iflag &= ~INLCR;
+	}
+	if (ntstdio->option & NTSTDIO_OPTION_LF_CRLF) {
+		termios->c_oflag |= ONLCR;
+	}
+	else {
+		termios->c_oflag &= ~ONLCR;
+	}
+
+	return 0;
+}
+
+int sio_tcsetattr(int fd, int optional_actions, const struct termios *termios)
+{
+	struct SHELL_FILE *fp = fd_to_fp(fd);
+	if ((fp == NULL) || (fp->type != &IO_TYPE_SIO))
+		return -EBADF;
+
+	ntstdio_t *ntstdio = (ntstdio_t *)fp->exinf;
+
+	if (optional_actions == TCSANOW) {
+		if (termios->c_lflag & ECHO) {
+			ntstdio->option |= NTSTDIO_OPTION_LINE_ECHO;
 		}
 		else {
-			termios->c_lflag &= ~ECHO;
-		}
-		if (ntstdio.option & NTSTDIO_OPTION_CANON) {
-			termios->c_lflag |= ICANON;
+			ntstdio->option &= ~NTSTDIO_OPTION_LINE_ECHO;
+		}
+		if (termios->c_lflag & ICANON) {
+			ntstdio->option |= NTSTDIO_OPTION_CANON;
 		}
 		else {
-			termios->c_lflag &= ~ICANON;
-		}
-		if (ntstdio.option & NTSTDIO_OPTION_LF_CR) {
-			termios->c_iflag |= INLCR;
+			ntstdio->option &= ~NTSTDIO_OPTION_CANON;
+		}
+		if (termios->c_iflag & INLCR) {
+			ntstdio->option |= NTSTDIO_OPTION_LF_CR;
 		}
 		else {
-			termios->c_iflag &= ~INLCR;
-		}
-		if (ntstdio.option & NTSTDIO_OPTION_LF_CRLF) {
-			termios->c_oflag |= ONLCR;
+			ntstdio->option &= ~NTSTDIO_OPTION_LF_CR;
+		}
+		if (termios->c_oflag & ONLCR) {
+			ntstdio->option |= NTSTDIO_OPTION_LF_CRLF;
 		}
 		else {
-			termios->c_oflag &= ~ONLCR;
+			ntstdio->option &= ~NTSTDIO_OPTION_LF_CRLF;
 		}
 		return 0;
 	}
-	shell_abort();
-	return 0;
-}
-
-int sio_tcsetattr(int fd, int optional_actions, const struct termios *termios)
-{
-	extern ntstdio_t ntstdio;
-
-	if ((fd == STDIN_FILENO) && (optional_actions == TCSANOW)) {
-		if (termios->c_lflag & ECHO) {
-			ntstdio.option |= NTSTDIO_OPTION_LINE_ECHO;
-		}
-		else {
-			ntstdio.option &= ~NTSTDIO_OPTION_LINE_ECHO;
-		}
-		if (termios->c_lflag & ICANON) {
-			ntstdio.option |= NTSTDIO_OPTION_CANON;
-		}
-		else {
-			ntstdio.option &= ~NTSTDIO_OPTION_CANON;
-		}
-		if (termios->c_iflag & INLCR) {
-			ntstdio.option |= NTSTDIO_OPTION_LF_CR;
-		}
-		else{
-			ntstdio.option &= ~NTSTDIO_OPTION_LF_CR;
-		}
-		if (termios->c_oflag & ONLCR) {
-			ntstdio.option |= NTSTDIO_OPTION_LF_CRLF;
-		}
-		else {
-			ntstdio.option &= ~NTSTDIO_OPTION_LF_CRLF;
-		}
-		return 0;
-	}
+
 	shell_abort();
 	return 0;
@@ -396,11 +442,11 @@
 	FILINFO fi;
 	FRESULT ret;
-#if _USE_LFN
-	static char lfn[_MAX_LFN + 1];   /* Buffer to store the LFN */
+#if FF_USE_LFN
+	static char lfn[FF_MAX_LFN + 1];   /* Buffer to store the LFN */
 	fi.lfname = lfn;
 	fi.lfsize = sizeof lfn;
 #endif
 	if (strcmp(path, ".") == 0) {
-		char cwd[_MAX_LFN];
+		char cwd[FF_MAX_LFN];
 		if ((ret = f_getcwd(cwd, sizeof(cwd))) != FR_OK) {
 			return fresult2errno(ret);
@@ -426,5 +472,5 @@
 	st->st_mtim.tv_nsec = 0;
 	st->st_mtim.tv_sec = fi.fdate + fi.ftime;
-	st->st_mode  = (S_IRUSR | S_IRGRP | S_IROTH);
+	st->st_mode = (S_IRUSR | S_IRGRP | S_IROTH);
 	st->st_mode |= (fi.fattrib & AM_RDO) ? 0 : (S_IWUSR | S_IWGRP | S_IWOTH);
 	st->st_mode |= (fi.fattrib & (AM_DIR | AM_VOL)) ? S_IFDIR : S_IFREG;
@@ -485,6 +531,6 @@
 	BYTE mask = AM_RDO | AM_SYS; // AM_ARC, AM_HID
 
-	if(mode & S_IREAD) {
-		if((mode & S_IWRITE) == 0) {
+	if (mode & S_IREAD) {
+		if ((mode & S_IWRITE) == 0) {
 			attr |= AM_RDO;
 		}
@@ -494,5 +540,5 @@
 	}
 
-	if((res = f_chmod(path, attr, mask)) != FR_OK) {
+	if ((res = f_chmod(path, attr, mask)) != FR_OK) {
 		return fresult2errno(res);
 	}
@@ -507,6 +553,6 @@
 	BYTE mask = AM_RDO | AM_SYS; // AM_ARC, AM_HID
 
-	if(mode & S_IREAD) {
-		if((mode & S_IWRITE) == 0) {
+	if (mode & S_IREAD) {
+		if ((mode & S_IWRITE) == 0) {
 			attr |= AM_RDO;
 		}
@@ -516,5 +562,5 @@
 	}
 
-	if((res = f_chmod(path, attr, mask)) != FR_OK) {
+	if ((res = f_chmod(path, attr, mask)) != FR_OK) {
 		return fresult2errno(res);
 	}
@@ -526,5 +572,5 @@
 {
 	FRESULT ret;
-	if((ret = f_getcwd(buf, size)) != FR_OK) {
+	if ((ret = f_getcwd(buf, size)) != FR_OK) {
 		return NULL;
 	}
@@ -549,8 +595,8 @@
 }
 
-int dir_close(struct _IO_FILE *fp)
-{
-	FRESULT res;
-	if ((res = f_closedir(&fp->pdir->dir)) != FR_OK) {
+int dir_close(struct SHELL_FILE *fp)
+{
+	FRESULT res;
+	if ((res = f_closedir(&((struct SHELL_DIR *)fp->exinf)->dir)) != FR_OK) {
 		return fresult2errno(res);
 	}
@@ -564,21 +610,21 @@
 		return -EINVAL;
 
-	struct _IO_FILE *fp = fd_to_fp(fd);
+	struct SHELL_FILE *fp = fd_to_fp(fd);
 	if (fp == NULL)
 		return -EBADF;
 
 	FILINFO fno;
-#if _USE_LFN
-	static char lfn[_MAX_LFN + 1];   /* Buffer to store the LFN */
+#if FF_USE_LFN
+	static char lfn[FF_MAX_LFN + 1];   /* Buffer to store the LFN */
 	fno.lfname = lfn;
 	fno.lfsize = sizeof lfn;
 #endif
 	FRESULT res;
-	if ((res = f_readdir(&fp->pdir->dir, &fno)) != FR_OK || fno.fname[0] == '\0') {
+	if ((res = f_readdir(&((struct SHELL_DIR *)fp->exinf)->dir, &fno)) != FR_OK || fno.fname[0] == '\0') {
 		return fresult2errno(res);
 	}
 
 	memset(de, 0, sizeof(*de));
-#if _USE_LFN
+#if FF_USE_LFN
 	ntlibc_strlcpy(de->d_name, *fno.lfname ? fno.lfname : fno.fname, sizeof(de->d_name));
 #else
@@ -589,15 +635,15 @@
 }
 
-size_t dir_read(struct _IO_FILE *fp, unsigned char *data, size_t len)
+size_t dir_read(struct SHELL_FILE *fp, unsigned char *data, size_t len)
 {
 	return -EPERM;
 }
 
-size_t dir_write(struct _IO_FILE *fp, const unsigned char *data, size_t len)
+size_t dir_write(struct SHELL_FILE *fp, const unsigned char *data, size_t len)
 {
 	return -EPERM;
 }
 
-off_t dir_seek(struct _IO_FILE *fp, off_t ptr, int dir)
+off_t dir_seek(struct SHELL_FILE *fp, off_t ptr, int dir)
 {
 	FRESULT res;
@@ -607,5 +653,5 @@
 
 	if (ptr == 0) {
-		if ((res = f_rewinddir(&fp->pdir->dir)) != FR_OK) {
+		if ((res = f_rewinddir(&((struct SHELL_DIR *)fp->exinf)->dir)) != FR_OK) {
 			return fresult2errno(res);
 		}
@@ -613,15 +659,15 @@
 	else {
 		FILINFO fno;
-#if _USE_LFN
-		static char lfn[_MAX_LFN + 1];   /* Buffer to store the LFN */
+#if FF_USE_LFN
+		static char lfn[FF_MAX_LFN + 1];   /* Buffer to store the LFN */
 		fno.lfname = lfn;
 		fno.lfsize = sizeof lfn;
 #endif
-		if ((res = f_rewinddir(&fp->pdir->dir)) != FR_OK) {
+		if ((res = f_rewinddir(&((struct SHELL_DIR *)fp->exinf)->dir)) != FR_OK) {
 			return fresult2errno(res);
 		}
 
 		for (int i = 0; i < ptr; i++) {
-			if ((res = f_readdir(&fp->pdir->dir, &fno)) != FR_OK || fno.fname[0] == '\0') {
+			if ((res = f_readdir(&((struct SHELL_DIR *)fp->exinf)->dir, &fno)) != FR_OK || fno.fname[0] == '\0') {
 				return fresult2errno(res);
 			}
@@ -632,7 +678,18 @@
 }
 
-int dir_ioctl(struct _IO_FILE *fp, int req, void *arg)
+int dir_ioctl(struct SHELL_FILE *fp, int req, void *arg)
 {
 	return -EINVAL;
+}
+
+bool_t dir_readable(struct SHELL_FILE *fp)
+{
+	return fp->readevt_w != fp->readevt_r;
+}
+
+void dir_delete(struct SHELL_FILE *fp)
+{
+	free((struct SHELL_DIR *)fp->exinf);
+	fp->exinf = NULL;
 }
 
@@ -687,68 +744,6 @@
 {
 	//if ((addr >= (void *)&__HeapBase) && (addr + len < (void *)&__HeapLimit)) {
-		return 0;
-	//}
-	//return -1;
-}
-
-#include "tlsf.h"
-
-static tlsf_t sys_tlsf;
-static pool_t sys_pool;
-
-void sys_init(void)
-{
-	sys_tlsf = tlsf_create(&__HeapBase);
-	if (sys_tlsf == NULL)
-		return;
-
-	sys_pool = tlsf_add_pool(sys_tlsf, ((uint8_t *)&__HeapBase) + tlsf_size(), ((intptr_t)&__HeapLimit - (intptr_t)&__HeapBase) - tlsf_size());
-}
-
-void sys_fini(void)
-{
-	tlsf_destroy(sys_tlsf);
-}
-
-void *malloc(size_t size)
-{
-	void *result;
-	wai_sem(SEM_MALLOC);
-	result = tlsf_malloc(sys_tlsf, size);
-	sig_sem(SEM_MALLOC);
-	if (result == NULL)
-		tlsf_check_pool(sys_pool);
-	return result;
-}
-
-void *calloc(size_t size, size_t count)
-{
-	void *result;
-	wai_sem(SEM_MALLOC);
-	result = tlsf_malloc(sys_tlsf, count * size);
-	sig_sem(SEM_MALLOC);
-	if (result != NULL)
-		memset(result, 0, count * size);
-	else
-		tlsf_check_pool(sys_pool);
-	return result;
-}
-
-void *realloc(void *ptr, size_t size)
-{
-	void *result;
-	wai_sem(SEM_MALLOC);
-	result = tlsf_realloc(sys_tlsf, ptr, size);
-	sig_sem(SEM_MALLOC);
-	if (result == NULL)
-		tlsf_check_pool(sys_pool);
-	return result;
-}
-
-void free(void *ptr)
-{
-	wai_sem(SEM_MALLOC);
-	tlsf_free(sys_tlsf, ptr);
-	sig_sem(SEM_MALLOC);
-}
-
+	return 0;
+//}
+//return -1;
+}
Index: asp3_tinet_ecnl_arm/trunk/ntshell/src/net_misc.c
===================================================================
--- asp3_tinet_ecnl_arm/trunk/ntshell/src/net_misc.c	(revision 369)
+++ asp3_tinet_ecnl_arm/trunk/ntshell/src/net_misc.c	(revision 374)
@@ -60,7 +60,5 @@
 #include "kernel_cfg.h"
 #include "tinet_cfg.h"
-#include "util/ntstdio.h"
-
-extern ntstdio_t ntstdio;
+#include <stdio.h>
 
 T_DHCP4_CLI_CONTEXT *dhcp4_cli_initialize(ID tskid, ID cepid);
@@ -97,5 +95,5 @@
 
 	get_tid(&nc->tskid);
-	ntstdio_printf(&ntstdio, "[NET MISC:%d,%d] started.", nc->tskid, (ID)exinf);
+	printf("[NET MISC:%d,%d] started.", nc->tskid, (ID)exinf);
 
 	/* 初期化 */
@@ -105,5 +103,5 @@
 	ret = get_tim(&time);
 	if (ret != E_OK) {
-		ntstdio_printf(&ntstdio, "[NET MISC,%d] get_tim error: %7lu,%s",
+		printf("[NET MISC,%d] get_tim error: %7lu,%s",
 			nc->cepid, time / SYSTIM_HZ, itron_strerror(ret));
 		return;
@@ -119,5 +117,5 @@
 		error = tslp_tsk(timer);
 		if ((error != E_OK) && (error != E_TMOUT)) {
-			ntstdio_printf(&ntstdio, "[NET MISC,%d] tslp_tsk error: %s %d",
+			printf("[NET MISC,%d] tslp_tsk error: %s %d",
 				nc->cepid, itron_strerror(error), timer);
 			break;
@@ -126,5 +124,5 @@
 		ret = get_tim(&time);
 		if (ret != E_OK) {
-			ntstdio_printf(&ntstdio, "[NET MISC,%d] get_tim error: %s",
+			printf("[NET MISC,%d] get_tim error: %s",
 				nc->cepid, itron_strerror(ret));
 			break;
Index: asp3_tinet_ecnl_arm/trunk/ntshell/src/netcmd.c
===================================================================
--- asp3_tinet_ecnl_arm/trunk/ntshell/src/netcmd.c	(revision 369)
+++ asp3_tinet_ecnl_arm/trunk/ntshell/src/netcmd.c	(revision 374)
@@ -59,9 +59,7 @@
 #include <netapp/resolver.h>
 #include "core/ntlibc.h"
-#include "util/ntstdio.h"
+#include <stdio.h>
 #include "ntp_cli.h"
 #include "kernel_cfg.h"
-
-extern ntstdio_t ntstdio;
 
 #if defined(SUPPORT_INET6)
@@ -280,5 +278,5 @@
 
 	if ((line = lookup_ipaddr(&addr, line, apip)) == NULL) {
-		ntstdio_printf(&ntstdio, "[PING] unknown host.\n");
+		printf("[PING] unknown host.\n");
 		return 0;
 	}
@@ -299,18 +297,18 @@
 #if defined(SUPPORT_INET4)
 	if (apip == API_PROTO_IPV6) {
-		ntstdio_printf(&ntstdio, "[PING6] size: %d, tmo: %d, host: %s\n", size, tmo, ipv62str(NULL, &addr));
+		printf("[PING6] size: %d, tmo: %d, host: %s\n", size, tmo, ipv62str(NULL, &addr));
 		ping6(&addr, (uint_t)tmo, (uint_t)size);
 	}
 	else {
 		addr4 = ntohl(addr.s6_addr32[3]);
-		ntstdio_printf(&ntstdio, "[PING4] size: %d, tmo: %d, host: %s\n", size, tmo, ip2str(NULL, &addr4));
+		printf("[PING4] size: %d, tmo: %d, host: %s\n", size, tmo, ip2str(NULL, &addr4));
 		ping4(&addr4, (uint_t)tmo, (uint_t)size);
 	}
 #else /* of #if defined(SUPPORT_INET4) */
-	ntstdio_printf(&ntstdio, "[PING6] size: %d, tmo: %d, host: %s\n", size, tmo, ipv62str(NULL, &addr));
+	printf("[PING6] size: %d, tmo: %d, host: %s\n", size, tmo, ipv62str(NULL, &addr));
 	ping6(&addr, (uint_t)tmo, (uint_t)size);
 #endif	/* of #if defined(SUPPORT_INET4) */
 #else	/* of #if defined(SUPPORT_INET6) */
-	ntstdio_printf(&ntstdio, "[PING4] size: %d, tmo: %d, host: %s\n", size, tmo, ip2str(NULL, &addr));
+	printf("[PING4] size: %d, tmo: %d, host: %s\n", size, tmo, ip2str(NULL, &addr));
 	ping4(&addr, (uint_t)tmo, (uint_t)size);
 #endif	/* of #if defined(SUPPORT_INET6) */
@@ -331,13 +329,13 @@
 		pos = str_ipv4addr(temp, sizeof(temp), &svaddr, 0);
 		temp[pos] = '\0';
-		ntstdio_printf(&ntstdio, "DHCPv4 server: %s,\n", temp);
-		ntstdio_printf(&ntstdio, "  Renew:       %u:%02u:%02u,\n",
+		printf("DHCPv4 server: %s,\n", temp);
+		printf("  Renew:       %u:%02u:%02u,\n",
 			renew / 3600, (renew / 60) % 60, renew % 60);
-		ntstdio_printf(&ntstdio, "  Rebind:      %u:%02u:%02u, Expire:   %u:%02u:%02u.\n",
+		printf("  Rebind:      %u:%02u:%02u, Expire:   %u:%02u:%02u.\n",
 			rebind / 3600, (rebind / 60) % 60, rebind % 60,
 			expire / 3600, (expire / 60) % 60, expire % 60);
 	}
 	else if (ret == E_OBJ)
-		ntstdio_printf(&ntstdio, "DHCPv4 server: not available.\n");
+		printf("DHCPv4 server: not available.\n");
 }
 
@@ -351,9 +349,9 @@
 	if (ntlibc_strcmp(argv[1], "rel") == 0) {
 		ret = dhcp4c_rel_info();
-		ntstdio_printf(&ntstdio, "dhcp4c_rel_info %d\n", ret);
+		printf("dhcp4c_rel_info %d\n", ret);
 	}
 	else if (ntlibc_strcmp(argv[1], "renew") == 0) {
 		ret = dhcp4c_renew_info();
-		ntstdio_printf(&ntstdio, "dhcp4c_renew_info %d\n", ret);
+		printf("dhcp4c_renew_info %d\n", ret);
 	}
 	else {
@@ -383,8 +381,8 @@
 		else {
 			for (c = 1; c <= *ptr; c++)
-				ntstdio_printf(&ntstdio, "%c", *(ptr + c));
+				printf("%c", *(ptr + c));
 			ptr += *ptr + 1;
 			if (*ptr)
-				ntstdio_printf(&ntstdio, ".");
+				printf(".");
 		}
 	}
@@ -406,16 +404,16 @@
 		return error;
 
-	ntstdio_printf(&ntstdio, "    mname:   ");
+	printf("    mname:   ");
 	rn_offset = s_show_dns_domain_name(msg, offset);
-	ntstdio_putc(&ntstdio, '\n');
-	ntstdio_printf(&ntstdio, "    rname:   ");
+	putchar('\n');
+	printf("    rname:   ");
 	s_show_dns_domain_name(msg, rn_offset);
-	ntstdio_putc(&ntstdio, '\n');
-
-	ntstdio_printf(&ntstdio, "    serial:  %d\n", soa.serial);
-	ntstdio_printf(&ntstdio, "    refresh: %d\n", soa.refresh);
-	ntstdio_printf(&ntstdio, "    retry:   %d\n", soa.retry);
-	ntstdio_printf(&ntstdio, "    expirel: %d\n", soa.expire);
-	ntstdio_printf(&ntstdio, "    minimum: %d\n", soa.minimum);
+	putchar('\n');
+
+	printf("    serial:  %d\n", soa.serial);
+	printf("    refresh: %d\n", soa.refresh);
+	printf("    retry:   %d\n", soa.retry);
+	printf("    expirel: %d\n", soa.expire);
+	printf("    minimum: %d\n", soa.minimum);
 
 	return E_OK;
@@ -433,5 +431,5 @@
 	int		scount;
 
-	ntstdio_printf(&ntstdio, "question   section: %d\n", rslv->dns_hdr.qdcount);
+	printf("question   section: %d\n", rslv->dns_hdr.qdcount);
 	offset = rslv->qd_offset;
 	for (scount = 1; scount <= rslv->dns_hdr.qdcount; scount++) {
@@ -439,7 +437,7 @@
 			return error;
 
-		ntstdio_printf(&ntstdio, "%2d: ", scount);
+		printf("%2d: ", scount);
 		s_show_dns_domain_name(msg, offset);
-		ntstdio_printf(&ntstdio, "\n    type: %-4s, class: %2s\n", dns_strtype(qd.type), dns_strclass(qd.class));
+		printf("\n    type: %-4s, class: %2s\n", dns_strtype(qd.type), dns_strclass(qd.class));
 		offset = error;
 	}
@@ -463,12 +461,12 @@
 	int pos;
 
-	ntstdio_printf(&ntstdio, "%10s section: %d\n", title, scount);
+	printf("%10s section: %d\n", title, scount);
 	for (count = 1; count <= scount; count++) {
 		if ((error = dns_analyze_rr(&rr, offset, msg, length)) < 0)
 			return error;
 
-		ntstdio_printf(&ntstdio, "%2d: ", count);
+		printf("%2d: ", count);
 		s_show_dns_domain_name(msg, offset);
-		ntstdio_printf(&ntstdio, "\n    type: %-4s, class: %2s, TTL: %2d, len: %3d, offset: 0x%02x\n",
+		printf("\n    type: %-4s, class: %2s, TTL: %2d, len: %3d, offset: 0x%02x\n",
 			dns_strtype(rr.type), dns_strclass(rr.class), rr.ttl, rr.rdlength, rr.rdata_offset);
 
@@ -479,15 +477,15 @@
 			pos = str_ipv4addr(temp, sizeof(temp), &in4_addr, 0);
 			temp[pos] = '\0';
-			ntstdio_printf(&ntstdio, "    IPv4 addr: %s\n", temp);
+			printf("    IPv4 addr: %s\n", temp);
 			break;
 		case DNS_TYPE_NS:
-			ntstdio_printf(&ntstdio, "    host: ");
+			printf("    host: ");
 			s_show_dns_domain_name(msg, rr.rdata_offset);
-			ntstdio_putc(&ntstdio, '\n');
+			putchar('\n');
 			break;
 		case DNS_TYPE_CNAME:
-			ntstdio_printf(&ntstdio, "    host: ");
+			printf("    host: ");
 			s_show_dns_domain_name(msg, rr.rdata_offset);
-			ntstdio_putc(&ntstdio, '\n');
+			putchar('\n');
 			break;
 		case DNS_TYPE_SOA:
@@ -495,7 +493,7 @@
 			break;
 		case DNS_TYPE_PTR:
-			ntstdio_printf(&ntstdio, "     PTR: ");
+			printf("     PTR: ");
 			s_show_dns_domain_name(msg, rr.rdata_offset);
-			ntstdio_putc(&ntstdio, '\n');
+			putchar('\n');
 			break;
 		case DNS_TYPE_AAAA:
@@ -503,17 +501,17 @@
 			pos = str_ipv6addr(temp, sizeof(temp), &in6_addr, 0);
 			temp[pos] = '\0';
-			ntstdio_printf(&ntstdio, "    IPv6 addr: %s\n", temp);
+			printf("    IPv6 addr: %s\n", temp);
 			break;
 		default:
-			ntstdio_printf(&ntstdio, "    data: ");
+			printf("    data: ");
 			col = 32;
 			for (dcount = 0; dcount < rr.rdlength; dcount++) {
-				ntstdio_printf(&ntstdio, "%02x", *(msg + rr.rdata_offset + dcount));
+				printf("%02x", *(msg + rr.rdata_offset + dcount));
 				if (--col == 0) {
-					ntstdio_printf(&ntstdio, "\n          ");
+					printf("\n          ");
 					col = 32;
 				}
 			}
-			ntstdio_putc(&ntstdio, '\n');
+			putchar('\n');
 			break;
 		}
@@ -539,9 +537,9 @@
 #if defined(SUPPORT_INET6)
 
-	ntstdio_printf(&ntstdio, "domain name:     %s\n", dns_in6_get_dname());
+	printf("domain name:     %s\n", dns_in6_get_dname());
 
 #else	/* of #if defined(SUPPORT_INET6) */
 
-	ntstdio_printf(&ntstdio, "domain name:     %s\n", dns_in4_get_dname());
+	printf("domain name:     %s\n", dns_in4_get_dname());
 
 #endif	/* of #if defined(SUPPORT_INET6) */
@@ -549,11 +547,11 @@
 #if defined(SUPPORT_INET6)
 	dns_in6_get_addr(&in6_addr);
-	ntstdio_printf(&ntstdio, "IPv6 DNS server: ");
+	printf("IPv6 DNS server: ");
 	if (IN6_IS_ADDR_UNSPECIFIED(&in6_addr))
-		ntstdio_printf(&ntstdio, "not available.\n");
+		printf("not available.\n");
 	else {
 		pos = str_ipv6addr(temp, sizeof(temp), &in6_addr, 0);
 		temp[pos] = '\0';
-		ntstdio_printf(&ntstdio, "%s.\n", temp);
+		printf("%s.\n", temp);
 	}
 #endif	/* of #if defined(SUPPORT_INET6) */
@@ -561,11 +559,11 @@
 #if defined(SUPPORT_INET4)
 	dns_in4_get_addr(&in4_addr);
-	ntstdio_printf(&ntstdio, "IPv4 DNS server: ");
+	printf("IPv4 DNS server: ");
 	if (in4_addr == IPV4_ADDRANY)
-		ntstdio_printf(&ntstdio, "not available.\n");
+		printf("not available.\n");
 	else {
 		pos = str_ipv4addr(temp, sizeof(temp), &in4_addr, 0);
 		temp[pos] = '\0';
-		ntstdio_printf(&ntstdio, "%s.\n", temp);
+		printf("%s.\n", temp);
 	}
 #endif	/* of #if defined(SUPPORT_INET4) */
@@ -604,5 +602,5 @@
 	line = skip_blanks(resolv_options(&flags, line, DEFAULT_API_PROTO));
 	if ((flags & (DNS_LUP_FLAGS_PROTO_IPV6 | DNS_LUP_FLAGS_PROTO_IPV4)) == 0) {
-		ntstdio_printf(&ntstdio, "DNS server not available.\n");
+		printf("DNS server not available.\n");
 		return 0;
 	}
@@ -620,47 +618,47 @@
 
 	if ((error = tget_mpf(MPF_RSLV_SRBUF, (void*)&msg, TMO_FEVR)) != E_OK) {
-		ntstdio_printf(&ntstdio, "get buffer error: %s.\n", itron_strerror(error));
+		printf("get buffer error: %s.\n", itron_strerror(error));
 		return 0;
 	}
 
 	if ((length = dns_lookup_host(flags | DNS_LUP_FLAGS_MSG, line, msg, DNS_UDP_MSG_LENGTH, &rslv)) < 0) {
-		//ntstdio_printf(&ntstdio, "error: %s.\n", itron_strerror(length));
+		//printf("error: %s.\n", itron_strerror(length));
 		goto err_ret;
 	}
 
 	dly_tsk(1 * 1000);
-	ntstdio_printf(&ntstdio, "DNS header: flags: ");
+	printf("DNS header: flags: ");
 	if (rslv.dns_hdr.code & (DNS_QR_RESPONSE | DNS_AUTHORITATIVE |
 		DNS_TRUN_CATION | DNS_RECURSION_DESIRED | DNS_RECURSION_AVAILABLE)) {
-		ntstdio_printf(&ntstdio, (rslv.dns_hdr.code & DNS_QR_RESPONSE) ? "QR," : "");
-		ntstdio_printf(&ntstdio, (rslv.dns_hdr.code & DNS_AUTHORITATIVE) ? "AA," : "");
-		ntstdio_printf(&ntstdio, (rslv.dns_hdr.code & DNS_TRUN_CATION) ? "TC," : "");
-		ntstdio_printf(&ntstdio, (rslv.dns_hdr.code & DNS_RECURSION_DESIRED) ? "RD," : "");
-		ntstdio_printf(&ntstdio, (rslv.dns_hdr.code & DNS_RECURSION_AVAILABLE) ? "RA," : "");
-		ntstdio_printf(&ntstdio, " ");
-	}
-	ntstdio_printf(&ntstdio, "opcode: ");
-	ntstdio_printf(&ntstdio, (rslv.dns_hdr.code & DNS_OPCODE_REVERSE) ? "RV" : "FW");
-	ntstdio_printf(&ntstdio, (rslv.dns_hdr.code & DNS_OPCODE_STATUS) ? ",ST" : "");
-	ntstdio_printf(&ntstdio, ", rcode: %s.\n",
+		printf((rslv.dns_hdr.code & DNS_QR_RESPONSE) ? "QR," : "");
+		printf((rslv.dns_hdr.code & DNS_AUTHORITATIVE) ? "AA," : "");
+		printf((rslv.dns_hdr.code & DNS_TRUN_CATION) ? "TC," : "");
+		printf((rslv.dns_hdr.code & DNS_RECURSION_DESIRED) ? "RD," : "");
+		printf((rslv.dns_hdr.code & DNS_RECURSION_AVAILABLE) ? "RA," : "");
+		printf(" ");
+	}
+	printf("opcode: ");
+	printf((rslv.dns_hdr.code & DNS_OPCODE_REVERSE) ? "RV" : "FW");
+	printf((rslv.dns_hdr.code & DNS_OPCODE_STATUS) ? ",ST" : "");
+	printf(", rcode: %s.\n",
 		(rslv.dns_hdr.code & DNS_RCODE_MASK) > DNS_RCODE_REFUSED
 		? "6" : rcode_str[rslv.dns_hdr.code & DNS_RCODE_MASK]);
 
 	if ((offset = show_dns_qdsection(msg, length, &rslv)) < 0) {
-		ntstdio_printf(&ntstdio, "msg error: %s.\n", itron_strerror(offset));
+		printf("msg error: %s.\n", itron_strerror(offset));
 	}
 	if ((offset = show_dns_section(msg, length, rslv.dns_hdr.ancount, rslv.an_offset, "answer")) < 0) {
-		ntstdio_printf(&ntstdio, "msg error: %s.\n", itron_strerror(offset));
+		printf("msg error: %s.\n", itron_strerror(offset));
 	}
 	if ((offset = show_dns_section(msg, length, rslv.dns_hdr.nscount, rslv.ns_offset, "authority")) < 0) {
-		ntstdio_printf(&ntstdio, "msg error: %s.\n", itron_strerror(offset));
+		printf("msg error: %s.\n", itron_strerror(offset));
 	}
 	if ((offset = show_dns_section(msg, length, rslv.dns_hdr.arcount, rslv.ar_offset, "additional")) < 0) {
-		ntstdio_printf(&ntstdio, "msg error: %s.\n", itron_strerror(offset));
+		printf("msg error: %s.\n", itron_strerror(offset));
 	}
 
 err_ret:
 	if ((error = rel_mpf(MPF_RSLV_SRBUF, msg)) != E_OK)
-		ntstdio_printf(&ntstdio, "release buffer error: %s.\n", itron_strerror(error));
+		printf("release buffer error: %s.\n", itron_strerror(error));
 	return 0;
 }
Index: asp3_tinet_ecnl_arm/trunk/ntshell/src/ntp_cli.c
===================================================================
--- asp3_tinet_ecnl_arm/trunk/ntshell/src/ntp_cli.c	(revision 369)
+++ asp3_tinet_ecnl_arm/trunk/ntshell/src/ntp_cli.c	(revision 374)
@@ -50,7 +50,5 @@
 #include <t_syslog.h>
 #include "kernel_cfg.h"
-#include "util/ntstdio.h"
-
-extern ntstdio_t ntstdio;
+#include <stdio.h>
 
 #endif	/* of #if defined(TARGET_KERNEL_ASP) */
@@ -279,5 +277,5 @@
 	}
 
-	ntstdio_printf(&ntstdio, "[NTP CLI,%d] recv time: %s .%09u\n",
+	printf("[NTP CLI,%d] recv time: %s .%09u\n",
 		nc->cepid, nc->buf, tp.tv_nsec);
 }
@@ -311,5 +309,5 @@
 		line = lookup_ipaddr(&nc->ipaddr6, NTP_SRV_URL, API_PROTO_IPV4);
 		if (line == NULL || !in6_is_addr_ipv4mapped(&nc->ipaddr6)) {
-			ntstdio_printf(&ntstdio, "[NTP CLI,%d] sleep %d.%03u[s], unknown host.",
+			printf("[NTP CLI,%d] sleep %d.%03u[s], unknown host.",
 				nc->cepid, SLP_ITV / SYSTIM_HZ, SLP_ITV % SYSTIM_HZ);
 			nc->timer = SLP_ITV;
@@ -319,5 +317,5 @@
 #else	/* of #if defined(SUPPORT_INET6) && defined(SUPPORT_INET4) */
 		if ((line = lookup_ipaddr(&nc->snd_rmt.ipaddr, NTP_SRV_URL, DEFAULT_API_PROTO)) == NULL) {
-			ntstdio_printf(&ntstdio, "[NTP CLI,%d] sleep %d.%03u[s], unknown host.",
+			printf("[NTP CLI,%d] sleep %d.%03u[s], unknown host.",
 				nc->cepid, SLP_ITV / SYSTIM_HZ, SLP_ITV % SYSTIM_HZ);
 			nc->timer = SLP_ITV;
@@ -423,5 +421,5 @@
 
 	if ((error = udp_snd_dat(nc->cepid, &nc->snd_rmt, ntp, len, TMO_NBLK)) != E_WBLK) {
-		ntstdio_printf(&ntstdio, "[NTP CLI,%d] udp_snd_dat error: %s",
+		printf("[NTP CLI,%d] udp_snd_dat error: %s",
 			nc->cepid, itron_strerror(error));
 		return error;
@@ -441,5 +439,5 @@
 	ret = get_tim(&time);
 	if (ret != E_OK) {
-		ntstdio_printf(&ntstdio, "[NTP CLI,%d] get_tim error: %s",
+		printf("[NTP CLI,%d] get_tim error: %s",
 			nc->cepid, itron_strerror(ret));
 		tp->tv_sec = 0;
@@ -461,5 +459,5 @@
 	ret = set_tim(time);
 	if (ret != E_OK) {
-		ntstdio_printf(&ntstdio, "[NTP CLI,%d] set_tim error: %s",
+		printf("[NTP CLI,%d] set_tim error: %s",
 			nc->cepid, itron_strerror(ret));
 	}
@@ -479,5 +477,5 @@
 	if (len < 0 && len != E_RLWAI) {
 		/* E_RLWAI 以外で、0 以下の場合は、エラーを意味している。*/
-		ntstdio_printf(&ntstdio, "[NTP CLI,%d] callback error: %s, fncd: %s", nc->cepid,
+		printf("[NTP CLI,%d] callback error: %s, fncd: %s", nc->cepid,
 			itron_strerror(len), in_strtfn(fncd));
 	}
@@ -486,5 +484,5 @@
 			if ((len = udp_rcv_dat(nc->cepid, &nc->rcv_rmt, &nc->ntp_msg, len, TMO_POL)) < 0)
 			{
-				ntstdio_printf(&ntstdio, "[NTP CLI,%d] udp_rcv_dat error: %s", nc->cepid,
+				printf("[NTP CLI,%d] udp_rcv_dat error: %s", nc->cepid,
 					itron_strerror(len));
 			}
@@ -518,5 +516,5 @@
 
 	get_tid(&nc->tskid);
-	ntstdio_printf(&ntstdio, "[NTP CLI:%d,%d] started.", nc->tskid, (ID)exinf);
+	printf("[NTP CLI:%d,%d] started.", nc->tskid, (ID)exinf);
 
 	/* 初期化 */
@@ -525,5 +523,5 @@
 	ret = get_tim(&time);
 	if (ret != E_OK) {
-		ntstdio_printf(&ntstdio, "[NTP CLI,%d] get_tim error: %7lu,%s",
+		printf("[NTP CLI,%d] get_tim error: %7lu,%s",
 			nc->cepid, time / SYSTIM_HZ, itron_strerror(ret));
 		return;
@@ -539,5 +537,5 @@
 		error = tslp_tsk(timer);
 		if ((error != E_OK) && (error != E_TMOUT)) {
-			ntstdio_printf(&ntstdio, "[NTP CLI,%d] tslp_tsk error: %s %d",
+			printf("[NTP CLI,%d] tslp_tsk error: %s %d",
 				nc->cepid, itron_strerror(error), timer);
 			break;
@@ -546,5 +544,5 @@
 		ret = get_tim(&time);
 		if (ret != E_OK) {
-			ntstdio_printf(&ntstdio, "[NTP CLI,%d] get_tim error: %s",
+			printf("[NTP CLI,%d] get_tim error: %s",
 				nc->cepid, itron_strerror(ret));
 			break;
Index: asp3_tinet_ecnl_arm/trunk/ntshell/src/ntshell_main.c
===================================================================
--- asp3_tinet_ecnl_arm/trunk/ntshell/src/ntshell_main.c	(revision 369)
+++ asp3_tinet_ecnl_arm/trunk/ntshell/src/ntshell_main.c	(revision 374)
@@ -59,10 +59,6 @@
 #include "ntshell_main.h"
 #include "socket_stub.h"
-#include "usb_hbth.h"
-
-extern int bt_bnep_mode;
 
 char command[NTOPT_TEXT_MAXLEN];
-ntstdio_t ntstdio;
 
 extern uint8_t mac_addr[6];
@@ -87,33 +83,8 @@
 volatile int ntshell_state;
 jmp_buf process_exit;
-void sys_init(void);
-NTSHELL_SERIAL_READ ntshell_serial_read = 0;
-NTSHELL_SERIAL_WRITE ntshell_serial_write = 0;
-void *ntshell_serial_extobj;
-
-unsigned char ntstdio_xi(struct ntstdio_t *handle)
-{
-	unsigned char buf[1];
-	ntshell_serial_read((char *)buf, 1, ntshell_serial_extobj);
-	return buf[0];
-}
-
-void ntstdio_xo(struct ntstdio_t *handle, unsigned char c)
-{
-	char buf[1];
-	buf[0] = c;
-	ntshell_serial_write(buf, 1, ntshell_serial_extobj);
-}
-
-void ntshell_task_init(NTSHELL_SERIAL_READ func_read,
-	NTSHELL_SERIAL_WRITE func_write, void *extobj)
-{
-	ntshell_serial_read = func_read;
-	ntshell_serial_write = func_write;
-	ntshell_serial_extobj = extobj;
-
-	sys_init();
-
-	ntstdio_init(&ntstdio, NTSTDIO_OPTION_LINE_ECHO | NTSTDIO_OPTION_CANON | NTSTDIO_OPTION_LF_CRLF | NTSTDIO_OPTION_LF_CR, ntstdio_xi, ntstdio_xo);
+
+void ntshell_task_init(ID portid)
+{
+	serial_ctl_por(portid, IOCTL_CRLF | IOCTL_FCSND | IOCTL_FCRCV);
 }
 
@@ -177,8 +148,7 @@
 	const cmd_table_t *p = cmd_table_info.table;
 	for (int i = 0; i < cmd_table_info.count; i++) {
-		ntstdio_puts(&ntstdio, p->cmd);
-		ntstdio_puts(&ntstdio, "\t:");
-		ntstdio_puts(&ntstdio, p->desc);
-		ntstdio_puts(&ntstdio, "\n");
+		fwrite(p->cmd, strlen(p->cmd), 1, stdout);
+		fwrite("\t:", strlen("\t:"), 1, stdout);
+		puts(p->desc);
 		p++;
 	}
@@ -206,4 +176,5 @@
 int execute_command(int wait)
 {
+	T_RTSK rtsk;
 	ER ret;
 
@@ -228,4 +199,8 @@
 	do {
 		tslp_tsk(100000);
+
+		ret = ref_tsk(NTSHELL_TASK, &rtsk);
+		if ((ret != E_OK) || (rtsk.tskstat == TTS_DMT))
+			ntshell_state = 3;
 	} while(ntshell_state == 1);
 
@@ -237,83 +212,4 @@
 	ntlibc_strlcpy(command, text, sizeof(command));
 	return execute_command(1);
-}
-
-int stdio_close(struct _IO_FILE *fp)
-{
-	return -EPERM;
-}
-
-size_t stdio_read(struct _IO_FILE *fp, unsigned char *data, size_t len)
-{
-	return -EPERM;
-}
-
-size_t stdio_write(struct _IO_FILE *fp, const unsigned char *data, size_t len)
-{
-	return -EPERM;
-}
-
-size_t stdin_read(struct _IO_FILE *fp, unsigned char *data, size_t len)
-{
-	int i = 0;
-	while (i < len) {
-		int c = ntstdio_getc(&ntstdio);
-		data[i++] = c;
-		if ((c == EOF) || (c == '\n'))
-			break;
-	}
-	return i;
-}
-
-size_t stdout_write(struct _IO_FILE *fp, const unsigned char *data, size_t len)
-{
-	for (int i = 0; i < len; i++) {
-		ntstdio_putc(&ntstdio, data[i]);
-	}
-	return len;
-}
-
-size_t stderr_write(struct _IO_FILE *fp, const unsigned char *data, size_t len)
-{
-	for (int i = 0; i < len; i++) {
-		ntstdio_putc(&ntstdio, data[i]);
-	}
-	return len;
-}
-
-int sio_close(struct _IO_FILE *fp)
-{
-	return -EPERM;
-}
-
-size_t sio_read(struct _IO_FILE *fp, unsigned char *data, size_t len)
-{
-	return -EPERM;
-}
-
-size_t sio_write(struct _IO_FILE *fp, const unsigned char *data, size_t len)
-{
-	return -EPERM;
-}
-
-off_t sio_seek(struct _IO_FILE *fp, off_t ofs, int org)
-{
-	return -EPERM;
-}
-
-int sio_ioctl(struct _IO_FILE *fp, int request, void *arg)
-{
-	switch (request) {
-	case TIOCGWINSZ:
-		return 0;
-	case TCGETS:
-		return sio_tcgetattr(fp->fd, (struct termios *)arg);
-	case TCSETS + TCSANOW:
-	case TCSETS + TCSADRAIN:
-	case TCSETS + TCSAFLUSH:
-		return sio_tcsetattr(fp->fd, request - TCSETS, (const struct termios *)arg);
-	}
-
-	return -EINVAL;
 }
 
@@ -456,2 +352,18 @@
 }
 
+int shell_kill(int pid, int sig)
+{
+	DebugBreak();
+	return -1;
+}
+
+int shell_gettimeofday(struct timeval *tv, void *tzvp)
+{
+	SYSTIM time;
+	if (!tv) return 0;
+	get_tim(&time);
+	tv->tv_sec = time / 1000000;
+	tv->tv_usec = time - (tv->tv_sec * 1000000);
+	return 0;
+}
+
Index: asp3_tinet_ecnl_arm/trunk/ntshell/src/ntshell_main.cfg
===================================================================
--- asp3_tinet_ecnl_arm/trunk/ntshell/src/ntshell_main.cfg	(revision 369)
+++ asp3_tinet_ecnl_arm/trunk/ntshell/src/ntshell_main.cfg	(revision 374)
@@ -41,6 +41,7 @@
 #include "ntshell_main.h"
 
-CRE_TSK(NTSHELL_TASK, { TA_NULL, 0, ntshell_task, NTSHELL_PRIORITY, NTSHELL_STACK_SIZE, NULL });
+ATT_INI({ TA_NULL, 0, sys_init });
+
+CRE_TSK(NTSHELL_TASK, { TA_FPU, 0, ntshell_task, NTSHELL_PRIORITY, NTSHELL_STACK_SIZE, NULL });
 CRE_FLG(FLG_SELECT_WAIT, { TA_WMUL, 0x00 });
 CRE_SEM(SEM_FILEDESC, { TA_TPRI, 1, 1 });
-CRE_SEM(SEM_MALLOC, { TA_TPRI, 1, 1 });
Index: asp3_tinet_ecnl_arm/trunk/ntshell/src/ntshell_main.h
===================================================================
--- asp3_tinet_ecnl_arm/trunk/ntshell/src/ntshell_main.h	(revision 369)
+++ asp3_tinet_ecnl_arm/trunk/ntshell/src/ntshell_main.h	(revision 374)
@@ -76,7 +76,9 @@
 extern PRI main_task_priority;
 
+/* ntshellの初期化 */
+void sys_init(intptr_t exinf);
+
 /* ntshellタスク初期化 */
-void ntshell_task_init(NTSHELL_SERIAL_READ func_read,
-	NTSHELL_SERIAL_WRITE func_write, void *extobj);
+void ntshell_task_init(ID portid);
 
 /* ntshellタスク */
Index: asp3_tinet_ecnl_arm/trunk/ntshell/src/shellif.h
===================================================================
--- asp3_tinet_ecnl_arm/trunk/ntshell/src/shellif.h	(revision 369)
+++ asp3_tinet_ecnl_arm/trunk/ntshell/src/shellif.h	(revision 374)
@@ -134,5 +134,5 @@
 
 // dirent.h
-typedef struct __dirstream DIR;
+typedef struct __dirstream FATFS_DIR;
 
 int shell_getdents(int, struct dirent *, size_t);
@@ -303,5 +303,4 @@
 #endif
 
-struct tm *gmtime_r(const time_t *t, struct tm *tm);
 void *malloc(size_t size);
 void *calloc(size_t size, size_t count);
Index: asp3_tinet_ecnl_arm/trunk/ntshell/src/socket_stub.c
===================================================================
--- asp3_tinet_ecnl_arm/trunk/ntshell/src/socket_stub.c	(revision 369)
+++ asp3_tinet_ecnl_arm/trunk/ntshell/src/socket_stub.c	(revision 374)
@@ -57,5 +57,8 @@
 #include <netinet/udp_var.h>
 #include <net/net_buf.h>
-//#include <netinet/tcp_var.h>
+#include <netinet/udp.h>
+#include <netinet/udp_var.h>
+#include <netinet/tcp.h>
+#include <netinet/tcp_var.h>
 #include <netapp/resolver.h>
 extern const ID tmax_tcp_cepid;
@@ -64,5 +67,28 @@
 #include "kernel_cfg.h"
 
+#ifdef _DEBUG
+static const char THIS_FILE[] = __FILE__;
+#endif
+
 #define SOCKET_TIMEOUT 2000000
+
+static int tcp_fd_close(struct SHELL_FILE *fp);
+static size_t tcp_fd_read(struct SHELL_FILE *fp, unsigned char *data, size_t len);
+static size_t tcp_fd_write(struct SHELL_FILE *fp, const unsigned char *data, size_t len);
+static off_t tcp_fd_seek(struct SHELL_FILE *fp, off_t ofs, int org);
+static int tcp_fd_ioctl(struct SHELL_FILE *fp, int req, void *arg);
+static bool_t tcp_fd_readable(struct SHELL_FILE *fp);
+static void tcp_fd_delete(struct SHELL_FILE *fp);
+
+static int udp_fd_close(struct SHELL_FILE *fp);
+static size_t udp_fd_read(struct SHELL_FILE *fp, unsigned char *data, size_t len);
+static size_t udp_fd_write(struct SHELL_FILE *fp, const unsigned char *data, size_t len);
+static off_t udp_fd_seek(struct SHELL_FILE *fp, off_t ofs, int org);
+static int udp_fd_ioctl(struct SHELL_FILE *fp, int req, void *arg);
+static bool_t udp_fd_readable(struct SHELL_FILE *fp);
+static void udp_fd_delete(struct SHELL_FILE *fp);
+
+IO_TYPE IO_TYPE_TCP = { tcp_fd_close, tcp_fd_read, tcp_fd_write, tcp_fd_seek, tcp_fd_ioctl, tcp_fd_readable, tcp_fd_delete };
+IO_TYPE IO_TYPE_UDP = { udp_fd_close, udp_fd_read, udp_fd_write, udp_fd_seek, udp_fd_ioctl, udp_fd_readable, udp_fd_delete };
 
 typedef struct id_table_t {
@@ -116,10 +142,5 @@
 }
 
-int delete_tcp_rep(int repid)
-{
-	return delete_tcp_fd(tmax_tcp_cepid + repid);
-}
-
-typedef struct _IO_FILE SOCKET;
+typedef struct SHELL_FILE SOCKET;
 
 int shell_socket(int family, int type, int protocol)
@@ -141,8 +162,18 @@
 	switch (type) {
 	case SOCK_STREAM:
-		fp = new_tcp_fd(0);
+		fp = new_fp(&IO_TYPE_TCP, 0, 0);
+		if (fp == NULL)
+			return -ENOMEM;
+
+		fp->exinf = malloc(sizeof(socket_t));
+		memset(fp->exinf, 0, sizeof(socket_t));
 		break;
 	case SOCK_DGRAM:
-		fp = new_udp_fd(0);
+		fp = new_fp(&IO_TYPE_UDP, 0, 1);
+		if (fp == NULL)
+			return -ENOMEM;
+
+		fp->exinf = malloc(sizeof(socket_t));
+		memset(fp->exinf, 0, sizeof(socket_t));
 		break;
 	default:
@@ -150,12 +181,9 @@
 	}
 
-	if (fp == NULL) {
-		return -ENOMEM;
-	}
-
-	fp->psock->family = family;
-	fp->psock->type = type;
-	fp->psock->protocol = protocol;
-	fp->psock->flags = flags;
+	socket_t *socket = (socket_t *)fp->exinf;
+	socket->family = family;
+	socket->type = type;
+	socket->protocol = protocol;
+	socket->flags = flags;
 
 	return fp->fd;
@@ -167,5 +195,6 @@
 	if (fp == NULL)
 		return -EBADF;
-	if (fp->psock->family != addr->sa_family)
+	socket_t *socket = (socket_t *)fp->exinf;
+	if (socket->family != addr->sa_family)
 		return -EINVAL;
 
@@ -177,6 +206,6 @@
 		}
 		struct sockaddr_in *addr_in = (struct sockaddr_in *)addr;
-		memcpy(&fp->psock->laddr4, addr, len);
-		switch (fp->psock->type) {
+		memcpy(&socket->laddr4, addr, len);
+		switch (socket->type) {
 		case SOCK_STREAM: {
 			ID cepid = new_id(tcp_cepid_table, tcp_cepid_table_count);
@@ -184,10 +213,10 @@
 				return -ENOMEM;
 
-			fp->psock->buf_size = 512 + 512;
-			fp->psock->buf = malloc(fp->psock->buf_size);
+			socket->buf_size = 512 + 512;
+			socket->buf = malloc(socket->buf_size);
 #ifdef _DEBUG
-			memset(fp->psock->buf, 0, fp->psock->buf_size);
+			memset(socket->buf, 0, socket->buf_size);
 #endif
-			T_TCP_CCEP ccep = { 0, fp->psock->buf, 512, &fp->psock->buf[512], 512, (FP)socket_tcp_callback };
+			T_TCP_CCEP ccep = { 0, socket->buf, 512, &socket->buf[512], 512, (FP)socket_tcp_callback };
 			ret = tcp_cre_cep(cepid, &ccep);
 			if (ret != E_OK) {
@@ -196,5 +225,5 @@
 			}
 			fp->handle = cepid;
-			fp->psock->cepid = cepid;
+			socket->cepid = cepid;
 			break;
 		}
@@ -211,5 +240,5 @@
 			}
 			fp->handle = cepid;
-			fp->psock->cepid = cepid;
+			socket->cepid = cepid;
 			break;
 		}
@@ -223,5 +252,5 @@
 			return -EINVAL;
 		}
-		memcpy(&fp->psock->laddr4, addr, len);
+		memcpy(&socket->laddr4, addr, len);
 		break;
 	}
@@ -236,11 +265,12 @@
 	if (fp == NULL)
 		return -EBADF;
-	if (fp->psock->type != SOCK_STREAM)
+	socket_t *socket = (socket_t *)fp->exinf;
+	if (socket->type != SOCK_STREAM)
 		return -EINVAL;
 
-	fp->psock->backlog = backlog;
+	socket->backlog = backlog;
 
 	ER ret;
-	switch (fp->psock->family) {
+	switch (socket->family) {
 	case AF_INET: {
 		ID repid = new_id(tcp_repid_table, tcp_repid_table_count);
@@ -248,5 +278,5 @@
 			return -ENOMEM;
 
-		struct sockaddr_in *laddr = &fp->psock->laddr4;
+		struct sockaddr_in *laddr = &socket->laddr4;
 		T_TCP_CREP crep = { 0, {ntohl(laddr->sin_addr.s_addr), ntohs(laddr->sin_port)} };
 		ret = tcp_cre_rep(repid, &crep);
@@ -255,5 +285,5 @@
 			return -ENOMEM;
 		}
-		fp->psock->repid = repid;
+		socket->repid = repid;
 		break;
 	}
@@ -271,24 +301,25 @@
 	if (fp == NULL)
 		return -EBADF;
-	if (fp->psock->type != SOCK_STREAM)
+	socket_t *socket = (socket_t *)fp->exinf;
+	if (socket->type != SOCK_STREAM)
 		return -EINVAL;
 
 	ER ret;
-	switch (fp->psock->family) {
+	switch (socket->family) {
 	case AF_INET: {
 		if (len < 8) {
 			return -EINVAL;
 		}
-		if (fp->psock->cepid == 0) {
+		if (socket->cepid == 0) {
 			ID cepid = new_id(tcp_cepid_table, tcp_cepid_table_count);
 			if (cepid < 0)
 				return -ENOMEM;
 
-			fp->psock->buf_size = 512 + 512;
-			fp->psock->buf = malloc(fp->psock->buf_size);
+			socket->buf_size = 512 + 512;
+			socket->buf = malloc(socket->buf_size);
 #ifdef _DEBUG
-			memset(fp->psock->buf, 0, fp->psock->buf_size);
+			memset(socket->buf, 0, socket->buf_size);
 #endif
-			T_TCP_CCEP ccep = { 0, fp->psock->buf, 512, &fp->psock->buf[512], 512, (FP)socket_tcp_callback };
+			T_TCP_CCEP ccep = { 0, socket->buf, 512, &socket->buf[512], 512, (FP)socket_tcp_callback };
 			ret = tcp_cre_cep(cepid, &ccep);
 			if (ret != E_OK) {
@@ -297,13 +328,13 @@
 			}
 			fp->handle = cepid;
-			fp->psock->cepid = cepid;
-		}
-		struct sockaddr_in *laddr = &fp->psock->laddr4;
-		struct sockaddr_in *raddr = &fp->psock->raddr4;
+			socket->cepid = cepid;
+		}
+		struct sockaddr_in *laddr = &socket->laddr4;
+		struct sockaddr_in *raddr = &socket->raddr4;
 		memset(raddr, 0, sizeof(*raddr));
 		memcpy(raddr, addr, len);
 		T_IPV4EP lep = { ntohl(laddr->sin_addr.s_addr), ntohs(laddr->sin_port) };
 		T_IPV4EP rep = { ntohl(raddr->sin_addr.s_addr), ntohs(raddr->sin_port) };
-		ret = tcp_con_cep(fp->psock->cepid, &lep, &rep, SOCKET_TIMEOUT);
+		ret = tcp_con_cep(socket->cepid, &lep, &rep, SOCKET_TIMEOUT);
 		if (ret < 0) {
 			return -EHOSTUNREACH;
@@ -324,29 +355,32 @@
 	if (lfp == NULL)
 		return -EBADF;
-	if (lfp->psock->type != SOCK_STREAM)
+	if (((socket_t *)lfp->exinf)->type != SOCK_STREAM)
 		return -EINVAL;
 
-	SOCKET *fp = new_tcp_fd(0);
-	if (fp == NULL) {
+	SOCKET *fp = new_fp(&IO_TYPE_TCP, 0, 0);
+	if (fp == NULL)
 		return -ENOMEM;
-	}
-
-	memcpy(fp->psock, lfp->psock, offsetof(socket_t, buf_size));
+
+	fp->exinf = malloc(sizeof(socket_t));
+	memset(fp->exinf, 0, sizeof(socket_t));
+
+	memcpy(fp->exinf, lfp->exinf, offsetof(socket_t, buf_size));
 
 	ER ret;
-	switch (fp->psock->family) {
+	socket_t *socket = (socket_t *)fp->exinf;
+	switch (socket->family) {
 	case AF_INET: {
 		ID cepid;
-		if (fp->psock->cepid == 0) {
+		if (socket->cepid == 0) {
 			cepid = new_id(tcp_cepid_table, tcp_cepid_table_count);
 			if (cepid < 0)
 				return -ENOMEM;
 
-			fp->psock->buf_size = 512 + 512;
-			fp->psock->buf = malloc(fp->psock->buf_size);
+			socket->buf_size = 512 + 512;
+			socket->buf = malloc(socket->buf_size);
 #ifdef _DEBUG
-			memset(fp->psock->buf, 0, fp->psock->buf_size);
+			memset(socket->buf, 0, socket->buf_size);
 #endif
-			T_TCP_CCEP ccep = { 0, fp->psock->buf, 512, &fp->psock->buf[512], 512, (FP)socket_tcp_callback };
+			T_TCP_CCEP ccep = { 0, socket->buf, 512, &socket->buf[512], 512, (FP)socket_tcp_callback };
 			ret = tcp_cre_cep(cepid, &ccep);
 			if (ret != E_OK) {
@@ -355,20 +389,20 @@
 			}
 			fp->handle = cepid;
-			fp->psock->cepid = cepid;
+			socket->cepid = cepid;
 		}
 		else {
-			cepid = lfp->psock->cepid;
+			cepid = ((socket_t *)lfp->exinf)->cepid;
 			fp->handle = cepid;
-			lfp->handle = tmax_tcp_cepid + lfp->psock->repid;
-			lfp->psock->cepid = 0;
-			lfp->psock->buf_size = 0;
-			lfp->psock->buf = 0;
+			lfp->handle = tmax_tcp_cepid + ((socket_t *)lfp->exinf)->repid;
+			((socket_t *)lfp->exinf)->cepid = 0;
+			((socket_t *)lfp->exinf)->buf_size = 0;
+			((socket_t *)lfp->exinf)->buf = 0;
 		}
 		T_IPV4EP rep = { 0, 0 };
-		ret = tcp_acp_cep(fp->psock->cepid, fp->psock->repid, &rep, TMO_FEVR);
+		ret = tcp_acp_cep(socket->cepid, socket->repid, &rep, TMO_FEVR);
 		if (ret < 0) {
 			return -ENOMEM;
 		}
-		struct sockaddr_in *raddr = &fp->psock->raddr4;
+		struct sockaddr_in *raddr = &socket->raddr4;
 		memset(raddr, 0, sizeof(*raddr));
 		raddr->sin_family = AF_INET;
@@ -387,5 +421,5 @@
 			return -EINVAL;
 		}
-		struct sockaddr_in *raddr = &fp->psock->raddr4;
+		struct sockaddr_in *raddr = &socket->raddr4;
 		if (sz > sizeof(*raddr))
 			sz = sizeof(*raddr);
@@ -405,7 +439,8 @@
 
 	int ret = 0;
-	switch (fp->psock->family) {
+	socket_t *socket = (socket_t *)fp->exinf;
+	switch (socket->family) {
 	case AF_INET: {
-		switch (fp->psock->type) {
+		switch (socket->type) {
 		case SOCK_STREAM: {
 			if ((addr != NULL) || (alen != 0)) {
@@ -414,5 +449,5 @@
 
 			if (flags & MSG_OOB) {
-				ret = tcp_snd_oob(fp->psock->cepid, (void *)buf, len, SOCKET_TIMEOUT);
+				ret = tcp_snd_oob(socket->cepid, (void *)buf, len, SOCKET_TIMEOUT);
 				if (ret < 0) {
 					return -ECOMM;
@@ -421,5 +456,5 @@
 			else {
 				for (;;) {
-					ret = tcp_snd_dat(fp->psock->cepid, (void *)buf, len, SOCKET_TIMEOUT);
+					ret = tcp_snd_dat(socket->cepid, (void *)buf, len, SOCKET_TIMEOUT);
 					if (ret < 0) {
 						if (ret == E_TMOUT)
@@ -440,10 +475,10 @@
 				return -EINVAL;
 			}
-			struct sockaddr_in *raddr = &fp->psock->raddr4;
+			struct sockaddr_in *raddr = &socket->raddr4;
 			memset(raddr, 0, sizeof(*raddr));
 			memcpy(raddr, addr, sz);
 			T_IPV4EP rep = { ntohl(raddr->sin_addr.s_addr), ntohs(raddr->sin_port) };
-			ret = udp_snd_dat(fp->psock->cepid, &rep, (void *)buf, len,
-				(fp->psock->flags & O_NONBLOCK) ? TMO_POL : SOCKET_TIMEOUT);
+			ret = udp_snd_dat(socket->cepid, &rep, (void *)buf, len,
+				(socket->flags & O_NONBLOCK) ? TMO_POL : SOCKET_TIMEOUT);
 			if (ret < 0) {
 				return (ret == E_TMOUT) ? -ETIME : -ECOMM;
@@ -476,10 +511,11 @@
 
 	int ret = 0;
-	switch (fp->psock->family) {
+	socket_t *socket = (socket_t *)fp->exinf;
+	switch (socket->family) {
 	case AF_INET: {
-		switch (fp->psock->type) {
+		switch (socket->type) {
 		case SOCK_STREAM: {
 			if (flags & MSG_OOB) {
-				ret = tcp_rcv_oob(fp->psock->cepid, buf, len);
+				ret = tcp_rcv_oob(socket->cepid, buf, len);
 				if (ret < 0) {
 					syslog(LOG_ERROR, "tcp_rcv_oob => %d", ret);
@@ -489,15 +525,15 @@
 			else {
 				int rsz, tmp;
-				if (fp->psock->input == NULL) {
+				if (socket->input == NULL) {
 					ret = wai_sem(SEM_FILEDESC);
 					if (ret < 0) {
 						syslog(LOG_ERROR, "wai_sem => %d", ret);
 					}
-					fp->psock->len = 0;
+					socket->len = 0;
 					ret = sig_sem(SEM_FILEDESC);
 					if (ret < 0) {
 						syslog(LOG_ERROR, "sig_sem => %d", ret);
 					}
-					ret = tcp_rcv_buf(fp->psock->cepid, &fp->psock->input, TMO_FEVR);
+					ret = tcp_rcv_buf(socket->cepid, &socket->input, TMO_FEVR);
 					if (ret < 0) {
 						syslog(LOG_ERROR, "tcp_rcv_buf => %d", ret);
@@ -507,15 +543,15 @@
 				}
 				else
-					rsz = fp->psock->len;
+					rsz = socket->len;
 				tmp = rsz;
 				if (rsz > len)
 					rsz = len;
 				if (rsz >= 0) {
-					memcpy(buf, fp->psock->input, rsz);
+					memcpy(buf, socket->input, rsz);
 					ret = wai_sem(SEM_FILEDESC);
 					if (ret < 0) {
 						syslog(LOG_ERROR, "wai_sem => %d", ret);
 					}
-					fp->psock->len = tmp - rsz;
+					socket->len = tmp - rsz;
 					ret = sig_sem(SEM_FILEDESC);
 					if (ret < 0) {
@@ -523,9 +559,9 @@
 					}
 					if (tmp - rsz == 0) {
-						fp->psock->input = NULL;
+						socket->input = NULL;
 					}
 					else
-						fp->psock->input = (void *)&((uint8_t *)fp->psock->input)[rsz];
-					ret = tcp_rel_buf(fp->psock->cepid, rsz);
+						socket->input = (void *)&((uint8_t *)socket->input)[rsz];
+					ret = tcp_rel_buf(socket->cepid, rsz);
 					if ((ret != E_OBJ) && (ret < 0)) {
 						syslog(LOG_ERROR, "tcp_rel_buf => %d", ret);
@@ -538,5 +574,5 @@
 		}
 		case SOCK_DGRAM: {
-			struct sockaddr_in *raddr = &fp->psock->raddr4;
+			struct sockaddr_in *raddr = &socket->raddr4;
 			int rsz;
 			ret = wai_sem(SEM_FILEDESC);
@@ -544,5 +580,5 @@
 				syslog(LOG_ERROR, "wai_sem => %d", ret);
 			}
-			T_NET_BUF *input = fp->psock->input;
+			T_NET_BUF *input = socket->input;
 			if (input == NULL) {
 				ret = sig_sem(SEM_FILEDESC);
@@ -552,8 +588,9 @@
 
 				T_IPV4EP rep = { 0, 0 };
-				ret = udp_rcv_dat(fp->psock->cepid, &rep, buf, len,
-					(fp->psock->flags & O_NONBLOCK) ? TMO_POL : SOCKET_TIMEOUT);
+				ret = udp_rcv_dat(socket->cepid, &rep, buf, len,
+					(socket->flags & O_NONBLOCK) ? TMO_POL : SOCKET_TIMEOUT);
 				if (ret < 0) {
-					syslog(LOG_ERROR, "udp_rcv_buf => %d", ret);
+					if ((socket->flags & O_NONBLOCK) == 0)
+						syslog(LOG_ERROR, "udp_rcv_buf => %d", ret);
 					return (ret == E_TMOUT) ? -ETIME : -ECOMM;
 				}
@@ -565,10 +602,10 @@
 					}
 					int sz = *alen;
-					memset(raddr, 0, sizeof(fp->psock->raddr4));
+					memset(raddr, 0, sizeof(socket->raddr4));
 					raddr->sin_family = AF_INET;
 					raddr->sin_port = htons(rep.portno);
 					raddr->sin_addr.s_addr = htonl(rep.ipaddr);
-					if (sz > sizeof(fp->psock->raddr4))
-						sz = sizeof(fp->psock->raddr4);
+					if (sz > sizeof(socket->raddr4))
+						sz = sizeof(socket->raddr4);
 					memcpy(addr, raddr, sz);
 					*alen = sz;
@@ -580,13 +617,13 @@
 			}
 			else {
-				rsz = fp->psock->len;
-				void *pbuf = fp->psock->buf;
-				fp->psock->input = NULL;
-				fp->psock->len = 0;
-				fp->psock->buf = NULL;
+				rsz = socket->len;
+				void *pbuf = socket->buf;
+				socket->input = NULL;
+				socket->len = 0;
+				socket->buf = NULL;
 				if ((addr != NULL) && (alen != NULL)) {
 					int sz = *alen;
-					if (sz > sizeof(fp->psock->raddr4))
-						sz = sizeof(fp->psock->raddr4);
+					if (sz > sizeof(socket->raddr4))
+						sz = sizeof(socket->raddr4);
 					memcpy(addr, raddr, sz);
 					*alen = sz;
@@ -632,9 +669,10 @@
 
 	ER ret;
-	switch (fp->psock->family) {
+	socket_t *socket = (socket_t *)fp->exinf;
+	switch (socket->family) {
 	case AF_INET: {
-		switch (fp->psock->type) {
+		switch (socket->type) {
 		case SOCK_STREAM: {
-			ret = tcp_sht_cep(fp->psock->cepid);
+			ret = tcp_sht_cep(socket->cepid);
 			if (ret < 0) {
 				return -ECOMM;
@@ -661,7 +699,8 @@
 
 	ER ret;
-	switch (fp->psock->family) {
+	socket_t *socket = (socket_t *)fp->exinf;
+	switch (socket->family) {
 	case AF_INET: {
-		switch (fp->psock->type) {
+		switch (socket->type) {
 		case SOCK_STREAM: {
 			switch (level) {
@@ -669,5 +708,5 @@
 				switch (optname) {
 				case SO_REUSEADDR:
-					if (fp->psock->flags & SO_REUSEADDR) {
+					if (socket->flags & SO_REUSEADDR) {
 						*(bool *)optval = true;
 					}
@@ -677,5 +716,5 @@
 					break;
 				case SO_KEEPALIVE:
-					if (fp->psock->flags & SO_KEEPALIVE) {
+					if (socket->flags & SO_KEEPALIVE) {
 						*(bool *)optval = true;
 					}
@@ -692,5 +731,5 @@
 				break;
 			case IPPROTO_TCP:
-				ret = tcp_get_opt(fp->psock->cepid, optname, (void *)optval, *optlen);
+				ret = tcp_get_opt(socket->cepid, optname, (void *)optval, *optlen);
 				if (ret < 0) {
 					return -EINVAL;
@@ -706,5 +745,5 @@
 			switch (level) {
 			case IPPROTO_UDP:
-				ret = udp_get_opt(fp->psock->cepid, optname, (void *)optval, *optlen);
+				ret = udp_get_opt(socket->cepid, optname, (void *)optval, *optlen);
 				if (ret < 0) {
 					return -EINVAL;
@@ -736,7 +775,8 @@
 
 	ER ret;
-	switch (fp->psock->family) {
+	socket_t *socket = (socket_t *)fp->exinf;
+	switch (socket->family) {
 	case AF_INET: {
-		switch (fp->psock->type) {
+		switch (socket->type) {
 		case SOCK_STREAM: {
 			switch (level){
@@ -745,16 +785,16 @@
 				case SO_REUSEADDR:
 					if (*(bool *)optval) {
-						fp->psock->flags |= SO_REUSEADDR;
+						socket->flags |= SO_REUSEADDR;
 					}
 					else {
-						fp->psock->flags &= ~SO_REUSEADDR;
+						socket->flags &= ~SO_REUSEADDR;
 					}
 					break;
 				case SO_KEEPALIVE:
 					if (*(bool *)optval) {
-						fp->psock->flags |= SO_KEEPALIVE;
+						socket->flags |= SO_KEEPALIVE;
 					}
 					else {
-						fp->psock->flags &= ~SO_KEEPALIVE;
+						socket->flags &= ~SO_KEEPALIVE;
 					}
 					break;
@@ -764,5 +804,5 @@
 				break;
 			case IPPROTO_TCP:
-				ret = tcp_set_opt(fp->psock->cepid, optname, (void *)optval, optlen);
+				ret = tcp_set_opt(socket->cepid, optname, (void *)optval, optlen);
 				if (ret < 0) {
 					return -EINVAL;
@@ -777,5 +817,5 @@
 			switch (level){
 			case IPPROTO_UDP:
-				ret = udp_set_opt(fp->psock->cepid, optname, (void *)optval, optlen);
+				ret = udp_set_opt(socket->cepid, optname, (void *)optval, optlen);
 				if (ret < 0) {
 					return -EINVAL;
@@ -809,7 +849,8 @@
 
 	socklen_t size = *len;
-	switch (fp->psock->family) {
+	socket_t *socket = (socket_t *)fp->exinf;
+	switch (socket->family) {
 	case AF_INET: {
-		struct sockaddr_in *raddr = &fp->psock->raddr4;
+		struct sockaddr_in *raddr = &socket->raddr4;
 		*len = sizeof(struct sockaddr_in);
 		if (size > sizeof(struct sockaddr_in))
@@ -837,5 +878,6 @@
 
 	socklen_t size = *len;
-	switch (fp->psock->family) {
+	socket_t *socket = (socket_t *)fp->exinf;
+	switch (socket->family) {
 	case AF_INET: {
 		const T_IN4_ADDR *laddr4 = in4_get_ifaddr(0);
@@ -843,5 +885,5 @@
 		laddr.sin_family = AF_INET;
 		laddr.sin_addr.s_addr = htonl(*laddr4);
-		laddr.sin_port = fp->psock->laddr4.sin_port;
+		laddr.sin_port = socket->laddr4.sin_port;
 		memset(&laddr.sin_zero, 0, sizeof(laddr.sin_zero));
 		*len = sizeof(struct sockaddr_in);
@@ -859,21 +901,20 @@
 }
 
-int tcp_fd_close(struct _IO_FILE *fp)
+int tcp_fd_close(struct SHELL_FILE *fp)
 {
 	ER ret, ret2;
 
-	switch (fp->psock->family) {
+	socket_t *socket = (socket_t *)fp->exinf;
+	switch (socket->family) {
 	case AF_INET: {
-		if (fp->psock->cepid != 0) {
-			ID cepid = fp->psock->cepid;
+		if (socket->cepid != 0) {
+			ID cepid = socket->cepid;
 			ret = tcp_sht_cep(cepid);
 			if (ret < 0) {
 				//return -1;
 			}
-			ret = tcp_cls_cep(cepid, (fp->psock->repid != 0) ? 0 : SOCKET_TIMEOUT);
+			ret = tcp_cls_cep(cepid, (socket->repid != 0) ? 0 : SOCKET_TIMEOUT);
 			ret2 = tcp_del_cep(cepid);
-			free(fp->psock->buf);
-			fp->psock->buf = NULL;
-			delete_tcp_fd(cepid);
+			//delete_fd_by_id(&IO_TYPE_TCP, cepid);
 			delete_id(tcp_cepid_table, tcp_cepid_table_count, cepid);
 			if ((ret < 0) || (ret2 < 0)) {
@@ -881,10 +922,8 @@
 			}
 		}
-		else if (fp->psock->repid != 0) {
-			ID repid = fp->psock->repid;
+		else if (socket->repid != 0) {
+			ID repid = socket->repid;
 			ret = tcp_del_rep(repid);
-			free(fp->psock->buf);
-			fp->psock->buf = NULL;
-			delete_tcp_fd(tmax_tcp_cepid + repid);
+			//delete_fd_by_id(&IO_TYPE_TCP, tmax_tcp_cepid + repid);
 			delete_id(tcp_repid_table, tcp_repid_table_count, repid);
 			if (ret < 0) {
@@ -893,6 +932,4 @@
 		}
 		else {
-			free(fp->psock->buf);
-			fp->psock->buf = NULL;
 			return -EINVAL;
 		}
@@ -907,36 +944,157 @@
 }
 
-size_t tcp_fd_read(struct _IO_FILE *fp, unsigned char *dst, size_t dstsz)
+size_t tcp_fd_read(struct SHELL_FILE *fp, unsigned char *dst, size_t dstsz)
 {
 	return shell_recvfrom(fp->fd, dst, dstsz, 0, NULL, NULL);
 }
 
-size_t tcp_fd_write(struct _IO_FILE *fp, const unsigned char *src, size_t srcsz)
+size_t tcp_fd_write(struct SHELL_FILE *fp, const unsigned char *src, size_t srcsz)
 {
 	return shell_sendto(fp->fd, src, srcsz, 0, NULL, 0);
 }
 
-off_t tcp_fd_seek(struct _IO_FILE *fp, off_t ofs, int org)
+off_t tcp_fd_seek(struct SHELL_FILE *fp, off_t ofs, int org)
 {
 	return -EPERM;
 }
 
-int tcp_fd_ioctl(struct _IO_FILE *fp, int req, void *arg)
+int tcp_fd_ioctl(struct SHELL_FILE *fp, int req, void *arg)
 {
 	return -EINVAL;
 }
 
-int udp_fd_close(struct _IO_FILE *fp)
+bool_t tcp_fd_readable(struct SHELL_FILE *fp)
+{
+	ER ret;
+
+	socket_t *socket = (socket_t *)fp->exinf;
+	if (socket->cepid != 0) {
+		if (socket->len == 0) {
+			ret = tcp_rcv_buf(socket->cepid, &socket->input, TMO_NBLK);
+			if ((ret != E_WBLK) && (ret != E_OBJ) && (ret < 0)) {
+				syslog(LOG_ERROR, "tcp_rcv_buf => %d", ret);
+				//return ret;
+			}
+			if (ret > 0) {
+				ret = wai_sem(SEM_FILEDESC);
+				if (ret < 0) {
+					syslog(LOG_ERROR, "wai_sem => %d", ret);
+				}
+				socket->len += ret;
+				ret = sig_sem(SEM_FILEDESC);
+				if (ret < 0) {
+					syslog(LOG_ERROR, "sig_sem => %d", ret);
+				}
+			}
+		}
+		else ret = 1;
+		if (ret > 0) {
+			return true;
+		}
+	}
+
+	return false;
+}
+
+void tcp_fd_delete(struct SHELL_FILE *fp)
+{
+	socket_t *socket = (socket_t *)fp->exinf;
+	free(socket->buf);
+	socket->buf = NULL;
+	free(fp->exinf);
+	fp->exinf = NULL;
+}
+
+ER socket_tcp_callback(ID cepid, FN fncd, void *p_parblk)
+{
+	struct SHELL_FILE *fp = id_to_fd(&IO_TYPE_TCP, cepid);
+	FLGPTN flgptn = 0;
+	ER ret;
+	int len;
+
+	if (fp == NULL)
+		return E_PAR;
+
+	int fd = fp->fd;
+	FD_SET(fd, (fd_set *)&flgptn);
+
+	switch (fncd) {
+	case TFN_TCP_RCV_BUF:
+		len = *(int *)p_parblk;
+		if ((len <= 0) || (fp->exinf == NULL))
+			return E_OK;
+
+		ret = wai_sem(SEM_FILEDESC);
+		if (ret < 0) {
+			syslog(LOG_ERROR, "wai_sem => %d", ret);
+		}
+		socket_t *socket = (socket_t *)fp->exinf;
+		socket->len += len;
+		ret = sig_sem(SEM_FILEDESC);
+		if (ret < 0) {
+			syslog(LOG_ERROR, "sig_sem => %d", ret);
+		}
+
+		if (fp->readevt_w == fp->readevt_r) fp->readevt_w++;
+
+		set_flg(FLG_SELECT_WAIT, flgptn);
+		return E_OK;
+
+	case TFN_TCP_RCV_DAT:
+		len = *(int *)p_parblk;
+		if ((len <= 0) || (fp->exinf == NULL))
+			return E_OK;
+
+		ret = wai_sem(SEM_FILEDESC);
+		if (ret < 0) {
+			syslog(LOG_ERROR, "wai_sem => %d", ret);
+		}
+		socket->len += len;
+		ret = sig_sem(SEM_FILEDESC);
+		if (ret < 0) {
+			syslog(LOG_ERROR, "sig_sem => %d", ret);
+		}
+
+		if (fp->readevt_w == fp->readevt_r) fp->readevt_w++;
+
+		set_flg(FLG_SELECT_WAIT, flgptn);
+		return E_OK;
+
+	case TFN_TCP_SND_DAT:
+		if (fp->writeevt_w == fp->writeevt_r) fp->writeevt_w++;
+
+		set_flg(FLG_SELECT_WAIT, flgptn);
+		return E_OK;
+
+	case TFN_TCP_CAN_CEP:
+		if (fp->errorevt_w == fp->errorevt_r) fp->errorevt_w++;
+
+		set_flg(FLG_SELECT_WAIT, flgptn);
+		return E_OK;
+
+	case TFN_TCP_DEL_REP:
+		delete_fd_by_id(&IO_TYPE_TCP, tmax_tcp_cepid + cepid);
+		return E_OK;
+
+	case TFN_TCP_DEL_CEP:
+		delete_fd_by_id(&IO_TYPE_TCP, cepid);
+		return E_OK;
+
+	default:
+		return E_OK;
+	}
+}
+
+int udp_fd_close(struct SHELL_FILE *fp)
 {
 	ER ret;
 	ID cepid;
 
-	switch (fp->psock->family) {
+	socket_t *socket = (socket_t *)fp->exinf;
+	switch (socket->family) {
 	case AF_INET: {
-		cepid = fp->psock->cepid;
+		cepid = socket->cepid;
 		ret = udp_del_cep(cepid);
-		//free(fp->psock->buf);
-		//fp->psock->buf = NULL;
-		delete_udp_fd(cepid);
+		//delete_fd_by_id(&IO_TYPE_UDP, cepid);
 		delete_id(udp_cepid_table, udp_cepid_table_count, cepid);
 		if (ret < 0) {
@@ -953,22 +1111,126 @@
 }
 
-size_t udp_fd_read(struct _IO_FILE *fp, unsigned char *dst, size_t dstsz)
+size_t udp_fd_read(struct SHELL_FILE *fp, unsigned char *dst, size_t dstsz)
 {
 	return shell_recvfrom(fp->fd, dst, dstsz, 0, NULL, NULL);
 }
 
-size_t udp_fd_write(struct _IO_FILE *fp, const unsigned char *src, size_t srcsz)
+size_t udp_fd_write(struct SHELL_FILE *fp, const unsigned char *src, size_t srcsz)
 {
 	return shell_sendto(fp->fd, src, srcsz, 0, NULL, 0);
 }
 
-off_t udp_fd_seek(struct _IO_FILE *fp, off_t ofs, int org)
+off_t udp_fd_seek(struct SHELL_FILE *fp, off_t ofs, int org)
 {
 	return -EPERM;
 }
 
-int udp_fd_ioctl(struct _IO_FILE *fp, int req, void *arg)
+int udp_fd_ioctl(struct SHELL_FILE *fp, int req, void *arg)
 {
 	return -EINVAL;
+}
+
+bool_t udp_fd_readable(struct SHELL_FILE *fp)
+{
+	socket_t *socket = (socket_t *)fp->exinf;
+	if (socket->cepid != 0) {
+		if (socket->input != NULL) {
+			return true;
+		}
+	}
+
+	return false;
+}
+
+void udp_fd_delete(struct SHELL_FILE *fp)
+{
+	//socket_t *socket = (socket_t *)fp->exinf;
+	//free(socket->buf);
+	//socket->buf = NULL;
+	free(fp->exinf);
+	fp->exinf = NULL;
+}
+
+ER socket_udp_callback(ID cepid, FN fncd, void *p_parblk)
+{
+	struct SHELL_FILE *fp = id_to_fd(&IO_TYPE_UDP, cepid);
+	FLGPTN flgptn = 0;
+	int len;
+
+	if (fp == NULL)
+		return E_PAR;
+
+	int fd = fp->fd;
+	FD_SET(fd, (fd_set *)&flgptn);
+
+	switch (fncd) {
+	case TEV_UDP_RCV_DAT:
+	{
+		T_UDP_RCV_DAT_PARA *udppara = (T_UDP_RCV_DAT_PARA *)p_parblk;
+		len = udppara->len;
+		if ((len <= 0) || (fp->exinf == NULL))
+			return E_OK;
+
+		ER ret = wai_sem(SEM_FILEDESC);
+		if (ret < 0) {
+			syslog(LOG_ERROR, "wai_sem => %d", ret);
+		}
+		socket_t *socket = (socket_t *)fp->exinf;
+		socket->len = len;
+		if (socket->input != NULL) {
+			ret = rel_net_buf(socket->input);
+			if (ret < 0) {
+				syslog(LOG_ERROR, "rel_net_buf => %d", ret);
+			}
+		}
+		socket->input = udppara->input;
+		socket->buf = GET_UDP_SDU(udppara->input, udppara->off);
+		memset(&socket->raddr4, 0, sizeof(socket->raddr4));
+		socket->raddr4.sin_family = AF_INET;
+		socket->raddr4.sin_port = htons(udppara->rep4.portno);
+		socket->raddr4.sin_addr.s_addr = htonl(udppara->rep4.ipaddr);
+		udppara->input->flags |= NB_FLG_NOREL_IFOUT;
+		ret = sig_sem(SEM_FILEDESC);
+		if (ret < 0) {
+			syslog(LOG_ERROR, "sig_sem => %d", ret);
+		}
+
+		if (fp->readevt_w == fp->readevt_r) fp->readevt_w++;
+
+		set_flg(FLG_SELECT_WAIT, flgptn);
+		return E_OK;
+	}
+	case TFN_UDP_CRE_CEP:
+		return E_OK;
+
+	case TFN_UDP_RCV_DAT:
+		len = *(int *)p_parblk;
+		if ((len <= 0) || (fp->exinf == NULL))
+			return E_OK;
+
+		if (fp->readevt_w == fp->readevt_r) fp->readevt_w++;
+
+		set_flg(FLG_SELECT_WAIT, flgptn);
+		return E_OK;
+
+	case TFN_UDP_SND_DAT:
+		if (fp->writeevt_w == fp->writeevt_r) fp->writeevt_w++;
+
+		set_flg(FLG_SELECT_WAIT, flgptn);
+		return E_OK;
+
+	case TFN_UDP_CAN_CEP:
+		if (fp->errorevt_w == fp->errorevt_r) fp->errorevt_w++;
+
+		set_flg(FLG_SELECT_WAIT, flgptn);
+		return E_OK;
+
+	case TFN_UDP_DEL_CEP:
+		delete_fd_by_id(&IO_TYPE_UDP, cepid);
+		return E_OK;
+
+	default:
+		return E_OK;
+	}
 }
 
Index: asp3_tinet_ecnl_arm/trunk/ntshell/src/socket_stub.h
===================================================================
--- asp3_tinet_ecnl_arm/trunk/ntshell/src/socket_stub.h	(revision 369)
+++ asp3_tinet_ecnl_arm/trunk/ntshell/src/socket_stub.h	(revision 374)
@@ -103,18 +103,15 @@
 } socket_t;
 
-struct _IO_DIR {
-	DIR dir;
+struct SHELL_DIR {
+	FATFS_DIR dir;
 	struct dirent dirent;
 };
 
-struct _IO_FILE {
+typedef const struct io_type_s IO_TYPE;
+
+struct SHELL_FILE {
 	int fd;
-	int type;
+	IO_TYPE *type;
 	int handle;
-	int (*close)(struct _IO_FILE *);
-	size_t (*read)(struct _IO_FILE *, unsigned char *, size_t);
-	size_t (*write)(struct _IO_FILE *, const unsigned char *, size_t);
-	off_t (*seek)(struct _IO_FILE *, off_t, int);
-	int (*ioctl)(struct _IO_FILE *, int, void *);
 	int readevt_r;
 	int readevt_w;
@@ -124,9 +121,15 @@
 	int errorevt_r;
 	int errorevt_w;
-	union {
-		FIL *pfile;
-		struct _IO_DIR *pdir;
-		socket_t *psock;
-	};
+	void *exinf;
+};
+
+struct io_type_s {
+	int (*close)(struct SHELL_FILE *);
+	size_t (*read)(struct SHELL_FILE *, unsigned char *, size_t);
+	size_t (*write)(struct SHELL_FILE *, const unsigned char *, size_t);
+	off_t (*seek)(struct SHELL_FILE *, off_t, int);
+	int (*ioctl)(struct SHELL_FILE *, int, void *);
+	bool_t (*readable)(struct SHELL_FILE *);
+	void (*delete)(struct SHELL_FILE *);
 };
 
@@ -141,65 +144,10 @@
 #endif
 
-extern int stdio_close(struct _IO_FILE *fp);
-extern size_t stdio_read(struct _IO_FILE *fp, unsigned char *data, size_t len);
-extern size_t stdio_write(struct _IO_FILE *fp, const unsigned char *data, size_t len);
-extern size_t stdin_read(struct _IO_FILE *fp, unsigned char *data, size_t len);
-extern size_t stdout_write(struct _IO_FILE *fp, const unsigned char *data, size_t len);
-extern size_t stderr_write(struct _IO_FILE *fp, const unsigned char *data, size_t len);
+struct SHELL_FILE *new_fp(IO_TYPE *type, int id, int writable);
+int delete_fd_by_id(IO_TYPE *type, int id);
+struct SHELL_FILE *fd_to_fp(int fd);
+struct SHELL_FILE *id_to_fd(IO_TYPE *type, int id);
 
-extern int sio_close(struct _IO_FILE *fp);
-extern size_t sio_read(struct _IO_FILE *fp, unsigned char *data, size_t len);
-extern size_t sio_write(struct _IO_FILE *fp, const unsigned char *data, size_t len);
-extern off_t sio_seek(struct _IO_FILE *fp, off_t ofs, int org);
-extern int sio_ioctl(struct _IO_FILE *fp, int req, void *arg);
-
-extern int file_close(struct _IO_FILE *fp);
-extern size_t file_read(struct _IO_FILE *fp, unsigned char *data, size_t len);
-extern size_t file_write(struct _IO_FILE *fp, const unsigned char *data, size_t len);
-extern off_t file_seek(struct _IO_FILE *fp, off_t ofs, int org);
-extern int file_ioctl(struct _IO_FILE *fp, int req, void *arg);
-
-extern int dir_close(struct _IO_FILE *fp);
-extern size_t dir_read(struct _IO_FILE *fp, unsigned char *data, size_t len);
-extern size_t dir_write(struct _IO_FILE *fp, const unsigned char *data, size_t len);
-extern off_t dir_seek(struct _IO_FILE *fp, off_t ofs, int org);
-extern int dir_ioctl(struct _IO_FILE *fp, int req, void *arg);
-
-extern int tcp_fd_close(struct _IO_FILE *fp);
-extern size_t tcp_fd_read(struct _IO_FILE *fp, unsigned char *data, size_t len);
-extern size_t tcp_fd_write(struct _IO_FILE *fp, const unsigned char *data, size_t len);
-extern off_t tcp_fd_seek(struct _IO_FILE *fp, off_t ofs, int org);
-extern int tcp_fd_ioctl(struct _IO_FILE *fp, int req, void *arg);
-
-extern int udp_fd_close(struct _IO_FILE *fp);
-extern size_t udp_fd_read(struct _IO_FILE *fp, unsigned char *data, size_t len);
-extern size_t udp_fd_write(struct _IO_FILE *fp, const unsigned char *data, size_t len);
-extern off_t udp_fd_seek(struct _IO_FILE *fp, off_t ofs, int org);
-extern int udp_fd_ioctl(struct _IO_FILE *fp, int req, void *arg);
-
-struct _IO_FILE *fd_to_fp(int fd);
-
-struct _IO_FILE *new_sio_fd(int sioid);
-int delete_sio_fd(int sioid);
-struct _IO_FILE *sioid_to_fd(int sioid);
-
-struct _IO_FILE *new_file_fd(int fileid);
-int delete_file_fd(int fileid);
-struct _IO_FILE *fileid_to_fd(int fileid);
-
-struct _IO_FILE *new_dir_fd(int dirid);
-int delete_dir_fd(int dirid);
-struct _IO_FILE *dirid_to_fd(int dirid);
-
-struct _IO_FILE *new_tcp_fd(int tcpid);
-int delete_tcp_fd(int tcpid);
-struct _IO_FILE *tcpid_to_fd(int tcpid);
-
-struct _IO_FILE *new_udp_fd(int udpid);
-int delete_udp_fd(int udpid);
-struct _IO_FILE *udpid_to_fd(int udpid);
-
-int delete_fp(struct _IO_FILE *fp);
-int delete_tcp_rep(int repid);
+int delete_fp(struct SHELL_FILE *fp);
 void clean_fd();
 
Index: asp3_tinet_ecnl_arm/trunk/ntshell/src/syscall.c
===================================================================
--- asp3_tinet_ecnl_arm/trunk/ntshell/src/syscall.c	(revision 369)
+++ asp3_tinet_ecnl_arm/trunk/ntshell/src/syscall.c	(revision 374)
@@ -48,9 +48,9 @@
 
 	/* ==== Cleaning and invalidation of the L1 data cache ==== */
-	__v7_all_cache(2);
+	L1C_CleanInvalidateDCacheAll();
 	__DSB();
 
 	/* ==== Cleaning and invalidation of the L2 cache ==== */
-	if (PL310->AUX_CNT & (1 << 16)) {
+	if (L2C_310->AUX_CNT & (1 << 16)) {
 		assoc = 16;
 	}
@@ -58,13 +58,13 @@
 		assoc = 8;
 	}
-	PL310->INV_WAY = (1 << assoc) - 1;
-	while (PL310->INV_WAY & ((1 << assoc) - 1)); // poll invalidate
-	PL310->CACHE_SYNC = 0x0;
+	L2C_310->INV_WAY = (1 << assoc) - 1;
+	while (L2C_310->INV_WAY & ((1 << assoc) - 1)); // poll invalidate
+	L2C_310->CACHE_SYNC = 0x0;
 
 	/* ==== Invalidate all TLB entries ==== */
-	__ca9u_inv_tlb_all();
+	MMU_InvalidateTLB();
 
 	/* ==== Invalidate the L1 instruction cache ==== */
-	__v7_inv_icache_all();
+	L1C_InvalidateICacheAll();
 	__DSB();
 	__ISB();
@@ -184,5 +184,6 @@
 }
 
-long SYS_fdatasync() {
+long SYS_fdatasync(long a) {
+	//int fdatasync(int fd)
 	return no_implement("fdatasync\n");
 }
@@ -200,10 +201,11 @@
 }
 
-long SYS_futex() {
-	int futex(int *uaddr, int op, int val, const struct timespec *timeout, int *uaddr2, int val3);
+long SYS_futex(long a, long b, long c, long d, long e, long f) {
+	//int futex(int *uaddr, int op, int val, const struct timespec *timeout, int *uaddr2, int val3);
 	return no_implement("futex\n");
 }
 
-long SYS_futimesat() {
+long SYS_futimesat(long a, long b, long c) {
+	//int futimesat(int dirfd, const char *pathname, const struct timeval times[2])
 	return no_implement("futimesat\n");
 }
@@ -281,5 +283,6 @@
 }
 
-long SYS_munmap() {
+long SYS_munmap(long a, long b) {
+	//int munmap(void *start, size_t len)
 	return no_implement("munmap\n");
 }
@@ -293,9 +296,13 @@
 }
 
-long SYS_pread64() {
+long SYS_pread64(long a, long b, long c, long d) {
+	//#define pread64 pread
+	//ssize_t pread(int fd, void *buf, size_t size, off_t ofs)
 	return no_implement("pread64\n");
 }
 
-long SYS_pwrite64() {
+long SYS_pwrite64(long a, long b, long c, long d) {
+	//#define pwrite64 pwrite
+	//ssize_t pwrite(int fd, const void *buf, size_t size, off_t ofs)
 	return no_implement("pwrite64\n");
 }
@@ -337,5 +344,6 @@
 }
 
-long SYS_rt_sigqueueinfo() {
+long SYS_rt_sigqueueinfo(long a, long b, long c) {
+	//int rt_sigqueueinfo(pid_t tgid, int sig, siginfo_t *uinfo)
 	return no_implement("rt_sigqueueinfo\n");
 }
@@ -361,9 +369,11 @@
 }
 
-long SYS_sched_setscheduler() {
+long SYS_sched_setscheduler(long a, long b, long c) {
+	//int sched_setscheduler(pid_t pid, int sched, const struct sched_param *param)
 	return no_implement("sched_setscheduler\n");
 }
 
-long SYS_set_robust_list() {
+long SYS_set_robust_list(long a, long b) {
+	//long set_robust_list(struct robust_list_head *head, size_t len)
 	return no_implement("set_robust_list\n");
 }
@@ -401,9 +411,11 @@
 }
 
-long SYS_utimensat() {
+long SYS_utimensat(long a, long b, long c, long d) {
+	//int utimensat(int fd, const char *path, const struct timespec times[2], int flags)
 	return no_implement("utimensat\n");
 }
 
-long SYS_utimes() {
+long SYS_utimes(long a, long b) {
+	//int utimes(const char *path, const struct timeval times[2])
 	return no_implement("utimes\n");
 }
@@ -417,57 +429,134 @@
 }
 
-long SYS_dup()
-{
+long SYS_dup(long a) {
+	//int dup(int fd)
 	return no_implement("dup\n");
 }
 
-long SYS_dup2()
-{
+long SYS_dup2(long a, long b) {
+	//int dup2(int old, int new)
 	return no_implement("dup2\n");
 }
 
-long SYS_pipe()
-{
+long SYS_pipe(long a) {
+	//int pipe(int fd[2])
 	return no_implement("pipe\n");
 }
 
-long SYS_readlink()
-{
+long SYS_readlink(long a, long b, long c) {
+	//ssize_t readlink(const char *restrict path, char *restrict buf, size_t bufsize)
 	return no_implement("readlink\n");
 }
 
-long SYS_symlink()
-{
+long SYS_symlink(long a, long b) {
+	//int symlink(const char *existing, const char *new)
 	return no_implement("symlink\n");
 }
 
-long SYS_umask()
-{
+long SYS_umask(long a) {
+	//mode_t umask(mode_t mode)
 	return no_implement("umask\n");
 }
 
-long SYS_execve()
-{
+long SYS_execve(long a, long b, long c) {
+	//int execve(const char *path, char *const argv[], char *const envp[])
 	return no_implement("execve\n");
 }
 
-long SYS_fork()
-{
+long SYS_fork() {
+	//pid_t fork(void)
 	return no_implement("fork\n");
 }
 
-long SYS_wait4()
-{
+long SYS_wait4(long a, long b, long c, long d) {
+	//pid_t wait4(pid_t pid, int *status, int options, struct rusage *usage)
 	return no_implement("wait4\n");
 }
 
-long SYS_socketpair()
-{
+long SYS_socketpair(long a, long b, long c, long d) {
+	//int socketpair(int domain, int type, int protocol, int fd[2])
 	return no_implement("socketpair\n");
 }
 
-long SYS_flock()
-{
+long SYS_flock(long a, long b) {
+	//int flock(int fd, int op)
 	return no_implement("flock\n");
+}
+
+long SYS_fchdir()
+{
+	return no_implement("fchdir\n");
+}
+
+long SYS_getegid32()
+{
+	return no_implement("getegid32\n");
+}
+
+long SYS_geteuid32()
+{
+	return no_implement("geteuid32\n");
+}
+
+long SYS_getgid32()
+{
+	return no_implement("getgid32\n");
+}
+
+long SYS_pipe2()
+{
+	return no_implement("pipe2\n");
+}
+
+long SYS_setgid32()
+{
+	return no_implement("setgid32\n");
+}
+
+long SYS_setpgid()
+{
+	return no_implement("setpgid\n");
+}
+
+long SYS_setsid()
+{
+	return no_implement("setsid\n");
+}
+
+long SYS_setuid32()
+{
+	return no_implement("setuid32\n");
+}
+
+long SYS_tgkill()
+{
+	return no_implement("tgkill\n");
+}
+
+long SYS_nanosleep(long a, long b) {
+	//int nanosleep(const struct timespec *req, struct timespec *rem)
+	return no_implement("nanosleep\n");
+}
+
+long SYS_prlimit64(long a, long b, long c, long d) {
+	//#define prlimit64 prlimit
+	//int prlimit(pid_t pid, int resource, const struct rlimit *new_limit, struct rlimit *old_limit)
+	return no_implement("prlimit64\n");
+}
+
+long SYS_sched_getaffinity(long a, long b, long c) {
+	//int sched_getaffinity(pid_t tid, size_t size, cpu_set_t *set)
+	return no_implement("sched_getaffinity\n");
+}
+
+long SYS_sysinfo(long a) {
+	//int sysinfo(struct sysinfo *info)
+	return no_implement("sysinfo\n");
+}
+
+long SYS_ugetrlimit(long a, long b) {
+	//#define SYS_getrlimit SYS_ugetrlimit
+	//int getrlimit(int resource, struct rlimit *rlim)
+	return no_implement("ugetrlimit\n");
 }
 
Index: asp3_tinet_ecnl_arm/trunk/ntshell/tlsf/tlsf.c
===================================================================
--- asp3_tinet_ecnl_arm/trunk/ntshell/tlsf/tlsf.c	(revision 369)
+++ asp3_tinet_ecnl_arm/trunk/ntshell/tlsf/tlsf.c	(revision 374)
@@ -5,5 +5,5 @@
 #include <stdlib.h>
 #include <string.h>
-#include "util/ntstdio.h"
+#include <stdio.h>
 
 #include "tlsf.h"
@@ -16,6 +16,4 @@
 #define tlsf_decl static
 #endif
-
-extern ntstdio_t ntstdio;
 
 /*
@@ -889,5 +887,5 @@
 {
 	(void)user;
-	ntstdio_printf(&ntstdio, "\t%p %s size: %x (%p)\n", ptr, used ? "used" : "free", (unsigned int)size, block_from_ptr(ptr));
+	printf("\t%p %s size: %x (%p)\n", ptr, used ? "used" : "free", (unsigned int)size, block_from_ptr(ptr));
 }
 
@@ -978,5 +976,5 @@
 	if (((ptrdiff_t)mem % ALIGN_SIZE) != 0)
 	{
-		ntstdio_printf(&ntstdio, "tlsf_add_pool: Memory must be aligned by %u bytes.\n",
+		printf("tlsf_add_pool: Memory must be aligned by %u bytes.\n",
 			(unsigned int)ALIGN_SIZE);
 		return 0;
@@ -986,9 +984,9 @@
 	{
 #if defined (TLSF_64BIT)
-		ntstdio_printf(&ntstdio, "tlsf_add_pool: Memory size must be between 0x%x and 0x%x00 bytes.\n", 
+		printf("tlsf_add_pool: Memory size must be between 0x%x and 0x%x00 bytes.\n", 
 			(unsigned int)(pool_overhead + block_size_min),
 			(unsigned int)((pool_overhead + block_size_max) / 256));
 #else
-		ntstdio_printf(&ntstdio, "tlsf_add_pool: Memory size must be between %u and %u bytes.\n", 
+		printf("tlsf_add_pool: Memory size must be between %u and %u bytes.\n", 
 			(unsigned int)(pool_overhead + block_size_min),
 			(unsigned int)(pool_overhead + block_size_max));
@@ -1058,5 +1056,5 @@
 	if (rv)
 	{
-		ntstdio_printf(&ntstdio, "test_ffs_fls: %x ffs/fls tests failed.\n", rv);
+		printf("test_ffs_fls: %x ffs/fls tests failed.\n", rv);
 	}
 	return rv;
@@ -1075,5 +1073,5 @@
 	if (((tlsfptr_t)mem % ALIGN_SIZE) != 0)
 	{
-		ntstdio_printf(&ntstdio, "tlsf_create: Memory must be aligned to %u bytes.\n",
+		printf("tlsf_create: Memory must be aligned to %u bytes.\n",
 			(unsigned int)ALIGN_SIZE);
 		return 0;
