mirror of
https://github.com/wiidev/usbloadergx.git
synced 2024-11-16 00:15:08 +01:00
*Fixed display of partition size on WBFS partitions with a different wbfs sector size than 512bytes.
*Made the ProgressWindow for game installation more accurate *Added displaying newly installed games (marked as new) on favorite list, so you don't have to change to full list when installing new games. (Thanks Cyan for the patch) *Lot's a small fixes *Added WDM Menu on game start. You can set it in the alternative DOL option (one new option there). The menu lists all DOLs on the disc and if a wdm file is provided in the WDM path (configurable in the settings) than the dol parameter and dol replacement name will be taken from the wdm. The DOLs that are not listed in the WDM but exist on the DISC will be listed at the end of the list. *Added avoid of multiple app cleanup when game fails to boot *Changed libfat to use FS info sector on FAT32 partitions. This speeds up the free space information getting to instant. For that the FS info sector has to have correct values. The values of all partitions where homebrews were writing to are currently incorrect because the official libfat does not support FS info sector (i submited a patch) (Windows does write it correct though). That is why there needs to be a synchronization of the FS info sector for partitions used with homebrews. For this purpose a new setting was added in the Loader Settings. You can synchronize all your FAT32 partitions on the USB with it once and you are done (if you don't write to that partition with current homebrews). After that you can enable free space display and it will be instant like on WBFS/NTFS/EXT partitions.
This commit is contained in:
parent
85eb0a7ed2
commit
9d46977121
@ -264,34 +264,6 @@ bool _FAT_cache_eraseWritePartialSector (CACHE* cache, const void* buffer, sec_t
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef GEKKO
|
|
||||||
static CACHE_ENTRY* _FAT_cache_findPage(CACHE *cache, sec_t sector, sec_t count) {
|
|
||||||
|
|
||||||
unsigned int i;
|
|
||||||
CACHE_ENTRY* cacheEntries = cache->cacheEntries;
|
|
||||||
unsigned int numberOfPages = cache->numberOfPages;
|
|
||||||
CACHE_ENTRY *entry = NULL;
|
|
||||||
sec_t lowest = UINT_MAX;
|
|
||||||
|
|
||||||
for(i=0;i<numberOfPages;i++) {
|
|
||||||
if (cacheEntries[i].sector != CACHE_FREE) {
|
|
||||||
bool intersect;
|
|
||||||
if (sector > cacheEntries[i].sector) {
|
|
||||||
intersect = sector - cacheEntries[i].sector < cacheEntries[i].count;
|
|
||||||
} else {
|
|
||||||
intersect = cacheEntries[i].sector - sector < count;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( intersect && (cacheEntries[i].sector < lowest)) {
|
|
||||||
lowest = cacheEntries[i].sector;
|
|
||||||
entry = &cacheEntries[i];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return entry;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
bool _FAT_cache_writeSectors (CACHE* cache, sec_t sector, sec_t numSectors, const void* buffer)
|
bool _FAT_cache_writeSectors (CACHE* cache, sec_t sector, sec_t numSectors, const void* buffer)
|
||||||
{
|
{
|
||||||
@ -302,24 +274,9 @@ bool _FAT_cache_writeSectors (CACHE* cache, sec_t sector, sec_t numSectors, cons
|
|||||||
|
|
||||||
while(numSectors>0)
|
while(numSectors>0)
|
||||||
{
|
{
|
||||||
#ifdef GEKKO
|
|
||||||
entry = _FAT_cache_getPage(cache,sector);
|
entry = _FAT_cache_getPage(cache,sector);
|
||||||
if(entry==NULL) return false;
|
if(entry==NULL) return false;
|
||||||
#else
|
|
||||||
entry = _FAT_cache_findPage(cache,sector,numSectors);
|
|
||||||
|
|
||||||
if(entry==NULL)
|
|
||||||
return _FAT_disc_writeSectors(cache->disc,sector,numSectors,src);
|
|
||||||
|
|
||||||
if ( entry->sector > 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;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
sec = sector - entry->sector;
|
sec = sector - entry->sector;
|
||||||
secs_to_write = entry->count - sec;
|
secs_to_write = entry->count - sec;
|
||||||
if(secs_to_write>numSectors) secs_to_write = numSectors;
|
if(secs_to_write>numSectors) secs_to_write = numSectors;
|
||||||
|
@ -32,7 +32,7 @@
|
|||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <sys/dir.h>
|
#include <sys/iosupport.h>
|
||||||
|
|
||||||
#include "fatdir.h"
|
#include "fatdir.h"
|
||||||
|
|
||||||
@ -465,7 +465,16 @@ int _FAT_statvfs_r (struct _reent *r, const char *path, struct statvfs *buf)
|
|||||||
|
|
||||||
_FAT_lock(&partition->lock);
|
_FAT_lock(&partition->lock);
|
||||||
|
|
||||||
freeClusterCount = _FAT_fat_freeClusterCount (partition);
|
if(memcmp(&buf->f_flag, "SCAN", 4) == 0)
|
||||||
|
{
|
||||||
|
//Special command was given to sync the numberFreeCluster
|
||||||
|
_FAT_partition_createFSinfo(partition);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(partition->filesysType == FS_FAT32)
|
||||||
|
freeClusterCount = partition->fat.numberFreeCluster;
|
||||||
|
else
|
||||||
|
freeClusterCount = _FAT_fat_freeClusterCount (partition);
|
||||||
|
|
||||||
// FAT clusters = POSIX blocks
|
// FAT clusters = POSIX blocks
|
||||||
buf->f_bsize = partition->bytesPerCluster; // File system block size.
|
buf->f_bsize = partition->bytesPerCluster; // File system block size.
|
||||||
|
@ -245,6 +245,8 @@ uint32_t _FAT_fat_linkFreeCluster(PARTITION* partition, uint32_t cluster) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
partition->fat.firstFree = firstFree;
|
partition->fat.firstFree = firstFree;
|
||||||
|
partition->fat.numberFreeCluster--;
|
||||||
|
partition->fat.numberLastAllocCluster = firstFree;
|
||||||
|
|
||||||
if ((cluster >= CLUSTER_FIRST) && (cluster <= lastCluster))
|
if ((cluster >= CLUSTER_FIRST) && (cluster <= lastCluster))
|
||||||
{
|
{
|
||||||
@ -309,6 +311,7 @@ bool _FAT_fat_clearLinks (PARTITION* partition, uint32_t cluster) {
|
|||||||
// Erase the link
|
// Erase the link
|
||||||
_FAT_fat_writeFatEntry (partition, cluster, CLUSTER_FREE);
|
_FAT_fat_writeFatEntry (partition, cluster, CLUSTER_FREE);
|
||||||
|
|
||||||
|
partition->fat.numberFreeCluster++;
|
||||||
// Move onto next cluster
|
// Move onto next cluster
|
||||||
cluster = nextCluster;
|
cluster = nextCluster;
|
||||||
}
|
}
|
||||||
|
@ -95,7 +95,20 @@ enum BPB {
|
|||||||
BPB_bootSig_AA = 0x1FF
|
BPB_bootSig_AA = 0x1FF
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// File system information block offsets
|
||||||
|
enum FSIB
|
||||||
|
{
|
||||||
|
FSIB_SIG1 = 0x00,
|
||||||
|
FSIB_SIG2 = 0x1e4,
|
||||||
|
FSIB_numberOfFreeCluster = 0x1e8,
|
||||||
|
FSIB_numberLastAllocCluster = 0x1ec,
|
||||||
|
FSIB_bootSig_55 = 0x1FE,
|
||||||
|
FSIB_bootSig_AA = 0x1FF
|
||||||
|
};
|
||||||
|
|
||||||
static const char FAT_SIG[3] = {'F', 'A', 'T'};
|
static const char FAT_SIG[3] = {'F', 'A', 'T'};
|
||||||
|
static const char FS_INFO_SIG1[4] = {'R', 'R', 'a', 'A'};
|
||||||
|
static const char FS_INFO_SIG2[4] = {'r', 'r', 'A', 'a'};
|
||||||
|
|
||||||
|
|
||||||
sec_t FindFirstValidPartition(const DISC_INTERFACE* disc)
|
sec_t FindFirstValidPartition(const DISC_INTERFACE* disc)
|
||||||
@ -234,10 +247,15 @@ PARTITION* _FAT_partition_constructor (const DISC_INTERFACE* disc, uint32_t cach
|
|||||||
|
|
||||||
partition->totalSize = ((uint64_t)partition->numberOfSectors - (partition->dataStart - startSector)) * (uint64_t)partition->bytesPerSector;
|
partition->totalSize = ((uint64_t)partition->numberOfSectors - (partition->dataStart - startSector)) * (uint64_t)partition->bytesPerSector;
|
||||||
|
|
||||||
|
//FS info sector
|
||||||
|
partition->fsInfoSector = startSector + (u8array_to_u16(sectorBuffer, BPB_FAT32_fsInfo) ? u8array_to_u16(sectorBuffer, BPB_FAT32_fsInfo) : 1);
|
||||||
|
|
||||||
// Store info about FAT
|
// Store info about FAT
|
||||||
uint32_t clusterCount = (partition->numberOfSectors - (uint32_t)(partition->dataStart - startSector)) / partition->sectorsPerCluster;
|
uint32_t clusterCount = (partition->numberOfSectors - (uint32_t)(partition->dataStart - startSector)) / partition->sectorsPerCluster;
|
||||||
partition->fat.lastCluster = clusterCount + CLUSTER_FIRST - 1;
|
partition->fat.lastCluster = clusterCount + CLUSTER_FIRST - 1;
|
||||||
partition->fat.firstFree = CLUSTER_FIRST;
|
partition->fat.firstFree = CLUSTER_FIRST;
|
||||||
|
partition->fat.numberFreeCluster = 0;
|
||||||
|
partition->fat.numberLastAllocCluster = 0;
|
||||||
|
|
||||||
if (clusterCount < CLUSTERS_PER_FAT12) {
|
if (clusterCount < CLUSTERS_PER_FAT12) {
|
||||||
partition->filesysType = FS_FAT12; // FAT12 volume
|
partition->filesysType = FS_FAT12; // FAT12 volume
|
||||||
@ -272,6 +290,8 @@ PARTITION* _FAT_partition_constructor (const DISC_INTERFACE* disc, uint32_t cach
|
|||||||
partition->openFileCount = 0;
|
partition->openFileCount = 0;
|
||||||
partition->firstOpenFile = NULL;
|
partition->firstOpenFile = NULL;
|
||||||
|
|
||||||
|
_FAT_partition_readFSinfo(partition);
|
||||||
|
|
||||||
return partition;
|
return partition;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -287,6 +307,9 @@ void _FAT_partition_destructor (PARTITION* partition) {
|
|||||||
nextFile = nextFile->nextOpenFile;
|
nextFile = nextFile->nextOpenFile;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Write out the fs info sector
|
||||||
|
_FAT_partition_writeFSinfo(partition);
|
||||||
|
|
||||||
// Free memory used by the cache, writing it to disc at the same time
|
// Free memory used by the cache, writing it to disc at the same time
|
||||||
_FAT_cache_destructor (partition->cache);
|
_FAT_cache_destructor (partition->cache);
|
||||||
|
|
||||||
@ -309,3 +332,77 @@ PARTITION* _FAT_partition_getPartitionFromPath (const char* path) {
|
|||||||
|
|
||||||
return (PARTITION*)devops->deviceData;
|
return (PARTITION*)devops->deviceData;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void _FAT_partition_createFSinfo(PARTITION * partition)
|
||||||
|
{
|
||||||
|
if(partition->readOnly || partition->filesysType != FS_FAT32)
|
||||||
|
return;
|
||||||
|
|
||||||
|
uint8_t sectorBuffer[BYTES_PER_READ];
|
||||||
|
memset(sectorBuffer, 0, sizeof(sectorBuffer));
|
||||||
|
|
||||||
|
int i;
|
||||||
|
for(i = 0; i < 4; ++i)
|
||||||
|
{
|
||||||
|
sectorBuffer[FSIB_SIG1+i] = FS_INFO_SIG1[i];
|
||||||
|
sectorBuffer[FSIB_SIG2+i] = FS_INFO_SIG2[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
partition->fat.numberFreeCluster = _FAT_fat_freeClusterCount(partition);
|
||||||
|
u32_to_u8array(sectorBuffer, FSIB_numberOfFreeCluster, partition->fat.numberFreeCluster);
|
||||||
|
u32_to_u8array(sectorBuffer, FSIB_numberLastAllocCluster, partition->fat.numberLastAllocCluster);
|
||||||
|
|
||||||
|
sectorBuffer[FSIB_bootSig_55] = 0x55;
|
||||||
|
sectorBuffer[FSIB_bootSig_AA] = 0xAA;
|
||||||
|
|
||||||
|
_FAT_disc_writeSectors (partition->disc, partition->fsInfoSector, 1, sectorBuffer);
|
||||||
|
}
|
||||||
|
|
||||||
|
void _FAT_partition_readFSinfo(PARTITION * partition)
|
||||||
|
{
|
||||||
|
if(partition->filesysType != FS_FAT32)
|
||||||
|
return;
|
||||||
|
|
||||||
|
uint8_t sectorBuffer[BYTES_PER_READ] = {0};
|
||||||
|
|
||||||
|
// Read first sector of disc
|
||||||
|
if (!_FAT_disc_readSectors (partition->disc, partition->fsInfoSector, 1, sectorBuffer)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(memcmp(sectorBuffer+FSIB_SIG1, FS_INFO_SIG1, 4) != 0 ||
|
||||||
|
memcmp(sectorBuffer+FSIB_SIG2, FS_INFO_SIG2, 4) != 0 ||
|
||||||
|
u8array_to_u32(sectorBuffer, FSIB_numberOfFreeCluster) == 0)
|
||||||
|
{
|
||||||
|
//sector does not yet exist, create one!
|
||||||
|
_FAT_partition_createFSinfo(partition);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
partition->fat.numberFreeCluster = u8array_to_u32(sectorBuffer, FSIB_numberOfFreeCluster);
|
||||||
|
partition->fat.numberLastAllocCluster = u8array_to_u32(sectorBuffer, FSIB_numberLastAllocCluster);
|
||||||
|
}
|
||||||
|
|
||||||
|
void _FAT_partition_writeFSinfo(PARTITION * partition)
|
||||||
|
{
|
||||||
|
if(partition->filesysType != FS_FAT32)
|
||||||
|
return;
|
||||||
|
|
||||||
|
uint8_t sectorBuffer[BYTES_PER_READ] = {0};
|
||||||
|
|
||||||
|
// Read first sector of disc
|
||||||
|
if (!_FAT_disc_readSectors (partition->disc, partition->fsInfoSector, 1, sectorBuffer)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(memcmp(sectorBuffer+FSIB_SIG1, FS_INFO_SIG1, 4) || memcmp(sectorBuffer+FSIB_SIG2, FS_INFO_SIG2, 4))
|
||||||
|
return;
|
||||||
|
|
||||||
|
u32_to_u8array(sectorBuffer, FSIB_numberOfFreeCluster, partition->fat.numberFreeCluster);
|
||||||
|
u32_to_u8array(sectorBuffer, FSIB_numberLastAllocCluster, partition->fat.numberLastAllocCluster);
|
||||||
|
|
||||||
|
// Read first sector of disc
|
||||||
|
if (!_FAT_disc_writeSectors (partition->disc, partition->fsInfoSector, 1, sectorBuffer)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -45,6 +45,8 @@ typedef struct {
|
|||||||
uint32_t sectorsPerFat;
|
uint32_t sectorsPerFat;
|
||||||
uint32_t lastCluster;
|
uint32_t lastCluster;
|
||||||
uint32_t firstFree;
|
uint32_t firstFree;
|
||||||
|
uint32_t numberFreeCluster;
|
||||||
|
uint32_t numberLastAllocCluster;
|
||||||
} FAT;
|
} FAT;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
@ -60,6 +62,7 @@ typedef struct {
|
|||||||
uint32_t bytesPerSector;
|
uint32_t bytesPerSector;
|
||||||
uint32_t sectorsPerCluster;
|
uint32_t sectorsPerCluster;
|
||||||
uint32_t bytesPerCluster;
|
uint32_t bytesPerCluster;
|
||||||
|
uint32_t fsInfoSector;
|
||||||
FAT fat;
|
FAT fat;
|
||||||
// Values that may change after construction
|
// Values that may change after construction
|
||||||
uint32_t cwdCluster; // Current working directory cluster
|
uint32_t cwdCluster; // Current working directory cluster
|
||||||
@ -86,4 +89,19 @@ Return the partition specified in a path, as taken from the devoptab.
|
|||||||
*/
|
*/
|
||||||
PARTITION* _FAT_partition_getPartitionFromPath (const char* path);
|
PARTITION* _FAT_partition_getPartitionFromPath (const char* path);
|
||||||
|
|
||||||
|
/*
|
||||||
|
Create the fs info sector.
|
||||||
|
*/
|
||||||
|
void _FAT_partition_createFSinfo(PARTITION * partition);
|
||||||
|
|
||||||
|
/*
|
||||||
|
Read the fs info sector data.
|
||||||
|
*/
|
||||||
|
void _FAT_partition_readFSinfo(PARTITION * partition);
|
||||||
|
|
||||||
|
/*
|
||||||
|
Write the fs info sector data.
|
||||||
|
*/
|
||||||
|
void _FAT_partition_writeFSinfo(PARTITION * partition);
|
||||||
|
|
||||||
#endif // _PARTITION_H
|
#endif // _PARTITION_H
|
||||||
|
Loading…
Reference in New Issue
Block a user