From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from list by lists.gnu.org with archive (Exim 4.71) id 1aga3q-0006h3-Hz for mharc-grub-devel@gnu.org; Thu, 17 Mar 2016 11:42:06 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:60926) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aga3o-0006gX-27 for grub-devel@gnu.org; Thu, 17 Mar 2016 11:42:05 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aga3l-0004P7-6O for grub-devel@gnu.org; Thu, 17 Mar 2016 11:42:03 -0400 Received: from sender163-mail.zoho.com ([74.201.84.163]:25467) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aga3k-0004OF-TR for grub-devel@gnu.org; Thu, 17 Mar 2016 11:42:01 -0400 Received: from JTJLaptop (c-68-59-201-157.hsd1.tn.comcast.net [68.59.201.157]) by mx.zohomail.com with SMTPS id 1458229316838690.9040108731916; Thu, 17 Mar 2016 08:41:56 -0700 (PDT) From: "James Johnston" To: Subject: [PATCH] getroot: Correctly handle missing btrfs device identifiers. Date: Thu, 17 Mar 2016 15:41:46 -0000 Message-ID: <026301d18063$842a3010$8c7e9030$@codenest.com> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Mailer: Microsoft Outlook 14.0 Thread-Index: AdGAY4Mr3WJhJCI5SrqMd49FtLAmIQ== Content-Language: en-us X-Zoho-Virus-Status: 1 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 74.201.84.163 X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.14 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: Thu, 17 Mar 2016 15:42:05 -0000 >From 97bcb9eb8c34329a8ca1ec88fd89296e273ceb24 Mon Sep 17 00:00:00 2001 From: James Johnston Date: Thu, 17 Mar 2016 15:10:49 +0000 Subject: [PATCH] getroot: Correctly handle missing btrfs device identifiers. The btrfs driver's BTRFS_IOC_FS_INFO ioctl only tells you the maximum device ID and the number of devices. It does not tell you which device IDs may no longer be allocated - for example, if a device is later deleted from the file system, its device ID won't be allocated any more. You must then probe each device ID with BTRFS_IOC_DEV_INFO to see if it is a valid device or not. It is not an error condition for this ioctl to return ENODEV: it seems to mean that the device was deleted by the user. Signed-off-by: James Johnston --- grub-core/osdep/linux/getroot.c | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/grub-core/osdep/linux/getroot.c b/grub-core/osdep/linux/getroot.c index 10480b6..852f3a2 100644 --- a/grub-core/osdep/linux/getroot.c +++ b/grub-core/osdep/linux/getroot.c @@ -242,15 +242,29 @@ grub_find_root_devices_from_btrfs (const char *dir) struct btrfs_ioctl_dev_info_args devi; memset (&devi, 0, sizeof (devi)); devi.devid = i; + /* We have to probe all possible device IDs, since btrfs doesn't + give us a list of all the valid ones. */ if (ioctl (fd, BTRFS_IOC_DEV_INFO, &devi) < 0) { - close (fd); - free (ret); - return NULL; + /* ENODEV is normal, e.g. if the first device is deleted from + an array. */ + int last_error = errno; + if (last_error != ENODEV) + { + grub_util_warn(_("btrfs device info could not be read " + "for %s, device %d: errno %d"), dir, i, + last_error); + close (fd); + free (ret); + return NULL; + } + } + else + { + ret[j++] = xstrdup ((char *) devi.path); + if (j >= fsi.num_devices) + break; } - ret[j++] = xstrdup ((char *) devi.path); - if (j >= fsi.num_devices) - break; } close (fd); ret[j] = 0; -- 1.9.5.msysgit.1