Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sparse files can be incompatible with GS/OS #49

Closed
ibrumby opened this issue Jul 23, 2021 · 7 comments
Closed

Sparse files can be incompatible with GS/OS #49

ibrumby opened this issue Jul 23, 2021 · 7 comments
Labels

Comments

@ibrumby
Copy link

ibrumby commented Jul 23, 2021

If you have a file which has 512 bytes or more of zeros at the start of the file, Ciderpress will write the first block as a sparse block.

If you attempt to read this using GS/OS / the ProDOS FST it will not be read in as sparse! As a result the file will be corrupt.

If you write 512 bytes or more of zeros from within a GS/OS program it will not write the first block as a sparse block! Other blocks will be written as sparse, but not the first. As a result, this issue was never encountered prior to the invention of external tools.

There even appears to be code within GS/OS when reading the file to bypass sparse handling for the first block. So it appears to be deliberate behaviour, even though the reasons are unknown.

@fadden
Copy link
Owner

fadden commented Jul 23, 2021

I've seen Copy ][+ fail on such files (see issue #15), but I was not aware that the ProDOS FST had issues. What version of GS/OS are you using? Can you attach a disk image with a file that fails?

@fadden
Copy link
Owner

fadden commented Jul 23, 2021

A ran some tests. A file with 1024 zeroes stored in a ShrinkIt archive occupies 3 blocks when extracted by P8 ShrinkIt, but only 1 block when extracted by GS/ShrinkIt, and 1 block when created by CiderPress. Looking at the directory entry, GS/OS set the storage type to 5 (forked) for all files, while P8 set it to 2. P8 ShrinkIt is able to "type" files extracted by either (it just can't open resource forks).

So both GS/OS and P8 are able to handle files with an initial sparse block. I'm not sure why you're seeing failures / corruption.

@fadden fadden added the bug label Jul 23, 2021
@fadden
Copy link
Owner

fadden commented Jul 23, 2021

I've been able to reproduce an issue. It appears that a file with nothing but zeroes can be represented as fully sparse, but a file that starts with zeroes and then has some nonzero values must have an explicitly-allocated block 0, or you can get failures. So far I've only seen them happen when the file is > 128KB (the transition from "sapling" to "tree" structure). I suspect the problem is that there must be at least one block allocated in the first 128KB, so that the first block in the tree's master block list is allocated.

@ibrumby
Copy link
Author

ibrumby commented Jul 24, 2021

Glad you have been able to reproduce it. I noticed it on a tree, but another person on the Slack has seen it on a 34 KB file (i.e. sapling).

fadden added a commit that referenced this issue Jul 24, 2021
It appears that some programs, notably Copy ][+ and the GS/OS FST,
expect that the first block of a sparse file will always be
allocated, even if it's just 512 zeroes.  I've only seen this fail
in cases where the first entry in the master index block of a "tree"
file is zero, because the first 128KB are sparse, but rumor has it
that the issue can affect "sapling" files as well.

This changes CiderPress to work the way ProDOS does: always allocate
a block to hold the first 512 bytes of the file.  The only exception
to this is a file that is nothing but zeroes (perhaps populated by
creating a file and setting its EOF to something large), which can
be stored as a seedling.

(for issues #15 and #49)
@fadden
Copy link
Owner

fadden commented Jul 24, 2021

This should fix the issue: https://github.com/fadden/ciderpress/releases/tag/v4.1.0-d3

I'm always nervous messing with the filesystem stuff, but I threw a bunch of tests at it and nothing seemed to break. Let me know if it does the trick.

@ibrumby
Copy link
Author

ibrumby commented Jul 24, 2021

That's fixed it! Thanks a lot!

@polluks
Copy link
Contributor

polluks commented Jul 24, 2021

@fadden Indeed, good unit tests are your friend.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants