Skip to content

Commit b007d5f

Browse files
ecm-pushbxPerditionC
authored andcommitted
fatfs.c: fix to the fix to the fix, only write file size if appended
The prior revision incorrectly corrupted the file size even if just scanning the file, including for read. Move the code so it only runs after the very spot that found it is writing, needed to append a new cluster to the chain, and successfully did do that. Script for lDebug file to test this error: === testtrun.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, (#10240 >> 10) mov dx, (#10240 & FFFF) int 21 mov ah, 40 mov dx, 400 mov cx, 0 int 21 mov ah, 68 int 21 nop mov ax, 4200 xor cx, cx xor dx, dx int 21 mov dx, 800 mov ah, 3F mov cx, 380 int 21 int3 mov ah, 68 int 21 nop int3 nop jmp 100 . ===
1 parent 2b7c317 commit b007d5f

1 file changed

Lines changed: 11 additions & 6 deletions

File tree

kernel/fatfs.c

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1024,16 +1024,21 @@ COUNT map_cluster(REG f_node_ptr fnp, COUNT mode)
10241024
cluster = extend(fnp);
10251025
if (cluster == LONG_LAST_CLUSTER)
10261026
return DE_HNDLDSKFULL;
1027+
1028+
/* ecm: finally the right solution, only extend/modify
1029+
file size after having just appended a cluster. */
1030+
fnp->f_dir.dir_size =
1031+
(((ULONG)fnp->f_cluster_offset + 2)
1032+
/* at 0 we will increment to 1, having allocated the second
1033+
cluster, so + 2 for the then-total size. */
1034+
* (ULONG)fnp->f_dpb->dpb_secsize)
1035+
<<
1036+
fnp->f_dpb->dpb_shftcnt;
1037+
merge_file_changes(fnp, FALSE);
10271038
}
10281039

10291040
fnp->f_cluster = cluster;
10301041
fnp->f_cluster_offset++;
1031-
fnp->f_dir.dir_size =
1032-
(((ULONG)fnp->f_cluster_offset + 1)
1033-
* (ULONG)fnp->f_dpb->dpb_secsize)
1034-
<<
1035-
fnp->f_dpb->dpb_shftcnt;
1036-
merge_file_changes(fnp, FALSE);
10371042
}
10381043

10391044
#ifdef DISPLAY_GETBLOCK

0 commit comments

Comments
 (0)