[Depreciated][Patch] VHD support

Post new patches here!
Post Reply
shermanp
Posts: 70
Joined: Sat 18 Feb, 2017 2:09 am

[Depreciated][Patch] VHD support

Post by shermanp » Mon 04 Jun, 2018 6:20 am

2018-06-29: I consider this patch DEPRECIATED. I have now added a lot more functionality, including dynamic VHD support. I created a new topic for the patch, available here: viewtopic.php?f=4&t=3056


After tearing my hair out figuring out wx-config.c, I have finally added initial VHD support to PCem.

With this patch, PCem will be able to load VHD files. Only fixed VHD images are supported at this time, no dynamic or differencing image support.

PCem cannot currently create VHD images. That will be next, when I/we can figure out the best method of creating UUID's in a simple, cross platform manner.

Windows users can create VHD image files using the "Disk Management" tool built into Windows.

@SarahWalker I am rather inexperienced with C, so if you have any problems with my patch, please let me know, or feel free to alter it. I will not be offended.

Some of what I've done may be overkill for loading existing VHD files, but has been added in anticipation of VHD creation support.

Note, I have not regenerated Makefile.in, although I've added the additions to the other makefiles including Makefile.am

EDIT: I am going to be making some changes, so it's not really ready yet.

EDIT2 2018-06-07: I have a working implementation of VHD support (including creation). I would like it to be tested by somebody else to make sure I haven't made any silly mistakes. Attached patch has been updated.

EDIT3 2018-06-07: Updating the patch again. I noticed I had an oopsie with one of the makefiles.

EDIT4 2018-06-08: Updated patch to fix broken large VHD images.

EDIT5 2018-06-09 Did some refactoring. Added some more checks to test for possible corruption. Now sets the HD type for MFM drives on import.
Last edited by shermanp on Fri 29 Jun, 2018 7:03 am, edited 6 times in total.

User avatar
resle
Posts: 50
Joined: Mon 23 Feb, 2015 8:00 am

Re: [Patch] Initial VHD support

Post by resle » Mon 04 Jun, 2018 8:35 am

Could this RFC-compliant function that appears in a few JS libraries be ported to C?
Not that I have the palest idea of how regular expressions are handled in C, but this function seems to be abstract enough to me.

Code: Select all

function uuid() 
{
  return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, 
  function(c) 
  {
    var r = Math.random() * 16 | 0, v = c == "x" ? r : (r & 0x3 | 0x8);
    return v.toString(16);
  });
}

shermanp
Posts: 70
Joined: Sat 18 Feb, 2017 2:09 am

Re: [Patch] Initial VHD support

Post by shermanp » Mon 04 Jun, 2018 10:40 am

Yeah, looks like creating a variant 4 UUID should do the trick. Can be done with some random bytes and a bit of bit manipulation. No real need for cryptographic RNG for this purpose either, although it looks like arc4random from OpenBSD would do the trick if we did need it.

I'll probably just stick to rand() from the standard library though...

User avatar
JohnElliott
Posts: 63
Joined: Sun 31 Jan, 2016 7:29 pm

Re: [Patch] Initial VHD support

Post by JohnElliott » Mon 04 Jun, 2018 6:50 pm

This is not particularly tested, but I think should put the bits in the right place. mkguid() is the function that does the work; the rest is a test harness.

The #ifdefs mean that if the system provides a GUID generator, that will be used in preference to the rand() method.

Code: Select all


#include <stdio.h>
#include <stdlib.h>

#ifdef HAVE_OBJBASE_H
#include <objbase.h>
#endif

#ifdef HAVE_UUID_H
#include <uuid/uuid.h>
#endif

void mkguid(unsigned char *guid)
{
#if defined(HAVE_UUID_H)
	uuid_generate(guid);
#elif defined(HAVE_OBJBASE_H)
	CoCreateGuid( (GUID *)guid);
#else
	int n;

	srand(time(NULL));
	for (n = 0; n < 16; n++)
	{
		guid[n] = rand();
	}
	guid[7] &= 0x0F;
	guid[7] |= 0x40;	/* Type 4 */
	guid[9] &= 0x3F;
	guid[9] |= 0x80;	/* Variant 1 */
#endif
}


