Thread: Get information about the hard disk

  1. #1
    Registered User
    Join Date
    Jan 2004
    Posts
    13

    Get information about the hard disk

    I'm trying to get information about the harddisk usage, similar to the output generated by "df"

    I actually only need the number of free bytes available on the current mounting point (where the program is running) to check if it's possible to store large files the program downloads.

    And it would be great, if there'd be both an answer for Linux and Windows systems

    Sloede

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    37,736
    > I'm trying to get information about the harddisk usage, similar to the output generated by "df"
    Well your linux answer exists in the source code for df - heh, that was easy

    > And it would be great, if there'd be both an answer for Linux and Windows systems
    Ask on the windows board for whatever the win32 API call is for "getdiskinformation"
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    Jan 2004
    Posts
    13
    Phew, I just mangled through the whole df.c code just to find out that it's using the statfs function to gather all the needed data

    My only remaining question (as far as linux is concerned): How can I find out what the block size on my machine is or is the block size the same for let's say all i386 machines?


    Sloede

  4. #4
    Registered User
    Join Date
    Jan 2004
    Posts
    13
    Actually, it's still not working out for me. Statfs tells me that I only have some 435000 free blocks left while df tells me that there are for more than 2 mio. free blocks available. Does anyone know where this difference may come from?

  5. #5
    Registered User
    Join Date
    Jan 2004
    Posts
    13
    Thx people for not answering my questions. Now, after nobody gave me any hints I had to find it out myself - it took me a while but I managed to do it and now I learned more about the whole matter. I got the results I wanted just by trying - the best way to learn, eh

    Sloede


    P.S.: If anyone might have the same question in the future: Include <sys/vfs.h> and use statfs (man statfs). It gives you the blocksize and the number of blocks available - that's what you want to know to calcute the free disk space.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Struct/parse returning wrong information
    By dontknowc in forum C Programming
    Replies: 5
    Last Post: 12-04-2007, 01:39 PM
  2. Hard Disk Data Corrupted - Please Help
    By Draco in forum Tech Board
    Replies: 16
    Last Post: 12-01-2007, 12:02 AM
  3. Writing Directly to Hard Disk Sectors
    By ali_aslam in forum Linux Programming
    Replies: 2
    Last Post: 07-27-2007, 02:29 AM
  4. Going out of scope
    By nickname_changed in forum C++ Programming
    Replies: 9
    Last Post: 10-12-2003, 06:27 PM
  5. Strange hard disk
    By GanglyLamb in forum Tech Board
    Replies: 20
    Last Post: 03-01-2003, 04:05 AM