diff options
author | patacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3> | 2008-09-07 22:27:17 +0000 |
---|---|---|
committer | patacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3> | 2008-09-07 22:27:17 +0000 |
commit | b827730a940a06038b95e30f183824ca6123966b (patch) | |
tree | 041bcc53020abb575168c1597cb106aee4ff53dc | |
parent | 2831d048c995917abbf96226f3a23efff3d01d0c (diff) | |
download | px4-nuttx-b827730a940a06038b95e30f183824ca6123966b.tar.gz px4-nuttx-b827730a940a06038b95e30f183824ca6123966b.tar.bz2 px4-nuttx-b827730a940a06038b95e30f183824ca6123966b.zip |
Fixed critical FAT bugs
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@894 42af7a65-404d-4744-a932-0658087f49c3
-rw-r--r-- | nuttx/ChangeLog | 5 | ||||
-rw-r--r-- | nuttx/Documentation/NuttX.html | 3 | ||||
-rw-r--r-- | nuttx/fs/fat/fs_fat32.c | 2 | ||||
-rw-r--r-- | nuttx/fs/fat/fs_fat32util.c | 30 |
4 files changed, 29 insertions, 11 deletions
diff --git a/nuttx/ChangeLog b/nuttx/ChangeLog index 8f774358d..bb4f3ac04 100644 --- a/nuttx/ChangeLog +++ b/nuttx/ChangeLog @@ -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!! diff --git a/nuttx/Documentation/NuttX.html b/nuttx/Documentation/NuttX.html index 04704af51..e70fd88ce 100644 --- a/nuttx/Documentation/NuttX.html +++ b/nuttx/Documentation/NuttX.html @@ -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> diff --git a/nuttx/fs/fat/fs_fat32.c b/nuttx/fs/fat/fs_fat32.c index 6c4f66743..47290642d 100644 --- a/nuttx/fs/fat/fs_fat32.c +++ b/nuttx/fs/fat/fs_fat32.c @@ -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 */ diff --git a/nuttx/fs/fat/fs_fat32util.c b/nuttx/fs/fat/fs_fat32util.c index c70c4cb1e..c6680b6f0 100644 --- a/nuttx/fs/fat/fs_fat32util.c +++ b/nuttx/fs/fat/fs_fat32util.c @@ -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; } |