We are currently working on building a system for data visualisation for different sensors.

To make development of the Linux application possible we would need to emulate the behaviour of the different character devices as the device drivers and the hardware design aren't done yet.

So is there a way to receive the system calls (open(), read(), write()...) on a specific file inside a, for instance, C program that is also run from userspace?

(Userspace Application/Database) <========= (~/mydev) <===== (dummy_driver)

You could use cuse Character Device in Userspace which is a part of the fuse library, available as a package in most systems. An example "driver" is cuse.c. When you compile and run this example as:

sudo ./cuse -f --name=mydevice

it creates /dev/mydevice and receives all the open, close, read, write, ioctl calls on it. To "unmount" the device (in fuse terminology), just kill the process.

The example is probably not distributed, so to compile, download (or git clone) the zip, change to the libfuse/example directory, and compile as shown in the C file:

gcc -Wall cuse.c $(pkg-config fuse --cflags --libs) -o cuse -I.

You may need to install a fuse-devel package or similar for this to work. If you need to implement more ioctl's, check out this link given as a comment to the answer of this stackexchange question.

Simpler alternatives to consider are a pseudo-tty pty, or tty0tty which is a kernel module that joins two serial ports together.

  • Thanks you so much, fuse/cuse seems to be the perfect solution for our needs! – free_hat Oct 27 '18 at 16:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.