Lucky_girl
Lucky_girl

Reputation: 31

What kind of macro correspond to what kind of file system in linux

What kind of macro correspond to what kind of file system in linux. in ReadHat linux Here is [a Link] http://lxr.free-electrons.com/source/include/uapi/linux/magic.h#L24

Eg:
#define EXT2_SUPER_MAGIC     0xEF53
#define EXT3_SUPER_MAGIC     0xEF53
#define EXT4_SUPER_MAGIC     0xEF53
------------------------------> are file system EXT2/EXT3/EXT4
what is the others?// HFS、NFS、XFS、JFS、Minix fs ......

Thanks!

Upvotes: 0

Views: 605

Answers (2)

B. Mayfield
B. Mayfield

Reputation: 1

This is an old question, but I will provide my perspective for anyone digs it up as I did looking for the reason why linux/magic.h seems incomplete and I see no definition for XFS_SUPER_MAGIC or the value I believe it should be in any system header files.

It depends on what you are trying to accomplish. If, for example, you are trying to read from some media that you don’t know the formatting of then Celada is correct you are going to need more information about the layout of that file system and in cases like NFS it may be that the magic number does not make sense.

However, if you are using the statfs() system call to determine what type of file system an inode is on, perhaps looking at dirent entries or something of that nature then the magic numbers in linux/magic.h identify file systems fairly well as far as i can tell. Unfortunately there appear to be gaps as I’ve discovered looking for one for XFS. Which by the way seems to be returned from statfs() as 0x58465342. For better or worse (likely worse unfortunately), I have for now:

#include <linux/magic.h> 
#ifndef XFS_SUPER_MAGIC
#define XFS_SUPER_MAGIC 0x58465342
#endif

Upvotes: 0

Celada
Celada

Reputation: 22261

The magic.h file you refer to isn't really usable to identify filesystems by their format's magic numbers. For one thing, it gives magic numbers for some filesystems but it doesn't say anything about where in the filesystem's on-disk format to look for it! For example, the 0xef53 magic number you cite for ext* must be found by looking at offset 0x438 from the start of the filesystem whereas the magic number in an XFS filesystem is found right at the beginning (byte offset 0) and you can look for reiserfs's magic number at offset 0x10034. It is not even strictly necessary for a filesystem to be identifiable by magic number – it's just good practice. As such, that magic.h file can never really be complete nor useful.

If you want to identify different types of filesystems, I suggest using file. You can look at the filesystems magic file from its source code. It contains matching rules for most of the filesystem types you mentioned.

Note: you mentioned NFS too. As NFS is a network filesystem and doesn't have any on-disk format, how could it have a magic number like the others?

Upvotes: 1

Related Questions