+ /* Force mke2fs to create a filesystem, even if it thinks it
+ * shouldn't (RHBZ#690819).
+ */
+ if (STREQ (fstype, "ext2") || STREQ (fstype, "ext3") ||
+ STREQ (fstype, "ext4"))
+ argv[i++] = "-F";
+
+ /* 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 (STREQ (fstype, "ntfs"))
+ argv[i++] = "-Q";
+
+ /* mkfs.reiserfs produces annoying interactive prompts unless you
+ * tell it to be quiet.
+ */
+ if (STREQ (fstype, "reiserfs"))
+ argv[i++] = "-f";
+
+ /* Same for JFS. */
+ if (STREQ (fstype, "jfs"))
+ argv[i++] = "-f";
+
+ /* For GFS, GFS2, assume a single node. */
+ if (STREQ (fstype, "gfs") || STREQ (fstype, "gfs2")) {
+ argv[i++] = "-p";
+ argv[i++] = "lock_nolock";
+ /* The man page says this is default, but it doesn't seem to be: */
+ argv[i++] = "-j";
+ argv[i++] = "1";
+ /* Don't ask questions: */
+ argv[i++] = "-O";
+ }
+
+ /* Process blocksize parameter if set. */
+ if (optargs_bitmask & GUESTFS_MKFS_OPTS_BLOCKSIZE_BITMASK) {
+ if (blocksize <= 0 || !is_power_of_2 (blocksize)) {
+ reply_with_error ("block size must be > 0 and a power of 2");
+ return -1;
+ }
+
+ if (STREQ (fstype, "vfat") ||
+ STREQ (fstype, "msdos")) {
+ /* For VFAT map the blocksize into a cluster size. However we
+ * have to determine the block device sector size in order to do
+ * this.
+ */
+ int sectorsize = do_blockdev_getss (device);
+ if (sectorsize == -1)
+ return -1;
+
+ int sectors_per_cluster = blocksize / sectorsize;
+ if (sectors_per_cluster < 1 || sectors_per_cluster > 128) {
+ reply_with_error ("unsupported cluster size for %s filesystem (requested cluster size = %d, sector size = %d, trying sectors per cluster = %d)",
+ fstype, blocksize, sectorsize, sectors_per_cluster);
+ return -1;
+ }