質問

what is the 'magic' value in tty_driver struct

struct tty_driver {
   int     magic;          /* magic number for this structure */
   struct kref kref;       /* Reference management */
   struct cdev cdev;
   struct module   *owner;
   const char      *driver_name;
   ....
   ....

I don't understand why is it called 'magic'

役に立ちましたか?

解決

Magic numbers often refer to specific constants that identify a structure, file type or software. In this case, the tty_driver's magic number is apparently always defined like this:

#define TTY_DRIVER_MAGIC        0x5402

One practical use of the magic number in such a context might be to check the value of the first sizeof(int) bytes and make sure they == 0x5402 before casting the rest of the received bytes into a tty_driver struct. In this respect, it might also be used to determine the appropriate byte ordering (little/big endian) for the rest of the header.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top