Need to know the filesystem on /dev/sda1

This is a discussion on Need to know the filesystem on /dev/sda1 within the Linux Programming forums, part of the Platform Specific Boards category; hi, I need to know the filesystem on /dev/sda1 i.e. on the usb pen drive. I tried by taking a ...

  1. #1
    Registered User
    Join Date
    Nov 2007
    Posts
    15

    Need to know the filesystem on /dev/sda1

    hi,
    I need to know the filesystem on /dev/sda1 i.e. on the usb pen drive. I tried by taking a look at the output of "strace mount /dev/sda1 /mnt/usb" but am not able to understand.
    I need this information so as I can mount my usb through code with proper filesystem instead of hardcoding the name of filesystem.

    Please help, if anyone is aware...
    Thanks in advance...

    Regards,
    Amit Sahrawat

  2. #2
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Usually, if you DON'T specify a filesystem, mount will detect the correct filesystem - assuming there is a filesystem driver for that filesystem. Have you actually tried that?

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  3. #3
    Registered User
    Join Date
    Nov 2007
    Posts
    15
    I tried by passing NULL in the mount() api like this

    mount("/dev/sda1","/mnt/usb",NULL,MS_NODIRATIME | MS_NOATIME, NULL);
    it does not work,
    however, by doing this from command line like
    mount /dev/sda1 /mnt/usb - > it detects the file system and mount it.

    I somehow need the file system information...

    Thanks

  4. #4
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Ah, ok, I though you were talking about the mount (8) comand, rather than the mount (2) system call. I suspect you'll have to read through /proc/filesystems and try each one until you find one that matches - of course, you could keep a "most recently success" list, so that when you have had some success with for example MSDOS filesystem, you attempt that FIRST next time around.

    I suspect that's what strace shows - but I haven't got a Linux machine to try with right now.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  5. #5
    Registered User
    Join Date
    Nov 2007
    Posts
    15
    strace output show that it does some reading from the device itself...

    It does some lseek(), read and then simply doing the mount()...

    I tried by doing the same... but not able to extract the filesystem from the data...

    by reading in the filesystems and then mounting the device won't be write approach I guess, b'cz same device can be mounted using different filesystems and there will be no error but that won't reflect the data...
    that's why I need exact filesystem information...

    even though I could do this by invoking system(mount <other parameters>), but I am not interested in doing that...

    Thanks,
    Amit Sahrawat

  6. #6
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Ok, perhaps you want to use "libblkid" to detect it correctly. Here's the source code:
    http://git.kernel.org/?p=fs/ext2/e2f...0cbf48;hb=HEAD

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  7. #7
    Registered User
    Join Date
    Nov 2007
    Posts
    15
    Thanks Mats,

    I think I can manage with the blkid thing, there's a file in /etc/blkid.tab, an entry gets added to this... I can read the file type from this.

    again Thanks...

    Regards,
    Amit Sahrawat

  8. #8
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by amit_sahrawat View Post
    Thanks Mats,

    I think I can manage with the blkid thing, there's a file in /etc/blkid.tab, an entry gets added to this... I can read the file type from this.

    again Thanks...

    Regards,
    Amit Sahrawat
    Yes, but if you get the ext2fsprog package, you should be able to reuse that code in the form of the libblkid library, saving you having to recreate some of the intricacies [such as FAT not always storing the magical words/strings in the same offset, but rather you have to read some info first, then figure out where the ID is].

    Reuse other peoples tested code, rather than re-invent the wheel.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Filesystem questions
    By Drogin in forum Tech Board
    Replies: 4
    Last Post: 04-13-2009, 12:59 PM
  2. Replies: 1
    Last Post: 01-22-2009, 02:52 PM
  3. NTFS ( FileSystem ) with C++
    By bobbelPoP in forum Windows Programming
    Replies: 1
    Last Post: 07-19-2008, 03:34 PM
  4. C Library For Filesystem information?
    By Newmer60 in forum C Programming
    Replies: 2
    Last Post: 06-27-2008, 12:12 PM
  5. Filesystem monitoring question
    By rools in forum Linux Programming
    Replies: 2
    Last Post: 11-18-2005, 12:09 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21