Skip to content
Permalink
Browse files

subsys/fs: remove ambiguity in readdir results

Existing file system implementations do not provide the special "."
(current) and ".." (parent) directory entries in the readdir results.
littlefs does.

Remove these entries in the abstraction layer.  This simplifies code in
higher level consumers that aren't prepared to see them.  Consumers like
FUSE that need them can put them back without having to worry about
conflicts.

Closes issue #17951

Signed-off-by: Peter A. Bigot <pab@pabigot.com>
  • Loading branch information...
pabigot authored and carlescufi committed Aug 2, 2019
1 parent 979fb85 commit a8b7a21524ceead6eb5fb42b9aef7b5278743ff8
Showing with 23 additions and 3 deletions.
  1. +6 −1 include/fs/fs.h
  2. +15 −1 subsys/fs/fs.c
  3. +2 −1 tests/subsys/fs/littlefs/src/testfs_util.c
@@ -362,7 +362,12 @@ int fs_opendir(struct fs_dir_t *zdp, const char *path);
/**
* @brief Directory read entry
*
* Reads directory entries of a open directory
* Reads directory entries of a open directory.
*
* @note: Most existing underlying file systems do not generate POSIX
* special directory entries "." or "..". For consistency the
* abstraction layer will remove these from lower layer results so
* higher layers see consistent results.
*
* @param zdp Pointer to the directory object
* @param entry Pointer to zfs_dirent structure to read the entry into
@@ -255,11 +255,25 @@ int fs_readdir(struct fs_dir_t *zdp, struct fs_dirent *entry)
int rc = -EINVAL;

if (zdp->mp->fs->readdir != NULL) {
rc = zdp->mp->fs->readdir(zdp, entry);
/* Loop until error or not special directory */
while (true) {
rc = zdp->mp->fs->readdir(zdp, entry);
if (rc < 0) {
break;
}
if (entry->type != FS_DIR_ENTRY_DIR) {
break;
}
if ((strcmp(entry->name, ".") != 0)
&& (strcmp(entry->name, "..") != 0)) {
break;
}
}
if (rc < 0) {
LOG_ERR("directory read error (%d)", rc);
}
}

return rc;
}

@@ -393,7 +393,8 @@ int testfs_bcmd_verify_layout(struct testfs_path *pp,
stat.size);

if (dotdir) {
/* ignore */
zassert_true(false,
"special directories observed");
} else if (cp != NULL) {
rc = check_layout_entry(pp, &stat, cp, ecp);
if (rc > 0) {

0 comments on commit a8b7a21

Please sign in to comment.
You can’t perform that action at this time.