stdio fles, opening with wb and rb, files getting mangled.

Post Reply
tschak909
Well known member
Posts: 171
Joined: Sun Sep 09, 2018 5:44 pm

stdio fles, opening with wb and rb, files getting mangled.

Post by tschak909 »

I'm genuinely scratching my head.. I have a a tool I've written that has subcommands to e.g. get a file from the network and put to the local disk.
I am opening the files "wb" to write them to disk, and I even tried to make sure I was writing at most 128 bytes at a time to disk, but files (such as ZIP files are coming across very mangled, and I'm at a loss...
WIN_20220223_16_23_02_Pro.jpg
Original ZIP:
https://drive.google.com/file/d/12isATP ... sp=sharing

ZIP after a copy to the host system and back again:
https://drive.google.com/file/d/1TqtQd0 ... sp=sharing

Code:
https://github.com/FujiNetWIFI/fujinet- ... /src/get.c

-Thom
You do not have the required permissions to view the files attached to this post.
nuc1e0n
Member
Posts: 49
Joined: Wed Jun 10, 2020 12:34 am

Re: stdio fles, opening with wb and rb, files getting mangled.

Post by nuc1e0n »

Are you able to update your code to print to the screen whatever network_read puts into the buffer and then test with the transfer of a text file? This would help to ensure you're receiving the proper data before it's written to disk.

hited.zip is the same size as the original file but seems to have random data in it. To me it looks like the buffer is not being populated with the correct data at all rather than some kind of 'off-by-one' type problem.
User avatar
dom
Well known member
Posts: 2072
Joined: Sun Jul 15, 2007 10:01 pm

Re: stdio fles, opening with wb and rb, files getting mangled.

Post by dom »

It's interesting, it looks like the contents of hited are the same (bar the padding) but (guessing here) the 64k blocks are in the wrong order.

If you try with a file < 64k I presume it works correctly?
User avatar
dom
Well known member
Posts: 2072
Joined: Sun Jul 15, 2007 10:01 pm

Re: stdio fles, opening with wb and rb, files getting mangled.

Post by dom »

I've just run this test:

Code: Select all

#include <stdio.h>

long buf[1024];

int main() {
        long i;
        FILE *fp = fopen("abc","wb");
        for ( i = 0; i < 65536 * 10; i+= 1024 ) {
                for ( long j = i; j < i + 1024; j++ ) {
                        buf[j - i] = j;
                }
                fwrite(buf, 4, 1024, fp);
        }
        fclose(fp);

}
Using zxcc and the file comes out in the correct order. Similarly when writing out 128 byte and 64 byte blocks. So file io seems to be working as expected.

It might be worth running a similar test on the Adam as sanity check.
tschak909
Well known member
Posts: 171
Joined: Sun Sep 09, 2018 5:44 pm

Re: stdio fles, opening with wb and rb, files getting mangled.

Post by tschak909 »

dom wrote: Thu Feb 24, 2022 10:20 pm It's interesting, it looks like the contents of hited are the same (bar the padding) but (guessing here) the 64k blocks are in the wrong order.

If you try with a file < 64k I presume it works correctly?
That is exactly right.
-Thom
tschak909
Well known member
Posts: 171
Joined: Sun Sep 09, 2018 5:44 pm

Re: stdio fles, opening with wb and rb, files getting mangled.

Post by tschak909 »

Oh SHIT! Look at this!
WIN_20220224_17_44_04_Pro.jpg
-Thom
You do not have the required permissions to view the files attached to this post.
tschak909
Well known member
Posts: 171
Joined: Sun Sep 09, 2018 5:44 pm

Re: stdio fles, opening with wb and rb, files getting mangled.

Post by tschak909 »

Well, I narrowed it down to the 8mb CP/M image that is in use in the Adam community. Write a file larger than 64K? the extent wraps around, so probably an errant extent mask or block shift value in the DPB.

When I mentioned this to the guy who made the image, "Yeah, I know the problem, just haven't had the enthusiasm to fix it."

...he released a disk image, that Adam users are using...and it has this bug...and he knows about it....and he didn't even so much as put a warning label on it.

fucking hell.

So, it's not z88dk.

-Thom
Post Reply