>From 4ccaf11cb04d69763e390d4df5d6eecf9270e2ca Mon Sep 17 00:00:00 2001 From: Richard Jones Date: Sun, 8 Nov 2009 11:57:02 +0000 Subject: [PATCH] NTFS: Invoke mkfs ntfs with -Q option. By default mkfs.ntfs writes zeroes and does bad block detection over the whole disk. This is slow and unnecessary in the virtual case. Pass -Q option to avoid this. --- daemon/mkfs.c | 58 ++++++++++++++++++++++++++++++++++++++++---------------- 1 files changed, 41 insertions(+), 17 deletions(-) diff --git a/daemon/mkfs.c b/daemon/mkfs.c index faeeaeb..84b7298 100644 --- a/daemon/mkfs.c +++ b/daemon/mkfs.c @@ -29,15 +29,40 @@ #include "daemon.h" #include "actions.h" -int -do_mkfs (const char *fstype, const char *device) +#define MAX_ARGS 16 + +static int +mkfs (const char *fstype, const char *device, + const char **extra, size_t nr_extra) { - char *err; + const char *argv[MAX_ARGS]; + size_t i = 0, j; int r; + char *err; + + argv[i++] = "/sbin/mkfs"; + argv[i++] = "-t"; + argv[i++] = fstype; + + /* mkfs.ntfs requires the -Q argument otherwise it writes zeroes + * to every block and does bad block detection, neither of which + * are useful behaviour for virtual devices. + */ + if (strcmp (fstype, "ntfs") == 0) + argv[i++] = "-Q"; - r = command (NULL, &err, "/sbin/mkfs", "-t", fstype, device, NULL); + for (j = 0; j < nr_extra; ++j) + argv[i++] = extra[j]; + + argv[i++] = device; + argv[i++] = NULL; + + if (i > MAX_ARGS) + abort (); + + r = commandv (NULL, &err, argv); if (r == -1) { - reply_with_error ("mkfs: %s", err); + reply_with_error ("mkfs: %s: %s: %s", fstype, device, err); free (err); return -1; } @@ -47,22 +72,21 @@ do_mkfs (const char *fstype, const char *device) } int -do_mkfs_b (const char *fstype, int blocksize, const char *device) +do_mkfs (const char *fstype, const char *device) { - char *err; - int r; + return mkfs (fstype, device, NULL, 0); +} +int +do_mkfs_b (const char *fstype, int blocksize, const char *device) +{ + const char *extra[2]; char blocksize_s[32]; + snprintf (blocksize_s, sizeof blocksize_s, "%d", blocksize); - r = command (NULL, &err, - "/sbin/mkfs", "-t", fstype, "-b", blocksize_s, device, NULL); - if (r == -1) { - reply_with_error ("mkfs_b: %s", err); - free (err); - return -1; - } + extra[0] = "-b"; + extra[1] = blocksize_s; - free (err); - return 0; + return mkfs (fstype, device, extra, 2); } -- 1.6.5.rc2