Skip to content

fatfs.c: update dir_size during map_cluster extend loop [fixes #241]#242

Merged
PerditionC merged 1 commit intoFDOS:masterfrom
ecm-pushbx:ecm-fix-partial-extend
Apr 21, 2026
Merged

fatfs.c: update dir_size during map_cluster extend loop [fixes #241]#242
PerditionC merged 1 commit intoFDOS:masterfrom
ecm-pushbx:ecm-fix-partial-extend

Conversation

@ecm-pushbx
Copy link
Copy Markdown
Contributor

Problem discussed in #241 With this fix, the partial extend loop updates the directory entry's file size field after allocating every cluster so that the final result is a file properly allocated all clusters left free prior.

To consider: Is map_cluster used by directory code? Will have to re-order this then so that subdirectories aren't given a nonzero size.

@ecm-pushbx
Copy link
Copy Markdown
Contributor Author

It appears that map_cluster is only called for files after all. I tested with a small loop like this in lDebug:

-a
29B2:0100 mov ah, 5a
29B2:0102 mov cx, 0
29B2:0105 mov dx, 200
29B2:0108
-e 200 "A:\FOO\" 0
-d 200 l 10
29B2:0200  41 3A 5C 46 4F 4F 5C 00-00 00 00 00 00 00 00 00 A:\FOO\.........
-a 108
29B2:0108 mov byte [207], 0
29B2:010D int 21
29B2:010F dec si
29B2:0110 jnz 100
29B2:0112 int3
29B2:0113
-r
AX=0000 BX=0000 CX=0000 DX=0000 SP=FFFE BP=0000 SI=0000 DI=0000
DS=29B2 ES=29B2 SS=29B2 CS=29B2 IP=0100 NV UP EI PL ZR NA PE NC
29B2:0100 B45A              mov     ah, 5A
-r si 200
-g

Then l 600 a: 0+1+9+9 1 and the directory entry for FOO ends in four zeroes (file size field).

@ecm-pushbx ecm-pushbx marked this pull request as ready for review April 21, 2026 16:29
@PerditionC PerditionC merged commit 6734c10 into FDOS:master Apr 21, 2026
2 checks passed
ecm-pushbx added a commit to ecm-pushbx/fdkernel that referenced this pull request Apr 22, 2026
Earlier fix was FDOS#242 (this got the
cluster value to use wrong).

Original problem recorded in FDOS#241

Reset disk scriptlet:

nasm -I ~/proj/lmacros/ ~/proj/bootimg/bootimg.asm \
  -D_PAYLOADFILE=::empty -o diskempt.img
cp -a ~/proj/kernel/bin/kernel.sys fdkernel.sys

Run dosemu2 with -I "floppy { device diskempt.img }"

After a test, run /sbin/dosfsck -n diskempt.img

The following Script for lDebug files are test cases:

=== testshrt.sld
e 200 "A:\test.dat" 0
f 300 l 100 26
a
 mov ah, 3C
 mov cx, 0
 mov dx, 200
 int 21
 xchg bx, ax
 mov ax, 4200
 mov cx, 1000
 mov dx, cx
 int 21
 mov dx, 300
 mov cx, 10
 mov ah, 3F
 int 21
 .
r v0 := aao
a
 mov ah, 40
 int 21
 int3
 int3
 jmp (v0)
 .

=== testfull.sld
e 200 "A:\test.dat" 0
f 400 l 400 38
a
 mov ah, 3C
 mov cx, 0
 mov dx, 200
 int 21
 xchg bx, ax
 mov ax, 4200
 mov cx, ((#1424 * #1024 - 1) >> 10)
 mov dx, ((#1424 * #1024 - 1) & FFFF)
 int 21
 mov ah, 40
 mov dx, 400
 mov cx, 1
 int 21
 mov ah, 68
 int 21
 mov ax, 4202
 mov cx, -1
 mov dx, -10
 int 21
 mov ah, 40
 mov dx, 400
 mov cx, 10
 int 21
 int3
 mov ah, 68
 int 21
 nop
 int3
 nop
 jmp 100
 .

=== testful2.sld
e 200 "A:\test.dat" 0
f 400 l 400 38
a
 mov ah, 3C
 mov cx, 0
 mov dx, 200
 int 21
 xchg bx, ax
 mov ax, 4200
 mov cx, ((#1424 * #1024 - #512 - 1) >> 10)
 mov dx, ((#1424 * #1024 - #512 - 1) & FFFF)
 int 21
 mov ah, 40
 mov dx, 400
 mov cx, 1
 int 21
 mov ah, 68
 int 21
 mov ax, 4202
 mov cx, -1
 mov dx, -10
 int 21
 mov ah, 40
 mov dx, 400
 mov cx, 10
 int 21
 int3
 mov ah, 68
 int 21
 nop
 int3
 nop
 jmp 100
 .

=== testful3.sld
e 200 "A:\test.dat" 0
f 400 l 400 38
a
 mov ah, 3C
 mov cx, 0
 mov dx, 200
 int 21
 xchg bx, ax
 mov ax, 4200
 mov cx, ((#1424 * #1024 - #512) >> 10)
 mov dx, ((#1424 * #1024 - #512) & FFFF)
 int 21
 mov ah, 40
 mov dx, 400
 mov cx, 0
 int 21
 mov ah, 68
 int 21
 mov ax, 4202
 mov cx, -1
 mov dx, -10
 int 21
 mov ah, 40
 mov dx, 400
 mov cx, 10
 int 21
 int3
 mov ah, 68
 int 21
 nop
 int3
 nop
 jmp 100
 .

===
PerditionC pushed a commit that referenced this pull request Apr 22, 2026
Earlier fix was #242 (this got the
cluster value to use wrong).

Original problem recorded in #241

Reset disk scriptlet:

nasm -I ~/proj/lmacros/ ~/proj/bootimg/bootimg.asm \
  -D_PAYLOADFILE=::empty -o diskempt.img
cp -a ~/proj/kernel/bin/kernel.sys fdkernel.sys

Run dosemu2 with -I "floppy { device diskempt.img }"

After a test, run /sbin/dosfsck -n diskempt.img

The following Script for lDebug files are test cases:

=== testshrt.sld
e 200 "A:\test.dat" 0
f 300 l 100 26
a
 mov ah, 3C
 mov cx, 0
 mov dx, 200
 int 21
 xchg bx, ax
 mov ax, 4200
 mov cx, 1000
 mov dx, cx
 int 21
 mov dx, 300
 mov cx, 10
 mov ah, 3F
 int 21
 .
r v0 := aao
a
 mov ah, 40
 int 21
 int3
 int3
 jmp (v0)
 .

=== testfull.sld
e 200 "A:\test.dat" 0
f 400 l 400 38
a
 mov ah, 3C
 mov cx, 0
 mov dx, 200
 int 21
 xchg bx, ax
 mov ax, 4200
 mov cx, ((#1424 * #1024 - 1) >> 10)
 mov dx, ((#1424 * #1024 - 1) & FFFF)
 int 21
 mov ah, 40
 mov dx, 400
 mov cx, 1
 int 21
 mov ah, 68
 int 21
 mov ax, 4202
 mov cx, -1
 mov dx, -10
 int 21
 mov ah, 40
 mov dx, 400
 mov cx, 10
 int 21
 int3
 mov ah, 68
 int 21
 nop
 int3
 nop
 jmp 100
 .

=== testful2.sld
e 200 "A:\test.dat" 0
f 400 l 400 38
a
 mov ah, 3C
 mov cx, 0
 mov dx, 200
 int 21
 xchg bx, ax
 mov ax, 4200
 mov cx, ((#1424 * #1024 - #512 - 1) >> 10)
 mov dx, ((#1424 * #1024 - #512 - 1) & FFFF)
 int 21
 mov ah, 40
 mov dx, 400
 mov cx, 1
 int 21
 mov ah, 68
 int 21
 mov ax, 4202
 mov cx, -1
 mov dx, -10
 int 21
 mov ah, 40
 mov dx, 400
 mov cx, 10
 int 21
 int3
 mov ah, 68
 int 21
 nop
 int3
 nop
 jmp 100
 .

=== testful3.sld
e 200 "A:\test.dat" 0
f 400 l 400 38
a
 mov ah, 3C
 mov cx, 0
 mov dx, 200
 int 21
 xchg bx, ax
 mov ax, 4200
 mov cx, ((#1424 * #1024 - #512) >> 10)
 mov dx, ((#1424 * #1024 - #512) & FFFF)
 int 21
 mov ah, 40
 mov dx, 400
 mov cx, 0
 int 21
 mov ah, 68
 int 21
 mov ax, 4202
 mov cx, -1
 mov dx, -10
 int 21
 mov ah, 40
 mov dx, 400
 mov cx, 10
 int 21
 int3
 mov ah, 68
 int 21
 nop
 int3
 nop
 jmp 100
 .

===
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants