[2] | 1 | /*
|
---|
| 2 | * This program is free software; you can redistribute it and/or modify
|
---|
| 3 | * it under the terms of the GNU General Public License as published by
|
---|
| 4 | * the Free Software Foundation; either version 2, or (at your option)
|
---|
| 5 | * any later version.
|
---|
| 6 | *
|
---|
| 7 | * This program is distributed in the hope that it will be useful,
|
---|
| 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
| 10 | * GNU General Public License for more details.
|
---|
| 11 | *
|
---|
| 12 | * You should have received a copy of the GNU General Public License
|
---|
| 13 | * along with this program; see the file COPYING. If not, write to
|
---|
| 14 | * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
|
---|
| 15 | */
|
---|
| 16 | /*
|
---|
| 17 | * If you need another license for your project/product contact me at
|
---|
| 18 | *
|
---|
| 19 | * http://www.os2world.com/cdwriting
|
---|
| 20 | * http://www.geocities.com/SiliconValley/Sector/5785/
|
---|
| 21 | */
|
---|
| 22 |
|
---|
| 23 | #define INCL_PM
|
---|
| 24 | #define INCL_ERRORS
|
---|
| 25 | #include <os2.h>
|
---|
| 26 | #include <wpfolder.h>
|
---|
| 27 | #include "sys_funcs.h"
|
---|
| 28 |
|
---|
| 29 | /*!*************************************************************/
|
---|
| 30 | /* */
|
---|
| 31 | /* @@FUNC */
|
---|
| 32 | /* BOOL EASaveString(WPFileSystem * wpFSObject, */
|
---|
| 33 | /* PSZ pKey, PSZ pValue) */
|
---|
| 34 | /* */
|
---|
| 35 | /* */
|
---|
| 36 | /* @@DESC */
|
---|
| 37 | /* Save an ASCII value to the EA <pKey> of the */
|
---|
| 38 | /* filesystem object <wpFSObject>. */
|
---|
| 39 | /* */
|
---|
| 40 | /* @@RETURNS */
|
---|
| 41 | /* */
|
---|
| 42 | /* BOOL rc */
|
---|
| 43 | /* */
|
---|
| 44 | /* TRUE if the string was saved in the extended attribute, */
|
---|
| 45 | /* FALSE otherwise. */
|
---|
| 46 | /* */
|
---|
| 47 | /* @@PARAM */
|
---|
| 48 | /* */
|
---|
| 49 | /* WPFileSystem* wpFSObject input */
|
---|
| 50 | /* */
|
---|
| 51 | /* Pointer to a file system object. */
|
---|
| 52 | /* */
|
---|
| 53 | /* @@PARAM */
|
---|
| 54 | /* */
|
---|
| 55 | /* PSZ pKey input */
|
---|
| 56 | /* */
|
---|
| 57 | /* Attribute name to be used. */
|
---|
| 58 | /* */
|
---|
| 59 | /* @@PARAM */
|
---|
| 60 | /* */
|
---|
| 61 | /* PSZ pValue input */
|
---|
| 62 | /* */
|
---|
| 63 | /* The null terminated string to be saved in the extended */
|
---|
| 64 | /* attribute :hp2.pKey:ehp2.. */
|
---|
| 65 | /* :p. */
|
---|
| 66 | /* If this is an empty string or NULL the attribute will */
|
---|
| 67 | /* be deleted from the file. */
|
---|
| 68 | /* */
|
---|
| 69 | /* @@REMARKS */
|
---|
| 70 | /* */
|
---|
| 71 | /* Attribute names starting with a point (:hp2..:ehp2.) are */
|
---|
| 72 | /* reserved for the operating system. */
|
---|
| 73 | /* */
|
---|
| 74 | /* */
|
---|
| 75 | /* */
|
---|
| 76 | /* */
|
---|
| 77 | /*!!************************************************************/
|
---|
| 78 | BOOL EASaveString(WPFileSystem * wpFSObject, PSZ pKey, PSZ pValue)
|
---|
| 79 | {
|
---|
| 80 | LONG rc; /* Ret code */
|
---|
| 81 | PVOID fealist; /* fealist buffer */
|
---|
| 82 | EAOP2 eaop; /* eaop structure */
|
---|
| 83 | PFEA2 pfea; /* pfea structure */
|
---|
| 84 | HFILE handle; /* file handle */
|
---|
| 85 | ULONG act; /* open action */
|
---|
| 86 | ULONG ulSize;
|
---|
| 87 | USHORT usSizeEA;
|
---|
| 88 |
|
---|
| 89 | char chrFileName[CCHMAXPATH];
|
---|
| 90 |
|
---|
| 91 | //SysWriteToTrapLog("%s %s\n", pKey, pValue);
|
---|
| 92 |
|
---|
| 93 | if(!somIsObj(wpFSObject) || !pKey || strlen(pKey)==0)
|
---|
| 94 | return FALSE;
|
---|
| 95 |
|
---|
| 96 | if(pValue) {
|
---|
| 97 | if((fealist=_wpAllocMem(wpFSObject, strlen(pKey)+strlen(pValue)+sizeof(FEA2)+0x100 /* Add some space */,
|
---|
| 98 | &ulSize))==NULLHANDLE)
|
---|
| 99 | return FALSE;
|
---|
| 100 | }
|
---|
| 101 | else {
|
---|
| 102 | if((fealist=_wpAllocMem(wpFSObject, strlen(pKey)+sizeof(FEA2)+0x100 /* Add some space */,
|
---|
| 103 | &ulSize))==NULLHANDLE)
|
---|
| 104 | return FALSE;
|
---|
| 105 | }
|
---|
| 106 |
|
---|
| 107 | ulSize=sizeof(chrFileName);
|
---|
| 108 | _wpQueryRealName(wpFSObject, chrFileName,&ulSize,TRUE);
|
---|
| 109 |
|
---|
| 110 |
|
---|
| 111 | if ((rc = DosOpen(chrFileName, &handle, &act,
|
---|
| 112 | 0L, 0, OPEN_ACTION_OPEN_IF_EXISTS,
|
---|
| 113 | OPEN_ACCESS_READWRITE + OPEN_SHARE_DENYWRITE +
|
---|
| 114 | OPEN_FLAGS_FAIL_ON_ERROR + OPEN_FLAGS_WRITE_THROUGH, NULL))!=NO_ERROR) {
|
---|
| 115 | _wpFreeMem(wpFSObject,fealist); /* Free the memory */
|
---|
| 116 | return FALSE;
|
---|
| 117 | }
|
---|
| 118 |
|
---|
| 119 | eaop.fpFEA2List = (PFEA2LIST)fealist;/* Set memory for the FEA */
|
---|
| 120 | eaop.fpGEA2List = NULL; /* GEA is unused */
|
---|
| 121 | pfea = &eaop.fpFEA2List->list[0]; /* point to first FEA */
|
---|
| 122 | pfea->fEA = '\0'; /* set the flags to non critical */
|
---|
| 123 | /* Size of FEA name field */
|
---|
| 124 | pfea->cbName = (BYTE)strlen(pKey);
|
---|
| 125 | strcpy((PSZ)pfea->szName, pKey); /* Set the name of this FEA */
|
---|
| 126 |
|
---|
| 127 |
|
---|
| 128 | /* Size of Value for this one */
|
---|
| 129 | if(!pValue || strlen(pValue)==0) {
|
---|
| 130 | pfea->cbValue = 0; /* Delete EA if no Value given */
|
---|
| 131 | }
|
---|
| 132 | else {
|
---|
| 133 | pfea->cbValue = (SHORT)strlen(pValue)+4; /* 4 bytes for marking as ASCII attribute */
|
---|
| 134 |
|
---|
| 135 | /* Set the EA value after the FEA2 */
|
---|
| 136 | usSizeEA=0xFFFD;
|
---|
| 137 | memcpy((PSZ)pfea->szName+(pfea->cbName+1), &usSizeEA, 2); /* It's an ASCII value */
|
---|
| 138 | usSizeEA=strlen(pValue);
|
---|
| 139 | memcpy((PSZ)pfea->szName+(pfea->cbName+3), &usSizeEA, sizeof(USHORT));/* Length of ASCII value */
|
---|
| 140 |
|
---|
| 141 | memcpy((PSZ)pfea->szName+(pfea->cbName+5), pValue, usSizeEA); /* And now the value */
|
---|
| 142 | }
|
---|
| 143 | pfea->oNextEntryOffset = 0; /* no next entry */
|
---|
| 144 | eaop.fpFEA2List->cbList = /* Set the total size var */
|
---|
| 145 | sizeof(ULONG) + sizeof(FEA2) + pfea->cbName + pfea->cbValue;
|
---|
| 146 |
|
---|
| 147 | /* set the file info */
|
---|
| 148 | rc = DosSetFileInfo(handle, 2, (PSZ)&eaop, sizeof(EAOP2));
|
---|
| 149 | DosClose(handle); /* Close the File */
|
---|
| 150 | _wpFreeMem(wpFSObject,fealist); /* Free the memory */
|
---|
| 151 | return TRUE;
|
---|
| 152 | }
|
---|
| 153 |
|
---|
| 154 | /*!*************************************************************/
|
---|
| 155 | /* */
|
---|
| 156 | /* @@FUNC */
|
---|
| 157 | /* BOOL EARestoreString(WPFileSystem * wpFSObject, */
|
---|
| 158 | /* PSZ pKey, char * chrBuffer, ULONG ulBuffSize) */
|
---|
| 159 | /* */
|
---|
| 160 | /* */
|
---|
| 161 | /* @@DESC */
|
---|
| 162 | /* Read an ASCII value from the EA <pKey> of the */
|
---|
| 163 | /* filesystem object <wpFSObject>. */
|
---|
| 164 | /* */
|
---|
| 165 | /* @@RETURNS */
|
---|
| 166 | /* */
|
---|
| 167 | /* BOOL rc */
|
---|
| 168 | /* */
|
---|
| 169 | /* TRUE if the string was queried from the extended attribute, */
|
---|
| 170 | /* FALSE in case of an error or if there's no attribute */
|
---|
| 171 | /* with the specified name. */
|
---|
| 172 | /* */
|
---|
| 173 | /* @@PARAM */
|
---|
| 174 | /* */
|
---|
| 175 | /* WPFileSystem* wpFSObject input */
|
---|
| 176 | /* */
|
---|
| 177 | /* Pointer to a file system object. */
|
---|
| 178 | /* */
|
---|
| 179 | /* @@PARAM */
|
---|
| 180 | /* */
|
---|
| 181 | /* PSZ pKey input */
|
---|
| 182 | /* */
|
---|
| 183 | /* Attribute name. */
|
---|
| 184 | /* */
|
---|
| 185 | /* @@PARAM */
|
---|
| 186 | /* */
|
---|
| 187 | /* char* chrBuffer in/out */
|
---|
| 188 | /* */
|
---|
| 189 | /* Buffer into which the string will be placed. */
|
---|
| 190 | /* */
|
---|
| 191 | /* @@PARAM */
|
---|
| 192 | /* */
|
---|
| 193 | /* ULONG ulBuffSize input */
|
---|
| 194 | /* */
|
---|
| 195 | /* Size of buffer :hp2.chrBuffer:ehp2.. */
|
---|
| 196 | /* */
|
---|
| 197 | /* @@REMARKS */
|
---|
| 198 | /* */
|
---|
| 199 | /* The string is always null terminated. If the buffer isn't */
|
---|
| 200 | /* large enough at most ulBuffSize-1 characters will be read. */
|
---|
| 201 | /* */
|
---|
| 202 | /* */
|
---|
| 203 | /*!!************************************************************/
|
---|
| 204 | BOOL EARestoreString(WPFileSystem * wpFSObject, PSZ pKey, char * chrBuffer, ULONG ulBuffSize)
|
---|
| 205 | {
|
---|
| 206 | LONG rc; /* Ret code */
|
---|
| 207 | UCHAR geabuff[300]; /* buffer for GEA */
|
---|
| 208 | PVOID fealist; /* fealist buffer */
|
---|
| 209 | EAOP2 eaop; /* eaop structure */
|
---|
| 210 | PGEA2 pgea; /* pgea structure */
|
---|
| 211 | PFEA2 pfea; /* pfea structure */
|
---|
| 212 | HFILE handle; /* file handle */
|
---|
| 213 | ULONG act; /* open action */
|
---|
| 214 | ULONG ulSize;
|
---|
| 215 | USHORT *ptrUs;
|
---|
| 216 |
|
---|
| 217 | char chrFileName[CCHMAXPATH];
|
---|
| 218 |
|
---|
| 219 | if((fealist=_wpAllocMem(wpFSObject, 0x00010000L /* Add some space */,
|
---|
| 220 | &ulSize))==NULLHANDLE)
|
---|
| 221 | return FALSE;
|
---|
| 222 |
|
---|
| 223 | ulSize=sizeof(chrFileName);
|
---|
| 224 | _wpQueryRealName(wpFSObject, chrFileName,&ulSize,TRUE);
|
---|
| 225 |
|
---|
| 226 | if ((rc = DosOpen(chrFileName, &handle, &act,
|
---|
| 227 | 0L, 0, OPEN_ACTION_OPEN_IF_EXISTS,
|
---|
| 228 | OPEN_ACCESS_READONLY + OPEN_SHARE_DENYREADWRITE +
|
---|
| 229 | OPEN_FLAGS_FAIL_ON_ERROR + OPEN_FLAGS_WRITE_THROUGH,NULL))!=NO_ERROR) {
|
---|
| 230 | _wpFreeMem(wpFSObject,fealist); /* Free the memory */
|
---|
| 231 | return FALSE;
|
---|
| 232 | } /* get the file status info */
|
---|
| 233 |
|
---|
| 234 |
|
---|
| 235 | /* FEA and GEA lists */
|
---|
| 236 | eaop.fpGEA2List = (PGEA2LIST)geabuff;
|
---|
| 237 | eaop.fpFEA2List = (PFEA2LIST)fealist;
|
---|
| 238 | eaop.oError = 0; /* no error occurred yet */
|
---|
| 239 | pgea = &eaop.fpGEA2List->list[0]; /* point to first GEA */
|
---|
| 240 | eaop.fpGEA2List->cbList = sizeof(ULONG) + sizeof(GEA2) +
|
---|
| 241 | strlen(pKey);
|
---|
| 242 | eaop.fpFEA2List->cbList = (ULONG)0xffff;
|
---|
| 243 |
|
---|
| 244 | /* fill in the EA name length */
|
---|
| 245 | pgea->cbName = (BYTE)strlen(pKey);
|
---|
| 246 | strcpy(pgea->szName, pKey); /* fill in the name */
|
---|
| 247 | pgea->oNextEntryOffset = 0; /* fill in the next offset */
|
---|
| 248 | /* read the extended attribute*/
|
---|
| 249 | rc = DosQueryFileInfo(handle, 3, (PSZ)&eaop, sizeof(EAOP2));
|
---|
| 250 | DosClose(handle); /* close the file */
|
---|
| 251 | if (eaop.fpFEA2List->cbList <= sizeof(ULONG))
|
---|
| 252 | rc = ERROR_EAS_NOT_SUPPORTED; /* this is error also */
|
---|
| 253 |
|
---|
| 254 | if (rc) { /* failure? */
|
---|
| 255 | _wpFreeMem(wpFSObject,fealist); /* Free the memory */
|
---|
| 256 | return FALSE;
|
---|
| 257 | }
|
---|
| 258 |
|
---|
| 259 | pfea = &(eaop.fpFEA2List->list[0]); /* point to the first FEA */
|
---|
| 260 |
|
---|
| 261 | #if 0
|
---|
| 262 | ldp.shvb.shvname.strptr = ldp.varname;
|
---|
| 263 | ldp.shvb.shvname.strlength = ldp.stemlen;
|
---|
| 264 | ldp.shvb.shvnamelen = ldp.stemlen;
|
---|
| 265 | ldp.shvb.shvvalue.strptr = ((PSZ)pfea->szName+(pfea->cbName+1));
|
---|
| 266 | ldp.shvb.shvvalue.strlength = pfea->cbValue;
|
---|
| 267 | ldp.shvb.shvvaluelen = ldp.shvb.shvvalue.strlength;
|
---|
| 268 | #endif
|
---|
| 269 |
|
---|
| 270 | ptrUs=(USHORT*)((PSZ)pfea->szName+(pfea->cbName+1));
|
---|
| 271 | if(*ptrUs!=0xfffd) {
|
---|
| 272 | /* Not an ASCII EA */
|
---|
| 273 | _wpFreeMem(wpFSObject,fealist); /* Free the memory */
|
---|
| 274 | return FALSE;
|
---|
| 275 | }
|
---|
| 276 | ptrUs++; /* Move to length */
|
---|
| 277 | ulSize=(ULONG)*ptrUs;
|
---|
| 278 |
|
---|
| 279 | ptrUs++; /* Move to value */
|
---|
| 280 | if(ulSize==0) {
|
---|
| 281 | /* Not an ASCII EA */
|
---|
| 282 | _wpFreeMem(wpFSObject,fealist); /* Free the memory */
|
---|
| 283 | return FALSE;
|
---|
| 284 | }
|
---|
| 285 | // HlpWriteToTrapLog("Length: %x, Value: %s\n", ulSize, (char*)ptrUs);
|
---|
| 286 | memset(chrBuffer,0,ulBuffSize);
|
---|
| 287 | memcpy(chrBuffer, (char*)ptrUs, (ulSize>=ulBuffSize ? ulBuffSize-1 : ulSize));
|
---|
| 288 | _wpFreeMem(wpFSObject,fealist); /* Free the memory */
|
---|
| 289 | return TRUE;
|
---|
| 290 | }
|
---|