S1: the write side learns to stream
osFileStart, osFileWrite and osFileDone are the mirror of osFileInfo and osFileBlock. A program can now write a file it never holds: Pour writes twelve blocks and a tail while keeping 256 bytes of it at a time, and the host tool reads all 3,112 bytes back with every block where it was put. ONE WRITE IS OPEN AT A TIME AND COSMOS HOLDS IT. Reading needs no state - a name and an index are the whole question - but writing safely does, because the new file has to exist before the old one is thrown away and something has to remember which temporary belongs to which name. Keeping that here means the careful order is written once instead of in every program that streams. Nothing already on the disk is touched until osFileDone, so a disk without room says so while the old file is still there. That is stronger than osFileSave can manage, where the size is only known once the caller has every byte in hand. osFileSave stays: Edit and Files hand over whole documents and have no reason to learn any of this. osFileWrite refuses an index past the end of the file, and that refusal is not politeness. Files are contiguous, so block nine of a three block file is a real block belonging to something else, and writing it would put one file's bytes inside another with nothing anywhere saying so. Checked both ways: the tail block is allowed and the one past it is not. Three bugs, all of them the same shape - a register or pointer used for two things at once: DP3 carried the block count in and was popped high byte first, which is the wrong way round from every reader in the system and made the count two hundred and fifty six times too big. sbfsStreamStart took the name in DP0 and then wanted DP0 for something else before it had read it, so it walked whatever it last pointed at and reported that it could find no room. sbfsStreamWrite kept the caller's block in DP3 across a find - DP3 being the pointer a return does not put back, which is exactly why the find uses it too. What went to the disk was whatever the scan last looked at. It goes in memory now, and the file is correct because every block says which block it is; a check on the length alone would have passed all three of these. Writing no longer finds the file for each block either. Nothing moves a file once it is made, so where it starts is settled when the temporary is created. That was not even slow - a scan stops the moment it matches - but it was a walk of the directory per block for an answer that cannot change, and it is 28 per cent of the cost of writing forty blocks. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01E2JrLzFvuFX9fgi1LDRjrW
This commit is contained in:
co-authored by
Claude Opus 5
parent
7cd5e34347
commit
9f7dffdeca
@@ -110,6 +110,38 @@ else
|
||||
report FAIL "a file down a path" "$(cmp host.img machine.img 2>&1 | head -1)"
|
||||
fi
|
||||
|
||||
# ---- A file written a block at a time ----
|
||||
#
|
||||
# The machine never holds more than 256 bytes of this file, and the host reads it back
|
||||
# whole. Every block is filled with a byte that says which block it is, so a block written
|
||||
# into the wrong place of the file is visible rather than merely being the right length -
|
||||
# which is the failure this actually had while it was being built, and the one a check on
|
||||
# the size alone would have passed.
|
||||
#
|
||||
# The last block is a part block on purpose. A tail is where every off-by-one in a
|
||||
# filesystem hides.
|
||||
"$ASM" -I "$ROOT/Programs/CosmOS/Source" \
|
||||
"$ROOT/Programs/CosmOS/Apps/Pour.asm" -o Pour.sbx >/dev/null 2>&1
|
||||
"$TOOL" format poured.img 256 2 >/dev/null
|
||||
"$TOOL" put poured.img Pour.sbx >/dev/null
|
||||
printf 'Pour 12\nexit\n' | "$EMU" cosmos.bin --fast --disk poured.img >/dev/null 2>&1
|
||||
"$TOOL" get poured.img poured.dat gotPoured.dat >/dev/null 2>&1
|
||||
|
||||
if [ -f gotPoured.dat ] && [ "$(wc -c < gotPoured.dat | tr -d ' ')" = "3112" ]; then
|
||||
report ok "streamed out block by block" "3112 bytes, twelve blocks and a tail"
|
||||
else
|
||||
report FAIL "streamed out block by block" "wanted 3112 bytes, got $(wc -c < gotPoured.dat 2>/dev/null || echo nothing)"
|
||||
fi
|
||||
|
||||
# Every byte has to name the block it came from, or a block went somewhere else.
|
||||
if od -An -v -tu1 gotPoured.dat 2>/dev/null | awk '
|
||||
{ for (i = 1; i <= NF; i++) { if ($i != 65 + int(n / 256)) bad = 1; n++ } }
|
||||
END { exit (bad ? 1 : 0) }'; then
|
||||
report ok "and every block landed" "each byte names its own block"
|
||||
else
|
||||
report FAIL "and every block landed" "a block is not where it was written"
|
||||
fi
|
||||
|
||||
# ---- And each can read what the other wrote ----
|
||||
#
|
||||
# Matching bytes and being readable are not the same claim. A field both of them write
|
||||
|
||||
@@ -3,11 +3,11 @@ CosmOS
|
||||
> two stops, and what the registers were at each
|
||||
break at 400E
|
||||
A 11 B 22 Q 00 status 00
|
||||
DP0 2030 DP1 09C4 DP2 0000 DP3 4000 SP FFFF
|
||||
DP0 2030 DP1 09F0 DP2 0000 DP3 4000 SP FFFF
|
||||
press a key
|
||||
break at 4023
|
||||
A 44 B 55 Q 00 status 00
|
||||
DP0 2000 DP1 09C4 DP2 0000 DP3 4000 SP FFF5
|
||||
DP0 2000 DP1 09F0 DP2 0000 DP3 4000 SP FFF5
|
||||
press a key
|
||||
carried on to the end
|
||||
finished
|
||||
|
||||
@@ -416,6 +416,7 @@ app-Files | CosmOS/Apps/Files.asm | assemble | -
|
||||
app-Stream | CosmOS/Apps/Stream.asm | assemble | - | -
|
||||
app-Type | CosmOS/Apps/Type.asm | assemble | - | -
|
||||
app-Wander | CosmOS/Apps/Wander.asm | assemble | - | -
|
||||
app-Pour | CosmOS/Apps/Pour.asm | assemble | - | -
|
||||
app-More | CosmOS/Apps/More.asm | assemble | - | -
|
||||
# The assembler that runs on the machine, and its parts. Checked on their own so that a
|
||||
# failure reads as "it does not assemble" rather than as a broken disk image.
|
||||
|
||||
Reference in New Issue
Block a user