From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with archive (Exim 4.43) id 1M0DCN-0005Em-DK for mharc-grub-devel@gnu.org; Sat, 02 May 2009 07:16:03 -0400 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1M0DCK-0005Ed-Pn for grub-devel@gnu.org; Sat, 02 May 2009 07:16:00 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1M0DCE-0005Cz-TX for grub-devel@gnu.org; Sat, 02 May 2009 07:15:59 -0400 Received: from [199.232.76.173] (port=45708 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1M0DCC-0005Cl-OF for grub-devel@gnu.org; Sat, 02 May 2009 07:15:53 -0400 Received: from aybabtu.com ([69.60.117.155]:50000) by monty-python.gnu.org with esmtps (TLS-1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1M0DCC-00041s-7J for grub-devel@gnu.org; Sat, 02 May 2009 07:15:52 -0400 Received: from [192.168.10.10] (helo=thorin) by aybabtu.com with esmtp (Exim 4.69) (envelope-from ) id 1M0Cyu-0001TK-Ok for grub-devel@gnu.org; Sat, 02 May 2009 13:02:09 +0200 Received: from rmh by thorin with local (Exim 4.69) (envelope-from ) id 1M0DC7-0007LB-JJ for grub-devel@gnu.org; Sat, 02 May 2009 13:15:47 +0200 Date: Sat, 2 May 2009 13:15:47 +0200 From: Robert Millan To: grub-devel@gnu.org Message-ID: <20090502111547.GA28211@thorin> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="YZ5djTAD1cGYuMQK" Content-Disposition: inline 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.18 (2008-05-17) X-detected-operating-system: by monty-python.gnu.org: Genre and OS details not recognized. Subject: [PATCH] improve error messages in grub-setup 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, 02 May 2009 11:16:01 -0000 --YZ5djTAD1cGYuMQK Content-Type: text/plain; charset=us-ascii Content-Disposition: inline This patch improves error messages in grub-setup, and adds a few warnings when requested to install in odd layouts. Since there was no facility to emmit a warning that is always visible (regardless of verbosity), but doesn't abort execution, I added one (grub_util_warn ()). Is everyone fine with using this interface? -- Robert Millan The DRM opt-in fallacy: "Your data belongs to us. We will decide when (and how) you may access your data; but nobody's threatening your freedom: we still allow you to remove your data and not access it at all." --YZ5djTAD1cGYuMQK Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="embedding_warnings.diff" 2009-05-02 Robert Millan * util/misc.c (grub_util_warn): New function. Emmits a warning unconditionally. * include/grub/util/misc.h (grub_util_warn): New declaration. * util/i386/pc/grub-setup.c (setup): Improve error messages and add warnings when requested to install in odd layouts. Index: include/grub/util/misc.h =================================================================== --- include/grub/util/misc.h (revision 2154) +++ include/grub/util/misc.h (working copy) @@ -40,6 +40,7 @@ extern char *progname; extern int verbosity; extern jmp_buf main_env; +void grub_util_warn (const char *fmt, ...); void grub_util_info (const char *fmt, ...); void grub_util_error (const char *fmt, ...) __attribute__ ((noreturn)); Index: util/i386/pc/grub-setup.c =================================================================== --- util/i386/pc/grub-setup.c (revision 2154) +++ util/i386/pc/grub-setup.c (working copy) @@ -109,7 +109,7 @@ setup (const char *dir, FILE *fp; struct { grub_uint64_t start; grub_uint64_t end; } embed_region; embed_region.start = embed_region.end = ~0UL; - int able_to_embed = 1; + int embedding_area_exists = 0, able_to_embed = 0; auto void NESTED_FUNC_ATTR save_first_sector (grub_disk_addr_t sector, unsigned offset, unsigned length); @@ -304,6 +304,12 @@ setup (const char *dir, grub_util_info ("dos partition is %d, bsd partition is %d", dos_part, bsd_part); + + if (! dest_dev->disk->has_partitions) + grub_util_warn ("Attempting to install GRUB to a partitionless disk. This is a BAD idea."); + + if (dest_dev->disk->partition) + grub_util_warn ("Attempting to install GRUB to a partition instead of the MBR. This is a BAD idea."); /* If the destination device can have partitions and it is the MBR, try to embed the core image into after the MBR. */ @@ -311,11 +317,16 @@ setup (const char *dir, { grub_partition_iterate (dest_dev->disk, find_usable_region); + if (embed_region.end != 0) + embedding_area_exists = 1; + /* If there is enough space... */ if ((unsigned long) core_sectors <= embed_region.end - embed_region.start) { grub_util_info ("will embed the core image at sector 0x%llx", embed_region.start); + able_to_embed = 1; + *install_dos_part = grub_cpu_to_le32 (dos_part); *install_bsd_part = grub_cpu_to_le32 (bsd_part); @@ -349,16 +360,20 @@ setup (const char *dir, goto finish; } + } + + if (! able_to_embed) + { + if (embedding_area_exists) + grub_util_warn ("Embedding area is too small for core.img."); else - able_to_embed = 0; + grub_util_warn ("Embedding area not present at all!"); + + if (must_embed) + grub_util_error ("Embedding is not possible, but this is required when " + "the root device is on a RAID array or LVM volume."); } - else - able_to_embed = 0; - if (must_embed && ! able_to_embed) - grub_util_error ("Core image is too big for embedding, but this is required when\n" - "the root device is on a RAID array or LVM volume."); - /* The core image must be put on a filesystem unfortunately. */ grub_util_info ("will leave the core image on the filesystem"); Index: util/misc.c =================================================================== --- util/misc.c (revision 2154) +++ util/misc.c (working copy) @@ -52,6 +52,19 @@ char *progname = 0; int verbosity = 0; void +grub_util_warn (const char *fmt, ...) +{ + va_list ap; + + fprintf (stderr, "%s: warn: ", progname); + va_start (ap, fmt); + vfprintf (stderr, fmt, ap); + va_end (ap); + fputc ('\n', stderr); + fflush (stderr); +} + +void grub_util_info (const char *fmt, ...) { if (verbosity > 0) --YZ5djTAD1cGYuMQK--