Hello.
Is there a linux syscall to get a list of mounted devices?
Thanks,
Luka
Printable View
Hello.
Is there a linux syscall to get a list of mounted devices?
Thanks,
Luka
Or ... how can I get the used and unused space used space of the mounted device?
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).
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.
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.
/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).
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...
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.
I have NetBSD and getfsstat(2) seems to have everything you need.
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.