Changeset 108 for trunk/src/helpers/dosh.c
- Timestamp:
- Oct 13, 2001, 7:57:58 PM (24 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/helpers/dosh.c
r105 r108 69 69 #pragma hdrstop 70 70 71 static const CHAR G_acDriveLetters[28] = " ABCDEFGHIJKLMNOPQRSTUVWXYZ";71 // static const CHAR G_acDriveLetters[28] = " ABCDEFGHIJKLMNOPQRSTUVWXYZ"; 72 72 73 73 /* … … 703 703 PFSQBUFFER2 pfsqBuffer = (PFSQBUFFER2)fsqBuffer; 704 704 705 szName[0] = G_acDriveLetters[ulLogicalDrive];705 szName[0] = ulLogicalDrive + 'A' - 1; 706 706 szName[1] = ':'; 707 707 szName[2] = '\0'; … … 753 753 &ulBootDrive, 754 754 sizeof(ulBootDrive)); 755 return ( G_acDriveLetters[ulBootDrive]);755 return (ulBootDrive + 'A' - 1); 756 756 } 757 757 … … 1034 1034 *@@changed V0.9.1 (99-12-12) [umoeller]: added cbBuf to prototype 1035 1035 *@@changed V0.9.14 (2001-08-01) [umoeller]: fixed, this never respected cbBuf 1036 *@@changed V0.9.16 (2001-10-02) [umoeller]: added check for valid logical disk no 1036 1037 */ 1037 1038 … … 1048 1049 1049 1050 // compose "D:"-type string from logical drive letter 1050 szName[0] = G_acDriveLetters[ulLogicalDrive];1051 szName[1] = ':';1052 szName[2] = '\0';1053 1054 arc = DosQueryFSAttach(szName, // logical drive of attached FS ("D:"-style)1055 0, // ulOrdinal, ignored for FSAIL_QUERYNAME 1056 FSAIL_QUERYNAME, // return name for a drive or device1057 pfsqBuffer, // buffer for returned data1058 &cbBuffer); // sizeof(*pfsqBuffer)1059 1060 if (arc == NO_ERROR)1061 { 1062 if ( pszBuf)1051 if (ulLogicalDrive > 0 && ulLogicalDrive < 27) 1052 { 1053 szName[0] = ulLogicalDrive + 'A' - 1; 1054 szName[1] = ':'; 1055 szName[2] = '\0'; 1056 1057 arc = DosQueryFSAttach(szName, // logical drive of attached FS ("D:"-style) 1058 0, // ulOrdinal, ignored for FSAIL_QUERYNAME 1059 FSAIL_QUERYNAME, // return name for a drive or device 1060 pfsqBuffer, // buffer for returned data 1061 &cbBuffer); // sizeof(*pfsqBuffer) 1062 1063 if (arc == NO_ERROR) 1063 1064 { 1064 // The data for the last three fields in the FSQBUFFER2 1065 // structure are stored at the offset of fsqBuffer.szName. 1066 // Each data field following fsqBuffer.szName begins 1067 // immediately after the previous item. 1068 strncpy(pszBuf, 1069 (CHAR*)(&pfsqBuffer->szName) + pfsqBuffer->cbName + 1, 1070 cbBuf); // V0.9.14 (2001-08-01) [umoeller] 1071 *(pszBuf + cbBuf) = '\0'; 1065 if (pszBuf) 1066 { 1067 // The data for the last three fields in the FSQBUFFER2 1068 // structure are stored at the offset of fsqBuffer.szName. 1069 // Each data field following fsqBuffer.szName begins 1070 // immediately after the previous item. 1071 strncpy(pszBuf, 1072 (CHAR*)(&pfsqBuffer->szName) + pfsqBuffer->cbName + 1, 1073 cbBuf); // V0.9.14 (2001-08-01) [umoeller] 1074 *(pszBuf + cbBuf) = '\0'; 1075 } 1072 1076 } 1073 1077 } 1078 else 1079 arc = ERROR_INVALID_PARAMETER; // V0.9.16 (2001-10-02) [umoeller] 1074 1080 1075 1081 return (arc); … … 1883 1889 ULONG cbWritten; 1884 1890 DosGetDateTime(&dt); 1885 sprintf(szTemp, "Time: %02d:%02d:%02d %s", 1886 dt.hours, dt.minutes, dt.seconds, 1887 pcsz); 1891 sprintf(szTemp, 1892 "Time: %02d:%02d:%02d %s", 1893 dt.hours, dt.minutes, dt.seconds, 1894 pcsz); 1888 1895 return (DosWrite(hfLog, (PVOID)szTemp, strlen(szTemp), &cbWritten)); 1889 1896 } … … 2000 2007 ULONG ulCurDisk = 0; 2001 2008 ULONG ulMap = 0; 2002 arc = DosQueryCurrentDisk(&ulCurDisk, &ulMap); 2003 if (arc == NO_ERROR) 2009 if (!(arc = DosQueryCurrentDisk(&ulCurDisk, &ulMap))) 2004 2010 { 2005 2011 ULONG cbBuf = CCHMAXPATH - 3; 2006 *pszBuf = G_acDriveLetters[ulCurDisk];2012 *pszBuf = ulCurDisk + 'A' - 1; 2007 2013 *(pszBuf + 1) = ':'; 2008 2014 *(pszBuf + 2) = '\\'; … … 2270 2276 2271 2277 // resolve DosPerfSysCall API entry 2272 arc = DosLoadModule(NULL, 0, "DOSCALLS", &pPerfSys->hmod); 2273 if (arc == NO_ERROR) 2278 if (!(arc = DosLoadModule(NULL, 0, "DOSCALLS", &pPerfSys->hmod))) 2274 2279 { 2275 arc = DosQueryProcAddr(pPerfSys->hmod, 2276 976, 2277 "DosPerfSysCall", 2278 (PFN*)(&pPerfSys->pDosPerfSysCall)); 2279 if (arc == NO_ERROR) 2280 if (!(arc = DosQueryProcAddr(pPerfSys->hmod, 2281 976, 2282 "DosPerfSysCall", 2283 (PFN*)(&pPerfSys->pDosPerfSysCall)))) 2280 2284 { 2281 2285 // OK, we got the API: initialize! 2282 arc = pPerfSys->pDosPerfSysCall(CMD_KI_ENABLE, 0, 0, 0); 2283 if (arc == NO_ERROR) 2286 if (!(arc = pPerfSys->pDosPerfSysCall(CMD_KI_ENABLE, 0, 0, 0))) 2284 2287 { 2285 2288 pPerfSys->fInitialized = TRUE; 2286 2289 // call CMD_KI_DISABLE later 2287 2290 2288 arc = pPerfSys->pDosPerfSysCall(CMD_PERF_INFO, 2289 0, 2290 (ULONG)(&pPerfSys->cProcessors), 2291 0); 2292 if (arc == NO_ERROR) 2291 if (!(arc = pPerfSys->pDosPerfSysCall(CMD_PERF_INFO, 2292 0, 2293 (ULONG)(&pPerfSys->cProcessors), 2294 0))) 2293 2295 { 2294 ULONG ul = 0; 2296 ULONG ul = 0, 2297 cProcs = pPerfSys->cProcessors, 2298 cbDouble = cProcs * sizeof(double), 2299 cbLong = cProcs * sizeof(LONG); 2295 2300 2296 2301 // allocate arrays 2297 pPerfSys->paCPUUtils = (PCPUUTIL)calloc(pPerfSys->cProcessors, 2298 sizeof(CPUUTIL)); 2299 if (!pPerfSys->paCPUUtils) 2302 if ( (!(pPerfSys->paCPUUtils = (PCPUUTIL)calloc(cProcs, 2303 sizeof(CPUUTIL)))) 2304 || (!(pPerfSys->padBusyPrev 2305 = (double*)malloc(cbDouble))) 2306 || (!(pPerfSys->padTimePrev 2307 = (double*)malloc(cbDouble))) 2308 || (!(pPerfSys->padIntrPrev 2309 = (double*)malloc(cbDouble))) 2310 || (!(pPerfSys->palLoads 2311 = (PLONG)malloc(cbLong))) 2312 || (!(pPerfSys->palIntrs 2313 = (PLONG)malloc(cbLong))) 2314 ) 2300 2315 arc = ERROR_NOT_ENOUGH_MEMORY; 2301 2316 else 2302 2317 { 2303 pPerfSys->padBusyPrev = (double*)malloc(pPerfSys->cProcessors * sizeof(double)); 2304 if (!pPerfSys->padBusyPrev) 2305 arc = ERROR_NOT_ENOUGH_MEMORY; 2306 else 2318 for (ul = 0; ul < cProcs; ul++) 2307 2319 { 2308 pPerfSys->padTimePrev 2309 = (double*)malloc(pPerfSys->cProcessors * sizeof(double)); 2310 if (!pPerfSys->padTimePrev) 2311 arc = ERROR_NOT_ENOUGH_MEMORY; 2312 else 2313 { 2314 pPerfSys->padIntrPrev 2315 = (double*)malloc(pPerfSys->cProcessors * sizeof(double)); 2316 if (!pPerfSys->padIntrPrev) 2317 arc = ERROR_NOT_ENOUGH_MEMORY; 2318 else 2319 { 2320 pPerfSys->palLoads = (PLONG)malloc(pPerfSys->cProcessors * sizeof(LONG)); 2321 if (!pPerfSys->palLoads) 2322 arc = ERROR_NOT_ENOUGH_MEMORY; 2323 else 2324 { 2325 pPerfSys->palIntrs = (PLONG)malloc(pPerfSys->cProcessors * sizeof(LONG)); 2326 if (!pPerfSys->palIntrs) 2327 arc = ERROR_NOT_ENOUGH_MEMORY; 2328 else 2329 { 2330 for (ul = 0; ul < pPerfSys->cProcessors; ul++) 2331 { 2332 pPerfSys->padBusyPrev[ul] = 0.0; 2333 pPerfSys->padTimePrev[ul] = 0.0; 2334 pPerfSys->padIntrPrev[ul] = 0.0; 2335 pPerfSys->palLoads[ul] = 0; 2336 pPerfSys->palIntrs[ul] = 0; 2337 } 2338 } 2339 } 2340 } 2341 } 2320 pPerfSys->padBusyPrev[ul] = 0.0; 2321 pPerfSys->padTimePrev[ul] = 0.0; 2322 pPerfSys->padIntrPrev[ul] = 0.0; 2323 pPerfSys->palLoads[ul] = 0; 2324 pPerfSys->palIntrs[ul] = 0; 2342 2325 } 2343 2326 } … … 2347 2330 } // end if (arc == NO_ERROR) 2348 2331 2349 if (arc != NO_ERROR)2350 {2332 if (arc) 2333 // error: clean up 2351 2334 doshPerfClose(ppPerfSys); 2352 } 2335 2353 2336 } // end else if (!*ppPerfSys) 2354 2337 … … 2405 2388 else 2406 2389 { 2407 arc = pPerfSys->pDosPerfSysCall(CMD_KI_RDCNT, 2408 (ULONG)pPerfSys->paCPUUtils, 2409 0, 0); 2410 if (arc == NO_ERROR) 2390 if (!(arc = pPerfSys->pDosPerfSysCall(CMD_KI_RDCNT, 2391 (ULONG)pPerfSys->paCPUUtils, 2392 0, 0))) 2411 2393 { 2412 2394 // go thru all processors
Note:
See TracChangeset
for help on using the changeset viewer.