From: Christian Franke <Christian.Franke@t-online.de>
To: grub-devel@gnu.org
Subject: [PATCH] (scsi.mod) Fix SCSI read for blocksize != 512
Date: Sat, 17 Jan 2009 17:39:54 +0100 [thread overview]
Message-ID: <497209DA.30505@t-online.de> (raw)
[-- Attachment #1: Type: text/plain, Size: 539 bytes --]
This patch fixes SCSI blocksize handling, necessary for ATAPI CD/DVD.
OT: There might be a memory leak in scsi_open(): free(scsi) is missing,
at least on open error.
Christian
2009-01-17 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.
[-- Attachment #2: grub2-scsi-blocksize-fix.patch --]
[-- Type: text/x-diff, Size: 2329 bytes --]
diff --git a/disk/scsi.c b/disk/scsi.c
index b7b6834..d165309 100644
--- a/disk/scsi.c
+++ b/disk/scsi.c
@@ -119,7 +119,7 @@ grub_scsi_read10 (grub_disk_t disk, grub_disk_addr_t sector,
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
@@ -140,7 +140,7 @@ grub_scsi_read12 (grub_disk_t disk, grub_disk_addr_t sector,
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
@@ -163,7 +163,7 @@ grub_scsi_write10 (grub_disk_t disk, grub_disk_addr_t sector,
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
@@ -184,7 +184,7 @@ grub_scsi_write12 (grub_disk_t disk, grub_disk_addr_t sector,
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
@@ -325,8 +325,22 @@ grub_scsi_read (grub_disk_t disk, grub_disk_addr_t sector,
/* 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)
next reply other threads:[~2009-01-17 16:40 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-01-17 16:39 Christian Franke [this message]
2009-01-19 20:42 ` [PATCH] (scsi.mod) Fix SCSI read for blocksize != 512 Christian Franke
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=497209DA.30505@t-online.de \
--to=christian.franke@t-online.de \
--cc=grub-devel@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.