From c73e37e45a2c6006a1575c6c1ff588aaeccc4837 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?N=C3=A9stor=20Soriano?= Date: Sun, 30 Aug 2020 15:35:29 +0200 Subject: [PATCH] Move UD_ACLU to the end of the unit descriptor (#72) The improvement of the cluster chain allocation process performance introduced a new unit descriptor field, UD_ACLU, in the middle of the unit descriptor (between UD_MBYTE and UD_CDIR). This caused severe problems when writing data (weird errors, computer crashes, even data corruption) because somewhere in the kernel there's code that assumed that these fields are stored consecutively in memory. The fix consists of moving UD_ACLU to the end of the unit descriptor. --- source/kernel/bank2/val.mac | 11 +++++++---- source/kernel/kvar.mac | 4 ++-- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/source/kernel/bank2/val.mac b/source/kernel/bank2/val.mac index def23ff8..1fedd15d 100644 --- a/source/kernel/bank2/val.mac +++ b/source/kernel/bank2/val.mac @@ -1852,7 +1852,7 @@ endif ; Assumes: UPB_DIRT=UPB_VOLID+6 UPB_ID=UPB_DIRT+1 ; (UD_CMSK, UD_CSHFT, UD_RES, UD_NFAT, UD_ODE, UD_WDS ; UD_SFAT, UD_SDIR, UD_SDAT, UD_NCLU, UD_DIRT, UD_ID, -; UD_MBYTE and UD_ACLU) must all be sequential. +; and UD_MBYTE) must all be sequential. ; ; call _NEW_UPB @@ -2157,9 +2157,12 @@ upb_dos220: ; from UPB to unit descriptor ld (hl),a - inc hl ;Initialize next cluster to check for allocation to 2 - ld (hl),1 ;(it's stored as value-1) - inc hl + pop hl + push hl + ld bc,UD_ACLU## + add hl,bc + ld (hl),1 ;Initialize next cluster to check for allocation to 2 + inc hl ;(it's stored as value-1) ld (hl),0 pop hl diff --git a/source/kernel/kvar.mac b/source/kernel/kvar.mac index 9900876d..61b86ec4 100644 --- a/source/kernel/kvar.mac +++ b/source/kernel/kvar.mac @@ -193,8 +193,6 @@ size macro name field 4,UD_ID ;Current volume ID field 1,UD_MBYTE ;Media descriptor byte - field 2,UD_ACLU ;Next cluster to check for allocation -1 -; field 2,UD_CDIR ;First cluster of current directory ; -ve => root directory ; 0000h => cluster not known @@ -209,6 +207,8 @@ size macro name ;(for device-based drivers this is only used if the driver ; provides configuration, in order to get the default mapping ; for the drive) + field 2,UD_ACLU ;Next cluster to check for allocation -1 + ; ;--- Extra fields used when mounting files ; This extra space should NOT be allocated unless a file is mounted to the drive