diff options
author | patacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3> | 2008-09-11 21:51:41 +0000 |
---|---|---|
committer | patacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3> | 2008-09-11 21:51:41 +0000 |
commit | 4f1ed7c159a1b7b5a9b584708253118a70ba99fa (patch) | |
tree | 485359f130d1b9161763bad00b3608c52b63eea6 | |
parent | bbc91813bdbcc6cb1a0db5a1a469c0a5c792ee3d (diff) | |
download | px4-nuttx-4f1ed7c159a1b7b5a9b584708253118a70ba99fa.tar.gz px4-nuttx-4f1ed7c159a1b7b5a9b584708253118a70ba99fa.tar.bz2 px4-nuttx-4f1ed7c159a1b7b5a9b584708253118a70ba99fa.zip |
ROMFS fixes discovered during testing
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@908 42af7a65-404d-4744-a932-0658087f49c3
-rw-r--r-- | nuttx/fs/fs_internal.h | 3 | ||||
-rw-r--r-- | nuttx/fs/romfs/fs_romfs.c | 15 | ||||
-rw-r--r-- | nuttx/fs/romfs/fs_romfs.h | 4 | ||||
-rw-r--r-- | nuttx/fs/romfs/fs_romfsutil.c | 59 |
4 files changed, 64 insertions, 17 deletions
diff --git a/nuttx/fs/fs_internal.h b/nuttx/fs/fs_internal.h index 3ebf3f210..1df37a6b5 100644 --- a/nuttx/fs/fs_internal.h +++ b/nuttx/fs/fs_internal.h @@ -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 */ diff --git a/nuttx/fs/romfs/fs_romfs.c b/nuttx/fs/romfs/fs_romfs.c index 55b86869f..8b1ecad09 100644 --- a/nuttx/fs/romfs/fs_romfs.c +++ b/nuttx/fs/romfs/fs_romfs.c @@ -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); diff --git a/nuttx/fs/romfs/fs_romfs.h b/nuttx/fs/romfs/fs_romfs.h index 8432c9bd0..607ca3f97 100644 --- a/nuttx/fs/romfs/fs_romfs.h +++ b/nuttx/fs/romfs/fs_romfs.h @@ -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) diff --git a/nuttx/fs/romfs/fs_romfsutil.c b/nuttx/fs/romfs/fs_romfsutil.c index 77d03b565..7b4f43b4b 100644 --- a/nuttx/fs/romfs/fs_romfsutil.c +++ b/nuttx/fs/romfs/fs_romfsutil.c @@ -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 */ +} + |