s32 USBStorage2_Init(u32 port)
{
	if(hddInUse[port])
		return 0;

	/* Create heap */
	if (hid < 0)
	{
		hid = iosCreateHeap(UMS_HEAPSIZE);
		if (hid < 0) return IPC_ENOMEM;
	}

	/* Open USB device */
	if (fd < 0) fd = IOS_Open(fs, 0);
	if (fd < 0) fd = IOS_Open(fs2, 0);
	if (fd < 0) fd = IOS_Open(fs3, 0);
	if (fd < 0) return fd;

	USBStorage2_SetPort(port);

	/* Initialize USB storage */
	IOS_IoctlvFormat(hid, fd, USB_IOCTL_UMS_INIT, ":");

	/* Get device capacity */
	if (USBStorage2_GetCapacity(port, &hdd_sector_size[port]) == 0)
		return IPC_ENOENT;

	hddInUse[port] = true;

	return 0; // 0->HDD, 1->DVD
}
Exemple #2
0
s32 Partition_GetEntries(u32 device, partitionEntry *outbuf, u32 *outval)
{
	static partitionTable table ATTRIBUTE_ALIGN(32);

	u32 cnt, sector_size;
	s32 ret;

	/* Read from specified device */
	switch (device) {
	case WBFS_DEVICE_USB: {
		/* Get sector size */
		ret = USBStorage2_GetCapacity(&sector_size);
		if (ret < 0)
			return ret;

		/* Read partition table */
		ret = USBStorage2_ReadSectors(0, 1, &table);
		if (ret < 0)
			return ret;

		break;
	}

	case WBFS_DEVICE_SDHC: {
		/* SDHC sector size */
		sector_size = SDHC_SECTOR_SIZE;

		/* Read partition table */
		ret = SDHC_ReadSectors(0, 1, &table);
		if (!ret)
			return -1;

		break;
	}

	default:
		return -1;
	}


	/* Swap endianess */
	for (cnt = 0; cnt < 4; cnt++) {
		partitionEntry *entry = &table.entries[cnt];

		entry->sector = swap32(entry->sector);
		entry->size   = swap32(entry->size);
	}

	/* Set partition entries */
	memcpy(outbuf, table.entries, sizeof(table.entries));

	/* Set sector size */
	*outval = sector_size;

	return 0;
}
static bool __usbstorage_IsInserted2(void)
{
	return (USBStorage2_GetCapacity(1, NULL) != 0);
}