Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Linux file system SUPER_MAGIC, FS_MAGIC and TEST_MAGIC difference

Going through the man page of stasfs( http://man7.org/linux/man-pages/man2/statfs.2.html) I see in the Filesystem types SUPER_MAGIC, FS_MAGIC and TEST_MAGIC.

Filesystem types:

ADFS_SUPER_MAGIC      0xadf5
.
.
.
BTRFS_SUPER_MAGIC     0x9123683e
BTRFS_TEST_MAGIC      0x73727279

BPF_FS_MAGIC          0xcafe4a11

I know that the magic numbers are used to identify the format of file system.

But then what is the difference between SUPER_MAGIC, FS_MAGIC and TEST_MAGIC?

like image 956
RKum Avatar asked Jun 29 '26 13:06

RKum


1 Answers

To answer your question, there is a difference in naming and in values of these macros. There is no difference in the purpose of these macros, as they all are used in identifying a format of a filesystem.
Constants *_MAGIC are defined in linux/magic.h file from linux kernel.
So BPF_FS_MAGIC is used to identify BPS filesystem, BTRFS_TEST_MAGIC is used to identify some testing btrfs filesystem, while BTRFS_MAGIC_NUMBER is used to identify (production-ready) btrfs filesystem and so on. The naming of these macros may be not consistent, but they all share the same purpose.

The naming of a constant may be a hint to programmers and/or may be confusing to programmers, since we all think differently. I would expect constants named *_MAGIC to have the value of some magic number constant, macros named *_TEST_MAGIC to identify some testing filesystem of some format, while constants named *_FS_MAGIC and/or *_MAGIC_NUMBER mean exactly the same for me. So someone (probably the author of BPS kernel driver) named the BPS magic number macro as BPS_FS_MAGIC and that was his choice, others named they magic number constants differently.

like image 107
KamilCuk Avatar answered Jul 02 '26 07:07

KamilCuk