int main()
{
	unsigned char guid[16];

	mkguid(guid);

	printf("Result = %02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-"
		"%02x%02x%02x%02x%02x%02x\n",
		guid[3], guid[2], guid[1], guid[0],
		guid[5], guid[4],
		guid[7], guid[6],
		guid[9], guid[8],
		guid[10], guid[11], guid[12], guid[13], guid[14], guid[15]);
	return 0;
}


shermanp
Posts: 70
Joined: Sat 18 Feb, 2017 2:09 am

Re: [Patch] Initial VHD support

Post by shermanp » Tue 05 Jun, 2018 6:17 am

Thanks JohnElliott. I'll adapt that.

I guess I should have mentioned that a string representation is not required. The raw bytes are saved directly to the footer.

EDIT: Turns out Mingw-w64 doesn't include a definition for CoCreateGuid in its objbase.h for some reason (legacy MinGW does--go figure). The only definition I could find, is in combaseapi.h, and it didn't appear to work. It's not worth trying to use an OS call on windows for the task required, so I'll just use the random version on Windows.

User avatar
JohnElliott
Posts: 63
Joined: Sun 31 Jan, 2016 7:29 pm

Re: [Patch] Initial VHD support

Post by JohnElliott » Tue 05 Jun, 2018 9:57 am

Looking at https://github.com/libLAS/libLAS-1.2/bl ... s/guid.hpp I think the variant and version should be at offsets 6 and 8 rather than 7 and 9:

Code: Select all

	guid[6] &= 0x0F;
	guid[6] |= 0x40;	/* Type 4 */
	guid[8] &= 0x3F;
	guid[8] |= 0x80;	/* Variant 1 */
#endif
}

shermanp
Posts: 70
Joined: Sat 18 Feb, 2017 2:09 am

Re: [Patch] Initial VHD support

Post by shermanp » Wed 06 Jun, 2018 4:57 am

JohnElliott wrote:
Tue 05 Jun, 2018 9:57 am
Looking at https://github.com/libLAS/libLAS-1.2/bl ... s/guid.hpp I think the variant and version should be at offsets 6 and 8 rather than 7 and 9:

Code: Select all

	guid[6] &= 0x0F;
	guid[6] |= 0x40;	/* Type 4 */
	guid[8] &= 0x3F;
	guid[8] |= 0x80;	/* Variant 1 */
#endif
}
After reading the RFC, I think your revision is correct.

On another note. I can create VHD files! And PCem didn't crash! And Windows mounted it!

I probably need to do some more testing and cleanup before unleashing it to the masses however...

shermanp
Posts: 70
Joined: Sat 18 Feb, 2017 2:09 am

Re: [Patch] Initial VHD support

Post by shermanp » Thu 07 Jun, 2018 1:38 am

I've noticed some differences in the way PCem and the VHD spec calculates disk geometry. PCem almost seems too specific, or not lenient enough.

For example, a 100MB image (104,857,600 bytes)

Code: Select all

PCEM: Cyl: 203 Head: 16 SPT: 63
VHD :  Cyl: 1003 Head: 12 SPT: 17
However, if one passes 104,761,344 bytes (1003*12*17*512) to both methods, the following occurs:

Code: Select all

PCEM: Cyl: 1003 Head: 12 SPT: 17
VHD:   Cyl: 1003 Head: 12 SPT: 17
I think the main difference is that PCem (and maybe some other tools?) use CHS to calculate the created file size, whereas VHD creates a file (to the nearest megabyte) and then works out the CHS from the filesize. In the case of the 100MB test file, 100MB doesn't divide perfectly into 17, therefore the PCem calculation doesn't even attempt to use 17 SPT as an option, even if may be a valid geometry for the desired disk size otherwise.

Not sure what I'm going to do here with regards calculating new VHD geometry. I've got an idea, but will require some testing first.

shermanp
Posts: 70
Joined: Sat 18 Feb, 2017 2:09 am

Re: [Patch] Initial VHD support

Post by shermanp » Thu 07 Jun, 2018 2:40 am

For those who are interested, I ported the algorithm for both approaches to a python script and compared them.

The script takes the size in MB, and calculates the geometry using the VHD method.
It then uses the CHS output from the VHD method as the size parameter of the PCem method.

Differing geometries printed. The most differences are below 250MB and above ~32GB:

Code: Select all

