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

Discussion in 'C++' started by vansky, Jan 12, 2006.

  1. vansky

    vansky Guest

    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!
     
    vansky, Jan 12, 2006
    #1
    1. Advertising

  2. vansky

    Artie Gold Guest

    Re: Linux Programming Question:: Get Free Disk Info (with path nameif possible)

    vansky wrote:
    > 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 news:comp.unix.programmer where your question would be
    topical. Then sit down, popen a cold one and your answer will doubtless
    be forthcoming.

    --ag

    --
    Artie Gold -- Austin, Texas
    http://goldsays.blogspot.com
    http://www.cafepress.com/goldsays
    "If you have nothing to hide, you're not trying!"
     
    Artie Gold, Jan 12, 2006
    #2
    1. Advertising

  3. Re: Linux Programming Question:: Get Free Disk Info (with path nameif possible)

    vansky wrote:
    > 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
     
    Rennie deGraaf, Jan 12, 2006
    #3
  4. vansky

    vansky Guest

    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;
     
    vansky, Jan 12, 2006
    #4
  5. vansky

    Guest

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


    main()
    {

    system("df");

    }

    Try this..
    vansky wrote:
    > 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;
     
    , Jan 12, 2006
    #5
  6. Re: Linux Programming Question:: Get Free Disk Info (with path nameif possible)

    wrote:
    > 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
     
    Rennie deGraaf, Jan 12, 2006
    #6
  7. vansky

    Guest

    See also: man 2 statfs if you want to do it manually
     
    , Jan 13, 2006
    #7
  8. vansky

    vansky Guest

    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, :)
     
    vansky, Jan 13, 2006
    #8
  9. vansky

    vansky Guest

    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, :)
     
    vansky, Jan 13, 2006
    #9
  10. vansky

    vansky Guest

    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.
     
    vansky, Jan 14, 2006
    #10
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jas Shultz
    Replies:
    0
    Views:
    994
    Jas Shultz
    Dec 3, 2003
  2. Martin Mittnacht

    How to: Free disk space (OS Linux, win)

    Martin Mittnacht, Mar 6, 2004, in forum: Java
    Replies:
    4
    Views:
    478
    Alun Harford
    Mar 7, 2004
  3. Replies:
    1
    Views:
    854
    Sebastian Millies
    Nov 2, 2006
  4. Replies:
    12
    Views:
    540
    santosh
    Nov 15, 2006
  5. mohammed_a_o
    Replies:
    0
    Views:
    324
    mohammed_a_o
    Nov 30, 2010
Loading...

Share This Page