NXFFS file deletion is functional
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@3552 42af7a65-404d-4744-a932-0658087f49c3
This commit is contained in:
parent
071b087bfa
commit
39c59cd8f6
@ -374,9 +374,12 @@ static inline int nxffs_rdfile(FAR struct nxffs_filedesc_s *file)
|
|||||||
fd = open(file->name, O_RDONLY);
|
fd = open(file->name, O_RDONLY);
|
||||||
if (fd < 0)
|
if (fd < 0)
|
||||||
{
|
{
|
||||||
fprintf(stderr, "ERROR: Failed to open file for reading: %d\n", errno);
|
if (!file->deleted)
|
||||||
fprintf(stderr, " File name: %s\n", file->name);
|
{
|
||||||
fprintf(stderr, " File size: %d\n", file->len);
|
fprintf(stderr, "ERROR: Failed to open file for reading: %d\n", errno);
|
||||||
|
fprintf(stderr, " File name: %s\n", file->name);
|
||||||
|
fprintf(stderr, " File size: %d\n", file->len);
|
||||||
|
}
|
||||||
return ERROR;
|
return ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -481,6 +484,63 @@ static int nxffs_verifyfs(void)
|
|||||||
return OK;
|
return OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Name: nxffs_delfiles
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
static int nxffs_delfiles(void)
|
||||||
|
{
|
||||||
|
FAR struct nxffs_filedesc_s *file;
|
||||||
|
int ndel;
|
||||||
|
int ret;
|
||||||
|
int i;
|
||||||
|
int j;
|
||||||
|
|
||||||
|
/* How many files should we delete? */
|
||||||
|
|
||||||
|
ndel = (rand() % (g_nfiles - g_ndeleted)) + 1;
|
||||||
|
|
||||||
|
/* Now pick which files to delete */
|
||||||
|
|
||||||
|
for (i = 0; i < ndel; i++)
|
||||||
|
{
|
||||||
|
/* Guess a file index */
|
||||||
|
|
||||||
|
int ndx = (rand() % (g_nfiles - g_ndeleted));
|
||||||
|
|
||||||
|
/* And delete the next undeleted file after that random index */
|
||||||
|
|
||||||
|
for (j = ndx + 1; j != ndx; j++)
|
||||||
|
{
|
||||||
|
if (j >= CONFIG_EXAMPLES_NXFFS_MAXOPEN)
|
||||||
|
{
|
||||||
|
j = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
file = &g_files[j];
|
||||||
|
if (file->name && !file->deleted)
|
||||||
|
{
|
||||||
|
ret = unlink(file->name);
|
||||||
|
if (ret < 0)
|
||||||
|
{
|
||||||
|
fprintf(stderr, "ERROR: Unlink %d failed: %d\n", i+1, errno);
|
||||||
|
fprintf(stderr, " File name: %s\n", file->name);
|
||||||
|
fprintf(stderr, " File size: %d\n", file->len);
|
||||||
|
fprintf(stderr, " File index: %d\n", j);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
file->deleted = true;
|
||||||
|
g_ndeleted++;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return OK;
|
||||||
|
}
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Public Functions
|
* Public Functions
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
@ -538,6 +598,31 @@ int user_start(int argc, char *argv[])
|
|||||||
|
|
||||||
/* Verify all files written to FLASH */
|
/* Verify all files written to FLASH */
|
||||||
|
|
||||||
|
ret = nxffs_verifyfs();
|
||||||
|
if (ret < 0)
|
||||||
|
{
|
||||||
|
fprintf(stderr, "ERROR: Failed to verify files\n");
|
||||||
|
fprintf(stderr, " Number of files: %d\n", g_nfiles);
|
||||||
|
fprintf(stderr, " Number deleted: %d\n", g_ndeleted);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Delete some files */
|
||||||
|
|
||||||
|
ret = nxffs_delfiles();
|
||||||
|
if (ret < 0)
|
||||||
|
{
|
||||||
|
fprintf(stderr, "ERROR: Failed to delete files\n");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
fprintf(stderr, "Deleted some files\n");
|
||||||
|
}
|
||||||
|
fprintf(stderr, " Number of files: %d\n", g_nfiles);
|
||||||
|
fprintf(stderr, " Number deleted: %d\n", g_ndeleted);
|
||||||
|
nxffs_dump(mtd);
|
||||||
|
|
||||||
|
/* Verify all files written to FLASH */
|
||||||
|
|
||||||
ret = nxffs_verifyfs();
|
ret = nxffs_verifyfs();
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user