lclevy / ADFlib

A free, portable and open implementation of the Amiga filesystem
GNU General Public License v2.0
90 stars 30 forks source link

Opening devices in the current dev branch #79

Closed DidierMalenfant closed 9 months ago

DidierMalenfant commented 9 months ago

The following code in. add_dev.c:

struct AdfDevice * adfDevOpen ( const char * const  name,
                                const AdfAccessMode mode )
{
    const struct AdfDeviceDriver * const driver = adfGetDeviceDriverByDevName ( name );
    if ( driver == NULL || driver->openDev == NULL )
        return NULL;
    return driver->openDev ( name, mode );
}

seems to use name as both name for the device name and the adf name.

Am I reading this correctly?

t-w commented 9 months ago

Not quite.

Read carefully how the driver is gotten: "...ByDevName" means "get driver according to the device name" (not the driver name). It basically tries to match the device driver with device name (with a fallback/default to the dump file driver).

Actually, while changing the devices code recently, I was not sure if this is needed. It could be left totally to client code to match device driver with the device. I decided to leave it this way to simplify most cases and to keep compatibility with earlier code.

Note also that now the drivers can be enabled/disabled - so, for instance, there can be only one enabled and every adfDevOpen will use that one. In fact, matching is used only for "native" devices - and the native dev. driver is disabled by default.

There is a new function (adfDevOpenWithDriver) where the driver can be explicitly specified (by its name), so it is up to you which way you prefer in your code.

t-w commented 8 months ago

In fact, it is me who apparently haven't read carefully your question ;-) Sorry about that.

Yes - you are reading it right. This is a string representing:

However, how it will be used depends on which drivers are enabled:

(Sorry, one more time, I just responded to quickly...)