Apr 012015
 

For one program of mine I had a lot of dynamic resource fetching to do. Unfortunately, sometimes a lookup in resources would return null bitmap. Whether that was due to the missing resource or because of a wrong key is of less importance. I didn’t want system to crash but I did want for program to crash just because bitmap was missing. But I did want to have that clearly visible so that I could catch it.

One idea was to use dummy resource, e.g.:

item.Image = (bitmap != null) ? bitmap : dummyBitmap;

However, I didn’t like that solution due to a potential resource release at other places. Nothing worse then releasing resource in use somewhere else. And I was more in the mood for one-liner – resources be damned.

But how to create an bitmap and color it at the same time (by default, bitmap is transparent)? Well, we could always create one without alpha channel, e.g.:

item.Image = (bitmap != null) ? bitmap : new Bitmap(size, size, PixelFormat.Format8bppIndexed);

This will make your bitmap one big black rectangle. It might not be ideal but it is definitely noticeable.

PS: Since I wanted this only during debugging, my final code ended up being just a smidge more complicated:

#if DEBUG
    item.Image = (bitmap != null) ? bitmap : new Bitmap(size, size, PixelFormat.Format8bppIndexed);
#else
    if (bitmap != null) { item.Image = bitmap; }
#endif
Mar 262015
 

After playing with ReFS a bit, time came for Windows update restart. After initial second or so of booting screen blanked and stayed that way. I waited and waited but there was neither screen nor disk activity. And same thing happened every time I rebooted.

And it got frozen at the worst spot. I have a dual boot and freeze happen to be just before OS selection screen. With one error both installations were dead. And since I used BitLocker on both I wasn’t really in the mood for recovery.

Fortunately, after turning off system few times during boot, I got into Automatic Repair prompt. I entered BitLocker key for my main OS and proceeded with Advanced Options. There I just selected Continue (Exit and continue to Windows 8.1). While this should have technically been exactly the same boot, it was different enough that it actually worked. And then, as soon as system booted up, I removed ReFS capability (this registry file) and rebooted again. All came back successfully.

PS: Even when ReFS functionality is “turned off” you can still use existing ReFS disks. You just cannot format new ones.

Mar 202015
 

VHD Attach 4.00After a really long hiatus, there is an update for VHD Attach.

First change that everybody will notice are new icons. Due to their monochrome nature it will probably be a love-hate relationship but they do come in multiple sizes as a saving grace. While VHD Attach has supported high-DPI scaling for a while now, it always did that with the cost of blurry toolbar icons. With all sizes I have these icons in, blurriness won’t be a problem for a while.

Another big news is improved support for VHD on ReFS formatted drives. Main driver here was issue that Microsoft API does not support virtual disk file with ReFS integrity streams and there is no practical way around it. However, you can use API to remove integrity stream on per-file basis. When VHD Attach opens virtual disk it will offer to automatically remove integrity stream and allow you to attach it. Yes, you could have done this yourself but this is a time saver.

Other changes include few bugfixes that will help GUI not to crash as much. Quite a few of them are long overdue.

As usual you can upgrade from within application itself or grab a setup from these pages.

Enjoy.

Mar 182015
 

Process Monitor - Set integrity informationAs I moved my data drive to ReFS, I was faced with a problem of removing integrity stream for virtual disks. For performance reasons Microsoft doesn’t work with ReFS integrity streams and thus I had to disable it for all VHD files I had.

Since I use my own VHD Attach to attach disks, I also wanted to integrate removal of integrity stream upon opening the disk. And that meant C# solution was strongly preferred. As functionality is rather new, Windows API was the only way.

First course of action is, of course, to open the file. Only important thing is to have have both read and write access:

var handle = NativeMethods.CreateFile(
    fileName,
    NativeMethods.GENERIC_READ | NativeMethods.GENERIC_WRITE,
    FileShare.None,
    IntPtr.Zero,
    FileMode.Open,
    0,
    IntPtr.Zero);

Once we have a handle, we can can use DeviceIoControl to set checksum type to none.

var newInfo = new NativeMethods.FSCTL_SET_INTEGRITY_INFORMATION_BUFFER() {
    ChecksumAlgorithm = NativeMethods.CHECKSUM_TYPE_NONE
};
var newInfoSizeReturn = 0;

NativeMethods.DeviceIoControl(
    handle,
    NativeMethods.FSCTL_SET_INTEGRITY_INFORMATION,
    ref newInfo,
    Marshal.SizeOf(newInfo),
    IntPtr.Zero,
    0,
    out newInfoSizeReturn,
    IntPtr.Zero
);

Those two simple commands are all that takes. Sample (with actual API definitions) is available for download.

And rant for the end – it was annoyingly hard to find resources for this. Yes, some resources do exist (albeit without examples) but to find them you need to know what you are searching for. Since I knew Set-FileIntegrity PowerShell cmdlet does it somehow, I used Process Monitor tool to capture what exactly was happening. There I got a hint toward DeviceIoControl function and things got a bit easier. To keep it a bit interesting, documentation also lies that “The integrity status can only be changed for empty files.” Only confidence in Process Monitor’s capture kept me going in that direction.

Maybe it is me getting older but I have a feeling Windows API documentation is getting worse and worse. I hated Windows 7 documentation for virtual disk support and I thought that was the lowest quality Microsoft can do. But not much seems improved with newer versions. Gone are the times when new feature would get an example or two and more than a blog post as a design document.

I believe ReFS should deserve more.