/* 
Listing 1.0: Probing the Amiga DOS Device List
*/

#include <exec/types.h>
#include <exec/alerts.h>
#include <exec/memory.h>
#include <exec/libraries.h>

#include <intuition/intuition.h>

#include <libraries/dos.h>
#include <libraries/dosextens.h>

#include <stdio.h>

#include <libraries/arpbase.h>
#include <libraries/arpfunc.h>

struct ArpBase *arpBase;

extern struct Library *OpenLibrary();

struct DosLibrary *dosLibrary = NULL;
struct RootNode   *rootNode   = NULL;
struct DosInfo    *dosInfo    = NULL;
struct DevInfo    *devInfo    = NULL;

#define AZTEC_C

/* ********************************************************************* */

main(argc, argv)
int argc;
char *argv[];
{
  char cString[100];

  if((arpBase = (struct ArpBase *) OpenLibrary("arp.library", 34L)) == NULL)
  Alert(AG_OpenLib | AN_ArpLib, 0L);
  else printf("ARP Library Successfully opened\n");

  if((dosLibrary = (struct DosLibrary *) OpenLibrary(DOSNAME, 0L)) == NULL) 
  {
    printf("DOS library could not be opened");
    exit(20);
  }

  rootNode = (struct RootNode *) dosLibrary->dl_Root;

  dosInfo  = (struct DosInfo *) BADDR(rootNode->rn_Info);

  devInfo  = (struct DevInfo *) BADDR(dosInfo->di_DevInfo);

  printf("The system's DosLibrary structure located at address $%lx\n", dosLibrary);
  printf("The system's RootNode   structure located at address $%lx\n", rootNode);
  printf("The system's DosInfo    structure located at address $%lx\n", dosInfo);
  printf("The system's DevInfo    structure located at address $%lx\n\n", devInfo);

  for(devInfo; devInfo != NULL; devInfo = BADDR(devInfo->dvi_Next))
  {
    printf("\n\n");

    cString[0] = '\0';

    if(BtoCStr(cString, devInfo->dvi_Name, 99) == 0) 
    printf("devInfo->dvi_Name string not properly converted\n");

    printf("This device node has name %s\n", cString); 

    printf("This device node is for type %ld\n", (LONG) devInfo->dvi_Type);

    if((LONG) devInfo->dvi_Type == 0) printf("This is a REAL PHYSICAL DEVICE type device\n");
    if((LONG) devInfo->dvi_Type == 1) printf("This is a ASSIGNED LOGICAL DIRECTORY type device\n");
    if((LONG) devInfo->dvi_Type == 2) printf("This is a PHYSICAL DISK VOLUME type device\n");

    cString[0] = '\0';

    if(BtoCStr(cString, devInfo->dvi_Handler, 99) == 0) 
    printf("No devInfo->dvi_Handler string for this item\n");

    if(BtoCStr(cString, devInfo->dvi_Handler, 99) != 0) 
    printf("This device node Handler File Name is %s\n", cString); 
  }

  if(dosLibrary) CloseLibrary(dosLibrary);
  if(arpBase)    CloseLibrary(arpBase);
  exit(0);
}

