From: Lukasz Majewski <lukma@denx.de>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH 1/3] fat: write: fix broken write to fragmented files
Date: Mon, 16 Sep 2019 23:38:01 +0200 [thread overview]
Message-ID: <20190916233801.656c39aa@jawa> (raw)
In-Reply-To: <20190916122417.27520-2-m.szyprowski@samsung.com>
Hi Marek,
> 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>
> ---
> fs/fat/fat_write.c | 6 +++---
> 1 file changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/fs/fat/fat_write.c b/fs/fat/fat_write.c
> index 729cf39630d..6cfa5b45652 100644
> --- a/fs/fat/fat_write.c
> +++ b/fs/fat/fat_write.c
> @@ -794,6 +794,8 @@ set_contents(fsdata *mydata, dir_entry *dentptr,
> loff_t pos, __u8 *buffer,
> newclust = get_fatent(mydata, endclust);
>
> + if ((newclust - 1) != endclust)
> + break;
> if (IS_LAST_CLUST(newclust, mydata->fatsize))
> break;
> if (CHECK_CLUST(newclust, mydata->fatsize)) {
> @@ -811,7 +813,7 @@ set_contents(fsdata *mydata, dir_entry *dentptr,
> loff_t pos, __u8 *buffer, offset = 0;
> else
> offset = pos - cur_pos;
> - wsize = min(cur_pos + actsize, filesize) - pos;
> + wsize = min_t(unsigned long long, actsize, filesize
> - cur_pos); if (get_set_cluster(mydata, curclust, offset,
> buffer, wsize, &actsize)) {
> printf("Error get-and-setting cluster\n");
> @@ -824,8 +826,6 @@ set_contents(fsdata *mydata, dir_entry *dentptr,
> loff_t pos, __u8 *buffer, if (filesize <= cur_pos)
> break;
>
> - /* CHECK: newclust = get_fatent(mydata, endclust); */
> -
> if (IS_LAST_CLUST(newclust, mydata->fatsize))
> /* no more clusters */
> break;
Reviewed-by: Lukasz Majewski <lukma@denx.de>
Best regards,
Lukasz Majewski
--
DENX Software Engineering GmbH, Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-59 Fax: (+49)-8142-66989-80 Email: lukma at denx.de
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 488 bytes
Desc: OpenPGP digital signature
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20190916/9542053b/attachment.sig>
next prev parent reply other threads:[~2019-09-16 21:38 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <CGME20190916122430eucas1p164f3467e5ad5981c01bde6376ec51a27@eucas1p1.samsung.com>
2019-09-16 12:24 ` [U-Boot] [PATCH 0/3] Raspberry Pi4: add support for DFU over USB Marek Szyprowski
2019-09-16 12:24 ` [U-Boot] [PATCH 1/3] fat: write: fix broken write to fragmented files Marek Szyprowski
2019-09-16 13:18 ` Oleksandr Suvorov
2019-09-16 21:38 ` Lukasz Majewski [this message]
2019-09-16 12:24 ` [U-Boot] [PATCH 2/3] usb: dwc2_udc_otg: add bcm2835 SoC (Raspberry Pi4) support Marek Szyprowski
2019-09-16 21:40 ` Lukasz Majewski
2019-09-16 12:24 ` [U-Boot] [PATCH 3/3] config: enable DFU over USB on Raspberry Pi4 boards Marek Szyprowski
2019-09-16 12:45 ` Matthias Brugger
2019-09-16 12:53 ` Marek Szyprowski
2019-09-16 16:18 ` Jonathan Gray
2019-09-17 5:41 ` Marek Szyprowski
2019-09-16 21:41 ` Lukasz Majewski
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20190916233801.656c39aa@jawa \
--to=lukma@denx.de \
--cc=u-boot@lists.denx.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.