Check 4 connected drives 
Author Message
 Check 4 connected drives

Just a simple question...

Does anybody know how to list connected drives? And once the drives are
listed, how to find the kind of each of them (I mean: Floppy disk, RAM disk,
Hard disk, novel disk.....)?

Thanks for help (if possible in assembly language,C or Pascal!!!)



Mon, 13 Oct 1997 03:00:00 GMT  
 Check 4 connected drives

Quote:

> Does anybody know how to list connected drives? And once the drives are
> listed, how to find the kind of each of them (I mean: Floppy disk, RAM disk,
> Hard disk, novel disk.....)?

> Thanks for help (if possible in assembly language,C or Pascal!!!)

/*

DRIVES.C -- find out which disk drives are available on system

A quick hack by Paul Schlyter, 1994-04-27

1995-03-14  PS  Now also outputs true drive names (network etc)

*/

#include <stdio.h>
#include <string.h>
#include <ctype.h>

#include <dos.h>

typedef unsigned char  byte;
typedef unsigned short word;
typedef unsigned long  dword;

#define BIT(n)  ( 1 << (n) )

char startup_drive(void)
{
    union REGS r;
    r.x.ax = 0x3305;
    intdos( &r, &r );

Quote:
}  /* startup_drive */

char default_drive(void)
{
    union REGS r;
    r.h.ah = 0x19;
    intdos( &r, &r );
    return r.h.al + 'A';

Quote:
}  /* default_drive */

int is_removable( char drive )
{
    union REGS r;
    r.x.ax = 0x4408;

    intdos( &r, &r );
    if ( r.x.cflag )
        return -1;
    else
        return  r.x.ax == 0;  /* AX == 0 ==> removable media */

Quote:
}  /* is_removable */

int host_drive( char drive )
{
    union REGS r;
    r.x.bx = 1;            /* DSGetDriveMapping */
    r.h.dl = drive - 'A';  /* Drive */
    r.x.ax = 0x4A11;       /* DoubleSpace multiplex function */
    int86( 0x2F, &r, &r );
    if ( r.x.ax != 0 )
        return -1;         /* Error */
    if ( (r.h.bl & 0x80) == 0 )
        return 0;          /* Not compressed */
    else
        return  (r.h.bl & 0x7F) + 'A';

Quote:
}  /* host_drive */

int drivetype( char drive )
{
    union REGS r;
    r.x.ax = 0x4409;

    intdos( &r, &r );
    if ( r.x.cflag )
        return -1;
    else
        return  r.x.dx;
    /*
     *  DX now contains:
     *
     * Bit  1:  1=Drive uses 32-bit sector addressing
     * Bit  6:  1=Drive accepts Generic IOCTL, GET/SET Logical Drive Map
     *             (Functions 440Dh, 440Eh, 440Fh)
     * Bit  7:  1=Drive accepts Query IOCTL (Function 4411h)
     * Bit  9:  1=Drive is local but shared by others on the network
     * Bit 11:  1=Drive accepts Does Device Use Removable Media (Func 4408h)
     * Bit 12:  1=Drive is remote
     * Bit 13:  1=Drive requires media descriptor in FAT
     * Bit 14:  1=Drive accepts Send/Receive Control Data To/From Block
                    Device (Functions 4404h, 4405h)
     * Bit 15:  1=Substitution Drive
     *
     */

Quote:
}  /* drivetype */

int isCDROMdrive( char drive )
{
    union REGS r;

    r.x.ax = 0x1500;        /* First test for presence of MSCDEX */
    r.x.bx = 0;
    int86( 0x2F, &r, &r );
    if ( r.x.bx == 0 )
        return 0;           /* MSCDEX not there, so return FALSE */
    r.x.ax = 0x150B;        /* MSCDEX driver check API */
    r.x.cx = drive - 'A';
    int86( 0x2F, &r, &r );
    return  r.x.ax != 0;    /* Drive is CDROM if AX nonzero */

Quote:
}  /* isCDROMdrive */

