Yet another re-implementation of the NXFFS bug fix

git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@4072 42af7a65-404d-4744-a932-0658087f49c3
This commit is contained in:
patacongo
2011-10-31 13:16:08 +00:00
parent ee27333dc5
commit ae91fa0be3
+34 -28
View File
@@ -468,9 +468,22 @@ 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 */ /* Is there room for an inode structure in this block? */
if(pack->iooffset + SIZEOF_NXFFS_INODE_HDR > volume->geo.blocksize)
{
/* No.. that inode name will not fit in this block. Return an
* indication that we are at the end of the block and try again
* later.
*/
return -ENOSPC;
}
/* The inode header will be placed at this position (but not until
* we are finished.
*/
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 /* Make sure that the initialize state of the inode header memory is
@@ -544,7 +557,7 @@ static int nxffs_destsetup(FAR struct nxffs_volume_s *volume,
*/ */
ret = -ENOSPC; ret = -ENOSPC;
goto errout; goto errout;
} }
/* Yes.. reserve space for the data block header */ /* Yes.. reserve space for the data block header */
@@ -1440,34 +1453,27 @@ int nxffs_pack(FAR struct nxffs_volume_s *volume)
{ {
DEBUGASSERT(packed == true); DEBUGASSERT(packed == true);
/* Make sure there is space at this location for an inode /* Pack write data into this block */
* header.
*/
if (pack.iooffset + SIZEOF_NXFFS_INODE_HDR <= volume->geo.blocksize) ret = nxffs_packwriter(volume, &pack, wrfile);
{ if (ret < 0)
/* Pack write data into this block */ {
/* The error -ENOSPC is a special value that simply
* means that there is nothing further to be packed.
*/
ret = nxffs_packwriter(volume, &pack, wrfile); if (ret == -ENOSPC)
if (ret < 0) {
{ wrfile = NULL;
/* The error -ENOSPC is a special value that simply }
* means that there is nothing further to be packed. else
*/ {
/* Otherwise, something really bad happened */
if (ret == -ENOSPC) fdbg("Failed to pack into block %d: %d\n",
{ block, ret);
wrfile = NULL; goto errout_with_pack;
} }
else
{
/* Otherwise, something really bad happened */
fdbg("Failed to pack into block %d: %d\n",
block, ret);
goto errout_with_pack;
}
}
} }
} }
} }