summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2011-05-05 13:12:43 +0000
committerpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2011-05-05 13:12:43 +0000
commit697ebec39680857ebbf7537e38a88b1370b7c23f (patch)
tree7e8d5cea76ac592aff9110ef1e1e6f42e993f997
parente19726b3e335c2ca6bb58e55af43f1ccb3ac3057 (diff)
downloadnuttx-697ebec39680857ebbf7537e38a88b1370b7c23f.tar.gz
nuttx-697ebec39680857ebbf7537e38a88b1370b7c23f.tar.bz2
nuttx-697ebec39680857ebbf7537e38a88b1370b7c23f.zip
Fix two more NXFFS bugs
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@3564 42af7a65-404d-4744-a932-0658087f49c3
-rw-r--r--apps/examples/nxffs/nxffs_main.c20
-rw-r--r--nuttx/fs/nxffs/nxffs_inode.c15
-rw-r--r--nuttx/fs/nxffs/nxffs_pack.c58
-rw-r--r--nuttx/fs/nxffs/nxffs_read.c15
4 files changed, 71 insertions, 37 deletions
diff --git a/apps/examples/nxffs/nxffs_main.c b/apps/examples/nxffs/nxffs_main.c
index af16b983d..12383071a 100644
--- a/apps/examples/nxffs/nxffs_main.c
+++ b/apps/examples/nxffs/nxffs_main.c
@@ -103,7 +103,7 @@
#endif
#ifndef CONFIG_EXAMPLES_NXFFS_NLOOPS
-# define CONFIG_EXAMPLES_NXFFS_NLOOPS 3
+# define CONFIG_EXAMPLES_NXFFS_NLOOPS 10
#endif
#ifndef CONFIG_EXAMPLES_NXFFS_VERBOSE
@@ -336,7 +336,10 @@ static int nxffs_fillfs(void)
return ERROR;
}
- g_nfiles++;
+#if CONFIG_EXAMPLES_NXFFS_VERBOSE != 0
+ message(" Created file %s\n", file->name);
+#endif
+ g_nfiles++;
}
}
@@ -513,7 +516,7 @@ static int nxffs_verifyfs(void)
else
{
#if CONFIG_EXAMPLES_NXFFS_VERBOSE != 0
- message("File %d: OK\n", i);
+ message(" Verifed file %s\n", file->name);
#endif
}
}
@@ -564,9 +567,12 @@ static int nxffs_delfiles(void)
}
else
{
- file->deleted = true;
- g_ndeleted++;
- break;
+#if CONFIG_EXAMPLES_NXFFS_VERBOSE != 0
+ message(" Deleted file %s\n", file->name);
+#endif
+ file->deleted = true;
+ g_ndeleted++;
+ break;
}
}
@@ -711,7 +717,6 @@ int user_start(int argc, char *argv[])
message("ERROR: Failed to verify files\n");
message(" Number of files: %d\n", g_nfiles);
message(" Number deleted: %d\n", g_ndeleted);
- nxffs_dump(mtd, true);
}
else
{
@@ -752,7 +757,6 @@ int user_start(int argc, char *argv[])
message("ERROR: Failed to verify files\n");
message(" Number of files: %d\n", g_nfiles);
message(" Number deleted: %d\n", g_ndeleted);
- nxffs_dump(mtd, true);
}
else
{
diff --git a/nuttx/fs/nxffs/nxffs_inode.c b/nuttx/fs/nxffs/nxffs_inode.c
index 496b87418..361b5df7e 100644
--- a/nuttx/fs/nxffs/nxffs_inode.c
+++ b/nuttx/fs/nxffs/nxffs_inode.c
@@ -316,10 +316,23 @@ int nxffs_nextentry(FAR struct nxffs_volume_s *volume, off_t offset,
if (ch != g_inodemagic[nmagic])
{
- nmagic = 0;
+ /* Ooops... this is the not the right character for the magic
+ * Sequence. Check if we need to restart or to cancel the sequence:
+ */
+
+ if (ch == g_inodemagic[0])
+ {
+ nmagic = 1;
+ }
+ else
+ {
+ nmagic = 0;
+ }
}
else if (nmagic < NXFFS_MAGICSIZE - 1)
{
+ /* We have one more character in the magic sequence */
+
nmagic++;
}
diff --git a/nuttx/fs/nxffs/nxffs_pack.c b/nuttx/fs/nxffs/nxffs_pack.c
index 70ae506d4..d4a7d5f39 100644
--- a/nuttx/fs/nxffs/nxffs_pack.c
+++ b/nuttx/fs/nxffs/nxffs_pack.c
@@ -259,9 +259,11 @@ static inline off_t nxffs_mediacheck(FAR struct nxffs_volume_s *volume,
* volume - The volume to be packed
* pack - The volume packing state structure.
* froffset - On input, this is the location where we should be searching
- * for the location to begin packing. If -ENOSPC is returned -- meaning
- * that the FLASH -- then no packing can be performed. In this case
- * (only) , then the free flash offset is returned through this location.
+ * for the location to begin packing. On successful return, froffset
+ * will be set the the offset in FLASH where the first inode should be
+ * copied to. If -ENOSPC is returned -- meaning that the FLASH is full
+ * -- then no packing can be performed. In this case, then the free
+ * flash offset is returned through this location.
*
* Returned Values:
* Zero on success; Otherwise, a negated errno value is returned to
@@ -301,7 +303,6 @@ static inline int nxffs_startpos(FAR struct nxffs_volume_s *volume,
* inode header (only non-zero entries need to be initialized).
*/
- pack->dest.entry.hoffset = offset;
pack->dest.entry.name = pack->src.entry.name;
pack->dest.entry.utc = pack->src.entry.utc;
pack->dest.entry.datlen = pack->src.entry.datlen;
@@ -309,6 +310,10 @@ static inline int nxffs_startpos(FAR struct nxffs_volume_s *volume,
/* The destination entry now "owns" the name string */
pack->src.entry.name = NULL;
+
+ /* Return the FLASH offset to the destination inode header */
+
+ *froffset = offset;
return OK;
}
@@ -456,10 +461,21 @@ static int nxffs_destsetup(FAR struct nxffs_volume_s *volume,
if (pack->dest.entry.hoffset == 0)
{
+ /* Initialize the FLASH offset to the inode header */
+
DEBUGASSERT(pack->iooffset + SIZEOF_NXFFS_INODE_HDR <= volume->geo.blocksize);
pack->dest.entry.hoffset = nxffs_packtell(volume, pack);
+
+ /* Make sure that the initialize state of the inode header memory is
+ * erased. This is important because we may not write to inode header
+ * until it has already been written to FLASH.
+ */
+
memset(&pack->iobuffer[pack->iooffset], CONFIG_NXFFS_ERASEDSTATE,
SIZEOF_NXFFS_INODE_HDR);
+
+ /* Then set the new FLASH offset */
+
pack->iooffset += SIZEOF_NXFFS_INODE_HDR;
}
@@ -992,7 +1008,7 @@ int nxffs_pack(FAR struct nxffs_volume_s *volume)
if (ret == -ENOSPC)
{
/* In the case where the volume is full, nxffs_startpos() will
- * recalculate the free FLASH offset and store in in iooffset. There
+ * recalculate the free FLASH offset and store it in iooffset. There
* may be deleted files at the end of FLASH. In this case, we don't
* have to pack any files, we simply have to erase FLASH at the end.
* But don't do this unless there is some particularly big FLASH
@@ -1001,15 +1017,9 @@ int nxffs_pack(FAR struct nxffs_volume_s *volume)
if (iooffset + CONFIG_NXFFS_TAILTHRESHOLD < volume->froffset)
{
- /* Yes... we can recover CONFIG_NXFFS_TAILTHRESHOLD bytes */
+ /* Setting 'packed' to true will supress all packing operations */
- pack.ioblock = nxffs_getblock(volume, iooffset);
- pack.iooffset = nxffs_getoffset(volume, iooffset, pack.ioblock);
- volume->froffset = iooffset;
-
- /* Setting packed to true will supress all packing operations */
-
- packed = true;
+ packed = true;
}
/* Otherwise return OK.. meaning that there is nothing more we can
@@ -1027,22 +1037,16 @@ int nxffs_pack(FAR struct nxffs_volume_s *volume)
return ret;
}
}
- else
- {
- /* Otherwise, begin pack at this src/dest block combination. Initialize
- * ioblock and iooffset with the position of the first inode header.
- */
- pack.ioblock = nxffs_getblock(volume, pack.dest.entry.hoffset);
- pack.iooffset = nxffs_getoffset(volume, pack.dest.entry.hoffset, pack.ioblock);
-
- /* Reserve space for the inode header. Note we are guaranteed by
- * nxffs_startpos() that the inode header will fit at hoffset.
- */
+ /* Otherwise, begin pack at this src/dest block combination. Initialize
+ * ioblock and iooffset with the position of the first inode header. In
+ * this case, the FLASH offset to the first inode header is return in
+ * iooffset.
+ */
- pack.iooffset += SIZEOF_NXFFS_INODE_HDR;
- volume->froffset = nxffs_packtell(volume, &pack);
- }
+ pack.ioblock = nxffs_getblock(volume, iooffset);
+ pack.iooffset = nxffs_getoffset(volume, iooffset, pack.ioblock);
+ volume->froffset = iooffset;
/* Then pack all erase blocks starting with the erase block that contains
* the ioblock and through the final erase block on the FLASH.
diff --git a/nuttx/fs/nxffs/nxffs_read.c b/nuttx/fs/nxffs/nxffs_read.c
index bc222c159..f52e21859 100644
--- a/nuttx/fs/nxffs/nxffs_read.c
+++ b/nuttx/fs/nxffs/nxffs_read.c
@@ -327,10 +327,23 @@ int nxffs_nextblock(FAR struct nxffs_volume_s *volume, off_t offset,
if (ch != g_datamagic[nmagic])
{
- nmagic = 0;
+ /* Ooops... this is the not the right character for the magic
+ * Sequence. Check if we need to restart or to cancel the sequence:
+ */
+
+ if (ch == g_datamagic[0])
+ {
+ nmagic = 1;
+ }
+ else
+ {
+ nmagic = 0;
+ }
}
else if (nmagic < NXFFS_MAGICSIZE - 1)
{
+ /* We have one more character in the magic sequence */
+
nmagic++;
}