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