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