-
Notifications
You must be signed in to change notification settings - Fork 31
Add rebuilding of block allocation bitmap (if marked as invalid in root block) #66
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
Conversation
It includes an adf floppy image, which has a unique (so far) property (or an error) of having a non-zero entry in bitmap pages array beyond what was expected (a fixed, calculated size, depending on the size the volume).
…ond expected size), lclevy#63
Block calculation moved inside and removed parameter. Called in adfMount, not in adfRead/ReconstructBitmap, what allows to call adfReconstructBitmap separated (on a mounted volume). NULLify deallocated objects.
…es beyond size also in bitmap ext. blocks, lclevy#63
…bitmap ext. blocks.
…nly showing the bitmap).
... and minor code improvements.
…allocation bitmap.
…ils. ... ie. skip comparison.
…f the volume's root dir. is empty.
I wonder if mandatory bitmap rebuilding is risky or not, because of custom storage like demo with track loaders. First track look likes amigados, but this is not with a valid filesystem since the operation system is not used. Is it mandatory or not? By default or not? |
Anyway having such code is very good. I just wonder in which cases to activate it or not for end users.. |
I was going to improve the mounting part later - but you are right, it is better to do it properly from the start. It is good that you pointed this out. I have prepared some changes which will improve safety of adding this, they can be summarized as follows:
So far, I have also made it this way, that for read-only the bitmap is not even read - but here is trouble. Even in read-only mode there are features ( For me it seems that the reconstruction should be done also for read-only (just without writing anything). Note that this of course implies reading all meta-data blocks from the volume (to find all file, directory, link and directory cache blocks used). Let me know what you think. |
In fact, rebuilding the bitmap is relevant only for real amigados formatted media. Do the user is capable of deciding? Not sure. |
... just keep it in memory.
(no fail-safe read-only mounting).
1. First, always read the existing bitmap. 2. If the existing bitmap is marked 'invalid' in root block - for read-only mount: reconstruct the bitmap in memory (no overwriting the existing one) - for read-write mount: fail mounting the volume.
The new function remounts a volume, already mounted as read-only, as read-write. It updates (overwrites) the changed block allocation bitmap blocks (so if the bitmap was reconstructed in memory during the read-only mount, this operation will write the changes to the volume).
Well, I do not quite understand how the bitmap is important only for AmigaOS formatted disks only. The bitmap is used by the ADFlib in both modes:
and it does not really matter if it is orig. formatted or not (unless I am missing something). It would be possible to write the lib in such way so that it would not use the bitmap from the disk (reconstruct everything from other metadata, keep the bitmap only in memory and mark the bitmap as invalid for any future writes...). But I am not sure this is the right way... If I understand well - AmigaDos was rebuilding the bitmap automatically with DiskValidator (which, if I remember well, had its own set of issues) if the bitmap was marked as invalid. So adding rebuilding the bitmap to the ADFlib is basically reimplementing the feature normally present on the original filesystem. IMHO, not rebuilding the bitmap and using an invalid one, can be more harmful. I have just pushed a few changes that I think deal with this in a reasonable way -
in short:
Beyond that, the volume mounted "read-only" can be remounted as read-write, and by this, if the bitmap was reconstructed in memory (was invalid), it is written to the volume. So an update of the bitmap can happen only on an explicit call to All this trouble is coming with write support... If it is supposed to be reliable, it has to use correct block allocation data. Other option could be, for instance, always only read the bitmap in whatever mode and let the lib user to execute Concerning if the operations are explicit - the read-write mode is selected rather explicitly by a very human readable constant-defined parameters (there was a long discussion about this before...). Concerning bitmap - I see 2 options above, either safe read-write mount and writing data, or power to the user. I am rather for the 1st option (safer, shorter client code), but maybe for flexibility the second is better ... |
…nvalid. Power and flexibility to the client code: client code decides which bitmap to use - it should check bitmap validity (if bmFlag in rootblock in valid / invalid) and rebuild the bitmap calling adfReconstructBitmap.
Power and flexibility to the client code: If the bitmap is rebuilt on a volume mounted read-only, it can be written to the volume by calling adfUpdateBitmap.
Remove commented out adfVolReconstructBitmap and function prototypes already present in adf_bitm header.
I have changed the code so that:
So power, flexibility and responsibility for using an invalid bitmap goes to the client code. |
You've got 'trackdisks', where there is no filesystem apart bootblock. Data is loader via specific code (track loader) inside bootblock. |
If inserted in an already booted system. Amiga os might detect it as invalid. |
If there is no valid metadata, ie. no rootblocks, mounting a volume from these "trackdisks" will fail (on reading the rootblock). Basically this blocks write mode for such cases. There is no change on this, it was like this before. Note that because volume's bitmap was (and is) always loaded (as is the rootblock during mounting), there was (and there is) no way to mount such volume just for accessing raw blocks of a volume. For now, such access has to be done using blocks on the device level. Support for this could be eventually added, it will require careful redesign on several pieces, so that bitmap is not required on a mounted volume, but, for instance, is used in a lazy way (loaded when needed). This would be like another layer of mounting - without the filesystem (accessing only raw volume blocks) or with the filesystem (accessing filesystem-specific, byte-reordered blocks with filesystem (meta)data etc.). Or what you mean above is just blocking write access (read-write volume mount) when the bitmap is marked invalid in rootblock? Such blocking is not really necessary, assuming that, as I wrote, responsibility for checking this goes fully to the client code. But, of course, this can be easily put back. |
Looks fine to me. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok
This was started in consequence of #63, and discussed further in #64.
The new code in the update does what's in the title - it rebuilds the block allocation bitmap when mounting a volume, if the bitmap is marked as "invalid".
There is also a new command-line utility, which allows to display and to enforce rebuilding the bitmap.
While this resolves #63, there is still one thing to consider: 2. from #64 (but that is to further improve the reliability).
There are some new tests (in
regtests/
) that works as follows:regtests/Dumps/
makes a copy, rebuilds the bitmap and compares it to the original (here some surprises - some of the images created with old ADFlib seem not valid(!), see exceptions in the scriptregtests/Test/bitmap_recreate.sh
)This means that any image copied to
regtests/Dumps/
will be checked by the test - so anyone can use the test with any adf image. I have done this on many images and the rebuilt bitmap was always identical (with the exceptions mentioned earlier...). It is not really feasible to add to the repo many more dumps for testing...So - the code seems to work fine. But, of course, more tests are welcomed, if anyone is willing to do so.