December, 2005

  • The Old New Thing

    Why does Windows setup lay down a new boot sector?

    • 77 Comments

    Why does Windows setup lay down a new boot sector? Because the alternative is worse.

    You would expect that after installing an operating system, the operating system should boot. If your boot sector is damaged, say because this is a brand new hard drive with no boot sector, or because it was infected with a boot sector virus, you expect the operating system's setup program to replace the boot sector with a good one. If it didn't, you'd have an operating system that didn't boot.

    Not the greatest introduction to a new operating system.

    I know some people are going to suggest, "Why doesn't the setup program ask before overwriting the boot sector?" But think about it. It's Christmas Day, you're installing Windows XP on your computer, you go through the setup process, and it asks you a question you can't answer. "Gosh, the computer says that I have a custom boot sector. It says that this could be for legitimate reasons, or it could be due to a virus. How the heck am I supposed to know the difference?" That's assuming they even read the dialog. A much more realistic scenario is, "Eek! The computer is asking me a scary question! How do I cancel out of this? I hate computers. They're so hard to use."

    Yes, this means that if you are an ultradweeb with a custom boot sector, you will lose it when you install Windows. But Windows isn't picking on you. It even destroys itself. If you take a Windows XP machine and install Windows 2000 onto it, the Windows 2000 setup program will lay down a new boot sector that knows how to boot Windows 2000 but doesn't know about Windows XP. You'll have to restore the Windows XP boot files to restore that functionality.

    [Update 9am: Even if Windows Setup did give you the option of "don't overwrite the boot sector" you still wouldn't like it. Windows Setup would get to the point where it lays down a new boot sector, and it says, "Ooh, an unrecognized boot sector, and the user said they want to leave it alone. Okay, I won't touch it. Now, how do I tell the foreign boot sector where I installed this operating system?" Since the authors of Windows Setup are not clairvoyant, they don't know what kind of boot sector you're going to have, so they won't know how to tell that foreign boot sector, "Please add 'Windows' to the list of known operating systems, and here is how you start it." The result: You just installed an operating system and have no way to run it.]

    Things are a little better starting with Windows XP Service Pack 2 and Windows Server 2003 Service Pack 1, though. Those and future versions of Windows setup check the version of the NTLDR file and will leave a newer version of the boot loader intact rather than overwriting it with an older version. Let's just hope that you're not installing because you need a fresh boot sector...

  • The Old New Thing

    On the inability to support hardware that nobody makes any more

    • 67 Comments

    Windows Vista will not have support for really old DVD drives. (The information below was kindly provided to me by the optical storage driver team.)

    When PC DVD drives first came out in 1998, the drives themselves did not have support for region codes but instead relied on (and in fact the DVD specification required) the operating system to enforce region coding, with the further understanding that starting on January 1, 2000 all newly-manufactured drives would support region coding in hardware rather than relying on software enforcement. For the purpose of this discussion, I will call the two types of drives "old" (manufactured before 2000) and "new" (manufactured on or after January 1, 2000).

    It is that software enforcement that is going away. Turns out that the enforcement of region coding in software had its own problems:

    • It was impossible for third-parties to compile their own CDROM.SYS from the source code in the DDK because the region code enforcement code was not included in the DDK.
    • The region code enforcement code would sometimes mistake a new drive for an old one, resulting in customers unable to play DVDs. Even worse, the driver test team could not reproduce the problem reliably, and the problem went away entirely once a debugger was attached to the system.
    • The code to support the older drives is complex, and the drives that the optical storage team purchased prior to January 1, 2000 are dead or dying. Consequently, testing the code that provides support for old drives has become increasingly difficult, and when the last old drive finally gives up the ghost, testing will become impossible altogether.

    These were among the considerations which contributed to the decision to stop supporting these old drives.

    What does this mean for you? Almost certainly, the answer is "absolutely nothing".

    First, there is no change to the way data is read from DVD drives, so data discs will still work the same way as they do today. Second, all new DVD drives will continue to run as they did before; the only change is that the risk of mis-identification as an old drive has been removed. Only if you have an old drive will you notice anything different, namely that encrypted/regionalized DVD movies will no longer play. And since the average drive lifetime is only three years, the number of such old drives that are still working is vanishingly small. Not even the optical drive test team can manage to keep their old drives alive that long.

  • The Old New Thing

    What one Windows XP feature am I most proud of?

    • 56 Comments

    Of all the things I did for Windows XP, if I had to choose the one feature that I'm most proud of, it's fixing Pinball so it doesn't consume 100% CPU.

    The program was originally written for Windows 95 and had a render loop that simply painted frames as fast as possible. In the checked build, you could tell the program to display the number of frames per second. They reserved room for two digits of FPS.

    When I got to looking at Pinball's CPU usage, I built the checked version and took a peek at the frame rate. Imagine my surprise when I saw that Pinball's frame rate on contemporary hardware was over one million frames per second.

    I added a limiter that capped the frame rate to 120 frames per second. This was enough to drop the CPU usage from 100% to 1%. Now you can play Pinball while waiting for your document to print without noticeably impacting printing speed.

  • The Old New Thing

    Humanity's greatest invention, according to seventh grade students

    • 42 Comments

    When I read that Ecologist Magazine is co-sponsoring an essay contest on the topic What is Humanity's worst Invention?, it reminded me of a related essay exercise assigned to seventh-graders by a friend of mine. The students (typically thirteen years of age) were given the topic What is humanity's greatest invention or discovery? Here are some of the greatest inventions and discoveries of all time, according to these students:

    pencils airplanes vaccines refrigerators
    pets craftsman tools steam engines iPods
    alarm clocks laptops shoes transportation
    computers microbes medicine microphones
    tomatoes cars light bulbs batteries
    fire hair products toilets spear tips
    marrying a princess incandescent light

    Some sentences written in support of these claims:

    • The invention of the light bulb has literally shed light on the world.
    • The first car ever invented was the Mercedes around the early 1800s.
    • You might have to actually wash the plates (without electricity).
    • The car was first invented by Harrison Ford.
    • the one thing that makes nerds drool when they here [sic] it's [sic] name: videogames
    • We all know that IPODS have a great deal of greatness.
    • A light bulb comes with a switch to turn it off.
    • All they had to eat was tin biscuits.
    • What if someone discovers a machine to make you love forever? You couldn't have that without electricity!
    • The light bolb helps in menny dirfpeant ways.
    • This realy cool pen could wright and use the couckulater
    • Wagons can have horses pull them while riding in them.
    • It can be used for evel porpoises such as bombs.
    • Thomas Edison was a very smart, experimental man.
    • Cars make it possible for people to have space time.
    • Without electricity, housework would take all day!
    • The computer has easily beat out the dog in the man's best friend race these days.
    • The riders are throwing themselves off cliffs and hitting trees. These are happy people.
    • The catskane will be even more helpful in the furter.
    • Many school assignments would be close to impossible, or even cancelled if computers were never invented.
    • The airplane was invented by the Write brothers.
    • When the austronaughts go up into the bitch black space.
    • Without these things (electricicity) there wouldn't be a AC/DC or Led Zeppelin and that would be torture.
    • If you forgot to make your mom a birthday cake, you would need a light bulb to read the recipe
    • Back then the only domesticated animals were calvary, poultry and livestock.
    • Cars are good because they are the fastest way in and out for the C.I.A.
    • The tomato, I believe is a harmless fruit that has been around for hundreds of years.
    • When the cavemen were around they probably didn't stress good hygine, but they did likely emphasize beauty. Cavemen and women used bones from animals as hair rollers or ornaments and used animal fat for gel in their hair.
    • If you open your heart to a cat and love it forever, it will eventually love you back.

    That last one is my favorite. There's something poetic about it.

    Update 1pm: It should have gone without saying that these are hardly representative samples of the students' work but rather the most amusing ones.

  • The Old New Thing

    You probably don't want to run programs directly off your USB memory drive

    • 42 Comments

    You probably wouldn't want to run Windows or applications directly off your USB memory drive, even if you could. The reason is that the solid-state memory used by these drives support only a limited number of write cycles per block. (Originally measured in the thousands, though I'm led to believe that it's gone up since then.) Most software assume that a disk's lifetime is essentially infinite and have no qualms about writing to a file multiple times. For example, your program might decide to group its data in chunks. To modify a byte of the file, you would load a chunk, modify the byte, then write the chunk out. You've "spent" a write cycle for an entire chunk of data even though you really might have been able to get away with updating a single sector. What's more, if that one byte gets modified three times in a row, you just paid for three writes when you could have gotten away with just one if you had just done a little more caching.

    Operating systems often update a file's metadata with high frequency. The last-modified time on a directory entry gets rewritten each time the file is updated. The free block bitmap is updated each time disk space is allocated or released. The page file gets updated constantly. A database application will update its database index very frequently. Even a simple application will probably update its history and settings files often. These "hot spots" are most likely to wear out first on a drive. Unfortunately, these hot spots also tend to coincide with nonrelocatable critical file system metadata; as a result, once the sector responsible for, say, the free cluster table goes bad, the drive is useless (in the absence of hardware sector remapping).

    I know some people who wrote a so-called "Flash File System" specifically designed for this class of devices. It spread the writes out across the disk so that it wore uniformly, avoiding the "hot spot" problem. The file system came out in the early 1990's and promptly died because the hardware hadn't yet caught up to the software. It was a solution ahead of its time.

    Note that my information about the number of write cycles of flash memory is pretty old. Can modern USB drives handle millions of writes before wearing out?

  • The Old New Thing

    Whimsical embarrassment as a gentle form of reprimand

    • 39 Comments

    A few months ago, I messed up a cross-component check-in and broke the build. I'm not proud of it. (In my excitement over finally having passed a few weeks' worth of testing requirements, I absently submitted only one of the components for check-in! My change was 99% within one component, and I forgot about the other 1%.) My submission cleared the "single-component check-in" queue at around 4:30am, and before I got a chance to fix the problem at 8am, a complex job was submitted into the "multi-component check-in" queue. That job failed, of course, because I neglected to update the second component.

    A few hours later, I was greeted with a large inflatable bunny rabbit (looks similar to this guy) in my office. His name is "Bug Bunny", and it is my lot to be Bug's keeper until somebody else breaks the build. (But hey, at least I fixed it before 5pm. At 5pm, my team's lab kicks off its nightly builds, and if you break those builds, the next morning's "official team build" doesn't get released, and testers don't have anything to install.)

    I suspect many groups have an object with a similar purpose, namely to be "bestowed upon" the person who most recently messed up.

  • The Old New Thing

    It's always a good idea to check your sources

    • 35 Comments

    For a while, our cafeteria was trying to sell three-packs of bottled water. A sign proudly announced:

    Drink more water: What you should know about H2O

    Drink plenty of water throughout the day. Make it easy. Carry a bottle of water when you commute to work or run errands.

    This is what I should know about H2O?

    "Drink more water": Notice that they didn't specify a target amount. Just drink more.

    "Carry a bottle of water when you commute": I should drive with one hand on the wheel and the other hand clutching a bottle of water? Isn't that dangerous?

    And who is providing this "helpful" information?

    Source: International Bottled Water Association

    Hardly an impartial organization.

  • The Old New Thing

    The office disco party

    • 34 Comments

    One of the long-standing traditions at Microsoft is to play a prank on someone's office while they're away on vacation. You can imagine what most of these pranks are like, filling someone's office with packing peanuts or other materials, or relocating their office to an unlikely part of the building (the bathroom, the cafeteria), or something more subtle like mirror-reversing all the furniture in the office. Redecorating an office is a common theme, such as turning their office into a French bistro or a golf course (with real grass).

    One particularly memorable office redecoration was from 1996 or so. One of the managers, let's call him "Bob", had a bit of a reputation for being "cool" in a nightclubby sort of way. While Bob was away on vacation, his team set to work. They emptied his office completely, painted the walls black, removed the ceiling tiles to give it that "industrial" look, and installed a disco dance floor, disco lights, and a stereo with turntable.

    It was Disco Bob's Party Palace.

    When Bob returned, there was quite a happenin' disco party waiting for him.

  • The Old New Thing

    Why do up-down controls have the arrows backwards?

    • 29 Comments

    When you create an up-down control (some people call a "spinner" control) in its default configuration, the up-arrow decrements the value and the down-arrow increments it. Most people expect the up-arrow to increment and the down-arrow to decrement. Why is it backwards?

    The up-down control is a victim of Windows' reversed y-axis.

    Mathematically, the (0, 0) coordinate should be at the bottom left corner of the screen (and in fact that's where OS/2 puts it), with y increasing as you move up the screen. Windows, on the other hand, puts the (0, 0) coordinate at the upper left corner, with y increasing as you move down the screen.

    What does that have to do with anything?

    The up-down control can be positioned horizontally or vertically. Let's first look at the less problematic horizontal configuration. Windows and mathematics agree that the x coordinate increases to the right, and the right-arrow (the arrow with higher x-coordinate) causes the value to increase. (Let's leave right-to-left languages out of the picture for the purpose of this discussion.)

    Once you have the horizontal version of the control working, converting it to a vertical control is a simple matter of interchanging the x- and y-axes.

    That's why the up-arrow decreases the value. The up-arrow points towards smaller y-coordinates and consequently decrements the value.

    It's perfectly logical and simultaneously counter-intuitive. (It's slightly more intuitive if you imagine the value attached to the up-down control as controlling the y-coordinate of an imaginary object on the screen. In that case, clicking the up-arrow causes the y-coordinate to decrease and the object moves up the screen.)

    Fortunately, this wackiness doesn't last long, because the moment you change the range of the up-down control from the (not very useful) default of 0–100 to whatever you actually need, the arrows behave "normally" again.

    Perhaps intuitiveness should have won out over logic. But what's done is done, and, as noted above, the problem goes away soon enough.

    [Raymond is currently away; this message was pre-recorded.]

  • The Old New Thing

    On the ambiguity of uniqueness

    • 27 Comments

    The MSDN documentation for System.Object.GetHashCode says

    [T]he implementation of GetHashCode provided by the String class returns unique hash codes for unique string values.

    This is another case of ambiguous use of the word "unique". The intended meaning is "for each string value, the same hash code is returned".

    Even though "unique" means "one and only one", the domain in which the term applies is often left unsaid, as here, where the domain of comparison is "all the hash codes returned for a specific string value". If you instead misinterpreted the domain as "all the hash codes returned for all string values", then you end up erroneously concluding that no two strings hash to the same value.

    Another conflicting sense of "unique" is "you get the same one each time" as opposed to "you get a different one each time".

    • GetCurrentProcessId returns a unique value that identifies the process. You get the same one each time.
    • CoCreateGuid returns a unique GUID. You get a different one each time.

    In the original C standard, malloc(0) is permitted to return NULL or "a unique pointer". What does "unique" mean here? Does it mean that the non-NULL return value is always the same? Can I assert(malloc(0) == malloc(0))? Or does it mean that the non-NULL return value is a value distinct from any other return value from malloc()?

    In Technical Corrigendum 1, this ambiguity was resolved by removing the word "unique". Instead, the specification says "as if the size were some nonzero value" which makes it clear that it is the second interpretation that is intended.

    My suggestion: Don't use the word "unique". It's too ambiguous.

Page 1 of 4 (33 items) 1234