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. How to get the total sectors of physical disk

How to get the total sectors of physical disk

Scheduled Pinned Locked Moved C / C++ / MFC
adobetutorialquestion
4 Posts 2 Posters 0 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.
  • B Offline
    B Offline
    bghuang
    wrote on last edited by
    #1

    The USB flash disk have no CHS parameters (the system use virtual parameters),I only need to get teh total sectors for physical drive. The MBR and BOOT may be failure. so your function is invalid. ,how to do it? Thanks.

    D 1 Reply Last reply
    0
    • B bghuang

      The USB flash disk have no CHS parameters (the system use virtual parameters),I only need to get teh total sectors for physical drive. The MBR and BOOT may be failure. so your function is invalid. ,how to do it? Thanks.

      D Offline
      D Offline
      Devendra Vaja
      wrote on last edited by
      #2

      Hi, Could you please elaborate the question? Are you looking for the Sector information of the Physical drives i.e Hard disk or USB disk??

      B 1 Reply Last reply
      0
      • D Devendra Vaja

        Hi, Could you please elaborate the question? Are you looking for the Sector information of the Physical drives i.e Hard disk or USB disk??

        B Offline
        B Offline
        bghuang
        wrote on last edited by
        #3

        I want to get the disk size for every physical disk. The CHS parameter is true for harddisk,but wrong for USB flash disk. Becase the system assume that's X*255*63,the total sectors are also wrong. I dont know what function can I use.

        D 1 Reply Last reply
        0
        • B bghuang

          I want to get the disk size for every physical disk. The CHS parameter is true for harddisk,but wrong for USB flash disk. Becase the system assume that's X*255*63,the total sectors are also wrong. I dont know what function can I use.

          D Offline
          D Offline
          Devendra Vaja
          wrote on last edited by
          #4

          Hi As per my knowledge, You can open any disk (using CreateFile(DriveName,....)and after reading the first sector of the disk you will get Boot record of the same from there I feel you can get the size of the disk Otherwise harddisk has Master boot table from where you can get the partitions and their sizes.If you want to open a physical drive you can open it using the CreateFile("\\\\.\\PHYSICALDRIVE0",....) for the harddisk.and after reading the MBT you can get the drive information .If you want to use the WINDOWS api then you can use GetDiskFreeSpace() API and pass NULL as a root directory it will return you the TOTAL number of clusters,multiply it with the Sectores per cluster and bytes per sector.You will get the disk size.

          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