mirror of
https://github.com/reactos/reactos.git
synced 2025-08-05 12:43:05 +00:00
[ROSAPPS:PARTINFO] Code formatting.
This commit is contained in:
parent
de16ef3da0
commit
118fa50269
1 changed files with 140 additions and 144 deletions
|
@ -2,46 +2,35 @@
|
||||||
* partinfo - partition info program
|
* partinfo - partition info program
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
#define WIN32_NO_STATUS
|
#define WIN32_NO_STATUS
|
||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
#include <stdlib.h>
|
|
||||||
#include <ntndk.h>
|
#include <ntndk.h>
|
||||||
#include <stdio.h>
|
|
||||||
|
|
||||||
// #define DUMP_DATA
|
// #define DUMP_DATA
|
||||||
#define DUMP_SIZE_INFO
|
#define DUMP_SIZE_INFO
|
||||||
|
|
||||||
#ifdef DUMP_DATA
|
#ifdef DUMP_DATA
|
||||||
void HexDump(char *buffer, ULONG size)
|
void HexDump(
|
||||||
|
IN PVOID buffer,
|
||||||
|
IN ULONG size)
|
||||||
{
|
{
|
||||||
ULONG offset = 0;
|
ULONG_PTR offset = 0;
|
||||||
unsigned char *ptr;
|
PUCHAR ptr;
|
||||||
|
|
||||||
while (offset < (size & ~15))
|
while (offset < (size & ~15))
|
||||||
{
|
{
|
||||||
ptr = (unsigned char*)((ULONG)buffer + offset);
|
ptr = (PUCHAR)((ULONG_PTR)buffer + offset);
|
||||||
printf("%08lx %02hx %02hx %02hx %02hx %02hx %02hx %02hx %02hx-%02hx %02hx %02hx %02hx %02hx %02hx %02hx %02hx\n",
|
printf("%08lx %02hx %02hx %02hx %02hx %02hx %02hx %02hx %02hx-%02hx %02hx %02hx %02hx %02hx %02hx %02hx %02hx\n",
|
||||||
offset,
|
offset,
|
||||||
ptr[0],
|
ptr[0], ptr[1], ptr[2] , ptr[3] , ptr[4] , ptr[5] , ptr[6] , ptr[7],
|
||||||
ptr[1],
|
ptr[8], ptr[9], ptr[10], ptr[11], ptr[12], ptr[13], ptr[14], ptr[15]);
|
||||||
ptr[2],
|
|
||||||
ptr[3],
|
|
||||||
ptr[4],
|
|
||||||
ptr[5],
|
|
||||||
ptr[6],
|
|
||||||
ptr[7],
|
|
||||||
ptr[8],
|
|
||||||
ptr[9],
|
|
||||||
ptr[10],
|
|
||||||
ptr[11],
|
|
||||||
ptr[12],
|
|
||||||
ptr[13],
|
|
||||||
ptr[14],
|
|
||||||
ptr[15]);
|
|
||||||
offset += 16;
|
offset += 16;
|
||||||
}
|
}
|
||||||
|
|
||||||
ptr = (unsigned char*)((ULONG)buffer + offset);
|
ptr = (PUCHAR)((ULONG_PTR)buffer + offset);
|
||||||
printf("%08lx ", offset);
|
printf("%08lx ", offset);
|
||||||
while (offset < size)
|
while (offset < size)
|
||||||
{
|
{
|
||||||
|
@ -54,67 +43,65 @@ void HexDump(char *buffer, ULONG size)
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
void Usage(void)
|
void Usage(void)
|
||||||
{
|
{
|
||||||
puts("Usage: partinfo <drive number>");
|
puts("Usage: partinfo <drive number>");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
|
NTSTATUS Status;
|
||||||
|
ULONG ulDrive;
|
||||||
HANDLE hDisk;
|
HANDLE hDisk;
|
||||||
DWORD dwRead;
|
DWORD dwRead;
|
||||||
DWORD i;
|
DWORD i;
|
||||||
char *Buffer;
|
|
||||||
DRIVE_LAYOUT_INFORMATION *LayoutBuffer;
|
|
||||||
DISK_GEOMETRY DiskGeometry;
|
|
||||||
ULONG ulDrive;
|
|
||||||
CHAR DriveName[40];
|
|
||||||
SYSTEM_DEVICE_INFORMATION DeviceInfo;
|
SYSTEM_DEVICE_INFORMATION DeviceInfo;
|
||||||
NTSTATUS Status;
|
DISK_GEOMETRY DiskGeometry;
|
||||||
|
PDRIVE_LAYOUT_INFORMATION LayoutBuffer;
|
||||||
|
CHAR DriveName[40];
|
||||||
|
|
||||||
if (argc != 2)
|
if (argc != 2)
|
||||||
{
|
{
|
||||||
Usage();
|
Usage();
|
||||||
return(0);
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
ulDrive = strtoul(argv[1], NULL, 10);
|
ulDrive = strtoul(argv[1], NULL, 10);
|
||||||
if (errno != 0)
|
if (errno != 0)
|
||||||
{
|
{
|
||||||
printf("Error: Malformed drive number\n");
|
printf("Error: Malformed drive number\n");
|
||||||
return(0);
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Check drive number */
|
/*
|
||||||
|
* Retrieve the number of disks on the system.
|
||||||
|
*/
|
||||||
Status = NtQuerySystemInformation(SystemDeviceInformation,
|
Status = NtQuerySystemInformation(SystemDeviceInformation,
|
||||||
&DeviceInfo,
|
&DeviceInfo,
|
||||||
sizeof(SYSTEM_DEVICE_INFORMATION),
|
sizeof(DeviceInfo),
|
||||||
&i);
|
&i);
|
||||||
if (!NT_SUCCESS(Status))
|
if (!NT_SUCCESS(Status))
|
||||||
{
|
{
|
||||||
printf("NtQuerySystemInformation() failed (Status %lx)\n", Status);
|
printf("NtQuerySystemInformation() failed (Status %lx)\n", Status);
|
||||||
return(0);
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (DeviceInfo.NumberOfDisks == 0)
|
if (DeviceInfo.NumberOfDisks == 0)
|
||||||
{
|
{
|
||||||
printf("No disk drive installed!\n");
|
printf("No disk drive installed!\n");
|
||||||
return(0);
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ulDrive >= DeviceInfo.NumberOfDisks)
|
if (ulDrive >= DeviceInfo.NumberOfDisks)
|
||||||
{
|
{
|
||||||
printf("Invalid disk drive number! Valid drive numbers [0-%lu]\n",
|
printf("Invalid disk drive number! Valid drive numbers [0-%lu]\n",
|
||||||
DeviceInfo.NumberOfDisks-1);
|
DeviceInfo.NumberOfDisks-1);
|
||||||
return(0);
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Build full drive name */
|
/* Build the full drive name */
|
||||||
sprintf(DriveName, "\\\\.\\PHYSICALDRIVE%lu", ulDrive);
|
sprintf(DriveName, "\\\\.\\PHYSICALDRIVE%lu", ulDrive);
|
||||||
|
|
||||||
/* Open drive */
|
/* Open the drive */
|
||||||
hDisk = CreateFileA(DriveName,
|
hDisk = CreateFileA(DriveName,
|
||||||
GENERIC_READ,
|
GENERIC_READ,
|
||||||
FILE_SHARE_READ | FILE_SHARE_WRITE,
|
FILE_SHARE_READ | FILE_SHARE_WRITE,
|
||||||
|
@ -128,24 +115,26 @@ int main (int argc, char *argv[])
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Get drive geometry */
|
/*
|
||||||
|
* Get the drive geometry.
|
||||||
|
*/
|
||||||
if (!DeviceIoControl(hDisk,
|
if (!DeviceIoControl(hDisk,
|
||||||
IOCTL_DISK_GET_DRIVE_GEOMETRY,
|
IOCTL_DISK_GET_DRIVE_GEOMETRY,
|
||||||
NULL,
|
NULL,
|
||||||
0,
|
0,
|
||||||
&DiskGeometry,
|
&DiskGeometry,
|
||||||
sizeof(DISK_GEOMETRY),
|
sizeof(DiskGeometry),
|
||||||
&dwRead,
|
&dwRead,
|
||||||
NULL))
|
NULL))
|
||||||
{
|
{
|
||||||
CloseHandle(hDisk);
|
printf("DeviceIoControl(IOCTL_DISK_GET_DRIVE_GEOMETRY) failed! Error: %lu\n",
|
||||||
printf("DeviceIoControl failed! Error: %lu\n",
|
|
||||||
GetLastError());
|
GetLastError());
|
||||||
|
CloseHandle(hDisk);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef DUMP_DATA
|
#ifdef DUMP_DATA
|
||||||
HexDump((char*)&DiskGeometry, dwRead);
|
HexDump(&DiskGeometry, dwRead);
|
||||||
#endif
|
#endif
|
||||||
printf("Drive number: %lu\n", ulDrive);
|
printf("Drive number: %lu\n", ulDrive);
|
||||||
printf("Cylinders: %I64u\nMediaType: %x\nTracksPerCylinder: %lu\n"
|
printf("Cylinders: %I64u\nMediaType: %x\nTracksPerCylinder: %lu\n"
|
||||||
|
@ -156,40 +145,45 @@ int main (int argc, char *argv[])
|
||||||
DiskGeometry.SectorsPerTrack,
|
DiskGeometry.SectorsPerTrack,
|
||||||
DiskGeometry.BytesPerSector);
|
DiskGeometry.BytesPerSector);
|
||||||
|
|
||||||
|
#if 0 // TODO!
|
||||||
|
/* Get extended drive geometry */
|
||||||
|
// IOCTL_DISK_GET_DRIVE_GEOMETRY_EX
|
||||||
|
#endif
|
||||||
|
|
||||||
Buffer = (char*)malloc(8192);
|
/*
|
||||||
if (Buffer == NULL)
|
* Retrieve the legacy partition layout
|
||||||
|
*/
|
||||||
|
LayoutBuffer = (PDRIVE_LAYOUT_INFORMATION)malloc(8192);
|
||||||
|
if (LayoutBuffer == NULL)
|
||||||
{
|
{
|
||||||
CloseHandle(hDisk);
|
|
||||||
printf("Out of memory!");
|
printf("Out of memory!");
|
||||||
|
CloseHandle(hDisk);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
memset(Buffer, 0, 8192);
|
memset(LayoutBuffer, 0, 8192);
|
||||||
|
|
||||||
if (!DeviceIoControl(hDisk,
|
if (!DeviceIoControl(hDisk,
|
||||||
IOCTL_DISK_GET_DRIVE_LAYOUT,
|
IOCTL_DISK_GET_DRIVE_LAYOUT,
|
||||||
NULL,
|
NULL,
|
||||||
0,
|
0,
|
||||||
Buffer,
|
LayoutBuffer,
|
||||||
8192,
|
8192,
|
||||||
&dwRead,
|
&dwRead,
|
||||||
NULL))
|
NULL))
|
||||||
{
|
{
|
||||||
CloseHandle(hDisk);
|
|
||||||
printf("DeviceIoControl(IOCTL_DISK_GET_DRIVE_LAYOUT) failed! Error: %lu\n",
|
printf("DeviceIoControl(IOCTL_DISK_GET_DRIVE_LAYOUT) failed! Error: %lu\n",
|
||||||
GetLastError());
|
GetLastError());
|
||||||
free(Buffer);
|
CloseHandle(hDisk);
|
||||||
|
free(LayoutBuffer);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
CloseHandle(hDisk);
|
CloseHandle(hDisk);
|
||||||
|
|
||||||
#ifdef DUMP_DATA
|
#ifdef DUMP_DATA
|
||||||
HexDump(Buffer, dwRead);
|
HexDump(LayoutBuffer, dwRead);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
LayoutBuffer = (DRIVE_LAYOUT_INFORMATION*)Buffer;
|
|
||||||
|
|
||||||
printf("Partitions %lu Signature %lx\n",
|
printf("Partitions %lu Signature %lx\n",
|
||||||
LayoutBuffer->PartitionCount,
|
LayoutBuffer->PartitionCount,
|
||||||
LayoutBuffer->Signature);
|
LayoutBuffer->Signature);
|
||||||
|
@ -205,7 +199,9 @@ int main (int argc, char *argv[])
|
||||||
LayoutBuffer->PartitionEntry[i].PartitionLength.QuadPart);
|
LayoutBuffer->PartitionEntry[i].PartitionLength.QuadPart);
|
||||||
}
|
}
|
||||||
|
|
||||||
free(Buffer);
|
free(LayoutBuffer);
|
||||||
|
|
||||||
|
// TODO: Retrieve the extended partition layout
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue