LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 01-14-2004, 09:01 AM   #1
fa3a
LQ Newbie
 
Registered: Aug 2003
Location: Minsk
Distribution: RHEL, Fedora
Posts: 8

Rep: Reputation: 0
Question 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??
 
Old 01-21-2004, 08:05 AM   #2
UltimaGuy
Member
 
Registered: Aug 2003
Location: Chennai, India
Distribution: PCLinuxOS .92, FC4
Posts: 840

Rep: Reputation: 31
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!
 
Old 01-21-2004, 10:02 AM   #3
fa3a
LQ Newbie
 
Registered: Aug 2003
Location: Minsk
Distribution: RHEL, Fedora
Posts: 8

Original Poster
Rep: Reputation: 0
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
...
 
Old 01-21-2004, 10:07 AM   #4
jtshaw
Senior Member
 
Registered: Nov 2000
Location: Seattle, WA USA
Distribution: Ubuntu @ Home, RHEL @ Work
Posts: 3,892
Blog Entries: 1

Rep: Reputation: 66
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.
 
Old 01-21-2004, 11:33 AM   #5
fa3a
LQ Newbie
 
Registered: Aug 2003
Location: Minsk
Distribution: RHEL, Fedora
Posts: 8

Original Poster
Rep: Reputation: 0
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..
 
Old 01-21-2004, 11:38 AM   #6
jtshaw
Senior Member
 
Registered: Nov 2000
Location: Seattle, WA USA
Distribution: Ubuntu @ Home, RHEL @ Work
Posts: 3,892
Blog Entries: 1

Rep: Reputation: 66
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.
 
Old 01-22-2004, 03:13 AM   #7
UltimaGuy
Member
 
Registered: Aug 2003
Location: Chennai, India
Distribution: PCLinuxOS .92, FC4
Posts: 840

Rep: Reputation: 31
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!
 
Old 01-22-2004, 04:37 AM   #8
fa3a
LQ Newbie
 
Registered: Aug 2003
Location: Minsk
Distribution: RHEL, Fedora
Posts: 8

Original Poster
Rep: Reputation: 0
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.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
ext3\ext2 filesystem amjad Linux - General 1 05-23-2005 05:51 AM
FC2 used filesystem ext3 or ext2? DriveMeCrazy Fedora 1 06-03-2004 10:12 PM
change filesystem from ext2 --> ext3 or Reiserfs without reinstall everything balki Linux - General 3 04-29-2004 04:02 PM
Changing filesystem from ext3 to ext2. hellblade Linux - Hardware 1 01-26-2004 10:24 PM
ext2_read_super: mounting ext3 filesystem as ext2 Jiggy Linux - Newbie 8 11-18-2003 08:27 PM


All times are GMT -5. The time now is 03:44 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration