Index: uspace/app/mkexfat/mkexfat.c
===================================================================
--- uspace/app/mkexfat/mkexfat.c	(revision 9bbe54fde30f4c15a3e8748ec55f606e0ce54f71)
+++ uspace/app/mkexfat/mkexfat.c	(revision 0f225288ef9788287ec0fcc0e8997e8a8585189c)
@@ -144,4 +144,5 @@
 {
 	unsigned long fat_bytes;
+	unsigned long fat_cls;
 	aoff64_t const volume_bytes = (cfg->volume_count - FAT_SECTOR_START) *
 	    cfg->sector_size;
@@ -180,7 +181,13 @@
 	 * number of available clusters.
 	 */
-	cfg->total_clusters -= div_round_up((cfg->data_start_sector -
+	fat_cls = div_round_up((cfg->data_start_sector -
 	    FAT_SECTOR_START) * cfg->sector_size,
 	    cfg->cluster_size);
+	if (fat_cls >= cfg->total_clusters) {
+		/* Insufficient disk space on device */
+		cfg->total_clusters = 0;
+		return;
+	}
+	cfg->total_clusters -= fat_cls;
 
 	/* Compute the bitmap size */
@@ -821,5 +828,5 @@
 	cfg_print_info(&cfg);
 
-	if ((cfg.total_clusters - cfg.allocated_clusters) <= 2) {
+	if (cfg.total_clusters <= cfg.allocated_clusters + 2) {
 		printf(NAME ": Error, insufficient disk space on device.\n");
 		return 2;
@@ -897,4 +904,6 @@
 	}
 
+	printf(NAME ": Writing the boot sectors.\n");
+
 	rc = bootsec_write(service_id, &cfg);
 	if (rc != EOK) {
