Changeset 75542 in vbox for trunk/src/VBox/Additions/os2/VBoxSF
- Timestamp:
- Nov 17, 2018 3:56:04 AM (6 years ago)
- Location:
- trunk/src/VBox/Additions/os2/VBoxSF
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Additions/os2/VBoxSF/Makefile.kmk
r75461 r75542 216 216 VBoxSFUtil_ASFLAGS = -f obj -DASM_FORMAT_OMF 217 217 VBoxSFUtil_INCS = $(PATH_TOOL_OPENWATCOM)/h/os2 218 VBoxSFUtil_LDFLAGS = -bcl=os2v2 218 VBoxSFUtil_LDFLAGS = -bcl=os2v2 #"IMPORT DosGlobalInfo doscalls.217" 219 VBoxSFUtil_DEFS = $(DEFS) IN_RING3 219 220 else 220 221 VBoxSFUtil_TEMPLATE = VBoxGuestR3Exe -
trunk/src/VBox/Additions/os2/VBoxSF/VBoxSFUtil.cpp
r75461 r75542 34 34 *********************************************************************************************************************************/ 35 35 #include <string.h> 36 #include <stdarg.h> 36 37 #include <stdio.h> 37 38 #include <stdint.h> 38 39 #include <stdlib.h> 39 40 #define INCL_BASE 41 #define INCL_DOSINFOSEG 40 42 #define OS2EMX_PLAIN_CHAR 41 43 #include <os2.h> 44 #include <iprt/asm-amd64-x86.h> 42 45 43 46 … … 47 50 extern "C" APIRET __cdecl CallDosQFileMode(const char *pszFilename, PUSHORT pfAttr, ULONG ulReserved); 48 51 52 #ifndef GETGINFOSEG 53 typedef struct _GINFOSEG 54 { 55 ULONG time; 56 ULONG msecs; 57 UCHAR hour; 58 UCHAR minutes; 59 UCHAR seconds; 60 UCHAR hundredths; 61 USHORT timezone; 62 USHORT cusecTimerInterval; 63 UCHAR day; 64 UCHAR month; 65 USHORT year; 66 UCHAR weekday; 67 UCHAR uchMajorVersion; 68 UCHAR uchMinorVersion; 69 UCHAR chRevisionLetter; 70 UCHAR sgCurrent; 71 UCHAR sgMax; 72 UCHAR cHugeShift; 73 UCHAR fProtectModeOnly; 74 USHORT pidForeground; 75 UCHAR fDynamicSched; 76 UCHAR csecMaxWait; 77 USHORT cmsecMinSlice; 78 USHORT cmsecMaxSlice; 79 USHORT bootdrive; 80 UCHAR amecRAS[32]; 81 UCHAR csgWindowableVioMax; 82 UCHAR csgPMMax; 83 USHORT SIS_Syslog; 84 USHORT SIS_MMIOBase; 85 USHORT SIS_MMIOAddr; 86 UCHAR SIS_MaxVDMs; 87 UCHAR SIS_Reserved; 88 } GINFOSEG; 89 typedef GINFOSEG *PGINFOSEG; 90 91 extern "C" void _System DOS16GLOBALINFO(void); 92 # define GETGINFOSEG() ((PGINFOSEG)(void *)(((unsigned)&DOS16GLOBALINFO & 0xfff8) << 13)) 93 94 #endif 95 96 97 /********************************************************************************************************************************* 98 * Global Variables * 99 *********************************************************************************************************************************/ 100 static GINFOSEG volatile *g_pGInfoSeg; 101 static PTIB g_pTib; 102 static PPIB g_pPib; 103 104 105 static int syntaxError(const char *pszFormat, ...) 106 { 107 fprintf(stderr, "syntax error: "); 108 va_list va; 109 va_start(va, pszFormat); 110 vfprintf(stderr, pszFormat, va); 111 va_end(va); 112 if (strchr(pszFormat, '\0')[-1] != '\n') 113 fputc('\n', stderr); 114 return 2; 115 } 116 117 118 static int error(const char *pszFormat, ...) 119 { 120 fprintf(stderr, "error: "); 121 va_list va; 122 va_start(va, pszFormat); 123 vfprintf(stderr, pszFormat, va); 124 va_end(va); 125 if (strchr(pszFormat, '\0')[-1] != '\n') 126 fputc('\n', stderr); 127 return 1; 128 } 49 129 50 130 … … 55 135 */ 56 136 if (argc != 3) 57 { 58 fprintf(stderr, "syntax error: Expected three arguments to 'use' command\n"); 59 return 2; 60 } 137 return syntaxError("Expected three arguments to 'use' command\n"); 61 138 62 139 /* The drive letter. */ … … 68 145 { /* likely */ } 69 146 else 70 { 71 fprintf(stderr, "syntax error: Invalid drive specification '%s', expected something like 'K:'.\n", pszDrive); 72 return 2; 73 } 147 return syntaxError("Invalid drive specification '%s', expected something like 'K:'.\n", pszDrive); 74 148 75 149 /* The shared folder. */ … … 79 153 { /* likely */ } 80 154 else 81 { 82 fprintf(stderr, "syntax error: Shared folder name '%s' is too %s!\n", pszFolder, cchFolder >= 1 ? "long" : "short"); 83 return 2; 84 } 155 return syntaxError("Shared folder name '%s' is too %s!\n", pszFolder, cchFolder >= 1 ? "long" : "short"); 85 156 86 157 /* … … 93 164 return 0; 94 165 } 95 fprintf(stderr, "error: DosFSAttach failed: %lu\n", rc); 96 return 1; 166 return error("DosFSAttach failed: %lu\n", rc); 97 167 } 98 168 … … 355 425 pszArg = "h"; 356 426 else 357 { 358 fprintf(stderr, "syntax error: Unknown option: %s\n", argv[i]); 359 return 2; 360 } 427 return syntaxError("Unknown option: %s\n", argv[i]); 361 428 } 362 429 do … … 371 438 pszValue = argv[++i]; 372 439 else 373 { 374 fprintf(stderr, "syntax error: -%c takes a value\n", chOpt); 375 return 2; 376 } 440 return syntaxError("-%c takes a value\n", chOpt); 377 441 pszArg = ""; 378 442 } … … 398 462 return 0; 399 463 default: 400 fprintf(stderr, "syntax error: Unknown option '%c' (%s)\n", chOpt, argv[i - (pszValue != NULL)]); 401 return 2; 464 return syntaxError("Unknown option '%c' (%s)\n", chOpt, argv[i - (pszValue != NULL)]); 402 465 } 403 466 … … 413 476 pbBuf = (uint8_t *)malloc(cbBuf); 414 477 if (!pbBuf) 415 { 416 fprintf(stderr, "error: out of memory (cbBuf=%#x)\n", cbBuf); 417 return 1; 418 } 478 return error("out of memory (cbBuf=%#x)\n", cbBuf); 419 479 } 420 480 … … 503 563 504 564 565 static int vboxSfOs2UtilBenchFStat(int argc, char **argv) 566 { 567 int rcRet = 0; 568 bool fOptions = true; 569 unsigned msRuntime = 5*1000; 570 for (int i = 1; i < argc; i++) 571 { 572 /* 573 * Parse arguments. 574 */ 575 const char *pszArg = argv[i]; 576 if (*pszArg == '-' && fOptions) 577 { 578 if (*++pszArg == '-') 579 { 580 pszArg++; 581 if (*pszArg == '\0') 582 { 583 fOptions = false; 584 continue; 585 } 586 if (strcmp(pszArg, "runtime") == 0) 587 pszArg = "r"; 588 else if (strcmp(pszArg, "help") == 0) 589 pszArg = "h"; 590 else 591 return syntaxError("Unknown option: %s", argv[i]); 592 } 593 594 while (*pszArg != '\0') 595 { 596 char chOpt = *pszArg++; 597 const char *pszValue = NULL; 598 if (chOpt == 'r') 599 { 600 if (*pszArg != '\0') 601 { 602 pszValue = *pszArg == ':' || *pszArg == '=' ? pszArg + 1 : pszArg; 603 pszArg = ""; 604 } 605 else if (i + 1 < argc) 606 pszValue = argv[++i]; 607 else 608 return syntaxError("Expected value after -%c.", chOpt); 609 } 610 switch (chOpt) 611 { 612 case 'r': 613 msRuntime = atoi(pszValue); 614 break; 615 616 default: 617 return syntaxError("Unknown option: -%c", chOpt); 618 } 619 } 620 } 621 /* 622 * Run tests on the file. 623 */ 624 else 625 { 626 ULONG ulAction = 0; 627 HFILE hFile = NULLHANDLE; 628 APIRET rc = DosOpen(pszArg, &hFile, &ulAction, 0 /*cbFile*/, FILE_NORMAL, 629 OPEN_ACTION_FAIL_IF_NEW | OPEN_ACTION_OPEN_IF_EXISTS, 630 OPEN_SHARE_DENYNONE | OPEN_ACCESS_READONLY | OPEN_FLAGS_FAIL_ON_ERROR, NULL /*pEaBuf*/); 631 if (rc == NO_ERROR) 632 { 633 /* Do a test run. */ 634 FILESTATUS3 Info; 635 rc = DosQueryFileInfo(hFile, FIL_STANDARD, &Info, sizeof(Info)); 636 if (rc == NO_ERROR) 637 { 638 printf("Testing '%s'...\n", pszArg); 639 640 /* Tread water till the microsecond count changes. */ 641 ULONG msStart = g_pGInfoSeg->msecs; 642 while (g_pGInfoSeg->msecs == msStart) 643 { /* nothing */ } 644 645 /* Do the actual testing. */ 646 msStart = g_pGInfoSeg->msecs; 647 ULONG cCalls = 0; 648 uint64_t cTscElapsed = ASMReadTSC(); 649 do 650 { 651 cCalls++; 652 rc = DosQueryFileInfo(hFile, FIL_STANDARD, &Info, sizeof(Info)); 653 } while (rc == NO_ERROR && g_pGInfoSeg->msecs - msStart < msRuntime ); 654 cTscElapsed = ASMReadTSC() - cTscElapsed; 655 656 if (rc == NO_ERROR) 657 printf("%7lu calls in %14lu ms - %6llu ns per call\n" 658 "%7lu calls in %14llu ticks - %6llu ticks per call\n", 659 cCalls, msRuntime, msRuntime * (uint64_t)1000000 / cCalls, 660 cCalls, cTscElapsed, cTscElapsed / cCalls); 661 else 662 rcRet = error("DosQueryFileInfo failed on '%s' after %u calls: %u", pszArg, cCalls, rc); 663 } 664 else 665 rcRet = error("DosQueryFileInfo failed on '%s': %u", pszArg, rc); 666 DosClose(hFile); 667 } 668 else 669 rcRet = error("DosOpen failed on '%s': %u", pszArg, rc); 670 } 671 } 672 return rcRet; 673 } 674 675 505 676 int main(int argc, char **argv) 506 677 { 678 g_pGInfoSeg = GETGINFOSEG(); 679 DosGetInfoBlocks(&g_pTib, &g_pPib); 680 507 681 /* 508 682 * Parse input. … … 519 693 if (strcmp(pszArg, "mkdir") == 0) 520 694 return vboxSfOs2UtilMkDir(argc - i, argv + i); 695 if (strcmp(pszArg, "benchfstat") == 0) 696 return vboxSfOs2UtilBenchFStat(argc - i, argv + i); 521 697 522 698 fprintf(stderr, "Unknown command/option: %s\n", pszArg);
Note:
See TracChangeset
for help on using the changeset viewer.