+2009-01-19 Christian Franke <franke@computer.org>
+
+ * disk/scsi.c (grub_scsi_read10): Use scsi->blocksize instead
+ of 512 to calculate data size.
+ (grub_scsi_read12): Likewise.
+ (grub_scsi_write10): Likewise.
+ (grub_scsi_write12): Likewise.
+ (grub_scsi_read): Adjust size according to blocksize.
+ Add checks for invalid blocksize and unaligned transfer.
+
2009-01-19 Vesa Jääskeläinen <chaac@nic.fi>
* font/font.c (grub_font_loader_init): Re-position unknown glyph.
rd.reserved2 = 0;
rd.pad = 0;
- return scsi->dev->read (scsi, sizeof (rd), (char *) &rd, size * 512, buf);
+ return scsi->dev->read (scsi, sizeof (rd), (char *) &rd, size * scsi->blocksize, buf);
}
/* Send a SCSI request for DISK: read SIZE sectors starting with
rd.reserved = 0;
rd.control = 0;
- return scsi->dev->read (scsi, sizeof (rd), (char *) &rd, size * 512, buf);
+ return scsi->dev->read (scsi, sizeof (rd), (char *) &rd, size * scsi->blocksize, buf);
}
#if 0
wr.reserved2 = 0;
wr.pad = 0;
- return scsi->dev->write (scsi, sizeof (wr), (char *) &wr, size * 512, buf);
+ return scsi->dev->write (scsi, sizeof (wr), (char *) &wr, size * scsi->blocksize, buf);
}
/* Send a SCSI request for DISK: write the data stored in BUF to SIZE
wr.reserved = 0;
wr.pad = 0;
- return scsi->dev->write (scsi, sizeof (wr), (char *) &wr, size * 512, buf);
+ return scsi->dev->write (scsi, sizeof (wr), (char *) &wr, size * scsi->blocksize, buf);
}
#endif
/* SCSI sectors are variable in size. GRUB uses 512 byte
sectors. */
- sector = grub_divmod64 (sector, scsi->blocksize >> GRUB_DISK_SECTOR_BITS,
- NULL);
+ if (scsi->blocksize != GRUB_DISK_SECTOR_SIZE)
+ {
+ unsigned spb = scsi->blocksize >> GRUB_DISK_SECTOR_BITS;
+ if (! (spb != 0 && (scsi->blocksize & GRUB_DISK_SECTOR_SIZE) == 0))
+ return grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET,
+ "Unsupported SCSI block size");
+
+ grub_int32_t sector_mod = 0;
+ sector = grub_divmod64 (sector, spb, §or_mod);
+
+ if (! (sector_mod == 0 && size % spb == 0))
+ return grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET,
+ "Unaligned SCSI read not supported");
+
+ size /= spb;
+ }
/* Depending on the type, select a read function. */
switch (scsi->devtype)