home *** CD-ROM | disk | FTP | other *** search
/ Il CD di internet / CD.iso / SOURCE / KERNEL-S / V1.2 / LINUX-1.2 / LINUX-1 / linux / MAGIC < prev    next >
Encoding:
Text File  |  1995-01-10  |  2.8 KB  |  74 lines

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