Changeset 37340 in vbox for trunk/src/VBox/Additions
- Timestamp:
- Jun 7, 2011 11:25:35 AM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Additions/common/VBoxService/VBoxServiceToolBox.cpp
r36754 r37340 5 5 6 6 /* 7 * Copyright (C) 201 0Oracle Corporation7 * Copyright (C) 2011 Oracle Corporation 8 8 * 9 9 * This file is part of VirtualBox Open Source Edition (OSE), as … … 46 46 #define CAT_OPT_NO_CONTENT_INDEXED 1000 47 47 48 /* Enable the following define to be able to debug/invoke the toolbox 49 * commandos directly from command line, e.g. VBoxService vbox_cat [args] */ 50 #ifdef DEBUG 51 //# define VBOXSERVICE_TOOLBOX_DEBUG 52 #endif 53 48 54 /** 49 55 * An file/directory entry. Used to cache … … 68 74 "\n" 69 75 /** @todo Document options! */ 70 "mkdir [OPTION] DIRECTORY... - Create the DIRECTORY(ies), if they do not already exist.\n" 76 "mkdir [OPTION]... DIRECTORY... - Create the DIRECTORY(ies), if they do not already exist.\n" 77 "\n" 78 /** @todo Document options! */ 79 "stat [OPTION]... FILE... - Display file or file system status.\n" 80 "\n" 71 81 /** @todo Document options! */ 72 82 "\n"); … … 226 236 RTGetOptInit(&GetState, argc, argv, 227 237 s_aOptions, RT_ELEMENTS(s_aOptions), 228 1 /* Index of argv to start with. */, RTGETOPTINIT_FLAGS_OPTS_FIRST); 238 /* Index of argv to start with. */ 239 #ifdef VBOXSERVICE_TOOLBOX_DEBUG 240 2, 241 #else 242 1, 243 #endif 244 RTGETOPTINIT_FLAGS_OPTS_FIRST); 229 245 230 246 int rc = VINF_SUCCESS; … … 357 373 RTGETOPTUNION ValueUnion; 358 374 RTGETOPTSTATE GetState; 359 RTGetOptInit(&GetState, argc, argv, s_aOptions, RT_ELEMENTS(s_aOptions), 1, 0); 375 376 RTGetOptInit(&GetState, argc, argv, 377 s_aOptions, RT_ELEMENTS(s_aOptions), 378 /* Index of argv to start with. */ 379 #ifdef VBOXSERVICE_TOOLBOX_DEBUG 380 2, 381 #else 382 1, 383 #endif 384 0); 360 385 361 386 int rc = VINF_SUCCESS; … … 483 508 484 509 /** 510 * Main function for tool "vbox_stat". 511 * 512 * @return RTEXITCODE. 513 * @param argc Number of arguments. 514 * @param argv Pointer to argument array. 515 */ 516 static RTEXITCODE VBoxServiceToolboxStat(int argc, char **argv) 517 { 518 static const RTGETOPTDEF s_aOptions[] = 519 { 520 { "--file-system", 'f', RTGETOPT_REQ_NOTHING }, 521 { "--dereference", 'L', RTGETOPT_REQ_NOTHING }, 522 { "--terse", 't', RTGETOPT_REQ_NOTHING }, 523 { "--verbose", 'v', RTGETOPT_REQ_NOTHING } 524 }; 525 526 int ch; 527 RTGETOPTUNION ValueUnion; 528 RTGETOPTSTATE GetState; 529 RTGetOptInit(&GetState, argc, argv, 530 s_aOptions, RT_ELEMENTS(s_aOptions), 531 /* Index of argv to start with. */ 532 #ifdef VBOXSERVICE_TOOLBOX_DEBUG 533 2, 534 #else 535 1, 536 #endif 537 RTGETOPTINIT_FLAGS_OPTS_FIRST); 538 539 int rc = VINF_SUCCESS; 540 bool fVerbose = false; 541 542 /* Init file list. */ 543 RTLISTNODE fileList; 544 RTListInit(&fileList); 545 546 while ( (ch = RTGetOpt(&GetState, &ValueUnion)) 547 && RT_SUCCESS(rc)) 548 { 549 /* For options that require an argument, ValueUnion has received the value. */ 550 switch (ch) 551 { 552 case 'h': 553 VBoxServiceToolboxShowUsage(); 554 return RTEXITCODE_SUCCESS; 555 556 case 'f': 557 case 'L': 558 RTMsgError("stat: Sorry, option '%s' is not implemented yet!\n", 559 ValueUnion.pDef->pszLong); 560 rc = VERR_INVALID_PARAMETER; 561 break; 562 563 case 'v': 564 fVerbose = true; 565 break; 566 567 case 'V': 568 VBoxServiceToolboxShowVersion(); 569 return RTEXITCODE_SUCCESS; 570 571 case VINF_GETOPT_NOT_OPTION: 572 { 573 /* Add file(s) to buffer. This enables processing multiple files 574 * at once. 575 * 576 * Since the non-options (RTGETOPTINIT_FLAGS_OPTS_FIRST) come last when 577 * processing this loop it's safe to immediately exit on syntax errors 578 * or showing the help text (see above). */ 579 rc = VBoxServiceToolboxPathBufAddPathEntry(&fileList, ValueUnion.psz); 580 break; 581 } 582 583 default: 584 return RTGetOptPrintError(ch, &ValueUnion); 585 } 586 } 587 588 if (RT_SUCCESS(rc)) 589 { 590 PVBOXSERVICETOOLBOXPATHENTRY pNodeIt; 591 RTListForEach(&fileList, pNodeIt, VBOXSERVICETOOLBOXPATHENTRY, Node) 592 { 593 /* Only check for file existence for now. */ 594 if (RTFileExists(pNodeIt->pszName)) 595 { 596 /** @todo Do some more work (query size etc.) here later. 597 * Not needed for now. */ 598 } 599 else 600 { 601 RTMsgError("stat: Cannot stat for '%s': No such file or directory\n", 602 pNodeIt->pszName); 603 rc = VERR_FILE_NOT_FOUND; 604 /* Do not break here -- process every file in the list 605 * and keep failing rc. */ 606 } 607 } 608 609 if (RTListIsEmpty(&fileList)) 610 RTMsgError("stat: Missing operand\n"); 611 } 612 else if (fVerbose) 613 RTMsgError("stat: Failed with rc=%Rrc\n", rc); 614 615 VBoxServiceToolboxPathBufDestroy(&fileList); 616 return RT_SUCCESS(rc) ? RTEXITCODE_SUCCESS : RTEXITCODE_FAILURE; 617 } 618 619 620 /** 485 621 * Entry point for internal toolbox. 486 622 * … … 495 631 if (argc > 0) /* Do we have at least a main command? */ 496 632 { 497 if ( !strcmp(argv[0], "cat") 498 || !strcmp(argv[0], "vbox_cat")) 633 int iCmdIdx = 0; 634 #ifdef VBOXSERVICE_TOOLBOX_DEBUG 635 iCmdIdx = 1; 636 #endif 637 if ( !strcmp(argv[iCmdIdx], "cat") 638 || !strcmp(argv[iCmdIdx], "vbox_cat")) 499 639 { 500 640 *prcExit = VBoxServiceToolboxCat(argc, argv); … … 502 642 } 503 643 504 if ( !strcmp(argv[ 0], "mkdir")505 || !strcmp(argv[ 0], "vbox_mkdir"))644 if ( !strcmp(argv[iCmdIdx], "mkdir") 645 || !strcmp(argv[iCmdIdx], "vbox_mkdir")) 506 646 { 507 647 *prcExit = VBoxServiceToolboxMkDir(argc, argv); 508 648 return true; 509 649 } 650 651 if ( !strcmp(argv[iCmdIdx], "stat") 652 || !strcmp(argv[iCmdIdx], "vbox_stat")) 653 { 654 *prcExit = VBoxServiceToolboxStat(argc, argv); 655 return true; 656 } 510 657 } 511 658 return false;
Note:
See TracChangeset
for help on using the changeset viewer.