English Amiga Board

English Amiga Board (https://eab.abime.net/index.php)
-   Coders. System (https://eab.abime.net/forumdisplay.php?f=113)
-   -   get "xxx.device" name from volume/device name (https://eab.abime.net/showthread.php?t=91496)

jotd 25 March 2018 17:21

get "xxx.device" name from volume/device name
 
Hi,

I have "DH0:" which is my device name.

I'd like to know which device (scsi.device, uaehf.device...) drives it.

Any asm/C code to do so?

Thanks

thomas 25 March 2018 17:54

Code:

#include <proto/exec.h>
#include <proto/dos.h>

#include <dos/filehandler.h>

#include <string.h>



/* copy a BCPL string to a C string */

void bstrcpy (char *dest,UBYTE *src)
{
int len = *src++;
strncpy (dest,src,len);
dest[len] = 0;
}



/* get drive name, device and unit for a given path */

BOOL get_device_unit (const char *path,char *drive,char *device,long *unit)
{
BOOL ok = FALSE;
struct DevProc *proc;

if ((proc = GetDeviceProc (path,NULL)))
        {
        struct DosList *dl;

        dl = LockDosList (LDF_DEVICES | LDF_READ);

        while ((dl = NextDosEntry (dl,LDF_DEVICES)))
                {
                if (dl->dol_Task == proc->dvp_Port)
                        break;
                }

        if (dl)
                {
                struct FileSysStartupMsg *fssm = BADDR(dl->dol_misc.dol_handler.dol_Startup);

                if (TypeOfMem(fssm) && (APTR)fssm > (APTR)1000)
                        {
                        bstrcpy (drive,BADDR(dl->dol_Name));
                        bstrcpy (device,BADDR(fssm->fssm_Device));
                        *unit = fssm->fssm_Unit;
                        ok = TRUE;
                        }
                }

        UnLockDosList (LDF_DEVICES | LDF_READ);

        FreeDeviceProc (proc);
        }

return (ok);
}



/* main program */

int main (void)
{
struct RDArgs *rdargs;
struct {
        char **path;
        } args;

if (!(rdargs = ReadArgs ("PATH/A/M",(APTR)&args,NULL)))
        PrintFault (IoErr(),NULL);
else
        {
        char name[256];
        char device[256];
        long unit;
        char **path;

        for (path = args.path; *path; path++)
                {
                if (!get_device_unit (*path,name,device,&unit))
                        Printf ("could not find information for %s\n",*path);
                else
                        {
                        Printf ("info for %s: device=%s; unit=%ld\n",name,device,unit);
                        }
                }

        FreeArgs (rdargs);
        }

return (RETURN_OK);
}



All times are GMT +2. The time now is 08:04.

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.

Page generated in 0.04238 seconds with 10 queries