Index: asp3_tinet_ecnl_arm/trunk/ntshell/src/io_stub.c
===================================================================
--- asp3_tinet_ecnl_arm/trunk/ntshell/src/io_stub.c	(revision 374)
+++ asp3_tinet_ecnl_arm/trunk/ntshell/src/io_stub.c	(revision 387)
@@ -45,5 +45,5 @@
 #include "syssvc/serial.h"
 #include "syssvc/syslog.h"
-#include "socket_stub.h"
+#include "fdtable.h"
 #include "util/ntstdio.h"
 #include "usrcmd.h"
@@ -51,4 +51,9 @@
 #include "kernel_cfg.h"
 #include "target_syssvc.h"
+
+struct SHELL_DIR {
+	FATFS_DIR dir;
+	struct dirent dirent;
+};
 
 int fresult2errno(FRESULT res)
@@ -85,4 +90,5 @@
 static int file_ioctl(struct SHELL_FILE *fp, int req, void *arg);
 static bool_t file_readable(struct SHELL_FILE *fp);
+static bool_t file_writable(struct SHELL_FILE *fp);
 static void file_delete(struct SHELL_FILE *fp);
 
@@ -93,8 +99,9 @@
 static int dir_ioctl(struct SHELL_FILE *fp, int req, void *arg);
 static bool_t dir_readable(struct SHELL_FILE *fp);
+static bool_t dir_writable(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 };
+IO_TYPE IO_TYPE_FILE = { file_close, file_read, file_write, file_seek, file_ioctl, file_readable, file_writable, file_delete };
+IO_TYPE IO_TYPE_DIR = { dir_close, dir_read, dir_write, dir_seek, dir_ioctl, dir_readable, dir_writable, dir_delete };
 
 int shell_open(const char *path, int flags, void *arg)
@@ -114,4 +121,5 @@
 		FRESULT res;
 		if ((res = f_opendir(dir, path)) != FR_OK) {
+			delete_fp(fp);
 			return fresult2errno(res);
 		}
@@ -165,4 +173,5 @@
 	}
 
+	delete_fp(fp);
 	return fresult2errno(res);
 }
@@ -239,4 +248,9 @@
 }
 
+bool_t file_writable(struct SHELL_FILE *fp)
+{
+	return fp->writable && (fp->writeevt_w == fp->writeevt_r);
+}
+
 void file_delete(struct SHELL_FILE *fp)
 {
@@ -356,84 +370,4 @@
 {
 	return shell_ioctl(fd, cmd, arg);
-}
-
-extern IO_TYPE IO_TYPE_SIO;
-
-int sio_tcgetattr(int fd, 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;
-
-	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 {
-			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;
 }
 
@@ -688,4 +622,9 @@
 }
 
+bool_t dir_writable(struct SHELL_FILE *fp)
+{
+	return false;
+}
+
 void dir_delete(struct SHELL_FILE *fp)
 {
@@ -710,40 +649,2 @@
 	return 0;
 }
-
-#ifndef _MSC_VER
-extern uint32_t __HeapBase;
-extern uint32_t __HeapLimit;
-#else
-uint8_t __HeapBase[14 * 4096];
-#define __HeapLimit __HeapBase[sizeof(__HeapBase)]
-#endif
-
-void *shell_brk(void *addr)
-{
-	if (addr == 0) {
-		return (void *)(&__HeapBase);
-	}
-	if ((addr >= (void *)&__HeapBase) && (addr < (void *)&__HeapLimit)) {
-		return addr;
-	}
-	return (void *)-1;
-}
-
-void *shell_mmap2(void *start, size_t length, int prot, int flags, int fd, off_t pgoffset)
-{
-	if (fd != -1)
-		return (void *)-EINVAL;
-
-	if ((length >= 0) && (length <= sizeof(&__HeapBase))) {
-		return &__HeapBase;
-	}
-	return (void *)-1;
-}
-
-int shell_mprotect(void *addr, size_t len, int prot)
-{
-	//if ((addr >= (void *)&__HeapBase) && (addr + len < (void *)&__HeapLimit)) {
-	return 0;
-//}
-//return -1;
-}
