From 4610a2d28a1e52200bb622b426eeaed3d2a96834 Mon Sep 17 00:00:00 2001 From: patacongo Date: Sat, 29 Oct 2011 16:30:29 +0000 Subject: Add some missing error handling to NXFFS git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@4068 42af7a65-404d-4744-a932-0658087f49c3 --- nuttx/fs/nxffs/nxffs_pack.c | 55 +++++++++++++++++++++++++++------------------ 1 file changed, 33 insertions(+), 22 deletions(-) (limited to 'nuttx/fs') diff --git a/nuttx/fs/nxffs/nxffs_pack.c b/nuttx/fs/nxffs/nxffs_pack.c index 66ae2b073..d0e5deb56 100644 --- a/nuttx/fs/nxffs/nxffs_pack.c +++ b/nuttx/fs/nxffs/nxffs_pack.c @@ -1433,34 +1433,45 @@ int nxffs_pack(FAR struct nxffs_volume_s *volume) } /* If all of the "normal" inodes have been packed, then check if - * we need to the current, in-progress write operation. + * we need to pack the current, in-progress write operation. */ if (wrfile) { DEBUGASSERT(packed == true); - /* Pack write data into this block */ - - ret = nxffs_packwriter(volume, &pack, wrfile); - if (ret < 0) - { - /* The error -ENOSPC is a special value that simply - * means that there is nothing further to be packed. - */ - - if (ret == -ENOSPC) - { - wrfile = NULL; - } - else - { - /* Otherwise, something really bad happened */ - - fdbg("Failed to pack into block %d: %d\n", - block, ret); - goto errout_with_pack; - } + /* Make sure there is space at this location for an inode header */ + + if (pack.iooffset + SIZEOF_NXFFS_INODE_HDR > volume->geo.blocksize) + { + /* No.. not enough space here. Skip the rest of this block */ + + pack.iooffset = SIZEOF_NXFFS_BLOCK_HDR; + } + else + { + /* Pack write data into this block */ + + ret = nxffs_packwriter(volume, &pack, wrfile); + if (ret < 0) + { + /* The error -ENOSPC is a special value that simply + * means that there is nothing further to be packed. + */ + + if (ret == -ENOSPC) + { + wrfile = NULL; + } + else + { + /* Otherwise, something really bad happened */ + + fdbg("Failed to pack into block %d: %d\n", + block, ret); + goto errout_with_pack; + } + } } } } -- cgit v1.2.3