From 266a5fc635135a9ffaa8683da1ec03aae1553b7b Mon Sep 17 00:00:00 2001
From: Andreas Bombe <aeb@debian.org>
Date: Fri, 20 Feb 2015 03:19:28 +0100
Subject: [PATCH 05/14] mkfs.fat: Allow 0xF0 to be specified as media byte

Let the -M option accept 0xF0, which should be the proper descriptor
byte for 3.5" 1.44 MB and 2.88 MB floppies.

Also split the error reporting for -M between badly formatted and
invalid numbers.

Signed-off-by: Andreas Bombe <aeb@debian.org>
---
 manpages/de/mkfs.fat.de.8    |  4 ++--
 manpages/en/mkfs.fat.8       |  2 +-
 manpages/po/de/mkfs.fat.8.po |  6 +++---
 manpages/pot/mkfs.fat.8.pot  |  6 +++---
 src/mkfs.fat.c               | 12 ++++++++----
 5 files changed, 17 insertions(+), 13 deletions(-)

diff --git a/manpages/de/mkfs.fat.de.8 b/manpages/de/mkfs.fat.de.8
index 5a6eb1a..2386410 100644
--- a/manpages/de/mkfs.fat.de.8
+++ b/manpages/de/mkfs.fat.de.8
@@ -121,8 +121,8 @@ return\-line feed combinations, and tabs have been expanded. If the filename
 is a hyphen (\-), the text is taken from standard input.
 .IP "\fB\-M\fP \fIFAT\-media\-type\fP" 4
 Specify the media type to be stored in the FAT boot sector. This value is
-usually 0xF8 for hard disks and has a value from 0xF9 to 0xFF for floppies
-or partitions to be used for floppy emulation.
+usually 0xF8 for hard disks and is 0xF0 or a value from 0xF9 to 0xFF for
+floppies or partitions to be used for floppy emulation.
 .IP "\fB\-n\fP \fIvolume\-name\fP" 4
 Sets the volume name (label) of the filesystem. The volume name can be up to
 11 characters long. The default is no label.
diff --git a/manpages/en/mkfs.fat.8 b/manpages/en/mkfs.fat.8
index 9dd8115..81bf461 100644
--- a/manpages/en/mkfs.fat.8
+++ b/manpages/en/mkfs.fat.8
@@ -58,7 +58,7 @@ Read the bad blocks list from \fIfilename\fR.
 .IP "\fB\-m\fR \fImessage-file\fR" 4
 Sets the message the user receives on attempts to boot this filesystem without having properly installed an operating system. The message file must not exceed 418 bytes once line feeds have been converted to carriage return-line feed combinations, and tabs have been expanded. If the filename is a hyphen (-), the text is taken from standard input.
 .IP "\fB\-M\fR \fIFAT-media-type\fR" 4
-Specify the media type to be stored in the FAT boot sector. This value is usually 0xF8 for hard disks and has a value from 0xF9 to 0xFF for floppies or partitions to be used for floppy emulation.
+Specify the media type to be stored in the FAT boot sector. This value is usually 0xF8 for hard disks and is 0xF0 or a value from 0xF9 to 0xFF for floppies or partitions to be used for floppy emulation.
 .IP "\fB\-n\fR \fIvolume-name\fR" 4
 Sets the volume name (label) of the filesystem. The volume name can be up to 11 characters long. The default is no label.
 .IP "\fB\-r\fR \fIroot-dir-entries\fR" 4
diff --git a/manpages/po/de/mkfs.fat.8.po b/manpages/po/de/mkfs.fat.8.po
index 2531179..360fe16 100644
--- a/manpages/po/de/mkfs.fat.8.po
+++ b/manpages/po/de/mkfs.fat.8.po
@@ -3,7 +3,7 @@
 msgid ""
 msgstr ""
 "Project-Id-Version: dosfstools VERSION\n"
-"POT-Creation-Date: 2014-11-12 00:52+0100\n"
+"POT-Creation-Date: 2015-02-20 03:31+0100\n"
 "PO-Revision-Date: 2013-06-06 09:34+0300\n"
 "Last-Translator: Automatically generated\n"
 "Language-Team: none\n"
@@ -354,8 +354,8 @@ msgstr ""
 #: en/mkfs.fat.8:62
 msgid ""
 "Specify the media type to be stored in the FAT boot sector. This value is "
-"usually 0xF8 for hard disks and has a value from 0xF9 to 0xFF for floppies "
-"or partitions to be used for floppy emulation."
+"usually 0xF8 for hard disks and is 0xF0 or a value from 0xF9 to 0xFF for "
+"floppies or partitions to be used for floppy emulation."
 msgstr ""
 
 #. type: IP
diff --git a/manpages/pot/mkfs.fat.8.pot b/manpages/pot/mkfs.fat.8.pot
index a6106bc..32486ea 100644
--- a/manpages/pot/mkfs.fat.8.pot
+++ b/manpages/pot/mkfs.fat.8.pot
@@ -7,7 +7,7 @@
 msgid ""
 msgstr ""
 "Project-Id-Version: dosfstools VERSION\n"
-"POT-Creation-Date: 2014-11-12 00:52+0100\n"
+"POT-Creation-Date: 2015-02-20 03:31+0100\n"
 "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
 "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
 "Language-Team: LANGUAGE <LL@li.org>\n"
@@ -357,8 +357,8 @@ msgstr ""
 #: en/mkfs.fat.8:62
 msgid ""
 "Specify the media type to be stored in the FAT boot sector. This value is "
-"usually 0xF8 for hard disks and has a value from 0xF9 to 0xFF for floppies "
-"or partitions to be used for floppy emulation."
+"usually 0xF8 for hard disks and is 0xF0 or a value from 0xF9 to 0xFF for "
+"floppies or partitions to be used for floppy emulation."
 msgstr ""
 
 #. type: IP
diff --git a/src/mkfs.fat.c b/src/mkfs.fat.c
index a3dff54..e6f9390 100644
--- a/src/mkfs.fat.c
+++ b/src/mkfs.fat.c
@@ -1569,10 +1569,14 @@ int main(int argc, char **argv)
 	    break;
 
 	case 'M':		/* M : FAT Media byte */
-	    fat_media_byte = (int) strtol (optarg, &tmp, 0);
-	    if (*tmp || fat_media_byte < 248 || fat_media_byte > 255) {
-		printf ("FAT Media byte must be between 0xF8 and 0xFF : %s\n", optarg);
-		usage ();
+	    fat_media_byte = (int)strtol(optarg, &tmp, 0);
+	    if (*tmp) {
+		printf("Bad number for media descriptor : %s\n", optarg);
+		usage();
+	    }
+	    if (fat_media_byte != 0xf0 && (fat_media_byte < 0xf8 || fat_media_byte > 0xff)) {
+		printf("FAT Media byte must either be between 0xF8 and 0xFF or be 0xF0 : %s\n", optarg);
+		usage();
 	    }
 	    break;
 
-- 
1.9.1

