Path: utzoo!attcan!uunet!lll-winken!lll-tis!ames!necntc!ima!cfisun!lakart!dg From: dg@lakart.UUCP (David Goodenough) Newsgroups: comp.os.cpm Subject: Re: file truncation in CP/M 2.2? Message-ID: <144@lakart.UUCP> Date: 2 Jun 88 14:25:49 GMT References: <8806010017.AA28247@newton.arpa> Organization: Lake - The systems people Lines: 40 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 +-+-+ | +---+