Es este un interesante código que le dará la posibilidad a los que logren dominarlo de hacer algunas otras cositas con el trabajo de los discos duros.
// Get Disk Geometry.cpp : Defines the entry point for the console application.
    //
#include "stdafx.h"
  #include <windows.h>
  #include <stdio.h>
  #include <winioctl.h>
DISK_GEOMETRY SupportedGeometry[20];
    DWORD SupportedGeometryCount;
VOID
    GetSupportedGeometrys(HANDLE hDisk)
    {
      DWORD ReturnedByteCount;
      if(DeviceIoControl(hDisk,IOCTL_DISK_GET_DRIVE_GEOMETRY,NULL,0,SupportedGeometry,sizeof(SupportedGeometry),&ReturnedByteCount,NULL))
        SupportedGeometryCount = ReturnedByteCount / sizeof(DISK_GEOMETRY);
      else 
    SupportedGeometryCount = 0;
    }
 VOID
    PrintGeometry( PDISK_GEOMETRY lpGeometry )
    {
      LPSTR MediaType;
      switch ( lpGeometry->MediaType ) 
      {
        case F5_1Pt2_512:
          MediaType = "5.25, 1.2MB,  512 bytes/sector";
        break;
        case F3_1Pt44_512:
          MediaType = "3.5,  1.44MB, 512 bytes/sector";
        break;
        case F3_2Pt88_512:
          MediaType = "3.5,  2.88MB, 512 bytes/sector";
        break;
        case F3_20Pt8_512:
          MediaType = "3.5,  20.8MB, 512   bytes/sector";
        break;
        case F3_720_512:
          MediaType = "3.5,  720KB,  512 bytes/sector";
        break;
        case F5_360_512:
          MediaType = "5.25, 360KB,  512 bytes/sector";
        break;
        case F5_320_512:
          MediaType = "5.25, 320KB,  512 bytes/sector";
        break;
        case F5_320_1024:
          MediaType = "5.25, 320KB,  1024 bytes/sector";
        break;
        case F5_180_512:
          MediaType = "5.25, 180KB,  512 bytes/sector";
        break;
        case F5_160_512:
          MediaType = "5.25, 160KB,  512  bytes/sector";
        break;
        case RemovableMedia:
          MediaType = "Removable media other than floppy";
        break;
        case FixedMedia:
          MediaType = "Fixed hard disk media";
        break;
        default:
          MediaType = "Unknown";
        break;
      }
      printf("    Media Type: %s\n", MediaType );
      printf("Cylinders%d,Tracks/Cylinder%d,Sectors/Track%d\n",lpGeometry->Cylinders.LowPart,lpGeometry->TracksPerCylinder,lpGeometry->SectorsPerTrac);
  }
int main(int argc, char* argv[])
    {
      HANDLE hDrive;
      UINT i;
      hDrive = CreateFile(
    "\\\\.\\C:",
      0,
      FILE_SHARE_READ,
      NULL,
      OPEN_ALWAYS,
      0,
      NULL);
      if (hDrive == INVALID_HANDLE_VALUE)
      {
        printf( "Open failed: %d\n", GetLastError());
        ExitProcess(1);
    }
   GetSupportedGeometrys( hDrive );
   printf( "\nDrive C supports the following disk geometries\n" );
        for( i=0; i<SupportedGeometryCount; i++ )
      {
        printf("\n");
        PrintGeometry (&SupportedGeometry[i]);
      }
      printf("\n");
      system ("pause");
      return 0;
    }

No hay comentarios:
Publicar un comentario