From 0f945247dc14f2880cc548fa32a8275851df5bd7 Mon Sep 17 00:00:00 2001 From: dimok321 <15055714+dimok789@users.noreply.github.com> Date: Fri, 17 Sep 2010 23:28:01 +0000 Subject: [PATCH] *Revert of libfat it causes crashes for most people and doesn't really work. We will deal with it later. For now the old one is good. *Removed a few compile flags which were duplicated. Changed to optimization Os. --- HBC/META.XML | 4 +- Makefile | 3 +- source/libfat/bit_ops.h | 6 +-- source/libfat/common.h | 53 +++++--------------- source/libfat/directory.c | 46 +----------------- source/libfat/directory.h | 19 +++----- source/libfat/{fat_disc.c => disc_fat.c} | 50 +++---------------- source/libfat/fat.h | 32 ++---------- source/libfat/fat_cache.c | 22 ++++----- source/libfat/fatdir.c | 2 +- source/libfat/fatdir.h | 10 ++-- source/libfat/fatfile.c | 2 +- source/libfat/file_allocation_table.h | 12 ++--- source/libfat/filetime.h | 6 +-- source/libfat/libfat.c | 62 ++++-------------------- source/libfat/lock.h | 4 +- source/libfat/mem_allocate.h | 7 +-- source/libfat/partition.c | 10 +--- source/libfat/partition.h | 11 ++--- 19 files changed, 84 insertions(+), 277 deletions(-) rename source/libfat/{fat_disc.c => disc_fat.c} (73%) diff --git a/HBC/META.XML b/HBC/META.XML index 29ed8b3a..9d8c76f4 100644 --- a/HBC/META.XML +++ b/HBC/META.XML @@ -2,8 +2,8 @@ USB Loader GX USB Loader GX Team - 1.0 r947 - 201009171621 + 1.0 r948 + 201009172243 Loads games from USB-devices USB Loader GX is a libwiigui based USB iso loader with a wii-like GUI. You can install games to your HDDs and boot them with shorter loading times. The interactive GUI is completely controllable with WiiMote, Classic Controller or GC Controller. diff --git a/Makefile b/Makefile index 1982c83e..36403e3a 100644 --- a/Makefile +++ b/Makefile @@ -55,8 +55,7 @@ INCLUDES := source # options for code generation #--------------------------------------------------------------------------------- -CFLAGS = -ffast-math -g -O3 -pipe -mrvl -mcpu=750 -meabi -mhard-float -Wall $(MACHDEP) $(INCLUDE) -DHAVE_CONFIG_H -DGEKKO \ - -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE +CFLAGS = -g -Os -Wall $(MACHDEP) $(INCLUDE) -DHAVE_CONFIG_H CXXFLAGS = -Xassembler -aln=$@.lst $(CFLAGS) LDFLAGS = -g $(MACHDEP) -Wl,-Map,$(notdir $@).map,--section-start,.init=0x80B00000,-wrap,malloc,-wrap,free,-wrap,memalign,-wrap,calloc,-wrap,realloc,-wrap,malloc_usable_size -include $(PROJECTDIR)/Make.config diff --git a/source/libfat/bit_ops.h b/source/libfat/bit_ops.h index 762be0b3..8a5fb3e1 100644 --- a/source/libfat/bit_ops.h +++ b/source/libfat/bit_ops.h @@ -3,7 +3,7 @@ Functions for dealing with conversion of data between types Copyright (c) 2006 Michael "Chishm" Chisholm - + Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: @@ -26,8 +26,8 @@ EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef _BIT_OPS_H -#define _BIT_OPS_H +#ifndef __BIT_OPS_H +#define __BIT_OPS_H #include diff --git a/source/libfat/common.h b/source/libfat/common.h index 98845e05..85d15db9 100644 --- a/source/libfat/common.h +++ b/source/libfat/common.h @@ -3,7 +3,7 @@ Common definitions and included files for the FATlib Copyright (c) 2006 Michael "Chishm" Chisholm - + Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: @@ -26,54 +26,23 @@ EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef _COMMON_H -#define _COMMON_H +#ifndef __COMMON_H +#define __COMMON_H #define BYTES_PER_READ 512 +#include "fat.h" #include #include -#include "libfat/fat.h" -// When compiling for NDS, make sure NDS is defined -#ifndef NDS - #if defined ARM9 || defined ARM7 - #define NDS - #endif -#endif // Platform specific includes -#if defined(__gamecube__) || defined (__wii__) - #include - #include - #include -#elif defined(NDS) - #include - #include - #include -#elif defined(GBA) - #include - #include -#endif - +#include +#include +#include // Platform specific options -#if defined (__wii__) - #define DEFAULT_CACHE_PAGES 4 - #define DEFAULT_SECTORS_PAGE 64 - #define USE_LWP_LOCK - #define USE_RTC_TIME -#elif defined (__gamecube__) - #define DEFAULT_CACHE_PAGES 4 - #define DEFAULT_SECTORS_PAGE 64 - #define USE_LWP_LOCK - #define USE_RTC_TIME -#elif defined (NDS) - #define DEFAULT_CACHE_PAGES 4 - #define DEFAULT_SECTORS_PAGE 8 - #define USE_RTC_TIME -#elif defined (GBA) - #define DEFAULT_CACHE_PAGES 2 - #define DEFAULT_SECTORS_PAGE 8 - #define LIMIT_SECTORS 128 -#endif +#define DEFAULT_CACHE_PAGES 4 +#define DEFAULT_SECTORS_PAGE 64 +#define USE_LWP_LOCK +#define USE_RTC_TIME #endif // _COMMON_H diff --git a/source/libfat/directory.c b/source/libfat/directory.c index 0e7b5ede..279a361d 100644 --- a/source/libfat/directory.c +++ b/source/libfat/directory.c @@ -329,8 +329,7 @@ bool _FAT_directory_getNextEntry (PARTITION* partition, DIR_ENTRY* entry) { } lfn[lfnPos] = '\0'; // Set end of lfn to null character lfnChkSum = entryData[LFN_offset_checkSum]; - } - if (lfnChkSum != entryData[LFN_offset_checkSum]) { + } if (lfnChkSum != entryData[LFN_offset_checkSum]) { lfnExists = false; } if (lfnExists) { @@ -418,49 +417,6 @@ bool _FAT_directory_getRootEntry (PARTITION* partition, DIR_ENTRY* entry) { return true; } -bool _FAT_directory_getVolumeLabel (PARTITION* partition, char *label) { - DIR_ENTRY entry; - DIR_ENTRY_POSITION entryEnd; - uint8_t entryData[DIR_ENTRY_DATA_SIZE]; - int i; - bool end; - - _FAT_directory_getRootEntry(partition, &entry); - - entryEnd = entry.dataEnd; - - // Make sure we are using the correct root directory, in case of FAT32 - if (entryEnd.cluster == FAT16_ROOT_DIR_CLUSTER) { - entryEnd.cluster = partition->rootDirCluster; - } - - label[0]='\0'; - label[11]='\0'; - end = false; - //this entry should be among the first 3 entries in the root directory table, if not, then system can have trouble displaying the right volume label - while(!end) { - if (_FAT_directory_incrementDirEntryPosition (partition, &entryEnd, false) == false) { - end = true; - } - - if(!_FAT_cache_readPartialSector (partition->cache, entryData, - _FAT_fat_clusterToSector(partition, entryEnd.cluster) + entryEnd.sector, - entryEnd.offset * DIR_ENTRY_DATA_SIZE, DIR_ENTRY_DATA_SIZE)) - { //error reading - return false; - } - if (entryData[DIR_ENTRY_attributes] == ATTRIB_VOL && entryData[0] != DIR_ENTRY_FREE) { - for (i = 0; i < 11; i++) { - label[i] = entryData[DIR_ENTRY_name + i]; - } - return true; - } else if (entryData[0] == DIR_ENTRY_LAST) { - end = true; - } - } - return false; -} - bool _FAT_directory_entryFromPosition (PARTITION* partition, DIR_ENTRY* entry) { DIR_ENTRY_POSITION entryStart = entry->dataStart; DIR_ENTRY_POSITION entryEnd = entry->dataEnd; diff --git a/source/libfat/directory.h b/source/libfat/directory.h index 93429217..02bd82ff 100644 --- a/source/libfat/directory.h +++ b/source/libfat/directory.h @@ -4,7 +4,7 @@ a FAT partition Copyright (c) 2006 Michael "Chishm" Chisholm - + Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: @@ -27,8 +27,8 @@ EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef _DIRECTORY_H -#define _DIRECTORY_H +#ifndef __DIRECTORY_H +#define __DIRECTORY_H #include @@ -132,7 +132,7 @@ Returns true on success, false on failure */ bool _FAT_directory_entryFromPath (PARTITION* partition, DIR_ENTRY* entry, const char* path, const char* pathEnd); -/* +/* Changes the current directory to the one specified by path Returns true on success, false on failure */ @@ -156,10 +156,10 @@ bool _FAT_directory_addEntry (PARTITION* partition, DIR_ENTRY* entry, uint32_t d /* Get the start cluster of a file from it's entry data */ -uint32_t _FAT_directory_entryGetCluster (PARTITION* partition, const uint8_t* entryData); +uint32_t _FAT_directory_entryGetCluster (PARTITION* partition, const uint8_t* entryData); -/* -Fill in the file name and entry data of DIR_ENTRY* entry. +/* +Fill in the file name and entry data of DIR_ENTRY* entry. Assumes that the entry's dataStart and dataEnd are correct Returns true on success, false on failure */ @@ -170,9 +170,4 @@ Fill in a stat struct based on a file entry */ void _FAT_directory_entryStat (PARTITION* partition, DIR_ENTRY* entry, struct stat *st); -/* -Get volume label -*/ -bool _FAT_directory_getVolumeLabel (PARTITION* partition, char *label); - #endif // _DIRECTORY_H diff --git a/source/libfat/fat_disc.c b/source/libfat/disc_fat.c similarity index 73% rename from source/libfat/fat_disc.c rename to source/libfat/disc_fat.c index 1fac0ed9..c17ca4c5 100644 --- a/source/libfat/fat_disc.c +++ b/source/libfat/disc_fat.c @@ -2,9 +2,9 @@ disc.c Interface to the low level disc functions. Used by the higher level file system code. - + Copyright (c) 2008 Michael "Chishm" Chisholm - + Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: @@ -27,7 +27,7 @@ EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#include "disc.h" +#include "disc_fat.h" /* The list of interfaces consists of a series of name/interface pairs. @@ -39,16 +39,15 @@ The list is terminated by a NULL/NULL entry. */ /* ====================== Wii ====================== */ -#if defined (__wii__) #include -#include +#include "usbloader/usbstorage2.h" #include static const DISC_INTERFACE* get_io_wiisd (void) { return &__io_wiisd; } static const DISC_INTERFACE* get_io_usbstorage (void) { - return &__io_usbstorage; + return &__io_usbstorage2; } static const DISC_INTERFACE* get_io_gcsda (void) { @@ -64,42 +63,5 @@ const INTERFACE_ID _FAT_disc_interfaces[] = { {"carda", get_io_gcsda}, {"cardb", get_io_gcsdb}, {NULL, NULL} -}; - -/* ==================== Gamecube ==================== */ -#elif defined (__gamecube__) -#include - -static const DISC_INTERFACE* get_io_gcsda (void) { - return &__io_gcsda; -} -static const DISC_INTERFACE* get_io_gcsdb (void) { - return &__io_gcsdb; -} - -const INTERFACE_ID _FAT_disc_interfaces[] = { - {"carda", get_io_gcsda}, - {"cardb", get_io_gcsdb}, - {NULL, NULL} -}; - -/* ====================== NDS ====================== */ -#elif defined (NDS) -#include - -const INTERFACE_ID _FAT_disc_interfaces[] = { - {"fat", dldiGetInternal}, - {NULL, NULL} -}; - -/* ====================== GBA ====================== */ -#elif defined (GBA) -#include - -const INTERFACE_ID _FAT_disc_interfaces[] = { - {"fat", discGetInterface}, - {NULL, NULL} -}; - -#endif +}; diff --git a/source/libfat/fat.h b/source/libfat/fat.h index b0ffc13a..d7b11176 100644 --- a/source/libfat/fat.h +++ b/source/libfat/fat.h @@ -1,10 +1,8 @@ /* fat.h Simple functionality for startup, mounting and unmounting of FAT-based devices. - - Copyright (c) 2006 - 2009 - Michael "Chishm" Chisholm - Dave "WinterMute" Murphy + + Copyright (c) 2006 Michael "Chishm" Chisholm Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: @@ -36,24 +34,8 @@ extern "C" { #endif -// When compiling for NDS, make sure NDS is defined -#ifndef NDS - #if defined ARM9 || defined ARM7 - #define NDS - #endif -#endif - #include - -#if defined(__gamecube__) || defined (__wii__) -# include -#else -# ifdef NDS -# include "nds/disc_io.h" -# else -# include "disc_io.h" -# endif -#endif +#include /* Initialise any inserted block-devices. @@ -71,7 +53,7 @@ extern bool fatInitDefault (void); /* Mount the device pointed to by interface, and set up a devoptab entry for it as "name:". You can then access the filesystem using "name:/". -This will mount the active partition or the first valid partition on the disc, +This will mount the active partition or the first valid partition on the disc, and will use a cache size optimized for the host system. */ extern bool fatMountSimple (const char* name, const DISC_INTERFACE* interface); @@ -85,18 +67,12 @@ cacheSize specifies the number of pages to allocate for the cache. This will not startup the disc, so you need to call interface->startup(); first. */ extern bool fatMount (const char* name, const DISC_INTERFACE* interface, sec_t startSector, uint32_t cacheSize, uint32_t SectorsPerPage); - /* Unmount the partition specified by name. If there are open files, it will attempt to synchronise them to disc. */ extern void fatUnmount (const char* name); -/* -Get Volume Label -*/ -extern void fatGetVolumeLabel (const char* name, char *label); - #ifdef __cplusplus } #endif diff --git a/source/libfat/fat_cache.c b/source/libfat/fat_cache.c index 3fe34537..422915b8 100644 --- a/source/libfat/fat_cache.c +++ b/source/libfat/fat_cache.c @@ -37,8 +37,8 @@ #include #include "common.h" -#include "cache.h" -#include "disc.h" +#include "fat_cache.h" +#include "disc_fat.h" #include "mem_allocate.h" #include "bit_ops.h" @@ -127,7 +127,7 @@ static CACHE_ENTRY* _FAT_cache_getPage(CACHE *cache,sec_t sector) cacheEntries[i].last_access = accessTime(); return &(cacheEntries[i]); } - + if(foundFree==false && (cacheEntries[i].sector==CACHE_FREE || cacheEntries[i].last_accesssector > sector) { - + secs_to_write = entry->sector - sector; - + _FAT_disc_writeSectors(cache->disc,sector,secs_to_write,src); src += (secs_to_write*BYTES_PER_READ); sector += secs_to_write; numSectors -= secs_to_write; } - + sec = sector - entry->sector; secs_to_write = entry->count - sec; @@ -327,7 +327,7 @@ bool _FAT_cache_writeSectors (CACHE* cache, sec_t sector, sec_t numSectors, cons numSectors -= secs_to_write; entry->dirty = true; - + } else { _FAT_disc_writeSectors(cache->disc,sector,numSectors,src); numSectors=0; diff --git a/source/libfat/fatdir.c b/source/libfat/fatdir.c index 55faa0b9..5a555e38 100644 --- a/source/libfat/fatdir.c +++ b/source/libfat/fatdir.c @@ -36,7 +36,7 @@ #include "fatdir.h" -#include "cache.h" +#include "fat_cache.h" #include "file_allocation_table.h" #include "partition.h" #include "directory.h" diff --git a/source/libfat/fatdir.h b/source/libfat/fatdir.h index 426dd30b..1b47a914 100644 --- a/source/libfat/fatdir.h +++ b/source/libfat/fatdir.h @@ -1,11 +1,11 @@ /* fatdir.h - - Functions used by the newlib disc stubs to interface with + + Functions used by the newlib disc stubs to interface with this library Copyright (c) 2006 Michael "Chishm" Chisholm - + Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: @@ -29,8 +29,8 @@ */ -#ifndef _FATDIR_H -#define _FATDIR_H +#ifndef __FATDIR_H +#define __FATDIR_H #include #include diff --git a/source/libfat/fatfile.c b/source/libfat/fatfile.c index 0892f960..ba8dddb5 100644 --- a/source/libfat/fatfile.c +++ b/source/libfat/fatfile.c @@ -39,7 +39,7 @@ #include #include -#include "cache.h" +#include "fat_cache.h" #include "file_allocation_table.h" #include "bit_ops.h" #include "filetime.h" diff --git a/source/libfat/file_allocation_table.h b/source/libfat/file_allocation_table.h index 560c616d..de500496 100644 --- a/source/libfat/file_allocation_table.h +++ b/source/libfat/file_allocation_table.h @@ -4,7 +4,7 @@ a FAT partition Copyright (c) 2006 Michael "Chishm" Chisholm - + Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: @@ -27,8 +27,8 @@ EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef _FAT_H -#define _FAT_H +#ifndef __FAT_H +#define __FAT_H #include "common.h" #include "partition.h" @@ -36,7 +36,7 @@ #define CLUSTER_EOF_16 0xFFFF #define CLUSTER_EOF 0x0FFFFFFF #define CLUSTER_FREE 0x00000000 -#define CLUSTER_ROOT 0x00000000 +#define CLUSTER_ROOT 0x00000000 #define CLUSTER_FIRST 0x00000002 #define CLUSTER_ERROR 0xFFFFFFFF @@ -58,8 +58,8 @@ uint32_t _FAT_fat_lastCluster (PARTITION* partition, uint32_t cluster); unsigned int _FAT_fat_freeClusterCount (PARTITION* partition); static inline sec_t _FAT_fat_clusterToSector (PARTITION* partition, uint32_t cluster) { - return (cluster >= CLUSTER_FIRST) ? - ((cluster - CLUSTER_FIRST) * (sec_t)partition->sectorsPerCluster) + partition->dataStart : + return (cluster >= CLUSTER_FIRST) ? + ((cluster - CLUSTER_FIRST) * (sec_t)partition->sectorsPerCluster) + partition->dataStart : partition->rootDirStart; } diff --git a/source/libfat/filetime.h b/source/libfat/filetime.h index 3bfd8ed8..8ffd539a 100644 --- a/source/libfat/filetime.h +++ b/source/libfat/filetime.h @@ -3,7 +3,7 @@ Conversion of file time and date values to various other types Copyright (c) 2006 Michael "Chishm" Chisholm - + Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: @@ -26,8 +26,8 @@ EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef _FILETIME_H -#define _FILETIME_H +#ifndef __FILETIME_H +#define __FILETIME_H #include "common.h" #include diff --git a/source/libfat/libfat.c b/source/libfat/libfat.c index 71af3689..0b3cbd06 100644 --- a/source/libfat/libfat.c +++ b/source/libfat/libfat.c @@ -36,7 +36,7 @@ #include "fatdir.h" #include "lock.h" #include "mem_allocate.h" -#include "disc.h" +#include "disc_fat.h" static const devoptab_t dotab_fat = { "fat", @@ -69,17 +69,17 @@ bool fatMount (const char* name, const DISC_INTERFACE* interface, sec_t startSec devoptab_t* devops; char* nameCopy; - if(!name || !interface) - return false; - if(!interface->startup()) return false; - if(!interface->isInserted()) + if(!interface->isInserted()) { + interface->shutdown(); return false; + } devops = _FAT_mem_allocate (sizeof(devoptab_t) + strlen(name) + 1); if (!devops) { + interface->shutdown(); return false; } // Use the space allocated at the end of the devoptab struct for storing the name @@ -89,6 +89,7 @@ bool fatMount (const char* name, const DISC_INTERFACE* interface, sec_t startSec partition = _FAT_partition_constructor (interface, cacheSize, SectorsPerPage, startSector); if (!partition) { _FAT_mem_free (devops); + interface->shutdown(); return false; } @@ -110,9 +111,7 @@ bool fatMountSimple (const char* name, const DISC_INTERFACE* interface) { void fatUnmount (const char* name) { devoptab_t *devops; PARTITION* partition; - - if(!name) - return; + const DISC_INTERFACE *disc; devops = (devoptab_t*)GetDeviceOpTab (name); if (!devops) { @@ -129,8 +128,10 @@ void fatUnmount (const char* name) { } partition = (PARTITION*)devops->deviceData; + disc = partition->disc; _FAT_partition_destructor (partition); _FAT_mem_free (devops); + disc->shutdown(); } bool fatInit (uint32_t cacheSize, bool setAsDefaultDevice) { @@ -193,49 +194,4 @@ bool fatInitDefault (void) { return fatInit (DEFAULT_CACHE_PAGES, true); } -void fatGetVolumeLabel (const char* name, char *label) { - devoptab_t *devops; - PARTITION* partition; - char *buf; - int namelen,i; - if(!name || !label) - return; - - namelen = strlen(name); - buf=(char*)_FAT_mem_allocate(sizeof(char)*namelen+2); - strcpy(buf,name); - - if (name[namelen-1] == '/') { - buf[namelen-1]='\0'; - namelen--; - } - - if (name[namelen-1] != ':') { - buf[namelen]=':'; - buf[namelen+1]='\0'; - } - - devops = (devoptab_t*)GetDeviceOpTab(buf); - - for(i=0;buf[i]!='\0' && buf[i]!=':';i++); - if (!devops || strncasecmp(buf,devops->name,i)) { - free(buf); - return; - } - - free(buf); - - // Perform a quick check to make sure we're dealing with a libfat controlled device - if (devops->open_r != dotab_fat.open_r) { - return; - } - - partition = (PARTITION*)devops->deviceData; - - if(!_FAT_directory_getVolumeLabel(partition, label)) { - strncpy(label,partition->label,11); - label[11]='\0'; - } - if(!strncmp(label, "NO NAME", 7)) label[0]='\0'; -} diff --git a/source/libfat/lock.h b/source/libfat/lock.h index a93194c2..73b8902b 100644 --- a/source/libfat/lock.h +++ b/source/libfat/lock.h @@ -26,8 +26,8 @@ */ -#ifndef _LOCK_H -#define _LOCK_H +#ifndef __LOCK_H +#define __LOCK_H #include "common.h" diff --git a/source/libfat/mem_allocate.h b/source/libfat/mem_allocate.h index 451cf3b1..2d38f9ce 100644 --- a/source/libfat/mem_allocate.h +++ b/source/libfat/mem_allocate.h @@ -5,7 +5,7 @@ malloc is unavailable Copyright (c) 2006 Michael "Chishm" Chisholm - + Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: @@ -28,8 +28,8 @@ EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef _MEM_ALLOCATE_H -#define _MEM_ALLOCATE_H +#ifndef __MEM_ALLOCATE_H_ +#define __MEM_ALLOCATE_H_ #include @@ -38,6 +38,7 @@ static inline void* _FAT_mem_allocate (size_t size) { } static inline void* _FAT_mem_align (size_t size) { + return memalign (32, size); } diff --git a/source/libfat/partition.c b/source/libfat/partition.c index dc1a29c9..955468de 100644 --- a/source/libfat/partition.c +++ b/source/libfat/partition.c @@ -205,16 +205,10 @@ PARTITION* _FAT_partition_constructor (const DISC_INTERFACE* disc, uint32_t cach return NULL; } - // Init the partition lock - _FAT_lock_init(&partition->lock); - _FAT_startSector = startSector; - if (!memcmp(sectorBuffer + BPB_FAT16_fileSysType, FAT_SIG, sizeof(FAT_SIG))) - strncpy(partition->label, (char*)(sectorBuffer + BPB_FAT16_volumeLabel), 11); - else - strncpy(partition->label, (char*)(sectorBuffer + BPB_FAT32_volumeLabel), 11); - partition->label[11] = '\0'; + // Init the partition lock + _FAT_lock_init(&partition->lock); // Set partition's disc interface partition->disc = disc; diff --git a/source/libfat/partition.h b/source/libfat/partition.h index 52e6648d..5c9595e0 100644 --- a/source/libfat/partition.h +++ b/source/libfat/partition.h @@ -4,7 +4,7 @@ on various block devices. Copyright (c) 2006 Michael "Chishm" Chisholm - + Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: @@ -27,11 +27,11 @@ EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef _PARTITION_H -#define _PARTITION_H +#ifndef __PARTITION_H +#define __PARTITION_H #include "common.h" -#include "cache.h" +#include "fat_cache.h" #include "lock.h" // Device name @@ -67,7 +67,6 @@ typedef struct { struct _FILE_STRUCT* firstOpenFile; // The start of a linked list of files mutex_t lock; // A lock for partition operations bool readOnly; // If this is set, then do not try writing to the disc - char label[12]; // Volume label } PARTITION; /* @@ -76,7 +75,7 @@ Mount the supplied device and return a pointer to the struct necessary to use it PARTITION* _FAT_partition_constructor (const DISC_INTERFACE* disc, uint32_t cacheSize, uint32_t SectorsPerPage, sec_t startSector); /* -Dismount the device and free all structures used. +Dismount the device and free all structures used. Will also attempt to synchronise all open files to disc. */ void _FAT_partition_destructor (PARTITION* partition);