source: branches/branch-1-0/src/helpers/_test_dosh.c

Last change on this file was 220, checked in by umoeller, 23 years ago

Misc changes.

  • Property svn:eol-style set to CRLF
  • Property svn:keywords set to Author Date Id Revision
File size: 8.4 KB
Line 
1
2#define OS2EMX_PLAIN_CHAR
3 // this is needed for "os2emx.h"; if this is defined,
4 // emx will define PSZ as _signed_ char, otherwise
5 // as unsigned char
6
7#define INCL_DOSMODULEMGR
8#define INCL_DOSPROCESS
9#define INCL_DOSEXCEPTIONS
10#define INCL_DOSSESMGR
11#define INCL_DOSQUEUES
12#define INCL_DOSSEMAPHORES
13#define INCL_DOSMISC
14#define INCL_DOSDEVICES
15#define INCL_DOSDEVIOCTL
16#define INCL_DOSERRORS
17
18#define INCL_KBD
19#include <os2.h>
20
21#include <stdlib.h>
22#include <string.h>
23#include <stdio.h>
24#include <stdarg.h>
25#include <ctype.h>
26
27#include "setup.h" // code generation and debugging options
28
29#include "helpers\dosh.h"
30#include "helpers\standards.h"
31
32#pragma hdrstop
33
34int main (int argc, char *argv[])
35{
36 APIRET arc;
37
38 BYTE cCDs,
39 bFirstCD;
40
41 ULONG ul;
42
43 printf("Drive checker ("__DATE__")\n");
44 printf(" type fs remot fixed parrm bootd media audio eas longn\n");
45
46 for (ul = 1;
47 ul <= 26;
48 ul++)
49 {
50 XDISKINFO xdi;
51 arc = doshGetDriveInfo(ul,
52 0, // DRVFL_TOUCHFLOPPIES,
53 &xdi);
54
55 printf(" %c: ", xdi.cDriveLetter, ul);
56
57 if (!xdi.fPresent)
58 printf("not present\n");
59 else
60 {
61 if (arc)
62 printf("error %d (IsFixedDisk: %d, QueryDiskParams %d, QueryMedia %d)\n",
63 arc,
64 xdi.arcIsFixedDisk,
65 xdi.arcQueryDiskParams,
66 xdi.arcQueryMedia);
67 else
68 {
69 ULONG aulFlags[] =
70 {
71 DFL_REMOTE,
72 DFL_FIXED,
73 DFL_PARTITIONABLEREMOVEABLE,
74 DFL_BOOTDRIVE,
75 0,
76 DFL_MEDIA_PRESENT,
77 DFL_AUDIO_CD,
78 DFL_SUPPORTS_EAS,
79 DFL_SUPPORTS_LONGNAMES
80 };
81 ULONG ul2;
82
83 PCSZ pcsz = NULL;
84
85 switch (xdi.bType)
86 {
87 case DRVTYPE_HARDDISK: pcsz = "HDISK "; break;
88 case DRVTYPE_FLOPPY: pcsz = "FLOPPY"; break;
89 case DRVTYPE_TAPE: pcsz = "TAPE "; break;
90 case DRVTYPE_VDISK: pcsz = "VDISK "; break;
91 case DRVTYPE_CDROM: pcsz = "CDROM "; break;
92 case DRVTYPE_LAN: pcsz = "LAN "; break;
93 case DRVTYPE_PRT:
94 pcsz = "PRTREM"; break;
95 default:
96 printf("bType=%d, BPB.bDevType=%d",
97 xdi.bType,
98 xdi.bpb.bDeviceType);
99 printf("\n ");
100 }
101
102 if (pcsz)
103 printf("%s ", pcsz);
104
105 if (xdi.lFileSystem < 0)
106 // negative means error
107 printf("E%3d ", xdi.lFileSystem); // , xdi.bFileSystem);
108 else
109 printf("%7s ", xdi.szFileSystem); // , xdi.bFileSystem);
110
111 for (ul2 = 0;
112 ul2 < ARRAYITEMCOUNT(aulFlags);
113 ul2++)
114 {
115 if (xdi.flDevice & aulFlags[ul2])
116 printf(" X ");
117 else
118 if ( (xdi.arcOpenLongnames)
119 && (aulFlags[ul2] == DFL_SUPPORTS_LONGNAMES)
120 )
121 printf(" E%03d ", xdi.arcOpenLongnames);
122 else
123 printf(" - ");
124 }
125 printf("\n");
126 }
127 }
128 }
129
130 if (!(arc = doshQueryCDDrives(&cCDs,
131 &bFirstCD)))
132 {
133 printf("First CD-ROM drive is %c:\n", bFirstCD);
134 printf("%d CD-ROM drive(s) present\n", cCDs);
135 }
136 else
137 printf("doshQueryCDDrives returned %d\n", arc);
138
139 {
140 #pragma pack(1)
141 struct
142 {
143 BYTE ci;
144 USHORT usDrive;
145 } parms;
146 #pragma pack()
147
148 USHORT fs = 123;
149
150 parms.ci = 0;
151 parms.usDrive = bFirstCD - 'A';
152
153 if (!(arc = doshDevIOCtl((HFILE)-1,
154 IOCTL_DISK,
155 DSK_GETLOCKSTATUS,
156 &parms, sizeof(parms),
157 &fs, sizeof(fs))))
158 {
159 printf("IOCTL_DISK DSK_GETLOCKSTATUS returned 0x%lX\n", fs);
160 switch (fs & 0x03)
161 {
162 case 0:
163 printf(" Lock/Unlock/Eject/Status functions not supported\n");
164 break;
165
166 case 1:
167 printf(" Drive locked; Lock/Unlock/Eject functions supported\n");
168 break;
169
170 case 2:
171 printf(" Drive unlocked; Lock/Unlock/Eject functions supported\n");
172 break;
173
174 case 3:
175 printf(" Lock Status not supported; Lock/Unlock/Eject functions supported\n");
176 break;
177 }
178
179 if (fs & 0x04)
180 printf(" Media in drive\n");
181 else
182 printf(" No media in drive\n");
183
184 }
185 else
186 printf("ioctl DSK_GETLOCKSTATUS returned %d\n", arc);
187 }
188
189 {
190 HFILE hf;
191 ULONG dummy;
192 CHAR szDrive[] = "C:";
193 szDrive[0] = bFirstCD;
194 if (arc = DosOpen(szDrive, // "C:", "D:", ...
195 &hf,
196 &dummy,
197 0,
198 FILE_NORMAL,
199 // OPEN_ACTION_FAIL_IF_NEW
200 OPEN_ACTION_OPEN_IF_EXISTS,
201 OPEN_FLAGS_DASD
202 | OPEN_FLAGS_FAIL_ON_ERROR
203 // ^^^ if this flag is not set, we get the white
204 // hard-error box
205 | OPEN_FLAGS_NOINHERIT // V0.9.6 (2000-11-25) [pr]
206 // | OPEN_ACCESS_READONLY // V0.9.13 (2001-06-14) [umoeller]
207 | OPEN_SHARE_DENYNONE,
208 NULL))
209 printf("DosOpen(\"%s\") returned %d\n",
210 szDrive,
211 arc);
212 else
213 {
214 ULONG fl;
215 if (!(arc = doshQueryCDStatus(hf, &fl)))
216 {
217 #define FLAG(f) f, # f
218 struct
219 {
220 ULONG fl;
221 PCSZ pcszFl;
222 } aFlags[] =
223 {
224 FLAG(CDFL_DOOROPEN),
225 FLAG(CDFL_DOORLOCKED),
226 FLAG(CDFL_COOKEDANDRAW),
227 FLAG(CDFL_READWRITE),
228 FLAG(CDFL_DATAANDAUDIO),
229 FLAG(CDFL_ISO9660INTERLEAVE ),
230 FLAG(CDFL_PREFETCHSUPPORT),
231 FLAG(CDFL_AUDIOCHANNELMANIP),
232 FLAG(CDFL_MINUTESECONDADDR),
233 FLAG(CDFL_MODE2SUPPORT),
234 FLAG(CDFL_DISKPRESENT),
235 FLAG(CDFL_PLAYINGAUDIO),
236 FLAG(CDFL_CDDA),
237 };
238 ULONG ul;
239
240 printf("IOCTL_CDROMDISK CDROMDISK_DEVICESTATUS returned 0x%lX\n", fl);
241
242 for (ul = 0;
243 ul < ARRAYITEMCOUNT(aFlags);
244 ++ul)
245 {
246 if (fl & aFlags[ul].fl)
247 printf(" + ");
248 else
249 printf(" - ");
250 printf("%s\n", aFlags[ul].pcszFl);
251 }
252 }
253 else
254 printf("IOCTL_CDROMDISK CDROMDISK_DEVICESTATUS returned error 0x%lX (%d)\n",
255 arc, arc);
256
257 DosClose(hf);
258 }
259 }
260}
Note: See TracBrowser for help on using the repository browser.