9
0
Fork 0

Add NXFFS ioctls

git-svn-id: https://nuttx.svn.sourceforge.net/svnroot/nuttx/trunk@3566 7fd9a85b-ad96-42d3-883c-3090e2eb8679
This commit is contained in:
patacongo 2011-05-05 20:01:43 +00:00
parent fd627dc2b8
commit 9163401634
3 changed files with 170 additions and 7 deletions

View File

@ -142,10 +142,73 @@ static const char g_mountdir[] = CONFIG_EXAMPLES_NXFFS_MOUNTPT "/";
static int g_nfiles;
static int g_ndeleted;
static struct mallinfo g_mmbefore;
static struct mallinfo g_mmprevious;
static struct mallinfo g_mmafter;
/****************************************************************************
* Private Functions
****************************************************************************/
/****************************************************************************
* Name: nxffs_memusage
****************************************************************************/
static void nxffs_showmemusage(struct mallinfo *mmbefore,
struct mallinfo *mmafter)
{
message("VARIABLE BEFORE AFTER\n");
message("======== ======== ========\n");
message("arena %8x %8x\n", mmbefore->arena, mmafter->arena);
message("ordblks %8d %8d\n", mmbefore->ordblks, mmafter->ordblks);
message("mxordblk %8x %8x\n", mmbefore->mxordblk, mmafter->mxordblk);
message("uordblks %8x %8x\n", mmbefore->uordblks, mmafter->uordblks);
message("fordblks %8x %8x\n", mmbefore->fordblks, mmafter->fordblks);
}
/****************************************************************************
* Name: nxffs_loopmemusage
****************************************************************************/
static void nxffs_loopmemusage(void)
{
/* Get the current memory usage */
#ifdef CONFIG_CAN_PASS_STRUCTS
g_mmafter = mallinfo();
#else
(void)mallinfo(&g_mmafter);
#endif
/* Show the change from the previous loop */
message("\nEnd of loop memory usage:\n");
nxffs_showmemusage(&g_mmprevious, &g_mmafter);
/* Set up for the next test */
#ifdef CONFIG_CAN_PASS_STRUCTS
g_mmprevious = g_mmafter;
#else
memcpy(&g_mmprevious, &g_mmafter, sizeof(struct mallinfo));
#endif
}
/****************************************************************************
* Name: nxffs_endmemusage
****************************************************************************/
static void nxffs_endmemusage(void)
{
#ifdef CONFIG_CAN_PASS_STRUCTS
g_mmafter = mallinfo();
#else
(void)mallinfo(&g_mmafter);
#endif
message("\nFinal memory usage:\n");
nxffs_showmemusage(&g_mmbefore, &g_mmafter);
}
/****************************************************************************
* Name: nxffs_randchar
****************************************************************************/
@ -265,7 +328,7 @@ static inline int nxffs_wrfile(FAR struct nxffs_filedesc_s *file)
return ERROR;
}
/* Write a random amount of data dat the file */
/* Write a random amount of data to the file */
for (offset = 0; offset < file->len; )
{
@ -610,6 +673,44 @@ static int nxffs_delfiles(void)
return OK;
}
/****************************************************************************
* Name: nxffs_delallfiles
****************************************************************************/
static int nxffs_delallfiles(void)
{
FAR struct nxffs_filedesc_s *file;
int ret;
int i;
for (i = 0; i < CONFIG_EXAMPLES_NXFFS_MAXOPEN; i++)
{
file = &g_files[i];
if (file->name)
{
ret = unlink(file->name);
if (ret < 0)
{
message("ERROR: Unlink %d failed: %d\n", i+1, errno);
message(" File name: %s\n", file->name);
message(" File size: %d\n", file->len);
message(" File index: %d\n", i);
}
else
{
#if CONFIG_EXAMPLES_NXFFS_VERBOSE != 0
message(" Deleted file %s\n", file->name);
#endif
nxffs_freefile(file);
}
}
}
g_nfiles = 0;
g_ndeleted = 0;
return OK;
}
/****************************************************************************
* Name: nxffs_directory
****************************************************************************/
@ -703,6 +804,16 @@ int user_start(int argc, char *argv[])
exit(3);
}
/* Set up memory monitoring */
#ifdef CONFIG_CAN_PASS_STRUCTS
g_mmbefore = mallinfo();
g_mmprevious = g_mmbefore;
#else
(void)mallinfo(&g_mmbefore);
memcpy(&g_mmprevious, &g_mmbefore, sizeof(struct mallinfo));
#endif
/* Loop a few times ... file the file system with some random, files,
* delete some files randomly, fill the file system with more random file,
* delete, etc. This beats the FLASH very hard!
@ -719,7 +830,7 @@ int user_start(int argc, char *argv[])
* (hopefully that the file system is full)
*/
message("=== FILLING %d =============================\n", i);
message("\n=== FILLING %d =============================\n", i);
ret = nxffs_fillfs();
message("Filled file system\n");
message(" Number of files: %d\n", g_nfiles);
@ -750,7 +861,7 @@ int user_start(int argc, char *argv[])
/* Delete some files */
message("=== DELETING %d ============================\n", i);
message("\n=== DELETING %d ============================\n", i);
ret = nxffs_delfiles();
if (ret < 0)
{
@ -788,9 +899,17 @@ int user_start(int argc, char *argv[])
#endif
}
/* Show memory usage */
nxffs_loopmemusage();
msgflush();
}
/* Delete all files then show memory usage again */
nxffs_delallfiles();
nxffs_endmemusage();
msgflush();
return 0;
}

