Changeset 1ef8e3d4 in rtems
- Timestamp:
- 09/27/01 13:31:56 (22 years ago)
- Branches:
- 4.10, 4.11, 4.8, 4.9, 5, master
- Children:
- 5b87515d
- Parents:
- d9e4f08
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
c/src/exec/libnetworking/ChangeLog
rd9e4f08 r1ef8e3d4 1 2001-09-27 Eric Norum <eric.norum@usask.ca> 2 3 * lib/tftpDriver.c: Add limited chdir() support to the TFTP 4 filesystem. 5 1 6 2001-09-23 Ralf Corsepius <corsepiu@faw.uni-ulm.de> 2 7 -
c/src/exec/libnetworking/lib/tftpDriver.c
rd9e4f08 r1ef8e3d4 25 25 #include <rtems.h> 26 26 #include <rtems/libio.h> 27 #include <rtems/libio_.h> 27 28 #include <rtems/rtems_bsdnet.h> 28 29 #include <sys/types.h> … … 434 435 ) 435 436 { 436 437 /* 438 * Read-only or write-only for now 437 pathloc->handlers = &rtems_tftp_handlers; 438 439 /* 440 * Hack to provide the illusion of directories inside the TFTP file system. 441 * Paths ending in a / are assumed to be directories. 442 */ 443 if (pathname[strlen(pathname)-1] == '/') { 444 char *cp; 445 446 /* 447 * Reject attempts to open() directories 448 */ 449 if (flags) 450 set_errno_and_return_minus_one( EISDIR ); 451 cp = strdup (pathname); 452 if (cp == NULL) 453 set_errno_and_return_minus_one( ENOMEM ); 454 pathloc->node_access = cp; 455 return 0; 456 } 457 458 /* 459 * Reject it if it's not read-only or write-only. 439 460 */ 440 461 flags &= RTEMS_LIBIO_PERMS_READ | RTEMS_LIBIO_PERMS_WRITE; 441 462 if ((flags != RTEMS_LIBIO_PERMS_READ) && (flags != RTEMS_LIBIO_PERMS_WRITE) ) 442 463 set_errno_and_return_minus_one( EINVAL ); 443 444 /* 445 * The File system is mounted at TFTP_PATHNAME_PREFIX 446 * the caller of this routine has striped off this part of the 447 * name. Save the remainder of the name for use by the open routine. 448 */ 449 pathloc->node_access = (void * ) pathname; 450 pathloc->handlers = &rtems_tftp_handlers; 464 pathloc->node_access = NULL; 451 465 return 0; 452 466 } 453 467 454 static int rtems_tftp_open( 468 /* 469 * The routine which does most of the work for the IMFS open handler 470 */ 471 static int rtems_tftp_open_worker( 455 472 rtems_libio_t *iop, 456 c onst char *new_name,473 char *full_path_name, 457 474 unsigned32 flags, 458 475 unsigned32 mode … … 472 489 473 490 /* 474 * This came from the evaluate path. 475 * Extract host name component 476 */ 477 cp1 = cp2 = iop->file_info; 491 * Extract the host name component 492 */ 493 cp2 = full_path_name; 494 while (*cp2 == '/') 495 cp2++; 496 hostname = cp2; 478 497 while (*cp2 != '/') { 479 498 if (*cp2 == '\0') … … 481 500 cp2++; 482 501 } 483 len = cp2 - cp1; 484 hostname = malloc (len + 1); 485 if (hostname == NULL) 486 return ENOMEM; 487 strncpy (hostname, cp1, len); 488 hostname[len] = '\0'; 502 *cp2++ = '\0'; 489 503 490 504 /* … … 495 509 else 496 510 farAddress.s_addr = inet_addr (hostname); 497 free (hostname);498 511 if ((farAddress.s_addr == 0) || (farAddress.s_addr == ~0)) 499 512 return ENOENT; … … 667 680 668 681 /* 682 * The IMFS open handler 683 */ 684 static int rtems_tftp_open( 685 rtems_libio_t *iop, 686 const char *new_name, 687 unsigned32 flags, 688 unsigned32 mode 689 ) 690 { 691 char *full_path_name; 692 char *s1; 693 int err; 694 695 /* 696 * Tack the `current directory' on to relative paths. 697 * We know that the current directory ends in a / character. 698 */ 699 if (*new_name == '/') { 700 /* 701 * Skip the TFTP filesystem prefix. 702 */ 703 int len = strlen (TFTP_PATHNAME_PREFIX); 704 if (strncmp (new_name, TFTP_PATHNAME_PREFIX, len)) 705 return ENOENT; 706 new_name += len; 707 s1 = ""; 708 } 709 else { 710 /* 711 * Skip any leading ./ or ../ components. 712 */ 713 for (;;) { 714 while (*new_name == '/') 715 new_name++; 716 if ((new_name[0] == '.') && (new_name[1] == '/')) { 717 new_name += 2; 718 continue; 719 } 720 if ((new_name[0] == '.') && (new_name[1] == '.') && (new_name[2] == '/')) { 721 new_name += 3; 722 continue; 723 } 724 break; 725 } 726 s1 = rtems_filesystem_current.node_access; 727 } 728 full_path_name = malloc (strlen (s1) + strlen (new_name) + 1); 729 if (full_path_name == NULL) 730 return ENOMEM; 731 strcpy (full_path_name, s1); 732 strcat (full_path_name, new_name); 733 err = rtems_tftp_open_worker (iop, full_path_name, flags, mode); 734 free (full_path_name); 735 return err; 736 } 737 738 /* 669 739 * Read from a TFTP stream 670 740 */ … … 863 933 } 864 934 865 rtems_filesystem_node_types_t rtems_tftp_node_type(935 static rtems_filesystem_node_types_t rtems_tftp_node_type( 866 936 rtems_filesystem_location_info_t *pathloc /* IN */ 867 937 ) 868 938 { 869 return RTEMS_FILESYSTEM_MEMORY_FILE; 939 if (pathloc->node_access == NULL) 940 return RTEMS_FILESYSTEM_MEMORY_FILE; 941 return RTEMS_FILESYSTEM_DIRECTORY; 942 } 943 944 static int rtems_tftp_free_node_info( 945 rtems_filesystem_location_info_t *pathloc /* IN */ 946 ) 947 { 948 if (pathloc->node_access) { 949 free (pathloc->node_access); 950 pathloc->node_access = NULL; 951 } 952 return 0; 870 953 } 871 954 … … 879 962 NULL, /* mknod */ 880 963 NULL, /* chown */ 881 NULL,/* freenodinfo */964 rtems_tftp_free_node_info, /* freenodinfo */ 882 965 NULL, /* mount */ 883 966 rtems_tftp_mount_me, /* initialize */ -
c/src/libnetworking/ChangeLog
rd9e4f08 r1ef8e3d4 1 2001-09-27 Eric Norum <eric.norum@usask.ca> 2 3 * lib/tftpDriver.c: Add limited chdir() support to the TFTP 4 filesystem. 5 1 6 2001-09-23 Ralf Corsepius <corsepiu@faw.uni-ulm.de> 2 7 -
c/src/libnetworking/lib/tftpDriver.c
rd9e4f08 r1ef8e3d4 25 25 #include <rtems.h> 26 26 #include <rtems/libio.h> 27 #include <rtems/libio_.h> 27 28 #include <rtems/rtems_bsdnet.h> 28 29 #include <sys/types.h> … … 434 435 ) 435 436 { 436 437 /* 438 * Read-only or write-only for now 437 pathloc->handlers = &rtems_tftp_handlers; 438 439 /* 440 * Hack to provide the illusion of directories inside the TFTP file system. 441 * Paths ending in a / are assumed to be directories. 442 */ 443 if (pathname[strlen(pathname)-1] == '/') { 444 char *cp; 445 446 /* 447 * Reject attempts to open() directories 448 */ 449 if (flags) 450 set_errno_and_return_minus_one( EISDIR ); 451 cp = strdup (pathname); 452 if (cp == NULL) 453 set_errno_and_return_minus_one( ENOMEM ); 454 pathloc->node_access = cp; 455 return 0; 456 } 457 458 /* 459 * Reject it if it's not read-only or write-only. 439 460 */ 440 461 flags &= RTEMS_LIBIO_PERMS_READ | RTEMS_LIBIO_PERMS_WRITE; 441 462 if ((flags != RTEMS_LIBIO_PERMS_READ) && (flags != RTEMS_LIBIO_PERMS_WRITE) ) 442 463 set_errno_and_return_minus_one( EINVAL ); 443 444 /* 445 * The File system is mounted at TFTP_PATHNAME_PREFIX 446 * the caller of this routine has striped off this part of the 447 * name. Save the remainder of the name for use by the open routine. 448 */ 449 pathloc->node_access = (void * ) pathname; 450 pathloc->handlers = &rtems_tftp_handlers; 464 pathloc->node_access = NULL; 451 465 return 0; 452 466 } 453 467 454 static int rtems_tftp_open( 468 /* 469 * The routine which does most of the work for the IMFS open handler 470 */ 471 static int rtems_tftp_open_worker( 455 472 rtems_libio_t *iop, 456 c onst char *new_name,473 char *full_path_name, 457 474 unsigned32 flags, 458 475 unsigned32 mode … … 472 489 473 490 /* 474 * This came from the evaluate path. 475 * Extract host name component 476 */ 477 cp1 = cp2 = iop->file_info; 491 * Extract the host name component 492 */ 493 cp2 = full_path_name; 494 while (*cp2 == '/') 495 cp2++; 496 hostname = cp2; 478 497 while (*cp2 != '/') { 479 498 if (*cp2 == '\0') … … 481 500 cp2++; 482 501 } 483 len = cp2 - cp1; 484 hostname = malloc (len + 1); 485 if (hostname == NULL) 486 return ENOMEM; 487 strncpy (hostname, cp1, len); 488 hostname[len] = '\0'; 502 *cp2++ = '\0'; 489 503 490 504 /* … … 495 509 else 496 510 farAddress.s_addr = inet_addr (hostname); 497 free (hostname);498 511 if ((farAddress.s_addr == 0) || (farAddress.s_addr == ~0)) 499 512 return ENOENT; … … 667 680 668 681 /* 682 * The IMFS open handler 683 */ 684 static int rtems_tftp_open( 685 rtems_libio_t *iop, 686 const char *new_name, 687 unsigned32 flags, 688 unsigned32 mode 689 ) 690 { 691 char *full_path_name; 692 char *s1; 693 int err; 694 695 /* 696 * Tack the `current directory' on to relative paths. 697 * We know that the current directory ends in a / character. 698 */ 699 if (*new_name == '/') { 700 /* 701 * Skip the TFTP filesystem prefix. 702 */ 703 int len = strlen (TFTP_PATHNAME_PREFIX); 704 if (strncmp (new_name, TFTP_PATHNAME_PREFIX, len)) 705 return ENOENT; 706 new_name += len; 707 s1 = ""; 708 } 709 else { 710 /* 711 * Skip any leading ./ or ../ components. 712 */ 713 for (;;) { 714 while (*new_name == '/') 715 new_name++; 716 if ((new_name[0] == '.') && (new_name[1] == '/')) { 717 new_name += 2; 718 continue; 719 } 720 if ((new_name[0] == '.') && (new_name[1] == '.') && (new_name[2] == '/')) { 721 new_name += 3; 722 continue; 723 } 724 break; 725 } 726 s1 = rtems_filesystem_current.node_access; 727 } 728 full_path_name = malloc (strlen (s1) + strlen (new_name) + 1); 729 if (full_path_name == NULL) 730 return ENOMEM; 731 strcpy (full_path_name, s1); 732 strcat (full_path_name, new_name); 733 err = rtems_tftp_open_worker (iop, full_path_name, flags, mode); 734 free (full_path_name); 735 return err; 736 } 737 738 /* 669 739 * Read from a TFTP stream 670 740 */ … … 863 933 } 864 934 865 rtems_filesystem_node_types_t rtems_tftp_node_type(935 static rtems_filesystem_node_types_t rtems_tftp_node_type( 866 936 rtems_filesystem_location_info_t *pathloc /* IN */ 867 937 ) 868 938 { 869 return RTEMS_FILESYSTEM_MEMORY_FILE; 939 if (pathloc->node_access == NULL) 940 return RTEMS_FILESYSTEM_MEMORY_FILE; 941 return RTEMS_FILESYSTEM_DIRECTORY; 942 } 943 944 static int rtems_tftp_free_node_info( 945 rtems_filesystem_location_info_t *pathloc /* IN */ 946 ) 947 { 948 if (pathloc->node_access) { 949 free (pathloc->node_access); 950 pathloc->node_access = NULL; 951 } 952 return 0; 870 953 } 871 954 … … 879 962 NULL, /* mknod */ 880 963 NULL, /* chown */ 881 NULL,/* freenodinfo */964 rtems_tftp_free_node_info, /* freenodinfo */ 882 965 NULL, /* mount */ 883 966 rtems_tftp_mount_me, /* initialize */ -
cpukit/libnetworking/ChangeLog
rd9e4f08 r1ef8e3d4 1 2001-09-27 Eric Norum <eric.norum@usask.ca> 2 3 * lib/tftpDriver.c: Add limited chdir() support to the TFTP 4 filesystem. 5 1 6 2001-09-23 Ralf Corsepius <corsepiu@faw.uni-ulm.de> 2 7 -
cpukit/libnetworking/lib/tftpDriver.c
rd9e4f08 r1ef8e3d4 25 25 #include <rtems.h> 26 26 #include <rtems/libio.h> 27 #include <rtems/libio_.h> 27 28 #include <rtems/rtems_bsdnet.h> 28 29 #include <sys/types.h> … … 434 435 ) 435 436 { 436 437 /* 438 * Read-only or write-only for now 437 pathloc->handlers = &rtems_tftp_handlers; 438 439 /* 440 * Hack to provide the illusion of directories inside the TFTP file system. 441 * Paths ending in a / are assumed to be directories. 442 */ 443 if (pathname[strlen(pathname)-1] == '/') { 444 char *cp; 445 446 /* 447 * Reject attempts to open() directories 448 */ 449 if (flags) 450 set_errno_and_return_minus_one( EISDIR ); 451 cp = strdup (pathname); 452 if (cp == NULL) 453 set_errno_and_return_minus_one( ENOMEM ); 454 pathloc->node_access = cp; 455 return 0; 456 } 457 458 /* 459 * Reject it if it's not read-only or write-only. 439 460 */ 440 461 flags &= RTEMS_LIBIO_PERMS_READ | RTEMS_LIBIO_PERMS_WRITE; 441 462 if ((flags != RTEMS_LIBIO_PERMS_READ) && (flags != RTEMS_LIBIO_PERMS_WRITE) ) 442 463 set_errno_and_return_minus_one( EINVAL ); 443 444 /* 445 * The File system is mounted at TFTP_PATHNAME_PREFIX 446 * the caller of this routine has striped off this part of the 447 * name. Save the remainder of the name for use by the open routine. 448 */ 449 pathloc->node_access = (void * ) pathname; 450 pathloc->handlers = &rtems_tftp_handlers; 464 pathloc->node_access = NULL; 451 465 return 0; 452 466 } 453 467 454 static int rtems_tftp_open( 468 /* 469 * The routine which does most of the work for the IMFS open handler 470 */ 471 static int rtems_tftp_open_worker( 455 472 rtems_libio_t *iop, 456 c onst char *new_name,473 char *full_path_name, 457 474 unsigned32 flags, 458 475 unsigned32 mode … … 472 489 473 490 /* 474 * This came from the evaluate path. 475 * Extract host name component 476 */ 477 cp1 = cp2 = iop->file_info; 491 * Extract the host name component 492 */ 493 cp2 = full_path_name; 494 while (*cp2 == '/') 495 cp2++; 496 hostname = cp2; 478 497 while (*cp2 != '/') { 479 498 if (*cp2 == '\0') … … 481 500 cp2++; 482 501 } 483 len = cp2 - cp1; 484 hostname = malloc (len + 1); 485 if (hostname == NULL) 486 return ENOMEM; 487 strncpy (hostname, cp1, len); 488 hostname[len] = '\0'; 502 *cp2++ = '\0'; 489 503 490 504 /* … … 495 509 else 496 510 farAddress.s_addr = inet_addr (hostname); 497 free (hostname);498 511 if ((farAddress.s_addr == 0) || (farAddress.s_addr == ~0)) 499 512 return ENOENT; … … 667 680 668 681 /* 682 * The IMFS open handler 683 */ 684 static int rtems_tftp_open( 685 rtems_libio_t *iop, 686 const char *new_name, 687 unsigned32 flags, 688 unsigned32 mode 689 ) 690 { 691 char *full_path_name; 692 char *s1; 693 int err; 694 695 /* 696 * Tack the `current directory' on to relative paths. 697 * We know that the current directory ends in a / character. 698 */ 699 if (*new_name == '/') { 700 /* 701 * Skip the TFTP filesystem prefix. 702 */ 703 int len = strlen (TFTP_PATHNAME_PREFIX); 704 if (strncmp (new_name, TFTP_PATHNAME_PREFIX, len)) 705 return ENOENT; 706 new_name += len; 707 s1 = ""; 708 } 709 else { 710 /* 711 * Skip any leading ./ or ../ components. 712 */ 713 for (;;) { 714 while (*new_name == '/') 715 new_name++; 716 if ((new_name[0] == '.') && (new_name[1] == '/')) { 717 new_name += 2; 718 continue; 719 } 720 if ((new_name[0] == '.') && (new_name[1] == '.') && (new_name[2] == '/')) { 721 new_name += 3; 722 continue; 723 } 724 break; 725 } 726 s1 = rtems_filesystem_current.node_access; 727 } 728 full_path_name = malloc (strlen (s1) + strlen (new_name) + 1); 729 if (full_path_name == NULL) 730 return ENOMEM; 731 strcpy (full_path_name, s1); 732 strcat (full_path_name, new_name); 733 err = rtems_tftp_open_worker (iop, full_path_name, flags, mode); 734 free (full_path_name); 735 return err; 736 } 737 738 /* 669 739 * Read from a TFTP stream 670 740 */ … … 863 933 } 864 934 865 rtems_filesystem_node_types_t rtems_tftp_node_type(935 static rtems_filesystem_node_types_t rtems_tftp_node_type( 866 936 rtems_filesystem_location_info_t *pathloc /* IN */ 867 937 ) 868 938 { 869 return RTEMS_FILESYSTEM_MEMORY_FILE; 939 if (pathloc->node_access == NULL) 940 return RTEMS_FILESYSTEM_MEMORY_FILE; 941 return RTEMS_FILESYSTEM_DIRECTORY; 942 } 943 944 static int rtems_tftp_free_node_info( 945 rtems_filesystem_location_info_t *pathloc /* IN */ 946 ) 947 { 948 if (pathloc->node_access) { 949 free (pathloc->node_access); 950 pathloc->node_access = NULL; 951 } 952 return 0; 870 953 } 871 954 … … 879 962 NULL, /* mknod */ 880 963 NULL, /* chown */ 881 NULL,/* freenodinfo */964 rtems_tftp_free_node_info, /* freenodinfo */ 882 965 NULL, /* mount */ 883 966 rtems_tftp_mount_me, /* initialize */
Note: See TracChangeset
for help on using the changeset viewer.