Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Physical drive size

Physical drive size

Scheduled Pinned Locked Moved C / C++ / MFC
performancetutorialquestion
12 Posts 5 Posters 4 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Lost User

    If the file system is corrupt then it is unlikely that any of the normal functions will work successfully, you should try to reformat the device.

    Use the best guess

    J Offline
    J Offline
    john5632
    wrote on last edited by
    #3

    But we nothing to do with file system, need to get physical disk size. Many other software are showing correct size for same memory card. Can you please give any idea?

    L 1 Reply Last reply
    0
    • J john5632

      But we nothing to do with file system, need to get physical disk size. Many other software are showing correct size for same memory card. Can you please give any idea?

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #4

      Maybe you need to show us the code you have tried.

      Use the best guess

      J 2 Replies Last reply
      0
      • L Lost User

        Maybe you need to show us the code you have tried.

        Use the best guess

        J Offline
        J Offline
        john5632
        wrote on last edited by
        #5

        Below is WMI call

        VariantClear(&vtProp);
        hr = pclsObj->Get(L"Size", 0, &vtProp, 0, 0);

        Below is IOCTL call

        bResult = DeviceIoControl(hDevice, // device to be queried
        IOCTL_DISK_GET_DRIVE_GEOMETRY, // operation to perform
        NULL, 0, // no input buffer
        pdg, sizeof(*pdg), // output buffer
        &junk, // # bytes returned
        (LPOVERLAPPED) NULL); // synchronous I/O

        CloseHandle(hDevice);

        	ULONGLONG DiskSize = 0;    // size of the drive, in bytes
        

        DiskSize = pdg->Cylinders.QuadPart * (ULONG)pdg->TracksPerCylinder *
        (ULONG)pdg->SectorsPerTrack * (ULONG)pdg->BytesPerSector;
        wprintf(L"Disk size = %I64d (Bytes)\n"
        L" = %.2f (Gb)\n",
        DiskSize, (double) DiskSize / (1024 * 1024 * 1024));

        But both gives same result. pdg->Cylinders.QuadPart is coming 1.

        1 Reply Last reply
        0
        • L Lost User

          Maybe you need to show us the code you have tried.

          Use the best guess

          J Offline
          J Offline
          john5632
          wrote on last edited by
          #6

          I tried IOCTL

          DeviceIoControl(hDevice,IOCTL_DISK_GET_LENGTH_INFO,0,0,&gli,sizeof(gli),&ret,0);
          ULONGLONG siize = gli.Length.QuadPart;

          It gives correct result on VS2008 but not on VS2003. I need to code for VS2003. Please guide...

          J L 2 Replies Last reply
          0
          • J john5632

            I tried IOCTL

            DeviceIoControl(hDevice,IOCTL_DISK_GET_LENGTH_INFO,0,0,&gli,sizeof(gli),&ret,0);
            ULONGLONG siize = gli.Length.QuadPart;

            It gives correct result on VS2008 but not on VS2003. I need to code for VS2003. Please guide...

            J Offline
            J Offline
            Jochen Arndt
            wrote on last edited by
            #7

            The VS version should make no difference for device IO control API functions. But IOCTL_DISK_GET_LENGTH_INFO requires XP or later. To support older Windows versions use IOCTL_DISK_GET_PARTITION_INFO.

            J 1 Reply Last reply
            0
            • J john5632

              I tried IOCTL

              DeviceIoControl(hDevice,IOCTL_DISK_GET_LENGTH_INFO,0,0,&gli,sizeof(gli),&ret,0);
              ULONGLONG siize = gli.Length.QuadPart;

              It gives correct result on VS2008 but not on VS2003. I need to code for VS2003. Please guide...

              L Offline
              L Offline
              Lost User
              wrote on last edited by
              #8

              Simple answer use VS2008 or later.

              Use the best guess

              1 Reply Last reply
              0
              • J Jochen Arndt

                The VS version should make no difference for device IO control API functions. But IOCTL_DISK_GET_LENGTH_INFO requires XP or later. To support older Windows versions use IOCTL_DISK_GET_PARTITION_INFO.

                J Offline
                J Offline
                john5632
                wrote on last edited by
                #9

                But why it is not giving correct result on my machine win7+vs2003 but working fine with win7+vs2008. I can not use vs2008 simply because whole product is in vs2003 and need to make correction in same. please suggest solution...

                J 1 Reply Last reply
                0
                • J john5632

                  I have a memory card which is having corrupted file system. I need to get physical drive size. I tried using WMI but it gives 8 MB only even though its size is 30GB. Can you please guide me?

                  C Offline
                  C Offline
                  Chris Losinger
                  wrote on last edited by
                  #10

                  you have a 30GB memory card? that's a strange size... they're sized in generally powers of two.

                  image processing toolkits | batch image processing

                  D 1 Reply Last reply
                  0
                  • J john5632

                    But why it is not giving correct result on my machine win7+vs2003 but working fine with win7+vs2008. I can not use vs2008 simply because whole product is in vs2003 and need to make correction in same. please suggest solution...

                    J Offline
                    J Offline
                    Jochen Arndt
                    wrote on last edited by
                    #11

                    I don't know why. DeviceIoControl() is a Windows kernel function that passes the request to the device specific driver. So there should be no differences on one machine when calling this from a VS 2003 or VS 2008 generated application or even any other programming language.

                    1 Reply Last reply
                    0
                    • C Chris Losinger

                      you have a 30GB memory card? that's a strange size... they're sized in generally powers of two.

                      image processing toolkits | batch image processing

                      D Offline
                      D Offline
                      dusty_dex
                      wrote on last edited by
                      #12

                      Chris Losinger wrote:

                      you have a 30GB memory card? that's a strange size... they're sized in generally powers of two.

                      That's generally the case, but some lower capacity SSDs are specified in tens of gigs. try googling for 30GB/40GB SSD. ;)

                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      • Login

                      • Don't have an account? Register

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • World
                      • Users
                      • Groups