From 489f56e58b6ee2d915f85c0c745189760658dbfa Mon Sep 17 00:00:00 2001 From: Augustin Cavalier Date: Sat, 6 Oct 2018 14:48:00 -0400 Subject: [PATCH] fat: If the filesystem extends past the end of the partition, mount read-only. instead of failing to mount at all. This matches behavior of Linux and the BSDs. Fixes #14539. --- src/add-ons/kernel/file_systems/fat/dosfs.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/add-ons/kernel/file_systems/fat/dosfs.c b/src/add-ons/kernel/file_systems/fat/dosfs.c index 3fb5f849d5..bfa61481ab 100644 --- a/src/add-ons/kernel/file_systems/fat/dosfs.c +++ b/src/add-ons/kernel/file_systems/fat/dosfs.c @@ -398,6 +398,14 @@ volume_init(int fd, uint8* buf, } } + /* check that the partition is large enough to contain the file system */ + if (geo != NULL + && vol->total_sectors > + geo->sectors_per_track * geo->cylinder_count + * geo->head_count) { + dprintf("dosfs: volume extends past end of partition, mounting read-only\n"); + vol->flags |= B_FS_IS_READONLY; + } // now we are convinced of the drive's validity @@ -595,14 +603,6 @@ mount_fat_disk(const char *path, fs_volume *_vol, const int flags, goto error1; } - /* check that the partition is large enough to contain the file system */ - if (vol->total_sectors > geo.sectors_per_track * geo.cylinder_count - * geo.head_count) { - dprintf("dosfs: volume extends past end of partition\n"); - err = B_PARTITION_TOO_SMALL; - goto error2; - } - vol->volume = _vol; vol->id = _vol->id; strncpy(vol->device, path, sizeof(vol->device));