1 /* libguestfs - the guestfsd daemon
2 * Copyright (C) 2009 Red Hat Inc.
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
35 mkfs (const char *fstype, const char *device,
36 const char **extra, size_t nr_extra)
38 const char *argv[MAX_ARGS];
47 /* mkfs.ntfs requires the -Q argument otherwise it writes zeroes
48 * to every block and does bad block detection, neither of which
49 * are useful behaviour for virtual devices.
51 if (STREQ (fstype, "ntfs"))
54 /* mkfs.reiserfs produces annoying interactive prompts unless you
55 * tell it to be quiet.
57 if (STREQ (fstype, "reiserfs"))
61 if (STREQ (fstype, "jfs"))
64 /* For GFS, GFS2, assume a single node. */
65 if (STREQ (fstype, "gfs") || STREQ (fstype, "gfs2")) {
67 argv[i++] = "lock_nolock";
68 /* The man page says this is default, but it doesn't seem to be: */
71 /* Don't ask questions: */
75 for (j = 0; j < nr_extra; ++j)
84 r = commandv (NULL, &err, argv);
86 reply_with_error ("%s: %s: %s", fstype, device, err);
96 do_mkfs (const char *fstype, const char *device)
98 return mkfs (fstype, device, NULL, 0);
102 do_mkfs_b (const char *fstype, int blocksize, const char *device)
104 const char *extra[2];
105 char blocksize_s[32];
107 snprintf (blocksize_s, sizeof blocksize_s, "%d", blocksize);
110 extra[1] = blocksize_s;
112 return mkfs (fstype, device, extra, 2);