diff options
author | patacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3> | 2011-10-31 20:23:17 +0000 |
---|---|---|
committer | patacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3> | 2011-10-31 20:23:17 +0000 |
commit | aca0035de6e6039f03b4954cdb6187267e1917d9 (patch) | |
tree | 05b374750789b462c791e30da39c5912adbc78f2 | |
parent | 1670d2d218ad2dbcf33c53dbce818b8514836f65 (diff) | |
download | nuttx-aca0035de6e6039f03b4954cdb6187267e1917d9.tar.gz nuttx-aca0035de6e6039f03b4954cdb6187267e1917d9.tar.bz2 nuttx-aca0035de6e6039f03b4954cdb6187267e1917d9.zip |
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
-rw-r--r-- | apps/examples/nxffs/nxffs_main.c | 14 | ||||
-rw-r--r-- | nuttx/ChangeLog | 3 | ||||
-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 |
7 files changed, 77 insertions, 20 deletions
diff --git a/apps/examples/nxffs/nxffs_main.c b/apps/examples/nxffs/nxffs_main.c index e201f0802..863f8bb43 100644 --- a/apps/examples/nxffs/nxffs_main.c +++ b/apps/examples/nxffs/nxffs_main.c @@ -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 */ diff --git a/nuttx/ChangeLog b/nuttx/ChangeLog index 8226a61ba..6c9af7dcb 100644 --- a/nuttx/ChangeLog +++ b/nuttx/ChangeLog @@ -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. diff --git a/nuttx/fs/nxffs/nxffs.h b/nuttx/fs/nxffs/nxffs.h index e5aee4abc..426bd6316 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 0fe519cee..da729302f 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 3362d1f29..505a6c686 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 4f16e89ac..5a82ae4fd 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 b2b9dbab2..02c9c5c5c 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); |