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