[Parted-commits] GNU Parted Official Repository: Changes to 'master'

Jim Meyering meyering at alioth.debian.org
Thu Dec 10 16:44:34 UTC 2009


 include/parted/disk.h  |    5 +-
 libparted/disk.c       |   97 +++++++++++++++++++++++++++++++++----------------
 libparted/labels/gpt.c |   52 ++++++++++++++++++++++----
 3 files changed, 114 insertions(+), 40 deletions(-)

New commits:
commit b502cd524c9ca7df8624e102024bc054b2102661
Author: Hans de Goede <hdegoede at redhat.com>
Date:   Thu Dec 10 12:43:18 2009 +0100

    libparted: missing pop update mode in ped_disk_delete_all error path
    
    * libparted/disk.c(ped_disk_delete_all): Add missing update mode pop
    call in error path.

diff --git a/libparted/disk.c b/libparted/disk.c
index cf810d9..7cbde81 100644
--- a/libparted/disk.c
+++ b/libparted/disk.c
@@ -2124,8 +2124,10 @@ ped_disk_delete_all (PedDisk* disk)
 	for (walk = disk->part_list; walk; walk = next) {
 		next = walk->next;
 
-		if (!ped_disk_delete_partition (disk, walk))
+		if (!ped_disk_delete_partition (disk, walk)) {
+		        _disk_pop_update_mode(disk);
 			return 0;
+                }
 	}
 
 	if (!_disk_pop_update_mode (disk))

commit 46fad42f0d9707efb8fc62ba844d0bb9751179ba
Author: Hans de Goede <hdegoede at redhat.com>
Date:   Thu Dec 10 12:43:17 2009 +0100

    libparted: make pop/push update mode propagate sanity check errors
    
    Sanity check errors indicate something is really really wrong, still
    sometimes they happen, when they happen it helps a lot in debugging
    them when the libparted caller immediately errors out at the first
    moment, rather then slugging along until things crash somewere.
    * libparted/disk.c(_disk_push_update_mode,_disk_pop_update_mode):
    Change return value from void to int, and return 0 when the sanity
    check calls fail.
    * libparted/disk.c(*): Update all _disk_push_update_mode /
    _disk_pop_update_mode callers to propagate the return value.

diff --git a/libparted/disk.c b/libparted/disk.c
index a138bef..cf810d9 100644
--- a/libparted/disk.c
+++ b/libparted/disk.c
@@ -54,8 +54,8 @@
 #ifdef DEBUG
 static int _disk_check_sanity (PedDisk* disk);
 #endif
-static void _disk_push_update_mode (PedDisk* disk);
-static void _disk_pop_update_mode (PedDisk* disk);
+static int _disk_push_update_mode (PedDisk* disk);
+static int _disk_pop_update_mode (PedDisk* disk);
 static int _disk_raw_insert_before (PedDisk* disk, PedPartition* loc,
 				    PedPartition* part);
 static int _disk_raw_insert_after (PedDisk* disk, PedPartition* loc,
@@ -222,9 +222,11 @@ _add_duplicate_part (PedDisk* disk, PedPartition* old_part)
 		goto error;
 	new_part->disk = disk;
 
-	_disk_push_update_mode (disk);
+	if (!_disk_push_update_mode (disk))
+		goto error_destroy_new_part;
 	ret = _disk_raw_add (disk, new_part);
-	_disk_pop_update_mode (disk);
+	if (!_disk_pop_update_mode (disk))
+		goto error_destroy_new_part;
 	if (!ret)
 		goto error_destroy_new_part;
 #ifdef DEBUG
@@ -260,7 +262,8 @@ ped_disk_duplicate (const PedDisk* old_disk)
 	if (!new_disk)
 		goto error;
 
-	_disk_push_update_mode (new_disk);
+	if (!_disk_push_update_mode (new_disk))
+		goto error_destroy_new_disk;
 	for (old_part = ped_disk_next_partition (old_disk, NULL); old_part;
 	     old_part = ped_disk_next_partition (old_disk, old_part)) {
 		if (ped_partition_is_active (old_part)) {
@@ -270,7 +273,8 @@ ped_disk_duplicate (const PedDisk* old_disk)
 			}
 		}
 	}
-	_disk_pop_update_mode (new_disk);
+	if (!_disk_pop_update_mode (new_disk))
+		goto error_destroy_new_disk;
 	return new_disk;
 
 error_destroy_new_disk:
@@ -373,12 +377,15 @@ ped_disk_new_fresh (PedDevice* dev, const PedDiskType* type)
 	disk = type->ops->alloc (dev);
 	if (!disk)
        		goto error;
-	_disk_pop_update_mode (disk);
+        if (!_disk_pop_update_mode (disk))
+                goto error_destroy_disk;
 	PED_ASSERT (disk->update_mode == 0, ignored);
 
 	disk->needs_clobber = 1;
 	return disk;
 
+error_destroy_disk:
+        ped_disk_destroy (disk);
 error:
 	return NULL;
 }
@@ -1099,12 +1106,13 @@ _disk_alloc_freespace (PedDisk* disk)
  * partitions are removed, making it much easier for various manipulation
  * routines...
  */
-static void
+static int
 _disk_push_update_mode (PedDisk* disk)
 {
 	if (!disk->update_mode) {
 #ifdef DEBUG
-		_disk_check_sanity (disk);
+		if (!_disk_check_sanity (disk))
+			return 0;
 #endif
 
 		_disk_remove_freespace (disk);
@@ -1112,24 +1120,27 @@ _disk_push_update_mode (PedDisk* disk)
 		_disk_remove_metadata (disk);
 
 #ifdef DEBUG
-		_disk_check_sanity (disk);
+		if (!_disk_check_sanity (disk))
+			return 0;
 #endif
 	} else {
 		disk->update_mode++;
 	}
+	return 1;
 }
 
-static void
+static int
 _disk_pop_update_mode (PedDisk* disk)
 {
-	PED_ASSERT (disk->update_mode, return);
+	PED_ASSERT (disk->update_mode, return 0);
 
 	if (disk->update_mode == 1) {
 	/* re-allocate metadata BEFORE leaving update mode, to prevent infinite
 	 * recursion (metadata allocation requires update mode)
 	 */
 #ifdef DEBUG
-		_disk_check_sanity (disk);
+		if (!_disk_check_sanity (disk))
+			return 0;
 #endif
 
 		_disk_alloc_metadata (disk);
@@ -1137,11 +1148,13 @@ _disk_pop_update_mode (PedDisk* disk)
 		_disk_alloc_freespace (disk);
 
 #ifdef DEBUG
-		_disk_check_sanity (disk);
+		if (!_disk_check_sanity (disk))
+			return 0;
 #endif
 	} else {
 		disk->update_mode--;
 	}
+	return 1;
 }
 
 /** @} */
