ReactOS  0.4.14-dev-815-ge410a12
partinfo.c File Reference
#include <windows.h>
#include <stdlib.h>
#include <ntndk.h>
#include <stdio.h>
Include dependency graph for partinfo.c:

Go to the source code of this file.

Macros

#define WIN32_NO_STATUS
 
#define DUMP_SIZE_INFO
 

Functions

void Usage (void)
 
int main (int argc, char *argv[])
 

Macro Definition Documentation

◆ DUMP_SIZE_INFO

#define DUMP_SIZE_INFO

Definition at line 12 of file partinfo.c.

◆ WIN32_NO_STATUS

#define WIN32_NO_STATUS

Definition at line 5 of file partinfo.c.

Function Documentation

◆ main()

int main ( int argc  ,
char argv[] 
)

hosttype.c Copyright (C) 2002 by Brian Palmer brian.nosp@m.p@sg.nosp@m.inet..nosp@m.com

Definition at line 64 of file partinfo.c.

65 {
66  HANDLE hDisk;
67  DWORD dwRead;
68  DWORD i;
69  char *Buffer;
70  DRIVE_LAYOUT_INFORMATION *LayoutBuffer;
71  DISK_GEOMETRY DiskGeometry;
72  ULONG ulDrive;
73  CHAR DriveName[40];
76 
77  if (argc != 2)
78  {
79  Usage();
80  return(0);
81  }
82 
83  ulDrive = strtoul(argv[1], NULL, 10);
84  if (errno != 0)
85  {
86  printf("Error: Malformed drive number\n");
87  return(0);
88  }
89 
90  /* Check drive number */
92  &DeviceInfo,
94  &i);
95  if (!NT_SUCCESS(Status))
96  {
97  printf("NtQuerySystemInformation() failed (Status %lx)\n", Status);
98  return(0);
99  }
100 
101  if (DeviceInfo.NumberOfDisks == 0)
102  {
103  printf("No disk drive installed!\n");
104  return(0);
105  }
106 
107  if (ulDrive >= DeviceInfo.NumberOfDisks)
108  {
109  printf("Invalid disk drive number! Valid drive numbers [0-%lu]\n",
110  DeviceInfo.NumberOfDisks-1);
111  return(0);
112  }
113 
114  /* Build full drive name */
115  sprintf(DriveName, "\\\\.\\PHYSICALDRIVE%lu", ulDrive);
116 
117  /* Open drive */
118  hDisk = CreateFileA(DriveName,
119  GENERIC_READ,
121  NULL,
123  0,
124  NULL);
125  if (hDisk == INVALID_HANDLE_VALUE)
126  {
127  printf("Invalid disk handle!");
128  return 0;
129  }
130 
131  /* Get drive geometry */
132  if (!DeviceIoControl(hDisk,
134  NULL,
135  0,
136  &DiskGeometry,
137  sizeof(DISK_GEOMETRY),
138  &dwRead,
139  NULL))
140  {
141  CloseHandle(hDisk);
142  printf("DeviceIoControl failed! Error: %lu\n",
143  GetLastError());
144  return 0;
145  }
146 
147 #ifdef DUMP_DATA
148  HexDump((char*)&DiskGeometry, dwRead);
149 #endif
150  printf("Drive number: %lu\n", ulDrive);
151  printf("Cylinders: %I64u\nMediaType: %x\nTracksPerCylinder: %lu\n"
152  "SectorsPerTrack: %lu\nBytesPerSector: %lu\n\n",
153  DiskGeometry.Cylinders.QuadPart,
154  DiskGeometry.MediaType,
155  DiskGeometry.TracksPerCylinder,
156  DiskGeometry.SectorsPerTrack,
157  DiskGeometry.BytesPerSector);
158 
159 
160  Buffer = (char*)malloc(8192);
161  if (Buffer == NULL)
162  {
163  CloseHandle(hDisk);
164  printf("Out of memory!");
165  return 0;
166  }
167  memset(Buffer, 0, 8192);
168 
169  if (!DeviceIoControl(hDisk,
171  NULL,
172  0,
173  Buffer,
174  8192,
175  &dwRead,
176  NULL))
177  {
178  CloseHandle(hDisk);
179  printf("DeviceIoControl(IOCTL_DISK_GET_DRIVE_LAYOUT) failed! Error: %lu\n",
180  GetLastError());
181  free(Buffer);
182  return 0;
183  }
184 
185  CloseHandle(hDisk);
186 
187 #ifdef DUMP_DATA
188  HexDump(Buffer, dwRead);
189 #endif
190 
191  LayoutBuffer = (DRIVE_LAYOUT_INFORMATION*)Buffer;
192 
193  printf("Partitions %lu Signature %lx\n",
194  LayoutBuffer->PartitionCount,
195  LayoutBuffer->Signature);
196 
197  for (i = 0; i < LayoutBuffer->PartitionCount; i++)
198  {
199  printf(" %ld: nr: %ld boot: %1x type: %x start: 0x%I64x count: 0x%I64x\n",
200  i,
201  LayoutBuffer->PartitionEntry[i].PartitionNumber,
202  LayoutBuffer->PartitionEntry[i].BootIndicator,
203  LayoutBuffer->PartitionEntry[i].PartitionType,
204  LayoutBuffer->PartitionEntry[i].StartingOffset.QuadPart,
205  LayoutBuffer->PartitionEntry[i].PartitionLength.QuadPart);
206  }
207 
208  free(Buffer);
209 
210  return 0;
211 }
static int argc
Definition: ServiceArgs.c:12
UINT32 strtoul(const char *String, char **Terminator, UINT32 Base)
Definition: utclib.c:696
NTSYSAPI NTSTATUS NTAPI NtQuerySystemInformation(IN SYSTEM_INFORMATION_CLASS SystemInfoClass, OUT PVOID SystemInfoBuffer, IN ULONG SystemInfoBufferSize, OUT PULONG BytesReturned OPTIONAL)
#define CloseHandle
Definition: compat.h:406
LARGE_INTEGER PartitionLength
Definition: ntdddisk.h:399
void Usage(void)
Definition: partinfo.c:58
char CHAR
Definition: xmlstorage.h:175
#define free
Definition: debug_ros.c:5
LONG NTSTATUS
Definition: precomp.h:26
#define INVALID_HANDLE_VALUE
Definition: compat.h:399
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
ULONG BytesPerSector
Definition: ntdddisk.h:381
ULONG TracksPerCylinder
Definition: ntdddisk.h:379
int errno
#define FILE_SHARE_WRITE
Definition: nt_native.h:681
#define argv
Definition: mplay32.c:18
#define FILE_SHARE_READ
Definition: compat.h:125
#define sprintf(buf, format,...)
Definition: sprintf.c:55
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
smooth NULL
Definition: ftsmooth.c:416
PARTITION_INFORMATION PartitionEntry[1]
Definition: ntdddisk.h:476
Definition: bufpool.h:45
#define OPEN_EXISTING
Definition: compat.h:434
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
LARGE_INTEGER StartingOffset
Definition: ntdddisk.h:398
LARGE_INTEGER Cylinders
Definition: ntdddisk.h:377
ULONG SectorsPerTrack
Definition: ntdddisk.h:380
void HexDump(PUCHAR buffer, ULONG size)
Definition: cmdcons.c:277
struct _DeviceInfo DeviceInfo
unsigned long DWORD
Definition: ntddk_ex.h:95
MEDIA_TYPE MediaType
Definition: ntdddisk.h:378
#define GENERIC_READ
Definition: compat.h:124
Status
Definition: gdiplustypes.h:24
#define IOCTL_DISK_GET_DRIVE_LAYOUT
Definition: ntdddisk.h:76
BOOL WINAPI DeviceIoControl(IN HANDLE hDevice, IN DWORD dwIoControlCode, IN LPVOID lpInBuffer OPTIONAL, IN DWORD nInBufferSize OPTIONAL, OUT LPVOID lpOutBuffer OPTIONAL, IN DWORD nOutBufferSize OPTIONAL, OUT LPDWORD lpBytesReturned OPTIONAL, IN LPOVERLAPPED lpOverlapped OPTIONAL)
Definition: deviceio.c:136
unsigned int ULONG
Definition: retypes.h:1
#define malloc
Definition: debug_ros.c:4
#define CreateFileA(a, b, c, d, e, f, g)
Definition: compat.h:407
IN BOOLEAN OUT PSTR Buffer
Definition: progress.h:34
#define memset(x, y, z)
Definition: compat.h:39
#define IOCTL_DISK_GET_DRIVE_GEOMETRY
Definition: cdrw_usr.h:169
LONGLONG QuadPart
Definition: typedefs.h:112
#define printf
Definition: config.h:203

◆ Usage()

void Usage ( void  )

Definition at line 58 of file partinfo.c.

59 {
60  puts("Usage: partinfo <drive number>");
61 }
int puts(const char *string)
Definition: crtsupp.c:23

Referenced by main().