pointer usb_filesystem_install( pointer usb_handle, char_ptr block_device_name, char_ptr partition_manager_name, char_ptr file_system_name ) { uint_32 partition_number; uchar_ptr dev_info; int_32 error_code; uint_32 mfs_status; USB_FILESYSTEM_STRUCT_PTR usb_fs_ptr; usb_fs_ptr = _mem_alloc_system_zero(sizeof(USB_FILESYSTEM_STRUCT)); if (usb_fs_ptr==NULL) { return NULL; } _io_usb_mfs_install(block_device_name, 0, (pointer)usb_handle); usb_fs_ptr->DEV_NAME = block_device_name; /* Open the USB mass storage device */ _time_delay(500); usb_fs_ptr->DEV_FD_PTR = fopen(block_device_name, (char_ptr) 0); if (usb_fs_ptr->DEV_FD_PTR == NULL) { printf("\nUnable to open USB disk"); usb_filesystem_uninstall(usb_fs_ptr); return NULL; } _io_ioctl(usb_fs_ptr->DEV_FD_PTR, IO_IOCTL_SET_BLOCK_MODE, NULL); /* get the vendor information and display it */ printf("\n************************************************************************"); _io_ioctl(usb_fs_ptr->DEV_FD_PTR, IO_IOCTL_GET_VENDOR_INFO, &dev_info); printf("\nVendor Information: %-1.8s Mass Storage Device",dev_info); _io_ioctl(usb_fs_ptr->DEV_FD_PTR, IO_IOCTL_GET_PRODUCT_ID, &dev_info); printf("\nProduct Identification: %-1.16s",dev_info); _io_ioctl(usb_fs_ptr->DEV_FD_PTR, IO_IOCTL_GET_PRODUCT_REV, &dev_info); printf("\nProduct Revision Level: %-1.4s",dev_info); printf("\n************************************************************************"); /* Try Installing a the partition manager */ error_code = _io_part_mgr_install(usb_fs_ptr->DEV_FD_PTR, partition_manager_name, 0); if (error_code != MFS_NO_ERROR) { printf("\nError while initializing (%s)", MFS_Error_text((uint_32)error_code)); usb_filesystem_uninstall(usb_fs_ptr); return NULL; } usb_fs_ptr->PM_NAME = partition_manager_name; usb_fs_ptr->PM_FD_PTR = fopen(partition_manager_name, NULL); if (usb_fs_ptr->PM_FD_PTR == NULL) { error_code = ferror(usb_fs_ptr->PM_FD_PTR); printf("\nError while opening partition (%s)", MFS_Error_text((uint_32)error_code)); usb_filesystem_uninstall(usb_fs_ptr); return NULL; } printf("\n--->USB Mass storage device opened"); partition_number = 1; error_code = _io_ioctl(usb_fs_ptr->PM_FD_PTR, IO_IOCTL_VAL_PART, &partition_number); if (error_code == PMGR_INVALID_PARTITION) { printf("\n--->No partition available on this device"); /* uninitialize */ fclose(usb_fs_ptr->PM_FD_PTR); usb_fs_ptr->PM_FD_PTR = NULL; _io_part_mgr_uninstall(usb_fs_ptr->PM_NAME); usb_fs_ptr->PM_NAME = NULL; /* install MFS without partition */ mfs_status = _io_mfs_install(usb_fs_ptr->DEV_FD_PTR, file_system_name, 0); } else { printf("\n--->Partition Manager installed"); /* Install MFS on the partition #1 */ mfs_status = _io_mfs_install(usb_fs_ptr->PM_FD_PTR, file_system_name, partition_number); } if (mfs_status != MFS_NO_ERROR) { printf("\nError initializing MFS (%s)", MFS_Error_text((uint_32)mfs_status)); /* uninitialize and exit */ usb_filesystem_uninstall(usb_fs_ptr); return NULL; } printf("\n--->File System installed"); usb_fs_ptr->FS_NAME = file_system_name; usb_fs_ptr->FS_FD_PTR = fopen(file_system_name, 0); if (usb_fs_ptr->FS_FD_PTR==NULL) { usb_filesystem_uninstall(usb_fs_ptr); return NULL; } printf("\n--->File System opened"); return (pointer) usb_fs_ptr; }
pointer usb_filesystem_install( pointer usb_handle, char_ptr block_device_name, char_ptr partition_manager_name, char_ptr file_system_name ) { uint_32 partition_number; uchar_ptr dev_info; int_32 error_code; USB_FILESYSTEM_STRUCT_PTR usb_fs_ptr; usb_fs_ptr = _mem_alloc_system_zero(sizeof(USB_FILESYSTEM_STRUCT)); if (usb_fs_ptr==NULL) { return NULL; } /* Install USB device */ error_code = _io_usb_mfs_install(block_device_name, 0, (pointer)usb_handle); if (error_code != MQX_OK) { printf("Error while installing USB device (0x%X)\n", error_code); return NULL; } usb_fs_ptr->DEV_NAME = block_device_name; /* Open the USB mass storage device */ _time_delay(500); // printf("open msd dev\n"); usb_fs_ptr->DEV_FD_PTR = fopen(block_device_name, 0); if (usb_fs_ptr->DEV_FD_PTR == NULL) { printf("Unable to open USB device\n"); /*usb_filesystem_uninstall*/usb_filesystem_cancel_install(usb_fs_ptr,USB_DEV_OPEN_FAIL); return NULL; } _io_ioctl(usb_fs_ptr->DEV_FD_PTR, IO_IOCTL_SET_BLOCK_MODE, NULL); /* Get the vendor information and display it */ printf("\n************************************************************************\n"); _io_ioctl(usb_fs_ptr->DEV_FD_PTR, USB_MFS_IOCTL_GET_VENDOR_INFO, &dev_info); printf("Vendor Information: %-1.8s Mass Storage Device\n",dev_info); _io_ioctl(usb_fs_ptr->DEV_FD_PTR, USB_MFS_IOCTL_GET_PRODUCT_ID, &dev_info); printf("Product Identification: %-1.16s\n",dev_info); _io_ioctl(usb_fs_ptr->DEV_FD_PTR, USB_MFS_IOCTL_GET_PRODUCT_REV, &dev_info); printf("Product Revision Level: %-1.4s\n",dev_info); printf("************************************************************************\n"); /* Try to install the partition manager */ // printf("_io_part_mgr_install\n"); error_code = _io_part_mgr_install(usb_fs_ptr->DEV_FD_PTR, partition_manager_name, 0); if (error_code != MFS_NO_ERROR) { printf("Error while initializing partition manager: %s\n", MFS_Error_text((uint_32)error_code)); /* usb_filesystem_uninstall */usb_filesystem_cancel_install(usb_fs_ptr,PARTITION_INIT_FAIL); return NULL; } usb_fs_ptr->PM_NAME = partition_manager_name; /* Open partition manager */ // printf("fopen partition\n"); usb_fs_ptr->PM_FD_PTR = fopen(partition_manager_name, NULL); if (usb_fs_ptr->PM_FD_PTR == NULL) { error_code = ferror(usb_fs_ptr->PM_FD_PTR); printf("Error while opening partition manager: %s\n", MFS_Error_text((uint_32)error_code)); /*usb_filesystem_uninstall*/usb_filesystem_cancel_install(usb_fs_ptr,PARTITION_OPEN_FAIL); return NULL; } /* Select partition */ partition_number = 1; // printf("select partition\n"); error_code = _io_ioctl(usb_fs_ptr->PM_FD_PTR, IO_IOCTL_SEL_PART, &partition_number); if (error_code == MFS_NO_ERROR) { printf("Installing MFS over partition...\n"); /* Validate partition */ // printf("Validate partition\n"); error_code = _io_ioctl(usb_fs_ptr->PM_FD_PTR, IO_IOCTL_VAL_PART, NULL); if (error_code != MFS_NO_ERROR) { printf("Error while validating partition: %s\n", MFS_Error_text((uint32_t)error_code)); printf("Not installing MFS.\n"); /*usb_filesystem_uninstall*/usb_filesystem_cancel_install(usb_fs_ptr,PARTITION_VALIDATE_FAIL); return NULL; } /* Install MFS over partition */ //printf("Install MFS over partition\n"); error_code = _io_mfs_install(usb_fs_ptr->PM_FD_PTR, file_system_name, 0); if (error_code != MFS_NO_ERROR) { printf("Error initializing MFS over partition: %s\n", MFS_Error_text((uint_32)error_code)); } } else { printf("Installing MFS over USB device...\n"); /* Install MFS over USB device driver */ //printf("Install MFS over USB device driver\n"); error_code = _io_mfs_install(usb_fs_ptr->DEV_FD_PTR, file_system_name, 0); if (error_code != MFS_NO_ERROR) { printf("Error initializing MFS: %s\n", MFS_Error_text((uint_32)error_code)); } } /* Open file system */ if (error_code == MFS_NO_ERROR) { usb_fs_ptr->FS_NAME = file_system_name; //printf("Open file system\n"); usb_fs_ptr->FS_FD_PTR = fopen(file_system_name, NULL); error_code = ferror(usb_fs_ptr->FS_FD_PTR); if (error_code == MFS_NOT_A_DOS_DISK) { printf("NOT A DOS DISK! You must format to continue.\n"); } else if (error_code != MFS_NO_ERROR) { printf("Error opening filesystem: %s\n", MFS_Error_text((uint_32)error_code)); /* usb_filesystem_uninstall*/usb_filesystem_cancel_install(usb_fs_ptr,MFS_OPEN_FAIL); return NULL; } printf("USB device installed to %s\n", file_system_name); } else { /*usb_filesystem_uninstall*/usb_filesystem_cancel_install(usb_fs_ptr,MFS_INIT_FAIL); return NULL; } return (pointer)usb_fs_ptr; }