Add a test of the union file system to apps/examaples.

This commit is contained in:
Gregory Nutt 2015-06-05 14:23:07 -06:00
parent 3a83a3068f
commit ae6868bf9e
16 changed files with 488 additions and 0 deletions

View File

@ -74,6 +74,7 @@ source "$APPSDIR/examples/touchscreen/Kconfig"
source "$APPSDIR/examples/udp/Kconfig"
source "$APPSDIR/examples/discover/Kconfig"
source "$APPSDIR/examples/webserver/Kconfig"
source "$APPSDIR/examples/unionfs/Kconfig"
source "$APPSDIR/examples/usbserial/Kconfig"
source "$APPSDIR/examples/usbterm/Kconfig"
source "$APPSDIR/examples/udgram/Kconfig"

View File

@ -1852,6 +1852,27 @@ examples/udp
CONFIG_NETUTILS_NETLIB=y
examples/unionfs
^^^^^^^^^^^^^^^^
This is at trivial test of the Union File System. See
nuttx/fs/unionfs/README.txt. Dependencies:
CONFIG_DISABLE_MOUNTPOINT - Mountpoint support must not be disabled
CONFIG_NFILE_DESCRIPTORS < 4 - Some file descriptors must be allocated
CONFIG_FS_ROMFS - ROMFS support is required
CONFIG_FS_UNIONFS - Union File System support is required
Configuration options. Use the defaults if you are unsure of what you are doing:
CONFIG_EXAMPLES_UNIONFS - Enables the example
CONFIG_EXAMPLES_UNIONFS_MOUNTPT - Mountpoint path for the Union File System
CONFIG_EXAMPLES_UNIONFS_TMPA - Temporary mount point for file system 1
CONFIG_EXAMPLES_UNIONFS_TMPB - Temporary mount point for file system 2
CONFIG_EXAMPLES_UNIONFS_RAMDEVNO_A - ROMFS file system 1 RAM disk device number
CONFIG_EXAMPLES_UNIONFS_RAMDEVNO_B - ROMFS file system 2 RAM disk device number
CONFIG_EXAMPLES_UNIONFS_SECTORSIZE - ROM disk sector size.
examples/usbserial
^^^^^^^^^^^^^^^^^^

15
examples/unionfs/.gitignore vendored Normal file
View File

