fix finding . and .. entries for root directory

This commit is contained in:
mtheall 2012-09-13 18:21:00 -05:00
parent 27d818367e
commit 2aaf2cfd6f

View File

@ -566,13 +566,6 @@ bool _FAT_directory_entryFromPath (PARTITION* partition, DIR_ENTRY* entry, const
dirCluster = partition->cwdCluster; dirCluster = partition->cwdCluster;
} }
// If the path is only specifying a directory in the form "."
// and this is the root directory, return it
if ((dirCluster == partition->rootDirCluster) && (strcmp(".", pathPosition) == 0)) {
_FAT_directory_getRootEntry (partition, entry);
found = true;
}
while (!found && !notFound) { while (!found && !notFound) {
// Get the name of the next required subdirectory within the path // Get the name of the next required subdirectory within the path
nextPathPosition = strchr (pathPosition, DIR_SEPARATOR); nextPathPosition = strchr (pathPosition, DIR_SEPARATOR);
@ -587,30 +580,39 @@ bool _FAT_directory_entryFromPath (PARTITION* partition, DIR_ENTRY* entry, const
return false; return false;
} }
// Look for the directory within the path // Check for "." or ".." when the dirCluster is root cluster
foundFile = _FAT_directory_getFirstEntry (partition, entry, dirCluster); // These entries do not exist, so we must fake it
if ((dirCluster == partition->rootDirCluster)
&& ((strncmp(".", pathPosition, dirnameLength) == 0)
|| (strncmp("..", pathPosition, dirnameLength) == 0))) {
foundFile = true;
_FAT_directory_getRootEntry(partition, entry);
} else {
// Look for the directory within the path
foundFile = _FAT_directory_getFirstEntry (partition, entry, dirCluster);
while (foundFile && !found && !notFound) { // It hasn't already found the file while (foundFile && !found && !notFound) { // It hasn't already found the file
// Check if the filename matches // Check if the filename matches
if ((dirnameLength == strnlen(entry->filename, MAX_FILENAME_LENGTH)) if ((dirnameLength == strnlen(entry->filename, MAX_FILENAME_LENGTH))
&& (_FAT_directory_mbsncasecmp(pathPosition, entry->filename, dirnameLength) == 0)) { && (_FAT_directory_mbsncasecmp(pathPosition, entry->filename, dirnameLength) == 0)) {
found = true; found = true;
} }
// Check if the alias matches // Check if the alias matches
_FAT_directory_entryGetAlias (entry->entryData, alias); _FAT_directory_entryGetAlias (entry->entryData, alias);
if ((dirnameLength == strnlen(alias, MAX_ALIAS_LENGTH)) if ((dirnameLength == strnlen(alias, MAX_ALIAS_LENGTH))
&& (strncasecmp(pathPosition, alias, dirnameLength) == 0)) { && (strncasecmp(pathPosition, alias, dirnameLength) == 0)) {
found = true; found = true;
} }
if (found && !(entry->entryData[DIR_ENTRY_attributes] & ATTRIB_DIR) && (nextPathPosition != NULL)) { 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 // Make sure that we aren't trying to follow a file instead of a directory in the path
found = false; found = false;
} }
if (!found) { if (!found) {
foundFile = _FAT_directory_getNextEntry (partition, entry); foundFile = _FAT_directory_getNextEntry (partition, entry);
}
} }
} }
@ -623,6 +625,8 @@ bool _FAT_directory_entryFromPath (PARTITION* partition, DIR_ENTRY* entry, const
found = true; found = true;
} else if (entry->entryData[DIR_ENTRY_attributes] & ATTRIB_DIR) { } else if (entry->entryData[DIR_ENTRY_attributes] & ATTRIB_DIR) {
dirCluster = _FAT_directory_entryGetCluster (partition, entry->entryData); dirCluster = _FAT_directory_entryGetCluster (partition, entry->entryData);
if (dirCluster == CLUSTER_ROOT)
dirCluster = partition->rootDirCluster;
pathPosition = nextPathPosition; pathPosition = nextPathPosition;
// Consume separator(s) // Consume separator(s)
while (pathPosition[0] == DIR_SEPARATOR) { while (pathPosition[0] == DIR_SEPARATOR) {