@@ -1971,7 +1984,8 @@ ped_disk_add_partition (PedDisk* disk, PedPartition* part,
 	if (!_partition_check_basic_sanity (disk, part))
 		return 0;
 
-	_disk_push_update_mode (disk);
+	if (!_disk_push_update_mode (disk))
+		return 0;
 
 	if (ped_partition_is_active (part)) {
 		overlap_constraint
@@ -2005,7 +2019,8 @@ ped_disk_add_partition (PedDisk* disk, PedPartition* part,
 
 	ped_constraint_destroy (overlap_constraint);
 	ped_constraint_destroy (constraints);
-	_disk_pop_update_mode (disk);
+	if (!_disk_pop_update_mode (disk))
+		return 0;
 #ifdef DEBUG
 	if (!_disk_check_sanity (disk))
 		return 0;
@@ -2034,10 +2049,12 @@ ped_disk_remove_partition (PedDisk* disk, PedPartition* part)
 	PED_ASSERT (disk != NULL, return 0);
 	PED_ASSERT (part != NULL, return 0);
 
-	_disk_push_update_mode (disk);
+	if (!_disk_push_update_mode (disk))
+		return 0;
 	PED_ASSERT (part->part_list == NULL, ignored);
 	_disk_raw_remove (disk, part);
-	_disk_pop_update_mode (disk);
+	if (!_disk_pop_update_mode (disk))
+		return 0;
 	ped_disk_enumerate_partitions (disk);
 	return 1;
 }
@@ -2056,12 +2073,14 @@ ped_disk_delete_partition (PedDisk* disk, PedPartition* part)
 	PED_ASSERT (disk != NULL, return 0);
 	PED_ASSERT (part != NULL, return 0);
 
-	_disk_push_update_mode (disk);
+	if (!_disk_push_update_mode (disk))
+		return 0;
 	if (part->type == PED_PARTITION_EXTENDED)
 		ped_disk_delete_all_logical (disk);
 	ped_disk_remove_partition (disk, part);
 	ped_partition_destroy (part);
-	_disk_pop_update_mode (disk);
+	if (!_disk_pop_update_mode (disk))
+		return 0;
 
 	return 1;
 }
@@ -2099,7 +2118,8 @@ ped_disk_delete_all (PedDisk* disk)
 
 	PED_ASSERT (disk != NULL, return 0);
 
-	_disk_push_update_mode (disk);
+	if (!_disk_push_update_mode (disk))
+		return 0;
 
 	for (walk = disk->part_list; walk; walk = next) {
 		next = walk->next;
@@ -2108,7 +2128,8 @@ ped_disk_delete_all (PedDisk* disk)
 			return 0;
 	}
 
-	_disk_pop_update_mode (disk);
+	if (!_disk_pop_update_mode (disk))
+		return 0;
 
 	return 1;
 }
