ROMFS fixes discovered during testing
git-svn-id: https://nuttx.svn.sourceforge.net/svnroot/nuttx/trunk@908 7fd9a85b-ad96-42d3-883c-3090e2eb8679
This commit is contained in:
parent
110d333a5c
commit
7e73d17765
|
@ -116,8 +116,7 @@ struct fs_fatdir_s
|
||||||
|
|
||||||
struct fs_romfsdir_s
|
struct fs_romfsdir_s
|
||||||
{
|
{
|
||||||
uint32 fr_diroffset; /* Offset to the directory entry */
|
uint32 fr_firstoffset; /* Offset to the first entry in the directory */
|
||||||
uint32 fr_firstoffset; /* Offset to the first entry */
|
|
||||||
uint32 fr_curroffset; /* Current offset into the directory contents */
|
uint32 fr_curroffset; /* Current offset into the directory contents */
|
||||||
};
|
};
|
||||||
#endif /* CONFIG_FS_ROMFS */
|
#endif /* CONFIG_FS_ROMFS */
|
||||||
|
|
|
@ -223,8 +223,7 @@ static int romfs_open(FAR struct file *filep, const char *relpath,
|
||||||
/* 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_open = TRUE;
|
||||||
rf->rf_diroffset = dirinfo.rd_dir.fr_diroffset;
|
rf->rf_startoffset = romfs_datastart(rm, dirinfo.rd_dir.fr_curroffset);
|
||||||
rf->rf_startoffset = dirinfo.rd_dir.fr_curroffset;
|
|
||||||
rf->rf_size = dirinfo.rd_size;
|
rf->rf_size = dirinfo.rd_size;
|
||||||
rf->rf_cachesector = (uint32)-1;
|
rf->rf_cachesector = (uint32)-1;
|
||||||
|
|
||||||
|
@ -314,6 +313,7 @@ static ssize_t romfs_read(FAR struct file *filep, char *buffer, size_t buflen)
|
||||||
unsigned int bytesread;
|
unsigned int bytesread;
|
||||||
unsigned int readsize;
|
unsigned int readsize;
|
||||||
unsigned int nsectors;
|
unsigned int nsectors;
|
||||||
|
uint32 offset;
|
||||||
size_t bytesleft;
|
size_t bytesleft;
|
||||||
off_t sector;
|
off_t sector;
|
||||||
ubyte *userbuffer = (ubyte*)buffer;
|
ubyte *userbuffer = (ubyte*)buffer;
|
||||||
|
@ -354,11 +354,6 @@ static ssize_t romfs_read(FAR struct file *filep, char *buffer, size_t buflen)
|
||||||
buflen = bytesleft;
|
buflen = bytesleft;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Get the first sector and index to read from. */
|
|
||||||
|
|
||||||
sector = SEC_NSECTORS(rm, filep->f_pos);
|
|
||||||
sectorndx = filep->f_pos & SEC_NDXMASK(rm);
|
|
||||||
|
|
||||||
/* Loop until either (1) all data has been transferred, or (2) an
|
/* Loop until either (1) all data has been transferred, or (2) an
|
||||||
* error occurs.
|
* error occurs.
|
||||||
*/
|
*/
|
||||||
|
@ -366,6 +361,11 @@ static ssize_t romfs_read(FAR struct file *filep, char *buffer, size_t buflen)
|
||||||
readsize = 0;
|
readsize = 0;
|
||||||
while (buflen > 0)
|
while (buflen > 0)
|
||||||
{
|
{
|
||||||
|
/* Get the first sector and index to read from. */
|
||||||
|
|
||||||
|
offset = rf->rf_startoffset + filep->f_pos;
|
||||||
|
sector = SEC_NSECTORS(rm, offset);
|
||||||
|
sectorndx = offset & SEC_NDXMASK(rm);
|
||||||
bytesread = 0;
|
bytesread = 0;
|
||||||
|
|
||||||
/* Check if the user has provided a buffer large enough to
|
/* Check if the user has provided a buffer large enough to
|
||||||
|
@ -429,7 +429,6 @@ static ssize_t romfs_read(FAR struct file *filep, char *buffer, size_t buflen)
|
||||||
filep->f_pos += bytesread;
|
filep->f_pos += bytesread;
|
||||||
readsize += bytesread;
|
readsize += bytesread;
|
||||||
buflen -= bytesread;
|
buflen -= bytesread;
|
||||||
sectorndx = filep->f_pos & SEC_NDXMASK(rm);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
romfs_semgive(rm);
|
romfs_semgive(rm);
|
||||||
|
|
|
@ -153,8 +153,7 @@ struct romfs_file_s
|
||||||
{
|
{
|
||||||
struct romfs_file_s *rf_next; /* Retained in a singly linked list */
|
struct romfs_file_s *rf_next; /* Retained in a singly linked list */
|
||||||
boolean rf_open; /* TRUE: The file is (still) open */
|
boolean rf_open; /* TRUE: The file is (still) open */
|
||||||
uint32 rf_diroffset; /* Offset to the parent directory entry */
|
uint32 rf_startoffset; /* Offset to the start of the file data */
|
||||||
uint32 rf_startoffset; /* Offset to the start of the file */
|
|
||||||
uint32 rf_size; /* Size of the file in bytes */
|
uint32 rf_size; /* Size of the file in bytes */
|
||||||
uint32 rf_cachesector; /* Current sector in the rf_buffer */
|
uint32 rf_cachesector; /* Current sector in the rf_buffer */
|
||||||
ubyte *rf_buffer; /* File sector buffer */
|
ubyte *rf_buffer; /* File sector buffer */
|
||||||
|
@ -213,6 +212,7 @@ EXTERN int romfs_parsedirentry(struct romfs_mountpt_s *rm,
|
||||||
uint32 *pinfo, uint32 *psize);
|
uint32 *pinfo, uint32 *psize);
|
||||||
EXTERN int romfs_parsefilename(struct romfs_mountpt_s *rm, uint32 offset,
|
EXTERN int romfs_parsefilename(struct romfs_mountpt_s *rm, uint32 offset,
|
||||||
char *pname);
|
char *pname);
|
||||||
|
EXTERN uint32 romfs_datastart(struct romfs_mountpt_s *rm, uint32 offset);
|
||||||
|
|
||||||
#undef EXTERN
|
#undef EXTERN
|
||||||
#if defined(__cplusplus)
|
#if defined(__cplusplus)
|
||||||
|
|
|
@ -45,6 +45,7 @@
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
#include <assert.h>
|
||||||
#include <debug.h>
|
#include <debug.h>
|
||||||
|
|
||||||
#include "fs_romfs.h"
|
#include "fs_romfs.h"
|
||||||
|
@ -165,7 +166,6 @@ static inline int romfs_checkentry(struct romfs_mountpt_s *rm, uint32 offset,
|
||||||
|
|
||||||
if (IS_DIRECTORY(next))
|
if (IS_DIRECTORY(next))
|
||||||
{
|
{
|
||||||
dirinfo->rd_dir.fr_diroffset = linkoffset;
|
|
||||||
dirinfo->rd_dir.fr_firstoffset = info;
|
dirinfo->rd_dir.fr_firstoffset = info;
|
||||||
dirinfo->rd_dir.fr_curroffset = info;
|
dirinfo->rd_dir.fr_curroffset = info;
|
||||||
dirinfo->rd_size = 0;
|
dirinfo->rd_size = 0;
|
||||||
|
@ -205,11 +205,12 @@ static inline int romfs_searchdir(struct romfs_mountpt_s *rm,
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
/* Then loop through the current directory until the directory
|
/* Then loop through the current directory until the directory
|
||||||
* with the matching name is found.
|
* with the matching name is found. Or until all of the entries
|
||||||
|
* the directory have been examined.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
offset = dirinfo->rd_dir.fr_firstoffset;
|
offset = dirinfo->rd_dir.fr_firstoffset;
|
||||||
for (;;)
|
do
|
||||||
{
|
{
|
||||||
/* Convert the offset into sector + index */
|
/* Convert the offset into sector + index */
|
||||||
|
|
||||||
|
@ -249,7 +250,7 @@ static inline int romfs_searchdir(struct romfs_mountpt_s *rm,
|
||||||
|
|
||||||
offset = next;
|
offset = next;
|
||||||
}
|
}
|
||||||
while (next != 0)
|
while (next != 0);
|
||||||
|
|
||||||
/* There is nothing in this directoy with that name */
|
/* There is nothing in this directoy with that name */
|
||||||
|
|
||||||
|
@ -540,7 +541,6 @@ int romfs_finddirentry(struct romfs_mountpt_s *rm, struct romfs_dirinfo_s *dirin
|
||||||
|
|
||||||
/* Start with the first element after the root directory */
|
/* Start with the first element after the root directory */
|
||||||
|
|
||||||
dirinfo->rd_dir.fr_diroffset = 0;
|
|
||||||
dirinfo->rd_dir.fr_firstoffset = rm->rm_rootoffset;
|
dirinfo->rd_dir.fr_firstoffset = rm->rm_rootoffset;
|
||||||
dirinfo->rd_dir.fr_curroffset = rm->rm_rootoffset;
|
dirinfo->rd_dir.fr_curroffset = rm->rm_rootoffset;
|
||||||
dirinfo->rd_next = RFNEXT_DIRECTORY;
|
dirinfo->rd_next = RFNEXT_DIRECTORY;
|
||||||
|
@ -780,3 +780,52 @@ int romfs_parsefilename(struct romfs_mountpt_s *rm, uint32 offset, char *pname)
|
||||||
pname[namelen] = '\0';
|
pname[namelen] = '\0';
|
||||||
return OK;
|
return OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Name: romfs_datastart
|
||||||
|
*
|
||||||
|
* Desciption:
|
||||||
|
* Given the offset to a file header, return the offset to the start of
|
||||||
|
* the file data
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
uint32 romfs_datastart(struct romfs_mountpt_s *rm, uint32 offset)
|
||||||
|
{
|
||||||
|
uint32 sector;
|
||||||
|
uint16 ndx;
|
||||||
|
int ret;
|
||||||
|
|
||||||
|
/* Loop until the header size of obtained. */
|
||||||
|
|
||||||
|
offset += ROMFS_FHDR_NAME;
|
||||||
|
for (;;)
|
||||||
|
{
|
||||||
|
/* Convert the offset into sector + index */
|
||||||
|
|
||||||
|
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);
|
||||||
|
|
||||||
|
/* Is the name terminated in this 16-byte block */
|
||||||
|
|
||||||
|
if (rm->rm_buffer[ndx + 15] == '\0')
|
||||||
|
{
|
||||||
|
/* Yes.. then the data starts after this chunk */
|
||||||
|
|
||||||
|
return offset;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return ERROR; /* Won't get here */
|
||||||
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue