Re: sector and cylinder Information
- From: Lasse <Lasse-NO@xxxxxxxxxxxxxxxx>
- Date: Thu, 27 Nov 2008 23:48:23 +0100
Ali wrote:
Hi,A fraction of something I once wrote
I want to write a program to get the information about sector,track
and cylinder of the hard disk.
for example the number of sectors in a partition or the first cylinder
of a partition.
how can I write such program?
thanks,
Ali
#include <WinIoctl.h>
int Build_SectorTable(int DriveNum)
{
BOOL bResult;
HANDLE hDevice; // handle to the drive to be examined
DWORD BytesReturned;
char DriveName[32];
char Buff[4096];
DRIVE_LAYOUT_INFORMATION_EX *pDriveInfoEx;
DRIVE_LAYOUT_INFORMATION *pDriveInfo;
BOOL bIsXp;
OSVERSIONINFO OsVersionInfo;
OsVersionInfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
GetVersionEx(&OsVersionInfo);
if((OsVersionInfo.dwMajorVersion >= 5)
&& (OsVersionInfo.dwMinorVersion >= 1)) // XP
bIsXp = TRUE;
else
bIsXp = FALSE;
sprintf(DriveName,"\\\\.\\PhysicalDrive%d",DriveNum);
memset(Buff,0,sizeof(Buff));
memset(Buff,0,sizeof(Buff));
hDevice = CreateFile(DriveName, // drive to open
GENERIC_READ, //don't need any access to the drive
FILE_SHARE_READ, // share mode
NULL, // default security attributes
OPEN_EXISTING, // disposition
0, // file attributes
NULL); // don't copy any file's attributes
if (hDevice == INVALID_HANDLE_VALUE) // we can't open the drive
{
printf("...");
return (-1);
}
pDriveInfoEx = (DRIVE_LAYOUT_INFORMATION_EX *) Buff;
pDriveInfo = (DRIVE_LAYOUT_INFORMATION *) Buff;
bResult = DeviceIoControl(
hDevice,
bIsXp ? IOCTL_DISK_GET_DRIVE_LAYOUT_EX
: IOCTL_DISK_GET_DRIVE_LAYOUT,
NULL, // lpInBuffer
0, // nInBufferSize
pDriveInfoEx, // output buffer
sizeof(Buff), // size of output buffer
&BytesReturned, // number of bytes returned
NULL); // lpOverlapped
if(!bResult)
{ error handling }
....
....
Use DRIVE_LAYOUT_INFORMATION_EX *pDriveInfoEx and get partition and sector info
L.E.
.
- References:
- sector and cylinder Information
- From: Ali
- sector and cylinder Information
- Prev by Date: RE: RAM serial number and vendor
- Next by Date: How to read !heap -s output?
- Previous by thread: Re: sector and cylinder Information
- Next by thread: Destroy problems with an un-parented dialog-window
- Index(es):
Relevant Pages
|