<< Previous Message Main Index Next Message >>
<< Previous Message in Thread This Month Next Message in Thread >>
Date   : Thu, 02 Jun 1988 14:25:49 GMT
From   : necntc!ima!cfisun!lakart!dg@ames.arc.nasa.gov (David Goodenough)
Subject: file truncation in CP/M 2.2?

From article <8806010017.AA28247@newton.arpa>, by bridger%newton@RAND-UNIX.ARPA
(Bridger Mitchell):
> 
> Unlike CP/M Plus, CP/M 2.2 has no truncate-file function.  This
> is a useful function when a large file (e.g. a database or library file)
> needs to be "lopped off", or packed down, and there's a lack of disk
> space to create a temporary duplicate file.
> 
> Is there a portable method of truncating a CP/M 2.2 file, using only
> BDOS calls?

[description of how to do it]

Yes - changing the file size (.fcb + 0fh) will do what you want - this is
how xsub works.

> BUT...what can be done if the truncation results in eliminating the
> last physical extent(s)?
> ..... But this can't be done by BDOS calls.  Or can it?

No it can't. but it CAN be done portably with BIOS calls. By inspecting
the bios tables (use the "get dpb address" function from bdos) you can
figure out exactly where the directory is, and how big it is. Now keep
on reading directory sectors using bios till you hit the one with the
extent that you want to nuke. Now just replace the first byte in the 32
byte entry with 0e5h, write it back (see caveat) and voila!
CAVEAT: whatever you do, when you write this sector back, reuse the
bios select disk, track, and sector routines, AND MAKE SURE C CONTAINS 1.
At least one bios I've seen destroys the track/sector info on each
read/write, so it's a good idea to reset them. Setting C to 1 forces
the write to happen: usually on bioses where the sector size is
greater than 128 bytes (i.e. all 5.25" DD versions) when a write happens,
the data is just buffered, and only gets flushed when another write to a
different sector occurs. By making C == 1, it forces the bios to write,
hence the directory is kept up to date.

Easy Huh? :-) :-)
-- 
       dg@lakart.UUCP - David Goodenough               +---+
                                                       | +-+-+
       ....... !harvard!adelie!cfisun!lakart!dg        +-+-+ |
                                                         +---+

<< Previous Message Main Index Next Message >>
<< Previous Message in Thread This Month Next Message in Thread >>