From 0cbe9754939282b05dbf12606e741f59e36072bc Mon Sep 17 00:00:00 2001 From: patacongo Date: Sun, 10 Aug 2008 16:36:33 +0000 Subject: [PATCH] Added test for mkfatfs git-svn-id: https://nuttx.svn.sourceforge.net/svnroot/nuttx/trunk@807 7fd9a85b-ad96-42d3-883c-3090e2eb8679 --- nuttx/ChangeLog | 3 +- nuttx/Documentation/NuttX.html | 3 +- nuttx/Documentation/NuttxUserGuide.html | 96 ++++++++++++++++++------- nuttx/configs/sim/mount/defconfig | 4 ++ nuttx/drivers/ramdisk.c | 2 + nuttx/examples/mount/mount.h | 3 +- nuttx/examples/mount/mount_main.c | 25 +++++-- nuttx/examples/mount/ramdisk.c | 13 ++-- nuttx/fs/fat/fs_mkfatfs.c | 3 +- nuttx/include/nuttx/mkfatfs.h | 8 +-- 10 files changed, 116 insertions(+), 44 deletions(-) diff --git a/nuttx/ChangeLog b/nuttx/ChangeLog index 9e2e4347b..28703b510 100644 --- a/nuttx/ChangeLog +++ b/nuttx/ChangeLog @@ -389,5 +389,6 @@ * Moved all FAT related files from fs to fs/fat * Implemented mkfatfs(), a non-standard API to create a FAT filesystem on a block device (not yet tested). - * Added a test for mkfatfs() on a RAM disk in examples/mount + * Added a test for mkfatfs() on a RAM disk in examples/mount and verified + basic mkfatfs functionality for FAT12. diff --git a/nuttx/Documentation/NuttX.html b/nuttx/Documentation/NuttX.html index fc53f66ef..bd914f23b 100644 --- a/nuttx/Documentation/NuttX.html +++ b/nuttx/Documentation/NuttX.html @@ -1038,7 +1038,8 @@ nuttx-0.3.12 2008-xx-xx Gregory Nutt <spudmonkey@racsa.co.cr> * Moved all FAT related files from fs to fs/fat * Implemented mkfatfs(), a non-standard API to create a FAT filesystem on a block device (not yet tested). - * Added a test for mkfatfs() on a RAM disk in examples/mount + * Added a test for mkfatfs() on a RAM disk in examples/mount and verified + basic mkfatfs functionality for FAT12. pascal-0.1.3 2008-xx-xx Gregory Nutt <spudmonkey@racsa.co.cr> diff --git a/nuttx/Documentation/NuttxUserGuide.html b/nuttx/Documentation/NuttxUserGuide.html index f480187bc..a6e6ea90d 100644 --- a/nuttx/Documentation/NuttxUserGuide.html +++ b/nuttx/Documentation/NuttxUserGuide.html @@ -21,7 +21,7 @@ User's Manual

Gregory Nutt

-Last Update: July 20, 2008 +Last Update: August 10, 2008

1.0 Introduction

@@ -5843,7 +5843,16 @@ interface of the same name.

2.11 File System Interfaces

-

Overview

+ + +

2.11.1 NuttX File System Overview

Overview. NuttX includes an optional, scalable file system. @@ -5971,9 +5980,9 @@ interface of the same name. int statfs(const char *path, FAR struct statfs *buf); /* Prototyped but not implemented */ -

2.11.4 Pipes and FIFOs

+

2.11.5 Pipes and FIFOs

-

2.11.4.1 pipe

+

2.11.5.1 pipe

Function Prototype:

@@ -6007,7 +6016,7 @@ interface of the same name.

-

2.11.4.2 mkfifo

+

2.11.5.2 mkfifo

Function Prototype:

@@ -6054,22 +6063,25 @@ interface of the same name.

-

2.10.4 setenv

+

2.11.6 FAT File System Support

+

2.11.5.1 mkfatfs

Function Prototype:

