*let's get rid of last compile warning

This commit is contained in:
dimok321 2010-09-24 15:08:03 +00:00
parent f8c1692809
commit 5bf2c813b6
2 changed files with 420 additions and 419 deletions

View File

@ -2,8 +2,8 @@
<app version="1"> <app version="1">
<name> USB Loader GX</name> <name> USB Loader GX</name>
<coder>USB Loader GX Team</coder> <coder>USB Loader GX Team</coder>
<version>1.0 r967</version> <version>1.0 r968</version>
<release_date>201009241313</release_date> <release_date>201009241346</release_date>
<short_description>Loads games from USB-devices</short_description> <short_description>Loads games from USB-devices</short_description>
<long_description>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. <long_description>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. The interactive GUI is completely controllable with WiiMote, Classic Controller or GC Controller.

View File

@ -1,417 +1,418 @@
// Modified by oggzee // Modified by oggzee
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include <ogcsys.h> #include <ogcsys.h>
#include <unistd.h> #include <unistd.h>
#include "partition_usbloader.h" #include "partition_usbloader.h"
#include "sdhc.h" #include "sdhc.h"
#include "usbstorage2.h" #include "usbstorage2.h"
#include "utils.h" #include "utils.h"
#include "wbfs.h" #include "wbfs.h"
#include "libwbfs/libwbfs.h" #include "libwbfs/libwbfs.h"
/* 'partition table' structure */ /* 'partition table' structure */
typedef struct typedef struct
{ {
/* Zero bytes */ /* Zero bytes */
u8 padding[446]; u8 padding[446];
/* Partition table entries */ /* Partition table entries */
partitionEntry entries[MAX_PARTITIONS]; partitionEntry entries[MAX_PARTITIONS];
}ATTRIBUTE_PACKED partitionTable; }ATTRIBUTE_PACKED partitionTable;
s32 Partition_GetEntries(u32 device, partitionEntry *outbuf, u32 *outval) s32 Partition_GetEntries(u32 device, partitionEntry *outbuf, u32 *outval)
{ {
static partitionTable table ATTRIBUTE_ALIGN( 32 ); static partitionTable table ATTRIBUTE_ALIGN( 32 );
u32 cnt, sector_size; u32 cnt, sector_size;
s32 ret; s32 ret;
/* Read from specified device */ /* Read from specified device */
switch (device) switch (device)
{ {
case WBFS_DEVICE_USB: case WBFS_DEVICE_USB:
{ {
/* Get sector size */ /* Get sector size */
ret = USBStorage2_GetCapacity(&sector_size); ret = USBStorage2_GetCapacity(&sector_size);
if (ret == 0) return -1; if (ret == 0) return -1;
/* Read partition table */ /* Read partition table */
ret = USBStorage2_ReadSectors(0, 1, &table); ret = USBStorage2_ReadSectors(0, 1, &table);
if (ret < 0) return ret; if (ret < 0) return ret;
break; break;
} }
case WBFS_DEVICE_SDHC: case WBFS_DEVICE_SDHC:
{ {
/* SDHC sector size */ /* SDHC sector size */
sector_size = SDHC_SECTOR_SIZE; sector_size = SDHC_SECTOR_SIZE;
/* Read partition table */ /* Read partition table */
ret = SDHC_ReadSectors(0, 1, &table); ret = SDHC_ReadSectors(0, 1, &table);
if (!ret) return -1; if (!ret) return -1;
break; break;
} }
default: default:
return -1; return -1;
} }
/* Swap endianess */ /* Swap endianess */
for (cnt = 0; cnt < 4; cnt++) for (cnt = 0; cnt < 4; cnt++)
{ {
partitionEntry *entry = &table.entries[cnt]; partitionEntry *entry = &table.entries[cnt];
entry->sector = swap32(entry->sector); entry->sector = swap32(entry->sector);
entry->size = swap32(entry->size); entry->size = swap32(entry->size);
} }
/* Set partition entries */ /* Set partition entries */
memcpy(outbuf, table.entries, sizeof(table.entries)); memcpy(outbuf, table.entries, sizeof(table.entries));
/* Set sector size */ /* Set sector size */
*outval = sector_size; *outval = sector_size;
return 0; return 0;
} }
bool Device_ReadSectors(u32 device, u32 sector, u32 count, void *buffer) bool Device_ReadSectors(u32 device, u32 sector, u32 count, void *buffer)
{ {
s32 ret; s32 ret;
/* Read from specified device */ /* Read from specified device */
switch (device) switch (device)
{ {
case WBFS_DEVICE_USB: case WBFS_DEVICE_USB:
ret = USBStorage2_ReadSectors(sector, count, buffer); ret = USBStorage2_ReadSectors(sector, count, buffer);
if (ret < 0) return false; if (ret < 0) return false;
return true; return true;
case WBFS_DEVICE_SDHC: case WBFS_DEVICE_SDHC:
return SDHC_ReadSectors(sector, count, buffer); return SDHC_ReadSectors(sector, count, buffer);
} }
return false; return false;
} }
bool Device_WriteSectors(u32 device, u32 sector, u32 count, void *buffer) bool Device_WriteSectors(u32 device, u32 sector, u32 count, void *buffer)
{ {
s32 ret; s32 ret;
/* Read from specified device */ /* Read from specified device */
switch (device) switch (device)
{ {
case WBFS_DEVICE_USB: case WBFS_DEVICE_USB:
ret = USBStorage2_WriteSectors(sector, count, buffer); ret = USBStorage2_WriteSectors(sector, count, buffer);
if (ret < 0) return false; if (ret < 0) return false;
return true; return true;
case WBFS_DEVICE_SDHC: case WBFS_DEVICE_SDHC:
return SDHC_WriteSectors(sector, count, buffer); return SDHC_WriteSectors(sector, count, buffer);
} }
return false; return false;
} }
s32 Partition_GetEntriesEx(u32 device, partitionEntry *outbuf, u32 *psect_size, u8 *num) s32 Partition_GetEntriesEx(u32 device, partitionEntry *outbuf, u32 *psect_size, u8 *num)
{ {
static partitionTable table ATTRIBUTE_ALIGN( 32 ); static u8 Buffer[sizeof(partitionTable)] ATTRIBUTE_ALIGN( 32 );
partitionEntry *entry; partitionTable *table = (partitionTable *) Buffer;
partitionEntry *entry;
u32 i, sector_size;
s32 ret; u32 i, sector_size;
int maxpart = *num; s32 ret;
int maxpart = *num;
// Get sector size
switch (device) // Get sector size
{ switch (device)
case WBFS_DEVICE_USB: {
ret = USBStorage2_GetCapacity(&sector_size); case WBFS_DEVICE_USB:
if (ret == 0) return -1; ret = USBStorage2_GetCapacity(&sector_size);
break; if (ret == 0) return -1;
case WBFS_DEVICE_SDHC: break;
sector_size = SDHC_SECTOR_SIZE; case WBFS_DEVICE_SDHC:
break; sector_size = SDHC_SECTOR_SIZE;
default: break;
return -1; default:
} return -1;
/* Set sector size */ }
*psect_size = sector_size; /* Set sector size */
*psect_size = sector_size;
u32 ext = 0;
u32 next = 0; u32 ext = 0;
u32 next = 0;
// Read partition table
ret = Device_ReadSectors(device, 0, 1, &table); // Read partition table
if (!ret) return -1; ret = Device_ReadSectors(device, 0, 1, table);
// Check if it's a RAW WBFS disc, without partition table if (!ret) return -1;
if (get_fs_type(&table) == FS_TYPE_WBFS) // Check if it's a RAW WBFS disc, without partition table
{ if (get_fs_type(table) == FS_TYPE_WBFS)
memset(outbuf, 0, sizeof(table.entries)); {
wbfs_head_t *head = (wbfs_head_t*) &table; memset(outbuf, 0, sizeof(table->entries));
outbuf->size = wbfs_ntohl( head->n_hd_sec ); wbfs_head_t * head = (wbfs_head_t *) Buffer;
*num = 1; outbuf->size = wbfs_ntohl( head->n_hd_sec );
return 0; *num = 1;
} return 0;
/* Swap endianess */ }
for (i = 0; i < 4; i++) /* Swap endianess */
{ for (i = 0; i < 4; i++)
entry = &table.entries[i]; {
entry->sector = swap32(entry->sector); entry = &table->entries[i];
entry->size = swap32(entry->size); entry->sector = swap32(entry->sector);
if (!ext && part_is_extended(entry->type)) entry->size = swap32(entry->size);
{ if (!ext && part_is_extended(entry->type))
ext = entry->sector; {
} ext = entry->sector;
} }
/* Set partition entries */ }
memcpy(outbuf, table.entries, sizeof(table.entries)); /* Set partition entries */
// num primary memcpy(outbuf, table->entries, sizeof(table->entries));
*num = 4; // num primary
*num = 4;
if (!ext) return 0;
if (!ext) return 0;
next = ext;
// scan extended partition for logical next = ext;
for (i = 0; i < maxpart - 4; i++) // scan extended partition for logical
{ for (i = 0; i < maxpart - 4; i++)
ret = Device_ReadSectors(device, next, 1, &table); {
if (!ret) break; ret = Device_ReadSectors(device, next, 1, table);
if (i == 0) if (!ret) break;
{ if (i == 0)
// handle the invalid scenario where wbfs is on an EXTENDED {
// partition instead of on the Logical inside Extended. // handle the invalid scenario where wbfs is on an EXTENDED
if (get_fs_type(&table) == FS_TYPE_WBFS) break; // partition instead of on the Logical inside Extended.
} if (get_fs_type(&table) == FS_TYPE_WBFS) break;
entry = &table.entries[0]; }
entry->sector = swap32(entry->sector); entry = &table->entries[0];
entry->size = swap32(entry->size); entry->sector = swap32(entry->sector);
if (entry->type && entry->size && entry->sector) entry->size = swap32(entry->size);
{ if (entry->type && entry->size && entry->sector)
// rebase to abolute address {
entry->sector += next; // rebase to abolute address
// add logical entry->sector += next;
memcpy(&outbuf[*num], entry, sizeof(*entry)); // add logical
(*num)++; memcpy(&outbuf[*num], entry, sizeof(*entry));
// get next (*num)++;
entry++; // get next
if (entry->type && entry->size && entry->sector) entry++;
{ if (entry->type && entry->size && entry->sector)
next = ext + swap32(entry->sector); {
} next = ext + swap32(entry->sector);
else }
{ else
break; {
} break;
} }
} }
}
return 0;
} return 0;
}
bool part_is_extended(int type)
{ bool part_is_extended(int type)
if (type == 0x05) return true; {
if (type == 0x0f) return true; if (type == 0x05) return true;
return false; if (type == 0x0f) return true;
} return false;
}
bool part_is_data(int type)
{ bool part_is_data(int type)
if (type && !part_is_extended(type)) return true; {
return false; if (type && !part_is_extended(type)) return true;
} return false;
}
bool part_valid_data(partitionEntry *entry)
{ bool part_valid_data(partitionEntry *entry)
if (entry->size && entry->type && entry->sector) {
{ if (entry->size && entry->type && entry->sector)
return part_is_data(entry->type); {
} return part_is_data(entry->type);
return false; }
} return false;
}
char* part_type_data(int type)
{ char* part_type_data(int type)
switch (type) {
{ switch (type)
case 0x01: {
return "FAT12"; case 0x01:
case 0x04: return "FAT12";
return "FAT16"; case 0x04:
case 0x06: return "FAT16";
return "FAT16"; //+ case 0x06:
case 0x07: return "FAT16"; //+
return "NTFS"; case 0x07:
case 0x0b: return "NTFS";
return "FAT32"; case 0x0b:
case 0x0c: return "FAT32";
return "FAT32"; case 0x0c:
case 0x0e: return "FAT32";
return "FAT16"; case 0x0e:
case 0x82: return "FAT16";
return "LxSWP"; case 0x82:
case 0x83: return "LxSWP";
return "LINUX"; case 0x83:
case 0x8e: return "LINUX";
return "LxLVM"; case 0x8e:
case 0xa8: return "LxLVM";
return "OSX"; case 0xa8:
case 0xab: return "OSX";
return "OSXBT"; case 0xab:
case 0xaf: return "OSXBT";
return "OSXHF"; case 0xaf:
case 0xe8: return "OSXHF";
return "LUKS"; case 0xe8:
} return "LUKS";
return NULL; }
} return NULL;
}
char *part_type_name(int type)
{ char *part_type_name(int type)
static char unk[8]; {
if (type == 0) return "UNUSED"; static char unk[8];
if (part_is_extended(type)) return "EXTEND"; if (type == 0) return "UNUSED";
char *p = part_type_data(type); if (part_is_extended(type)) return "EXTEND";
if (p) return p; char *p = part_type_data(type);
sprintf(unk, "UNK-%02x", type); if (p) return p;
return unk; sprintf(unk, "UNK-%02x", type);
} return unk;
}
int get_fs_type(void *buff)
{ int get_fs_type(void *buff)
char *buf = buff; {
// WBFS char *buf = buff;
wbfs_head_t *head = (wbfs_head_t *) buff; // WBFS
if (head->magic == wbfs_htonl( WBFS_MAGIC )) return FS_TYPE_WBFS; wbfs_head_t *head = (wbfs_head_t *) buff;
// 55AA if (head->magic == wbfs_htonl( WBFS_MAGIC )) return FS_TYPE_WBFS;
if (buf[0x1FE] == 0x55 && buf[0x1FF] == 0xAA) // 55AA
{ if (buf[0x1FE] == 0x55 && buf[0x1FF] == 0xAA)
// FAT {
if (memcmp(buf + 0x36, "FAT", 3) == 0) return FS_TYPE_FAT16; // FAT
if (memcmp(buf + 0x52, "FAT", 3) == 0) return FS_TYPE_FAT32; if (memcmp(buf + 0x36, "FAT", 3) == 0) return FS_TYPE_FAT16;
// NTFS if (memcmp(buf + 0x52, "FAT", 3) == 0) return FS_TYPE_FAT32;
if (memcmp(buf + 0x03, "NTFS", 4) == 0) return FS_TYPE_NTFS; // NTFS
} if (memcmp(buf + 0x03, "NTFS", 4) == 0) return FS_TYPE_NTFS;
return FS_TYPE_UNK; }
} return FS_TYPE_UNK;
}
int get_part_fs(int fs_type)
{ int get_part_fs(int fs_type)
switch (fs_type) {
{ switch (fs_type)
case FS_TYPE_FAT32: {
return PART_FS_FAT; case FS_TYPE_FAT32:
case FS_TYPE_NTFS: return PART_FS_FAT;
return PART_FS_NTFS; case FS_TYPE_NTFS:
case FS_TYPE_WBFS: return PART_FS_NTFS;
return PART_FS_WBFS; case FS_TYPE_WBFS:
default: return PART_FS_WBFS;
return -1; default:
} return -1;
} }
}
bool is_type_fat(int type)
{ bool is_type_fat(int type)
return (type == FS_TYPE_FAT16 || type == FS_TYPE_FAT32); {
} return (type == FS_TYPE_FAT16 || type == FS_TYPE_FAT32);
}
char *get_fs_name(int i)
{ char *get_fs_name(int i)
switch (i) {
{ switch (i)
case FS_TYPE_FAT16: {
return "FAT16"; case FS_TYPE_FAT16:
case FS_TYPE_FAT32: return "FAT16";
return "FAT32"; case FS_TYPE_FAT32:
case FS_TYPE_NTFS: return "FAT32";
return "NTFS"; case FS_TYPE_NTFS:
case FS_TYPE_WBFS: return "NTFS";
return "WBFS"; case FS_TYPE_WBFS:
} return "WBFS";
return ""; }
} return "";
}
s32 Partition_GetList(u32 device, PartList *plist)
{ s32 Partition_GetList(u32 device, PartList *plist)
partitionEntry *entry = NULL; {
PartInfo *pinfo = NULL; partitionEntry *entry = NULL;
int i, ret; PartInfo *pinfo = NULL;
int i, ret;
memset(plist, 0, sizeof(PartList));
memset(plist, 0, sizeof(PartList));
// Get partition entries
plist->num = MAX_PARTITIONS_EX; // Get partition entries
ret = Partition_GetEntriesEx(device, plist->pentry, &plist->sector_size, &plist->num); plist->num = MAX_PARTITIONS_EX;
if (ret < 0) ret = Partition_GetEntriesEx(device, plist->pentry, &plist->sector_size, &plist->num);
{ if (ret < 0)
return -1; {
} return -1;
// check for RAW WBFS disc }
if (plist->num == 1) // check for RAW WBFS disc
{ if (plist->num == 1)
pinfo = &plist->pinfo[0]; {
entry = &plist->pentry[0]; pinfo = &plist->pinfo[0];
plist->wbfs_n = 1; entry = &plist->pentry[0];
pinfo->wbfs_i = pinfo->index = 1; plist->wbfs_n = 1;
return 0; pinfo->wbfs_i = pinfo->index = 1;
} return 0;
}
char buf[plist->sector_size];
char buf[plist->sector_size];
// scan partitions for filesystem type
for (i = 0; i < plist->num; i++) // scan partitions for filesystem type
{ for (i = 0; i < plist->num; i++)
pinfo = &plist->pinfo[i]; {
entry = &plist->pentry[i]; pinfo = &plist->pinfo[i];
if (!entry->size) continue; entry = &plist->pentry[i];
if (!entry->type) continue; if (!entry->size) continue;
if (!entry->sector) continue; if (!entry->type) continue;
// even though wrong, it's possible WBFS is on an extended part. if (!entry->sector) continue;
//if (!part_is_data(entry->type)) continue; // even though wrong, it's possible WBFS is on an extended part.
if (!Device_ReadSectors(device, entry->sector, 1, buf)) continue; //if (!part_is_data(entry->type)) continue;
pinfo->fs_type = get_fs_type(buf); if (!Device_ReadSectors(device, entry->sector, 1, buf)) continue;
if (pinfo->fs_type == FS_TYPE_WBFS) pinfo->fs_type = get_fs_type(buf);
{ if (pinfo->fs_type == FS_TYPE_WBFS)
// multiple wbfs on sdhc not supported {
if (device == WBFS_DEVICE_SDHC && (plist->wbfs_n > 1 || i > 4)) continue; // multiple wbfs on sdhc not supported
plist->wbfs_n++; if (device == WBFS_DEVICE_SDHC && (plist->wbfs_n > 1 || i > 4)) continue;
pinfo->wbfs_i = pinfo->index = plist->wbfs_n; plist->wbfs_n++;
} pinfo->wbfs_i = pinfo->index = plist->wbfs_n;
else if (is_type_fat(pinfo->fs_type)) }
{ else if (is_type_fat(pinfo->fs_type))
plist->fat_n++; {
pinfo->fat_i = pinfo->index = plist->fat_n; plist->fat_n++;
} pinfo->fat_i = pinfo->index = plist->fat_n;
else if (pinfo->fs_type == FS_TYPE_NTFS) }
{ else if (pinfo->fs_type == FS_TYPE_NTFS)
plist->ntfs_n++; {
pinfo->ntfs_i = pinfo->index = plist->ntfs_n; plist->ntfs_n++;
} pinfo->ntfs_i = pinfo->index = plist->ntfs_n;
pinfo->part_fs = get_part_fs(pinfo->fs_type); }
} pinfo->part_fs = get_part_fs(pinfo->fs_type);
return 0; }
} return 0;
}
int Partition_FixEXT(u32 device, u8 part)
{ int Partition_FixEXT(u32 device, u8 part)
static partitionTable table ATTRIBUTE_ALIGN( 32 ); {
int ret; static partitionTable table ATTRIBUTE_ALIGN( 32 );
int ret;
if (part > 3) return -1;
// Read partition table if (part > 3) return -1;
ret = Device_ReadSectors(device, 0, 1, &table); // Read partition table
if (!ret) return -1; ret = Device_ReadSectors(device, 0, 1, &table);
if (part_is_extended(table.entries[part].type)) if (!ret) return -1;
{ if (part_is_extended(table.entries[part].type))
table.entries[part].type = 0x0b; // FAT32 {
ret = Device_WriteSectors(device, 0, 1, &table); table.entries[part].type = 0x0b; // FAT32
if (!ret) return -1; ret = Device_WriteSectors(device, 0, 1, &table);
return 0; if (!ret) return -1;
} return 0;
return -1; }
} return -1;
}