From mboxrd@z Thu Jan 1 00:00:00 1970 From: Tom Rini Date: Fri, 7 Feb 2020 19:05:48 -0500 Subject: [U-Boot] [PATCH v4 1/6] fat: write: fix broken write to fragmented files In-Reply-To: <20191202111118.12868-2-m.szyprowski@samsung.com> References: <20191202111118.12868-1-m.szyprowski@samsung.com> <20191202111118.12868-2-m.szyprowski@samsung.com> Message-ID: <20200208000548.GK13379@bill-the-cat> List-Id: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: u-boot@lists.denx.de On Mon, Dec 02, 2019 at 12:11:13PM +0100, Marek Szyprowski wrote: > 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 > > This patch partially fixes the issue revealed by the following test > script: > > --->8-fat_test1.sh--- > #!/bin/bash > make sandbox_defconfig > make > dd if=/dev/zero of=/tmp/10M.img bs=1024 count=10k > mkfs.vfat -v /tmp/10M.img > cat >/tmp/cmds < x > host bind 0 /tmp/10M.img > fatls host 0 > mw 0x1000000 0x0a434241 0x1000 # "ABC\n" > mw 0x1100000 0x0a464544 0x8000 # "DEF\n" > fatwrite host 0 0x1000000 file0001.raw 0x1000 > fatwrite host 0 0x1000000 file0002.raw 0x1000 > fatwrite host 0 0x1000000 file0003.raw 0x1000 > fatwrite host 0 0x1000000 file0004.raw 0x1000 > fatwrite host 0 0x1000000 file0005.raw 0x1000 > fatrm host 0 file0002.raw > fatrm host 0 file0004.raw > fatls host 0 > fatwrite host 0 0x1100000 file0007.raw 0x4000 > fatwrite host 0 0x1100000 file0007.raw 0x4000 > reset > EOF > ./u-boot #verify > rm -r /tmp/result /tmp/model > mkdir /tmp/result > mkdir /tmp/model > yes ABC | head -c 4096 >/tmp/model/file0001.raw > yes ABC | head -c 4096 >/tmp/model/file0003.raw > yes ABC | head -c 4096 >/tmp/model/file0005.raw > yes DEF | head -c 16384 >/tmp/model/file0007.raw > mcopy -n -i /tmp/10M.img ::file0001.raw /tmp/result > mcopy -n -i /tmp/10M.img ::file0003.raw /tmp/result > mcopy -n -i /tmp/10M.img ::file0005.raw /tmp/result > mcopy -n -i /tmp/10M.img ::file0007.raw /tmp/result > hd /tmp/10M.img > if diff -urq /tmp/model /tmp/result > then > echo Test okay > else > echo Test fail > fi Applied to u-boot/master, thanks! -- Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 833 bytes Desc: not available URL: