Fix two more NXFFS bugs

git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@3564 42af7a65-404d-4744-a932-0658087f49c3
This commit is contained in:
patacongo 2011-05-05 13:12:43 +00:00
parent d6812a0f9f
commit 8865c298c6
3 changed files with 59 additions and 29 deletions

View File

@ -315,11 +315,24 @@ int nxffs_nextentry(FAR struct nxffs_volume_s *volume, off_t offset,
*/ */
if (ch != g_inodemagic[nmagic]) if (ch != g_inodemagic[nmagic])
{
/* 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; nmagic = 0;
} }
}
else if (nmagic < NXFFS_MAGICSIZE - 1) else if (nmagic < NXFFS_MAGICSIZE - 1)
{ {
/* We have one more character in the magic sequence */
nmagic++; 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 * volume - The volume to be packed
* pack - The volume packing state structure. * pack - The volume packing state structure.
* froffset - On input, this is the location where we should be searching * froffset - On input, this is the location where we should be searching
* for the location to begin packing. If -ENOSPC is returned -- meaning * for the location to begin packing. On successful return, froffset
* that the FLASH -- then no packing can be performed. In this case * will be set the the offset in FLASH where the first inode should be
* (only) , then the free flash offset is returned through this location. * 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: * Returned Values:
* Zero on success; Otherwise, a negated errno value is returned to * 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). * 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.name = pack->src.entry.name;
pack->dest.entry.utc = pack->src.entry.utc; pack->dest.entry.utc = pack->src.entry.utc;
pack->dest.entry.datlen = pack->src.entry.datlen; 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 */ /* The destination entry now "owns" the name string */
pack->src.entry.name = NULL; pack->src.entry.name = NULL;
/* Return the FLASH offset to the destination inode header */
*froffset = offset;
return OK; return OK;
} }
@ -456,10 +461,21 @@ static int nxffs_destsetup(FAR struct nxffs_volume_s *volume,
if (pack->dest.entry.hoffset == 0) if (pack->dest.entry.hoffset == 0)
{ {
/* Initialize the FLASH offset to the inode header */
DEBUGASSERT(pack->iooffset + SIZEOF_NXFFS_INODE_HDR <= volume->geo.blocksize); DEBUGASSERT(pack->iooffset + SIZEOF_NXFFS_INODE_HDR <= volume->geo.blocksize);
pack->dest.entry.hoffset = nxffs_packtell(volume, pack); 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, memset(&pack->iobuffer[pack->iooffset], CONFIG_NXFFS_ERASEDSTATE,
SIZEOF_NXFFS_INODE_HDR); SIZEOF_NXFFS_INODE_HDR);
/* Then set the new FLASH offset */
pack->iooffset += SIZEOF_NXFFS_INODE_HDR; pack->iooffset += SIZEOF_NXFFS_INODE_HDR;
} }
@ -992,7 +1008,7 @@ int nxffs_pack(FAR struct nxffs_volume_s *volume)
if (ret == -ENOSPC) if (ret == -ENOSPC)
{ {
/* In the case where the volume is full, nxffs_startpos() will /* 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 * 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. * 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 * But don't do this unless there is some particularly big FLASH
@ -1001,13 +1017,7 @@ int nxffs_pack(FAR struct nxffs_volume_s *volume)
if (iooffset + CONFIG_NXFFS_TAILTHRESHOLD < volume->froffset) 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;
} }
@ -1027,22 +1037,16 @@ int nxffs_pack(FAR struct nxffs_volume_s *volume)
return ret; return ret;
} }
} }
else
{
/* Otherwise, begin pack at this src/dest block combination. Initialize /* Otherwise, begin pack at this src/dest block combination. Initialize
* ioblock and iooffset with the position of the first inode header. * 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.ioblock = nxffs_getblock(volume, pack.dest.entry.hoffset); pack.ioblock = nxffs_getblock(volume, iooffset);
pack.iooffset = nxffs_getoffset(volume, pack.dest.entry.hoffset, pack.ioblock); pack.iooffset = nxffs_getoffset(volume, iooffset, pack.ioblock);
volume->froffset = 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);
}
/* Then pack all erase blocks starting with the erase block that contains /* Then pack all erase blocks starting with the erase block that contains
* the ioblock and through the final erase block on the FLASH. * the ioblock and through the final erase block on the FLASH.

View File

@ -326,11 +326,24 @@ int nxffs_nextblock(FAR struct nxffs_volume_s *volume, off_t offset,
*/ */
if (ch != g_datamagic[nmagic]) if (ch != g_datamagic[nmagic])
{
/* 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; nmagic = 0;
} }
}
else if (nmagic < NXFFS_MAGICSIZE - 1) else if (nmagic < NXFFS_MAGICSIZE - 1)
{ {
/* We have one more character in the magic sequence */
nmagic++; nmagic++;
} }