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

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