Ignore:
Timestamp:
Jan 4, 2002, 3:11:23 PM (24 years ago)
Author:
sandervl
Message:

rewrote GetDriveType

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/kernel32/oslibdos.cpp

    r7704 r7724  
    1 /* $Id: oslibdos.cpp,v 1.91 2001-12-30 11:04:19 sandervl Exp $ */
     1/* $Id: oslibdos.cpp,v 1.92 2002-01-04 14:11:23 sandervl Exp $ */
    22/*
    33 * Wrappers for OS/2 Dos* API
     
    25522552}
    25532553//******************************************************************************
     2554
     2555#define FSAttachSpace 100
     2556
     2557#define CDType         0x8000
     2558#define FloppyType     0x4000
     2559#define LanType        0x2000
     2560#define LogicalType    0x1000
     2561#define VDISKType      0x0800
     2562#define OpticalType    0x0400
     2563#define NonRemovable   0x01
     2564
     2565#define FirstDrive             0
     2566#define B_Drive_0_Based        1
     2567#define Base_1_offset          1
     2568#define Binary_to_Printable 0x41
     2569#define LastDrive             26
     2570#define OpticalSectorsPerCluster 4
     2571
     2572#define DisketteCylinders 80
     2573
     2574#ifndef DEVTYPE_OPTICAL
     2575#define DEVTYPE_OPTICAL                    0x0008
     2576#endif
     2577
     2578// used for input to logical disk Get device parms Ioctl
     2579struct {
     2580        UCHAR Infotype;
     2581        UCHAR DriveUnit;
     2582        } DriveRequest;
     2583
     2584// used for CD number of units Ioctl
     2585struct {
     2586        USHORT count;
     2587        USHORT first;
     2588        } cdinfo;
     2589
     2590//******************************************************************************
     2591ULONG OSLibGetDriveType(ULONG DriveIndex)
     2592{
     2593 ULONG  ulDriveNum = 0;
     2594 ULONG  ulDriveMap = 0;
     2595 APIRET rc;
     2596 ULONG  parmsize,datasize;
     2597 ULONG  mask,Action;
     2598 HFILE  handle;
     2599 UCHAR  devname[5]="c:";
     2600 PFSQBUFFER2 fsinfo;
     2601 ULONG  len;
     2602 PSZ    name;
     2603 BIOSPARAMETERBLOCK device = {0};
     2604 UINT   type;
     2605
     2606    rc = DosQueryCurrentDisk(&ulDriveNum, &ulDriveMap);
     2607    mask = 1 << DriveIndex;
     2608
     2609    if(rc == NO_ERROR && (mask & ulDriveMap))
     2610    {//drive present??
     2611        parmsize=sizeof(DriveRequest);
     2612        datasize=sizeof(device);
     2613        DriveRequest.Infotype  = 0;
     2614        DriveRequest.DriveUnit = (UCHAR)DriveIndex;
     2615
     2616        // Get BIOS parameter block
     2617        if(DosDevIOCtl(-1, IOCTL_DISK,DSK_GETDEVICEPARAMS,
     2618                       (PVOID)&DriveRequest, sizeof(DriveRequest),
     2619                       &parmsize, (PVOID)&device,
     2620                       sizeof(BIOSPARAMETERBLOCK), &datasize) == NO_ERROR)
     2621        {
     2622            if(device.bDeviceType == 0 && device.fsDeviceAttr == 0)
     2623            {   // fix for LAN type drives
     2624                device.fsDeviceAttr = LanType;
     2625            }
     2626        }
     2627        else {//could be a LAN drive
     2628            device.fsDeviceAttr = LanType;
     2629        }
     2630    }
     2631    else {
     2632        //drive not present -> fail
     2633        return DRIVE_DOESNOTEXIST_W;
     2634    }
     2635
     2636    // check for CD drives
     2637    if(DosOpen("\\DEV\\CD-ROM2$", &handle,&Action,
     2638               0, FILE_NORMAL, OPEN_ACTION_OPEN_IF_EXISTS,
     2639               OPEN_SHARE_DENYNONE|OPEN_ACCESS_READONLY, NULL) == 0)
     2640    {
     2641        datasize=sizeof(cdinfo);
     2642        rc = DosDevIOCtl(handle, 0x82, 0x60,
     2643                         NULL, 0,
     2644                         NULL, (PVOID)&cdinfo,
     2645                         sizeof(cdinfo),
     2646                         &datasize);
     2647        if(rc == NO_ERROR)
     2648        {
     2649            // this is a CDROM/DVD drive
     2650            if(cdinfo.first <= DriveIndex && DriveIndex < cdinfo.first + cdinfo.count)
     2651                device.fsDeviceAttr |= CDType;
     2652        }
     2653        DosClose(handle);
     2654    }
     2655
     2656    // disable error popups
     2657    DosError(FERR_DISABLEEXCEPTION | FERR_DISABLEHARDERR);
     2658
     2659    fsinfo = (PFSQBUFFER2)malloc(FSAttachSpace);
     2660
     2661    // if the device is removable and NOT a CD
     2662    if(device.bDeviceType || device.fsDeviceAttr == LanType)
     2663    {
     2664        if((device.fsDeviceAttr & (CDType | NonRemovable)) == 0)
     2665        {
     2666            devname[0] = (UCHAR)(DriveIndex+Binary_to_Printable);
     2667            len        = FSAttachSpace;
     2668            rc = DosQueryFSAttach((PSZ) devname, 0L, FSAIL_QUERYNAME,
     2669                                  fsinfo, &len);
     2670            if(rc == NO_ERROR)
     2671            {
     2672                if(fsinfo->iType == FSAT_REMOTEDRV) {
     2673                   device.fsDeviceAttr |= LanType;
     2674                }
     2675                else
     2676                if(fsinfo->iType == FSAT_LOCALDRV)
     2677                {
     2678                    name = (char *) fsinfo->szName;
     2679                    name += strlen(name)+1;
     2680                    if(strcmp(name,"FAT") == 0)
     2681                    {
     2682                        // device is a removable FAT drive, so it MUST be diskette
     2683                        // as Optical has another name as does LAN and SRVIFS
     2684                        if(device.bSectorsPerCluster != OpticalSectorsPerCluster)
     2685                        {
     2686                             device.fsDeviceAttr |= FloppyType;
     2687                        }
     2688                        else device.fsDeviceAttr |= OpticalType;
     2689                    }
     2690                 }
     2691            }
     2692            else // must be no media or audio only (for CDs at least)
     2693            {
     2694                if(device.cCylinders <= DisketteCylinders) // floppies will always be 80
     2695                {                                          // or less cylinders
     2696                    if(device.bSectorsPerCluster != OpticalSectorsPerCluster) {
     2697                         device.fsDeviceAttr |= FloppyType;
     2698                    }
     2699                    else device.fsDeviceAttr |= OpticalType;
     2700                }
     2701            }
     2702        }
     2703        else     
     2704        {// non removable or CD type. maybe RAM disk
     2705            if(!(device.fsDeviceAttr & CDType))       // if NOT CD
     2706            {
     2707                if(device.cFATs == 1)                 // is there only one FAT?
     2708                   device.fsDeviceAttr |= VDISKType;  // -> RAM disk
     2709            }
     2710        }
     2711    }
     2712    free(fsinfo);
     2713
     2714    if(device.fsDeviceAttr & FloppyType) {
     2715        type = DRIVE_REMOVABLE_W;
     2716    }
     2717    else
     2718    if(device.fsDeviceAttr & CDType) {
     2719        type = DRIVE_CDROM_W;
     2720    }
     2721    else
     2722    if(device.fsDeviceAttr & LanType) {
     2723        type = DRIVE_REMOTE_W;
     2724    }
     2725    else
     2726    if(device.fsDeviceAttr & VDISKType) {
     2727        type = DRIVE_RAMDISK_W;
     2728    }
     2729    else
     2730    if(device.fsDeviceAttr & OpticalType || device.bDeviceType == DEVTYPE_OPTICAL) {
     2731        type = DRIVE_FIXED_W;
     2732    }
     2733    else
     2734    if(device.bDeviceType == DEVTYPE_FIXED) {
     2735        type = DRIVE_FIXED_W;
     2736    }
     2737    else type = 0;
     2738
     2739    //Enable error popups again
     2740    DosError(FERR_ENABLEEXCEPTION | FERR_ENABLEHARDERR);
     2741
     2742    return type;
     2743}
     2744//******************************************************************************
    25542745//Returns bit map where with the mapping of the logical drives
    25552746//******************************************************************************
Note: See TracChangeset for help on using the changeset viewer.