source: trunk/include/helpers/dosh.h@ 59

Last change on this file since 59 was 59, checked in by umoeller, 24 years ago

Various fixes for V0.9.10.

  • Property svn:eol-style set to CRLF
  • Property svn:keywords set to Author Date Id Revision
File size: 38.9 KB
Line 
1
2/*
3 *@@sourcefile dosh.h:
4 * header file for dosh.c. See remarks there.
5 *
6 * Note: Version numbering in this file relates to XWorkplace version
7 * numbering.
8 *
9 *@@include #define INCL_DOSPROCESS
10 *@@include #define INCL_DOSDEVIOCTL // for doshQueryDiskParams only
11 *@@include #include <os2.h>
12 *@@include #include "dosh.h"
13 */
14
15/* This file Copyright (C) 1997-2001 Ulrich M”ller,
16 * Dmitry A. Steklenev.
17 * This file is part of the "XWorkplace helpers" source package.
18 * This is free software; you can redistribute it and/or modify
19 * it under the terms of the GNU General Public License as published
20 * by the Free Software Foundation, in version 2 as it comes in the
21 * "COPYING" file of the XWorkplace main distribution.
22 * This program is distributed in the hope that it will be useful,
23 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 * GNU General Public License for more details.
26 */
27
28#if __cplusplus
29extern "C" {
30#endif
31
32#ifndef DOSH_HEADER_INCLUDED
33 #define DOSH_HEADER_INCLUDED
34
35 /* ******************************************************************
36 *
37 * Miscellaneous
38 *
39 ********************************************************************/
40
41 CHAR doshGetChar(VOID);
42
43 BOOL doshQueryShiftState(VOID);
44
45 ULONG doshIsWarp4(VOID);
46
47 PSZ doshQuerySysErrorMsg(APIRET arc);
48
49 /* ******************************************************************
50 *
51 * Memory helpers
52 *
53 ********************************************************************/
54
55 PVOID doshAllocSharedMem(ULONG ulSize,
56 const char* pcszName);
57
58 PVOID doshRequestSharedMem(const char *pcszName);
59
60 /* ******************************************************************
61 *
62 * Drive helpers
63 *
64 ********************************************************************/
65
66 VOID doshEnumDrives(PSZ pszBuffer,
67 const char *pcszFileSystem,
68 BOOL fSkipRemoveables);
69
70 CHAR doshQueryBootDrive(VOID);
71
72 APIRET doshAssertDrive(ULONG ulLogicalDrive);
73
74 APIRET doshSetLogicalMap(ULONG ulLogicalDrive);
75
76 APIRET doshQueryDiskFree(ULONG ulLogicalDrive,
77 double *pdFree);
78
79 APIRET doshQueryDiskFSType(ULONG ulLogicalDrive,
80 PSZ pszBuf,
81 ULONG cbBuf);
82
83 APIRET doshIsFixedDisk(ULONG ulLogicalDrive,
84 PBOOL pfFixed);
85
86 #ifdef INCL_DOSDEVIOCTL
87
88 // flags for DRIVEPARMS.usDeviceAttrs (see DSK_GETDEVICEPARAMS in CPREF):
89 #define DEVATTR_REMOVEABLE 0x0001 // drive is removeable
90 #define DEVATTR_CHANGELINE 0x0002 // media has been removed since last I/O operation
91 #define DEVATTR_GREATER16MB 0x0004 // physical device driver supports physical addresses > 16 MB
92
93 #pragma pack(1)
94
95 /*
96 *@@ DRIVEPARAMS:
97 * structure used for doshQueryDiskParams.
98 */
99
100 typedef struct _DRIVEPARAMS
101 {
102 BIOSPARAMETERBLOCK bpb;
103 // BIOS parameter block. This is the first sector
104 // (at byte 0) in each partition. This is defined
105 // in the OS2 headers as follows:
106
107 /*
108 typedef struct _BIOSPARAMETERBLOCK {
109 USHORT usBytesPerSector;
110 // Number of bytes per sector.
111 BYTE bSectorsPerCluster;
112 // Number of sectors per cluster.
113 USHORT usReservedSectors;
114 // Number of reserved sectors.
115 BYTE cFATs;
116 // Number of FATs.
117 USHORT cRootEntries;
118 // Number of root directory entries.
119 USHORT cSectors;
120 // Number of sectors.
121 BYTE bMedia;
122 // Media descriptor.
123 USHORT usSectorsPerFAT;
124 // Number of secctors per FAT.
125 USHORT usSectorsPerTrack;
126 // Number of sectors per track.
127 USHORT cHeads;
128 // Number of heads.
129 ULONG cHiddenSectors;
130 // Number of hidden sectors.
131 ULONG cLargeSectors;
132 // Number of large sectors.
133 BYTE abReserved[6];
134 // Reserved.
135 USHORT cCylinders;
136 // Number of cylinders defined for the physical
137 // device.
138 BYTE bDeviceType;
139 // Physical layout of the specified device.
140 USHORT fsDeviceAttr;
141 // A bit field that returns flag information
142 // about the specified drive.
143 } BIOSPARAMETERBLOCK; */
144
145 USHORT usCylinders;
146 // no. of cylinders
147 UCHAR ucDeviceType;
148 // device type; according to the IBM Control
149 // Program Reference (see DSK_GETDEVICEPARAMS),
150 // this value can be:
151 // -- 0: 48 TPI low-density diskette drive
152 // -- 1: 96 TPI high-density diskette drive
153 // -- 2: 3.5-inch 720KB diskette drive
154 // -- 3: 8-Inch single-density diskette drive
155 // -- 4: 8-Inch double-density diskette drive
156 // -- 5: Fixed disk
157 // -- 6: Tape drive
158 // -- 7: Other (includes 1.44MB 3.5-inch diskette drive)
159 // -- 8: R/W optical disk
160 // -- 9: 3.5-inch 4.0MB diskette drive (2.88MB formatted)
161 USHORT usDeviceAttrs;
162 // DEVATTR_* flags
163 } DRIVEPARAMS, *PDRIVEPARAMS;
164 #pragma pack()
165
166 APIRET doshQueryDiskParams(ULONG ulLogicalDrive,
167 PDRIVEPARAMS pdp);
168 #endif
169
170 APIRET doshQueryDiskLabel(ULONG ulLogicalDrive,
171 PSZ pszVolumeLabel);
172
173 APIRET doshSetDiskLabel(ULONG ulLogicalDrive,
174 PSZ pszNewLabel);
175
176 /* ******************************************************************
177 *
178 * Module handling helpers
179 *
180 ********************************************************************/
181
182 /*
183 *@@ RESOLVEFUNCTION:
184 * one of these structures each define
185 * a single function import to doshResolveImports.
186 *
187 *@@added V0.9.3 (2000-04-25) [umoeller]
188 */
189
190 typedef struct _RESOLVEFUNCTION
191 {
192 const char *pcszFunctionName;
193 PFN *ppFuncAddress;
194 } RESOLVEFUNCTION, *PRESOLVEFUNCTION;
195
196 APIRET doshResolveImports(PSZ pszModuleName,
197 HMODULE *phmod,
198 PRESOLVEFUNCTION paResolves,
199 ULONG cResolves);
200
201 /* ******************************************************************
202 *
203 * Performance Counters (CPU Load)
204 *
205 ********************************************************************/
206
207 #define CMD_PERF_INFO 0x41
208 #define CMD_KI_ENABLE 0x60
209 #define CMD_KI_DISABLE 0x61
210 #ifndef CMD_KI_RDCNT
211 #define CMD_KI_RDCNT 0x63
212 typedef APIRET APIENTRY FNDOSPERFSYSCALL(ULONG ulCommand,
213 ULONG ulParm1,
214 ULONG ulParm2,
215 ULONG ulParm3);
216 typedef FNDOSPERFSYSCALL *PFNDOSPERFSYSCALL;
217 #endif
218
219 typedef struct _CPUUTIL
220 {
221 ULONG ulTimeLow; // low 32 bits of time stamp
222 ULONG ulTimeHigh; // high 32 bits of time stamp
223 ULONG ulIdleLow; // low 32 bits of idle time
224 ULONG ulIdleHigh; // high 32 bits of idle time
225 ULONG ulBusyLow; // low 32 bits of busy time
226 ULONG ulBusyHigh; // high 32 bits of busy time
227 ULONG ulIntrLow; // low 32 bits of interrupt time
228 ULONG ulIntrHigh; // high 32 bits of interrupt time
229 } CPUUTIL, *PCPUUTIL;
230
231 // macro to convert 8-byte (low, high) time value to double
232 #define LL2F(high, low) (4294967296.0*(high)+(low))
233
234 /*
235 *@@ DOSHPERFSYS:
236 * structure used with doshPerfOpen.
237 *
238 *@@added V0.9.7 (2000-12-02) [umoeller]
239 *@@changed V0.9.9 (2001-03-14) [umoeller]: added interrupt load
240 */
241
242 typedef struct _DOSHPERFSYS
243 {
244 // output: no. of processors on the system
245 ULONG cProcessors;
246 // output: one CPU load for each CPU
247 PLONG palLoads;
248
249 // output: one CPU interrupt load for each CPU
250 PLONG palIntrs;
251
252 // each of the following ptrs points to an array of cProcessors items
253 PCPUUTIL paCPUUtils; // CPUUTIL structures
254 double *padBusyPrev; // previous "busy" calculations
255 double *padTimePrev; // previous "time" calculations
256 double *padIntrPrev; // previous "intr" calculations
257
258 // private stuff
259 HMODULE hmod;
260 BOOL fInitialized;
261 PFNDOSPERFSYSCALL pDosPerfSysCall;
262 } DOSHPERFSYS, *PDOSHPERFSYS;
263
264 APIRET doshPerfOpen(PDOSHPERFSYS *ppPerfSys);
265
266 APIRET doshPerfGet(PDOSHPERFSYS pPerfSys);
267
268 APIRET doshPerfClose(PDOSHPERFSYS *ppPerfSys);
269
270 /* ******************************************************************
271 *
272 * File helpers
273 *
274 ********************************************************************/
275
276 PSZ doshGetExtension(const char *pcszFilename);
277
278 BOOL doshIsFileOnFAT(const char* pcszFileName);
279
280 APIRET doshIsValidFileName(const char* pcszFile,
281 BOOL fFullyQualified);
282
283 BOOL doshMakeRealName(PSZ pszTarget, PSZ pszSource, CHAR cReplace, BOOL fIsFAT);
284
285 ULONG doshQueryFileSize(HFILE hFile);
286
287 ULONG doshQueryPathSize(PSZ pszFile);
288
289 APIRET doshQueryPathAttr(const char* pcszFile,
290 PULONG pulAttr);
291
292 APIRET doshSetPathAttr(const char* pcszFile,
293 ULONG ulAttr);
294
295 APIRET doshLoadTextFile(const char *pcszFile,
296 PSZ* ppszContent);
297
298 PSZ doshCreateBackupFileName(const char* pszExisting);
299
300 APIRET doshCreateTempFileName(PSZ pszTempFileName,
301 const char *pcszDir,
302 const char *pcszPrefix,
303 const char *pcszExt);
304
305 APIRET doshWriteTextFile(const char* pszFile,
306 const char* pszContent,
307 PULONG pulWritten,
308 PSZ pszBackup);
309
310 HFILE doshOpenLogFile(const char* pcszFilename);
311
312 APIRET doshWriteToLogFile(HFILE hfLog, const char* pcsz);
313
314 /* ******************************************************************
315 *
316 * Directory helpers
317 *
318 ********************************************************************/
319
320 BOOL doshQueryDirExist(const char *pcszDir);
321
322 APIRET doshCreatePath(const char *pcszPath,
323 BOOL fHidden);
324
325 APIRET doshQueryCurrentDir(PSZ pszBuf);
326
327 APIRET doshSetCurrentDir(const char *pcszDir);
328
329 #define DOSHDELDIR_RECURSE 0x0001
330 #define DOSHDELDIR_DELETEFILES 0x0002
331
332 APIRET doshDeleteDir(const char *pcszDir,
333 ULONG flFlags,
334 PULONG pulDirs,
335 PULONG pulFiles);
336
337 /* ******************************************************************
338 *
339 * Process helpers
340 *
341 ********************************************************************/
342
343 ULONG XWPENTRY doshMyPID(VOID);
344 typedef ULONG XWPENTRY DOSHMYPID(VOID);
345 typedef DOSHMYPID *PDOSHMYPID;
346
347 ULONG XWPENTRY doshMyTID(VOID);
348 typedef ULONG XWPENTRY DOSHMYTID(VOID);
349 typedef DOSHMYTID *PDOSHMYTID;
350
351 APIRET doshFindExecutable(const char *pcszCommand,
352 PSZ pszExecutable,
353 ULONG cbExecutable,
354 const char **papcszExtensions,
355 ULONG cExtensions);
356
357 APIRET doshExecVIO(const char *pcszExecWithArgs,
358 PLONG plExitCode);
359
360 APIRET doshQuickStartSession(const char *pcszPath,
361 const char *pcszParams,
362 BOOL fForeground,
363 USHORT usPgmCtl,
364 BOOL fWait,
365 PULONG pulSID,
366 PPID ppid);
367
368 /* ******************************************************************
369 *
370 * Environment helpers
371 *
372 ********************************************************************/
373
374 /*
375 *@@ DOSENVIRONMENT:
376 * structure holding an array of environment
377 * variables (papszVars). This is initialized
378 * doshGetEnvironment,
379 *
380 *@@added V0.9.4 (2000-07-19) [umoeller]
381 */
382
383 typedef struct _DOSENVIRONMENT
384 {
385 ULONG cVars; // count of vars in papzVars
386 PSZ *papszVars; // array of PSZ's to environment strings (VAR=VALUE)
387 } DOSENVIRONMENT, *PDOSENVIRONMENT;
388
389 APIRET doshParseEnvironment(const char *pcszEnv,
390 PDOSENVIRONMENT pEnv);
391
392 APIRET doshGetEnvironment(PDOSENVIRONMENT pEnv);
393
394 PSZ* doshFindEnvironmentVar(PDOSENVIRONMENT pEnv,
395 PSZ pszVarName);
396
397 APIRET doshSetEnvironmentVar(PDOSENVIRONMENT pEnv,
398 PSZ pszNewEnv,
399 BOOL fAddFirst);
400
401 APIRET doshConvertEnvironment(PDOSENVIRONMENT pEnv,
402 PSZ *ppszEnv,
403 PULONG pulSize);
404
405 APIRET doshFreeEnvironment(PDOSENVIRONMENT pEnv);
406
407 /********************************************************************
408 *
409 * Executable helpers
410 *
411 ********************************************************************/
412
413 /*
414 *@@ DOSEXEHEADER:
415 * old DOS EXE header at offset 0
416 * in any EXE file.
417 *
418 *@@changed V0.9.7 (2000-12-20) [umoeller]: fixed NE offset
419 *@@changed V0.9.9 (2001-04-06) [lafaix]: additional fields defined
420 */
421
422 #pragma pack(1)
423 typedef struct _DOSEXEHEADER
424 {
425 USHORT usDosExeID; // 00: DOS exeid (0x5a4d)
426 USHORT usFileLenMod512; // 02: filelen mod 512
427 USHORT usFileLenDiv512; // 04: filelen div 512
428 USHORT usSegFix; // 06: count of segment adds to fix
429 USHORT usHdrPargCnt; // 08: size of header in paragrphs
430 USHORT usMinAddPargCnt; // 0a: minimum addtl paragraphs count
431 USHORT usMaxAddPargCnt; // 0c: max addtl paragraphs count
432 USHORT usSSStartup; // 0e: SS at startup
433 USHORT usSPStartup; // 10: SP at startup
434 USHORT usHdrChecksum; // 12: header checksum
435 USHORT usIPStartup; // 14: IP at startup
436 USHORT usCodeSegOfs; // 16: code segment offset from EXE start
437 USHORT usRelocTableOfs; // 18: reloc table ofs.header (Win: >= 0x40)
438 USHORT usOverlayNo; // 1a: overlay no.
439 USHORT usLinkerVersion; // 1c: linker version (if 0x18 > 0x28)
440 USHORT usUnused1; // 1e: unused
441 USHORT usBehaviorBits; // 20: exe.h says this field contains
442 // 'behavior bits'
443 USHORT usUnused2; // 22: unused
444 USHORT usOEMIdentifier; // 24: OEM identifier
445 USHORT usOEMInformation; // 26: OEM information
446 ULONG ulUnused3; // 28:
447 ULONG ulUnused4; // 2c:
448 ULONG ulUnused5; // 30:
449 ULONG ulUnused6; // 34:
450 ULONG ulUnused7; // 38:
451 ULONG ulNewHeaderOfs; // 3c: new header ofs (if 0x18 > 0x40)
452 // fixed this from USHORT, thanks Martin Lafaix
453 // V0.9.7 (2000-12-20) [umoeller]
454 } DOSEXEHEADER, *PDOSEXEHEADER;
455
456 // NE and LX OS types
457 #define NEOS_UNKNOWN 0
458 #define NEOS_OS2 1 // Win16 SDK says: "reserved"...
459 #define NEOS_WIN16 2
460 #define NEOS_DOS4 3 // Win16 SDK says: "reserved"...
461 #define NEOS_WIN386 4 // Win16 SDK says: "reserved"...
462
463 /*
464 *@@ NEHEADER:
465 * linear executable (LX) header format,
466 * which comes after the DOS header in the
467 * EXE file (at DOSEXEHEADER.ulNewHeaderOfs).
468 *
469 *@@changed V0.9.9 (2001-04-06) [lafaix]: fixed typo in usMoveableEntries
470 */
471
472 typedef struct _NEHEADER
473 {
474 CHAR achNE[2]; // 00: NE
475 BYTE bLinkerVersion; // 02: linker version
476 BYTE bLinkerRevision; // 03: linker revision
477 USHORT usEntryTblOfs; // 04: ofs from this to entrytable
478 USHORT usEntryTblLen; // 06: length of entrytable
479 ULONG ulChecksum; // 08: MS: reserved, OS/2: checksum
480 USHORT usFlags; // 0c: flags
481 USHORT usAutoDataSegNo; // 0e: auto-data seg no.
482 USHORT usInitlHeapSize; // 10: initl. heap size
483 USHORT usInitlStackSize; // 12: initl. stack size
484 ULONG ulCSIP; // 14: CS:IP
485 ULONG ulSSSP; // 18: SS:SP
486 USHORT usSegTblEntries; // 1c: segment tbl entry count
487 USHORT usModuleTblEntries; // 1e: module ref. table entry count
488 USHORT usNonResdTblLen; // 20: non-resd. name tbl length
489 USHORT usSegTblOfs; // 22: segment tbl ofs
490 USHORT usResTblOfs; // 24: resource tbl ofs
491 USHORT usResdNameTblOfs; // 26: resd. name tbl ofs
492 USHORT usModRefTblOfs; // 28: module ref. table ofs
493 USHORT usImportTblOfs; // 2a: import tbl ofs
494 ULONG ulNonResdTblOfs; // 2c: non-resd. name tbl ofs
495 USHORT usMoveableEntries; // 30: moveable entry pts. count
496 USHORT usLogicalSectShift; // 32: logcl. sector shift
497 USHORT usResSegmCount; // 34: resource segm. count
498 BYTE bTargetOS; // 36: target OS (NEOS_* flags)
499 BYTE bFlags2; // 37: addtl. flags
500 USHORT usFastLoadOfs; // 38: fast-load area ofs
501 USHORT usFastLoadLen; // 3a: fast-load area length
502 USHORT usReserved; // 3c: MS: 'reserved'
503 USHORT usReqWinVersion; // 3e: Win-only: min. Win version
504 } NEHEADER, *PNEHEADER;
505
506 /*
507 *@@ LXHEADER:
508 * linear executable (LX) header format,
509 * which comes after the DOS header in the
510 * EXE file (at DOSEXEHEADER.ulNewHeaderOfs).
511 *
512 *@@changed V0.9.9 (2001-04-06) [lafaix]: fixed auto data object and ulinstanceDemdCnt
513 */
514
515 typedef struct _LXHEADER
516 {
517 CHAR achLX[2]; // 00: LX or LE
518 /* this is "LX" for 32-bit OS/2 programs, but
519 "LE" for MS-DOS progs which use this format
520 (e.g. WINDOWS\SMARTDRV.EXE) */
521 BYTE fByteBigEndian; // 02: byte ordering (1 = big endian)
522 BYTE fWordBigEndian; // 03: word ordering (1 = big endian)
523 ULONG ulFormatLevel; // 04: format level
524 USHORT usCPU; // 08: CPU type
525 USHORT usTargetOS; // 0a: OS type (NEOS_* flags)
526 ULONG ulModuleVersion; // 0c: module version
527 ULONG ulFlags; // 10: module flags
528 ULONG ulPageCount; // 14: no. of pages in module
529 ULONG ulEIPRelObj; // 18: object to which EIP is relative
530 ULONG ulEIPEntryAddr; // 1c: EIP entry addr
531 ULONG ulESPObj; // 20: ESP object
532 ULONG ulESP; // 24: ESP
533 ULONG ulPageSize; // 28: page size (4K)
534 ULONG ulPageLeftShift; // 2c: page left-shift
535 ULONG ulFixupTblLen; // 30: fixup section total size
536 ULONG ulFixupTblChecksum; // 34: fixup section checksum
537 ULONG ulLoaderLen; // 38: size req. for loader section
538 ULONG ulLoaderChecksum; // 3c: loader section checksum
539 ULONG ulObjTblOfs; // 40: object table offset
540 ULONG ulObjCount; // 44: object count
541 ULONG ulObjPageTblOfs; // 48: object page table ofs
542 ULONG ulObjIterPagesOfs; // 4c: object iter pages ofs
543 ULONG ulResTblOfs; // 50: resource table ofs
544 ULONG ulResTblCnt; // 54: resource entry count
545 ULONG ulResdNameTblOfs; // 58: resident name tbl ofs
546 ULONG ulEntryTblOfs; // 5c: entry tbl ofs
547 ULONG ulModDirectivesOfs; // 60: module directives ofs
548 ULONG ulModDirectivesCnt; // 64: module directives count
549 ULONG ulFixupPagePageTblOfs;// 68: fixup page tbl ofs
550 ULONG ulFixupRecTblOfs; // 6c: fixup record tbl ofs
551 ULONG ulImportModTblOfs; // 70: import modl tbl ofs
552 ULONG ulImportModTblCnt; // 74: import modl tbl count
553 ULONG ulImportProcTblOfs; // 78: import proc tbl ofs
554 ULONG ulPerPageCSOfs; // 7c: per page checksum ofs
555 ULONG ulDataPagesOfs; // 80: data pages ofs
556 ULONG ulPreloadPagesCnt; // 84: preload pages count
557 ULONG ulNonResdNameTblOfs; // 88: non-resdnt name tbl ofs
558 ULONG ulNonResdNameTblLen; // 8c: non-resdnt name tbl length
559 ULONG ulNonResdNameTblCS; // 90: non-res name tbl checksum
560 ULONG ulAutoDataSegObj; // 94: auto dataseg object
561 ULONG ulDebugOfs; // 98: debug info ofs
562 ULONG ulDebugLen; // 9c: debug info length
563 ULONG ulInstancePrelCnt; // a0: instance preload count
564 ULONG ulInstanceDemdCnt; // a0: instance demand count
565 ULONG ulHeapSize16; // a8: heap size (16-bit)
566 ULONG ulStackSize; // ac: stack size
567 } LXHEADER, *PLXHEADER;
568
569 /*
570 *@@ PEHEADER:
571 * portable executable (PE) header format,
572 * which comes after the DOS header in the
573 * EXE file (at DOSEXEHEADER.ulNewHeaderOfs).
574 *
575 *@@added V0.9.10 (2001-04-08) [lafaix]
576 */
577
578 typedef struct _PEHEADER
579 {
580 // standard header
581 ULONG ulSignature; // 00: 'P', 'E', 0, 0
582 USHORT usCPU; // 04: CPU type
583 USHORT usObjCount; // 06: number of object entries
584 ULONG ulTimeDateStamp; // 08: store the time and date the
585 // file was created or modified
586 // by the linker
587 ULONG ulReserved1; // 0c: reserved
588 ULONG ulReserved2; // 10: reserved
589 USHORT usHeaderSize; // 14: number of remaining bytes after
590 // usImageFlags
591 USHORT usImageFlags; // 16: flags bits for the image
592
593 // optional header (always present in valid Win32 files)
594 USHORT usReserved3; // 18: reserved
595 USHORT usLinkerMajor; // 1a: linker major version number
596 USHORT usLinkerMinor; // 1c: linker minor version number
597 USHORT usReserved4; // 1e: reserved
598 ULONG ulReserved5; // 20: reserved
599 ULONG ulReserved6; // 24: reserved
600 ULONG ulEntryPointRVA; // 28: entry point relative virtual address
601 ULONG ulReserved7; // 2c: reserved
602 ULONG ulReserved8; // 30: reserved
603 ULONG ulImageBase; // 34:
604 ULONG ulObjectAlign; // 38:
605 ULONG ulFileAlign; // 3c:
606 USHORT usOSMajor; // 40:
607 USHORT usOSMinor; // 42:
608 USHORT usUserMajor; // 44:
609 USHORT usUserMinor; // 46:
610 USHORT usSubSystemMajor; // 48:
611 USHORT usSubSystemMinor; // 4a:
612 ULONG ulReserved9; // 4c: reserved
613 ULONG ulImageSize; // 50:
614 ULONG ulHeaderSize; // 54:
615 ULONG ulFileChecksum; // 58:
616 USHORT usSubSystem; // 5c:
617 USHORT usDLLFlags; // 5e:
618 ULONG ulStackReserveSize; // 60:
619 ULONG ulStackCommitSize; // 64:
620 ULONG ulHeapReserveSize; // 68:
621 ULONG ulHeapCommitSize; // 6c:
622 ULONG ulReserved10; // 70: reserved
623 ULONG ulInterestingRVACount;// 74:
624 ULONG aulRVASize[1]; // 78: array of RVA/Size entries
625 } PEHEADER, *PPEHEADER;
626
627 #pragma pack()
628
629 /*
630 *@@ FSYSMODULE:
631 *
632 *@@added V0.9.9 (2001-03-11) [lafaix]
633 */
634
635 typedef struct _FSYSMODULE
636 {
637 CHAR achModuleName[256];
638 } FSYSMODULE, *PFSYSMODULE;
639
640 /*
641 *@@ FSYSFUNCTION:
642 *
643 *@@added V0.9.9 (2001-03-11) [lafaix]
644 */
645
646 typedef struct _FSYSFUNCTION
647 {
648 ULONG ulOrdinal;
649 ULONG ulType;
650 CHAR achFunctionName[256];
651 } FSYSFUNCTION, *PFSYSFUNCTION;
652
653 /*
654 *@@ FSYSRESOURCE:
655 *
656 *@@added V0.9.7 (2000-12-18) [lafaix]
657 */
658
659 typedef struct _FSYSRESOURCE
660 {
661 ULONG ulID; // resource ID
662 ULONG ulType; // resource type
663 ULONG ulSize; // resource size in bytes
664 ULONG ulFlag; // resource flags
665 } FSYSRESOURCE, *PFSYSRESOURCE;
666
667 // object/segment flags (in NE and LX)
668 #define OBJWRITE 0x0002L // Writeable Object
669 #define OBJDISCARD 0x0010L // Object is Discardable
670 #define OBJSHARED 0x0020L // Object is Shared
671 #define OBJPRELOAD 0x0040L // Object has preload pages
672
673 // resource flags
674 #define RNMOVE 0x0010 // Moveable resource
675 #define RNPURE 0x0020 // Pure (read-only) resource
676 #define RNPRELOAD 0x0040 // Preloaded resource
677 #define RNDISCARD 0xF000 // Discard priority level for resource
678
679 // EXE format
680 #define EXEFORMAT_OLDDOS 1
681 #define EXEFORMAT_NE 2
682 #define EXEFORMAT_PE 3
683 #define EXEFORMAT_LX 4
684 #define EXEFORMAT_TEXT_BATCH 5
685 #define EXEFORMAT_TEXT_REXX 6
686
687 // target OS (in NE and LX)
688 #define EXEOS_DOS3 1
689 #define EXEOS_DOS4 2 // there is a flag for this in NE
690 #define EXEOS_OS2 3
691 #define EXEOS_WIN16 4
692 #define EXEOS_WIN386 5 // according to IBM, there are flags
693 // for this both in NE and LX
694 #define EXEOS_WIN32 6
695
696 /*
697 *@@ EXECUTABLE:
698 * structure used with all the doshExec*
699 * functions.
700 */
701
702 typedef struct _EXECUTABLE
703 {
704 HFILE hfExe;
705
706 /* All the following fields are set by
707 doshExecOpen if NO_ERROR is returned. */
708
709 // old DOS EXE header (always valid)
710 PDOSEXEHEADER pDosExeHeader;
711 ULONG cbDosExeHeader;
712
713 // New Executable (NE) header, if ulExeFormat == EXEFORMAT_NE
714 PNEHEADER pNEHeader;
715 ULONG cbNEHeader;
716
717 // Linear Executable (LX) header, if ulExeFormat == EXEFORMAT_LX
718 PLXHEADER pLXHeader;
719 ULONG cbLXHeader;
720
721 // Portable Executable (PE) header, if ulExeFormat == EXEFORMAT_PE
722 PPEHEADER pPEHeader;
723 ULONG cbPEHeader;
724
725 // module analysis (always set):
726 ULONG ulExeFormat;
727 // one of:
728 // EXEFORMAT_OLDDOS 1
729 // EXEFORMAT_NE 2
730 // EXEFORMAT_PE 3
731 // EXEFORMAT_LX 4
732 // EXEFORMAT_TEXT_BATCH 5
733 // EXEFORMAT_TEXT_REXX 6
734
735 BOOL fLibrary,
736 f32Bits;
737 ULONG ulOS;
738 // one of:
739 // EXEOS_DOS3 1
740 // EXEOS_DOS4 2 // there is a flag for this in NE
741 // EXEOS_OS2 3
742 // EXEOS_WIN16 4
743 // EXEOS_WIN386 5 // according to IBM, there are flags
744 // // for this both in NE and LX
745 // EXEOS_WIN32 6
746
747 /* The following fields are only set after
748 an extra call to doshExecQueryBldLevel. */
749
750 PSZ pszDescription; // whole string (first non-res name tbl entry)
751 PSZ pszVendor; // vendor substring (if IBM BLDLEVEL format)
752 PSZ pszVersion; // version substring (if IBM BLDLEVEL format)
753 PSZ pszInfo; // module info substring (if IBM BLDLEVEL format)
754
755 } EXECUTABLE, *PEXECUTABLE;
756
757 APIRET doshExecOpen(const char* pcszExecutable,
758 PEXECUTABLE* ppExec);
759
760 APIRET doshExecClose(PEXECUTABLE pExec);
761
762 APIRET doshExecQueryBldLevel(PEXECUTABLE pExec);
763
764 APIRET doshExecQueryImportedModules(PEXECUTABLE pExec,
765 PFSYSMODULE *ppaModules,
766 PULONG pcModules);
767
768 APIRET doshExecFreeImportedModules(PFSYSMODULE paModules);
769
770 APIRET doshExecQueryExportedFunctions(PEXECUTABLE pExec,
771 PFSYSFUNCTION *ppaFunctions,
772 PULONG pcFunctions);
773
774 APIRET doshExecFreeExportedFunctions(PFSYSFUNCTION paFunctions);
775
776 APIRET doshExecQueryResources(PEXECUTABLE pExec,
777 PFSYSRESOURCE *ppaResources,
778 PULONG pcResources);
779
780 APIRET doshExecFreeResources(PFSYSRESOURCE paResources);
781
782 /********************************************************************
783 *
784 * Partition functions
785 *
786 ********************************************************************/
787
788 /*
789 *@@ LVMINFO:
790 * informational structure created by
791 * doshQueryLVMInfo.
792 *
793 *@@added V0.9.9 (2001-04-07) [umoeller]
794 */
795
796 typedef struct _LVMINFO
797 {
798 HMODULE hmodLVM;
799
800 } LVMINFO, *PLVMINFO;
801
802 #define DOSH_PARTITIONS_LIMIT 10
803
804 #define PAR_UNUSED 0x00 // Unused
805 #define PAR_FAT12SMALL 0x01 // DOS FAT 12-bit < 10 Mb
806 #define PAR_XENIXROOT 0x02 // XENIX root
807 #define PAR_XENIXUSER 0x03 // XENIX user
808 #define PAR_FAT16SMALL 0x04 // DOS FAT 16-bit < 32 Mb
809 #define PAR_EXTENDED 0x05 // Extended partition
810 #define PAR_FAT16BIG 0x06 // DOS FAT 16-bit > 32 Mb
811 #define PAR_HPFS 0x07 // OS/2 HPFS
812 #define PAR_AIXBOOT 0x08 // AIX bootable partition
813 #define PAR_AIXDATA 0x09 // AIX bootable partition
814 #define PAR_BOOTMANAGER 0x0A // OS/2 Boot Manager
815 #define PAR_WINDOWS95 0x0B // Windows 95 32-bit FAT
816 #define PAR_WINDOWS95LB 0x0C // Windows 95 32-bit FAT with LBA
817 #define PAR_VFAT16BIG 0x0E // LBA VFAT (same as 06h but using LBA-mode)
818 #define PAR_VFAT16EXT 0x0F // LBA VFAT (same as 05h but using LBA-mode)
819 #define PAR_OPUS 0x10 // OPUS
820 #define PAR_HID12SMALL 0x11 // OS/2 hidden DOS FAT 12-bit
821 #define PAR_COMPAQDIAG 0x12 // Compaq diagnostic
822 #define PAR_HID16SMALL 0x14 // OS/2 hidden DOS FAT 16-bit
823 #define PAR_HID16BIG 0x16 // OS/2 hidden DOS FAT 16-bit
824 #define PAR_HIDHPFS 0x17 // OS/2 hidden HPFS
825 #define PAR_WINDOWSSWP 0x18 // AST Windows Swap File
826 #define PAR_NECDOS 0x24 // NEC MS-DOS 3.x
827 #define PAR_THEOS 0x38 // THEOS
828 #define PAR_VENIX 0x40 // VENIX
829 #define PAR_RISCBOOT 0x41 // Personal RISC boot
830 #define PAR_SFS 0x42 // SFS
831 #define PAR_ONTRACK 0x50 // Ontrack
832 #define PAR_ONTRACKEXT 0x51 // Ontrack extended partition
833 #define PAR_CPM 0x52 // CP/M
834 #define PAR_UNIXSYSV 0x63 // UNIX SysV/386
835 #define PAR_NOVELL_64 0x64 // Novell
836 #define PAR_NOVELL_65 0x65 // Novell
837 #define PAR_NOVELL_67 0x67 // Novell
838 #define PAR_NOVELL_68 0x68 // Novell
839 #define PAR_NOVELL_69 0x69 // Novell
840 #define PAR_PCIX 0x75 // PCIX
841 #define PAR_MINIX 0x80 // MINIX
842 #define PAR_LINUX 0x81 // Linux
843 #define PAR_LINUXSWAP 0x82 // Linux Swap Partition
844 #define PAR_LINUXFILE 0x83 // Linux File System
845 #define PAR_FREEBSD 0xA5 // FreeBSD
846 #define PAR_BBT 0xFF // BBT
847
848 // one-byte alignment
849 #pragma pack(1)
850
851 /*
852 *@@ PAR_INFO:
853 * partition table
854 */
855
856 typedef struct _PAR_INFO
857 {
858 BYTE bBootFlag; // 0=not active, 80H = active (boot this partition
859 BYTE bBeginHead; // partition begins at this head...
860 USHORT rBeginSecCyl; // ...and this sector and cylinder (see below)
861 BYTE bFileSysCode; // file system type
862 BYTE bEndHead; // partition ends at this head...
863 USHORT bEndSecCyl; // ...and this sector and cylinder (see below)
864 ULONG lBeginAbsSec; // partition begins at this absolute sector #
865 ULONG lTotalSects; // total sectors in this partition
866 } PAR_INFO, *PPAR_INFO;
867
868 /*
869 *@@ MBR_INFO:
870 * master boot record table.
871 * This has the four primary partitions.
872 */
873
874 typedef struct _MBR_INFO // MBR
875 {
876 BYTE aBootCode[0x1BE]; // abBootCode master boot executable code
877 PAR_INFO sPrtnInfo[4]; // primary partition entries
878 USHORT wPrtnTblSig; // partition table signature (aa55H)
879 } MBR_INFO, *PMBR_INFO;
880
881 /*
882 *@@ SYS_INFO:
883 *
884 */
885
886 typedef struct _SYS_INFO
887 {
888 BYTE startable;
889 BYTE unknown[3];
890 BYTE bootable;
891 BYTE name[8];
892 BYTE reservd[3];
893 } SYS_INFO, *PSYS_INFO;
894
895 /*
896 *@@ SYE_INFO:
897 *
898 */
899
900 typedef struct _SYE_INFO
901 {
902 BYTE bootable;
903 BYTE name[8];
904 } SYE_INFO, *PSYE_INFO;
905
906 /*
907 *@@ EXT_INFO:
908 *
909 */
910
911 typedef struct _EXT_INFO
912 {
913 BYTE aBootCode[0x18A]; // abBootCode master boot executable code
914 SYE_INFO sBmNames[4]; // System Names
915 BYTE bReserved[16]; // reserved
916 PAR_INFO sPrtnInfo[4]; // partitioms entrys
917 USHORT wPrtnTblSig; // partition table signature (aa55H)
918 } EXT_INFO, *PEXT_INFO;
919
920 typedef struct _PARTITIONINFO *PPARTITIONINFO;
921
922 /*
923 *@@ PARTITIONINFO:
924 * informational structure returned
925 * by doshGetPartitionsList. One of
926 * these items is created for each
927 * bootable partition.
928 */
929
930 typedef struct _PARTITIONINFO
931 {
932 BYTE bDisk; // drive number
933 CHAR cLetter; // probable drive letter or ' ' if none
934 BYTE bFSType; // file system type
935 CHAR szFSType[10]; // file system name (created by us)
936 BOOL fPrimary; // primary partition?
937 BOOL fBootable; // bootable by Boot Manager?
938 CHAR szBootName[9]; // Boot Manager name, if (fBootable)
939 ULONG ulSize; // size MBytes
940 PPARTITIONINFO pNext; // next info or NULL if last
941 } PARTITIONINFO;
942
943 UINT doshQueryDiskCount(VOID);
944
945 APIRET doshReadSector(USHORT disk,
946 void *buff,
947 USHORT head,
948 USHORT cylinder,
949 USHORT sector);
950
951 // restore original alignment
952 #pragma pack()
953
954 const char* doshType2FSName(unsigned char bFSType);
955
956 APIRET doshGetBootManager(USHORT *pusDisk,
957 USHORT *pusPart,
958 PAR_INFO *BmInfo);
959
960 typedef struct _PARTITIONSLIST
961 {
962 PLVMINFO pLVMInfo; // != NULL if LVM is installed
963
964 // partitions array
965 PPARTITIONINFO pPartitionInfo;
966 USHORT cPartitions;
967 } PARTITIONSLIST, *PPARTITIONSLIST;
968
969 APIRET doshGetPartitionsList(PPARTITIONSLIST *ppList,
970 PUSHORT pusContext);
971
972 APIRET doshFreePartitionsList(PPARTITIONSLIST ppList);
973
974 APIRET doshQueryLVMInfo(PLVMINFO *ppLVMInfo);
975
976 APIRET doshReadLVMPartitions(PLVMINFO pInfo,
977 PPARTITIONINFO *ppPartitionInfo,
978 PUSHORT pcPartitions);
979
980 VOID doshFreeLVMInfo(PLVMINFO pInfo);
981
982#endif
983
984#if __cplusplus
985}
986#endif
987
Note: See TracBrowser for help on using the repository browser.