From 17027da1eda39d20b2d6dca0a59ac4afc5409318 Mon Sep 17 00:00:00 2001
From: "Samantha N. Bueno" <sbueno@redhat.com>
Date: Sun, 10 Apr 2013 08:47:26 -0700
Subject: [PATCH] add ped_assert for help debugging 1224833

testing only

diff -u -r -p parted-3.1/libparted/arch/linux.c parted-3.1-assert/libparted/arch/linux.c
--- parted-3.1/libparted/arch/linux.c	2016-04-07 19:55:04.635877266 -0400
+++ parted-3.1-assert/libparted/arch/linux.c	2016-04-10 13:35:08.411258350 -0400
@@ -666,7 +666,9 @@ _device_set_sector_size (PedDevice* dev)
         dev->sector_size = PED_SECTOR_SIZE_DEFAULT;
         dev->phys_sector_size = PED_SECTOR_SIZE_DEFAULT;
 
-        PED_ASSERT (dev->open_count);
+        /*PED_ASSERT (dev->open_count);*/
+        PED_ASSERT (dev != NULL);
+        PED_ASSERT (dev->open_count > 0);
 
         if (_get_linux_version() < KERNEL_VERSION (2,3,0)) {
                 dev->sector_size = PED_SECTOR_SIZE_DEFAULT;
@@ -736,6 +738,8 @@ _device_get_length (PedDevice* dev)
         PedSector               test_size;
 
 
+        /*PED_ASSERT (dev->open_count > 0);*/
+        PED_ASSERT (dev != NULL);
         PED_ASSERT (dev->open_count > 0);
         PED_ASSERT (dev->sector_size % PED_SECTOR_SIZE_DEFAULT == 0);
 
@@ -774,6 +778,9 @@ _device_probe_geometry (PedDevice* dev)
                 return 0;
         PED_ASSERT (S_ISBLK (dev_stat.st_mode));
 
+        PED_ASSERT (dev != NULL);
+        PED_ASSERT (dev->open_count > 0);
+
         _device_set_sector_size (dev);
 
         dev->length = _device_get_length (dev);
@@ -984,6 +991,9 @@ scsi_query_product_info (PedDevice* dev,
         LinuxSpecific* arch_specific = LINUX_SPECIFIC (dev);
         char    buf[32];
 
+        PED_ASSERT (dev != NULL);
+        PED_ASSERT (dev->open_count > 0);
+
         *vendor = NULL;
         *product = NULL;
 
@@ -1508,6 +1518,10 @@ _flush_cache (PedDevice* dev)
         LinuxSpecific*  arch_specific = LINUX_SPECIFIC (dev);
         int             i;
 
+        PED_ASSERT (dev != NULL);
+        PED_ASSERT (!dev->external_mode);
+        PED_ASSERT (dev->open_count > 0);
+
         if (dev->read_only)
                 return;
         dev->dirty = 0;
@@ -1677,6 +1691,7 @@ _device_seek (const PedDevice* dev, PedS
         PED_ASSERT (dev->sector_size % PED_SECTOR_SIZE_DEFAULT == 0);
         PED_ASSERT (dev != NULL);
         PED_ASSERT (!dev->external_mode);
+        PED_ASSERT (dev->open_count > 0);
 
         arch_specific = LINUX_SPECIFIC (dev);
 
@@ -1703,6 +1718,9 @@ _read_lastoddsector (const PedDevice* de
 
         arch_specific = LINUX_SPECIFIC (dev);
 
+        PED_ASSERT (dev != NULL);
+        PED_ASSERT (dev->open_count > 0);
+
 retry:
         ioctl_param.block = 0; /* read the last sector */
         ioctl_param.content_length = dev->sector_size;
@@ -1734,6 +1752,8 @@ linux_read (const PedDevice* dev, void*
         void*                   diobuf = NULL;
 
         PED_ASSERT (dev != NULL);
+        PED_ASSERT (!dev->external_mode);
+        PED_ASSERT (dev->open_count > 0);
         PED_ASSERT (dev->sector_size % PED_SECTOR_SIZE_DEFAULT == 0);
 
         if (_get_linux_version() < KERNEL_VERSION (2,6,0)) {
Binary files parted-3.1/libparted/arch/.linux.c.swp and parted-3.1-assert/libparted/arch/.linux.c.swp differ
diff -u -r -p parted-3.1/libparted/labels/dasd.c parted-3.1-assert/libparted/labels/dasd.c
--- parted-3.1/libparted/labels/dasd.c	2016-04-09 23:50:07.188009075 -0400
+++ parted-3.1-assert/libparted/labels/dasd.c	2016-04-10 14:02:54.722030633 -0400
@@ -953,11 +953,14 @@ dasd_alloc_metadata (PedDisk* disk)
 	struct fdasd_anchor anchor;
 
 	PED_ASSERT (disk != NULL);
-	PED_ASSERT (disk->dev != NULL);
 
 	arch_specific = LINUX_SPECIFIC (disk->dev);
 	disk_specific = disk->disk_specific;
 
+	PED_ASSERT (disk->dev != NULL);
+    PED_ASSERT (!disk->dev->external_mode);
+    PED_ASSERT (disk->dev->open_count > 0);
+
 	constraint_any = ped_constraint_any (disk->dev);
 
 	/* For LDL or CMS, the leading metadata ends at the sector before
diff -u -r -p parted-3.1/libparted/labels/fdasd.c parted-3.1-assert/libparted/labels/fdasd.c
--- parted-3.1/libparted/labels/fdasd.c	2016-04-07 19:55:04.037881281 -0400
+++ parted-3.1-assert/libparted/labels/fdasd.c	2016-04-10 14:02:35.738159087 -0400
@@ -21,6 +21,7 @@
 #include <parted/vtoc.h>
 #include <parted/device.h>
 #include <parted/fdasd.h>
+#include <parted/debug.h>
 
 #include <parted/parted.h>
 
@@ -957,6 +958,10 @@ fdasd_get_geometry (const PedDevice *dev
 	dasd_information_t dasd_info;
 	struct dasd_eckd_characteristics *characteristics;
 
+    PED_ASSERT (dev != NULL);
+    PED_ASSERT (!dev->external_mode);
+    PED_ASSERT (dev->open_count > 0);
+
 	/* We can't get geometry from a regular file,
 	   so simulate something usable, for the sake of testing.  */
 	struct stat st;
