fs/romfs: fix bug about test:examples/romfs

Mounting ROMFS filesystem at target=/usr/local/share with source=/dev/ram1
Traversing directory: /usr/local/share
  DIRECTORY: /usr/local/share/adir/
Traversing directory: /usr/local/share/adir
  FILE: /usr/local/share/adir/anotherfile.txt/
  DIRECTORY: /usr/local/share/adir/subdir/
Traversing directory: /usr/local/share/adir/subdir
  FILE: /usr/local/share/adir/subdir/subdirfile.txt/
Continuing directory: /usr/local/share/adir
  FILE: /usr/local/share/adir/yafile.txt/
Continuing directory: /usr/local/share
  FILE: /usr/local/share/afile.txt/
  FILE: /usr/local/share/hfile/
ERROR: ldir never found
Finished with  1 errors

Signed-off-by: Jiuzhu Dong <dongjiuzhu1@xiaomi.com>
This commit is contained in:
Jiuzhu Dong 2022-03-10 21:43:51 +08:00 committed by Petro Karashchenko
parent 0d365f6fb9
commit a721bc8830

View File

@ -108,12 +108,6 @@ static inline int romfs_checkentry(FAR struct romfs_mountpt_s *rm,
return ret;
}
/* Now we are pointing to the real entry of interest. Is it a
* directory? Or a file?
*/
if (IS_DIRECTORY(next) || IS_FILE(next))
{
/* Get the name of the directory entry. */
ret = romfs_parsefilename(rm, offset, name);
@ -127,8 +121,8 @@ static inline int romfs_checkentry(FAR struct romfs_mountpt_s *rm,
* on entryname (there is a terminator on name, however)
*/
if (memcmp(entryname, name, entrylen) == 0 &&
strlen(name) == entrylen)
if (strlen(name) == entrylen &&
memcmp(entryname, name, entrylen) == 0)
{
/* Found it -- save the component info and return success */
@ -146,7 +140,6 @@ static inline int romfs_checkentry(FAR struct romfs_mountpt_s *rm,
nodeinfo->rn_next = next;
return OK;
}
}
/* The entry is not a directory or it does not have the matching name */
@ -321,7 +314,7 @@ static inline int romfs_searchdir(FAR struct romfs_mountpt_s *rm,
FAR struct romfs_nodeinfo_s **cnodeinfo;
cnodeinfo = bsearch(entryname, nodeinfo->rn_child, nodeinfo->rn_count,
sizeof(FAR struct romfs_nodeinfo_s *),
sizeof(struct romfs_nodeinfo_s *),
romfs_nodeinfo_search);
if (cnodeinfo)
{
@ -436,12 +429,6 @@ static int romfs_cachenode(FAR struct romfs_mountpt_s *rm,
return ret;
}
/* Now we are pointing to the real entry of interest. Is it a
* directory? Or a file?
*/
if (IS_DIRECTORY(next) || IS_FILE(next))
{
ret = romfs_parsefilename(rm, offset, childname);
if (ret < 0)
{
@ -456,7 +443,7 @@ static int romfs_cachenode(FAR struct romfs_mountpt_s *rm,
tmp = kmm_realloc(nodeinfo->rn_child,
(num + NODEINFO_NINCR) *
sizeof(FAR struct romfs_nodeinfo_s *));
sizeof(struct romfs_nodeinfo_s *));
if (tmp == NULL)
{
return -ENOMEM;
@ -464,7 +451,7 @@ static int romfs_cachenode(FAR struct romfs_mountpt_s *rm,
nodeinfo->rn_child = tmp;
memset(nodeinfo->rn_child + num, 0, NODEINFO_NINCR *
sizeof(FAR struct romfs_nodeinfo_s *));
sizeof(struct romfs_nodeinfo_s *));
num += NODEINFO_NINCR;
}
@ -482,7 +469,6 @@ static int romfs_cachenode(FAR struct romfs_mountpt_s *rm,
return ret;
}
}
}
next &= RFNEXT_OFFSETMASK;
offset = next;
@ -492,7 +478,7 @@ static int romfs_cachenode(FAR struct romfs_mountpt_s *rm,
if (nodeinfo->rn_count > 1)
{
qsort(nodeinfo->rn_child, nodeinfo->rn_count,
sizeof(FAR struct romfs_nodeinfo_s *),
sizeof(struct romfs_nodeinfo_s *),
romfs_nodeinfo_compare);
}