New partition API: part_resize

This can be used to enlarge or shrink an existing partition.
This commit is contained in:
Nikos Skalkotos
2017-07-29 20:51:04 +03:00
committed by Pino Toscano
parent b934614057
commit c355b744bf
4 changed files with 55 additions and 1 deletions

View File

@@ -177,6 +177,37 @@ do_part_del (const char *device, int partnum)
return 0;
}
int
do_part_resize (const char *device, int partnum, int64_t endsect)
{
int r;
CLEANUP_FREE char *err = NULL;
char endstr[32];
char partnum_str[16];
if (partnum <= 0) {
reply_with_error ("partition number must be >= 1");
return -1;
}
snprintf (partnum_str, sizeof partnum_str, "%d", partnum);
snprintf (endstr, sizeof endstr, "%" PRIi64 "s", endsect);
udev_settle ();
r = commandf (NULL, &err, COMMAND_FLAG_FOLD_STDOUT_ON_STDERR,
"parted", "-s", "--", device, "resizepart", partnum_str,
endstr, NULL);
if (r == -1) {
reply_with_error ("parted: %s: %s:", device, err);
return -1;
}
udev_settle();
return 0;
}
int
do_part_disk (const char *device, const char *parttype)
{

View File

@@ -9646,4 +9646,26 @@ be mountable but require special options. Filesystems may
not all belong to a single logical operating system
(use C<guestfs_inspect_os> to look for OSes)." };
{ defaults with
name = "part_resize"; added = (1, 37, 20);
style = RErr, [String (Device, "device"); Int "partnum"; Int64 "endsect"], [];
tests = [
InitEmpty, Always, TestRun (
[["part_init"; "/dev/sda"; "mbr"];
["part_add"; "/dev/sda"; "primary"; "1"; "-1025"];
["part_resize"; "/dev/sda"; "1"; "-1"]]), []
];
shortdesc = "resize a partition";
longdesc = "\
This command resizes the partition numbered C<partnum> on C<device>
by moving the end position.
Note that this does not modify any filesystem present in the partition.
If you wish to do this, you will need to use filesystem resizing
commands like C<guestfs_resize2fs>.
When growing a partition you will want to grow the filesystem
afterwards, but when shrinking, you need to shrink the filesystem
before the partition." };
]

View File

@@ -484,6 +484,7 @@ let proc_nr = [
474, "internal_yara_scan";
475, "file_architecture";
476, "list_filesystems";
477, "part_resize";
]
(* End of list. If adding a new entry, add it at the end of the list

View File

@@ -1 +1 @@
476
477