42 #include "sbIWindowsFormatter_i.c"
45 #include <sbWindowsStorage.h>
46 #include <sbWindowsUtils.h>
80 ULONG refCount = --mRefCount;
106 if (IsBadWritePtr(aInterface,
sizeof(
void*)))
113 if (InlineIsEqualGUID(aIID, IID_IUnknown))
114 *aInterface =
static_cast<IUnknown*
>(
this);
115 else if (InlineIsEqualGUID(aIID, IID_sbIWindowsFormatter))
116 *aInterface = static_cast<sbIWindowsFormatter*>(
this);
118 return E_NOINTERFACE;
121 (
static_cast<IUnknown*
>(*aInterface))->AddRef();
158 DWORD aUnitAllocationSize,
161 long aEnableCompression)
164 SB_WIN_ENSURE_ARG_POINTER(aVolumeName);
167 sbWindowsEventLog(
"Formatting volume: %S\n", aVolumeName);
173 IVdsVolumeMF* volume;
174 result = GetVolume(aVolumeName, &volume);
176 SB_WIN_ENSURE_TRUE(result == S_OK, HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND));
177 sbAutoIUnknown autoVolume(volume);
181 result = volume->Format(static_cast<VDS_FILE_SYSTEM_TYPE>(aType),
189 sbAutoIUnknown autoAsync(async);
192 VDS_ASYNC_OUTPUT asyncOutput;
193 HRESULT formatResult;
194 result = async->Wait(&formatResult, &asyncOutput);
217 SB_WIN_ENSURE_ARG_POINTER(aWindowsFormatter);
224 SB_WIN_ENSURE_TRUE(windowsFormatter, E_OUTOFMEMORY);
225 windowsFormatter->AddRef();
226 sbAutoIUnknown autoWindowsFormatter(windowsFormatter);
229 result = windowsFormatter->Initialize();
233 *aWindowsFormatter = windowsFormatter;
234 autoWindowsFormatter.forget();
249 mVdsService->Release();
264 sbWindowsFormatter::sbWindowsFormatter() :
277 sbWindowsFormatter::Initialize()
287 IVdsServiceLoader* vdsServiceLoader;
288 result = CoCreateInstance(CLSID_VdsLoader,
291 IID_IVdsServiceLoader,
292 reinterpret_cast<void**>(&vdsServiceLoader));
294 sbAutoIUnknown autoVdsServiceLoader(vdsServiceLoader);
297 result = vdsServiceLoader->LoadService(NULL, &mVdsService);
299 result = mVdsService->WaitForServiceReady();
312 sbWindowsFormatter::GetVolume(BSTR aVolumeName,
313 IVdsVolumeMF** aVolume)
316 SB_WIN_ENSURE_ARG_POINTER(aVolumeName);
317 SB_WIN_ENSURE_ARG_POINTER(aVolume);
326 IEnumVdsObject* swProviderEnum;
327 result = mVdsService->QueryProviders(VDS_QUERY_SOFTWARE_PROVIDERS,
330 sbAutoIUnknown autoSwProviderEnum(swProviderEnum);
337 IUnknown* swProviderIUnknown;
339 result = swProviderEnum->Next(1, &swProviderIUnknown, &count);
343 sbAutoIUnknown autoSwProviderIUnknown(swProviderIUnknown);
346 IVdsSwProvider* swProvider;
347 result = swProviderIUnknown->QueryInterface
349 reinterpret_cast<void**>(&swProvider));
351 sbAutoIUnknown autoSwProvider(swProvider);
355 result = GetVolume(swProvider, aVolumeName, aVolume);
371 sbWindowsFormatter::GetVolume(IVdsSwProvider* aSwProvider,
373 IVdsVolumeMF** aVolume)
376 SB_WIN_ENSURE_ARG_POINTER(aSwProvider);
377 SB_WIN_ENSURE_ARG_POINTER(aVolumeName);
378 SB_WIN_ENSURE_ARG_POINTER(aVolume);
387 IEnumVdsObject* packEnum;
388 result = aSwProvider->QueryPacks(&packEnum);
390 sbAutoIUnknown autoPackEnum(packEnum);
397 IUnknown* packIUnknown;
399 result = packEnum->Next(1, &packIUnknown, &count);
403 sbAutoIUnknown autoPackIUnknown(packIUnknown);
407 result = packIUnknown->QueryInterface(IID_IVdsPack,
408 reinterpret_cast<void**>(&pack));
410 sbAutoIUnknown autoPack(pack);
413 result = GetVolume(pack, aVolumeName, aVolume);
429 sbWindowsFormatter::GetVolume(IVdsPack* aPack,
431 IVdsVolumeMF** aVolume)
434 SB_WIN_ENSURE_ARG_POINTER(aPack);
435 SB_WIN_ENSURE_ARG_POINTER(aVolumeName);
436 SB_WIN_ENSURE_ARG_POINTER(aVolume);
445 STORAGE_DEVICE_NUMBER targetDevNum;
450 IEnumVdsObject* volumeEnum;
451 result = aPack->QueryVolumes(&volumeEnum);
453 sbAutoIUnknown autoVolumeEnum(volumeEnum);
460 IUnknown* volumeIUnknown;
462 result = volumeEnum->Next(1, &volumeIUnknown, &count);
466 sbAutoIUnknown autoVolumeIUnknown(volumeIUnknown);
470 result = volumeIUnknown->QueryInterface(IID_IVdsVolume,
471 reinterpret_cast<void**>(&volume));
473 sbAutoIUnknown autoVolume(volume);
476 VDS_VOLUME_PROP volumeProp;
477 result = volume->GetProperties(&volumeProp);
481 STORAGE_DEVICE_NUMBER volumeDevNum;
486 if ((volumeDevNum.DeviceType == targetDevNum.DeviceType) &&
487 (volumeDevNum.DeviceNumber == targetDevNum.DeviceNumber) &&
488 (volumeDevNum.PartitionNumber == targetDevNum.PartitionNumber)) {
489 result = volumeIUnknown->QueryInterface
491 reinterpret_cast<void**>(aVolume));
HRESULT Initialize(DWORD aInitFlags=COINIT_MULTITHREADED)
nsresult sbWinGetStorageDevNum(DEVINST aDevInst, const GUID *aGUID, STORAGE_DEVICE_NUMBER *aStorageDevNum)
#define SB_WIN_ENSURE_SUCCESS(aHR, aRV)
HRESULT GetHRESULT() const