Loadable Modules & the Linux 2.6 Kernel
By Daniele Paolo Scarpazza, June 01, 2005
Source Code Accompanies This Article. Download It Now.
The Linux Kernel 2.6 introduces significant changes with respect to 2.4.
June, 2005: Loadable Modules & The Linux 2.6 Kernel
# make
make -C /usr/src/linux-2.6.5-1.358 SUBDIRS=/root/sysfs_example modules
make[1]: Entering directory '/usr/src/linux-2.6.5-1.358'
CC [M] /root/sysfs_example/sysfs_example.o
Building modules, stage 2.
MODPOST
CC /root/sysfs_example/sysfs_example.mod.o
LD [M] /root/sysfs_example/sysfs_example.ko
make[1]: Leaving directory '/usr/src/linux-2.6.5-1.358'
# insmod sysfs_example.ko
# cd /sys
# ls
block bus class devices firmware power sysfs_example
# cd sysfs_sample
# ls
hex integer string
# cat hex
0xdeadbeef
# cat integer
123
# cat string
test
# echo 0xbabeface > hex
# echo 456 > integer
# echo hello > string
# cat hex
0xbabeface
# cat integer
456
# cat string
hello
# cd ..
# rmmod sysfs_example
# ls
block bus class devices firmware power
Example 2: Interactive session in which the module sysfs_example.c is compiled, inserted, and tested. Attributes are inspected, changed, and inspected again.