diff --git a/Makefile b/Makefile index 4c3525f4..1a1fef4a 100644 --- a/Makefile +++ b/Makefile @@ -91,13 +91,13 @@ export OFILES := $(CPPFILES:.cpp=.o) $(CFILES:.c=.o) \ export INCLUDE := $(foreach dir,$(INCLUDES), -iquote $(CURDIR)/$(dir)) \ $(foreach dir,$(LIBDIRS),-I$(dir)/include) \ -I$(CURDIR)/$(BUILD) \ - -I$(LIBOGC_INC) + -I$(LIBOGC_INC) -I$(PORTLIBS)/include #--------------------------------------------------------------------------------- # build a list of library paths #--------------------------------------------------------------------------------- export LIBPATHS := $(foreach dir,$(LIBDIRS),-L$(dir)/lib) \ - -L$(LIBOGC_LIB) + -L$(LIBOGC_LIB) -L$(PORTLIBS)/lib export OUTPUT := $(CURDIR)/$(TARGET) .PHONY: $(BUILD) clean diff --git a/source/devicemounter.c b/source/devicemounter.c index b9c21b83..82be74bc 100644 --- a/source/devicemounter.c +++ b/source/devicemounter.c @@ -3,6 +3,7 @@ #include #include #include +#include #include #include #include @@ -13,6 +14,8 @@ #include #include "devicemounter.h" +#define MAX_SECTOR_SIZE 4096 + //these are the only stable and speed is good #define CACHE 8 #define SECTORS 64 @@ -54,36 +57,41 @@ int USBDevice_Init() return -1; int i; - MASTER_BOOT_RECORD mbr; - char BootSector[512]; + MASTER_BOOT_RECORD *mbr = (MASTER_BOOT_RECORD *) malloc(MAX_SECTOR_SIZE); + char *BootSector = (char *) malloc(MAX_SECTOR_SIZE); + if(!mbr || !BootSector) + return -1; - __io_usbstorage.readSectors(0, 1, &mbr); + __io_usbstorage.readSectors(0, 1, mbr); for(i = 0; i < 4; ++i) { - if(mbr.partitions[i].type == 0) + if(mbr->partitions[i].type == 0) continue; - __io_usbstorage.readSectors(le32(mbr.partitions[i].lba_start), 1, BootSector); + __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); + 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); + 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) + 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); + ext2Mount(DeviceName[USB1+i], &__io_usbstorage, le32(mbr->partitions[i].lba_start), CACHE, SECTORS, EXT2_FLAG_DEFAULT); } } + free(mbr); + free(BootSector); + return -1; }