The Geometries are not the same for 10MB
VHD    C: 301  H: 4  S: 17
PCEM   C: 0  H: 4  S: 17
The Geometries are not the same for 11MB
VHD    C: 331  H: 4  S: 17
PCEM   C: 0  H: 4  S: 17
The Geometries are not the same for 12MB
VHD    C: 361  H: 4  S: 17
PCEM   C: 0  H: 4  S: 17
The Geometries are not the same for 13MB
VHD    C: 391  H: 4  S: 17
PCEM   C: 0  H: 4  S: 17
The Geometries are not the same for 14MB
VHD    C: 421  H: 4  S: 17
PCEM   C: 0  H: 4  S: 17
The Geometries are not the same for 15MB
VHD    C: 451  H: 4  S: 17
PCEM   C: 0  H: 4  S: 17
The Geometries are not the same for 16MB
VHD    C: 481  H: 4  S: 17
PCEM   C: 0  H: 4  S: 17
The Geometries are not the same for 17MB
VHD    C: 512  H: 4  S: 17
PCEM   C: 0  H: 4  S: 17
The Geometries are not the same for 18MB
VHD    C: 542  H: 4  S: 17
PCEM   C: 0  H: 4  S: 17
The Geometries are not the same for 19MB
VHD    C: 572  H: 4  S: 17
PCEM   C: 0  H: 4  S: 17
The Geometries are not the same for 20MB
VHD    C: 602  H: 4  S: 17
PCEM   C: 0  H: 4  S: 17
The Geometries are not the same for 21MB
VHD    C: 632  H: 4  S: 17
PCEM   C: 0  H: 4  S: 17
The Geometries are not the same for 22MB
VHD    C: 662  H: 4  S: 17
PCEM   C: 0  H: 4  S: 17
The Geometries are not the same for 23MB
VHD    C: 692  H: 4  S: 17
PCEM   C: 0  H: 4  S: 17
The Geometries are not the same for 24MB
VHD    C: 722  H: 4  S: 17
PCEM   C: 0  H: 4  S: 17
The Geometries are not the same for 25MB
VHD    C: 752  H: 4  S: 17
PCEM   C: 0  H: 4  S: 17
The Geometries are not the same for 26MB
VHD    C: 783  H: 4  S: 17
PCEM   C: 0  H: 6  S: 17
The Geometries are not the same for 27MB
VHD    C: 813  H: 4  S: 17
PCEM   C: 0  H: 6  S: 17
The Geometries are not the same for 28MB
VHD    C: 843  H: 4  S: 17
PCEM   C: 0  H: 6  S: 17
The Geometries are not the same for 29MB
VHD    C: 873  H: 4  S: 17
PCEM   C: 0  H: 6  S: 17
The Geometries are not the same for 30MB
VHD    C: 903  H: 4  S: 17
PCEM   C: 0  H: 6  S: 17
The Geometries are not the same for 31MB
VHD    C: 933  H: 4  S: 17
PCEM   C: 0  H: 6  S: 17
The Geometries are not the same for 32MB
VHD    C: 963  H: 4  S: 17
PCEM   C: 0  H: 6  S: 17
The Geometries are not the same for 33MB
VHD    C: 993  H: 4  S: 17
PCEM   C: 0  H: 6  S: 17
The Geometries are not the same for 34MB
VHD    C: 140  H: 16  S: 31
PCEM   C: 68  H: 16  S: 63
The Geometries are not the same for 43MB
VHD    C: 863  H: 6  S: 17
PCEM   C: 0  H: 6  S: 17
The Geometries are not the same for 44MB
VHD    C: 883  H: 6  S: 17
PCEM   C: 0  H: 6  S: 17
The Geometries are not the same for 45MB
VHD    C: 903  H: 6  S: 17
PCEM   C: 0  H: 6  S: 17
The Geometries are not the same for 46MB
VHD    C: 923  H: 6  S: 17
PCEM   C: 0  H: 6  S: 17
The Geometries are not the same for 47MB
VHD    C: 943  H: 6  S: 17
PCEM   C: 0  H: 6  S: 17
The Geometries are not the same for 48MB
VHD    C: 963  H: 6  S: 17
PCEM   C: 0  H: 6  S: 17
The Geometries are not the same for 49MB
VHD    C: 983  H: 6  S: 17
PCEM   C: 0  H: 6  S: 17
The Geometries are not the same for 50MB
VHD    C: 1003  H: 6  S: 17
PCEM   C: 0  H: 6  S: 17
The Geometries are not the same for 51MB
VHD    C: 210  H: 16  S: 31
PCEM   C: 103  H: 16  S: 63
The Geometries are not the same for 68MB
VHD    C: 280  H: 16  S: 31
PCEM   C: 137  H: 16  S: 63
The Geometries are not the same for 85MB
VHD    C: 350  H: 16  S: 31
PCEM   C: 172  H: 16  S: 63
The Geometries are not the same for 102MB
VHD    C: 421  H: 16  S: 31
PCEM   C: 207  H: 16  S: 63
The Geometries are not the same for 119MB
VHD    C: 491  H: 16  S: 31
PCEM   C: 241  H: 16  S: 63
The Geometries are not the same for 136MB
VHD    C: 561  H: 16  S: 31
PCEM   C: 1023  H: 16  S: 17
The Geometries are not the same for 137MB
VHD    C: 565  H: 16  S: 31
PCEM   C: 278  H: 16  S: 63
The Geometries are not the same for 138MB
VHD    C: 569  H: 16  S: 31
PCEM   C: 279  H: 16  S: 63
The Geometries are not the same for 139MB
VHD    C: 573  H: 16  S: 31
PCEM   C: 281  H: 16  S: 63
The Geometries are not the same for 140MB
VHD    C: 578  H: 16  S: 31
PCEM   C: 284  H: 16  S: 63
The Geometries are not the same for 141MB
VHD    C: 582  H: 16  S: 31
PCEM   C: 286  H: 16  S: 63
The Geometries are not the same for 142MB
VHD    C: 586  H: 16  S: 31
PCEM   C: 288  H: 16  S: 63
The Geometries are not the same for 143MB
VHD    C: 590  H: 16  S: 31
PCEM   C: 290  H: 16  S: 63
The Geometries are not the same for 144MB
VHD    C: 594  H: 16  S: 31
PCEM   C: 292  H: 16  S: 63
The Geometries are not the same for 145MB
VHD    C: 598  H: 16  S: 31
PCEM   C: 294  H: 16  S: 63
The Geometries are not the same for 146MB
VHD    C: 602  H: 16  S: 31
PCEM   C: 296  H: 16  S: 63
The Geometries are not the same for 147MB
VHD    C: 606  H: 16  S: 31
PCEM   C: 298  H: 16  S: 63
The Geometries are not the same for 148MB
VHD    C: 611  H: 16  S: 31
PCEM   C: 300  H: 16  S: 63
The Geometries are not the same for 149MB
VHD    C: 615  H: 16  S: 31
PCEM   C: 302  H: 16  S: 63
The Geometries are not the same for 150MB
VHD    C: 619  H: 16  S: 31
PCEM   C: 304  H: 16  S: 63
The Geometries are not the same for 151MB
VHD    C: 623  H: 16  S: 31
PCEM   C: 306  H: 16  S: 63
The Geometries are not the same for 152MB
VHD    C: 627  H: 16  S: 31
PCEM   C: 308  H: 16  S: 63
The Geometries are not the same for 153MB
VHD    C: 631  H: 16  S: 31
PCEM   C: 310  H: 16  S: 63
The Geometries are not the same for 154MB
VHD    C: 635  H: 16  S: 31
PCEM   C: 312  H: 16  S: 63
The Geometries are not the same for 155MB
VHD    C: 640  H: 16  S: 31
PCEM   C: 314  H: 16  S: 63
The Geometries are not the same for 156MB
VHD    C: 644  H: 16  S: 31
PCEM   C: 316  H: 16  S: 63
The Geometries are not the same for 157MB
VHD    C: 648  H: 16  S: 31
PCEM   C: 318  H: 16  S: 63
The Geometries are not the same for 158MB
VHD    C: 652  H: 16  S: 31
PCEM   C: 320  H: 16  S: 63
The Geometries are not the same for 159MB
VHD    C: 656  H: 16  S: 31
PCEM   C: 322  H: 16  S: 63
The Geometries are not the same for 160MB
VHD    C: 660  H: 16  S: 31
PCEM   C: 324  H: 16  S: 63
The Geometries are not the same for 161MB
VHD    C: 664  H: 16  S: 31
PCEM   C: 326  H: 16  S: 63
The Geometries are not the same for 162MB
VHD    C: 668  H: 16  S: 31
PCEM   C: 328  H: 16  S: 63
The Geometries are not the same for 163MB
VHD    C: 673  H: 16  S: 31
PCEM   C: 331  H: 16  S: 63
The Geometries are not the same for 164MB
VHD    C: 677  H: 16  S: 31
PCEM   C: 333  H: 16  S: 63
The Geometries are not the same for 165MB
VHD    C: 681  H: 16  S: 31
PCEM   C: 335  H: 16  S: 63
The Geometries are not the same for 166MB
VHD    C: 685  H: 16  S: 31
PCEM   C: 337  H: 16  S: 63
The Geometries are not the same for 167MB
VHD    C: 689  H: 16  S: 31
PCEM   C: 339  H: 16  S: 63
The Geometries are not the same for 168MB
VHD    C: 693  H: 16  S: 31
PCEM   C: 341  H: 16  S: 63
The Geometries are not the same for 169MB
VHD    C: 697  H: 16  S: 31
PCEM   C: 342  H: 16  S: 63
The Geometries are not the same for 170MB
VHD    C: 701  H: 16  S: 31
PCEM   C: 344  H: 16  S: 63
The Geometries are not the same for 171MB
VHD    C: 706  H: 16  S: 31
PCEM   C: 347  H: 16  S: 63
The Geometries are not the same for 172MB
VHD    C: 710  H: 16  S: 31
PCEM   C: 349  H: 16  S: 63
The Geometries are not the same for 173MB
VHD    C: 714  H: 16  S: 31
PCEM   C: 351  H: 16  S: 63
The Geometries are not the same for 174MB
VHD    C: 718  H: 16  S: 31
PCEM   C: 353  H: 16  S: 63
The Geometries are not the same for 175MB
VHD    C: 722  H: 16  S: 31
PCEM   C: 355  H: 16  S: 63
The Geometries are not the same for 176MB
VHD    C: 726  H: 16  S: 31
PCEM   C: 357  H: 16  S: 63
The Geometries are not the same for 177MB
VHD    C: 730  H: 16  S: 31
PCEM   C: 359  H: 16  S: 63
The Geometries are not the same for 178MB
VHD    C: 734  H: 16  S: 31
PCEM   C: 361  H: 16  S: 63
The Geometries are not the same for 179MB
VHD    C: 739  H: 16  S: 31
PCEM   C: 363  H: 16  S: 63
The Geometries are not the same for 180MB
VHD    C: 743  H: 16  S: 31
PCEM   C: 365  H: 16  S: 63
The Geometries are not the same for 181MB
VHD    C: 747  H: 16  S: 31
PCEM   C: 367  H: 16  S: 63
The Geometries are not the same for 182MB
VHD    C: 751  H: 16  S: 31
PCEM   C: 369  H: 16  S: 63
The Geometries are not the same for 183MB
VHD    C: 755  H: 16  S: 31
PCEM   C: 371  H: 16  S: 63
The Geometries are not the same for 184MB
VHD    C: 759  H: 16  S: 31
PCEM   C: 373  H: 16  S: 63
The Geometries are not the same for 185MB
VHD    C: 763  H: 16  S: 31
PCEM   C: 375  H: 16  S: 63
The Geometries are not the same for 186MB
VHD    C: 768  H: 16  S: 31
PCEM   C: 377  H: 16  S: 63
The Geometries are not the same for 187MB
VHD    C: 772  H: 16  S: 31
PCEM   C: 379  H: 16  S: 63
The Geometries are not the same for 188MB
VHD    C: 776  H: 16  S: 31
PCEM   C: 381  H: 16  S: 63
The Geometries are not the same for 189MB
VHD    C: 780  H: 16  S: 31
PCEM   C: 383  H: 16  S: 63
The Geometries are not the same for 190MB
VHD    C: 784  H: 16  S: 31
PCEM   C: 385  H: 16  S: 63
The Geometries are not the same for 191MB
VHD    C: 788  H: 16  S: 31
PCEM   C: 387  H: 16  S: 63
The Geometries are not the same for 192MB
VHD    C: 792  H: 16  S: 31
PCEM   C: 389  H: 16  S: 63
The Geometries are not the same for 193MB
VHD    C: 796  H: 16  S: 31
PCEM   C: 391  H: 16  S: 63
The Geometries are not the same for 194MB
VHD    C: 801  H: 16  S: 31
PCEM   C: 394  H: 16  S: 63
The Geometries are not the same for 195MB
VHD    C: 805  H: 16  S: 31
PCEM   C: 396  H: 16  S: 63
The Geometries are not the same for 196MB
VHD    C: 809  H: 16  S: 31
PCEM   C: 398  H: 16  S: 63
The Geometries are not the same for 197MB
VHD    C: 813  H: 16  S: 31
PCEM   C: 400  H: 16  S: 63
The Geometries are not the same for 198MB
VHD    C: 817  H: 16  S: 31
PCEM   C: 402  H: 16  S: 63
The Geometries are not the same for 199MB
VHD    C: 821  H: 16  S: 31
PCEM   C: 403  H: 16  S: 63
The Geometries are not the same for 200MB
VHD    C: 825  H: 16  S: 31
PCEM   C: 405  H: 16  S: 63
The Geometries are not the same for 201MB
VHD    C: 829  H: 16  S: 31
PCEM   C: 407  H: 16  S: 63
The Geometries are not the same for 202MB
VHD    C: 834  H: 16  S: 31
PCEM   C: 410  H: 16  S: 63
The Geometries are not the same for 203MB
VHD    C: 838  H: 16  S: 31
PCEM   C: 412  H: 16  S: 63
The Geometries are not the same for 204MB
VHD    C: 842  H: 16  S: 31
PCEM   C: 414  H: 16  S: 63
The Geometries are not the same for 205MB
VHD    C: 846  H: 16  S: 31
PCEM   C: 416  H: 16  S: 63
The Geometries are not the same for 206MB
VHD    C: 850  H: 16  S: 31
PCEM   C: 418  H: 16  S: 63
The Geometries are not the same for 207MB
VHD    C: 854  H: 16  S: 31
PCEM   C: 420  H: 16  S: 63
The Geometries are not the same for 208MB
VHD    C: 858  H: 16  S: 31
PCEM   C: 422  H: 16  S: 63
The Geometries are not the same for 209MB
VHD    C: 862  H: 16  S: 31
PCEM   C: 424  H: 16  S: 63
The Geometries are not the same for 210MB
VHD    C: 867  H: 16  S: 31
PCEM   C: 426  H: 16  S: 63
The Geometries are not the same for 211MB
VHD    C: 871  H: 16  S: 31
PCEM   C: 428  H: 16  S: 63
The Geometries are not the same for 212MB
VHD    C: 875  H: 16  S: 31
PCEM   C: 430  H: 16  S: 63
The Geometries are not the same for 213MB
VHD    C: 879  H: 16  S: 31
PCEM   C: 432  H: 16  S: 63
The Geometries are not the same for 214MB
VHD    C: 883  H: 16  S: 31
PCEM   C: 434  H: 16  S: 63
The Geometries are not the same for 215MB
VHD    C: 887  H: 16  S: 31
PCEM   C: 436  H: 16  S: 63
The Geometries are not the same for 216MB
VHD    C: 891  H: 16  S: 31
PCEM   C: 438  H: 16  S: 63
The Geometries are not the same for 217MB
VHD    C: 896  H: 16  S: 31
PCEM   C: 440  H: 16  S: 63
The Geometries are not the same for 218MB
VHD    C: 900  H: 16  S: 31
PCEM   C: 442  H: 16  S: 63
The Geometries are not the same for 219MB
VHD    C: 904  H: 16  S: 31
PCEM   C: 444  H: 16  S: 63
The Geometries are not the same for 220MB
VHD    C: 908  H: 16  S: 31
PCEM   C: 446  H: 16  S: 63
The Geometries are not the same for 221MB
VHD    C: 912  H: 16  S: 31
PCEM   C: 448  H: 16  S: 63
The Geometries are not the same for 222MB
VHD    C: 916  H: 16  S: 31
PCEM   C: 450  H: 16  S: 63
The Geometries are not the same for 223MB
VHD    C: 920  H: 16  S: 31
PCEM   C: 452  H: 16  S: 63
The Geometries are not the same for 224MB
VHD    C: 924  H: 16  S: 31
PCEM   C: 454  H: 16  S: 63
The Geometries are not the same for 225MB
VHD    C: 929  H: 16  S: 31
PCEM   C: 457  H: 16  S: 63
The Geometries are not the same for 226MB
VHD    C: 933  H: 16  S: 31
PCEM   C: 459  H: 16  S: 63
The Geometries are not the same for 227MB
VHD    C: 937  H: 16  S: 31
PCEM   C: 461  H: 16  S: 63
The Geometries are not the same for 228MB
VHD    C: 941  H: 16  S: 31
PCEM   C: 463  H: 16  S: 63
The Geometries are not the same for 229MB
VHD    C: 945  H: 16  S: 31
PCEM   C: 465  H: 16  S: 63
The Geometries are not the same for 230MB
VHD    C: 949  H: 16  S: 31
PCEM   C: 466  H: 16  S: 63
The Geometries are not the same for 231MB
VHD    C: 953  H: 16  S: 31
PCEM   C: 468  H: 16  S: 63
The Geometries are not the same for 232MB
VHD    C: 957  H: 16  S: 31
PCEM   C: 470  H: 16  S: 63
The Geometries are not the same for 233MB
VHD    C: 962  H: 16  S: 31
PCEM   C: 473  H: 16  S: 63
The Geometries are not the same for 234MB
VHD    C: 966  H: 16  S: 31
PCEM   C: 475  H: 16  S: 63
The Geometries are not the same for 235MB
VHD    C: 970  H: 16  S: 31
PCEM   C: 477  H: 16  S: 63
The Geometries are not the same for 236MB
VHD    C: 974  H: 16  S: 31
PCEM   C: 479  H: 16  S: 63
The Geometries are not the same for 237MB
VHD    C: 978  H: 16  S: 31
PCEM   C: 481  H: 16  S: 63
The Geometries are not the same for 238MB
VHD    C: 982  H: 16  S: 31
PCEM   C: 483  H: 16  S: 63
The Geometries are not the same for 239MB
VHD    C: 986  H: 16  S: 31
PCEM   C: 485  H: 16  S: 63
The Geometries are not the same for 240MB
VHD    C: 990  H: 16  S: 31
PCEM   C: 487  H: 16  S: 63
The Geometries are not the same for 241MB
VHD    C: 995  H: 16  S: 31
PCEM   C: 489  H: 16  S: 63
The Geometries are not the same for 242MB
VHD    C: 999  H: 16  S: 31
PCEM   C: 491  H: 16  S: 63
The Geometries are not the same for 243MB
VHD    C: 1003  H: 16  S: 31
PCEM   C: 493  H: 16  S: 63
The Geometries are not the same for 244MB
VHD    C: 1007  H: 16  S: 31
PCEM   C: 495  H: 16  S: 63
The Geometries are not the same for 245MB
VHD    C: 1011  H: 16  S: 31
PCEM   C: 497  H: 16  S: 63
The Geometries are not the same for 246MB
VHD    C: 1015  H: 16  S: 31
PCEM   C: 499  H: 16  S: 63
The Geometries are not the same for 247MB
VHD    C: 1019  H: 16  S: 31
PCEM   C: 501  H: 16  S: 63
The Geometries are not the same for 32256MB
VHD    C: 16191.0  H: 16  S: 255
PCEM   C: 65535.0  H: 16  S: 63
The Geometries are not the same for 32257MB
VHD    C: 16191.0  H: 16  S: 255
PCEM   C: 65535.0  H: 16  S: 63
The Geometries are not the same for 32258MB
VHD    C: 16192.0  H: 16  S: 255
PCEM   C: 65539.0  H: 16  S: 63
The Geometries are not the same for 32259MB+
VHD    C: 16192.0  H: 16  S: 255
PCEM   C: 65539.0  H: 16  S: 63

