usbloadergx/source/devicemounter.c
dimok321 1618b4b1e0 USB Loader GX Release V2.2
New:
- Added game categories and filter games list by categories (Can be imported from WiiTDB).
- Wiinertag support.
- Supporting arguments from meta.xml on boot (--ios=xxx and --usbport=x) (Requires Homebrew Channel 1.0.7+ or 
  UNEO Forwarder v3.0).
- New ehci modules by Rodries with better drive compatibility.
- Added two new video modes to force progressive video mode, 'FORCE PAL480p' and 'FORCE NTSC480p'.
- Added Sneek Video Patch mode.
- Added new 'Inherit' setting for game settings named "Use global". If that option is set then the main loader 
  setting is used.
- Full d2x cIOS support with it's new features (Block IOS Reload, Return To, Sector Sizes > 512).
- Support for sector sizes > 512B with FAT32/NTFS (Requires d2x v6+)
- Real support for simultanious use of both USB ports without switching the 2nd drive temporary off. (Requires 
  Hermes cIOS or Rodries MOD of the Hermes cIOS (recommended))
- Added two new settings menus
- Added saving of game browser position when returning to USB Loader GX

Changes:
- Improved several GUI controls/navigations
- Changed settings menu layout and sorted the items to their correct place (HDD menu, features menu)
- Set games settings to use the global setting by default, set to "use global" to use the main loader settings.
- Use TinyXML instead of MXML (better XML support)
- Updated to new libs (libogc, libfat, libext2fs, libntfs)

Fix:  
- "Return to" option now work for all games, even problematic games like Prince of Persia. (Requires d2x v4+)
- Xflip setting fixed.
- Fix the parental lock of Individual game settings (Thanks to NJ7)
- Fix Theme downloader
- Fixed reset of the loader when loading game with IOS reload and disabled WiiTDB titles
- Fixed timeout timer on startup to count correctly.
- Fixed reversed disc image download when Custom/Original option is selected
- Fixed reload of game list after a game rename
- Fixed horizontal text scrolling
- Fixed booting games by arguments (headless id feature)
- Fixed We Dare game boot (thx oggzee)



R1099 Change Log:
    *Added IOS225 from Rodries cIOS Installer MOD to Hermes IOS types

New Forwarder V3.0 Changes:
    *added support for ext partitions
    *added support for arguments from xml
    *clean up of source
2011-06-29 20:45:40 +00:00

126 lines
3.8 KiB
C

#include <gccore.h>
#include <ogc/mutex.h>
#include <ogc/system.h>
#include <ogc/usbstorage.h>
#include <ogc/lwp_watchdog.h>
#include <string.h>
#include <stdio.h>
#include <fat.h>
#include <ntfs.h>
#include <ext2.h>
#include <sdcard/wiisd_io.h>
#include <unistd.h>
#include <time.h>
#include "devicemounter.h"
//these are the only stable and speed is good
#define CACHE 8
#define SECTORS 64
typedef struct _PARTITION_RECORD {
u8 status; /* Partition status; see above */
u8 chs_start[3]; /* Cylinder-head-sector address to first block of partition */
u8 type; /* Partition type; see above */
u8 chs_end[3]; /* Cylinder-head-sector address to last block of partition */
u32 lba_start; /* Local block address to first sector of partition */
u32 block_count; /* Number of blocks in partition */
} __attribute__((__packed__)) PARTITION_RECORD;
typedef struct _MASTER_BOOT_RECORD {
u8 code_area[446]; /* Code area; normally empty */
PARTITION_RECORD partitions[4]; /* 4 primary partitions */
u16 signature; /* MBR signature; 0xAA55 */
} __attribute__((__packed__)) MASTER_BOOT_RECORD;
#define PARTITION_TYPE_LINUX 0x83
#define le32(i) (((((u32) i) & 0xFF) << 24) | ((((u32) i) & 0xFF00) << 8) | \
((((u32) i) & 0xFF0000) >> 8) | ((((u32) i) & 0xFF000000) >> 24))
int USBDevice_Init()
{
time_t start = time(0);
while(start-time(0) < 10) // 10 sec
{
if(__io_usbstorage.startup() && __io_usbstorage.isInserted())
break;
usleep(200000); // 1/5 sec
}
if(!__io_usbstorage.startup() || !__io_usbstorage.isInserted())
return -1;
int i;
MASTER_BOOT_RECORD mbr;
char BootSector[512];
__io_usbstorage.readSectors(0, 1, &mbr);
for(i = 0; i < 4; ++i)
{
if(mbr.partitions[i].type == 0)
continue;
__io_usbstorage.readSectors(le32(mbr.partitions[i].lba_start), 1, BootSector);
if(*((u16 *) (BootSector + 0x1FE)) == 0x55AA)
{
//! Partition typ can be missleading the correct partition format. Stupid lazy ass Partition Editors.
if(memcmp(BootSector + 0x36, "FAT", 3) == 0 || memcmp(BootSector + 0x52, "FAT", 3) == 0)
{
fatMount(DeviceName[USB1+i], &__io_usbstorage, le32(mbr.partitions[i].lba_start), CACHE, SECTORS);
}
else if (memcmp(BootSector + 0x03, "NTFS", 4) == 0)
{
ntfsMount(DeviceName[USB1+i], &__io_usbstorage, le32(mbr.partitions[i].lba_start), CACHE, SECTORS, NTFS_SHOW_HIDDEN_FILES | NTFS_RECOVER | NTFS_IGNORE_CASE);
}
}
else if(mbr.partitions[i].type == PARTITION_TYPE_LINUX)
{
ext2Mount(DeviceName[USB1+i], &__io_usbstorage, le32(mbr.partitions[i].lba_start), CACHE, SECTORS, EXT2_FLAG_DEFAULT);
}
}
return -1;
}
void USBDevice_deInit()
{
int dev;
char Name[20];
for(dev = USB1; dev <= USB4; ++dev)
{
sprintf(Name, "%s:/", DeviceName[dev]);
fatUnmount(Name);
ntfsUnmount(Name, true);
}
//Let's not shutdown so it stays awake for the application
__io_usbstorage.shutdown();
USB_Deinitialize();
}
int SDCard_Init()
{
if(!__io_wiisd.startup() || !__io_wiisd.isInserted())
return -1;
if (fatMount(DeviceName[SD], &__io_wiisd, 0, CACHE, SECTORS))
return 1;
return -1;
}
void SDCard_deInit()
{
char Name[20];
sprintf(Name, "%s:/", DeviceName[SD]);
//closing all open Files write back the cache and then shutdown em!
fatUnmount(Name);
//Let's not shutdown so it stays awake for the application
__io_wiisd.shutdown();
}