fat: write: fix broken write to fragmented files
authorMarek Szyprowski <m.szyprowski@samsung.com>
Fri, 13 Sep 2019 11:54:08 +0000 (13:54 +0200)
committerJaehoon Chung <jh80.chung@samsung.com>
Tue, 20 Oct 2020 06:13:47 +0000 (15:13 +0900)
The code for handing file overwrite incorrectly assumed that the file on
disk is always contiguous. This resulted in corrupting disk structure
every time when write to existing fragmented file happened. Fix this
by adding proper check for cluster discontinuity and adjust chunk size
on each partial write.

Signed-off-by: Marek Szyprowski <m.szyprowski@samsung.com>
Reviewed-by: Oleksandr Suvorov <oleksandr.suvorov@toradex.com>
Reviewed-by: Lukasz Majewski <lukma@denx.de>
Change-Id: Ic32563cd9e1fc34efd153d94ecd34de4de80e8b2
Signed-off-by: Jaehoon Chung <jh80.chung@samsung.com>
fs/fat/fat_write.c

index a2682b5f4655328d4065a9fd643e64d4ba18c56f..d7fdc56c8259a303414c6509308da9eb35cbcc32 100644 (file)
@@ -832,7 +832,6 @@ set_contents(fsdata *mydata, dir_entry *dentptr, loff_t pos, __u8 *buffer,
                        offset = pos - cur_pos;
                wsize = min_t(unsigned long long, actsize, filesize - cur_pos);
                wsize -= offset;
-
                if (get_set_cluster(mydata, curclust, offset,
                                    buffer, wsize, &actsize)) {
                        printf("Error get-and-setting cluster\n");