fstab.h weirdness

This is a discussion on fstab.h weirdness within the Linux Programming forums, part of the Platform Specific Boards category; I'm trying to write a block of C code that parses the /etc/fstab file and gives me back the information ...

  1. #1
    Registered User
    Join Date
    Apr 2011
    Posts
    8

    fstab.h weirdness

    I'm trying to write a block of C code that parses the /etc/fstab file and gives me back the information for each mount. I'm really only interested in three bits of data per mount, the mount point, the filesystem type and the mount options. I have the following code:

    Code:
    setfsent();
    while (fs_tab = getfsent()) {
    	printf("Mount source: %s\n", fs_tab -> fs_spec);
    	printf("Mount point: %s\n", fs_tab -> fs_file);
    	printf("Mount type: %s\n", fs_tab -> fs_type);
    	printf("Mount options: %s\n", fs_tab -> fs_mntops);
    	printf("--------------------------\n");
    }
    endfsent();
    When I compile my program and run it. I get a list of every mount point, but the type just shows ?? eg:

    Code:
    Mount source: /dev/sda3
    Mount point: /var
    Mount type: ??
    Mount options: defaults
    --------------------------
    Mount source: /dev/sda1
    Mount point: none
    Mount type: sw
    Mount options: sw
    --------------------------
    Mount source: /dev/hda
    Mount point: /media/cdrom0
    Mount type: ??
    Mount options: user,noauto
    --------------------------
    The filetypes in this example output are xfs for /var and udf,iso9660 for the cdrom drive. Why can't fstab.h determine the filetype for the mount?

    In the documents for fstab.h it says:

    char *fs_vfstype
    This is the type of the filesystem. Depending on what the underlying kernel understands it can be any string.
    So I assume that because the system can mountan xfs filesystem, it must know what that type is. When I run an lsmod I see that there is an xfs module so does that mean that because xfs is not natively compiled into the kernel it cannot display it? If so, is there an alternate gnu libc that can parse the fstab file that would show me the fstype?

    Thanks

  2. #2
    Registered User
    Join Date
    Apr 2011
    Posts
    8
    Aaaargh!! As soon as I posted this I found my problem. I was using fs_tab -> fs_type when I should have been using fs_tab -> fs_vfstype. It works as expected now. My eyes are crossed from looking at code all day.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. WM_PASTE weirdness
    By anon in forum Windows Programming
    Replies: 1
    Last Post: 03-12-2009, 05:14 AM
  2. Pass-by-value weirdness
    By sillyfofilly in forum C Programming
    Replies: 8
    Last Post: 02-16-2009, 08:08 AM
  3. rand() weirdness
    By Mostly Harmless in forum C++ Programming
    Replies: 3
    Last Post: 08-25-2006, 11:41 PM
  4. total weirdness
    By lilhawk2892 in forum Tech Board
    Replies: 7
    Last Post: 07-06-2006, 06:07 PM
  5. weirdness
    By newbieneedzhelp in forum C Programming
    Replies: 2
    Last Post: 07-02-2005, 02:38 PM

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