summaryrefslogtreecommitdiff
path: root/nuttx/examples/mount
diff options
context:
space:
mode:
authorpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2007-05-14 02:13:27 +0000
committerpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2007-05-14 02:13:27 +0000
commitce1b502f81ef5c420f4d6d9fd68c31a1627cac55 (patch)
tree4e74b85732876960d2e262ee59425aa706157de9 /nuttx/examples/mount
parentd07ff3e417def7eccb497b7a046d692019b163ae (diff)
downloadpx4-nuttx-ce1b502f81ef5c420f4d6d9fd68c31a1627cac55.tar.gz
px4-nuttx-ce1b502f81ef5c420f4d6d9fd68c31a1627cac55.tar.bz2
px4-nuttx-ce1b502f81ef5c420f4d6d9fd68c31a1627cac55.zip
Improved FS test
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@226 42af7a65-404d-4744-a932-0658087f49c3
Diffstat (limited to 'nuttx/examples/mount')
-rw-r--r--nuttx/examples/mount/mount_main.c50
1 files changed, 48 insertions, 2 deletions
diff --git a/nuttx/examples/mount/mount_main.c b/nuttx/examples/mount/mount_main.c
index a6699c96b..541530d6b 100644
--- a/nuttx/examples/mount/mount_main.c
+++ b/nuttx/examples/mount/mount_main.c
@@ -37,8 +37,15 @@
* Included Files
****************************************************************************/
-#include <stdio.h>
#include <sys/mount.h>
+#include <sys/types.h>
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <string.h>
+#include <fcntl.h>
+#include <errno.h>
/****************************************************************************
* Definitions
@@ -52,10 +59,14 @@
* Private Data
****************************************************************************/
-static const char g_source[] ="/dev/blkdev";
+static const char g_source[] = "/dev/blkdev";
static const char g_target[] = "/mnt/fs";
static const char g_filesystemtype[] = "vfat";
+static const char g_testfile1[] = "/mnt/fs/nuttx-test/test-file.txt";
+static const char g_testfile2[] = "/mnt/fs/nuttx-test/write-test.txt";
+static const char g_testmsg[] = "This is a write test";
+
/****************************************************************************
* Private Functions
****************************************************************************/
@@ -85,6 +96,41 @@ int user_start(int argc, char *argv[])
ret = mount(g_source, g_target, g_filesystemtype, 0, NULL);
printf("main: mount() returned %d\n", ret);
+
+ if (ret == 0)
+ {
+ printf("main: opening %s for reading\n", g_testfile1);
+
+ int fd = open(g_testfile1, O_RDONLY);
+ if (fd < 0)
+ {
+ printf("main: failed open %s, errno=%d\n", g_testfile1, *get_errno_ptr());
+ }
+ else
+ {
+ close(fd);
+ }
+
+ printf("main: opening %s for reading\n", g_testfile2);
+
+ fd = open(g_testfile2, O_WRONLY|O_CREAT|O_TRUNC, 0644);
+ if (fd < 0)
+ {
+ printf("main: failed open %s, errno=%d\n", g_testfile2, *get_errno_ptr());
+ }
+ else
+ {
+ int nbytes = write(fd, g_testmsg, strlen(g_testmsg));
+ if (nbytes < 0)
+ {
+ printf("main: failed to write to %s, errno=%d\n", g_testfile2, *get_errno_ptr());
+ }
+ close(fd);
+ }
+
+ ret = umount(g_target);
+ printf("main: umount() returned %d\n", ret);
+ }
fflush(stdout);
return 0;