reboot(2) syscall and agic numbers

I’m currently reading “The Linux Programming Interface” and I intend to use this blog as a way to share what i’m learning (to make sure I’m actually learning).

In one of the first chapters there is an exercise about the reboot(2) syscall and some magic numbers that are used as parameters.

The reboot(2) syscall has the following signature:

int reboot(int magic, int magic2, int cmd, void *arg);

As can be read from the man page, the first parameter, magic, must be set to LINUX_REBOOT_MAGIC1, that is 0xfee1dead(nice one). But the mistery lies on the second parameter, magic2, which must be set to one of the following constants:

LINUX_REBOOT_MAGIC2 (that is, 672274793)
LINUX_REBOOT_MAGIC2A (that is, 85072278)
LINUX_REBOOT_MAGIC2B (that is, 369367448)
LINUX_REBOOT_MAGIC2C (that is, 537993216)

As the book and the man page states, converting these numbers to hexadecimal can give some clue on their meaning. We can use the following Go code(also available on go playground) to get their hexadecimal values.

package main

import (
	"fmt"
	"strconv"
)

func main() {
	consts := []int64{672274793, 85072278, 369367448, 537993216}
	for _, c := range consts {
		fmt.Printf("%d: %s\n", c, strconv.FormatInt(c, 16))
	}
}

Which prints:

672274793: 28121969
85072278: 5121996
369367448: 16041998
537993216: 20112000

At first glance those looked just like any random number for me, but looking a little closer I realized they are actually dates: 28/12/1969, 05/12/1996, 16/04/1998 and 20/11/2000. But what those dates mean?

The first date, 28/12/1969, was the day Linus Torvalds was born. The others all refer to his daughters birthdays. Cute.

What are those magic numbers for?

As stated on linux/reboot.c, they are merely used to make sure one does not reboot the machine by mistake:

* Reboot system call: for obvious reasons only root may call it, 
* and even root needs to set up some magic numbers in the registers * so that some mistake won't make this reboot the whole machine.
comments powered by Disqus