View File

@ -47,6 +47,7 @@
#include <debug.h>
#include <nuttx/fs.h>
#include <nuttx/ioctl.h>
#include <nuttx/mtd.h>
#include "nxffs.h"
@ -82,6 +83,7 @@
int nxffs_ioctl(FAR struct file *filep, int cmd, unsigned long arg)
{
FAR struct nxffs_volume_s *volume;
int ret;
fvdbg("cmd: %d arg: %08lx\n", cmd, arg);
@ -94,7 +96,45 @@ int nxffs_ioctl(FAR struct file *filep, int cmd, unsigned long arg)
volume = filep->f_inode->i_private;
DEBUGASSERT(volume != NULL);
/* No ioctl commands yet supported */
/* Get exclusive access to the volume. Note that the volume exclsem
* protects the open file list.
*/
return -ENOTTY;
ret = sem_wait(&volume->exclsem);
if (ret != OK)
{
ret = -errno;
fdbg("sem_wait failed: %d\n", ret);
goto errout;
}
/* Only a reformat command is supported */
if (cmd == FIOC_REFORMAT)
{
fvdbg("Reformat command\n");
/* We cannot reformat the volume if there are any open inodes */
if (volume->ofiles)
{
fdbg("Open files\n");
ret = -EBUSY;
goto errout_with_semaphore;
}
/* Re-format the volume -- all is lost */
ret = nxffs_reformat(volume);
goto errout_with_semaphore;
}
/* No other commands supported */
ret = -ENOTTY;
errout_with_semaphore:
sem_post(&volume->exclsem);
errout:
return ret;
}

View File

@ -94,17 +94,21 @@
* return (void*) base address
* of file
*/
#define FIOC_REFORMAT _FIOC(0x0002) /* IN: None
* OUT: None
*/
/* NuttX file system ioctl definitions */
#define _DIOCVALID(c) (_IOC_TYPE(c)==_DIOCBASE)
#define _DIOC(nr) _IOC(_DIOCBASE,nr)
#define DIOC_GETPRIV _DIOC(0x0001) /* IN: Location to return handle (void **)
#define DIOC_GETPRIV _DIOC(0x0001) /* IN: Location to return handle (void **)
* OUT: Reference to internal data
* structure. May have a reference
* incremented.
*/
#define DIOC_RELPRIV _DIOC(0x0003) /* IN: None
#define DIOC_RELPRIV _DIOC(0x0003) /* IN: None
* OUT: None, reference obtained by
* FIOC_GETPRIV released.
*/