From ae77bd1b7e4f4c0e45bcb63243f8049197e42ead Mon Sep 17 00:00:00 2001 From: dimok321 <15055714+dimok789@users.noreply.github.com> Date: Fri, 4 Feb 2011 15:25:27 +0000 Subject: [PATCH] *Added support for Wiimms virtual sector sizes for WBFS (sector sizes other than 512 bytes per sector). Sector sizes other than 512 bytes support more games than 500 (sector size - 12 games). You can just format your drive with Wiimms tools and use it. *Changed USB Loader GX WBFS formatter to choose 2048 as virtual sector size if a drive with a size > 500GB is formatted. NOTE: Don't use this feature with IOS58 mode. It might damage the partition. I did not build in a safety check for IOS58 mode because it will be removed soon anyway. --- HBC/META.XML | 4 ++-- source/BoxCover/BoxCover.cpp | 6 +++--- source/libs/libwbfs/libwbfs.c | 5 ++++- source/prompts/ProgressWindow.cpp | 2 +- source/settings/menus/LoaderSettings.cpp | 3 --- source/usbloader/GameList.cpp | 6 ++++-- source/usbloader/wbfs.cpp | 19 ++++++++----------- source/usbloader/wbfs/wbfs_base.h | 4 ++-- source/usbloader/wbfs/wbfs_fat.cpp | 18 +++++++++--------- source/usbloader/wbfs/wbfs_fat.h | 1 - source/usbloader/wbfs/wbfs_rw.c | 8 ++++---- source/usbloader/wbfs/wbfs_wbfs.cpp | 24 +++++++++++++++++++----- 12 files changed, 56 insertions(+), 44 deletions(-) diff --git a/HBC/META.XML b/HBC/META.XML index 3084f375..d308d94f 100644 --- a/HBC/META.XML +++ b/HBC/META.XML @@ -2,8 +2,8 @@ USB Loader GX USB Loader GX Team - 2.0 r1061 - 201102021831 + 2.0 r1062 + 201102032147 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. diff --git a/source/BoxCover/BoxCover.cpp b/source/BoxCover/BoxCover.cpp index 2e5d906e..18da96cc 100644 --- a/source/BoxCover/BoxCover.cpp +++ b/source/BoxCover/BoxCover.cpp @@ -94,7 +94,7 @@ void BoxCover::WiiPADControl(GuiTrigger *t) } else if((t->wpad.btns_h & WPAD_BUTTON_A) && moveChan == t->chan && t->wpad.ir.valid) { - movePosX = (t->wpad.ir.x-moveStartPosX) / 220.0f; + movePosX = (t->wpad.ir.x-moveStartPosX) / 180.0f; movePosY = (moveStartPosY-t->wpad.ir.y) / 180.0f; last_manual_move_frame = frameCount; } @@ -199,10 +199,10 @@ void BoxCover::Draw() GX_LoadPosMtxImm(modelView, GX_PNMTX0); + //! Border quads GX_LoadTexObj(&boxBorderTex, GX_TEXMAP0); GX_InvalidateTexAll(); - //! Border quads GX_SetArray(GX_VA_POS, (void *) &g_boxMeshQ[0].pos, sizeof(g_boxMeshQ[0])); GX_SetArray(GX_VA_TEX0, (void *) &g_boxMeshQ[0].texCoord, sizeof(g_boxMeshQ[0])); @@ -228,10 +228,10 @@ void BoxCover::Draw() } GX_End(); + //! Back Cover (Might be flat) GX_LoadTexObj(flatCover ? &defaultBoxTex : &coverTex, GX_TEXMAP0); GX_InvalidateTexAll(); - //! Back Cover GX_SetArray(GX_VA_POS, (void *) &g_boxBackCoverMesh[0].pos, sizeof(g_boxBackCoverMesh[0])); GX_SetArray(GX_VA_TEX0, (void *) &g_boxBackCoverMesh[0].texCoord, sizeof(g_boxBackCoverMesh[0])); diff --git a/source/libs/libwbfs/libwbfs.c b/source/libs/libwbfs/libwbfs.c index abf4632b..1b799e51 100644 --- a/source/libs/libwbfs/libwbfs.c +++ b/source/libs/libwbfs/libwbfs.c @@ -754,8 +754,11 @@ int wbfs_extract_file(wbfs_disc_t*d, char *path, void **data) int wbfs_get_fragments(wbfs_disc_t *d, _frag_append_t append_fragment, void *callback_data) { if (!d) return -1; + + //! Use here real physical HDD sector size + u32 phys_hdd_sec_sz = *(((u32 *) d->p->callback_data)+1); wbfs_t *p = d->p; - int src_wbs_nlb = p->wbfs_sec_sz / p->hd_sec_sz; + int src_wbs_nlb = p->wbfs_sec_sz / phys_hdd_sec_sz; int i, ret, last = 0; for (i = 0; i < p->n_wbfs_sec_per_disc; i++) { diff --git a/source/prompts/ProgressWindow.cpp b/source/prompts/ProgressWindow.cpp index d83592c3..2483c30e 100644 --- a/source/prompts/ProgressWindow.cpp +++ b/source/prompts/ProgressWindow.cpp @@ -351,7 +351,7 @@ static void ProgressWindow(const char *title, const char *msg1, const char *msg2 while (showProgress) { - usleep(30000); + usleep(50000); if (shutdown) Sys_Shutdown(); diff --git a/source/settings/menus/LoaderSettings.cpp b/source/settings/menus/LoaderSettings.cpp index 2c6787e7..72b8dca7 100644 --- a/source/settings/menus/LoaderSettings.cpp +++ b/source/settings/menus/LoaderSettings.cpp @@ -300,9 +300,6 @@ int LoaderSettings::GetMenuInternal() //! Settings: Game/Install Partition else if (ret == ++Idx) { - if(DeviceHandler::Instance()->GetUSBHandle()->GetPartitionCount() < 2) - return MENU_NONE; - // Select the next valid partition, even if that's the same one int fs_type = 0; int ios = IOS_GetVersion(); diff --git a/source/usbloader/GameList.cpp b/source/usbloader/GameList.cpp index 8af99a8d..d2b18fd0 100644 --- a/source/usbloader/GameList.cpp +++ b/source/usbloader/GameList.cpp @@ -48,6 +48,7 @@ void GameList::clear() //! Clear memory of the vector completely std::vector().swap(FilteredList); std::vector().swap(FullGameList); + std::vector().swap(GamePartitionList); } struct discHdr * GameList::GetDiscHeader(const char * gameID) const @@ -78,8 +79,6 @@ int GameList::GetPartitionNumber(const u8 *gameID) const void GameList::RemovePartition(int part) { - wString filter(GameFilter); - for(u32 i = 0; i < GamePartitionList.size(); ++i) { if(GamePartitionList[i] == part) @@ -91,7 +90,10 @@ void GameList::RemovePartition(int part) } if(FullGameList.size() > 0) + { + wString filter(GameFilter); FilterList(filter.c_str()); + } } int GameList::InternalReadList(int part) diff --git a/source/usbloader/wbfs.cpp b/source/usbloader/wbfs.cpp index d6962c36..9c2b9466 100644 --- a/source/usbloader/wbfs.cpp +++ b/source/usbloader/wbfs.cpp @@ -35,16 +35,12 @@ void WBFS_CloseDisc(wbfs_disc_t *disc) { if(!disc) return; - for(u32 i = 0; i < WbfsList.size(); ++i) - { - if(!WbfsList[i]) continue; + struct discHdr * header = (struct discHdr *) disc->header; + int part_num = gameList.GetPartitionNumber(header->id); + if(!VALID(part_num)) + return; - if(WbfsList[i]->GetHDDHandle() == disc->p) - { - WbfsList[i]->CloseDisc(disc); - break; - } - } + WbfsList[part_num]->CloseDisc(disc); } s32 WBFS_Init(u32 device) @@ -117,7 +113,6 @@ bool WBFS_Close(int part_num) if(!VALID(part_num)) return false; - WbfsList[part_num]->Close(); delete WbfsList[part_num]; WbfsList[part_num] = NULL; @@ -128,6 +123,8 @@ bool WBFS_Close(int part_num) void WBFS_CloseAll() { + gameList.clear(); + for(u32 i = 0; i < WbfsList.size(); ++i) WBFS_Close(i); } @@ -159,7 +156,7 @@ s32 WBFS_CheckGame(u8 *discid) { int part_num = gameList.GetPartitionNumber(discid); if(!VALID(part_num)) - return -1; + return 0; return WbfsList[part_num]->CheckGame(discid); } diff --git a/source/usbloader/wbfs/wbfs_base.h b/source/usbloader/wbfs/wbfs_base.h index de8cd070..95ceb52b 100644 --- a/source/usbloader/wbfs/wbfs_base.h +++ b/source/usbloader/wbfs/wbfs_base.h @@ -12,7 +12,7 @@ class Wbfs { public: Wbfs(u32, u32, u32); - + ~Wbfs() { Close(); }; static s32 Init(u32); s32 CheckGame(u8 *); s32 GameSize(u8 *, f32 *); @@ -21,7 +21,7 @@ class Wbfs virtual bool ShowFreeSpace(void); virtual s32 Open() = 0; - virtual void Close() = 0; + virtual void Close() {}; virtual wbfs_disc_t* OpenDisc(u8 *discid) = 0; virtual void CloseDisc(wbfs_disc_t *disc) = 0; virtual s32 Format(); diff --git a/source/usbloader/wbfs/wbfs_fat.cpp b/source/usbloader/wbfs/wbfs_fat.cpp index 62d9cf7e..bf6acd8f 100644 --- a/source/usbloader/wbfs/wbfs_fat.cpp +++ b/source/usbloader/wbfs/wbfs_fat.cpp @@ -36,7 +36,7 @@ using namespace std; static const char wbfs_fat_dir[] = "/wbfs"; static const char invalid_path[] = "/\\:|<>?*\"'"; -static const u32 fat_sector_size = 512; +extern u32 hdd_sector_size; Wbfs_Fat::Wbfs_Fat(u32 device, u32 lba, u32 size) : Wbfs(device, lba, size), fat_hdr_list(NULL), fat_hdr_count(0) @@ -96,13 +96,13 @@ wbfs_disc_t* Wbfs_Fat::OpenDisc(u8 *discid) return iso_file; } - hdd = OpenPart(fname); - if (!hdd) return NULL; + wbfs_t *part = OpenPart(fname); + if (!part) return NULL; - wbfs_disc_t *disc = wbfs_open_disc(hdd, discid); + wbfs_disc_t *disc = wbfs_open_disc(part, discid); if(!disc) { - ClosePart(hdd); + ClosePart(part); return NULL; } @@ -318,12 +318,12 @@ u64 Wbfs_Fat::EstimateGameSize() { wbfs_t *part = NULL; u64 size = (u64) 143432 * 2 * 0x8000ULL; - u32 n_sector = size / fat_sector_size; + u32 n_sector = size / hdd_sector_size; u32 wii_sec_sz; // init a temporary dummy part // as a placeholder for wbfs_size_disc - part = wbfs_open_partition(nop_rw_sector, nop_rw_sector, NULL, fat_sector_size, n_sector, 0, 1); + part = wbfs_open_partition(nop_rw_sector, nop_rw_sector, NULL, hdd_sector_size, n_sector, 0, 1); if (!part) return -1; wii_sec_sz = part->wii_sec_sz; @@ -687,7 +687,7 @@ wbfs_t* Wbfs_Fat::OpenPart(char *fname) ret = split_open(&split, fname); if (ret) return NULL; part = wbfs_open_partition(split_read_sector, nop_rw_sector, //readonly //split_write_sector, - &split, fat_sector_size, split.total_sec, 0, 0); + &split, hdd_sector_size, split.total_sec, 0, 0); if (!part) { split_close(&split); @@ -769,7 +769,7 @@ wbfs_t* Wbfs_Fat::CreatePart(u8 *id, char *path) return NULL; } - part = wbfs_open_partition(split_read_sector, split_write_sector, &split, fat_sector_size, n_sector, 0, 1); + part = wbfs_open_partition(split_read_sector, split_write_sector, &split, hdd_sector_size, n_sector, 0, 1); if (!part) { split_close(&split); diff --git a/source/usbloader/wbfs/wbfs_fat.h b/source/usbloader/wbfs/wbfs_fat.h index dad80490..09d0f7ff 100644 --- a/source/usbloader/wbfs/wbfs_fat.h +++ b/source/usbloader/wbfs/wbfs_fat.h @@ -11,7 +11,6 @@ class Wbfs_Fat: public Wbfs { public: Wbfs_Fat(u32 device, u32 lba, u32 size); - ~Wbfs_Fat(); virtual s32 Open(); virtual void Close(); diff --git a/source/usbloader/wbfs/wbfs_rw.c b/source/usbloader/wbfs/wbfs_rw.c index d1aa5346..f759f065 100644 --- a/source/usbloader/wbfs/wbfs_rw.c +++ b/source/usbloader/wbfs/wbfs_rw.c @@ -68,12 +68,12 @@ s32 __ReadUSB(void *fp, u32 lba, u32 count, void *iobuf) u32 cnt = 0; s32 ret; u32 partition_offset = info->partition_lba + (lba-info->partition_lba)*(info->wbfs_sector_size/info->hdd_sector_size); - count *= info->wbfs_sector_size/info->hdd_sector_size; + count *= (info->wbfs_sector_size/info->hdd_sector_size); /* Do reads */ while (cnt < count) { - u8 *ptr = ((u8 *) iobuf) + (cnt * info->wbfs_sector_size); + u8 *ptr = ((u8 *) iobuf) + (cnt * info->hdd_sector_size); u32 sectors = (count - cnt); /* Read sectors is too big */ @@ -96,12 +96,12 @@ s32 __WriteUSB(void *fp, u32 lba, u32 count, void *iobuf) u32 cnt = 0; s32 ret; u32 partition_offset = info->partition_lba + (lba-info->partition_lba)*(info->wbfs_sector_size/info->hdd_sector_size); - count *= info->wbfs_sector_size/info->hdd_sector_size; + count *= (info->wbfs_sector_size/info->hdd_sector_size); /* Do writes */ while (cnt < count) { - u8 *ptr = ((u8 *) iobuf) + (cnt * info->wbfs_sector_size); + u8 *ptr = ((u8 *) iobuf) + (cnt * info->hdd_sector_size); u32 sectors = (count - cnt); /* Write sectors is too big */ diff --git a/source/usbloader/wbfs/wbfs_wbfs.cpp b/source/usbloader/wbfs/wbfs_wbfs.cpp index 4872166a..6fa15c17 100644 --- a/source/usbloader/wbfs/wbfs_wbfs.cpp +++ b/source/usbloader/wbfs/wbfs_wbfs.cpp @@ -4,19 +4,21 @@ #include "usbloader/wbfs.h" #include "wbfs_rw.h" +#define MAX_WBFS_SECTORSIZE 4096 + extern u32 hdd_sector_size; s32 Wbfs_Wbfs::Open() { wbfs_t *part = NULL; - PartInfo.wbfs_sector_size = hdd_sector_size; + PartInfo.wbfs_sector_size = MAX_WBFS_SECTORSIZE; PartInfo.hdd_sector_size = hdd_sector_size; PartInfo.partition_lba = lba; PartInfo.partition_num_sec = size; - u8 * buffer = (u8 *) malloc(hdd_sector_size); - memset(buffer, 0, hdd_sector_size); + u8 * buffer = (u8 *) malloc(MAX_WBFS_SECTORSIZE); + memset(buffer, 0, MAX_WBFS_SECTORSIZE); if(readCallback(&PartInfo, lba, 1, buffer) < 0) { @@ -31,10 +33,14 @@ s32 Wbfs_Wbfs::Open() if (head.magic != wbfs_htonl(WBFS_MAGIC)) return -1; + /* Set correct sector values for wbfs read/write */ PartInfo.wbfs_sector_size = 1 << head.hd_sec_sz_s; + PartInfo.partition_num_sec = head.n_hd_sec; /* Open partition */ - part = wbfs_open_partition(readCallback, writeCallback, &PartInfo, 1 << head.hd_sec_sz_s, head.n_hd_sec, lba, 0); + part = wbfs_open_partition(readCallback, writeCallback, &PartInfo, + PartInfo.wbfs_sector_size, PartInfo.partition_num_sec, + lba, 0); if (!part) return -1; /* Close current hard disk */ @@ -79,10 +85,18 @@ s32 Wbfs_Wbfs::Format() HDD_Inf.partition_lba = lba; HDD_Inf.partition_num_sec = size; + //! If size is over 500GB in sectors and sector size is 512 + //! set 2048 as hdd sector size + if(size > 1048576000 && hdd_sector_size == 512) + { + HDD_Inf.wbfs_sector_size = 2048; + HDD_Inf.partition_num_sec = size/(2048/hdd_sector_size); + } + wbfs_t *partition = NULL; /* Reset partition */ - partition = wbfs_open_partition(readCallback, writeCallback, &PartInfo, hdd_sector_size, size, lba, 1); + partition = wbfs_open_partition(readCallback, writeCallback, &HDD_Inf, HDD_Inf.wbfs_sector_size, HDD_Inf.partition_num_sec, lba, 1); if (!partition) return -1; /* Free memory */