From: Ali on
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
From: David Craig on
1. Look at the code for this program:
http://www.winsim.com/diskid32/diskid32.html . It does not exactly provide
the information you want, but it is a start about how to use some of the
various IoCtls.
2. Read the documentation on CreateFile(). Read it again. Repeat at least
5 more times.
3. Read the code for disk.sys in the WDK that will show you which storage
and disk IoCtls are handled. Also look at the headers in the WDK for
storage and disk.
4. Experiment using only query and read IoCtls being careful to not do a
write or other destructive actions. I would suggest you use a test system
or virtual machine. With VMWare you can create the boot & system partition
and then add a couple of others to include dynamic volumes. You will still
need to test real hardware and I would use at least five hard drives with
different sizes and partition schemes. Don't forget dynamic volumes as they
are different in some ways.
5. After doing the things above, answer the following questions:
a. How do I open a hard drive?
b. How do I open a volume?
c. What requests are valid for a hard drive and what information can I
expect to obtain?
d. What requests are valid for a volume and what information can I
expect to obtain?


"Ali" <nikzad.a(a)gmail.com> wrote in message
news:889933c0-c079-4107-8a3d-03dbc59e20e0(a)h20g2000yqn.googlegroups.com...
> 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


From: Fred on
David Craig wrote:
> 1. Look at the code for this program:
> http://www.winsim.com/

Completely off-topic (and bad code, as often mentioned on usenet)
Just see MSDN samples to read sectors.
From: Alexander Grigoriev on
Adding to other responses,

The only thing you can meaningfully have from a hard disk is a logical
block. Cylinder, head, sector on a track do not mean anything now.

"Ali" <nikzad.a(a)gmail.com> wrote in message
news:889933c0-c079-4107-8a3d-03dbc59e20e0(a)h20g2000yqn.googlegroups.com...
> 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


From: Lasse on
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.