usbloadergx/libcustomfat/fatfile_frag.c
dimok321 f6c9003574 *Added support for starting .wbfs game files from fat32/ntfs partitions on a sector size > 512 (tested with 4096)
*modified libcustomfat and ntfs fragment fetch function to support >512 bytes per sector
*Added new ehcmodule (thanks rodries)
*Added real support of using both ports simultaniously without shutting down the other (thanks rodries for the ehcmodule works on this). There is no longer the limitation that the settings have to be on SD card for this. (ONLY HERMES CIOS)
*Moved a few settings to Feature Settings and added a new Hard Drive Settings
*Changed Wiinnertag path to only point to the path and not to the file. You must correct the path manually in custom path settings or reset you configs for this change or Winnertag won't work!!
*Removed a few compile warnings for devkitPPC R23
2011-06-22 17:57:37 +00:00

64 lines
1.4 KiB
C

#include "fatfile.h"
#include <fcntl.h>
#include <string.h>
#include <errno.h>
#include <ctype.h>
#include <unistd.h>
#include "cache.h"
#include "file_allocation_table.h"
#include "bit_ops.h"
#include "filetime.h"
#include "lock.h"
#include "fatfile_frag.h"
int _FAT_get_fragments (const char *path, _fat_frag_append_t append_fragment, void *callback_data)
{
struct _reent r;
FILE_STRUCT file;
PARTITION* partition;
u32 cluster;
u32 sector;
u32 offset; // in sectors
u32 size; // in sectors
int ret = -1;
int fd;
fd = _FAT_open_r (&r, &file, path, O_RDONLY, 0);
if (fd == -1) return -1;
if (fd != (int)&file) return -1;
partition = file.partition;
_FAT_lock(&partition->lock);
size = file.filesize / partition->bytesPerSector;
cluster = file.startCluster;
offset = 0;
do {
if (!_FAT_fat_isValidCluster(partition, cluster)) {
// invalid cluster
goto out;
}
// add cluster to fileinfo
sector = _FAT_fat_clusterToSector(partition, cluster);
if (append_fragment(callback_data, offset, sector, partition->sectorsPerCluster)) {
// too many fragments
goto out;
}
offset += partition->sectorsPerCluster;
cluster = _FAT_fat_nextCluster (partition, cluster);
} while (offset < size);
// set size
append_fragment(callback_data, size, 0, 0);
// success
ret = 0;
out:
_FAT_unlock(&partition->lock);
_FAT_close_r(&r, fd);
return ret;
}