From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with archive (Exim 4.43) id 1LOEDS-00058R-8A for mharc-grub-devel@gnu.org; Sat, 17 Jan 2009 11:40:10 -0500 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1LOEDQ-00058D-6f for grub-devel@gnu.org; Sat, 17 Jan 2009 11:40:08 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1LOEDO-00057y-KM for grub-devel@gnu.org; Sat, 17 Jan 2009 11:40:07 -0500 Received: from [199.232.76.173] (port=54839 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1LOEDO-00057v-H4 for grub-devel@gnu.org; Sat, 17 Jan 2009 11:40:06 -0500 Received: from mailout03.t-online.de ([194.25.134.81]:54977) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1LOEDO-0003kT-08 for grub-devel@gnu.org; Sat, 17 Jan 2009 11:40:06 -0500 Received: from fwd01.aul.t-online.de by mailout03.sul.t-online.de with smtp id 1LOEDM-00077w-03; Sat, 17 Jan 2009 17:40:04 +0100 Received: from [10.3.2.2] (TWAxZ4ZeQhUuJ6pzPfbLyOOoKPTFLzalRS-6OKyfVJmrzgN6rYgoH87aWa2ZV+8QCV@[217.235.240.7]) by fwd01.aul.t-online.de with esmtp id 1LOEDB-0i21YG0; Sat, 17 Jan 2009 17:39:53 +0100 Message-ID: <497209DA.30505@t-online.de> Date: Sat, 17 Jan 2009 17:39:54 +0100 From: Christian Franke User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.16) Gecko/20080702 SeaMonkey/1.1.11 MIME-Version: 1.0 To: grub-devel@gnu.org Content-Type: multipart/mixed; boundary="------------090300040004030805010900" X-ID: TWAxZ4ZeQhUuJ6pzPfbLyOOoKPTFLzalRS-6OKyfVJmrzgN6rYgoH87aWa2ZV+8QCV X-TOI-MSGID: 645452b8-c433-428a-930f-cf233c483b7f X-detected-operating-system: by monty-python.gnu.org: GNU/Linux 2.6 (newer, 3) Subject: [PATCH] (scsi.mod) Fix SCSI read for blocksize != 512 X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: The development of GRUB 2 List-Id: The development of GRUB 2 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 17 Jan 2009 16:40:08 -0000 This is a multi-part message in MIME format. --------------090300040004030805010900 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit 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 * 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. --------------090300040004030805010900 Content-Type: text/x-diff; name="grub2-scsi-blocksize-fix.patch" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="grub2-scsi-blocksize-fix.patch" 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) --------------090300040004030805010900--