fs/hostfs: Add a special file system for use with simulator that supports access to the host file system from the simulation. From Ken Petit
This commit is contained in:
parent
cd7c6705a8
commit
c0b9dcf8a9
@ -11145,4 +11145,7 @@
|
||||
that sizeof(size_t) should be the same as sizeof(uinptr_t). mmsize_t
|
||||
should always be 32-bits in any event. The last change to stddef has
|
||||
been backed out. With these changes, the simulator builds without
|
||||
warnings on a 64-bit machine (2015-11-23).
|
||||
* fs/hostfs: Add a special file system for use with simulator that
|
||||
supports access to the host file system from the simulation. From
|
||||
Ken Petit (2015-11-25).
|
||||
|
||||
|
2
arch
2
arch
@ -1 +1 @@
|
||||
Subproject commit ffcd26aff904843e043a333e6f73d900423ca211
|
||||
Subproject commit 93f8b673c8d0c4d3f534ef08163d51187a07a390
|
2
configs
2
configs
@ -1 +1 @@
|
||||
Subproject commit 82d56af7017b9524403d5f10b612effa08e71d61
|
||||
Subproject commit 98ebc3e0a5f2313942a5083bbc177388aad59fb3
|
@ -62,6 +62,7 @@ source fs/smartfs/Kconfig
|
||||
source fs/binfs/Kconfig
|
||||
source fs/procfs/Kconfig
|
||||
source fs/unionfs/Kconfig
|
||||
source fs/hostfs/Kconfig
|
||||
|
||||
comment "System Logging"
|
||||
|
||||
|
@ -71,6 +71,7 @@ include smartfs/Make.defs
|
||||
include binfs/Make.defs
|
||||
include procfs/Make.defs
|
||||
include unionfs/Make.defs
|
||||
include hostfs/Make.defs
|
||||
|
||||
endif
|
||||
endif
|
||||
|
24
fs/hostfs/Kconfig
Normal file
24
fs/hostfs/Kconfig
Normal file
@ -0,0 +1,24 @@
|
||||
#
|
||||
# For a description of the syntax of this configuration file,
|
||||
# see the file kconfig-language.txt in the NuttX tools repository.
|
||||
#
|
||||
|
||||
config FS_HOSTFS
|
||||
bool "Host File System"
|
||||
default n
|
||||
depends on !DISABLE_MOUNTPOINT
|
||||
depends on ARCH_SIM
|
||||
select FS_READABLE
|
||||
select FS_WRITABLE
|
||||
---help---
|
||||
The Host file system provides a mechanism to mount directories
|
||||
from the host OS during simulation mode. The host directory
|
||||
to be "mounted" is specified during the mount command using
|
||||
the -o command line switch, such as:
|
||||
|
||||
mount -t hostfs -o fs=/home/user/nuttx_root /host
|
||||
|
||||
For non-NSH operation, the option "fs=home/user/nuttx_root" would
|
||||
be passed to the 'mount()' routine using the optional 'void *data'
|
||||
parameter.
|
||||
|
48
fs/hostfs/Make.defs
Normal file
48
fs/hostfs/Make.defs
Normal file
@ -0,0 +1,48 @@
|
||||
############################################################################
|
||||
# Make.defs
|
||||
#
|
||||
# Copyright (C) 2015 Ken Pettit. All rights reserved.
|
||||
# Author: Ken Pettit <pettitkd@gmail.com>
|
||||
#
|
||||
# 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_HOSTFS),y)
|
||||
|
||||
# Files required for HostFS file system support
|
||||
|
||||
ASRCS +=
|
||||
CSRCS += hostfs.c
|
||||
|
||||
# Include HOSTFS build support
|
||||
|
||||
DEPPATH += --dep-path hostfs
|
||||
VPATH += :hostfs
|
||||
|
||||
endif
|
1217
fs/hostfs/hostfs.c
Normal file
1217
fs/hostfs/hostfs.c
Normal file
File diff suppressed because it is too large
Load Diff
117
fs/hostfs/hostfs.h
Normal file
117
fs/hostfs/hostfs.h
Normal file
@ -0,0 +1,117 @@
|
||||
/****************************************************************************
|
||||
* nuttx/fs/hostfs/hostfs.h
|
||||
*
|
||||
* Copyright (C) 2015 Ken Pettit. All rights reserved.
|
||||
* Author: Ken Pettit <pettitkd@gmail.com>
|
||||
*
|
||||
* 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_HOSTFS_HOSTFS_H
|
||||
#define __FS_HOSTFS_HOSTFS_H
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include <semaphore.h>
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
/* Quasi-standard definitions */
|
||||
|
||||
#ifndef MIN
|
||||
# define MIN(a,b) (a < b ? a : b)
|
||||
#endif
|
||||
|
||||
#ifndef MAX
|
||||
# define MAX(a,b) (a > b ? a : b)
|
||||
#endif
|
||||
|
||||
#define HOSTFS_MAX_PATH 256
|
||||
|
||||
/****************************************************************************
|
||||
* Public Types
|
||||
****************************************************************************/
|
||||
|
||||
/* This structure describes the state of one open file. This structure
|
||||
* is protected by the volume semaphore.
|
||||
*/
|
||||
|
||||
struct hostfs_ofile_s
|
||||
{
|
||||
struct hostfs_ofile_s *fnext; /* Supports a singly linked list */
|
||||
int16_t crefs; /* Reference count */
|
||||
mode_t oflags; /* Open mode */
|
||||
int fd;
|
||||
};
|
||||
|
||||
/* This structure represents the overall mountpoint state. An instance of this
|
||||
* structure is retained as inode private data on each mountpoint that is
|
||||
* mounted with a hostfs filesystem.
|
||||
*/
|
||||
|
||||
struct hostfs_mountpt_s
|
||||
{
|
||||
sem_t *fs_sem; /* Used to assure thread-safe access */
|
||||
FAR struct hostfs_ofile_s *fs_head; /* A singly-linked list of open files */
|
||||
char fs_root[HOSTFS_MAX_PATH];
|
||||
};
|
||||
|
||||
/****************************************************************************
|
||||
* Public Data
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Internal function prototypes
|
||||
****************************************************************************/
|
||||
|
||||
/* Semaphore access for internal use */
|
||||
|
||||
void hostfs_semtake(struct hostfs_mountpt_s *fs);
|
||||
void hostfs_semgive(struct hostfs_mountpt_s *fs);
|
||||
|
||||
/* Forward references for utility functions */
|
||||
|
||||
struct hostfs_mountpt_s;
|
||||
|
||||
struct file; /* Forward references */
|
||||
struct inode;
|
||||
struct fs_dirent_s;
|
||||
struct statfs;
|
||||
struct stat;
|
||||
|
||||
#endif /* __FS_HOSTFS_HOSTFS_H */
|
@ -138,6 +138,9 @@ extern const struct mountpt_operations binfs_operations;
|
||||
#ifdef CONFIG_FS_PROCFS
|
||||
extern const struct mountpt_operations procfs_operations;
|
||||
#endif
|
||||
#ifdef CONFIG_FS_HOSTFS
|
||||
extern const struct mountpt_operations hostfs_operations;
|
||||
#endif
|
||||
|
||||
static const struct fsmap_t g_nonbdfsmap[] =
|
||||
{
|
||||
@ -155,6 +158,9 @@ static const struct fsmap_t g_nonbdfsmap[] =
|
||||
#endif
|
||||
#ifdef CONFIG_FS_PROCFS
|
||||
{ "procfs", &procfs_operations },
|
||||
#endif
|
||||
#ifdef CONFIG_FS_HOSTFS
|
||||
{ "hostfs", &hostfs_operations },
|
||||
#endif
|
||||
{ NULL, NULL },
|
||||
};
|
||||
|
@ -177,6 +177,17 @@ struct fs_unionfsdir_s
|
||||
};
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_FS_HOSTFS
|
||||
/* HOSTFS provides mapping to directories on the host machine in the
|
||||
* sim environment.
|
||||
*/
|
||||
|
||||
struct fs_hostfsdir_s
|
||||
{
|
||||
FAR void * fs_dir; /* Opaque pointer to host DIR * */
|
||||
};
|
||||
#endif
|
||||
|
||||
#endif /* CONFIG_DISABLE_MOUNTPOINT */
|
||||
|
||||
struct fs_dirent_s
|
||||
@ -243,6 +254,9 @@ struct fs_dirent_s
|
||||
#ifdef CONFIG_FS_UNIONFS
|
||||
struct fs_unionfsdir_s unionfs;
|
||||
#endif
|
||||
#ifdef CONFIG_FS_HOSTFS
|
||||
struct fs_hostfsdir_s hostfs;
|
||||
#endif
|
||||
#endif /* !CONFIG_DISABLE_MOUNTPOINT */
|
||||
} u;
|
||||
|
||||
|
133
include/nuttx/fs/hostfs.h
Normal file
133
include/nuttx/fs/hostfs.h
Normal file
@ -0,0 +1,133 @@
|
||||
/****************************************************************************
|
||||
* include/nuttx/fs/hostfs.h
|
||||
*
|
||||
* Copyright (C) 2015 Ken Pettit. All rights reserved.
|
||||
* Author: Ken Pettit <pettitkd@gmail.com>
|
||||
*
|
||||
* 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 __INCLUDE_NUTTX_FS_HOSTFS_H
|
||||
#define __INCLUDE_NUTTX_FS_HOSTFS_H
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
#define HOST_ST_MODE_REG 0x01000
|
||||
#define HOST_ST_MODE_DIR 0x02000
|
||||
#define HOST_ST_MODE_CHR 0x04000
|
||||
#define HOST_ST_MODE_BLK 0x08000
|
||||
#define HOST_ST_MODE_PIPE 0x10000
|
||||
#define HOST_ST_MODE_LINK 0x20000
|
||||
|
||||
#define HOSTFS_FLAG_RDOK 0x0001
|
||||
#define HOSTFS_FLAG_WROK 0x0002
|
||||
#define HOSTFS_FLAG_CREAT 0x0004
|
||||
#define HOSTFS_FLAG_EXCL 0x0008
|
||||
#define HOSTFS_FLAG_APPEND 0x0010
|
||||
#define HOSTFS_FLAG_TRUNC 0x0020
|
||||
|
||||
#define HOSTFS_DTYPE_FILE 0x0001
|
||||
#define HOSTFS_DTYPE_CHR 0x0002
|
||||
#define HOSTFS_DTYPE_BLK 0x0004
|
||||
#define HOSTFS_DTYPE_DIRECTORY 0x0008
|
||||
|
||||
/****************************************************************************
|
||||
* Public Type Definitions
|
||||
****************************************************************************/
|
||||
|
||||
struct host_dirent_s
|
||||
{
|
||||
size_t d_ino;
|
||||
size_t d_off;
|
||||
unsigned short d_reclen;
|
||||
unsigned char d_type;
|
||||
char d_name[256];
|
||||
};
|
||||
|
||||
struct host_statfs_s
|
||||
{
|
||||
size_t f_type; /* Type of file system */
|
||||
size_t f_bsize; /* Optimal transfer block size */
|
||||
size_t f_blocks; /* Total data blocks in the file system */
|
||||
size_t f_bfree; /* Free blocks */
|
||||
size_t f_bavail; /* Free blocks available */
|
||||
size_t f_files; /* Total file nodes in file system */
|
||||
size_t f_ffree; /* Free file nodes in fs */
|
||||
size_t f_fsid; /* File Systme ID */
|
||||
size_t f_namelen; /* Max length of filenames */
|
||||
size_t f_frsize; /* Fragment size */
|
||||
};
|
||||
|
||||
struct host_stat_s
|
||||
{
|
||||
int st_dev; /* ID of the device containing file */
|
||||
size_t st_ino; /* inode number */
|
||||
size_t st_mode; /* protection */
|
||||
size_t st_nlink; /* number of hard links */
|
||||
size_t st_uid; /* user ID of owner */
|
||||
size_t st_gid; /* group ID of owner */
|
||||
size_t st_rdev; /* device ID */
|
||||
size_t st_size; /* total size, in bytes */
|
||||
size_t st_blksize; /* blocksize for file system I/O */
|
||||
size_t st_blocks; /* number of 512B blocks allocated */
|
||||
size_t st_atim; /* time of last access */
|
||||
size_t st_mtim; /* time of last modification */
|
||||
size_t st_ctim; /* time of last status change */
|
||||
};
|
||||
|
||||
/****************************************************************************
|
||||
* Public Function Prototypes
|
||||
****************************************************************************/
|
||||
|
||||
int host_open(const char *pathname, int flags, int mode);
|
||||
int host_close(int fd);
|
||||
ssize_t host_read(int fd, void* buf, size_t count);
|
||||
ssize_t host_write(int fd, const void *buf, size_t count);
|
||||
off_t host_lseek(int fd, off_t offset, int whence);
|
||||
int host_ioctl(int fd, int request, unsigned long arg);
|
||||
void host_sync(int fd);
|
||||
int host_dup(int fd);
|
||||
void *host_opendir(const char *name);
|
||||
int host_readdir(void* dirp, struct host_dirent_s* entry);
|
||||
void host_rewinddir(void* dirp);
|
||||
int host_closedir(void* dirp);
|
||||
int host_statfs(const char *path, struct host_statfs_s *buf);
|
||||
int host_unlink(const char *pathname);
|
||||
int host_mkdir(const char *pathname, mode_t mode);
|
||||
int host_rmdir(const char *pathname);
|
||||
int host_rename(const char *oldpath, const char *newpath);
|
||||
int host_stat(const char *path, struct host_stat_s *buf);
|
||||
|
||||
#endif /* __INCLUDE_NUTTX_FS_HOSTFS_H */
|
@ -103,6 +103,7 @@
|
||||
#define NXFFS_MAGIC 0x4747
|
||||
#define SMARTFS_MAGIC 0x54524D53
|
||||
#define UNIONFS_MAGIC 0x53464e55
|
||||
#define HOSTFS_MAGIC 0x54534f48
|
||||
|
||||
/****************************************************************************
|
||||
* Type Definitions
|
||||
|
Loading…
Reference in New Issue
Block a user