All of lore.kernel.org
 help / color / mirror / Atom feed
From: Robert Millan <rmh@aybabtu.com>
To: The development of GRUB 2 <grub-devel@gnu.org>
Subject: Re: [PATCH] Refuse to install on XFS destroying its superblock
Date: Sat, 17 Oct 2009 13:25:45 +0200	[thread overview]
Message-ID: <20091017112545.GA3556@thorin> (raw)
In-Reply-To: <4AD8F11D.1030007@gmail.com>

[-- Attachment #1: Type: text/plain, Size: 908 bytes --]

On Sat, Oct 17, 2009 at 12:18:05AM +0200, Vladimir 'phcoder' Serbinenko wrote:
>  2009-10-16  Vladimir Serbinenko  <phcoder@gmail.com>
>  
> +	* util/i386/pc/grub-setup.c (setup): Refuse to overwrite XFS superblock.
> +	(options): New option --destroy-xfs.
> +	(main): Handle --destroy-xfs.

I gave this some more thought, and I think this could be less ad-hoc.  We're
treating XFS as if it were a "weird", unique thing just because it isn't biased
towards DOS-style boot like most filesystems are.

Instead, I've done something more generic, using our standard filesystem
probing engine which should be more reliable than a single memcmp.

I propose the attached patch.

-- 
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."

[-- Attachment #2: fs_check.diff --]
[-- Type: text/x-diff, Size: 4265 bytes --]

=== modified file 'ChangeLog'
--- ChangeLog	2009-10-16 20:21:12 +0000
+++ ChangeLog	2009-10-17 11:19:35 +0000
@@ -1,3 +1,13 @@
+2009-10-17  Robert Millan  <rmh.grub@aybabtu.com>
+
+	* include/grub/fs.h (struct grub_fs): Add `begins_at_first_sector'
+	member.
+	* fs/xfs.c (grub_xfs_fs): Initialize `begins_at_first_sector' to 1.
+	* util/i386/pc/grub-setup.c (setup): Add safety check that probes for
+	filesystems which begin at first sector.
+	(options): New option --skip-fs-probe.
+	(main): Handle --skip-fs-probe and pass it to setup().
+
 2009-10-16  Vladimir Serbinenko  <phcoder@gmail.com>
 
 	Let user specify OpenBSD root device.

=== modified file 'fs/xfs.c'
--- fs/xfs.c	2009-08-26 14:17:34 +0000
+++ fs/xfs.c	2009-10-17 11:19:35 +0000
@@ -805,6 +805,9 @@
     .close = grub_xfs_close,
     .label = grub_xfs_label,
     .uuid = grub_xfs_uuid,
+#ifdef GRUB_UTIL
+    .begins_at_first_sector = 1,
+#endif
     .next = 0
   };
 

=== modified file 'include/grub/fs.h'
--- include/grub/fs.h	2009-06-10 21:04:23 +0000
+++ include/grub/fs.h	2009-10-17 11:19:35 +0000
@@ -68,6 +68,12 @@
   /* Get writing time of filesystem. */
   grub_err_t (*mtime) (grub_device_t device, grub_int32_t *timebuf);
 
+#ifdef GRUB_UTIL
+  /* Whether this filesystem begins at first sector or reserves it for
+     DOS-style boot.  */
+  int begins_at_first_sector;
+#endif
+
   /* The next filesystem.  */
   struct grub_fs *next;
 };

