VBoxServiceToolBox.cpp revision 83a235f69fa15d92a6f5e7ad6f6a61b5a2c18962
/* $Id$ */
/** @file
* VBoxServiceToolBox - Internal (BusyBox-like) toolbox.
*/
/*
* Copyright (C) 2010 Oracle Corporation
*
* This file is part of VirtualBox Open Source Edition (OSE), as
* available from http://www.virtualbox.org. This file is free software;
* General Public License (GPL) as published by the Free Software
* Foundation, in version 2 as it comes in the "COPYING" file of the
* VirtualBox OSE distribution. VirtualBox OSE is distributed in the
* hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
*/
/*******************************************************************************
* Header Files *
*******************************************************************************/
#include <stdio.h>
#ifndef RT_OS_WINDOWS
#endif
#include <VBox/VBoxGuestLib.h>
#include "VBoxServiceInternal.h"
#include "VBoxServiceUtils.h"
/** @todo r=bird: Don't use VBoxServiceError here, just use RTMsg**. */
/** @todo r=bird: 'static' is a wonderful keyword, please use it as much as
* possible like I've said in the coding guidelines. Not only does it
* help wrt to linking, but it also helps understanding what's
* internal and external interfaces in a source file! */
/**
* Displays a help text to stdout.
*/
void VBoxServiceToolboxShowUsage(void)
{
RTPrintf("Toolbox Usage:\n"
"cat [FILE] - Concatenate FILE(s), or standard input, to standard output\n"
"\n");
}
/**
*
*
* @return int
*
* @param pszFormat
*/
int VBoxServiceToolboxErrorSyntax(const char *pszFormat, ...)
{
RTPrintf("\n"
return VERR_INVALID_PARAMETER;
}
/**
*
*
* @return int
*
* @param hInput
* @param hOutput
*/
{
int rc = VINF_SUCCESS;
if (hInput == NIL_RTFILE)
{
if (RT_FAILURE(rc))
}
if (hOutput == NIL_RTFILE)
{
if (RT_FAILURE(rc))
}
if (RT_SUCCESS(rc))
{
for (;;)
{
{
cbRead = 0;
}
else
{
if ( cbRead == 0
&& rc == VERR_BROKEN_PIPE)
{
rc = VINF_SUCCESS;
}
break;
}
}
}
return rc;
}
/** @todo r=bird: Again, function headers like this are uslesss and better left
* out. */
/**
*
*
* @return int
*
* @param argc
* @param argv
*/
{
static const RTGETOPTDEF s_aOptions[] =
{
};
int ch;
/** @todo r=bird: Pass RTGETOPTINIT_FLAGS_OPTS_FIRST, our mkdir shall be
* like the GNU one wrt to option (dash-something) and argument
* order (dirs). */
int rc = VINF_SUCCESS;
bool fMakeParentDirs = false;
bool fVerbose = false;
char szDir[RTPATH_MAX];
#ifdef RT_OS_WINDOWS
#else
RTFMODE fileMode = S_IRWXU | S_IRWXG | S_IRWXO; /** @todo r=bird: We've got RTFS_ defines for these, they are x-platform. Why 'file' when we're creating directories? */
#endif
&& RT_SUCCESS(rc))
{
/* For options that require an argument, ValueUnion has received the value. */
switch (ch)
{
case 'p':
fMakeParentDirs = true;
break;
case 'm':
VBoxServiceVerbose(0, "mkdir: Mode flag strings not implemented yet!\n");
break;
case 'v':
fVerbose = true;
break;
case VINF_GETOPT_NOT_OPTION:
{
if (RT_FAILURE(rc))
VBoxServiceError("mkdir: Could not build absolute directory!\n");
/** @todo r=bird: you can make multiple directories just by
* adding them to the mkdir command line:
* because the two previous steps weren't executed. It
* will also leak memory, but that's not important. (Also,
* I don't get why we need to call RTPathAbs here as nobody
* is going to change the current directory.) */
break;
}
/** @todo r=bird: Missing handling of the standard options 'V' and
* 'h'. */
default:
}
}
if (RT_SUCCESS(rc))
{
if (fMakeParentDirs || newMode)
{
#ifndef RT_OS_WINDOWS
if (newMode)
#endif
}
rc = fMakeParentDirs ?
VBoxServiceVerbose(0, "mkdir: Created directory '%s', mode 0x%RTfmode\n", szDir, fileMode); /** @todo r=bird: drop the 0x here, use %#RTfmode instead. */
{
if (pMsg)
else
}
}
else if (fVerbose)
return rc;
}
/**
*
*
* @return int
*
* @param argc
* @param argv
*/
{
static const RTGETOPTDEF s_aOptions[] =
{
/** @todo r=bird: Missing options 'A', 'b', 'e', 'E', 'n', 's', 'T',
* 'u', 'v' as found on 'man cat' on a linux system. They must
* not be implemented, just return an apologetic error message. */
};
int ch;
int rc = VINF_SUCCESS;
&& RT_SUCCESS(rc))
{
/* For options that require an argument, ValueUnion has received the value. */
switch (ch)
{
/** @todo r=bird: You add a flag --no-content-indexed without a
* short form (use a #define CAT_OPT_NO_CONTENT_INDEXED 1000 for
* iShort). */
case 'f':
/* Process flags; no fancy parsing here yet. */
else
{
VBoxServiceError("cat: Unknown flag set!\n");
}
break;
case 'o':
if (RT_FAILURE(rc))
VBoxServiceError("cat: Could not create output file \"%s\"! rc=%Rrc\n",
break;
/** @todo r=bird: Again, there shall be no need for any -i
* options since all non-options are input files. */
case 'i':
case VINF_GETOPT_NOT_OPTION:
{
if (RT_FAILURE(rc))
VBoxServiceError("cat: Could not open input file \"%s\"! rc=%Rrc\n",
break;
}
/** @todo r=bird: Missing handling of the standard options 'V' and
* 'h'. */
default:
}
}
if (RT_SUCCESS(rc))
if (hInput != NIL_RTFILE)
if (hOutput != NIL_RTFILE)
return rc;
}
/**
* Main routine for toolbox command line handling.
*
* @return int
*
* @param argc
* @param argv
*/
{
/** @todo r=bird: The return type of this function is mixed; both RTEXITCODE
* and IPRT status code. That doesn't cut it. The RTEXITCODE part should
* be returned separately from the handled-or-unhandled bit.
*
* Also, please change VBoxServiceToolboxCat and VBoxServiceToolboxMkDir to
* return RTEXITCODE and use RTMsg* like RTZipTarCmd (and later
* RTZipGzipCmd). */
int rc = VERR_NOT_FOUND;
if (argc > 0) /* Do we have at least a main command? */
{
{
}
{
}
}
if (rc != VERR_NOT_FOUND)
return rc;
}