mount list

This is a discussion on mount list within the Linux Programming forums, part of the Platform Specific Boards category; Hello. Is there a linux syscall to get a list of mounted devices? Thanks, Luka...

  1. #1
    Registered User
    Join Date
    Oct 2004
    Posts
    15

    mount list

    Hello.

    Is there a linux syscall to get a list of mounted devices?

    Thanks,
    Luka

  2. #2
    Registered User
    Join Date
    Oct 2004
    Posts
    15
    Or ... how can I get the used and unused space used space of the mounted device?

  3. #3
    Sr. Software Engineer filker0's Avatar
    Join Date
    Sep 2005
    Location
    West Virginia
    Posts
    235

    mount

    I'd suggest getting a copy of the source to /bin/mount (I don't have it myself) and seeing what magic it's doing with the kernel filesystem.

    I've done a google search, but have come up empty, and I don't have access to a source distro with the sys utilities at the moment. Perhaps someone else here can point you at where the source lives.

    I believe that it all has to do with the virtual file system code (vfs) -- I'm certain that there are internal data structures for that.

    If you don't mind using /proc for the information, you might try looking at /proc/mounts (which is actually a symlink to /proc/self/mounts, and /proc/self is a symlink... but reading /proc/mounts should give you the info).
    Last edited by filker0; 12-05-2005 at 04:01 PM. Reason: added /proc/mounts info
    Insert obnoxious but pithy remark here

  4. #4
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,892
    Open and read /proc/mounts. Each line looks like this:
    <device> <mountpoint> <type> <mode> <integer> <integer>
    I think the last two integers are about the checking order.
    Nodev filesystems (like rootfs, proc, etc.) have their own name instead of the device.
    /proc/mounts ought to be world-readable.
    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

  5. #5
    Me -=SoKrA=-'s Avatar
    Join Date
    Oct 2002
    Location
    Europe
    Posts
    448
    I believe mount parses /proc/mounts to find out what is mounted. A better way would be to parse /proc/self/mounts which will give you the mounts visible to you or somesuch.

    As for the space, I think you need to invoke some filesystem magic there. Get the source for df and see what it does.
    SoKrA-BTS "Judge not the program I made, but the one I've yet to code"
    I say what I say, I mean what I mean.
    IDE: emacs + make + gcc and proud of it.

  6. #6
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,892
    /proc/mounts is a symlink to /proc/self/mounts (and /proc/self in turn is a symlink to /proc/nnnnn, where nnnnn is the current process id).
    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

  7. #7
    junior member mix0matt's Avatar
    Join Date
    Aug 2001
    Posts
    144
    Source is available for all GNU software in the software directory on the gnu.org website. You can find the source for df, du etc. in the fileutils package here: http://ftp.gnu.org/gnu/fileutils/fileutils-4.1.tar.gz

    Of course using GPL'd code means your code is GPL'd...
    THIS IS NOT JUST A CHRONICLING OF THINGS WE HAVE DONE IN THE PAST BUT OUR RISE TO POWER.

  8. #8
    Registered User Jaqui's Avatar
    Join Date
    Feb 2005
    Posts
    416
    or, use this:

    http://www.freebsd.org/projects/index.html

    since the bsd license allows for commercial use of the products.
    get the appropriate source package from the cvs repository and go from there with your code.
    Quote Originally Posted by Jeff Henager
    If the average user can put a CD in and boot the system and follow the prompts, he can install and use Linux. If he can't do that simple task, he doesn't need to be around technology.

  9. #9
    Registered User
    Join Date
    Sep 2003
    Posts
    224
    I have NetBSD and getfsstat(2) seems to have everything you need.

  10. #10
    Registered User
    Join Date
    Nov 2005
    Posts
    14
    I thought that if you looked at the man file for 'fstab' it showed you the functions you can use for gaining info on drives? worth checking anyway, I'm afraid my Slackware box isn't networked, this is a windows box.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Link List math
    By t014y in forum C Programming
    Replies: 17
    Last Post: 02-20-2009, 05:55 PM
  2. instantiated from here: errors...
    By advocation in forum C++ Programming
    Replies: 5
    Last Post: 03-27-2005, 08:01 AM
  3. How can I traverse a huffman tree
    By carrja99 in forum C++ Programming
    Replies: 3
    Last Post: 04-28-2003, 05:46 PM
  4. List class
    By SilasP in forum C++ Programming
    Replies: 0
    Last Post: 02-10-2002, 04:20 PM
  5. singly linked list
    By clarinetster in forum C Programming
    Replies: 2
    Last Post: 08-26-2001, 10:21 PM

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