Skip to content
This repository has been archived by the owner on Nov 11, 2024. It is now read-only.

ENOTDIR vs ENOENT for invalid path prefix #6

Open
FrankHB opened this issue Oct 6, 2015 · 0 comments
Open

ENOTDIR vs ENOENT for invalid path prefix #6

FrankHB opened this issue Oct 6, 2015 · 0 comments

Comments

@FrankHB
Copy link
Contributor

FrankHB commented Oct 6, 2015

Some POSIX functions (e.g. open, unlink, opendir, mkdir) requires setting errno to ENOTDIR rather than ENOENT when "a component of the path prefix names an existing file that is neither a directory nor a symbolic link to a directory". They are implemented by function _FAT_directory_entryFromPath in libfat, which does not provide right information to distinguish the accurate errors:

                if (found && !(entry->entryData[DIR_ENTRY_attributes] & ATTRIB_DIR) && (nextPathPosition != NULL)) {
                    // Make sure that we aren't trying to follow a file instead of a directory in the path
                    found = false;
                }

Note that the implementation like _FAT_open_r is not sufficient, because it only tests the last component (not prefix) of the path:

                if (!_FAT_directory_entryFromPath (partition, &dirEntry, path, pathEnd) ||
                    !_FAT_directory_isDirectory(&dirEntry)) {
                    _FAT_unlock(&partition->lock);
                    r->_errno = ENOTDIR;
                    return -1;
                }
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant