Question

Windows has several "virtual folders" and "special folders" (Wikipedia's names for them) that change the way the file system works. For example, the Desktop folder acts like the root of the file system hierarchy in some circumstances, even though C:/ is the drive, also called the partition, that the entire file system is on, and therefore logically Desktop should be under C:/. Screenshots:This PC circled">This PC, showing that C:/ isn't always the root of the filesystem"> There are also the Library folders. Also, with msysGit and Cygwin on your computer, the program's folder then magically becomes the root of the file system.

I'm sure there are instances on other OS's, but I only really work with Windows, although it seems Linux is much less abstracted.

How do applications do this? Is it just a really complicated shell script, or something that only affects certain programs (Wikipedia says Desktop is only the root folder in Windows Explorer, for example)? Is it similar to how on Linux all folders are "mounted", even the root folder? Even if the OS developers don't usually give away their secrets, I would still like to know the basic method, if possible.

Was it helpful?

Solution

So, wikipedia's entry for special folder says that:

The Desktop virtual folder is the root of the Windows Shell namespace, which contains other virtual folders.

This is not the same as saying it's "the root of the file system hierarchy". Windows has a set of set of virtual folders. All of these are nested under Desktop.

For Win7 and up, the default filesystem layout is actually:

  • Desktop -> C:\Users\(username)\Desktop
  • My Documents -> C:\Users\(username)\Documents
  • Downloads -> C:\Users\(username)\Downloads

These aliases mean something to the explorer shell, but not at the filesystem level (open cmd.exe and see what I mean).

At the filesystem level, and to an application, the filesystem path is what is going to matter. It takes extra API calls (the use of SHGetSpecialFolderPath()) to figure out where on the filesystem that special folder lives; the app only cares about where in the filesystem it needs to target.

As for Cygwin, I strongly suspect that it's doing something totally different. Unix has a special call, chroot(), that really does modify the root for the currently running shell. This means that applications running under that shell have absolutely no knowledge of the directory structure below the chroot()'d path, and this is generally done for security reasons. In fact, this is usually referred to as a chroot jail, because it isn't an alias or a virtual directory, and can't be escaped from (unless there's a bug in the kernel).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top