]> git.sur5r.net Git - freertos/blobdiff - FreeRTOS-Plus/Source/Reliance-Edge/core/driver/dir.c
Update Reliance Edge fail safe file system to the latest version.
[freertos] / FreeRTOS-Plus / Source / Reliance-Edge / core / driver / dir.c
index 66b5072ed1c3b26a5fc62c3a26881a4c982b0323..cfda1c1aa235011b3db8604f865a3c72f4483fd5 100644 (file)
@@ -199,21 +199,23 @@ REDSTATUS RedDirEntryDelete(
     }\r
     else if((DirEntryIndexToOffset(ulDeleteIdx) + DIRENT_SIZE) == pPInode->pInodeBuf->ullSize)\r
     {\r
-        uint32_t ulTruncIdx = ulDeleteIdx;\r
+        /*  Start searching one behind the index to be deleted.\r
+        */\r
+        uint32_t ulTruncIdx = ulDeleteIdx - 1U;\r
         bool     fDone = false;\r
 \r
         /*  We are deleting the last dirent in the directory, so search\r
             backwards to find the last populated dirent, allowing us to truncate\r
             the directory to that point.\r
         */\r
-        while((ret == 0) && (ulTruncIdx > 0U) && !fDone)\r
+        while((ret == 0) && (ulTruncIdx != UINT32_MAX) && !fDone)\r
         {\r
             ret = RedInodeDataSeekAndRead(pPInode, ulTruncIdx / DIRENTS_PER_BLOCK);\r
 \r
             if(ret == 0)\r
             {\r
                 const DIRENT *pDirents = CAST_CONST_DIRENT_PTR(pPInode->pbData);\r
-                uint32_t      ulBlockIdx = (ulTruncIdx - 1U) % DIRENTS_PER_BLOCK;\r
+                uint32_t      ulBlockIdx = ulTruncIdx % DIRENTS_PER_BLOCK;\r
 \r
                 do\r
                 {\r
@@ -242,6 +244,12 @@ REDSTATUS RedDirEntryDelete(
             }\r
         }\r
 \r
+        /*  Currently ulTruncIdx represents the last valid dirent index, or\r
+            UINT32_MAX if the directory is now empty.  Increment it so that it\r
+            represents the first invalid entry, which will be truncated.\r
+        */\r
+        ulTruncIdx++;\r
+\r
         /*  Truncate the directory, deleting the requested entry and any empty\r
             dirents at the end of the directory.\r
         */\r
@@ -449,7 +457,7 @@ REDSTATUS RedDirEntryLookup(
 #if (REDCONF_API_POSIX_READDIR == 1) || (REDCONF_CHECKER == 1)\r
 /** @brief Read the next entry from a directory, given a starting index.\r
 \r
-    @param pInode   A pointer to the cached inode structure of the directory to\r
+    @param pPInode  A pointer to the cached inode structure of the directory to\r
                     read from.\r
     @param pulIdx   On entry, the directory index to start reading from.  On\r
                     successful return, populated with the directory index to use\r