Microsoft KB Archive/62261

How to Find All Available Drives in OS/2 Protected Mode

PSS ID Number: Q62261 Article last modified on 05-29-1990

3.00 3.00a OS/2

Summary: Microsoft COBOL versions 3.00 and 3.00a protected mode programs can call the OS/2 API function DosQCurDisk to get all the available logical drives. These versions of COBOL can call API functions directly, prefixing their names with a double underscore; for example: CALL &quot;__DosQCurDisk&quot; USING BY REFERENCE DriveBitmap, BY REFERENCE DriveCode For more information on calling OS/2 API functions from COBOL 3.00 and 3.00a, see the file OS2API.DOC included with 3.00a. For more information on DosQCurDisk, see Page 547 of “Advanced OS/2 Programming,” by Ray Duncan (Microsoft Press, 1989). This information applies to Microsoft COBOL Compiler versions 3.00 and 3.00a for MS OS/2.

More Information: The API function DosQCurDisk requires that the following data items be passed to it: PTR WORD Receives current drive code (1 = A, 2 = B, etc.) PTR DWORD Receives logical drive bitmap (logical drives A-Z correspond to bits 0-25; a bit is set if a logical drive exists) The first parameter is not important in getting all the available logical drives, but it is worthy to note that for API functions, a WORD (2 bytes) has a picture clause of “9(4) COMP-5”. Likewise, a DWORD (4 bytes) has a picture clause of “9(8) COMP-5”. Since the specification requires pointers to these data items, they must be passed using the BY REFERENCE clause. Remember also that API functions use a calling convention that is the reverse of COBOL’s, so the parameters must be passed in the reverse order. The sample program below (LOGICAL.CBL) reports all the available logical drives. To compile and link the program, do the following: pcobol logical; link /nop logical,,,pcobol doscalls;

Code Example
DATA DIVISION. WORKING-STORAGE SECTION. * Receives current drive from API call, not used here. 01 DriveCode      PIC 9(4) COMP-5. * Receives bitmap of availability of all logical drives. 01 DriveBitmap    PIC 9(8) COMP-5. * Used to circulate through bits (drives) of DriveBitmap. 01 Bit            PIC 99   COMP-5. * Used to display drive letter corresponding to Bit. 01 DriveLetter    REDEFINES Bit PIC X.  * Used to shift bits of DriveBitmap to check if Bit is set. 01 ShiftedBitmap  PIC 9(8) COMP-5. PROCEDURE DIVISION. DISPLAY &quot;The following drives are available:&quot;. *   Call the API function to get bitmap of logical drives. CALL &quot;__DosQCurDisk&quot; USING BY REFERENCE DriveBitmap, BY REFERENCE DriveCode *   Circulate through bits 0-25 (drives A-Z) of DriveBitmap PERFORM VARYING Bit FROM 0 BY 1 UNTIL Bit > 25 *      Shift all bits of DriveBitmap to the right of Bit *      so that Bit is now at the leftmost bit position *      (31). This will clear out all bits to the left *      of Bit. This value is copied to ShiftedBitmap to *       be manipulated because DriveBitmap will be needed for *      the remaining values of Bit. COMPUTE ShiftedBitmap = DriveBitmap * (2**(31 - Bit)) *      Shift bit 31 (Bit) back down to bit 0. This will *      clear out all bits to the right of Bit. If Bit was *      set, ShiftedBitmap will now equal 1, which means the *      corresponding drive is available. COMPUTE ShiftedBitmap = ShiftedBitmap / (2**31) IF ShiftedBitmap = 1 THEN *         Bit 1 corresponds to drive A, but A is ASCII 65 COMPUTE Bit = Bit + 65 DISPLAY DriveLetter COMPUTE Bit = Bit - 65 END-IF END-PERFORM. STOP RUN. Copyright Microsoft Corporation 1990.