Before we define a file system, we need to define the physical layer. Since the file system needs to be independent of the hardware, a simple abstraction of a disk is chosen.
The disk is abstracted as a simple collection of contiguous sectors. This is implemented through the data structure FS_DISK, which contains the following:
- The Sector size in bytes
- The number of the first sector in the disk
- The total number of sectors in the disk
- A pointer to a function that reads arbitrary sectors
- A pointer to a function that writes arbitrary sectors
The first 3 items are self-explanatory and completely define the group of sectors that will be available to the file system. The last two are functions that a driver needs to implement and that will be used by the file system to access sectors in the disk. Using this simple abstraction, the file system can be used with any physical media, like hard drives, flash memory, ram memory or even a file within another file system. This allows the CleanFS library to be used both to access physical media and also as an archiving tool, creating entire file systems within a file.
The developer must fill and provide the FS_DISK structure, including implementing the read and write functions, in order to use the CleanFS file system.
A volume defines the extent of the file system within the disk. The file system might take the entire disk or not.
The volume is represented by the data structure FS_VOLUME, and is one of the most important data structures in the file system library, containing everything necessary to access the volume. The contents are implementation defined, and the user of the library need not know what is inside this structure.
When mounting the volume, the file system will fill out the FS_VOLUME structure with proper information. This structure will have to be passed later as an argument to all other functions (like open and closing files, etc) to identify the volume on which they should operate.
The file system implementation should have no global variables, everything must be included within the FS_VOLUME structure, in order for the user to be able to mount and use several file systems simultaneously.