summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2011-05-05 20:01:43 +0000
committerpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2011-05-05 20:01:43 +0000
commit1f8899bbb98173dc72daba93b77a80aa7162c5d5 (patch)
treecd1dad6b6851e791f4a551c8e95b870496d610a8
parentfe8430b28928dd36a9d881b4f02ce56d91dec6a0 (diff)
downloadnuttx-1f8899bbb98173dc72daba93b77a80aa7162c5d5.tar.gz
nuttx-1f8899bbb98173dc72daba93b77a80aa7162c5d5.tar.bz2
nuttx-1f8899bbb98173dc72daba93b77a80aa7162c5d5.zip
Add NXFFS ioctls
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@3566 42af7a65-404d-4744-a932-0658087f49c3
-rw-r--r--apps/examples/nxffs/nxffs_main.c125
-rw-r--r--nuttx/fs/nxffs/nxffs_ioctl.c44
-rw-r--r--nuttx/include/nuttx/ioctl.h8
3 files changed, 170 insertions, 7 deletions
diff --git a/apps/examples/nxffs/nxffs_main.c b/apps/examples/nxffs/nxffs_main.c
index b2a6846c0..c94b3cb80 100644
--- a/apps/examples/nxffs/nxffs_main.c
+++ b/apps/examples/nxffs/nxffs_main.c
@@ -142,11 +142,74 @@ 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; )
{
@@ -611,6 +674,44 @@ static int nxffs_delfiles(void)
}
/****************************************************************************
+ * 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;
}
diff --git a/nuttx/fs/nxffs/nxffs_ioctl.c b/nuttx/fs/nxffs/nxffs_ioctl.c
index d5fe2ece8..e24cf0564 100644
--- a/nuttx/fs/nxffs/nxffs_ioctl.c
+++ b/nuttx/fs/nxffs/nxffs_ioctl.c
@@ -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;
}
diff --git a/nuttx/include/nuttx/ioctl.h b/nuttx/include/nuttx/ioctl.h
index 5eaf886c8..0c32004f8 100644
--- a/nuttx/include/nuttx/ioctl.h
+++ b/nuttx/include/nuttx/ioctl.h
@@ -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.
*/