0

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:Picture of Desktop folder, with <code>This PC</code> circledPicture of <code>This PC</code>, showing that <code>C:/</code> 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.

tshepang
  • 12,111
  • 21
  • 91
  • 136
trysis
  • 8,086
  • 17
  • 51
  • 80
  • Would the downvoter care to elaborate on what he/she didn't like about my question? Maybe I could fix it. – trysis Mar 06 '14 at 20:43

1 Answers1

2

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).

Lynn Crumbling
  • 12,985
  • 8
  • 57
  • 95
  • For all intents & purposes, Desktop (the virtual folder, not physical) acts as the root of the filesystem hierarchy, at least to some programs like Windows Explorer. That's what I was trying to say. I noticed the Desktop folder inside C:\Users\, and always wondered if that were the same folder as the virtual Desktop. – trysis Mar 06 '14 at 22:52
  • if Cygwin uses a chroot jail, how do you access the whole file? Also, this doesn't explain how the explorer shell puts `C:/` under `Desktop`. Thanks. – trysis Mar 07 '14 at 01:18
  • It seems like you forgot to take out one of your "username"s. I hope you don't mind, but I suggested the edit for you. I'm not sure how it works, but I think if you say OK it stays. Either way I'm fine with it; at least I brought it to your attention. **Edit**: Nevermind, I see you already accepted it. – trysis Mar 07 '14 at 01:52
  • @trysis Thanks for catching that. It was near the end of the day and I was ready to head out. – Lynn Crumbling Mar 07 '14 at 02:52
  • @trysis re: C:\ and Desktop -- and the answer is, it can't; `Desktop` is actually a subdirectory down below C:\. The trees to the right of my explorer pane show (1) Favorites, (2) Libraries, (3) Computer, and (4) Network. Could you post a pic where you're seeing C:\ nested under `Desktop`? – Lynn Crumbling Mar 07 '14 at 03:06
  • No problem. As to `C:/` being under `Desktop`, well, technically it's 2 folders under. From `Windows 8` & back I forget how far, the hierarchy goes `Desktop->My Computer->C:`. On `8.1`, replace `My Computer` with `This PC` (supposedly because it reflects how computers are now a commodity because of the Internet, but I personally don't like it). I'll post a screenshot, give me a second. – trysis Mar 07 '14 at 03:50
  • Posted pictures. Sorry, they're huge, I'll try to shrink them while still letting them be legible. – trysis Mar 07 '14 at 04:00
  • @trysis Ha - no, they're great. Ok, so "This PC", aka "My Computer" isn't even a virtual directory. I'm not sure what to call it, other than a top-level container that isn't anything other than a list of drives on your system (C:, D:, etc), favorites, etc. Just to give you an idea of just how much of a placeholder this is, take a look at [this superuser question](http://superuser.com/q/655804/105558) that discusses how to remove folders from being listed in it. Applications will never care about "This PC".. it's purely for users to have a nice starting place. – Lynn Crumbling Mar 07 '14 at 04:34
  • Wow, so you can delete folders by modifying the `registry`? O.O... I have seen references to folders being `XML` files, maybe `My Computer`/`This PC` is one of these. Still leaves open the question of how in the heck THAT can happen, but that's another story, that will be told another time. – trysis Mar 07 '14 at 04:50