From 4815a2fb0e87d0b64a61f57f287de92be5027e90 Mon Sep 17 00:00:00 2001 From: patacongo Date: Sun, 20 May 2007 23:22:56 +0000 Subject: Implemented FAT write git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@244 42af7a65-404d-4744-a932-0658087f49c3 --- nuttx/examples/mount/mount_main.c | 41 +++++++++++++++++++++++++++++++++------ 1 file changed, 35 insertions(+), 6 deletions(-) (limited to 'nuttx/examples/mount/mount_main.c') 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); } -- cgit v1.2.3