summaryrefslogtreecommitdiffstats
path: root/daemon/ext2.c
diff options
context:
space:
mode:
authorRichard Jones <rjones@redhat.com>2010-05-21 14:13:24 +0100
committerRichard Jones <rjones@redhat.com>2010-05-21 14:51:54 +0100
commit71b02d6654395ff04689055f3820b3ad4e54ec00 (patch)
treef05c6f64ee13874a6b32ded10b24533883ee05bb /daemon/ext2.c
parent5e1aff7856f721bf5737815a5b65c0de23ab0b0c (diff)
downloadlibguestfs-71b02d6654395ff04689055f3820b3ad4e54ec00.tar.gz
libguestfs-71b02d6654395ff04689055f3820b3ad4e54ec00.tar.xz
libguestfs-71b02d6654395ff04689055f3820b3ad4e54ec00.zip
New API: resize2fs-size to allow shrinking ext2 filesystems (RHBZ#585221).
Diffstat (limited to 'daemon/ext2.c')
-rw-r--r--daemon/ext2.c36
1 files changed, 36 insertions, 0 deletions
diff --git a/daemon/ext2.c b/daemon/ext2.c
index 3758f4ee..3a075e56 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;