MAGIC 3.67 KB
Newer Older
Linus Torvalds's avatar
Linus Torvalds committed
1 2 3 4 5 6 7 8
This file is a registry of magic numbers which are in use.  When you
add a magic number to a structure, you should also add it to this
file, since it is best if the magic numbers used by various structures
are unique.

It is a *very* good idea to protect kernel data structures with magic
numbers.  This allows you to check at run time whether (a) a structure
has been clobbered, or (b) you've passed the wrong structure to a
Linus Torvalds's avatar
Linus Torvalds committed
9
routine.  This last is especially useful --- particularly when you are
Linus Torvalds's avatar
Linus Torvalds committed
10 11 12 13 14 15 16 17 18 19 20 21
passing pointers to structures via a void * pointer.  The tty code,
for example, does this frequently to pass driver-specific and line
discipline-specific structures back and forth.

The way to use magic numbers is to declare then at the beginning of
the structure, like so:

struct tty_ldisc {
	int	magic;
	...
};

Linus Torvalds's avatar
Linus Torvalds committed
22
Please follow this discipline when you are adding future enhancements
Linus Torvalds's avatar
Linus Torvalds committed
23 24 25
to the kernel!  It has saved me countless hours of debugging,
especially in the screw cases where an array has been overrun and
structures following the array have been overwritten.  Using this
Linus Torvalds's avatar
Linus Torvalds committed
26
discipline, these cases get detected quickly and safely.
Linus Torvalds's avatar
Linus Torvalds committed
27

Linus Torvalds's avatar
Linus Torvalds committed
28 29 30 31 32 33 34 35
You should also register the magic number used by ioctls in the table
below.  This allows ioctls on inappropriate devices to fail, rather than
doing something completely unexpected.  The magic number is the first
argument to the _IO family of macros (see include/linux/ioctl.h) or
in general bits 8..15 of the ioctl number.  Where ioctls are done on
devices with a major device number, it is recommended that you use the
major device number as the ioctl magic value (e.g. hd, lp).

Linus Torvalds's avatar
Linus Torvalds committed
36 37 38
					Theodore Ts'o
					31-Mar-94

Linus Torvalds's avatar
Linus Torvalds committed
39 40 41 42 43 44 45 46 47 48 49 50
The magic table is current to Linux 1.3.35.
The ioctl table is current to Linux 1.3.35.
For a complete list of kernel ioctl's, look for 'ioctl-list.X.Y.ZZ' on
an ftp site, where 'X.Y.ZZ' is the kernel version for the ioctl list.

					Michael Chastain
					<mec@duracef.shout.net>
					17-Oct-95




Linus Torvalds's avatar
Linus Torvalds committed
51 52
Magic Name          Number  Structure            File
===========================================================================
Linus Torvalds's avatar
Linus Torvalds committed
53
APM_BIOS_MAGIC      0x4101  struct apm_struct    include/linux/apm_bios.h
Linus Torvalds's avatar
Linus Torvalds committed
54
CYCLADES_MAGIC      0x4359  struct cyclades_port include/linux/cyclades.h
Linus Torvalds's avatar
Linus Torvalds committed
55 56
FASYNC_MAGIC        0x4601  struct fasync_struct include/linux/fs.h
PTY_MAGIC           0x5001  struct pty_struct    drivers/char/pty.c
Linus Torvalds's avatar
Linus Torvalds committed
57
PPP_MAGIC           0x5002  struct ppp_struct    include/linux/if_ppp.h
Linus Torvalds's avatar
Linus Torvalds committed
58 59 60 61 62
TTY_MAGIC           0x5401  struct tty_struct    include/linux/tty.h
TTY_DRIVER_MAGIC    0x5402  struct tty_driver    include/linux/tty_driver.h
TTY_LDISC_MAGIC     0x5403  struct tty_ldisc     include/linux/tty_ldisc.h
SERIAL_MAGIC        0x5301  struct async_struct  include/linux/serial.h
SLIP_MAGIC          0x5302  struct slip          drivers/net/slip.h
Linus Torvalds's avatar
Linus Torvalds committed
63
SCC_MAGIC           0x8530  struct scc_channel   include/linux/scc.h
Linus Torvalds's avatar
Linus Torvalds committed
64 65


Linus Torvalds's avatar
Linus Torvalds committed
66 67 68 69 70 71 72 73 74 75 76

Ioctl	Include File		Comments
========================================================
0x00	linux/fs.h		only FIBMAP, FIGETBSZ
0x00	linux/random.h		codes in 0x010800NN
0x02	linux/fd.h
0x03	linux/hdreg.h
0x04	linux/umsdos_fs.h
0x06	linux/lp.h
0x12	linux/fs.h
0x20	linux/cm206.h
Linus Torvalds's avatar
Linus Torvalds committed
77
0x22	linux/scc.h
Linus Torvalds's avatar
Linus Torvalds committed
78
'A'	linux/apm_bios.h
Linus Torvalds's avatar
Linus Torvalds committed
79 80 81 82 83 84 85 86 87 88 89
'C'	linux/soundcard.h
'K'	linux/kd.h
'M'	linux/soundcard.h
'P'	linux/soundcard.h
'Q'	linux/soundcard.h
'S'	linux/cdrom.h		conflict!
'S'	linux/scsi.h		conflict!
'T'	linux/soundcard.h	conflict!
'T'	asm/termios.h		conflict!
'V'	linux/vt.h
'Y'	linux/cyclades.h	codes in 0x004359NN
Linus Torvalds's avatar
Linus Torvalds committed
90
'a'	various, see http://lrcwww.epfl.ch/linux-atm/magic.html
Linus Torvalds's avatar
Linus Torvalds committed
91 92 93 94 95 96 97 98 99 100
'f'	linux/ext2_fs.h
'm'	linux/mtio.h		conflict!
'm'	linux/soundcard.h	conflict!
's'	linux/cdk.h
't'	linux/if_ppp.h
'u'	linux/smb_fs.h
'u'	linux/smb_fs.h
'v'	linux/ext2_fs.h
0x89	asm/socket.h		no conflict
0x89	linux/sockios.h		no conflict