Changeset 36 for rxutilex/trunk/rxutilex.c
- Timestamp:
- Feb 12, 2017, 8:48:39 AM (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
rxutilex/trunk/rxutilex.c
r33 r36 1 1 /****************************************************************************** 2 2 * REXX Utility Functions - Extended (RXUTILEX.DLL) * 3 * (C) 2011, 201 4Alex Taylor. *3 * (C) 2011, 2017 Alex Taylor. * 4 4 * * 5 5 * LICENSE: * … … 45 45 #define INCL_WINCLIPBOARD 46 46 #define INCL_WINERRORS 47 #define INCL_DOS 48 #define INCL_DOSDEVIOCTL 47 49 #define INCL_DOSERRORS 48 50 #define INCL_DOSMISC … … 55 57 #endif 56 58 59 #include <ctype.h> 57 60 #include <stdio.h> 58 61 #include <stdlib.h> … … 88 91 #define SZ_LIBRARY_NAME "RXUTILEX" // Name of this library 89 92 //#define SZ_ERROR_NAME "SYS2ERR" // REXX variable used to store error codes 90 #define SZ_VERSION "0.1. 3" // Current version of this library93 #define SZ_VERSION "0.1.4" // Current version of this library 91 94 92 95 // Maximum string lengths... … … 106 109 #define US_NUMSTR_MAXZ 64 // ...of a formatted number string 107 110 #define US_PIPESTATUS_MAXZ 128 // ...of a pipe status string 111 #define US_DISKINFO_MAXZ 128 // ...of a disk information string 108 112 109 113 #define UL_SSBUFSIZE 0xFFFF // Buffer size for the DosQuerySysState() data … … 124 128 "Sys2QueryProcessList", 125 129 "Sys2KillProcess", 130 "Sys2QueryDriveInfo", 126 131 "Sys2QueryForegroundProcess", 127 132 "Sys2QueryPhysicalMemory", … … 163 168 RexxFunctionHandler Sys2QueryForegroundProcess; 164 169 170 RexxFunctionHandler Sys2QueryDriveInfo; 171 165 172 RexxFunctionHandler Sys2QueryPhysicalMemory; 166 173 167 174 RexxFunctionHandler Sys2LocateDLL; 168 175 RexxFunctionHandler Sys2ReplaceModule; 169 170 // RexxFunctionHandler Sys2ReplaceObjectClass;171 176 172 177 RexxFunctionHandler Sys2CreateNamedPipe; … … 181 186 RexxFunctionHandler Sys2Write; 182 187 RexxFunctionHandler Sys2SyncBuffer; 188 183 189 184 190 // Private internal functions … … 2279 2285 2280 2286 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 * ------------------------------------------------------------------------- */ 2315 ULONG 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 2281 2403 2282 2404 // ------------------------------------------------------------------------- … … 2477 2599 2478 2600 2479 /* MOVED */ 2601 2602 2480 2603 #ifdef NO_SHARED_SOURCE 2604 2605 /**** 2606 **** MOVED TO shfuncs.c 2607 ****/ 2481 2608 2482 2609 /* ------------------------------------------------------------------------- * … … 2501 2628 // 2016-02-20 SHL Rework for easier usage 2502 2629 if (!pchBytes) 2503 ulBytes = 0; // Sync for caller2630 ulBytes = 0; // Sync for caller 2504 2631 if ( ulBytes > 256 ) { 2505 2632 // REXX provides 256 bytes by default; allocate more if necessary … … 2515 2642 } 2516 2643 if (ulBytes) 2517 memcpy( prsResult->strptr, pchBytes, ulBytes );2644 memcpy( prsResult->strptr, pchBytes, ulBytes ); 2518 2645 prsResult->strlength = ulBytes; 2519 2646 … … 2607 2734 } 2608 2735 2609 #endif 2736 #endif // NO_SHARED_SOURCE 2737
Note:
See TracChangeset
for help on using the changeset viewer.