int truename( char far *src, char far *dst )
{
    union REGS r;
    struct SREGS s;
    char far *s2;

    /* INT 21h AH=60h doesn't like leading or trailing blanks */
    while (isspace(*src))
        src++;
    s2 = src;
    while (*s2)
        s2++;
    s2--;
    while (isspace(*s2))
        *s2-- = 0;

    s.ds = FP_SEG(src);
    s.es = FP_SEG(dst);
    r.x.si = FP_OFF(src);
    r.x.di = FP_OFF(dst);
    r.h.ah = 0x60;
    intdosx( &r, &r, &s );

    return  r.x.cflag ? -1 : 0;

Quote:
}  /* truename */

char *truedrive( char drive )
{
    static char src[20] = "X:\\", dst[80];

    src[0] = toupper(drive);
    if ( truename( src, dst ) < 0 )
        return  NULL;
    else if ( strcmp( src, dst ) == 0 )
        return NULL;
    else
        return dst;

Quote:
}  /* truedrive */

char logdrvmap( char drive )
{
    union REGS r;
    r.x.ax = 0x440E;   /* MS-DOS Get Logical Drive Map function */
    r.h.bl = (char) (drive - 'A' + 1);
    intdos( &r, &r );
    if ( r.x.cflag )
        return  r.h.al;  /*   1 = drive remote or cannot be shared
                          *   5 = device driver returns error
                          * 0xF = drive invalid
                          */
    else if ( r.h.al )
        return  (char) (r.h.al - 1 + 'A');  /* Drive shared with ... */
    else
        return 0;        /* Drive not shared */

Quote:
}  /* logdrvmap */

struct unit_tab
{
    void far * next;
    byte       drvno;       /* DL while calling int 13h */
    byte       DOS_drvno;   /* 0-based DOS drive number */
    byte       BPB[0x19];   /* BIOS Parameter Block for this drive */
    byte       fsf;         /* File System Flags for HD partitions:  
                             * 00h = 12-bit FAT
                             * 40h = 16-bit FAT
                             * 80h = unsupported partition
                             */
    word       opens;       /* # Open's without matching Close's */
    byte       dev_type;    /* Form factor:  
                             * 00h = floppy, 40 cyl's, <= 9 sect/trk  
                             * 01h = floppy, 80 cyl's, 15 sect/trk
                             * 02h = floppy, 80 cyls, 9 sect/trk
                             * 05h = hard disk
                             * 07h = other type of floppy
                             * 09h = floppy, 80 cyls, 36 sect/trk
                             */
    word       status;      /* Status flags for the drive:
                             * 0001h  non-removable media
                             * 0002h  change-line detection supp. by BIOS
                             * 0004h  disk PBP (at offset 06h) locked
                             * 0008h  good track layout, sect's equally sized
                             * 0010h  shares whole phys.dev w other LUN's
                             * 0020h  active unit for shared phys. dev
                             * 0040h  disk change detected
                             * 0080h  set DASD before format
                             * 0100h  disk reformat detected
                             * 0200h  read/write disabled
                             */
    word       cylinders;   /* Number of cylinders spanning the drive/part */
    byte   def_BPB[0x1F];   /* BPB repr. default disk format for drive */
    byte       cyl8;        /* Low 8bits of cyl # for last giid rd/wr/ver */
    dword      clk_corr;    /* Remov. disk: clock count of last good access */
                            /* Fixed disk: minidisk cyl corr to complete
                               reduction of drive parameters logic==>physic */
    byte   vollab[0x0C];    /* 11-byte volume label + NUL terminator */
    dword      serial_no;   /* Disk serial number */
    byte       filesys[9];  /* 8-byte file system label + NUL:
                               "FAT12" or "FAT16", padded with spaces */

Quote:
};

#ifndef MK_FP
#define MK_FP(seg,ofs)  (void far *) ( ((long)(seg) << 16) + (ofs) )
#endif

