Writing Filesystems - Sourcecode Structure
From Genunix
| 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! |
[edit]
Sourcecode/Binaries for Solaris filesystems - what do you need ?
Run the following shell command on a Solaris system:
grep '/fs/' /var/sadm/install/contents
What do you get ?
Lots of output is the answer. You'll find:
| Subdirectory | Description |
|---|---|
| /kernel/fs/fsname /kernel/fs/sparcv9/fsname | These subdirectories contain kernel filesystem drivers. They are, like all kernel drivers, architecture-specific binaries. An x86 machine doesn't have the /sparcv9/ subdirectory, and sparc systems will of course have no 32bit x86 or amd64 drivers. |
| /usr/lib/fs/fsname/ /etc/fs/fsname/ | These subdirectories contain filesystem-specific utilities. Essentially all of the Solaris command line utilities related to file/filesystem management accept the -F fsname parameter, to select which filesystem types to apply to. This includes utilities like mkfs, fsck, mount, umount, fstyp, tunefs, df, fsdb and many others. The generic command which goes into /usr/bin will call (and pass through to) the filesystem-specific utility if available. It is not necessary for all filesystem types to provide all utilities. The only one that must be available is the mount command. Note that there is no written-down standard which declares that unbundled filesystems must provide utility backends for certain utilities. Whether you have/ship 'advanced' commands like quota, fssnap, or even basic ones such as fsck or mkfs is all up to you (although, if the filesystem is read/write capable, not shipping mkfs would be a bit rude to the users ... and likewise, unless the filesystem is always-consistent, would be not shipping fsck). This has, in the past, lead to kind of cancerous growth of utilities, like semi-duplicated functionality in newfs and mkfs. The best suggestion which of those utilities you should provide is: Check what your filesystem can do, then identify whether there's already a Solaris command doing something like it, and if so just provide the backend. Should that not be the case, you can always go for a name like myfsfoobarutil. |
| /usr/include/sys/fs/ | This subdirectory contains the header files used by the various filesystems. These headers have definitions for the filesystem's metadata structures, both on-disk (if the filesystem is disk-based) and in-core (as used by the filesystem driver internally for instance/file state). It is not strictly necessary or mandated to provide header files since these of course deliver some insight into the internal workings of the filesystem driver and its associated utilities, which may contain sensitive/proprietary information. Whether a specific filesystem ships its associated header files and so allows "3rd party utilities" to be written is up to the vendor/author of that filesystem. |
All this means that a Solaris filesystem contains the following:
- A kernel driver, which must be provided in 32bit/64bit for the appropriate platform
- A set of filesystem utilities that - at the very least - allow the user/admin to mount a filesystem of this type. Even if the filesystem is readonly, a disk-based one should also have fstyp, and if it's writeable mkfs better be there as well.
- A set of filesystem headers, so that developers can create their own 'advanced' utilities if they like (and you wish to allow them to do so).
If you compare the above deliverables list with the OpenSolaris sourcecode, you find that there is a match for it in the sourcecode directory layout of the ON consolidation as well. The sourcecode structure looks like this:
| Sourcecode directory | Resulting deliverables | Description |
|---|---|---|
| usr/src/cmd/fs.d/fstype/ | /usr/lib/fs/fstype/ | Userspace utilities for managing filesystems of this type |
| usr/src/uts/common/sys/fs/ | /usr/include/sys/fs/ | Header files for this filesystem type |
| usr/src/uts/common/fs/fstype/ | n/a | Sourcecode for the kernel driver |
| usr/src/uts/intel/fstype/obj32/ | {/usr}/kernel/fs/fstype | Build target / installation directory for 32bit Solaris/x86 filesystem driver modules |
| usr/src/uts/intel/fstype/obj64/ | {/usr}/kernel/fs/amd64/fstype | Build target / installation directory for 64bit Solaris/x86 (amd64) filesystem driver modules |
| usr/src/uts/sparc/fstype/obj64/ | {/usr}/kernel/fs/sparcv9/fstype | Build target / installation directory for Solaris/SPARC filesystem driver modules (there is no 32bit kernel on SPARC anymore) |
The next section will show how to create the "process glue" (goo ?), in your actual filesystem workspace.
