Changeset 441 for EcnlProtoTool/trunk/ntshell/src/fdtable.c
- Timestamp:
- Jul 10, 2020, 9:09:25 PM (4 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
EcnlProtoTool/trunk/ntshell/src/fdtable.c
r434 r441 43 43 #include "syssvc/serial.h" 44 44 #include "syssvc/syslog.h" 45 #include <tinet_config.h> 46 #include <netinet/in.h> 47 #include <netinet/in_itron.h> 48 #include <tinet_nic_defs.h> 49 #include <tinet_cfg.h> 50 #include <netinet/in_var.h> 51 #include <net/ethernet.h> 52 #include <net/if6_var.h> 53 #include <net/net.h> 54 #include <net/if_var.h> 55 #include <netinet/udp_var.h> 56 //#include <ethernet_api.h> 57 #include "ff.h" 45 #include "target_syssvc.h" 58 46 #include "fdtable.h" 59 47 #include "kernel_cfg.h" 60 //#include <string.h> 61 62 #define SIO_PORTID 1 63 64 #define IO_TYPE_FREE 0 65 #define IO_TYPE_SIO 1 66 #define IO_TYPE_FILE 2 67 #define IO_TYPE_DIR 3 68 #define IO_TYPE_TCP 4 69 #define IO_TYPE_UDP 5 70 71 static struct _IO_FILE fd_table[8 * sizeof(FLGPTN)] = { 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 }, 48 #include <string.h> 49 #include "util/ntstdio.h" 50 #include "hal/serial_api.h" 51 52 #ifdef _DEBUG 53 static const char THIS_FILE[] = __FILE__; 54 #endif 55 56 extern IO_TYPE IO_TYPE_STDIN; 57 extern IO_TYPE IO_TYPE_STDOUT; 58 extern IO_TYPE IO_TYPE_STDERR; 59 60 static struct SHELL_FILE fd_table[8 * sizeof(FLGPTN)] = { 61 { STDIN_FILENO, &IO_TYPE_STDIN, 0 }, 62 { STDOUT_FILENO, &IO_TYPE_STDOUT, 0 }, 63 { STDERR_FILENO, &IO_TYPE_STDERR, 0 }, 75 64 }; 76 65 #define fd_table_count (sizeof(fd_table) / sizeof(fd_table[0])) 77 66 78 static int new_fd(int type, int id) 79 { 67 struct SHELL_FILE *new_fp(IO_TYPE *type, int id, int writable) 68 { 69 struct SHELL_FILE *fp = NULL; 70 ER ret; 71 72 ret = wai_sem(SEM_FILEDESC); 73 if (ret < 0) { 74 syslog(LOG_ERROR, "wai_sem => %d", ret); 75 } 76 80 77 for (int fd = 3; fd < fd_table_count; fd++) { 81 struct _IO_FILE *fp = &fd_table[fd];82 if (fp->type != IO_TYPE_FREE)78 fp = &fd_table[fd]; 79 if (fp->type != NULL) 83 80 continue; 84 81 82 memset(fp, 0, sizeof(struct SHELL_FILE)); 85 83 fp->fd = fd; 86 84 fp->type = type; 87 85 fp->handle = id; 88 return fd; 89 } 90 91 return -ENOMEM; 92 } 93 94 static struct _IO_FILE *id_to_fd(int type, int id) 95 { 86 fp->writable = writable; 87 break; 88 } 89 90 ret = sig_sem(SEM_FILEDESC); 91 if (ret < 0) { 92 syslog(LOG_ERROR, "sig_sem => %d", ret); 93 } 94 95 if (fp != NULL) { 96 FLGPTN flgptn = 0; 97 98 FD_SET(fp->fd, (fd_set *)&flgptn); 99 100 ret = clr_flg(FLG_SELECT_WAIT, ~flgptn); 101 if (ret != E_OK) { 102 syslog(LOG_ERROR, "clr_flg => %d", ret); 103 } 104 } 105 106 return fp; 107 } 108 109 struct SHELL_FILE *id_to_fd(IO_TYPE *type, int id) 110 { 111 struct SHELL_FILE *fp = NULL; 112 ER ret; 113 114 ret = wai_sem(SEM_FILEDESC); 115 if (ret < 0) { 116 syslog(LOG_ERROR, "wai_sem => %d", ret); 117 } 118 96 119 for (int fd = 3; fd < fd_table_count; fd++) { 97 struct _IO_FILE *fp = &fd_table[fd];120 fp = &fd_table[fd]; 98 121 if ((fp->type == type) && (fp->handle == id)) 99 return fp; 100 } 101 102 return NULL; 103 } 104 105 static int delete_fd(int type, int id) 106 { 107 struct _IO_FILE *fp = id_to_fd(type, id); 122 break; 123 } 124 125 ret = sig_sem(SEM_FILEDESC); 126 if (ret < 0) { 127 syslog(LOG_ERROR, "sig_sem => %d", ret); 128 } 129 130 return fp; 131 } 132 133 int delete_fd_by_id(IO_TYPE *type, int id) 134 { 135 struct SHELL_FILE *fp = id_to_fd(type, id); 108 136 if (fp == NULL) 109 137 return -EBADF; 110 138 111 memset(fp, 0, sizeof(struct _IO_FILE)); 139 return delete_fp(fp); 140 } 141 142 int delete_fp(struct SHELL_FILE *fp) 143 { 144 ER ret; 145 146 if (fp->type == NULL) 147 return 0; 148 149 fp->type->delete(fp); 150 151 ret = wai_sem(SEM_FILEDESC); 152 if (ret < 0) { 153 syslog(LOG_ERROR, "wai_sem => %d", ret); 154 } 155 156 memset(fp, 0, sizeof(struct SHELL_FILE)); 157 158 ret = sig_sem(SEM_FILEDESC); 159 if (ret < 0) { 160 syslog(LOG_ERROR, "sig_sem => %d", ret); 161 } 112 162 113 163 return 0; 114 164 } 115 165 116 struct _IO_FILE *fd_to_fp(int fd)166 struct SHELL_FILE *fd_to_fp(int fd) 117 167 { 118 168 if ((fd < 0) || (fd >= fd_table_count)) … … 121 171 } 122 172 123 struct _IO_FILE *new_sio_fd(int sioid) 124 { 125 int fd = new_fd(IO_TYPE_SIO, sioid); 126 if ((fd < 0) || (fd >= fd_table_count)) 127 return NULL; 128 129 struct _IO_FILE *fp = &fd_table[fd]; 130 fp->close = sio_close; 131 fp->read = sio_read; 132 fp->write = sio_write; 133 fp->seek = sio_seek; 134 fp->ioctl = sio_ioctl; 135 136 return fp; 137 } 138 139 int delete_sio_fd(int sioid) 140 { 141 return delete_fd(IO_TYPE_SIO, sioid); 142 } 143 144 struct _IO_FILE *sioid_to_fd(int sioid) 145 { 146 return id_to_fd(IO_TYPE_SIO, sioid); 147 } 148 149 struct _IO_FILE *new_file_fd(int fileid) 150 { 151 int fd = new_fd(IO_TYPE_FILE, fileid); 152 if ((fd < 0) || (fd >= fd_table_count)) 153 return NULL; 154 155 struct _IO_FILE *fp = &fd_table[fd]; 156 fp->close = file_close; 157 fp->read = file_read; 158 fp->write = file_write; 159 fp->seek = file_seek; 160 fp->ioctl = file_ioctl; 161 162 return fp; 163 } 164 165 int delete_file_fd(int fileid) 166 { 167 return delete_fd(IO_TYPE_FILE, fileid); 168 } 169 170 struct _IO_FILE *fileid_to_fd(int fileid) 171 { 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); 199 } 200 201 struct _IO_FILE *new_tcp_fd(int tcpid) 202 { 203 int fd = new_fd(IO_TYPE_TCP, tcpid); 204 if ((fd < 0) || (fd >= fd_table_count)) 205 return NULL; 206 207 struct _IO_FILE *fp = &fd_table[fd]; 208 fp->close = tcp_fd_close; 209 fp->read = tcp_fd_read; 210 fp->write = tcp_fd_write; 211 fp->seek = tcp_fd_seek; 212 fp->ioctl = tcp_fd_ioctl; 213 214 return fp; 215 } 216 217 int delete_tcp_fd(int tcpid) 218 { 219 return delete_fd(IO_TYPE_TCP, tcpid); 220 } 221 222 struct _IO_FILE *tcpid_to_fd(int tcpid) 223 { 224 return id_to_fd(IO_TYPE_TCP, tcpid); 225 } 226 227 struct _IO_FILE *new_udp_fd(int udpid) 228 { 229 int fd = new_fd(IO_TYPE_UDP, udpid); 230 if ((fd < 0) || (fd >= fd_table_count)) 231 return NULL; 232 233 struct _IO_FILE *fp = &fd_table[fd]; 234 fp->close = udp_fd_close; 235 fp->read = udp_fd_read; 236 fp->write = udp_fd_write; 237 fp->seek = udp_fd_seek; 238 fp->ioctl = udp_fd_ioctl; 239 240 return fp; 241 } 242 243 int delete_udp_fd(int udpid) 244 { 245 return delete_fd(IO_TYPE_UDP, udpid); 246 } 247 248 struct _IO_FILE *udpid_to_fd(int udpid) 249 { 250 return id_to_fd(IO_TYPE_UDP, udpid); 173 void memand(void *dst, void *src, size_t len) 174 { 175 uint8_t *d = (uint8_t *)dst; 176 uint8_t *s = (uint8_t *)src; 177 uint8_t *e = &s[len]; 178 179 while (s < e) { 180 *d++ &= *s++; 181 } 251 182 } 252 183 … … 258 189 }; 259 190 260 ER shell_get_evts(struct fd_events *evts, TMO tmout);191 ER shell_get_evts(struct fd_events *evts, TMO *tmout); 261 192 262 193 #define TMO_MAX INT_MAX 263 194 264 int shell_select(int n, fd_set * __restrict rfds, fd_set *__restrict wfds, fd_set *__restrict efds, struct timeval *__restrict tv)195 int shell_select(int n, fd_set *restrict rfds, fd_set *restrict wfds, fd_set *restrict efds, struct timeval *restrict tv) 265 196 { 266 197 ER ret; … … 275 206 } 276 207 277 memcpy(&evts.readfds, rfds, sizeof(fd_set)); 278 memcpy(&evts.writefds, wfds, sizeof(fd_set)); 279 memcpy(&evts.errorfds, efds, sizeof(fd_set)); 208 if (rfds != NULL) 209 memcpy(&evts.readfds, rfds, sizeof(fd_set)); 210 else 211 memset(&evts.readfds, 0, sizeof(fd_set)); 212 if (wfds != NULL) 213 memcpy(&evts.writefds, wfds, sizeof(fd_set)); 214 else 215 memset(&evts.writefds, 0, sizeof(fd_set)); 216 if (efds != NULL) 217 memcpy(&evts.errorfds, efds, sizeof(fd_set)); 218 else 219 memset(&evts.errorfds, 0, sizeof(fd_set)); 280 220 evts.count = 0; 281 221 282 ret = shell_get_evts(&evts, tmout);222 ret = shell_get_evts(&evts, &tmout); 283 223 if (ret == E_OK) { 284 memcpy(rfds, &evts.readfds, sizeof(fd_set)); 285 memcpy(wfds, &evts.writefds, sizeof(fd_set)); 286 memcpy(efds, &evts.errorfds, sizeof(fd_set)); 224 if (rfds != NULL) 225 memand(rfds, &evts.readfds, sizeof(fd_set)); 226 if (wfds != NULL) 227 memand(wfds, &evts.writefds, sizeof(fd_set)); 228 if (efds != NULL) 229 memand(efds, &evts.errorfds, sizeof(fd_set)); 287 230 return evts.count; 288 231 } 289 232 if (ret == E_TMOUT) { 290 memset(rfds, 0, sizeof(fd_set)); 291 memset(wfds, 0, sizeof(fd_set)); 292 memset(efds, 0, sizeof(fd_set)); 233 if (rfds != NULL) 234 memset(rfds, 0, sizeof(fd_set)); 235 if (wfds != NULL) 236 memset(wfds, 0, sizeof(fd_set)); 237 if (efds != NULL) 238 memset(efds, 0, sizeof(fd_set)); 293 239 return 0; 294 240 } … … 310 256 tmout = TMO_MAX; 311 257 258 retry: 312 259 memset(&evts, 0, sizeof(evts)); 313 260 … … 327 274 } 328 275 329 ret = shell_get_evts(&evts, tmout);276 ret = shell_get_evts(&evts, &tmout); 330 277 if (ret == E_OK) { 331 278 int result = 0; … … 345 292 result++; 346 293 } 294 if (result == 0) 295 goto retry; 347 296 return result; 348 297 } … … 354 303 } 355 304 356 void stdio_update_evts() 357 { 358 int fd = STDIN_FILENO; 359 struct _IO_FILE *fp = &fd_table[fd]; 360 T_SERIAL_RPOR rpor; 361 FLGPTN flgptn = 0; 362 363 ER ret = serial_ref_por(SIO_PORTID, &rpor); 364 if (ret != E_OK) 365 return; 366 367 if (rpor.reacnt != 0) { 368 if (fp->readevt_w == fp->readevt_r) fp->readevt_w++; 369 370 FD_SET(fd, (fd_set *)&flgptn); 371 } 372 if (rpor.wricnt != 0) { 373 if (fp->writeevt_w == fp->writeevt_r) fp->writeevt_w++; 374 375 FD_SET(fd, (fd_set *)&flgptn); 376 } 377 378 if (flgptn != 0) { 379 set_flg(FLG_SELECT_WAIT, flgptn); 380 } 381 } 382 383 void stdio_flgptn(FLGPTN *flgptn) 384 { 385 int fd = STDIN_FILENO; 386 struct _IO_FILE *fp = &fd_table[fd]; 387 T_SERIAL_RPOR rpor; 388 *flgptn = 0; 389 390 ER ret = serial_ref_por(SIO_PORTID, &rpor); 391 if (ret != E_OK) 392 return; 393 394 if (rpor.reacnt != 0) { 395 if (fp->readevt_w == fp->readevt_r) fp->readevt_w++; 396 397 FD_SET(fd, (fd_set *)flgptn); 398 } 399 if (rpor.wricnt != 0) { 400 if (fp->writeevt_w == fp->writeevt_r) fp->writeevt_w++; 401 402 FD_SET(fd, (fd_set *)flgptn); 403 } 404 } 405 406 ER socket_tcp_callback(ID cepid, FN fncd, void *p_parblk) 407 { 408 struct _IO_FILE *fp = tcpid_to_fd(cepid); 409 FLGPTN flgptn = 0; 410 411 if (fp == NULL) 412 return E_PAR; 413 414 int fd = fp->fd; 415 FD_SET(fd, (fd_set *)&flgptn); 416 417 switch (fncd) { 418 case TFN_TCP_RCV_DAT: 419 if (fp->readevt_w == fp->readevt_r) fp->readevt_w++; 420 421 set_flg(FLG_SELECT_WAIT, flgptn); 422 return E_OK; 423 424 case TFN_TCP_SND_DAT: 425 if (fp->writeevt_w == fp->writeevt_r) fp->writeevt_w++; 426 427 set_flg(FLG_SELECT_WAIT, flgptn); 428 return E_OK; 429 430 case TFN_TCP_CAN_CEP: 431 if (fp->errorevt_w == fp->errorevt_r) fp->errorevt_w++; 432 433 set_flg(FLG_SELECT_WAIT, flgptn); 434 return E_OK; 435 436 case TFN_TCP_DEL_REP: 437 delete_tcp_rep(cepid); 438 return E_OK; 439 440 case TFN_TCP_DEL_CEP: 441 delete_tcp_fd(cepid); 442 return E_OK; 443 444 default: 445 return E_OK; 446 } 447 } 448 449 ER socket_udp_callback(ID cepid, FN fncd, void *p_parblk) 450 { 451 struct _IO_FILE *fp = udpid_to_fd(cepid); 452 FLGPTN flgptn = 0; 453 454 if (fp == NULL) 455 return E_PAR; 456 457 int fd = fp->fd; 458 FD_SET(fd, (fd_set *)&flgptn); 459 460 switch (fncd) { 461 case TFN_UDP_CRE_CEP: 462 case TFN_UDP_RCV_DAT: 463 if (fp->readevt_w == fp->readevt_r) fp->readevt_w++; 464 465 set_flg(FLG_SELECT_WAIT, flgptn); 466 return E_OK; 467 468 case TFN_UDP_SND_DAT: 469 if (fp->writeevt_w == fp->writeevt_r) fp->writeevt_w++; 470 471 set_flg(FLG_SELECT_WAIT, flgptn); 472 return E_OK; 473 474 case TFN_UDP_CAN_CEP: 475 if (fp->errorevt_w == fp->errorevt_r) fp->errorevt_w++; 476 477 set_flg(FLG_SELECT_WAIT, flgptn); 478 return E_OK; 479 480 case TFN_UDP_DEL_CEP: 481 delete_udp_fd(cepid); 482 return E_OK; 483 484 default: 485 return E_OK; 486 } 487 } 488 489 ER shell_get_evts(struct fd_events *evts, TMO tmout) 490 { 491 ER ret; 492 FLGPTN waitptn, flgptn = 0; 493 494 stdio_update_evts(); 495 496 waitptn = *((FLGPTN *)&evts->readfds) | *((FLGPTN *)&evts->writefds) | *((FLGPTN *)&evts->errorfds); 497 memset(evts, 0, sizeof(*evts)); 498 499 /* イベント待ち */ 500 ret = twai_flg(FLG_SELECT_WAIT, waitptn, TWF_ORW, &flgptn, tmout); 501 if (ret != E_OK) { 502 if (ret != E_TMOUT) { 503 syslog(LOG_ERROR, "twai_flg => %d", ret); 504 return ret; 505 } 506 507 stdio_flgptn(&flgptn); 508 509 if (flgptn == 0) 305 ER shell_get_evts(struct fd_events *evts, TMO *tmout) 306 { 307 int count; 308 SYSTIM prev, now; 309 FLGPTN flgptn; 310 311 get_tim(&prev); 312 313 for (;;) { 314 ER ret; 315 FLGPTN waitptn, readfds = 0, writefds = 0; 316 struct SHELL_FILE *fp = NULL; 317 318 #ifndef NTSHELL_NO_SOCKET 319 waitptn = *((FLGPTN *)&evts->errorfds); 320 #else 321 waitptn = *((FLGPTN *)&evts->readfds) | *((FLGPTN *)&evts->errorfds); 322 #endif 323 count = 0; 324 for (int fd = 0; fd < fd_table_count; fd++) { 325 fp = &fd_table[fd]; 326 327 if (FD_ISSET(fd, &evts->readfds)) { 328 if (fp->type->readable(fp)) { 329 FD_SET(fd, (fd_set *)&readfds); 330 count++; 331 if (fp->readevt_w == fp->readevt_r) fp->readevt_r--; 332 } 333 else { 334 FD_SET(fd, (fd_set *)&waitptn); 335 } 336 } 337 338 if (FD_ISSET(fd, &evts->writefds)) { 339 if (fp->type->writable(fp)) { 340 FD_SET(fd, (fd_set *)&writefds); 341 count++; 342 if (fp->writeevt_w == fp->writeevt_r) fp->writeevt_r--; 343 } 344 else { 345 FD_SET(fd, (fd_set *)&waitptn); 346 } 347 } 348 } 349 memset(evts, 0, sizeof(*evts)); 350 351 if (waitptn == 0) { 352 memcpy(&evts->readfds, &readfds, sizeof(evts->readfds)); 353 memcpy(&evts->writefds, &writefds, sizeof(evts->writefds)); 354 evts->count = count; 355 return E_OK; 356 } 357 else if ((readfds | writefds) != 0) { 358 set_flg(FLG_SELECT_WAIT, (readfds | writefds)); 359 } 360 361 /* イベント待ち */ 362 flgptn = 0; 363 ret = twai_flg(FLG_SELECT_WAIT, waitptn, TWF_ORW, &flgptn, *tmout); 364 if (ret != E_OK) { 365 if (ret != E_TMOUT) { 366 syslog(LOG_ERROR, "twai_flg => %d", ret); 367 return ret; 368 } 369 } 370 371 if (flgptn != 0) { 372 flgptn &= waitptn; 373 374 /* 受け取ったフラグのみクリア */ 375 ret = clr_flg(FLG_SELECT_WAIT, ~flgptn); 376 if (ret != E_OK) { 377 syslog(LOG_ERROR, "clr_flg => %d", ret); 378 } 379 } 380 381 count = 0; 382 for (int fd = 0; fd < fd_table_count; fd++) { 383 fp = &fd_table[fd]; 384 385 if (FD_ISSET(fd, (fd_set *)&waitptn) 386 && (fp->readevt_w != fp->readevt_r)) { 387 fp->readevt_r++; 388 FD_SET(fd, &evts->readfds); 389 count++; 390 } 391 if (FD_ISSET(fd, (fd_set *)&waitptn) 392 && (fp->writeevt_w != fp->writeevt_r)) { 393 fp->writeevt_r++; 394 FD_SET(fd, &evts->writefds); 395 count++; 396 } 397 if (FD_ISSET(fd, (fd_set *)&waitptn) 398 && (fp->errorevt_w != fp->errorevt_r)) { 399 fp->errorevt_r++; 400 FD_SET(fd, &evts->errorfds); 401 count++; 402 } 403 } 404 405 if (count > 0) 406 break; 407 408 get_tim(&now); 409 410 SYSTIM elapse = now - prev; 411 if (elapse > *tmout) { 412 *tmout = 0; 413 evts->count = 0; 510 414 return E_TMOUT; 511 } 512 flgptn &= waitptn; 513 514 /* 受け取ったフラグのみクリア */ 515 ret = clr_flg(FLG_SELECT_WAIT, ~flgptn); 516 if (ret != E_OK) { 517 syslog(LOG_ERROR, "clr_flg => %d", ret); 518 } 519 520 struct _IO_FILE *fp = NULL; 521 for (int fd = 0; fd < fd_table_count; fd++) { 522 if (!FD_ISSET(fd, (fd_set *)&flgptn)) 523 continue; 524 525 fp = &fd_table[fd]; 526 527 if (fp->readevt_w != fp->readevt_r) { 528 fp->readevt_r++; 529 FD_SET(fd, &evts->readfds); 530 evts->count++; 531 } 532 if (fp->writeevt_w != fp->writeevt_r) { 533 fp->writeevt_r++; 534 FD_SET(fd, &evts->writefds); 535 evts->count++; 536 } 537 if (fp->errorevt_w != fp->errorevt_r) { 538 fp->errorevt_r++; 539 FD_SET(fd, &evts->errorfds); 540 evts->count++; 541 } 542 } 415 } 416 417 prev = now; 418 *tmout -= elapse; 419 } 420 421 evts->count = count; 543 422 544 423 return E_OK; … … 547 426 void clean_fd() 548 427 { 549 struct _IO_FILE *fp = NULL;428 struct SHELL_FILE *fp = NULL; 550 429 for (int fd = 3; fd < fd_table_count; fd++) { 551 430 fp = &fd_table[fd]; … … 553 432 continue; 554 433 555 fp->close(fp); 556 557 memset(fp, 0, sizeof(*fp)); 558 } 434 fp->type->close(fp); 435 436 delete_fp(fp); 437 } 438 } 439 440 int shell_close(int fd) 441 { 442 struct SHELL_FILE *fp = fd_to_fp(fd); 443 if ((fp == NULL) || (fp->type == NULL)) 444 return -EBADF; 445 446 int ret = fp->type->close(fp); 447 448 delete_fp(fp); 449 450 return ret; 451 } 452 453 ssize_t shell_read(int fd, void *data, size_t len) 454 { 455 struct SHELL_FILE *fp = fd_to_fp(fd); 456 if ((fp == NULL) || (fp->type == NULL)) 457 return -EBADF; 458 459 return fp->type->read(fp, (unsigned char *)data, len); 460 } 461 462 int shell_readv(int fd, const struct iovec *iov, int iovcnt) 463 { 464 int result = 0; 465 struct SHELL_FILE *fp = fd_to_fp(fd); 466 if ((fp == NULL) || (fp->type == NULL)) 467 return -EBADF; 468 469 const struct iovec *end = &iov[iovcnt]; 470 for (; iov < end; iov++) { 471 result += fp->type->read(fp, (unsigned char *)iov->iov_base, iov->iov_len); 472 } 473 474 return result; 475 } 476 477 ssize_t shell_write(int fd, const void *data, size_t len) 478 { 479 struct SHELL_FILE *fp = fd_to_fp(fd); 480 if ((fp == NULL) || (fp->type == NULL)) 481 return -EBADF; 482 483 return fp->type->write(fp, (unsigned char *)data, len); 484 } 485 486 int shell_writev(int fd, const struct iovec *iov, int iovcnt) 487 { 488 int result = 0; 489 struct SHELL_FILE *fp = fd_to_fp(fd); 490 if ((fp == NULL) || (fp->type == NULL)) 491 return -EBADF; 492 493 const struct iovec *end = &iov[iovcnt]; 494 for (; iov < end; iov++) { 495 result += fp->type->write(fp, (unsigned char *)iov->iov_base, iov->iov_len); 496 } 497 498 return result; 499 } 500 501 int shell_llseek(int fd, off_t ptr, off_t *result, int dir) 502 { 503 struct SHELL_FILE *fp = fd_to_fp(fd); 504 if ((fp == NULL) || (fp->type == NULL)) 505 return -EBADF; 506 507 off_t ret = fp->type->seek(fp, ptr, dir); 508 if (ret < 0) 509 return ret; 510 511 *result = ret; 512 return 0; 559 513 } 560 514 561 515 int shell_ioctl(int fd, int request, void *arg) 562 516 { 563 struct _IO_FILE *fp = fd_to_fp(fd);517 struct SHELL_FILE *fp = fd_to_fp(fd); 564 518 if (fp == NULL) 565 519 return -EBADF; 566 520 567 return fp->ioctl(fp, request, arg); 568 } 521 return fp->type->ioctl(fp, request, arg); 522 } 523 524 #ifdef NTSHELL_NO_SOCKET 525 526 int shell_socket(int family, int type, int protocol) 527 { 528 return -ENOMEM; 529 } 530 531 int shell_bind(int fd, const struct sockaddr *addr, socklen_t len) 532 { 533 return -ENOMEM; 534 } 535 536 int shell_listen(int fd, int backlog) 537 { 538 return -ENOMEM; 539 } 540 541 int shell_connect(int fd, const struct sockaddr *addr, socklen_t len) 542 { 543 return -ENOMEM; 544 } 545 546 int shell_accept(int fd, struct sockaddr *restrict addr, socklen_t *restrict len) 547 { 548 return -ENOMEM; 549 } 550 551 ssize_t shell_sendto(int fd, const void *buf, size_t len, int flags, const struct sockaddr *addr, socklen_t alen) 552 { 553 return -ENOMEM; 554 } 555 556 ssize_t shell_sendmsg(int fd, const struct msghdr *msg, int flags) 557 { 558 return -ENOMEM; 559 } 560 561 ssize_t shell_recvfrom(int fd, void *restrict buf, size_t len, int flags, struct sockaddr *restrict addr, socklen_t *restrict alen) 562 { 563 return -ENOMEM; 564 } 565 566 ssize_t shell_recvmsg(int fd, struct msghdr *msg, int flags) 567 { 568 return -ENOMEM; 569 } 570 571 int shell_shutdown(int fd, int how) 572 { 573 return -ENOMEM; 574 } 575 576 int shell_getsockopt(int fd, int level, int optname, void *optval, socklen_t *restrict optlen) 577 { 578 return -ENOMEM; 579 } 580 581 int shell_setsockopt(int fd, int level, int optname, const void *optval, socklen_t optlen) 582 { 583 return -ENOMEM; 584 } 585 586 int shell_getpeername(int fd, struct sockaddr *restrict addr, socklen_t *restrict len) 587 { 588 return -ENOMEM; 589 } 590 591 int shell_getsockname(int fd, struct sockaddr *restrict addr, socklen_t *restrict len) 592 { 593 return -ENOMEM; 594 } 595 #endif
Note:
See TracChangeset
for help on using the changeset viewer.