summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2011-05-07 20:08:46 +0000
committerpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2011-05-07 20:08:46 +0000
commit77f5bc2c9f37c3e15e1ea07f0954d61c65210e6a (patch)
treee08843a13827de30586a98e801c9507fd41b3674
parentca700d2e3c06a80de37c5ef8383ca550fe20c750 (diff)
downloadnuttx-77f5bc2c9f37c3e15e1ea07f0954d61c65210e6a.tar.gz
nuttx-77f5bc2c9f37c3e15e1ea07f0954d61c65210e6a.tar.bz2
nuttx-77f5bc2c9f37c3e15e1ea07f0954d61c65210e6a.zip
Add fs/mmap
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@3576 42af7a65-404d-4744-a932-0658087f49c3
-rw-r--r--nuttx/fs/Makefile16
-rw-r--r--nuttx/fs/mmap/Make.defs43
-rw-r--r--nuttx/fs/mmap/fs_mmap.c (renamed from nuttx/fs/fs_mmap.c)54
-rw-r--r--nuttx/fs/mmap/fs_munmap.c114
-rw-r--r--nuttx/fs/mmap/fs_rammap.c85
-rw-r--r--nuttx/fs/mmap/fs_rammap.h109
6 files changed, 392 insertions, 29 deletions
diff --git a/nuttx/fs/Makefile b/nuttx/fs/Makefile
index 3f9356391..45ff2db79 100644
--- a/nuttx/fs/Makefile
+++ b/nuttx/fs/Makefile
@@ -46,14 +46,16 @@ endif
else
CSRCS += fs_open.c fs_close.c fs_read.c fs_write.c fs_ioctl.c \
fs_poll.c fs_select.c fs_lseek.c fs_dup.c fs_filedup.c \
- fs_dup2.c fs_fcntl.c fs_filedup2.c fs_mmap.c fs_opendir.c \
- fs_closedir.c fs_stat.c fs_readdir.c fs_seekdir.c fs_rewinddir.c \
- fs_files.c fs_inode.c fs_inodefind.c fs_inodereserve.c \
- fs_statfs.c fs_inoderemove.c fs_registerdriver.c fs_unregisterdriver.c \
+ fs_dup2.c fs_fcntl.c fs_filedup2.c fs_opendir.c fs_closedir.c \
+ fs_stat.c fs_readdir.c fs_seekdir.c fs_rewinddir.c fs_files.c \
+ fs_inode.c fs_inodefind.c fs_inodereserve.c fs_statfs.c \
+ fs_inoderemove.c fs_registerdriver.c fs_unregisterdriver.c \
fs_inodeaddref.c fs_inoderelease.c
CSRCS += fs_registerblockdriver.c fs_unregisterblockdriver.c \
fs_findblockdriver.c fs_openblockdriver.c fs_closeblockdriver.c
+include mmap/Make.defs
+
ifneq ($(CONFIG_NFILE_STREAMS),0)
CSRCS += fs_fdopen.c
endif
@@ -74,8 +76,8 @@ OBJS = $(AOBJS) $(COBJS)
BIN = libfs$(LIBEXT)
-SUBDIRS = fat romfs nxffs
-VPATH = fat:romfs:nxffs
+SUBDIRS = mmap fat romfs nxffs
+VPATH = mmap:fat:romfs:nxffs
all: $(BIN)
@@ -91,7 +93,7 @@ $(BIN): $(OBJS)
done ; )
.depend: Makefile $(SRCS)
- @$(MKDEP) --dep-path . $(FATDEPPATH) $(ROMFSDEPPATH) $(NXFFSDEPPATH) \
+ @$(MKDEP) --dep-path . $(MMAPDEPPATH) $(FATDEPPATH) $(ROMFSDEPPATH) $(NXFFSDEPPATH) \
$(CC) -- $(CFLAGS) -- $(SRCS) >Make.dep
@touch $@
diff --git a/nuttx/fs/mmap/Make.defs b/nuttx/fs/mmap/Make.defs
new file mode 100644
index 000000000..2d3d00694
--- /dev/null
+++ b/nuttx/fs/mmap/Make.defs
@@ -0,0 +1,43 @@
+############################################################################
+# fs/mmap/Make.defs
+#
+# Copyright (C) 2011 Gregory Nutt. All rights reserved.
+# Author: Gregory Nutt <spudmonkey@racsa.co.cr>
+#
+# 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.
+#
+############################################################################
+
+ASRCS +=
+CSRCS += fs_mmap.c
+
+ifeq ($(CONFIG_FS_RAMMAP),y)
+CSRCS += fs_munmap.c fs_rammap.c
+endif
+
+MMAPDEPPATH = --dep-path mmap
diff --git a/nuttx/fs/fs_mmap.c b/nuttx/fs/mmap/fs_mmap.c
index 5368b426a..3a69e5167 100644
--- a/nuttx/fs/fs_mmap.c
+++ b/nuttx/fs/mmap/fs_mmap.c
@@ -1,7 +1,7 @@
/****************************************************************************
- * fs/fs_mmap.c
+ * fs/mmap/fs_mmap.c
*
- * Copyright (C) 2008-2009 Gregory Nutt. All rights reserved.
+ * Copyright (C) 2008-2009, 2011 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
*
* Redistribution and use in source and binary forms, with or without
@@ -57,25 +57,30 @@
*
* Description:
* NuttX operates in a flat open address space. Therefore, it generally
- * does not require mmap() functionality. There is one one exception:
- * mmap() is the API that is used to support direct access to random
- * access media under the following very restrictive conditions:
+ * does not require mmap() functionality. There are two exceptions:
*
- * 1. The filesystem supports the FIOC_MMAP ioctl command. Any file system
- * that maps files contiguously on the media should support this ioctl.
- * (vs. file system that scatter files over the media in non-contiguous
- * sectors). As of this writing, ROMFS is the only file system that
- * meets this requirement.
- * 2. The underly block driver supports the BIOC_XIPBASE ioctl command
- * that maps the underlying media to a randomly accessible address. At
- * present, only the RAM/ROM disk driver does this.
+ * 1. mmap() is the API that is used to support direct access to random
+ * access media under the following very restrictive conditions:
+ *
+ * a. The filesystem supports the FIOC_MMAP ioctl command. Any file
+ * system that maps files contiguously on the media should support
+ * this ioctl. (vs. file system that scatter files over the media
+ * in non-contiguous sectors). As of this writing, ROMFS is the
+ * only file system that meets this requirement.
+ * b. The underlying block driver supports the BIOC_XIPBASE ioctl
+ * command that maps the underlying media to a randomly accessible
+ * address. At present, only the RAM/ROM disk driver does this.
+ *
+ * 2. If CONFIG_FS_RAMMAP is defined in the configuration, then mmap() will
+ * support simulation of memory mapped files by copying files whole
+ * into RAM.
*
* Parameters:
* start A hint at where to map the memory -- ignored. The address
- * of the underlying media is fixed and cannot be re-mapped withou
+ * of the underlying media is fixed and cannot be re-mapped without
* MMU support.
- * length The length of the mapping -- ignored. The entire underlying
- * media is always accessible.
+ * length The length of the mapping. For exception #1 above, this length
+ * ignored: The entire underlying media is always accessible.
* prot See the PROT_* definitions in sys/mman.h.
* PROT_NONE - Will cause an error
* PROT_READ - PROT_WRITE and PROT_EXEC also assumed
@@ -98,9 +103,9 @@
* fd file descriptor of the backing file -- required.
* offset The offset into the file to map
*
- * Return:
- * On success, mmap() returns a pointer to the mapped area.
- * On error, the value MAP_FAILED is returned, and errno is set appropriately.
+ * Returned Value:
+ * On success, mmap() returns a pointer to the mapped area. On error, the
+ * value MAP_FAILED is returned, and errno is set appropriately.
*
* ENOSYS
* Returned if any of the unsupported mmap() features are attempted
@@ -155,8 +160,14 @@ FAR void *mmap(FAR void *start, size_t length, int prot, int flags,
ret = ioctl(fd, FIOC_MMAP, (unsigned long)((uintptr_t)&addr));
if (ret < 0)
{
- fdbg("ioctl(FIOC_MMAP) failed: %d\n", errno);
- goto errout;
+#ifdef CONFIG_FS_RAMMAP
+ ret = rammap(fd, length, offset, &addr);
+ if (ret < 0)
+#endif
+ {
+ fdbg("ioctl(FIOC_MMAP) failed: %d\n", errno);
+ goto errout;
+ }
}
/* Return the offset address */
@@ -171,4 +182,3 @@ errout_with_ret:
errout:
return MAP_FAILED;
}
-
diff --git a/nuttx/fs/mmap/fs_munmap.c b/nuttx/fs/mmap/fs_munmap.c
new file mode 100644
index 000000000..e42450458
--- /dev/null
+++ b/nuttx/fs/mmap/fs_munmap.c
@@ -0,0 +1,114 @@
+/****************************************************************************
+ * fs/mmap/fs_munmap.c
+ *
+ * Copyright (C) 2011 Gregory Nutt. All rights reserved.
+ * Author: Gregory Nutt <spudmonkey@racsa.co.cr>
+ *
+ * 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/mman.h>
+
+#include <stdint.h>
+#include <errno.h>
+#include <debug.h>
+
+#include "fs_internal.h"
+
+#ifdef CONFIG_FS_RAMMAP
+
+/****************************************************************************
+ * Global Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: munmap
+ *
+ * Description:
+ *
+ * munmap() system call deletes mappings for the specified address range.
+ * The region is also automatically unmapped when the process is terminated.
+ * On the other hand, closing the file descriptor does not unmap the region.
+ *
+ * NuttX operates in a flat open address space. Therefore, it generally
+ * does not require mmap() and, hence, munmap functionality. There are
+ * two exceptions where mmap() is available:
+ *
+ * 1. mmap() is the API that is used to support direct access to random
+ * access media under the following very restrictive conditions:
+ *
+ * a. The filesystem supports the FIOC_MMAP ioctl command. Any file
+ * system that maps files contiguously on the media should support
+ * this ioctl. (vs. file system that scatter files over the media
+ * in non-contiguous sectors). As of this writing, ROMFS is the
+ * only file system that meets this requirement.
+ * b. The underlying block driver supports the BIOC_XIPBASE ioctl
+ * command that maps the underlying media to a randomly accessible
+ * address. At present, only the RAM/ROM disk driver does this.
+ *
+ * munmap() is still not required in this first case. In this first
+ * The mapped address is a static address in the MCUs address space
+ * does not need to be munmapped. Support for munmap() in this case
+ * provided by the simple definition in sys/mman.h:
+ *
+ * #define munmap(start, length)
+ *
+ * 2. If CONFIG_FS_RAMMAP is defined in the configuration, then mmap() will
+ * support simulation of memory mapped files by copying files whole
+ * into RAM. munmap() is required in this case to free the allocated
+ * memory holding the shared copy of the file.
+ *
+ * Parameters:
+ * start The start address of the mapping to delete. For this
+ * simplified munmap() implementation, the *must* be the start
+ * address of the memory region (the same address returned by
+ * mmap()).
+ * length The length region to be umapped. Ignored. The entire underlying
+ * media is always freed.
+ *
+ * Returned Value:
+ * On success, munmap() returns 0, on failure -1, and errno is set
+ * (probably to EINVAL).
+ *
+ ****************************************************************************/
+
+int munmap(FART void *start, size_t length)
+{
+#warning "Missing logic"
+ return MAP_FAILED;
+}
+
+#endif /* CONFIG_FS_RAMMAP */
diff --git a/nuttx/fs/mmap/fs_rammap.c b/nuttx/fs/mmap/fs_rammap.c
new file mode 100644
index 000000000..91f753cd0
--- /dev/null
+++ b/nuttx/fs/mmap/fs_rammap.c
@@ -0,0 +1,85 @@
+/****************************************************************************
+ * fs/mmap/fs_rammmap.c
+ *
+ * Copyright (C) 2011 Gregory Nutt. All rights reserved.
+ * Author: Gregory Nutt <spudmonkey@racsa.co.cr>
+ *
+ * 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 <errno.h>
+#include <debug.h>
+
+#include "fs_internal.h"
+
+#ifdef CONFIG_FS_RAMMAP
+
+/****************************************************************************
+ * Global Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: rammmap
+ *
+ * Description:
+ * Support simulation of memory mapped files by copying files into RAM.
+ *
+ * Parameters:
+ * fd file descriptor of the backing file -- required.
+ * length The length of the mapping. For exception #1 above, this length
+ * ignored: The entire underlying media is always accessible.
+ * offset The offset into the file to map
+ *
+ * Returned Value:
+ * On success, rammmap() returns a pointer to the mapped area. On error, the
+ * value MAP_FAILED is returned, and errno is set appropriately.
+ *
+ * EBADF
+ * 'fd' is not a valid file descriptor.
+ * EINVAL
+ * 'length' or 'offset' are invalid
+ * ENOMEM
+ * Insufficient memory is available to map the file.
+ *
+ ****************************************************************************/
+
+int rammap(int fd, size_t length, off_t offset, FAR void **addr)
+{
+#warning "Missing logic"
+ return -ENOSYS;
+}
+
+#endif /* CONFIG_FS_RAMMAP */
diff --git a/nuttx/fs/mmap/fs_rammap.h b/nuttx/fs/mmap/fs_rammap.h
new file mode 100644
index 000000000..c8eba76b6
--- /dev/null
+++ b/nuttx/fs/mmap/fs_rammap.h
@@ -0,0 +1,109 @@
+/****************************************************************************
+ * fs/mmap/rammap.h
+ *
+ * Copyright (C) 2011 Gregory Nutt. All rights reserved.
+ * Author: Gregory Nutt <spudmonkey@racsa.co.cr>
+ *
+ * References: Linux/Documentation/filesystems/romfs.txt
+ *
+ * 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_MMAP_RAMMAP_H
+#define __FS_MMAP_RAMMAP_H
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+
+#ifdef CONFIG_FS_RAMMAP
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Public Types
+ ****************************************************************************/
+
+/* This structure describes one file that has been copied to memory and
+ * managed as a share-able "memory mapped" file. This functionality is
+ * intended to provide a substitute for memory mapped files for architectures
+ * that do not have MMUs and, hence, cannot support on demand paging of
+ * blocks of a file.
+ *
+ * This copied file has many of the properties of a standard memory mapped
+ * file except for all of the file must be present in memory. This limits
+ * the size of files that may be memory mapped (especially on MCUs with
+ * no significant RAM resources).
+ */
+
+struct fs_rammap_s
+{
+};
+
+/****************************************************************************
+ * Public Variables
+ ****************************************************************************/
+
+/****************************************************************************
+ * Public Function Prototypes
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: rammmap
+ *
+ * Description:
+ * Support simulation of memory mapped files by copying files into RAM.
+ *
+ * Parameters:
+ * fd file descriptor of the backing file -- required.
+ * length The length of the mapping. For exception #1 above, this length
+ * ignored: The entire underlying media is always accessible.
+ * offset The offset into the file to map
+ *
+ * Returned Value:
+ * On success, rammmap() returns a pointer to the mapped area. On error, the
+ * value MAP_FAILED is returned, and errno is set appropriately.
+ *
+ * EBADF
+ * 'fd' is not a valid file descriptor.
+ * EINVAL
+ * 'length' or 'offset' are invalid
+ * ENOMEM
+ * Insufficient memory is available to map the file.
+ *
+ ****************************************************************************/
+
+extern int rammap(int fd, size_t length, off_t offset, FAR void **addr);
+
+#endif /* CONFIG_FS_RAMMAP */
+#endif /* __FS_MMAP_RAMMAP_H */