Skip to content

alessandro-scalambrino/Kernel-Module-with-Sysfs-Attributes

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Kernel Hello World Module with Sysfs Attributes

Overview

This project implements a simple Linux kernel module (KMM) named kmt, which demonstrates the use of sysfs attributes for interacting with kernel modules. The module provides several attributes that can be read from and written to via the sysfs filesystem, allowing users to interact with the kernel module directly.

Features

  • Sysfs Attributes: The module exposes four attributes:

    • status: Indicates the current status of the module (active/inactive).
    • message: A customizable message that can be set by the user.
    • version: Displays the version of the module.
    • mode: Allows setting and retrieving the operational mode of the module.
  • Dynamic Message Handling: Users can dynamically change the message displayed by the module through the sysfs interface.

  • Easy Integration: The module can be built and integrated easily into a Linux kernel environment.

Requirements

  • Linux kernel headers matching your running kernel version.
  • Build tools such as make and gcc.

Installation

  1. Clone the repository:

    git clone https://github.com/yourusername/kernel-module-sysfs.git
    cd kernel-module-sysfs
  2. Build the module:

    make
  3. Load the module:

    sudo insmod kmt.ko
  4. Verify the module is loaded:

    dmesg | tail -n 10
  5. Interact with sysfs attributes:

    • Check the status:
      cat /sys/class/driver/hello_world_driver/status
    • Set a message:
      echo "Hello, World!" > /sys/class/driver/hello_world_driver/message
    • Check the message:
      cat /sys/class/driver/hello_world_driver/message
    • Check the version:
      cat /sys/class/driver/hello_world_driver/version
    • Set the mode:
      echo "custom_mode" > /sys/class/driver/hello_world_driver/mode
    • Check the mode:
      cat /sys/class/driver/hello_world_driver/mode
  6. Remove the module:

    sudo rmmod kmt

Cleanup

To remove the compiled module and associated files, run:

make clean

Usage

This kernel module can be used for educational purposes to demonstrate the interaction between user space and kernel space through sysfs. It can also be extended to include more complex behaviors and additional attributes.

License

This project is licensed under the GNU General Public License v2.0 - see the LICENSE file for details.

About

A simple Linux kernel module that demonstrates the use of sysfs attributes for interactivity. This module allows users to read and write messages, check status, and manage modes through the sysfs interface. It includes automated build and test scripts using GitLab CI/CD.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors