Received: from mailman by lists.gnu.org with archive (Exim 4.43) id 1Ou7ad-0004Ko-E9 for mharc-grub-devel@gnu.org; Fri, 10 Sep 2010 13:40:43 -0400 Received: from [140.186.70.92] (port=44157 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Ou7aa-0004Da-1g for grub-devel@gnu.org; Fri, 10 Sep 2010 13:40:41 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1Ou7Th-0006Om-4u for grub-devel@gnu.org; Fri, 10 Sep 2010 13:33:34 -0400 Received: from smarthost01.mail.zen.net.uk ([212.23.3.140]:58648) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1Ou7Tg-0006OP-RO for grub-devel@gnu.org; Fri, 10 Sep 2010 13:33:33 -0400 Received: from [82.69.40.219] (helo=riva.pelham.vpn.ucam.org) by smarthost01.mail.zen.net.uk with esmtp (Exim 4.63) (envelope-from ) id 1Ou7Te-0000v1-PB for grub-devel@gnu.org; Fri, 10 Sep 2010 17:33:30 +0000 Received: from cjwatson by riva.pelham.vpn.ucam.org with local (Exim 3.36 #1 (Debian)) for grub-devel@gnu.org id 1Ou7Td-0006Es-00; Fri, 10 Sep 2010 18:33:29 +0100 Date: Fri, 10 Sep 2010 18:33:29 +0100 From: Colin Watson To: grub-devel@gnu.org Message-ID: <20100910173329.GX21862@riva.ucam.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.5.18 (2008-05-17) X-Originating-Smarthost01-IP: [82.69.40.219] X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 3) Subject: [PATCH] Handle partition devices without corresponding disk devices X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: The development of GNU GRUB List-Id: The development of GNU GRUB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 10 Sep 2010 17:40:41 -0000 On Xen (I'm told), it's possible to assign disk images in the host to things that are named rather like partitions in the guest (e.g. /dev/sda1), but that don't have an associated disk (e.g. /dev/sda); indeed, the latter device is nonexistent. This confuses grub_util_biosdisk_get_grub_dev. There's really no other situation in which I think it's terribly plausible that you might have /dev/sda1 but not /dev/sda, so it seems to me that in this case we can reasonably treat the apparent "partition" as a disk in its own right. 2010-09-10 Colin Watson * grub-core/kern/emu/hostdisk.c (find_system_device): Only try to convert partition names to disk names if the new `convert' parameter is set. (grub_util_biosdisk_get_grub_dev): If opening the disk device returns GRUB_ERR_UNKNOWN_DEVICE, treat the partition device as a disk in its own right. This can happen with Xen disk images. === modified file 'grub-core/kern/emu/hostdisk.c' --- grub-core/kern/emu/hostdisk.c 2010-07-12 19:13:28 +0000 +++ grub-core/kern/emu/hostdisk.c 2010-09-10 17:24:11 +0000 @@ -1334,12 +1334,15 @@ device_is_wholedisk (const char *os_dev) #endif /* defined(__NetBSD__) */ static int -find_system_device (const char *os_dev, struct stat *st) +find_system_device (const char *os_dev, struct stat *st, int convert) { unsigned int i; char *os_disk; - os_disk = convert_system_partition_to_system_disk (os_dev, st); + if (convert) + os_disk = convert_system_partition_to_system_disk (os_dev, st); + else + os_disk = xstrdup (os_dev); if (! os_disk) return -1; @@ -1373,7 +1376,7 @@ grub_util_biosdisk_get_grub_dev (const c return 0; } - drive = find_system_device (os_dev, &st); + drive = find_system_device (os_dev, &st, 1); if (drive < 0) { grub_error (GRUB_ERR_UNKNOWN_DEVICE, @@ -1456,7 +1459,32 @@ grub_util_biosdisk_get_grub_dev (const c free (name); if (! disk) - return 0; + { + /* We already know that the partition exists. Given that we already + checked the device map above, we can only get + GRUB_ERR_UNKNOWN_DEVICE at this point if the disk does not exist. + This can happen on Xen, where disk images in the host can be + assigned to devices that have partition-like names in the guest + but are really more like disks. */ + if (grub_errno == GRUB_ERR_UNKNOWN_DEVICE) + { + grub_util_info + ("disk does not exist, so falling back to partition device %s", + os_dev); + + drive = find_system_device (os_dev, &st, 0); + if (drive < 0) + { + grub_error (GRUB_ERR_UNKNOWN_DEVICE, + "no mapping exists for `%s'", os_dev); + return 0; + } + + return make_device_name (drive, -1, -1); + } + else + return 0; + } partname = NULL; grub_partition_iterate (disk, find_partition); -- Colin Watson [cjwatson@ubuntu.com]