Writing Filesystems - Introduction
From Genunix
aczelrolra
| This article has been identified as a draft. It is currently undergoing a community review. Please add your comments to the discussion page.
Do not quote any text on this page! It is still a draft! |
Well, where do you start with a topic such as this one ? Traditionally, the documentation for device driver development on Solaris has avoided mentioning the possibility to write filesystem drivers. It's undocumented, and deliberately so, because the filesystem "DDI" interfaces are not stable and change, sometimes even within the release cycle of a particular Solaris version. The interface between the VM subsystem and a filesystem likewise isn't documented, nor committed to. The consequence of this is that filesystems cannot be written in the same way as hardware/pseudo/streams device drivers are - based on only public and well-documented interfaces.
Filesystem drivers on Solaris therefore, again traditonally, have been based on "template" code - that means old-enough ufs sourcecode floating out there amongst the void called the internet (from ARPAnet via Usenet to WWW ...), and on a lot of hearsay "that's how it's done". This has made 3rd-party filesystems for Solaris a scarce thing, since few companies (and even fewer individuals) have had the resources and/or willingness to keep up with Sun changing the interfaces, and to reverse engineer ufs functionality in order to answer the question "how do I ... ?".
The release of OpenSolaris has opened an entirely new playing field here. While Sun can still claim to say the interfaces are undocumented, and reserve the right to change them if so desired, the availability of the OpenSolaris sourcecode at least makes the interfaces visible to the public - and makes current, working and maintained Solaris filesystem sourcecode available without requiring time-consuming reverse engineering efforts or expensive NDA Solaris sourcecode licenses.
It's therefore about time to give an introduction about what's involved when writing a Solaris filesystem, in particular a disk-based one, and give a simple yet complete "template filesystem" that can be used as a starting point for own implementations, and avoids both the huge complexity of mature/feature-loaded implementations like UFS or ZFS, and the errors and design flaws in too-simple implementations like the existing PCFS or HSFS filesystem drivers.
A few words of caution in advance ...
The coding hints and explanations here are not officially sanctioned. This series is not claiming to provide the once-and-for-all guide to creating Solaris filesystems, and some of the code samples shown will definitely not be applicable to all filesystems. The purpose of this series is to show how it can be done, not how it is done correctly - I make no claim of correctness. Please be aware that there is a reason why Sun does not elevate the "filesystem interface" to the same level of stability as DDI - these interfaces evolve quickly. A filesystem driver written for Solaris 8 will not even compile anymore on OpenSolaris, and much less so run. While Sun has gone great strides in abstracting usage models for functions and data structures in the filesystem interfaces, it's still neither static nor stable. Whoever develops filesystems for Solaris therefore should better sign up for filesystem-related discussion lists on http://www.opensolaris.org in order to stay current and get notified when so-called flag days occur (changes that modify these interfaces). It's also a good idea to read filesystem code for several of the Solaris filesystems, in order to get a broader view of "how is it done". You can look at the sourcecode for bundled Solaris filesystems via http://cvs.opensolaris.org/source/xref/on/usr/src/uts/common/fs/ in the OpenSolaris source browser.