shermanp
Posts: 70
Joined: Sat 18 Feb, 2017 2:09 am

Re: [Patch] VHD support

Post by shermanp » Thu 07 Jun, 2018 9:02 am

Ok, I've updated my OP with a new patch, which now allows for creation of VHD's as well as opening them.

With regards to my previous posts, I have implemented the VHD algorithm for calculating CHS in the size dialog when a VHD file is selected for creation. More specifically, the algorithm is used when the user modifies the values in the 'size' text box. Users can still choose custom CHS, or MFM arrangements as well. The existing solution is still kept when a user creates a raw img file.

Windows happily mounts the PCem created VHD files, and the utility azure-vhd-utils shows a valid footer.

Now I just need others to test the thing...

jznomoney
Posts: 80
Joined: Sat 06 Dec, 2014 9:11 pm

Re: [Patch] VHD support

Post by jznomoney » Thu 07 Jun, 2018 10:39 pm

Great job on this patch. Issue I have is any vhd I create larger than 2048mb is not mountable under windows. I tried different sizes because the first one I tried was 4096mb and pcem worked fine. I installed Windows ME. When I tried mounting the vhd in windows it did not work. So I created smaller ones starting at 500mb. The 500mb, 1024, and 2048 worked. Anything over 2048mb does not mount in Windows.

