fs/romfs: always save linkoffset in romfs_nodeinfo_s
Signed-off-by: Jiuzhu Dong <dongjiuzhu1@xiaomi.com>
This commit is contained in:
parent
07bfa32e87
commit
bc43206920
@ -134,7 +134,7 @@ const struct mountpt_operations romfs_operations =
|
||||
static int romfs_open(FAR struct file *filep, FAR const char *relpath,
|
||||
int oflags, mode_t mode)
|
||||
{
|
||||
struct romfs_dirinfo_s dirinfo;
|
||||
struct romfs_nodeinfo_s nodeinfo;
|
||||
FAR struct romfs_mountpt_s *rm;
|
||||
FAR struct romfs_file_s *rf;
|
||||
int ret;
|
||||
@ -179,13 +179,9 @@ static int romfs_open(FAR struct file *filep, FAR const char *relpath,
|
||||
goto errout_with_semaphore;
|
||||
}
|
||||
|
||||
/* Initialize the directory info structure */
|
||||
|
||||
memset(&dirinfo, 0, sizeof(struct romfs_dirinfo_s));
|
||||
|
||||
/* Locate the directory entry for this path */
|
||||
|
||||
ret = romfs_finddirentry(rm, &dirinfo, relpath);
|
||||
ret = romfs_finddirentry(rm, &nodeinfo, relpath);
|
||||
if (ret < 0)
|
||||
{
|
||||
ferr("ERROR: Failed to find directory directory entry for '%s': %d\n",
|
||||
@ -201,7 +197,7 @@ static int romfs_open(FAR struct file *filep, FAR const char *relpath,
|
||||
* types. At present, it returns the ENXIO.
|
||||
*/
|
||||
|
||||
if (IS_DIRECTORY(dirinfo.rd_next))
|
||||
if (IS_DIRECTORY(nodeinfo.rn_next))
|
||||
{
|
||||
/* It is a directory */
|
||||
|
||||
@ -209,7 +205,7 @@ static int romfs_open(FAR struct file *filep, FAR const char *relpath,
|
||||
ferr("ERROR: '%s' is a directory\n", relpath);
|
||||
goto errout_with_semaphore;
|
||||
}
|
||||
else if (!IS_FILE(dirinfo.rd_next))
|
||||
else if (!IS_FILE(nodeinfo.rn_next))
|
||||
{
|
||||
/* ENXIO indicates "The named file is a character special or
|
||||
* block special file, and the device associated with this
|
||||
@ -240,13 +236,13 @@ static int romfs_open(FAR struct file *filep, FAR const char *relpath,
|
||||
* non-zero elements)
|
||||
*/
|
||||
|
||||
rf->rf_size = dirinfo.rd_size;
|
||||
rf->rf_type = (uint8_t)(dirinfo.rd_next & RFNEXT_ALLMODEMASK);
|
||||
rf->rf_size = nodeinfo.rn_size;
|
||||
rf->rf_type = (uint8_t)(nodeinfo.rn_next & RFNEXT_ALLMODEMASK);
|
||||
strcpy(rf->rf_path, relpath);
|
||||
|
||||
/* Get the start of the file data */
|
||||
|
||||
ret = romfs_datastart(rm, dirinfo.rd_dir.fr_curroffset,
|
||||
ret = romfs_datastart(rm, nodeinfo.rn_offset,
|
||||
&rf->rf_startoffset);
|
||||
if (ret < 0)
|
||||
{
|
||||
@ -399,9 +395,9 @@ static ssize_t romfs_read(FAR struct file *filep, FAR char *buffer,
|
||||
{
|
||||
/* 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);
|
||||
offset = rf->rf_startoffset + filep->f_pos;
|
||||
sector = SEC_NSECTORS(rm, offset);
|
||||
sectorndx = offset & SEC_NDXMASK(rm);
|
||||
|
||||
/* Check if the user has provided a buffer large enough to
|
||||
* hold one or more complete sectors -AND- the read is
|
||||
@ -426,7 +422,7 @@ static ssize_t romfs_read(FAR struct file *filep, FAR char *buffer,
|
||||
goto errout_with_semaphore;
|
||||
}
|
||||
|
||||
bytesread = nsectors * rm->rm_hwsectorsize;
|
||||
bytesread = nsectors * rm->rm_hwsectorsize;
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -490,8 +486,8 @@ static off_t romfs_seek(FAR struct file *filep, off_t offset, int whence)
|
||||
|
||||
/* Recover our private data from the struct file instance */
|
||||
|
||||
rf = filep->f_priv;
|
||||
rm = filep->f_inode->i_private;
|
||||
rf = filep->f_priv;
|
||||
rm = filep->f_inode->i_private;
|
||||
|
||||
DEBUGASSERT(rm != NULL);
|
||||
|
||||
@ -745,7 +741,7 @@ static int romfs_opendir(FAR struct inode *mountpt, FAR const char *relpath,
|
||||
FAR struct fs_dirent_s *dir)
|
||||
{
|
||||
FAR struct romfs_mountpt_s *rm;
|
||||
struct romfs_dirinfo_s dirinfo;
|
||||
struct romfs_nodeinfo_s nodeinfo;
|
||||
int ret;
|
||||
|
||||
finfo("relpath: '%s'\n", relpath);
|
||||
@ -775,7 +771,7 @@ static int romfs_opendir(FAR struct inode *mountpt, FAR const char *relpath,
|
||||
|
||||
/* Find the requested directory */
|
||||
|
||||
ret = romfs_finddirentry(rm, &dirinfo, relpath);
|
||||
ret = romfs_finddirentry(rm, &nodeinfo, relpath);
|
||||
if (ret < 0)
|
||||
{
|
||||
ferr("ERROR: Failed to find directory '%s': %d\n", relpath, ret);
|
||||
@ -784,7 +780,7 @@ static int romfs_opendir(FAR struct inode *mountpt, FAR const char *relpath,
|
||||
|
||||
/* Verify that it is some kind of directory */
|
||||
|
||||
if (!IS_DIRECTORY(dirinfo.rd_next))
|
||||
if (!IS_DIRECTORY(nodeinfo.rn_next))
|
||||
{
|
||||
/* The entry is not a directory */
|
||||
|
||||
@ -795,7 +791,8 @@ static int romfs_opendir(FAR struct inode *mountpt, FAR const char *relpath,
|
||||
|
||||
/* The entry is a directory */
|
||||
|
||||
memcpy(&dir->u.romfs, &dirinfo.rd_dir, sizeof(struct fs_romfsdir_s));
|
||||
dir->u.romfs.fr_firstoffset = nodeinfo.rn_offset;
|
||||
dir->u.romfs.fr_curroffset = nodeinfo.rn_offset;
|
||||
|
||||
errout_with_semaphore:
|
||||
romfs_semgive(rm);
|
||||
@ -1251,7 +1248,7 @@ static int romfs_stat(FAR struct inode *mountpt, FAR const char *relpath,
|
||||
FAR struct stat *buf)
|
||||
{
|
||||
FAR struct romfs_mountpt_s *rm;
|
||||
struct romfs_dirinfo_s dirinfo;
|
||||
struct romfs_nodeinfo_s nodeinfo;
|
||||
uint8_t type;
|
||||
int ret;
|
||||
|
||||
@ -1282,7 +1279,7 @@ static int romfs_stat(FAR struct inode *mountpt, FAR const char *relpath,
|
||||
|
||||
/* Find the directory entry corresponding to relpath. */
|
||||
|
||||
ret = romfs_finddirentry(rm, &dirinfo, relpath);
|
||||
ret = romfs_finddirentry(rm, &nodeinfo, relpath);
|
||||
|
||||
/* If nothing was found, then we fail with EEXIST */
|
||||
|
||||
@ -1294,8 +1291,8 @@ static int romfs_stat(FAR struct inode *mountpt, FAR const char *relpath,
|
||||
|
||||
/* Return information about the directory entry */
|
||||
|
||||
type = (uint8_t)(dirinfo.rd_next & RFNEXT_ALLMODEMASK);
|
||||
ret = romfs_stat_common(type, dirinfo.rd_size, rm->rm_hwsectorsize, buf);
|
||||
type = (uint8_t)(nodeinfo.rn_next & RFNEXT_ALLMODEMASK);
|
||||
ret = romfs_stat_common(type, nodeinfo.rn_size, rm->rm_hwsectorsize, buf);
|
||||
|
||||
errout_with_semaphore:
|
||||
romfs_semgive(rm);
|
||||
|
@ -158,19 +158,11 @@ struct romfs_file_s
|
||||
* walking a path
|
||||
*/
|
||||
|
||||
struct romfs_dirinfo_s
|
||||
struct romfs_nodeinfo_s
|
||||
{
|
||||
/* These values describe the directory containing the terminal
|
||||
* path component (of the terminal component itself if it is
|
||||
* a directory.
|
||||
*/
|
||||
|
||||
struct fs_romfsdir_s rd_dir; /* Describes directory. */
|
||||
|
||||
/* Values from the ROMFS file entry */
|
||||
|
||||
uint32_t rd_next; /* Offset of the next file header+flags */
|
||||
uint32_t rd_size; /* Size (if file) */
|
||||
uint32_t rn_offset; /* Offset of real file header */
|
||||
uint32_t rn_next; /* Offset of the next file header+flags */
|
||||
uint32_t rn_size; /* Size (if file) */
|
||||
};
|
||||
|
||||
/****************************************************************************
|
||||
@ -202,7 +194,7 @@ int romfs_fileconfigure(FAR struct romfs_mountpt_s *rm,
|
||||
FAR struct romfs_file_s *rf);
|
||||
int romfs_checkmount(FAR struct romfs_mountpt_s *rm);
|
||||
int romfs_finddirentry(FAR struct romfs_mountpt_s *rm,
|
||||
FAR struct romfs_dirinfo_s *dirinfo,
|
||||
FAR struct romfs_nodeinfo_s *nodeinfo,
|
||||
FAR const char *path);
|
||||
int romfs_parsedirentry(FAR struct romfs_mountpt_s *rm, uint32_t offset,
|
||||
FAR uint32_t *poffset, FAR uint32_t *pnext,
|
||||
|
@ -87,7 +87,7 @@ static uint32_t romfs_devread32(FAR struct romfs_mountpt_s *rm, int ndx)
|
||||
static inline int romfs_checkentry(FAR struct romfs_mountpt_s *rm,
|
||||
uint32_t offset,
|
||||
FAR const char *entryname, int entrylen,
|
||||
FAR struct romfs_dirinfo_s *dirinfo)
|
||||
FAR struct romfs_nodeinfo_s *nodeinfo)
|
||||
{
|
||||
char name[NAME_MAX + 1];
|
||||
uint32_t linkoffset;
|
||||
@ -132,17 +132,16 @@ static inline int romfs_checkentry(FAR struct romfs_mountpt_s *rm,
|
||||
|
||||
if (IS_DIRECTORY(next))
|
||||
{
|
||||
dirinfo->rd_dir.fr_firstoffset = info;
|
||||
dirinfo->rd_dir.fr_curroffset = info;
|
||||
dirinfo->rd_size = 0;
|
||||
nodeinfo->rn_offset = info;
|
||||
nodeinfo->rn_size = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
dirinfo->rd_dir.fr_curroffset = offset;
|
||||
dirinfo->rd_size = size;
|
||||
nodeinfo->rn_offset = linkoffset;
|
||||
nodeinfo->rn_size = size;
|
||||
}
|
||||
|
||||
dirinfo->rd_next = next;
|
||||
nodeinfo->rn_next = next;
|
||||
return OK;
|
||||
}
|
||||
}
|
||||
@ -266,13 +265,13 @@ static int romfs_followhardlinks(FAR struct romfs_mountpt_s *rm,
|
||||
*
|
||||
* Description:
|
||||
* This is part of the romfs_finddirentry log. Search the directory
|
||||
* beginning at dirinfo->fr_firstoffset for entryname.
|
||||
* beginning at nodeinfo->rn_offset for entryname.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
static inline int romfs_searchdir(FAR struct romfs_mountpt_s *rm,
|
||||
FAR const char *entryname, int entrylen,
|
||||
FAR struct romfs_dirinfo_s *dirinfo)
|
||||
FAR struct romfs_nodeinfo_s *nodeinfo)
|
||||
{
|
||||
uint32_t offset;
|
||||
uint32_t next;
|
||||
@ -284,7 +283,7 @@ static inline int romfs_searchdir(FAR struct romfs_mountpt_s *rm,
|
||||
* the directory have been examined.
|
||||
*/
|
||||
|
||||
offset = dirinfo->rd_dir.fr_firstoffset;
|
||||
offset = nodeinfo->rn_offset;
|
||||
do
|
||||
{
|
||||
/* Read the sector into memory (do this before calling
|
||||
@ -308,7 +307,7 @@ static inline int romfs_searchdir(FAR struct romfs_mountpt_s *rm,
|
||||
* name
|
||||
*/
|
||||
|
||||
ret = romfs_checkentry(rm, offset, entryname, entrylen, dirinfo);
|
||||
ret = romfs_checkentry(rm, offset, entryname, entrylen, nodeinfo);
|
||||
if (ret == OK)
|
||||
{
|
||||
/* Its a match! Return success */
|
||||
@ -525,7 +524,7 @@ int romfs_hwconfigure(FAR struct romfs_mountpt_s *rm)
|
||||
|
||||
/* Determine if block driver supports the XIP mode of operation */
|
||||
|
||||
rm->rm_cachesector = (uint32_t)-1;
|
||||
rm->rm_cachesector = (uint32_t)-1;
|
||||
|
||||
if (INODE_IS_MTD(inode))
|
||||
{
|
||||
@ -714,7 +713,7 @@ int romfs_checkmount(FAR struct romfs_mountpt_s *rm)
|
||||
****************************************************************************/
|
||||
|
||||
int romfs_finddirentry(FAR struct romfs_mountpt_s *rm,
|
||||
FAR struct romfs_dirinfo_s *dirinfo,
|
||||
FAR struct romfs_nodeinfo_s *nodeinfo,
|
||||
FAR const char *path)
|
||||
{
|
||||
FAR const char *entryname;
|
||||
@ -724,10 +723,9 @@ int romfs_finddirentry(FAR struct romfs_mountpt_s *rm,
|
||||
|
||||
/* Start with the first element after the root directory */
|
||||
|
||||
dirinfo->rd_dir.fr_firstoffset = rm->rm_rootoffset;
|
||||
dirinfo->rd_dir.fr_curroffset = rm->rm_rootoffset;
|
||||
dirinfo->rd_next = RFNEXT_DIRECTORY;
|
||||
dirinfo->rd_size = 0;
|
||||
nodeinfo->rn_offset = rm->rm_rootoffset;
|
||||
nodeinfo->rn_next = RFNEXT_DIRECTORY;
|
||||
nodeinfo->rn_size = 0;
|
||||
|
||||
/* The root directory is a special case */
|
||||
|
||||
@ -775,7 +773,7 @@ int romfs_finddirentry(FAR struct romfs_mountpt_s *rm,
|
||||
* matching name.
|
||||
*/
|
||||
|
||||
ret = romfs_searchdir(rm, entryname, entrylen, dirinfo);
|
||||
ret = romfs_searchdir(rm, entryname, entrylen, nodeinfo);
|
||||
if (ret < 0)
|
||||
{
|
||||
return ret;
|
||||
@ -794,7 +792,7 @@ int romfs_finddirentry(FAR struct romfs_mountpt_s *rm,
|
||||
* better have been a directory
|
||||
*/
|
||||
|
||||
if (!IS_DIRECTORY(dirinfo->rd_next))
|
||||
if (!IS_DIRECTORY(nodeinfo->rn_next))
|
||||
{
|
||||
return -ENOTDIR;
|
||||
}
|
||||
@ -957,15 +955,6 @@ int romfs_datastart(FAR struct romfs_mountpt_s *rm, uint32_t offset,
|
||||
FAR uint32_t *start)
|
||||
{
|
||||
int16_t ndx;
|
||||
int ret;
|
||||
|
||||
/* Traverse hardlinks as necessary to get to the real file header */
|
||||
|
||||
ret = romfs_followhardlinks(rm, offset, &offset);
|
||||
if (ret < 0)
|
||||
{
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* Loop until the header size is obtained. */
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user