Alternate Data Streams

NTFS has quite a few features that are hidden from everyday user. One of features that is difficult to access is alternate data streams.

Additionally to normal content, each file can have additional content attached to it. That content is, for all practical purposes, independent of original file content and it can contain anything. Most common stream is “Zone.Identifier”. It gets added by Internet Explorer (and some other browsers) to each executable to mark it as “unsafe”. Before such file gets executed you get security warning with notification that file arrived from big-bad-Internet.

Unfortunately this is as far as using this feature goes in Windows. Although one could think of thousands of more uses for it (e.g. adding thumbnails to file itself instead of separate file) its downfall is support on other file systems. Mere act of copying file to FAT partition will strip additional file streams. Mailing it is out of question and not even HTTP has any provisioning for it. With all that in mind, it is very unlikely that it gets used for anything more than temporary data.

If you are C# programmer and you have purpose for ADS, you will stumble upon another problem - it has no support in .NET framework. This is where this post gets useful.

I decided to implement support for alternate data streams in FileStream-like class that allows for same read/write functions to be used as in any Stream. It just wraps native CreateFile function into some FileStream contructor overloads. For deletion of particular stream within file we can use native DeleteFile and stream-specific functions (FindFirstStream and FindNextStream) will take care of enumeration.

I will let source code speak for itself.

Startup Customizations

Illustration

My BeBook e-book reader is just rebranded Jinke and as such there is quite a lot possibility of customization. I will save discussing all different versions of firmware for some other post, this time I will just discuss changing logo.

Jinke decided to make it’s LogoMaker available for all owners to change both boot and shutdown images.

Preparing is easy. Just create two bitmaps (one for boot and one for shutdown) and save them as .bmp images. Start LogoMaker and give path to those two images just created and you will get logo.bin and logo.md5. Those two files are all you need.

Create /jinke/logo on SD card. Easiest way is to do this is to connect BeBook mini (or Hanlin V5, or Pocket PRO, or whatever clone there is) to USB and copy it from there, but choice is yours.

Once both SD card and logo files are in place you can go into Settings. There you will see “Update boot and shutdown logo” option available. Once selected, update will happen very fast and device will be turned off.

Once you turn device back on you will be able to enjoy your new startup screen.

Probably most difficult thing is selecting proper logo for it. I decided upon “Don’t Panic” statement. If you wish it, you can have it too.

What Else I Didn't Notice?

I accidentally did click’n’drag on tray notification are in Windows 7. I was quite surprised when icon actually moved.

Yes, Windows 7 allows notification icons to be moved around. And to make it better all icons will stick to that place - no matter in which order you start applications that create them.

I wonder what else I don’t know about Windows 7… I should probably start reading manuals. :)

Backing Field Must Be Fully Assigned

Structures are peculiar creatures in C#. One of more interesting peculiarities comes in combination with auto-implemented properties.

Lets begin with following struct:

public struct Test {
    public Test(int a) {
        this.A = 1;
    }

    public int A;
}

It is something that works, but having variable A directly exposed is not something that looks too good. Auto-implemented properties come to rescue:

public struct Test {
    public Test(int a) {
        this.A = 1;
    }

    public int A { get; set; }
}

This looks much better from design point of view. However, it also does not compile. It will greet us with: “Backing field for automatically implemented property ‘Test.A’ must be fully assigned before control is returned to the caller. Consider calling the default constructor from a constructor initializer.”

Solution is quite simple, just call default constructor (as suggested in error message) and everything is fine:

public struct Test {
    public Test(int a)
        this(): {
        this.A = 1;
    }

    public int A { get; set; }
}

Unfortunately, you gain something, you lose something. Our original structure stops us when we forget to initialize field and I think of this as great feature. It ensures that we cannot forget a field.

Solution with auto-implemented properties has no such assurance. Since we need to call default constructor at one point or another, we will end-up with all fields initialized by struct itself. There will be no further checks whether fields are set or not.

While code did get nicer, our refactoring just got harder.

I Forgot :)

Illustration

I was having a beer with some friends in Berlin and talk came to Avatar. Yes, that 3D movie that everyone is so fascinated with. I had one more night to fill in Berlin so I decided to go and see what is that all about.

Unfortunately, there was no show playing on Wednesday (my last day in Berlin). Fortunately, I have friends who know German and she was kind enough to find a show that night and to reserve a seat for me. :)

As soon as I left U-Bahn station and went into Sony Center, I was amazed. I spent a lot of time in Berlin last few months and I cannot believe what I have missed. Yes, I was on Potsdamer Platz before, but it was during day time. I had no idea how beautiful it looks during night hours.

I got ticket for my first IMAX 3D movie, bought a pretzel and I was ready to see some 3D action. As lights dimmed I placed glasses on my nose and got ready to enjoy movie. Movie started and I could hear unprovoked wow from some girls behind me. After few more wows I was puzzled. There was nothing that interesting on screen.

I took me few more wows before remembering that I have diagnosis of congenital strabismus. I was diagnosed with it at age of four but I cannot say that it bothered me too much. It really has only one consequence - no depth perception. As you may guess, it is very hard to see anything in 3D when your eyes are not used to work together. To make it short - 3D was not working for me.

I spent rest of movie trying to get my eyes aligned. Not an easy task considering that I haven’t manage to do this for my whole life. Of course, I failed.

Nevertheless, it was an interesting experience and night well spent. :)