[7] | 1 |
|
---|
| 2 | /*
|
---|
| 3 | *@@sourcefile wphandle.h:
|
---|
| 4 | * header file for wphandle.c, which contains the logic for
|
---|
| 5 | * dealing with those annoying WPS object handles in OS2SYS.INI.
|
---|
| 6 | *
|
---|
| 7 | * This code is mostly written by Henk Kelder and published
|
---|
| 8 | * with his kind permission.
|
---|
| 9 | *
|
---|
| 10 | * Note: Version numbering in this file relates to XWorkplace version
|
---|
| 11 | * numbering.
|
---|
| 12 | *
|
---|
| 13 | *@@include #define INCL_WINSHELLDATA
|
---|
| 14 | *@@include #define INCL_WINWORKPLACE
|
---|
| 15 | *@@include #include <os2.h>
|
---|
[113] | 16 | *@@include #include "helpers\wphandle.h"
|
---|
[7] | 17 | */
|
---|
| 18 |
|
---|
[113] | 19 | /* This file Copyright (C) 1997-2001 Ulrich Mller.
|
---|
[14] | 20 | * This file is part of the "XWorkplace helpers" source package.
|
---|
| 21 | * This is free software; you can redistribute it and/or modify
|
---|
[7] | 22 | * it under the terms of the GNU General Public License as published by
|
---|
| 23 | * the Free Software Foundation, in version 2 as it comes in the COPYING
|
---|
| 24 | * file of the XWorkplace main distribution.
|
---|
| 25 | * This program is distributed in the hope that it will be useful,
|
---|
| 26 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 27 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
| 28 | * GNU General Public License for more details.
|
---|
| 29 | */
|
---|
| 30 |
|
---|
| 31 | #if __cplusplus
|
---|
| 32 | extern "C" {
|
---|
| 33 | #endif
|
---|
| 34 |
|
---|
| 35 | #ifndef WPHANDLE_HEADER_INCLUDED
|
---|
| 36 | #define WPHANDLE_HEADER_INCLUDED
|
---|
| 37 |
|
---|
[106] | 38 | /* ******************************************************************
|
---|
| 39 | *
|
---|
| 40 | * Errors
|
---|
| 41 | *
|
---|
| 42 | ********************************************************************/
|
---|
[7] | 43 |
|
---|
[106] | 44 | #define ERROR_WPH_FIRST 41000
|
---|
[153] | 45 |
|
---|
[180] | 46 | // #define ERROR_WPH_CRASHED (ERROR_WPH_FIRST + 0)
|
---|
| 47 | // now using ERROR_PROTECTION_VIOLATION instead
|
---|
| 48 | // V0.9.19 (2002-07-01) [umoeller]
|
---|
[106] | 49 | #define ERROR_WPH_NO_BASECLASS_DATA (ERROR_WPH_FIRST + 1)
|
---|
| 50 | #define ERROR_WPH_NO_ACTIVEHANDLES_DATA (ERROR_WPH_FIRST + 2)
|
---|
| 51 | #define ERROR_WPH_INCOMPLETE_BASECLASS_DATA (ERROR_WPH_FIRST + 3)
|
---|
| 52 | #define ERROR_WPH_NO_HANDLES_DATA (ERROR_WPH_FIRST + 4)
|
---|
| 53 | #define ERROR_WPH_CORRUPT_HANDLES_DATA (ERROR_WPH_FIRST + 5)
|
---|
[180] | 54 | // cannot determine format (invalid keywords)
|
---|
[106] | 55 | #define ERROR_WPH_INVALID_PARENT_HANDLE (ERROR_WPH_FIRST + 6)
|
---|
[113] | 56 | #define ERROR_WPH_CANNOT_FIND_HANDLE (ERROR_WPH_FIRST + 7)
|
---|
| 57 | #define ERROR_WPH_DRIV_TREEINSERT_FAILED (ERROR_WPH_FIRST + 8)
|
---|
| 58 | #define ERROR_WPH_NODE_TREEINSERT_FAILED (ERROR_WPH_FIRST + 9)
|
---|
| 59 | #define ERROR_WPH_NODE_BEFORE_DRIV (ERROR_WPH_FIRST + 10)
|
---|
| 60 | #define ERROR_WPH_NO_MATCHING_DRIVE_BLOCK (ERROR_WPH_FIRST + 11)
|
---|
| 61 | #define ERROR_WPH_NO_MATCHING_ROOT_DIR (ERROR_WPH_FIRST + 12)
|
---|
[127] | 62 | #define ERROR_WPH_NOT_FILESYSTEM_HANDLE (ERROR_WPH_FIRST + 13)
|
---|
[180] | 63 | #define ERROR_WPH_PRFQUERYPROFILESIZE_BLOCK (ERROR_WPH_FIRST + 14)
|
---|
| 64 | // PrfQueryProfileSize failed on BLOCK (fatal)
|
---|
| 65 | // V0.9.19 (2002-07-01) [umoeller]
|
---|
| 66 | #define ERROR_WPH_PRFQUERYPROFILEDATA_BLOCK (ERROR_WPH_FIRST + 15)
|
---|
| 67 | // PrfQueryProfileData failed on BLOCK (fatal)
|
---|
| 68 | // V0.9.19 (2002-07-01) [umoeller]
|
---|
[7] | 69 |
|
---|
[180] | 70 | #define ERROR_WPH_LAST (ERROR_WPH_FIRST + 15)
|
---|
[153] | 71 |
|
---|
[106] | 72 | /* ******************************************************************
|
---|
[7] | 73 | *
|
---|
[106] | 74 | * Definitions
|
---|
| 75 | *
|
---|
| 76 | ********************************************************************/
|
---|
[7] | 77 |
|
---|
[106] | 78 | #pragma pack(1)
|
---|
[7] | 79 |
|
---|
| 80 | /*
|
---|
[106] | 81 | *@@ NODE:
|
---|
| 82 | * file or directory node in the BLOCKS
|
---|
| 83 | * in OS2SYS.INI. See wphandle.c.
|
---|
[7] | 84 | *
|
---|
[106] | 85 | *@@added V0.9.16 (2001-10-02) [umoeller]
|
---|
[7] | 86 | */
|
---|
| 87 |
|
---|
[106] | 88 | typedef struct _NODE
|
---|
| 89 | {
|
---|
| 90 | CHAR achName[4]; // = 'NODE'
|
---|
| 91 | USHORT usUsage; // always == 1
|
---|
| 92 | USHORT usHandle; // object handle of this NODE
|
---|
| 93 | USHORT usParentHandle; // object handle of parent NODE
|
---|
| 94 | BYTE achFiller[20]; // filler
|
---|
| 95 | USHORT usNameSize; // size of non-qualified filename
|
---|
| 96 | CHAR szName[1]; // variable length: non-qualified filename
|
---|
| 97 | // (zero-terminated)
|
---|
| 98 | } NODE, *PNODE;
|
---|
[7] | 99 |
|
---|
| 100 | /*
|
---|
[106] | 101 | *@@ DRIVE:
|
---|
| 102 | * drive node in the BLOCKS
|
---|
| 103 | * in OS2SYS.INI. See wphandle.c.
|
---|
[7] | 104 | *
|
---|
[106] | 105 | *@@added V0.9.16 (2001-10-02) [umoeller]
|
---|
[7] | 106 | */
|
---|
| 107 |
|
---|
[106] | 108 | typedef struct _DRIVE
|
---|
| 109 | {
|
---|
| 110 | CHAR achName[4]; // = 'DRIV'
|
---|
| 111 | USHORT usUnknown1[4];
|
---|
| 112 | ULONG ulSerialNr;
|
---|
| 113 | USHORT usUnknown2[2];
|
---|
| 114 | CHAR szName[1];
|
---|
[113] | 115 | } DRIVE, *PDRIVE;
|
---|
[7] | 116 |
|
---|
[106] | 117 | #pragma pack()
|
---|
[7] | 118 |
|
---|
[113] | 119 | /* ******************************************************************
|
---|
[106] | 120 | *
|
---|
[113] | 121 | * Private declarations
|
---|
| 122 | *
|
---|
| 123 | ********************************************************************/
|
---|
[7] | 124 |
|
---|
[113] | 125 | #ifdef INCLUDE_WPHANDLE_PRIVATE
|
---|
[7] | 126 |
|
---|
[113] | 127 | /*
|
---|
| 128 | *@@ DRIVETREENODE:
|
---|
| 129 | *
|
---|
| 130 | *@@added V0.9.16 (2001-10-19) [umoeller]
|
---|
| 131 | */
|
---|
[7] | 132 |
|
---|
[113] | 133 | typedef struct _DRIVETREENODE
|
---|
| 134 | {
|
---|
| 135 | TREE Tree; // ulKey points to the DRIVE.szName
|
---|
| 136 | // (null terminated)
|
---|
| 137 | PDRIVE pDriv; // actual DRIVE node
|
---|
[7] | 138 |
|
---|
[113] | 139 | TREE *ChildrenTree; // NODETREENODE's, if any
|
---|
| 140 | LONG cChildren;
|
---|
[7] | 141 |
|
---|
[113] | 142 | } DRIVETREENODE, *PDRIVETREENODE;
|
---|
| 143 |
|
---|
| 144 | /*
|
---|
| 145 | *@@ NODETREENODE:
|
---|
| 146 | *
|
---|
| 147 | *@@added V0.9.16 (2001-10-19) [umoeller]
|
---|
| 148 | */
|
---|
| 149 |
|
---|
| 150 | typedef struct _NODETREENODE
|
---|
| 151 | {
|
---|
| 152 | TREE Tree; // ulKey points to the NODE.szName
|
---|
| 153 | // (null terminated)
|
---|
| 154 | PNODE pNode; // actual NODE node
|
---|
| 155 |
|
---|
| 156 | TREE *ChildrenTree; // NODETREENODE's, if any
|
---|
| 157 | LONG cChildren;
|
---|
| 158 |
|
---|
| 159 | } NODETREENODE, *PNODETREENODE;
|
---|
| 160 |
|
---|
| 161 | /*
|
---|
| 162 | *@@ WPHANDLESBUF:
|
---|
| 163 | * structure created by wphLoadHandles.
|
---|
| 164 | *
|
---|
| 165 | * The composed BLOCKs in the handles buffer make up a tree of
|
---|
| 166 | * DRIVE and NODE structures (see wphandle.h). Each NODE stands
|
---|
| 167 | * for either a directory or a file. (We don't care about the
|
---|
| 168 | * DRIVE structures because the root directory gets a NODE also.)
|
---|
| 169 | * Each NODE contains the non-qualified file name, an fshandle,
|
---|
| 170 | * and the fshandle of its parent NODE.
|
---|
| 171 | *
|
---|
| 172 | *@@added V0.9.16 (2001-10-02) [umoeller]
|
---|
| 173 | */
|
---|
| 174 |
|
---|
| 175 | typedef struct _WPHANDLESBUF
|
---|
| 176 | {
|
---|
| 177 | PBYTE pbData; // ptr to all handles (buffers from OS2SYS.INI)
|
---|
| 178 | ULONG cbData; // byte count of *p
|
---|
| 179 |
|
---|
| 180 | USHORT usHiwordAbstract, // hiword for WPAbstract handles
|
---|
| 181 | usHiwordFileSystem; // hiword for WPFileSystem handles
|
---|
| 182 |
|
---|
| 183 | BOOL fCacheValid; // TRUE after wphRebuildNodeHashTable()
|
---|
| 184 | PNODETREENODE NodeHashTable[65536]; // hash table with all nodes sorted by handle;
|
---|
| 185 | // if item is NULL, no handle is assigned
|
---|
| 186 | TREE *DrivesTree; // DRIVETREENODE structs really
|
---|
| 187 | LONG cDrives;
|
---|
| 188 |
|
---|
| 189 | LINKLIST llDuplicateHandles; // linked list of NODETREENODE's that
|
---|
| 190 | // have an fshandle that was already
|
---|
| 191 | // occupied (i.e. same fshandle for two
|
---|
| 192 | // NODEs)
|
---|
| 193 | LINKLIST llDuplicateShortNames;
|
---|
| 194 |
|
---|
| 195 | } HANDLESBUF, *PHANDLESBUF;
|
---|
| 196 |
|
---|
| 197 | #endif
|
---|
| 198 |
|
---|
[106] | 199 | /* ******************************************************************
|
---|
[7] | 200 | *
|
---|
[106] | 201 | * Load handles functions
|
---|
| 202 | *
|
---|
| 203 | ********************************************************************/
|
---|
[7] | 204 |
|
---|
[113] | 205 | typedef unsigned long HHANDLES;
|
---|
| 206 |
|
---|
[106] | 207 | APIRET wphQueryActiveHandles(HINI hiniSystem,
|
---|
| 208 | PSZ *ppszActiveHandles);
|
---|
[7] | 209 |
|
---|
[106] | 210 | APIRET wphQueryBaseClassesHiwords(HINI hiniUser,
|
---|
| 211 | PUSHORT pusHiwordAbstract,
|
---|
| 212 | PUSHORT pusHiwordFileSystem);
|
---|
[7] | 213 |
|
---|
[140] | 214 | APIRET wphRebuildNodeHashTable(HHANDLES hHandles,
|
---|
| 215 | BOOL fQuitOnErrors);
|
---|
[7] | 216 |
|
---|
[106] | 217 | APIRET wphLoadHandles(HINI hiniUser,
|
---|
| 218 | HINI hiniSystem,
|
---|
| 219 | const char *pcszActiveHandles,
|
---|
[113] | 220 | HHANDLES *phHandles);
|
---|
[7] | 221 |
|
---|
[113] | 222 | APIRET wphFreeHandles(HHANDLES *phHandles);
|
---|
[7] | 223 |
|
---|
[106] | 224 | APIRET wphQueryHandleFromPath(HINI hiniUser,
|
---|
| 225 | HINI hiniSystem,
|
---|
| 226 | const char *pcszName,
|
---|
| 227 | HOBJECT *phobj);
|
---|
[7] | 228 |
|
---|
[113] | 229 | APIRET wphComposePath(HHANDLES hHandles,
|
---|
[106] | 230 | USHORT usHandle,
|
---|
| 231 | PSZ pszFilename,
|
---|
| 232 | ULONG cbFilename,
|
---|
| 233 | PNODE *ppNode);
|
---|
[7] | 234 |
|
---|
[106] | 235 | APIRET wphQueryPathFromHandle(HINI hiniUser,
|
---|
| 236 | HINI hiniSystem,
|
---|
| 237 | HOBJECT hObject,
|
---|
| 238 | PSZ pszFilename,
|
---|
| 239 | ULONG cbFilename);
|
---|
[7] | 240 |
|
---|
[180] | 241 | PCSZ wphDescribeError(APIRET arc);
|
---|
| 242 |
|
---|
[7] | 243 | #endif
|
---|
| 244 |
|
---|
| 245 | #if __cplusplus
|
---|
| 246 | }
|
---|
| 247 | #endif
|
---|
| 248 |
|
---|