From ea13e24392fc6b052785c1d3737cc4f63d20ab37 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Thu, 26 Oct 2017 16:30:59 -0600 Subject: [PATCH] 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. --- fs/procfs/fs_procfs.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/fs/procfs/fs_procfs.c b/fs/procfs/fs_procfs.c index 5ba4cfb3da..8fd3f821d6 100644 --- a/fs/procfs/fs_procfs.c +++ b/fs/procfs/fs_procfs.c @@ -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; }