On Wed, Jul 22, 2009 at 7:22 PM, Robert Millan<r...@aybabtu.com> wrote:
> On Sat, Jul 18, 2009 at 11:28:58PM +0200, Vladimir 'phcoder' Serbinenko wrote:
>> > I don't understand what you mean here.
>> Let's take a common example of cdrom. Most of the users and developers
>> are accustomed to a cdrom holding one filesystem. On macs however cds
>> are partitioned and not being able to access all the partitions is a
>> problem for end user. Such situations are probably common. If we ditch
>> has_partitions altogether the only negative side effect will be that
>> in some weird configurations unpartitioned media may appear to have
>> partitions but whole media is still accessible. Additionally it
>> simplifies and makes kernel smaller

See nopart.diff. Once Pavel's patch for partitions is committed they
can integrate nicely in util/i386/pc/grub-setup.c

>> He said: checking that bootable flags of all
>> partitions are either set (0x80) or unset (0x0) and not another value
>
> Oh, that's different.  I think it's fine provided that:
>
>  - None of the commonly used free partitioning tools uses an illegal value.
>
>  - We fail gracefully and let the user know why.

See mbr.diff

>
> --
> 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."
>
>
> _______________________________________________
> Grub-devel mailing list
> Grub-devel@gnu.org
> http://lists.gnu.org/mailman/listinfo/grub-devel
>



-- 
Regards
Vladimir 'phcoder' Serbinenko

Personal git repository: http://repo.or.cz/w/grub2/phcoder.git
diff --git a/ChangeLog b/ChangeLog
index 752bde8..0d42f3c 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2009-07-26  Vladimir Serbinenko  <phco...@gmail.com>
+
+       * partmap/pc.c (pc_partition_map_iterate): Check that boot flags are
+       valid.
+
 2009-07-25  Felix Zielcke  <fziel...@z-51.de>
 
        * kern/file.c (grub_file_open): Revert to previous check with
