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

A generic API for all types of devices #73

Closed
t-w opened this issue Feb 10, 2024 · 6 comments
Closed

A generic API for all types of devices #73

t-w opened this issue Feb 10, 2024 · 6 comments

Comments

@t-w
Copy link
Collaborator

t-w commented Feb 10, 2024

The main ideas:

  • make a simple, generic and unified API for all types of devices
  • provide a simple way for creating other, used-implemented types of devices
    (one of such devices is ramdisk, proposed and implemented by @kyz, hooked so far as a "native" device)
t-w referenced this issue in t-w/ADFlib Feb 10, 2024
The main change is creating a generic API for all already
existing types of devices (files (dumps), real/native
devices for Linux and Win32, and ramdisk).

Making it simple and generic, provides also a simple way
to implement new types of devices, also as a part of
the client code.

It also allows better and more efficient testing, for
instance, by simple replacement of slow ADF devices
(like files) with more efficient ones (like ramdisk).
@lclevy
Copy link
Collaborator

lclevy commented Feb 10, 2024

Hi,
That's a good idea. But hardisk have specific structure like rigid disk block, no ?
What would be the difference classes of devices, towards 'dump' ?

@t-w
Copy link
Collaborator Author

t-w commented Feb 10, 2024

Mounting remains different for hard disks (with rigid blocks). These changes are for block-level device access only.

Some time ago, I made a change (for #17) making 2 levels of accessing ADF devices:

  • opening-closing: for device block level access (only), to allow, for instance, formatting an empty device
  • mounting-unmounting: available when volume information is already on the device; mounting a device is basically required to access (mount) its volumes

In 0.8.0, this was not quite properly separated (mounting was doing opening, for instance... this was in a way to preserve compatibility with earlier code). Now it is really separated, so a device has to be first opened, then mounted (mounting is an operation on an already existing and opened, or created, ADF device).

And as I wrote above - mounting devices is unchanged.
(though it may be worthy to look a that also, as I am not sure yet if there is really need to distinguish "native" devices - the only place using it is adfmountDev, to do exactly MountHDFile vs MountHD; I do not quite understand the difference, yet).

@t-w
Copy link
Collaborator Author

t-w commented Feb 10, 2024

Btw. you can have a look at the changes in the commit above.

There are still some (probably minor) things to correct (tests with autotools failed for some reason) but all the major changes are already there.

@lclevy
Copy link
Collaborator

lclevy commented Feb 10, 2024

This looks good! I trust your work 👍

t-w referenced this issue in t-w/ADFlib Feb 10, 2024
The main change is creating a generic API for all already
existing types of devices (files (dumps), real/native
devices for Linux and Win32, and ramdisk).

The main concept is creating a generic device driver
interface, defined in adf_dev_driver.h, which requires
implementing just a few functions to make a valid driver.

Making it simple and generic, provides also a simple way
to implement new types of devices, also as a part of
the client code.

It also allows better and more efficient testing, for
instance, by simple replacement of slow ADF devices
(like files) with more efficient ones (like ramdisk).

These device drivers can be "activated" or "deactivated"
as needed (using adfAdd/RemoveDeviceDriver, see
adf_device_drivers.h). This is done for flexibility
(a user can easily add a custom driver developed in his
own client code), but also for security (an application
working only on ADF files does not need a driver for real
block devices).

By default, only "dump" (ADF files) and "ramdisk" are
activated.
@t-w
Copy link
Collaborator Author

t-w commented Feb 12, 2024

So, according to this piece:

RETCODE adfDevMount ( struct AdfDevice * const dev )
{
    if ( dev == NULL )
        return RC_ERROR;

    RETCODE rc;

    switch( dev->devType ) {
[...]

    case DEVTYPE_HARDDISK: {
        uint8_t buf[512];
        rc = adfDevReadBlock ( dev, 0, 512, buf );

       /* BV ...from here*/
        if( rc != RC_OK ) {
            adfEnv.eFct ( "adfMountDev : adfReadBlockDev 0 (bootblock) failed");
            return rc;
        }

        /* a file with the first three bytes equal to 'DOS' */
        if ( ! dev->drv->isNative() &&
             strncmp ( "DOS", (char *) buf, 3 ) == 0 )
        {
            rc = adfMountHdFile ( dev );
            if ( rc != RC_OK )
                return rc;
        }
        else {
            rc = adfMountHd ( dev );
            if ( rc != RC_OK )
                return rc;								/* BV ...to here.*/
            }
        }
        break;
[...]

the information whether a device is "native" or not is used only to prevent mounting "native" device as an unpartitioned, single volume device (like a floppy or an hdf without rigid block, so without geometry and partition information). While, if I understand well, this is not a valid case for Amiga which, I suspect, had nothing in OS to detect hard disk geometry. That is why rigid blocks are required - so that special tools could detect geometry of the device and write it on the first sectors of disk so that the OS could use it. Is that right?

If it is so - then we do not need this information in the ADFlib. If someone wants to create a single volume on the whole device (without partitioning), the library should be able to open it (like an HD file). But, of course, it is useless on real Amiga which will not be able to know device geometry...

There would be a point to have this "native" info if ADFlib was used on Amiga - but I do not think it is ever the case. It would be like carrying coals to Newcastle...

So I would remove this "native" attribute and, if the disk starts with "DOS", let it mount as any HD file, regardless if the device is "native" or not.

What do you think?

(btw - what is this "BV" acronym that appears sometimes in the comments to the code? It seems like marking something but it is not clear what it means, at least in English, en Francais ca peut etre "bien vu", n'est-ce pas? ;-)

@t-w
Copy link
Collaborator Author

t-w commented Feb 19, 2024

The "native" attribute is kept - it will allow to know which device should have a real geometry (which should come from the hardware).

(cont. on geometry matters in t-w#4)

@t-w t-w closed this as completed Feb 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants