aboutsummaryrefslogtreecommitdiff
path: root/nuttx/fs
diff options
context:
space:
mode:
Diffstat (limited to 'nuttx/fs')
-rw-r--r--nuttx/fs/Kconfig3
-rw-r--r--nuttx/fs/Makefile15
-rw-r--r--nuttx/fs/binfs/Kconfig19
-rw-r--r--nuttx/fs/binfs/Make.defs48
-rw-r--r--nuttx/fs/binfs/fs_binfs.c446
-rw-r--r--nuttx/fs/fat/Make.defs9
-rw-r--r--nuttx/fs/fat/fs_fat32.c171
-rw-r--r--nuttx/fs/fat/fs_fat32.h1
-rw-r--r--nuttx/fs/fat/fs_fat32util.c10
-rw-r--r--nuttx/fs/fs_files.c18
-rw-r--r--nuttx/fs/fs_mount.c15
-rw-r--r--nuttx/fs/mmap/Make.defs9
-rw-r--r--nuttx/fs/nfs/Make.defs9
-rw-r--r--nuttx/fs/nfs/nfs_node.h3
-rw-r--r--nuttx/fs/nfs/nfs_util.c9
-rw-r--r--nuttx/fs/nfs/nfs_vfsops.c163
-rw-r--r--nuttx/fs/nfs/rpc_clnt.c28
-rw-r--r--nuttx/fs/nxffs/Make.defs9
-rw-r--r--nuttx/fs/nxffs/nxffs.h41
-rw-r--r--nuttx/fs/nxffs/nxffs_initialize.c4
-rw-r--r--nuttx/fs/nxffs/nxffs_open.c65
-rw-r--r--nuttx/fs/romfs/Make.defs9
-rw-r--r--nuttx/fs/romfs/fs_romfs.c258
-rw-r--r--nuttx/fs/romfs/fs_romfs.h1
-rw-r--r--nuttx/fs/romfs/fs_romfsutil.c12
25 files changed, 1128 insertions, 247 deletions
diff --git a/nuttx/fs/Kconfig b/nuttx/fs/Kconfig
index 1d1046735..dfbfda3fa 100644
--- a/nuttx/fs/Kconfig
+++ b/nuttx/fs/Kconfig
@@ -5,11 +5,12 @@
comment "File system configuration"
-source fs/fat/Kconfig
source fs/mmap/Kconfig
+source fs/fat/Kconfig
source fs/nfs/Kconfig
source fs/nxffs/Kconfig
source fs/romfs/Kconfig
+source fs/binfs/Kconfig
comment "System Logging"
diff --git a/nuttx/fs/Makefile b/nuttx/fs/Makefile
index 6955c164b..2a1fd75a8 100644
--- a/nuttx/fs/Makefile
+++ b/nuttx/fs/Makefile
@@ -1,7 +1,7 @@
############################################################################
# fs/Makefile
#
-# Copyright (C) 2007, 2008, 2011-2012 Gregory Nutt. All rights reserved.
+# Copyright (C) 2007, 2008, 2011-2013 Gregory Nutt. All rights reserved.
# Author: Gregory Nutt <gnutt@nuttx.org>
#
# Redistribution and use in source and binary forms, with or without
@@ -72,6 +72,9 @@ CSRCS += fs_registerdriver.c fs_unregisterdriver.c
CSRCS += fs_registerblockdriver.c fs_unregisterblockdriver.c \
fs_findblockdriver.c fs_openblockdriver.c fs_closeblockdriver.c
+DEPPATH =
+VPATH = .
+
include mmap/Make.defs
# Stream support
@@ -91,13 +94,17 @@ endif
# Additional files required is mount-able file systems are supported
ifneq ($(CONFIG_DISABLE_MOUNTPOINT),y)
+
CSRCS += fs_fsync.c fs_mkdir.c fs_mount.c fs_rename.c fs_rmdir.c \
fs_umount.c fs_unlink.c
CSRCS += fs_foreachmountpoint.c
+
include fat/Make.defs
include romfs/Make.defs
include nxffs/Make.defs
include nfs/Make.defs
+include binfs/Make.defs
+
endif
endif
@@ -108,8 +115,7 @@ OBJS = $(AOBJS) $(COBJS)
BIN = libfs$(LIBEXT)
-SUBDIRS = mmap fat romfs nxffs:nfs
-VPATH = mmap:fat:romfs:nxffs:nfs
+SUBDIRS = mmap fat romfs nxffs nfs binfs
all: $(BIN)
@@ -123,8 +129,7 @@ $(BIN): $(OBJS)
$(call ARCHIVE, $@, $(OBJS))
.depend: Makefile $(SRCS)
- $(Q) $(MKDEP) --dep-path . $(MMAPDEPPATH) $(FATDEPPATH) $(ROMFSDEPPATH) $(NXFFSDEPPATH) $(NFSDEPPATH) \
- "$(CC)" -- $(CFLAGS) -- $(SRCS) >Make.dep
+ $(Q) $(MKDEP) --dep-path . $(DEPPATH) "$(CC)" -- $(CFLAGS) -- $(SRCS) >Make.dep
$(Q) touch $@
depend: .depend
diff --git a/nuttx/fs/binfs/Kconfig b/nuttx/fs/binfs/Kconfig
new file mode 100644
index 000000000..eedbe497d
--- /dev/null
+++ b/nuttx/fs/binfs/Kconfig
@@ -0,0 +1,19 @@
+#
+# For a description of the syntax of this configuration file,
+# see misc/tools/kconfig-language.txt.
+#
+
+config FS_BINFS
+ bool "BINFS File System"
+ default n
+ depends on BUILTIN
+ ---help---
+ The BINFS file system is provides access to builtin applications through
+ the NuttX file system. The BINFS may, for example, be mount at /bin.
+ Then all of the built-in applications will appear as executable files in
+ /bin. Then, for example, you list them from NSH like:
+
+ nsh> ls -l /bin
+
+ If the BINFS BINFMT loader is also enabled, then the builtin applications
+ can be executed through the normal mechanisms (posix_spawn(), exev(), etc.)
diff --git a/nuttx/fs/binfs/Make.defs b/nuttx/fs/binfs/Make.defs
new file mode 100644
index 000000000..a65b7367f
--- /dev/null
+++ b/nuttx/fs/binfs/Make.defs
@@ -0,0 +1,48 @@
+############################################################################
+# fs/binfs/Make.defs
+#
+# Copyright (C) 2013 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_BINFS),y)
+# Files required for BINFS file system support
+
+ASRCS +=
+CSRCS += fs_binfs.c
+
+# Include BINFS build support
+
+DEPPATH += --dep-path binfs
+VPATH += :binfs
+CFLAGS += ${shell $(INCDIR) $(INCDIROPT) "$(CC)" $(TOPDIR)$(DELIM)fs$(DELIM)binfs}
+
+endif
diff --git a/nuttx/fs/binfs/fs_binfs.c b/nuttx/fs/binfs/fs_binfs.c
new file mode 100644
index 000000000..ed6326eba
--- /dev/null
+++ b/nuttx/fs/binfs/fs_binfs.c
@@ -0,0 +1,446 @@
+/****************************************************************************
+ * fs/binfs/fs_binfs.c
+ *
+ * Copyright (C) 2011-2013 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/statfs.h>
+#include <sys/stat.h>
+
+#include <stdint.h>
+#include <stdbool.h>
+#include <string.h>
+#include <fcntl.h>
+#include <assert.h>
+#include <errno.h>
+#include <debug.h>
+
+#include <nuttx/fs/fs.h>
+#include <nuttx/fs/binfs.h>
+#include <nuttx/fs/dirent.h>
+#include <nuttx/fs/ioctl.h>
+#include <nuttx/binfmt/builtin.h>
+
+#if !defined(CONFIG_DISABLE_MOUNTPOINT) && defined(CONFIG_FS_BINFS)
+
+/****************************************************************************
+ * Private Types
+ ****************************************************************************/
+
+/****************************************************************************
+ * Private Function Prototypes
+ ****************************************************************************/
+
+static int binfs_open(FAR struct file *filep, const char *relpath,
+ int oflags, mode_t mode);
+static int binfs_close(FAR struct file *filep);
+static ssize_t binfs_read(FAR struct file *filep, char *buffer, size_t buflen);
+static int binfs_ioctl(FAR struct file *filep, int cmd, unsigned long arg);
+
+static int binfs_dup(FAR const struct file *oldp, FAR struct file *newp);
+
+static int binfs_opendir(struct inode *mountpt, const char *relpath,
+ struct fs_dirent_s *dir);
+static int binfs_readdir(FAR struct inode *mountpt,
+ FAR struct fs_dirent_s *dir);
+static int binfs_rewinddir(FAR struct inode *mountpt,
+ FAR struct fs_dirent_s *dir);
+
+static int binfs_bind(FAR struct inode *blkdriver, FAR const void *data,
+ FAR void **handle);
+static int binfs_unbind(FAR void *handle, FAR struct inode **blkdriver);
+static int binfs_statfs(FAR struct inode *mountpt,
+ FAR struct statfs *buf);
+
+static int binfs_stat(FAR struct inode *mountpt, FAR const char *relpath,
+ FAR struct stat *buf);
+
+/****************************************************************************
+ * Private Variables
+ ****************************************************************************/
+
+/****************************************************************************
+ * Public Variables
+ ****************************************************************************/
+
+/* See fs_mount.c -- this structure is explicitly externed there.
+ * We use the old-fashioned kind of initializers so that this will compile
+ * with any compiler.
+ */
+
+const struct mountpt_operations binfs_operations =
+{
+ binfs_open, /* open */
+ binfs_close, /* close */
+ binfs_read, /* read */
+ NULL, /* write */
+ NULL, /* seek */
+ binfs_ioctl, /* ioctl */
+
+ NULL, /* sync */
+ binfs_dup, /* dup */
+
+ binfs_opendir, /* opendir */
+ NULL, /* closedir */
+ binfs_readdir, /* readdir */
+ binfs_rewinddir, /* rewinddir */
+
+ binfs_bind, /* bind */
+ binfs_unbind, /* unbind */
+ binfs_statfs, /* statfs */
+
+ NULL, /* unlink */
+ NULL, /* mkdir */
+ NULL, /* rmdir */
+ NULL, /* rename */
+ binfs_stat /* stat */
+};
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: binfs_open
+ ****************************************************************************/
+
+static int binfs_open(FAR struct file *filep, FAR const char *relpath,
+ int oflags, mode_t mode)
+{
+ int index;
+
+ fvdbg("Open '%s'\n", relpath);
+
+ /* BINFS is read-only. Any attempt to open with any kind of write
+ * access is not permitted.
+ */
+
+ if ((oflags & O_WRONLY) != 0 || (oflags & O_RDONLY) == 0)
+ {
+ fdbg("ERROR: Only O_RDONLY supported\n");
+ return -EACCES;
+ }
+
+ /* Check if the an entry exists with this name in the root directory.
+ * so the 'relpath' must be the name of the builtin function.
+ */
+
+ index = builtin_isavail(relpath);
+ if (index < 0)
+ {
+ fdbg("ERROR: Builting %s does not exist\n", relpath);
+ return -ENOENT;
+ }
+
+ /* Save the index as the open-specific state in filep->f_priv */
+
+ filep->f_priv = (FAR void *)index;
+ return OK;
+}
+
+/****************************************************************************
+ * Name: binfs_close
+ ****************************************************************************/
+
+static int binfs_close(FAR struct file *filep)
+{
+ fvdbg("Closing\n");
+ return OK;
+}
+
+/****************************************************************************
+ * Name: binfs_read
+ ****************************************************************************/
+
+static ssize_t binfs_read(FAR struct file *filep, char *buffer, size_t buflen)
+{
+ /* Reading is not supported. Just return end-of-file */
+
+ fvdbg("Read %d bytes from offset %d\n", buflen, filep->f_pos);
+ return 0;
+}
+
+/****************************************************************************
+ * Name: binfs_ioctl
+ ****************************************************************************/
+
+static int binfs_ioctl(FAR struct file *filep, int cmd, unsigned long arg)
+{
+ int ret;
+
+ fvdbg("cmd: %d arg: %08lx\n", cmd, arg);
+
+ /* Only one IOCTL command is supported */
+
+ if (cmd == FIOC_FILENAME)
+ {
+ /* IN: FAR char const ** pointer
+ * OUT: Pointer to a persistent file name (Guaranteed to persist while
+ * the file is open).
+ */
+
+ FAR const char **ptr = (FAR const char **)((uintptr_t)arg);
+ if (ptr == NULL)
+ {
+ ret = -EINVAL;
+ }
+ else
+ {
+ *ptr = g_builtins[(int)filep->f_priv].name;
+ ret = OK;
+ }
+ }
+ else
+ {
+ ret = -ENOTTY;
+ }
+
+ return ret;
+}
+
+/****************************************************************************
+ * Name: binfs_dup
+ *
+ * Description:
+ * Duplicate open file data in the new file structure.
+ *
+ ****************************************************************************/
+
+static int binfs_dup(FAR const struct file *oldp, FAR struct file *newp)
+{
+ fvdbg("Dup %p->%p\n", oldp, newp);
+
+ /* Copy the index from the old to the new file structure */
+
+ newp->f_priv = oldp->f_priv;
+ return OK;
+}
+
+/****************************************************************************
+ * Name: binfs_opendir
+ *
+ * Description:
+ * Open a directory for read access
+ *
+ ****************************************************************************/
+
+static int binfs_opendir(struct inode *mountpt, const char *relpath,
+ struct fs_dirent_s *dir)
+{
+ fvdbg("relpath: \"%s\"\n", relpath ? relpath : "NULL");
+
+ /* The requested directory must be the volume-relative "root" directory */
+
+ if (relpath && relpath[0] != '\0')
+ {
+ return -ENOENT;
+ }
+
+ /* Set the index to the first entry */
+
+ dir->u.binfs.fb_index = 0;
+ return OK;
+}
+
+/****************************************************************************
+ * Name: binfs_readdir
+ *
+ * Description: Read the next directory entry
+ *
+ ****************************************************************************/
+
+static int binfs_readdir(struct inode *mountpt, struct fs_dirent_s *dir)
+{
+ unsigned int index;
+ int ret;
+
+ /* Have we reached the end of the directory */
+
+ index = dir->u.binfs.fb_index;
+ if (g_builtins[index].name == NULL)
+ {
+ /* We signal the end of the directory by returning the
+ * special error -ENOENT
+ */
+
+ fvdbg("Entry %d: End of directory\n", index);
+ ret = -ENOENT;
+ }
+ else
+ {
+ /* Save the filename and file type */
+
+ fvdbg("Entry %d: \"%s\"\n", index, g_builtins[index].name);
+ dir->fd_dir.d_type = DTYPE_FILE;
+ strncpy(dir->fd_dir.d_name, g_builtins[index].name, NAME_MAX+1);
+
+ /* The application list is terminated by an entry with a NULL name.
+ * Therefore, there is at least one more entry in the list.
+ */
+
+ index++;
+
+ /* Set up the next directory entry offset. NOTE that we could use the
+ * standard f_pos instead of our own private fb_index.
+ */
+
+ dir->u.binfs.fb_index = index;
+ ret = OK;
+ }
+
+ return ret;
+}
+
+/****************************************************************************
+ * Name: binfs_rewindir
+ *
+ * Description: Reset directory read to the first entry
+ *
+ ****************************************************************************/
+
+static int binfs_rewinddir(struct inode *mountpt, struct fs_dirent_s *dir)
+{
+ fvdbg("Entry\n");
+
+ dir->u.binfs.fb_index = 0;
+ return OK;
+}
+
+/****************************************************************************
+ * Name: binfs_bind
+ *
+ * Description: This implements a portion of the mount operation. This
+ * function allocates and initializes the mountpoint private data and
+ * binds the blockdriver inode to the filesystem private data. The final
+ * binding of the private data (containing the blockdriver) to the
+ * mountpoint is performed by mount().
+ *
+ ****************************************************************************/
+
+static int binfs_bind(FAR struct inode *blkdriver, const void *data,
+ void **handle)
+{
+ fvdbg("Entry\n");
+ return OK;
+}
+
+/****************************************************************************
+ * Name: binfs_unbind
+ *
+ * Description: This implements the filesystem portion of the umount
+ * operation.
+ *
+ ****************************************************************************/
+
+static int binfs_unbind(void *handle, FAR struct inode **blkdriver)
+{
+ fvdbg("Entry\n");
+ return OK;
+}
+
+/****************************************************************************
+ * Name: binfs_statfs
+ *
+ * Description: Return filesystem statistics
+ *
+ ****************************************************************************/
+
+static int binfs_statfs(struct inode *mountpt, struct statfs *buf)
+{
+ fvdbg("Entry\n");
+
+ /* Fill in the statfs info */
+
+ memset(buf, 0, sizeof(struct statfs));
+ buf->f_type = BINFS_MAGIC;
+ buf->f_bsize = 0;
+ buf->f_blocks = 0;
+ buf->f_bfree = 0;
+ buf->f_bavail = 0;
+ buf->f_namelen = NAME_MAX;
+ return OK;
+}
+
+/****************************************************************************
+ * Name: binfs_stat
+ *
+ * Description: Return information about a file or directory
+ *
+ ****************************************************************************/
+
+static int binfs_stat(struct inode *mountpt, const char *relpath, struct stat *buf)
+{
+ fvdbg("Entry\n");
+
+ /* The requested directory must be the volume-relative "root" directory */
+
+ if (relpath && relpath[0] != '\0')
+ {
+ /* Check if there is a file with this name. */
+
+ if (builtin_isavail(relpath) < 0)
+ {
+ return -ENOENT;
+ }
+
+ /* It's a execute-only file name */
+
+ buf->st_mode = S_IFREG|S_IXOTH|S_IXGRP|S_IXUSR;
+ }
+ else
+ {
+ /* It's a read/execute-only directory name */
+
+ buf->st_mode = S_IFDIR|S_IROTH|S_IRGRP|S_IRUSR|S_IXOTH|S_IXGRP|S_IXUSR;
+ }
+
+ /* File/directory size, access block size */
+
+ buf->st_size = 0;
+ buf->st_blksize = 0;
+ buf->st_blocks = 0;
+ return OK;
+}
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+#endif /* !CONFIG_DISABLE_MOUNTPOINT && CONFIG_FS_BINFS */
+
diff --git a/nuttx/fs/fat/Make.defs b/nuttx/fs/fat/Make.defs
index 136302b86..2769ab602 100644
--- a/nuttx/fs/fat/Make.defs
+++ b/nuttx/fs/fat/Make.defs
@@ -1,7 +1,7 @@
############################################################################
# Make.defs
#
-# Copyright (C) 2008, 2011 Gregory Nutt. All rights reserved.
+# Copyright (C) 2008, 2011, 2013 Gregory Nutt. All rights reserved.
# Author: Gregory Nutt <gnutt@nuttx.org>
#
# Redistribution and use in source and binary forms, with or without
@@ -44,7 +44,10 @@ CSRCS += fs_fat32.c fs_fat32dirent.c fs_fat32attrib.c fs_fat32util.c
ASRCS +=
CSRCS += fs_mkfatfs.c fs_configfat.c fs_writefat.c
-# Argument for dependency checking
+# Include FAT build support
+
+DEPPATH += --dep-path fat
+VPATH += :fat
+CFLAGS += ${shell $(INCDIR) $(INCDIROPT) "$(CC)" $(TOPDIR)$(DELIM)fs$(DELIM)fat}
-FATDEPPATH = --dep-path fat
endif
diff --git a/nuttx/fs/fat/fs_fat32.c b/nuttx/fs/fat/fs_fat32.c
index 0c28cea67..c10c28a5c 100644
--- a/nuttx/fs/fat/fs_fat32.c
+++ b/nuttx/fs/fat/fs_fat32.c
@@ -1,7 +1,7 @@
/****************************************************************************
* fs/fat/fs_fat32.c
*
- * Copyright (C) 2007-2009, 2011-2012 Gregory Nutt. All rights reserved.
+ * Copyright (C) 2007-2009, 2011-2013 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* References:
@@ -86,7 +86,9 @@ static ssize_t fat_write(FAR struct file *filep, const char *buffer,
size_t buflen);
static off_t fat_seek(FAR struct file *filep, off_t offset, int whence);
static int fat_ioctl(FAR struct file *filep, int cmd, unsigned long arg);
+
static int fat_sync(FAR struct file *filep);
+static int fat_dup(FAR const struct file *oldp, FAR struct file *newp);
static int fat_opendir(struct inode *mountpt, const char *relpath,
struct fs_dirent_s *dir);
@@ -121,28 +123,30 @@ static int fat_stat(struct inode *mountpt, const char *relpath, struct stat
const struct mountpt_operations fat_operations =
{
- fat_open,
- fat_close,
- fat_read,
- fat_write,
- fat_seek,
- fat_ioctl,
- fat_sync,
-
- fat_opendir,
- NULL,
- fat_readdir,
- fat_rewinddir,
-
- fat_bind,
- fat_unbind,
- fat_statfs,
-
- fat_unlink,
- fat_mkdir,
- fat_rmdir,
- fat_rename,
- fat_stat
+ fat_open, /* open */
+ fat_close, /* close */
+ fat_read, /* read */
+ fat_write, /* write */
+ fat_seek, /* seek */
+ fat_ioctl, /* ioctl */
+
+ fat_sync, /* sync */
+ fat_dup, /* dup */
+
+ fat_opendir, /* opendir */
+ NULL, /* closedir */
+ fat_readdir, /* readdir */
+ fat_rewinddir, /* rewinddir */
+
+ fat_bind, /* bind */
+ fat_unbind, /* unbind */
+ fat_statfs, /* statfs */
+
+ fat_unlink, /* unlinke */
+ fat_mkdir, /* mkdir */
+ fat_rmdir, /* rmdir */
+ fat_rename, /* rename */
+ fat_stat /* stat */
};
/****************************************************************************
@@ -311,7 +315,6 @@ static int fat_open(FAR struct file *filep, const char *relpath,
/* Initialize the file private data (only need to initialize non-zero elements) */
- ff->ff_open = true;
ff->ff_oflags = oflags;
/* Save information that can be used later to recover the directory entry */
@@ -896,6 +899,7 @@ static off_t fat_seek(FAR struct file *filep, off_t offset, int whence)
DEBUGASSERT(fs != NULL);
/* Map the offset according to the whence option */
+
switch (whence)
{
case SEEK_SET: /* The offset is set to offset bytes. */
@@ -969,6 +973,7 @@ static off_t fat_seek(FAR struct file *filep, off_t offset, int whence)
ret = cluster;
goto errout_with_semaphore;
}
+
ff->ff_startcluster = cluster;
}
@@ -1231,6 +1236,124 @@ errout_with_semaphore:
}
/****************************************************************************
+ * Name: fat_dup
+ *
+ * Description: Duplicate open file data in the new file structure.
+ *
+ ****************************************************************************/
+
+static int fat_dup(FAR const struct file *oldp, FAR struct file *newp)
+{
+ FAR struct fat_mountpt_s *fs;
+ FAR struct fat_file_s *oldff;
+ FAR struct fat_file_s *newff;
+ int ret;
+
+ fvdbg("Dup %p->%p\n", oldp, newp);
+
+ /* Sanity checks */
+
+ DEBUGASSERT(oldp->f_priv != NULL &&
+ newp->f_priv == NULL &&
+ newp->f_inode != NULL);
+
+ /* Recover our private data from the struct file instance */
+
+ fs = (struct fat_mountpt_s *)oldp->f_inode->i_private;
+ DEBUGASSERT(fs != NULL);
+
+ /* Check if the mount is still healthy */
+
+ fat_semtake(fs);
+ ret = fat_checkmount(fs);
+ if (ret != OK)
+ {
+ goto errout_with_semaphore;
+ }
+
+ /* Recover the old private data from the old struct file instance */
+
+ oldff = oldp->f_priv;
+
+ /* Create a new instance of the file private date to describe the
+ * dup'ed file.
+ */
+
+ newff = (struct fat_file_s *)kmalloc(sizeof(struct fat_file_s));
+ if (!newff)
+ {
+ ret = -ENOMEM;
+ goto errout_with_semaphore;
+ }
+
+ /* Create a file buffer to support partial sector accesses */
+
+ newff->ff_buffer = (uint8_t*)fat_io_alloc(fs->fs_hwsectorsize);
+ if (!newff->ff_buffer)
+ {
+ ret = -ENOMEM;
+ goto errout_with_struct;
+ }
+
+ /* Copy the rest of the open open file state from the old file structure.
+ * There are some assumptions and potential issues here:
+ *
+ * 1) We assume that the higher level logic has copied the elements of
+ * the file structure, in particular, the file position.
+ * 2) There is a problem with ff_size if there are multiple opened
+ * file structures, each believing they know the size of the file.
+ * If one instance modifies the file length, then the new size of
+ * the opened file will be unknown to the other. That is a lurking
+ * bug!
+ *
+ * One good solution to this might be to add a refernce count to the
+ * file structure. Then, instead of dup'ing the whole structure
+ * as is done here, just increment the reference count on the
+ * structure. The would have to be integrated with open logic as
+ * well, however, so that the same file structure is re-used if the
+ * file is re-opened.
+ */
+
+ newff->ff_bflags = 0; /* File buffer flags */
+ newff->ff_oflags = oldff->ff_oflags; /* File open flags */
+ newff->ff_sectorsincluster = oldff->ff_sectorsincluster; /* Sectors remaining in cluster */
+ newff->ff_dirindex = oldff->ff_dirindex; /* Index to directory entry */
+ newff->ff_currentcluster = oldff->ff_currentcluster; /* Current cluster */
+ newff->ff_dirsector = oldff->ff_dirsector; /* Sector containing directory entry */
+ newff->ff_size = oldff->ff_size; /* Size of the file */
+ newff->ff_startcluster = oldff->ff_startcluster; /* Start cluster of file on media */
+ newff->ff_currentsector = oldff->ff_currentsector; /* Current sector */
+ newff->ff_cachesector = 0; /* Sector in file buffer */
+
+ /* Attach the private date to the struct file instance */
+
+ newp->f_priv = newff;
+
+ /* Then insert the new instance into the mountpoint structure.
+ * It needs to be there (1) to handle error conditions that effect
+ * all files, and (2) to inform the umount logic that we are busy
+ * (but a simple reference count could have done that).
+ */
+
+ newff->ff_next = fs->fs_head;
+ fs->fs_head = newff->ff_next;
+
+ fat_semgive(fs);
+ return OK;
+
+ /* Error exits -- goto's are nasty things, but they sure can make error
+ * handling a lot simpler.
+ */
+
+errout_with_struct:
+ kfree(newff);
+
+errout_with_semaphore:
+ fat_semgive(fs);
+ return ret;
+}
+
+/****************************************************************************
* Name: fat_opendir
*
* Description: Open a directory for read access
diff --git a/nuttx/fs/fat/fs_fat32.h b/nuttx/fs/fat/fs_fat32.h
index 71a21333b..81f3f4675 100644
--- a/nuttx/fs/fat/fs_fat32.h
+++ b/nuttx/fs/fat/fs_fat32.h
@@ -752,7 +752,6 @@ struct fat_mountpt_s
struct fat_file_s
{
struct fat_file_s *ff_next; /* Retained in a singly linked list */
- bool ff_open; /* true: The file is (still) open */
uint8_t ff_bflags; /* The file buffer flags */
uint8_t ff_oflags; /* Flags provided when file was opened */
uint8_t ff_sectorsincluster; /* Sectors remaining in cluster */
diff --git a/nuttx/fs/fat/fs_fat32util.c b/nuttx/fs/fat/fs_fat32util.c
index 7231456d7..9aa1d3992 100644
--- a/nuttx/fs/fat/fs_fat32util.c
+++ b/nuttx/fs/fat/fs_fat32util.c
@@ -692,8 +692,6 @@ int fat_checkmount(struct fat_mountpt_s *fs)
if (fs && fs->fs_mounted)
{
- struct fat_file_s *file;
-
/* We still think the mount is healthy. Check an see if this is
* still the case
*/
@@ -715,14 +713,8 @@ int fat_checkmount(struct fat_mountpt_s *fs)
/* If we get here, the mount is NOT healthy */
fs->fs_mounted = false;
-
- /* Make sure that this is flagged in every opened file */
-
- for (file = fs->fs_head; file; file = file->ff_next)
- {
- file->ff_open = false;
- }
}
+
return -ENODEV;
}
diff --git a/nuttx/fs/fs_files.c b/nuttx/fs/fs_files.c
index 4da2d28a5..06addb1ef 100644
--- a/nuttx/fs/fs_files.c
+++ b/nuttx/fs/fs_files.c
@@ -1,7 +1,7 @@
/****************************************************************************
* fs/fs_files.c
*
- * Copyright (C) 2007-2009, 2011-2012 Gregory Nutt. All rights reserved.
+ * Copyright (C) 2007-2009, 2011-2013 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
@@ -284,14 +284,6 @@ int files_dup(FAR struct file *filep1, FAR struct file *filep2)
goto errout;
}
-#ifndef CONFIG_DISABLE_MOUNTPOINT
- if (INODE_IS_MOUNTPT(filep1->f_inode))
- {
- err = ENOSYS; /* Not yet supported */
- goto errout;
- }
-#endif
-
list = sched_getfiles();
if (!list)
{
@@ -331,18 +323,16 @@ int files_dup(FAR struct file *filep1, FAR struct file *filep2)
if (inode->u.i_ops && inode->u.i_ops->open)
{
#ifndef CONFIG_DISABLE_MOUNTPOINT
-#if 0 /* Not implemented */
if (INODE_IS_MOUNTPT(inode))
{
- /* Open a file on the mountpoint */
+ /* Dup the open file on the in the new file structure */
- ret = inode->u.i_mops->open(filep2, ?, filep2->f_oflags, ?);
+ ret = inode->u.i_mops->dup(filep1, filep2);
}
else
#endif
-#endif
{
- /* Open the pseudo file or device driver */
+ /* (Re-)open the pseudo file or device driver */
ret = inode->u.i_ops->open(filep2);
}
diff --git a/nuttx/fs/fs_mount.c b/nuttx/fs/fs_mount.c
index 228c1fc6e..a91e7d366 100644
--- a/nuttx/fs/fs_mount.c
+++ b/nuttx/fs/fs_mount.c
@@ -1,7 +1,7 @@
/****************************************************************************
* fs/fs_mount.c
*
- * Copyright (C) 2007-2009, 2011-2012 Gregory Nutt. All rights reserved.
+ * Copyright (C) 2007-2009, 2011-2013 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
@@ -47,10 +47,6 @@
#include <nuttx/fs/fs.h>
-#ifdef CONFIG_APPS_BINDIR
-# include <apps/apps.h>
-#endif
-
#include "fs_internal.h"
/* At least one filesystem must be defined, or this file will not compile.
@@ -78,7 +74,7 @@
/* These file systems do not require block drivers */
-#if defined(CONFIG_FS_NXFFS) || defined(CONFIG_APPS_BINDIR) || defined(CONFIG_NFS)
+#if defined(CONFIG_FS_NXFFS) || defined(CONFIG_FS_BINFS) || defined(CONFIG_NFS)
# define NONBDFS_SUPPORT
#endif
@@ -123,6 +119,9 @@ extern const struct mountpt_operations nxffs_operations;
#ifdef CONFIG_NFS
extern const struct mountpt_operations nfs_operations;
#endif
+#ifdef CONFIG_FS_BINFS
+extern const struct mountpt_operations binfs_operations;
+#endif
static const struct fsmap_t g_nonbdfsmap[] =
{
@@ -132,7 +131,7 @@ static const struct fsmap_t g_nonbdfsmap[] =
#ifdef CONFIG_NFS
{ "nfs", &nfs_operations },
#endif
-#ifdef CONFIG_APPS_BINDIR
+#ifdef CONFIG_FS_BINFS
{ "binfs", &binfs_operations },
#endif
{ NULL, NULL },
@@ -222,7 +221,7 @@ int mount(FAR const char *source, FAR const char *target,
/* Find the specified filesystem. Try the block driver file systems first */
#ifdef BDFS_SUPPORT
- if ((mops = mount_findfs(g_bdfsmap, filesystemtype)) != NULL)
+ if (source && (mops = mount_findfs(g_bdfsmap, filesystemtype)) != NULL)
{
/* Make sure that a block driver argument was provided */
diff --git a/nuttx/fs/mmap/Make.defs b/nuttx/fs/mmap/Make.defs
index 59857fe9c..b85d9f60f 100644
--- a/nuttx/fs/mmap/Make.defs
+++ b/nuttx/fs/mmap/Make.defs
@@ -1,7 +1,7 @@
############################################################################
# fs/mmap/Make.defs
#
-# Copyright (C) 2011 Gregory Nutt. All rights reserved.
+# Copyright (C) 2011, 2013 Gregory Nutt. All rights reserved.
# Author: Gregory Nutt <gnutt@nuttx.org>
#
# Redistribution and use in source and binary forms, with or without
@@ -40,4 +40,9 @@ ifeq ($(CONFIG_FS_RAMMAP),y)
CSRCS += fs_munmap.c fs_rammap.c
endif
-MMAPDEPPATH = --dep-path mmap
+# Include MMAP build support
+
+DEPPATH += --dep-path mmap
+VPATH += :mmap
+CFLAGS += ${shell $(INCDIR) $(INCDIROPT) "$(CC)" $(TOPDIR)$(DELIM)fs$(DELIM)mmap}
+
diff --git a/nuttx/fs/nfs/Make.defs b/nuttx/fs/nfs/Make.defs
index fc4682f85..ec2177fcf 100644
--- a/nuttx/fs/nfs/Make.defs
+++ b/nuttx/fs/nfs/Make.defs
@@ -1,7 +1,7 @@
############################################################################
# Make.defs
#
-# Copyright (C) 2012 Gregory Nutt. All rights reserved.
+# Copyright (C) 2012-2013 Gregory Nutt. All rights reserved.
# Author: Gregory Nutt <gnutt@nuttx.org>
#
# Redistribution and use in source and binary forms, with or without
@@ -44,7 +44,10 @@ CSRCS +=
ASRCS +=
CSRCS += rpc_clnt.c nfs_util.c nfs_vfsops.c
-# Argument for dependency checking
+# Include NFS build support
+
+DEPPATH += --dep-path nfs
+VPATH += :nfs
+CFLAGS += ${shell $(INCDIR) $(INCDIROPT) "$(CC)" $(TOPDIR)$(DELIM)fs$(DELIM)nfs}
-NFSDEPPATH = --dep-path nfs
endif
diff --git a/nuttx/fs/nfs/nfs_node.h b/nuttx/fs/nfs/nfs_node.h
index 4ae9e162c..408bd1993 100644
--- a/nuttx/fs/nfs/nfs_node.h
+++ b/nuttx/fs/nfs/nfs_node.h
@@ -1,7 +1,7 @@
/****************************************************************************
* fs/nfs/nfs_node.h
*
- * Copyright (C) 2012 Gregory Nutt. All rights reserved.
+ * Copyright (C) 2012-2013 Gregory Nutt. All rights reserved.
* Copyright (C) 2012 Jose Pablo Rojas Vargas. All rights reserved.
* Author: Jose Pablo Rojas Vargas <jrojas@nx-engineering.com>
* Gregory Nutt <gnutt@nuttx.org>
@@ -70,6 +70,7 @@
struct nfsnode
{
struct nfsnode *n_next; /* Retained in a singly linked list. */
+ uint8_t n_crefs; /* Reference count (for nfs_dup) */
uint8_t n_type; /* File type */
uint8_t n_fhsize; /* Size in bytes of the file handle */
uint8_t n_flags; /* Node flags */
diff --git a/nuttx/fs/nfs/nfs_util.c b/nuttx/fs/nfs/nfs_util.c
index 73fda72a7..e7d28b3d7 100644
--- a/nuttx/fs/nfs/nfs_util.c
+++ b/nuttx/fs/nfs/nfs_util.c
@@ -1,7 +1,7 @@
/****************************************************************************
* fs/nfs/nfs_util.c
*
- * Copyright (C) 2012 Gregory Nutt. All rights reserved.
+ * Copyright (C) 2012-2013 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
@@ -213,7 +213,6 @@ int nfs_request(struct nfsmount *nmp, int procnum,
{
struct rpcclnt *clnt = nmp->nm_rpcclnt;
struct nfs_reply_header replyh;
- int trylater_delay;
int error;
tryagain:
@@ -250,12 +249,6 @@ tryagain:
if (error == EAGAIN)
{
error = 0;
- trylater_delay *= NFS_TIMEOUTMUL;
- if (trylater_delay > NFS_MAXTIMEO)
- {
- trylater_delay = NFS_MAXTIMEO;
- }
-
goto tryagain;
}
diff --git a/nuttx/fs/nfs/nfs_vfsops.c b/nuttx/fs/nfs/nfs_vfsops.c
index 3cd5a47dc..2ff4ff9d3 100644
--- a/nuttx/fs/nfs/nfs_vfsops.c
+++ b/nuttx/fs/nfs/nfs_vfsops.c
@@ -1,7 +1,7 @@
/****************************************************************************
* fs/nfs/nfs_vfsops.c
*
- * Copyright (C) 2012 Gregory Nutt. All rights reserved.
+ * Copyright (C) 2012-2013 Gregory Nutt. All rights reserved.
* Copyright (C) 2012 Jose Pablo Rojas Vargas. All rights reserved.
* Author: Jose Pablo Rojas Vargas <jrojas@nx-engineering.com>
* Gregory Nutt <gnutt@nuttx.org>
@@ -133,6 +133,7 @@ static int nfs_close(FAR struct file *filep);
static ssize_t nfs_read(FAR struct file *filep, char *buffer, size_t buflen);
static ssize_t nfs_write(FAR struct file *filep, const char *buffer,
size_t buflen);
+static int nfs_dup(FAR const struct file *oldp, FAR struct file *newp);
static int nfs_opendir(struct inode *mountpt, const char *relpath,
struct fs_dirent_s *dir);
static int nfs_readdir(struct inode *mountpt, struct fs_dirent_s *dir);
@@ -166,7 +167,9 @@ const struct mountpt_operations nfs_operations =
nfs_write, /* write */
NULL, /* seek */
NULL, /* ioctl */
+
NULL, /* sync */
+ nfs_dup, /* dup */
nfs_opendir, /* opendir */
NULL, /* closedir */
@@ -357,7 +360,7 @@ static int nfs_filecreate(FAR struct nfsmount *nmp, struct nfsnode *np,
/* Save the attributes in the file data structure */
- tmp = *ptr++; /* handle_follows */
+ tmp = *ptr; /* handle_follows */
if (!tmp)
{
fdbg("WARNING: no file attributes\n");
@@ -367,7 +370,6 @@ static int nfs_filecreate(FAR struct nfsmount *nmp, struct nfsnode *np,
/* Initialize the file attributes */
nfs_attrupdate(np, (FAR struct nfs_fattr *)ptr);
- ptr += uint32_increment(sizeof(struct nfs_fattr));
}
/* Any following dir_wcc data is ignored for now */
@@ -410,7 +412,7 @@ static int nfs_filetruncate(FAR struct nfsmount *nmp, struct nfsnode *np)
reqlen += (int)np->n_fhsize;
ptr += uint32_increment(np->n_fhsize);
- /* Copy the variable-length attribtes */
+ /* Copy the variable-length attributes */
*ptr++ = nfs_false; /* Don't change mode */
*ptr++ = nfs_false; /* Don't change uid */
@@ -421,7 +423,7 @@ static int nfs_filetruncate(FAR struct nfsmount *nmp, struct nfsnode *np)
*ptr++ = HTONL(NFSV3SATTRTIME_TOSERVER); /* Use the server's time */
*ptr++ = HTONL(NFSV3SATTRTIME_TOSERVER); /* Use the server's time */
*ptr++ = nfs_false; /* No guard value */
- reqlen += 9*sizeof(uint32_t)
+ reqlen += 9 * sizeof(uint32_t);
/* Perform the SETATTR RPC */
@@ -551,9 +553,9 @@ static int nfs_fileopen(FAR struct nfsmount *nmp, struct nfsnode *np,
static int nfs_open(FAR struct file *filep, FAR const char *relpath,
int oflags, mode_t mode)
{
- struct nfsmount *nmp;
- struct nfsnode *np = NULL;
- int error;
+ struct nfsmount *nmp;
+ struct nfsnode *np;
+ int error;
/* Sanity checks */
@@ -632,6 +634,8 @@ static int nfs_open(FAR struct file *filep, FAR const char *relpath,
* non-zero elements)
*/
+ np->n_crefs = 1;
+
/* Attach the private data to the struct file instance */
filep->f_priv = np;
@@ -654,6 +658,7 @@ errout_with_semaphore:
{
kfree(np);
}
+
nfs_semgive(nmp);
return -error;
}
@@ -675,6 +680,7 @@ static int nfs_close(FAR struct file *filep)
FAR struct nfsnode *np;
FAR struct nfsnode *prev;
FAR struct nfsnode *curr;
+ int ret;
/* Sanity checks */
@@ -691,42 +697,64 @@ static int nfs_close(FAR struct file *filep)
nfs_semtake(nmp);
- /* Find our file structure in the list of file structures containted in the
- * mount structure.
+ /* Decrement the reference count. If the reference count would not
+ * decrement to zero, then that is all we have to do.
*/
- for (prev = NULL, curr = nmp->nm_head; curr; prev = curr, curr = curr->n_next)
- {
- /* Check if this node is ours */
+ if (np->n_crefs > 1)
+ {
+ np->n_crefs--;
+ ret = OK;
+ }
- if (np == curr)
- {
- /* Yes.. remove it from the list of file structures */
+ /* There are no more references to the file structure. Now we need to
+ * free up all resources associated with the open file.
+ *
+ * First, find our file structure in the list of file structures
+ * containted in the mount structure.
+ */
+
+ else
+ {
+ /* Assume file structure will not be found. This should never happen. */
+
+ ret = -EINVAL;
+
+ for (prev = NULL, curr = nmp->nm_head;
+ curr;
+ prev = curr, curr = curr->n_next)
+ {
+ /* Check if this node is ours */
- if (prev)
- {
- /* Remove from mid-list */
+ if (np == curr)
+ {
+ /* Yes.. remove it from the list of file structures */
- prev->n_next = np->n_next;
- }
- else
- {
- /* Remove from the head of the list */
+ if (prev)
+ {
+ /* Remove from mid-list */
- nmp->nm_head = np->n_next;
- }
+ prev->n_next = np->n_next;
+ }
+ else
+ {
+ /* Remove from the head of the list */
- /* Then deallocate the file structure and return success */
+ nmp->nm_head = np->n_next;
+ }
- kfree(np);
- nfs_semgive(nmp);
- return OK;
- }
- }
+ /* Then deallocate the file structure and return success */
- fdbg("ERROR: file structure not found in list: %p\n", np);
+ kfree(np);
+ ret = OK;
+ break;
+ }
+ }
+ }
+
+ filep->f_priv = NULL;
nfs_semgive(nmp);
- return EINVAL;
+ return ret;
}
/****************************************************************************
@@ -757,8 +785,8 @@ static ssize_t nfs_read(FAR struct file *filep, char *buffer, size_t buflen)
/* Recover our private data from the struct file instance */
- nmp = (struct nfsmount*) filep->f_inode->i_private;
- np = (struct nfsnode*) filep->f_priv;
+ nmp = (struct nfsmount*)filep->f_inode->i_private;
+ np = (struct nfsnode*)filep->f_priv;
DEBUGASSERT(nmp != NULL);
@@ -1092,6 +1120,66 @@ errout_with_semaphore:
}
/****************************************************************************
+ * Name: binfs_dup
+ *
+ * Description:
+ * Duplicate open file data in the new file structure.
+ *
+ ****************************************************************************/
+
+static int nfs_dup(FAR const struct file *oldp, FAR struct file *newp)
+{
+ struct nfsmount *nmp;
+ FAR struct nfsnode *np;
+ int error;
+
+ fvdbg("Dup %p->%p\n", oldp, newp);
+
+ /* Sanity checks */
+
+ DEBUGASSERT(oldp->f_priv != NULL && oldp->f_inode != NULL);
+
+ /* Recover our private data from the struct file instance */
+
+ nmp = (struct nfsmount*)oldp->f_inode->i_private;
+ np = (struct nfsnode*)oldp->f_priv;
+
+ DEBUGASSERT(nmp != NULL);
+
+ /* Check if the mount is still healthy */
+
+ nfs_semtake(nmp);
+ error = nfs_checkmount(nmp);
+ if (error != OK)
+ {
+ fdbg("ERROR: nfs_checkmount failed: %d\n", error);
+ nfs_semgive(nmp);
+ return -error;
+ }
+
+ /* Increment the reference count on the NFS node structure */
+
+ DEBUGASSERT(np->n_crefs < 0xff);
+ np->n_crefs++;
+
+ /* And save this as the file data for the new node */
+
+ newp->f_priv = np;
+
+ /* Then insert the new instance at the head of the list in the mountpoint
+ * tructure. It needs to be there (1) to handle error conditions that effect
+ * all files, and (2) to inform the umount logic that we are busy. We
+ * cannot unmount the file system if this list is not empty!
+ */
+
+ np->n_next = nmp->nm_head;
+ nmp->nm_head = np;
+
+ nfs_semgive(nmp);
+ return OK;
+}
+
+/****************************************************************************
* Name: nfs_opendir
*
* Description:
@@ -1754,12 +1842,15 @@ bad:
{
kfree(nmp->nm_so);
}
+
if (nmp->nm_rpcclnt)
{
kfree(nmp->nm_rpcclnt);
}
+
kfree(nmp);
}
+
return error;
}
diff --git a/nuttx/fs/nfs/rpc_clnt.c b/nuttx/fs/nfs/rpc_clnt.c
index 0e2a394ba..9c2ada4f2 100644
--- a/nuttx/fs/nfs/rpc_clnt.c
+++ b/nuttx/fs/nfs/rpc_clnt.c
@@ -1,7 +1,7 @@
/****************************************************************************
* fs/nfs/rpc_clnt.c
*
- * Copyright (C) 2012 Gregory Nutt. All rights reserved.
+ * Copyright (C) 2012-2013 Gregory Nutt. All rights reserved.
* Copyright (C) 2012 Jose Pablo Rojas Vargas. All rights reserved.
* Author: Jose Pablo Rojas Vargas <jrojas@nx-engineering.com>
* Gregory Nutt <gnutt@nuttx.org>
@@ -224,8 +224,6 @@ static int rpcclnt_receive(FAR struct rpcclnt *rpc, FAR struct sockaddr *aname,
static int rpcclnt_reply(FAR struct rpcclnt *rpc, int procid, int prog,
FAR void *reply, size_t resplen)
{
- FAR struct rpc_reply_header *replyheader;
- uint32_t rxid;
int error;
/* Get the next RPC reply from the socket */
@@ -235,22 +233,22 @@ static int rpcclnt_reply(FAR struct rpcclnt *rpc, int procid, int prog,
{
fdbg("ERROR: rpcclnt_receive returned: %d\n", error);
- /* If we failed because of a timeout, then try sending the CALL
- * message again.
- */
+ /* If we failed because of a timeout, then try sending the CALL
+ * message again.
+ */
- if (error == EAGAIN || error == ETIMEDOUT)
- {
- rpc->rc_timeout = true;
- }
- }
+ if (error == EAGAIN || error == ETIMEDOUT)
+ {
+ rpc->rc_timeout = true;
+ }
+ }
/* Get the xid and check that it is an RPC replysvr */
else
{
- replyheader = (FAR struct rpc_reply_header *)reply;
- rxid = replyheader->rp_xid;
+ FAR struct rpc_reply_header *replyheader =
+ (FAR struct rpc_reply_header *)reply;
if (replyheader->rp_direction != rpc_reply)
{
@@ -260,7 +258,7 @@ static int rpcclnt_reply(FAR struct rpcclnt *rpc, int procid, int prog,
}
}
- return OK;
+ return error;
}
/****************************************************************************
@@ -275,7 +273,6 @@ static uint32_t rpcclnt_newxid(void)
{
static uint32_t rpcclnt_xid = 0;
static uint32_t rpcclnt_xid_touched = 0;
- int xidp = 0;
srand(time(NULL));
if ((rpcclnt_xid == 0) && (rpcclnt_xid_touched == 0))
@@ -285,6 +282,7 @@ static uint32_t rpcclnt_newxid(void)
}
else
{
+ int xidp = 0;
do
{
xidp = rand();
diff --git a/nuttx/fs/nxffs/Make.defs b/nuttx/fs/nxffs/Make.defs
index b67ae4472..ccf1ba661 100644
--- a/nuttx/fs/nxffs/Make.defs
+++ b/nuttx/fs/nxffs/Make.defs
@@ -1,7 +1,7 @@
############################################################################
# fs/nxffs/Make.defs
#
-# Copyright (C) 2011 Gregory Nutt. All rights reserved.
+# Copyright (C) 2011, 2013 Gregory Nutt. All rights reserved.
# Author: Gregory Nutt <gnutt@nuttx.org>
#
# Redistribution and use in source and binary forms, with or without
@@ -40,7 +40,10 @@ CSRCS += nxffs_block.c nxffs_blockstats.c nxffs_cache.c nxffs_dirent.c \
nxffs_open.c nxffs_pack.c nxffs_read.c nxffs_reformat.c \
nxffs_stat.c nxffs_unlink.c nxffs_util.c nxffs_write.c
-# Argument for dependency checking
+# Include NXFFS build support
+
+DEPPATH += --dep-path nxffs
+VPATH += :nxffs
+CFLAGS += ${shell $(INCDIR) $(INCDIROPT) "$(CC)" $(TOPDIR)$(DELIM)fs$(DELIM)nxffs}
-NXFFSDEPPATH = --dep-path nxffs
endif
diff --git a/nuttx/fs/nxffs/nxffs.h b/nuttx/fs/nxffs/nxffs.h
index 616dc7197..083e00fa7 100644
--- a/nuttx/fs/nxffs/nxffs.h
+++ b/nuttx/fs/nxffs/nxffs.h
@@ -1,7 +1,7 @@
/****************************************************************************
* fs/nxffs/nxffs.h
*
- * Copyright (C) 2011 Gregory Nutt. All rights reserved.
+ * Copyright (C) 2011, 2013 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* References: Linux/Documentation/filesystems/romfs.txt
@@ -1044,6 +1044,7 @@ extern int nxffs_pack(FAR struct nxffs_volume_s *volume);
* - nxffs_read() is defined in nxffs_read.c
* - nxffs_write() is defined in nxffs_write.c
* - nxffs_ioctl() is defined in nxffs_ioctl.c
+ * - nxffs_dup() is defined in nxffs_open.c
* - nxffs_opendir(), nxffs_readdir(), and nxffs_rewindir() are defined in
* nxffs_dirent.c
* - nxffs_bind() and nxffs_unbind() are defined in nxffs_initialize.c
@@ -1058,25 +1059,25 @@ struct fs_dirent_s;
struct statfs;
struct stat;
-extern int nxffs_open(FAR struct file *filep, FAR const char *relpath,
- int oflags, mode_t mode);
-extern int nxffs_close(FAR struct file *filep);
-extern ssize_t nxffs_read(FAR struct file *filep, FAR char *buffer,
- size_t buflen);
-extern ssize_t nxffs_write(FAR struct file *filep, FAR const char *buffer,
- size_t buflen);
-extern int nxffs_ioctl(FAR struct file *filep, int cmd, unsigned long arg);
-extern int nxffs_opendir(FAR struct inode *mountpt, FAR const char *relpath,
- FAR struct fs_dirent_s *dir);
-extern int nxffs_readdir(FAR struct inode *mountpt, FAR struct fs_dirent_s *dir);
-extern int nxffs_rewinddir(FAR struct inode *mountpt, FAR struct fs_dirent_s *dir);
-extern int nxffs_bind(FAR struct inode *blkdriver, FAR const void *data,
- FAR void **handle);
-extern int nxffs_unbind(FAR void *handle, FAR struct inode **blkdriver);
-extern int nxffs_statfs(FAR struct inode *mountpt, FAR struct statfs *buf);
-extern int nxffs_stat(FAR struct inode *mountpt, FAR const char *relpath,
- FAR struct stat *buf);
-extern int nxffs_unlink(FAR struct inode *mountpt, FAR const char *relpath);
+int nxffs_open(FAR struct file *filep, FAR const char *relpath, int oflags,
+ mode_t mode);
+int nxffs_close(FAR struct file *filep);
+ssize_t nxffs_read(FAR struct file *filep, FAR char *buffer, size_t buflen);
+ssize_t nxffs_write(FAR struct file *filep, FAR const char *buffer,
+ size_t buflen);
+int nxffs_ioctl(FAR struct file *filep, int cmd, unsigned long arg);
+int nxffs_dup(FAR const struct file *oldp, FAR struct file *newp);
+int nxffs_opendir(FAR struct inode *mountpt, FAR const char *relpath,
+ FAR struct fs_dirent_s *dir);
+int nxffs_readdir(FAR struct inode *mountpt, FAR struct fs_dirent_s *dir);
+int nxffs_rewinddir(FAR struct inode *mountpt, FAR struct fs_dirent_s *dir);
+int nxffs_bind(FAR struct inode *blkdriver, FAR const void *data,
+ FAR void **handle);
+int nxffs_unbind(FAR void *handle, FAR struct inode **blkdriver);
+int nxffs_statfs(FAR struct inode *mountpt, FAR struct statfs *buf);
+int nxffs_stat(FAR struct inode *mountpt, FAR const char *relpath,
+ FAR struct stat *buf);
+int nxffs_unlink(FAR struct inode *mountpt, FAR const char *relpath);
#endif /* __FS_NXFFS_NXFFS_H */
diff --git a/nuttx/fs/nxffs/nxffs_initialize.c b/nuttx/fs/nxffs/nxffs_initialize.c
index 6d93a318a..4e7428c73 100644
--- a/nuttx/fs/nxffs/nxffs_initialize.c
+++ b/nuttx/fs/nxffs/nxffs_initialize.c
@@ -1,7 +1,7 @@
/****************************************************************************
* fs/nxffs/nxffs_initialize.c
*
- * Copyright (C) 2011 Gregory Nutt. All rights reserved.
+ * Copyright (C) 2011, 2013 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* References: Linux/Documentation/filesystems/romfs.txt
@@ -82,7 +82,9 @@ const struct mountpt_operations nxffs_operations =
nxffs_write, /* write */
NULL, /* seek -- Use f_pos in struct file */
nxffs_ioctl, /* ioctl */
+
NULL, /* sync -- No buffered data */
+ nxffs_dup, /* dup */
nxffs_opendir, /* opendir */
NULL, /* closedir */
diff --git a/nuttx/fs/nxffs/nxffs_open.c b/nuttx/fs/nxffs/nxffs_open.c
index eb7817c57..9fa4ef2e0 100644
--- a/nuttx/fs/nxffs/nxffs_open.c
+++ b/nuttx/fs/nxffs/nxffs_open.c
@@ -1,7 +1,7 @@
/****************************************************************************
* fs/nxffs/nxffs_open.c
*
- * Copyright (C) 2011 Gregory Nutt. All rights reserved.
+ * Copyright (C) 2011, 2013 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* References: Linux/Documentation/filesystems/romfs.txt
@@ -1023,7 +1023,7 @@ int nxffs_open(FAR struct file *filep, FAR const char *relpath,
#endif
/* Limitation: A file must be opened for reading or writing, but not both.
- * There is no general for extending the size of of a file. Extending the
+ * There is no general way of extending the size of a file. Extending the
* file size of possible if the file to be extended is the last in the
* sequence on FLASH, but since that case is not the general case, no file
* extension is supported.
@@ -1059,6 +1059,64 @@ int nxffs_open(FAR struct file *filep, FAR const char *relpath,
}
/****************************************************************************
+ * Name: binfs_dup
+ *
+ * Description:
+ * Duplicate open file data in the new file structure.
+ *
+ ****************************************************************************/
+
+int nxffs_dup(FAR const struct file *oldp, FAR struct file *newp)
+{
+#ifdef CONFIG_DEBUG
+ FAR struct nxffs_volume_s *volume;
+#endif
+ FAR struct nxffs_ofile_s *ofile;
+
+ fvdbg("Dup %p->%p\n", oldp, newp);
+
+ /* Sanity checks */
+
+#ifdef CONFIG_DEBUG
+ DEBUGASSERT(oldp->f_priv == NULL && oldp->f_inode != NULL);
+
+ /* Get the mountpoint private data from the NuttX inode reference in the
+ * file structure
+ */
+
+ volume = (FAR struct nxffs_volume_s*)oldp->f_inode->i_private;
+ DEBUGASSERT(volume != NULL);
+#endif
+
+ /* Recover the open file state from the struct file instance */
+
+ ofile = (FAR struct nxffs_ofile_s *)oldp->f_priv;
+
+ /* I do not think we need exclusive access to the volume to do this.
+ * The volume exclsem protects the open file list and, hence, would
+ * assure that the ofile is stable. However, it is assumed that the
+ * caller holds a value file descriptor associated with this ofile,
+ * so it should be stable throughout the life of this function.
+ */
+
+ /* Limitations: I do not think we have to be concerned about the
+ * usual NXFFS file limitations here: dup'ing cannot resulting
+ * in mixed reading and writing to the same file, or multiple
+ * writer to different file.
+ *
+ * I notice that nxffs_wropen will prohibit multiple opens for
+ * writing. But I do not thing that dup'ing a file already opened
+ * for writing suffers from any of these issues.
+ */
+
+ /* Just increment the reference count on the ofile */
+
+ ofile->crefs++;
+ newp->f_priv = (FAR void *)ofile;
+ return OK;
+}
+
+/****************************************************************************
* Name: nxffs_close
*
* Description:
@@ -1130,9 +1188,10 @@ int nxffs_close(FAR struct file *filep)
ofile->crefs--;
}
- filep->f_priv = NULL;
+ filep->f_priv = NULL;
sem_post(&volume->exclsem);
+
errout:
return ret;
}
diff --git a/nuttx/fs/romfs/Make.defs b/nuttx/fs/romfs/Make.defs
index 77de93c05..e87cbdf9e 100644
--- a/nuttx/fs/romfs/Make.defs
+++ b/nuttx/fs/romfs/Make.defs
@@ -1,7 +1,7 @@
############################################################################
# fs/romfs/Make.defs
#
-# Copyright (C) 2008, 2011 Gregory Nutt. All rights reserved.
+# Copyright (C) 2008, 2011, 2013 Gregory Nutt. All rights reserved.
# Author: Gregory Nutt <gnutt@nuttx.org>
#
# Redistribution and use in source and binary forms, with or without
@@ -39,7 +39,10 @@ ifeq ($(CONFIG_FS_ROMFS),y)
ASRCS +=
CSRCS += fs_romfs.c fs_romfsutil.c
-# Argument for dependency checking
+# Include ROMFS build support
+
+DEPPATH += --dep-path romfs
+VPATH += :romfs
+CFLAGS += ${shell $(INCDIR) $(INCDIROPT) "$(CC)" $(TOPDIR)$(DELIM)fs$(DELIM)romfs}
-ROMFSDEPPATH = --dep-path romfs
endif
diff --git a/nuttx/fs/romfs/fs_romfs.c b/nuttx/fs/romfs/fs_romfs.c
index b95619d75..6a6fca355 100644
--- a/nuttx/fs/romfs/fs_romfs.c
+++ b/nuttx/fs/romfs/fs_romfs.c
@@ -56,6 +56,7 @@
#include <errno.h>
#include <debug.h>
+#include <nuttx/kmalloc.h>
#include <nuttx/fs/fs.h>
#include <nuttx/fs/ioctl.h>
#include <nuttx/fs/dirent.h>
@@ -70,24 +71,33 @@
* Private Function Prototypes
****************************************************************************/
-static int romfs_open(FAR struct file *filep, const char *relpath,
+static int romfs_open(FAR struct file *filep, FAR const char *relpath,
int oflags, mode_t mode);
static int romfs_close(FAR struct file *filep);
-static ssize_t romfs_read(FAR struct file *filep, char *buffer, size_t buflen);
+static ssize_t romfs_read(FAR struct file *filep, FAR char *buffer,
+ size_t buflen);
static off_t romfs_seek(FAR struct file *filep, off_t offset, int whence);
-static int romfs_ioctl(FAR struct file *filep, int cmd, unsigned long arg);
+static int romfs_ioctl(FAR struct file *filep, int cmd,
+ unsigned long arg);
-static int romfs_opendir(struct inode *mountpt, const char *relpath,
- struct fs_dirent_s *dir);
-static int romfs_readdir(struct inode *mountpt, struct fs_dirent_s *dir);
-static int romfs_rewinddir(struct inode *mountpt, struct fs_dirent_s *dir);
+static int romfs_dup(FAR const struct file *oldp, FAR struct file *newp);
-static int romfs_bind(FAR struct inode *blkdriver, const void *data,
- void **handle);
-static int romfs_unbind(void *handle, FAR struct inode **blkdriver);
-static int romfs_statfs(struct inode *mountpt, struct statfs *buf);
+static int romfs_opendir(FAR struct inode *mountpt,
+ FAR const char *relpath,
+ FAR struct fs_dirent_s *dir);
+static int romfs_readdir(FAR struct inode *mountpt,
+ FAR struct fs_dirent_s *dir);
+static int romfs_rewinddir(FAR struct inode *mountpt,
+ FAR struct fs_dirent_s *dir);
-static int romfs_stat(struct inode *mountpt, const char *relpath, struct stat *buf);
+static int romfs_bind(FAR struct inode *blkdriver, FAR const void *data,
+ FAR void **handle);
+static int romfs_unbind(FAR void *handle, FAR struct inode **blkdriver);
+static int romfs_statfs(FAR struct inode *mountpt,
+ FAR struct statfs *buf);
+
+static int romfs_stat(FAR struct inode *mountpt, FAR const char *relpath,
+ FAR struct stat *buf);
/****************************************************************************
* Private Variables
@@ -110,7 +120,9 @@ const struct mountpt_operations romfs_operations =
NULL, /* write */
romfs_seek, /* seek */
romfs_ioctl, /* ioctl */
+
NULL, /* sync */
+ romfs_dup, /* dup */
romfs_opendir, /* opendir */
NULL, /* closedir */
@@ -136,13 +148,13 @@ const struct mountpt_operations romfs_operations =
* Name: romfs_open
****************************************************************************/
-static int romfs_open(FAR struct file *filep, const char *relpath,
- int oflags, mode_t mode)
+static int romfs_open(FAR struct file *filep, FAR const char *relpath,
+ int oflags, mode_t mode)
{
- struct romfs_dirinfo_s dirinfo;
- struct romfs_mountpt_s *rm;
- struct romfs_file_s *rf;
- int ret;
+ struct romfs_dirinfo_s dirinfo;
+ FAR struct romfs_mountpt_s *rm;
+ FAR struct romfs_file_s *rf;
+ int ret;
fvdbg("Open '%s'\n", relpath);
@@ -150,11 +162,11 @@ static int romfs_open(FAR struct file *filep, const char *relpath,
DEBUGASSERT(filep->f_priv == NULL && filep->f_inode != NULL);
- /* mountpoint private data from the inode reference from the file
+ /* Get mountpoint private data from the inode reference from the file
* structure
*/
- rm = (struct romfs_mountpt_s*)filep->f_inode->i_private;
+ rm = (FAR struct romfs_mountpt_s*)filep->f_inode->i_private;
DEBUGASSERT(rm != NULL);
@@ -214,7 +226,7 @@ static int romfs_open(FAR struct file *filep, const char *relpath,
* file.
*/
- rf = (struct romfs_file_s *)zalloc(sizeof(struct romfs_file_s));
+ rf = (FAR struct romfs_file_s *)kzalloc(sizeof(struct romfs_file_s));
if (!rf)
{
fdbg("Failed to allocate private data\n", ret);
@@ -226,8 +238,7 @@ static int romfs_open(FAR struct file *filep, const char *relpath,
* non-zero elements)
*/
- rf->rf_open = true;
- rf->rf_size = dirinfo.rd_size;
+ rf->rf_size = dirinfo.rd_size;
/* Get the start of the file data */
@@ -277,9 +288,9 @@ errout_with_semaphore:
static int romfs_close(FAR struct file *filep)
{
- struct romfs_mountpt_s *rm;
- struct romfs_file_s *rf;
- int ret = OK;
+ FAR struct romfs_mountpt_s *rm;
+ FAR struct romfs_file_s *rf;
+ int ret = OK;
fvdbg("Closing\n");
@@ -307,12 +318,12 @@ static int romfs_close(FAR struct file *filep)
if (!rm->rm_xipbase && rf->rf_buffer)
{
- free(rf->rf_buffer);
+ kfree(rf->rf_buffer);
}
/* Then free the file structure itself. */
- free(rf);
+ kfree(rf);
filep->f_priv = NULL;
return ret;
}
@@ -321,19 +332,20 @@ static int romfs_close(FAR struct file *filep)
* Name: romfs_read
****************************************************************************/
-static ssize_t romfs_read(FAR struct file *filep, char *buffer, size_t buflen)
+static ssize_t romfs_read(FAR struct file *filep, FAR char *buffer,
+ size_t buflen)
{
- struct romfs_mountpt_s *rm;
- struct romfs_file_s *rf;
- unsigned int bytesread;
- unsigned int readsize;
- unsigned int nsectors;
- uint32_t offset;
- size_t bytesleft;
- off_t sector;
- uint8_t *userbuffer = (uint8_t*)buffer;
- int sectorndx;
- int ret;
+ FAR struct romfs_mountpt_s *rm;
+ FAR struct romfs_file_s *rf;
+ unsigned int bytesread;
+ unsigned int readsize;
+ unsigned int nsectors;
+ uint32_t offset;
+ size_t bytesleft;
+ off_t sector;
+ FAR uint8_t *userbuffer = (FAR uint8_t*)buffer;
+ int sectorndx;
+ int ret;
fvdbg("Read %d bytes from offset %d\n", buflen, filep->f_pos);
@@ -467,10 +479,10 @@ errout_with_semaphore:
static off_t romfs_seek(FAR struct file *filep, off_t offset, int whence)
{
- struct romfs_mountpt_s *rm;
- struct romfs_file_s *rf;
- off_t position;
- int ret;
+ FAR struct romfs_mountpt_s *rm;
+ FAR struct romfs_file_s *rf;
+ off_t position;
+ int ret;
fvdbg("Seek to offset: %d whence: %d\n", offset, whence);
@@ -548,9 +560,9 @@ errout_with_semaphore:
static int romfs_ioctl(FAR struct file *filep, int cmd, unsigned long arg)
{
- struct romfs_mountpt_s *rm;
- struct romfs_file_s *rf;
- FAR void **ppv = (FAR void**)arg;
+ FAR struct romfs_mountpt_s *rm;
+ FAR struct romfs_file_s *rf;
+ FAR void **ppv = (FAR void**)arg;
fvdbg("cmd: %d arg: %08lx\n", cmd, arg);
@@ -582,6 +594,95 @@ static int romfs_ioctl(FAR struct file *filep, int cmd, unsigned long arg)
}
/****************************************************************************
+ * Name: romfs_dup
+ ****************************************************************************/
+
+static int romfs_dup(FAR const struct file *oldp, FAR struct file *newp)
+{
+ FAR struct romfs_mountpt_s *rm;
+ FAR struct romfs_file_s *oldrf;
+ FAR struct romfs_file_s *newrf;
+ int ret;
+
+ fvdbg("Dup %p->%p\n", oldp, newp);
+
+ /* Sanity checks */
+
+ DEBUGASSERT(oldp->f_priv != NULL &&
+ newp->f_priv == NULL &&
+ newp->f_inode != NULL);
+
+ /* Get mountpoint private data from the inode reference from the file
+ * structure
+ */
+
+ rm = (FAR struct romfs_mountpt_s*)newp->f_inode->i_private;
+ DEBUGASSERT(rm != NULL);
+
+ /* Check if the mount is still healthy */
+
+ romfs_semtake(rm);
+ ret = romfs_checkmount(rm);
+ if (ret != OK)
+ {
+ fdbg("romfs_checkmount failed: %d\n", ret);
+ goto errout_with_semaphore;
+ }
+
+ /* Recover the old private data from the old struct file instance */
+
+ oldrf = oldp->f_priv;
+
+ /* Create an new instance of the file private data to describe the new
+ * dup'ed file.
+ */
+
+ newrf = (FAR struct romfs_file_s *)kmalloc(sizeof(struct romfs_file_s));
+ if (!newrf)
+ {
+ fdbg("Failed to allocate private data\n", ret);
+ ret = -ENOMEM;
+ goto errout_with_semaphore;
+ }
+
+ /* Copy all file private data (except for the buffer) */
+
+ newrf->rf_startoffset = oldrf->rf_startoffset;
+ newrf->rf_size = oldrf->rf_size;
+
+ /* Configure buffering to support access to this file */
+
+ ret = romfs_fileconfigure(rm, newrf);
+ if (ret < 0)
+ {
+ fdbg("Failed configure buffering: %d\n", ret);
+ goto errout_with_semaphore;
+ }
+
+ /* Attach the new private date to the new struct file instance */
+
+ newp->f_priv = newrf;
+
+ /* Then insert the new instance into the mountpoint structure.
+ * It needs to be there (1) to handle error conditions that effect
+ * all files, and (2) to inform the umount logic that we are busy
+ * (but a simple reference count could have done that).
+ */
+
+ newrf->rf_next = rm->rm_head;
+ rm->rm_head = newrf->rf_next;
+
+ romfs_semgive(rm);
+ return OK;
+
+ /* Error exits */
+
+errout_with_semaphore:
+ romfs_semgive(rm);
+ return ret;
+}
+
+/****************************************************************************
* Name: romfs_opendir
*
* Description:
@@ -589,12 +690,12 @@ static int romfs_ioctl(FAR struct file *filep, int cmd, unsigned long arg)
*
****************************************************************************/
-static int romfs_opendir(struct inode *mountpt, const char *relpath,
- struct fs_dirent_s *dir)
+static int romfs_opendir(FAR struct inode *mountpt, FAR const char *relpath,
+ FAR struct fs_dirent_s *dir)
{
- struct romfs_mountpt_s *rm;
- struct romfs_dirinfo_s dirinfo;
- int ret;
+ FAR struct romfs_mountpt_s *rm;
+ FAR struct romfs_dirinfo_s dirinfo;
+ int ret;
fvdbg("relpath: '%s'\n", relpath);
@@ -654,14 +755,15 @@ errout_with_semaphore:
*
****************************************************************************/
-static int romfs_readdir(struct inode *mountpt, struct fs_dirent_s *dir)
+static int romfs_readdir(FAR struct inode *mountpt,
+ FAR struct fs_dirent_s *dir)
{
- struct romfs_mountpt_s *rm;
- uint32_t linkoffset;
- uint32_t next;
- uint32_t info;
- uint32_t size;
- int ret;
+ FAR struct romfs_mountpt_s *rm;
+ uint32_t linkoffset;
+ uint32_t next;
+ uint32_t info;
+ uint32_t size;
+ int ret;
fvdbg("Entry\n");
@@ -749,9 +851,10 @@ errout_with_semaphore:
*
****************************************************************************/
-static int romfs_rewinddir(struct inode *mountpt, struct fs_dirent_s *dir)
+static int romfs_rewinddir(FAR struct inode *mountpt,
+ FAR struct fs_dirent_s *dir)
{
- struct romfs_mountpt_s *rm;
+ FAR struct romfs_mountpt_s *rm;
int ret;
fvdbg("Entry\n");
@@ -788,8 +891,8 @@ static int romfs_rewinddir(struct inode *mountpt, struct fs_dirent_s *dir)
*
****************************************************************************/
-static int romfs_bind(FAR struct inode *blkdriver, const void *data,
- void **handle)
+static int romfs_bind(FAR struct inode *blkdriver, FAR const void *data,
+ FAR void **handle)
{
struct romfs_mountpt_s *rm;
int ret;
@@ -813,7 +916,7 @@ static int romfs_bind(FAR struct inode *blkdriver, const void *data,
/* Create an instance of the mountpt state structure */
- rm = (struct romfs_mountpt_s *)zalloc(sizeof(struct romfs_mountpt_s));
+ rm = (FAR struct romfs_mountpt_s *)kzalloc(sizeof(struct romfs_mountpt_s));
if (!rm)
{
fdbg("Failed to allocate mountpoint structure\n");
@@ -857,12 +960,12 @@ static int romfs_bind(FAR struct inode *blkdriver, const void *data,
errout_with_buffer:
if (!rm->rm_xipbase)
{
- free(rm->rm_buffer);
+ kfree(rm->rm_buffer);
}
errout_with_sem:
sem_destroy(&rm->rm_sem);
- free(rm);
+ kfree(rm);
return ret;
}
@@ -874,9 +977,9 @@ errout_with_sem:
*
****************************************************************************/
-static int romfs_unbind(void *handle, FAR struct inode **blkdriver)
+static int romfs_unbind(FAR void *handle, FAR struct inode **blkdriver)
{
- struct romfs_mountpt_s *rm = (struct romfs_mountpt_s*)handle;
+ FAR struct romfs_mountpt_s *rm = (FAR struct romfs_mountpt_s*)handle;
int ret;
fvdbg("Entry\n");
@@ -929,11 +1032,11 @@ static int romfs_unbind(void *handle, FAR struct inode **blkdriver)
if (!rm->rm_xipbase && rm->rm_buffer)
{
- free(rm->rm_buffer);
+ kfree(rm->rm_buffer);
}
sem_destroy(&rm->rm_sem);
- free(rm);
+ kfree(rm);
return OK;
}
@@ -948,10 +1051,10 @@ static int romfs_unbind(void *handle, FAR struct inode **blkdriver)
*
****************************************************************************/
-static int romfs_statfs(struct inode *mountpt, struct statfs *buf)
+static int romfs_statfs(FAR struct inode *mountpt, FAR struct statfs *buf)
{
- struct romfs_mountpt_s *rm;
- int ret;
+ FAR struct romfs_mountpt_s *rm;
+ int ret;
fvdbg("Entry\n");
@@ -1004,11 +1107,12 @@ errout_with_semaphore:
*
****************************************************************************/
-static int romfs_stat(struct inode *mountpt, const char *relpath, struct stat *buf)
+static int romfs_stat(FAR struct inode *mountpt, FAR const char *relpath,
+ FAR struct stat *buf)
{
- struct romfs_mountpt_s *rm;
- struct romfs_dirinfo_s dirinfo;
- int ret;
+ FAR struct romfs_mountpt_s *rm;
+ FAR struct romfs_dirinfo_s dirinfo;
+ int ret;
fvdbg("Entry\n");
diff --git a/nuttx/fs/romfs/fs_romfs.h b/nuttx/fs/romfs/fs_romfs.h
index 4081517fb..6a337d2c5 100644
--- a/nuttx/fs/romfs/fs_romfs.h
+++ b/nuttx/fs/romfs/fs_romfs.h
@@ -159,7 +159,6 @@ struct romfs_mountpt_s
struct romfs_file_s
{
struct romfs_file_s *rf_next; /* Retained in a singly linked list */
- bool rf_open; /* true: The file is (still) open */
uint32_t rf_startoffset; /* Offset to the start of the file data */
uint32_t rf_size; /* Size of the file in bytes */
uint32_t rf_cachesector; /* Current sector in the rf_buffer */
diff --git a/nuttx/fs/romfs/fs_romfsutil.c b/nuttx/fs/romfs/fs_romfsutil.c
index 6ea114b5e..4857fb6d3 100644
--- a/nuttx/fs/romfs/fs_romfsutil.c
+++ b/nuttx/fs/romfs/fs_romfsutil.c
@@ -613,7 +613,7 @@ int romfs_fsconfigure(struct romfs_mountpt_s *rm)
}
/****************************************************************************
- * Name: romfs_ffileconfigure
+ * Name: romfs_fileconfigure
*
* Desciption:
* This function is called as part of the ROMFS file open operation It
@@ -649,6 +649,7 @@ int romfs_fileconfigure(struct romfs_mountpt_s *rm, struct romfs_file_s *rf)
return -ENOMEM;
}
}
+
return OK;
}
@@ -663,7 +664,6 @@ int romfs_fileconfigure(struct romfs_mountpt_s *rm, struct romfs_file_s *rf)
int romfs_checkmount(struct romfs_mountpt_s *rm)
{
- struct romfs_file_s *file;
struct inode *inode;
struct geometry geo;
int ret;
@@ -692,14 +692,8 @@ int romfs_checkmount(struct romfs_mountpt_s *rm)
/* If we get here, the mount is NOT healthy */
rm->rm_mounted = false;
-
- /* Make sure that this is flagged in every opened file */
-
- for (file = rm->rm_head; file; file = file->rf_next)
- {
- file->rf_open = false;
- }
}
+
return -ENODEV;
}