# Linux Kernel Module Cheat

#### 17.7.3. sysfs

Sysfs is more restricted than procfs, as it does not take an arbitrary `file_operations`:

    ./sysfs.sh
    echo $?

Outcome: the test passes:

    0

Sources:

- kernel_modules/sysfs.c

- rootfs_overlay/lkmc/sysfs.sh

Vs procfs:

- https://unix.stackexchange.com/questions/4884/what-is-the-difference-between-procfs-and-sysfs/382315#382315

- https://stackoverflow.com/questions/37237835/how-to-attach-file-operations-to-sysfs-attribute-in-platform-driver

- https://serverfault.com/questions/65261/linux-proc-sys-kernel-vs-sys-kernel

You basically can only do `open`, `close`, `read`, `write`, and `lseek` on sysfs files.

It is similar to a seq_file file operation, except that write is also implemented.

TODO: what are those `kobject` structs? Make a more complex example that shows what they can do.

Bibliography:

- https://github.com/t3rm1n4l/kern-dev-tutorial/blob/1f036ef40fc4378f5c8d2842e55bcea7c6f8894a/05-sysfs/sysfs.c

- https://www.kernel.org/doc/Documentation/kobject.txt

- https://www.quora.com/What-are-kernel-objects-Kobj

- http://www.makelinux.net/ldd3/chp-14-sect-1

- https://www.win.tue.nl/~aeb/linux/lk/lk-13.html