From fd2df92bbaaa5926b0c67916a5947af102cac20c Mon Sep 17 00:00:00 2001 From: Joel Granados Moreno Date: Thu, 11 Jun 2009 17:05:39 +0200 Subject: [PATCH] return errro on push or pop update mode. --- libparted/disk.c | 85 +++++++++++++++++++++++++++++++++++------------------ 1 files changed, 56 insertions(+), 29 deletions(-) diff --git a/libparted/disk.c b/libparted/disk.c index 3269b9d..6884c83 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, @@ -215,9 +215,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 @@ -253,7 +255,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)) { @@ -261,7 +264,8 @@ ped_disk_duplicate (const PedDisk* old_disk) goto error_destroy_new_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: @@ -349,7 +353,8 @@ 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, goto error_destroy_disk); disk->needs_clobber = 1; @@ -914,12 +919,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); @@ -927,24 +933,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); @@ -952,11 +961,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; } /** @} */ @@ -1826,7 +1837,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 @@ -1854,7 +1866,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; @@ -1883,10 +1896,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, goto error); _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; @@ -1909,12 +1924,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; } @@ -1952,7 +1969,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; @@ -1961,7 +1979,8 @@ ped_disk_delete_all (PedDisk* disk) return 0; } - _disk_pop_update_mode (disk); + if (!_disk_pop_update_mode (disk)) + return 0; return 1; } @@ -1995,7 +2014,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); @@ -2018,7 +2038,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); @@ -2026,6 +2047,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; @@ -2064,7 +2086,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; @@ -2080,7 +2103,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: @@ -2152,11 +2176,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); } @@ -2169,7 +2195,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; } -- 1.6.0.6