Changeset 331 for EcnlProtoTool/trunk/ntshell/src/fdtable.c
- Timestamp:
- Jan 21, 2018, 12:10:09 AM (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
EcnlProtoTool/trunk/ntshell/src/fdtable.c
r321 r331 35 35 * @(#) $Id$ 36 36 */ 37 #include "shellif.h" 37 38 #include <stdint.h> 38 #include <stdio.h>39 #include <sys/unistd.h>40 #include <limits.h>41 39 #include <kernel.h> 42 40 #include <t_syslog.h> 43 41 #include <t_stdlib.h> 44 42 #include <sil.h> 45 #include <stdlib.h>46 #include <string.h>47 #include <stdio.h>48 #include <setjmp.h>49 #include "../../../musl-1.1.12/include/poll.h"50 43 #include "syssvc/serial.h" 51 44 #include "syssvc/syslog.h" … … 61 54 #include <net/if_var.h> 62 55 #include <netinet/udp_var.h> 63 #include <ethernet_api.h>56 //#include <ethernet_api.h> 64 57 #include "ff.h" 65 58 #include "socket_stub.h" 66 59 #include "kernel_cfg.h" 60 #include <string.h> 67 61 68 62 #define SIO_PORTID 1 … … 71 65 #define IO_TYPE_SIO 1 72 66 #define IO_TYPE_FILE 2 73 #define IO_TYPE_TCP 3 74 #define IO_TYPE_UDP 4 67 #define IO_TYPE_DIR 3 68 #define IO_TYPE_TCP 4 69 #define IO_TYPE_UDP 5 75 70 76 71 static struct _IO_FILE fd_table[8 * sizeof(FLGPTN)] = { 77 { 0, IO_TYPE_SIO, 0, stdio_close, stdin_read, stdio_write },78 { 1, IO_TYPE_SIO, 0, stdio_close, stdio_read, stdout_write },79 { 2, IO_TYPE_SIO, 0, stdio_close, stdio_read, stderr_write },72 { 0, IO_TYPE_SIO, 0, stdio_close, stdin_read, stdio_write, sio_seek, sio_ioctl }, 73 { 1, IO_TYPE_SIO, 0, stdio_close, stdio_read, stdout_write, sio_seek, sio_ioctl }, 74 { 2, IO_TYPE_SIO, 0, stdio_close, stdio_read, stderr_write, sio_seek, sio_ioctl }, 80 75 }; 81 76 #define fd_table_count (sizeof(fd_table) / sizeof(fd_table[0])) … … 94 89 } 95 90 96 return - 1;91 return -ENOMEM; 97 92 } 98 93 … … 112 107 struct _IO_FILE *fp = id_to_fd(type, id); 113 108 if (fp == NULL) 114 return - 1;109 return -EBADF; 115 110 116 111 memset(fp, 0, sizeof(struct _IO_FILE)); … … 136 131 fp->read = sio_read; 137 132 fp->write = sio_write; 133 fp->seek = sio_seek; 134 fp->ioctl = sio_ioctl; 138 135 139 136 return fp; … … 160 157 fp->read = file_read; 161 158 fp->write = file_write; 159 fp->seek = file_seek; 160 fp->ioctl = file_ioctl; 162 161 163 162 return fp; … … 172 171 { 173 172 return id_to_fd(IO_TYPE_FILE, fileid); 173 } 174 175 struct _IO_FILE *new_dir_fd(int fileid) 176 { 177 int fd = new_fd(IO_TYPE_DIR, fileid); 178 if ((fd < 0) || (fd >= fd_table_count)) 179 return NULL; 180 181 struct _IO_FILE *fp = &fd_table[fd]; 182 fp->close = dir_close; 183 fp->read = dir_read; 184 fp->write = dir_write; 185 fp->seek = dir_seek; 186 fp->ioctl = dir_ioctl; 187 188 return fp; 189 } 190 191 int delete_dir_fd(int dirid) 192 { 193 return delete_fd(IO_TYPE_DIR, dirid); 194 } 195 196 struct _IO_FILE *dirid_to_fd(int dirid) 197 { 198 return id_to_fd(IO_TYPE_DIR, dirid); 174 199 } 175 200 … … 184 209 fp->read = tcp_fd_read; 185 210 fp->write = tcp_fd_write; 211 fp->seek = tcp_fd_seek; 212 fp->ioctl = tcp_fd_ioctl; 186 213 187 214 return fp; … … 208 235 fp->read = udp_fd_read; 209 236 fp->write = udp_fd_write; 237 fp->seek = udp_fd_seek; 238 fp->ioctl = udp_fd_ioctl; 210 239 211 240 return fp; … … 220 249 { 221 250 return id_to_fd(IO_TYPE_UDP, udpid); 222 }223 224 int shell_isatty(int fd)225 {226 if ((fd < 0) || (fd >= fd_table_count))227 return 0;228 229 struct _IO_FILE *fp = &fd_table[fd];230 if (fp->type == IO_TYPE_SIO)231 return 1;232 233 return 0;234 251 } 235 252 … … 245 262 #define TMO_MAX INT_MAX 246 263 247 int s elect(int n, fd_set *rfds, fd_set *wfds, fd_set *efds, struct timeval *tv)264 int shell_select(int n, fd_set *__restrict rfds, fd_set *__restrict wfds, fd_set *__restrict efds, struct timeval *__restrict tv) 248 265 { 249 266 ER ret; … … 277 294 } 278 295 279 return - 1;280 } 281 282 int poll(struct pollfd *fds, nfds_t nfds, int timeout)296 return -EBADF; 297 } 298 299 int shell_poll(struct pollfd *fds, nfds_t nfds, int timeout) 283 300 { 284 301 ER ret; … … 334 351 } 335 352 336 return - 1;353 return -EBADF; 337 354 } 338 355 … … 541 558 } 542 559 } 560 561 int shell_ioctl(int fd, int request, void *arg) 562 { 563 struct _IO_FILE *fp = fd_to_fp(fd); 564 if (fp == NULL) 565 return -EBADF; 566 567 return fp->ioctl(fp, request, arg); 568 }
Note:
See TracChangeset
for help on using the changeset viewer.