@ -0,0 +1,15 @@
/Make.dep
/.depend
/.built
/atestdir.img
/btestdir.img
/romfs_atestdir.h
/romfs_btestdir.h
/*.asm
/*.obj
/*.rel
/*.lst
/*.sym
/*.adb
/*.lib
/*.src

39
examples/unionfs/Kconfig Normal file
View File

@ -0,0 +1,39 @@
#
# For a description of the syntax of this configuration file,
# see misc/tools/kconfig-language.txt.
#
config EXAMPLES_UNIONFS
bool "Union file system example"
default n
depends on FS_ROMFS || FS_UNIONFS
---help---
Enable the Union File System example
if EXAMPLES_UNIONFS
config EXAMPLES_UNIONFS_MOUNTPT
string "Union FS mount point"
default "/mnt/unionfs"
config EXAMPLES_UNIONFS_RAMDEVNO_A
int "File system 1 RAM disk device number"
default 1
config EXAMPLES_UNIONFS_RAMDEVNO_B
int "File system 1 RAM disk device number"
default 2
config EXAMPLES_UNIONFS_SECTORSIZE
int "ROMFS sector size"
default 64
config EXAMPLES_UNIONFS_TMPA
string "File system 1 temporary point"
default "/mnt/a"
config EXAMPLES_UNIONFS_TMPB
string "File system 2 temporary point"
default "/mnt/b"
endif

View File

@ -0,0 +1,38 @@
############################################################################
# apps/examples/unionfs/Make.defs
#
# Copyright (C) 2015 Gregory Nutt. All rights reserved.
# Author: Gregory Nutt <gnutt@nuttx.org>
#
# 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.
#
############################################################################
ifeq ($(CONFIG_EXAMPLES_UNIONFS),y)
CONFIGURED_APPS += examples/unionfs
endif

159
examples/unionfs/Makefile Normal file
View File

@ -0,0 +1,159 @@
############################################################################
# apps/examples/unionfs/Makefile
#
# Copyright (C) 2015 Gregory Nutt. All rights reserved.
# Author: Gregory Nutt <gnutt@nuttx.org>
#
# 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.
#
############################################################################
-include $(TOPDIR)/.config
-include $(TOPDIR)/Make.defs
include $(APPDIR)/Make.defs
# UNIONFS built-in application info
APPNAME = unionfs
PRIORITY = SCHED_PRIORITY_DEFAULT
STACKSIZE = 2048
# UNIONFS File System Example
ASRCS =
CSRCS =
MAINSRC = unionfs_main.c
AOBJS = $(ASRCS:.S=$(OBJEXT))
COBJS = $(CSRCS:.c=$(OBJEXT))
MAINOBJ = $(MAINSRC:.c=$(OBJEXT))
SRCS = $(ASRCS) $(CSRCS) $(MAINSRC)
OBJS = $(AOBJS) $(COBJS)
ifneq ($(CONFIG_BUILD_KERNEL),y)
OBJS += $(MAINOBJ)
endif
ifeq ($(CONFIG_WINDOWS_NATIVE),y)
BIN = ..\..\libapps$(LIBEXT)
else
ifeq ($(WINTOOL),y)
BIN = ..\\..\\libapps$(LIBEXT)
else
BIN = ../../libapps$(LIBEXT)
endif
endif
ifeq ($(WINTOOL),y)
INSTALL_DIR = "${shell cygpath -w $(BIN_DIR)}"
else
INSTALL_DIR = $(BIN_DIR)
endif
CONFIG_XYZ_PROGNAME ?= unionfs$(EXEEXT)
PROGNAME = $(CONFIG_XYZ_PROGNAME)
ROOTDEPPATH = --dep-path .
# Common build
VPATH =
all: .built
.PHONY: checkgenromfs clean depend distclean
$(AOBJS): %$(OBJEXT): %.S
$(call ASSEMBLE, $<, $@)
$(COBJS) $(MAINOBJ): %$(OBJEXT): %.c
$(call COMPILE, $<, $@)
checkgenromfs:
@genromfs -h 1>/dev/null 2>&1 || { \
echo "Host executable genromfs not available in PATH"; \
echo "You may need to download in from http://unionfs.sourceforge.net/"; \
exit 1; \
}
atestdir.img : checkgenromfs
@genromfs -f $@ -d atestdir -V "UNIONFS_Test" || { echo "genromfs failed" ; exit 1 ; }
romfs_atestdir.h : atestdir.img
@xxd -i $< >$@ || { echo "xxd of $< failed" ; exit 1 ; }
btestdir.img : checkgenromfs
@genromfs -f $@ -d btestdir -V "UNIONFS_Test" || { echo "genromfs failed" ; exit 1 ; }
romfs_btestdir.h : btestdir.img
@xxd -i $< >$@ || { echo "xxd of $< failed" ; exit 1 ; }
.built: romfs_atestdir.h romfs_btestdir.h $(OBJS)
$(call ARCHIVE, $(BIN), $(OBJS))
@touch .built
ifeq ($(CONFIG_BUILD_KERNEL),y)
$(BIN_DIR)$(DELIM)$(PROGNAME): $(OBJS) $(MAINOBJ)
@echo "LD: $(PROGNAME)"
$(Q) $(LD) $(LDELFFLAGS) $(LDLIBPATH) -o $(INSTALL_DIR)$(DELIM)$(PROGNAME) $(ARCHCRT0OBJ) $(MAINOBJ) $(LDLIBS)
$(Q) $(NM) -u $(INSTALL_DIR)$(DELIM)$(PROGNAME)
install: $(BIN_DIR)$(DELIM)$(PROGNAME)
else
install:
endif
ifeq ($(CONFIG_NSH_BUILTIN_APPS),y)
$(BUILTIN_REGISTRY)$(DELIM)$(APPNAME)_main.bdat: $(DEPCONFIG) Makefile
$(call REGISTER,$(APPNAME),$(PRIORITY),$(STACKSIZE),$(APPNAME)_main)
context: $(BUILTIN_REGISTRY)$(DELIM)$(APPNAME)_main.bdat
else
context:
endif
.depend: Makefile $(SRCS)
@$(MKDEP) $(ROOTDEPPATH) "$(CC)" -- $(CFLAGS) -- $(SRCS) >Make.dep
@touch $@
depend: .depend
clean:
$(call DELFILE, .built)
$(call CLEAN)
distclean: clean
$(call DELFILE, Make.dep)
$(call DELFILE, .depend)
$(call DELFILE, atestdir.img)
$(call DELFILE, btestdir.img)
-include Make.dep

View File

@ -0,0 +1,2 @@
This is a file in directory adir on file system 1

View File

@ -0,0 +1,2 @@
This is a file in directory adir/asubdir on file system 1

View File

@ -0,0 +1 @@
This is a file in the root directory on file system 1

View File

@ -0,0 +1,2 @@
This is a file in directory adir on file system 2

View File

@ -0,0 +1,2 @@
This is a file in directory adir/asubdir on file system 2

View File

@ -0,0 +1 @@
This is a file in the root directory on file system 2

View File

@ -0,0 +1,2 @@
This is a file in directory bdir on file system 2

View File

@ -0,0 +1,2 @@
This is a file in directory bdir/asubdir on file system 2

View File

@ -0,0 +1 @@
This is another file in the root directory on file system 2

View File

@ -0,0 +1,200 @@
/****************************************************************************
* examples/unionfs/unionfs_main.c
*
* Copyright (C) 2015 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* 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 <sys/mount.h>
#include <sys/stat.h>
#include <sys/mman.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <fcntl.h>
#include <dirent.h>
#include <errno.h>
#include <nuttx/fs/ramdisk.h>
#include <nuttx/fs/unionfs.h>
#include "romfs_atestdir.h"
#include "romfs_btestdir.h"
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
/* Configuration settings */
#ifdef CONFIG_DISABLE_MOUNTPOINT
# error "Mountpoint support is disabled"
#endif
#if CONFIG_NFILE_DESCRIPTORS < 4
# error "Not enough file descriptors"
#endif
#ifndef CONFIG_FS_ROMFS
# error "ROMFS support not enabled"
#endif
#ifndef CONFIG_FS_UNIONFS
# error "Union File System support not enabled"
#endif
#ifndef CONFIG_EXAMPLES_UNIONFS_RAMDEVNO_A
# define CONFIG_EXAMPLES_UNIONFS_RAMDEVNO_A 1
#endif
#ifndef CONFIG_EXAMPLES_UNIONFS_RAMDEVNO_B
# define CONFIG_EXAMPLES_UNIONFS_RAMDEVNO_B 2
#endif
#ifndef CONFIG_EXAMPLES_UNIONFS_SECTORSIZE
# define CONFIG_EXAMPLES_UNIONFS_SECTORSIZE 64
#endif
#ifndef CONFIG_EXAMPLES_UNIONFS_MOUNTPT
# define "/mnt/unionfs"
#endif
#ifndef CONFIG_EXAMPLES_UNIONFS_TMPA
# define "/mnt/a"
#endif
#ifndef CONFIG_EXAMPLES_UNIONFS_TMPB
# define "/mnt/b"
#endif
#define NSECTORS(b) (((b)+CONFIG_EXAMPLES_UNIONFS_SECTORSIZE-1)/CONFIG_EXAMPLES_UNIONFS_SECTORSIZE)
#define STR_RAMDEVNO(m) #m
#define MKMOUNT_DEVNAME(m) "/dev/ram" STR_RAMDEVNO(m)
#define MOUNT_DEVNAME_A MKMOUNT_DEVNAME(CONFIG_EXAMPLES_UNIONFS_RAMDEVNO_A)
#define MOUNT_DEVNAME_B MKMOUNT_DEVNAME(CONFIG_EXAMPLES_UNIONFS_RAMDEVNO_B)
#define SCRATCHBUFFER_SIZE 1024
/* Test directory stuff */
#define WRITABLE_MODE (S_IWOTH|S_IWGRP|S_IWUSR)
#define READABLE_MODE (S_IROTH|S_IRGRP|S_IRUSR)
#define EXECUTABLE_MODE (S_IXOTH|S_IXGRP|S_IXUSR)
#define DIRECTORY_MODE (S_IFDIR|READABLE_MODE|EXECUTABLE_MODE)
#define FILE_MODE (S_IFREG|READABLE_MODE)
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: unionfs_main
****************************************************************************/
#ifdef CONFIG_BUILD_KERNEL
int main(int argc, FAR char *argv[])
#else
int unionfs_main(int argc, char *argv[])
#endif
{
int ret;
/* Create a RAM disk for file system 1 */
ret = romdisk_register(CONFIG_EXAMPLES_UNIONFS_RAMDEVNO_A, atestdir_img,
NSECTORS(atestdir_img_len),
CONFIG_EXAMPLES_UNIONFS_SECTORSIZE);
if (ret < 0)
{
printf("ERROR: Failed to create file system 1 RAM disk\n");
return EXIT_FAILURE;
}
/* Mount test file system 1 */
printf("Mounting ROMFS file system 1 at target=%s with source=%s\n",
CONFIG_EXAMPLES_UNIONFS_TMPA, MOUNT_DEVNAME_A);
ret = mount(MOUNT_DEVNAME_A, CONFIG_EXAMPLES_UNIONFS_TMPA, "romfs",
MS_RDONLY, NULL);
if (ret < 0)
{
printf("ERROR: File system 1 mount failed: %d\n", errno);
return EXIT_FAILURE;
}
/* Create a RAM disk for file system 2 */
ret = romdisk_register(CONFIG_EXAMPLES_UNIONFS_RAMDEVNO_B, btestdir_img,
NSECTORS(btestdir_img_len),
CONFIG_EXAMPLES_UNIONFS_SECTORSIZE);
if (ret < 0)
{
printf("ERROR: Failed to register file system 1: %d\n", ret);
return EXIT_FAILURE;
}
/* Mount test file system 2 */
printf("Mounting ROMFS file system 2 at target=%s with source=%s\n",
CONFIG_EXAMPLES_UNIONFS_TMPB, MOUNT_DEVNAME_B);
ret = mount(MOUNT_DEVNAME_B, CONFIG_EXAMPLES_UNIONFS_TMPB, "romfs",
MS_RDONLY, NULL);
if (ret < 0)
{
printf("ERROR: Failed to register file system 1: %d\n", ret);
return EXIT_FAILURE;
}
/* Now create and mount the union file system */
ret = unionfs_mount(CONFIG_EXAMPLES_UNIONFS_TMPA, NULL,
CONFIG_EXAMPLES_UNIONFS_TMPB, NULL,
CONFIG_EXAMPLES_UNIONFS_MOUNTPT);
if (ret < 0)
{
printf("ERROR: Failed to crate the union file system 1: %d\n", ret);
return EXIT_FAILURE;
}
return EXIT_SUCCESS;
}