views:

107

answers:

9

Linux has a feature called namespaces, which let you give a different "view" of the filesystem to different processes. In Windows terms, this would be useful for example if you had a legacy program "floyd" that always loaded its configuration from C:\floyd\floyd.ini. If Windows had namespaces, you could write a wrapper script which would create a namespace in which to run floyd, making it so when Alice ran the script, floyd would start up in an environment where C:\floyd existed but actually pointed to C:\Users\Alice\Floyd.

Now you may be thinking, "OK, just use soft or hard links and make C:\floyd an alias for C:\Users\Alice." But with namespaces, Bob can also run the startup script, but his instance of floyd (on the same computer, running at the same time) will see C:\floyd with the contents of, say, C:\Users\Bob\Program Settings\Floyd Config (or any other path we like).

You can do this on Linux with namespaces. Is there something similar or analogous on Windows? It's fine if it requires writing a C program, and it's OK if it only works on recent versions of Windows.

A: 

You can use hardlinks for that, but only with NTFS. http://en.wikipedia.org/wiki/Hard_link

I think windows doesn't have virtual FS view per process.

munissor
i don't think that's even close...
Matt Joiner
Windows certainly has a virtual FS view per login session; remote drive mappings are generally inaccessible to other users on the same machine.
MSalters
MSalters: can remote drive mappings be different in different instances of say a command prompt for a single user? Or do they only differ at the level of a user's terminal session? I actually want to be able to have one logged-in user launch the thing in more than one "namespace" in some cases (i.e. Alice and Bob might be using the same Windows login session, just launching two different scripts).
John Zwinck
Users cannot share login sessions; Alice and Bob will have at least two. After all, they both logged in at least once. But if Alice logged in precisely once, all her command prompts will share the same drive mappings.
MSalters
What I meant is that Alice and Bob might both use the computer while logged in as "Home User" or whatever. You might say that's bad practice, but what I'm really getting at is that Alice may want to run the program with two different configs (Alice1 and Alice2). So I guess this idea won't really do it for me, which is fine.
John Zwinck
A: 

The most relevant thing is probably special environment folders, such as %temp%, %appdata%, %localappdata%. Not that they're equivalent, but they fulfil the same purpose.

You can define your own environment variables then use '%myspecialplace%\myfile.txt' to access them.

Tim
I think this assumes I can edit "floyd," which I cannot do.
John Zwinck
A: 

I think Virtual Store does this automatically for legacy programs that try to write to nonstandard directories. So the legacy program writes to a user- and program-specific directory instead to C:\floyd.

Philipp
I don't think random folders like `C:\floyd\` are virtualized. The Windows directory and Program Files directory both are.
MSalters
MSalter's take on this matches my own (limited) understanding, which means I can't use this to do what I need.
John Zwinck
A: 

This sounds like Windows Vista's file system virtualization. For example, it can silently redirect c:\Program Files\Floyd to c:\Users\<username>\AppData\Local\VirtualStore\Program Files\Floyd. However, file system virtualization isn't nearly as configurable as Linux namespaces. From what I can tell from reading, file system virtualization should apply any time a 32-bit interactive process opens for writing a file, folder, or registry key that's only writable by administrators. (So you typically end up with some read-only files under c:\Program Files and some per-user writable files under c:\Users\<username>\AppData\Local\VirtalStore.)

An application virtualization product can probably also do this, although those are often more complicated and more expensive.

Josh Kelley
A: 

As a horrid kludge (and here I book my passage to programming hell) could you use a NamedPipe for C:\Floyd that mapped the IO operations onto a file specific to the current process user?

I know it's not pretty and I don't know enough about NamedPipes (FIFOs in other dialects) on Windows to know how feasible this is.

Dan

Dan Kendall
Nope; the name `C:\Floyd` is recognized as a composite name, and `C:` is (considering the setup) a symbolic link in the kernel namespace, referring to a (NTFS or FAT) partition. Hence the `Floyd` part is resolved relative to that.
MSalters
On Windows, all named pipes are created in the `\\.\Pipe\` directory, they can't be named like normal files.
Ben Voigt
Thanks for the info guys. It's probably for the best that this is not a feasible approach.
Dan Kendall
+3  A: 

NTFS hard links are really a simple case of reparse points. Reparse points are typed, and can include more advanced behavior. For instance, they're also used for "offline storage" (transparent migration of files to and from secondary storage). You can therefore also use reparse points to implement per-user symbolic links, by creating a new reparse type.

The reparse point type even has an explicit "Name surrogate" bit, which (if set) indicates that reparse points of those types are some kind of symbolic link.

You can even have multiple reparse points in a path. Therefore files inside your symbolic namepace can still be migrated to secondary storage - you'd just have two reparse points in the path.

MSalters
Are there any tools related to this functionality, or would I have to basically define my own "application" tag for a reparse point data type, and write my own filesystem filter to actually implement the behavior of per-user symbolic links? I appreciate the answer very much for pointing me to the raw bits I could use, but at a glance this appears to require some pretty substantial work--just want to confirm my estimation matches yours.
John Zwinck
It's non-trivial, yes. I don't think you need a filesystem filter (because your reparse point performs only a simple redirect) but you do need a low-level component that can create and interpret your type of reparse points. Toolwise, I'd expect more information in the IFS SDK or DDK.
MSalters
A: 

e.g. http://www.msigeek.com/4819/file-re-direction-using-correctfilepaths-shim-to-fix-broken-applications

But I think it's not configurable per user, although the target can vary per-user based on environment variable substitution.

Most programs, though, store configuration in the registry, in which case RegOverridePredefKey would do the trick.

Ben Voigt
A: 

There are several things that come to my mind.

First of all you can create a file system filter driver (or use a ready driver, such as our CallbackFilter product) that would redirect all file system calls, coming from the application, to other location. This is close to virtualization that you mentioned but this won't change the list of drive letters though. Such approach is both powerful and non-trivial, so see the other option first of all.

And the other option is: there exist several products (Thinstall, Molebox if memory serves) that "wrap" the application redirecting it's file I/O to some other location. There was also some SDK to do the same, but I don't remember it's name at all.

Eugene Mayevski 'EldoS Corp
A: 

There's a shortage of good solutions for this. For simplicity, I can't improve on using NTFS soft links (junctions) for this - as you correctly point out, this creates issues if you want per-user configuration. As MSalters correctly says, all NTFS soft and hard links are just special cases of reparse points, so you could do something more general by impplementing a new reparse type, if you don't mind some work digging into NTFS..

(Junction is a pretty useful tool when experimenting with NTFS soft links: http://technet.microsoft.com/en-us/sysinternals/bb896768.aspx )

You could just take a direct approach - give each user (or your program initialization if you only care about one piece of software) a logon script that sets up the appropriate junction into their user directory (and make sure you clean it up afterwards). But it's clumsy.

In general the right Windows approach is to put things into the folders pointed at by the %localappdata% (from Vista on) and, more generally, %userprofile% system variables. Win file system virtualization is intended to ensure this in the cases where it applies.

Tynam