Fix another NXFFS write-when-flash-is-full problem
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@4075 42af7a65-404d-4744-a932-0658087f49c3
This commit is contained in:
parent
1670d2d218
commit
aca0035de6
|
@ -2,7 +2,7 @@
|
|||
* examples/nxffs/nxffs_main.c
|
||||
*
|
||||
* Copyright (C) 2011 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
|
@ -642,9 +642,17 @@ static int nxffs_delfiles(void)
|
|||
int i;
|
||||
int j;
|
||||
|
||||
/* How many files should we delete? */
|
||||
/* Are there any files to be deleted? */
|
||||
|
||||
ndel = (rand() % (g_nfiles - g_ndeleted)) + 1;
|
||||
int nfiles = g_nfiles - g_ndeleted;
|
||||
if (nfiles < 1)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Yes... How many files should we delete? */
|
||||
|
||||
ndel = (rand() % nfiles) + 1;
|
||||
|
||||
/* Now pick which files to delete */
|
||||
|
||||
|
|
|
@ -2185,4 +2185,7 @@
|
|||
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.
|
||||
* fs/nxffs/nxffs_write.c and nxffs_pack.c: Fix an error that can occur
|
||||
when attempt to write to FLASH volume that is completely full but
|
||||
has no value inodes on it.
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
* fs/nxffs/nxffs.h
|
||||
*
|
||||
* Copyright (C) 2011 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* References: Linux/Documentation/filesystems/romfs.txt
|
||||
*
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
* fs/nxffs/nxffs_initialize.c
|
||||
*
|
||||
* Copyright (C) 2011 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* References: Linux/Documentation/filesystems/romfs.txt
|
||||
*
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
* fs/nxffs/nxffs_inode.c
|
||||
*
|
||||
* Copyright (C) 2011 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* References: Linux/Documentation/filesystems/romfs.txt
|
||||
*
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
* fs/nxffs/nxffs_pack.c
|
||||
*
|
||||
* Copyright (C) 2011 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* References: Linux/Documentation/filesystems/romfs.txt
|
||||
*
|
||||
|
@ -84,7 +84,7 @@ struct nxffs_pack_s
|
|||
|
||||
FAR uint8_t *iobuffer; /* I/O block start position */
|
||||
off_t ioblock; /* I/O block number */
|
||||
off_t block0; /* First I/O Block number in the erase block */
|
||||
off_t block0; /* First I/O block number in the erase block */
|
||||
uint16_t iooffset; /* I/O block offset */
|
||||
};
|
||||
|
||||
|
@ -282,8 +282,8 @@ static inline int nxffs_startpos(FAR struct nxffs_volume_s *volume,
|
|||
off_t nbytes;
|
||||
int ret;
|
||||
|
||||
/* Loop until we find a gap of unused FLASH large enough to warrant the
|
||||
* compression.
|
||||
/* Loop until we find a gap of unused FLASH large enough to warrant
|
||||
* compacting.
|
||||
*/
|
||||
|
||||
for(;;)
|
||||
|
@ -1279,25 +1279,68 @@ int nxffs_pack(FAR struct nxffs_volume_s *volume)
|
|||
|
||||
/* Get the offset to the first valid inode entry */
|
||||
|
||||
wrfile = NULL;
|
||||
packed = false;
|
||||
|
||||
iooffset = nxffs_mediacheck(volume, &pack);
|
||||
if (iooffset == 0)
|
||||
{
|
||||
/* Offset zero is only returned if no valid blocks were found on the
|
||||
* FLASH media or if there are no valid inode entries on the FLASH after
|
||||
* the first valid block. In this case, the media needs to be re-
|
||||
* formatted.
|
||||
* the first valid block. There are two possibilities: (1) there
|
||||
* really is nothing on the FLASH, or (2) there is a file being written
|
||||
* to the FLASH now.
|
||||
*/
|
||||
|
||||
return nxffs_reformat(volume);
|
||||
/* Is there a writer? */
|
||||
|
||||
wrfile = nxffs_setupwriter(volume, &pack);
|
||||
if (wrfile)
|
||||
{
|
||||
/* If there is a write, just set ioffset to the offset of data in
|
||||
* first block. Setting 'packed' to true will supress normal inode
|
||||
* packing operation. Then we can start compacting the FLASH.
|
||||
*/
|
||||
|
||||
iooffset = SIZEOF_NXFFS_BLOCK_HDR;
|
||||
packed = true;
|
||||
goto start_pack;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* No, there is no write in progress. We just have an empty flash
|
||||
* full of deleted files. In this case, the media needs to be re-
|
||||
* formatted.
|
||||
*/
|
||||
|
||||
ret = nxffs_reformat(volume);
|
||||
if (ret == OK)
|
||||
{
|
||||
/* The free flash offset will be in the first valid block of
|
||||
* the FLASH.
|
||||
*/
|
||||
|
||||
block = 0;
|
||||
ret = nxffs_validblock(volume, &block);
|
||||
if (ret == OK)
|
||||
{
|
||||
/* Set to the offset past the block header in the first
|
||||
* valid block
|
||||
*/
|
||||
|
||||
volume->froffset =
|
||||
block * volume->geo.blocksize + SIZEOF_NXFFS_BLOCK_HDR;
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
||||
/* There is a valid format and valid inodes on the media.. setup up to
|
||||
* begin the packing operation.
|
||||
*/
|
||||
|
||||
packed = false;
|
||||
wrfile = NULL;
|
||||
|
||||
ret = nxffs_startpos(volume, &pack, &iooffset);
|
||||
if (ret < 0)
|
||||
{
|
||||
|
@ -1351,6 +1394,8 @@ int nxffs_pack(FAR struct nxffs_volume_s *volume)
|
|||
* iooffset.
|
||||
*/
|
||||
|
||||
start_pack:
|
||||
|
||||
pack.ioblock = nxffs_getblock(volume, iooffset);
|
||||
pack.iooffset = nxffs_getoffset(volume, iooffset, pack.ioblock);
|
||||
volume->froffset = iooffset;
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
* fs/nxffs/nxffs_write.c
|
||||
*
|
||||
* Copyright (C) 2011 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* References: Linux/Documentation/filesystems/romfs.txt
|
||||
*
|
||||
|
@ -267,11 +267,12 @@ static inline int nxffs_wralloc(FAR struct nxffs_volume_s *volume,
|
|||
fdbg("Failed to pack the volume: %d\n", -ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
/* After packing the volume, froffset will be updated to point to the
|
||||
* new free flash region. Try again.
|
||||
*/
|
||||
|
||||
|
||||
nxffs_ioseek(volume, volume->froffset);
|
||||
packed = true;
|
||||
}
|
||||
|
||||
|
@ -496,7 +497,7 @@ ssize_t nxffs_write(FAR struct file *filep, FAR const char *buffer, size_t bufle
|
|||
|
||||
if (wrfile->doffset == 0)
|
||||
{
|
||||
/* No, allocate the data block now */
|
||||
/* No, allocate the data block now, re-packing if necessary. */
|
||||
|
||||
wrfile->datlen = 0;
|
||||
ret = nxffs_wralloc(volume, wrfile, remaining);
|
||||
|
|
Loading…
Reference in New Issue