_sion_filedesc is probably a god object
... or rather, it would be one, if C was an object oriented language. It contains everything and at the same time encapsulates almost nothing. It represents all of these:
- a single physical file with a single logical file opened,
- a single physical file with multiple (or all) of its logical files opened,
- multiple physical files with mulitple (or all) of their logical files opened.
To make matters worse, at any given time, only a single logical file in a single physical file out of these collections is in focus. When switching focus (which commonly happens when seeking, but also during open and close), the meta-data of the newly selected file (be it logical and/or physical) is copied to special fields of _sion_filedesc
and the meta-data of the no longer in focus file is written back to the fields it was previously copied from. There are however no functions that do this. These copies are done ad-hoc, every time, see, e.g., sion_seek or sion_generic_paropen_mapped.
Separating the different aspects of _sion_filedesc
into multiple types and encapsulating copy operations (or not copying in the first place) would help cut down on redundant code and clarify responsibilities.