Skip to contentSkip to conversation

Remove has_paritions

PATCH In review Vladimir 'phcoder' Serbinenko 2 participants 3 messages Aug 28, 2009 – Aug 30, 2009

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Remove has_paritions

Signature · 4 lines
Regards
Vladimir 'phcoder' Serbinenko

Personal git repository: http://repo.or.cz/w/grub2/phcoder.git
Changelog.phcoder new file +10 -0
new file mode 100644
index 0000000..978faf6
@@ -0,0 +1,10 @@
+2009-07-26  Vladimir Serbinenko  <[email protected]>
+
+	* 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.
disk/ata.c +0 -1
index 78d3965..73b07be 100644
@@ -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;
disk/efi/efidisk.c +0 -4
index de84859..fd1fae4 100644
@@ -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:
disk/fs_file.c +0 -1
index e095682..19dabef 100644
@@ -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));
disk/fs_uuid.c +0 -1
index 6901dba..aabebdf 100644
@@ -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));
disk/host.c +0 -1
index c4f3e71..c519662 100644
@@ -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;
disk/i386/pc/biosdisk.c +0 -1
index 0a6137f..115e2c1 100644
@@ -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));
disk/ieee1275/nand.c +0 -1
index 37427f8..9d96d51 100644
@@ -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;
disk/ieee1275/ofdisk.c +0 -2
index ca257d6..e749259 100644
@@ -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;
 
disk/loopback.c +1 -10
index 2980518..d98dbb2 100644
@@ -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);
 }
disk/lvm.c +0 -1
index 126b494..59bf2d7 100644
@@ -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;
disk/memdisk.c +0 -1
index 4a04708..d93752f 100644
@@ -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;
 }
disk/raid.c +0 -1
index c720fb3..fc12683 100644
@@ -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;
 
disk/scsi.c +0 -5
index 24ebdb6..85d53b3 100644
@@ -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)
 	{
fs/i386/pc/pxe.c +0 -1
index 4032e12..1a99ad4 100644
@@ -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;
include/grub/disk.h +0 -3
index de71bb5..31d0e1a 100644
@@ -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;
 
kern/device.c +1 -1
index 83ae3dc..b9c340e 100644
@@ -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;
kern/disk.c +0 -6
index e463626..5fe1bcf 100644
@@ -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)
normal/completion.c +13 -4
index 4b38e33..7b3de44 100644
@@ -161,14 +161,23 @@ iterate_dev (const char *devname)
 
   if (dev)
     {
-      if (dev->disk && dev->disk->has_partitions)
+      char tmp[grub_strlen (devname) + sizeof (",")];
+
+      grub_memcpy (tmp, devname, grub_strlen (devname));
+
+      if (grub_strcmp (devname, current_word) == 0)
 	{
-	  if (add_completion (devname, ",", GRUB_COMPLETION_TYPE_DEVICE))
+	  if (add_completion (devname, ")", GRUB_COMPLETION_TYPE_PARTITION))
 	    return 1;
+
+	  if (dev->disk)
+	    if (grub_partition_iterate (dev->disk, iterate_partition))
+	      return 1;
 	}
       else
 	{
-	  if (add_completion (devname, ")", GRUB_COMPLETION_TYPE_DEVICE))
+	  grub_memcpy (tmp + grub_strlen (devname), "", sizeof (""));
+	  if (add_completion (tmp, "", GRUB_COMPLETION_TYPE_DEVICE))
 	    return 1;
 	}
     }
@@ -216,7 +225,7 @@ complete_device (void)
 
       if (dev)
 	{
-	  if (dev->disk && dev->disk->has_partitions)
+	  if (dev->disk)
 	    {
 	      if (grub_partition_iterate (dev->disk, iterate_partition))
 		{
normal/misc.c +1 -3
index 0a1a2f0..cddd1d3 100644
@@ -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);
     }
util/grub-fstest.c +2 -2
index 1bb3706..d522e53 100644
@@ -277,7 +277,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++)
@@ -288,7 +288,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.");
     }
 
util/hostdisk.c +0 -1
index a06ecca..384d5cb 100644
@@ -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.  */
util/i386/pc/grub-setup.c +10 -15
index ccfbd1d..8a2f914 100644
@@ -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,8 +324,17 @@ 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, "part_msdos") ?
-					   find_usable_region_gpt : find_usable_region_msdos));
+					   find_usable_region_gpt
+					   : find_usable_region_msdos));
 
   if (embed_region.end == embed_region.start)
     {
#1 lore raw

disk/lvm.c grub_lvm_open (const char *name, grub_disk_t disk) · line 102

Quoted 12 lines · Vladimir 'phcoder' Serbinenko
disk/lvm.c +0 -1
index 126b494..59bf2d7 100644
@@ -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;

Why would LVM users want to nest partition maps in them?

This makes me think removing has_partitions is not such a good idea.

Actually, LVM is a partition map of sorts. If we're going to refurbish our partition handling model, I think we should contemplate the possibility of LVM (and perhaps swRAID) becoming less ad-hoc.

But that is more an idea for 2.0. What are our inmediate needs?

Signature · 5 lines
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."
#2 lore raw
Quoted 9 lines · Robert Millan
Quoted 8 lines · Vladimir 'phcoder' Serbinenko
disk/lvm.c +0 -0
index 126b494..59bf2d7 100644
@@ -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);
 
Quoted 9 lines

disk/lvm.c grub_lvm_open (const char *name, grub_disk_t disk) · line 102

Quoted 4 lines
disk/lvm.c +0 -1
-  disk->has_partitions = 0;
    disk->id = lv->number;
    disk->data = lv;
    disk->total_sectors = lv->size;

Why would LVM users want to nest partition maps in them?

This makes me think removing has_partitions is not such a good idea.

Probing for partition map when already probing for fs is cheap. has_partitions gets in the way of probing and the need for it was dictated by FAT floppies being detected as msdos partmap. This was recently fixed (by checking bootflags) and now has_partitions has become an artifact needing support in code, increasing code size and no benefit.

Quoted 4 lines

Actually, LVM is a partition map of sorts.  If we're going to refurbish our partition handling model, I think we should contemplate the possibility of LVM (and perhaps swRAID) becoming less ad-hoc.

I would happy if we could do it someway considering LVM can span across multiple devices. We have to consider multidrive filesystems like zfs and btrfs too.

Quoted 1 line

But that is more an idea for 2.0.  What are our inmediate needs?

This was actually triggered by grub2 not seeing partitions on Apple bootable CDs just because has_partitions=0. I vaguely remember I noticed other places where has_partitions was set in a heuristical way but can't point it now

Quoted 14 lines

--
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
[email protected]
http://lists.gnu.org/mailman/listinfo/grub-devel

Signature · 4 lines
Regards
Vladimir 'phcoder' Serbinenko

Personal git repository: http://repo.or.cz/w/grub2/phcoder.git