Changeset 387 for asp3_tinet_ecnl_arm/trunk/ntshell/src/io_stub.c
- Timestamp:
- May 22, 2019, 4:09:18 PM (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
asp3_tinet_ecnl_arm/trunk/ntshell/src/io_stub.c
r374 r387 45 45 #include "syssvc/serial.h" 46 46 #include "syssvc/syslog.h" 47 #include " socket_stub.h"47 #include "fdtable.h" 48 48 #include "util/ntstdio.h" 49 49 #include "usrcmd.h" … … 51 51 #include "kernel_cfg.h" 52 52 #include "target_syssvc.h" 53 54 struct SHELL_DIR { 55 FATFS_DIR dir; 56 struct dirent dirent; 57 }; 53 58 54 59 int fresult2errno(FRESULT res) … … 85 90 static int file_ioctl(struct SHELL_FILE *fp, int req, void *arg); 86 91 static bool_t file_readable(struct SHELL_FILE *fp); 92 static bool_t file_writable(struct SHELL_FILE *fp); 87 93 static void file_delete(struct SHELL_FILE *fp); 88 94 … … 93 99 static int dir_ioctl(struct SHELL_FILE *fp, int req, void *arg); 94 100 static bool_t dir_readable(struct SHELL_FILE *fp); 101 static bool_t dir_writable(struct SHELL_FILE *fp); 95 102 static void dir_delete(struct SHELL_FILE *fp); 96 103 97 IO_TYPE IO_TYPE_FILE = { file_close, file_read, file_write, file_seek, file_ioctl, file_readable, file_ delete };98 IO_TYPE IO_TYPE_DIR = { dir_close, dir_read, dir_write, dir_seek, dir_ioctl, dir_readable, dir_ delete };104 IO_TYPE IO_TYPE_FILE = { file_close, file_read, file_write, file_seek, file_ioctl, file_readable, file_writable, file_delete }; 105 IO_TYPE IO_TYPE_DIR = { dir_close, dir_read, dir_write, dir_seek, dir_ioctl, dir_readable, dir_writable, dir_delete }; 99 106 100 107 int shell_open(const char *path, int flags, void *arg) … … 114 121 FRESULT res; 115 122 if ((res = f_opendir(dir, path)) != FR_OK) { 123 delete_fp(fp); 116 124 return fresult2errno(res); 117 125 } … … 165 173 } 166 174 175 delete_fp(fp); 167 176 return fresult2errno(res); 168 177 } … … 239 248 } 240 249 250 bool_t file_writable(struct SHELL_FILE *fp) 251 { 252 return fp->writable && (fp->writeevt_w == fp->writeevt_r); 253 } 254 241 255 void file_delete(struct SHELL_FILE *fp) 242 256 { … … 356 370 { 357 371 return shell_ioctl(fd, cmd, arg); 358 }359 360 extern IO_TYPE IO_TYPE_SIO;361 362 int sio_tcgetattr(int fd, struct termios *termios)363 {364 struct SHELL_FILE *fp = fd_to_fp(fd);365 if ((fp == NULL) || (fp->type != &IO_TYPE_SIO))366 return -EBADF;367 368 ntstdio_t *ntstdio = (ntstdio_t *)fp->exinf;369 370 memset(termios, 0, sizeof(*termios));371 372 if (ntstdio->option & NTSTDIO_OPTION_LINE_ECHO) {373 termios->c_lflag |= ECHO;374 }375 else {376 termios->c_lflag &= ~ECHO;377 }378 if (ntstdio->option & NTSTDIO_OPTION_CANON) {379 termios->c_lflag |= ICANON;380 }381 else {382 termios->c_lflag &= ~ICANON;383 }384 if (ntstdio->option & NTSTDIO_OPTION_LF_CR) {385 termios->c_iflag |= INLCR;386 }387 else {388 termios->c_iflag &= ~INLCR;389 }390 if (ntstdio->option & NTSTDIO_OPTION_LF_CRLF) {391 termios->c_oflag |= ONLCR;392 }393 else {394 termios->c_oflag &= ~ONLCR;395 }396 397 return 0;398 }399 400 int sio_tcsetattr(int fd, int optional_actions, const struct termios *termios)401 {402 struct SHELL_FILE *fp = fd_to_fp(fd);403 if ((fp == NULL) || (fp->type != &IO_TYPE_SIO))404 return -EBADF;405 406 ntstdio_t *ntstdio = (ntstdio_t *)fp->exinf;407 408 if (optional_actions == TCSANOW) {409 if (termios->c_lflag & ECHO) {410 ntstdio->option |= NTSTDIO_OPTION_LINE_ECHO;411 }412 else {413 ntstdio->option &= ~NTSTDIO_OPTION_LINE_ECHO;414 }415 if (termios->c_lflag & ICANON) {416 ntstdio->option |= NTSTDIO_OPTION_CANON;417 }418 else {419 ntstdio->option &= ~NTSTDIO_OPTION_CANON;420 }421 if (termios->c_iflag & INLCR) {422 ntstdio->option |= NTSTDIO_OPTION_LF_CR;423 }424 else {425 ntstdio->option &= ~NTSTDIO_OPTION_LF_CR;426 }427 if (termios->c_oflag & ONLCR) {428 ntstdio->option |= NTSTDIO_OPTION_LF_CRLF;429 }430 else {431 ntstdio->option &= ~NTSTDIO_OPTION_LF_CRLF;432 }433 return 0;434 }435 436 shell_abort();437 return 0;438 372 } 439 373 … … 688 622 } 689 623 624 bool_t dir_writable(struct SHELL_FILE *fp) 625 { 626 return false; 627 } 628 690 629 void dir_delete(struct SHELL_FILE *fp) 691 630 { … … 710 649 return 0; 711 650 } 712 713 #ifndef _MSC_VER714 extern uint32_t __HeapBase;715 extern uint32_t __HeapLimit;716 #else717 uint8_t __HeapBase[14 * 4096];718 #define __HeapLimit __HeapBase[sizeof(__HeapBase)]719 #endif720 721 void *shell_brk(void *addr)722 {723 if (addr == 0) {724 return (void *)(&__HeapBase);725 }726 if ((addr >= (void *)&__HeapBase) && (addr < (void *)&__HeapLimit)) {727 return addr;728 }729 return (void *)-1;730 }731 732 void *shell_mmap2(void *start, size_t length, int prot, int flags, int fd, off_t pgoffset)733 {734 if (fd != -1)735 return (void *)-EINVAL;736 737 if ((length >= 0) && (length <= sizeof(&__HeapBase))) {738 return &__HeapBase;739 }740 return (void *)-1;741 }742 743 int shell_mprotect(void *addr, size_t len, int prot)744 {745 //if ((addr >= (void *)&__HeapBase) && (addr + len < (void *)&__HeapLimit)) {746 return 0;747 //}748 //return -1;749 }
Note:
See TracChangeset
for help on using the changeset viewer.