From: Lukasz Majewski <lukma@denx.de>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH v2 2/6] fat: write: fix broken write at non-zero file offset
Date: Tue, 24 Sep 2019 21:47:32 +0200 [thread overview]
Message-ID: <20190924214732.0806963c@jawa> (raw)
In-Reply-To: <20190924131111.1691-3-m.szyprowski@samsung.com>
Hi Marek,
> Handling of the start file offset was broken in the current code.
> Although the code skipped the needed clusters, it then tried to
> continue write with current cluster set to EOF, what caused
> assertion. It also lacked adjusting filesize in case of writing at
> the end of file and adjusting in-cluster offset for partial overwrite.
>
> This patch fixes all those issues.
Reviewed-by: Lukasz Majewski <lukma@denx.de>
>
> Signed-off-by: Marek Szyprowski <m.szyprowski@samsung.com>
> ---
> fs/fat/fat_write.c | 12 ++++++------
> 1 file changed, 6 insertions(+), 6 deletions(-)
>
> diff --git a/fs/fat/fat_write.c b/fs/fat/fat_write.c
> index 6cfa5b4565..d7a814eb0c 100644
> --- a/fs/fat/fat_write.c
> +++ b/fs/fat/fat_write.c
> @@ -756,14 +756,12 @@ set_contents(fsdata *mydata, dir_entry
> *dentptr, loff_t pos, __u8 *buffer, /* go to cluster at pos */
> cur_pos = bytesperclust;
> while (1) {
> + newclust = get_fatent(mydata, curclust);
> if (pos <= cur_pos)
> break;
> - if (IS_LAST_CLUST(curclust, mydata->fatsize))
> + if (IS_LAST_CLUST(newclust, mydata->fatsize))
> break;
> -
> - newclust = get_fatent(mydata, curclust);
> - if (!IS_LAST_CLUST(newclust, mydata->fatsize) &&
> - CHECK_CLUST(newclust, mydata->fatsize)) {
> + if (CHECK_CLUST(newclust, mydata->fatsize)) {
> debug("curclust: 0x%x\n", curclust);
> debug("Invalid FAT entry\n");
> return -1;
> @@ -772,8 +770,9 @@ set_contents(fsdata *mydata, dir_entry *dentptr,
> loff_t pos, __u8 *buffer, cur_pos += bytesperclust;
> curclust = newclust;
> }
> - if (IS_LAST_CLUST(curclust, mydata->fatsize)) {
> + if (IS_LAST_CLUST(newclust, mydata->fatsize)) {
> assert(pos == cur_pos);
> + filesize -= pos;
> goto set_clusters;
> }
>
> @@ -814,6 +813,7 @@ set_contents(fsdata *mydata, dir_entry *dentptr,
> loff_t pos, __u8 *buffer, else
> 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");
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/20190924/29ae8096/attachment.sig>
next prev parent reply other threads:[~2019-09-24 19:47 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <CGME20190924131119eucas1p2e457a2eaa370e6930d90b93d3ace9ce2@eucas1p2.samsung.com>
2019-09-24 13:11 ` [U-Boot] [PATCH v2 0/6] Raspberry Pi4: add support for DFU over USB Marek Szyprowski
2019-09-24 13:11 ` [U-Boot] [PATCH v2 1/6] fat: write: fix broken write to fragmented files Marek Szyprowski
2019-09-24 13:11 ` [U-Boot] [PATCH v2 2/6] fat: write: fix broken write at non-zero file offset Marek Szyprowski
2019-09-24 19:47 ` Lukasz Majewski [this message]
2019-09-24 13:11 ` [U-Boot] [PATCH v2 3/6] dfu: mmc: rearrange the code Marek Szyprowski
2019-09-24 19:48 ` Lukasz Majewski
2019-09-24 13:11 ` [U-Boot] [PATCH v2 4/6] dfu: mmc: remove file size limit for io operations Marek Szyprowski
2019-09-24 19:49 ` Lukasz Majewski
2019-09-24 13:11 ` [U-Boot] [PATCH v2 5/6] usb: dwc2_udc_otg: add bcm2835 SoC (Raspberry Pi4) support Marek Szyprowski
2019-09-24 13:11 ` [U-Boot] [PATCH v2 6/6] config: enable DFU over USB on Raspberry Pi4 boards Marek Szyprowski
2019-11-08 16:57 ` Matthias Brugger
2019-11-11 18:01 ` Matthias Brugger
2019-11-12 9:52 ` Marek Szyprowski
2019-11-12 10:30 ` Matthias Brugger
2019-11-15 13:47 ` [U-Boot] [PATCH v3 " Marek Szyprowski
2019-11-19 16:05 ` Matthias Brugger
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=20190924214732.0806963c@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.