1This file is a registry of magic numbers which are in use. When you 2add a magic number to a structure, you should also add it to this 3file, since it is best if the magic numbers used by various structures 4are unique. 5 6It is a *very* good idea to protect kernel data structures with magic 7numbers. This allows you to check at run time whether (a) a structure 8has been clobbered, or (b) you've passed the wrong structure to a 9routine. This last is especially useful --- particularly when you are 10passing pointers to structures via a void * pointer. The tty code, 11for example, does this frequently to pass driver-specific and line 12discipline-specific structures back and forth. 13 14The way to use magic numbers is to declare then at the beginning of 15the structure, like so: 16 17struct tty_ldisc { 18 int magic; 19 ... 20}; 21 22Please follow this discipline when you are adding future enhancements 23to the kernel! It has saved me countless hours of debugging, 24especially in the screw cases where an array has been overrun and 25structures following the array have been overwritten. Using this 26discipline, these cases get detected quickly and safely. 27 28You should also register the magic number used by ioctls in the table 29below. This allows ioctls on inappropriate devices to fail, rather than 30doing something completely unexpected. The magic number is the first 31argument to the _IO family of macros (see include/linux/ioctl.h) or 32in general bits 8..15 of the ioctl number. Where ioctls are done on 33devices with a major device number, it is recommended that you use the 34major device number as the ioctl magic value (e.g. hd, lp). 35 36 Theodore Ts'o 37 31-Mar-94 38 39Magic Name Number Structure File 40=========================================================================== 41FASYNC_MAGIC 0x4601 struct fasync_struct include/linux/fs.h 42PTY_MAGIC 0x5001 struct pty_struct drivers/char/pty.c 43PPP_MAGIC 0x5002 struct ppp_struct include/linux/ppp.h 44TTY_MAGIC 0x5401 struct tty_struct include/linux/tty.h 45TTY_DRIVER_MAGIC 0x5402 struct tty_driver include/linux/tty_driver.h 46TTY_LDISC_MAGIC 0x5403 struct tty_ldisc include/linux/tty_ldisc.h 47SERIAL_MAGIC 0x5301 struct async_struct include/linux/serial.h 48SLIP_MAGIC 0x5302 struct slip drivers/net/slip.h 49 50Ioctl Include File Comments 51======================================================== 520x00 fd.h 530x03 hdreg.h 540x06 lp.h 550x12 fs.h 56'C' soundcard.h 57'K' kd.h 58'M' soundcard.h 59'P' soundcard.h 60'Q' soundcard.h 61'S' cdrom.h 62'S' fs.h subcodes from 0x80, no conflict 63'T' soundcard.h conflicts with termios.h 64'T' termios.h conflicts with soundcard.h 65'T' ppp.h subcodes from 0x90, no conflict 66'V' vt.h 67'f' ext2_fs.h 68'm' mtio.h conflicts with soundcard.h 69'm' soundcard.h conflicts with mtio.h 70's' pcsp.h 71'v' ext2_fs.h 720x89 sockios.h 73 74

