diff options
author | Richard Jones <rjones@redhat.com> | 2009-04-30 19:28:54 +0100 |
---|---|---|
committer | Richard Jones <rjones@redhat.com> | 2009-04-30 19:28:54 +0100 |
commit | 62df226f26bd6ac3c481a7790eb89d760d2f0386 (patch) | |
tree | 617a5a436598902b2239d67535925520c20a6e6e /daemon | |
parent | 2a42bec2c5ee521f29179a5aab713f5a9ca2c3b8 (diff) | |
download | libguestfs-62df226f26bd6ac3c481a7790eb89d760d2f0386.tar.gz libguestfs-62df226f26bd6ac3c481a7790eb89d760d2f0386.tar.xz libguestfs-62df226f26bd6ac3c481a7790eb89d760d2f0386.zip |
Added 'zero' command to wipe partition tables and superblocks.
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/zero.c | 52 |
4 files changed, 81 insertions, 0 deletions
diff --git a/daemon/Makefile.am b/daemon/Makefile.am index 91237e23..c2c4a118 100644 --- a/daemon/Makefile.am +++ b/daemon/Makefile.am @@ -41,6 +41,7 @@ guestfsd_SOURCES = \ sync.c \ tar.c \ upload.c \ + zero.c \ ../src/guestfs_protocol.h \ ../src/guestfs_protocol.c diff --git a/daemon/actions.h b/daemon/actions.h index 74555862..501e3377 100644 --- a/daemon/actions.h +++ b/daemon/actions.h @@ -105,3 +105,4 @@ extern char *do_get_e2label (const char *device); extern int do_set_e2uuid (const char *device, const char *uuid); extern char *do_get_e2uuid (const char *device); extern int do_fsck (const char *fstype, const char *device); +extern int do_zero (const char *device); diff --git a/daemon/stubs.c b/daemon/stubs.c index 9e0ce559..937913f3 100644 --- a/daemon/stubs.c +++ b/daemon/stubs.c @@ -2103,6 +2103,30 @@ done: xdr_free ((xdrproc_t) xdr_guestfs_fsck_args, (char *) &args); } +static void zero_stub (XDR *xdr_in) +{ + int r; + struct guestfs_zero_args args; + const char *device; + + memset (&args, 0, sizeof args); + + if (!xdr_guestfs_zero_args (xdr_in, &args)) { + reply_with_error ("%s: daemon failed to decode procedure arguments", "zero"); + return; + } + device = args.device; + + r = do_zero (device); + if (r == -1) + /* do_zero has already called reply_with_error */ + goto done; + + reply (NULL, NULL); +done: + xdr_free ((xdrproc_t) xdr_guestfs_zero_args, (char *) &args); +} + void dispatch_incoming_message (XDR *xdr_in) { switch (proc_nr) { @@ -2358,6 +2382,9 @@ void dispatch_incoming_message (XDR *xdr_in) case GUESTFS_PROC_FSCK: fsck_stub (xdr_in); break; + case GUESTFS_PROC_ZERO: + zero_stub (xdr_in); + break; default: reply_with_error ("dispatch_incoming_message: unknown procedure number %d", proc_nr); } diff --git a/daemon/zero.c b/daemon/zero.c new file mode 100644 index 00000000..2c20abc3 --- /dev/null +++ b/daemon/zero.c @@ -0,0 +1,52 @@ +/* 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_zero (const char *device) +{ + int fd, i; + char buf[4096]; + + IS_DEVICE (device, -1); + + fd = open (device, O_WRONLY); + if (fd == -1) { + reply_with_perror ("%s", device); + return -1; + } + + memset (buf, 0, sizeof buf); + + for (i = 0; i < 32; ++i) + (void) write (fd, buf, sizeof buf); + + close (fd); + + return 0; +} |