ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I would suggest you look into the statfs function call, make sure you check your local man pages as I think it's very non standard.
I looked at the statvfs() function, is statfs() similar? Cause as far as I understand it, I can only get the size of a certain file within a filesystem that way. What I want to know is the size of the disk/partition, just like the info provided by df.
by Ephracis I looked at the statvfs() function, is statfs() similar?
Yes. I didn't know until now but it appears that statvfs calls statfs
by Ephracis Cause as far as I understand it, I can only get the size of a certain file within a filesystem that way.
No, I quote from the man page for statvfs - "The function statvfs returns information about a mounted file system."
by Ephracis What I want to know is the size of the disk/partition, just like the info provided by df.
As already stated by jlliagre, df does not return disk/partition information. It returns filesystem information. What would you expect df to say about a filesystem on a raid0 array? Information for each disk?
I quote from "strace df" to show you that it does use this system call (at least on my system)
The hard, system-dependent way: pipe, fork, exec, parse.
Make a new pipe to share between two processes.
Fork; close the correct ends of the pipe.
Exec one child to "df", send output through the pipe.
Use the second child to parse the output from the first.
That's not very nice. But if you can't find the system call you want, it will work. Of course, with this method, C is hardly the ideal language...
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.