Beispiel #1
0
wbfs_t *wbfs_try_open_partition(char *partitionLetter, int reset)
{
	HANDLE *handle;
	char drivePath[8] = "\\\\?\\Z:";
	
	u32 sector_size, sector_count;
	
	if (strlen(partitionLetter) != 1)
	{
		wbfs_error("bad drive name");
		return NULL;
	}

	drivePath[4] = partitionLetter[0];
	
	if (!get_capacity(drivePath, &sector_size, &sector_count))
	{
		return NULL;
	}
	
	handle = CreateFile(drivePath, GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, FILE_FLAG_NO_BUFFERING, NULL);
	
	if (handle == INVALID_HANDLE_VALUE)
	{
		return NULL;
	}
	
	return wbfs_open_partition(read_sector, write_sector, close_handle, handle, sector_size, sector_count, 0, reset);
}
Beispiel #2
0
wbfs_t*wbfs_open_hd(
					rw_sector_callback_t read_hdsector,
					rw_sector_callback_t write_hdsector,
#ifdef WIN32
					close_callback_t close_hd,
#endif
					void *callback_data,
		    int hd_sector_size, 
#ifdef WIN32
					int num_hd_sector,
#else
		    int num_hd_sector __attribute((unused)), 
#endif
		    int reset)
{
	int i
#ifdef UNUSED_STUFF
	= num_hd_sector 
#endif
	, ret;
	u8 *ptr,*tmp_buffer = wbfs_ioalloc(hd_sector_size);
	u8 part_table[16*4];
	ret = read_hdsector(callback_data,0,1,tmp_buffer);
	if(ret)
		return 0;
	//find wbfs partition
	wbfs_memcpy(part_table,tmp_buffer+0x1be,16*4);
	ptr = part_table;
	for(i=0;i<4;i++,ptr+=16)
	{
		u32 part_lba = read_le32_unaligned(ptr+0x8);
		wbfs_head_t *head = (wbfs_head_t *)tmp_buffer;
#ifdef UNUSED_STUFF
		ret = 
#endif
				read_hdsector(callback_data,part_lba,1,tmp_buffer);
		// verify there is the magic.
		if (head->magic == wbfs_htonl(WBFS_MAGIC))
		{
					wbfs_t *p = wbfs_open_partition(	read_hdsector, 
														write_hdsector,
#ifdef WIN32
														close_hd,
#endif
														callback_data, 
														hd_sector_size, 
														0, 
														part_lba,reset
														);
					return p;
		}
	}
	if(reset)// XXX make a empty hd partition..
	{
	}
	return 0;
}
Beispiel #3
0
wbfs_t *wbfs_try_open_partition(char *fn,int reset)
{
	u32 sector_size, n_sector;
	if(!get_capacity(fn,&sector_size,&n_sector))
		return NULL;
	FILE *f = fopen(fn,"r+");
	if (!f)
		return NULL;
	return wbfs_open_partition(wbfs_fread_sector,wbfs_fwrite_sector,f,
				   sector_size ,n_sector,0,reset);
}
Beispiel #4
0
s32 WBFS_Format(u32 lba, u32 size)
{
	wbfs_t *partition = NULL;

	/* Reset partition */
	partition = wbfs_open_partition(readCallback, writeCallback, NULL, sector_size, size, lba, 1);
	if (!partition)
		return -1;

	/* Free memory */
	wbfs_close(partition);

	return 0;
}
Beispiel #5
0
s32 WBFS_OpenLBA(u32 lba, u32 size)
{
	wbfs_t *part = NULL;

	/* Open partition */
	part = wbfs_open_partition(readCallback, writeCallback, NULL, wbfs_dev_sector_size, size, lba, 0);
	if (!part) return -1;

	/* Close current hard disk */
	if (hdd) wbfs_close(hdd);
	hdd = part;

	return 0;
}
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;
}