问题
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'
回答1:
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.
来源:https://stackoverflow.com/questions/21296469/magic-value-device-driver