fs: fat_write: fix the incorrect last cluster checking
authorWu, Josh <Josh.wu@atmel.com>
Thu, 8 May 2014 08:14:06 +0000 (16:14 +0800)
committerChanho Park <chanho61.park@samsung.com>
Thu, 6 Aug 2015 05:57:44 +0000 (14:57 +0900)
In fat_write.c, the last clust condition check is incorrect:

  if ((curclust >= 0xffffff8) || (curclust >= 0xfff8)) {
   ... ...
  }

For example, in FAT32 if curclust is 0x11000. It is a valid clust.
But on above condition check, it will be think as a last clust.

So the correct last clust check should be:
  in fat32, curclust >= 0xffffff8
  in fat16, curclust >= 0xfff8
  in fat12, curclust >= 0xff8

This patch correct the last clust check.

Signed-off-by: Josh Wu <josh.wu@atmel.com>
fs/fat/fat_write.c
include/fat.h

index c4ef13857122a327c57a02293b7c3c1d13374332..76b9b7c9c43f631eca63d273ebad394f33690182 100644 (file)
@@ -898,7 +898,7 @@ static dir_entry *find_directory_entry(fsdata *mydata, int startsect,
                }
 
                curclust = get_fatent_value(mydata, dir_curclust);
-               if ((curclust >= 0xffffff8) || (curclust >= 0xfff8)) {
+               if (IS_LAST_CLUST(curclust, mydata->fatsize)) {
                        empty_dentptr = dentptr;
                        return NULL;
                }
index b5a6969c0c2afff3697621e5e596cc3d9d0e78f5..6950e0b819218f4f3ba0bf3528236d331ff0b069 100644 (file)
 #define START(dent)    (FAT2CPU16((dent)->start) \
                        + (mydata->fatsize != 32 ? 0 : \
                          (FAT2CPU16((dent)->starthi) << 16)))
+#define IS_LAST_CLUST(x, fatsize) ((x) >= ((fatsize) != 32 ? \
+                                       ((fatsize) != 16 ? 0xff8 : 0xfff8) : \
+                                       0xffffff8))
 #define CHECK_CLUST(x, fatsize) ((x) <= 1 || \
                                (x) >= ((fatsize) != 32 ? 0xfff0 : 0xffffff0))