VirtualBox

source: vbox/trunk/src/VBox/VMM/testcase/tstSSM-2.cpp@ 107876

Last change on this file since 107876 was 107808, checked in by vboxsync, 4 weeks ago

VMM/testcase/tstSSM-2.cpp: Print error message when writing the SSM unit failed, bugref:3409

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 3.5 KB
Line 
1/* $Id: tstSSM-2.cpp 107808 2025-01-16 10:35:41Z vboxsync $ */
2/** @file
3 * Saved State Manager Testcase: Extract the content of a saved state.
4 */
5
6/*
7 * Copyright (C) 2015-2024 Oracle and/or its affiliates.
8 *
9 * This file is part of VirtualBox base platform packages, as
10 * available from https://www.virtualbox.org.
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation, in version 3 of the
15 * License.
16 *
17 * This program is distributed in the hope that it will be useful, but
18 * WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, see <https://www.gnu.org/licenses>.
24 *
25 * SPDX-License-Identifier: GPL-3.0-only
26 */
27
28
29/*********************************************************************************************************************************
30* Header Files *
31*********************************************************************************************************************************/
32#include <VBox/vmm/ssm.h>
33
34#include <VBox/log.h>
35#include <iprt/assert.h>
36#include <iprt/getopt.h>
37#include <iprt/errcore.h>
38#include <iprt/file.h>
39#include <iprt/path.h>
40#include <iprt/stream.h>
41#include <iprt/initterm.h>
42
43static RTEXITCODE extractUnit(const char *pszFilename, const char *pszUnitname, const char *pszOutputFilename)
44{
45 PSSMHANDLE pSSM;
46 int rc = SSMR3Open(pszFilename, NULL /*pStreamOps*/, NULL /*pvStreamOps*/, 0, &pSSM);
47 RTEXITCODE rcExit = RTEXITCODE_FAILURE;
48 if (RT_SUCCESS(rc))
49 {
50 RTFILE hFile;
51 rc = RTFileOpen(&hFile, pszOutputFilename, RTFILE_O_DENY_NONE | RTFILE_O_WRITE | RTFILE_O_CREATE);
52 if (RT_SUCCESS(rc))
53 {
54 uint32_t version = 0;
55 rc = SSMR3Seek(pSSM, pszUnitname, 0 /* iInstance */, &version);
56 size_t cbUnit = 0;
57 if (RT_SUCCESS(rc))
58 {
59 for (;;)
60 {
61 uint8_t u8;
62 rc = SSMR3GetU8(pSSM, &u8);
63 if (RT_FAILURE(rc))
64 break;
65 size_t cbWritten;
66 rc = RTFileWrite(hFile, &u8, sizeof(u8), &cbWritten);
67 if (RT_FAILURE(rc))
68 RTPrintf("Writing unit '%s' to '%s' failed with %Rrc\n",
69 pszUnitname, pszOutputFilename, rc);
70 cbUnit++;
71 }
72 RTPrintf("Unit size %zu bytes, version %d\n", cbUnit, version);
73 }
74 else
75 RTPrintf("Cannot find unit '%s' (%Rrc)\n", pszUnitname, rc);
76 RTFileClose(hFile);
77 }
78 else
79 RTPrintf("Cannot open output file '%s' (%Rrc)\n", pszOutputFilename, rc);
80 SSMR3Close(pSSM);
81 }
82 else
83 RTPrintf("Cannot open SSM file '%s' (%Rrc)\n", pszFilename, rc);
84 return rcExit;
85}
86
87int main(int argc, char **argv)
88{
89 int rc = RTR3InitExe(argc, &argv, 0);
90 AssertRCReturn(rc, RTEXITCODE_INIT);
91
92 if (argc != 4)
93 {
94 RTPrintf("Usage: %s <SSM filename> <SSM unitname> <outfile>\n", RTPathFilename(argv[0]));
95 /* don't fail by default */
96 return RTEXITCODE_SUCCESS;
97 }
98 return extractUnit(argv[1], argv[2], argv[3]);
99}
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette