Skip to content

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

4 Commits

Folders and files

Repository files navigation

Linux Kernel Character Device Driver

A Linux kernel module written in C that implements a full character device driver, exposed via /dev/mydriver.

Features

  • Character device registration with major/minor number allocation
  • Full file_operations interface: open, read, write, release
  • ioctl interface with three commands:
    • MYDRIVER_CLEAR — wipe internal buffer
    • MYDRIVER_GET_LEN — query current buffer length
    • MYDRIVER_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

Environment

  • 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)

Build and Run

make
sudo insmod mydriver.ko
sudo chmod 666 /dev/mydriver
python3 test_driver.py
sudo rmmod mydriver
make clean

Project Structure

mydriver.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

Concepts Demonstrated

  • 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)
image

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages