[comp.lang.c] Volume labels from MS-DOS function calls

tjones@killer.UUCP (Tim Jones) (08/01/87)

I need an algorithm for reading/writing the volume label of a diskette
from MS-DOS 2.11.

I *almost* know how to get the job accomplished with the use of function 
calls to examine the directory information at sectors 5-11, but I just
can't seem to make it work quite right.

I think this can also be done by using the "search for first match" 
function (0x4E).

If anybody has a C algorithm for doing this, I'd really appreciate a
copy, or if not, just some advice on how to write an effective one 
myself.

Thanks in advance,
Tim.

killer!tjones

PEPRBV@cfaamp.bitnet (08/03/87)

Tim Jones <tjones@killer.uucp> asks
>I need an algorithm for reading/writing the volume label of a diskette
>from MS-DOS 2.11.

I have successfully read and written volume labels using a C program to
issue DOS calls under MS-DOS 2.11.  First a few warnings about DOS bugs
(I don't know if these have been fixed under DOS 3.x):

1. You cannot use functions 0x4e and 0x4f to read volume labels.  If
   the volume label is the first entry in the directory it will not be
   found, and if the label contains blanks it will not be read properly.
2. You should not use function 0x13 to erase a volume label.  This will
   clobber the file access table entry for the first file on the disk,
   at least if this file is a hidden system file.  I don't know how to
   remove a volume label with a DOS call (short of doing absolute disk
   writes to the directory), but you can use function 0x17 to rename.
3. You cannot create or rename volumes with illegal names, i.e. no
   lower case letters.

To read a volume label, first use function 0x1a to set the DTA (disk
transfer address) to point to an unopened (extended) FCB.  In the FCB,
set the flag to 0xff, the attribute to 0x08, the appropriate drive
number, and file name to "???????????".  Then use function 0x11 to
search for a matching entry.

Writing or renaming are similar; use function 0x16 or 0x17.  It
may also be a good idea to issue function 0x0d to flush disk buffers
before doing anything, although the only case I have seen where this
seemed necessary was with a defective disk cache utility, and it
didn't help.

If this isn't enough to get you going, I can send you my code for
writing labels.  However, the code I use for reading labels is a
modification of source code which cam with my compiler, and thus is
still covered by the license agreement.

I figured out most of this by disassembling 2 volume labeling
utilities and reading between the lines of my DOS manual.  But it
is spelled out on page 158 of Advanced MS-DOS by Ray Duncan and
Microsoft Press