Addes CROMFS prototype. CROMFS is a commpressed, in-memory read-only file system based on LZF.

Squashed commit of the following:

    fs/cromfs:  Now depends on EXPERIMENTAL because it is not yet verified.
    fs/cromfs:  This commit brings the CROMFS file system to code complete.  Still completely untested.  Next steps:  Need a tool to generate CROMFS file system images and a test case under apps/
    fs/cromfs:  Add logic to traverse the in-memory file system nodes.
    fs/cromfs:  Add initial support for an in-memory, compressed, read-only file system.
This commit is contained in:
Gregory Nutt 2018-03-19 07:08:40 -06:00
parent ed59157a4b
commit 0478b5bce4
10 changed files with 1349 additions and 7 deletions

View File

@ -81,6 +81,7 @@ source fs/fat/Kconfig
source fs/nfs/Kconfig source fs/nfs/Kconfig
source fs/nxffs/Kconfig source fs/nxffs/Kconfig
source fs/romfs/Kconfig source fs/romfs/Kconfig
source fs/cromfs/Kconfig
source fs/tmpfs/Kconfig source fs/tmpfs/Kconfig
source fs/smartfs/Kconfig source fs/smartfs/Kconfig
source fs/binfs/Kconfig source fs/binfs/Kconfig

View File

@ -1,7 +1,7 @@
############################################################################ ############################################################################
# fs/Makefile # fs/Makefile
# #
# Copyright (C) 2007, 2008, 2011-2014, 2016-2017 Gregory Nutt. All rights # Copyright (C) 2007, 2008, 2011-2014, 2016-2018 Gregory Nutt. All rights
# reserved. # reserved.
# Author: Gregory Nutt <gnutt@nuttx.org> # Author: Gregory Nutt <gnutt@nuttx.org>
# #
@ -65,6 +65,7 @@ ifneq ($(CONFIG_DISABLE_MOUNTPOINT),y)
include mount/Make.defs include mount/Make.defs
include fat/Make.defs include fat/Make.defs
include romfs/Make.defs include romfs/Make.defs
include cromfs/Make.defs
include tmpfs/Make.defs include tmpfs/Make.defs
include nxffs/Make.defs include nxffs/Make.defs
include nfs/Make.defs include nfs/Make.defs

15
fs/cromfs/Kconfig Normal file
View File

@ -0,0 +1,15 @@
#
# For a description of the syntax of this configuration file,
# see the file kconfig-language.txt in the NuttX tools repository.
#
config FS_CROMFS
bool "CROMFS file system"
default n
depends on !DISABLE_MOUNTPOINT && EXPERIMENTAL
select FS_READABLE
---help---
Enable Compessed Read-Only Filesystem (CROMFS) support
if FS_CROMFS
endif

47
fs/cromfs/Make.defs Normal file
View File

@ -0,0 +1,47 @@
############################################################################
# fs/cromfs/Make.defs
#
# Copyright (C) 2008 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_FS_CROMFS),y)
# Files required for CROMFS file system support
ASRCS +=
CSRCS += fs_cromfs.c
# Include ROMFS build support
DEPPATH += --dep-path cromfs
VPATH += :cromfs
endif

127
fs/cromfs/cromfs.h Normal file
View File

@ -0,0 +1,127 @@
/****************************************************************************
* fs/cromfs/cromfs.h
*
* Copyright (C) 2018 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.
*
****************************************************************************/
#ifndef __FS_CROMFS_CROMFS_H
#define __FS_CROMFS_CROMFS_H 1
/****************************************************************************
* Included Files
****************************************************************************/
#include <sys/types.h>
#include <stdint.h>
/****************************************************************************
* Public Types
****************************************************************************/
/* This structure describes the CROMFS volume. It provides most of the
* information needed for statfs() including:
*
* f_type - Type of filesystem
* Return cv_magic (CROMFS_MAGIC)
* f_namelen - Maximum length of filenames
* Return NAME_MAX
* f_bsize - Optimal block size for transfers
* Return cv_bsize, the block size used when file system was
* compressed
* f_blocks - Total data blocks in the file system
* - Return cv_nblocks
* f_bfree - Free blocks in the file system
* Return 0
* f_bavail - Free blocks avail to non-superuser
* Return 0
* f_files - Total file nodes in the file system
* - Return cv_nnodes
* f_ffree - Free file nodes in the file system
* Return 0
*
* The volume header is followed immediately by the root directory node. An
* offset to that node is used to permit future variable length data (such as
* a volumne name) which may intervene.
*
* Since this is an in-memory file system, size_t is the most relevant type for
* internal file system offsets.
*/
struct cromfs_volume_s
{
uint32_t cv_magic; /* Must be first. Must be CROMFS_MAGIC */
uint16_t cv_nnodes; /* Total number of nodes in-use */
uint16_t cv_nblocks; /* Total number of data blocks in-use */
size_t cv_root; /* Offset to the first node in the root file system */
size_t cv_fsize; /* Size of the compressed file system image */
size_t cv_bsize; /* Optimal block size for transfers */
};
/* This describes one node in the CROMFS file system. It holds node meta
* data that provides the information that will be return by stat() or fstat()
* and also provides the information needed by the CROMFS file system to
* access the node data.
*
* Relationship to struct stat:
*
* st_mode - File type, attributes, and access mode bits
* Return cn_mode from the node structure
* st_size - Size of file/directory, in bytes
* Return cn_size from the node structure
* st_blksize - Block size used for filesystem I/O
* Return cv_bsize from the volume header.
* st_blocks - Number of blocks allocated
* Return (cn_size + (cv_bsize - 1)) / cv_bsize
* st_atime - Time of last access
* Return 0
* st_mtime - Time of last modification
* Return 0
* st_ctime - Time of last status change
* Return 0
*/
struct cromfs_node_s
{
mode_t cn_mode; /* File type, attributes, and access mode bits */
size_t cn_name; /* Offset from the beginning of the volume header to the
* node name string. NUL-terminated. */
size_t cn_size; /* Size of the uncompressed data (in bytes) */
size_t cn_peer; /* Offset to next node in this directory (for readdir())*/
union /* Must be last */
{
size_t cn_child; /* Offset to first node in sub-directory (directories only) */
size_t cn_link; /* Offset to an arbitrary node (for hard link) */
size_t cn_blocks; /* Offset to first block of compressed data (for read) */
} u;
};
#endif /* __FS_CROMFS_CROMFS_H */

1129
fs/cromfs/fs_cromfs.c Normal file

File diff suppressed because it is too large Load Diff

View File

@ -79,7 +79,8 @@
#if defined(CONFIG_FS_NXFFS) || defined(CONFIG_FS_BINFS) || \ #if defined(CONFIG_FS_NXFFS) || defined(CONFIG_FS_BINFS) || \
defined(CONFIG_FS_PROCFS) || defined(CONFIG_NFS) || \ defined(CONFIG_FS_PROCFS) || defined(CONFIG_NFS) || \
defined(CONFIG_FS_TMPFS) || defined(CONFIG_FS_USERFS) defined(CONFIG_FS_TMPFS) || defined(CONFIG_FS_USERFS) || \
defined(CONFIG_FS_CROMFS)
# define NONBDFS_SUPPORT # define NONBDFS_SUPPORT
#endif #endif
@ -145,6 +146,9 @@ extern const struct mountpt_operations userfs_operations;
#ifdef CONFIG_FS_HOSTFS #ifdef CONFIG_FS_HOSTFS
extern const struct mountpt_operations hostfs_operations; extern const struct mountpt_operations hostfs_operations;
#endif #endif
#ifdef CONFIG_FS_CROMFS
extern const struct mountpt_operations cromfs_operations;
#endif
static const struct fsmap_t g_nonbdfsmap[] = static const struct fsmap_t g_nonbdfsmap[] =
{ {
@ -168,6 +172,9 @@ static const struct fsmap_t g_nonbdfsmap[] =
#endif #endif
#ifdef CONFIG_FS_HOSTFS #ifdef CONFIG_FS_HOSTFS
{ "hostfs", &hostfs_operations }, { "hostfs", &hostfs_operations },
#endif
#ifdef CONFIG_FS_CROMFS
{ "cromfs", &cromfs_operations },
#endif #endif
{ NULL, NULL }, { NULL, NULL },
}; };

View File

@ -1,7 +1,8 @@
/**************************************************************************** /****************************************************************************
* include/nuttx/fs/dirent.h * include/nuttx/fs/dirent.h
* *
* Copyright (C) 2007, 2009, 2011-2013, 2015 Gregory Nutt. All rights reserved. * Copyright (C) 2007, 2009, 2011-2013, 2015, 20189 Gregory Nutt. All
* rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org> * Author: Gregory Nutt <gnutt@nuttx.org>
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
@ -102,6 +103,16 @@ struct fs_romfsdir_s
}; };
#endif /* CONFIG_FS_ROMFS */ #endif /* CONFIG_FS_ROMFS */
#ifdef CONFIG_FS_CROMFS
/* For CROMFS, we need to return the next compressed node to be examined. */
struct fs_cromfsdir_s
{
off_t cr_firstoffset; /* Offset to the first entry in the directory */
off_t cr_curroffset; /* Current offset into the directory contents */
};
#endif /* CONFIG_FS_ROMFS */
#ifdef CONFIG_FS_TMPFS #ifdef CONFIG_FS_TMPFS
/* For TMPFS, we need the directory object and an index into the directory /* For TMPFS, we need the directory object and an index into the directory
* entries. * entries.
@ -244,6 +255,9 @@ struct fs_dirent_s
#ifdef CONFIG_FS_ROMFS #ifdef CONFIG_FS_ROMFS
struct fs_romfsdir_s romfs; struct fs_romfsdir_s romfs;
#endif #endif
#ifdef CONFIG_FS_ROMFS
struct fs_cromfsdir_s cromfs;
#endif
#ifdef CONFIG_FS_TMPFS #ifdef CONFIG_FS_TMPFS
struct fs_tmpfsdir_s tmpfs; struct fs_tmpfsdir_s tmpfs;
#endif #endif

View File

@ -122,9 +122,9 @@ struct stat
{ {
/* Required, standard fields */ /* Required, standard fields */
mode_t st_mode; /* File type, atributes, and access mode bits */ mode_t st_mode; /* File type, attributes, and access mode bits */
off_t st_size; /* Size of file/directory, in bytes */ off_t st_size; /* Size of file/directory, in bytes */
blksize_t st_blksize; /* Blocksize used for filesystem I/O */ blksize_t st_blksize; /* Block size used for filesystem I/O */
blkcnt_t st_blocks; /* Number of blocks allocated */ blkcnt_t st_blocks; /* Number of blocks allocated */
time_t st_atime; /* Time of last access */ time_t st_atime; /* Time of last access */
time_t st_mtime; /* Time of last modification */ time_t st_mtime; /* Time of last modification */

View File

@ -105,6 +105,7 @@
#define UNIONFS_MAGIC 0x53464e55 #define UNIONFS_MAGIC 0x53464e55
#define HOSTFS_MAGIC 0x54534f48 #define HOSTFS_MAGIC 0x54534f48
#define USERFS_MAGIC 0x52455355 #define USERFS_MAGIC 0x52455355
#define CROMFS_MAGIC 0x4d4f5243
/**************************************************************************** /****************************************************************************
* Type Definitions * Type Definitions