Hicking with NetBSD

This last semester, I have been spending much time with NetBSD. In this article I will tell you about the adventures, and how it has developed me as a programmer.

Over the fence, off the wall

So a while ago, a good colleague of mine wrote a Linux kernel module for fun and exercise. This module is called /dev/schutting, and it is a /dev/null clone. The term ‘schutting’ meaning ‘fence’ in Dutch, is a reference to the proverb “Over de schutting gooien” which means: Making something not your problem anymore.

Because I thought this was a really interesting exercise, I decided to port /dev/schutting to NetBSD. I started with an empty C source file, and I looked up the function signatures for device open(), read(), write(), and close(); which I implemented with the functionality of /dev/null. Funny enough, the first try did not succeed.

The thing is that the build system is both very good, and very weird. It does not want you to be creative with naming certain functions, specifically the device attach function; in my case void schuttingattach(int);. If you turn it into schutting_attach() or SchuttingAttach() all will be fine… Until the linking phase comes, then the compiler will scream at you without telling you what is actually going on!

After spending the saturday evening figuring out why things where not working, I discovered proper spelling and the building of the kernel succeeded. After a short reboot and a couple of attempts with mknod(8) I had a working /dev/schutting. Overall this project was really fun.

Finally, I want to thank my colleague for his encouragement regarding projects like these.

Chroot environments

As my personal project this semester, I choose to implement a container-like runtime called: RootVE. It works similair to containerd, and makes much use of facilities found in NetBSD. RootVE can create environments for both interactive and background services/applications. It does this by leveraging terminal control groups. I even implemented (altough not that elegant) networking.

At the time of writing, RootVE does contain some inelegances and inconsistencies. But considering the entire system is written in less then 1000 lines of code, I would say it pretty complete. I really enjoyed this project, because it made me reach the limit of what Go could teach me about programming.

Pipes, Ports, and Channels

I like tinkering on de novo operating systems, and one of such systems is Plan 9. Plan 9 has this device called srv(3) which is a registry for file descriptor backed channels. Altough NetBSD does not have such a device, it does have two component parts: tmpfs, and pipes.

So I wrote a couple of scripts: One would mount a tmpfs on /srv at startup, the other a shell library that implements functions for (de)registering pipes.

I realised I could do the same for sockets. For good meassure (and use in RootVE), I wrote a Go package and put all of it into a single repository called ipcfs.