Re: [hatari-devel] Replacing direct file system access with an abstraction layer?

[ Thread Index | Date Index | More lists.tuxfamily.org/hatari-devel Archives ]


Le 31/08/2023 à 20:38, Brad Smith a écrit :
I recently created a new adaptation of Hatari as a Libretro core (an alternative to the existing libretro/hatari), and in an Atari Forum discussion Eero Tamminen suggested it might be worth incorporating some of the adaptations I had to make into the main project.

Atari Forum thread: https://www.atari-forum.com/viewtopic.php?p=450412#p450412 <https://www.atari-forum.com/viewtopic.php?p=450412#p450412> My adaptation: https://github.com/bbbradsmith/hatariB <https://github.com/bbbradsmith/hatariB>

In my adaptation I had to find and replace (or remove) every direct use of the filesystem. I replaced fopen, fseek, ftell, fseeko, ftello, scandir, stat, etc. with an abstract replacement interface provided by my core, which itself was a wrapper around Libretro's virtual file system interface)

Would it be worthwhile and/or desirable to do this for main Hatari? Essentially the idea is to create an abstraction interface in Hatari's file.h, and use it to replace all existing direct filesystem calls. File_fopen, File_ftell, File_stat, etc.

I hadn't initially considered it, since I don't see the direct file system use as a problem for the stand-alone application, but maybe it would make it easier for other adaptations like mine where the standard file system is not available? It may also just be useful to consolidate all the file system use in one place like this for purposes of debugging and diagnostics.

So, that's the proposal. I think there's some potential benefits, but I didn't want to do the work of preparing a PR for this unless I first understood that it was wanted.

In my own adaptation I already had to do the work of finding and replacing them all, so for that alone it's probably just extra work rather than a benefit... though at least it could remove ~100 points of change vs. the main source, which would be nice. However, I'd be happy to do it if others think it would be a good change to have in the main project.

So, is that worth doing? Would anyone here want to see this change?

Hi

thanks for your work on hatari + retroarch, well done !

regarding the change of fopen/fread/... becoming an intermediate/wrapper function such as Fopen/Fread/... or any other prefix, I think I have a similar opinion to Eero's one (that he posted in atari-forum) :
it could be handled with some define such as :

#define File_ftell ftell
#define File_fopen fopen

In fact I had the same issue when merging WinUAE's CPU core to use it in Hatari : it uses many Windows' system call to access file, instead of the unix/linux equivalent. So instead of replacing all thoses calls in WinUae's source (which makes merging patch more complicated later), I added a list of define to replace each windows' call with the posix equivalent.

I think you could do the same in your retro version, just adding a few define and keeping all fopen/fread/... as they are in Hatari sources.

Nicolas




Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/