Developing "File Systems" for linux, mac, windows
What technologies do applications such as dropbox (http://www.dropbox.com/) a开发者_如何学JAVAnd expandrive (http://www.expandrive.com/mac) use to build functionality right into the local filesystems on each platform? Can anyone suggest anything that would allow for maximum code reuse on all of the major platforms?
I've only looked into FUSE on linux so far and I like what I see.
Implementing a virtual file system is very OS-specific. The reason is that architecture of drivers is different in Unix-like OS and in Windows.
To avoid writing your own driver, you can use user-mode file system toolkit. On Linux, BSD and MacOS there exist FUSE and OSXFUSE (fork of now-inactive MacFUSE) respectively. On Windows our Callback File System is used.
Dropbox at the moment doesn't have a virtual file system but only shell extension (afaik they planned to create a virtual disk but I don't know what they have decided).
Regarding how file changes are tracked: there exist several methods. The simplest is to scan the directory on timer and compare timestamps and file sizes. Next, one can use FindFirstChangeNotification WinAPI function. And the most sophisticated and most reliable method is to use a filesystem filter driver. On Windows our CallbackFilter can be used. On MacOS X and on Linux you can get post-notifications similar to what FileSystemWatcher offers in .NET/Windows. In particular, on Linux, one can use inotify.
What you are after are usrspace filesystems. I don't know if there is a unified solution for implementing userspace filesystems on all (or most of all) platforms (probably not), but here's a starting point:
- for linux and (I think only some) unices: fusefs
- for windows: dokan
- for mac os: macfuse
I am not familiar with all of them so I don't know how easy is to code proxies/interfaces so you can seamlessly implement filesystems in a platform-independent manner. Anyway, the operations that a filesystem is supposed to support are (to some extent) the same for everyone (open,read,write,etc) so at first sight this seems to be an easy start (even if coded with C preprocessing techniques, altho you may want to take a look at C++ boost libraries which are supposed to be highly platform independent and offer some good platform independent development tools as well).
Good luck!
I've sort of encountering similar issues as yours: developing "cross-platform" file systems.
- If you are going to develop a native file system, the best you can do is try to isolate as much as your file system algorithms (calculating disk-layout, checksums, directory data structures and etc.), besides the os-specific APIs, into ansi-c. You may read through ZFS code, which is considered well written so that it is relatively easy to port to FreeBSD/Mac/Linux.
- Otherwise, if you can satisfy with the performance costs of user-land file systems, to maintain a file system across Mac/Linux/BSD is trivial. Using POSIX API, FUSE and 3rd-party libraries available on each platform, which is what I am doing now. However for windows, I've heard a FUSE implementation, but I don't think it is production-ready. So, as same as developing native file system, try to encapsulate your file system logics in ansi-c as much as possible.
it's quite easy on Windows to listen for file changes: http://msdn.microsoft.com/en-us/library/atwhk15d(v=vs.80).aspx
This is an example for a Mac OS FUSE implementation: http://www.macupdate.com/app/mac/23729/macfuse
精彩评论