apps/examples/fstest: Add logic to dump logic content of SPIFFS

This commit is contained in:
Gregory Nutt 2018-09-28 11:27:01 -06:00
parent 3abd6f2ac8
commit a1be83cda9
2 changed files with 73 additions and 12 deletions

View File

@ -46,10 +46,10 @@ config EXAMPLES_FSTEST_SPIFFS
depends on FS_SPIFFS
---help---
SPIFFS garbage collection and integrity checking will be performed
after a write fails with ENOSPC.
after each pass through the test and if a write fails with ENOSPC.
If this option is not selected then the SPIFFS FLASH will likely
become full before you finish the test.
If this option is not selected then the SPIFFS FLASH will be be
reclaimed on-demand when there is no longer any available FLASH.
config EXAMPLES_FSTEST_VERBOSE
bool "Verbose output"

View File

@ -275,14 +275,26 @@ static void fstest_freefile(FAR struct fstest_filedesc_s *file)
}
/****************************************************************************
* Name: fstest_gc
* Name: fstest_gc and fstest_gc_withfd
****************************************************************************/
#ifdef CONFIG_EXAMPLES_FSTEST_SPIFFS
static int fstest_gc(int fd, size_t nbytes)
static int fstest_gc_withfd(int fd, size_t nbytes)
{
int ret;
#ifdef CONFIG_SPIFFS_DUMP
/* Dump the logic content of FLASH before garbage collection */
printf("SPIFFS Content (before GC):\n");
ret = ioctl(fd, FIOC_DUMP, (unsigned long)nbytes);
if (ret < 0)
{
printf("ERROR: ioctl(FIOC_DUMP) failed: %d\n", errno);
}
#endif
/* Perform SPIFFS garbage collection */
printf("SPIFFS Garbage Collection: %lu bytes\n", (unsigned long)nbytes);
@ -314,10 +326,60 @@ static int fstest_gc(int fd, size_t nbytes)
}
}
#ifdef CONFIG_SPIFFS_DUMP
/* Dump the logic content of FLASH after garbage collection */
printf("SPIFFS Content (After GC):\n");
ret = ioctl(fd, FIOC_DUMP, (unsigned long)nbytes);
if (ret < 0)
{
printf("ERROR: ioctl(FIOC_DUMP) failed: %d\n", errno);
}
#endif
return ret;
}
static int fstest_gc(size_t nbytes)
{
FAR struct fstest_filedesc_s *file;
int ret = OK;
int fd;
int i;
/* Find the first valid file */
for (i = 0; i < CONFIG_EXAMPLES_FSTEST_MAXOPEN; i++)
{
file = &g_files[i];
if (file->name != NULL && !file->deleted)
{
/* Open the file for reading */
fd = open(file->name, O_RDONLY);
if (fd < 0)
{
printf("ERROR: Failed to open file for reading: %d\n", errno);
ret = ERROR;
}
else
{
/* Use this file descriptor to support the garbage collection */
ret = fstest_gc_withfd(fd, nbytes);
close(fd);
}
break;
}
}
return ret;
}
#else
# define fstest_gc(f,n) (-ENOSYS)
# define fstest_gc_withfd(f,n) (-ENOSYS)
# define fstest_gc(n) (-ENOSYS)
#endif
/****************************************************************************
@ -390,7 +452,7 @@ static inline int fstest_wrfile(FAR struct fstest_filedesc_s *file)
/* Try to recover some space on the FLASH */
ret2 = fstest_gc(fd, nbytestowrite);
ret2 = fstest_gc_withfd(fd, nbytestowrite);
if (ret2 >= 0)
{
continue;
@ -429,11 +491,6 @@ static inline int fstest_wrfile(FAR struct fstest_filedesc_s *file)
offset += nbyteswritten;
}
/* Try to recover some space on the FLASH to write another file of this
* size.
*/
(void)fstest_gc(fd, file->len);
close(fd);
return OK;
}
@ -958,6 +1015,10 @@ int fstest_main(int argc, char *argv[])
printf(" Free File Nodes: %ld\n", (long)buf.f_ffree);
}
/* Perform garbage collection, integrity checks */
(void)fstest_gc(buf.f_bfree);
/* Show memory usage */
fstest_loopmemusage();