Acorn DFS and ADFS in B-Em (as a Master 128, not that it matters).
I am writing lines to a text file. !INDEX, three at a time, don't know in advance how long it will be, and have to open and close because I am swapping discs and filing systems in between each update -- and even stopping and starting in the middle of a batch.
The disc is empty to start with. I create the text file using OPENOUT, and on subsequent calls use OPENUP. I am also copying files to the same disc after each update. When !INDEX gets to 255 bytes or thereabouts I get 'can't extend' because the other files have been saved since it was created, leaving no room for it (as DFS doesn't do fragmented files).
Nothing unexpected there.
So to reserve room, I do this:
1. First create a temp file 6 sectors long, which should be plenty - Starts at sector 02)
2. Write another file to the disc, !BOOT in fact, (which gets saved just after it on the disc) - starts at sector 08
3. Delete the temporary file, leaving a hole for my text file.
4. As it's the first time, OPENOUT, write a couple lines, and close. I expect it to be created in the gap left by the temp file, but it actually starts at sector 09
5. Its EXT# is now quite small, but even if it had been located in the gap at 02, the hole would still be smaller than any other file that will be copied to it subsequently so it shouldn't get used.
6. Go into a loop where I open and update !INDEX, close it, copy a file from a different disc (which saves at 0A), swap discs and repeat.
How large a gap does it have to be before DFS allocates it to sector 02?
There is a partial workaround: If I name the temp file !INDEX and don't delete it explicitly, but open it with OPENOUT, DFS uses the right slot. The trouble with this is that I am testing for the existence of !INDEX and only OPENOUT on the first attempt, thereafter OPENingUP to append to it. I suppose the answer is a lock file, but I'd like to know if there's a better solution.
I also thought of keeping !INDEX &600 bytes long and marking the end of file with NUL, but I'd have to read the whole file on each iteration to find the marker, which again, would be better avoided.
My code:
Code: Select all
780 PROCswapdisc(FALSE ,"$",TRUE )
790 *SAVE !ZZZZ! E00 +600
800 H%=OPENOUT("!BOOT")
810 PROCwriteline(H%,"*BASIC")
820 PROCwriteline(H%,"*SHADOW")
830 PROCwriteline(H%,"CH."+CHR$ 34+"PPMenu"+CHR$ 34)
840 CLOSE #H%
850 *OPT 4,3
870 *DELETE !ZZZZ!
880 IF FNexists("!Index") ENDPROC
940 H%=OPENOUT("!Index")
950 IF H%=0 PRINTCHR$ 134"Index file could not be created!"
955 REM Write first two lines to index
960 PROCwriteline(H%,GAME$)
970 PROCwriteline(H%,VENUE$)
980 CLOSE #H%
990 ENDPROC