https://github.com/amid68/virtual-character-device-driver
https://github.com/amid68/virtual-character-device-driver
Last synced: 4 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/amid68/virtual-character-device-driver
- Owner: Amid68
- License: mit
- Created: 2024-11-18T12:34:09.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-11-18T18:37:17.000Z (over 1 year ago)
- Last Synced: 2026-01-03T10:28:52.965Z (7 months ago)
- Language: C
- Size: 4.88 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Virtual Character Device Driver
## Overview
This project implements a virtual character device driver for Linux, allowing interaction between the kernel and user space via a virtual device file (`/dev/virtchar`). It demonstrates key concepts in Linux driver development, such as registering a device, handling file operations, and managing memory.
## Project Structure
```
virtchar/
├── Makefile
├── README.md
├── include/
│ └── virtchar.h
└── src/
├── virtchar.c
└── virtchar_ops.c
```
## Building the Module
Run the following command in the project root directory:
```bash
make
```
## Installing the Module
Load the module into the kernel:
```bash
sudo insmod virtchar.ko
```
Verify that the module is loaded:
```bash
lsmod | grep virtchar
```
## Creating the Device File
The module now automatically creates the device file `/dev/virtchar`. If not, you can create it manually:
```bash
sudo mknod /dev/virtchar c 0
sudo chmod 666 /dev/virtchar
```
Replace `` with the major number assigned to the device (check `dmesg` logs).
## Testing the Driver
**Write to the Device:**
```bash
echo "Hello from userspace" > /dev/virtchar
```
**Read from the Device:**
```bash
cat /dev/virtchar
```
**Check Kernel Logs:**
```bash
dmesg | tail -n 20
```
## Uninstalling the Module
To remove the module from the kernel:
```bash
sudo rmmod virtchar
```
Clean the build files:
```bash
make clean
```