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

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

Misc changes.

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