I can create vhd in windows disk management over 2048 and they work in PCem. I can also mount them still under windows after using them in pcem. It's just pcem creating vhd over 2048mb with this patch. Other than that I don't have any other issues.

shermanp
Posts: 70
Joined: Sat 18 Feb, 2017 2:09 am

Re: [Patch] VHD support

Post by shermanp » Thu 07 Jun, 2018 11:14 pm

jznomoney wrote:
Thu 07 Jun, 2018 10:39 pm
Great job on this patch. Issue I have is any vhd I create larger than 2048mb is not mountable under windows. I tried different sizes because the first one I tried was 4096mb and pcem worked fine. I installed Windows ME. When I tried mounting the vhd in windows it did not work. So I created smaller ones starting at 500mb. The 500mb, 1024, and 2048 worked. Anything over 2048mb does not mount in Windows.

I can create vhd in windows disk management over 2048 and they work in PCem. I can also mount them still under windows after using them in pcem. It's just pcem creating vhd over 2048mb with this patch. Other than that I don't have any other issues.
Thanks for the feedback. I didn't actually test with larger images (naughty, naughty me...), so I shall investigate to see what's going on.

EDIT: It appears there is a bug when calculating the geometry for larger sizes. I can't imagine windows is happy with 0 cylinders... Time to start debugging.

