{***********************************************************************}
{									}
{ __SetVlFil  Create or alter the volume label				}
{									}
{ function  __SetVlFil(Drive : char; VolLabel : string) : boolean;	}
{									}
{	      Drive	The drive whose volume label is altered.	}
{	      VolLabel	The label to assign to the disk.		}
{									}
{ Description __SetVlFil sets the volume label to the specified string. }
{	      The function uses DOS to create a file with attribute 8,	}
{	      and assigns the first eleven characters of VolLabel as	}
{	      the name.  The system date and time are used as the date	}
{	      of creation.  If the volume label already exists, it is	}
{	      changed, and if it does not a new label is created.  If	}
{	      there is not room on the disk for the new directory entry,}
{	      or the volume label is not a legal label (it contains a	}
{	      period), then the function value returned is FALSE (the	}
{	      label could not be created), otherwise TRUE is returned.	}
{									}
{ Version     4.00 (C)Copyright Blaise Computing Inc.  1987		}
{_______________________________________________________________________}

function __SetVlFil(Drive : char; VolLabel : string) : boolean;

  var
    ExtendedFcb : array[-7..36] of byte; { Extended File Control Block	}
    DTAPtr	: pointer;		 { Pointer to Disk Transfer Area}
    TempDTA	: array[0..44] of byte;
    DriveNo	: byte;
    Reg 	: registers;

  begin {__SetVlFil}

    { The current DTA must be saved and a new one established, because	}
    { the DOS functions used ($11) use the DTA. 			}

    DTAPtr  := __RetDTFil;	       { Get the current DTA address	}
    __SetDtFil(@TempDTA);	       { Use the work area DTA		}

    DriveNo := byte(Upcase(Drive)) - byte('A') + 1;

    { Set up the extended file control block for a call to DOS function }
    { $11 to see if a volume label already exists.			}

    ExtendedFcb[-7] := $FF;	       { This is an extended FCB	}
    ExtendedFcb[-1] := $08;	       { Attribute 8 = volume label	}
    ExtendedFcb[0]  := DriveNo;
    FillChar(ExtendedFcb[1],11,$3F);   { Search on '???????? ???'	}
    FillChar(ExtendedFcb[12],25,0);    { Reset the rest to zeros	}

    with Reg do
      begin
	AH := $11;
	DS := Seg(ExtendedFcb);
	DX := Ofs(ExtendedFcb);
	Intr(_DOS,Reg);

	if (AL = $FF) then	       { Volume label was not found, so }
	   begin		       { we create the file.		}
	     FillChar(ExtendedFcb[1],11,$20);  { Initialize to blanks	}
	     Move(VolLabel[1],ExtendedFcb[1],Length(VolLabel));
	     AH := $16;
	     DS := Seg(ExtendedFcb);
	     DX := Ofs(ExtendedFcb);
	     Intr(_DOS,Reg);
	     if (AL = $FF) then        { Could not create the file.	}
		__SetVlFil := FALSE
	     else
		begin
		  __SetVlFil := TRUE;	   { But now close the file, so }
		  AH := $10;		   { the directory gets updated.}
		  DS := Seg(ExtendedFcb);  { Use DOS function call $10. }
		  DX := Ofs(ExtendedFcb);
		  Intr(_DOS,Reg)
		end
	   end
	else			       { Volume label was found, so	}
	   begin		       { modify it using function $17.	}
	     Move(TempDTA,ExtendedFcb[-7],39);
	     FillChar(ExtendedFcb[12],25,0);
	     FillChar(ExtendedFcb[17],11,$20);	{ Initialize with blanks}
	     Move(VolLabel[1],ExtendedFcb[17],Length(VolLabel));
	     AH := $17;
	     DS := Seg(ExtendedFcb);
	     DX := Ofs(ExtendedFcb);
	     Intr(_DOS,Reg);
	     __SetVlFil := (AL = 0)
	   end
      end;
    __SetDtFil(DTAPtr)		       { Restore the previous DTA	}

  end;	{SetVlFil}