=== modified file 'util/i386/pc/grub-setup.c'
--- util/i386/pc/grub-setup.c	2009-08-25 08:28:13 +0000
+++ util/i386/pc/grub-setup.c	2009-10-17 11:19:35 +0000
@@ -86,7 +86,7 @@
 static void
 setup (const char *dir,
        const char *boot_file, const char *core_file,
-       const char *root, const char *dest, int must_embed, int force)
+       const char *root, const char *dest, int must_embed, int force, int fs_probe)
 {
   char *boot_path, *core_path, *core_path_dev;
   char *boot_img, *core_img;
@@ -251,6 +251,16 @@
   if (grub_disk_read (dest_dev->disk, 0, 0, GRUB_DISK_SECTOR_SIZE, tmp_img))
     grub_util_error ("%s", grub_errmsg);
 
+  if (fs_probe)
+    {
+      grub_fs_t fs;
+      fs = grub_fs_probe (dest_dev);
+      if (fs && fs->begins_at_first_sector)
+	grub_util_error ("%s appears to contain a %s filesystem, which would be "
+			 "overwritten by grub-setup (--skip-fs-probe disables this "
+			 "check, use at your own risk).", dest_dev->disk->name, fs->name);
+    }
+
   /* Copy the possible DOS BPB.  */
   memcpy (boot_img + GRUB_BOOT_MACHINE_BPB_START,
 	  tmp_img + GRUB_BOOT_MACHINE_BPB_START,
@@ -556,6 +566,7 @@
     {"device-map", required_argument, 0, 'm'},
     {"root-device", required_argument, 0, 'r'},
     {"force", no_argument, 0, 'f'},
+    {"skip-fs-probe", no_argument, 0, 's'},
     {"help", no_argument, 0, 'h'},
     {"version", no_argument, 0, 'V'},
     {"verbose", no_argument, 0, 'v'},
@@ -580,6 +591,7 @@
   -m, --device-map=FILE   use FILE as the device map [default=%s]\n\
   -r, --root-device=DEV   use DEV as the root device [default=guessed]\n\
   -f, --force             install even if problems are detected\n\
+  -s, --skip-fs-probe     do not probe for filesystems in DEVICE\n\
   -h, --help              display this message and exit\n\
   -V, --version           print version information and exit\n\
   -v, --verbose           print verbose messages\n\
@@ -613,7 +625,7 @@
   char *dev_map = 0;
   char *root_dev = 0;
   char *dest_dev;
-  int must_embed = 0, force = 0;
+  int must_embed = 0, force = 0, fs_probe = 1;
 
   progname = "grub-setup";
 
@@ -666,6 +678,10 @@
 	    force = 1;
 	    break;
 
+	  case 's':
+	    fs_probe = 0;
+	    break;
+
 	  case 'h':
 	    usage (0);
 	    break;
@@ -767,7 +783,7 @@
 	  setup (dir ? : DEFAULT_DIRECTORY,
 		 boot_file ? : DEFAULT_BOOT_FILE,
 		 core_file ? : DEFAULT_CORE_FILE,
-		 root_dev, grub_util_get_grub_dev (devicelist[i]), 1, force);
+		 root_dev, grub_util_get_grub_dev (devicelist[i]), 1, force, fs_probe);
 	}
     }
   else
@@ -776,7 +792,7 @@
     setup (dir ? : DEFAULT_DIRECTORY,
 	   boot_file ? : DEFAULT_BOOT_FILE,
 	   core_file ? : DEFAULT_CORE_FILE,
-	   root_dev, dest_dev, must_embed, force);
+	   root_dev, dest_dev, must_embed, force, fs_probe);
 
   /* Free resources.  */
   grub_fini_all ();


  reply	other threads:[~2009-10-17 11:25 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-10-16 10:56 [PATCH] Refuse to install on XFS destroying its superblock Vladimir 'phcoder' Serbinenko
2009-10-16 14:03 ` Vladimir 'phcoder' Serbinenko
2009-10-16 16:01   ` Jordi Mallach
2009-10-16 18:38     ` Robert Millan
2009-10-16 20:09       ` Vladimir 'phcoder' Serbinenko
2009-10-16 20:52         ` Robert Millan
2009-10-16 21:08           ` Vladimir 'phcoder' Serbinenko
2009-10-16 21:53             ` Robert Millan
2009-10-16 22:18               ` Vladimir 'phcoder' Serbinenko
2009-10-17 11:25                 ` Robert Millan [this message]
2009-10-17 11:43                   ` Vladimir 'phcoder' Serbinenko
2009-10-17 12:00                     ` Robert Millan
2009-10-17 12:06                       ` Felix Zielcke
2009-10-17 12:09                       ` Vladimir 'phcoder' Serbinenko
2009-10-17 16:12                         ` richardvoigt
2009-10-18 16:44                           ` Vladimir 'phcoder' Serbinenko
2009-10-18 15:46                         ` Robert Millan
2009-10-18 16:30                           ` Vladimir 'phcoder' Serbinenko
2009-10-20 10:18                             ` Robert Millan
2009-10-20 10:51                               ` Vladimir 'phcoder' Serbinenko
2009-10-25  0:01                                 ` Robert Millan

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20091017112545.GA3556@thorin \
    --to=rmh@aybabtu.com \
    --cc=grub-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.