home *** CD-ROM | disk | FTP | other *** search
- unit vl;
- {
- A volume labeling unit for Turbo Pascal 4.0
- Author places no restrictions on code usage and accepts no responsibility
- for performance or problems arising from usage.
- Version 01.00.00, 28-Feb-88, Stuart Johnson, CompuServe 71331,1716
- ^ ^ ^
- | | |
- | | correction, zeroed after modification
- | modification, zeroed after rewrite to new base
- Base version
-
- Note: Some of the code in these routines is duplicated DELIBERATELY because
- it sets up a xfcb for supsequent operations... these routines do not
- call each other.
- }
-
- interface
-
- uses dos;
-
- const vl_success = 0;
- vl_disk = 1;
- vl_label = 2;
- vl_create = 3;
- vl_rename = 4;
- vl_delete = 5;
- vl_nolabel = 6;
-
- type label_type = array[1..11] of char;
-
- type
- xfcb = record { not necessarily the definitive format for xfcb }
- flag : byte;
- fill1 : array[1..5] of byte;
- attr : byte;
- drive : byte;
- old_name : label_type;
- fill2 : array[1..5] of byte;
- new_name : label_type;
- fill3 : array[1..8] of char;
- end;
-
-
-
- {==============================================================}
- function put_volume_label(disk : byte; in_vlabel : string):byte;
- {
- Procedure to add or change the volume label on a specified drive.
- Many thanks to the author of LABEL.PAS, a Turbo 3 volume label program,
- and to Borland for SEG and OFS, which made this easy..
-
-
- Input : byte specifying disk drive. 1 = A, 2 = B...
- string containing new label. Only uses left 11 characters, pads
- with spaces if input less than 11.
-
- Output: vl_success = success
- vl_disk = invalid drive number
- vl_label = invalid volume label
- vl_create = create failure
- vl_rename = rename failure
-
-
- Notes:
- vl_disk, invalid drive number is asserted if drive < 1 or > 26.
-
- vl_label, invalid volume label can be caused by a blank or non-left
- justified label. Volume labels, like filenames, cannot begin with
- spaces.
-
- An error reading the disk in the wildcard search will cause error
- vl_create to be returned because the code assumes wildcard lookup
- failures are ALL due to the file (volume label) not being found.
- If the disk is write protected, the file creation will also fail,
- causing error vl_create.
-
- An error vl_rename, renaming the volume, is almost certainly due the
- the disk being write-protected.
- }
-
-
-
- {==============================================}
- function delete_volume_label(disk : byte): byte;
- {
- Function to delete a volume label.
-
- Input: drive number 1..26
- Output: vl_success = success
- vl_delete = delete failed
- vl_nolabel = could not delete.. no label on volume
-
- Notes: vl_delete may be caused by
- 1) volume label read-only
- 2) disk write protected
-
- vl_nolabel may be caused by
- 1) no label on disk
- 2) no disk in drive
- }
-
-
-
- {=============================================================}
- function get_volume_label(disk : byte; var str : string): byte;
- {
- Function to get a volume label
-
- Input: drive number 1..26
- Output: vl_success = success
- vl_nolabel = no label
-
- Notes: vl_nolabel may be caused by
- 1) no volume label on disk
- 2) no disk in drive
- }
-
-
-
- implementation
-
-
-
- {==============================================================}
- function put_volume_label(disk : byte; in_vlabel : string):byte;
-
-
- var xfcb1, { for file lookup }
- xfcb2 : xfcb; { dummy returned by file lookup }
- regs : registers;
- new_label : label_type;
- vlabel : string[11]; { input may not be large enough to pad to 11 }
-
-
- begin
- put_volume_label := vl_success; { assume success }
-
- if (disk < 1) or (disk > 26) then
- begin
- put_volume_label := vl_disk;
- exit;
- end;
-
- vlabel := in_vlabel;
- while length(vlabel) < 11 do vlabel := vlabel + ' '; { pad to 11 }
- move(vlabel[1],new_label,11);
- if new_label[1] = ' ' then { cannot be blank! }
- begin
- put_volume_label := vl_label;
- exit;
- end;
-
- with xfcb1 do
- begin
- flag := $ff; { fcb type is extended }
- attr := $8; { attribute = volume label }
- fillchar(fill1,5,0);
- drive := disk;
- fillchar(old_name,11,'?');
- fillchar(new_name,11,0);
- fillchar(fill2,4,0);
- fillchar(fill3,9,0);
- end;
-
- with regs do
- begin
-
- ds := seg(xfcb2); { xfcb2 will recieve a psuedo xfcb from dos }
- dx := ofs(xfcb2); { containing info from wildcard dir lookup }
- ax := $1A shl 8; { ah = $1A, al = 0 }
- msdos(regs); { set disk transfer area }
-
- ds := seg(xfcb1); { point to xfcb specifying files to look for }
- dx := ofs(xfcb1);
- ax := $11 shl 8; { ah = $11, al = 0 }
- msdos(regs); { search for first }
-
- if al = $ff then { no label found, create volume label }
- begin
- xfcb1.old_name := new_label;
- ds := seg(xfcb1); { point to xfcb specifying file to create }
- dx := ofs(xfcb1);
- ax := $16 shl 8; { ah = $16, al = 0 }
- msdos(regs); { create file }
- if al = $ff then put_volume_label := vl_create;
- end
- else { has a label, rename it }
- begin
- xfcb2.new_name := new_label;
- ds := seg(xfcb2); { point at xfcb recieved during wildcard lookup }
- dx := ofs(xfcb2);
- ax := $17 shl 8; { ah = $17, al = 0 }
- msdos(regs); { rename file }
- if al = $ff then put_volume_label := vl_rename;
- end;
- end;
- end;
-
-
-
- {=============================================}
- function delete_volume_label(disk : byte):byte;
-
- var xfcb1,
- xfcb2 : xfcb;
- regs : registers;
-
- begin
- delete_volume_label := vl_success;
- with xfcb1 do
- begin
- flag := $ff; { fcb type is extended }
- attr := $8; { attribute = volume label }
- fillchar(fill1,5,0);
- drive := disk;
- fillchar(old_name,11,'?');
- fillchar(new_name,11,0);
- fillchar(fill2,4,0);
- fillchar(fill3,9,0);
- end;
-
- with regs do
- begin
-
- ds := seg(xfcb2); { xfcb2 will recieve a psuedo xfcb from dos }
- dx := ofs(xfcb2); { containing info from wildcard dir lookup }
- ax := $1A shl 8; { ah = $1A, al = 0 }
- msdos(regs); { set disk transfer area }
-
- ds := seg(xfcb1); { point to xfcb specifying files to look for }
- dx := ofs(xfcb1);
- ax := $11 shl 8; { ah = $11, al = 0 }
- msdos(regs); { search for first }
- if al = $ff then
- begin
- delete_volume_label := vl_nolabel;
- exit;
- end
- else
- begin
- ds := seg(xfcb1); { point to xfcb specifying file to delete }
- dx := ofs(xfcb1);
- ax := $13 shl 8; { ah = $13, al = 0 }
- msdos(regs); { delete file }
- if al = $ff then delete_volume_label := vl_delete;
- end;
- end;
- end;
-
-
-
- {==================================================}
- function get_volume_label(disk : byte; var str : string);
-
- var xfcb1,
- xfcb2 : xfcb;
- regs : registers;
-
- begin
- with xfcb1 do
- begin
- flag := $ff; { fcb type is extended }
- attr := $8; { attribute = volume label }
- fillchar(fill1,5,0);
- drive := disk;
- fillchar(old_name,11,'?');
- fillchar(new_name,11,0);
- fillchar(fill2,4,0);
- fillchar(fill3,9,0);
- end;
-
- with regs do
- begin
-
- ds := seg(xfcb2); { xfcb2 will recieve a psuedo xfcb from dos }
- dx := ofs(xfcb2); { containing info from wildcard dir lookup }
- ax := $1A shl 8; { ah = $1A, al = 0 }
- msdos(regs); { set disk transfer area }
-
- ds := seg(xfcb1); { point to xfcb specifying files to look for }
- dx := ofs(xfcb1);
- ax := $11 shl 8; { ah = $11, al = 0 }
- msdos(regs); { search for first }
- if al = $ff then get_volume_label := vl_nolabel
- else
- begin
- get_volume_label := vl_success;
- str := xfcb2.old_name;
- end;
- end;
- end;
-
- end. { unit }