Correct a problem that was causing an apparent directory to be reported as a file instead of a directory by opendir.

This happened after adding these three new procfs entries:

  fs/block
  fs/mount
  fs/usage

Of course, there is no directory fs in this case, only three files that have fs/ in their relative pathnames.  The logic was detecting that fs was the name of the enty to report, but it was then declaring that fs was a file (because fs/block is of type file).

This was fixed by adding a check for matching lenghts.  i.e., if strlen(fs) != strlen(fs/block), then report fs as a directory instead of a file.
This commit is contained in:
Gregory Nutt 2017-10-26 16:30:59 -06:00
parent 1ed816de4b
commit ea13e24392
1 changed files with 7 additions and 1 deletions

View File

@ -787,7 +787,13 @@ static int procfs_readdir(struct inode *mountpt, struct fs_dirent_s *dir)
strncpy(dir->fd_dir.d_name, name, level0->lastlen);
dir->fd_dir.d_name[level0->lastlen] = '\0';
if (entry->type == PROCFS_DIR_TYPE)
/* If the entry is a directory type OR if the reported name is
* only a sub-string of the entry (meaning that it contains
* '/'), then report this entry as a directory.
*/
if (entry->type == PROCFS_DIR_TYPE ||
level0->lastlen != strlen(name))
{
dir->fd_dir.d_type = DTYPE_DIRECTORY;
}