1
0
Fork
You've already forked fcdl
0
A Linux Kernel module - File Creation/Deletion Logger. Provides functionality similar to inotify. Can be used as a reference for learning how to write Linux kernel modules in C, working with atomics and Kprobes. https://lch361.net/projects/fcdl
  • C 94.3%
  • Makefile 5.7%
2025年08月15日 14:27:36 +03:00
.gitignore Gave more specific name to bpftrace script 2025年08月15日 14:25:06 +03:00
demo.gif Renovated README.md 2025年06月21日 23:03:23 +03:00
event.c Added event_mpsc_clean 2025年06月20日 22:30:10 +03:00
event.h Added event_mpsc_clean 2025年06月20日 22:30:10 +03:00
fcdl-ext4.bpftrace Cleared map at the bpftrace end 2025年08月15日 14:27:36 +03:00
LICENSE Add LICENSE 2024年07月03日 21:43:17 +03:00
main.c Added renameat2 kretprobe 2025年06月21日 20:17:36 +03:00
Makefile Added event and an mpsc event queue 2025年06月19日 02:58:38 +03:00
README.md Fixed license link 2025年06月21日 23:10:24 +03:00

Overview

FCDL — File Creation/Deletion Logger. A Linux kernel module that intercepts the system calls and outputs created or deleted files from a character device.

This document is a short description of my module, focused on how to build and use it. For history of development and architectural details, see my website.

Demonstration

FCDL demonstration

On left pane: commands being entered in the real time.

On right pane: launched fcdl-cli.

The following software was used:

  • module: fcdlogger.ko 2.0.0-x86_64
  • shell: fish 3.7.1
  • multiplexer: zellij 0.40.1

Building and installing

Building is done, like with all kernel modules, through Kbuild:

make # put the module in this directory
make install # probably requires root privilege

After building, an fcdlogger.ko will be available at this directory for you to insmod and experiment. Have fun!

KBuilding was tested on Linux kernel 6.15.2, although it should be supported on many other versions of Linux kernel as well.

Usage

After you do one of the following commands:

insmod fcdlogger.ko # if built in this directory
modprobe fcdlogger # if installed

A character device /dev/fcdl appears. Only one process can read it, and by default it has UID = GID = 0, mode = 0600.

There are 2 ways it can be read:

  1. with command line utility fcdl-cli, which parses binary output and formats it to the user;
  2. reading manually.

We'll focus on manual reading, on the basics.

For one read system call with count >= 50041 , one filesystem event gets returned to the userspace buffer, with the following contents:

  1. 8 bytes — time of event, in seconds since Unix epoch;

  2. 1 byte — type of event:

    0
    File was created.
    1
    File was deleted.
  3. Remaining bytes — absolute2 path to the file.

Practical application

There is none.

If you really need a robust functionality for watching the filesystem events, use inotify. My module is just an experiment and a way to learn the Linux kernel programming and share the experience with others. Also, it's not very tested and probably never will be.

License

GPL-2.0.


  1. Can be relative if this module couldn't get the full path (error). ↩︎

  2. 5004 is the maximum size of a filesystem event. Attempts to read less will result in an error. ↩︎