4

I saw an ad on StackOverflow today for a project called WinFsp.

The site mentions the following features:

  • Allows for easy development of file systems in user mode. There are no restrictions on what a process can do in order to implement a file system (other than respond in a timely manner to file system requests).
  • Support for disk and network based file systems.
  • Support for NTFS level security and access control.
  • Support for memory mapped files, cached files and the NT cache manager.
  • Support for file change notifications.
  • Support for file locking.
  • Correct NT semantics with respect to file sharing, file deletion and renaming.

Out of sheer curiosity: what might such library be used for? Why would anyone want to re-implement NTFS or something similar?

closed as primarily opinion-based by gnat, TMN, DeadMG, Christophe, Doc Brown Jul 8 '16 at 5:42

Many good questions generate some degree of opinion based on expert experience, but answers to this question will tend to be almost entirely based on opinions, rather than facts, references, or specific expertise. If this question can be reworded to fit the rules in the help center, please edit the question.

  • This case study explains in detail one example of its use: secfs.net/winfsp/develop/sshfs – Robert Harvey Jul 7 '16 at 15:12
  • Here's a good article on pros and cons of user mode file systems. It's focused on Linux, but WinFsp seems to be a Windows version of the same concept. – Eric King Jul 7 '16 at 15:16
  • For experiental, scientific purposes? And why not for Windows? – Doc Brown Jul 7 '16 at 20:15
  • This is definitely too opinion-based. A simple answer would be "Because they're on drugs" and you can't disprove it in any way. – DeadMG Jul 7 '16 at 21:50
  • Not so long ago, DropBox announced Infinty, to offer cloud storage as if it were on the local disk (today dropbox uses a replication mechanism creating a local copy on your drive). It appeared that they want access to the kernel to implement this. I guess that this project intends something similar but with the more reasonable user-mode approach. – Christophe Jul 7 '16 at 23:41
4

There are two aspects to that question: why would one want to develop a filesystem interface to data, and the other, why would one want to do that in userspace?

Let's answer the second one first, because it's the obvious one: because it is waaaaayyyyy easier. In fact, the question should be asked the other way around: why would one want to implement a filesystem in the kernel? Why would one want to implement anything in the kernel, really? And the answer is: you don't want to implement anything in the kernel. You do it, because you have to, because you can't implement it any other way. Well, in this case, you can, and so you do.

The first one is a bit trickier: why do we want to have a filesystem interface to data? And the answer is: because there is a vast amount of tools that can work with files, so by exposing data as files, you get access to all those tools.

Imagine for example a metadata filesystem, which exposes file metadata as files within a folder. So, an MP3 or a JPEG file would appear as folders and you could cd into an MP3 file and inside that folder, there would be files like artist.txt, title.txt, album.txt, lyrics.txt, etc. Now, if you wanted to mass-edit the titles of your MP3 files, you wouldn't need to use a tag editor that someone else wrote, which may lack the certain feature you need, you could just use all the tools for editing text files you are familiar with – and editing text files is something we have been doing ever since the dawn of computing, so we are very good at that! (Or similarly, delete all author info from all Word documents on your system, would be absolutely trivial!)

Or, imagine a gitfs, which exposes branches, tags, commits, etc. as folders, and you can explore your history using the same tools you already know how to use for exploring your filesystem. Or, a mediaconvertfs, which exposes all your audio files, regardless of which format they are actually in, as MP3 files and converts them on-the-fly. A firefoxfs which exposes Firefox's browsing history or settings as a folder hierarchy. A filesystem that can mount your Google Drive, Dropbox, iCloud, OneDrive, etc. as a folder hierarchy. A gmailfs that can mount your emails as a folder hierarchy. A wordpressfs that lets you edit your blog as a folder hierarchy. And so on.

Note that something similar is already happening in the Windows world. For example, PowerShell has very generic "cmdlets" that work with all sorts of objects, and files and folders are just yet another kind of object. However, this requires all sorts of new cmdlets to be written that can work with those generic objects, and it only works in PowerShell. The approach of a userspace filesystem is dual: instead of treating files as just objects and writing cmdlets that deal with objects, you treat objects as just files and rely on the vast amount of tools that have already been written for dealing with files. Similarly, the Windows explorer tries in some cases to pretend that something is a folder hierarchy when it really isn't, and lets you navigate it that way. But, that only works in the Explorer, it doesn't work anywhere else, whereas exposing something as a filesystem works everywhere, because everything knows how to deal with files.

Another different thing you can do with a userspace filesystem is to rapidly implement other actual filesystems. Remember, writing kernel code is harder than writing userspace code. So, it is often faster to implement a filesystem in userspace than in the kernel. In the Linux world, for example, there used to be a very clever implementation of NTFS using a userspace filesystem: it was implemented as a compatibility layer that emulates the NT kernel, and then simply used the actual ntfs.sys file from Windows! The disadvantage is that this is somewhat slow, and it requires you to own a Windows license (to copy the ntfs.sys from), but the advantage is that it is by definition always correct! How much more compatible can you be than using the actual filesystem driver code from Microsoft itself?

You could do something similar the other way around. E.g. e2fsprogs contains libext2fs which is a userspace implementation of the ext2/3/4 filesystem family. This library is already used by several Ext2 for Windows tools, but those tools are usually one-off filemanagers that allow you to copy files to and from the filesystem but not much else. It shouldn't be too hard to build a "proper" userspace filesystem driver around it, to seamlessly mount ext2/3/4 filesystems the same way you can mount NTFS and FAT filesystems today.

  • PowerShell does have a kind of usermode filesystem, although it only works within the PowerShell environment, not systemwide. But you can cd AD: to walk Active Directory as if it was a filesystem, cd hklm: to walk into the registry, and use cmdlets to process their contents in the same sort of way as files and folders. Also the function namespace, variable namespace are exposed the same way. Get-PSProvider will list the ones available. – TessellatingHeckler Jul 8 '16 at 1:58
  • Thanks for explaining in so much detail, I really appreciate it! – MarioDS Jul 8 '16 at 7:19
4

More specifically, why would anyone want to build a User Space file system?

  1. Easier semantics. No obscure system calls.
  2. Better isolation. A User Space file system crash doesn't bring down the whole OS.
  3. Easier to update than the kernel.
  4. Support for several programming languages.

You're not re-implementing NTFS. What you're actually doing is adding features to an already-existing file system, creating a file system metaphor over some existing data store, or providing a universal file system API. Imagine being able to browse a SQL database using file explorer, or integrating mail communications as files.

1

At a glance, it appears to be similar to FUSE, which is used for the development of dozens of filesystems and filesystem-like tools. Essentially, anything that makes sense in the form of files and directories can be exposed as a filesystem, and mounted through FUSE or WinFsp as if it were a physical disk, all with the added benefits of running as a user process instead of as a kernel service.

For example, Gnome GVFS uses FUSE to expose its GIO interfaces and to present SFTP, SMB, HTTP, DAV, and a lot of other services as filesystem mounts, so that you can use, for example, SFTP as if it were a disk in your system.

Not the answer you're looking for? Browse other questions tagged or ask your own question.