/* Filedisk PnP ID query-response routine. */ static NTSTATUS STDCALL WvFilediskPnpQueryId_( IN PDEVICE_OBJECT dev_obj, IN PIRP irp, IN WVL_SP_DISK_T disk ) { static const WCHAR * hw_ids[WvlDiskMediaTypes] = { WVL_M_WLIT L"\\FileFloppyDisk", WVL_M_WLIT L"\\FileHardDisk", WVL_M_WLIT L"\\FileOpticalDisc" }; WCHAR (*buf)[512]; NTSTATUS status; WV_SP_FILEDISK_T filedisk = CONTAINING_RECORD(disk, WV_S_FILEDISK_T, disk); BUS_QUERY_ID_TYPE query_type; /* Allocate a buffer. */ buf = wv_mallocz(sizeof *buf); if (!buf) { status = STATUS_INSUFFICIENT_RESOURCES; goto err_buf; } /* Populate the buffer with IDs. */ query_type = IoGetCurrentIrpStackLocation(irp)->Parameters.QueryId.IdType; switch (query_type) { case BusQueryDeviceID: swprintf(*buf, hw_ids[disk->Media]); break; case BusQueryInstanceID: /* "Location". */ swprintf(*buf, L"Hash_%08X", filedisk->hash); break; case BusQueryHardwareIDs: swprintf( *buf + swprintf(*buf, hw_ids[disk->Media]) + 1, WvlDiskCompatIds[disk->Media] ); break; case BusQueryCompatibleIDs: swprintf(*buf, WvlDiskCompatIds[disk->Media]); default: DBG("Unknown query type %d for %p!\n", query_type, filedisk); status = STATUS_INVALID_PARAMETER; goto err_query_type; } DBG("IRP_MN_QUERY_ID for file-backed disk %p.\n", filedisk); return WvlIrpComplete(irp, (ULONG_PTR) buf, STATUS_SUCCESS); err_query_type: wv_free(buf); err_buf: return WvlIrpComplete(irp, 0, status); }
NTSTATUS STDCALL WvDiskPnpQueryDevText( IN PDEVICE_OBJECT dev_obj, IN PIRP irp, IN WVL_SP_DISK_T disk ) { IN WV_SP_DEV_T dev = WvDevFromDevObj(dev_obj); WCHAR (*str)[512]; PIO_STACK_LOCATION io_stack_loc = IoGetCurrentIrpStackLocation(irp); NTSTATUS status; UINT32 str_len; /* Allocate a string buffer. */ str = wv_mallocz(sizeof *str); if (str == NULL) { DBG("wv_malloc IRP_MN_QUERY_DEVICE_TEXT\n"); status = STATUS_INSUFFICIENT_RESOURCES; goto alloc_str; } /* Determine the query type. */ switch (io_stack_loc->Parameters.QueryDeviceText.DeviceTextType) { case DeviceTextDescription: str_len = swprintf(*str, WVL_M_WLIT L" Disk") + 1; irp->IoStatus.Information = (ULONG_PTR) wv_palloc(str_len * sizeof *str); if (irp->IoStatus.Information == 0) { DBG("wv_palloc DeviceTextDescription\n"); status = STATUS_INSUFFICIENT_RESOURCES; goto alloc_info; } RtlCopyMemory( (PWCHAR) irp->IoStatus.Information, str, str_len * sizeof *str ); status = STATUS_SUCCESS; goto alloc_info; case DeviceTextLocationInformation: if (disk->disk_ops.PnpQueryId) { io_stack_loc->MinorFunction = IRP_MN_QUERY_ID; io_stack_loc->Parameters.QueryId.IdType = BusQueryInstanceID; return disk->disk_ops.PnpQueryId(dev_obj, irp, disk); } /* Else, fall through... */ default: irp->IoStatus.Information = 0; status = STATUS_NOT_SUPPORTED; } /* irp->IoStatus.Information not freed. */ alloc_info: wv_free(str); alloc_str: return WvlIrpComplete(irp, irp->IoStatus.Information, status); }
static NTSTATUS STDCALL AoeBusPnpQueryDevText_( IN WVL_SP_BUS_T bus, IN PIRP irp ) { WCHAR (*str)[512]; PIO_STACK_LOCATION io_stack_loc = IoGetCurrentIrpStackLocation(irp); NTSTATUS status; UINT32 str_len; /* Allocate a string buffer. */ str = wv_mallocz(sizeof *str); if (str == NULL) { DBG("wv_malloc IRP_MN_QUERY_DEVICE_TEXT\n"); status = STATUS_INSUFFICIENT_RESOURCES; goto alloc_str; } /* Determine the query type. */ switch (io_stack_loc->Parameters.QueryDeviceText.DeviceTextType) { case DeviceTextDescription: str_len = swprintf(*str, L"AoE Bus") + 1; irp->IoStatus.Information = (ULONG_PTR) wv_palloc(str_len * sizeof **str); if (irp->IoStatus.Information == 0) { DBG("wv_palloc DeviceTextDescription\n"); status = STATUS_INSUFFICIENT_RESOURCES; goto alloc_info; } RtlCopyMemory( (PWCHAR) irp->IoStatus.Information, str, str_len * sizeof **str ); status = STATUS_SUCCESS; goto alloc_info; case DeviceTextLocationInformation: str_len = AoeBusPnpId_( NULL, BusQueryInstanceID, str ); irp->IoStatus.Information = (ULONG_PTR) wv_palloc(str_len * sizeof **str); if (irp->IoStatus.Information == 0) { DBG("wv_palloc DeviceTextLocationInformation\n"); status = STATUS_INSUFFICIENT_RESOURCES; goto alloc_info; } RtlCopyMemory( (PWCHAR) irp->IoStatus.Information, str, str_len * sizeof **str ); status = STATUS_SUCCESS; goto alloc_info; default: irp->IoStatus.Information = 0; status = STATUS_NOT_SUPPORTED; } /* irp->IoStatus.Information not freed. */ alloc_info: wv_free(str); alloc_str: return WvlIrpComplete(irp, irp->IoStatus.Information, status); }