summaryrefslogtreecommitdiffstats
path: root/apps
diff options
context:
space:
mode:
authorpatacongo <patacongo@7fd9a85b-ad96-42d3-883c-3090e2eb8679>2011-05-04 18:49:53 +0000
committerpatacongo <patacongo@7fd9a85b-ad96-42d3-883c-3090e2eb8679>2011-05-04 18:49:53 +0000
commit51740b3bfa2f4db7cf23da37b7152fe597fa6bee (patch)
treeb812c7578cc5369898dc14d49913d490cd75d0de /apps
parent5cbf37fadcf91c2eb2a7714116fff4955220a987 (diff)
More NXFFS bugfixes
git-svn-id: https://nuttx.svn.sourceforge.net/svnroot/nuttx/trunk@3560 7fd9a85b-ad96-42d3-883c-3090e2eb8679
Diffstat (limited to 'apps')
-rw-r--r--apps/examples/nxffs/nxffs_main.c31
1 files changed, 24 insertions, 7 deletions
diff --git a/apps/examples/nxffs/nxffs_main.c b/apps/examples/nxffs/nxffs_main.c
index 19e93138d3..7793756291 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;
+ }
+
}
}