diff --git a/partmap/pc.c b/partmap/pc.c
index 6f68ecf..e3ea53a 100644
--- a/partmap/pc.c
+++ b/partmap/pc.c
@@ -121,6 +121,13 @@ pc_partition_map_iterate (grub_disk_t disk,
       if (mbr.signature != grub_cpu_to_le16 (GRUB_PC_PARTITION_SIGNATURE))
        return grub_error (GRUB_ERR_BAD_PART_TABLE, "no signature");
 
+      for (i = 0; i < 4; i++)
+       if (mbr.entries[i].flag & 0x7f)
+         break;
+
+      if (i != 4)
+       return grub_error (GRUB_ERR_BAD_PART_TABLE, "bad boot flag");
+
       /* Analyze DOS partitions.  */
       for (p.index = 0; p.index < 4; p.index++)
        {
diff --git a/ChangeLog b/ChangeLog
index 752bde8..bda13e9 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,14 @@
+2009-07-26  Vladimir Serbinenko  <phco...@gmail.com>
+
+       * include/grub/disk.h (grub_disk): Remove has_partitions.
+       All users updated.
+       * disk/loopback.c (grub_loopback): Remove has_partitions.
+       All users updated.
+       * util/grub-fstest.c (fstest): Don't pass "-p" to loopback.
+       (options): Remove partitions. All users updated.
+       * util/i386/pc/grub-setup.c (setup): copy parition table only when
+       actual partition table is found.
+
 2009-07-25  Felix Zielcke  <fziel...@z-51.de>
 
        * kern/file.c (grub_file_open): Revert to previous check with
diff --git a/disk/ata.c b/disk/ata.c
index 78d3965..73b07be 100644
--- a/disk/ata.c
+++ b/disk/ata.c
@@ -683,7 +683,6 @@ grub_ata_open (const char *name, grub_disk_t disk)
 
   disk->id = (unsigned long) dev;
 
-  disk->has_partitions = 1;
   disk->data = dev;
 
   return 0;
diff --git a/disk/efi/efidisk.c b/disk/efi/efidisk.c
index de84859..fd1fae4 100644
--- a/disk/efi/efidisk.c
+++ b/disk/efi/efidisk.c
@@ -514,16 +514,12 @@ grub_efidisk_open (const char *name, struct grub_disk 
*disk)
   switch (name[0])
     {
     case 'f':
-      disk->has_partitions = 0;
       d = get_device (fd_devices, num);
       break;
     case 'c':
-      /* FIXME: a CDROM should have partitions, but not implemented yet.  */
-      disk->has_partitions = 0;
       d = get_device (cd_devices, num);
       break;
     case 'h':
-      disk->has_partitions = 1;
       d = get_device (hd_devices, num);
       break;
     default:
diff --git a/disk/fs_file.c b/disk/fs_file.c
index e095682..19dabef 100644
--- a/disk/fs_file.c
+++ b/disk/fs_file.c
@@ -76,7 +76,6 @@ grub_fs_file_open (const char *name, grub_disk_t disk)
     return grub_error (GRUB_ERR_UNKNOWN_DEVICE, "no matching file found");
 
   disk->total_sectors = dev->disk->total_sectors;
-  disk->has_partitions = 0;
   if (dev->disk->partition)
     {
       disk->partition = grub_malloc (sizeof (*disk->partition));
diff --git a/disk/fs_uuid.c b/disk/fs_uuid.c
index 6901dba..aabebdf 100644
--- a/disk/fs_uuid.c
+++ b/disk/fs_uuid.c
@@ -88,7 +88,6 @@ grub_fs_uuid_open (const char *name, grub_disk_t disk)
     return grub_error (GRUB_ERR_UNKNOWN_DEVICE, "no matching UUID found");
 
   disk->total_sectors = dev->disk->total_sectors;
-  disk->has_partitions = 0;
   if (dev->disk->partition)
     {
       disk->partition = grub_malloc (sizeof (*disk->partition));
diff --git a/disk/host.c b/disk/host.c
index c4f3e71..c519662 100644
--- a/disk/host.c
+++ b/disk/host.c
@@ -43,7 +43,6 @@ grub_host_open (const char *name, grub_disk_t disk)
   disk->total_sectors = 0;
   disk->id = (unsigned long) "host";
 
-  disk->has_partitions = 0;
   disk->data = 0;
 
   return GRUB_ERR_NONE;
diff --git a/disk/i386/pc/biosdisk.c b/disk/i386/pc/biosdisk.c
index 0a6137f..115e2c1 100644
--- a/disk/i386/pc/biosdisk.c
+++ b/disk/i386/pc/biosdisk.c
@@ -106,7 +106,6 @@ grub_biosdisk_open (const char *name, grub_disk_t disk)
   if (drive < 0)
     return grub_errno;
 
-  disk->has_partitions = ((drive & 0x80) && (drive != cd_drive));
   disk->id = drive;
 
   data = (struct grub_biosdisk_data *) grub_zalloc (sizeof (*data));
diff --git a/disk/ieee1275/nand.c b/disk/ieee1275/nand.c
index 37427f8..9d96d51 100644
--- a/disk/ieee1275/nand.c
+++ b/disk/ieee1275/nand.c
@@ -113,7 +113,6 @@ grub_nand_open (const char *name, grub_disk_t disk)
 
   disk->id = dev_ihandle;
 
-  disk->has_partitions = 0;
   disk->data = data;
 
   return 0;
diff --git a/disk/ieee1275/ofdisk.c b/disk/ieee1275/ofdisk.c
index ca257d6..e749259 100644
--- a/disk/ieee1275/ofdisk.c
+++ b/disk/ieee1275/ofdisk.c
@@ -208,8 +208,6 @@ grub_ofdisk_open (const char *name, grub_disk_t disk)
 
   disk->id = (unsigned long) op;
 
-  /* XXX: Read this, somehow.  */
-  disk->has_partitions = 1;
   disk->data = (void *) (unsigned long) dev_ihandle;
   return 0;
 
diff --git a/disk/loopback.c b/disk/loopback.c
index 2980518..d98dbb2 100644
--- a/disk/loopback.c
+++ b/disk/loopback.c
@@ -28,7 +28,6 @@ struct grub_loopback
 {
   char *devname;
   char *filename;
-  int has_partitions;
   struct grub_loopback *next;
 };
 
@@ -37,7 +36,6 @@ static struct grub_loopback *loopback_list;
 static const struct grub_arg_option options[] =
   {
     {"delete", 'd', 0, "delete the loopback device entry", 0, 0},
-    {"partitions", 'p', 0, "simulate a hard drive with partitions", 0, 0},
     {0, 0, 0, 0, 0, 0}
   };
 
@@ -107,9 +105,6 @@ grub_cmd_loopback (grub_extcmd_t cmd, int argc, char **args)
       grub_free (newdev->filename);
       newdev->filename = newname;
 
-      /* Set has_partitions when `--partitions' was used.  */
-      newdev->has_partitions = state[1].set;
-
       return 0;
     }
 
@@ -133,9 +128,6 @@ grub_cmd_loopback (grub_extcmd_t cmd, int argc, char **args)
       return grub_errno;
     }
 
-  /* Set has_partitions when `--partitions' was used.  */
-  newdev->has_partitions = state[1].set;
-
   /* Add the new entry to the list.  */
   newdev->next = loopback_list;
   loopback_list = newdev;
@@ -178,7 +170,6 @@ grub_loopback_open (const char *name, grub_disk_t disk)
                         / GRUB_DISK_SECTOR_SIZE);
   disk->id = (unsigned long) dev;
 
-  disk->has_partitions = dev->has_partitions;
   disk->data = file;
 
   return 0;
@@ -245,7 +236,7 @@ GRUB_MOD_INIT(loop)
 {
   cmd = grub_register_extcmd ("loopback", grub_cmd_loopback,
                              GRUB_COMMAND_FLAG_BOTH,
-                             "loopback [-d|-p] DEVICENAME FILE",
+                             "loopback [-d] DEVICENAME FILE",
                              "Make a device of a file.", options);
   grub_disk_dev_register (&grub_loopback_dev);
 }
diff --git a/disk/lvm.c b/disk/lvm.c
index 6707a40..f3c153b 100644
--- a/disk/lvm.c
+++ b/disk/lvm.c
@@ -97,7 +97,6 @@ grub_lvm_open (const char *name, grub_disk_t disk)
   if (! lv)
     return grub_error (GRUB_ERR_UNKNOWN_DEVICE, "Unknown LVM device %s", name);
 
-  disk->has_partitions = 0;
   disk->id = lv->number;
   disk->data = lv;
   disk->total_sectors = lv->size;
diff --git a/disk/memdisk.c b/disk/memdisk.c
index 4a04708..d93752f 100644
--- a/disk/memdisk.c
+++ b/disk/memdisk.c
@@ -42,7 +42,6 @@ grub_memdisk_open (const char *name, grub_disk_t disk)
 
   disk->total_sectors = memdisk_size / GRUB_DISK_SECTOR_SIZE;
   disk->id = (unsigned long) "mdsk";
-  disk->has_partitions = 0;
 
   return GRUB_ERR_NONE;
 }
diff --git a/disk/raid.c b/disk/raid.c
index c4d0857..f9aaf28 100644
--- a/disk/raid.c
+++ b/disk/raid.c
@@ -126,7 +126,6 @@ grub_raid_open (const char *name, grub_disk_t disk)
     return grub_error (GRUB_ERR_UNKNOWN_DEVICE, "Unknown RAID device %s",
                        name);
 
-  disk->has_partitions = 1;
   disk->id = array->number;
   disk->data = array;
 
diff --git a/disk/scsi.c b/disk/scsi.c
index 24ebdb6..85d53b3 100644
--- a/disk/scsi.c
+++ b/disk/scsi.c
@@ -283,11 +283,6 @@ grub_scsi_open (const char *name, grub_disk_t disk)
                             "unknown SCSI device");
        }
 
