diff --git a/libcustomfat/Makefile b/libcustomfat/Makefile index d909ca3b..d68f3bc7 100644 --- a/libcustomfat/Makefile +++ b/libcustomfat/Makefile @@ -6,7 +6,7 @@ export TOPDIR := $(CURDIR) export LIBFAT_MAJOR := 1 export LIBFAT_MINOR := 0 -export LIBFAT_PATCH := 10 +export LIBFAT_PATCH := 13 export VERSTRING := $(LIBFAT_MAJOR).$(LIBFAT_MINOR).$(LIBFAT_PATCH) diff --git a/libcustomfat/include/fat.h b/libcustomfat/include/fat.h index b0ffc13a..03e83a21 100644 --- a/libcustomfat/include/fat.h +++ b/libcustomfat/include/fat.h @@ -2,7 +2,7 @@ fat.h Simple functionality for startup, mounting and unmounting of FAT-based devices. - Copyright (c) 2006 - 2009 + Copyright (c) 2006 - 2012 Michael "Chishm" Chisholm Dave "WinterMute" Murphy @@ -36,6 +36,8 @@ extern "C" { #endif +#include "libfatversion.h" + // When compiling for NDS, make sure NDS is defined #ifndef NDS #if defined ARM9 || defined ARM7 @@ -49,9 +51,9 @@ extern "C" { # include #else # ifdef NDS -# include "nds/disc_io.h" +# include # else -# include "disc_io.h" +# include # endif #endif @@ -97,6 +99,22 @@ Get Volume Label */ extern void fatGetVolumeLabel (const char* name, char *label); +// File attributes +#define ATTR_ARCHIVE 0x20 // Archive +#define ATTR_DIRECTORY 0x10 // Directory +#define ATTR_VOLUME 0x08 // Volume +#define ATTR_SYSTEM 0x04 // System +#define ATTR_HIDDEN 0x02 // Hidden +#define ATTR_READONLY 0x01 // Read only + +/* +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 } #endif diff --git a/libcustomfat/include/libfatversion.h b/libcustomfat/include/libfatversion.h index 82c3187b..67a43e59 100644 --- a/libcustomfat/include/libfatversion.h +++ b/libcustomfat/include/libfatversion.h @@ -3,8 +3,8 @@ #define _LIBFAT_MAJOR_ 1 #define _LIBFAT_MINOR_ 0 -#define _LIBFAT_PATCH_ 10 +#define _LIBFAT_PATCH_ 13 -#define _LIBFAT_STRING "libFAT Release 1.0.10" +#define _LIBFAT_STRING "libFAT Release 1.0.13" #endif // __LIBFATVERSION_H__ diff --git a/libcustomfat/libfat.pnproj b/libcustomfat/libfat.pnproj index 9b35658d..38752445 100644 --- a/libcustomfat/libfat.pnproj +++ b/libcustomfat/libfat.pnproj @@ -1 +1 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/libcustomfat/libfat.pnps b/libcustomfat/libfat.pnps index bb191eba..1a471630 100644 --- a/libcustomfat/libfat.pnps +++ b/libcustomfat/libfat.pnps @@ -1 +1 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/libcustomfat/libogc/Makefile b/libcustomfat/libogc/Makefile index 30a396b8..ded05d21 100644 --- a/libcustomfat/libogc/Makefile +++ b/libcustomfat/libogc/Makefile @@ -30,7 +30,7 @@ LIBDIR := $(TOPDIR)/libogc/lib #--------------------------------------------------------------------------------- # options for code generation #--------------------------------------------------------------------------------- -CFLAGS = -g -O2 -Wall $(MACHDEP) $(INCLUDE) +CFLAGS = -g -Os -Wall $(MACHDEP) $(INCLUDE) CXXFLAGS = $(CFLAGS) ASFLAGS := -g @@ -96,17 +96,19 @@ $(BUILD): #--------------------------------------------------------------------------------- clean: @echo clean ... - @rm -fr wii_debug wii_release cube_debug cube_release $(LIBDIR) + @rm -fr wii_debug wii_release cube_debug cube_release $(LIBDIR) include all: $(CUBEBIN) dist-bin: + @mkdir -p include + @cp $(TOPDIR)/include/fat.h $(TOPDIR)/include/libfatversion.h include @tar --exclude=.svn --exclude=*CVS* -cvjf $(TOPDIR)/distribute/$(VERSTRING)/libfat-ogc-$(VERSTRING).tar.bz2 include lib install: - cp lib/wii/libfat.a $(DEVKITPRO)/libogc/lib/wii - cp lib/cube/libfat.a $(DEVKITPRO)/libogc/lib/cube - cp include/fat.h $(DEVKITPRO)/libogc/include + @cp lib/wii/libfat.a $(DEVKITPRO)/libogc/lib/wii + @cp lib/cube/libfat.a $(DEVKITPRO)/libogc/lib/cube + @cp $(TOPDIR)/include/fat.h $(TOPDIR)/include/libfatversion.h $(DEVKITPRO)/libogc/include #--------------------------------------------------------------------------------- else diff --git a/libcustomfat/source/directory.c b/libcustomfat/source/directory.c index c09debe6..69771b79 100644 --- a/libcustomfat/source/directory.c +++ b/libcustomfat/source/directory.c @@ -125,7 +125,7 @@ static size_t _FAT_directory_mbstoucs2 (ucs2_t* dst, const char* src, size_t len int bytes; size_t count = 0; - while (count < len-1 && src != '\0') { + while (count < len-1 && *src != '\0') { bytes = mbrtowc (&tempChar, src, MB_CUR_MAX, &ps); if (bytes > 0) { *dst = (ucs2_t)tempChar; @@ -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) { diff --git a/libcustomfat/source/fatfile.c b/libcustomfat/source/fatfile.c index f1e6d43e..99d0e767 100644 --- a/libcustomfat/source/fatfile.c +++ b/libcustomfat/source/fatfile.c @@ -69,9 +69,54 @@ int FAT_getAttr(const char *file) { } int FAT_setAttr(const char *file, int attr) { - DIR_ENTRY dirEntry; - if (!_FAT_findEntry(file,&dirEntry)) return -1; + + // Defines... + DIR_ENTRY_POSITION entryEnd; + PARTITION *partition = NULL; + DIR_ENTRY* dirEntry = NULL; + + // Get Partition + partition = _FAT_partition_getPartitionFromPath( file ); + + // Check Partition + if( !partition ) + return -1; + // Move the path pointer to the start of the actual path + if (strchr (file, ':') != NULL) + file = strchr (file, ':') + 1; + if (strchr (file, ':') != NULL) + return -1; + + // Get DIR_ENTRY + if( !_FAT_directory_entryFromPath (partition, dirEntry, file, NULL) ) + return -1; + + // Get Entry-End + entryEnd = dirEntry->dataEnd; + + // Lock Partition + _FAT_lock(&partition->lock); + + + // Write Data + _FAT_cache_writePartialSector ( + partition->cache // Cache to write + , &attr // Value to be written + , _FAT_fat_clusterToSector( partition , entryEnd.cluster ) + entryEnd.sector // cluster + , entryEnd.offset * DIR_ENTRY_DATA_SIZE + DIR_ENTRY_attributes // offset + , 1 // Size in bytes + ); + + // Flush any sectors in the disc cache + if ( !_FAT_cache_flush( partition->cache ) ) { + _FAT_unlock(&partition->lock); // Unlock Partition + return -1; + } + + // Unlock Partition + _FAT_unlock(&partition->lock); + return 0; } diff --git a/libcustomfat/source/libfat.c b/libcustomfat/source/libfat.c index 9f8dd014..aabb3ad6 100644 --- a/libcustomfat/source/libfat.c +++ b/libcustomfat/source/libfat.c @@ -30,6 +30,7 @@ #include #include #include +#include #include "common.h" #include "partition.h" @@ -82,7 +83,8 @@ bool fatMount (const char* name, const DISC_INTERFACE* interface, sec_t startSec return false; char devname[10]; - sprintf(devname, "%s:", name); + strcpy(devname, name); + strcat(devname, ":"); if(FindDevice(devname) >= 0) return true; diff --git a/libcustomfat/source/partition.c b/libcustomfat/source/partition.c index 9d220413..108776a6 100644 --- a/libcustomfat/source/partition.c +++ b/libcustomfat/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; +}