From 2aaf2cfd6f03b8ca79558eee0d1af3a8e00067a5 Mon Sep 17 00:00:00 2001 From: mtheall Date: Thu, 13 Sep 2012 18:21:00 -0500 Subject: [PATCH 1/2] fix finding . and .. entries for root directory --- source/directory.c | 58 +++++++++++++++++++++++++--------------------- 1 file changed, 31 insertions(+), 27 deletions(-) diff --git a/source/directory.c b/source/directory.c index c09debe..801ae74 100644 --- a/source/directory.c +++ b/source/directory.c @@ -566,13 +566,6 @@ bool _FAT_directory_entryFromPath (PARTITION* partition, DIR_ENTRY* entry, const 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) { // Get the name of the next required subdirectory within the path nextPathPosition = strchr (pathPosition, DIR_SEPARATOR); @@ -587,30 +580,39 @@ bool _FAT_directory_entryFromPath (PARTITION* partition, DIR_ENTRY* entry, const return false; } - // Look for the directory within the path - foundFile = _FAT_directory_getFirstEntry (partition, entry, dirCluster); + // Check for "." or ".." when the dirCluster is root cluster + // 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 - // Check if the filename matches - if ((dirnameLength == strnlen(entry->filename, MAX_FILENAME_LENGTH)) - && (_FAT_directory_mbsncasecmp(pathPosition, entry->filename, dirnameLength) == 0)) { - found = true; - } + while (foundFile && !found && !notFound) { // It hasn't already found the file + // Check if the filename matches + if ((dirnameLength == strnlen(entry->filename, MAX_FILENAME_LENGTH)) + && (_FAT_directory_mbsncasecmp(pathPosition, entry->filename, dirnameLength) == 0)) { + found = true; + } - // Check if the alias matches - _FAT_directory_entryGetAlias (entry->entryData, alias); - if ((dirnameLength == strnlen(alias, MAX_ALIAS_LENGTH)) - && (strncasecmp(pathPosition, alias, dirnameLength) == 0)) { - found = true; - } + // Check if the alias matches + _FAT_directory_entryGetAlias (entry->entryData, alias); + if ((dirnameLength == strnlen(alias, MAX_ALIAS_LENGTH)) + && (strncasecmp(pathPosition, alias, dirnameLength) == 0)) { + found = true; + } - 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; - } + 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; + } - if (!found) { - foundFile = _FAT_directory_getNextEntry (partition, entry); + if (!found) { + foundFile = _FAT_directory_getNextEntry (partition, entry); + } } } @@ -623,6 +625,8 @@ bool _FAT_directory_entryFromPath (PARTITION* partition, DIR_ENTRY* entry, const found = true; } else if (entry->entryData[DIR_ENTRY_attributes] & ATTRIB_DIR) { dirCluster = _FAT_directory_entryGetCluster (partition, entry->entryData); + if (dirCluster == CLUSTER_ROOT) + dirCluster = partition->rootDirCluster; pathPosition = nextPathPosition; // Consume separator(s) while (pathPosition[0] == DIR_SEPARATOR) { From 8ae46ee04fa42b91b7c7169e4a253be2a1ab204b Mon Sep 17 00:00:00 2001 From: mtheall Date: Fri, 14 Sep 2012 16:48:11 -0500 Subject: [PATCH 2/2] Add hidden interface to support FeOS implementation of multiple cwd. This interface grabs the pointer to the cwd cluster. This interface is hidden because it can be very easily used incorrectly. Modifying the cwd cluster value may cause unexpected results, so use at your own risk, which includes a corrupted storage medium. --- include/fat.h | 1 + source/partition.c | 10 ++++++++++ 2 files changed, 11 insertions(+) diff --git a/include/fat.h b/include/fat.h index 32da817..03e83a2 100644 --- a/include/fat.h +++ b/include/fat.h @@ -113,6 +113,7 @@ Methods to modify DOS File Attributes int FAT_getAttr(const char *file); int FAT_setAttr(const char *file, int attr ); +#define LIBFAT_FEOS_MULTICWD #ifdef __cplusplus } diff --git a/source/partition.c b/source/partition.c index 9d22041..108776a 100644 --- a/source/partition.c +++ b/source/partition.c @@ -429,3 +429,13 @@ void _FAT_partition_writeFSinfo(PARTITION * partition) _FAT_disc_writeSectors (partition->disc, partition->fsInfoSector, 1, sectorBuffer); _FAT_mem_free(sectorBuffer); } + +uint32_t* _FAT_getCwdClusterPtr(const char* name) { + PARTITION *partition = _FAT_partition_getPartitionFromPath(name); + + if (!partition) { + return NULL; + } + + return &partition->cwdCluster; +}