moeryn
moeryn

Reputation: 198

In C get hard drive free space from device name

In order to have stats on a hardrive one can use the sys/statvfs

It takes either a path or a fd.

int statvfs(const char *path, struct statvfs *buf);
int fstatvfs(int fd, struct statvfs *buf);

In my application I am parsing /proc/diskstats which provide me with the device name (ex: sda1, sda2).

I don't know how to use that device name in order to get the same stats as the statvfs functions. What functions can be used?

Upvotes: 0

Views: 638

Answers (2)

n. m. could be an AI
n. m. could be an AI

Reputation: 119877

Read /etc/mtab and map device names to mount paths.

Upvotes: 1

woolstar
woolstar

Reputation: 5083

To connect a device with where its mounted, look at mount. The source for mount should tell you how to find the path each device is mounted on. Then you can open the path and call statvfs

Upvotes: 0

Related Questions