Windows ConfidentialA "Mixed" Blessing

Raymond Chen

When you insert a CD or DVD , the shell "sniffs" the disk to determine what type of content resides on it. This determination then guides the shell in deciding which autoplay action it should perform. The precise details of how the sniffing is done are not documented because they are heuristics that can change in the future if a better algorithm is found.

Formally documenting the algorithm would make it contractual, thereby preventing the algorithm from being tweaked in subsequent releases. Officially, therefore, the details of the algorithm are left unspecified.

If you've never written documentation for an SDK, you may not have realized that documentation leads to contract. Once you go on record that something behaves a certain way, you can't change it. If you do, people who were relying on that behavior will say, "Hey, that's not what the documentation says. You're changing the rules after the game has started."

With that caveat out of the way, here's a quick, incredibly oversimplified description of how Windows® XP Service Pack 2 (SP2) categorizes the contents of data CDs and data DVDs that lack an autorun.inf file. (Future service packs and future versions of Windows may behave differently.) I say "incredibly oversimplified" because the actual algorithm is a 61-step decision table that takes into account all sorts of information like whether the foreground application responded to the "Query cancel autoplay" notification, whether a full-screen program is running, and even whether the computer is a laptop that was recently docked or undocked. But I'm going to look only at the content-sniffing step.

  

First, the shell checks whether the user specified "Take no action" as the action for all content types. If so, then there's no point sniffing. The decision is simply "Take no action."

Otherwise, the shell has something to do. It looks at each file on the disk-up to four directories deep-and puts them into one of the following categories based on their perceived type: image, music, movie.

Files that don't fit into one of the these categories are ignored. If only one category is represented among all the files that were checked (say, for instance, all the files on the disk are music files), then that establishes the type of disk. If more than one of the three categories is represented, then the disk is deemed mixed content.

This means that album art on your CD full of music files will cause the CD to be treated as mixed content by Windows XP SP2. This is one of those things that could probably stand some tweaking. But suppose this algorithm did get tweaked, and we decided that an occasional picture on a CD full of MP3s should not tip the balance to mixed content. Some company might have a CD with a lot of audio files and just a few pictures on it. The company does, indeed, rely on the CD being detected as mixed content. But when the algorithm changes, the CD gets miscategorized as music. Now that company is upset. But who is to blame for this problem? Can the company be blamed for relying on the details of the sniffing algorithm? Or is Windows to be blamed since it is responsible for changing the algorithm?

Lo and behold, in Windows Vista™, the algorithm has changed-albeit only slightly. In Windows Vista, several checks are made up front to short-circuit the algorithm for certain well-known disk layouts. For example, if a DCIM folder is present in the root of the disk, then it is assumed to consist of digital pictures. Now we'll wait to see if anybody notices.

Raymond Chen’s Web site, The Old New Thing, and his identically titled book (Addison-Wesley, 2007) deal with both Windows history and Win32 programming. Raymond wonders what the sun looks like.

© 2008 Microsoft Corporation and CMP Media, LLC. All rights reserved; reproduction in part or in whole without permission is prohibited.