Changeset 36


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

Add Sys2QueryDriveInfo function and updated documentation.

Location:
rxutilex/trunk
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • rxutilex/trunk/TODO

    r21 r36  
    11FUNCTION WISHLIST
    22
    3  * Sys2ReplaceModule - A wrapper for DosReplaceModule()
    43 - Sys2TokenizeString - A string tokenizer
    54 - Sys2FormatCurrency - A strfmon wrapper
     
    2019 ? Access to the Win32 registry     <-- exists in sp1utils
    2120 ? Sys2CloseWindow & Sys2ExitWindow <-- exists in pr1util
    22  ? Sys2ReplaceObjectClass           <-- exists in rexxutil replacement
     21 ? Sys2ReplaceObjectClass           <-- exists in pr1util
    2322 ? Query/extract an object's icon   <-- exists in RWS?
    2423
  • rxutilex/trunk/readme.txt

    r18 r36  
    11REXX Utility Functions - Extended (RXUTILEX.DLL)
    22http://trac.netlabs.org/rexxlibs/
     3
     4This library requires OS/2 4.5x, as it makes use of large file support
     5functions (e.g. DosOpenL).
     6
    37
    48OBJECTIVE
     
    5155
    5256  REXX Utility Functions - Extended (RXUTILEX)
    53   (C) 2011, 2014 Alex Taylor.
     57  (C) 2011, 2017 Alex Taylor.
    5458
    5559  Redistribution and use in source and binary forms, with or without
  • 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
  • rxutilex/trunk/rxutilex.def

    r33 r36  
    11LIBRARY     RXUTILEX INITINSTANCE TERMINSTANCE
    22DATA        MULTIPLE NONSHARED
    3 DESCRIPTION '@#Alex Taylor:0.1.3#@##1## 10 May 2016 22:01:20     REINFORCE::::::@@Extended REXX Utility Functions'
     3DESCRIPTION '@#Alex Taylor:0.1.4#@##1## 12 Feb 2017 16:36:51     REINFORCE::::::@@Extended REXX Utility Functions'
    44
    55EXPORTS     Sys2LoadFuncs
     
    2828Sys2Write
    2929Sys2SyncBuffer
     30Sys2QueryDriveInfo
  • rxutilex/trunk/rxutilex.txt

    r33 r36  
    11FUNCTIONS IN RXUTILEX.DLL
    2 
    3 (See file 'TODO' for functions which are under consideration to be added.)
    42
    53Sys2CheckNamedPipe          - Check the status of a named pipe (server side)
     
    1816Sys2Open                    - Open a file or stream (with >2GB support)
    1917Sys2PutClipboardText        - Copy a text string to the clipboard
     18Sys2QueryDriveInfo          - Get non-filesystem-dependent info about a drive
    2019Sys2QueryForegroundProcess  - Get the PID of the current foreground process
    2120Sys2QueryPhysicalMemory     - Get the amount of installed RAM
     
    4039
    4140Checks the status of a named pipe that was previously created using
    42 Sys2CreateNamedPipe. 
    43 
    44 This function is designed for use by the process that created the pipe 
    45 (i.e. the server side).  Clients which are accessing a named pipe should 
    46 use the standard REXX STREAM and/or CHARS functions to determine the 
     41Sys2CreateNamedPipe.
     42
     43This function is designed for use by the process that created the pipe
     44(i.e. the server side).  Clients which are accessing a named pipe should
     45use the standard REXX STREAM and/or CHARS functions to determine the
    4746pipe's status.
    4847
    4948REXX ARGUMENTS:
    50   1. The pipe handle (from Sys2CreateNamedPipe or DosOpen).  (REQUIRED)
     49  1. The pipe handle (from Sys2CreateNamedPipe or Sys2Open).  (REQUIRED)
    5150
    5251REXX RETURN VALUE:
     
    151150
    152151-------------------------------------------------------------------------
    153 Sys2FormatNumber                                                         
    154                                                                          
     152Sys2FormatNumber
     153
    155154Formats a number to use thousands-grouping characters.  The system values
    156155for the current locale are used for the thousands-grouping character and
    157 the decimal place, if any.  Note that the IBM C runtime's locale 
    158 definitions are used; these may not correspond precisely to the system 
     156the decimal place, if any.  Note that the IBM C runtime's locale
     157definitions are used; these may not correspond precisely to the system
    159158locales as defined in the OS/2 Locale object.
    160159
    161160The input number may be a positive or negative integer or floating point
    162161value.  It must be a simple, non-localized number value; in other words,
    163 it must not contain any thousands-grouping characters, and any decimal 
    164 point which it contains must be a period (rather than any localized 
     162it must not contain any thousands-grouping characters, and any decimal
     163point which it contains must be a period (rather than any localized
    165164decimal symbol).
    166                                                                          
    167 REXX ARGUMENTS:                                                         
    168   1. Number to be formatted.                                  (REQUIRED) 
    169   2. Number of decimal places to use for floating point values. 
     165
     166REXX ARGUMENTS:
     167  1. Number to be formatted.                                  (REQUIRED)
     168  2. Number of decimal places to use for floating point values.
    170169     Ignored for integer values.                            (DEFAULT: 2)
    171                                                                          
    172 REXX RETURN VALUE: The formatted number, or '' on error.                 
     170
     171REXX RETURN VALUE: The formatted number, or '' on error.
    173172
    174173
     
    177176
    178177Converts a number of seconds from the epoch (1970-01-01 0:00:00 UTC) into
    179 a formatted date and time string. 
     178a formatted date and time string.
    180179
    181180REXX ARGUMENTS:
     
    279278
    280279If a DLL with the given name is currently loaded, that instance of the
    281 DLL will be returned.  Otherwise, unless 'L' is specified in the second 
    282 parameter, standard DLL loading rules (which will be governed by the 
     280DLL will be returned.  Otherwise, unless 'L' is specified in the second
     281parameter, standard DLL loading rules (which will be governed by the
    283282current LIBPATH and/or extended LIBPATH configuration) are used to
    284283search for a loadable DLL whose module name matches the one specified.
     
    288287REXX ARGUMENTS:
    289288  1. The name of the DLL to search for.  (REQUIRED)
    290   2. Flag to limit search context, must be one of:                       
     289  2. Flag to limit search context, must be one of:
    291290       A : 'All', search for both loaded and loadable DLLs      (DEFAULT)
    292        L : 'Loaded', search only for currently-loaded DLLs 
     291       L : 'Loaded', search only for currently-loaded DLLs
    293292
    294293
     
    373372
    374373-------------------------------------------------------------------------
     374Sys2QueryDriveInfo
     375
     376Get non-filesystem-dependent information about a logical drive (volume).
     377
     378REXX ARGUMENTS:
     379  1. Drive/volume letter to query, trailing colon optional.    (REQUIRED)
     380
     381REXX RETURN VALUE:
     382  On success, returns a string in the format
     383     <drive> <size> <type> <flag>
     384  where <drive> is the uppercase drive letter followed by a colon,
     385        <size>  is the total size of the drive/volume in binary kilobytes,
     386        <type>  is one of:
     387                  FLOPPY_5L - 48 TPI low-density diskette drive
     388                  FLOPPY_5H - 96 TPI high-density diskette drive
     389                  FLOPPY_3L - 3.5-inch 720KB drive
     390                  FLOPPY_3H - 3.5-inch high-density 1.44MB diskette drive
     391                  FLOPPY_3X - 3.5-inch ext-density 2.88MB diskette drive
     392                  FLOPPY_8L - 8-inch single-density diskette drive
     393                  FLOPPY_8H - 8-inch double-density diskette drive
     394                  OTHER     - other (including CD drive with no media)
     395                  HDD       - hard disk drive (including PRM)
     396                  TAPE      - tape drive
     397                  OPTICAL   - read/write optical drive
     398    and <flag> is 1 for non-partitionable removable media (e.g. floppies)
     399               or 0 otherwise (including both fixed and PRM disks)
     400  On error, returns "".
     401
     402-------------------------------------------------------------------------
    375403Sys2QueryForegroundProcess
    376404
    377405Queries the PID of the current foreground process. (Note that this is not
    378 necessarily the same as the process which is calling this function, which 
     406necessarily the same as the process which is calling this function, which
    379407could, for example, be running in the background and/or as a child of the
    380408foreground process.)
     
    404432Queries information about the specified process.
    405433
    406 Specifying a process ID of 0 will return the information for the 
     434Specifying a process ID of 0 will return the information for the
    407435current process (that is, the process calling this function); note that
    408436this requires the second parameter to specify that the identifier is in
     
    499527Sys2SyncBuffer
    500528
    501 Used to synchronize buffer read/write transactions (wrapper to 
    502 DosResetBuffer).  For external files, writes the buffer to disk. 
    503 For named pipes, blocks until the remote client end of the pipe has read 
     529Used to synchronize buffer read/write transactions (wrapper to
     530DosResetBuffer).  For external files, writes the buffer to disk.
     531For named pipes, blocks until the remote client end of the pipe has read
    504532the contents.
    505                                                                          
    506 REXX ARGUMENTS:                                                         
     533
     534REXX ARGUMENTS:
    507535  1. File handle (as returned by Sys2Open or Sys2CreateNamedPipe).
    508536     (REQUIRED)
    509                                                                          
     537
    510538REXX RETURN VALUE:  1 on success, 0 on failure
    511539
  • rxutilex/trunk/testlib.cmd

    r29 r36  
    3939say Sys2LocateDLL('ehxdlmri', 'l')
    4040say Sys2LocateDLL('gcc1', 'l')
     41say
    4142
     43map = SysDriveMap('A', 'USED')
     44do i = 1 to words( map )
     45    info = Sys2QueryDriveInfo( WORD( map, i ))
     46    if info == '' then info = WORD( map, i ) 'Unable to get drive data ('SYS2ERR')'
     47    say info
     48end
    4249
    4350call Sys2DropFuncs
Note: See TracChangeset for help on using the changeset viewer.