contributed by < As7r1d
>
注意書寫規範!
$ dpkg -L linux-headers-6.11.0-21-generic | grep "/lib/modules"
/lib/modules
/lib/modules/6.11.0-21-generic
/lib/modules/6.11.0-21-generic/build
編譯並測試
$ make check
Git hooks are installed successfully.
cc -Wall -Werror -o user user.c
cc -Wall -Werror -o test_xoro test_xoro.c
make -C /lib/modules/6.11.0-21-generic/build M=/home/as7r1d/linux2025/ksort modules
make[1]: Entering directory '/usr/src/linux-headers-6.11.0-21-generic'
warning: the compiler differs from the one used to build the kernel
The kernel was built by: x86_64-linux-gnu-gcc-13 (Ubuntu 13.3.0-6ubuntu2~24.04) 13.3.0
You are using: gcc-13 (Ubuntu 13.3.0-6ubuntu2~24.04) 13.3.0
CC [M] /home/as7r1d/linux2025/ksort/sort_mod.o
CC [M] /home/as7r1d/linux2025/ksort/sort_impl.o
LD [M] /home/as7r1d/linux2025/ksort/sort.o
CC [M] /home/as7r1d/linux2025/ksort/xoro_mod.o
LD [M] /home/as7r1d/linux2025/ksort/xoro.o
MODPOST /home/as7r1d/linux2025/ksort/Module.symvers
CC [M] /home/as7r1d/linux2025/ksort/sort.mod.o
LD [M] /home/as7r1d/linux2025/ksort/sort.ko
BTF [M] /home/as7r1d/linux2025/ksort/sort.ko
Skipping BTF generation for /home/as7r1d/linux2025/ksort/sort.ko due to unavailability of vmlinux
CC [M] /home/as7r1d/linux2025/ksort/xoro.mod.o
LD [M] /home/as7r1d/linux2025/ksort/xoro.ko
BTF [M] /home/as7r1d/linux2025/ksort/xoro.ko
Skipping BTF generation for /home/as7r1d/linux2025/ksort/xoro.ko due to unavailability of vmlinux
make[1]: Leaving directory '/usr/src/linux-headers-6.11.0-21-generic'
make insmod
make[1]: Entering directory '/home/as7r1d/linux2025/ksort'
make -C /lib/modules/6.11.0-21-generic/build M=/home/as7r1d/linux2025/ksort modules
make[2]: Entering directory '/usr/src/linux-headers-6.11.0-21-generic'
warning: the compiler differs from the one used to build the kernel
The kernel was built by: x86_64-linux-gnu-gcc-13 (Ubuntu 13.3.0-6ubuntu2~24.04) 13.3.0
You are using: gcc-13 (Ubuntu 13.3.0-6ubuntu2~24.04) 13.3.0
make[2]: Leaving directory '/usr/src/linux-headers-6.11.0-21-generic'
[sudo] password for as7r1d:
sudo insmod sort.ko
sudo insmod xoro.ko
make[1]: Leaving directory '/home/as7r1d/linux2025/ksort'
sudo ./user
Sorting succeeded!
sudo ./test_xoro
n_bytes=0 n_bytes_read=0 value=0000000000000000
n_bytes=1 n_bytes_read=1 value=000000000000005f
n_bytes=2 n_bytes_read=2 value=000000000000ed8e
n_bytes=3 n_bytes_read=3 value=0000000000747c6a
n_bytes=4 n_bytes_read=4 value=00000000c61be1dd
n_bytes=5 n_bytes_read=5 value=000000f069befa4a
n_bytes=6 n_bytes_read=6 value=0000ebab275f98f0
n_bytes=7 n_bytes_read=7 value=0042569408ac9f4b
n_bytes=8 n_bytes_read=8 value=16b355d705d7d6d7
n_bytes=9 n_bytes_read=8 value=0b7f14b4fc108855
make rmmod
make[1]: Entering directory '/home/as7r1d/linux2025/ksort'
make[1]: Leaving directory '/home/as7r1d/linux2025/ksort'
$ modinfo sort.ko
description: Concurrent sorting driver
author: National Cheng Kung University, Taiwan
license: Dual MIT/GPL
name: sort
vermagic: 6.11.0-21-generic SMP preempt mod_unload modversions
$ sudo insmod sort.ko
$ ls -l /dev/sort
crw------- 1 root root 508, 0 Apr 20 00:12 /dev/sort
$ cat /sys/class/sort/sort/dev
508:0
$ cat /sys/module/sort/version
0.1
$ lsmod | grep sort
sort 12288 0
$ cat /sys/module/sort/refcnt
0
說好的進度呢?
p = &list->head:首先獲取「指向頭節點指標」的指標*p != before:檢查當前 p 指向的節點是否是目標節點(before)p = &(*p)->next:如果不是,就移動到下一個節點的指標一旦找到,*p = item 將指向 before 的指標改為指向 itemitem->next = before 將 item 的 next 指向 before,完成插入
May 6, 2025contributed by <As7r1d>
Apr 25, 2025contributed by <As7r1d>
Mar 24, 2025contributed by < >
Mar 11, 2025or
By clicking below, you agree to our terms of service.
New to HackMD? Sign up