Changing a Drive's Volume LabelLast reviewed: April 4, 1995Article ID: Q58650 |
The information in this article applies to:
SUMMARYChanging 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 INFORMATIONBelow 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 "*.*" 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}%.MODEL model,lang .DATA maxlen EQU 11 ;Maximum name length datasz EQU 2 ;Size of Data Pointers; Setup an extended FCB fcb DB 255, 0, 0, 0, 0, 0, 8, 1 DB 37 DUP (?) default DB '* * ' ;Equivalent to "*.*".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 retNewVol ENDP END |
Additional reference words: kbinf 5.10
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |