Ignore:
Timestamp:
Feb 12, 2017, 8:48:39 AM (8 years ago)
Author:
Alex Taylor
Message:

Add Sys2QueryDriveInfo function and updated documentation.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • rxutilex/trunk/rxutilex.c

    r33 r36  
    11/******************************************************************************
    22 * REXX Utility Functions - Extended (RXUTILEX.DLL)                           *
    3  * (C) 2011, 2014 Alex Taylor.                                                *
     3 * (C) 2011, 2017 Alex Taylor.                                                *
    44 *                                                                            *
    55 * LICENSE:                                                                   *
     
    4545#define INCL_WINCLIPBOARD
    4646#define INCL_WINERRORS
     47#define INCL_DOS
     48#define INCL_DOSDEVIOCTL
    4749#define INCL_DOSERRORS
    4850#define INCL_DOSMISC
     
    5557#endif
    5658
     59#include <ctype.h>
    5760#include <stdio.h>
    5861#include <stdlib.h>
     
    8891#define SZ_LIBRARY_NAME         "RXUTILEX"  // Name of this library
    8992//#define SZ_ERROR_NAME           "SYS2ERR"   // REXX variable used to store error codes
    90 #define SZ_VERSION              "0.1.3"     // Current version of this library
     93#define SZ_VERSION              "0.1.4"     // Current version of this library
    9194
    9295// Maximum string lengths...
     
    106109#define US_NUMSTR_MAXZ          64                                   // ...of a formatted number string
    107110#define US_PIPESTATUS_MAXZ      128                                  // ...of a pipe status string
     111#define US_DISKINFO_MAXZ        128                                  // ...of a disk information string
    108112
    109113#define UL_SSBUFSIZE            0xFFFF      // Buffer size for the DosQuerySysState() data
     
    124128    "Sys2QueryProcessList",
    125129    "Sys2KillProcess",
     130    "Sys2QueryDriveInfo",
    126131    "Sys2QueryForegroundProcess",
    127132    "Sys2QueryPhysicalMemory",
     
    163168RexxFunctionHandler Sys2QueryForegroundProcess;
    164169
     170RexxFunctionHandler Sys2QueryDriveInfo;
     171
    165172RexxFunctionHandler Sys2QueryPhysicalMemory;
    166173
    167174RexxFunctionHandler Sys2LocateDLL;
    168175RexxFunctionHandler Sys2ReplaceModule;
    169 
    170 // RexxFunctionHandler Sys2ReplaceObjectClass;
    171176
    172177RexxFunctionHandler Sys2CreateNamedPipe;
     
    181186RexxFunctionHandler Sys2Write;
    182187RexxFunctionHandler Sys2SyncBuffer;
     188
    183189
    184190// Private internal functions
     
    22792285
    22802286
     2287/* ------------------------------------------------------------------------- *
     2288 * Sys2QueryDriveInfo                                                        *
     2289 *                                                                           *
     2290 * Get non-filesystem-dependent information about a logical drive (volume).  *
     2291 *                                                                           *
     2292 * REXX ARGUMENTS:                                                           *
     2293 *   1. Drive/volume letter to query, trailing colon optional.    (REQUIRED) *
     2294 *                                                                           *
     2295 * REXX RETURN VALUE:                                                        *
     2296 *   On success, returns a string in the format                              *
     2297 *      <drive> <size> <type> <flag>                                         *
     2298 *   where <drive> is the uppercase drive letter followed by a colon,        *
     2299 *         <size>  is the total size of the drive/volume in binary kilobytes,*
     2300 *         <type>  is one of:                                                *
     2301 *                   FLOPPY_5L - 48 TPI low-density diskette drive           *
     2302 *                   FLOPPY_5H - 96 TPI high-density diskette drive          *
     2303 *                   FLOPPY_3L - 3.5-inch 720KB drive                        *
     2304 *                   FLOPPY_3H - 3.5-inch high-density 1.44MB diskette drive *
     2305 *                   FLOPPY_3X - 3.5-inch ext-density 2.88MB diskette drive  *
     2306 *                   FLOPPY_8L - 8-inch single-density diskette drive        *
     2307 *                   FLOPPY_8H - 8-inch double-density diskette drive        *
     2308 *                   OTHER     - other (including CD drive with no media)    *
     2309 *                   HDD       - hard disk drive (including PRM)             *
     2310 *                   TAPE      - tape drive                                  *
     2311 *                   OPTICAL   - read/write optical drive                    *
     2312 *     and <flag> is 1 for non-partitionable removable media (e.g. floppies) *
     2313 *                or 0 otherwise (including both fixed and PRM disks)        *
     2314 * ------------------------------------------------------------------------- */
     2315ULONG APIENTRY Sys2QueryDriveInfo( PSZ pszName, ULONG argc, RXSTRING argv[], PSZ pszQueue, PRXSTRING prsResult )
     2316{
     2317    BIOSPARAMETERBLOCK data;
     2318    CHAR   szDiskInfo[ US_DISKINFO_MAXZ ];
     2319    UCHAR  achPP[ 2 ],
     2320           chVol;
     2321    ULONG  cbPP,
     2322           cbData,
     2323           ulSectors,
     2324           ulSize;
     2325    BOOL   bRemovable;
     2326    APIRET rc;
     2327
     2328
     2329    // Reset the error indicator
     2330    WriteErrorCode( 0, NULL );
     2331
     2332    // Make sure we have exactly one valid argument (the drive letter)
     2333    if ( argc != 1  || ( !RXVALIDSTRING(argv[0]) ))
     2334        return ( 40 );
     2335    chVol = toupper( argv[0].strptr[0] );
     2336    if (( chVol < 'A') || ( chVol > 'Z'))
     2337        return ( 40 );
     2338
     2339    cbPP = 2;
     2340    achPP[ 0 ] = 0;
     2341    achPP[ 1 ] = chVol - 65;
     2342    cbData = sizeof( data );
     2343    rc = DosDevIOCtl( (HFILE) -1, IOCTL_DISK, DSK_GETDEVICEPARAMS,
     2344                      (PVOID) achPP, 2, &cbPP, &data, cbData, &cbData );
     2345    if ( rc != NO_ERROR ) {
     2346        WriteErrorCode( rc, "DosDevIOCtl");
     2347        SaveResultString( prsResult, NULL, 0 );
     2348        return ( 0 );
     2349    }
     2350
     2351    ulSectors = data.cSectors? data.cSectors: data.cLargeSectors;
     2352    ulSize = (data.usBytesPerSector > 1024) ?
     2353                 (ULONG) (ulSectors * ( data.usBytesPerSector / 1024 )) :
     2354                 (ULONG) (ulSectors / ( 1024 / data.usBytesPerSector ));
     2355    bRemovable = !( data.fsDeviceAttr & 1 );
     2356
     2357    sprintf( szDiskInfo, "%c: %u ", chVol, ulSize );
     2358    switch( data.bDeviceType ) {
     2359        case 0:     // 48 TPI low-density diskette drive
     2360            strncat( szDiskInfo, "FLOPPY_5L", US_DISKINFO_MAXZ-1 );
     2361            break;
     2362        case 1:     // 96 TPI high-density diskette drive
     2363            strncat( szDiskInfo, "FLOPPY_5H", US_DISKINFO_MAXZ-1 );
     2364            break;
     2365        case 2:     // Small (3.5-inch) 720KB drive
     2366            strncat( szDiskInfo, "FLOPPY_3L", US_DISKINFO_MAXZ-1 );
     2367            break;
     2368        case 3:     // 8-inch single-density diskette drive
     2369            strncat( szDiskInfo, "FLOPPY_8L", US_DISKINFO_MAXZ-1 );
     2370            break;
     2371        case 4:     // 8-inch double-density diskette drive
     2372            strncat( szDiskInfo, "FLOPPY_8H", US_DISKINFO_MAXZ-1 );
     2373            break;
     2374        case 5:     // Fixed disk
     2375            strncat( szDiskInfo, "HDD", US_DISKINFO_MAXZ-1 );
     2376            break;
     2377        case 6:     // Tape drive
     2378            strncat( szDiskInfo, "TAPE", US_DISKINFO_MAXZ-1 );
     2379            break;
     2380        case 7:     // Other (includes 1.44MB 3.5-inch diskette drive)
     2381            if ( ulSize == 1440 )
     2382                strncat( szDiskInfo, "FLOPPY_3H", US_DISKINFO_MAXZ-1 );
     2383            else
     2384                strncat( szDiskInfo, "OTHER", US_DISKINFO_MAXZ-1 );
     2385            break;
     2386        case 8:     // R/W optical disk
     2387            strncat( szDiskInfo, "OPTICAL", US_DISKINFO_MAXZ-1 );
     2388            break;
     2389        case 9:     // 3.5-inch 4.0MB diskette drive (2.88MB formatted)
     2390            strncat( szDiskInfo, "FLOPPY_3X", US_DISKINFO_MAXZ-1 );
     2391            break;
     2392        default:
     2393            strncat( szDiskInfo, "UNKNOWN", US_DISKINFO_MAXZ-1 );
     2394            break;
     2395    }
     2396    strncat( szDiskInfo, ( bRemovable? " 1": " 0" ), US_DISKINFO_MAXZ-1 );
     2397
     2398    SaveResultString( prsResult, szDiskInfo, strlen(szDiskInfo) );
     2399    return ( 0 );
     2400}
     2401
     2402
    22812403
    22822404// -------------------------------------------------------------------------
     
    24772599
    24782600
    2479 /* MOVED */
     2601
     2602
    24802603#ifdef NO_SHARED_SOURCE
     2604
     2605/****
     2606 **** MOVED TO shfuncs.c
     2607 ****/
    24812608
    24822609/* ------------------------------------------------------------------------- *
     
    25012628    // 2016-02-20 SHL Rework for easier usage
    25022629    if (!pchBytes)
    2503       ulBytes = 0;                              // Sync for caller
     2630        ulBytes = 0;                              // Sync for caller
    25042631    if ( ulBytes > 256 ) {
    25052632        // REXX provides 256 bytes by default; allocate more if necessary
     
    25152642    }
    25162643    if (ulBytes)
    2517       memcpy( prsResult->strptr, pchBytes, ulBytes );
     2644        memcpy( prsResult->strptr, pchBytes, ulBytes );
    25182645    prsResult->strlength = ulBytes;
    25192646
     
    26072734}
    26082735
    2609 #endif
     2736#endif // NO_SHARED_SOURCE
     2737
Note: See TracChangeset for help on using the changeset viewer.