From 48fcadd44cec578e9dcd4af44e6596714e3086c7 Mon Sep 17 00:00:00 2001 From: John Scipione Date: Wed, 5 Feb 2014 20:34:14 -0500 Subject: [PATCH] exfat: recheck device size is big enough to hold fs I didn't mean to omit this check, I just need to save deviceSize below for get_default_volume_name() so that it will match the mount point name. Checked to make sure the calculation works on a 2GiB, 32GiB, and 128GiB (virtual) exfat volume. --- src/add-ons/kernel/file_systems/exfat/Volume.cpp | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/add-ons/kernel/file_systems/exfat/Volume.cpp b/src/add-ons/kernel/file_systems/exfat/Volume.cpp index 2868e8af6f..757f7cea84 100644 --- a/src/add-ons/kernel/file_systems/exfat/Volume.cpp +++ b/src/add-ons/kernel/file_systems/exfat/Volume.cpp @@ -334,6 +334,15 @@ Volume::Mount(const char* deviceName, uint32 flags) fEntriesPerBlock = (fBlockSize / sizeof(struct exfat_entry)); // check if the device size is large enough to hold the file system + off_t fileSystemSize; + status = opener.GetSize(&fileSystemSize); + if (status != B_OK) + return status; + + off_t deviceSize = (off_t)fSuperBlock.NumBlocks() << fSuperBlock.BlockShift(); + if (fileSystemSize < deviceSize) + return B_BAD_VALUE; + fBlockCache = opener.InitCache(fSuperBlock.NumBlocks(), fBlockSize); if (fBlockCache == NULL) return B_ERROR; @@ -363,11 +372,8 @@ Volume::Mount(const char* deviceName, uint32 flags) LabelVisitor visitor(this); iterator.Iterate(visitor); - if (fName[0] == '\0') { - off_t deviceSize = (off_t)fSuperBlock.NumBlocks() - << fSuperBlock.BlockShift(); + if (fName[0] == '\0') get_default_volume_name(deviceSize, fName, sizeof(fName)); - } return B_OK; }