summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2008-11-16 01:28:01 +0000
committerpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2008-11-16 01:28:01 +0000
commitfd8cf5088ad9d355baa5bfad15617b0f2459a7a9 (patch)
tree19effabc97123de0838c12226c19a79c00d784e9
parentd7445458fbee6a0939be1f1560b01e138b7767af (diff)
downloadnuttx-fd8cf5088ad9d355baa5bfad15617b0f2459a7a9.tar.gz
nuttx-fd8cf5088ad9d355baa5bfad15617b0f2459a7a9.tar.bz2
nuttx-fd8cf5088ad9d355baa5bfad15617b0f2459a7a9.zip
Fix a FAT mount bug
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@1249 42af7a65-404d-4744-a932-0658087f49c3
-rw-r--r--nuttx/ChangeLog6
-rw-r--r--nuttx/Documentation/NuttX.html6
-rw-r--r--nuttx/fs/fat/fs_fat32util.c40
3 files changed, 30 insertions, 22 deletions
diff --git a/nuttx/ChangeLog b/nuttx/ChangeLog
index 04d47cfc1..ad48012d8 100644
--- a/nuttx/ChangeLog
+++ b/nuttx/ChangeLog
@@ -548,10 +548,12 @@
no longer have to be the same.
* Add a loop device that converts a file into a block device.
* Each NSH command can not be disabled through a configuration setting. All of these
- settings make the configuration of NSH potentially complex but also allow it to squeeze
- into very small memory footprints.
+ settings make the configuration of NSH potentially complex but also allow it to squeeze
+ into very small memory footprints.
* Added a block to character (BCH) driver. This is kind of the reverse of the loop
device; it allows you access a block device like a character device.
* Added strcasecmp() and strncasecmp()
* NSH: Added the 'dd' command
* NSH: Added the 'losetup' command
+ * Fixed a FAT bug: After recent changes, it would mount a (invalid) FAT file system
+ even if the medium is not formatted!
diff --git a/nuttx/Documentation/NuttX.html b/nuttx/Documentation/NuttX.html
index 6bb9c58c3..a1bd82f02 100644
--- a/nuttx/Documentation/NuttX.html
+++ b/nuttx/Documentation/NuttX.html
@@ -1191,12 +1191,14 @@ nuttx-0.3.18 2008-xx-xx Gregory Nutt &lt;spudmonkey@racsa.co.cr&gt;
no longer have to be the same.
* Add a loop device that converts a file into a block device.
* Each NSH command can not be disabled through a configuration setting. All of these
- settings make the configuration of NSH potentially complex but also allow it to squeeze
- into very small memory footprints.
+ settings make the configuration of NSH potentially complex but also allow it to squeeze
+ into very small memory footprints.
* Added a block to character (BCH) driver. This is kind of the reverse of the loop
device; it allows you access a block device like a character device.
* NSH: Added the 'dd' command
* NSH: Added the 'losetup' command
+ * Fixed a FAT bug: After recent changes, it would mount a (invalid) FAT file system
+ even if the medium is not formatted!
pascal-0.1.3 2008-xx-xx Gregory Nutt &lt;spudmonkey@racsa.co.cr&gt;
diff --git a/nuttx/fs/fat/fs_fat32util.c b/nuttx/fs/fat/fs_fat32util.c
index 6c96746cc..dc1404f9e 100644
--- a/nuttx/fs/fat/fs_fat32util.c
+++ b/nuttx/fs/fat/fs_fat32util.c
@@ -314,10 +314,10 @@ static int fat_checkbootrecord(struct fat_mountpt_s *fs)
fs->fs_rootentcnt = MBR_GETROOTENTCNT(fs->fs_buffer);
if (fs->fs_rootentcnt != 0)
- {
+ {
notfat32 = TRUE; /* Must be zero for FAT32 */
rootdirsectors = (32 * fs->fs_rootentcnt + fs->fs_hwsectorsize - 1) / fs->fs_hwsectorsize;
- }
+ }
/* Determine the number of sectors in a FAT. */
@@ -655,28 +655,32 @@ int fat_mount(struct fat_mountpt_s *fs, boolean writeable)
* partition and see if we can find the boot record there.
*/
- if (PART1_GETTYPE(fs->fs_buffer) != 0)
+ if (PART1_GETTYPE(fs->fs_buffer) == 0)
{
- /* There appears to be a partition, get the sector number of the
- * partition (LBA)
- */
+ fdbg("No MBR or partition\n");
+ goto errout_with_buffer;
+ }
- fs->fs_fatbase = PART1_GETSTARTSECTOR(fs->fs_buffer);
+ /* There appears to be a partition, get the sector number of the
+ * partition (LBA)
+ */
- /* Read the new candidate boot sector */
+ fs->fs_fatbase = PART1_GETSTARTSECTOR(fs->fs_buffer);
- ret = fat_hwread(fs, fs->fs_buffer, fs->fs_fatbase, 1);
- if (ret < 0)
- {
- goto errout_with_buffer;
- }
+ /* Read the new candidate boot sector */
+
+ ret = fat_hwread(fs, fs->fs_buffer, fs->fs_fatbase, 1);
+ if (ret < 0)
+ {
+ goto errout_with_buffer;
+ }
- /* Check if this is a boot record */
+ /* Check if this is a boot record */
- if (fat_checkbootrecord(fs) != OK)
- {
- goto errout_with_buffer;
- }
+ if (fat_checkbootrecord(fs) != OK)
+ {
+ fdbg("No valid MBR\n");
+ goto errout_with_buffer;
}
}