51 #include <sbWindowsUtils.h>
80 PRBool aMatchPartitionNumber,
82 nsTArray<DEVINST>& aDevInstList)
85 NS_ENSURE_ARG_POINTER(aStorageDevNum);
86 NS_ENSURE_ARG_POINTER(aGUID);
93 SetupDiGetClassDevsW(aGUID,
96 DIGCF_DEVICEINTERFACE | DIGCF_PRESENT);
97 NS_ENSURE_TRUE(devInfo != INVALID_HANDLE_VALUE, NS_ERROR_FAILURE);
98 sbAutoHDEVINFO autoDevInfo(devInfo);
101 aDevInstList.Clear();
105 PSP_DEVICE_INTERFACE_DETAIL_DATA devIfDetailData;
106 SP_DEVINFO_DATA devInfoData;
112 if (rv == NS_ERROR_NOT_AVAILABLE)
114 NS_ENSURE_SUCCESS(rv, rv);
116 autoDevIfDetailData(devIfDetailData);
119 STORAGE_DEVICE_NUMBER storageDevNum;
126 if (storageDevNum.DeviceType != aStorageDevNum->DeviceType)
128 if (storageDevNum.DeviceNumber != aStorageDevNum->DeviceNumber)
130 if (aMatchPartitionNumber &&
131 (storageDevNum.PartitionNumber != aStorageDevNum->PartitionNumber)) {
136 NS_ENSURE_TRUE(aDevInstList.AppendElement(devInfoData.DevInst),
137 NS_ERROR_OUT_OF_MEMORY);
159 STORAGE_DEVICE_NUMBER* aStorageDevNum)
162 NS_ENSURE_ARG_POINTER(aStorageDevNum);
163 NS_ENSURE_ARG_POINTER(aGUID);
169 nsAutoString deviceInterfacePath;
171 NS_ENSURE_SUCCESS(rv, rv);
190 STORAGE_DEVICE_NUMBER* aStorageDevNum)
193 NS_ENSURE_ARG_POINTER(aDevPath);
194 NS_ENSURE_ARG_POINTER(aStorageDevNum);
197 PRBool hasDevNum = PR_TRUE;
201 HANDLE devFile = CreateFileW(aDevPath,
203 FILE_SHARE_READ | FILE_SHARE_WRITE,
208 if (devFile == INVALID_HANDLE_VALUE)
209 return NS_ERROR_NOT_AVAILABLE;
210 sbAutoHANDLE autoDevFile(devFile);
213 STORAGE_DEVICE_NUMBER getDevNumParams;
215 success = DeviceIoControl(devFile,
216 IOCTL_STORAGE_GET_DEVICE_NUMBER,
220 sizeof(getDevNumParams),
224 return NS_ERROR_NOT_AVAILABLE;
225 NS_ENSURE_TRUE(getDevNumParams.DeviceNumber != 0xFFFFFFFF,
229 CopyMemory(aStorageDevNum, &getDevNumParams,
sizeof(STORAGE_DEVICE_NUMBER));
254 NS_ENSURE_ARG_POINTER(aIsReady);
261 GUID guid = GUID_DEVINTERFACE_VOLUME;
262 nsAutoString volumeDeviceInterfacePath;
264 NS_ENSURE_SUCCESS(rv, rv);
267 static const DWORD volumeGUIDPathLength = 51;
268 WCHAR volumeGUIDPath[volumeGUIDPathLength];
269 volumeDeviceInterfacePath.AppendLiteral(
"\\");
270 success = GetVolumeNameForVolumeMountPointW(volumeDeviceInterfacePath.get(),
272 volumeGUIDPathLength);
274 *aIsReady = PR_FALSE;
280 DWORD fileSystemFlags;
281 WCHAR volumeLabel[MAX_PATH+1];
282 WCHAR fileSystemName[MAX_PATH+1];
283 success = GetVolumeInformationW(volumeDeviceInterfacePath.BeginReading(),
285 NS_ARRAY_LENGTH(volumeLabel),
290 NS_ARRAY_LENGTH(fileSystemName));
292 *aIsReady = PR_FALSE;
316 NS_ENSURE_ARG_POINTER(aIsReadOnly);
322 DWORD fileSystemFlags;
323 WCHAR volumeLabel[MAX_PATH+1];
324 WCHAR fileSystemName[MAX_PATH+1];
325 success = GetVolumeInformationW(aVolumeMountPath.BeginReading(),
327 NS_ARRAY_LENGTH(volumeLabel),
332 NS_ARRAY_LENGTH(fileSystemName));
333 NS_ENSURE_TRUE(success, NS_ERROR_FAILURE);
336 if (fileSystemFlags & FILE_READ_ONLY_VOLUME)
337 *aIsReadOnly = PR_TRUE;
339 *aIsReadOnly = PR_FALSE;
357 nsAString& aVolumeGUIDPath)
363 GUID guid = GUID_DEVINTERFACE_VOLUME;
364 nsAutoString volumeDeviceInterfacePath;
366 NS_ENSURE_SUCCESS(rv, rv);
369 static const DWORD volumeGUIDPathLength = 51;
370 WCHAR volumeGUIDPath[volumeGUIDPathLength];
371 volumeDeviceInterfacePath.AppendLiteral(
"\\");
372 success = GetVolumeNameForVolumeMountPointW(volumeDeviceInterfacePath.get(),
374 volumeGUIDPathLength);
375 NS_ENSURE_TRUE(success, NS_ERROR_FAILURE);
378 aVolumeGUIDPath.Assign(volumeGUIDPath);
396 nsAString& aVolumeGUID)
402 NS_ENSURE_SUCCESS(rv, rv);
408 index = aVolumeGUID.Find(
"{");
409 NS_ENSURE_TRUE(index >= 0, NS_ERROR_UNEXPECTED);
410 aVolumeGUID.Cut(0, index);
411 index = aVolumeGUID.Find(
"}");
412 NS_ENSURE_TRUE(index >= 0, NS_ERROR_UNEXPECTED);
413 aVolumeGUID.SetLength(index + 1);
429 nsTArray<nsString>& aPathNames)
434 nsAutoString volumeGUIDPath;
436 NS_ENSURE_SUCCESS(rv, rv);
440 NS_ENSURE_SUCCESS(rv, rv);
456 nsTArray<nsString>& aPathNames)
465 DWORD pathNamesLength;
466 success = GetVolumePathNamesForVolumeNameW(aVolumeGUIDPath.BeginReading(),
471 NS_ENSURE_TRUE(GetLastError() == ERROR_MORE_DATA, NS_ERROR_FAILURE);
472 if (pathNamesLength == 0)
477 static_cast<WCHAR*
>(malloc(pathNamesLength *
sizeof(WCHAR)));
478 NS_ENSURE_TRUE(pathNames, NS_ERROR_OUT_OF_MEMORY);
482 success = GetVolumePathNamesForVolumeNameW(aVolumeGUIDPath.BeginReading(),
486 NS_ENSURE_TRUE(success, NS_ERROR_FAILURE);
489 DWORD pathNameIndex = 0;
490 while (pathNameIndex < pathNamesLength) {
492 WCHAR* pathName = pathNames + pathNameIndex;
493 if (pathName[0] == L
'\0')
497 aPathNames.AppendElement(pathName);
500 pathNameIndex += wcslen(pathName) + 1;
517 nsACString& aVolumeLabel)
522 WCHAR volumeLabel[MAX_PATH+1];
523 WCHAR fileSystemName[MAX_PATH+1];
524 success = GetVolumeInformationW(aVolumeMountPath.BeginReading(),
526 NS_ARRAY_LENGTH(volumeLabel),
531 NS_ARRAY_LENGTH(fileSystemName));
532 NS_ENSURE_TRUE(success, NS_ERROR_FAILURE);
535 aVolumeLabel.Assign(NS_ConvertUTF16toUTF8(volumeLabel));
551 const nsACString& aVolumeLabel)
556 success = SetVolumeLabelW(aVolumeMountPath.BeginReading(),
557 NS_ConvertUTF8toUTF16(aVolumeLabel).get());
558 NS_ENSURE_TRUE(success, NS_ERROR_FAILURE);
574 #define CDB6GENERIC_LENGTH 6
583 #define SCSIOP_INQUIRY 0x12
597 nsAString& aVendorID,
598 nsAString& aProductID)
606 sbAutoHANDLE diskHandle;
607 GUID guid = GUID_DEVINTERFACE_DISK;
612 FILE_SHARE_READ | FILE_SHARE_WRITE,
617 NS_ENSURE_SUCCESS(rv, rv);
620 STORAGE_PROPERTY_QUERY storagePropertyQuery;
621 memset(&storagePropertyQuery, 0,
sizeof(storagePropertyQuery));
622 storagePropertyQuery.PropertyId = StorageDeviceProperty;
623 storagePropertyQuery.QueryType = PropertyStandardQuery;
627 STORAGE_DESCRIPTOR_HEADER storageDescriptorHeader;
628 success = DeviceIoControl(diskHandle,
629 IOCTL_STORAGE_QUERY_PROPERTY,
630 &storagePropertyQuery,
631 sizeof(storagePropertyQuery),
632 &storageDescriptorHeader,
633 sizeof(storageDescriptorHeader),
636 NS_ENSURE_TRUE(success, NS_ERROR_FAILURE);
637 NS_ENSURE_TRUE(byteCount ==
sizeof(storageDescriptorHeader),
642 storageDeviceDescriptor =
static_cast<PSTORAGE_DEVICE_DESCRIPTOR
>
643 (malloc(storageDescriptorHeader.Size));
644 NS_ENSURE_TRUE(storageDeviceDescriptor, NS_ERROR_OUT_OF_MEMORY);
647 success = DeviceIoControl(diskHandle,
648 IOCTL_STORAGE_QUERY_PROPERTY,
649 &storagePropertyQuery,
650 sizeof(storagePropertyQuery),
651 storageDeviceDescriptor,
652 storageDescriptorHeader.Size,
655 NS_ENSURE_TRUE(success, NS_ERROR_FAILURE);
656 NS_ENSURE_TRUE(byteCount == storageDescriptorHeader.Size, NS_ERROR_FAILURE);
660 aVendorID.AssignLiteral
661 (reinterpret_cast<char*>(storageDeviceDescriptor.
get()) +
662 storageDeviceDescriptor->VendorIdOffset);
663 aVendorID.Trim(
" ", PR_FALSE, PR_TRUE);
664 aProductID.AssignLiteral
665 (reinterpret_cast<char*>(storageDeviceDescriptor.
get()) +
666 storageDeviceDescriptor->ProductIdOffset);
667 aProductID.Trim(
" ", PR_FALSE, PR_TRUE);
nsresult sbWinCreateDeviceFile(HANDLE *aDevFile, DEVINST aDevInst, const GUID *aGUID, DWORD aDesiredAccess, DWORD aShareMode, LPSECURITY_ATTRIBUTES aSecurityAttributes, DWORD aCreationDisposition, DWORD aFlagsAndAttributes, HANDLE aTemplateFile)
nsresult sbWinVolumeIsReady(DEVINST aDevInst, PRBool *aIsReady)
Songbird Windows Device Utilities Definitions.
nsresult sbWinGetDevDetail(PSP_DEVICE_INTERFACE_DETAIL_DATA *aDevIfDetailData, SP_DEVINFO_DATA *aDevInfoData, HDEVINFO aDevInfo, const GUID *aGUID, DWORD aDevIndex)
nsresult sbWinGetVolumeGUID(DEVINST aDevInst, nsAString &aVolumeGUID)
nsresult sbWinFindDevicesByStorageDevNum(STORAGE_DEVICE_NUMBER *aStorageDevNum, PRBool aMatchPartitionNumber, const GUID *aGUID, nsTArray< DEVINST > &aDevInstList)
nsresult sbWinSetVolumeLabel(const nsAString &aVolumeMountPath, const nsACString &aVolumeLabel)
nsresult sbWinGetStorageDevNum(DEVINST aDevInst, const GUID *aGUID, STORAGE_DEVICE_NUMBER *aStorageDevNum)
nsresult sbWinVolumeGetIsReadOnly(const nsAString &aVolumeMountPath, PRBool *aIsReadOnly)
nsresult sbWinGetSCSIProductInfo(DEVINST aDevInst, nsAString &aVendorID, nsAString &aProductID)
nsresult sbWinGetVolumePathNames(DEVINST aDevInst, nsTArray< nsString > &aPathNames)
nsresult sbWinGetVolumeLabel(const nsAString &aVolumeMountPath, nsACString &aVolumeLabel)
Songbird Windows Storage Device Utilities Definitions.
nsresult sbWinGetVolumeGUIDPath(DEVINST aDevInst, nsAString &aVolumeGUIDPath)
struct _SCSI_PASS_THROUGH_WITH_BUFFERS * PSCSI_PASS_THROUGH_WITH_BUFFERS
struct _SCSI_PASS_THROUGH_WITH_BUFFERS SCSI_PASS_THROUGH_WITH_BUFFERS
nsresult sbWinGetDevicePath(DEVINST aDevInst, const GUID *aGUID, nsAString &aDevicePath)