/* $Id: VBoxServiceToolBox.cpp 44863 2013-02-28 12:18:17Z vboxsync $ */ /** @file * VBoxServiceToolbox - Internal (BusyBox-like) toolbox. */ /* * Copyright (C) 2012 Oracle Corporation * * This file is part of VirtualBox Open Source Edition (OSE), as * available from http://www.virtualbox.org. This file is free software; * you can redistribute it and/or modify it under the terms of the GNU * 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 #include #include #include #include #include #include #include #include #include #include #include #include #ifndef RT_OS_WINDOWS # include /* need umask */ #endif #include #include #include "VBoxServiceInternal.h" #include "VBoxServiceUtils.h" /******************************************************************************* * Defined Constants And Macros * *******************************************************************************/ /** Generic option indices for commands. */ enum { VBOXSERVICETOOLBOXOPT_MACHINE_READABLE = 1000, VBOXSERVICETOOLBOXOPT_VERBOSE }; /** Options indices for "vbox_cat". */ typedef enum VBOXSERVICETOOLBOXCATOPT { VBOXSERVICETOOLBOXCATOPT_NO_CONTENT_INDEXED = 1000 } VBOXSERVICETOOLBOXCATOPT; /** Flags for "vbox_ls". */ typedef enum VBOXSERVICETOOLBOXLSFLAG { VBOXSERVICETOOLBOXLSFLAG_NONE = 0x0, VBOXSERVICETOOLBOXLSFLAG_RECURSIVE = 0x1, VBOXSERVICETOOLBOXLSFLAG_SYMLINKS = 0x2 } VBOXSERVICETOOLBOXLSFLAG; /** Flags for fs object output. */ typedef enum VBOXSERVICETOOLBOXOUTPUTFLAG { VBOXSERVICETOOLBOXOUTPUTFLAG_NONE = 0x0, VBOXSERVICETOOLBOXOUTPUTFLAG_LONG = 0x1, VBOXSERVICETOOLBOXOUTPUTFLAG_PARSEABLE = 0x2 } VBOXSERVICETOOLBOXOUTPUTFLAG; /******************************************************************************* * Structures and Typedefs * *******************************************************************************/ /** Pointer to a handler function. */ typedef RTEXITCODE (*PFNHANDLER)(int , char **); /** * An file/directory entry. Used to cache * file names/paths for later processing. */ typedef struct VBOXSERVICETOOLBOXPATHENTRY { /** Our node. */ RTLISTNODE Node; /** Name of the entry. */ char *pszName; } VBOXSERVICETOOLBOXPATHENTRY, *PVBOXSERVICETOOLBOXPATHENTRY; typedef struct VBOXSERVICETOOLBOXDIRENTRY { /** Our node. */ RTLISTNODE Node; /** The actual entry. */ RTDIRENTRYEX dirEntry; } VBOXSERVICETOOLBOXDIRENTRY, *PVBOXSERVICETOOLBOXDIRENTRY; /** * Displays a common header for all help text to stdout. */ static void VBoxServiceToolboxShowUsageHeader(void) { RTPrintf(VBOX_PRODUCT " Guest Toolbox Version " VBOX_VERSION_STRING "\n" "(C) " VBOX_C_YEAR " " VBOX_VENDOR "\n" "All rights reserved.\n" "\n"); RTPrintf("Usage:\n\n"); } /** * Displays a help text to stdout. */ static void VBoxServiceToolboxShowUsage(void) { VBoxServiceToolboxShowUsageHeader(); RTPrintf(" VBoxService [--use-toolbox] vbox_ [] \n\n" "General options:\n\n" " --machinereadable produce all output in machine-readable form\n" " -V print version number and exit\n" "\n" "Commands:\n\n" " cat [] ...\n" " ls [] [--dereference|-L] [-l] [-R]\n" " [--verbose|-v] [...]\n" " rm [] [-r|-R] ...\n" " mktemp [] [--directory|-d] [--mode|-m ]\n" " [--secure|-s] [--tmpdir|-t ]\n" "