[Patch] New VHD support... now with added dynamics

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

[Patch] New VHD support... now with added dynamics

Post by shermanp » Fri 29 Jun, 2018 6:57 am

EDIT 2018-07-09: Updated patch available with post #2
Hi all,

I wanted to see if I could extend myself, and implement sparse, or dynamic VHD support to PCem. I am happy to announce that I appear to have succeeded.

This patch replaces my earlier VHD patch, which I consider depreciated (I'll edit the previous topic to state this). It does of course still support fixed VHD images, but with this patch, PCem can create dynamic VHD's, and read/write them. PCem created VHD images can be mounted by Windows 10 (7, 8 should also work), with the caveat that the image needs a supported filesystem (FAT, FAT32, NTFS).

Because I had to write my own image read/write functions for dynamic VHD support, I consider it experimental, until it has had more testing. There are bound to be some silly bugs still waiting to be found (there were plenty of those during development!).

This patch does NOT support differential VHD images. These are not common, and the Windows Disk Management tool cannot create them either. I have no plans to implement differencing support. I have no desire to deal with strings in C thank you very much, let alone utf16 encoded strings...

The current method of choosing between fixed and dynamic VHD creation is not very elegant at the moment. It simply displays a messagebox asking the user to choose. This area could probably use a little refinement, but it works for now.

@SarahWalker I've left in the extra logging function and (commented out) code that I used during development. I will most likely want to remove some or all of this before you merge it, unless you want it to stay there.

I am an amateur with C, so if I've done something majorly silly in the code, feel free to point it out!

Finally, could I please have some vict—er—volunteers to help test this patch for performance and stability? I am NOT a hard disk expert, just a person who can follow a rather straightforward technical document.
Last edited by shermanp on Mon 09 Jul, 2018 5:36 am, edited 1 time in total.

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

Re: [Patch] New VHD support... now with added dynamics

Post by shermanp » Mon 09 Jul, 2018 5:29 am

MAJOR REFACTOR

I decided that projects other than PCem may find my VHD code useful. To that end, I've disentangled the VHD code from the PCem code as much as possible. I am now calling this implementation MiniVHD, or Minimalist VHD. The code is available at https://github.com/shermp/MiniVHD, released under the same license as Pcem (GPLv2).

As well as separating out the VHD code, I've also done a more general refactor, such as improving function and variable name consistency etc.

A new patch is included in this post. Barring any issues or bugs (there may still be a few!), I think I'll call this one more or less complete.

Patch is against the latest public commit (390edaf).

EDIT 2018-11-13 Patch removed for refactoring

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

Re: [Patch] New VHD support... now with added dynamics

Post by shermanp » Mon 12 Nov, 2018 9:55 pm

Just a heads up that I've temporarily removed the patch while I do some more work on it.

I've since switched from manually serializing/deserializing the VHD header/footer, to using using #pragma pack. This should be much less error prone compared to the previous method, and I think modern ARM architectures support unaligned memory accesses, so it should be portable enough for modern usage.

I also want to see if I can improve the GUI side of it, so it's a little less jerry-rigged. Especially the VHD creation.

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

Re: [Patch] New VHD support... now with added dynamics

Post by shermanp » Mon 26 Nov, 2018 5:34 am

Ok, I think I'm finally done with this. New patch added to this post.

As stated in my previous post, the VHD changes are mostly around serialization/deserialization of VHD metadata. Tweaked VHD creation a bit as well. The core data read/write code has not changed.

Quite a few changes on the PCem side. I've tried to make the integration as non-VHD specific as I can, so hopefully it will be rather straightforward to add additional formats in the future if desired.

I think I've finally figured out the way PCem handles wxWidgets (the PCem C wrapper doesn't exactly help make it easier to figure out...) and HDD image creation is now better integrated into the GUI. No more messageboxes to set things! Note, if anyone else wants RadioBoxes, they're in PCem now :)
HDDConfigWindow.png
Unless anybody discovers any issues or bugs, I think I'm done with this.

EDIT: Patch deleted, see next post for new version.
Last edited by shermanp on Mon 24 Dec, 2018 6:55 am, edited 1 time in total.

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

Re: [Patch] New VHD support... now with added dynamics

Post by shermanp » Mon 24 Dec, 2018 6:54 am

shermanp wrote:
Mon 26 Nov, 2018 5:34 am
Unless anybody discovers any issues or bugs, I think I'm done with this.
So, umm, about that....

I decided to simplify the sector read/write functions. The old "fast" path has been dropped in favor of improving the old "slow" path to be, well, not slow. Basically minimized the use of fseek() where possible, which in turn minimizes the file stream buffer flushes.

Have tested by installing both Windows 98SE and Windows 2000 to dynamic VHD's. Also ran an ATTO benchmark. There doesn't appear to be any performance or stability regressions, but as always, I welcome any testers and bug reports.

I would also welcome another pair of eyes on the code if anybody is interested. The (non PCem specific) code can be found at https://github.com/shermp/MiniVHD. This patch is based on master. The PCem integration code is in this patch, I don't have an online repository for that.

I've also tried (and tried again) to get differencing VHD support working. Unfortunately, I have yet to succeed, and have just about decided to give up on that aspect. The current attempt is in the "diff-v3" branch if anyone is interested to help me figure it out. I've probably made a silly mistake somewhere that I keep missing...
Attachments
newVHD_v4.patch
(122.73 KiB) Downloaded 48 times

Post Reply