Search the FAQ Archives

3 - A - B - C - D - E - F - G - H - I - J - K - L - M
N - O - P - Q - R - S - T - U - V - W - X - Y - Z
faqs.org - Internet FAQ Archives

comp.os.msdos.programmer FAQ part 3/5
Section - - How can I read, create, change, or delete the volume label?

( Part1 - Part2 - Part3 - Part4 - Part5 - Single Page )
[ Usenet FAQs | Web FAQs | Documents | RFC Index | Property taxes ]


Top Document: comp.os.msdos.programmer FAQ part 3/5
Previous Document: - How can my program open more files than DOS's limit of 20?
Next Document: - How can I get the disk serial number?
See reader questions & answers on this topic! - Help others by sharing your knowledge
Date: 5 Feb 2002 22:03:03 -0400

 In DOS 5.0 (and possibly in 4.0 as well), there are actually two volume
 labels: the LABEL command reports only the first but changes both of
 them.

 * The traditional volume label is an entry with "volume label" attribute
   in the root directory of the disk. The DIR, VOL, and LABEL commands
   report this volume label, and LABEL sets it.

 * There is a second volume label, which may be different, in the boot
   record along with the serial number. In DOS 4.0 and later, INT 21
   AH=69 gets or sets the boot record's serial number and volume label
   together; see <Q:05.13> [How can I get the disk serial number?] DIR
   and VOL ignore this volume label; the LABEL command doesn't report it
   but does set it.

 The rest of this answer assumes that by "volume label" you mean the
 traditional one, the one that DIR and VOL display. Though it's a
 directory entry in the root directory, you can't change it using the
 newer DOS file-access functions (INT 21 AH=3C, 41, 43); instead, use the
 old FCB-oriented directory functions. Specifically, you need to allocate
 a 64-byte buffer and a 41- byte extended FCB (file control block). Call
 INT 21 AH=1A to find out whether there is a volume label. If there is,
 AL returns 0 and you can change the label using DOS function 17 or
 delete it using DOS function 13. If there's no volume label, function 1A
 will return FF and you can create a label via function 16. Important
 points to notice are that ? wildcards are allowed but * are not; the
 volume label must be space filled not null terminated.

 The following MSC 7.0 code worked for me in DOS 5.0; the functions it
 uses have been around since DOS 2.0. The function parameter is 0 for the
 current disk, 1 for a:, 2 for b:, etc. It doesn't matter what your
 current directory is; these functions always search the root directory
 for volume labels. (I didn't try to change the volume label of any
 networked drives.)

   // Requires DOS.H, STDIO.H, STRING.H

   void vollabel(unsigned char drivenum)
   {
     static  unsigned  char  extfcb[41],  dta[64],  status,  *newlabel;
     int chars_got = 0;

     #define DOS(buff,func) __asm { __asm mov dx,offset buff  \
       __asm mov ax,seg buff  __asm push ds  __asm mov ds,ax  \
       __asm  mov  ah,func   __asm int  21h   __asm  pop  ds  \
       __asm mov status,al }

     #define getlabel(buff,prompt) newlabel = buff;  \
       memset(newlabel,' ',11);  printf(prompt);   \
       scanf("%11[^\n]%n", newlabel, &chars_got);  \
       if (chars_got < 11) newlabel[chars_got] = ' ';

     // Set up the 64-byte transfer area used by function 1A.
     DOS(dta, 1Ah)
  
     //  Set  up  an extended FCB and search for the  volume label.
     memset(extfcb, 0, sizeof extfcb);
     extfcb[0] = 0xFF;           // denotes extended FCB
     extfcb[6] = 8;              // volume-label attribute  bit
     extfcb[7] = drivenum;       // 1=A,2=B,...; 0=current drive
  
     memset(&extfcb[8], '?', 11);// wildcard *.*
     DOS(extfcb,11h)
     if(status == 0)
     {                           // DTA has volume  label's FCB
       printf("volume label is %11.11s\n", &dta[8]);
       getlabel(&dta[0x18], "new label (\"delete\" to delete): ");
      
       if(chars_got==0)
         printf("label not changed\n");
       else if (strncmp(newlabel,"delete  ",11) == 0)
       {
         DOS(dta,13h)
         printf(status ? "label failed\n":"label deleted\n");
       }
       else
       {                  // user wants to change label
         DOS(dta,17h)
         printf(status ? "label failed\n" : "label changed\n");
       }
     }
     else
     {                      // no volume label was found
       printf("disk has no volume label.\n");
       getlabel(&extfcb[8], "new label (<Enter>  for  none): ");

       if (chars_got > 0)
       {
         DOS(extfcb,16h)
         printf(status ? "label failed\n" : "label created\n");
       }
     }
   } // end function vollabel

User Contributions:

Comment about this article, ask questions, or add new information about this topic:

CAPTCHA




Top Document: comp.os.msdos.programmer FAQ part 3/5
Previous Document: - How can my program open more files than DOS's limit of 20?
Next Document: - How can I get the disk serial number?

Part1 - Part2 - Part3 - Part4 - Part5 - Single Page

[ Usenet FAQs | Web FAQs | Documents | RFC Index ]

Send corrections/additions to the FAQ Maintainer:
jeffrey@carlyle.org (Jeffrey Carlyle)





Last Update March 27 2014 @ 02:11 PM