summaryrefslogtreecommitdiff
path: root/nuttx/examples/mount
diff options
context:
space:
mode:
authorpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2007-05-20 23:22:56 +0000
committerpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2007-05-20 23:22:56 +0000
commit4815a2fb0e87d0b64a61f57f287de92be5027e90 (patch)
tree0c7e51da8deec2627958437c76f329219dfa84f8 /nuttx/examples/mount
parent87d2e8e9ebb04306b09e647833fac0a4f71acceb (diff)
downloadpx4-nuttx-4815a2fb0e87d0b64a61f57f287de92be5027e90.tar.gz
px4-nuttx-4815a2fb0e87d0b64a61f57f287de92be5027e90.tar.bz2
px4-nuttx-4815a2fb0e87d0b64a61f57f287de92be5027e90.zip
Implemented FAT write
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@244 42af7a65-404d-4744-a932-0658087f49c3
Diffstat (limited to 'nuttx/examples/mount')
-rw-r--r--nuttx/examples/mount/mount_main.c41
1 files changed, 35 insertions, 6 deletions
diff --git a/nuttx/examples/mount/mount_main.c b/nuttx/examples/mount/mount_main.c
index 274a35010..09dc8e189 100644
--- a/nuttx/examples/mount/mount_main.c
+++ b/nuttx/examples/mount/mount_main.c
@@ -64,7 +64,7 @@ static const char g_target[] = "/mnt/fs";
static const char g_filesystemtype[] = "vfat";
static const char g_testfile1[] = "/mnt/fs/TestDir/TestFile.txt";
-static const char g_testfile2[] = "/mnt/fs/TestDir/WriteTest.txt";
+static const char g_testfile2[] = "/mnt/fs/TestDir/WritTest.txt";
static const char g_testmsg[] = "This is a write test";
/****************************************************************************
@@ -89,7 +89,9 @@ void user_initialize(void)
int user_start(int argc, char *argv[])
{
- int ret;
+ char buffer[128];
+ int nbytes;
+ int ret;
printf("main: mounting %s filesystem at target=%s with source=%s\n",
g_filesystemtype, g_target, g_source);
@@ -104,12 +106,12 @@ int user_start(int argc, char *argv[])
int fd = open(g_testfile1, O_RDONLY);
if (fd < 0)
{
- printf("main: failed open %s, errno=%d\n", g_testfile1, *get_errno_ptr());
+ printf("main: failed to open %s, errno=%d\n", g_testfile1, *get_errno_ptr());
}
else
{
- char buffer[128];
- int nbytes = read(fd, buffer, 128);
+ memset(buffer, 0, 128);
+ nbytes = read(fd, buffer, 128);
if (nbytes < 0)
{
printf("main: failed to read from %s, errno=%d\n", g_testfile1, *get_errno_ptr());
@@ -127,7 +129,7 @@ int user_start(int argc, char *argv[])
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());
+ printf("main: failed to open %s for writing, errno=%d\n", g_testfile2, *get_errno_ptr());
}
else
{
@@ -136,6 +138,33 @@ int user_start(int argc, char *argv[])
{
printf("main: failed to write to %s, errno=%d\n", g_testfile2, *get_errno_ptr());
}
+ else
+ {
+ printf("main: wrote %d bytes to %s\n", nbytes, g_testfile2);
+ }
+ close(fd);
+ }
+
+ printf("main: opening %s for reading\n", g_testfile2);
+
+ fd = open(g_testfile2, O_RDONLY);
+ if (fd < 0)
+ {
+ printf("main: failed to open %s for reading, errno=%d\n", g_testfile2, *get_errno_ptr());
+ }
+ else
+ {
+ memset(buffer, 0, 128);
+ nbytes = read(fd, buffer, 128);
+ if (nbytes < 0)
+ {
+ printf("main: failed to read from %s, errno=%d\n", g_testfile2, *get_errno_ptr());
+ }
+ else
+ {
+ buffer[127]='\0';
+ printf("main: Read \"%s\" from %s\n", buffer, g_testfile2);
+ }
close(fd);
}