Linux Programming Question:: Get Free Disk Info (with path name if possible)

V

vansky

hi all,

as people known, we can use comm 'df' to get the disk info.

but i'd like to get the disk info included in a C/C++ file, could any
super guy help me with it?

thx a lot!
 
A

Artie Gold

vansky said:
hi all,

as people known, we can use comm 'df' to get the disk info.

but i'd like to get the disk info included in a C/C++ file, could any
super guy help me with it?

thx a lot!
Sure. Just ask in where your question would be
topical. Then sit down, popen a cold one and your answer will doubtless
be forthcoming.

--ag
 
R

Rennie deGraaf

vansky said:
hi all,

as people known, we can use comm 'df' to get the disk info.

but i'd like to get the disk info included in a C/C++ file, could any
super guy help me with it?

thx a lot!

You could use popen() (in <cstdio>) to execute df and pipe its output
into a stream, which you could then read in and parse.

Alternately, you could look at the source code for df and gather the
information in the same way that it does.

Rennie deGraaf
 
V

vansky

thx all,


the following way is From:: Artie Gold

#include <stdlib.h>
#include <stdio.h>


int main(void) {
FILE * df = popen("df", "r");
int c;
while ((c = fgetc(df)) != EOF)
putchar(c);
pclose(df);
return 0;
 
R

Rennie deGraaf

Can't u use system() function to achieve this,


main()
{

system("df");

}

Try this..

System() will execute the command and return its exit code, but won't
give you its output, which is what the OP is looking for. (At least not
without some trickery that would end up being more complicated than
using popen().)

Rennie deGraaf
 
V

vansky

hi saldon,

i have tried statfs, that's also a great way!

btw, i got free blocks in fs with var f_bfree, also block size in
bytes is needed to convert blocks value to bytes value,

so, the question is: the funcs or global definition to get block
sizewhats ?

sort of stupid question, :)
 
V

vansky

hi saldon,


i have tried statfs, that's also a great way!


btw, i got free blocks in fs with var f_bfree, also block size in
bytes is needed to convert blocks value to bytes value,


so, the question is: whats the funcs or global definition to get block
size ??


sort of stupid question, :)
 
V

vansky

struct stats{
.....
f_bsize; /*optimal transfer block size */
.....
}

so sleepless these days...

but compared with "df -k", the value (f_bsize * f_bfree) is slightly
larger.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,682
Members
48,796
Latest member
Greg L.

Latest Threads

Top