-
-  #include 
-  int setenv(const char *name, const char *value, int overwrite);
-
+

Description:

@@ -6077,16 +6089,30 @@ interface of the same name. Input Parameters:

@@ -6094,7 +6120,23 @@ interface of the same name. Returned Values:

@@ -6928,7 +6970,7 @@ notify a task when a message is available on a queue.

Index

- -
+
  • accept
  • bind
  • clock_getres
  • @@ -6940,6 +6982,7 @@ notify a task when a message is available on a queue.
  • Directory operations
  • Driver operations
  • exit
  • +
  • FAT File System Support
  • File system, interfaces
  • File system, overview
  • getpid
  • @@ -6950,6 +6993,7 @@ notify a task when a message is available on a queue.
  • listen
  • localtime_r
  • Named Message Queue Interfaces +
  • mkfatfs
  • mkfifo
  • mktime
  • mq_close
  • @@ -7005,9 +7049,9 @@ notify a task when a message is available on a queue.
  • pthread_mutexattr_getpshared
  • pthread_mutexattr_gettype
  • pthread_mutexattr_init
  • -
  • pthread_mutexattr_setpshared
  • + +
  • pthread_mutexattr_setpshared
  • pthread_mutexattr_settype
  • pthread_mutex_destroy
  • pthread_mutex_init
  • diff --git a/nuttx/configs/sim/mount/defconfig b/nuttx/configs/sim/mount/defconfig index 1acf235ce..e77905b55 100644 --- a/nuttx/configs/sim/mount/defconfig +++ b/nuttx/configs/sim/mount/defconfig @@ -301,6 +301,10 @@ CONFIG_EXAMPLES_NSH_NETMASK=(255<<24|255<<16|255<<8|0) # # Settings for examples/mount CONFIG_EXAMPLES_MOUNT_DEVNAME="/dev/ram0" +#CONFIG_EXAMPLES_MOUNT_NSECTORS=2048 +#CONFIG_EXAMPLES_MOUNT_SECTORSIZE=512 +#CONFIG_EXAMPLES_MOUNT_RAMDEVNO=1 + # # Stack and heap information # diff --git a/nuttx/drivers/ramdisk.c b/nuttx/drivers/ramdisk.c index 506eb4593..48c969030 100644 --- a/nuttx/drivers/ramdisk.c +++ b/nuttx/drivers/ramdisk.c @@ -43,6 +43,7 @@ #include #include #include +#include #include #include @@ -243,6 +244,7 @@ int rd_register(int minor, ubyte *buffer, uint32 nsectors, uint16 sectsize, ret = register_blockdriver(devname, &g_bops, 0, dev); if (ret < 0) { + fdbg("register_blockdriver failed: %d\n", -ret); free(dev); } } diff --git a/nuttx/examples/mount/mount.h b/nuttx/examples/mount/mount.h index 388a6200b..5a2ab61cd 100644 --- a/nuttx/examples/mount/mount.h +++ b/nuttx/examples/mount/mount.h @@ -66,7 +66,8 @@ # if !defined(CONFIG_EXAMPLES_MOUNT_RAMDEVNO) # define CONFIG_EXAMPLES_MOUNT_RAMDEVNO 0 # endif -# define MKMOUNT_DEVNAME(m) "/dev/ram" #m +# define STR_RAMDEVNO(m) #m +# define MKMOUNT_DEVNAME(m) "/dev/ram" STR_RAMDEVNO(m) # define MOUNT_DEVNAME MKMOUNT_DEVNAME(CONFIG_EXAMPLES_MOUNT_RAMDEVNO) #endif diff --git a/nuttx/examples/mount/mount_main.c b/nuttx/examples/mount/mount_main.c index 3959abefb..74c692e77 100644 --- a/nuttx/examples/mount/mount_main.c +++ b/nuttx/examples/mount/mount_main.c @@ -76,7 +76,9 @@ static const char g_testdir1[] = "/mnt/fs/TestDir"; static const char g_testdir2[] = "/mnt/fs/NewDir1"; static const char g_testdir3[] = "/mnt/fs/NewDir2"; static const char g_testdir4[] = "/mnt/fs/NewDir3"; +#ifdef CONFIG_EXAMPLES_MOUNT_DEVNAME static const char g_testfile1[] = "/mnt/fs/TestDir/TestFile.txt"; +#endif static const char g_testfile2[] = "/mnt/fs/TestDir/WrTest1.txt"; static const char g_testfile3[] = "/mnt/fs/NewDir1/WrTest2.txt"; static const char g_testfile4[] = "/mnt/fs/NewDir3/Renamed.txt"; @@ -218,7 +220,7 @@ static void show_directories(const char *path, int indent) /**************************************************************************** * Name: fail_read_open ****************************************************************************/ - +#ifdef CONFIG_EXAMPLES_MOUNT_DEVNAME static void fail_read_open(const char *path, int expectederror) { int fd; @@ -239,6 +241,7 @@ static void fail_read_open(const char *path, int expectederror) g_nerrors++; } } +#endif /**************************************************************************** * Name: read_test_file @@ -587,6 +590,7 @@ int user_start(int argc, char *argv[]) if (ret < 0) { printf("user_start: ERROR failed to create RAM disk\n"); + return 1; } #endif @@ -603,12 +607,21 @@ int user_start(int argc, char *argv[]) show_statfs(g_mntdir); show_statfs(g_target); +#ifdef CONFIG_EXAMPLES_MOUNT_DEVNAME /* Read a test file that is already on the test file system image */ show_directories("", 0); succeed_stat(g_testfile1); show_statfs(g_testfile1); read_test_file(g_testfile1); +#else + /* Create the test directory that would have been on the canned filesystem */ + + succeed_mkdir(g_testdir1); + show_directories("", 0); + succeed_stat(g_testdir1); + show_statfs(g_testdir1); +#endif /* Write a test file into a pre-existing directory on the test file system */ @@ -623,8 +636,9 @@ int user_start(int argc, char *argv[]) read_test_file(g_testfile2); /* Try rmdir() against a file on the directory. It should fail with ENOTDIR */ - +#ifdef CONFIG_EXAMPLES_MOUNT_DEVNAME fail_rmdir(g_testfile1, ENOTDIR); +#endif /* Try rmdir() against the test directory. It should fail with ENOTEMPTY */ @@ -635,15 +649,16 @@ int user_start(int argc, char *argv[]) fail_unlink(g_testdir1, EISDIR); /* Try unlink() against the test file1. It should succeed. */ - +#ifdef CONFIG_EXAMPLES_MOUNT_DEVNAME succeed_unlink(g_testfile1); fail_stat(g_testfile1, ENOENT); show_directories("", 0); +#endif /* Attempt to open testfile1 should fail with ENOENT */ - +#ifdef CONFIG_EXAMPLES_MOUNT_DEVNAME fail_read_open(g_testfile1, ENOENT); - +#endif /* Try rmdir() against the test directory. It should still fail with ENOTEMPTY */ fail_rmdir(g_testdir1, ENOTEMPTY); diff --git a/nuttx/examples/mount/ramdisk.c b/nuttx/examples/mount/ramdisk.c index 47238e336..905c56492 100644 --- a/nuttx/examples/mount/ramdisk.c +++ b/nuttx/examples/mount/ramdisk.c @@ -40,9 +40,9 @@ #include #include +#include #include #include -#include #include #include @@ -105,7 +105,8 @@ int create_ramdisk(void) pbuffer = (char*)malloc(BUFFER_SIZE); if (!pbuffer) { - dbg("Failed to allocate ramdisk of size %d\n", BUFFER_SIZE); + printf("create_ramdisk: Failed to allocate ramdisk of size %d\n", + BUFFER_SIZE); return -ENOMEM; } @@ -114,11 +115,12 @@ int create_ramdisk(void) ret = rd_register(CONFIG_EXAMPLES_MOUNT_RAMDEVNO, pbuffer, CONFIG_EXAMPLES_MOUNT_NSECTORS, - CONFIG_EXAMPLES_MOUNT_NSECTORS, + CONFIG_EXAMPLES_MOUNT_SECTORSIZE, TRUE); if (ret < 0) { - dbg("Failed to register ramdisk at %s\n", g_source); + printf("create_ramdisk: Failed to register ramdisk at %s: %d\n", + g_source, -ret); free(pbuffer); return ret; } @@ -128,7 +130,8 @@ int create_ramdisk(void) ret = mkfatfs(g_source, &g_fmt); if (ret < 0) { - dbg("Failed to create FAT filesystem on ramdisk at %s\n", g_source); + printf("create_ramdisk: Failed to create FAT filesystem on ramdisk at %s\n", + g_source); /* free(pbuffer); -- RAM disk is registered */ return ret; } diff --git a/nuttx/fs/fat/fs_mkfatfs.c b/nuttx/fs/fat/fs_mkfatfs.c index ce467e8ab..d9bd8fe30 100644 --- a/nuttx/fs/fat/fs_mkfatfs.c +++ b/nuttx/fs/fat/fs_mkfatfs.c @@ -209,13 +209,14 @@ int mkfatfs(FAR const char *pathname, FAR struct fat_format_s *fmt) ret = -EINVAL; goto errout; } +#endif var.fv_fattype = fmt->ff_fattype; /* The valid range off ff_clustshift is {0,1,..7} corresponding to * cluster sizes of {1,2,..128} sectors. The special value of 0xff * means that we should autoselect the cluster sizel. */ - +#ifdef CONFIG_DEBUG if (fmt->ff_clustshift > 7 && fmt->ff_clustshift != 0xff) { fdbg("Invalid cluster shift value: %d\n", fmt->ff_clustshift); diff --git a/nuttx/include/nuttx/mkfatfs.h b/nuttx/include/nuttx/mkfatfs.h index 7f43c8673..22a08d972 100644 --- a/nuttx/include/nuttx/mkfatfs.h +++ b/nuttx/include/nuttx/mkfatfs.h @@ -48,8 +48,8 @@ ****************************************************************************/ #define MKFATFS_DEFAULT_NFATS 2 /* 2: Default number of FATs */ -#define MKFATFS_DEFAULT_FATTYPE 0xff /* 0: Autoselect FAT size */ -#define MKFATFS_DEFAULT_CLUSTSIZE 0 /* 0: Autoselect cluster size */ +#define MKFATFS_DEFAULT_FATTYPE 0 /* 0: Autoselect FAT size */ +#define MKFATFS_DEFAULT_CLUSTSHIFT 0xff /* 0xff: Autoselect cluster size */ #define MKFATFS_DEFAULT_VOLUMELABEL { ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ' } #define MKFATFS_DEFAULT_BKUPBOOT 0 /* 0: Determine sector number of the backup boot sector */ #define MKFATFS_DEFAULT_ROOTDIRENTS 0 /* 0: Autoselect number of root directory entries */ @@ -62,7 +62,7 @@ { \ MKFATFS_DEFAULT_NFATS, \ MKFATFS_DEFAULT_FATTYPE, \ - MKFATFS_DEFAULT_CLUSTSIZE, \ + MKFATFS_DEFAULT_CLUSTSHIFT, \ MKFATFS_DEFAULT_VOLUMELABEL, \ MKFATFS_DEFAULT_BKUPBOOT, \ MKFATFS_DEFAULT_ROOTDIRENTS, \ @@ -127,7 +127,7 @@ extern "C" { * size in 'fmt', bad cluster size in 'fmt' * ENOENT - 'pathname' does not refer to anything in the filesystem. * ENOTBLK - 'pathname' does not refer to a block driver - * EACCESS - block driver does not support wrie or geometry methods + * EACCESS - block driver does not support write or geometry methods * * Assumptions: * - The caller must assure that the block driver is not mounted and not in