Ejemplo n.º 1
0
Disk*
diskinit(void)
{
	Disk *d;

	d = emalloc(sizeof(Disk));
	d->fd = tempdisk();
	if(d->fd < 0){
		fprint(2, "sam: can't create temp file: %r\n");
		exits("diskinit");
	}
	return d;
}
Ejemplo n.º 2
0
CMBR::CMBR(const TCHAR* deviceName, HANDLE hDevice)
{
	m_pPhysRawDisk = NULL;
	VOLUME_DISK_EXTENTS extents;
	memset(&extents, 0, sizeof(extents));
	DWORD byteswritten = 0;
	if (!hDevice)
	{
		CRawDisk tempdisk(deviceName);
		hDevice = tempdisk.getHandle();
		if (!DeviceIoControl(hDevice, IOCTL_VOLUME_GET_VOLUME_DISK_EXTENTS, NULL, 0, &extents, sizeof(extents), &byteswritten, NULL))
		{
			cout << "Error getting Physical Device (" << GetLastError() << "), aborting...\n";
			throw "Error in MBR (" __FILE__ ") attaining physcial device";
		}
	}
	else
	{
		if (!DeviceIoControl(hDevice, IOCTL_VOLUME_GET_VOLUME_DISK_EXTENTS, NULL, 0, &extents, sizeof(extents), &byteswritten, NULL))
		{
			cout << "Error getting Physical Device (" << GetLastError() << "), aborting...\n";
			throw "Error in MBR (" __FILE__ ") attaining physcial device";
		}
	}
	m_hDevice = hDevice;
	if (!DeviceIoControl(hDevice, IOCTL_DISK_GET_DRIVE_GEOMETRY, NULL, 0, &geometry, sizeof(geometry), &byteswritten, NULL))
	{
		cout << "Error getting Physical Device (" << GetLastError() << "), aborting...\n";
		throw "Error in MBR (" __FILE__ ") attaining physcial device";
	}
	int nPhysDrive = extents.Extents[0].DiskNumber;
	tstring path = tstring(_T("\\\\.\\PhysicalDrive") + to_tstring(nPhysDrive));
	m_physicalpath = path;
	m_pPhysRawDisk = new CRawDisk(path.c_str());
	m_pPhysRawDisk->setSectorSize(geometry.BytesPerSector);
	PARTITION_INFORMATION_EX partinfo;
	DWORD read = 0;
	if (!DeviceIoControl(hDevice, IOCTL_DISK_GET_PARTITION_INFO_EX, NULL, 0, &partinfo, sizeof(partinfo), &read, NULL))
		throw "Cannot get partititon information";
	m_partsize = partinfo.PartitionLength.QuadPart / geometry.BytesPerSector;
}