branches: Updating LibFAT to 1.0.13

This commit is contained in:
Cyan 2015-03-08 16:40:59 +00:00
parent 0cd2573062
commit 1fed6e83f2
10 changed files with 125 additions and 44 deletions

View File

@ -6,7 +6,7 @@ export TOPDIR := $(CURDIR)
export LIBFAT_MAJOR := 1 export LIBFAT_MAJOR := 1
export LIBFAT_MINOR := 0 export LIBFAT_MINOR := 0
export LIBFAT_PATCH := 10 export LIBFAT_PATCH := 13
export VERSTRING := $(LIBFAT_MAJOR).$(LIBFAT_MINOR).$(LIBFAT_PATCH) export VERSTRING := $(LIBFAT_MAJOR).$(LIBFAT_MINOR).$(LIBFAT_PATCH)

View File

@ -2,7 +2,7 @@
fat.h fat.h
Simple functionality for startup, mounting and unmounting of FAT-based devices. Simple functionality for startup, mounting and unmounting of FAT-based devices.
Copyright (c) 2006 - 2009 Copyright (c) 2006 - 2012
Michael "Chishm" Chisholm Michael "Chishm" Chisholm
Dave "WinterMute" Murphy Dave "WinterMute" Murphy
@ -36,6 +36,8 @@
extern "C" { extern "C" {
#endif #endif
#include "libfatversion.h"
// When compiling for NDS, make sure NDS is defined // When compiling for NDS, make sure NDS is defined
#ifndef NDS #ifndef NDS
#if defined ARM9 || defined ARM7 #if defined ARM9 || defined ARM7
@ -49,9 +51,9 @@ extern "C" {
# include <ogc/disc_io.h> # include <ogc/disc_io.h>
#else #else
# ifdef NDS # ifdef NDS
# include "nds/disc_io.h" # include <nds/disc_io.h>
# else # else
# include "disc_io.h" # include <disc_io.h>
# endif # endif
#endif #endif
@ -97,6 +99,22 @@ Get Volume Label
*/ */
extern void fatGetVolumeLabel (const char* name, char *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 #ifdef __cplusplus
} }
#endif #endif

View File

@ -3,8 +3,8 @@
#define _LIBFAT_MAJOR_ 1 #define _LIBFAT_MAJOR_ 1
#define _LIBFAT_MINOR_ 0 #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__ #endif // __LIBFATVERSION_H__

View File

@ -1 +1 @@
<Project name="libfat"><MagicFolder excludeFolders="CVS;.svn" filter="*.c;*.h" name="source" path="source\"><File path="bit_ops.h"></File><File path="cache.c"></File><File path="cache.h"></File><File path="common.h"></File><File path="directory.c"></File><File path="directory.h"></File><File path="disc.c"></File><File path="disc.h"></File><File path="fatdir.c"></File><File path="fatdir.h"></File><File path="fatfile.c"></File><File path="fatfile.h"></File><File path="fatfile_frag.c"></File><File path="fatfile_frag.h"></File><File path="filetime.c"></File><File path="filetime.h"></File><File path="file_allocation_table.c"></File><File path="file_allocation_table.h"></File><File path="libfat.c"></File><File path="lock.c"></File><File path="lock.h"></File><File path="mem_allocate.h"></File><File path="partition.c"></File><File path="partition.h"></File></MagicFolder><Folder name="nds"><Folder name="include"><File path="nds\include\fat.h"></File><File path="nds\include\nitrofs.h"></File></Folder><Folder name="source"><File path="nds\source\nitrofs.c"></File></Folder><File path="nds\Makefile"></File></Folder><Folder name="libogc"><Folder name="include"><File path="libogc\include\fat.h"></File></Folder><File path="libogc\Makefile"></File></Folder><Folder name="gba"><Folder name="include"><File path="gba\include\fat.h"></File></Folder><File path="gba\Makefile"></File></Folder><MagicFolder excludeFolders="CVS;.svn" filter="*.h" name="include" path="include\"><File path="fat.h"></File><File path="libfatversion.h"></File></MagicFolder><File path="Makefile"></File></Project> <Project name="libfat"><MagicFolder excludeFolders="CVS;.svn" filter="*.c;*.h" name="source" path="source\"><File path="bit_ops.h"></File><File path="cache.c"></File><File path="cache.h"></File><File path="common.h"></File><File path="directory.c"></File><File path="directory.h"></File><File path="disc.c"></File><File path="disc.h"></File><File path="fatdir.c"></File><File path="fatdir.h"></File><File path="fatfile.c"></File><File path="fatfile.h"></File><File path="fatfile_frag.c"></File><File path="fatfile_frag.h"></File><File path="filetime.c"></File><File path="filetime.h"></File><File path="file_allocation_table.c"></File><File path="file_allocation_table.h"></File><File path="libfat.c"></File><File path="lock.c"></File><File path="lock.h"></File><File path="mem2.h"></File><File path="mem_allocate.h"></File><File path="partition.c"></File><File path="partition.h"></File></MagicFolder><Folder name="libogc"><Folder name="include"><File path="libogc\include\fat.h"></File></Folder><File path="libogc\Makefile"></File></Folder><MagicFolder excludeFolders="CVS;.svn" filter="*.h" name="include" path="include\"><File path="fat.h"></File><File path="libfatversion.h"></File></MagicFolder><File path="Makefile"></File></Project>

View File

@ -1 +1 @@
<pd><ViewState><e p="libfat\include" x="false"></e><e p="libfat\libogc" x="false"></e><e p="libfat\nds" x="false"></e><e p="libfat" x="true"></e><e p="libfat\gba" x="false"></e><e p="libfat\source" x="false"></e></ViewState></pd> <pd><ViewState><e p="libfat" x="true"></e><e p="libfat\include" x="false"></e><e p="libfat\libogc" x="false"></e><e p="libfat\source" x="false"></e></ViewState></pd>

View File

@ -30,7 +30,7 @@ LIBDIR := $(TOPDIR)/libogc/lib
#--------------------------------------------------------------------------------- #---------------------------------------------------------------------------------
# options for code generation # options for code generation
#--------------------------------------------------------------------------------- #---------------------------------------------------------------------------------
CFLAGS = -g -O2 -Wall $(MACHDEP) $(INCLUDE) CFLAGS = -g -Os -Wall $(MACHDEP) $(INCLUDE)
CXXFLAGS = $(CFLAGS) CXXFLAGS = $(CFLAGS)
ASFLAGS := -g ASFLAGS := -g
@ -96,17 +96,19 @@ $(BUILD):
#--------------------------------------------------------------------------------- #---------------------------------------------------------------------------------
clean: clean:
@echo 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) all: $(CUBEBIN)
dist-bin: 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 @tar --exclude=.svn --exclude=*CVS* -cvjf $(TOPDIR)/distribute/$(VERSTRING)/libfat-ogc-$(VERSTRING).tar.bz2 include lib
install: install:
cp lib/wii/libfat.a $(DEVKITPRO)/libogc/lib/wii @cp lib/wii/libfat.a $(DEVKITPRO)/libogc/lib/wii
cp lib/cube/libfat.a $(DEVKITPRO)/libogc/lib/cube @cp lib/cube/libfat.a $(DEVKITPRO)/libogc/lib/cube
cp include/fat.h $(DEVKITPRO)/libogc/include @cp $(TOPDIR)/include/fat.h $(TOPDIR)/include/libfatversion.h $(DEVKITPRO)/libogc/include
#--------------------------------------------------------------------------------- #---------------------------------------------------------------------------------
else else

View File

@ -125,7 +125,7 @@ static size_t _FAT_directory_mbstoucs2 (ucs2_t* dst, const char* src, size_t len
int bytes; int bytes;
size_t count = 0; size_t count = 0;
while (count < len-1 && src != '\0') { while (count < len-1 && *src != '\0') {
bytes = mbrtowc (&tempChar, src, MB_CUR_MAX, &ps); bytes = mbrtowc (&tempChar, src, MB_CUR_MAX, &ps);
if (bytes > 0) { if (bytes > 0) {
*dst = (ucs2_t)tempChar; *dst = (ucs2_t)tempChar;
@ -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,6 +580,14 @@ bool _FAT_directory_entryFromPath (PARTITION* partition, DIR_ENTRY* entry, const
return false; return false;
} }
// 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 // Look for the directory within the path
foundFile = _FAT_directory_getFirstEntry (partition, entry, dirCluster); foundFile = _FAT_directory_getFirstEntry (partition, entry, dirCluster);
@ -613,6 +614,7 @@ bool _FAT_directory_entryFromPath (PARTITION* partition, DIR_ENTRY* entry, const
foundFile = _FAT_directory_getNextEntry (partition, entry); foundFile = _FAT_directory_getNextEntry (partition, entry);
} }
} }
}
if (!foundFile) { if (!foundFile) {
// Check that the search didn't get to the end of the directory // Check that the search didn't get to the end of the directory
@ -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) {

View File

@ -69,8 +69,53 @@ int FAT_getAttr(const char *file) {
} }
int FAT_setAttr(const char *file, int attr) { 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; return 0;
} }

View File

@ -30,6 +30,7 @@
#include <unistd.h> #include <unistd.h>
#include <string.h> #include <string.h>
#include <stdio.h> #include <stdio.h>
#include <sys/param.h>
#include "common.h" #include "common.h"
#include "partition.h" #include "partition.h"
@ -82,7 +83,8 @@ bool fatMount (const char* name, const DISC_INTERFACE* interface, sec_t startSec
return false; return false;
char devname[10]; char devname[10];
sprintf(devname, "%s:", name); strcpy(devname, name);
strcat(devname, ":");
if(FindDevice(devname) >= 0) if(FindDevice(devname) >= 0)
return true; return true;

View File

@ -429,3 +429,13 @@ void _FAT_partition_writeFSinfo(PARTITION * partition)
_FAT_disc_writeSectors (partition->disc, partition->fsInfoSector, 1, sectorBuffer); _FAT_disc_writeSectors (partition->disc, partition->fsInfoSector, 1, sectorBuffer);
_FAT_mem_free(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;
}