Fixed critical FAT bugs

git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@894 42af7a65-404d-4744-a932-0658087f49c3
This commit is contained in:
patacongo 2008-09-07 22:27:17 +00:00
parent cd1ddef34a
commit 34cfa3ead5
4 changed files with 29 additions and 11 deletions

View File

@ -449,11 +449,14 @@
* NSH: Add ping command
* Correct IP checksum calculation in ICMP and UDP message send logic.
* NSH: Created an HTML document and a more detailed README file describing NSH.
* Added basic TFTP client logic (netutils/tftpc). Untested as of initial check-in.
* Added basic TFTP client logic (netutils/tftpc).
* NSH: Add get and put commands to support TFTP get and put operations.
* NSH: Added a mkrd command that will create a RAMDISK that can be formatted
and mounted.
* Corrected a critical bug that prevent recvfrom from receiving packets from
any remote UDP port.
* NSH: Add hexadecimal dump command (xd)
* Fixed several critical bugs with regard to fat reading and writing and FAT12
accesses. Basically the FAT FS only worked with my tiny test files and test
cases. A lot of stronger FAT tested is needed!!

View File

@ -1083,6 +1083,9 @@ nuttx-0.3.14 2008-xx-xx Gregory Nutt <spudmonkey@racsa.co.cr>
* Corrected a critical bug that prevent recvfrom from receiving packets from
any remote UDP port.
* NSH: Add hexadecimal dump command (xd)
* Fixed several critical bugs with regard to fat reading and writing and FAT12
accesses. Basically the FAT FS only worked with my tiny test files and test
cases. A lot of stronger FAT tested is needed!!
pascal-0.1.3 2008-xx-xx Gregory Nutt <spudmonkey@racsa.co.cr>

View File

@ -579,7 +579,7 @@ static ssize_t fat_read(FAR struct file *filep, char *buffer, size_t buflen)
{
/* Find the next cluster in the FAT. */
cluster = fat_getcluster(fs, cluster);
cluster = fat_getcluster(fs, ff->ff_currentcluster);
if (cluster < 2 || cluster >= fs->fs_nclusters)
{
ret = -EINVAL; /* Not the right error */

View File

@ -986,11 +986,11 @@ ssize_t fat_getcluster(struct fat_mountpt_s *fs, uint32 clusterno)
/****************************************************************************
* Name: fat_putcluster
*
* Desciption: Write a new cluster start sector into the FAT
* Desciption: Write a new cluster into the FAT
*
****************************************************************************/
int fat_putcluster(struct fat_mountpt_s *fs, uint32 clusterno, size_t startsector)
int fat_putcluster(struct fat_mountpt_s *fs, uint32 clusterno, size_t nextcluster)
{
/* Verify that the cluster number is within range. Zero erases the cluster. */
@ -1021,21 +1021,26 @@ int fat_putcluster(struct fat_mountpt_s *fs, uint32 clusterno, size_t startsecto
if (fat_fscacheread(fs, fatsector)< 0)
{
/* Read error */
break;
}
/* Output the LS byte first handling the 12-bit alignment within
/* Get the LS byte first handling the 12-bit alignment within
* the 16-bits
*/
fatindex = fatoffset & SEC_NDXMASK(fs);
if ((clusterno & 1) != 0)
{
value = (fs->fs_buffer[fatindex] & 0x0f) | startsector << 4;
/* Save the LS four bits of the next cluster */
value = (fs->fs_buffer[fatindex] & 0x0f) | nextcluster << 4;
}
else
{
value = (ubyte)startsector;
/* Save the LS eight bits of the next cluster */
value = (ubyte)nextcluster;
}
fs->fs_buffer[fatindex] = value;
@ -1069,11 +1074,15 @@ int fat_putcluster(struct fat_mountpt_s *fs, uint32 clusterno, size_t startsecto
if ((clusterno & 1) != 0)
{
value = (ubyte)(startsector >> 4);
/* Save the MS eight bits of the next cluster */
value = (ubyte)(nextcluster >> 4);
}
else
{
value = (fs->fs_buffer[fatindex] & 0xf0) | (startsector & 0x0f);
/* Save the MS four bits of the next cluster */
value = (fs->fs_buffer[fatindex] & 0xf0) | ((nextcluster >> 8) & 0x0f);
}
fs->fs_buffer[fatindex] = value;
}
@ -1090,7 +1099,7 @@ int fat_putcluster(struct fat_mountpt_s *fs, uint32 clusterno, size_t startsecto
/* Read error */
break;
}
FAT_PUTFAT16(fs->fs_buffer, fatindex, startsector & 0xffff);
FAT_PUTFAT16(fs->fs_buffer, fatindex, nextcluster & 0xffff);
}
break;
@ -1105,7 +1114,7 @@ int fat_putcluster(struct fat_mountpt_s *fs, uint32 clusterno, size_t startsecto
/* Read error */
break;
}
FAT_PUTFAT32(fs->fs_buffer, fatindex, startsector & 0x0fffffff);
FAT_PUTFAT32(fs->fs_buffer, fatindex, nextcluster & 0x0fffffff);
}
break;
@ -1213,16 +1222,19 @@ sint32 fat_extendchain(struct fat_mountpt_s *fs, uint32 cluster)
if (startsector < 0)
{
/* An error occurred, return the error value */
return startsector;
}
else if (startsector < 2)
{
/* Oops.. this cluster does not exist. */
return 0;
}
else if (startsector < fs->fs_nclusters)
{
/* It is already followed by next cluster */
return startsector;
}