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>
This commit is contained in:
parent
979fb85d50
commit
a8b7a21524
3 changed files with 23 additions and 3 deletions
|
@ -362,7 +362,12 @@ int fs_opendir(struct fs_dir_t *zdp, const char *path);
|
||||||
/**
|
/**
|
||||||
* @brief Directory read entry
|
* @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 zdp Pointer to the directory object
|
||||||
* @param entry Pointer to zfs_dirent structure to read the entry into
|
* @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;
|
int rc = -EINVAL;
|
||||||
|
|
||||||
if (zdp->mp->fs->readdir != NULL) {
|
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) {
|
if (rc < 0) {
|
||||||
LOG_ERR("directory read error (%d)", rc);
|
LOG_ERR("directory read error (%d)", rc);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -393,7 +393,8 @@ int testfs_bcmd_verify_layout(struct testfs_path *pp,
|
||||||
stat.size);
|
stat.size);
|
||||||
|
|
||||||
if (dotdir) {
|
if (dotdir) {
|
||||||
/* ignore */
|
zassert_true(false,
|
||||||
|
"special directories observed");
|
||||||
} else if (cp != NULL) {
|
} else if (cp != NULL) {
|
||||||
rc = check_layout_entry(pp, &stat, cp, ecp);
|
rc = check_layout_entry(pp, &stat, cp, ecp);
|
||||||
if (rc > 0) {
|
if (rc > 0) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue