On Tue, Aug 6, 2024, 4:48 AM Ben Russell via Freedos-devel <
freedos-devel@lists.sourceforge.net> wrote:

> On 06/08/2024 04:55, Wilhelm Spiegl via Freedos-devel wrote:
>
> I just stumbled over this old bug report referring to xcopy:
>
> https://sourceforge.net/p/freedos/bugs/346/
>
> It is still active. means: It can happen that only some files will be
> copied, others not.
>
> A comment in that thread links to a repo on GitHub, FDOS/xcopy. It has a
> "version 1.5" last updated 3 years ago. From an examination of the code,
> the bug is probably still present.
>
> The two checks are in the form "if (number_of_bytes_to_add >
> free_diskspace) { complain(); clean_up(); exit(39); }".
>
> Part of me would be tempted to do "ceiling division" in both cases and
> operate in terms of clusters, while another part of me is aware that doing
> an unsigned 32-bit saturating multiply would probably be "good enough".
> ... now that I think of it, converting the sizes from bytes to clusters
> via ceiling division would actually be the best solution here.
>
> That is: (WARNING: This is untested, might not even compile, and would
> need to have its math checked possibly via exhaustive search)
>
> getdfree(dest_drive, &disktable);
> [unsigned long] bpc = (unsigned long) disktable.df_sclus *
> disktable.df_bsec; /* bytes per cluster, 2^10 x 2^16 = 2^26 < 2^32 so this
> step should be OK */
> [unsigned long] free_clusters = (unsigned long) disktable.df_avail;
>
> and the easy case (the "else" block used when a file does not already
> exist):
>
> if ((src_statbuf.st_size + (cpb - 1UL)) / cpb > free_clusters) { ... }
>
> and the hard case (the "if" block used when a file already exists):
>
> if ( (src_statbuf.st_size > dest_statbuf.st_size) &&
> ((src_statbuf.st_size  + (bpc - 1UL)) / bpc - (dest_statbuf.st_size + (bpc
> - 1UL)) / bpc) > free_clusters) ) { ... }
>
> I claim no copyright on these code snippets, but they will end up under
> GPLv2-only due to the Xcopy project licence.
>
> Regards,
> Ben R
>

I will try and update xcopy on GitHub with your suggestions and post an
updated release.

Jeremy
_______________________________________________
Freedos-devel mailing list
Freedos-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/freedos-devel

Reply via email to