Netdisk Linux Kernel Module
So here's my first ever Linux kernel module other than a worthless "Hello World!" character device I did a while ago. The goal of this module for me was to learn how block devices work and how to open up a socket in a kernel module. I have to give credit to this article: http://lwn.net/Articles/58719/ for pretty much guiding me through the block device part and to the khttpd project which led me to sock_create() and many good links from Google.
So what exactly is this... basically I wanted to create a block device that would look like a floppy but instead of storing the data locally it would send/receive each sector from another computer. I was originally going to write a small server that would fseek() in a disk image and read/write from it, but I decided to do it with a webserver using PHP. The reason for PHP was because 1) it's a really small simple script and 2) I find it humorous using PHP for the backend of a kernel module :). The obvious disadvantage of PHP here is the extra overhead of having HTTP headers around the sector data and the fact that I decided not to do a connection keep-alive on the socket, so every sector read/write will have to reestablish the TCP connection.
TODO and Possible Improvments
First thing needed to test this out is make sure your computer has gcc installed and the Linux kernel source tree for your current running kernel. You will also need a web server with PHP installed to run the server part. The server doesn't have to be Linux since the backend to this Linux module is PHP. In order to format the disk image that will sit on the web server side, you will need mkfs.vfat. Actually, technically you should be able to format the disk with any valid filesystem, I just used vfat here. Please note this is a beta kernel module and if it crashes, your computer will crash with it. Use at your own risk. To test this out, simply do the following:
You should now be able to read/write from /mnt/netdisk which will actually be reading and writing from the /tmp/netdisk.img image on the computer with the web server.
Copyright 1997-2013 - Michael Kohn