Results 1 to 5 of 5

Thread: Disk usage

  1. #1
    Join Date
    Apr 2007
    Beans
    4

    Disk usage

    I need to get disk statistics in a program I'm porting from Windows. Specifically, I need to know how to find the filesystem that a given pathname belongs to and how much space is available on that filesystem. I'm having trouble finding a lib or system calls to support this requirement. Does anyone know what I can use?

  2. #2
    Join Date
    Apr 2005
    Location
    USA
    Beans
    Hidden!
    Distro
    Ubuntu Development Release

    Re: Disk usage

    I think there was an app called Disk usage Manager.

  3. #3
    Join Date
    Apr 2006
    Beans
    368
    Distro
    Edubuntu 7.04 Feisty Fawn

    Re: Disk usage

    try xdiskusage, it is cool.

  4. #4
    WW is offline Iced Blended Vanilla Crème Ubuntu
    Join Date
    Oct 2004
    Beans
    1,532

    Re: Disk usage

    The library function statfs returns information about a file system. Check out man statfs.

    For example:
    Code:
    /* fstest.c */
    
    #include <sys/statfs.h>
    #include <errno.h>
    #include <stdio.h>
    
    int main(int argc, char **argv)
        {
        struct statfs s;
        int e;
    
        if (argc != 2)
            {
            fprintf(stderr,"use: fstest filesystem\n");
            return -1;
            }
        e = statfs(argv[1], &s);
        if (e != 0)
            printf("statfs failed; errno = %d\n", errno);
        else
            {
            printf("Results of statfs for %s\n",argv[1]);
            printf("%10d block size\n",s.f_bsize);
            printf("%10ld total data blocks\n", s.f_blocks);
            printf("%10ld free blocks\n",s.f_bfree);
            printf("%10ld free blocks available to non-superuser\n",s.f_bavail);
            printf("%10ld total file nodes\n",s.f_files);
            printf("%10ld free file nodes\n",s.f_ffree);
            }
        return 0;
        }
    Compile and run, and compare the output to the df command:
    Code:
    $ gcc -Wall fstest.c -o fstest
    $ ./fstest /
    Results of statfs for /
          4096 block size
       3605336 total data blocks
       2865519 free blocks
       2682379 free blocks available to non-superuser
       1831424 total file nodes
       1744030 free file nodes
    $ df --block-size=4096 /
    Filesystem           4K-blocks      Used Available Use% Mounted on
    /dev/hda1              3605336    739817   2682379  22% /

  5. #5
    Join Date
    Apr 2007
    Beans
    4

    Re: Disk usage

    Thanks to all for the responses. WW's response was exactly what I was looking for. For some reason I had fstat stuck in my brain. Neither my gray matter, nor man -k could find what WW so kindly provided. The statfs call was just the thing. Thank again!

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •