mirror of
https://github.com/apache/nuttx.git
synced 2026-06-06 08:36:24 +08:00
Added test for mkfatfs
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@807 42af7a65-404d-4744-a932-0658087f49c3
This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user