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.
This commit is contained in:
Augustin Cavalier
2018-10-06 14:48:00 -04:00
parent 906af5f58c
commit 489f56e58b
+8 -8
View File
@@ -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));