ReactOS  0.4.15-dev-5112-g22d8c0f
dump.c
Go to the documentation of this file.
1 /*
2  * PROJECT: ReactOS DiskPart
3  * LICENSE: GPL - See COPYING in the top level directory
4  * FILE: base/system/diskpart/dump.c
5  * PURPOSE: Manages all the partitions of the OS in an interactive way.
6  * PROGRAMMERS: Eric Kohl
7  */
8 
9 #include "diskpart.h"
10 
11 #define NDEBUG
12 #include <debug.h>
13 
14 /* FUNCTIONS ******************************************************************/
15 
16 static
17 VOID
19  _In_ UCHAR *addr,
20  _In_ int len)
21 {
22  WCHAR Buffer[17];
23  UCHAR *pc;
24  int i;
25 
26  Buffer[16] = L'\0';
27 
28  pc = addr;
29  for (i = 0; i < len; i++)
30  {
31  if ((i % 16) == 0)
32  ConPrintf(StdOut, L" %04x ", i);
33 
34  ConPrintf(StdOut, L" %02x", pc[i]);
35 
36  if ((pc[i] < 0x20) || (pc[i] > 0x7e))
37  Buffer[i % 16] = L'.';
38  else
39  Buffer[i % 16] = (WCHAR)(USHORT)pc[i];
40 
41  if ((i % 16) == (16 - 1))
42  ConPrintf(StdOut, L" %s\n", Buffer);
43  }
44 }
45 
46 
47 BOOL
49  _In_ INT argc,
50  _In_ LPWSTR *argv)
51 {
58  PUCHAR pSectorBuffer = NULL;
60  LONGLONG Sector;
61  LPWSTR endptr = NULL;
62 
63 #if 0
64  if (argc == 2)
65  {
66  ConResPuts(StdOut, IDS_HELP_CMD_DUMP_DISK);
67  return TRUE;
68  }
69 #endif
70 
71  if (CurrentDisk == NULL)
72  {
74  return TRUE;
75  }
76 
77  Sector = _wcstoi64(argv[2], &endptr, 0);
78  if (((Sector == 0) && (endptr == argv[2])) ||
79  (Sector < 0))
80  {
82  return TRUE;
83  }
84 
85  pSectorBuffer = RtlAllocateHeap(RtlGetProcessHeap(), HEAP_ZERO_MEMORY, CurrentDisk->BytesPerSector);
86  if (pSectorBuffer == NULL)
87  {
88  DPRINT1("\n");
89  /* Error message */
90  goto done;
91  }
92 
94  L"\\Device\\Harddisk%d\\Partition0",
97  Buffer);
98 
100  &Name,
101  0,
102  NULL,
103  NULL);
104 
108  &Iosb,
111  if (!NT_SUCCESS(Status))
112  {
113  DPRINT1("\n");
114  goto done;
115  }
116 
117  FileOffset.QuadPart = Sector * CurrentDisk->BytesPerSector;
119  NULL,
120  NULL,
121  NULL,
122  &Iosb,
123  (PVOID)pSectorBuffer,
125  &FileOffset,
126  NULL);
127  if (!NT_SUCCESS(Status))
128  {
129  DPRINT1("NtReadFile failed, status=%x\n", Status);
130  goto done;
131  }
132 
133  HexDump(pSectorBuffer, CurrentDisk->BytesPerSector);
134 
135 done:
136  if (FileHandle)
138 
139  RtlFreeHeap(RtlGetProcessHeap(), 0, pSectorBuffer);
140 
141  return TRUE;
142 }
143 
144 
145 BOOL
147  _In_ INT argc,
148  _In_ LPWSTR *argv)
149 {
156  PUCHAR pSectorBuffer = NULL;
158  LONGLONG Sector;
159  LPWSTR endptr = NULL;
160 
161 
162 #if 0
163  if (argc == 2)
164  {
165  ConResPuts(StdOut, IDS_HELP_CMD_DUMP_DISK);
166  return TRUE;
167  }
168 #endif
169 
170  if (CurrentDisk == NULL)
171  {
173  return TRUE;
174  }
175 
176  if (CurrentPartition == NULL)
177  {
179  return TRUE;
180  }
181 
182  Sector = _wcstoi64(argv[2], &endptr, 0);
183  if (((Sector == 0) && (endptr == argv[2])) ||
184  (Sector < 0))
185  {
187  return TRUE;
188  }
189 
190  pSectorBuffer = RtlAllocateHeap(RtlGetProcessHeap(), HEAP_ZERO_MEMORY, CurrentDisk->BytesPerSector);
191  if (pSectorBuffer == NULL)
192  {
193  DPRINT1("\n");
194  /* Error message */
195  goto done;
196  }
197 
199  L"\\Device\\Harddisk%d\\Partition%d",
203  Buffer);
204 
206  &Name,
207  0,
208  NULL,
209  NULL);
210 
214  &Iosb,
217  if (!NT_SUCCESS(Status))
218  {
219  DPRINT1("\n");
220  goto done;
221  }
222 
223  FileOffset.QuadPart = Sector * CurrentDisk->BytesPerSector;
225  NULL,
226  NULL,
227  NULL,
228  &Iosb,
229  (PVOID)pSectorBuffer,
231  &FileOffset,
232  NULL);
233  if (!NT_SUCCESS(Status))
234  {
235  DPRINT1("NtReadFile failed, status=%x\n", Status);
236  goto done;
237  }
238 
239  HexDump(pSectorBuffer, CurrentDisk->BytesPerSector);
240 
241 done:
242  if (FileHandle)
244 
245  RtlFreeHeap(RtlGetProcessHeap(), 0, pSectorBuffer);
246 
247  return TRUE;
248 }
#define IDS_SELECT_NO_PARTITION
Definition: resource.h:88
IN PUNICODE_STRING IN POBJECT_ATTRIBUTES ObjectAttributes
Definition: conport.c:35
static int argc
Definition: ServiceArgs.c:12
ULONG PartitionNumber
Definition: partlist.h:55
#define TRUE
Definition: types.h:120
unsigned char * PUCHAR
Definition: retypes.h:3
LONG NTSTATUS
Definition: precomp.h:26
BOOLEAN NTAPI RtlFreeHeap(IN PVOID HeapHandle, IN ULONG Flags, IN PVOID HeapBase)
Definition: heap.c:606
ULONG DiskNumber
Definition: partlist.h:111
static PPARTENTRY CurrentPartition
Definition: usetup.c:76
PDISKENTRY CurrentDisk
Definition: partlist.c:74
#define argv
Definition: mplay32.c:18
int32_t INT
Definition: typedefs.h:58
#define FILE_SHARE_READ
Definition: compat.h:136
#define IDS_ERROR_INVALID_ARGS
Definition: resource.h:187
#define L(x)
Definition: ntvdm.h:50
unsigned int BOOL
Definition: ntddk_ex.h:94
__MINGW_EXTENSION _Check_return_ _CRTIMP __int64 __cdecl _wcstoi64(_In_z_ const wchar_t *_Str, _Out_opt_ _Deref_post_z_ wchar_t **_EndPtr, _In_ int _Radix)
#define FILE_READ_DATA
Definition: nt_native.h:628
struct NameRec_ * Name
Definition: cdprocs.h:459
static VOID HexDump(_In_ UCHAR *addr, _In_ int len)
Definition: dump.c:18
#define _In_
Definition: ms_sal.h:308
Definition: bufpool.h:45
void ConResPuts(FILE *fp, UINT nID)
Definition: fc.c:27
BOOL DumpPartition(_In_ INT argc, _In_ LPWSTR *argv)
Definition: dump.c:146
PVOID NTAPI RtlAllocateHeap(IN PVOID HeapHandle, IN ULONG Flags, IN SIZE_T Size)
Definition: heap.c:588
Status
Definition: gdiplustypes.h:24
int64_t LONGLONG
Definition: typedefs.h:68
NTSYSAPI NTSTATUS NTAPI NtOpenFile(OUT PHANDLE phFile, IN ACCESS_MASK DesiredAccess, IN POBJECT_ATTRIBUTES ObjectAttributes, OUT PIO_STATUS_BLOCK pIoStatusBlock, IN ULONG ShareMode, IN ULONG OpenMode)
Definition: file.c:3951
ULONG BytesPerSector
Definition: partlist.h:95
__wchar_t WCHAR
Definition: xmlstorage.h:180
return Iosb
Definition: create.c:4402
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define MAX_PATH
Definition: compat.h:34
#define IDS_SELECT_NO_DISK
Definition: resource.h:85
NTSTATUS NTAPI NtClose(IN HANDLE Handle)
Definition: obhandle.c:3402
#define FILE_READ_ATTRIBUTES
Definition: nt_native.h:647
unsigned char UCHAR
Definition: xmlstorage.h:181
GLenum const GLvoid * addr
Definition: glext.h:9621
GLenum GLsizei len
Definition: glext.h:6722
#define SYNCHRONIZE
Definition: nt_native.h:61
int _cdecl swprintf(const WCHAR *,...)
void ConPrintf(FILE *fp, LPCWSTR psz,...)
Definition: fc.c:20
_Must_inspect_result_ _In_opt_ PFLT_INSTANCE _Out_ PHANDLE FileHandle
Definition: fltkernel.h:1230
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
unsigned short USHORT
Definition: pedump.c:61
_In_ PFCB _In_ LONGLONG FileOffset
Definition: cdprocs.h:159
#define NULL
Definition: types.h:112
#define HEAP_ZERO_MEMORY
Definition: compat.h:134
#define DPRINT1
Definition: precomp.h:8
#define FILE_SYNCHRONOUS_IO_NONALERT
Definition: from_kernel.h:31
#define StdOut
Definition: fc.c:14
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
#define InitializeObjectAttributes(p, n, a, r, s)
Definition: reg.c:106
WCHAR * LPWSTR
Definition: xmlstorage.h:184
BOOL DumpDisk(_In_ INT argc, _In_ LPWSTR *argv)
Definition: dump.c:48
NTSTATUS NTAPI NtReadFile(HANDLE FileHandle, HANDLE Event, PIO_APC_ROUTINE ApcRoutine, PVOID ApcContext, PIO_STATUS_BLOCK IoStatusBlock, PVOID Buffer, ULONG Length, PLARGE_INTEGER ByteOffset, PULONG Key)
#define StdErr
Definition: fc.c:15