13386670d0
- libparted: Add support for partition resize - parted: add resizepart command
147 lines
5.2 KiB
Diff
147 lines
5.2 KiB
Diff
From 21c58e17c473ea8ef31a18d03348eb2381c0f36c Mon Sep 17 00:00:00 2001
|
|
From: Petr Uzel <petr.uzel@suse.cz>
|
|
Date: Mon, 26 Sep 2011 17:21:01 +0200
|
|
Subject: [PATCH 126/134] parted: add resizepart command
|
|
|
|
Add resizepart command to resize ( change the end position ) an existing
|
|
partition. Note that it does nothing to a filesystem in the partition.
|
|
---
|
|
NEWS | 2 ++
|
|
parted/parted.c | 86 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
|
2 files changed, 88 insertions(+)
|
|
|
|
diff --git a/NEWS b/NEWS
|
|
index 3de5dde..7069020 100644
|
|
--- a/NEWS
|
|
+++ b/NEWS
|
|
@@ -4,6 +4,8 @@ GNU parted NEWS -*- outline -*-
|
|
|
|
** New Features
|
|
|
|
+ Add resizepart command to resize a partition
|
|
+
|
|
Add support for EAV DASD partitions, which are ECKD's with more than
|
|
65520 cylinders.
|
|
|
|
diff --git a/parted/parted.c b/parted/parted.c
|
|
index 3bf03ea..a36ca28 100644
|
|
--- a/parted/parted.c
|
|
+++ b/parted/parted.c
|
|
@@ -153,6 +153,9 @@ static const char* fs_type_msg_start = N_("FS-TYPE is one of: ");
|
|
static const char* start_end_msg = N_("START and END are disk locations, such as "
|
|
"4GB or 10%. Negative values count from the end of the disk. "
|
|
"For example, -1s specifies exactly the last sector.\n");
|
|
+static const char* end_msg = N_("END is disk location, such as "
|
|
+ "4GB or 10%. Negative value counts from the end of the disk. "
|
|
+ "For example, -1s specifies exactly the last sector.\n");
|
|
static const char* state_msg = N_("STATE is one of: on, off\n");
|
|
static const char* device_msg = N_("DEVICE is usually /dev/hda or /dev/sda\n");
|
|
static const char* name_msg = N_("NAME is any word you want\n");
|
|
@@ -437,6 +440,21 @@ constraint_from_start_end (PedDevice* dev, PedGeometry* range_start,
|
|
range_start, range_end, 1, dev->length);
|
|
}
|
|
|
|
+
|
|
+static PedConstraint*
|
|
+constraint_from_start_end_fixed_start (PedDevice* dev, PedSector start_sector,
|
|
+ PedGeometry* range_end)
|
|
+{
|
|
+ PedGeometry range_start;
|
|
+ range_start.dev = dev;
|
|
+ range_start.start = start_sector;
|
|
+ range_start.end = start_sector;
|
|
+ range_start.length = 1;
|
|
+
|
|
+ return ped_constraint_new (ped_alignment_any, ped_alignment_any,
|
|
+ &range_start, range_end, 1, dev->length);
|
|
+}
|
|
+
|
|
void
|
|
help_on (char* topic)
|
|
{
|
|
@@ -1484,6 +1502,66 @@ error:
|
|
}
|
|
|
|
static int
|
|
+do_resizepart (PedDevice** dev, PedDisk** diskp)
|
|
+{
|
|
+ PedDisk *disk = *diskp;
|
|
+ PedPartition *part = NULL;
|
|
+ PedSector start, end, oldend;
|
|
+ PedGeometry *range_end = NULL;
|
|
+ PedConstraint* constraint;
|
|
+ int rc = 0;
|
|
+
|
|
+ if (!disk) {
|
|
+ disk = ped_disk_new (*dev);
|
|
+ *diskp = disk;
|
|
+ }
|
|
+ if (!disk)
|
|
+ goto error;
|
|
+
|
|
+ if (ped_disk_is_flag_available(disk, PED_DISK_CYLINDER_ALIGNMENT))
|
|
+ if (!ped_disk_set_flag(disk, PED_DISK_CYLINDER_ALIGNMENT,
|
|
+ alignment == ALIGNMENT_CYLINDER))
|
|
+ goto error;
|
|
+
|
|
+ if (!command_line_get_partition (_("Partition number?"), disk, &part))
|
|
+ goto error;
|
|
+ if (!_partition_warn_busy (part))
|
|
+ goto error;
|
|
+
|
|
+ start = part->geom.start;
|
|
+ end = oldend = part->geom.end;
|
|
+ if (!command_line_get_sector (_("End?"), *dev, &end, &range_end, NULL))
|
|
+ goto error;
|
|
+ /* Do not move start of the partition */
|
|
+ constraint = constraint_from_start_end_fixed_start (*dev, start, range_end);
|
|
+ if (!ped_disk_set_partition_geom (disk, part, constraint,
|
|
+ start, end))
|
|
+ goto error_destroy_constraint;
|
|
+ /* warn when shrinking partition - might lose data */
|
|
+ if (part->geom.end < oldend)
|
|
+ if (ped_exception_throw (
|
|
+ PED_EXCEPTION_WARNING,
|
|
+ PED_EXCEPTION_YES_NO,
|
|
+ _("Shrinking a partition can cause data loss, " \
|
|
+ "are you sure you want to continue?")) != PED_EXCEPTION_YES)
|
|
+ goto error_destroy_constraint;
|
|
+ ped_disk_commit (disk);
|
|
+
|
|
+ if ((*dev)->type != PED_DEVICE_FILE)
|
|
+ disk_is_modified = 1;
|
|
+
|
|
+ rc = 1;
|
|
+
|
|
+error_destroy_constraint:
|
|
+ ped_constraint_destroy (constraint);
|
|
+error:
|
|
+ if (range_end != NULL)
|
|
+ ped_geometry_destroy (range_end);
|
|
+ return rc;
|
|
+}
|
|
+
|
|
+
|
|
+static int
|
|
do_rm (PedDevice** dev, PedDisk** diskp)
|
|
{
|
|
PedPartition* part = NULL;
|
|
@@ -1906,6 +1984,14 @@ NULL),
|
|
str_list_create (_(start_end_msg), NULL), 1));
|
|
|
|
command_register (commands, command_create (
|
|
+ str_list_create_unique ("resizepart", _("resizepart"), NULL),
|
|
+ do_resizepart,
|
|
+ str_list_create (
|
|
+_("resizepart NUMBER END resize partition NUMBER"),
|
|
+NULL),
|
|
+ str_list_create (_(number_msg), _(end_msg), NULL), 1));
|
|
+
|
|
+command_register (commands, command_create (
|
|
str_list_create_unique ("rm", _("rm"), NULL),
|
|
do_rm,
|
|
str_list_create (
|
|
--
|
|
1.9.3
|
|
|