-      if (scsi->devtype == grub_scsi_devtype_cdrom)
-       disk->has_partitions = 0;
-      else
-       disk->has_partitions = 1;
-
       err = grub_scsi_read_capacity (scsi);
       if (err)
        {
diff --git a/fs/i386/pc/pxe.c b/fs/i386/pc/pxe.c
index 4032e12..1a99ad4 100644
--- a/fs/i386/pc/pxe.c
+++ b/fs/i386/pc/pxe.c
@@ -65,7 +65,6 @@ grub_pxe_open (const char *name, grub_disk_t disk)
   disk->total_sectors = 0;
   disk->id = (unsigned long) "pxe";
 
-  disk->has_partitions = 0;
   disk->data = 0;
 
   return GRUB_ERR_NONE;
diff --git a/include/grub/disk.h b/include/grub/disk.h
index de71bb5..31d0e1a 100644
--- a/include/grub/disk.h
+++ b/include/grub/disk.h
@@ -98,9 +98,6 @@ struct grub_disk
   /* The total number of sectors.  */
   grub_uint64_t total_sectors;
 
-  /* If partitions can be stored.  */
-  int has_partitions;
-
   /* The id used by the disk cache manager.  */
   unsigned long id;
 
diff --git a/kern/device.c b/kern/device.c
index 83ae3dc..b9c340e 100644
--- a/kern/device.c
+++ b/kern/device.c
@@ -100,7 +100,7 @@ grub_device_iterate (int (*hook) (const char *name))
       if (! dev)
        return 0;
 
-      if (dev->disk && dev->disk->has_partitions)
+      if (dev->disk)
        {
          struct part_ent *p;
          int ret = 0;
diff --git a/kern/disk.c b/kern/disk.c
index e463626..5fe1bcf 100644
--- a/kern/disk.c
+++ b/kern/disk.c
@@ -281,12 +281,6 @@ grub_disk_open (const char *name)
       goto fail;
     }
 
-  if (p && ! disk->has_partitions)
-    {
-      grub_error (GRUB_ERR_BAD_DEVICE, "no partition on this disk");
-      goto fail;
-    }
-
   disk->dev = dev;
 
   if (p)
diff --git a/normal/completion.c b/normal/completion.c
index 4b38e33..405976a 100644
--- a/normal/completion.c
+++ b/normal/completion.c
@@ -160,18 +160,9 @@ iterate_dev (const char *devname)
   dev = grub_device_open (devname);
 
   if (dev)
-    {
-      if (dev->disk && dev->disk->has_partitions)
-       {
-         if (add_completion (devname, ",", GRUB_COMPLETION_TYPE_DEVICE))
-           return 1;
-       }
-      else
-       {
-         if (add_completion (devname, ")", GRUB_COMPLETION_TYPE_DEVICE))
-           return 1;
-       }
-    }
+    if (add_completion (devname, ",", GRUB_COMPLETION_TYPE_DEVICE)
+       || add_completion (devname, ")", GRUB_COMPLETION_TYPE_DEVICE))
+      return 1;
 
   grub_errno = GRUB_ERR_NONE;
   return 0;
@@ -216,7 +207,7 @@ complete_device (void)
 
       if (dev)
        {
-         if (dev->disk && dev->disk->has_partitions)
+         if (dev->disk)
            {
              if (grub_partition_iterate (dev->disk, iterate_partition))
                {
diff --git a/normal/misc.c b/normal/misc.c
index 0a1a2f0..cddd1d3 100644
--- a/normal/misc.c
+++ b/normal/misc.c
@@ -94,10 +94,8 @@ grub_normal_print_device_info (const char *name)
              grub_errno = GRUB_ERR_NONE;
            }
        }
-      else if (! dev->disk->has_partitions || dev->disk->partition)
-       grub_printf ("Unknown filesystem");
       else
-       grub_printf ("Partition table");
+       grub_printf ("Unknown filesystem");
 
       grub_device_close (dev);
     }
diff --git a/util/grub-fstest.c b/util/grub-fstest.c
index 4722269..ddb2024 100644
--- a/util/grub-fstest.c
+++ b/util/grub-fstest.c
@@ -278,7 +278,7 @@ fstest (char **images, int num_disks, int cmd, int n, char 
**args)
 {
   char host_file[128];
   char loop_name[8];
-  char *argv[3] = { "-p", loop_name, host_file};
+  char *argv[2] = { loop_name, host_file};
   int i;
 
   for (i = 0; i < num_disks; i++)
@@ -289,7 +289,7 @@ fstest (char **images, int num_disks, int cmd, int n, char 
**args)
       grub_sprintf (loop_name, "loop%d", i);
       grub_sprintf (host_file, "(host)%s", images[i]);
 
-      if (execute_command ("loopback", 3, argv))
+      if (execute_command ("loopback", 2, argv))
         grub_util_error ("loopback command fails.");
     }
 
diff --git a/util/hostdisk.c b/util/hostdisk.c
index 5842698..0740da1 100644
--- a/util/hostdisk.c
+++ b/util/hostdisk.c
@@ -170,7 +170,6 @@ grub_util_biosdisk_open (const char *name, grub_disk_t disk)
     return grub_error (GRUB_ERR_BAD_DEVICE,
                       "no mapping exists for `%s'", name);
 
-  disk->has_partitions = 1;
   disk->id = drive;
 
   /* Get the size.  */
diff --git a/util/i386/pc/grub-setup.c b/util/i386/pc/grub-setup.c
index 852b498..9ec1faa 100644
--- a/util/i386/pc/grub-setup.c
+++ b/util/i386/pc/grub-setup.c
@@ -256,14 +256,6 @@ setup (const char *dir,
          tmp_img + GRUB_BOOT_MACHINE_BPB_START,
          GRUB_BOOT_MACHINE_BPB_END - GRUB_BOOT_MACHINE_BPB_START);
 
-  /* Copy the possible partition table.  */
-  if (dest_dev->disk->has_partitions)
-    memcpy (boot_img + GRUB_BOOT_MACHINE_WINDOWS_NT_MAGIC,
-           tmp_img + GRUB_BOOT_MACHINE_WINDOWS_NT_MAGIC,
-           GRUB_BOOT_MACHINE_PART_END - GRUB_BOOT_MACHINE_WINDOWS_NT_MAGIC);
-
-  free (tmp_img);
-
   /* If DEST_DRIVE is a hard disk, enable the workaround, which is
      for buggy BIOSes which don't pass boot drive correctly. Instead,
      they pass 0x00 or 0x01 even when booted from 0x80.  */
@@ -307,12 +299,6 @@ 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.");
-      goto unable_to_embed;
-    }
-
   if (dest_dev->disk->partition)
     {
       grub_util_warn ("Attempting to install GRUB to a partition instead of 
the MBR.  This is a BAD idea.");
@@ -338,6 +324,14 @@ setup (const char *dir,
       goto unable_to_embed;
     }
 
+  /* Copy the partition table.  */
+  if (dest_partmap)
+    memcpy (boot_img + GRUB_BOOT_MACHINE_WINDOWS_NT_MAGIC,
+           tmp_img + GRUB_BOOT_MACHINE_WINDOWS_NT_MAGIC,
+           GRUB_BOOT_MACHINE_PART_END - GRUB_BOOT_MACHINE_WINDOWS_NT_MAGIC);
+
+  free (tmp_img);
+
   grub_partition_iterate (dest_dev->disk, (strcmp (dest_partmap, 
"pc_partition_map") ?
                                           find_usable_region_gpt : 
find_usable_region_msdos));
 
_______________________________________________
Grub-devel mailing list
Grub-devel@gnu.org
http://lists.gnu.org/mailman/listinfo/grub-devel

Reply via email to