mirror of
https://github.com/apache/nuttx.git
synced 2026-05-28 03:45:50 +08:00
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
This commit is contained in:
+13
-3
@@ -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)
|
||||
|
||||
+10
-9
@@ -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)
|
||||
|
||||
+50
-11
@@ -914,13 +914,45 @@ 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 */
|
||||
|
||||
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);
|
||||
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 (;;)
|
||||
@@ -930,26 +962,33 @@ 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 */
|
||||
|
||||
offset += 16;
|
||||
DEBUGASSERT(offset < rm->rm_volsize);
|
||||
|
||||
/* 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 */
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user