bool PartitionHandle::Mount(int pos, const char *name, bool forceFAT)
{
	if(valid(pos))
		UnMount(pos);

	if(!name)
		return false;

	if(pos >= (int)MountNameList.size())
		MountNameList.resize(pos + 1);

	MountNameList[pos] = name;
	char DeviceSyn[10];
	memcpy(DeviceSyn, name, 8);
	strcat(DeviceSyn, ":");
	DeviceSyn[9] = '\0';

	//! Some stupid partition manager think they don't need to edit the freaken MBR.
	//! So we need to check the first 64 sectors and see if some partition is there.
	//! libfat does that by default so let's use it.
	if(forceFAT && (strlen(GetFSName(pos)) == 0 || strcmp(GetFSName(pos), "Unknown") == 0))
	{
		if(fatMount(MountNameList[pos].c_str(), interface, 0, CACHE, SECTORS))
		{
			sec_t FAT_startSector = FindFirstValidPartition(interface);
			AddPartition("FAT", FAT_startSector, 0xdeadbeaf, true, 0x0c, 0);
			gprintf("FAT Partition at %s (forceFAT) mounted.\n", DeviceSyn);
			SetWbfsHandle(pos, NULL);
			return true;
		}
	}
	if(!valid(pos))
		return false;

	SetWbfsHandle(pos, NULL);
	if(strncmp(GetFSName(pos), "FAT", 3) == 0 || strcmp(GetFSName(pos), "GUID-Entry") == 0)
	{
		if(fatMount(MountNameList[pos].c_str(), interface, GetLBAStart(pos), CACHE, SECTORS))
		{
			gprintf("FAT Partition at %s mounted.\n", DeviceSyn);
			PartitionList[pos].FSName = "FAT";
			return true;
		}
	}
	else if(strncmp(GetFSName(pos), "NTFS", 4) == 0 || strcmp(GetFSName(pos), "GUID-Entry") == 0)
	{
		if(ntfsMount(MountNameList[pos].c_str(), interface, GetLBAStart(pos), CACHE, SECTORS, NTFS_SHOW_HIDDEN_FILES | NTFS_RECOVER))
		{
			gprintf("NTFS Partition at %s mounted.\n", DeviceSyn);
			PartitionList[pos].FSName = "NTFS";
			return true;
		}
	}
	else if(strncmp(GetFSName(pos), "LINUX", 5) == 0 || strcmp(GetFSName(pos), "GUID-Entry") == 0)
	{
		if(ext2Mount(MountNameList[pos].c_str(), interface, GetLBAStart(pos), CACHE, SECTORS, EXT2_FLAG_DEFAULT))
		{
			gprintf("EXT Partition at %s mounted.\n", DeviceSyn);
			PartitionList[pos].FSName = "LINUX";
			return true;
		}
	}
	else if(strncmp(GetFSName(pos), "WBFS", 4) == 0)
	{
		if(interface == &__io_usbstorage2_port0 || interface == &__io_usbstorage2_port1)
			SetWbfsHandle(pos, wbfs_open_partition(__WBFS_ReadUSB, __WBFS_WriteUSB, NULL, USBStorage2_GetSectorSize(), GetSecCount(pos), GetLBAStart(pos), 0));
		else if(interface == &__io_sdhc)
			SetWbfsHandle(pos, wbfs_open_partition(__WBFS_ReadSDHC, __WBFS_WriteSDHC, NULL, 512, GetSecCount(pos), GetLBAStart(pos), 0));
		if(GetWbfsHandle(pos))
		{
			gprintf("WBFS Partition at %s mounted.\n", DeviceSyn);
			PartitionList[pos].FSName = "WBFS";
			return true;
		}
	}
	/* FAIL */
	MountNameList[pos].clear();
	return false;
}
Example #2
0
int main(int argc, char **argv)
{
    long val;
    long long val2;
    int ret;
    
    if (argc < 2)
    {
        printf("Usage: %s str [base]\n", argv[0]);
        return -1;
    }
    
    printf("GetCycleCount: %lld, GetMsCount: %lld, GetSecCount: %lld\n", GetCycleCount(), GetMsCount(), GetSecCount());
    printf("GetCycleCount: %lld, GetMsCount: %lld, GetSecCount: %lld\n", GetCycleCount(), GetMsCount(), GetSecCount());

    ret = StrToLong(argv[1], &val, (argc < 3) ? 0 : atoi(argv[2]));
    if (ret < 0)
    {
        printf("StrToLong failed. [ret: %d]\n", ret);
    }
    else
    {
        printf("%ld\n", val);
    }

    ret = StrToLongLong(argv[1], &val2, (argc < 3) ? 0 : atoi(argv[2]));
    if (ret < 0)
    {
        printf("StrToLongLong failed. [ret: %d]\n", ret);
    }
    else
    {
        printf("%lld\n", val2);
    }
    
    usleep(1000 * 1000);

    printf("GetCycleCount: %lld, GetMsCount: %lld, GetSecCount: %lld\n", GetCycleCount(), GetMsCount(), GetSecCount());
    printf("GetCycleCount: %lld, GetMsCount: %lld, GetSecCount: %lld\n", GetCycleCount(), GetMsCount(), GetSecCount());
    
    return 0;
        
}