9
0
Fork 0

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:
patacongo 2008-09-11 21:51:41 +00:00
parent 110d333a5c
commit 7e73d17765
4 changed files with 64 additions and 17 deletions

View File

@ -116,8 +116,7 @@ struct fs_fatdir_s
struct fs_romfsdir_s
{
uint32 fr_diroffset; /* Offset to the directory entry */
uint32 fr_firstoffset; /* Offset to the first entry */
uint32 fr_firstoffset; /* Offset to the first entry in the directory */
uint32 fr_curroffset; /* Current offset into the directory contents */
};
#endif /* CONFIG_FS_ROMFS */

View File

@ -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) */
rf->rf_open = TRUE;
rf->rf_diroffset = dirinfo.rd_dir.fr_diroffset;
rf->rf_startoffset = dirinfo.rd_dir.fr_curroffset;
rf->rf_startoffset = romfs_datastart(rm, dirinfo.rd_dir.fr_curroffset);
rf->rf_size = dirinfo.rd_size;
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 readsize;
unsigned int nsectors;
uint32 offset;
size_t bytesleft;
off_t sector;
ubyte *userbuffer = (ubyte*)buffer;
@ -354,11 +354,6 @@ static ssize_t romfs_read(FAR struct file *filep, char *buffer, size_t buflen)
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
* error occurs.
*/
@ -366,6 +361,11 @@ static ssize_t romfs_read(FAR struct file *filep, char *buffer, size_t buflen)
readsize = 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;
/* 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;
readsize += bytesread;
buflen -= bytesread;
sectorndx = filep->f_pos & SEC_NDXMASK(rm);
}
romfs_semgive(rm);

View File

@ -153,8 +153,7 @@ struct romfs_file_s
{
struct romfs_file_s *rf_next; /* Retained in a singly linked list */
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 */
uint32 rf_startoffset; /* Offset to the start of the file data */
uint32 rf_size; /* Size of the file in bytes */
uint32 rf_cachesector; /* Current sector in the rf_buffer */
ubyte *rf_buffer; /* File sector buffer */
@ -213,6 +212,7 @@ EXTERN int romfs_parsedirentry(struct romfs_mountpt_s *rm,
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);
#undef EXTERN
#if defined(__cplusplus)

View File

@ -45,6 +45,7 @@
#include <string.h>
#include <assert.h>
#include <errno.h>
#include <assert.h>
#include <debug.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))
{
dirinfo->rd_dir.fr_diroffset = linkoffset;
dirinfo->rd_dir.fr_firstoffset = info;
dirinfo->rd_dir.fr_curroffset = info;
dirinfo->rd_size = 0;
@ -205,11 +205,12 @@ static inline int romfs_searchdir(struct romfs_mountpt_s *rm,
int ret;
/* 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;
for (;;)
do
{
/* Convert the offset into sector + index */
@ -249,7 +250,7 @@ static inline int romfs_searchdir(struct romfs_mountpt_s *rm,
offset = next;
}
while (next != 0)
while (next != 0);
/* 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 */
dirinfo->rd_dir.fr_diroffset = 0;
dirinfo->rd_dir.fr_firstoffset = rm->rm_rootoffset;
dirinfo->rd_dir.fr_curroffset = rm->rm_rootoffset;
dirinfo->rd_next = RFNEXT_DIRECTORY;
@ -780,3 +780,52 @@ int romfs_parsefilename(struct romfs_mountpt_s *rm, uint32 offset, char *pname)
pname[namelen] = '\0';
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 */
}