Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Disk Capacity Information - How?

Hi!

Anyone knows how to retrieve information on disk capacity (not only the partition size) using WINAPI functions?

Thanks!
Check my programs!

Comments

  • rollerolle Member Posts: 115
    : Hi!
    :
    : Anyone knows how to retrieve information on disk capacity (not only the partition size) using WINAPI functions?
    :
    : Thanks!
    : Check my programs!
    :
    Look up [b]GetVolumeInformation[/b] and [b]DeviceIoControl[/b] in MSDN and see if they give what you want
  • WizardyWizardy Member Posts: 24
    I checked it out and I found nothing. Do you have any other idea?

    Please help me with this :(.
    Check my programs!

  • rollerolle Member Posts: 115
    : I checked it out and I found nothing. Do you have any other idea?
    :
    : Please help me with this :(.
    : Check my programs!
    :
    :
    [green]I'll help you if I can. But first you must help me - what do you WANT to do? What info do you NEED for the partition or disk?[/green]
  • WizardyWizardy Member Posts: 24
    I mentioned that already in the first post. The DISK capacity information.
    Check my programs!

  • rollerolle Member Posts: 115
    : I mentioned that already in the first post. The DISK capacity information.
    : Check my programs!
    :
    :
    [green]You have 4 downloadable programs - which one of them should I check? BTW, have you looked at APIs [b]GetLogicalDrives[/b] and [b]GetLogicalDriveStrings[/b]?[/green]
  • WizardyWizardy Member Posts: 24
    You can download all 4 programs :). I recommend RPG and numbers.

    I'll look at those functions. Thank you for the tips.

    I'll be back.
    Check my programs!

  • rollerolle Member Posts: 115
    : You can download all 4 programs :). I recommend RPG and numbers.
    :
    : I'll look at those functions. Thank you for the tips.
    :
    : I'll be back.
    : Check my programs!
    :
    :
    [green]I still believe that DeviceIoControl is the API for you to use:[code]
    int main(int argc,char **argv)
    {

    BOOL fcc;
    HANDLE hFile = INVALID_HANDLE_VALUE;
    DISK_GEOMETRY dm;
    DWORD dwBytesReturned;

    ...
    hFile = CreateFile
    (
    argv[1],
    GENERIC_READ,
    FILE_SHARE_READ | FILE_SHARE_WRITE,
    NULL,
    OPEN_EXISTING,
    0,
    NULL
    );
    if (hFile == INVALID_HANDLE_VALUE)
    {
    ... // Error handling
    }

    fcc = DeviceIoControl
    (
    hFile,
    IOCTL_DISK_GET_DRIVE_GEOMETRY,
    NULL,
    0,
    &dm,
    sizeof(dm),
    &dwBytesReturned,
    (LPOVERLAPPED) NULL
    )
    if (fcc == FALSE)
    {
    ... // Error handling
    }

    cout << "Geometry for <" << argv[1] << ">:" << endl
    << "Cylinders (low) = " << dm.Cylinders.LowPart << endl
    << "Cylinders (high) = " << dm.Cylinders.HighPart << endl
    << "Media Type = " << dm.MediaType << endl
    << "Tracks per Cylinder = " << dm.TracksPerCylinder << endl
    << "Sectors per Track = " << dm.SectorsPerTrack << endl
    << "Bytes per Sector = " << dm.BytesPerSector
    ;

    ...

    }
    [/code]

    If you try this code with \.PhysicalDriveN and \.C: you will get the same results, provided that N (0+) is the physical drive that holds partition C:. If a 2nd partition D: is on the same PD, you will still get the same results.

    If you want to display or make calculations based on the capacity of the disk, you have to do some LARGE_INTEGER or __int64 arithmetic.[/green]
  • Justin BibJustin Bib USAMember Posts: 0

    ________ | http://forcoder.org | free ebooks and video tutorials about [ Go Python C++ JavaScript PL/SQL PHP Java Swift C# Scratch Visual Basic MATLAB Perl R Objective-C Ruby Assembly Delphi C Visual Basic .NET Dart Hack Transact-SQL Apex Bash Ada F# Lisp Alice Erlang Logo SAS Fortran Clojure Julia VBScript Scheme Prolog Rust ABAP Kotlin Awk ML D Lua COBOL LabVIEW Crystal Scala FoxPro ] ___

Sign In or Register to comment.