[Libguestfs] [PATCH v3 1/2] NEW API: add a new api wipefs

Wanlong Gao gaowanlong at cn.fujitsu.com
Wed Feb 8 05:32:47 UTC 2012


Add the new api wipefs to erase the filesystem signatures
on a device but now erase any data.

Signed-off-by: Wanlong Gao <gaowanlong at cn.fujitsu.com>
---
 TODO                           |    2 --
 daemon/zero.c                  |   17 +++++++++++++++++
 generator/generator_actions.ml |   14 ++++++++++++++
 src/MAX_PROC_NR                |    2 +-
 4 files changed, 32 insertions(+), 3 deletions(-)

diff --git a/TODO b/TODO
index 3adb740..b9a4ee9 100644
--- a/TODO
+++ b/TODO
@@ -318,8 +318,6 @@ Display the structure of an image file as a PS.
 Greater use of blkid / libblkid
 -------------------------------
 
-guestfs_zero should use wipefs.  See wipefs(8).
-
 There are various useful functions in libblkid for listing partitions,
 devices etc which we are essentially duplicating in the daemon.  It
 would make more sense to just use libblkid for this.
diff --git a/daemon/zero.c b/daemon/zero.c
index 398f844..22a65c4 100644
--- a/daemon/zero.c
+++ b/daemon/zero.c
@@ -73,6 +73,23 @@ do_zero (const char *device)
 }
 
 int
+do_wipefs (const char *device)
+{
+  int r;
+  char *err = NULL;
+
+  const char *wipefs[] = {"wipefs", "-a", device, NULL};
+  r = commandv (NULL, &err, wipefs);
+  if (r == -1) {
+    reply_with_error ("%s", err);
+    free (err);
+    return -1;
+  }
+  free (err);
+  return 0;
+}
+
+int
 do_zero_device (const char *device)
 {
   int64_t ssize = do_blockdev_getsize64 (device);
diff --git a/generator/generator_actions.ml b/generator/generator_actions.ml
index 3a7be79..b0d0629 100644
--- a/generator/generator_actions.ml
+++ b/generator/generator_actions.ml
@@ -6651,6 +6651,20 @@ This option may not be specified at the same time as the C<correct> option.
 
 =back");
 
+  ("wipefs", (RErr, [Device "device"], []), 305, [Progress],
+   [InitBasicFSonLVM, Always, TestRun (
+      [["wipefs"; "/dev/VG/LV"]])],
+   "wipe a filesystem signature from a device",
+   "\
+This command can  erase filesystem or raid signatures (magic strings) from
+the specified C<device> to make the filesystem invisible for libblkid.
+This does not erase the filesystem itself nor any other data from the C<device>.
+Compare with C<guestfs_zero> which just zeroes the first few blocks of a
+device, contained the partitions on the device, but this C<guestfs_wipefs>
+can't erase the partitions of a device.
+
+=back");
+
 ]
 
 let all_functions = non_daemon_functions @ daemon_functions
diff --git a/src/MAX_PROC_NR b/src/MAX_PROC_NR
index 873b744..67d04b9 100644
--- a/src/MAX_PROC_NR
+++ b/src/MAX_PROC_NR
@@ -1 +1 @@
-304
+305
-- 
1.7.9




More information about the Libguestfs mailing list