/*
P_DLIST.C
*/

#include <plib.h>

LOCAL_C TEXT *GetTypeText(UINT type)
    {
    switch (type)
        {
    case P_FMEDIA_FLOPPY:
        return "Floppy";
    case P_FMEDIA_HARDDISK:
        return "Hard";
    case P_FMEDIA_FLASH:
        return "Flash";
    case P_FMEDIA_RAM:
        return "RAM";
    case P_FMEDIA_ROM:
        return "ROM";
    case P_FMEDIA_WRITEPROTECTED:
        return "Protected";
        }
    return "Unknown";
    }

LOCAL_C VOID ListDevices(VOID)
    {
    VOID *ncb,*dcb;
    INT ret;
    TEXT device[P_FNAMESIZE];
    TEXT bb[E_MAX_ERROR_TEXT_SIZE];
    P_DINFO dinfo;
    
    p_printf("   Device       Name        Type       Size      Free");
    p_printf("===========  ==========  ==========  ========  ========");
    p_open(&ncb,"FIL:",P_FNODE);
    while (!p_iow(ncb,P_FREAD,&device[0],NULL))
        {
        p_scat(&device[0],"a:\\");
        if (p_open(&dcb,&device[0],P_FDEVICE))
            continue;
        while (!p_read(dcb,&device[P_FSYSNAMESIZE],0))
            {
            if ((ret=p_dinfo(&device[0],&dinfo))<0)
                {
                p_errs(&bb[0],ret);
                p_printf("%- 12s %- 12s<%s>",&device[0],"**Failed**",&bb[0]);
                continue;
                }
            p_printf("%- 12s %- 12s%- 11s %7ldK  %7ldK",
                &device[0],&dinfo.name[0],GetTypeText(dinfo.mediatype&0xff),
                (dinfo.size+512)>>10,(dinfo.free+512)>>10);
            }
        p_close(dcb);
        }
    p_close(ncb);
    }

GLDEF_C INT main(VOID)
    {
    ListDevices();
    p_getch();
    return(0);
    }
