mirror of
https://github.com/apache/nuttx.git
synced 2026-06-06 08:36:24 +08:00
Added mkfatfs() test
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@806 42af7a65-404d-4744-a932-0658087f49c3
This commit is contained in:
+20
-3
@@ -109,7 +109,22 @@ examples/mount
|
||||
This contains a simple test of filesystem mountpoints.
|
||||
|
||||
* CONFIG_EXAMPLES_MOUNT_DEVNAME
|
||||
The name of the device to mount. Default: "/dev/ram0"
|
||||
The name of the user-provided block device to mount.
|
||||
If CONFIG_EXAMPLES_MOUNT_DEVNAME is not provided, then
|
||||
a RAM disk will be configured.
|
||||
|
||||
* CONFIG_EXAMPLES_MOUNT_NSECTORS
|
||||
The number of "sectors" in the RAM disk used when
|
||||
CONFIG_EXAMPLES_MOUNT_DEVNAME is not defined.
|
||||
|
||||
* CONFIG_EXAMPLES_MOUNT_SECTORSIZE
|
||||
The size of each sectors in the RAM disk used when
|
||||
CONFIG_EXAMPLES_MOUNT_DEVNAME is not defined.
|
||||
|
||||
* CONFIG_EXAMPLES_MOUNT_RAMDEVNO
|
||||
The RAM device minor number used to mount the RAM disk used
|
||||
when CONFIG_EXAMPLES_MOUNT_DEVNAME is not defined. The
|
||||
default is zero (meaning that "/dev/ram0" will be used).
|
||||
|
||||
examples/null
|
||||
^^^^^^^^^^^^^
|
||||
@@ -144,6 +159,8 @@ examples/pashello
|
||||
examples/pipe
|
||||
^^^^^^^^^^^^^
|
||||
|
||||
A test of the mkfifo() and pipe() APIs.
|
||||
|
||||
A test of the mkfifo() and pipe() APIs.
|
||||
|
||||
* CONFIG_EXAMPLES_PIPE_STACKSIZE
|
||||
Sets the size of the stack to use when creating the child tasks.
|
||||
The default size is 1024.
|
||||
|
||||
@@ -38,7 +38,7 @@
|
||||
|
||||
ASRCS =
|
||||
AOBJS = $(ASRCS:.S=$(OBJEXT))
|
||||
CSRCS = mount_main.c
|
||||
CSRCS = mount_main.c ramdisk.c
|
||||
COBJS = $(CSRCS:.c=$(OBJEXT))
|
||||
|
||||
SRCS = $(ASRCS) $(CSRCS)
|
||||
|
||||
@@ -0,0 +1,92 @@
|
||||
/****************************************************************************
|
||||
* examples/mount/mount.h
|
||||
*
|
||||
* Copyright (C) 2008 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* 3. Neither the name NuttX nor the names of its contributors may be
|
||||
* used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef __EXAMPLES_MOUNT_MOUNT_H
|
||||
#define __EXAMPLES_MOUNT_MOUNT_H
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
|
||||
/****************************************************************************
|
||||
* Definitions
|
||||
****************************************************************************/
|
||||
|
||||
/* Configure the test */
|
||||
|
||||
#if defined(CONFIG_EXAMPLES_MOUNT_DEVNAME)
|
||||
# undef CONFIG_EXAMPLES_MOUNT_NSECTORS
|
||||
# undef CONFIG_EXAMPLES_MOUNT_SECTORSIZE
|
||||
# undef CONFIG_EXAMPLES_MOUNT_RAMDEVNO
|
||||
# define MOUNT_DEVNAME CONFIG_EXAMPLES_MOUNT_DEVNAME
|
||||
#else
|
||||
# if !defined(CONFIG_FS_FAT)
|
||||
# error "CONFIG_FS_FAT required in this configuration"
|
||||
# endif
|
||||
# if !defined(CONFIG_EXAMPLES_MOUNT_SECTORSIZE)
|
||||
# define CONFIG_EXAMPLES_MOUNT_SECTORSIZE 512
|
||||
# endif
|
||||
# if !defined(CONFIG_EXAMPLES_MOUNT_NSECTORS)
|
||||
# define CONFIG_EXAMPLES_MOUNT_NSECTORS 2048
|
||||
# endif
|
||||
# if !defined(CONFIG_EXAMPLES_MOUNT_RAMDEVNO)
|
||||
# define CONFIG_EXAMPLES_MOUNT_RAMDEVNO 0
|
||||
# endif
|
||||
# define MKMOUNT_DEVNAME(m) "/dev/ram" #m
|
||||
# define MOUNT_DEVNAME MKMOUNT_DEVNAME(CONFIG_EXAMPLES_MOUNT_RAMDEVNO)
|
||||
#endif
|
||||
|
||||
|
||||
/****************************************************************************
|
||||
* Public Types
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Public Variables
|
||||
****************************************************************************/
|
||||
|
||||
extern const char g_source[]; /* Mount 'source' path */
|
||||
|
||||
/****************************************************************************
|
||||
* Public Function Prototypes
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef CONFIG_EXAMPLES_MOUNT_DEVNAME
|
||||
extern int create_ramdisk(void);
|
||||
#endif
|
||||
|
||||
#endif /* __EXAMPLES_MOUNT_MOUNT_H */
|
||||
+43
-29
@@ -50,14 +50,12 @@
|
||||
#include <dirent.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include "mount.h"
|
||||
|
||||
/****************************************************************************
|
||||
* Definitions
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef CONFIG_EXAMPLES_MOUNT_DEVNAME
|
||||
# define CONFIG_EXAMPLES_MOUNT_DEVNAME "/dev/ram0"
|
||||
#endif
|
||||
|
||||
#define TEST_USE_STAT 1
|
||||
#define TEST_SHOW_DIRECTORIES 1
|
||||
#define TEST_USE_STATFS 1
|
||||
@@ -70,7 +68,6 @@
|
||||
* Private Data
|
||||
****************************************************************************/
|
||||
|
||||
static const char g_source[] = CONFIG_EXAMPLES_MOUNT_DEVNAME;
|
||||
static const char g_mntdir[] = "/mnt";
|
||||
static const char g_target[] = "/mnt/fs";
|
||||
static const char g_filesystemtype[] = "vfat";
|
||||
@@ -89,6 +86,12 @@ static int g_nerrors = 0;
|
||||
|
||||
static char g_namebuffer[256];
|
||||
|
||||
/****************************************************************************
|
||||
* Public Data
|
||||
****************************************************************************/
|
||||
|
||||
const char g_source[] = MOUNT_DEVNAME;
|
||||
|
||||
/****************************************************************************
|
||||
* Private Functions
|
||||
****************************************************************************/
|
||||
@@ -157,7 +160,7 @@ static void show_statfs(const char *path)
|
||||
else
|
||||
{
|
||||
printf("show_statfs: ERROR statfs(%s) failed with errno=%d\n",
|
||||
path, *get_errno_ptr());
|
||||
path, errno);
|
||||
g_nerrors++;
|
||||
}
|
||||
}
|
||||
@@ -179,7 +182,8 @@ static void show_directories(const char *path, int indent)
|
||||
dirp = opendir(path);
|
||||
if ( !dirp )
|
||||
{
|
||||
printf("show_directories: ERROR opendir(\"%s\") failed with errno=%d\n", path, *get_errno_ptr());
|
||||
printf("show_directories: ERROR opendir(\"%s\") failed with errno=%d\n",
|
||||
path, errno);
|
||||
g_nerrors++;
|
||||
return;
|
||||
}
|
||||
@@ -228,10 +232,10 @@ static void fail_read_open(const char *path, int expectederror)
|
||||
g_nerrors++;
|
||||
close(fd);
|
||||
}
|
||||
else if (*get_errno_ptr() != expectederror)
|
||||
else if (errno != expectederror)
|
||||
{
|
||||
printf("fail_read_open: ERROR open(%s) failed with errno=%d (expected %d)\n",
|
||||
path, *get_errno_ptr(), expectederror);
|
||||
path, errno, expectederror);
|
||||
g_nerrors++;
|
||||
}
|
||||
}
|
||||
@@ -254,7 +258,7 @@ static void read_test_file(const char *path)
|
||||
if (fd < 0)
|
||||
{
|
||||
printf("read_test_file: ERROR failed to open %s, errno=%d\n",
|
||||
path, *get_errno_ptr());
|
||||
path, errno);
|
||||
g_nerrors++;
|
||||
}
|
||||
else
|
||||
@@ -264,7 +268,7 @@ static void read_test_file(const char *path)
|
||||
if (nbytes < 0)
|
||||
{
|
||||
printf("read_test_file: ERROR failed to read from %s, errno=%d\n",
|
||||
path, *get_errno_ptr());
|
||||
path, errno);
|
||||
g_nerrors++;
|
||||
}
|
||||
else
|
||||
@@ -292,7 +296,7 @@ static void write_test_file(const char *path)
|
||||
if (fd < 0)
|
||||
{
|
||||
printf("write_test_file: ERROR failed to open %s for writing, errno=%d\n",
|
||||
path, *get_errno_ptr());
|
||||
path, errno);
|
||||
g_nerrors++;
|
||||
}
|
||||
else
|
||||
@@ -301,7 +305,7 @@ static void write_test_file(const char *path)
|
||||
if (nbytes < 0)
|
||||
{
|
||||
printf("write_test_file: ERROR failed to write to %s, errno=%d\n",
|
||||
path, *get_errno_ptr());
|
||||
path, errno);
|
||||
g_nerrors++;
|
||||
}
|
||||
else
|
||||
@@ -330,10 +334,10 @@ static void fail_mkdir(const char *path, int expectederror)
|
||||
printf("fail_mkdir: ERROR mkdir(%s) succeeded\n", path);
|
||||
g_nerrors++;
|
||||
}
|
||||
else if (*get_errno_ptr() != expectederror)
|
||||
else if (errno != expectederror)
|
||||
{
|
||||
printf("fail_mkdir: ERROR mkdir(%s) failed with errno=%d (expected %d)\n",
|
||||
path, *get_errno_ptr(), expectederror);
|
||||
path, errno, expectederror);
|
||||
g_nerrors++;
|
||||
}
|
||||
}
|
||||
@@ -352,7 +356,7 @@ static void succeed_mkdir(const char *path)
|
||||
if (ret != 0)
|
||||
{
|
||||
printf("succeed_mkdir: ERROR mkdir(%s) failed with errno=%d\n",
|
||||
path, *get_errno_ptr());
|
||||
path, errno);
|
||||
g_nerrors++;
|
||||
}
|
||||
}
|
||||
@@ -375,10 +379,10 @@ static void fail_rmdir(const char *path, int expectederror)
|
||||
printf("fail_rmdir: ERROR rmdir(%s) succeeded\n", path);
|
||||
g_nerrors++;
|
||||
}
|
||||
else if (*get_errno_ptr() != expectederror)
|
||||
else if (errno != expectederror)
|
||||
{
|
||||
printf("fail_rmdir: ERROR rmdir(%s) failed with errno=%d (expected %d)\n",
|
||||
path, *get_errno_ptr(), expectederror);
|
||||
path, errno, expectederror);
|
||||
g_nerrors++;
|
||||
}
|
||||
}
|
||||
@@ -397,7 +401,7 @@ static void succeed_rmdir(const char *path)
|
||||
if (ret != 0)
|
||||
{
|
||||
printf("succeed_rmdir: ERROR rmdir(%s) failed with errno=%d\n",
|
||||
path, *get_errno_ptr());
|
||||
path, errno);
|
||||
g_nerrors++;
|
||||
}
|
||||
}
|
||||
@@ -420,10 +424,10 @@ static void fail_unlink(const char *path, int expectederror)
|
||||
printf("fail_unlink: ERROR unlink(%s) succeeded\n", path);
|
||||
g_nerrors++;
|
||||
}
|
||||
else if (*get_errno_ptr() != expectederror)
|
||||
else if (errno != expectederror)
|
||||
{
|
||||
printf("fail_unlink: ERROR unlink(%s) failed with errno=%d (expected %d)\n",
|
||||
path, *get_errno_ptr(), expectederror);
|
||||
path, errno, expectederror);
|
||||
g_nerrors++;
|
||||
}
|
||||
}
|
||||
@@ -444,7 +448,7 @@ static void succeed_unlink(const char *path)
|
||||
if (ret != 0)
|
||||
{
|
||||
printf("succeed_unlink: ERROR unlink(%s) failed with errno=%d\n",
|
||||
path, *get_errno_ptr());
|
||||
path, errno);
|
||||
g_nerrors++;
|
||||
}
|
||||
}
|
||||
@@ -468,10 +472,10 @@ static void fail_rename(const char *oldpath, const char *newpath, int expecteder
|
||||
oldpath, newpath);
|
||||
g_nerrors++;
|
||||
}
|
||||
else if (*get_errno_ptr() != expectederror)
|
||||
else if (errno != expectederror)
|
||||
{
|
||||
printf("fail_rename: ERROR rename(%s->%s) failed with errno=%d (expected %d)\n",
|
||||
oldpath, newpath, *get_errno_ptr(), expectederror);
|
||||
oldpath, newpath, errno, expectederror);
|
||||
g_nerrors++;
|
||||
}
|
||||
}
|
||||
@@ -490,7 +494,7 @@ static void succeed_rename(const char *oldpath, const char *newpath)
|
||||
if (ret != 0)
|
||||
{
|
||||
printf("succeed_rename: ERROR rename(%s->%s) failed with errno=%d\n",
|
||||
oldpath, newpath, *get_errno_ptr());
|
||||
oldpath, newpath, errno);
|
||||
g_nerrors++;
|
||||
}
|
||||
}
|
||||
@@ -516,10 +520,10 @@ static void fail_stat(const char *path, int expectederror)
|
||||
show_stat(path, &buf);
|
||||
g_nerrors++;
|
||||
}
|
||||
else if (*get_errno_ptr() != expectederror)
|
||||
else if (errno != expectederror)
|
||||
{
|
||||
printf("fail_stat: ERROR stat(%s) failed with errno=%d (expected %d)\n",
|
||||
path, *get_errno_ptr(), expectederror);
|
||||
path, errno, expectederror);
|
||||
g_nerrors++;
|
||||
}
|
||||
}
|
||||
@@ -543,7 +547,7 @@ static void succeed_stat(const char *path)
|
||||
if (ret != 0)
|
||||
{
|
||||
printf("succeed_stat: ERROR stat(%s) failed with errno=%d\n",
|
||||
path, *get_errno_ptr());
|
||||
path, errno);
|
||||
g_nerrors++;
|
||||
}
|
||||
else
|
||||
@@ -576,6 +580,16 @@ int user_start(int argc, char *argv[])
|
||||
{
|
||||
int ret;
|
||||
|
||||
#ifndef CONFIG_EXAMPLES_MOUNT_DEVNAME
|
||||
/* Create a RAM disk for the test */
|
||||
|
||||
ret = create_ramdisk();
|
||||
if (ret < 0)
|
||||
{
|
||||
printf("user_start: ERROR failed to create RAM disk\n");
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Mount the test file system (see arch/sim/src/up_deviceimage.c */
|
||||
|
||||
printf("user_start: mounting %s filesystem at target=%s with source=%s\n",
|
||||
@@ -722,7 +736,7 @@ int user_start(int argc, char *argv[])
|
||||
ret = umount(g_target);
|
||||
if (ret != 0)
|
||||
{
|
||||
printf("user_start: ERROR umount() failed, errno %d\n", *get_errno_ptr());
|
||||
printf("user_start: ERROR umount() failed, errno %d\n", errno);
|
||||
g_nerrors++;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,138 @@
|
||||
/****************************************************************************
|
||||
* examples/mount/ramdisk.c
|
||||
*
|
||||
* Copyright (C) 2008 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* 3. Neither the name NuttX nor the names of its contributors may be
|
||||
* used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <debug.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include <nuttx/ramdisk.h>
|
||||
#include <nuttx/mkfatfs.h>
|
||||
|
||||
#include "mount.h"
|
||||
|
||||
#ifndef CONFIG_EXAMPLES_MOUNT_DEVNAME
|
||||
|
||||
/****************************************************************************
|
||||
* Private Definitions
|
||||
****************************************************************************/
|
||||
|
||||
#define BUFFER_SIZE (CONFIG_EXAMPLES_MOUNT_NSECTORS*CONFIG_EXAMPLES_MOUNT_SECTORSIZE)
|
||||
|
||||
/****************************************************************************
|
||||
* Private Types
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Private Function Prototypes
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Private Data
|
||||
****************************************************************************/
|
||||
|
||||
static struct fat_format_s g_fmt = FAT_FORMAT_INITIALIZER;
|
||||
|
||||
/****************************************************************************
|
||||
* Private Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: create_ramdisk
|
||||
*
|
||||
* Description:
|
||||
* Create a RAM disk of the specified size formatting with a FAT file
|
||||
* system
|
||||
*
|
||||
* Input Parameters:
|
||||
* None
|
||||
*
|
||||
* Return:
|
||||
* Zero on success, a negated errno on failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int create_ramdisk(void)
|
||||
{
|
||||
char *pbuffer;
|
||||
int ret;
|
||||
|
||||
/* Allocate a buffer to hold the file system image. */
|
||||
|
||||
pbuffer = (char*)malloc(BUFFER_SIZE);
|
||||
if (!pbuffer)
|
||||
{
|
||||
dbg("Failed to allocate ramdisk of size %d\n", BUFFER_SIZE);
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
/* Register a RAMDISK device to manage this RAM image */
|
||||
|
||||
ret = rd_register(CONFIG_EXAMPLES_MOUNT_RAMDEVNO,
|
||||
pbuffer,
|
||||
CONFIG_EXAMPLES_MOUNT_NSECTORS,
|
||||
CONFIG_EXAMPLES_MOUNT_NSECTORS,
|
||||
TRUE);
|
||||
if (ret < 0)
|
||||
{
|
||||
dbg("Failed to register ramdisk at %s\n", g_source);
|
||||
free(pbuffer);
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* Create a FAT filesystem on the ramdisk */
|
||||
|
||||
ret = mkfatfs(g_source, &g_fmt);
|
||||
if (ret < 0)
|
||||
{
|
||||
dbg("Failed to create FAT filesystem on ramdisk at %s\n", g_source);
|
||||
/* free(pbuffer); -- RAM disk is registered */
|
||||
return ret;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
#endif /* !CONFIG_EXAMPLES_MOUNT_DEVNAME */
|
||||
Reference in New Issue
Block a user