How to detect whether the filesystem is ext2 or ext3??
ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
How to detect whether the filesystem is ext2 or ext3??
The matter is that the magic number for ext2 fs is the same as for ext3 fs. So how is it possible to detect whether the fyle system is type of ext2 or ext3 in the C/C++ program??
The file system is the same. the only thing that changes is that you have journaling in ext3. Try to find out whether journaling is present or not, and you have the file system.
I don't know the exact steps, but since no one has answered this, I took a guess!
Yes i agree.. looks like I need to look at tune2fs code, since it detects somehow whether the fs has journal or not:
...
Filesystem features: has_journal filetype needs_recovery sparse_super
...
I don't run ext3 so I have no way of checking, but is the journal done in a file, or does it set aside part of the partition for it and not use a file like reiserfs does? If so you could just look for the journal file.
yes, it looks like the way.. but I won't be really satisfied if it would be the only way.. because if so, then removing a journal, or how it often happens, if journal is corrupted, then it "means" that ext3 fs becomes ext2 again?? hm.. I'll look at tune2fs code..
That probably is the case. Ext3 is exactly the same as Ext2 with the exception of the journal. They did it that way so if you forgot Ext3 support in your kernel, or your journal was messed up, it could mount it as an ext2 and just not use the journal.
Yes, and I have seen that you can convert an existing ext2 partition into an ext3 by just adding an journal using the tune2fs command. I've forgotten the exact options, but I have seen it done!
option is simple: tune2fs -j
anyway thanks!! it seems to be the correct way to detect if the UNMOUNTED filesystem is ext3 or ext2 by searching for its journal file.
For MOUNTED file system it's much simple -- via getmntent() and look for "ext3" in mnt_type member in mntent structure.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.