Question

I know I can get mount point utilization using command line tools like df and doing something like the following:

popen("df -h /var/log | awk '{if($1==\"tmpfs\") print $5}'","r")

where the fifth column is the usage percentage.

What I want to know is if there is a way to access mount point utilization from /proc/, such as /proc/mounts. I feel that getting this information from /proc/ would be a quicker and more efficient solution than using df and awk to parse out the usage. I've searched mntent.h but couldn't find anything promising there either. Any ideas?

Was it helpful?

Solution

You probably want the statfs(2) syscall (it does not use /proc/). You probably would use it thru statvfs(3) Posix function.

Notice that the /proc/ filesystem (and also /sys/ ...) contains pseudo-files which are generated by the kernel on demand without any IO. See proc(5). You could read sequentially /proc/self/mounts and/or /proc/self/mountstats and/or appropriate files under /proc/fs/ and/or /sys/ (such as some files in /proc/fs/ext4/sda1/ or even in /sys/block/sda/sda1/ for my desktop computer ; it would be different on yours ....)

Perhaps systemd is also able to give such information, but I don't know it enough.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top