diff options
author | Richard W.M. Jones <rjones@redhat.com> | 2009-05-14 23:47:17 +0100 |
---|---|---|
committer | Richard W.M. Jones <rjones@redhat.com> | 2009-05-14 23:47:17 +0100 |
commit | d901cc916102f1aaccfb73396b48aa303e5b8cd7 (patch) | |
tree | 7c2fd470088874ab99b5922393327170e653cf01 /daemon | |
parent | 4aa4ecc380edc509aba886417c67d9c39ab51c9a (diff) | |
download | libguestfs-d901cc916102f1aaccfb73396b48aa303e5b8cd7.tar.gz libguestfs-d901cc916102f1aaccfb73396b48aa303e5b8cd7.tar.xz libguestfs-d901cc916102f1aaccfb73396b48aa303e5b8cd7.zip |
Add support for zerofree command.
Diffstat (limited to 'daemon')
-rw-r--r-- | daemon/Makefile.am | 1 | ||||
-rw-r--r-- | daemon/actions.h | 1 | ||||
-rw-r--r-- | daemon/stubs.c | 27 | ||||
-rw-r--r-- | daemon/zerofree.c | 48 |
4 files changed, 77 insertions, 0 deletions
diff --git a/daemon/Makefile.am b/daemon/Makefile.am index 8460d44d..d6ae6c38 100644 --- a/daemon/Makefile.am +++ b/daemon/Makefile.am @@ -50,6 +50,7 @@ guestfsd_SOURCES = \ tar.c \ upload.c \ zero.c \ + zerofree.c \ ../src/guestfs_protocol.h \ ../src/guestfs_protocol.c diff --git a/daemon/actions.h b/daemon/actions.h index f4678f8c..37ec1253 100644 --- a/daemon/actions.h +++ b/daemon/actions.h @@ -117,3 +117,4 @@ extern int do_equal (const char *file1, const char *file2); extern char **do_strings (const char *path); extern char **do_strings_e (const char *encoding, const char *path); extern char *do_hexdump (const char *path); +extern int do_zerofree (const char *device); diff --git a/daemon/stubs.c b/daemon/stubs.c index 0e5b3513..212634fd 100644 --- a/daemon/stubs.c +++ b/daemon/stubs.c @@ -2397,6 +2397,30 @@ done: xdr_free ((xdrproc_t) xdr_guestfs_hexdump_args, (char *) &args); } +static void zerofree_stub (XDR *xdr_in) +{ + int r; + struct guestfs_zerofree_args args; + const char *device; + + memset (&args, 0, sizeof args); + + if (!xdr_guestfs_zerofree_args (xdr_in, &args)) { + reply_with_error ("%s: daemon failed to decode procedure arguments", "zerofree"); + return; + } + device = args.device; + + r = do_zerofree (device); + if (r == -1) + /* do_zerofree has already called reply_with_error */ + goto done; + + reply (NULL, NULL); +done: + xdr_free ((xdrproc_t) xdr_guestfs_zerofree_args, (char *) &args); +} + void dispatch_incoming_message (XDR *xdr_in) { switch (proc_nr) { @@ -2688,6 +2712,9 @@ void dispatch_incoming_message (XDR *xdr_in) case GUESTFS_PROC_HEXDUMP: hexdump_stub (xdr_in); break; + case GUESTFS_PROC_ZEROFREE: + zerofree_stub (xdr_in); + break; default: reply_with_error ("dispatch_incoming_message: unknown procedure number %d", proc_nr); } diff --git a/daemon/zerofree.c b/daemon/zerofree.c new file mode 100644 index 00000000..b44965a0 --- /dev/null +++ b/daemon/zerofree.c @@ -0,0 +1,48 @@ +/* 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 <fcntl.h> +#include <unistd.h> + +#include "daemon.h" +#include "actions.h" + +int +do_zerofree (const char *device) +{ + char *err; + int r; + + IS_DEVICE (device, -1); + + r = command (NULL, &err, "/usr/sbin/zerofree", device, NULL); + if (r == -1) { + reply_with_error ("zerofree: %s: %s", device, err); + free (err); + return -1; + } + + free (err); + + return 0; +} |