[Libguestfs] [PATCH] mkfs: wipefs before we mkfs

Wanlong Gao
Thu, 16 Feb 2012 09:59:24 -0000

we wipe the filesystem signatures from device before do mkfs,
since we can't trust mkfs can remove the filesystem signature absolutely.

Signed-off-by: Wanlong Gao <gaowanlong at cn.fujitsu.com>
---
 daemon/mkfs.c |    9 +++++++++
 1 files changed, 9 insertions(+), 0 deletions(-)

diff --git a/daemon/mkfs.c b/daemon/mkfs.c
index 5475582..19224ec 100644
--- a/daemon/mkfs.c
+++ b/daemon/mkfs.c
@@ -181,6 +181,15 @@ do_mkfs_opts (const char *fstype, const char *device, int
blocksize,
   ADD_ARG (argv, i, device);
   ADD_ARG (argv, i, NULL);

+  /* we wipe the filesystem signatures from device before do mkfs,
+   * since we can't trust mkfs can remove the filesystem signature
absolutely.
+   */
+  if (do_wipefs (device)) {
+    reply_with_error ("%s: %s: %s", fstype, device, err);
+    free (err);
+    return -1;
+  }
+
   r = commandv (NULL, &err, argv);
   if (r == -1) {
     reply_with_error ("%s: %s: %s", fstype, device, err);
--
1.7.9