shermanp
Posts: 70
Joined: Sat 18 Feb, 2017 2:09 am

Re: [Patch] VHD support

Post by shermanp » Fri 08 Jun, 2018 12:05 am

Large VHD image files should now work properly (cross fingers...). OP has updated patch.

Bit of a face-palm that one. I forgot to cast the file size calculations to large enough (64 bit) integers.

shermanp
Posts: 70
Joined: Sat 18 Feb, 2017 2:09 am

Re: [Patch] VHD support

Post by shermanp » Sat 09 Jun, 2018 9:32 am

Patch has been updated again. Changes are:
  • I did some more refactoring. No more malloc()...
  • Added some checks to test for possible VHD footer corruption/issues.
  • (Hopefully) set the HDD type when the MFM controller is selected, and the user loads a VHD with one of the supported geometries. (Does this actually do anything elsewhere in PCem?)
As always, I welcome anyone to test for any issues.

User avatar
SarahWalker
Site Admin
Posts: 1542
Joined: Thu 24 Apr, 2014 4:18 pm

Re: [Patch] VHD support

Post by SarahWalker » Sat 09 Jun, 2018 2:46 pm

shermanp wrote:
Sat 09 Jun, 2018 9:32 am
  • (Hopefully) set the HDD type when the MFM controller is selected, and the user loads a VHD with one of the supported geometries. (Does this actually do anything elsewhere in PCem?)
It's mainly a hint to the user when setting up machines. Some of the early MFM controllers only support a few hard drive types, and early AT machines require you to know what hard drive type you have when configuring. I thought reminding the user what type a hard drive image when loading it would probably be helpful.

shermanp
Posts: 70
Joined: Sat 18 Feb, 2017 2:09 am

Re: [Patch] VHD support

Post by shermanp » Sat 09 Jun, 2018 8:45 pm

SarahWalker wrote:
Sat 09 Jun, 2018 2:46 pm
shermanp wrote:
Sat 09 Jun, 2018 9:32 am
  • (Hopefully) set the HDD type when the MFM controller is selected, and the user loads a VHD with one of the supported geometries. (Does this actually do anything elsewhere in PCem?)
It's mainly a hint to the user when setting up machines. Some of the early MFM controllers only support a few hard drive types, and early AT machines require you to know what hard drive type you have when configuring. I thought reminding the user what type a hard drive image when loading it would probably be helpful.
Thanks for that Sarah. I'll just leave it as is (mimics what the 'check_hd_type' function does).

Post Reply