diff --git a/include/fs/fs.h b/include/fs/fs.h index 50ccf1fb64d..d35b6a6976f 100644 --- a/include/fs/fs.h +++ b/include/fs/fs.h @@ -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 diff --git a/subsys/fs/fs.c b/subsys/fs/fs.c index 6ec4bc59cde..fedec7c15ae 100644 --- a/subsys/fs/fs.c +++ b/subsys/fs/fs.c @@ -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; } diff --git a/tests/subsys/fs/littlefs/src/testfs_util.c b/tests/subsys/fs/littlefs/src/testfs_util.c index f21159e2e0f..9f1827a77f6 100644 --- a/tests/subsys/fs/littlefs/src/testfs_util.c +++ b/tests/subsys/fs/littlefs/src/testfs_util.c @@ -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) {