mirror of
https://github.com/reactos/reactos.git
synced 2024-12-26 17:14:41 +00:00
Read drive number from the command line.
Added some sanity checks. svn path=/trunk/; revision=3290
This commit is contained in:
parent
5faa3537c3
commit
c1652a2ee6
2 changed files with 58 additions and 10 deletions
|
@ -1,4 +1,4 @@
|
|||
# $Id: makefile,v 1.2 2002/06/07 22:58:18 ekohl Exp $
|
||||
# $Id: makefile,v 1.3 2002/07/22 17:53:12 ekohl Exp $
|
||||
|
||||
PATH_TO_TOP = ../../..
|
||||
|
||||
|
@ -12,7 +12,7 @@ TARGET_NAME = partinfo
|
|||
|
||||
#TARGET_CFLAGS = -fnative_struct
|
||||
|
||||
TARGET_SDKLIBS = kernel32.a
|
||||
TARGET_SDKLIBS = ntdll.a kernel32.a
|
||||
|
||||
TARGET_OBJECTS = $(TARGET_NAME).o
|
||||
|
||||
|
|
|
@ -54,6 +54,13 @@ void HexDump(char *buffer, ULONG size)
|
|||
}
|
||||
#endif
|
||||
|
||||
|
||||
void Usage(void)
|
||||
{
|
||||
puts("Usage: partinfo <drive number>");
|
||||
}
|
||||
|
||||
|
||||
int main (int argc, char *argv[])
|
||||
{
|
||||
HANDLE hDisk;
|
||||
|
@ -62,8 +69,53 @@ int main (int argc, char *argv[])
|
|||
char *Buffer;
|
||||
DRIVE_LAYOUT_INFORMATION *LayoutBuffer;
|
||||
DISK_GEOMETRY DiskGeometry;
|
||||
ULONG ulDrive;
|
||||
CHAR DriveName[40];
|
||||
SYSTEM_DEVICE_INFORMATION DeviceInfo;
|
||||
NTSTATUS Status;
|
||||
|
||||
hDisk = CreateFile("\\\\.\\PHYSICALDRIVE0",
|
||||
if (argc != 2)
|
||||
{
|
||||
Usage();
|
||||
return(0);
|
||||
}
|
||||
|
||||
ulDrive = strtoul(argv[1], NULL, 10);
|
||||
if (errno != 0)
|
||||
{
|
||||
printf("Error: Malformed drive number\n", errno);
|
||||
return(0);
|
||||
}
|
||||
|
||||
/* Check drive number */
|
||||
Status = NtQuerySystemInformation(SystemDeviceInformation,
|
||||
&DeviceInfo,
|
||||
sizeof(SYSTEM_DEVICE_INFORMATION),
|
||||
&i);
|
||||
if (!NT_SUCCESS(Status))
|
||||
{
|
||||
printf("NtQuerySystemInformation() failed (Status %lx)\n", Status);
|
||||
return(0);
|
||||
}
|
||||
|
||||
if (DeviceInfo.NumberOfDisks == 0)
|
||||
{
|
||||
printf("No disk drive installed!\n");
|
||||
return(0);
|
||||
}
|
||||
|
||||
if (ulDrive >= DeviceInfo.NumberOfDisks)
|
||||
{
|
||||
printf("Invalid disk drive number! Valid drive numbers [0-%lu]\n",
|
||||
DeviceInfo.NumberOfDisks-1);
|
||||
return(0);
|
||||
}
|
||||
|
||||
/* Build full drive name */
|
||||
sprintf(DriveName, "\\\\.\\PHYSICALDRIVE%lu", ulDrive);
|
||||
|
||||
/* Open drive */
|
||||
hDisk = CreateFile(DriveName,
|
||||
GENERIC_READ,
|
||||
FILE_SHARE_READ | FILE_SHARE_WRITE,
|
||||
NULL,
|
||||
|
@ -76,8 +128,7 @@ int main (int argc, char *argv[])
|
|||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/* get drive geometry */
|
||||
/* Get drive geometry */
|
||||
if (!DeviceIoControl(hDisk,
|
||||
IOCTL_DISK_GET_DRIVE_GEOMETRY,
|
||||
NULL,
|
||||
|
@ -97,6 +148,7 @@ int main (int argc, char *argv[])
|
|||
#ifdef DUMP_DATA
|
||||
HexDump((char*)&DiskGeometry, dwRead);
|
||||
#endif
|
||||
printf("Drive number: %lu\n", ulDrive);
|
||||
printf("Cylinders: %I64u\nMediaType: %lx\nTracksPerCylinder: %lu\n"
|
||||
"SectorsPerTrack: %lu\nBytesPerSector: %lu\n\n",
|
||||
DiskGeometry.Cylinders.QuadPart,
|
||||
|
@ -125,7 +177,7 @@ int main (int argc, char *argv[])
|
|||
NULL))
|
||||
{
|
||||
CloseHandle(hDisk);
|
||||
printf("DeviceIoControl failed! Error: %u\n",
|
||||
printf("DeviceIoControl(IOCTL_DISK_GET_DRIVE_LAYOUT) failed! Error: %u\n",
|
||||
GetLastError());
|
||||
free(Buffer);
|
||||
return 0;
|
||||
|
@ -154,10 +206,6 @@ int main (int argc, char *argv[])
|
|||
LayoutBuffer->PartitionEntry[i].PartitionLength.QuadPart);
|
||||
}
|
||||
|
||||
#ifdef DUMP_SIZE_INFO
|
||||
printf("\nsizeof(PARTITION_INFORMATION): %lu\n", sizeof(PARTITION_INFORMATION));
|
||||
#endif
|
||||
|
||||
free(Buffer);
|
||||
|
||||
return 0;
|
||||
|
|
Loading…
Reference in a new issue