[Libguestfs] [PATCH 2/4] New API: resize2fs-size to allow shrinking ext2 filesystems (RHBZ#585221).
Richard W.M. Jones
rjones at redhat.com
Fri May 21 13:53:01 UTC 2010
--
Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones
virt-df lists disk usage of guests without needing to install any
software inside the virtual machine. Supports Linux and Windows.
http://et.redhat.com/~rjones/virt-df/
-------------- next part --------------
>From 71b02d6654395ff04689055f3820b3ad4e54ec00 Mon Sep 17 00:00:00 2001
From: Richard Jones <rjones at redhat.com>
Date: Fri, 21 May 2010 14:13:24 +0100
Subject: [PATCH 2/4] New API: resize2fs-size to allow shrinking ext2 filesystems (RHBZ#585221).
---
daemon/ext2.c | 36 ++++++++++++++++++++++++++++++++++++
src/generator.ml | 7 +++++++
2 files changed, 43 insertions(+), 0 deletions(-)
diff --git a/daemon/ext2.c b/daemon/ext2.c
index 3758f4e..3a075e5 100644
--- a/daemon/ext2.c
+++ b/daemon/ext2.c
@@ -20,6 +20,7 @@
#include <stdio.h>
#include <stdlib.h>
+#include <inttypes.h>
#include <string.h>
#include <unistd.h>
@@ -301,6 +302,41 @@ do_resize2fs (const char *device)
}
int
+do_resize2fs_size (const char *device, int64_t size)
+{
+ char *err;
+ int r;
+
+ char prog[] = "resize2fs";
+ if (e2prog (prog) == -1)
+ return -1;
+
+ /* resize2fs itself may impose additional limits. Since we are
+ * going to use the 'K' suffix however we can only work with whole
+ * kilobytes.
+ */
+ if (size & 1023) {
+ reply_with_error ("%" PRIi64 ": size must be a round number of kilobytes",
+ size);
+ return -1;
+ }
+ size /= 1024;
+
+ char buf[32];
+ snprintf (buf, sizeof buf, "%" PRIi64 "K", size);
+
+ r = command (NULL, &err, prog, device, buf, NULL);
+ if (r == -1) {
+ reply_with_error ("%s", err);
+ free (err);
+ return -1;
+ }
+
+ free (err);
+ return 0;
+}
+
+int
do_e2fsck_f (const char *device)
{
char *err;
diff --git a/src/generator.ml b/src/generator.ml
index aca56a8..b2ba513 100755
--- a/src/generator.ml
+++ b/src/generator.ml
@@ -4686,6 +4686,13 @@ unlikely for regular files in ordinary circumstances.
See also C<guestfs_pread>.");
+ ("resize2fs_size", (RErr, [Device "device"; Int64 "size"]), 248, [],
+ [],
+ "resize an ext2/ext3 filesystem (with size)",
+ "\
+This command is the same as C<guestfs_resize2fs> except that it
+allows you to specify the new size (in bytes) explicitly.");
+
]
let all_functions = non_daemon_functions @ daemon_functions
--
1.6.6.1
More information about the Libguestfs
mailing list