Microsoft KB Archive/65035

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

PSS ID Number: Q65035 Article last modified on 11-21-1990

3.00 3.00a 4.00 OS/2

Summary: A protected mode COBOL program can set the volume label of a disk drive by calling the OS/2 API function DosSetFSInfo. Below is a sample program illustrating 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 can call OS/2 API functions directly by prefixing their names with a double-underscore (__) and linking with the DOSCALLS.LIB library. DosSetFSInfo 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, and otherwise are passed BY VALUE. Because COBOL’s calling convention is the reverse of OS/2’s, the parameters must be mentioned in reverse order in the CALL statement. 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 DosSetFSInfo, see page 562 of “Advanced OS/2 Programming” by Ray Duncan (Microsoft Press, 1989). The following sample program (SETLABEL.CBL) prompts you for a drive letter and a volume label for that drive. If the drive exists, the volume name is changed. To compile and link the program in COBOL 3.00/3.00a, enter the following at the OS/2 command prompt: pcobol setlabel; link /nop setlabel,,,pcobol doscalls; The compile and link lines for COBOL PDS 4.00 are as follows: cobol setlabel; link setlabel,,,coblib os2;

SETLABEL.CBL
$SET ANS85 OSVS IDENTIFICATION DIVISION. PROGRAM-ID. SetLabel. 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. *  File system information level (2 = set volume label). 01 InfoLevel       PIC 9(4)  COMP-5 VALUE 2. *  Size of the buffer to contain new volume information. 01 BufferSize      PIC 9(4)  COMP-5 VALUE 13. *  Contains the new volume label information for the drive. 01 Buffer. 05 LabelLength  PIC 99    COMP-5 VALUE 11. 05 VolumeLabel  PIC X(12)        VALUE LOW-VALUES. 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. *   Prompt the user for the new volume label. Since the user *   can only modify 11 characters, the 12th will remain a null. DISPLAY &quot;Enter the new volume label (up to 11 chars):&quot;. ACCEPT VolumeLabel(1:11). *   Make the API call and end. CALL &quot;__DosSetFSInfo&quot; USING BY VALUE    BufferSize, BY REFERENCE Buffer, BY VALUE    InfoLevel, BY VALUE    DriveCode. *   Check if operation was successful. IF RETURN-CODE = 0 THEN DISPLAY &quot;The volume label of drive &quot; DriveLetter &quot; has been changed to &quot; VolumeLabel ELSE DISPLAY &quot;ERROR: &quot; RETURN-CODE CALL X&quot;E5&quot; END-IF. STOP RUN. Copyright Microsoft Corporation 1990.