f8fb13ee6b615f6b104493bdbcd40cdaa23a7341
[reactos.git] / reactos / apps / tests / isotest / isotest.c
1 /*
2 * isotest - display cdrom information
3 */
4
5 #include <ddk/ntddk.h>
6 #include <windows.h>
7 #include <winioctl.h>
8 #include <stdio.h>
9 #include <stdlib.h>
10
11
12 void HexDump(char *buffer, ULONG size)
13 {
14 ULONG offset = 0;
15 unsigned char *ptr;
16
17 while (offset < (size & ~15))
18 {
19 ptr = (unsigned char*)((ULONG)buffer + offset);
20 printf("%08lx %02hx %02hx %02hx %02hx %02hx %02hx %02hx %02hx-%02hx %02hx %02hx %02hx %02hx %02hx %02hx %02hx",
21 offset,
22 ptr[0],
23 ptr[1],
24 ptr[2],
25 ptr[3],
26 ptr[4],
27 ptr[5],
28 ptr[6],
29 ptr[7],
30 ptr[8],
31 ptr[9],
32 ptr[10],
33 ptr[11],
34 ptr[12],
35 ptr[13],
36 ptr[14],
37 ptr[15]);
38
39 printf(" %c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c\n",
40 isprint(ptr[0])?ptr[0]:'.',
41 isprint(ptr[1])?ptr[1]:'.',
42 isprint(ptr[2])?ptr[2]:'.',
43 isprint(ptr[3])?ptr[3]:'.',
44 isprint(ptr[4])?ptr[4]:'.',
45 isprint(ptr[5])?ptr[5]:'.',
46 isprint(ptr[6])?ptr[6]:'.',
47 isprint(ptr[7])?ptr[7]:'.',
48 isprint(ptr[8])?ptr[8]:'.',
49 isprint(ptr[9])?ptr[9]:'.',
50 isprint(ptr[10])?ptr[10]:'.',
51 isprint(ptr[11])?ptr[11]:'.',
52 isprint(ptr[12])?ptr[12]:'.',
53 isprint(ptr[13])?ptr[13]:'.',
54 isprint(ptr[14])?ptr[14]:'.',
55 isprint(ptr[15])?ptr[15]:'.');
56
57 offset += 16;
58 }
59
60 ptr = (unsigned char*)((ULONG)buffer + offset);
61 if (offset < size)
62 {
63 printf("%08lx ", offset);
64 while (offset < size)
65 {
66 printf(" %02hx", *ptr);
67 offset++;
68 ptr++;
69 }
70 }
71
72 printf("\n\n");
73 }
74
75
76 #ifndef EVENT_ALL_ACCESS
77 #define EVENT_ALL_ACCESS (0x1f0003L)
78 #endif
79
80 BOOL
81 ReadBlock(HANDLE FileHandle,
82 PVOID Buffer,
83 PLARGE_INTEGER Offset,
84 ULONG Length,
85 PULONG BytesRead)
86 {
87 IO_STATUS_BLOCK IoStatusBlock;
88 OBJECT_ATTRIBUTES ObjectAttributes;
89 NTSTATUS Status;
90 HANDLE EventHandle;
91
92 InitializeObjectAttributes(&ObjectAttributes,
93 NULL, 0, NULL, NULL);
94
95 Status = NtCreateEvent(&EventHandle,
96 EVENT_ALL_ACCESS,
97 &ObjectAttributes,
98 TRUE,
99 FALSE);
100 if (!NT_SUCCESS(Status))
101 {
102 printf("NtCreateEvent() failed\n");
103 return(FALSE);
104 }
105
106 Status = NtReadFile(FileHandle,
107 EventHandle,
108 NULL,
109 NULL,
110 &IoStatusBlock,
111 Buffer,
112 Length,
113 Offset,
114 NULL);
115 if (Status == STATUS_PENDING)
116 {
117 NtWaitForSingleObject(EventHandle, FALSE, NULL);
118 Status = IoStatusBlock.Status;
119 }
120
121 NtClose(EventHandle);
122
123 if (Status != STATUS_PENDING && BytesRead != NULL)
124 {
125 *BytesRead = IoStatusBlock.Information;
126 }
127 if (!NT_SUCCESS(Status) && Status != STATUS_END_OF_FILE)
128 {
129 printf("ReadBlock() failed (Status: %lx)\n", Status);
130 return(FALSE);
131 }
132
133 return(TRUE);
134 }
135
136
137
138 int main (int argc, char *argv[])
139 {
140 HANDLE hDisk;
141 DWORD dwRead;
142 DWORD i;
143 char *Buffer;
144 CHAR Filename[80];
145 LARGE_INTEGER FilePosition;
146
147 if (argc != 2)
148 {
149 printf("Usage: isotest [Drive:]\n");
150 return 0;
151 }
152
153 strcpy(Filename, "\\\\.\\");
154 strcat(Filename, argv[1]);
155
156 hDisk = CreateFile(Filename,
157 GENERIC_READ,
158 FILE_SHARE_READ | FILE_SHARE_WRITE,
159 NULL,
160 OPEN_EXISTING,
161 0,
162 NULL);
163 if (hDisk == INVALID_HANDLE_VALUE)
164 {
165 printf("CreateFile(): Invalid disk handle!\n");
166 return 0;
167 }
168
169 Buffer = (char*)malloc(2048);
170 if (Buffer == NULL)
171 {
172 CloseHandle(hDisk);
173 printf("Out of memory!\n");
174 return 0;
175 }
176 memset(Buffer, 0, 2048);
177
178
179 FilePosition.QuadPart = 16 * 2048;
180 #if 0
181 SetLastError(NO_ERROR);
182 SetFilePointer(hDisk,
183 FilePosition.u.LowPart,
184 &FilePosition.u.HighPart,
185 FILE_BEGIN);
186 if (GetLastError() != NO_ERROR)
187 {
188 CloseHandle(hDisk);
189 free(Buffer);
190 printf("SetFilePointer() failed!\n");
191 return 0;
192 }
193
194 if (ReadFile(hDisk,
195 Buffer,
196 2048,
197 &dwRead,
198 NULL) == FALSE)
199 {
200 CloseHandle(hDisk);
201 free(Buffer);
202 printf("ReadFile() failed!\n");
203 return 0;
204 }
205 #endif
206
207 if (ReadBlock(hDisk,
208 Buffer,
209 &FilePosition,
210 2048,
211 &dwRead) == FALSE)
212 {
213 CloseHandle(hDisk);
214 free(Buffer);
215 #if 0
216 printf("ReadBlock() failed!\n");
217 #endif
218 return 0;
219 }
220
221 HexDump(Buffer, 128);
222
223 CloseHandle(hDisk);
224
225 free(Buffer);
226
227 return 0;
228 }
229
230 /* EOF */