Re: sector and cylinder Information

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



Ali wrote:
Hi,

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
A fraction of something I once wrote

#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.
.



Relevant Pages

  • Re: grub error 18
    ... because I thought the EXTEND partition would be the second partition in ... Selected cylinder exceeds maximum supported by BIOS." ... the disk using CHS addressing (that is: telling the BIOS a head number, ... sectors per track gave 32k bytes per track, ...
    (uk.comp.homebuilt)
  • Re: lilo removal in squeeze (or, "please test grub2")
    ... sector 2 and possibly subsequent sectors on cylinder 0 head 0. ... The reason for this extra space is that traditionally, the first partition on a DOS partition table can only start at the second cylinder, so boot loaders just used to use the remaining space from the first cylinder so they didn't have to ask anything to anybody, since it was always sufficient. ...
    (Debian-User)
  • Re: [opensuse] how to define partition size in sectors?
    ... take partition size input in megabytes even if units are set to sectors. ... multiple of a logical "cylinder". ... other primary partition of "same" size, ...
    (SuSE)
  • Re: fdisk Q
    ... that mean that the partition has an additional sector or is ... sectors, the "Blocks" column will still be in 1KB units, so will ... least places all blocks in one cylinder or another without splitting ... I'd like to nail this down, am I still missing something? ...
    (alt.os.linux)
  • Re: File Encryption : how I tricked myself
    ... Sounds more like you don't know the difference between a logical and physical partition image. ... Acronis TrueImage Home reads through the file system so what it saves are logical images, plus TI Home does *not* support VSS so there are problems saving inuse or locked files. ... It had the feature that it could read through recognized file systems in that partition to see which sectors were not allocated and wouldn't bother to include those in the image file. ... Norton Ghost used to default to saving logical images unless you specified a switch to make it save physical images. ...
    (microsoft.public.windowsxp.help_and_support)