summaryrefslogtreecommitdiff
path: root/firmware/usbstack/usb_storage.c
diff options
context:
space:
mode:
Diffstat (limited to 'firmware/usbstack/usb_storage.c')
-rw-r--r--firmware/usbstack/usb_storage.c45
1 files changed, 22 insertions, 23 deletions
diff --git a/firmware/usbstack/usb_storage.c b/firmware/usbstack/usb_storage.c
index 28510089f1..d29e731d5a 100644
--- a/firmware/usbstack/usb_storage.c
+++ b/firmware/usbstack/usb_storage.c
@@ -153,8 +153,7 @@ struct inquiry_data {
153struct report_lun_data { 153struct report_lun_data {
154 unsigned int lun_list_length; 154 unsigned int lun_list_length;
155 unsigned int reserved1; 155 unsigned int reserved1;
156 // TODO this should be cleaned up with the VOLUMES vs DRIVES mess 156 unsigned char luns[NUM_DRIVES][8];
157 unsigned char luns[NUM_VOLUMES][8];
158} __attribute__ ((packed)); 157} __attribute__ ((packed));
159 158
160struct sense_data { 159struct sense_data {
@@ -271,10 +270,10 @@ static void send_command_result(void *data,int size);
271static void send_command_failed_result(void); 270static void send_command_failed_result(void);
272static void send_block_data(void *data,int size); 271static void send_block_data(void *data,int size);
273static void receive_block_data(void *data,int size); 272static void receive_block_data(void *data,int size);
274static void fill_inquiry(IF_MV_NONVOID(int lun)); 273static void fill_inquiry(IF_MD_NONVOID(int lun));
275static void send_and_read_next(void); 274static void send_and_read_next(void);
276static bool ejected[NUM_VOLUMES]; 275static bool ejected[NUM_DRIVES];
277static bool locked[NUM_VOLUMES]; 276static bool locked[NUM_DRIVES];
278 277
279static int usb_interface; 278static int usb_interface;
280static int ep_in, ep_out; 279static int ep_in, ep_out;
@@ -309,7 +308,7 @@ static void fix_mbr(unsigned char* mbr)
309} 308}
310#endif 309#endif
311 310
312static bool check_disk_present(IF_MV_NONVOID(int volume)) 311static bool check_disk_present(IF_MD_NONVOID(int volume))
313{ 312{
314#ifdef USB_USE_RAMDISK 313#ifdef USB_USE_RAMDISK
315 return true; 314 return true;
@@ -325,7 +324,7 @@ void usb_storage_try_release_storage(void)
325 release excusive access */ 324 release excusive access */
326 bool canrelease=true; 325 bool canrelease=true;
327 int i; 326 int i;
328 for(i=0;i<NUM_VOLUMES;i++) { 327 for(i=0;i<storage_num_drives();i++) {
329 if(ejected[i]==false && locked[i]==true) { 328 if(ejected[i]==false && locked[i]==true) {
330 canrelease=false; 329 canrelease=false;
331 break; 330 break;
@@ -341,7 +340,7 @@ void usb_storage_try_release_storage(void)
341void usb_storage_notify_hotswap(int volume,bool inserted) 340void usb_storage_notify_hotswap(int volume,bool inserted)
342{ 341{
343 logf("notify %d",inserted); 342 logf("notify %d",inserted);
344 if(inserted && check_disk_present(IF_MV(volume))) { 343 if(inserted && check_disk_present(IF_MD(volume))) {
345 ejected[volume] = false; 344 ejected[volume] = false;
346 } 345 }
347 else { 346 else {
@@ -436,7 +435,7 @@ void usb_storage_init_connection(void)
436 usb_drv_recv(ep_out, cbw_buffer, 1024); 435 usb_drv_recv(ep_out, cbw_buffer, 1024);
437 436
438 int i; 437 int i;
439 for(i=0;i<NUM_VOLUMES;i++) { 438 for(i=0;i<storage_num_drives();i++) {
440#ifdef TOSHIBA_GIGABEAT_S 439#ifdef TOSHIBA_GIGABEAT_S
441 /* As long as the Gigabeat S is a non-removable device, we need 440 /* As long as the Gigabeat S is a non-removable device, we need
442 to mark the device as locked to avoid usb_storage_try_release_ata() 441 to mark the device as locked to avoid usb_storage_try_release_ata()
@@ -445,7 +444,7 @@ void usb_storage_init_connection(void)
445#else 444#else
446 locked[i] = false; 445 locked[i] = false;
447#endif 446#endif
448 ejected[i] = !check_disk_present(IF_MV(i)); 447 ejected[i] = !check_disk_present(IF_MD(i));
449 queue_broadcast(SYS_USB_LUN_LOCKED, (i<<16)+0); 448 queue_broadcast(SYS_USB_LUN_LOCKED, (i<<16)+0);
450 } 449 }
451} 450}
@@ -614,10 +613,9 @@ bool usb_storage_control_request(struct usb_ctrlrequest* req, unsigned char* des
614 (void)dest; 613 (void)dest;
615 switch (req->bRequest) { 614 switch (req->bRequest) {
616 case USB_BULK_GET_MAX_LUN: { 615 case USB_BULK_GET_MAX_LUN: {
617#ifdef ONLY_EXPOSE_CARD_SLOT 616 *tb.max_lun = storage_num_drives() - 1;
618 *tb.max_lun = 0; 617#ifdef HIDE_FIRST_DRIVE
619#else 618 *tb.max_lun --;
620 *tb.max_lun = NUM_VOLUMES - 1;
621#endif 619#endif
622 logf("ums: getmaxlun"); 620 logf("ums: getmaxlun");
623 usb_drv_send(EP_CONTROL, tb.max_lun, 1); 621 usb_drv_send(EP_CONTROL, tb.max_lun, 1);
@@ -690,12 +688,12 @@ static void handle_scsi(struct command_block_wrapper* cbw)
690 unsigned int block_size = 0; 688 unsigned int block_size = 0;
691 unsigned int block_count = 0; 689 unsigned int block_count = 0;
692 bool lun_present=true; 690 bool lun_present=true;
693#ifdef ONLY_EXPOSE_CARD_SLOT
694 unsigned char lun = cbw->lun+1;
695#else
696 unsigned char lun = cbw->lun; 691 unsigned char lun = cbw->lun;
697#endif
698 unsigned int block_size_mult = 1; 692 unsigned int block_size_mult = 1;
693#ifdef HIDE_FIRST_DRIVE
694 lun++;
695#endif
696
699 storage_get_info(lun,&info); 697 storage_get_info(lun,&info);
700#ifdef USB_USE_RAMDISK 698#ifdef USB_USE_RAMDISK
701 block_size = SECTOR_SIZE; 699 block_size = SECTOR_SIZE;
@@ -747,13 +745,14 @@ static void handle_scsi(struct command_block_wrapper* cbw)
747 logf("scsi report luns %d",lun); 745 logf("scsi report luns %d",lun);
748 int allocation_length=0; 746 int allocation_length=0;
749 int i; 747 int i;
748 unsigned int response_length = 8+8*storage_num_drives();
750 allocation_length|=(cbw->command_block[6]<<24); 749 allocation_length|=(cbw->command_block[6]<<24);
751 allocation_length|=(cbw->command_block[7]<<16); 750 allocation_length|=(cbw->command_block[7]<<16);
752 allocation_length|=(cbw->command_block[8]<<8); 751 allocation_length|=(cbw->command_block[8]<<8);
753 allocation_length|=(cbw->command_block[9]); 752 allocation_length|=(cbw->command_block[9]);
754 memset(tb.lun_data,0,sizeof(struct report_lun_data)); 753 memset(tb.lun_data,0,sizeof(struct report_lun_data));
755 tb.lun_data->lun_list_length=htobe32(8*NUM_VOLUMES); 754 tb.lun_data->lun_list_length=htobe32(8*storage_num_drives());
756 for(i=0;i<NUM_VOLUMES;i++) 755 for(i=0;i<storage_num_drives();i++)
757 { 756 {
758#ifdef HAVE_HOTSWAP 757#ifdef HAVE_HOTSWAP
759 if(storage_removable(i)) 758 if(storage_removable(i))
@@ -763,13 +762,13 @@ static void handle_scsi(struct command_block_wrapper* cbw)
763 tb.lun_data->luns[i][1]=0; 762 tb.lun_data->luns[i][1]=0;
764 } 763 }
765 send_command_result(tb.lun_data, 764 send_command_result(tb.lun_data,
766 MIN(sizeof(struct report_lun_data), length)); 765 MIN(response_length, length));
767 break; 766 break;
768 } 767 }
769 768
770 case SCSI_INQUIRY: 769 case SCSI_INQUIRY:
771 logf("scsi inquiry %d",lun); 770 logf("scsi inquiry %d",lun);
772 fill_inquiry(IF_MV(lun)); 771 fill_inquiry(IF_MD(lun));
773 length = MIN(length, cbw->command_block[4]); 772 length = MIN(length, cbw->command_block[4]);
774 send_command_result(tb.inquiry, 773 send_command_result(tb.inquiry,
775 MIN(sizeof(struct inquiry_data), length)); 774 MIN(sizeof(struct inquiry_data), length));
@@ -1136,7 +1135,7 @@ static void copy_padded(char *dest, char *src, int len)
1136} 1135}
1137 1136
1138/* build SCSI INQUIRY */ 1137/* build SCSI INQUIRY */
1139static void fill_inquiry(IF_MV_NONVOID(int lun)) 1138static void fill_inquiry(IF_MD_NONVOID(int lun))
1140{ 1139{
1141 struct storage_info info; 1140 struct storage_info info;
1142 memset(tb.inquiry, 0, sizeof(struct inquiry_data)); 1141 memset(tb.inquiry, 0, sizeof(struct inquiry_data));