VirtualBox

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

Last change on this file since 78382 was 76553, checked in by vboxsync, 6 years ago

scm --update-copyright-year

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 2.8 KB
Line 
1/* $Id: tstSSM-2.cpp 76553 2019-01-01 01:45:53Z vboxsync $ */
2/** @file
3 * Saved State Manager Testcase: Extract the content of a saved state.
4 */
5
6/*
7 * Copyright (C) 2015-2019 Oracle Corporation
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.virtualbox.org. This file is free software;
11 * you can redistribute it and/or modify it under the terms of the GNU
12 * General Public License (GPL) as published by the Free Software
13 * Foundation, in version 2 as it comes in the "COPYING" file of the
14 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
15 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
16 */
17
18
19/*********************************************************************************************************************************
20* Header Files *
21*********************************************************************************************************************************/
22#include <VBox/vmm/ssm.h>
23
24#include <VBox/log.h>
25#include <iprt/getopt.h>
26#include <iprt/errcore.h>
27#include <iprt/file.h>
28#include <iprt/path.h>
29#include <iprt/stream.h>
30
31static RTEXITCODE extractUnit(const char *pszFilename, const char *pszUnitname, const char *pszOutputFilename)
32{
33 PSSMHANDLE pSSM;
34 int rc = SSMR3Open(pszFilename, 0, &pSSM);
35 RTEXITCODE rcExit = RTEXITCODE_FAILURE;
36 if (RT_SUCCESS(rc))
37 {
38 RTFILE hFile;
39 rc = RTFileOpen(&hFile, pszOutputFilename, RTFILE_O_DENY_NONE | RTFILE_O_WRITE | RTFILE_O_CREATE);
40 if (RT_SUCCESS(rc))
41 {
42 uint32_t version = 0;
43 rc = SSMR3Seek(pSSM, pszUnitname, 0 /* iInstance */, &version);
44 size_t cbUnit = 0;
45 if (RT_SUCCESS(rc))
46 {
47 for (;;)
48 {
49 uint8_t u8;
50 rc = SSMR3GetU8(pSSM, &u8);
51 if (RT_FAILURE(rc))
52 break;
53 size_t cbWritten;
54 rc = RTFileWrite(hFile, &u8, sizeof(u8), &cbWritten);
55 cbUnit++;
56 }
57 RTPrintf("Unit size %zu bytes, version %d\n", cbUnit, version);
58 }
59 else
60 RTPrintf("Cannot find unit '%s' (%Rrc)\n", pszUnitname, rc);
61 RTFileClose(hFile);
62 }
63 else
64 RTPrintf("Cannot open output file '%s' (%Rrc)\n", pszOutputFilename, rc);
65 SSMR3Close(pSSM);
66 }
67 else
68 RTPrintf("Cannot open SSM file '%s' (%Rrc)\n", pszFilename, rc);
69 return rcExit;
70}
71
72int main(int argc, char **argv)
73{
74 if (argc != 4)
75 {
76 RTPrintf("Usage: %s <SSM filename> <SSM unitname> <outfile>\n", RTPathFilename(argv[0]));
77 /* don't fail by default */
78 return RTEXITCODE_SUCCESS;
79 }
80 return extractUnit(argv[1], argv[2], argv[3]);
81}
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