- Timestamp:
- Sep 15, 2000, 3:25:50 PM (25 years ago)
- Location:
- trunk/src/wnaspi32
- Files:
-
- 1 added
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wnaspi32/aspilib.cpp
r4260 r4265 1 /* $Id: aspilib.cpp,v 1. 4 2000-09-14 19:09:16 sandervl Exp $ */1 /* $Id: aspilib.cpp,v 1.5 2000-09-15 13:25:46 sandervl Exp $ */ 2 2 /* 3 3 * ASPI Router Library … … 21 21 #include <stdio.h> 22 22 #include <misc.h> 23 #include "aspilib.h" 23 #include "aspilib.h" 24 25 #define WNASPI32_MUTEX_NAME "\\SEM32\\ODIN\\ASPIROUT" 24 26 25 27 //*************************************************************************** … … 30 32 //* * 31 33 //*************************************************************************** 32 scsiObj::scsiObj() : buffer(NULL) 34 scsiObj::scsiObj() : buffer(NULL), hmtxDriver(0) 33 35 { 34 36 memset(&SRBlock, 0, sizeof(SRBlock)); … … 202 204 BOOL scsiObj::init(ULONG bufsize) 203 205 { 204 BOOL success; 205 ULONG rc; 206 207 rc = DosAllocMem(&buffer, bufsize, OBJ_TILE | PAG_READ | PAG_WRITE | PAG_COMMIT); 208 if (rc) return FALSE; 209 success=openDriver(); // call openDriver member function 210 if (!success) return FALSE; 211 success=initSemaphore(); // call initSemaphore member function 212 if (!success) return FALSE; 213 214 success=initBuffer(); 215 216 return TRUE; 206 BOOL success; 207 APIRET rc; 208 209 210 rc = DosCreateMutexSem(WNASPI32_MUTEX_NAME, (HMTX*)&hmtxDriver, 211 0, TRUE); 212 if(rc == ERROR_DUPLICATE_NAME) { 213 rc = DosOpenMutexSem(WNASPI32_MUTEX_NAME, (HMTX*)&hmtxDriver); 214 } 215 if(rc != NO_ERROR) { 216 dprintf(("scsiObj::init: DosCreate/OpenMutexSem failed! (rc=%d)", rc)); 217 return FALSE; 218 } 219 220 rc = DosAllocMem(&buffer, bufsize, OBJ_TILE | PAG_READ | PAG_WRITE | PAG_COMMIT); 221 if (rc) return FALSE; 222 success=openDriver(); // call openDriver member function 223 if (!success) return FALSE; 224 success=initSemaphore(); // call initSemaphore member function 225 if (!success) return FALSE; 226 227 success=initBuffer(); 228 229 return TRUE; 217 230 } 218 231 … … 239 252 if (!success) 240 253 { 241 printf("closeSemaphore() unsuccessful.\n");254 dprintf(("scsiObj::close: closeSemaphore() unsuccessful.")); 242 255 return FALSE; 243 256 } … … 245 258 if (!success) 246 259 { 260 dprintf(("scsiObj::close: closeDriver() unsucessful.")); 247 261 return FALSE; 248 printf("closeDriver() unsucessful.\n");249 262 } 250 263 rc = DosFreeMem(buffer); 251 264 if (rc) 252 265 { 253 printf("DosFreeMem unsuccessful. return code: %ld\n", rc);266 dprintf(("scsiObj::close: DosFreeMem unsuccessful. return code: %ld", rc)); 254 267 return FALSE; 255 268 } 269 if(hmtxDriver) { 270 rc = DosCloseMutexSem((HMTX)hmtxDriver); 271 if(rc != NO_ERROR) { 272 dprintf(("scsiObj::close: DosCloseMutexSem unsuccessful. return code: %ld", rc)); 273 return FALSE; 274 } 275 } 276 256 277 return TRUE; 257 278 } … … 451 472 //*************************************************************************** 452 473 //*************************************************************************** 453 BOOL fGainDrvAccess( BOOL fWait, 454 ULONG *phSem) 455 { 456 ULONG rc; 457 rc = DosCreateMutexSem ( "\\SEM32\\ODIN\\ASPIROUT", 458 (HMTX*)phSem, 459 0, 460 TRUE); 461 if(NO_ERROR==rc) 462 return TRUE; 463 if((ERROR_DUPLICATE_NAME!=rc)||(!fWait)) 464 return FALSE; 465 rc = DosOpenMutexSem ( "\\SEM32\\ODIN\\ASPIROUT", 466 (HMTX*)phSem); 467 if(NO_ERROR!=rc) 468 return FALSE; 469 470 rc = DosRequestMutexSem( (HMTX)(*phSem), 471 SEM_INDEFINITE_WAIT); 472 473 if(NO_ERROR!=rc) 474 return FALSE; 475 476 return TRUE; 477 } 478 //*************************************************************************** 479 //*************************************************************************** 480 BOOL fReleaseDrvAccess(ULONG hSem) 481 { 482 ULONG rc; 483 BOOL frc = TRUE; 484 485 rc = DosReleaseMutexSem((HMTX)hSem); 486 if(NO_ERROR!=rc) 487 frc=FALSE; 488 489 rc = DosCloseMutexSem((HMTX)hSem); 490 if(NO_ERROR!=rc) 491 frc=FALSE; 492 493 return frc; 494 } 474 BOOL scsiObj::access(BOOL fWait) 475 { 476 APIRET rc; 477 478 if(!fWait) { 479 rc = DosRequestMutexSem((HMTX) hmtxDriver, SEM_INDEFINITE_WAIT); 480 } 481 else rc = DosRequestMutexSem((HMTX) hmtxDriver, 100); 482 483 if(rc != NO_ERROR) { 484 dprintf(("scsiObj::access: DosRequestMutexSem failed with rc = %d", rc)); 485 return FALSE; 486 } 487 return TRUE; 488 } 489 //*************************************************************************** 490 //*************************************************************************** 491 BOOL scsiObj::release() 492 { 493 APIRET rc; 494 495 rc = DosReleaseMutexSem((HMTX)hmtxDriver); 496 if(rc != NO_ERROR) { 497 dprintf(("scsiObj::access: DosReleaseMutexSem failed with rc = %d", rc)); 498 return FALSE; 499 } 500 501 return TRUE; 502 } 503 //*************************************************************************** 504 //*************************************************************************** -
trunk/src/wnaspi32/aspilib.h
r3564 r4265 28 28 BOOL closeDriver(); 29 29 BOOL initBuffer(); 30 ULONG hmtxDriver; 30 31 31 32 public: … … 50 51 ULONG SendSRBlock(VOID); 51 52 ULONG getNumHosts(); 53 BOOL access(BOOL fWait); 54 BOOL release(); 55 52 56 53 57 SRBOS2 SRBlock; // SCSI Request Block … … 56 60 }; 57 61 58 59 extern "C" 60 { 61 BOOL fGainDrvAccess( BOOL fWait, ULONG *phSem); 62 BOOL fReleaseDrvAccess(ULONG hSem); 63 } 64 62 extern scsiObj *aspi; 65 63 66 64 #endif // _ASPILIB_H_ -
trunk/src/wnaspi32/makefile
r3864 r4265 1 # $Id: makefile,v 1.1 0 2000-07-19 19:05:27sandervl Exp $1 # $Id: makefile,v 1.11 2000-09-15 13:25:49 sandervl Exp $ 2 2 3 3 # … … 27 27 $(OBJDIR)\winaspi32.obj \ 28 28 $(OBJDIR)\wnaspi32rsrc.obj \ 29 $( PDWIN32_LIB)\dllentry.obj29 $(OBJDIR)\initterm.obj 30 30 31 31 -
trunk/src/wnaspi32/winaspi32.cpp
r4260 r4265 1 /* $Id: winaspi32.cpp,v 1. 8 2000-09-14 19:09:17sandervl Exp $ */1 /* $Id: winaspi32.cpp,v 1.9 2000-09-15 13:25:50 sandervl Exp $ */ 2 2 /* 3 3 * WNASPI routines … … 28 28 //#include "callback.h" 29 29 30 #ifdef DEBUG 31 #define DEBUG_BUFFER 32 #endif 33 30 34 DEFAULT_DEBUG_CHANNEL(aspi) 31 35 ODINDEBUGCHANNEL(WNASPI32) … … 80 84 cdb = &prb->CDBByte[0]; 81 85 cmd = prb->CDBByte[0]; 82 if (TRACE_ON(aspi)) 83 { 84 DPRINTF("CDB buffer["); 86 #ifdef DEBUG_BUFFER 87 dprintfNoEOL(("CDB buffer[")); 85 88 for (i = 0; i < prb->SRB_CDBLen; i++) { 86 if (i != 0) DPRINTF(",");87 DPRINTF("%02x", *cdb++);88 } 89 DPRINTF("]\n");90 } 89 if (i != 0) dprintfNoEOL((",0x%02x", *cdb++)); 90 else dprintfNoEOL(("0x%02x", *cdb++)); 91 } 92 dprintfNoEOL(("]\n")); 93 #endif 91 94 } 92 95 … … 178 181 lpPRB->SRB_BufPointer, 179 182 lpPRB->SRB_BufLen); 183 184 #ifdef DEBUG_BUFFER 185 char *cdb = (char *)lpPRB->SRB_BufPointer; 186 dprintfNoEOL(("Write SRB buffer[")); 187 for (int i = 0; i < lpPRB->SRB_BufLen; i++) { 188 if (i != 0) dprintfNoEOL((",0x%02x", *cdb++)); 189 else dprintfNoEOL(("0x%02x", *cdb++)); 190 } 191 dprintfNoEOL(("]\n")); 192 #endif 180 193 } 181 194 } … … 195 208 aspi->buffer, 196 209 lpPRB->SRB_BufLen); 210 #ifdef DEBUG_BUFFER 211 char *cdb = (char *)lpPRB->SRB_BufPointer; 212 dprintfNoEOL(("Read SRB buffer[")); 213 for (int i = 0; i < lpPRB->SRB_BufLen; i++) { 214 if (i != 0) dprintfNoEOL((",0x%02x", *cdb++)); 215 else dprintfNoEOL(("0x%02x", *cdb++)); 216 } 217 dprintfNoEOL(("]\n")); 218 #endif 219 197 220 } 198 221 } … … 251 274 { 252 275 LONG rc; 253 scsiObj *aspi;254 ULONG hmtxDriver;255 276 BYTE bNumDrv; 256 277 HKEY hkeyDrvInfo; … … 263 284 bNumDrv = 0; 264 285 265 aspi = new scsiObj(); 266 267 if( fGainDrvAccess( FALSE, &hmtxDriver) ) // Do nonblocking call for info 268 { 269 270 if(aspi->init(65535)==TRUE) 271 { 272 286 if(aspi->access(FALSE)) //'non-blocking' call 287 { 273 288 bNumDrv = aspi->getNumHosts(); 274 289 brc = SS_COMP; … … 287 302 RegCloseKey( hkeyDrvInfo); 288 303 } 289 aspi->close(); 290 } 291 else 292 brc = SS_FAILED_INIT; 293 294 fReleaseDrvAccess( hmtxDriver); 304 aspi->release(); 295 305 } 296 306 else … … 324 334 } 325 335 } 326 delete aspi;327 336 328 337 return ((brc << 8) | bNumDrv); /* FIXME: get # of host adapters installed */ … … 337 346 ULONG ulParam, ulReturn; 338 347 BYTE bRC; 339 scsiObj *aspi;340 ULONG hmtxDriver;341 348 LONG rc; 342 349 … … 357 364 } 358 365 359 aspi = new scsiObj();360 361 366 dwRC = SS_ERR; 362 367 363 if( fGainDrvAccess( TRUE, &hmtxDriver) ) // Block if a SRB is pending 364 { 365 if(aspi->init(65535)==TRUE) 366 { 368 if(aspi->access(TRUE)) // Block if a SRB is pending 369 { 367 370 switch (lpSRB->common.SRB_Cmd) 368 371 { … … 414 417 break; 415 418 416 } // end switch (lpSRB->common.SRB_Cmd) 417 418 } 419 else 420 { 421 dwRC = bRC; 422 } 423 424 fReleaseDrvAccess( hmtxDriver); 425 aspi->close(); 419 } // end switch (lpSRB->common.SRB_Cmd) 420 421 aspi->release(); 426 422 } 427 423 else 428 424 { 429 dwRC = SS_NO_ASPI; 430 } 431 delete aspi; 425 dwRC = SS_NO_ASPI; 426 } 432 427 433 428 return dwRC;
Note:
See TracChangeset
for help on using the changeset viewer.