@@ -2142,7 +2163,8 @@ ped_disk_set_partition_geom (PedDisk* disk, PedPartition* part,
 	old_geom = part->geom;
 	ped_geometry_init (&new_geom, part->geom.dev, start, end - start + 1);
 
-	_disk_push_update_mode (disk);
+	if (!_disk_push_update_mode (disk))
+		return 0;
 
 	overlap_constraint
 		= _partition_get_overlap_constraint (part, &new_geom);
@@ -2165,7 +2187,8 @@ ped_disk_set_partition_geom (PedDisk* disk, PedPartition* part,
 	_disk_raw_remove (disk, part);
 	_disk_raw_add (disk, part);
 
-	_disk_pop_update_mode (disk);
+	if (!_disk_pop_update_mode (disk))
+		goto error;
 
 	ped_constraint_destroy (overlap_constraint);
 	ped_constraint_destroy (constraints);
@@ -2173,6 +2196,7 @@ ped_disk_set_partition_geom (PedDisk* disk, PedPartition* part,
 
 error_pop_update_mode:
 	_disk_pop_update_mode (disk);
+error:
 	ped_constraint_destroy (overlap_constraint);
 	ped_constraint_destroy (constraints);
 	part->geom = old_geom;
@@ -2211,7 +2235,8 @@ ped_disk_maximize_partition (PedDisk* disk, PedPartition* part,
 
 	old_geom = part->geom;
 
-	_disk_push_update_mode (disk);
+	if (!_disk_push_update_mode (disk))
+		return 0;
 
 	if (part->prev)
 		new_start = part->prev->geom.end + 1;
@@ -2227,7 +2252,8 @@ ped_disk_maximize_partition (PedDisk* disk, PedPartition* part,
 					  new_end))
 		goto error;
 
-	_disk_pop_update_mode (disk);
+	if (!_disk_pop_update_mode (disk))
+		return 0;
 	return 1;
 
 error:
@@ -2299,11 +2325,13 @@ ped_disk_minimize_extended_partition (PedDisk* disk)
 	if (!ext_part)
 		return 1;
 
-	_disk_push_update_mode (disk);
+	if (!_disk_push_update_mode (disk))
+		return 0;
 
 	first_logical = ext_part->part_list;
 	if (!first_logical) {
-		_disk_pop_update_mode (disk);
+		if (!_disk_pop_update_mode (disk))
+			return 0;
 		return ped_disk_delete_partition (disk, ext_part);
 	}
 
@@ -2316,7 +2344,8 @@ ped_disk_minimize_extended_partition (PedDisk* disk)
 					      last_logical->geom.end);
 	ped_constraint_destroy (constraint);
 
-	_disk_pop_update_mode (disk);
+	if (!_disk_pop_update_mode (disk))
+		return 0;
 	return status;
 }
 

commit b6b1882f9c21bf96b5b1fc50a56ed7ea832e18f3
Author: Joel Granados Moreno <jgranado at redhat.com>
Date:   Thu Dec 10 12:43:15 2009 +0100

    libparted: add missing update mode pop in duplicate error path
    
    * libparted/disk.c(ped_disk_duplicate): Add missing update mode
    pop call in error path.

diff --git a/libparted/disk.c b/libparted/disk.c
index 99bd6df..a138bef 100644
--- a/libparted/disk.c
+++ b/libparted/disk.c
@@ -264,8 +264,10 @@ ped_disk_duplicate (const PedDisk* old_disk)
 	for (old_part = ped_disk_next_partition (old_disk, NULL); old_part;
 	     old_part = ped_disk_next_partition (old_disk, old_part)) {
 		if (ped_partition_is_active (old_part)) {
-			if (!_add_duplicate_part (new_disk, old_part))
+			if (!_add_duplicate_part (new_disk, old_part)){
+				_disk_pop_update_mode (new_disk);
 				goto error_destroy_new_disk;
+			}
 		}
 	}
 	_disk_pop_update_mode (new_disk);

commit 95eb769bd4bd7926de4c59282b2a65a1d29e6be7
Author: Joel Granados Moreno <jgranado at redhat.com>
Date:   Thu Dec 10 12:43:14 2009 +0100

    gpt: Add support for appletv partitions
    
    * include/parted/disk.h(PedPartitionFlag): Add
    PED_PARTITION_APPLE_TV_RECOVERY.
    * libparted/disk.c(ped_partition_flag_get_name): Handle
    PED_PARTITION_APPLE_TV_RECOVERY.
    * libparted/labels/gpt.c(PARTITION_APPLE_TV_RECOVERY_GUID):
    New define.
    * libparted/labels/gpt.c(GPTPartitionData): Add atvrecv member.
    * libparted/labels/gpt.c(_parse_part_entry, gpt_partition_new,
    gpt_partition_set_system, gpt_partition_set_flag,
    gpt_partition_get_flag, gpt_partition_is_flag_available):
    Handle atvrecv / PARTITION_APPLE_TV_RECOVERY_GUID.

diff --git a/include/parted/disk.h b/include/parted/disk.h
index eb8e37b..c567a8f 100644
--- a/include/parted/disk.h
+++ b/include/parted/disk.h
@@ -67,10 +67,11 @@ enum _PedPartitionFlag {
         PED_PARTITION_PALO=9,
         PED_PARTITION_PREP=10,
         PED_PARTITION_MSFT_RESERVED=11,
-        PED_PARTITION_BIOS_GRUB=12
+        PED_PARTITION_BIOS_GRUB=12,
+        PED_PARTITION_APPLE_TV_RECOVERY=13
 };
 #define PED_PARTITION_FIRST_FLAG        PED_PARTITION_BOOT
-#define PED_PARTITION_LAST_FLAG         PED_PARTITION_BIOS_GRUB
+#define PED_PARTITION_LAST_FLAG         PED_PARTITION_APPLE_TV_RECOVERY
 
 enum _PedDiskTypeFeature {
         PED_DISK_TYPE_EXTENDED=1,       /**< supports extended partitions */
diff --git a/libparted/disk.c b/libparted/disk.c
index e8014d1..99bd6df 100644
--- a/libparted/disk.c
+++ b/libparted/disk.c
@@ -2391,6 +2391,8 @@ ped_partition_flag_get_name (PedPartitionFlag flag)
 		return N_("prep");
 	case PED_PARTITION_MSFT_RESERVED:
 		return N_("msftres");
+        case PED_PARTITION_APPLE_TV_RECOVERY:
+                return N_("atvrecv");
 
 	default:
 		ped_exception_throw (
diff --git a/libparted/labels/gpt.c b/libparted/labels/gpt.c
index ca842d3..15da1a0 100644
--- a/libparted/labels/gpt.c
+++ b/libparted/labels/gpt.c
@@ -131,6 +131,10 @@ typedef struct
     ((efi_guid_t) { PED_CPU_TO_LE32 (0x48465300), PED_CPU_TO_LE16 (0x0000), \
                     PED_CPU_TO_LE16 (0x11AA), 0xaa, 0x11, \
                     { 0x00, 0x30, 0x65, 0x43, 0xEC, 0xAC }})
+#define PARTITION_APPLE_TV_RECOVERY_GUID \
+    ((efi_guid_t) { PED_CPU_TO_LE32 (0x5265636F), PED_CPU_TO_LE16 (0x7665), \
+                    PED_CPU_TO_LE16 (0x11AA), 0xaa, 0x11, \
+                    { 0x00, 0x30, 0x65, 0x43, 0xEC, 0xAC }})
 
 struct __attribute__ ((packed)) _GuidPartitionTableHeader_t
 {
@@ -264,6 +268,7 @@ typedef struct _GPTPartitionData
   int hp_service;
   int hidden;
   int msftres;
+  int atvrecv;
 } GPTPartitionData;
 
 static PedDiskType gpt_disk_type;
@@ -782,7 +787,7 @@ _parse_part_entry (PedDisk *disk, GuidPartitionEntry_t *pte)
   gpt_part_data->lvm = gpt_part_data->raid
     = gpt_part_data->boot = gpt_part_data->hp_service
     = gpt_part_data->hidden = gpt_part_data->msftres
-    = gpt_part_data->bios_grub = 0;
+    = gpt_part_data->bios_grub = gpt_part_data->atvrecv = 0;
 
   if (pte->Attributes.RequiredToFunction & 0x1)
     gpt_part_data->hidden = 1;
@@ -799,6 +804,8 @@ _parse_part_entry (PedDisk *disk, GuidPartitionEntry_t *pte)
     gpt_part_data->hp_service = 1;
   else if (!guid_cmp (gpt_part_data->type, PARTITION_MSFT_RESERVED_GUID))
     gpt_part_data->msftres = 1;
+  else if (!guid_cmp (gpt_part_data->type, PARTITION_APPLE_TV_RECOVERY_GUID))
+    gpt_part_data->atvrecv = 1;
 
   return part;
 }
@@ -1295,6 +1302,7 @@ gpt_partition_new (const PedDisk *disk,
   gpt_part_data->hp_service = 0;
   gpt_part_data->hidden = 0;
   gpt_part_data->msftres = 0;
+  gpt_part_data->atvrecv = 0;
   uuid_generate ((unsigned char *) &gpt_part_data->uuid);
   swap_uuid_and_efi_guid ((unsigned char *) (&gpt_part_data->uuid));
   memset (gpt_part_data->name, 0, sizeof gpt_part_data->name);
@@ -1390,6 +1398,11 @@ gpt_partition_set_system (PedPartition *part,
       gpt_part_data->type = PARTITION_MSFT_RESERVED_GUID;
       return 1;
     }
+  if (gpt_part_data->atvrecv)
+    {
+      gpt_part_data->type = PARTITION_APPLE_TV_RECOVERY_GUID;
+      return 1;
+    }
 
   if (fs_type)
     {
@@ -1487,7 +1500,9 @@ gpt_partition_set_flag (PedPartition *part, PedPartitionFlag flag, int state)
         gpt_part_data->raid
           = gpt_part_data->lvm
           = gpt_part_data->bios_grub
-          = gpt_part_data->hp_service = gpt_part_data->msftres = 0;
+          = gpt_part_data->hp_service
+          = gpt_part_data->msftres
+          = gpt_part_data->atvrecv = 0;
       return gpt_partition_set_system (part, part->fs_type);
     case PED_PARTITION_BIOS_GRUB:
       gpt_part_data->bios_grub = state;
@@ -1495,7 +1510,9 @@ gpt_partition_set_flag (PedPartition *part, PedPartitionFlag flag, int state)
         gpt_part_data->raid
           = gpt_part_data->lvm
           = gpt_part_data->boot
-          = gpt_part_data->hp_service = gpt_part_data->msftres = 0;
+          = gpt_part_data->hp_service
+          = gpt_part_data->msftres
+          = gpt_part_data->atvrecv = 0;
       return gpt_partition_set_system (part, part->fs_type);
     case PED_PARTITION_RAID:
       gpt_part_data->raid = state;
@@ -1503,7 +1520,9 @@ gpt_partition_set_flag (PedPartition *part, PedPartitionFlag flag, int state)
         gpt_part_data->boot
           = gpt_part_data->lvm
           = gpt_part_data->bios_grub
-          = gpt_part_data->hp_service = gpt_part_data->msftres = 0;
+          = gpt_part_data->hp_service
+          = gpt_part_data->msftres
+          = gpt_part_data->atvrecv = 0;
       return gpt_partition_set_system (part, part->fs_type);
     case PED_PARTITION_LVM:
       gpt_part_data->lvm = state;
@@ -1511,7 +1530,9 @@ gpt_partition_set_flag (PedPartition *part, PedPartitionFlag flag, int state)
         gpt_part_data->boot
           = gpt_part_data->raid
           = gpt_part_data->bios_grub
-          = gpt_part_data->hp_service = gpt_part_data->msftres = 0;
+          = gpt_part_data->hp_service
+          = gpt_part_data->msftres
+          = gpt_part_data->atvrecv = 0;
       return gpt_partition_set_system (part, part->fs_type);
     case PED_PARTITION_HPSERVICE:
       gpt_part_data->hp_service = state;
@@ -1519,7 +1540,9 @@ gpt_partition_set_flag (PedPartition *part, PedPartitionFlag flag, int state)
         gpt_part_data->boot
           = gpt_part_data->raid
           = gpt_part_data->lvm
-          = gpt_part_data->bios_grub = gpt_part_data->msftres = 0;
+          = gpt_part_data->bios_grub
+          = gpt_part_data->msftres
+          = gpt_part_data->atvrecv = 0;
       return gpt_partition_set_system (part, part->fs_type);
     case PED_PARTITION_MSFT_RESERVED:
       gpt_part_data->msftres = state;
@@ -1527,7 +1550,19 @@ gpt_partition_set_flag (PedPartition *part, PedPartitionFlag flag, int state)
         gpt_part_data->boot
           = gpt_part_data->raid
           = gpt_part_data->lvm
-          = gpt_part_data->bios_grub = gpt_part_data->hp_service = 0;
+          = gpt_part_data->bios_grub
+          = gpt_part_data->hp_service
+          = gpt_part_data->atvrecv = 0;
+      return gpt_partition_set_system (part, part->fs_type);
+    case PED_PARTITION_APPLE_TV_RECOVERY:
+      gpt_part_data->atvrecv = state;
+      if (state)
+        gpt_part_data->boot
+          = gpt_part_data->raid
+          = gpt_part_data->lvm
+          = gpt_part_data->bios_grub
+          = gpt_part_data->hp_service
+          = gpt_part_data->msftres = 0;
       return gpt_partition_set_system (part, part->fs_type);
     case PED_PARTITION_HIDDEN:
       gpt_part_data->hidden = state;
@@ -1562,6 +1597,8 @@ gpt_partition_get_flag (const PedPartition *part, PedPartitionFlag flag)
       return gpt_part_data->hp_service;
     case PED_PARTITION_MSFT_RESERVED:
       return gpt_part_data->msftres;
+   case PED_PARTITION_APPLE_TV_RECOVERY:
+      return gpt_part_data->atvrecv;
     case PED_PARTITION_HIDDEN:
       return gpt_part_data->hidden;
     case PED_PARTITION_SWAP:
@@ -1585,6 +1622,7 @@ gpt_partition_is_flag_available (const PedPartition *part,
     case PED_PARTITION_BIOS_GRUB:
     case PED_PARTITION_HPSERVICE:
     case PED_PARTITION_MSFT_RESERVED:
+    case PED_PARTITION_APPLE_TV_RECOVERY:
     case PED_PARTITION_HIDDEN:
       return 1;
     case PED_PARTITION_SWAP:



More information about the Parted-commits mailing list