VirtualBox

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

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

Main/Unattended: Get the image architecture if we can. bugref:9781

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 11.8 KB
Line 
1/* $Id: UnattendedImpl.h 93578 2022-02-03 12:39:56Z 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 mVersion;
41 Utf8Str mArch;
42 uint32_t mImageIndex;
43 Utf8Str getNameAndVersion() const;
44};
45
46/**
47 * Class implementing the IUnattended interface.
48 *
49 * This class is instantiated on the request by IMachine::getUnattended.
50 */
51class ATL_NO_VTABLE Unattended
52 : public UnattendedWrap
53{
54public:
55 DECLARE_COMMON_CLASS_METHODS(Unattended)
56
57 HRESULT FinalConstruct();
58 void FinalRelease();
59
60 // public initializer/uninitializer for internal purposes only
61 HRESULT initUnattended(VirtualBox *aParent);
62 void uninit();
63
64 // public methods for internal purposes
65 Utf8Str const &i_getIsoPath() const;
66 Utf8Str const &i_getUser() const;
67 Utf8Str const &i_getPassword() const;
68 Utf8Str const &i_getFullUserName() const;
69 Utf8Str const &i_getProductKey() const;
70 Utf8Str const &i_getProxy() const;
71 Utf8Str const &i_getAdditionsIsoPath() const;
72 bool i_getInstallGuestAdditions() const;
73 Utf8Str const &i_getValidationKitIsoPath() const;
74 bool i_getInstallTestExecService() const;
75 Utf8Str const &i_getTimeZone() const;
76 PCRTTIMEZONEINFO i_getTimeZoneInfo() const;
77 Utf8Str const &i_getLocale() const;
78 Utf8Str const &i_getLanguage() const;
79 Utf8Str const &i_getCountry() const;
80 bool i_isMinimalInstallation() const;
81 Utf8Str const &i_getHostname() const;
82 Utf8Str const &i_getAuxiliaryBasePath() const;
83 ULONG i_getImageIndex() const;
84 Utf8Str const &i_getScriptTemplatePath() const;
85 Utf8Str const &i_getPostInstallScriptTemplatePath() const;
86 Utf8Str const &i_getPostInstallCommand() const;
87 /** The directory where the unattended install config and script is
88 * located, from the perspective of the running unattended install. */
89 Utf8Str const &i_getAuxiliaryInstallDir() const;
90 Utf8Str const &i_getExtraInstallKernelParameters() const;
91
92 bool i_isRtcUsingUtc() const;
93 bool i_isGuestOs64Bit() const;
94 bool i_isFirmwareEFI() const;
95 Utf8Str const &i_getDetectedOSVersion();
96
97
98private:
99 ComPtr<VirtualBox> const mParent; /**< Strong reference to the parent object (VirtualBox/IMachine). */
100 ComPtr<Machine> mMachine; /**< Strong reference to the machine object (Machine/IMachine). */
101 Guid mMachineUuid; /**< The machine UUID. */
102 RTNATIVETHREAD mhThreadReconfigureVM; /**< Set when reconfigureVM is running. */
103 Utf8Str mStrGuestOsTypeId; /**< Guest OS type ID (set by prepare). */
104 bool mfRtcUseUtc; /**< Copy of IMachine::RTCUseUTC (locking reasons). */
105 bool mfGuestOs64Bit; /**< 64-bit (true) or 32-bit guest OS (set by prepare). */
106 FirmwareType_T menmFirmwareType; /**< Firmware type BIOS/EFI (set by prepare). */
107 UnattendedInstaller *mpInstaller; /**< The installer instance (set by prepare, deleted by done). */
108
109 /** @name Values of the IUnattended attributes.
110 * @{ */
111 Utf8Str mStrUser;
112 Utf8Str mStrPassword;
113 Utf8Str mStrFullUserName;
114 Utf8Str mStrProductKey;
115 Utf8Str mStrIsoPath;
116 Utf8Str mStrAdditionsIsoPath;
117 bool mfInstallGuestAdditions;
118 bool mfInstallTestExecService;
119 Utf8Str mStrValidationKitIsoPath;
120 Utf8Str mStrTimeZone;
121 PCRTTIMEZONEINFO mpTimeZoneInfo;
122 Utf8Str mStrLocale;
123 Utf8Str mStrLanguage; /**< (only relevant for windows at the moment) */
124 Utf8Str mStrCountry;
125 RTCList<RTCString, RTCString *> mPackageSelectionAdjustments;
126 Utf8Str mStrHostname;
127 Utf8Str mStrAuxiliaryBasePath;
128 bool mfIsDefaultAuxiliaryBasePath;
129 ULONG midxImage;
130 Utf8Str mStrScriptTemplatePath;
131 Utf8Str mStrPostInstallScriptTemplatePath;
132 Utf8Str mStrPostInstallCommand;
133 Utf8Str mStrExtraInstallKernelParameters;
134 Utf8Str mStrProxy;
135
136 bool mfDoneDetectIsoOS; /**< Set by detectIsoOS(), cleared by setIsoPath(). */
137 Utf8Str mStrDetectedOSTypeId;
138 Utf8Str mStrDetectedOSVersion;
139 Utf8Str mStrDetectedOSFlavor;
140 RTCList<RTCString, RTCString *> mDetectedOSLanguages; /**< (only relevant for windows at the moment) */
141 Utf8Str mStrDetectedOSHints;
142 RTCList<WIMImage> mDetectedImages;
143 /** @} */
144
145 // wrapped IUnattended functions:
146
147 /**
148 * Checks what mStrIsoPath points to and sets the detectedOS* properties.
149 */
150 HRESULT detectIsoOS();
151
152 /**
153 * Prepare any data, environment, etc.
154 */
155 HRESULT prepare();
156
157 /**
158 * Prepare installation ISO/floppy.
159 */
160 HRESULT constructMedia();
161
162 /**
163 * Prepare a VM to run an unattended installation
164 */
165 HRESULT reconfigureVM();
166
167 /**
168 * Done with all media construction and VM configuration and stuff.
169 */
170 HRESULT done();
171
172 // wrapped IUnattended attributes:
173 HRESULT getIsoPath(com::Utf8Str &isoPath);
174 HRESULT setIsoPath(const com::Utf8Str &isoPath);
175 HRESULT getUser(com::Utf8Str &user);
176 HRESULT setUser(const com::Utf8Str &user);
177 HRESULT getPassword(com::Utf8Str &password);
178 HRESULT setPassword(const com::Utf8Str &password);
179 HRESULT getFullUserName(com::Utf8Str &user);
180 HRESULT setFullUserName(const com::Utf8Str &user);
181 HRESULT getProductKey(com::Utf8Str &productKey);
182 HRESULT setProductKey(const com::Utf8Str &productKey);
183 HRESULT getAdditionsIsoPath(com::Utf8Str &additionsIsoPath);
184 HRESULT setAdditionsIsoPath(const com::Utf8Str &additionsIsoPath);
185 HRESULT getInstallGuestAdditions(BOOL *installGuestAdditions);
186 HRESULT setInstallGuestAdditions(BOOL installGuestAdditions);
187 HRESULT getValidationKitIsoPath(com::Utf8Str &aValidationKitIsoPath);
188 HRESULT setValidationKitIsoPath(const com::Utf8Str &aValidationKitIsoPath);
189 HRESULT getInstallTestExecService(BOOL *aInstallTestExecService);
190 HRESULT setInstallTestExecService(BOOL aInstallTestExecService);
191 HRESULT getTimeZone(com::Utf8Str &aTimezone);
192 HRESULT setTimeZone(const com::Utf8Str &aTimezone);
193 HRESULT getLocale(com::Utf8Str &aLocale);
194 HRESULT setLocale(const com::Utf8Str &aLocale);
195 HRESULT getLanguage(com::Utf8Str &aLanguage);
196 HRESULT setLanguage(const com::Utf8Str &aLanguage);
197 HRESULT getCountry(com::Utf8Str &aCountry);
198 HRESULT setCountry(const com::Utf8Str &aCountry);
199 HRESULT getProxy(com::Utf8Str &aProxy);
200 HRESULT setProxy(const com::Utf8Str &aProxy);
201 HRESULT getPackageSelectionAdjustments(com::Utf8Str &aPackageSelectionAdjustments);
202 HRESULT setPackageSelectionAdjustments(const com::Utf8Str &aPackageSelectionAdjustments);
203 HRESULT getHostname(com::Utf8Str &aHostname);
204 HRESULT setHostname(const com::Utf8Str &aHostname);
205 HRESULT getAuxiliaryBasePath(com::Utf8Str &aAuxiliaryBasePath);
206 HRESULT setAuxiliaryBasePath(const com::Utf8Str &aAuxiliaryBasePath);
207 HRESULT getImageIndex(ULONG *index);
208 HRESULT setImageIndex(ULONG index);
209 HRESULT getMachine(ComPtr<IMachine> &aMachine);
210 HRESULT setMachine(const ComPtr<IMachine> &aMachine);
211 HRESULT getScriptTemplatePath(com::Utf8Str &aScriptTemplatePath);
212 HRESULT setScriptTemplatePath(const com::Utf8Str &aScriptTemplatePath);
213 HRESULT getPostInstallScriptTemplatePath(com::Utf8Str &aPostInstallScriptTemplatePath);
214 HRESULT setPostInstallScriptTemplatePath(const com::Utf8Str &aPostInstallScriptTemplatePath);
215 HRESULT getPostInstallCommand(com::Utf8Str &aPostInstallCommand);
216 HRESULT setPostInstallCommand(const com::Utf8Str &aPostInstallCommand);
217 HRESULT getExtraInstallKernelParameters(com::Utf8Str &aExtraInstallKernelParameters);
218 HRESULT setExtraInstallKernelParameters(const com::Utf8Str &aExtraInstallKernelParameters);
219 HRESULT getDetectedOSTypeId(com::Utf8Str &aDetectedOSTypeId);
220 HRESULT getDetectedOSVersion(com::Utf8Str &aDetectedOSVersion);
221 HRESULT getDetectedOSLanguages(com::Utf8Str &aDetectedOSLanguages);
222 HRESULT getDetectedOSFlavor(com::Utf8Str &aDetectedOSFlavor);
223 HRESULT getDetectedOSHints(com::Utf8Str &aDetectedOSHints);
224 HRESULT getDetectedImageNames(std::vector<com::Utf8Str> &aDetectedImageNames);
225 HRESULT getDetectedImageIndices(std::vector<ULONG> &aDetectedImageIndices);
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.

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