VirtualBox

source: vbox/trunk/src/VBox/Main/include/UnattendedImpl.h@ 93533

Last change on this file since 93533 was 93533, checked in by vboxsync, 3 years ago

Main/Unattended: bugref:9781. Reading and storing image index from the xml metadata.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 11.7 KB
Line 
1/* $Id: UnattendedImpl.h 93533 2022-02-01 14:07:44Z vboxsync $ */
2/** @file
3 * Unattended class header
4 */
5
6/*
7 * Copyright (C) 2006-2022 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#ifndef MAIN_INCLUDED_UnattendedImpl_h
19#define MAIN_INCLUDED_UnattendedImpl_h
20#ifndef RT_WITHOUT_PRAGMA_ONCE
21# pragma once
22#endif
23
24#include <VBox/ostypes.h>
25#include <iprt/time.h>
26#include "UnattendedWrap.h"
27
28/* Forward declarations. */
29class UnattendedInstaller;
30struct UnattendedInstallationDisk;
31struct ControllerSlot;
32
33/**
34 * A data type to store image data which is read from intall.wim file.
35 * Currently relevant only for Windows OSs.
36 */
37struct WIMImage
38{
39 Utf8Str mName;
40 Utf8Str mVersionMajor;
41 Utf8Str mVersionMinor;
42 Utf8Str mVersionBuild;
43 uint32_t mImageIndex;
44 Utf8Str getNameAndVersion() const;
45};
46
47/**
48 * Class implementing the IUnattended interface.
49 *
50 * This class is instantiated on the request by IMachine::getUnattended.
51 */
52class ATL_NO_VTABLE Unattended
53 : public UnattendedWrap
54{
55public:
56 DECLARE_COMMON_CLASS_METHODS(Unattended)
57
58 HRESULT FinalConstruct();
59 void FinalRelease();
60
61 // public initializer/uninitializer for internal purposes only
62 HRESULT initUnattended(VirtualBox *aParent);
63 void uninit();
64
65 // public methods for internal purposes
66 Utf8Str const &i_getIsoPath() const;
67 Utf8Str const &i_getUser() const;
68 Utf8Str const &i_getPassword() const;
69 Utf8Str const &i_getFullUserName() const;
70 Utf8Str const &i_getProductKey() const;
71 Utf8Str const &i_getProxy() const;
72 Utf8Str const &i_getAdditionsIsoPath() const;
73 bool i_getInstallGuestAdditions() const;
74 Utf8Str const &i_getValidationKitIsoPath() const;
75 bool i_getInstallTestExecService() const;
76 Utf8Str const &i_getTimeZone() const;
77 PCRTTIMEZONEINFO i_getTimeZoneInfo() const;
78 Utf8Str const &i_getLocale() const;
79 Utf8Str const &i_getLanguage() const;
80 Utf8Str const &i_getCountry() const;
81 bool i_isMinimalInstallation() const;
82 Utf8Str const &i_getHostname() const;
83 Utf8Str const &i_getAuxiliaryBasePath() const;
84 ULONG i_getImageIndex() const;
85 Utf8Str const &i_getScriptTemplatePath() const;
86 Utf8Str const &i_getPostInstallScriptTemplatePath() const;
87 Utf8Str const &i_getPostInstallCommand() const;
88 /** The directory where the unattended install config and script is
89 * located, from the perspective of the running unattended install. */
90 Utf8Str const &i_getAuxiliaryInstallDir() const;
91 Utf8Str const &i_getExtraInstallKernelParameters() const;
92
93 bool i_isRtcUsingUtc() const;
94 bool i_isGuestOs64Bit() const;
95 bool i_isFirmwareEFI() const;
96 Utf8Str const &i_getDetectedOSVersion();
97
98
99private:
100 ComPtr<VirtualBox> const mParent; /**< Strong reference to the parent object (VirtualBox/IMachine). */
101 ComPtr<Machine> mMachine; /**< Strong reference to the machine object (Machine/IMachine). */
102 Guid mMachineUuid; /**< The machine UUID. */
103 RTNATIVETHREAD mhThreadReconfigureVM; /**< Set when reconfigureVM is running. */
104 Utf8Str mStrGuestOsTypeId; /**< Guest OS type ID (set by prepare). */
105 bool mfRtcUseUtc; /**< Copy of IMachine::RTCUseUTC (locking reasons). */
106 bool mfGuestOs64Bit; /**< 64-bit (true) or 32-bit guest OS (set by prepare). */
107 FirmwareType_T menmFirmwareType; /**< Firmware type BIOS/EFI (set by prepare). */
108 UnattendedInstaller *mpInstaller; /**< The installer instance (set by prepare, deleted by done). */
109
110 /** @name Values of the IUnattended attributes.
111 * @{ */
112 Utf8Str mStrUser;
113 Utf8Str mStrPassword;
114 Utf8Str mStrFullUserName;
115 Utf8Str mStrProductKey;
116 Utf8Str mStrIsoPath;
117 Utf8Str mStrAdditionsIsoPath;
118 bool mfInstallGuestAdditions;
119 bool mfInstallTestExecService;
120 Utf8Str mStrValidationKitIsoPath;
121 Utf8Str mStrTimeZone;
122 PCRTTIMEZONEINFO mpTimeZoneInfo;
123 Utf8Str mStrLocale;
124 Utf8Str mStrLanguage; /**< (only relevant for windows at the moment) */
125 Utf8Str mStrCountry;
126 RTCList<RTCString, RTCString *> mPackageSelectionAdjustments;
127 Utf8Str mStrHostname;
128 Utf8Str mStrAuxiliaryBasePath;
129 bool mfIsDefaultAuxiliaryBasePath;
130 ULONG midxImage;
131 Utf8Str mStrScriptTemplatePath;
132 Utf8Str mStrPostInstallScriptTemplatePath;
133 Utf8Str mStrPostInstallCommand;
134 Utf8Str mStrExtraInstallKernelParameters;
135 Utf8Str mStrProxy;
136
137 bool mfDoneDetectIsoOS; /**< Set by detectIsoOS(), cleared by setIsoPath(). */
138 Utf8Str mStrDetectedOSTypeId;
139 Utf8Str mStrDetectedOSVersion;
140 Utf8Str mStrDetectedOSFlavor;
141 RTCList<RTCString, RTCString *> mDetectedOSLanguages; /**< (only relevant for windows at the moment) */
142 Utf8Str mStrDetectedOSHints;
143 RTCList<WIMImage> mDetectedImages;
144 /** @} */
145
146 // wrapped IUnattended functions:
147
148 /**
149 * Checks what mStrIsoPath points to and sets the detectedOS* properties.
150 */
151 HRESULT detectIsoOS();
152
153 /**
154 * Prepare any data, environment, etc.
155 */
156 HRESULT prepare();
157
158 /**
159 * Prepare installation ISO/floppy.
160 */
161 HRESULT constructMedia();
162
163 /**
164 * Prepare a VM to run an unattended installation
165 */
166 HRESULT reconfigureVM();
167
168 /**
169 * Done with all media construction and VM configuration and stuff.
170 */
171 HRESULT done();
172
173 // wrapped IUnattended attributes:
174 HRESULT getIsoPath(com::Utf8Str &isoPath);
175 HRESULT setIsoPath(const com::Utf8Str &isoPath);
176 HRESULT getUser(com::Utf8Str &user);
177 HRESULT setUser(const com::Utf8Str &user);
178 HRESULT getPassword(com::Utf8Str &password);
179 HRESULT setPassword(const com::Utf8Str &password);
180 HRESULT getFullUserName(com::Utf8Str &user);
181 HRESULT setFullUserName(const com::Utf8Str &user);
182 HRESULT getProductKey(com::Utf8Str &productKey);
183 HRESULT setProductKey(const com::Utf8Str &productKey);
184 HRESULT getAdditionsIsoPath(com::Utf8Str &additionsIsoPath);
185 HRESULT setAdditionsIsoPath(const com::Utf8Str &additionsIsoPath);
186 HRESULT getInstallGuestAdditions(BOOL *installGuestAdditions);
187 HRESULT setInstallGuestAdditions(BOOL installGuestAdditions);
188 HRESULT getValidationKitIsoPath(com::Utf8Str &aValidationKitIsoPath);
189 HRESULT setValidationKitIsoPath(const com::Utf8Str &aValidationKitIsoPath);
190 HRESULT getInstallTestExecService(BOOL *aInstallTestExecService);
191 HRESULT setInstallTestExecService(BOOL aInstallTestExecService);
192 HRESULT getTimeZone(com::Utf8Str &aTimezone);
193 HRESULT setTimeZone(const com::Utf8Str &aTimezone);
194 HRESULT getLocale(com::Utf8Str &aLocale);
195 HRESULT setLocale(const com::Utf8Str &aLocale);
196 HRESULT getLanguage(com::Utf8Str &aLanguage);
197 HRESULT setLanguage(const com::Utf8Str &aLanguage);
198 HRESULT getCountry(com::Utf8Str &aCountry);
199 HRESULT setCountry(const com::Utf8Str &aCountry);
200 HRESULT getProxy(com::Utf8Str &aProxy);
201 HRESULT setProxy(const com::Utf8Str &aProxy);
202 HRESULT getPackageSelectionAdjustments(com::Utf8Str &aPackageSelectionAdjustments);
203 HRESULT setPackageSelectionAdjustments(const com::Utf8Str &aPackageSelectionAdjustments);
204 HRESULT getHostname(com::Utf8Str &aHostname);
205 HRESULT setHostname(const com::Utf8Str &aHostname);
206 HRESULT getAuxiliaryBasePath(com::Utf8Str &aAuxiliaryBasePath);
207 HRESULT setAuxiliaryBasePath(const com::Utf8Str &aAuxiliaryBasePath);
208 HRESULT getImageIndex(ULONG *index);
209 HRESULT setImageIndex(ULONG index);
210 HRESULT getMachine(ComPtr<IMachine> &aMachine);
211 HRESULT setMachine(const ComPtr<IMachine> &aMachine);
212 HRESULT getScriptTemplatePath(com::Utf8Str &aScriptTemplatePath);
213 HRESULT setScriptTemplatePath(const com::Utf8Str &aScriptTemplatePath);
214 HRESULT getPostInstallScriptTemplatePath(com::Utf8Str &aPostInstallScriptTemplatePath);
215 HRESULT setPostInstallScriptTemplatePath(const com::Utf8Str &aPostInstallScriptTemplatePath);
216 HRESULT getPostInstallCommand(com::Utf8Str &aPostInstallCommand);
217 HRESULT setPostInstallCommand(const com::Utf8Str &aPostInstallCommand);
218 HRESULT getExtraInstallKernelParameters(com::Utf8Str &aExtraInstallKernelParameters);
219 HRESULT setExtraInstallKernelParameters(const com::Utf8Str &aExtraInstallKernelParameters);
220 HRESULT getDetectedOSTypeId(com::Utf8Str &aDetectedOSTypeId);
221 HRESULT getDetectedOSVersion(com::Utf8Str &aDetectedOSVersion);
222 HRESULT getDetectedOSLanguages(com::Utf8Str &aDetectedOSLanguages);
223 HRESULT getDetectedOSFlavor(com::Utf8Str &aDetectedOSFlavor);
224 HRESULT getDetectedOSHints(com::Utf8Str &aDetectedOSHints);
225 HRESULT getDetectedImageNames(std::vector<com::Utf8Str> &aDetectedImageNames);
226 //internal functions
227
228 /**
229 * Worker for detectIsoOs().
230 *
231 * @returns COM status code.
232 * @retval S_OK if detected.
233 * @retval S_FALSE if not detected.
234 *
235 * @param hVfsIso The ISO file system handle.
236 */
237 HRESULT i_innerDetectIsoOS(RTVFS hVfsIso);
238 typedef union DETECTBUFFER
239 {
240 char sz[4096];
241 char ach[4096];
242 uint8_t ab[4096];
243 uint32_t au32[1024];
244 } DETECTBUFFER;
245 HRESULT i_innerDetectIsoOSWindows(RTVFS hVfsIso, DETECTBUFFER *puBuf, VBOXOSTYPE *penmOsType);
246 HRESULT i_innerDetectIsoOSLinux(RTVFS hVfsIso, DETECTBUFFER *puBuf, VBOXOSTYPE *penmOsType);
247 HRESULT i_innerDetectIsoOSOs2(RTVFS hVfsIso, DETECTBUFFER *puBuf, VBOXOSTYPE *penmOsType);
248
249 /**
250 * Worker for reconfigureVM().
251 * The caller makes sure to close the session whatever happens.
252 */
253 HRESULT i_innerReconfigureVM(AutoMultiWriteLock2 &rAutoLock, StorageBus_T enmRecommendedStorageBus,
254 ComPtr<IMachine> const &rPtrSessionMachine);
255 HRESULT i_reconfigureFloppy(com::SafeIfaceArray<IStorageController> &rControllers,
256 std::vector<UnattendedInstallationDisk> &rVecInstallatationDisks,
257 ComPtr<IMachine> const &rPtrSessionMachine,
258 AutoMultiWriteLock2 &rAutoLock);
259 HRESULT i_reconfigureIsos(com::SafeIfaceArray<IStorageController> &rControllers,
260 std::vector<UnattendedInstallationDisk> &rVecInstallatationDisks,
261 ComPtr<IMachine> const &rPtrSessionMachine,
262 AutoMultiWriteLock2 &rAutoLock, StorageBus_T enmRecommendedStorageBus);
263
264 /**
265 * Adds all free slots on the controller to @a rOutput.
266 */
267 HRESULT i_findOrCreateNeededFreeSlots(const Utf8Str &rStrControllerName, StorageBus_T enmStorageBus,
268 ComPtr<IMachine> const &rPtrSessionMachine, uint32_t cSlotsNeeded,
269 std::list<ControllerSlot> &rDvdSlots);
270
271 /**
272 * Attach to VM a disk
273 */
274 HRESULT i_attachImage(UnattendedInstallationDisk const *pImage, ComPtr<IMachine> const &rPtrSessionMachine,
275 AutoMultiWriteLock2 &rLock);
276
277 /*
278 * Wrapper functions
279 */
280
281 /**
282 * Check whether guest is 64bit platform or not
283 */
284 bool i_isGuestOSArchX64(Utf8Str const &rStrGuestOsTypeId);
285};
286
287#endif /* !MAIN_INCLUDED_UnattendedImpl_h */
Note: See TracBrowser for help on using the repository browser.

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