VirtualBox

source: vbox/trunk/src/VBox/Main/src-server/GuestOSTypeImpl.cpp

Last change on this file was 101683, checked in by vboxsync, 6 months ago

Main/Unattended|GuestOSType: Add an entry in the guest OS type to indicate the name of the additions install package instead of hardcoding it in the templates. Allows easy adaption if something changes and makes it possible to auto install guest additions for linux.arm64 guests, bugref:10542

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 14.4 KB
Line 
1/* $Id: GuestOSTypeImpl.cpp 101683 2023-10-31 12:38:46Z vboxsync $ */
2/** @file
3 * VirtualBox COM class implementation
4 */
5
6/*
7 * Copyright (C) 2006-2023 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#define LOG_GROUP LOG_GROUP_MAIN_GUESTOSTYPE
29#include "GuestOSTypeImpl.h"
30#include "AutoCaller.h"
31#include "LoggingNew.h"
32#include <iprt/cpp/utils.h>
33
34// constructor / destructor
35/////////////////////////////////////////////////////////////////////////////
36
37GuestOSType::GuestOSType()
38 : mOSType(VBOXOSTYPE_Unknown)
39 , mOSHint(VBOXOSHINT_NONE)
40 , mRAMSize(0)
41 , mCPUCount(1)
42 , mGraphicsControllerType(GraphicsControllerType_Null)
43 , mVRAMSize(0)
44 , mHDDSize(0)
45 , mNetworkAdapterType(NetworkAdapterType_Am79C973)
46 , mNumSerialEnabled(0)
47 , mDVDStorageControllerType(StorageControllerType_PIIX3)
48 , mDVDStorageBusType(StorageBus_IDE)
49 , mHDStorageControllerType(StorageControllerType_PIIX3)
50 , mHDStorageBusType(StorageBus_IDE)
51 , mChipsetType(ChipsetType_PIIX3)
52 , mIommuType(IommuType_None)
53 , mAudioControllerType(AudioControllerType_AC97)
54 , mAudioCodecType(AudioCodecType_STAC9700)
55{
56}
57
58GuestOSType::~GuestOSType()
59{
60}
61
62HRESULT GuestOSType::FinalConstruct()
63{
64 return BaseFinalConstruct();
65}
66
67void GuestOSType::FinalRelease()
68{
69 uninit();
70
71 BaseFinalRelease();
72}
73
74// public initializer/uninitializer for internal purposes only
75/////////////////////////////////////////////////////////////////////////////
76
77/**
78 * Initializes the guest OS type object.
79 *
80 * @returns COM result indicator
81 * @param ostype containing the following parts:
82 * @a aFamilyId os family short name string
83 * @a aFamilyDescription os family name string
84 * @a aId os short name string
85 * @a aDescription os name string
86 * @a aOSType global OS type ID
87 * @a aOSHint os configuration hint
88 * @a aRAMSize recommended RAM size in megabytes
89 * @a aVRAMSize recommended video memory size in megabytes
90 * @a aHDDSize recommended HDD size in bytes
91 */
92HRESULT GuestOSType::init(const Global::OSType &ostype)
93{
94 ComAssertRet(ostype.familyId && ostype.familyDescription && ostype.id && ostype.description, E_INVALIDARG);
95
96 /* Enclose the state transition NotReady->InInit->Ready */
97 AutoInitSpan autoInitSpan(this);
98 AssertReturn(autoInitSpan.isOk(), E_FAIL);
99
100 unconst(mFamilyID) = ostype.familyId;
101 unconst(mFamilyDescription) = ostype.familyDescription;
102 unconst(mOSSubtype) = ostype.subtype;
103 unconst(mID) = ostype.id;
104 unconst(mDescription) = ostype.description;
105 unconst(mOSType) = ostype.osType;
106 unconst(mOSHint) = ostype.osHint;
107 unconst(mRAMSize) = ostype.recommendedRAM;
108 unconst(mCPUCount) = ostype.recommendedCPUCount;
109 unconst(mHDDSize) = ostype.recommendedHDD;
110 unconst(mGraphicsControllerType) = ostype.graphicsControllerType;
111 unconst(mVRAMSize) = ostype.recommendedVRAM;
112 unconst(mNetworkAdapterType) = ostype.networkAdapterType;
113 unconst(mNumSerialEnabled) = ostype.numSerialEnabled;
114 unconst(mDVDStorageControllerType) = ostype.dvdStorageControllerType;
115 unconst(mDVDStorageBusType) = ostype.dvdStorageBusType;
116 unconst(mHDStorageControllerType) = ostype.hdStorageControllerType;
117 unconst(mHDStorageBusType) = ostype.hdStorageBusType;
118 unconst(mChipsetType) = ostype.chipsetType;
119 unconst(mIommuType) = ostype.iommuType;
120 unconst(mAudioControllerType) = ostype.audioControllerType;
121 unconst(mAudioCodecType) = ostype.audioCodecType;
122 unconst(mGuestAdditionsInstallPackageName) = ostype.guestAdditionsInstallPkgName;
123
124 /* Confirm a successful initialization when it's the case */
125 autoInitSpan.setSucceeded();
126
127 return S_OK;
128}
129
130/**
131 * Uninitializes the instance and sets the ready flag to FALSE.
132 * Called either from FinalRelease() or by the parent when it gets destroyed.
133 */
134void GuestOSType::uninit()
135{
136 /* Enclose the state transition Ready->InUninit->NotReady */
137 AutoUninitSpan autoUninitSpan(this);
138 if (autoUninitSpan.uninitDone())
139 return;
140}
141
142// IGuestOSType properties
143/////////////////////////////////////////////////////////////////////////////
144
145HRESULT GuestOSType::getFamilyId(com::Utf8Str &aFamilyId)
146{
147 /* mFamilyID is constant during life time, no need to lock */
148 aFamilyId = mFamilyID;
149 return S_OK;
150}
151
152
153HRESULT GuestOSType::getFamilyDescription(com::Utf8Str &aFamilyDescription)
154{
155 /* mFamilyDescription is constant during life time, no need to lock */
156 aFamilyDescription = mFamilyDescription;
157
158 return S_OK;
159}
160
161
162HRESULT GuestOSType::getSubtype(com::Utf8Str &aSubtype)
163{
164 /* mOSSubtype is constant during life time, no need to lock */
165 aSubtype = mOSSubtype;
166
167 return S_OK;
168}
169
170
171HRESULT GuestOSType::getId(com::Utf8Str &aId)
172{
173 /* mID is constant during life time, no need to lock */
174 aId = mID;
175
176 return S_OK;
177}
178
179
180HRESULT GuestOSType::getDescription(com::Utf8Str &aDescription)
181{
182 /* mDescription is constant during life time, no need to lock */
183 aDescription = mDescription;
184
185 return S_OK;
186}
187
188HRESULT GuestOSType::getIs64Bit(BOOL *aIs64Bit)
189{
190 /* mIs64Bit is constant during life time, no need to lock */
191 *aIs64Bit = !!(mOSHint & VBOXOSHINT_64BIT);
192
193 return S_OK;
194}
195
196PlatformArchitecture_T GuestOSType::i_platformArchitecture() const
197{
198 /* mOSType constant during life time, no need to lock */
199 VBOXOSTYPE const osTypePlatformArchitectureMasked = VBOXOSTYPE(mOSType & VBOXOSTYPE_ArchitectureMask);
200 if ( osTypePlatformArchitectureMasked == VBOXOSTYPE_x86
201 || osTypePlatformArchitectureMasked == VBOXOSTYPE_x64)
202 return PlatformArchitecture_x86;
203 else if ( osTypePlatformArchitectureMasked == VBOXOSTYPE_arm32
204 || osTypePlatformArchitectureMasked == VBOXOSTYPE_arm64)
205 return PlatformArchitecture_ARM;
206
207 /* Will happen when called before being properly initialized(). */
208 return PlatformArchitecture_None;
209}
210
211HRESULT GuestOSType::getPlatformArchitecture(PlatformArchitecture_T *aPlatformArchitecture)
212{
213 *aPlatformArchitecture = i_platformArchitecture();
214 return S_OK;
215}
216
217HRESULT GuestOSType::getRecommendedIOAPIC(BOOL *aRecommendedIOAPIC)
218{
219 /* mRecommendedIOAPIC is constant during life time, no need to lock */
220 *aRecommendedIOAPIC = !!(mOSHint & VBOXOSHINT_X86_IOAPIC);
221
222 return S_OK;
223}
224
225
226HRESULT GuestOSType::getRecommendedVirtEx(BOOL *aRecommendedVirtEx)
227{
228 /* mRecommendedVirtEx is constant during life time, no need to lock */
229 *aRecommendedVirtEx = !!(mOSHint & VBOXOSHINT_X86_HWVIRTEX);
230
231 return S_OK;
232}
233
234
235HRESULT GuestOSType::getRecommendedRAM(ULONG *aRAMSize)
236{
237 /* mRAMSize is constant during life time, no need to lock */
238 *aRAMSize = mRAMSize;
239
240 return S_OK;
241}
242
243
244HRESULT GuestOSType::getRecommendedGraphicsController(GraphicsControllerType_T *aRecommendedGraphicsController)
245{
246 /* mGraphicsController is constant during life time, no need to lock */
247 *aRecommendedGraphicsController = mGraphicsControllerType;
248
249 return S_OK;
250}
251
252
253HRESULT GuestOSType::getRecommendedVRAM(ULONG *aVRAMSize)
254{
255 /* mVRAMSize is constant during life time, no need to lock */
256 *aVRAMSize = mVRAMSize;
257
258 return S_OK;
259}
260
261
262HRESULT GuestOSType::getRecommended2DVideoAcceleration(BOOL *aRecommended2DVideoAcceleration)
263{
264 /* Constant during life time, no need to lock */
265 *aRecommended2DVideoAcceleration = !!(mOSHint & VBOXOSHINT_ACCEL2D);
266
267 return S_OK;
268}
269
270
271HRESULT GuestOSType::getRecommended3DAcceleration(BOOL *aRecommended3DAcceleration)
272{
273 /* Constant during life time, no need to lock */
274 *aRecommended3DAcceleration = !!(mOSHint & VBOXOSHINT_ACCEL3D);
275
276 return S_OK;
277}
278
279
280HRESULT GuestOSType::getRecommendedHDD(LONG64 *aHDDSize)
281{
282 /* mHDDSize is constant during life time, no need to lock */
283 *aHDDSize = (LONG64)mHDDSize;
284
285 return S_OK;
286}
287
288
289HRESULT GuestOSType::getAdapterType(NetworkAdapterType_T *aNetworkAdapterType)
290{
291 /* mNetworkAdapterType is constant during life time, no need to lock */
292 *aNetworkAdapterType = mNetworkAdapterType;
293
294 return S_OK;
295}
296
297HRESULT GuestOSType::getRecommendedPAE(BOOL *aRecommendedPAE)
298{
299 /* recommended PAE is constant during life time, no need to lock */
300 *aRecommendedPAE = !!(mOSHint & VBOXOSHINT_X86_PAE);
301
302 return S_OK;
303}
304
305
306HRESULT GuestOSType::getRecommendedFirmware(FirmwareType_T *aFirmwareType)
307{
308 /* firmware type is constant during life time, no need to lock */
309 if (mOSHint & VBOXOSHINT_EFI)
310 *aFirmwareType = FirmwareType_EFI;
311 else
312 *aFirmwareType = FirmwareType_BIOS;
313
314 return S_OK;
315}
316
317
318HRESULT GuestOSType::getRecommendedDVDStorageController(StorageControllerType_T *aStorageControllerType)
319{
320 /* storage controller type is constant during life time, no need to lock */
321 *aStorageControllerType = mDVDStorageControllerType;
322
323 return S_OK;
324}
325
326
327HRESULT GuestOSType::getRecommendedDVDStorageBus(StorageBus_T *aStorageBusType)
328{
329 /* storage controller type is constant during life time, no need to lock */
330 *aStorageBusType = mDVDStorageBusType;
331
332 return S_OK;
333}
334
335
336HRESULT GuestOSType::getRecommendedHDStorageController(StorageControllerType_T *aStorageControllerType)
337{
338 /* storage controller type is constant during life time, no need to lock */
339 *aStorageControllerType = mHDStorageControllerType;
340
341 return S_OK;
342}
343
344
345HRESULT GuestOSType::getRecommendedHDStorageBus(StorageBus_T *aStorageBusType)
346{
347 /* storage controller type is constant during life time, no need to lock */
348 *aStorageBusType = mHDStorageBusType;
349
350 return S_OK;
351}
352
353
354HRESULT GuestOSType::getRecommendedUSBHID(BOOL *aRecommendedUSBHID)
355{
356 /* HID type is constant during life time, no need to lock */
357 *aRecommendedUSBHID = !!(mOSHint & VBOXOSHINT_USBHID);
358
359 return S_OK;
360}
361
362
363HRESULT GuestOSType::getRecommendedHPET(BOOL *aRecommendedHPET)
364{
365 /* HPET recommendation is constant during life time, no need to lock */
366 *aRecommendedHPET = !!(mOSHint & VBOXOSHINT_X86_HPET);
367
368 return S_OK;
369}
370
371
372HRESULT GuestOSType::getRecommendedUSBTablet(BOOL *aRecommendedUSBTablet)
373{
374 /* HID type is constant during life time, no need to lock */
375 *aRecommendedUSBTablet = !!(mOSHint & VBOXOSHINT_USBTABLET);
376
377 return S_OK;
378}
379
380
381HRESULT GuestOSType::getRecommendedRTCUseUTC(BOOL *aRecommendedRTCUseUTC)
382{
383 /* Value is constant during life time, no need to lock */
384 *aRecommendedRTCUseUTC = !!(mOSHint & VBOXOSHINT_RTCUTC);
385
386 return S_OK;
387}
388
389
390HRESULT GuestOSType::getRecommendedChipset(ChipsetType_T *aChipsetType)
391{
392 /* chipset type is constant during life time, no need to lock */
393 *aChipsetType = mChipsetType;
394
395 return S_OK;
396}
397
398
399HRESULT GuestOSType::getRecommendedIommuType(IommuType_T *aIommuType)
400{
401 /* IOMMU type is constant during life time, no need to lock */
402 *aIommuType = mIommuType;
403
404 return S_OK;
405}
406
407
408HRESULT GuestOSType::getRecommendedAudioController(AudioControllerType_T *aAudioController)
409{
410 *aAudioController = mAudioControllerType;
411
412 return S_OK;
413}
414
415
416HRESULT GuestOSType::getRecommendedAudioCodec(AudioCodecType_T *aAudioCodec)
417{
418 *aAudioCodec = mAudioCodecType;
419
420 return S_OK;
421}
422
423
424HRESULT GuestOSType::getRecommendedFloppy(BOOL *aRecommendedFloppy)
425{
426 /* Value is constant during life time, no need to lock */
427 *aRecommendedFloppy = !!(mOSHint & VBOXOSHINT_FLOPPY);
428
429 return S_OK;
430}
431
432
433HRESULT GuestOSType::getRecommendedUSB(BOOL *aRecommendedUSB)
434{
435 /* Value is constant during life time, no need to lock */
436 *aRecommendedUSB = !(mOSHint & VBOXOSHINT_NOUSB);
437
438 return S_OK;
439}
440
441HRESULT GuestOSType::getRecommendedUSB3(BOOL *aRecommendedUSB3)
442{
443 /* Value is constant during life time, no need to lock */
444 *aRecommendedUSB3 = !!(mOSHint & VBOXOSHINT_USB3);
445
446 return S_OK;
447}
448
449HRESULT GuestOSType::getRecommendedTFReset(BOOL *aRecommendedTFReset)
450{
451 /* recommended triple fault behavior is constant during life time, no need to lock */
452 *aRecommendedTFReset = !!(mOSHint & VBOXOSHINT_TFRESET);
453
454 return S_OK;
455}
456
457HRESULT GuestOSType::getRecommendedX2APIC(BOOL *aRecommendedX2APIC)
458{
459 /* mRecommendedX2APIC is constant during life time, no need to lock */
460 *aRecommendedX2APIC = !!(mOSHint & VBOXOSHINT_X86_X2APIC);
461
462 return S_OK;
463}
464
465HRESULT GuestOSType::getRecommendedCPUCount(ULONG *aRecommendedCPUCount)
466{
467 /* mCPUCount is constant during life time, no need to lock */
468 *aRecommendedCPUCount = mCPUCount;
469
470 return S_OK;
471}
472
473HRESULT GuestOSType::getRecommendedTpmType(TpmType_T *aRecommendedTpmType)
474{
475 /* Value is constant during life time, no need to lock */
476 if (mOSHint & VBOXOSHINT_TPM2)
477 *aRecommendedTpmType = TpmType_v2_0;
478 else if (mOSHint & VBOXOSHINT_TPM)
479 *aRecommendedTpmType = TpmType_v1_2;
480 else
481 *aRecommendedTpmType = TpmType_None;
482
483 return S_OK;
484}
485
486HRESULT GuestOSType::getRecommendedSecureBoot(BOOL *aRecommendedSecureBoot)
487{
488 /* Value is constant during life time, no need to lock */
489 *aRecommendedSecureBoot = !!(mOSHint & VBOXOSHINT_EFI_SECUREBOOT);
490
491 return S_OK;
492}
493
494HRESULT GuestOSType::getRecommendedWDDMGraphics(BOOL *aRecommendedWDDMGraphics)
495{
496 /* Value is constant during life time, no need to lock */
497 *aRecommendedWDDMGraphics = !!(mOSHint & VBOXOSHINT_WDDM_GRAPHICS);
498
499 return S_OK;
500}
501
502HRESULT GuestOSType::getGuestAdditionsInstallPackageName(com::Utf8Str &aGuestAdditionsInstallPkgName)
503{
504 /* mGuestAdditionsInstallPackageName is constant during life time, no need to lock */
505 aGuestAdditionsInstallPkgName = mGuestAdditionsInstallPackageName;
506 return S_OK;
507}
508
509/* vi: set tabstop=4 shiftwidth=4 expandtab: */
Note: See TracBrowser for help on using the repository browser.

© 2023 Oracle
ContactPrivacy policyTerms of Use