return disk_ptr->SectorSize * aoe_disk_ptr->MaxSectorsPerPacket;
}
-static disk__pnp_id_decl(query_id)
- {
- struct aoe__disk_type_ * aoe_disk_ptr = aoe__get_(disk_ptr->device);
-
- switch ( query_type )
- {
+static winvblock__uint32 STDCALL query_id(
+ IN struct device__type * dev,
+ IN BUS_QUERY_ID_TYPE query_type,
+ IN OUT WCHAR (*buf)[512]
+ ) {
+ struct aoe__disk_type_ * aoe_disk = aoe__get_(dev);
+
+ switch (query_type) {
case BusQueryDeviceID:
- return swprintf ( buf_512, winvblock__literal_w L"\\AoEHardDisk" ) + 1;
+ return swprintf(*buf, winvblock__literal_w L"\\AoEHardDisk") + 1;
+
case BusQueryInstanceID:
- return swprintf ( buf_512, L"AoE_at_Shelf_%d.Slot_%d",
- aoe_disk_ptr->Major, aoe_disk_ptr->Minor ) + 1;
- case BusQueryHardwareIDs:
- {
- winvblock__uint32 tmp =
- swprintf ( buf_512, winvblock__literal_w L"\\AoEHardDisk" ) + 1;
- tmp += swprintf ( &buf_512[tmp], L"GenDisk" ) + 4;
- return tmp;
- }
+ return swprintf(
+ *buf,
+ L"AoE_at_Shelf_%d.Slot_%d",
+ aoe_disk->Major,
+ aoe_disk->Minor
+ ) + 1;
+
+ case BusQueryHardwareIDs: {
+ winvblock__uint32 tmp;
+
+ tmp = swprintf(
+ *buf,
+ winvblock__literal_w L"\\AoEHardDisk"
+ ) + 1;
+ tmp += swprintf(*buf + tmp, L"GenDisk") + 4;
+ return tmp;
+ }
+
case BusQueryCompatibleIDs:
- return swprintf ( buf_512, L"GenDisk" ) + 4;
+ return swprintf(*buf, L"GenDisk") + 4;
+
default:
- return 0;
+ return 0;
}
}
aoe_disk_ptr->disk = disk_ptr;
aoe_disk_ptr->prev_free = disk_ptr->device->ops.free;
disk_ptr->device->ops.free = aoe__free_disk_;
+ disk_ptr->device->ops.pnp_id = query_id;
disk_ptr->disk_ops.io = io;
disk_ptr->disk_ops.max_xfer_len = max_xfer_len;
- disk_ptr->disk_ops.pnp_id = query_id;
disk_ptr->disk_ops.init = init;
disk_ptr->disk_ops.close = close;
disk_ptr->ext = aoe_disk_ptr;
*/
typedef winvblock__bool STDCALL device__init_func(IN struct device__type *);
+/**
+ * Device PnP ID reponse routine.
+ *
+ * @v dev The device being queried for PnP IDs.
+ * @v query_type The query type.
+ * @v buf Wide character, 512-element buffer for the
+ * ID response.
+ * @ret winvblock__uint32 The number of wide characters in the response.
+ */
+typedef winvblock__uint32 STDCALL device__pnp_id_func(
+ IN struct device__type *,
+ IN BUS_QUERY_ID_TYPE,
+ IN OUT WCHAR (*)[512]
+ );
+
+extern winvblock__lib_func device__pnp_id_func device__pnp_id;
+
/**
* Device close routine.
*
- * @v dev_ptr The device being closed.
+ * @v dev The device being closed.
*/
typedef void STDCALL device__close_func(IN struct device__type *);
winvblock__def_struct(device__ops) {
device__create_pdo_func * create_pdo;
device__init_func * init;
+ device__pnp_id_func * pnp_id;
device__close_func * close;
device__free_func * free;
};
PDEVICE_OBJECT,
struct device__type *
);
+extern irp__handler device__pnp_query_id;
#endif /* _DEVICE_H */
( *disk__init_routine )
);
-/**
- * Disk PnP ID reponse routine
- *
- * @v disk_ptr The disk device being queried
- * @v query_type The query type
- * @v buf_512 Wide character 512-element buffer for ID response
- *
- * Returns the number of wide characters in the response.
- */
-# define disk__pnp_id_decl( x ) \
-\
-winvblock__uint32 STDCALL \
-x ( \
- IN disk__type_ptr disk_ptr, \
- IN BUS_QUERY_ID_TYPE query_type, \
- OUT PWCHAR buf_512 \
- )
-/*
- * Function pointer for a disk PnP response routine.
- * 'indent' mangles this, so it looks weird
- */
-typedef disk__pnp_id_decl (
- ( *disk__pnp_id_routine )
- );
-
/**
* Disk close routine
*
disk__io_routine io;
disk__max_xfer_len_routine max_xfer_len;
disk__init_routine init;
- disk__pnp_id_routine pnp_id;
disk__close_routine close;
};
extern disk__max_xfer_len_decl (
disk__max_xfer_len
);
-extern disk__pnp_id_decl (
- disk__query_id
- );
/**
* Attempt to guess a disk's geometry
return NULL;
}
+/**
+ * Respond to a device PnP ID query.
+ *
+ * @v dev The device being queried for PnP IDs.
+ * @v query_type The query type.
+ * @v buf Wide character, 512-element buffer for the
+ * ID response.
+ * @ret winvblock__uint32 The number of wide characters in the response,
+ * or 0 upon a failure.
+ */
+winvblock__uint32 STDCALL device__pnp_id(
+ IN struct device__type * dev,
+ IN BUS_QUERY_ID_TYPE query_type,
+ IN OUT WCHAR (*buf)[512]
+ ) {
+ return dev->ops.pnp_id ? dev->ops.pnp_id(dev, query_type, buf) : 0;
+ }
+
+/* An IRP handler for a PnP ID query. */
+NTSTATUS STDCALL device__pnp_query_id(
+ IN PDEVICE_OBJECT DeviceObject,
+ IN PIRP Irp,
+ IN PIO_STACK_LOCATION Stack,
+ IN struct device__type * dev,
+ OUT winvblock__bool_ptr completion
+ ) {
+ NTSTATUS status;
+ WCHAR (*str)[512];
+ winvblock__uint32 str_len;
+
+ /* Allocate the working buffer. */
+ str = wv_mallocz(sizeof *str);
+ if (str == NULL) {
+ DBG("wv_malloc IRP_MN_QUERY_ID\n");
+ status = STATUS_INSUFFICIENT_RESOURCES;
+ goto alloc_str;
+ }
+ /* Invoke the specific device's ID query. */
+ str_len = device__pnp_id(
+ dev,
+ Stack->Parameters.QueryId.IdType,
+ str
+ );
+ if (str_len == 0) {
+ Irp->IoStatus.Information = 0;
+ status = STATUS_NOT_SUPPORTED;
+ goto alloc_info;
+ }
+ /* Allocate the return buffer. */
+ Irp->IoStatus.Information = (ULONG_PTR) wv_palloc(str_len * sizeof **str);
+ if (Irp->IoStatus.Information == 0) {
+ DBG("wv_palloc failed.\n");
+ status = STATUS_INSUFFICIENT_RESOURCES;
+ goto alloc_info;
+ }
+ /* Copy the working buffer to the return buffer. */
+ RtlCopyMemory(
+ (void *) Irp->IoStatus.Information,
+ str,
+ str_len * sizeof **str
+ );
+ status = STATUS_SUCCESS;
+
+ /* Irp->IoStatus.Information not freed. */
+ alloc_info:
+
+ wv_free(str);
+ alloc_str:
+
+ Irp->IoStatus.Status = status;
+ IoCompleteRequest(Irp, IO_NO_INCREMENT);
+ *completion = TRUE;
+ return status;
+ }
+
/**
* Close a device.
*
IRP_MN_QUERY_DEVICE_TEXT, FALSE, FALSE,
disk_pnp__query_dev_text },
{ IRP_MJ_PNP,
- IRP_MN_QUERY_ID, FALSE, FALSE, disk_pnp__query_id },
+ IRP_MN_QUERY_ID, FALSE, FALSE, device__pnp_query_id },
};
status = irp__process_with_table(
{
return disk_ptr->disk_ops.max_xfer_len ( disk_ptr );
}
-
-/* See header for details */
-disk__pnp_id_decl ( disk__query_id )
-{
- return disk_ptr->disk_ops.pnp_id ( disk_ptr, query_type, buf_512 );
-}
#include "bus.h"
#include "debug.h"
-NTSTATUS STDCALL disk_pnp__query_id(
- IN PDEVICE_OBJECT DeviceObject,
- IN PIRP Irp,
- IN PIO_STACK_LOCATION Stack,
- IN struct device__type * dev_ptr,
- OUT winvblock__bool_ptr completion_ptr
- )
-{
- NTSTATUS status;
- PWCHAR string;
- winvblock__uint32 string_length;
- disk__type_ptr disk_ptr;
-
- disk_ptr = disk__get_ptr ( dev_ptr );
- string = wv_mallocz(512 * sizeof *string);
- if ( string == NULL )
- {
- DBG("wv_malloc IRP_MN_QUERY_ID\n");
- status = STATUS_INSUFFICIENT_RESOURCES;
- goto alloc_string;
- }
- /*
- * Invoke the specific disk class ID query
- */
- string_length =
- disk__query_id ( disk_ptr, Stack->Parameters.QueryId.IdType, string );
-
- if ( string_length == 0 )
- {
- Irp->IoStatus.Information = 0;
- status = STATUS_NOT_SUPPORTED;
- goto alloc_info;
- }
-
- Irp->IoStatus.Information = (ULONG_PTR) wv_palloc(
- string_length * sizeof *string
- );
- if ( Irp->IoStatus.Information == 0 )
- {
- DBG("wv_palloc failed.\n");
- status = STATUS_INSUFFICIENT_RESOURCES;
- goto alloc_info;
- }
- RtlCopyMemory ( ( PWCHAR ) Irp->IoStatus.Information, string,
- string_length * sizeof ( WCHAR ) );
- status = STATUS_SUCCESS;
- /*
- * Irp->IoStatus.Information not freed
- */
-alloc_info:
-
- wv_free(string);
-alloc_string:
-
- Irp->IoStatus.Status = status;
- IoCompleteRequest ( Irp, IO_NO_INCREMENT );
- *completion_ptr = TRUE;
- return status;
-}
-
NTSTATUS STDCALL disk_pnp__query_dev_text(
IN PDEVICE_OBJECT DeviceObject,
IN PIRP Irp,
status = STATUS_INSUFFICIENT_RESOURCES;
goto alloc_info;
}
- RtlCopyMemory ( ( PWCHAR ) Irp->IoStatus.Information, string,
- string_length * sizeof ( WCHAR ) );
+ RtlCopyMemory(
+ (PWCHAR) Irp->IoStatus.Information,
+ (WCHAR (*)[512]) string,
+ string_length * sizeof (WCHAR)
+ );
status = STATUS_SUCCESS;
goto alloc_info;
case DeviceTextLocationInformation:
- string_length =
- disk__query_id ( disk_ptr, BusQueryInstanceID, string );
- Irp->IoStatus.Information = (ULONG_PTR) wv_palloc(
- string_length * sizeof *string
- );
+ string_length = device__pnp_id(
+ dev_ptr,
+ BusQueryInstanceID,
+ (WCHAR (*)[512]) string
+ );
+ Irp->IoStatus.Information = (ULONG_PTR) wv_palloc(
+ string_length * sizeof *string
+ );
if ( Irp->IoStatus.Information == 0 )
{
DBG("wv_palloc DeviceTextLocationInformation\n");
return status;
}
-static
-disk__pnp_id_decl (
- query_id
- )
-{
- filedisk__type_ptr filedisk_ptr = filedisk__get_ptr ( disk_ptr->device );
- static PWCHAR hw_ids[disk__media_count] =
- { winvblock__literal_w L"\\FileFloppyDisk",
- winvblock__literal_w L"\\FileHardDisk",
- winvblock__literal_w L"\\FileOpticalDisc"
- };
-
- switch ( query_type )
- {
- case BusQueryDeviceID:
- return swprintf ( buf_512, hw_ids[disk_ptr->media] ) + 1;
- case BusQueryInstanceID:
- return swprintf ( buf_512, L"Hash_%08X", filedisk_ptr->hash ) + 1;
- case BusQueryHardwareIDs:
- {
- winvblock__uint32 tmp;
- tmp = swprintf ( buf_512, hw_ids[disk_ptr->media] ) + 1;
- tmp +=
- swprintf ( &buf_512[tmp], disk__compat_ids[disk_ptr->media] ) + 4;
- return tmp;
- }
- case BusQueryCompatibleIDs:
- return swprintf ( buf_512, disk__compat_ids[disk_ptr->media] ) + 4;
- default:
- return 0;
- }
-}
+static winvblock__uint32 STDCALL query_id(
+ IN struct device__type * dev,
+ IN BUS_QUERY_ID_TYPE query_type,
+ IN OUT WCHAR (*buf)[512]
+ ) {
+ disk__type_ptr disk = disk__get_ptr(dev);
+ filedisk__type_ptr filedisk = filedisk__get_ptr(dev);
+ static PWCHAR hw_ids[disk__media_count] = {
+ winvblock__literal_w L"\\FileFloppyDisk",
+ winvblock__literal_w L"\\FileHardDisk",
+ winvblock__literal_w L"\\FileOpticalDisc"
+ };
+
+ switch (query_type) {
+ case BusQueryDeviceID:
+ return swprintf(*buf, hw_ids[disk->media]) + 1;
+
+ case BusQueryInstanceID:
+ return swprintf(*buf, L"Hash_%08X", filedisk->hash) + 1;
+
+ case BusQueryHardwareIDs: {
+ winvblock__uint32 tmp;
+
+ tmp = swprintf(*buf, hw_ids[disk->media]) + 1;
+ tmp += swprintf(*buf + tmp, disk__compat_ids[disk->media]) + 4;
+ return tmp;
+ }
+
+ case BusQueryCompatibleIDs:
+ return swprintf(*buf, disk__compat_ids[disk->media]) + 4;
+
+ default:
+ return 0;
+ }
+ }
NTSTATUS STDCALL filedisk__attach(
IN PDEVICE_OBJECT DeviceObject,
filedisk_ptr->disk = disk_ptr;
filedisk_ptr->prev_free = disk_ptr->device->ops.free;
disk_ptr->device->ops.free = free_filedisk;
+ disk_ptr->device->ops.pnp_id = query_id;
disk_ptr->disk_ops.io = io;
- disk_ptr->disk_ops.pnp_id = query_id;
disk_ptr->disk_ops.close = close;
disk_ptr->ext = filedisk_ptr;
return STATUS_SUCCESS;
}
-static
-disk__pnp_id_decl (
- query_id
- )
-{
- ramdisk__type_ptr ramdisk_ptr = ramdisk_get_ptr ( disk_ptr->device );
- static PWCHAR hw_ids[disk__media_count] =
- { winvblock__literal_w L"\\RAMFloppyDisk",
- winvblock__literal_w L"\\RAMHardDisk",
- winvblock__literal_w L"\\RAMOpticalDisc"
- };
-
- switch ( query_type )
- {
- case BusQueryDeviceID:
- return swprintf ( buf_512, hw_ids[disk_ptr->media] ) + 1;
- case BusQueryInstanceID:
- /*
- * "Location"
- */
- return swprintf ( buf_512, L"RAM_at_%08X", ramdisk_ptr->DiskBuf ) + 1;
- case BusQueryHardwareIDs:
- {
- winvblock__uint32 tmp;
- tmp = swprintf ( buf_512, hw_ids[disk_ptr->media] ) + 1;
- tmp +=
- swprintf ( &buf_512[tmp], disk__compat_ids[disk_ptr->media] ) + 4;
- return tmp;
- }
- case BusQueryCompatibleIDs:
- return swprintf ( buf_512, disk__compat_ids[disk_ptr->media] ) + 4;
- default:
- return 0;
- }
-}
+static winvblock__uint32 STDCALL query_id(
+ IN struct device__type * dev,
+ IN BUS_QUERY_ID_TYPE query_type,
+ IN OUT WCHAR (*buf)[512]
+ ) {
+ disk__type_ptr disk = disk__get_ptr(dev);
+ ramdisk__type_ptr ramdisk = ramdisk_get_ptr(dev);
+ static PWCHAR hw_ids[disk__media_count] = {
+ winvblock__literal_w L"\\RAMFloppyDisk",
+ winvblock__literal_w L"\\RAMHardDisk",
+ winvblock__literal_w L"\\RAMOpticalDisc"
+ };
+
+ switch (query_type) {
+ case BusQueryDeviceID:
+ return swprintf(*buf, hw_ids[disk->media]) + 1;
+
+ case BusQueryInstanceID:
+ /* "Location" */
+ return swprintf(*buf, L"RAM_at_%08X", ramdisk->DiskBuf) + 1;
+
+ case BusQueryHardwareIDs: {
+ winvblock__uint32 tmp;
+
+ tmp = swprintf(*buf, hw_ids[disk->media]) + 1;
+ tmp += swprintf(*buf + tmp, disk__compat_ids[disk->media]) + 4;
+ return tmp;
+ }
+
+ case BusQueryCompatibleIDs:
+ return swprintf(*buf, disk__compat_ids[disk->media]) + 4;
+
+ default:
+ return 0;
+ }
+ }
/**
* Create a new RAM disk
ramdisk_ptr->disk = disk_ptr;
ramdisk_ptr->prev_free = disk_ptr->device->ops.free;
disk_ptr->device->ops.free = free_ramdisk;
+ disk_ptr->device->ops.pnp_id = query_id;
disk_ptr->disk_ops.io = io;
- disk_ptr->disk_ops.pnp_id = query_id;
disk_ptr->ext = ramdisk_ptr;
return ramdisk_ptr;