9
0
Fork 0

Fix two more NXFFS bugs

git-svn-id: https://nuttx.svn.sourceforge.net/svnroot/nuttx/trunk@3564 7fd9a85b-ad96-42d3-883c-3090e2eb8679
This commit is contained in:
patacongo 2011-05-05 13:12:43 +00:00
parent 50afdad793
commit 33b2bc77ba
4 changed files with 71 additions and 37 deletions

View File

@ -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
{

View File

@ -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++;
}

View File

@ -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);
/* 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.
*/
/* Reserve space for the inode header. Note we are guaranteed by
* nxffs_startpos() that the inode header will fit at hoffset.
*/
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.

View File

@ -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++;
}