The Programmer's Guide to TRSDOS Version 6 - Tim Mann's Home ...
The Programmer's Guide to TRSDOS Version 6 - Tim Mann's Home ...
The Programmer's Guide to TRSDOS Version 6 - Tim Mann's Home ...
Create successful ePaper yourself
Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.
does exist, @RENAME should return either an "Illegal access <strong>to</strong> protected file" error (if<br />
you do not have RENAME permission) or an "Illegal file name" error due <strong>to</strong> the duplicate<br />
name. <strong>The</strong> @RENAME method uses slightly less system overhead and thus will execute faster.<br />
It also will not attempt <strong>to</strong> set the direc<strong>to</strong>ry's "file open bit" thereby performing one<br />
less direc<strong>to</strong>ry write.<br />
6.2.4 Closing Files<br />
<strong>The</strong> reverse operation of opening a file, be it @INIT or @OPEN, is the CLOSE operation.<br />
Remember that files opened with UPDATE or greater access must be closed in order <strong>to</strong><br />
update the direc<strong>to</strong>ry entry record. <strong>The</strong> updating process will change the modification date<br />
and set the MODification flag bit if any writing has occurred. <strong>The</strong> updating process also<br />
alters the end-of-file information if a sequentially accessed file has been either<br />
extended or shortened. Finally, the updating process resets the "file open bit". <strong>The</strong><br />
CLOSE operation uses the information that the system has been maintaining in the FCB .<br />
Thus, you close a file simply by passing the FCB pointer <strong>to</strong> the SuperVisor Call as<br />
follows:<br />
LD DE,FCB1 ;Point <strong>to</strong> the open File Control Block<br />
LD A,@CLOSE ;Identify the SVC<br />
RST 40 ;Invoke the SVC<br />
JP NZ,IOERR ;Transfer on a returned error<br />
6.2.5 Miscellaneous File Control<br />
Before we leave the <strong>to</strong>pic of file control let's address some lesser used control<br />
requests. First we have the removal of a file. <strong>The</strong> system's REMOVE library command can<br />
delete a file from the disk when at DOS Ready or command level. You could also remove a<br />
file by passing a "REMOVE filespec" command line <strong>to</strong> the system via the @CMNDR SuperVisor<br />
Call request. If we consider the DOS command level <strong>to</strong> be the highest level, then the<br />
lowest level is via assembly language SVCs. <strong>The</strong> SVC method of file removal requires that<br />
the file first be opened. <strong>The</strong> reason for this requirement is based on the overlay<br />
structure of the system. <strong>The</strong> file control routines are resident in system overlays rather<br />
than in the memory resident portion of the system like the file access routines. It so<br />
happens that the routines <strong>to</strong> open a file are in an overlay (SYS2) different from the<br />
overlay containing the routines <strong>to</strong> remove a file (SYS10). Since the system has no<br />
provision for system overlays <strong>to</strong> invoke functions in other overlays, your application<br />
program "supervises" the two functions of opening and removal. This linkage is as<br />
follows:<br />
LD DE,FCB1 ;Point <strong>to</strong> the FCB holding the filespec<br />
LD A,@OPEN ;Identify the SVC<br />
RST 40 ;Invoke the SVC<br />
JR Z,OPENOK ;Continue if no open error<br />
CP 42 ;Check on "LRL open fault"<br />
JR NZ,RMVERR ;Error if anything else<br />
OPENOK LD A,@REMOV ;Identify the SVC<br />
RST 40 ;Invoke the SVC<br />
RMVERR JP NZ,IOERR ;Transfer on a returned error<br />
Notice that we did not need <strong>to</strong> reference a disk file I/O buffer since no I/O was going <strong>to</strong><br />
be performed (why waste the three bytes for the instruction?). Also, since we are going<br />
<strong>to</strong> ignore "LRL open fault" errors, there is no need <strong>to</strong> put an LRL value in<strong>to</strong> register B.<br />
When the system removes a file, it first deallocates the space taken up by the file by<br />
resetting the appropriate bits in the Granule Allocation Table. In the deallocation<br />
process, all of the file's extended direc<strong>to</strong>ry entry (FXDE) records are zeroed and their<br />
corresponding Direc<strong>to</strong>ry Entry Code (DEC) positions freed for future use. <strong>The</strong>n the hash<br />
code is removed from the file's primary direc<strong>to</strong>ry entry (FPDE) record DEC position of the<br />
Hash Index Table used by the file. Finally, the ACTIVE bit of the FPDE record is reset.<br />
<strong>The</strong> rest of the information in the FPDE is left unaltered. It is thus possible <strong>to</strong><br />
"unremove" a file that had a maximum of four extents by activating its FPDE, res<strong>to</strong>ring<br />
6-8