views:

128

answers:

2

Question says it all. I want C function call that returns the list the mounted filesystems along with associated information such as filesystem type.

A: 

You can parse /proc/filesystems.

dmckee
Or even /proc/mounts
MarkR
+5  A: 

You're looking for getmntent and other *mntent functions family. See manpage For further reference.

Code example taken from here and slightly modified. /etc/mtab is a file that contains a list of mounted filesystems.

mounts = setmntent("/etc/mtab", "r");
while ( (ent = getmntent(mounts)) != NULL ){
    if (strcmp(ent->mnt_type, "iso9660") == 0)
       /* copy mount point to output */
       strcpy(retval[cd_count - 1], ent->mnt_dir);
    } /* if */
} /* while */
endmntent(mounts);

Unfortunately, these functions are not in POSIX. But they're manpaged and implemented in glibc, so I think they're a better alternative than parsing /proc.

Pavel Shved