Skip to contentSkip to conversation

fs: FAT: Add support for DOS 1.x formatted volumes

PATCH Superseded Conrad Meyer 2 participants 2 messages Apr 14, 2014 – Apr 15, 2014 VFAT/FAT/msdos filesystem

v6 of 8 Superseded Latest is v8 →

lore
Share & tools
lore
#0 lore raw

PATCH v6 1/1 fs: FAT: Add support for DOS 1.x formatted volumes

Add structure for parsed BPB information, struct fat_bios_param_block, and move all of the deserialization and validation logic from fat_fill_super() into fat_read_bpb().

Add a 'dos1xfloppy' mount option to infer DOS 2.x BIOS Parameter Block defaults from block device geometry for ancient floppies and floppy images, as a fall-back from the default BPB parsing logic.

When fat_read_bpb() finds an invalid FAT filesystem and dos1xfloppy is set, fall back to fat_read_static_bpb(). fat_read_static_bpb() validates that the entire BPB is zero, and that the floppy has a DOS-style 8086 code bootstrapping header. Then it fills in default BPB values from media size and a table.[0]

Media size is assumed to be static for archaic FAT volumes. See also:
[1].

Fixes kernel.org bug #42617.

[0]: https://en.wikipedia.org/wiki/File_Allocation_Table#Exceptions
[1]: http://www.win.tue.nl/~aeb/linux/fs/fat/fat-1.html

---
Changes since v5:
* Leave the bulk of sbi-> filling logic to the aptly named fat_fill_super()
* Create separate structure for deserialized BPB values
* fat_read_bpb() deserializes BPB from raw fat_boot_sector and performs validations
* fat_read_static_bpb() validates raw fat_boot_sector as dos1x and fills in BPB values from table

Thanks,
Conrad

---
 fs/fat/fat.h   |  28 ++++-
 fs/fat/inode.c | 316 +++++++++++++++++++++++++++++++++++++++++++--------------
 2 files changed, 267 insertions(+), 77 deletions(-)
fs/fat/fat.h +27 -1
index 7270bdb..bcb0d67 100644
@@ -52,7 +52,8 @@ struct fat_mount_options {
 		 usefree:1,	   /* Use free_clusters for FAT32 */
 		 tz_set:1,	   /* Filesystem timestamps' offset set */
 		 rodir:1,	   /* allow ATTR_RO for directory */
-		 discard:1;	   /* Issue discard requests on deletions */
+		 discard:1,	   /* Issue discard requests on deletions */
+		 dos1xfloppy:1;	   /* Assume default BPB for DOS 1.x floppies */
 };
 
 #define FAT_HASH_BITS	8
@@ -139,6 +140,31 @@ struct fat_slot_info {
 	struct buffer_head *bh;
 };
 
+/*
+ * A deserialized copy of the on-disk structure laid out in struct
+ * fat_boot_sector.
+ */
+struct fat_bios_param_block {
+	u16	fat_sector_size;
+	u8	fat_sec_per_clus;
+	u16	fat_reserved;
+	u8	fat_fats;
+	u16	fat_dir_entries;
+	u16	fat_sectors;
+	u16	fat_fat_length;
+	u32	fat_total_sect;
+
+	u8	fat16_state;
+	u32	fat16_vol_id;
+
+	u32	fat32_length;
+	u32	fat32_root_cluster;
+	u16	fat32_info_sector;
+	u8	fat32_state;
+	u32	fat32_vol_id;
+
+};
+
 static inline struct msdos_sb_info *MSDOS_SB(struct super_block *sb)
 {
 	return sb->s_fs_info;
fs/fat/inode.c +240 -76

452 lines not on this page · raw message

Signature · 1 line
1.9.0
maintainer
#1 lore raw
Quoted 44 lines · Conrad Meyer

Add structure for parsed BPB information, struct fat_bios_param_block, and move all of the deserialization and validation logic from fat_fill_super() into fat_read_bpb().

Add a 'dos1xfloppy' mount option to infer DOS 2.x BIOS Parameter Block defaults from block device geometry for ancient floppies and floppy images, as a fall-back from the default BPB parsing logic.

When fat_read_bpb() finds an invalid FAT filesystem and dos1xfloppy is set, fall back to fat_read_static_bpb(). fat_read_static_bpb() validates that the entire BPB is zero, and that the floppy has a DOS-style 8086 code bootstrapping header. Then it fills in default BPB values from media size and a table.[0]

Media size is assumed to be static for archaic FAT volumes. See also:
[1].

Fixes kernel.org bug #42617.

[0]: https://en.wikipedia.org/wiki/File_Allocation_Table#Exceptions
[1]: http://www.win.tue.nl/~aeb/linux/fs/fat/fat-1.html

---
Changes since v5:
* Leave the bulk of sbi-> filling logic to the aptly named fat_fill_super()
* Create separate structure for deserialized BPB values
* fat_read_bpb() deserializes BPB from raw fat_boot_sector and performs validations
* fat_read_static_bpb() validates raw fat_boot_sector as dos1x and fills in BPB values from table

Thanks,
Conrad

---
 fs/fat/fat.h   |  28 ++++-
 fs/fat/inode.c | 316 +++++++++++++++++++++++++++++++++++++++++++--------------
 2 files changed, 267 insertions(+), 77 deletions(-)
fs/fat/fat.h +0 -0
index 7270bdb..bcb0d67 100644

fs/fat/fat.h struct fat_mount_options { · line 57

Quoted 7 lines
fs/fat/fat.h +2 -1
@@ -52,7 +52,8 @@ struct fat_mount_options {
 		 usefree:1,	   /* Use free_clusters for FAT32 */
 		 tz_set:1,	   /* Filesystem timestamps' offset set */
 		 rodir:1,	   /* allow ATTR_RO for directory */
-		 discard:1;	   /* Issue discard requests on deletions */
+		 discard:1,	   /* Issue discard requests on deletions */
+		 dos1xfloppy:1;	   /* Assume default BPB for DOS 1.x floppies */
 };

OK. Looks good basically.

Another one I am also forgetting. Need to update show_options() and Documents/fs/vfat.txt for new option.

Thanks.

Signature · 1 line
OGAWA Hirofumi <[email protected]>