9
0
Fork 0

Added test for mkfatfs

git-svn-id: https://nuttx.svn.sourceforge.net/svnroot/nuttx/trunk@807 7fd9a85b-ad96-42d3-883c-3090e2eb8679
This commit is contained in:
patacongo 2008-08-10 16:36:33 +00:00
parent 850816f817
commit 0cbe975493
10 changed files with 116 additions and 44 deletions

View File

@ -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.

View File

@ -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>

View File

@ -21,7 +21,7 @@ User's Manual
<p>
Gregory Nutt
<p>
<small>Last Update: July 20, 2008</small>
<small>Last Update: August 10, 2008</small>
</center>
<h1>1.0 <A NAME="Introduction">Introduction</a></h1>
@ -5843,7 +5843,16 @@ interface of the same name.
<h1><a name="FileSystem">2.11 File System Interfaces</a></h1>
<h2><a name="FileSystemOverview"2.11.1 >Overview</a></h2>
<ul>
<li><a href="#FileSystemOverview">2.11.1 NuttX File System Overview</a></li>
<li><a href="#driveroperations">2.11.2 Driver Operations</a></li>
<li><a href="#directoryoperations">2.11.3 Directory Operations</a></li>
<li><a href="#standardio">2.11.4 Standard I/O</a></li>
<li><a href="#PipesNFifos">2.11.5 Pipes and FIFOs</a></li>
<li><a href="#fatsupport">2.11.6 FAT File System Support</a></li>
</ul>
<h2><a name="FileSystemOverview">2.11.1 NuttX File System Overview</a></h2>
<p><b>Overview</b>.
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 */
</pre></ul>
<h2><a name="PipesNFifos">2.11.4 Pipes and FIFOs</a></h2>
<h2><a name="PipesNFifos">2.11.5 Pipes and FIFOs</a></h2>
<h3>2.11.4.1 <a name="pipe"><code>pipe</code></a></h3>
<h3>2.11.5.1 <a name="pipe"><code>pipe</code></a></h3>
<p>
<b>Function Prototype:</b>
</p>
@ -6007,7 +6016,7 @@ interface of the same name.
</ul>
</p>
<h3>2.11.4.2 <a name="mkfifo"><code>mkfifo</code></a></h3>
<h3>2.11.5.2 <a name="mkfifo"><code>mkfifo</code></a></h3>
<p>
<b>Function Prototype:</b>
</p>
@ -6054,22 +6063,25 @@ interface of the same name.
</ul>
</p>
<h2><a name="setenv">2.10.4 <code>setenv</code></a></h2>
<h2><a name="fatsupport">2.11.6 FAT File System Support</a></h2>
<h3>2.11.5.1 <a name="mkfatfs"><code>mkfatfs</code></a></h3>
<p>
<b>Function Prototype:</b>
</p>
<pre>
#include <stdlib.h>
int setenv(const char *name, const char *value, int overwrite);
</pre>
<ul><pre>
#include <nutts/mkfatfs.h>
int mkfatfs(FAR const char *pathname, FAR struct fat_format_s *fmt);
</pre></ul>
<p>
<b>Description:</b>
<ul>
<p>
The <code>setenv()</code> function adds the variable <code>name</code> to the environment with the
specified <code>value</code> if the variable <code>name</code> does not exist. If the <code>name</code>
does exist in the environment, then its value is changed to <code>value</code> if <code>overwrite</code>
is non-zero; if <code>overwrite</code> is zero, then the value of <code>name</code> is unaltered.
The <code>mkfafs()</code> formats a FAT file system image on the block
device specified by <code>pathname</code>
</p>
<p>Assumptions: The caller must assure that the block driver is not mounted and not in
use when this function is called.
The result of formatting a mounted device is indeterminate (but likely not good).
</p>
</ul>
</p>
@ -6077,16 +6089,30 @@ interface of the same name.
<b>Input Parameters:</b>
<ul>
<li>
<code>name</code>
The name of the variable to change.
<code>pathname</code>
The full path to the registered block driver in the file system.
</li>
<li>
<code>value</code>
The new value of the variable.
</li>
<li>
<code>value</code>
Replace any existing value if non-zero.
<code>fmt</code>
A reference to an instance of a structure that provides caller-selectable
attributes of the created FAT file system.
<ul>
<pre>
struct fat_format_s
{
ubyte ff_nfats; /* Number of FATs */
ubyte ff_fattype; /* FAT size: 0 (autoselect), 12, 16, or 32 */
ubyte ff_clustshift; /* Log2 of sectors per cluster: 0-5, 0xff (autoselect) */
ubyte ff_volumelabel[11]; /* Volume label */
uint16 ff_backupboot; /* Sector number of the backup boot sector (0=use default)*/
uint16 ff_rootdirentries; /* Number of root directory entries */
uint16 ff_rsvdseccount; /* Reserved sectors */
uint32 ff_hidsec; /* Count of hidden sectors preceding fat */
uint32 ff_volumeid; /* FAT volume id */
uint32 ff_nsectors; /* Number of sectors from device to use: 0: Use all */
};
</pre>
</ul></li>
</li>
</ul>
</p>
@ -6094,7 +6120,23 @@ interface of the same name.
<b>Returned Values:</b>
<ul>
<p>
Zero on success.
Zero (<code>OK</code>) on success;
-1 (<code>ERROR</code>) on failure with <code>errno</code> set appropriately:
<ul>
<li><code>EINVAL</code> -
NULL block driver string, bad number of FATS in <code>fmt</code>,
bad FAT size in <code>fmt</code>, bad cluster size in <code>fmt</code>
</li>
<li><code>ENOENT</code> -
<code>pathname</code> does not refer to anything in the filesystem.
</li>
<li><code>ENOTBLK</code> -
<code>pathname</code> does not refer to a block driver
</li>
<li><code>EACCESS</code> -
block driver does not support write or geometry methods
</li>
</ul>
</p>
</ul>
</p>
@ -6928,7 +6970,7 @@ notify a task when a message is available on a queue.
<h1><a name="index">Index</a></h1>
<table width="100%">
<tr>
<td>
<td valign="top">
<li><a href="#accept">accept</a></li>
<li><a href="#bind">bind</a></li>
<li><a href="#clockgetres">clock_getres</a></li>
@ -6940,6 +6982,7 @@ notify a task when a message is available on a queue.
<li><a href="#directoryoperations">Directory operations</a></li>
<li><a href="#driveroperations">Driver operations</a></li>
<li><a href="#exit">exit</a></li>
<li><a href="#fatsupport">FAT File System Support</a></li>
<li><a href="#FileSystem">File system, interfaces</a></li>
<li><a href="#FileSystemOverview">File system, overview</a></li>
<li><a href="#getpid">getpid</a></li>
@ -6950,6 +6993,7 @@ notify a task when a message is available on a queue.
<li><a href="#listen">listen</a></li>
<li><a href="#localtimer">localtime_r</a></li>
<li><a href="#Message_Queue">Named Message Queue Interfaces</a>
<li><a href="#mkfatfs">mkfatfs</a></li>
<li><a href="#mkfifo">mkfifo</a></li>
<li><a href="#mktime">mktime</a></li>
<li><a href="#mqclose">mq_close</a></li>
@ -7005,9 +7049,9 @@ notify a task when a message is available on a queue.
<li><a href="#pthreadmutexattrgetpshared">pthread_mutexattr_getpshared</a></li>
<li><a href="#pthreadmutexattrgettype">pthread_mutexattr_gettype</a></li>
<li><a href="#pthreadmutexattrinit">pthread_mutexattr_init</a></li>
<li><a href="#pthreadmutexattrsetpshared">pthread_mutexattr_setpshared</a></li>
</td>
<td>
<td valign="top">
<li><a href="#pthreadmutexattrsetpshared">pthread_mutexattr_setpshared</a></li>
<li><a href="#pthreadmutexattrsettype">pthread_mutexattr_settype</a></li>
<li><a href="#pthreadmutexdestrory">pthread_mutex_destroy</a></li>
<li><a href="#pthreadmutexinit">pthread_mutex_init</a></li>

View File

@ -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
#

View File

@ -43,6 +43,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <debug.h>
#include <errno.h>
#include <nuttx/fs.h>
@ -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);
}
}

View File

@ -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

View File

@ -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);

View File

@ -40,9 +40,9 @@
#include <nuttx/config.h>
#include <sys/types.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <debug.h>
#include <errno.h>
#include <nuttx/ramdisk.h>
@ -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;
}

View File

@ -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);

View File

@ -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