From 807c279a83799771e9d5e4f3bf9f745129306225 Mon Sep 17 00:00:00 2001 From: patacongo Date: Mon, 31 Oct 2011 17:04:03 +0000 Subject: [PATCH] Fix an NXFFS initialization problem git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@4074 42af7a65-404d-4744-a932-0658087f49c3 --- ChangeLog | 3 +++ fs/nxffs/nxffs_initialize.c | 19 ++++++++++++++++++- fs/nxffs/nxffs_inode.c | 6 ++++-- 3 files changed, 25 insertions(+), 3 deletions(-) diff --git a/ChangeLog b/ChangeLog index 507c36b4d1..8226a61bab 100644 --- a/ChangeLog +++ b/ChangeLog @@ -2183,3 +2183,6 @@ 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. + * fs/nxffs/nxffs_initialize.c: Fix an initialize error. If the FLASH + is on power-up, NXFFS will fail to initialize correctly. + diff --git a/fs/nxffs/nxffs_initialize.c b/fs/nxffs/nxffs_initialize.c index 0fa879f755..0fe519ceed 100644 --- a/fs/nxffs/nxffs_initialize.c +++ b/fs/nxffs/nxffs_initialize.c @@ -398,7 +398,24 @@ int nxffs_limits(FAR struct nxffs_volume_s *volume) * is full? */ - fvdbg("nxffs_getc failed: %d\n", -ch); + if (volume->ioblock + 1 >= volume->nblocks && + volume->iooffset + 1 >= volume->geo.blocksize) + { + /* Yes.. the FLASH is full. Force the offsets to the end of FLASH */ + + volume->froffset = volume->nblocks * volume->geo.blocksize; + fvdbg("Assume no free FLASH, froffset: %d\n", volume->froffset); + if (noinodes) + { + volume->inoffset = volume->froffset; + fvdbg("No inodes, inoffset: %d\n", volume->inoffset); + } + return OK; + } + + // No? Then it is some other failure that we do not know how to handle + + fdbg("nxffs_getc failed: %d\n", -ch); return ch; } diff --git a/fs/nxffs/nxffs_inode.c b/fs/nxffs/nxffs_inode.c index 121c1f6db4..3362d1f299 100644 --- a/fs/nxffs/nxffs_inode.c +++ b/fs/nxffs/nxffs_inode.c @@ -470,9 +470,11 @@ off_t nxffs_inodeend(FAR struct nxffs_volume_s *volume, if (entry->doffset) { - /* This is the maximum size of one data block */ + /* This is the maximum size of one data block. It is the physcal size + * of the block minus the minimum number of headers: block sna data + */ - uint16_t maxsize = volume->geo.blocksize - SIZEOF_NXFFS_DATA_HDR; + uint16_t maxsize = volume->geo.blocksize - SIZEOF_NXFFS_BLOCK_HDR - SIZEOF_NXFFS_DATA_HDR; /* This is the minimum number of blocks require to span all of the * inode data. One additional block could possibly be required -- we