diff options
author | patacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3> | 2011-10-29 16:30:29 +0000 |
---|---|---|
committer | patacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3> | 2011-10-29 16:30:29 +0000 |
commit | 4610a2d28a1e52200bb622b426eeaed3d2a96834 (patch) | |
tree | e2aa02fa122ba80340df5c18826d29451760ea6f | |
parent | e876ab20bae53a5e217f00c5b0dfb35554e6ac4f (diff) | |
download | px4-nuttx-4610a2d28a1e52200bb622b426eeaed3d2a96834.tar.gz px4-nuttx-4610a2d28a1e52200bb622b426eeaed3d2a96834.tar.bz2 px4-nuttx-4610a2d28a1e52200bb622b426eeaed3d2a96834.zip |
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
-rw-r--r-- | nuttx/ChangeLog | 5 | ||||
-rw-r--r-- | nuttx/fs/nxffs/nxffs_pack.c | 55 |
2 files changed, 38 insertions, 22 deletions
diff --git a/nuttx/ChangeLog b/nuttx/ChangeLog index efa9d15d7..507c36b4d 100644 --- a/nuttx/ChangeLog +++ b/nuttx/ChangeLog @@ -2178,3 +2178,8 @@ not being recognized and handled properly. * graphics/nxsu/nx_releasebkgdg.c: Fix a bad cast that was causing problems with the backgournd window was released. + * fs/nxffs/nxffs_pack.c: Correct a critical bug in the NXFFS file system: + When repacking the filesystem, there was a missing check to see if an + inode structure would fit at the end of a block. This is a rare case + if the block size is large, but can be common for tiny block sizes + and results in a crash and file system corruption. 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; + } + } } } } |