return 0;
}
-// Validate drive and find block size and sector count.
+// Validate drive, find block size / sector count, and register drive.
int
-scsi_init_drive(struct drive_s *drive, const char *s, int *pdt, char **desc)
+scsi_init_drive(struct drive_s *drive, const char *s, int prio)
{
if (!CONFIG_USB_MSC)
return 0;
nullTrailingSpace(product);
strtcpy(rev, data.rev, sizeof(rev));
nullTrailingSpace(rev);
- *pdt = data.pdt & 0x1f;
+ int pdt = data.pdt & 0x1f;
int removable = !!(data.removable & 0x80);
dprintf(1, "%s vendor='%s' product='%s' rev='%s' type=%d removable=%d\n"
- , s, vendor, product, rev, *pdt, removable);
+ , s, vendor, product, rev, pdt, removable);
drive->removable = removable;
- if (*pdt == SCSI_TYPE_CDROM) {
+ if (pdt == SCSI_TYPE_CDROM) {
drive->blksize = CDROM_SECTOR_SIZE;
drive->sectors = (u64)-1;
- *desc = znprintf(MAXDESCSIZE, "DVD/CD [%s Drive %s %s %s]"
+ char *desc = znprintf(MAXDESCSIZE, "DVD/CD [%s Drive %s %s %s]"
, s, vendor, product, rev);
+ boot_add_cd(drive, desc, prio);
return 0;
}
// We do not bother with READ CAPACITY(16) because BIOS does not support
// 64-bit LBA anyway.
drive->blksize = ntohl(capdata.blksize);
+ if (drive->blksize != DISK_SECTOR_SIZE) {
+ dprintf(1, "%s: unsupported block size %d\n", s, drive->blksize);
+ return -1;
+ }
drive->sectors = (u64)ntohl(capdata.sectors) + 1;
dprintf(1, "%s blksize=%d sectors=%d\n"
, s, drive->blksize, (unsigned)drive->sectors);
((u32)drive->sectors % (geomdata.heads * cylinders) == 0)) {
drive->pchs.cylinders = cylinders;
drive->pchs.heads = geomdata.heads;
- drive->pchs.spt = (u32)drive->sectors
- / (geomdata.heads * cylinders);
+ drive->pchs.spt = (u32)drive->sectors / (geomdata.heads * cylinders);
}
}
- *desc = znprintf(MAXDESCSIZE, "%s Drive %s %s %s"
- , s, vendor, product, rev);
+ char *desc = znprintf(MAXDESCSIZE, "%s Drive %s %s %s"
+ , s, vendor, product, rev);
+ boot_add_hd(drive, desc, prio);
return 0;
}
* Setup
****************************************************************/
-static int
-setup_drive_cdrom(struct drive_s *drive, char *desc)
-{
- drive->sectors = (u64)-1;
- struct usb_pipe *pipe = container_of(
- drive, struct usbdrive_s, drive)->bulkout;
- int prio = bootprio_find_usb(pipe->cntl->pci, pipe->path);
- boot_add_cd(drive, desc, prio);
- return 0;
-}
-
-static int
-setup_drive_hd(struct drive_s *drive, char *desc)
-{
- if (drive->blksize != DISK_SECTOR_SIZE) {
- dprintf(1, "Unsupported USB MSC block size %d\n", drive->blksize);
- return -1;
- }
-
- // Register with bcv system.
- struct usb_pipe *pipe = container_of(
- drive, struct usbdrive_s, drive)->bulkout;
- int prio = bootprio_find_usb(pipe->cntl->pci, pipe->path);
- boot_add_hd(drive, desc, prio);
- return 0;
-}
-
// Configure a usb msc device.
int
usb_msc_init(struct usb_pipe *pipe
if (!udrive_g->bulkin || !udrive_g->bulkout)
goto fail;
- int ret, pdt;
- char *desc = NULL;
- ret = scsi_init_drive(&udrive_g->drive, "USB MSC", &pdt, &desc);
- if (ret)
- goto fail;
-
- if (pdt == SCSI_TYPE_CDROM)
- ret = setup_drive_cdrom(&udrive_g->drive, desc);
- else
- ret = setup_drive_hd(&udrive_g->drive, desc);
-
+ int prio = bootprio_find_usb(pipe->cntl->pci, pipe->path);
+ int ret = scsi_init_drive(&udrive_g->drive, "USB MSC", prio);
if (ret)
goto fail;