Microsoft KB Archive/58650

= Changing a Drive's Volume Label =

PSS ID Number: 58650

Article Last Modified on 8/30/2001

-

The information in this article applies to:


 * Microsoft C for MS-DOS 5.1

-



This article was previously published under Q58650



SUMMARY
Changing a drive's volume label involves the use of FCB (file control block) file processing, and therefore is not supplied with the C run-time libraries. However, one of the ways to do this is through MS-DOS Interrupt 21h calls for FCB file manipulation.



MORE INFORMATION
Below is an assembly routine written with Microsoft MASM version 5.1 to change a drive's volume name. To do this, it first sets up an extended FCB to allow for manipulating files with attributes. Offset 6 of the FCB is set to 8 (_A_VOLID defined in DOS.H) to specify a volume. The old volume is searched for with &quot;*.*&quot; as a pattern and deleted, then the volume is re-created with the new volume label passed by the C caller. The function returns the error code supplied from the MS-DOS application programming interface (API) that creates the volume label.

Use the following: rc = NewVol( iDrive, szName ); // iDrive = Drive number ( 1, 2, ... ) // szName = Up to 11 chars. DOS filename // rc = Return Code from function. The new volume label must be passed with 11 characters for the name. Anything less MUST be padded with spaces.

Sample Code
;  unsigned NewVol( int, char * ) will delete a disk volume and
 * create one with the new name.
 * Assemble with /Dmodel={SMALL MEDIUM COMPACT LARGE}
 * /Dlang={C FORTRAN BASIC PASCAL}
 * /Dlang={C FORTRAN BASIC PASCAL}

%.MODEL model,lang

.DATA maxlen EQU     11                 ;Maximum name length datasz EQU      2                 ;Size of Data Pointers fcb    DB      255, 0, 0, 0, 0, 0, 8, 1 DB     37 DUP (?) default DB     '*       *  '      ;Equivalent to &quot;*.*&quot;
 * Setup an extended FCB

.CODE NewVol PROC USES si di es, Drive:WORD, VolName:WORD mov    bx,Drive           ;Get drive number ( 1 byte ) mov    fcb+7,bl           ;...and store in FCB offset 7 mov    ax,ds mov    es,ax cld                       ;Upward move mov    cx,maxlen          ;Size of move mov    si,OFFSET default  ;Source string to        mov     di,OFFSET fcb+8    ;...filename offset in 8 FCB rep    movsb              ;Move maxlen bytes of vol name mov    dx,OFFSET fcb      ;Delete volume off drive mov    ah,13H int    21H mov    cx,maxlen mov    si,VolName         ;New name passed by C caller mov    di,OFFSET fcb+8 rep    movsb              ;Copy 11 chars for new label mov    dx,OFFSET fcb      ;Create the new volume mov    ah,16H int    21H mov    dx,OFFSET fcb      ;Close the file mov    ah,10H int    21H mov    ah,0 ret NewVol ENDP END

Additional query words: kbinf 5.10

Keywords: KB58650

Technology: kbAudDeveloper kbCComp510DOS kbCCompSearch kbZNotKeyword3

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© 2004 Microsoft Corporation. All rights reserved.