Changeset 94 for trunk/src/helpers/dosh.c
- Timestamp:
- Aug 5, 2001, 6:32:52 PM (24 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/helpers/dosh.c
r91 r94 373 373 * to cause problems with some device drivers for 374 374 * removeable disks. 375 * 376 *@@changed V0.9.14 (2001-08-03) [umoeller]: added extra fix for A: and B: 375 377 */ 376 378 … … 379 381 { 380 382 APIRET arc = ERROR_INVALID_DRIVE; 383 384 if ( (ulLogicalDrive == 1) 385 || (ulLogicalDrive == 2) 386 ) 387 { 388 // drive A: and B: can never be fixed V0.9.14 (2001-08-03) [umoeller] 389 *pfFixed = FALSE; 390 return NO_ERROR; 391 } 381 392 382 393 if (ulLogicalDrive) … … 395 406 parms.drive = (UCHAR)(ulLogicalDrive-1); 396 407 arc = doshDevIOCtl((HFILE)-1, 397 IOCTL_DISK, 398 DSK_BLOCKREMOVABLE, 408 IOCTL_DISK, // 0x08 409 DSK_BLOCKREMOVABLE, // 0x20 399 410 &parms, sizeof(parms), 400 411 &ucNonRemoveable, sizeof(ucNonRemoveable)); … … 471 482 472 483 arc = doshDevIOCtl((HFILE)-1, 473 IOCTL_DISK, 474 DSK_GETDEVICEPARAMS, 484 IOCTL_DISK, // 0x08 485 DSK_GETDEVICEPARAMS, // 0x63 475 486 &parms, sizeof(parms), 476 487 pdp, sizeof(BIOSPARAMETERBLOCK)); … … 520 531 521 532 APIRET doshHasAudioCD(ULONG ulLogicalDrive, 533 HFILE hfDrive, // in: DASD open 522 534 BOOL fMixedModeCD, 523 535 PBOOL pfAudio) … … 525 537 APIRET arc = NO_ERROR; 526 538 527 HFILE hfDrive = 0;528 ULONG ulTemp= 0;529 530 CHAR szDrive[3] = "C:";531 szDrive[0] = 'A' + ulLogicalDrive - 1;539 ULONG ulAudioTracks = 0, 540 ulDataTracks = 0; 541 542 CHAR cds1[4] = { 'C', 'D', '0', '1' }; 543 CHAR cds2[4]; 532 544 533 545 *pfAudio = FALSE; 534 546 535 arc = DosOpen(szDrive, // "C:", "D:", ... 536 &hfDrive, 537 &ulTemp, 538 0, 539 FILE_NORMAL, 540 OPEN_ACTION_FAIL_IF_NEW 541 | OPEN_ACTION_OPEN_IF_EXISTS, 542 OPEN_FLAGS_DASD 543 | OPEN_FLAGS_FAIL_ON_ERROR 544 | OPEN_FLAGS_NOINHERIT // V0.9.6 (2000-11-25) [pr] 545 // | OPEN_ACCESS_READONLY // V0.9.13 (2001-06-14) [umoeller] 546 | OPEN_SHARE_DENYNONE, 547 NULL); 548 549 // _Pmpf((" DosOpen(OPEN_FLAGS_DASD) returned %d", arc)); 550 551 // this still returns NO_ERROR for audio CDs in a 552 // CD-ROM drive... 553 // however, the WPS then attempts to read in the 554 // root directory for audio CDs, which produces 555 // a "sector not found" error box... 556 557 if (!arc && hfDrive) // determined above 558 { 559 ULONG ulAudioTracks = 0, 560 ulDataTracks = 0; 561 562 CHAR cds1[4] = { 'C', 'D', '0', '1' }; 563 CHAR cds2[4]; 564 // check for proper driver signature 565 if (!(arc = doshDevIOCtl(hfDrive, 566 IOCTL_CDROMDISK, 567 CDROMDISK_GETDRIVER, 568 &cds1, sizeof(cds1), 569 &cds2, sizeof(cds2)))) 547 // check for proper driver signature 548 if (!(arc = doshDevIOCtl(hfDrive, 549 IOCTL_CDROMDISK, 550 CDROMDISK_GETDRIVER, 551 &cds1, sizeof(cds1), 552 &cds2, sizeof(cds2)))) 553 { 554 if (memcmp(&cds1, &cds2, 4)) 555 // this is not a CD-ROM then: 556 arc = NO_ERROR; 557 else 570 558 { 571 if (memcmp(&cds1, &cds2, 4)) 572 // this is not a CD-ROM then: 573 arc = NO_ERROR; 574 else 559 struct { 560 UCHAR ucFirstTrack, 561 ucLastTrack; 562 ULONG ulLeadOut; 563 } cdat; 564 565 // get track count 566 if (!(arc = doshDevIOCtl(hfDrive, 567 IOCTL_CDROMAUDIO, 568 CDROMAUDIO_GETAUDIODISK, 569 &cds1, sizeof(cds1), 570 &cdat, sizeof(cdat)))) 575 571 { 576 struct { 577 UCHAR ucFirstTrack, 578 ucLastTrack; 579 ULONG ulLeadOut; 580 } cdat; 581 582 // get track count 583 if (!(arc = doshDevIOCtl(hfDrive, 584 IOCTL_CDROMAUDIO, 585 CDROMAUDIO_GETAUDIODISK, 586 &cds1, sizeof(cds1), 587 &cdat, sizeof(cdat)))) 572 // still no error: build the audio TOC 573 ULONG i; 574 for (i = cdat.ucFirstTrack; 575 i <= cdat.ucLastTrack; 576 i++) 588 577 { 589 // still no error: build the audio TOC 590 ULONG i; 591 for (i = cdat.ucFirstTrack; 592 i <= cdat.ucLastTrack; 593 i++) 578 BYTE cdtp[5] = 579 { 'C', 'D', '0', '1', (UCHAR)i }; 580 581 struct { 582 ULONG ulTrackAddress; 583 BYTE bFlags; 584 } trackdata; 585 586 if (!(arc = doshDevIOCtl(hfDrive, 587 IOCTL_CDROMAUDIO, 588 CDROMAUDIO_GETAUDIOTRACK, 589 &cdtp, sizeof(cdtp), 590 &trackdata, sizeof(trackdata)))) 594 591 { 595 BYTE cdtp[5] = 596 { 'C', 'D', '0', '1', (UCHAR)i }; 597 598 struct { 599 ULONG ulTrackAddress; 600 BYTE bFlags; 601 } trackdata; 602 603 if (!(arc = doshDevIOCtl(hfDrive, 604 IOCTL_CDROMAUDIO, 605 CDROMAUDIO_GETAUDIOTRACK, 606 &cdtp, sizeof(cdtp), 607 &trackdata, sizeof(trackdata)))) 592 if (trackdata.bFlags & 64) 593 ulDataTracks++; 594 else 608 595 { 609 if (trackdata.bFlags & 64)610 ulDataTracks++; 611 else596 ulAudioTracks++; 597 598 if (!fMixedModeCD) 612 599 { 613 ulAudioTracks++; 614 615 if (!fMixedModeCD) 616 { 617 // caller doesn't want mixed mode: 618 // stop here 619 ulDataTracks = 0; 620 break; 621 } 600 // caller doesn't want mixed mode: 601 // stop here 602 ulDataTracks = 0; 603 break; 622 604 } 623 605 } 624 606 } 625 626 // _Pmpf((" got %d audio, %d data tracks",627 // ulAudioTracks, ulDataTracks));628 629 if (!ulDataTracks)630 *pfAudio = TRUE;631 607 } 632 else 633 { 634 // not audio disk: 635 // go on then 636 // _Pmpf((" CDROMAUDIO_GETAUDIODISK returned %d", arc)); 637 arc = NO_ERROR; 638 } 608 609 // _Pmpf((" got %d audio, %d data tracks", 610 // ulAudioTracks, ulDataTracks)); 611 612 if (!ulDataTracks) 613 *pfAudio = TRUE; 614 } 615 else 616 { 617 // not audio disk: 618 // go on then 619 // _Pmpf((" CDROMAUDIO_GETAUDIODISK returned %d", arc)); 620 arc = NO_ERROR; 639 621 } 640 622 } 641 else 642 { 643 // not CD-ROM: go on then 644 // _Pmpf((" CDROMDISK_GETDRIVER returned %d", arc)); 645 arc = NO_ERROR; 646 } 647 } 648 649 if (hfDrive) 650 DosClose(hfDrive); 623 } 624 else 625 { 626 // not CD-ROM: go on then 627 // _Pmpf((" CDROMDISK_GETDRIVER returned %d", arc)); 628 arc = NO_ERROR; 629 } 651 630 652 631 return (arc); … … 835 814 &fFixed); // V0.9.13 (2001-06-14) [umoeller] 836 815 837 //_Pmpf((__FUNCTION__ ": doshIsFixedDisk returned %d for disk %d", arc, ulLogicalDrive));838 //_Pmpf((" fFixed is %d", fFixed));816 _Pmpf((__FUNCTION__ ": doshIsFixedDisk returned %d for disk %d", arc, ulLogicalDrive)); 817 _Pmpf((" fFixed is %d", fFixed)); 839 818 840 819 if (!arc) … … 846 825 arc = doshQueryDiskParams(ulLogicalDrive, 847 826 &bpb); 848 //_Pmpf((" doshQueryDiskParams returned %d", arc));827 _Pmpf((" doshQueryDiskParams returned %d", arc)); 849 828 850 829 if ( (!arc) … … 852 831 ) 853 832 { 854 //_Pmpf((" --> is CD-ROM"));833 _Pmpf((" --> is CD-ROM")); 855 834 fCDROM = TRUE; 856 835 } 857 836 } 858 837 859 if ((!arc) && (fCDROM)) 860 { 861 BOOL fAudio; 862 if ( (!(arc = doshHasAudioCD(ulLogicalDrive, 863 ((fl & ASSERTFL_MIXEDMODECD) != 0), 864 &fAudio))) 865 && (fAudio) 838 if (!arc) 839 { 840 HFILE hfDrive = NULLHANDLE; 841 842 ULONG ulTemp = 0; 843 CHAR szDrive[3] = "C:"; 844 szDrive[0] = 'A' + ulLogicalDrive - 1; 845 846 arc = DosOpen(szDrive, // "C:", "D:", ... 847 &hfDrive, 848 &ulTemp, 849 0, 850 FILE_NORMAL, 851 OPEN_ACTION_FAIL_IF_NEW 852 | OPEN_ACTION_OPEN_IF_EXISTS, 853 OPEN_FLAGS_DASD 854 | OPEN_FLAGS_FAIL_ON_ERROR 855 | OPEN_FLAGS_NOINHERIT // V0.9.6 (2000-11-25) [pr] 856 // | OPEN_ACCESS_READONLY // V0.9.13 (2001-06-14) [umoeller] 857 | OPEN_SHARE_DENYNONE, 858 NULL); 859 860 // _Pmpf((" DosOpen(OPEN_FLAGS_DASD) returned %d", arc)); 861 862 // this still returns NO_ERROR for audio CDs in a 863 // CD-ROM drive... 864 // however, the WPS then attempts to read in the 865 // root directory for audio CDs, which produces 866 // a "sector not found" error box... 867 868 if ( (!arc) 869 && (hfDrive) 870 && (fCDROM) 866 871 ) 867 arc = ERROR_AUDIO_CD_ROM; // special private error code (10000) 872 { 873 BOOL fAudio; 874 if ( (!(arc = doshHasAudioCD(ulLogicalDrive, 875 hfDrive, 876 ((fl & ASSERTFL_MIXEDMODECD) != 0), 877 &fAudio))) 878 && (fAudio) 879 ) 880 arc = ERROR_AUDIO_CD_ROM; // special private error code (10000) 881 } 882 883 if (hfDrive) 884 DosClose(hfDrive); 868 885 } 869 886 … … 2649 2666 * 2650 2667 * If (fWait), this function will create a termination queue 2651 * and not return until the child session has ended. Otherwise 2652 * the function will return immediately, and the SID/PID of 2653 * the child session can be found in *pulSID and *ppid. 2668 * and not return until the child session has ended. Be warned, 2669 * this blocks the calling thread. 2670 * 2671 * Otherwise the function will return immediately. 2672 * 2673 * The session and process IDs of the child session will be 2674 * written to *pulSID and *ppid. Of course, in "wait" mode, 2675 * these are no longer valid after this function returns. 2654 2676 * 2655 2677 * Returns the error code of DosStartSession. … … 2661 2683 *@@changed V0.9.1 (99-12-30) [umoeller]: queue was sometimes not closed. Fixed. 2662 2684 *@@changed V0.9.3 (2000-05-03) [umoeller]: added fForeground 2685 *@@changed V0.9.14 (2001-08-03) [umoeller]: fixed potential queue leak 2686 *@@changed V0.9.14 (2001-08-03) [umoeller]: fixed memory leak in wait mode; added pusReturn to prototype 2663 2687 */ 2664 2688 … … 2669 2693 BOOL fWait, // in: wait for termination? 2670 2694 PULONG pulSID, // out: session ID (req.) 2671 PPID ppid) // out: process ID (req.) 2672 { 2673 APIRET arc; 2695 PPID ppid, // out: process ID (req.) 2696 PUSHORT pusReturn) // out: in wait mode, session's return code (ptr can be NULL) 2697 { 2698 APIRET arc = NO_ERROR; 2674 2699 // queue stuff 2675 2700 const char *pcszQueueName = "\\queues\\xwphlpsw.que"; 2676 2701 HQUEUE hq = 0; 2677 2702 PID qpid = 0; 2678 STARTDATA SData;2679 CHAR szObjBuf[CCHMAXPATH];2680 2703 2681 2704 if (fWait) 2682 2705 { 2683 if ((arc = DosCreateQueue(&hq, 2684 QUE_FIFO | QUE_CONVERT_ADDRESS, 2685 (PSZ)pcszQueueName)) 2686 != NO_ERROR) 2687 return (arc); 2688 2689 if ((arc = DosOpenQueue(&qpid, &hq, (PSZ)pcszQueueName)) != NO_ERROR) 2690 return (arc); 2691 } 2692 2693 SData.Length = sizeof(STARTDATA); 2694 SData.Related = SSF_RELATED_CHILD; //INDEPENDENT; 2695 SData.FgBg = (fForeground) ? SSF_FGBG_FORE : SSF_FGBG_BACK; 2696 // V0.9.3 (2000-05-03) [umoeller] 2697 SData.TraceOpt = SSF_TRACEOPT_NONE; 2698 2699 SData.PgmTitle = (PSZ)pcszPath; // title for window 2700 SData.PgmName = (PSZ)pcszPath; 2701 SData.PgmInputs = (PSZ)pcszParams; 2702 2703 SData.TermQ = (fWait) ? (PSZ)pcszQueueName : NULL; 2704 SData.Environment = 0; 2705 SData.InheritOpt = SSF_INHERTOPT_PARENT; 2706 SData.SessionType = SSF_TYPE_DEFAULT; 2707 SData.IconFile = 0; 2708 SData.PgmHandle = 0; 2709 2710 SData.PgmControl = usPgmCtl; 2711 2712 SData.InitXPos = 30; 2713 SData.InitYPos = 40; 2714 SData.InitXSize = 200; 2715 SData.InitYSize = 140; 2716 SData.Reserved = 0; 2717 SData.ObjectBuffer = (CHAR*)&szObjBuf; 2718 SData.ObjectBuffLen = (ULONG)sizeof(szObjBuf); 2719 2720 arc = DosStartSession(&SData, pulSID, ppid); 2721 2722 if (arc == NO_ERROR) 2723 { 2724 if (fWait) 2706 if (!(arc = DosCreateQueue(&hq, 2707 QUE_FIFO | QUE_CONVERT_ADDRESS, 2708 (PSZ)pcszQueueName))) 2709 arc = DosOpenQueue(&qpid, &hq, (PSZ)pcszQueueName); 2710 } 2711 2712 if (!arc) // V0.9.14 (2001-08-03) [umoeller] 2713 { 2714 STARTDATA SData; 2715 CHAR szObjBuf[CCHMAXPATH]; 2716 2717 SData.Length = sizeof(STARTDATA); 2718 SData.Related = SSF_RELATED_CHILD; //INDEPENDENT; 2719 SData.FgBg = (fForeground) ? SSF_FGBG_FORE : SSF_FGBG_BACK; 2720 // V0.9.3 (2000-05-03) [umoeller] 2721 SData.TraceOpt = SSF_TRACEOPT_NONE; 2722 2723 SData.PgmTitle = (PSZ)pcszPath; // title for window 2724 SData.PgmName = (PSZ)pcszPath; 2725 SData.PgmInputs = (PSZ)pcszParams; 2726 2727 SData.TermQ = (fWait) ? (PSZ)pcszQueueName : NULL; 2728 SData.Environment = 0; 2729 SData.InheritOpt = SSF_INHERTOPT_PARENT; 2730 SData.SessionType = SSF_TYPE_DEFAULT; 2731 SData.IconFile = 0; 2732 SData.PgmHandle = 0; 2733 2734 SData.PgmControl = usPgmCtl; 2735 2736 SData.InitXPos = 30; 2737 SData.InitYPos = 40; 2738 SData.InitXSize = 200; 2739 SData.InitYSize = 140; 2740 SData.Reserved = 0; 2741 SData.ObjectBuffer = szObjBuf; 2742 SData.ObjectBuffLen = (ULONG)sizeof(szObjBuf); 2743 2744 if ( (!(arc = DosStartSession(&SData, pulSID, ppid))) 2745 && (fWait) 2746 ) 2725 2747 { 2748 // block on the termination queue, which is written 2749 // to when the subprocess ends 2726 2750 REQUESTDATA rqdata; 2727 ULONG DataLength= 0;2728 PULONG DataAddress;2751 ULONG cbData = 0; 2752 PULONG pulData = NULL; 2729 2753 BYTE elpri; 2730 2754 2731 2755 rqdata.pid = qpid; 2732 DosReadQueue(hq, // in: queue handle 2733 &rqdata, // out: pid and ulData 2734 &DataLength, // out: size of data returned 2735 (PVOID*)&DataAddress, // out: data returned 2736 0, // in: remove first element in queue 2737 0, // in: wait for queue data (block thread) 2738 &elpri, // out: element's priority 2739 0); // in: event semaphore to be posted 2756 if (!(arc = DosReadQueue(hq, // in: queue handle 2757 &rqdata, // out: pid and ulData 2758 &cbData, // out: size of data returned 2759 (PVOID*)&pulData, // out: data returned 2760 0, // in: remove first element in queue 2761 0, // in: wait for queue data (block thread) 2762 &elpri, // out: element's priority 2763 0))) // in: event semaphore to be posted 2764 { 2765 if (!rqdata.ulData) 2766 { 2767 // child session ended: 2768 // V0.9.14 (2001-08-03) [umoeller] 2769 2770 // *pulSID = (*pulData) & 0xffff; 2771 if (pusReturn) 2772 *pusReturn = ((*pulData) >> 16) & 0xffff; 2773 2774 } 2775 // else: continue looping 2776 2777 if (pulData) 2778 DosFreeMem(pulData); 2779 } 2740 2780 } 2741 2781 }
Note:
See TracChangeset
for help on using the changeset viewer.