From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with archive (Exim 4.43) id 1KECVq-0001Jw-9E for mharc-grub-devel@gnu.org; Wed, 02 Jul 2008 20:17:26 -0400 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1KECVo-0001Jr-HR for grub-devel@gnu.org; Wed, 02 Jul 2008 20:17:24 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1KECVn-0001Jb-1t for grub-devel@gnu.org; Wed, 02 Jul 2008 20:17:24 -0400 Received: from [199.232.76.173] (port=44695 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1KECVm-0001JY-T6 for grub-devel@gnu.org; Wed, 02 Jul 2008 20:17:22 -0400 Received: from c60.cesmail.net ([216.154.195.49]:29251) by monty-python.gnu.org with esmtps (TLS-1.0:RSA_ARCFOUR_SHA1:16) (Exim 4.60) (envelope-from ) id 1KECVh-0004nq-Md; Wed, 02 Jul 2008 20:17:17 -0400 Received: from unknown (HELO relay.cesmail.net) ([192.168.1.81]) by c60.cesmail.net with ESMTP; 02 Jul 2008 20:17:16 -0400 Received: from dv.roinet.com (static-72-92-88-10.phlapa.fios.verizon.net [72.92.88.10]) by relay.cesmail.net (Postfix) with ESMTP id CE74C4F1869; Wed, 2 Jul 2008 20:17:16 -0400 (EDT) From: Pavel Roskin To: grub-devel@gnu.org, Marco Gerards Date: Wed, 02 Jul 2008 20:17:16 -0400 Message-ID: <20080703001716.13881.1754.stgit@dv.roinet.com> User-Agent: StGIT/0.14.3.163.g06f9 MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit X-detected-kernel: by monty-python.gnu.org: Genre and OS details not recognized. Cc: Subject: [PATCH] Enable writing to ATA devices, fix several bugs 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: Thu, 03 Jul 2008 00:17:24 -0000 We have save_env now, so we can use the write capability. This also fixes the last compiler warning in GRUB. Sorry, Marco, please ignore the previous message, as it didn't get to the list. ChangeLog: * disk/ata.c (grub_ata_pio_write): Check status before writing, like we do in grub_ata_pio_read(). (grub_ata_readwrite): Always write individual sectors. Fix the sector count for the remainder. (grub_ata_write): Enable writing to ATA devices. Correctly report error for ATAPI devices. --- disk/ata.c | 19 +++++++++++-------- 1 files changed, 11 insertions(+), 8 deletions(-) diff --git a/disk/ata.c b/disk/ata.c index 02c4b06..c9b0498 100644 --- a/disk/ata.c +++ b/disk/ata.c @@ -187,6 +187,9 @@ grub_ata_pio_write (struct grub_ata_device *dev, char *buf, grub_uint16_t *buf16 = (grub_uint16_t *) buf; unsigned int i; + if (grub_ata_regget (dev, GRUB_ATA_REG_STATUS) & 1) + return grub_ata_regget (dev, GRUB_ATA_REG_ERROR); + /* Wait until the device is ready to write. */ grub_ata_wait_drq (dev); @@ -562,10 +565,9 @@ grub_ata_readwrite (grub_disk_t disk, grub_disk_addr_t sector, /* Write sectors. */ grub_ata_regset (dev, GRUB_ATA_REG_CMD, cmd_write); grub_ata_wait (); - for (sect = 0; sect < batch; sect++) + for (sect = 0; sect < (size % batch); sect++) { - if (grub_ata_pio_write (dev, buf, - (size % batch) * GRUB_DISK_SECTOR_SIZE)) + if (grub_ata_pio_write (dev, buf, GRUB_DISK_SECTOR_SIZE)) return grub_error (GRUB_ERR_WRITE_ERROR, "ATA write error"); buf += GRUB_DISK_SECTOR_SIZE; } @@ -705,11 +707,12 @@ grub_ata_write (grub_disk_t disk, grub_size_t size, const char *buf) { -#if 1 - return GRUB_ERR_NOT_IMPLEMENTED_YET; -#else - return grub_ata_readwrite (disk, sector, size, (char *) buf, 1); -#endif + struct grub_ata_device *dev = (struct grub_ata_device *) disk->data; + + if (! dev->atapi) + return grub_ata_readwrite (disk, sector, size, (char *) buf, 1); + + return grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET, "ATAPI write not supported"); } static struct grub_disk_dev grub_atadisk_dev =