4

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?

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

1 Answer 1

9

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.

2
  • Thanks you so much, fuse/cuse seems to be the perfect solution for our needs! Commented Oct 27, 2018 at 16:34
  • 1
    Thank you! There also seems to be a Python implementation available: github.com/piranna/cusepy Commented Jan 24, 2022 at 10:18

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.