Skip to content
This repository has been archived by the owner on Apr 22, 2023. It is now read-only.

Porting UFS (using Spatch)

Graham MacDonald edited this page May 15, 2017 · 9 revisions

Introduction

Harvey needs a file system, and after investigating various file systems, we decided to port the FreeBSD implementation of UFS2 to Harvey.

This is not an easy task - it involves transplanting a major system from one operating system to another. Once the port is complete, we want to ensure we can incorporate any improvements to the FreeBSD implementation with minimal effort.

To achieve this, it was suggested we use spatch to create semantic patches. These patches are describe patterns of code that can be found across a code base and then modified as described in the patch. Where spatches are not possible, we can use sed, or if necessary, modify the code by hand.

Process

The process we intend to follow is:

  1. Fork FreeBSD. (Done)
  2. Copy the ufs code into a new library (libufs).
  3. Add an initially empty build file to allow us to build the library as a kernel library in Harvey.
  4. Develop simple spatches that can be applied to the code to slowly transform it into something that can be built.
  5. Implement a driver to integrate libufs with Harvey.

Notes

Spatch sometimes has problems parsing code with macros. An example is the use of the TAILQ_ENTRY() macro in the inode struct in ufs/inode.h. If spatch cannot parse this entry in the struct, it cannot transform any part of the struct. We can resolve this by adding the definition of the macro to a macro file, and pass this to spatch when applying the patches. We will build up this macro file as we go, from the actual macros in FreeBSD.

You can check that a file can be fully parsed by spatch as so: spatch --parse-c ../ufs/acl.h. This will report whether spatch can fully parse the file or not.