struct unit_tab far *next_unit_tab( struct unit_tab far *t )
{
    if ( t == NULL )
    {
        union REGS r;
        struct SREGS s;
        r.x.ax = 0x0800;
        int86( 0x2F, &r, &r );
        if ( r.h.al != 0xFF )
            return  NULL;           /* Unit Table chain not available */
        r.x.ax = 0x0803;
        int86x( 0x2F, &r, &r, &s );
        t = MK_FP( s.ds, r.x.di );  /* Get first entry to Unit Table chain */
    }
    else
        t = t->next;                /* Get next entry to Unit Table chain */
    if ( FP_OFF(t) == 0xFFFF )
        t = NULL;                   /* End of chain */
    return t;

Quote:
}  /* next_unit_tab */

struct unit_tab far *int13unit( int DOSvol )
{
    struct unit_tab far *t = NULL;
    for(;;)
    {
        t = next_unit_tab( t );
        if ( t == NULL )
            return  NULL;
        if ( DOSvol == (t->DOS_drvno + 'A') )
            return  t;
    }

Quote:
}  /* int13unit */

char read_cmos( int addr )
{
    outp( 0x70, addr );
    return  inp( 0x71 );

Quote:
}  /* read_cmos */

char *floppytype( int int13drive )
{
    int cmos_10h = read_cmos( 0x10 );
    if ( int13drive < 0 || int13drive > 1 )
        return "";
    if ( int13drive == 0 )
        cmos_10h >>= 4;
    cmos_10h &= 0x0F;
    switch( cmos_10h )
    {
        case 0:  return  "(no floppy)";
        case 1:  return  "5.25\" 360 kB";
        case 2:  return  "5.25\" 1.2 MB";
        case 3:  return  "3.5\"  720 kB";
        case 4:  return  "3.5\" 1.44 MB";
        case 5:  return  "3.5\" 2.88 MB";
        default: return  "";
    }

Quote:
}  /* floppytype */

void criterr( int install )
/*
 *  Install/deinstall Int 24h Critical Error Handler that just
 *  returns "fail".  Input:  1=installs, 0=deinstalls
 */
{
    static short i24_seg, i24_ofs;
    static char int24_handler[] =
    {
        0xB0, 0x03,   /* mov al, 03h */
        0xCF          /* iret */
    };
    union REGS r;
    struct SREGS s;

    if ( install )
    {
        /* First get -- and remember -- the old interrupt vector */
        segread(&s);
        r.x.ax = 0x3524;
        intdosx( &r, &r, &s );
        i24_seg = s.es, i24_ofs = r.x.bx;

        /* Now install our own Int 24h handler */
        r.x.dx = FP_OFF(int24_handler);
        r.x.ax = 0x2524;
        intdos( &r, &r );
    }

    else
    {
        /* Re-install the old Int 24h handler */
        segread(&s);
        s.ds = i24_seg, r.x.dx = i24_ofs;
        r.x.ax = 0x2524;
        intdosx( &r, &r, &s );
    }

Quote:
}  /* criterr */

main()
{
    char drive;

    criterr(1);  /* We handle our own DOS Critical Errors */

    printf( "Startup drive   %c:\n", startup_drive() );
    printf( "Default drive   %c:\n", default_drive() );

    for( drive='A'; drive<='Z'; drive++ )
    {
        int drvtyp = drivetype(drive);
        int hostdrv;
        int shdrv = logdrvmap( drive );

        if ( drvtyp == -1 )
            continue;
        printf( "Drive %c:  ", drive );
...

read more »



Tue, 14 Oct 1997 03:00:00 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Can't connect to library across mapped network drive

2. Getting Connected Drives Information

3. what kind of drives are connected to the system

4. CHECK DRIVE UNIT COMMAND

5. Disk Drives Check

6. Checking if drive is remote (networked)

7. Check drive A

8. checking if drive is mounted

9. Check Out this Virtual Drive!

10. check if a Internet connect exists?

11. Check if connected through SLIP/PPP?

12. Acucobol how check clients connected ?

 

 
Powered by phpBB® Forum Software