GSoC/GCI Archive
Google Code-in 2010 DragonFly BSD

code: write a libfsid

completed by: Ákos Kovács

mentors: Alex Hornung

The aim of this task is to write a library that provides 'probe' and 'volume name' functions for different file systems. They both take a device name (i.e. /dev/da0s1a); the first type, 'probe', should return '1' if the device has a volume of that FS type (otherwise 0). 'volname' would return the volume name if that is available on such an FS and that particular volume or NULL otherwise.

While this task might sound a bit overcomplicated in its formulation it should become very clear once you had a look at sbin/fsid.

The approach to doing this is the following:

  • create a lib/libfsid with a simple Makefile copied from any other lib/foo Makefile
  • move the file-system dependent magic from sbin/fsid to the new libfsid (fsid currently has probe and volname for ufs and hammer)
  • also copy over the array of structs containing information on all known FS and their functions
  • create some wrapper functions around the file system dependent parts:
    • a function to probe a specific fs; i.e. fsid_probe(char *dev, const char *fs_type) => fsid_probe("/dev/da0", "HAMMER") => would call the hammer-specific probe routine to probe /dev/da0.
    • a function to probe with all known FS; i.e. fsid_probe_all(char *dev) => fsid_probe("/dev/da0") => would call all probe routines for all available FS and return the name of the FS that the device is using. for example if /dev/da0 is using UFS, I'd expect a string "UFS" back; or a type UFS which is a #define.
    • the same as above for volname
  • add some more probe and possibly volname functions for:
    • cd9660 (iso 9660)
    • ext2
    • msdos[fs] (fat16, fat32)
  • as a proof of concept modify sbin/fsid to use the new lib/libfsid