diff --git a/common/include/usbhdfsd-common.h b/common/include/usbhdfsd-common.h index d06d13dd620..0417eeeeae0 100644 --- a/common/include/usbhdfsd-common.h +++ b/common/include/usbhdfsd-common.h @@ -17,18 +17,11 @@ #include -#define BD_MAX_FRAGMENTS 10 - typedef struct bd_fragment { u32 sector; /// start sector of fragmented bd/file u32 count; /// number of sector in this fragment } __attribute__((packed)) bd_fragment_t; -typedef struct bd_fraglist { - u32 count; /// number of fragments - bd_fragment_t list[BD_MAX_FRAGMENTS]; /// pointer to fragment list -} __attribute__((packed)) bd_fraglist_t; - // IOCTL function codes /** Rename opened file. Data input to ioctl() -> new, full filename of file. */ #define USBMASS_IOCTL_RENAME 0x0000 diff --git a/iop/fs/bdmfs_fatfs/src/fs_driver.c b/iop/fs/bdmfs_fatfs/src/fs_driver.c index fe21dd705e7..150d3b6613c 100644 --- a/iop/fs/bdmfs_fatfs/src/fs_driver.c +++ b/iop/fs/bdmfs_fatfs/src/fs_driver.c @@ -438,33 +438,30 @@ static int fs_getstat(iop_file_t *fd, const char *name, iox_stat_t *stat) static int get_frag_list(FIL *file, void *rdata, unsigned int rdatalen) { - bd_fraglist_t *l = (bd_fraglist_t*)rdata; + bd_fragment_t *f = (bd_fragment_t*)rdata; + int iMaxFragments = rdatalen / sizeof(bd_fragment_t); + int iFragCount = 0; + DWORD iClusterStart = file->obj.sclust; DWORD iClusterCurrent = iClusterStart; - if (rdatalen < sizeof(bd_fraglist_t)) { - M_DEBUG("ERROR: rdatalen=%d\n", rdatalen); - return -1; - } - - l->count = 0; do { DWORD iClusterNext = get_fat(&file->obj, iClusterCurrent); if (iClusterNext != (iClusterCurrent + 1)) { // Fragment or file end M_DEBUG("fragment: %uc - %uc + 1\n", iClusterStart, iClusterCurrent + 1); - if (l->count < 10) { - l->list[l->count].sector = clst2sect(file->obj.fs, iClusterStart); - l->list[l->count].count = clst2sect(file->obj.fs, iClusterCurrent) - clst2sect(file->obj.fs, iClusterStart) + file->obj.fs->csize; - M_DEBUG(" - sectors: %us count %us\n", l->list[l->count].sector, l->list[l->count].count); + if (iFragCount < iMaxFragments) { + f[iFragCount].sector = clst2sect(file->obj.fs, iClusterStart); + f[iFragCount].count = clst2sect(file->obj.fs, iClusterCurrent) - clst2sect(file->obj.fs, iClusterStart) + file->obj.fs->csize; + M_DEBUG(" - sectors: %us count %us\n", f[iFragCount].sector, f[iFragCount].count); } - l->count++; + iFragCount++; iClusterStart = iClusterNext; } iClusterCurrent = iClusterNext; } while(iClusterCurrent < file->obj.fs->n_fatent); - return l->count; + return iFragCount; } //--------------------------------------------------------------------------- diff --git a/iop/fs/libbdm/include/bd_defrag.h b/iop/fs/libbdm/include/bd_defrag.h index 43dd91da5ab..56756330ca2 100644 --- a/iop/fs/libbdm/include/bd_defrag.h +++ b/iop/fs/libbdm/include/bd_defrag.h @@ -21,7 +21,7 @@ #include -int bd_defrag(struct block_device* bd, struct bd_fraglist* fl, u32 sector, void* buffer, u16 count); +int bd_defrag(struct block_device* bd, u32 fragcount, struct bd_fragment* fraglist, u32 sector, void* buffer, u16 count); diff --git a/iop/fs/libbdm/src/bd_defrag.c b/iop/fs/libbdm/src/bd_defrag.c index 7a329919a27..3c7965e869b 100644 --- a/iop/fs/libbdm/src/bd_defrag.c +++ b/iop/fs/libbdm/src/bd_defrag.c @@ -4,7 +4,7 @@ #include "module_debug.h" -int bd_defrag(struct block_device* bd, struct bd_fraglist* fl, u32 sector, void* buffer, u16 count) +int bd_defrag(struct block_device* bd, u32 fragcount, struct bd_fragment* fraglist, u32 sector, void* buffer, u16 count) { u32 sector_start = sector; u16 count_left = count; @@ -16,8 +16,8 @@ int bd_defrag(struct block_device* bd, struct bd_fraglist* fl, u32 sector, void* int i; // Locate fragment containing start sector - for (i=0; icount; i++) { - f = &fl->list[i]; + for (i=0; icount) > sector_start) { // Fragment found break; @@ -25,7 +25,7 @@ int bd_defrag(struct block_device* bd, struct bd_fraglist* fl, u32 sector, void* offset += f->count; } - if (i == fl->count) { + if (i == fragcount) { M_PRINTF("%s: ERROR: fragment not found!\n", __FUNCTION__); return -1; }