summaryrefslogtreecommitdiff
path: root/nuttx/fs
diff options
context:
space:
mode:
authorpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2008-09-12 19:17:15 +0000
committerpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2008-09-12 19:17:15 +0000
commitbd5c6bfbaee32b963be80d872f9365d70d3b6ed8 (patch)
tree01215e0e0bc94258227cbe7b18db0b4ab731bd14 /nuttx/fs
parent725491fe0e537bfee94f143d5e6162a65d9bfaf4 (diff)
downloadpx4-nuttx-bd5c6bfbaee32b963be80d872f9365d70d3b6ed8.tar.gz
px4-nuttx-bd5c6bfbaee32b963be80d872f9365d70d3b6ed8.tar.bz2
px4-nuttx-bd5c6bfbaee32b963be80d872f9365d70d3b6ed8.zip
Added mmap()/XIP test to ROMFS test
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@917 42af7a65-404d-4744-a932-0658087f49c3
Diffstat (limited to 'nuttx/fs')
-rw-r--r--nuttx/fs/fs_mmap.c12
-rw-r--r--nuttx/fs/romfs/fs_romfs.c16
-rw-r--r--nuttx/fs/romfs/fs_romfs.h19
-rw-r--r--nuttx/fs/romfs/fs_romfsutil.c59
4 files changed, 78 insertions, 28 deletions
diff --git a/nuttx/fs/fs_mmap.c b/nuttx/fs/fs_mmap.c
index 57ab57fa1..309d48942 100644
--- a/nuttx/fs/fs_mmap.c
+++ b/nuttx/fs/fs_mmap.c
@@ -57,21 +57,21 @@
* 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
+ * mmap() is the API that is used to support direct access to random
* access media under the following very restrictive conditions:
*
* 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-contigous
+ * (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.
+ * 2. The underly block driver supports the BIOC_XIPBASE ioctl command
* that maps the underlying media to a randomly accessible address. At
- * present, on the RAM/ROM disk driver does this.
+ * present, only the RAM/ROM disk driver does this.
*
* Parameters:
* start A hint at where to map the memory -- ignored. The address
- * of the underlying media is fixed and cannot be re-mapped with
+ * of the underlying media is fixed and cannot be re-mapped withou
* MMU support.
* length The length of the mapping -- ignored. The entire underlying
* media is always accessible.
@@ -94,7 +94,7 @@
* MAP_NORESERVE - Ignored
* MAP_POPULATE - Ignored
* MAP_NONBLOCK - Ignored
- * fd file descriptor of backing file -- required.
+ * fd file descriptor of the backing file -- required.
* offset The offset into the file to map
*
* Return:
diff --git a/nuttx/fs/romfs/fs_romfs.c b/nuttx/fs/romfs/fs_romfs.c
index ae4542e40..5dbacd829 100644
--- a/nuttx/fs/romfs/fs_romfs.c
+++ b/nuttx/fs/romfs/fs_romfs.c
@@ -211,13 +211,23 @@ static int romfs_open(FAR struct file *filep, const char *relpath,
goto errout_with_semaphore;
}
- /* Initialize the file private data (only need to initialize non-zero elements) */
+ /* Initialize the file private data (only need to initialize
+ * non-zero elements)
+ */
rf->rf_open = TRUE;
- rf->rf_startoffset = romfs_datastart(rm, dirinfo.rd_dir.fr_curroffset);
rf->rf_size = dirinfo.rd_size;
- /* Confiure a buffering to support access to this file */
+ /* Get the start of the file data */
+
+ ret = romfs_datastart(rm, dirinfo.rd_dir.fr_curroffset,
+ &rf->rf_startoffset);
+ if (ret < 0)
+ {
+ goto errout_with_semaphore;
+ }
+
+ /* Configure buffering to support access to this file */
ret = romfs_fileconfigure(rm, rf);
if (ret < 0)
diff --git a/nuttx/fs/romfs/fs_romfs.h b/nuttx/fs/romfs/fs_romfs.h
index dd14f72e3..4dea1a25e 100644
--- a/nuttx/fs/romfs/fs_romfs.h
+++ b/nuttx/fs/romfs/fs_romfs.h
@@ -198,24 +198,25 @@ extern "C" {
EXTERN void romfs_semtake(struct romfs_mountpt_s *rm);
EXTERN void romfs_semgive(struct romfs_mountpt_s *rm);
EXTERN int romfs_hwread(struct romfs_mountpt_s *rm, ubyte *buffer,
- uint32 sector, unsigned int nsectors);
+ uint32 sector, unsigned int nsectors);
EXTERN int romfs_devcacheread(struct romfs_mountpt_s *rm, uint32 sector);
EXTERN int romfs_filecacheread(struct romfs_mountpt_s *rm,
- struct romfs_file_s *rf, uint32 sector);
+ struct romfs_file_s *rf, uint32 sector);
EXTERN int romfs_hwconfigure(struct romfs_mountpt_s *rm);
EXTERN int romfs_fsconfigure(struct romfs_mountpt_s *rm);
EXTERN int romfs_fileconfigure(struct romfs_mountpt_s *rm,
- struct romfs_file_s *rf);
+ struct romfs_file_s *rf);
EXTERN int romfs_checkmount(struct romfs_mountpt_s *rm);
EXTERN int romfs_finddirentry(struct romfs_mountpt_s *rm,
- struct romfs_dirinfo_s *dirinfo,
- const char *path);
+ struct romfs_dirinfo_s *dirinfo,
+ const char *path);
EXTERN int romfs_parsedirentry(struct romfs_mountpt_s *rm,
- uint32 offset, uint32 *poffset, uint32 *pnext,
- uint32 *pinfo, uint32 *psize);
+ uint32 offset, uint32 *poffset, uint32 *pnext,
+ uint32 *pinfo, uint32 *psize);
EXTERN int romfs_parsefilename(struct romfs_mountpt_s *rm, uint32 offset,
- char *pname);
-EXTERN uint32 romfs_datastart(struct romfs_mountpt_s *rm, uint32 offset);
+ char *pname);
+EXTERN int romfs_datastart(struct romfs_mountpt_s *rm, uint32 offset,
+ uint32 *start);
#undef EXTERN
#if defined(__cplusplus)
diff --git a/nuttx/fs/romfs/fs_romfsutil.c b/nuttx/fs/romfs/fs_romfsutil.c
index 7ae274cf0..6debb78cc 100644
--- a/nuttx/fs/romfs/fs_romfsutil.c
+++ b/nuttx/fs/romfs/fs_romfsutil.c
@@ -914,15 +914,16 @@ int romfs_parsefilename(struct romfs_mountpt_s *rm, uint32 offset, char *pname)
*
****************************************************************************/
-uint32 romfs_datastart(struct romfs_mountpt_s *rm, uint32 offset)
+int romfs_datastart(struct romfs_mountpt_s *rm, uint32 offset, uint32 *start)
{
uint32 sector;
+ uint32 next;
+ uint32 info;
uint16 ndx;
int ret;
- /* Loop until the header size of obtained. */
+ /* Loop while we traverse any hardlinks */
- offset += ROMFS_FHDR_NAME;
for (;;)
{
/* Convert the offset into sector + index */
@@ -930,26 +931,64 @@ uint32 romfs_datastart(struct romfs_mountpt_s *rm, uint32 offset)
sector = SEC_NSECTORS(rm, offset);
ndx = offset & SEC_NDXMASK(rm);
- /* Get the offset to the next chunk */
+ /* Read the sector into memory */
- offset += 16;
- DEBUGASSERT(offset < rm->rm_volsize);
+ ret = romfs_devcacheread(rm, sector);
+ if (ret < 0)
+ {
+ return ret;
+ }
+
+ /* Check if this is a hard link */
+
+ next = romfs_devread32(rm, ndx + ROMFS_FHDR_NEXT);
+ if ((next & RFNEXT_MODEMASK) != RFNEXT_HARDLINK)
+ {
+ break;
+ }
+
+ /* Follow the hard-link */
+
+ offset = romfs_devread32(rm, ndx + ROMFS_FHDR_INFO);
+ }
+
+ /* Loop until the header size is obtained. */
+
+ offset += ROMFS_FHDR_NAME;
+ for (;;)
+ {
+ /* Convert the offset into sector + index */
+
+ sector = SEC_NSECTORS(rm, offset);
+ ndx = offset & SEC_NDXMASK(rm);
/* Read the sector into memory */
ret = romfs_devcacheread(rm, sector);
- DEBUGASSERT(ret >= 0);
+ if (ret < 0)
+ {
+ return ret;
+ }
+
+ /* Get the offset to the next chunk */
+
+ offset += 16;
+ if (offset >= rm->rm_volsize)
+ {
+ return -EIO;
+ }
/* Is the name terminated in this 16-byte block */
if (rm->rm_buffer[ndx + 15] == '\0')
{
- /* Yes.. then the data starts after this chunk */
+ /* Yes.. then the data starts at the next chunk */
- return offset;
+ *start = offset;
+ return OK;
}
}
- return ERROR; /* Won't get here */
+ return -EINVAL; /* Won't get here */
}