diff options
author | patacongo <patacongo@7fd9a85b-ad96-42d3-883c-3090e2eb8679> | 2011-10-31 20:23:17 +0000 |
---|---|---|
committer | patacongo <patacongo@7fd9a85b-ad96-42d3-883c-3090e2eb8679> | 2011-10-31 20:23:17 +0000 |
commit | a9d842edd386ab0ac63ce6dadc09f3b4fa22aedb (patch) | |
tree | 05b374750789b462c791e30da39c5912adbc78f2 /nuttx/fs | |
parent | e349bc29c1c7c60148326caa9cae3757c338f774 (diff) |
Fix another NXFFS write-when-flash-is-full problem
git-svn-id: https://nuttx.svn.sourceforge.net/svnroot/nuttx/trunk@4075 7fd9a85b-ad96-42d3-883c-3090e2eb8679
Diffstat (limited to 'nuttx/fs')
-rw-r--r-- | nuttx/fs/nxffs/nxffs.h | 2 | ||||
-rw-r--r-- | nuttx/fs/nxffs/nxffs_initialize.c | 2 | ||||
-rw-r--r-- | nuttx/fs/nxffs/nxffs_inode.c | 2 | ||||
-rw-r--r-- | nuttx/fs/nxffs/nxffs_pack.c | 65 | ||||
-rw-r--r-- | nuttx/fs/nxffs/nxffs_write.c | 9 |
5 files changed, 63 insertions, 17 deletions
diff --git a/nuttx/fs/nxffs/nxffs.h b/nuttx/fs/nxffs/nxffs.h index e5aee4abc0..426bd6316d 100644 --- a/nuttx/fs/nxffs/nxffs.h +++ b/nuttx/fs/nxffs/nxffs.h @@ -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 * diff --git a/nuttx/fs/nxffs/nxffs_initialize.c b/nuttx/fs/nxffs/nxffs_initialize.c index 0fe519ceed..da729302fc 100644 --- a/nuttx/fs/nxffs/nxffs_initialize.c +++ b/nuttx/fs/nxffs/nxffs_initialize.c @@ -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 * diff --git a/nuttx/fs/nxffs/nxffs_inode.c b/nuttx/fs/nxffs/nxffs_inode.c index 3362d1f299..505a6c6863 100644 --- a/nuttx/fs/nxffs/nxffs_inode.c +++ b/nuttx/fs/nxffs/nxffs_inode.c @@ -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 * diff --git a/nuttx/fs/nxffs/nxffs_pack.c b/nuttx/fs/nxffs/nxffs_pack.c index 4f16e89ac2..5a82ae4fd3 100644 --- a/nuttx/fs/nxffs/nxffs_pack.c +++ b/nuttx/fs/nxffs/nxffs_pack.c @@ -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; diff --git a/nuttx/fs/nxffs/nxffs_write.c b/nuttx/fs/nxffs/nxffs_write.c index b2b9dbab28..02c9c5c5c3 100644 --- a/nuttx/fs/nxffs/nxffs_write.c +++ b/nuttx/fs/nxffs/nxffs_write.c @@ -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); |