Support for volume labels was first added to MS-DOS in version 2.0. A volume label is an optional name of from 1 to 11 characters that the user assigns to a disk during a FORMAT operation. You can display a volume label with the DIR, TREE, CHKDSK, or VOL command. Beginning with MS-DOS version 3.0, you can use the LABEL command to add, display, or alter the label after formatting. In MS-DOS version 4, the FORMAT program also assigns a semi-random 32-bit binary ID to each disk it formats; you can display this value, but you cannot change it.
The distinction between volumes and drives is important. A volume label is associated with a specific storage medium. A drive identifier (such as A) is associated with a physical device that a storage medium can be mounted on. In the case of fixed-disk drives, the medium associated with a drive identifier does not change (hence the name). In the case of floppy disks or other removable media, the disk accessed with a given drive identifier might have any volume label or none at all.
Hence, volume labels do not take the place of the logical-drive identifier and cannot be used as part of a pathname to identify a file. In fact, in MS-DOS version 2, the system does not use volume labels internally at all. In MS-DOS versions 3.0 and later, a disk driver can use volume labels to detect whether the user has replaced a disk while a file is open; this use is optional, however, and is not implemented in all systems.
MS-DOS volume labels are implemented as a special type of entry in a disk's root directory. The entry contains a time-and-date stamp and has an attribute value of 8 (i.e., bit 3 set). Except for the attribute, a volume label is identical to the directory entry for a file that was created but never had any data written into it, and you can manipulate volume labels with Int 21H functions much as you manipulate files. However, a volume label receives special handling at several levels:
When you create a volume label after a disk is formatted, MS-DOS always places it in the root directory, regardless of the current directory.
A disk can contain only one volume label; attempts to create additional volume labels (even with different names) will fail.
MS-DOS always carries out searches for volume labels in the root directory, regardless of the current directory, and does not also return all normal files.
In MS-DOS version 2, support for volume labels is not completely integrated into the handle file functions, and you must use extended FCBs instead to manipulate volume labels. For example, the code in Figure 9-4 searches for the volume label in the root directory of the current drive. You can also change volume labels with extended FCBs and the rename file function (Int 21H Function 17H), but you should not attempt to remove an existing volume label with Int 21H Function 13H under MS-DOS version 2, because this operation can damage the disk's FAT in an unpredictable manner.
In MS-DOS versions 3.0 and later, you can create a volume label in the expected manner, using Int 21H Function 3CH and an attribute of 8, and you can use the handle-type "search for first" function (4EH) to obtain an existing volume label for a logical drive (Figure 9-5). However, you still must use extended FCBs to change a volume label.
buff db 64 dup (?) ; receives search results
xfcb db 0ffh ; flag signifying extended FCB
db 5 dup (0) ; reserved
db 8 ; volume attribute byte
db 0 ; drive code (0 = current)
db 11 dup ('?') ; wildcard filename and extension
db 25 dup (0) ; remainder of FCB (not used)
.
.
.
; set DTA address for buffer
; used by search functions
mov dx,seg buff ; DS:DX = buffer address
mov ds,dx
mov dx,offset buff
mov ah,1ah ; function 1ah = set DTA
int 21h ; transfer to MS-DOS
; now search for label...
; DS:DX = extended FCB
mov dx,offset xfcb
mov ah,11h ; function 11h = search for first
int 21h ; transfer to MS-DOS
cmp al,0ffh ; search successful?
je no_label ; jump if no volume label
.
.
.
Figure 9-4. A volume-label search under MS-DOS version 2, using an extended file control block. If the search is successful, the volume label is returned in buff, formatted in the filename and extension fields of an extended FCB.
buff db 64 dup (?) ; receives search results
wildcd db '*.*',0 ; wildcard ASCIIZ filename
.
.
.
; set DTA address for buffer
; used by search functions
mov dx,seg buff ; DS:DX = buffer address
mov ds,dx
mov dx,offset buff
mov ah,1ah ; function 1ah = set DTA
int 21h ; transfer to MS-DOS
; now search for label...
; DS:DX = ASCIIZ string
mov dx,offset wildcd
mov cx,8 ; CX = volume attribute
mov ah,4eh ; function 4eh = search for first
int 21h ; transfer to MS-DOS
jc no_label ; jump if no volume label
.
.
.
Figure 9-5. A volume-label search under MS-DOS version 3, using the handle-type file functions. If the search is successful (carry flag returned clear), the volume name is placed at location buff+1EH in the form of an ASCIIZ string.