summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRichard W.M. Jones <rjones@redhat.com>2009-07-31 08:57:10 +0100
committerRichard W.M. Jones <rjones@redhat.com>2009-07-31 10:22:38 +0100
commit0e6e32025885286e2de39efca34ced2aaf26b3a3 (patch)
treee4c3c747a1d2c805cd01c1e0a9c526407b520641
parentafaff775c12f32b7912f194e2fcc8e76b8c82572 (diff)
downloadlibguestfs-0e6e32025885286e2de39efca34ced2aaf26b3a3.tar.gz
libguestfs-0e6e32025885286e2de39efca34ced2aaf26b3a3.tar.xz
libguestfs-0e6e32025885286e2de39efca34ced2aaf26b3a3.zip
New command: 'fallocate' to (pre-)allocate sized files.
-rw-r--r--TODO1
-rw-r--r--daemon/Makefile.am1
-rw-r--r--daemon/fallocate.c59
-rw-r--r--po/POTFILES.in1
-rw-r--r--src/MAX_PROC_NR2
-rwxr-xr-xsrc/generator.ml14
6 files changed, 76 insertions, 2 deletions
diff --git a/TODO b/TODO
index 2b9aae12..0326ad9d 100644
--- a/TODO
+++ b/TODO
@@ -147,7 +147,6 @@ Ideas for extra commands
dd (?)
utime / utimes / futimes / futimens / l..
more mk*temp calls
- some sort of alloc/fallocate/posix_fallocate call to create empty space
trunc[ate??]
ext2 properties:
diff --git a/daemon/Makefile.am b/daemon/Makefile.am
index 52482d08..6da485bc 100644
--- a/daemon/Makefile.am
+++ b/daemon/Makefile.am
@@ -35,6 +35,7 @@ guestfsd_SOURCES = \
dropcaches.c \
du.c \
ext2.c \
+ fallocate.c \
file.c \
find.c \
fsck.c \
diff --git a/daemon/fallocate.c b/daemon/fallocate.c
new file mode 100644
index 00000000..47e84c69
--- /dev/null
+++ b/daemon/fallocate.c
@@ -0,0 +1,59 @@
+/* libguestfs - the guestfsd daemon
+ * Copyright (C) 2009 Red Hat Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+#include <config.h>
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <fcntl.h>
+
+#include "daemon.h"
+#include "actions.h"
+
+int
+do_fallocate (char *path, int len)
+{
+ int fd, r;
+
+ NEED_ROOT (-1);
+ ABS_PATH (path, -1);
+
+ CHROOT_IN;
+ fd = open (path, O_WRONLY | O_CREAT | O_TRUNC | O_NOCTTY, 0666);
+ CHROOT_OUT;
+ if (fd == -1) {
+ reply_with_perror (path);
+ return -1;
+ }
+
+ r = posix_fallocate (fd, 0, len);
+ if (r == -1) {
+ reply_with_perror ("posix_fallocate: %s", path);
+ close (fd);
+ return -1;
+ }
+
+ if (close (fd) == -1) {
+ reply_with_perror ("close: %s", path);
+ return -1;
+ }
+
+ return 0;
+}
diff --git a/po/POTFILES.in b/po/POTFILES.in
index fc6c9f02..c7be2383 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -13,6 +13,7 @@ daemon/dmesg.c
daemon/dropcaches.c
daemon/du.c
daemon/ext2.c
+daemon/fallocate.c
daemon/file.c
daemon/find.c
daemon/fsck.c
diff --git a/src/MAX_PROC_NR b/src/MAX_PROC_NR
index de8febe1..fb402ef6 100644
--- a/src/MAX_PROC_NR
+++ b/src/MAX_PROC_NR
@@ -1 +1 @@
-168
+169
diff --git a/src/generator.ml b/src/generator.ml
index 34721938..e30f5ebf 100755
--- a/src/generator.ml
+++ b/src/generator.ml
@@ -3187,6 +3187,20 @@ The C<-f> option removes the link (C<linkname>) if it exists already.");
"\
This command reads the target of a symbolic link.");
+ ("fallocate", (RErr, [String "path"; Int "len"]), 169, [],
+ [InitBasicFS, Always, TestOutputStruct (
+ [["fallocate"; "/a"; "1000000"];
+ ["stat"; "/a"]], [CompareWithInt ("size", 1_000_000)])],
+ "preallocate a file in the guest filesystem",
+ "\
+This command preallocates a file (containing zero bytes) named
+C<path> of size C<len> bytes. If the file exists already, it
+is overwritten.
+
+Do not confuse this with the guestfish-specific
+C<alloc> command which allocates a file in the host and
+attaches it as a device.");
+
]
let all_functions = non_daemon_functions @ daemon_functions