A Linux kernel module written in C that implements a full character device driver, exposed via /dev/mydriver.
- Character device registration with major/minor number allocation
- Full
file_operationsinterface:open,read,write,release ioctlinterface with three commands:MYDRIVER_CLEAR— wipe internal bufferMYDRIVER_GET_LEN— query current buffer lengthMYDRIVER_SET_MODE— set device operating mode
- Safe kernel↔userspace data transfer via
copy_to_user/copy_from_user - Python test harness (
test_driver.py) validating all interfaces with 8 automated tests
- Kernel: Linux 5.15 (Ubuntu 22.04)
- Language: C (kernel module) + Python 3.10 (test harness)
- Tested in QEMU emulated environment (no physical hardware required)
make
sudo insmod mydriver.ko
sudo chmod 666 /dev/mydriver
python3 test_driver.py
sudo rmmod mydriver
make cleanmydriver.c — kernel module source
mydriver.h — shared ioctl command definitions
Makefile — kernel build system integration
test_ioctl.c — C test program
test_driver.py — Python automated test harness
- Loadable kernel module lifecycle (init/exit)
- Character device subsystem (cdev, chrdev_region, class, device)
- Kernel/userspace memory boundary (copy_to/from_user)
- ioctl command encoding (_IO, _IOR, _IOW macros)
- Kernel ring buffer logging (printk, dmesg)