Microsoft KB Archive/65288

How to Get a Volume Name in a Protected Mode COBOL Program

PSS ID Number: Q65288 Article last modified on 11-19-1990

3.00 3.00a 4.00 OS/2

Summary: A protected mode COBOL program can get the volume label of a disk drive by calling the OS/2 API function DosQFSInfo. The sample program below illustrates how to do this. This information applies to Microsoft COBOL Compiler versions 3.00 and 3.00a for MS OS/2, and to Microsoft COBOL Professional Development System (PDS) version 4.00 for MS OS/2.

More Information: COBOL versions 3.00, 3.00a, and 4.00 can directly call OS/2 API functions by prefixing their names with a double underscore (__) and linking with the DOSCALLS.LIB library. DosQFSInfo takes the following parameters:

Note that in COBOL a WORD has a picture clause of 9(4) COMP-5. Furthermore, data items prefixed with PTR must be passed BY REFERENCE; otherwise, they are passed BY VALUE. Also, the parameters must be mentioned in reverse order in the CALL statement because COBOL’s calling convention is the reverse of OS/2’s. 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 DosQFSInfo, see pages 549-550 of “Advanced OS/2 Programming” by Ray Duncan (Microsoft Press, 1989). The following sample program (GETLABEL.CBL) prompts the user for a drive letter and displays the volume label for that drive. To compile and link the program in COBOL 3.00/3.00a, enter the following at the OS/2 command prompt: pcobol getlabel; link /nop getlabel,,,pcobol doscalls; The compiling and linking lines for COBOL Professional Development System (PDS) version 4.00 are as follows: cobol getlabel; link getlabel,,,coblib os2;

GETLABEL.CBL
$SET ANS85 OSVS IDENTIFICATION DIVISION. PROGRAM-ID. GetLabel. DATA DIVISION. WORKING-STORAGE SECTION. *  Receives drive letter from user. 01 DriveLetter      PIC X.  *   Converts DriveLetter to be used by DriveCode. 01 DriveNumber      PIC 99   COMP-X REDEFINES DriveLetter. *  Code number of drive (0 = current, 1 = A, 2 = B, etc.) 01 DriveCode        PIC 9(4) COMP-5. *  Information desired (2 = get volume label). 01 InfoDesired      PIC 9(4) COMP-5 VALUE 2. *  Size of the buffer to receive information. 01 BufferSize       PIC 9(4) COMP-5 VALUE 17. *  Receives the volume label information of the drive. 01 Buffer. 05 CreationDate  PIC 9(4) COMP-5. 05 CreationTime  PIC 9(4) COMP-5. 05 LabelLength   PIC 99   COMP-5. 05 VolumeLabel   PIC X(12). PROCEDURE DIVISION. *   Prompt the user for a drive letter. DISPLAY &quot;Enter drive letter:&quot;. ACCEPT DriveLetter. *   Check if DriveNumber is in legal range (A-Z or a-z). IF ((DriveNumber >= 97) AND (DriveNumber <= 122)) THEN COMPUTE DriveNumber = DriveNumber - 32 ELSE IF ((DriveNumber < 65) OR (DriveNumber > 90)) THEN DISPLAY &quot;ERROR - Must enter a letter.&quot; CALL X&quot;E5&quot; STOP RUN END-IF END-IF. *   When DriveNumber = 65, DriveCode = 1, and so on. COMPUTE DriveCode = DriveNumber - 64. *   Make the API call. CALL &quot;__DosQFSInfo&quot; USING BY VALUE    BufferSize, BY REFERENCE Buffer, BY VALUE    InfoDesired, BY VALUE    DriveCode. *   If no error occurred, display the volume label. IF RETURN-CODE = 0 THEN DISPLAY &quot;The volume label of drive &quot; DriveLetter &quot; is &quot; VolumeLabel ELSE DISPLAY &quot;ERROR - Invalid drive.&quot; CALL X&quot;E5&quot; END-IF. STOP RUN. Copyright Microsoft Corporation 1990.