[bus/dev_ctl] Minor cosmetic changes
authorShao Miller <Shao.Miller@yrdsb.edu.on.ca>
Sun, 12 Dec 2010 02:43:37 +0000 (21:43 -0500)
committerShao Miller <Shao.Miller@yrdsb.edu.on.ca>
Sun, 12 Dec 2010 02:43:37 +0000 (21:43 -0500)
src/winvblock/bus/dev_ctl.c

index 912699f..78ec7d7 100644 (file)
 #include "filedisk.h"
 
 static NTSTATUS STDCALL disk_detach(
-    IN PDEVICE_OBJECT DeviceObject,
-    IN PIRP Irp,
-    IN PIO_STACK_LOCATION Stack,
-    IN struct device__type * dev_ptr,
-    OUT winvblock__bool_ptr completion_ptr
-  )
-{
-  winvblock__uint8_ptr buffer = Irp->AssociatedIrp.SystemBuffer;
-  struct device__type * dev_walker;
-  disk__type_ptr disk_walker = NULL,
-    prev_disk_walker;
-  struct bus__type * bus_ptr;
+    IN PDEVICE_OBJECT dev_obj,
+    IN PIRP irp,
+    IN PIO_STACK_LOCATION io_stack_loc,
+    IN struct device__type * dev,
+    OUT winvblock__bool_ptr completion
+  ) {
+    winvblock__uint8_ptr buffer = irp->AssociatedIrp.SystemBuffer;
+    winvblock__uint32 disk_num = *(winvblock__uint32_ptr) buffer;
+    struct device__type * dev_walker;
+    disk__type_ptr disk_walker = NULL, prev_disk_walker;
+    struct bus__type * bus;
 
-  DBG ( "Request to detach disk: %d\n", *( winvblock__uint32_ptr ) buffer );
-  bus_ptr = bus__get(dev_ptr);
-  dev_walker = bus_ptr->first_child;
-  if ( dev_walker != NULL )
-    disk_walker = disk__get_ptr ( dev_walker );
-  prev_disk_walker = disk_walker;
-  while ( ( disk_walker != NULL )
-         && ( disk_walker->DiskNumber != *( winvblock__uint32_ptr ) buffer ) )
-    {
-      prev_disk_walker = disk_walker;
-      dev_walker = dev_walker->next_sibling_ptr;
-      if ( dev_walker != NULL )
-       disk_walker = disk__get_ptr ( dev_walker );
-    }
-  if ( disk_walker != NULL )
-    {
-      if ( disk_walker->BootDrive )
-       {
-         DBG ( "Cannot unmount a boot drive.\n" );
-         Irp->IoStatus.Information = 0;
-         *completion_ptr = TRUE;
-         return STATUS_INVALID_DEVICE_REQUEST;
-       }
-      DBG ( "Deleting disk %d\n", disk_walker->DiskNumber );
-      if (disk_walker == disk__get_ptr(bus_ptr->first_child))
-         bus_ptr->first_child = dev_walker->next_sibling_ptr;
-      else {
-          prev_disk_walker->device->next_sibling_ptr =
-            dev_walker->next_sibling_ptr;
-       }
-      disk_walker->Unmount = TRUE;
-      dev_walker->next_sibling_ptr = NULL;
-      if ( bus_ptr->PhysicalDeviceObject != NULL )
-       IoInvalidateDeviceRelations ( bus_ptr->PhysicalDeviceObject,
-                                     BusRelations );
-    }
-  bus_ptr->Children--;
-  Irp->IoStatus.Information = 0;
-  *completion_ptr = TRUE;
-  return STATUS_SUCCESS;
-}
+    DBG("Request to detach disk: %d\n", disk_num);
+    bus = bus__get(dev);
+    dev_walker = bus->first_child;
+    if (dev_walker != NULL)
+      disk_walker = disk__get_ptr(dev_walker);
+    prev_disk_walker = disk_walker;
+    while ((disk_walker != NULL) && (disk_walker->DiskNumber != disk_num)) {
+        prev_disk_walker = disk_walker;
+        dev_walker = dev_walker->next_sibling_ptr;
+        if (dev_walker != NULL)
+          disk_walker = disk__get_ptr(dev_walker);
+      }
+    if (disk_walker != NULL) {
+        if (disk_walker->BootDrive) {
+            DBG("Cannot unmount a boot drive.\n");
+            irp->IoStatus.Information = 0;
+            *completion = TRUE;
+            return STATUS_INVALID_DEVICE_REQUEST;
+          }
+        DBG("Deleting disk %d\n", disk_walker->DiskNumber);
+        if (disk_walker == disk__get_ptr(bus->first_child))
+          bus->first_child = dev_walker->next_sibling_ptr;
+          else {
+            prev_disk_walker->device->next_sibling_ptr =
+              dev_walker->next_sibling_ptr;
+          }
+        disk_walker->Unmount = TRUE;
+        dev_walker->next_sibling_ptr = NULL;
+        if (bus->PhysicalDeviceObject != NULL)
+          IoInvalidateDeviceRelations(bus->PhysicalDeviceObject, BusRelations);
+      }
+    bus->Children--;
+    irp->IoStatus.Information = 0;
+    *completion = TRUE;
+    return STATUS_SUCCESS;
+  }
 
 NTSTATUS STDCALL bus_dev_ctl__dispatch(
-    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;
-  switch ( Stack->Parameters.DeviceIoControl.IoControlCode )
-    {
-      case IOCTL_FILE_ATTACH:
-       status =
-         filedisk__attach ( DeviceObject, Irp, Stack, dev_ptr,
-                            completion_ptr );
-       break;
-      case IOCTL_FILE_DETACH:
-       status =
-         disk_detach ( DeviceObject, Irp, Stack, dev_ptr, completion_ptr );
-       break;
-      default:
-       Irp->IoStatus.Information = 0;
-       status = STATUS_INVALID_DEVICE_REQUEST;
-    }
+    IN PDEVICE_OBJECT dev_obj,
+    IN PIRP irp,
+    IN PIO_STACK_LOCATION io_stack_loc,
+    IN struct device__type * dev,
+    OUT winvblock__bool_ptr completion
+  ) {
+    NTSTATUS status;
+    switch (io_stack_loc->Parameters.DeviceIoControl.IoControlCode) {
+        case IOCTL_FILE_ATTACH:
+          status = filedisk__attach(
+              dev_obj,
+              irp,
+              io_stack_loc,
+              dev,
+              completion
+            );
+          break;
 
-  Irp->IoStatus.Status = status;
-  IoCompleteRequest ( Irp, IO_NO_INCREMENT );
-  *completion_ptr = TRUE;
-  return status;
-}
+        case IOCTL_FILE_DETACH:
+          status = disk_detach(
+              dev_obj,
+              irp,
+              io_stack_loc,
+              dev,
+              completion
+            );
+          break;
+
+        default:
+          irp->IoStatus.Information = 0;
+          status = STATUS_INVALID_DEVICE_REQUEST;
+      }
+
+    irp->IoStatus.Status = status;
+    IoCompleteRequest(irp, IO_NO_INCREMENT);
+    *completion = TRUE;
+    return status;
+  }