From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with archive (Exim 4.43) id 1K3AmD-0000YB-B9 for mharc-grub-devel@gnu.org; Mon, 02 Jun 2008 10:12:45 -0400 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1K3AmB-0000W3-Bm for grub-devel@gnu.org; Mon, 02 Jun 2008 10:12:43 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1K3Am9-0000TI-In for grub-devel@gnu.org; Mon, 02 Jun 2008 10:12:41 -0400 Received: from [199.232.76.173] (port=33236 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1K3Am8-0000Sv-Rv for grub-devel@gnu.org; Mon, 02 Jun 2008 10:12:40 -0400 Received: from aybabtu.com ([69.60.117.155]:58252) by monty-python.gnu.org with esmtps (TLS-1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1K3Am8-0001aH-JY for grub-devel@gnu.org; Mon, 02 Jun 2008 10:12:40 -0400 Received: from [192.168.10.10] (helo=thorin) by aybabtu.com with esmtps (TLS-1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.63) (envelope-from ) id 1K3AlM-0004qe-GC for grub-devel@gnu.org; Mon, 02 Jun 2008 16:11:54 +0200 Received: from rmh by thorin with local (Exim 4.63) (envelope-from ) id 1K3Alr-0002EY-Sn for grub-devel@gnu.org; Mon, 02 Jun 2008 16:12:23 +0200 Date: Mon, 2 Jun 2008 16:12:23 +0200 From: Robert Millan To: grub-devel@gnu.org Message-ID: <20080602141223.GA8543@thorin> References: <20080602135014.GA4563@thorin> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20080602135014.GA4563@thorin> Organization: free as in freedom X-Message-Flag: Worried about Outlook viruses? Switch to Thunderbird! www.mozilla.com/thunderbird X-Debbugs-No-Ack: true User-Agent: Mutt/1.5.13 (2006-08-11) X-detected-kernel: by monty-python.gnu.org: Genre and OS details not recognized. Subject: Re: [PATCH] register dummy drive 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: Mon, 02 Jun 2008 14:12:43 -0000 Uhm.. however, you still need device-specific knowledge to find the full device containing your partition (needed for -t partmap). I'm not sure if there's a point to continue in this direction. Should we just exclude partmap from this? On Mon, Jun 02, 2008 at 03:50:14PM +0200, Robert Millan wrote: > > There's no reason grub-probe should fail if it can't resolve drive, when we > just asked for -t fs, -t fs_uuid or -t partmap. > > This patch solves the problem by spliting device/drive map[] entry registration > into a separate function, and using that from grub-probe.c to register a dummy > drive that will last during the current execution. > > It's diffed relative to my previous patch for device function names (but if > we need to change something in that one, not a problem for me to readapt it, > of course). > > -- > Robert Millan > > I know my rights; I want my phone call! > What good is a phone call… if you are unable to speak? > (as seen on /.) > 2008-06-02 Robert Millan > > * include/grub/util/biosdisk.h (grub_util_biosdisk_register): New > function declaration. > * util/biosdisk.c (open_device): Remove first grub_util_info() call > (too verbose). > (grub_util_biosdisk_register): New function. > (read_device_map): Use grub_util_biosdisk_register() for registration > of drive/device entries rather than doing it ourselves. > * util/grub-probe.c (probe): If we weren't asked to -t drive, allow > grub_util_get_grub_dev() to fail by registering a dummy drive entry, > so that other options like -t fs, -t fs_uuid or -t partmap will work > regardless. > > diff -x configure -x config.h.in -x CVS -x '*~' -x '*.mk' -urp ../tmp.old/include/grub/util/biosdisk.h ./include/grub/util/biosdisk.h > --- ../tmp.old/include/grub/util/biosdisk.h 2007-07-22 01:32:25.000000000 +0200 > +++ ./include/grub/util/biosdisk.h 2008-06-02 15:33:49.000000000 +0200 > @@ -23,5 +23,6 @@ > void grub_util_biosdisk_init (const char *dev_map); > void grub_util_biosdisk_fini (void); > char *grub_util_biosdisk_get_grub_dev (const char *os_dev); > +int grub_util_biosdisk_register (char *device, char *drive); > > #endif /* ! GRUB_BIOSDISK_MACHINE_UTIL_HEADER */ > diff -x configure -x config.h.in -x CVS -x '*~' -x '*.mk' -urp ../tmp.old/util/biosdisk.c ./util/biosdisk.c > --- ../tmp.old/util/biosdisk.c 2008-06-02 15:41:31.000000000 +0200 > +++ ./util/biosdisk.c 2008-06-02 15:38:13.000000000 +0200 > @@ -288,7 +288,6 @@ open_device (const grub_disk_t disk, gru > is_partition = linux_find_partition (dev, disk->partition->start); > > /* Open the partition. */ > - grub_util_info ("opening the device `%s'", dev); > fd = open (dev, flags); > if (fd < 0) > { > @@ -464,6 +463,20 @@ static struct grub_disk_dev grub_util_bi > .next = 0 > }; > > +/* Registers a device/drive map. */ > +int > +grub_util_biosdisk_register (char *device, char *drive) > +{ > + int index; > + /* Find a free slot. */ > + index = find_grub_drive (NULL); > + if (index < 0) > + return -1; > + map[index].device = device; > + map[index].drive = drive; > + return 0; > +} > + > static void > read_device_map (const char *dev_map) > { > @@ -486,7 +499,7 @@ read_device_map (const char *dev_map) > { > char *p = buf; > char *e; > - int drive; > + char *device, *drive; > > lineno++; > > @@ -502,19 +515,14 @@ read_device_map (const char *dev_map) > show_error ("No open parenthesis found"); > > p++; > - /* Find a free slot. */ > - drive = find_grub_drive (NULL); > - if (drive < 0) > - show_error ("Map table size exceeded"); > - > e = p; > p = strchr (p, ')'); > if (! p) > show_error ("No close parenthesis found"); > > - map[drive].drive = xmalloc (p - e + sizeof ('\0')); > - strncpy (map[drive].drive, e, p - e + sizeof ('\0')); > - map[drive].drive[p - e] = '\0'; > + drive = xmalloc (p - e + sizeof ('\0')); > + strncpy (drive, e, p - e + sizeof ('\0')); > + drive[p - e] = '\0'; > > p++; > /* Skip leading spaces. */ > @@ -540,12 +548,13 @@ read_device_map (const char *dev_map) > /* On Linux, the devfs uses symbolic links horribly, and that > confuses the interface very much, so use realpath to expand > symbolic links. */ > - map[drive].device = xmalloc (PATH_MAX); > - if (! realpath (p, map[drive].device)) > + device = xmalloc (PATH_MAX); > + if (! realpath (p, device)) > grub_util_error ("Cannot get the real path of `%s'", p); > #else > - map[drive].device = xstrdup (p); > + device = xstrdup (p); > #endif > + grub_util_biosdisk_register (device, drive); > } > > fclose (fp); > diff -x configure -x config.h.in -x CVS -x '*~' -x '*.mk' -urp ../tmp.old/util/grub-probe.c ./util/grub-probe.c > --- ../tmp.old/util/grub-probe.c 2008-05-30 13:07:10.000000000 +0200 > +++ ./util/grub-probe.c 2008-06-02 15:40:52.000000000 +0200 > @@ -153,15 +153,25 @@ probe (const char *path, char *device_na > } > > drive_name = grub_util_get_grub_dev (device_name); > - if (! drive_name) > - grub_util_error ("Cannot find a GRUB drive for %s. Check your device.map.\n", device_name); > > if (print == PRINT_DRIVE) > { > + if (! drive_name) > + grub_util_error ("Cannot find a GRUB drive for %s. Check your device.map.\n", device_name); > + > printf ("(%s)\n", drive_name); > goto end; > } > > + /* For the purpose of checks that follow, a dummy drive name will do. */ > + if (! drive_name) > + { > + drive_name = "dummy-grub-drive"; > + grub_util_info ("Cannot find GRUB drive for %s. Registering \"(%s)\t%s\".", > + device_name, drive_name, device_name); > + grub_util_biosdisk_register (xstrdup (device_name), xstrdup (drive_name)); > + } > + > grub_util_info ("opening %s", drive_name); > dev = grub_device_open (drive_name); > if (! dev) -- Robert Millan I know my rights; I want my phone call! What good is a phone call… if you are unable to speak? (as seen on /.)