Thread: How to get a list of file systems and their mount path?

  1. #1
    Registered User OnionKnight's Avatar
    Join Date
    Jan 2005
    Posts
    555

    How to get a list of file systems and their mount path?

    I want to be able to get a list of file systems and the path they're mounted just like the df program will print out, which reports disk usage. Is this possible with some POSIX.1 function or otherwise?
    I should add that it needs to work on a Solaris machine.
    Last edited by OnionKnight; 09-21-2008 at 12:25 PM.

  2. #2
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    Read /proc/mounts. It contains this information.

    Much system information in Linux is presented via pseudo-files in pseudo-filesystems like procfs (/proc), sysfs (/sys) and to some degree the devices in /dev.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  3. #3
    Registered User OnionKnight's Avatar
    Join Date
    Jan 2005
    Posts
    555
    There is no /proc/mounts on the machine that requires the program. I found out the mtab on it is /etc/mnttab so I suppose I could just parse that.

  4. #4
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    The Solaris box I have access to has getmntent that goes through the mnttab file one by one, if that helps.

  5. #5
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    glibc implements it too, but it sounds only vaguely portable.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  6. #6
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    The problem didn't sound all that portable to start with, but yes.

  7. #7
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    Well, portable between *nices. Mounting is a universal concept among those, though the way to acquire information about it is not.

    I think the most portable way would actually be to call /bin/mount without arguments and parse its output. I expect this command to be more consistent in its location than the /etc/mtab equivalent.

    Edit: I stand corrected. It's /sbin/mount under HP-UX. Also, the device and the mount point are reversed in its output. So that one is definitely not portable. It supports getmntent and related calls. However, like SysV, it stores the mount data in /etc/mnttab.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

Popular pages Recent additions subscribe to a feed