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

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

Lots of changes for icons and refresh.

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