diff --git a/samples/vboxwrapper/vbox_common.cpp b/samples/vboxwrapper/vbox_common.cpp index 4cca281ffb7cdf19bdaeef41c24987be602ff7ed..d026fd81a687c9410a6e78d3329e91b042793588 100644 --- a/samples/vboxwrapper/vbox_common.cpp +++ b/samples/vboxwrapper/vbox_common.cpp @@ -86,6 +86,7 @@ static bool is_timestamp_newer(VBOX_TIMESTAMP& t1, VBOX_TIMESTAMP& t2) { VBOX_BASE::VBOX_BASE() : VBOX_JOB() { VBOX_JOB::clear(); virtualbox_home_directory.clear(); + virtualbox_scratch_directory.clear(); virtualbox_install_directory.clear(); virtualbox_guest_additions.clear(); virtualbox_version.clear(); @@ -363,6 +364,18 @@ bool VBOX_BASE::is_virtualbox_version_newer(int maj, int min, int rel) { return false; } +int VBOX_BASE::get_scratch_directory(string& dir) { + APP_INIT_DATA aid; + boinc_get_init_data_p(&aid); + + dir = aid.project_dir + std::string("/scratch"); + + if (!dir.empty()) { + return 1; + } + return 0; +} + // Returns the current directory in which the executable resides. // int VBOX_BASE::get_slot_directory(string& dir) { diff --git a/samples/vboxwrapper/vbox_common.h b/samples/vboxwrapper/vbox_common.h index 125517dad807997fe70ec53a3b61426017d0b92f..5a07efcb31c3bef81251f10788c15c1fb84b18c7 100644 --- a/samples/vboxwrapper/vbox_common.h +++ b/samples/vboxwrapper/vbox_common.h @@ -101,6 +101,7 @@ public: virtual ~VBOX_BASE(); std::string virtualbox_home_directory; + std::string virtualbox_scratch_directory; std::string virtualbox_install_directory; std::string virtualbox_guest_additions; std::string virtualbox_version; @@ -201,6 +202,7 @@ public: virtual bool is_virtualbox_version_newer(int maj, int min, int rel); static int get_install_directory(std::string& dir); + static int get_scratch_directory(std::string& dir); static int get_version_information(std::string& version); virtual int get_guest_additions(std::string& dir) = 0; virtual int get_slot_directory(std::string& dir); diff --git a/samples/vboxwrapper/vbox_mscom_impl.cpp b/samples/vboxwrapper/vbox_mscom_impl.cpp index 29aa0349703a145c6c360cbafa8b7788fc7aba5a..74ba4ef5451dba663a94656cae016de3db3ae691 100644 --- a/samples/vboxwrapper/vbox_mscom_impl.cpp +++ b/samples/vboxwrapper/vbox_mscom_impl.cpp @@ -822,7 +822,7 @@ int VBOX_VM::create_vm() { } } - // Enable the shared folder if a shared folder is specified. + // Enable the shared folders if a shared folder is specified. // if (enable_shared_directory) { vboxlog_msg("Enabling shared directory for VM."); @@ -833,6 +833,15 @@ int VBOX_VM::create_vm() { TRUE ); if (CHECK_ERROR(rc)) goto CLEANUP; + + vboxlog_msg("Enabling scratch shared directory for VM."); + rc = pMachine->CreateSharedFolder( + CComBSTR("scratch"), + CComBSTR(virtualbox_scratch_directory.c_str()), + TRUE, + TRUE + ); + if (CHECK_ERROR(rc)) goto CLEANUP; } CLEANUP: diff --git a/samples/vboxwrapper/vbox_vboxmanage.cpp b/samples/vboxwrapper/vbox_vboxmanage.cpp index f506cea43c1f5de356eb4f8c280945258737bc6f..2d2849c8f551b7b7059d7192c4633f777bdb266c 100644 --- a/samples/vboxwrapper/vbox_vboxmanage.cpp +++ b/samples/vboxwrapper/vbox_vboxmanage.cpp @@ -82,6 +82,7 @@ int VBOX_VM::initialize() { boinc_get_init_data_p(&aid); get_install_directory(virtualbox_install_directory); + get_scratch_directory(virtualbox_scratch_directory); // Prep the environment so we can execute the vboxmanage application // @@ -610,7 +611,7 @@ int VBOX_VM::create_vm() { } } - // Enable the shared folder if a shared folder is specified. + // Enable the shared folders if a shared folder is specified. // if (enable_shared_directory) { vboxlog_msg("Enabling shared directory for VM."); @@ -620,6 +621,14 @@ int VBOX_VM::create_vm() { retval = vbm_popen(command, output, "enable shared dir"); if (retval) return retval; + + vboxlog_msg("Enabling scratch shared directory for VM."); + command = "sharedfolder add \"" + vm_name + "\" "; + command += "--name \"scratch\" "; + command += "--hostpath \"" + virtualbox_scratch_directory + "\""; + + retval = vbm_popen(command, output, "enable scratch shared dir"); + if (retval) return retval; } return 0; diff --git a/samples/vboxwrapper/vboxwrapper.cpp b/samples/vboxwrapper/vboxwrapper.cpp index b396949d44621ae92acc5780caa4b4b819238e2b..43d52f022bcf3bc91aa7ea2f46794d39c43242db 100644 --- a/samples/vboxwrapper/vboxwrapper.cpp +++ b/samples/vboxwrapper/vboxwrapper.cpp @@ -395,6 +395,7 @@ int main(int argc, char** argv) { bool is_notice = false; int temp_delay = 86400; string message; + string scratch_dir; char buf[256]; // Initialize diagnostics system @@ -594,6 +595,7 @@ int main(int argc, char** argv) { // Validate whatever configuration options we can // if (pVM->enable_shared_directory) { + pVM->get_scratch_directory(scratch_dir); if (boinc_file_exists("shared")) { if (!is_dir("shared")) { vboxlog_msg("ERROR: 'shared' exists but is not a directory."); @@ -601,7 +603,17 @@ int main(int argc, char** argv) { } else { retval = boinc_mkdir("shared"); if (retval) { - vboxlog_msg("ERROR: couldn't created shared directory: %s.", boincerror(retval)); + vboxlog_msg("ERROR: couldn't create shared directory: %s.", boincerror(retval)); + } + } + if (boinc_file_exists(scratch_dir.c_str())) { + if (!is_dir(scratch_dir.c_str())) { + vboxlog_msg("ERROR: 'scratch' exists but is not a directory."); + } + } else { + retval = boinc_mkdir(scratch_dir.c_str()); + if (retval) { + vboxlog_msg("ERROR: couldn't create scratch directory: %s.", boincerror(retval)); } } }