How to write a userspace linux block device driver?

Always looks at the first error:

In your case it looks like a problem with include files, e.g. request_queue_t is not defined.

Since this is a deprecated type, you are probably using a version of linux/blkdev.h that is newer than the code example.

Try adding typedef struct request_queue request_queue_t;


There isn't an "official" way of doing block drivers in userspace, however people often do it by (ab)using the NBD driver to talk over a loopback network to a daemon which listens on a normal socket and speaks the NBD protocol. See the NBD docs for more info.

Your example is for a kernel-mode block device, which will need to be built as a kernel module. And as the kernel internals are always changing, it's presumably now incompatible.


Following MarkR's suggestion, it is even possible to talk the NBD protocol over an AF_UNIX socket pair, so no extra local daemon is needed. The program implementing this protocol will need to set up the socket pair and fork off a child. Both parent and child close one end of the socket pair. One of them starts taking requests on its end of the socket while the other one connects the NBD driver to its end of the socket.