From 29bc6e24ce51bb7b97591f5d354bc3b9b3b05602 Mon Sep 17 00:00:00 2001 From: patacongo Date: Wed, 4 May 2011 18:49:53 +0000 Subject: More NXFFS bugfixes git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@3560 42af7a65-404d-4744-a932-0658087f49c3 --- apps/examples/nxffs/nxffs_main.c | 31 ++++++++++++++++++++++++------- 1 file changed, 24 insertions(+), 7 deletions(-) (limited to 'apps/examples/nxffs/nxffs_main.c') diff --git a/apps/examples/nxffs/nxffs_main.c b/apps/examples/nxffs/nxffs_main.c index 19e93138d..779375629 100644 --- a/apps/examples/nxffs/nxffs_main.c +++ b/apps/examples/nxffs/nxffs_main.c @@ -223,6 +223,7 @@ static inline int nxffs_wrfile(FAR struct nxffs_filedesc_s *file) { size_t offset; int fd; + int ret; /* Create a random file */ @@ -259,8 +260,21 @@ static inline int nxffs_wrfile(FAR struct nxffs_filedesc_s *file) fprintf(stderr, " File size: %d\n", file->len); fprintf(stderr, " Write offset: %d\n", offset); fprintf(stderr, " Write size: %d\n", nbytestowrite); - nxffs_freefile(file); close(fd); + + /* Remove any garbage file that might have been left behind */ + + ret = unlink(file->name); + if (ret < 0) + { + fprintf(stderr, " Failed to remove corrupted file\n"); + } + else + { + fprintf(stderr, " Successfully removed corrupted file\n"); + } + + nxffs_freefile(file); return ERROR; } else if (nbyteswritten != nbytestowrite) @@ -510,13 +524,8 @@ static int nxffs_delfiles(void) /* And delete the next undeleted file after that random index */ - for (j = ndx + 1; j != ndx; j++) + for (j = ndx + 1; j != ndx;) { - if (j >= CONFIG_EXAMPLES_NXFFS_MAXOPEN) - { - j = 0; - } - file = &g_files[j]; if (file->name && !file->deleted) { @@ -535,6 +544,14 @@ static int nxffs_delfiles(void) break; } } + + /* Increment the index and test for wrap-around */ + + if (++j >= CONFIG_EXAMPLES_NXFFS_MAXOPEN) + { + j = 0; + } + } } -- cgit v1.2.3