summaryrefslogtreecommitdiff
path: root/nuttx/fs
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 /nuttx/fs
parentfe8430b28928dd36a9d881b4f02ce56d91dec6a0 (diff)
downloadpx4-nuttx-1f8899bbb98173dc72daba93b77a80aa7162c5d5.tar.gz
px4-nuttx-1f8899bbb98173dc72daba93b77a80aa7162c5d5.tar.bz2
px4-nuttx-1f8899bbb98173dc72daba93b77a80aa7162c5d5.zip
Add NXFFS ioctls
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@3566 42af7a65-404d-4744-a932-0658087f49c3
Diffstat (limited to 'nuttx/fs')
-rw-r--r--nuttx/fs/nxffs/nxffs_ioctl.c44
1 files changed, 42 insertions, 2 deletions
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;
}