The Linux Programming Interface has an exercise in Chapter 3 that goes like this:
When using the Linux-specific reboot() system call to reboot the system, the second argument, magic2, must be specified as one of a set of magic numbers (e.g., LINUX_REBOOT_MAGIC2). What is the significance of these numbers? (Converting them to hexadecimal provides a clue.)
The man page tells us magic2
can be one of LINUX_REBOOT_MAGIC2
(672274793), LINUX_REBOOT_MAGIC2A
(85072278), LINUX_REBOOT_MAGIC2B
(369367448), or LINUX_REBOOT_MAGIC2C
(537993216). I failed to decipher their meaning in hex. I also looked at /usr/include/linux/reboot.h
, which didn't give any helpful comment either.
I then searched in the kernel's source code for sys_reboot
's definition. All I found was a declaration in a header file.
Therefore, my first question is, what is the significance of these numbers? My second question is, where's sys_reboot
's definition, and how did you find it?
EDIT: I found the definition in kernel/sys.c
. I only grepped for sys_reboot
, and forgot to grep for the MAGIC numbers. I figured the definition must be hidden behind some macro trick, so I looked at the System.map
file under /boot
, and found it next to ctrl_alt_del
. I then grepped for that symbol, which led me to the correct file. If I had compiled the kernel from source code, I could try to find which object file defined the symbol, and go from there.
Just a guess, but those numbers look more interesting in hex:
672274793 = 0x28121969
85072278 = 0x05121996
369367448 = 0x16041998
537993216 = 0x20112000
Developers' or developers' children's birthdays?
Regarding finding the syscall implementation, I did a git grep -n LINUX_REBOOT_MAGIC2
and found the definition in kernel/sys.c. The symbol sys_reboot
is generated by the SYSCALL_DEFINE4(reboot, ...
gubbins, I suspect.