Revert "[httpdisk] Apply WinVBlock-as-usual indentation"
authorShao Miller <Shao.Miller@yrdsb.edu.on.ca>
Wed, 29 Dec 2010 19:19:16 +0000 (14:19 -0500)
committerShao Miller <Shao.Miller@yrdsb.edu.on.ca>
Wed, 29 Dec 2010 19:19:16 +0000 (14:19 -0500)
This reverts commit 2549ed2921c3d63e38a609da89acb16101fdd0c9.

src/httpdisk/httpdisk.c
src/httpdisk/ksocket.c
src/httpdisk/ksocket.h
src/httpdisk/ktdi.c
src/httpdisk/ktdi.h
src/httpdisk_util/httpdisk.c
src/include/httpdisk.h

index 24a22d6..9d9c2d8 100644 (file)
 //
 #if (VER_PRODUCTBUILD < 2195)
 
-#  define FILE_DEVICE_MASS_STORAGE            0x0000002d
-#  define IOCTL_STORAGE_CHECK_VERIFY2         CTL_CODE(IOCTL_STORAGE_BASE, 0x0200, METHOD_BUFFERED, FILE_ANY_ACCESS)
+#define FILE_DEVICE_MASS_STORAGE            0x0000002d
+#define IOCTL_STORAGE_CHECK_VERIFY2         CTL_CODE(IOCTL_STORAGE_BASE, 0x0200, METHOD_BUFFERED, FILE_ANY_ACCESS)
 
-#endif                         // (VER_PRODUCTBUILD < 2195)
+#endif // (VER_PRODUCTBUILD < 2195)
 
 #if (VER_PRODUCTBUILD < 2600)
 
-#  define IOCTL_DISK_GET_PARTITION_INFO_EX    CTL_CODE(IOCTL_DISK_BASE, 0x0012, METHOD_BUFFERED, FILE_ANY_ACCESS)
-#  define IOCTL_DISK_GET_LENGTH_INFO          CTL_CODE(IOCTL_DISK_BASE, 0x0017, METHOD_BUFFERED, FILE_READ_ACCESS)
+#define IOCTL_DISK_GET_PARTITION_INFO_EX    CTL_CODE(IOCTL_DISK_BASE, 0x0012, METHOD_BUFFERED, FILE_ANY_ACCESS)
+#define IOCTL_DISK_GET_LENGTH_INFO          CTL_CODE(IOCTL_DISK_BASE, 0x0017, METHOD_BUFFERED, FILE_READ_ACCESS)
 
-typedef enum _PARTITION_STYLE
-{
-  PARTITION_STYLE_MBR,
-  PARTITION_STYLE_GPT
+typedef enum _PARTITION_STYLE {
+    PARTITION_STYLE_MBR,
+    PARTITION_STYLE_GPT
 } PARTITION_STYLE;
 
-typedef unsigned __int64 ULONG64,
-*PULONG64;
-
-typedef struct _PARTITION_INFORMATION_MBR
-{
-  UCHAR PartitionType;
-  BOOLEAN BootIndicator;
-  BOOLEAN RecognizedPartition;
-  ULONG HiddenSectors;
-} PARTITION_INFORMATION_MBR,
-*PPARTITION_INFORMATION_MBR;
-
-typedef struct _PARTITION_INFORMATION_GPT
-{
-  GUID PartitionType;
-  GUID PartitionId;
-  ULONG64 Attributes;
-  WCHAR Name[36];
-} PARTITION_INFORMATION_GPT,
-*PPARTITION_INFORMATION_GPT;
-
-typedef struct _PARTITION_INFORMATION_EX
-{
-  PARTITION_STYLE PartitionStyle;
-  LARGE_INTEGER StartingOffset;
-  LARGE_INTEGER PartitionLength;
-  ULONG PartitionNumber;
-  BOOLEAN RewritePartition;
-  union
-  {
-    PARTITION_INFORMATION_MBR Mbr;
-    PARTITION_INFORMATION_GPT Gpt;
-  };
-} PARTITION_INFORMATION_EX,
-*PPARTITION_INFORMATION_EX;
-
-typedef struct _GET_LENGTH_INFORMATION
-{
-  LARGE_INTEGER Length;
-} GET_LENGTH_INFORMATION,
-*PGET_LENGTH_INFORMATION;
-
-#endif                         // (VER_PRODUCTBUILD < 2600)
+typedef unsigned __int64 ULONG64, *PULONG64;
+
+typedef struct _PARTITION_INFORMATION_MBR {
+    UCHAR   PartitionType;
+    BOOLEAN BootIndicator;
+    BOOLEAN RecognizedPartition;
+    ULONG   HiddenSectors;
+} PARTITION_INFORMATION_MBR, *PPARTITION_INFORMATION_MBR;
+
+typedef struct _PARTITION_INFORMATION_GPT {
+    GUID    PartitionType;
+    GUID    PartitionId;
+    ULONG64 Attributes;
+    WCHAR   Name[36];
+} PARTITION_INFORMATION_GPT, *PPARTITION_INFORMATION_GPT;
+
+typedef struct _PARTITION_INFORMATION_EX {
+    PARTITION_STYLE PartitionStyle;
+    LARGE_INTEGER   StartingOffset;
+    LARGE_INTEGER   PartitionLength;
+    ULONG           PartitionNumber;
+    BOOLEAN         RewritePartition;
+    union {
+        PARTITION_INFORMATION_MBR Mbr;
+        PARTITION_INFORMATION_GPT Gpt;
+    };
+} PARTITION_INFORMATION_EX, *PPARTITION_INFORMATION_EX;
+
+typedef struct _GET_LENGTH_INFORMATION {
+    LARGE_INTEGER Length;
+} GET_LENGTH_INFORMATION, *PGET_LENGTH_INFORMATION;
+
+#endif // (VER_PRODUCTBUILD < 2600)
 
 //
 // For backward compatibility with Windows NT 4.0 by Bruce Engle.
 //
 #ifndef MmGetSystemAddressForMdlSafe
-#  define MmGetSystemAddressForMdlSafe(MDL, PRIORITY) MmGetSystemAddressForMdlPrettySafe(MDL)
+#define MmGetSystemAddressForMdlSafe(MDL, PRIORITY) MmGetSystemAddressForMdlPrettySafe(MDL)
 
 PVOID
 MmGetSystemAddressForMdlPrettySafe (
-  PMDL Mdl
- )
+    PMDL Mdl
   )
 {
-  CSHORT MdlMappingCanFail;
-  PVOID MappedSystemVa;
+    CSHORT  MdlMappingCanFail;
+    PVOID   MappedSystemVa;
 
-  MdlMappingCanFail = Mdl->MdlFlags & MDL_MAPPING_CAN_FAIL;
+    MdlMappingCanFail = Mdl->MdlFlags & MDL_MAPPING_CAN_FAIL;
 
-  Mdl->MdlFlags |= MDL_MAPPING_CAN_FAIL;
+    Mdl->MdlFlags |= MDL_MAPPING_CAN_FAIL;
 
-  MappedSystemVa = MmGetSystemAddressForMdl ( Mdl );
+    MappedSystemVa = MmGetSystemAddressForMdl(Mdl);
 
-  if ( MdlMappingCanFail == 0 )
+    if (MdlMappingCanFail == 0)
     {
-      Mdl->MdlFlags &= ~MDL_MAPPING_CAN_FAIL;
+        Mdl->MdlFlags &= ~MDL_MAPPING_CAN_FAIL;
     }
 
-  return MappedSystemVa;
+    return MappedSystemVa;
 }
 #endif
 
@@ -132,1363 +121,1440 @@ MmGetSystemAddressForMdlPrettySafe (
 
 HANDLE dir_handle;
 
-typedef struct _HTTP_HEADER
-{
-  LARGE_INTEGER ContentLength;
-} HTTP_HEADER,
-*PHTTP_HEADER;
+typedef struct _HTTP_HEADER {
+    LARGE_INTEGER ContentLength;
+} HTTP_HEADER, *PHTTP_HEADER;
+
+typedef struct _DEVICE_EXTENSION {
+    BOOLEAN         media_in_device;
+    ULONG           address;
+    USHORT          port;
+    PUCHAR          host_name;
+    PUCHAR          file_name;
+    LARGE_INTEGER   file_size;
+    int             socket;
+    LIST_ENTRY      list_head;
+    KSPIN_LOCK      list_lock;
+    KEVENT          request_event;
+    PVOID           thread_pointer;
+    BOOLEAN         terminate_thread;
+} DEVICE_EXTENSION, *PDEVICE_EXTENSION;
 
-typedef struct _DEVICE_EXTENSION
-{
-  BOOLEAN media_in_device;
-  ULONG address;
-  USHORT port;
-  PUCHAR host_name;
-  PUCHAR file_name;
-  LARGE_INTEGER file_size;
-  int socket;
-  LIST_ENTRY list_head;
-  KSPIN_LOCK list_lock;
-  KEVENT request_event;
-  PVOID thread_pointer;
-  BOOLEAN terminate_thread;
-} DEVICE_EXTENSION,
-*PDEVICE_EXTENSION;
-
-NTSTATUS DriverEntry (
-  IN PDRIVER_OBJECT DriverObject,
-  IN PUNICODE_STRING RegistryPath
- );
-
-NTSTATUS HttpDiskCreateDevice (
-  IN PDRIVER_OBJECT DriverObject,
-  IN ULONG Number,
-  IN DEVICE_TYPE DeviceType
- );
-
-VOID HttpDiskUnload (
-  IN PDRIVER_OBJECT DriverObject
- );
-
-PDEVICE_OBJECT HttpDiskDeleteDevice (
-  IN PDEVICE_OBJECT DeviceObject
- );
-
-NTSTATUS HttpDiskCreateClose (
-  IN PDEVICE_OBJECT DeviceObject,
-  IN PIRP Irp
- );
-
-NTSTATUS HttpDiskReadWrite (
-  IN PDEVICE_OBJECT DeviceObject,
-  IN PIRP Irp
- );
-
-NTSTATUS HttpDiskDeviceControl (
-  IN PDEVICE_OBJECT DeviceObject,
-  IN PIRP Irp
- );
-
-VOID HttpDiskThread (
-  IN PVOID Context
- );
-
-NTSTATUS HttpDiskConnect (
-  IN PDEVICE_OBJECT DeviceObject,
-  IN PIRP Irp
- );
-
-NTSTATUS HttpDiskDisconnect (
-  IN PDEVICE_OBJECT DeviceObject,
-  IN PIRP Irp
- );
-
-NTSTATUS HttpDiskGetHeader (
-  IN ULONG Address,
-  IN USHORT Port,
-  IN PUCHAR HostName,
-  IN PUCHAR FileName,
-  OUT PIO_STATUS_BLOCK IoStatus,
-  OUT PHTTP_HEADER HttpHeader
- );
-
-NTSTATUS HttpDiskGetBlock (
-  IN int *Socket,
-  IN ULONG Address,
-  IN USHORT Port,
-  IN PUCHAR HostName,
-  IN PUCHAR FileName,
-  IN PLARGE_INTEGER Offset,
-  IN ULONG Length,
-  OUT PIO_STATUS_BLOCK IoStatus,
-  OUT PVOID SystemBuffer
- );
-
-__int64 __cdecl _atoi64 (
-  const char *
- );
-int __cdecl _snprintf (
-  char *,
-  size_t,
-  const char *,
-  ...
- );
-int __cdecl swprintf (
-  wchar_t *,
-  const wchar_t *,
-  ...
- );
+NTSTATUS
+DriverEntry (
+    IN PDRIVER_OBJECT   DriverObject,
+    IN PUNICODE_STRING  RegistryPath
+);
+
+NTSTATUS
+HttpDiskCreateDevice (
+    IN PDRIVER_OBJECT   DriverObject,
+    IN ULONG            Number,
+    IN DEVICE_TYPE      DeviceType
+);
+
+VOID
+HttpDiskUnload (
+    IN PDRIVER_OBJECT   DriverObject
+);
+
+PDEVICE_OBJECT
+HttpDiskDeleteDevice (
+    IN PDEVICE_OBJECT   DeviceObject
+);
+
+NTSTATUS
+HttpDiskCreateClose (
+    IN PDEVICE_OBJECT   DeviceObject,
+    IN PIRP             Irp
+);
+
+NTSTATUS
+HttpDiskReadWrite (
+    IN PDEVICE_OBJECT   DeviceObject,
+    IN PIRP             Irp
+);
+
+NTSTATUS
+HttpDiskDeviceControl (
+    IN PDEVICE_OBJECT   DeviceObject,
+    IN PIRP             Irp
+);
+
+VOID
+HttpDiskThread (
+    IN PVOID            Context
+);
+
+NTSTATUS
+HttpDiskConnect (
+    IN PDEVICE_OBJECT   DeviceObject,
+    IN PIRP             Irp
+);
+
+NTSTATUS
+HttpDiskDisconnect (
+    IN PDEVICE_OBJECT   DeviceObject,
+    IN PIRP             Irp
+);
+
+NTSTATUS
+HttpDiskGetHeader (
+    IN ULONG                Address,
+    IN USHORT               Port,
+    IN PUCHAR               HostName,
+    IN PUCHAR               FileName,
+    OUT PIO_STATUS_BLOCK    IoStatus,
+    OUT PHTTP_HEADER        HttpHeader
+);
+
+NTSTATUS
+HttpDiskGetBlock (
+    IN int                  *Socket,
+    IN ULONG                Address,
+    IN USHORT               Port,
+    IN PUCHAR               HostName,
+    IN PUCHAR               FileName,
+    IN PLARGE_INTEGER       Offset,
+    IN ULONG                Length,
+    OUT PIO_STATUS_BLOCK    IoStatus,
+    OUT PVOID               SystemBuffer
+);
+
+__int64 __cdecl _atoi64(const char *);
+int __cdecl _snprintf(char *, size_t, const char *, ...);
+int __cdecl swprintf(wchar_t *, const wchar_t *, ...);
 
 #pragma code_seg("INIT")
 
 NTSTATUS
 DriverEntry (
-  IN PDRIVER_OBJECT DriverObject,
-  IN PUNICODE_STRING RegistryPath
- )
+    IN PDRIVER_OBJECT   DriverObject,
+    IN PUNICODE_STRING  RegistryPath
   )
 {
-  UNICODE_STRING parameter_path;
-  RTL_QUERY_REGISTRY_TABLE query_table[2];
-  ULONG n_devices;
-  NTSTATUS status;
-  UNICODE_STRING device_dir_name;
-  OBJECT_ATTRIBUTES object_attributes;
-  ULONG n;
-  USHORT n_created_devices;
+    UNICODE_STRING              parameter_path;
+    RTL_QUERY_REGISTRY_TABLE    query_table[2];
+    ULONG                       n_devices;
+    NTSTATUS                    status;
+    UNICODE_STRING              device_dir_name;
+    OBJECT_ATTRIBUTES           object_attributes;
+    ULONG                       n;
+    USHORT                      n_created_devices;
 
-  parameter_path.Length = 0;
+    parameter_path.Length = 0;
 
-  parameter_path.MaximumLength =
-    RegistryPath->Length + sizeof ( PARAMETER_KEY );
+    parameter_path.MaximumLength = RegistryPath->Length + sizeof(PARAMETER_KEY);
 
-  parameter_path.Buffer =
-    ( PWSTR ) ExAllocatePool ( PagedPool, parameter_path.MaximumLength );
+    parameter_path.Buffer = (PWSTR) ExAllocatePool(PagedPool, parameter_path.MaximumLength);
 
-  if ( parameter_path.Buffer == NULL )
+    if (parameter_path.Buffer == NULL)
     {
-      return STATUS_INSUFFICIENT_RESOURCES;
+        return STATUS_INSUFFICIENT_RESOURCES;
     }
 
-  RtlCopyUnicodeString ( &parameter_path, RegistryPath );
+    RtlCopyUnicodeString(&parameter_path, RegistryPath);
 
-  RtlAppendUnicodeToString ( &parameter_path, PARAMETER_KEY );
+    RtlAppendUnicodeToString(&parameter_path, PARAMETER_KEY);
 
-  RtlZeroMemory ( &query_table[0], sizeof ( query_table ) );
+    RtlZeroMemory(&query_table[0], sizeof(query_table));
 
-  query_table[0].Flags =
-    RTL_QUERY_REGISTRY_DIRECT | RTL_QUERY_REGISTRY_REQUIRED;
-  query_table[0].Name = NUMBEROFDEVICES_VALUE;
-  query_table[0].EntryContext = &n_devices;
+    query_table[0].Flags = RTL_QUERY_REGISTRY_DIRECT | RTL_QUERY_REGISTRY_REQUIRED;
+    query_table[0].Name = NUMBEROFDEVICES_VALUE;
+    query_table[0].EntryContext = &n_devices;
 
-  status =
-    RtlQueryRegistryValues ( RTL_REGISTRY_ABSOLUTE, parameter_path.Buffer,
-                            &query_table[0], NULL, NULL );
+    status = RtlQueryRegistryValues(
+        RTL_REGISTRY_ABSOLUTE,
+        parameter_path.Buffer,
+        &query_table[0],
+        NULL,
+        NULL
+        );
 
-  ExFreePool ( parameter_path.Buffer );
+    ExFreePool(parameter_path.Buffer);
 
-  if ( !NT_SUCCESS ( status ) )
+    if (!NT_SUCCESS(status))
     {
-      DbgPrint ( "HttpDisk: Query registry failed, using default values.\n" );
-      n_devices = DEFAULT_NUMBEROFDEVICES;
+        DbgPrint("HttpDisk: Query registry failed, using default values.\n");
+        n_devices = DEFAULT_NUMBEROFDEVICES;
     }
 
-  RtlInitUnicodeString ( &device_dir_name, DEVICE_DIR_NAME );
+    RtlInitUnicodeString(&device_dir_name, DEVICE_DIR_NAME);
 
-  InitializeObjectAttributes ( &object_attributes, &device_dir_name,
-                              OBJ_PERMANENT, NULL, NULL );
+    InitializeObjectAttributes(
+        &object_attributes,
+        &device_dir_name,
+        OBJ_PERMANENT,
+        NULL,
+        NULL
+        );
 
-  status =
-    ZwCreateDirectoryObject ( &dir_handle, DIRECTORY_ALL_ACCESS,
-                             &object_attributes );
+    status = ZwCreateDirectoryObject(
+        &dir_handle,
+        DIRECTORY_ALL_ACCESS,
+        &object_attributes
+        );
 
-  if ( !NT_SUCCESS ( status ) )
+    if (!NT_SUCCESS(status))
     {
-      return status;
+        return status;
     }
 
-  ZwMakeTemporaryObject ( dir_handle );
+    ZwMakeTemporaryObject(dir_handle);
 
-  for ( n = 0, n_created_devices = 0; n < n_devices; n++ )
+    for (n = 0, n_created_devices = 0; n < n_devices; n++)
     {
-      status = HttpDiskCreateDevice ( DriverObject, n, FILE_DEVICE_DISK );
+        status = HttpDiskCreateDevice(DriverObject, n, FILE_DEVICE_DISK);
 
-      if ( NT_SUCCESS ( status ) )
-       {
-         n_created_devices++;
-       }
+        if (NT_SUCCESS(status))
+        {
+            n_created_devices++;
+        }
     }
 
-  for ( n = 0; n < n_devices; n++ )
+    for (n = 0; n < n_devices; n++)
     {
-      status = HttpDiskCreateDevice ( DriverObject, n, FILE_DEVICE_CD_ROM );
+        status = HttpDiskCreateDevice(DriverObject, n, FILE_DEVICE_CD_ROM);
 
-      if ( NT_SUCCESS ( status ) )
-       {
-         n_created_devices++;
-       }
+        if (NT_SUCCESS(status))
+        {
+            n_created_devices++;
+        }
     }
 
-  if ( n_created_devices == 0 )
+    if (n_created_devices == 0)
     {
-      ZwClose ( dir_handle );
-      return status;
+        ZwClose(dir_handle);
+        return status;
     }
 
-  DriverObject->MajorFunction[IRP_MJ_CREATE] = HttpDiskCreateClose;
-  DriverObject->MajorFunction[IRP_MJ_CLOSE] = HttpDiskCreateClose;
-  DriverObject->MajorFunction[IRP_MJ_READ] = HttpDiskReadWrite;
-  DriverObject->MajorFunction[IRP_MJ_WRITE] = HttpDiskReadWrite;
-  DriverObject->MajorFunction[IRP_MJ_DEVICE_CONTROL] = HttpDiskDeviceControl;
+    DriverObject->MajorFunction[IRP_MJ_CREATE]         = HttpDiskCreateClose;
+    DriverObject->MajorFunction[IRP_MJ_CLOSE]          = HttpDiskCreateClose;
+    DriverObject->MajorFunction[IRP_MJ_READ]           = HttpDiskReadWrite;
+    DriverObject->MajorFunction[IRP_MJ_WRITE]          = HttpDiskReadWrite;
+    DriverObject->MajorFunction[IRP_MJ_DEVICE_CONTROL] = HttpDiskDeviceControl;
 
-  DriverObject->DriverUnload = HttpDiskUnload;
+    DriverObject->DriverUnload = HttpDiskUnload;
 
-  return STATUS_SUCCESS;
+    return STATUS_SUCCESS;
 }
 
 NTSTATUS
 HttpDiskCreateDevice (
-  IN PDRIVER_OBJECT DriverObject,
-  IN ULONG Number,
-  IN DEVICE_TYPE DeviceType
- )
+    IN PDRIVER_OBJECT   DriverObject,
+    IN ULONG            Number,
+    IN DEVICE_TYPE      DeviceType
   )
 {
-  WCHAR device_name_buffer[MAXIMUM_FILENAME_LENGTH];
-  UNICODE_STRING device_name;
-  NTSTATUS status;
-  PDEVICE_OBJECT device_object;
-  PDEVICE_EXTENSION device_extension;
-  HANDLE thread_handle;
+    WCHAR               device_name_buffer[MAXIMUM_FILENAME_LENGTH];
+    UNICODE_STRING      device_name;
+    NTSTATUS            status;
+    PDEVICE_OBJECT      device_object;
+    PDEVICE_EXTENSION   device_extension;
+    HANDLE              thread_handle;
 
-  ASSERT ( DriverObject != NULL );
+    ASSERT(DriverObject != NULL);
 
-  if ( DeviceType == FILE_DEVICE_CD_ROM )
+    if (DeviceType == FILE_DEVICE_CD_ROM)
     {
-      swprintf ( device_name_buffer, DEVICE_NAME_PREFIX L"Cd" L"%u", Number );
+        swprintf(
+            device_name_buffer,
+            DEVICE_NAME_PREFIX L"Cd" L"%u",
+            Number
+            );
     }
-  else
+    else
     {
-      swprintf ( device_name_buffer, DEVICE_NAME_PREFIX L"Disk" L"%u",
-                Number );
+        swprintf(
+            device_name_buffer,
+            DEVICE_NAME_PREFIX L"Disk" L"%u",
+            Number
+            );
     }
 
-  RtlInitUnicodeString ( &device_name, device_name_buffer );
+    RtlInitUnicodeString(&device_name, device_name_buffer);
 
-  status =
-    IoCreateDevice ( DriverObject, sizeof ( DEVICE_EXTENSION ), &device_name,
-                    DeviceType, 0, FALSE, &device_object );
+    status = IoCreateDevice(
+        DriverObject,
+        sizeof(DEVICE_EXTENSION),
+        &device_name,
+        DeviceType,
+        0,
+        FALSE,
+        &device_object
+        );
 
-  if ( !NT_SUCCESS ( status ) )
+    if (!NT_SUCCESS(status))
     {
-      return status;
+        return status;
     }
 
-  device_object->Flags |= DO_DIRECT_IO;
+    device_object->Flags |= DO_DIRECT_IO;
 
-  device_extension = ( PDEVICE_EXTENSION ) device_object->DeviceExtension;
+    device_extension = (PDEVICE_EXTENSION) device_object->DeviceExtension;
 
-  device_extension->media_in_device = FALSE;
+    device_extension->media_in_device = FALSE;
 
-  device_extension->host_name = NULL;
+    device_extension->host_name = NULL;
 
-  device_extension->file_name = NULL;
+    device_extension->file_name = NULL;
 
-  device_extension->socket = -1;
+    device_extension->socket = -1;
 
-  device_object->Characteristics |= FILE_READ_ONLY_DEVICE;
+    device_object->Characteristics |= FILE_READ_ONLY_DEVICE;
 
-  InitializeListHead ( &device_extension->list_head );
+    InitializeListHead(&device_extension->list_head);
 
-  KeInitializeSpinLock ( &device_extension->list_lock );
+    KeInitializeSpinLock(&device_extension->list_lock);
 
-  KeInitializeEvent ( &device_extension->request_event, SynchronizationEvent,
-                     FALSE );
+    KeInitializeEvent(
+        &device_extension->request_event,
+        SynchronizationEvent,
+        FALSE
+        );
 
-  device_extension->terminate_thread = FALSE;
+    device_extension->terminate_thread = FALSE;
 
-  status =
-    PsCreateSystemThread ( &thread_handle, ( ACCESS_MASK ) 0L, NULL, NULL,
-                          NULL, HttpDiskThread, device_object );
+    status = PsCreateSystemThread(
+        &thread_handle,
+        (ACCESS_MASK) 0L,
+        NULL,
+        NULL,
+        NULL,
+        HttpDiskThread,
+        device_object
+        );
 
-  if ( !NT_SUCCESS ( status ) )
+    if (!NT_SUCCESS(status))
     {
-      IoDeleteDevice ( device_object );
-      return status;
+        IoDeleteDevice(device_object);
+        return status;
     }
 
-  status =
-    ObReferenceObjectByHandle ( thread_handle, THREAD_ALL_ACCESS, NULL,
-                               KernelMode, &device_extension->thread_pointer,
-                               NULL );
+    status = ObReferenceObjectByHandle(
+        thread_handle,
+        THREAD_ALL_ACCESS,
+        NULL,
+        KernelMode,
+        &device_extension->thread_pointer,
+        NULL
+        );
 
-  if ( !NT_SUCCESS ( status ) )
+    if (!NT_SUCCESS(status))
     {
-      ZwClose ( thread_handle );
+        ZwClose(thread_handle);
 
-      device_extension->terminate_thread = TRUE;
+        device_extension->terminate_thread = TRUE;
 
-      KeSetEvent ( &device_extension->request_event, ( KPRIORITY ) 0, FALSE );
+        KeSetEvent(
+            &device_extension->request_event,
+            (KPRIORITY) 0,
+            FALSE
+            );
 
-      IoDeleteDevice ( device_object );
+        IoDeleteDevice(device_object);
 
-      return status;
+        return status;
     }
 
-  ZwClose ( thread_handle );
+    ZwClose(thread_handle);
 
-  return STATUS_SUCCESS;
+    return STATUS_SUCCESS;
 }
 
 #pragma code_seg("PAGE")
 
 VOID
 HttpDiskUnload (
-  IN PDRIVER_OBJECT DriverObject
- )
+    IN PDRIVER_OBJECT DriverObject
   )
 {
-  PDEVICE_OBJECT device_object;
+    PDEVICE_OBJECT device_object;
 
-  device_object = DriverObject->DeviceObject;
+    device_object = DriverObject->DeviceObject;
 
-  while ( device_object )
+    while (device_object)
     {
-      device_object = HttpDiskDeleteDevice ( device_object );
+        device_object = HttpDiskDeleteDevice(device_object);
     }
 
-  ZwClose ( dir_handle );
+    ZwClose(dir_handle);
 }
 
 PDEVICE_OBJECT
 HttpDiskDeleteDevice (
-  IN PDEVICE_OBJECT DeviceObject
- )
+    IN PDEVICE_OBJECT DeviceObject
   )
 {
-  PDEVICE_EXTENSION device_extension;
-  PDEVICE_OBJECT next_device_object;
+    PDEVICE_EXTENSION   device_extension;
+    PDEVICE_OBJECT      next_device_object;
 
-  ASSERT ( DeviceObject != NULL );
+    ASSERT(DeviceObject != NULL);
 
-  device_extension = ( PDEVICE_EXTENSION ) DeviceObject->DeviceExtension;
+    device_extension = (PDEVICE_EXTENSION) DeviceObject->DeviceExtension;
 
-  device_extension->terminate_thread = TRUE;
+    device_extension->terminate_thread = TRUE;
 
-  KeSetEvent ( &device_extension->request_event, ( KPRIORITY ) 0, FALSE );
+    KeSetEvent(
+        &device_extension->request_event,
+        (KPRIORITY) 0,
+        FALSE
+        );
 
-  KeWaitForSingleObject ( device_extension->thread_pointer, Executive,
-                         KernelMode, FALSE, NULL );
+    KeWaitForSingleObject(
+        device_extension->thread_pointer,
+        Executive,
+        KernelMode,
+        FALSE,
+        NULL
+        );
 
-  ObDereferenceObject ( device_extension->thread_pointer );
+    ObDereferenceObject(device_extension->thread_pointer);
 
-  next_device_object = DeviceObject->NextDevice;
+    next_device_object = DeviceObject->NextDevice;
 
-  IoDeleteDevice ( DeviceObject );
+    IoDeleteDevice(DeviceObject);
 
-  return next_device_object;
+    return next_device_object;
 }
 
 NTSTATUS
 HttpDiskCreateClose (
-  IN PDEVICE_OBJECT DeviceObject,
-  IN PIRP Irp
- )
+    IN PDEVICE_OBJECT   DeviceObject,
+    IN PIRP             Irp
   )
 {
-  Irp->IoStatus.Status = STATUS_SUCCESS;
-  Irp->IoStatus.Information = FILE_OPENED;
+    Irp->IoStatus.Status = STATUS_SUCCESS;
+    Irp->IoStatus.Information = FILE_OPENED;
 
-  IoCompleteRequest ( Irp, IO_NO_INCREMENT );
+    IoCompleteRequest(Irp, IO_NO_INCREMENT);
 
-  return STATUS_SUCCESS;
+    return STATUS_SUCCESS;
 }
 
 #pragma code_seg()
 
 NTSTATUS
 HttpDiskReadWrite (
-  IN PDEVICE_OBJECT DeviceObject,
-  IN PIRP Irp
- )
+    IN PDEVICE_OBJECT   DeviceObject,
+    IN PIRP             Irp
   )
 {
-  PDEVICE_EXTENSION device_extension;
-  PIO_STACK_LOCATION io_stack;
+    PDEVICE_EXTENSION   device_extension;
+    PIO_STACK_LOCATION  io_stack;
 
-  device_extension = ( PDEVICE_EXTENSION ) DeviceObject->DeviceExtension;
+    device_extension = (PDEVICE_EXTENSION) DeviceObject->DeviceExtension;
 
-  if ( !device_extension->media_in_device )
+    if (!device_extension->media_in_device)
     {
-      Irp->IoStatus.Status = STATUS_NO_MEDIA_IN_DEVICE;
-      Irp->IoStatus.Information = 0;
+        Irp->IoStatus.Status = STATUS_NO_MEDIA_IN_DEVICE;
+        Irp->IoStatus.Information = 0;
 
-      IoCompleteRequest ( Irp, IO_NO_INCREMENT );
+        IoCompleteRequest(Irp, IO_NO_INCREMENT);
 
-      return STATUS_NO_MEDIA_IN_DEVICE;
+        return STATUS_NO_MEDIA_IN_DEVICE;
     }
 
-  io_stack = IoGetCurrentIrpStackLocation ( Irp );
+    io_stack = IoGetCurrentIrpStackLocation(Irp);
 
-  if ( io_stack->Parameters.Read.Length == 0 )
+    if (io_stack->Parameters.Read.Length == 0)
     {
-      Irp->IoStatus.Status = STATUS_SUCCESS;
-      Irp->IoStatus.Information = 0;
+        Irp->IoStatus.Status = STATUS_SUCCESS;
+        Irp->IoStatus.Information = 0;
 
-      IoCompleteRequest ( Irp, IO_NO_INCREMENT );
+        IoCompleteRequest(Irp, IO_NO_INCREMENT);
 
-      return STATUS_SUCCESS;
+        return STATUS_SUCCESS;
     }
 
-  IoMarkIrpPending ( Irp );
+    IoMarkIrpPending(Irp);
 
-  ExInterlockedInsertTailList ( &device_extension->list_head,
-                               &Irp->Tail.Overlay.ListEntry,
-                               &device_extension->list_lock );
+    ExInterlockedInsertTailList(
+        &device_extension->list_head,
+        &Irp->Tail.Overlay.ListEntry,
+        &device_extension->list_lock
+        );
 
-  KeSetEvent ( &device_extension->request_event, ( KPRIORITY ) 0, FALSE );
+    KeSetEvent(
+        &device_extension->request_event,
+        (KPRIORITY) 0,
+        FALSE
+        );
 
-  return STATUS_PENDING;
+    return STATUS_PENDING;
 }
 
 NTSTATUS
 HttpDiskDeviceControl (
-  IN PDEVICE_OBJECT DeviceObject,
-  IN PIRP Irp
- )
+    IN PDEVICE_OBJECT   DeviceObject,
+    IN PIRP             Irp
   )
 {
-  PDEVICE_EXTENSION device_extension;
-  PIO_STACK_LOCATION io_stack;
-  NTSTATUS status;
+    PDEVICE_EXTENSION   device_extension;
+    PIO_STACK_LOCATION  io_stack;
+    NTSTATUS            status;
 
-  device_extension = ( PDEVICE_EXTENSION ) DeviceObject->DeviceExtension;
+    device_extension = (PDEVICE_EXTENSION) DeviceObject->DeviceExtension;
 
-  io_stack = IoGetCurrentIrpStackLocation ( Irp );
+    io_stack = IoGetCurrentIrpStackLocation(Irp);
 
-  if ( !device_extension->media_in_device
-       && io_stack->Parameters.DeviceIoControl.IoControlCode !=
-       IOCTL_HTTP_DISK_CONNECT )
+    if (!device_extension->media_in_device &&
+        io_stack->Parameters.DeviceIoControl.IoControlCode !=
+        IOCTL_HTTP_DISK_CONNECT)
     {
-      Irp->IoStatus.Status = STATUS_NO_MEDIA_IN_DEVICE;
-      Irp->IoStatus.Information = 0;
+        Irp->IoStatus.Status = STATUS_NO_MEDIA_IN_DEVICE;
+        Irp->IoStatus.Information = 0;
 
-      IoCompleteRequest ( Irp, IO_NO_INCREMENT );
+        IoCompleteRequest(Irp, IO_NO_INCREMENT);
 
-      return STATUS_NO_MEDIA_IN_DEVICE;
+        return STATUS_NO_MEDIA_IN_DEVICE;
     }
 
-  switch ( io_stack->Parameters.DeviceIoControl.IoControlCode )
+    switch (io_stack->Parameters.DeviceIoControl.IoControlCode)
     {
-      case IOCTL_HTTP_DISK_CONNECT:
-       {
-         if ( device_extension->media_in_device )
-           {
-             DbgPrint
-               ( "HttpDisk: IOCTL_HTTP_DISK_CONNECT: Media already opened.\n" );
-
-             status = STATUS_INVALID_DEVICE_REQUEST;
-             Irp->IoStatus.Information = 0;
-             break;
-           }
-
-         if ( io_stack->Parameters.DeviceIoControl.InputBufferLength <
-              sizeof ( HTTP_DISK_INFORMATION ) )
-           {
-             status = STATUS_INVALID_PARAMETER;
-             Irp->IoStatus.Information = 0;
-             break;
-           }
-
-         if ( io_stack->Parameters.DeviceIoControl.InputBufferLength <
-              sizeof ( HTTP_DISK_INFORMATION ) +
-              ( ( PHTTP_DISK_INFORMATION ) Irp->AssociatedIrp.
-                SystemBuffer )->FileNameLength - sizeof ( UCHAR ) )
-           {
-             status = STATUS_INVALID_PARAMETER;
-             Irp->IoStatus.Information = 0;
-             break;
-           }
-
-         IoMarkIrpPending ( Irp );
-
-         ExInterlockedInsertTailList ( &device_extension->list_head,
-                                       &Irp->Tail.Overlay.ListEntry,
-                                       &device_extension->list_lock );
-
-         KeSetEvent ( &device_extension->request_event, ( KPRIORITY ) 0,
-                      FALSE );
-
-         status = STATUS_PENDING;
-
-         break;
-       }
-
-      case IOCTL_HTTP_DISK_DISCONNECT:
-       {
-         IoMarkIrpPending ( Irp );
-
-         ExInterlockedInsertTailList ( &device_extension->list_head,
-                                       &Irp->Tail.Overlay.ListEntry,
-                                       &device_extension->list_lock );
-
-         KeSetEvent ( &device_extension->request_event, ( KPRIORITY ) 0,
-                      FALSE );
-
-         status = STATUS_PENDING;
-
-         break;
-       }
-
-      case IOCTL_DISK_CHECK_VERIFY:
-      case IOCTL_CDROM_CHECK_VERIFY:
-      case IOCTL_STORAGE_CHECK_VERIFY:
-      case IOCTL_STORAGE_CHECK_VERIFY2:
-       {
-         status = STATUS_SUCCESS;
-         Irp->IoStatus.Information = 0;
-         break;
-       }
-
-      case IOCTL_DISK_GET_DRIVE_GEOMETRY:
-      case IOCTL_CDROM_GET_DRIVE_GEOMETRY:
-       {
-         PDISK_GEOMETRY disk_geometry;
-         ULONGLONG length;
-
-         if ( io_stack->Parameters.DeviceIoControl.OutputBufferLength <
-              sizeof ( DISK_GEOMETRY ) )
-           {
-             status = STATUS_BUFFER_TOO_SMALL;
-             Irp->IoStatus.Information = 0;
-             break;
-           }
-
-         disk_geometry = ( PDISK_GEOMETRY ) Irp->AssociatedIrp.SystemBuffer;
-
-         length = device_extension->file_size.QuadPart;
-
-         disk_geometry->Cylinders.QuadPart = length / SECTOR_SIZE / 32 / 2;
-         disk_geometry->MediaType = FixedMedia;
-         disk_geometry->TracksPerCylinder = 2;
-         disk_geometry->SectorsPerTrack = 32;
-         disk_geometry->BytesPerSector = SECTOR_SIZE;
-
-         status = STATUS_SUCCESS;
-         Irp->IoStatus.Information = sizeof ( DISK_GEOMETRY );
-
-         break;
-       }
-
-      case IOCTL_DISK_GET_LENGTH_INFO:
-       {
-         PGET_LENGTH_INFORMATION get_length_information;
-
-         if ( io_stack->Parameters.DeviceIoControl.OutputBufferLength <
-              sizeof ( GET_LENGTH_INFORMATION ) )
-           {
-             status = STATUS_BUFFER_TOO_SMALL;
-             Irp->IoStatus.Information = 0;
-             break;
-           }
-
-         get_length_information =
-           ( PGET_LENGTH_INFORMATION ) Irp->AssociatedIrp.SystemBuffer;
-
-         get_length_information->Length.QuadPart =
-           device_extension->file_size.QuadPart;
-
-         status = STATUS_SUCCESS;
-         Irp->IoStatus.Information = sizeof ( GET_LENGTH_INFORMATION );
-
-         break;
-       }
-
-      case IOCTL_DISK_GET_PARTITION_INFO:
-       {
-         PPARTITION_INFORMATION partition_information;
-         ULONGLONG length;
-
-         if ( io_stack->Parameters.DeviceIoControl.OutputBufferLength <
-              sizeof ( PARTITION_INFORMATION ) )
-           {
-             status = STATUS_BUFFER_TOO_SMALL;
-             Irp->IoStatus.Information = 0;
-             break;
-           }
-
-         partition_information =
-           ( PPARTITION_INFORMATION ) Irp->AssociatedIrp.SystemBuffer;
-
-         length = device_extension->file_size.QuadPart;
-
-         partition_information->StartingOffset.QuadPart = 0;
-         partition_information->PartitionLength.QuadPart = length;
-         partition_information->HiddenSectors = 1;
-         partition_information->PartitionNumber = 0;
-         partition_information->PartitionType = 0;
-         partition_information->BootIndicator = FALSE;
-         partition_information->RecognizedPartition = FALSE;
-         partition_information->RewritePartition = FALSE;
-
-         status = STATUS_SUCCESS;
-         Irp->IoStatus.Information = sizeof ( PARTITION_INFORMATION );
-
-         break;
-       }
-
-      case IOCTL_DISK_GET_PARTITION_INFO_EX:
-       {
-         PPARTITION_INFORMATION_EX partition_information_ex;
-         ULONGLONG length;
-
-         if ( io_stack->Parameters.DeviceIoControl.OutputBufferLength <
-              sizeof ( PARTITION_INFORMATION_EX ) )
-           {
-             status = STATUS_BUFFER_TOO_SMALL;
-             Irp->IoStatus.Information = 0;
-             break;
-           }
-
-         partition_information_ex =
-           ( PPARTITION_INFORMATION_EX ) Irp->AssociatedIrp.SystemBuffer;
-
-         length = device_extension->file_size.QuadPart;
-
-         partition_information_ex->PartitionStyle = PARTITION_STYLE_MBR;
-         partition_information_ex->StartingOffset.QuadPart = 0;
-         partition_information_ex->PartitionLength.QuadPart = length;
-         partition_information_ex->PartitionNumber = 0;
-         partition_information_ex->RewritePartition = FALSE;
-         partition_information_ex->Mbr.PartitionType = 0;
-         partition_information_ex->Mbr.BootIndicator = FALSE;
-         partition_information_ex->Mbr.RecognizedPartition = FALSE;
-         partition_information_ex->Mbr.HiddenSectors = 1;
-
-         status = STATUS_SUCCESS;
-         Irp->IoStatus.Information = sizeof ( PARTITION_INFORMATION_EX );
-
-         break;
-       }
-
-      case IOCTL_DISK_IS_WRITABLE:
-       {
-         status = STATUS_MEDIA_WRITE_PROTECTED;
-         Irp->IoStatus.Information = 0;
-         break;
-       }
-
-      case IOCTL_DISK_MEDIA_REMOVAL:
-      case IOCTL_STORAGE_MEDIA_REMOVAL:
-       {
-         status = STATUS_SUCCESS;
-         Irp->IoStatus.Information = 0;
-         break;
-       }
-
-      case IOCTL_CDROM_READ_TOC:
-       {
-         PCDROM_TOC cdrom_toc;
-
-         if ( io_stack->Parameters.DeviceIoControl.OutputBufferLength <
-              sizeof ( CDROM_TOC ) )
-           {
-             status = STATUS_BUFFER_TOO_SMALL;
-             Irp->IoStatus.Information = 0;
-             break;
-           }
-
-         cdrom_toc = ( PCDROM_TOC ) Irp->AssociatedIrp.SystemBuffer;
-
-         RtlZeroMemory ( cdrom_toc, sizeof ( CDROM_TOC ) );
-
-         cdrom_toc->FirstTrack = 1;
-         cdrom_toc->LastTrack = 1;
-         cdrom_toc->TrackData[0].Control = TOC_DATA_TRACK;
-
-         status = STATUS_SUCCESS;
-         Irp->IoStatus.Information = sizeof ( CDROM_TOC );
-
-         break;
-       }
-
-      case IOCTL_DISK_SET_PARTITION_INFO:
-       {
-         status = STATUS_MEDIA_WRITE_PROTECTED;
-         Irp->IoStatus.Information = 0;
-         break;
-       }
-
-      case IOCTL_DISK_VERIFY:
-       {
-         PVERIFY_INFORMATION verify_information;
-
-         if ( io_stack->Parameters.DeviceIoControl.InputBufferLength <
-              sizeof ( VERIFY_INFORMATION ) )
-           {
-             status = STATUS_INVALID_PARAMETER;
-             Irp->IoStatus.Information = 0;
-             break;
-           }
-
-         verify_information =
-           ( PVERIFY_INFORMATION ) Irp->AssociatedIrp.SystemBuffer;
-
-         status = STATUS_SUCCESS;
-         Irp->IoStatus.Information = verify_information->Length;
-
-         break;
-       }
-
-      default:
-       {
-         KdPrint ( ( "HttpDisk: Unknown IoControlCode: %#x\n",
-                     io_stack->Parameters.DeviceIoControl.IoControlCode ) );
-
-         status = STATUS_INVALID_DEVICE_REQUEST;
-         Irp->IoStatus.Information = 0;
-       }
+    case IOCTL_HTTP_DISK_CONNECT:
+        {
+            if (device_extension->media_in_device)
+            {
+                DbgPrint("HttpDisk: IOCTL_HTTP_DISK_CONNECT: Media already opened.\n");
+
+                status = STATUS_INVALID_DEVICE_REQUEST;
+                Irp->IoStatus.Information = 0;
+                break;
+            }
+
+            if (io_stack->Parameters.DeviceIoControl.InputBufferLength <
+                sizeof(HTTP_DISK_INFORMATION))
+            {
+                status = STATUS_INVALID_PARAMETER;
+                Irp->IoStatus.Information = 0;
+                break;
+            }
+
+            if (io_stack->Parameters.DeviceIoControl.InputBufferLength <
+                sizeof(HTTP_DISK_INFORMATION) +
+                ((PHTTP_DISK_INFORMATION)Irp->AssociatedIrp.SystemBuffer)->FileNameLength -
+                sizeof(UCHAR))
+            {
+                status = STATUS_INVALID_PARAMETER;
+                Irp->IoStatus.Information = 0;
+                break;
+            }
+
+            IoMarkIrpPending(Irp);
+
+            ExInterlockedInsertTailList(
+                &device_extension->list_head,
+                &Irp->Tail.Overlay.ListEntry,
+                &device_extension->list_lock
+                );
+
+            KeSetEvent(
+                &device_extension->request_event,
+                (KPRIORITY) 0,
+                FALSE
+                );
+
+            status = STATUS_PENDING;
+
+            break;
+        }
+
+    case IOCTL_HTTP_DISK_DISCONNECT:
+        {
+            IoMarkIrpPending(Irp);
+
+            ExInterlockedInsertTailList(
+                &device_extension->list_head,
+                &Irp->Tail.Overlay.ListEntry,
+                &device_extension->list_lock
+                );
+
+            KeSetEvent(
+                &device_extension->request_event,
+                (KPRIORITY) 0,
+                FALSE
+                );
+
+            status = STATUS_PENDING;
+
+            break;
+        }
+
+    case IOCTL_DISK_CHECK_VERIFY:
+    case IOCTL_CDROM_CHECK_VERIFY:
+    case IOCTL_STORAGE_CHECK_VERIFY:
+    case IOCTL_STORAGE_CHECK_VERIFY2:
+        {
+            status = STATUS_SUCCESS;
+            Irp->IoStatus.Information = 0;
+            break;
+        }
+
+    case IOCTL_DISK_GET_DRIVE_GEOMETRY:
+    case IOCTL_CDROM_GET_DRIVE_GEOMETRY:
+        {
+            PDISK_GEOMETRY  disk_geometry;
+            ULONGLONG       length;
+
+            if (io_stack->Parameters.DeviceIoControl.OutputBufferLength <
+                sizeof(DISK_GEOMETRY))
+            {
+                status = STATUS_BUFFER_TOO_SMALL;
+                Irp->IoStatus.Information = 0;
+                break;
+            }
+
+            disk_geometry = (PDISK_GEOMETRY) Irp->AssociatedIrp.SystemBuffer;
+
+            length = device_extension->file_size.QuadPart;
+
+            disk_geometry->Cylinders.QuadPart = length / SECTOR_SIZE / 32 / 2;
+            disk_geometry->MediaType = FixedMedia;
+            disk_geometry->TracksPerCylinder = 2;
+            disk_geometry->SectorsPerTrack = 32;
+            disk_geometry->BytesPerSector = SECTOR_SIZE;
+
+            status = STATUS_SUCCESS;
+            Irp->IoStatus.Information = sizeof(DISK_GEOMETRY);
+
+            break;
+        }
+
+    case IOCTL_DISK_GET_LENGTH_INFO:
+        {
+            PGET_LENGTH_INFORMATION get_length_information;
+
+            if (io_stack->Parameters.DeviceIoControl.OutputBufferLength <
+                sizeof(GET_LENGTH_INFORMATION))
+            {
+                status = STATUS_BUFFER_TOO_SMALL;
+                Irp->IoStatus.Information = 0;
+                break;
+            }
+
+            get_length_information = (PGET_LENGTH_INFORMATION) Irp->AssociatedIrp.SystemBuffer;
+
+            get_length_information->Length.QuadPart = device_extension->file_size.QuadPart;
+
+            status = STATUS_SUCCESS;
+            Irp->IoStatus.Information = sizeof(GET_LENGTH_INFORMATION);
+
+        break;
+        }
+
+    case IOCTL_DISK_GET_PARTITION_INFO:
+        {
+            PPARTITION_INFORMATION  partition_information;
+            ULONGLONG               length;
+
+            if (io_stack->Parameters.DeviceIoControl.OutputBufferLength <
+                sizeof(PARTITION_INFORMATION))
+            {
+                status = STATUS_BUFFER_TOO_SMALL;
+                Irp->IoStatus.Information = 0;
+                break;
+            }
+
+            partition_information = (PPARTITION_INFORMATION) Irp->AssociatedIrp.SystemBuffer;
+
+            length = device_extension->file_size.QuadPart;
+
+            partition_information->StartingOffset.QuadPart = 0;
+            partition_information->PartitionLength.QuadPart = length;
+            partition_information->HiddenSectors = 1;
+            partition_information->PartitionNumber = 0;
+            partition_information->PartitionType = 0;
+            partition_information->BootIndicator = FALSE;
+            partition_information->RecognizedPartition = FALSE;
+            partition_information->RewritePartition = FALSE;
+
+            status = STATUS_SUCCESS;
+            Irp->IoStatus.Information = sizeof(PARTITION_INFORMATION);
+
+            break;
+        }
+
+    case IOCTL_DISK_GET_PARTITION_INFO_EX:
+        {
+            PPARTITION_INFORMATION_EX   partition_information_ex;
+            ULONGLONG                   length;
+
+            if (io_stack->Parameters.DeviceIoControl.OutputBufferLength <
+                sizeof(PARTITION_INFORMATION_EX))
+            {
+                status = STATUS_BUFFER_TOO_SMALL;
+                Irp->IoStatus.Information = 0;
+                break;
+            }
+
+            partition_information_ex = (PPARTITION_INFORMATION_EX) Irp->AssociatedIrp.SystemBuffer;
+
+            length = device_extension->file_size.QuadPart;
+
+            partition_information_ex->PartitionStyle = PARTITION_STYLE_MBR;
+            partition_information_ex->StartingOffset.QuadPart = 0;
+            partition_information_ex->PartitionLength.QuadPart = length;
+            partition_information_ex->PartitionNumber = 0;
+            partition_information_ex->RewritePartition = FALSE;
+            partition_information_ex->Mbr.PartitionType = 0;
+            partition_information_ex->Mbr.BootIndicator = FALSE;
+            partition_information_ex->Mbr.RecognizedPartition = FALSE;
+            partition_information_ex->Mbr.HiddenSectors = 1;
+
+            status = STATUS_SUCCESS;
+            Irp->IoStatus.Information = sizeof(PARTITION_INFORMATION_EX);
+
+            break;
+        }
+
+    case IOCTL_DISK_IS_WRITABLE:
+        {
+            status = STATUS_MEDIA_WRITE_PROTECTED;
+            Irp->IoStatus.Information = 0;
+            break;
+        }
+
+    case IOCTL_DISK_MEDIA_REMOVAL:
+    case IOCTL_STORAGE_MEDIA_REMOVAL:
+        {
+            status = STATUS_SUCCESS;
+            Irp->IoStatus.Information = 0;
+            break;
+        }
+
+    case IOCTL_CDROM_READ_TOC:
+        {
+            PCDROM_TOC cdrom_toc;
+
+            if (io_stack->Parameters.DeviceIoControl.OutputBufferLength <
+                sizeof(CDROM_TOC))
+            {
+                status = STATUS_BUFFER_TOO_SMALL;
+                Irp->IoStatus.Information = 0;
+                break;
+            }
+
+            cdrom_toc = (PCDROM_TOC) Irp->AssociatedIrp.SystemBuffer;
+
+            RtlZeroMemory(cdrom_toc, sizeof(CDROM_TOC));
+
+            cdrom_toc->FirstTrack = 1;
+            cdrom_toc->LastTrack = 1;
+            cdrom_toc->TrackData[0].Control = TOC_DATA_TRACK;
+
+            status = STATUS_SUCCESS;
+            Irp->IoStatus.Information = sizeof(CDROM_TOC);
+
+            break;
+        }
+
+    case IOCTL_DISK_SET_PARTITION_INFO:
+        {
+            status = STATUS_MEDIA_WRITE_PROTECTED;
+            Irp->IoStatus.Information = 0;
+            break;
+        }
+
+    case IOCTL_DISK_VERIFY:
+        {
+            PVERIFY_INFORMATION verify_information;
+
+            if (io_stack->Parameters.DeviceIoControl.InputBufferLength <
+                sizeof(VERIFY_INFORMATION))
+            {
+                status = STATUS_INVALID_PARAMETER;
+                Irp->IoStatus.Information = 0;
+                break;
+            }
+
+            verify_information = (PVERIFY_INFORMATION) Irp->AssociatedIrp.SystemBuffer;
+
+            status = STATUS_SUCCESS;
+            Irp->IoStatus.Information = verify_information->Length;
+
+            break;
+        }
+
+    default:
+        {
+            KdPrint((
+                "HttpDisk: Unknown IoControlCode: %#x\n",
+                io_stack->Parameters.DeviceIoControl.IoControlCode
+                ));
+
+            status = STATUS_INVALID_DEVICE_REQUEST;
+            Irp->IoStatus.Information = 0;
+        }
     }
 
-  if ( status != STATUS_PENDING )
+    if (status != STATUS_PENDING)
     {
-      Irp->IoStatus.Status = status;
+        Irp->IoStatus.Status = status;
 
-      IoCompleteRequest ( Irp, IO_NO_INCREMENT );
+        IoCompleteRequest(Irp, IO_NO_INCREMENT);
     }
 
-  return status;
+    return status;
 }
 
 #pragma code_seg("PAGE")
 
 VOID
 HttpDiskThread (
-  IN PVOID Context
- )
+    IN PVOID Context
   )
 {
-  PDEVICE_OBJECT device_object;
-  PDEVICE_EXTENSION device_extension;
-  PLIST_ENTRY request;
-  PIRP irp;
-  PIO_STACK_LOCATION io_stack;
+    PDEVICE_OBJECT      device_object;
+    PDEVICE_EXTENSION   device_extension;
+    PLIST_ENTRY         request;
+    PIRP                irp;
+    PIO_STACK_LOCATION  io_stack;
 
-  ASSERT ( Context != NULL );
+    ASSERT(Context != NULL);
 
-  device_object = ( PDEVICE_OBJECT ) Context;
+    device_object = (PDEVICE_OBJECT) Context;
 
-  device_extension = ( PDEVICE_EXTENSION ) device_object->DeviceExtension;
+    device_extension = (PDEVICE_EXTENSION) device_object->DeviceExtension;
 
-  KeSetPriorityThread ( KeGetCurrentThread (  ), LOW_REALTIME_PRIORITY );
+    KeSetPriorityThread(KeGetCurrentThread(), LOW_REALTIME_PRIORITY);
 
-  for ( ;; )
+    for (;;)
     {
-      KeWaitForSingleObject ( &device_extension->request_event, Executive,
-                             KernelMode, FALSE, NULL );
-
-      if ( device_extension->terminate_thread )
-       {
-         PsTerminateSystemThread ( STATUS_SUCCESS );
-       }
-
-      while ( request =
-             ExInterlockedRemoveHeadList ( &device_extension->list_head,
-                                           &device_extension->list_lock ) )
-       {
-         irp = CONTAINING_RECORD ( request, IRP, Tail.Overlay.ListEntry );
-
-         io_stack = IoGetCurrentIrpStackLocation ( irp );
-
-         switch ( io_stack->MajorFunction )
-           {
-             case IRP_MJ_READ:
-               HttpDiskGetBlock ( &device_extension->socket,
-                                  device_extension->address,
-                                  device_extension->port,
-                                  device_extension->host_name,
-                                  device_extension->file_name,
-                                  &io_stack->Parameters.Read.ByteOffset,
-                                  io_stack->Parameters.Read.Length,
-                                  &irp->IoStatus,
-                                  MmGetSystemAddressForMdlSafe
-                                  ( irp->MdlAddress, NormalPagePriority ) );
-               if ( !NT_SUCCESS ( irp->IoStatus.Status ) )
-                 {
-                   HttpDiskGetBlock ( &device_extension->socket,
-                                      device_extension->address,
-                                      device_extension->port,
-                                      device_extension->host_name,
-                                      device_extension->file_name,
-                                      &io_stack->Parameters.Read.ByteOffset,
-                                      io_stack->Parameters.Read.Length,
-                                      &irp->IoStatus,
-                                      MmGetSystemAddressForMdlSafe
-                                      ( irp->MdlAddress,
-                                        NormalPagePriority ) );
-                 }
-               break;
-
-             case IRP_MJ_WRITE:
-               irp->IoStatus.Status = STATUS_MEDIA_WRITE_PROTECTED;
-               irp->IoStatus.Information = 0;
-               break;
-
-             case IRP_MJ_DEVICE_CONTROL:
-               switch ( io_stack->Parameters.DeviceIoControl.IoControlCode )
-                 {
-                   case IOCTL_HTTP_DISK_CONNECT:
-                     irp->IoStatus.Status =
-                       HttpDiskConnect ( device_object, irp );
-                     break;
-
-                   case IOCTL_HTTP_DISK_DISCONNECT:
-                     irp->IoStatus.Status =
-                       HttpDiskDisconnect ( device_object, irp );
-                     break;
-
-                   default:
-                     irp->IoStatus.Status = STATUS_DRIVER_INTERNAL_ERROR;
-                 }
-               break;
-
-             default:
-               irp->IoStatus.Status = STATUS_DRIVER_INTERNAL_ERROR;
-           }
-
-         IoCompleteRequest ( irp,
-                             ( CCHAR ) ( NT_SUCCESS ( irp->IoStatus.Status ) ?
-                                         IO_DISK_INCREMENT :
-                                         IO_NO_INCREMENT ) );
-       }
+        KeWaitForSingleObject(
+            &device_extension->request_event,
+            Executive,
+            KernelMode,
+            FALSE,
+            NULL
+            );
+
+        if (device_extension->terminate_thread)
+        {
+            PsTerminateSystemThread(STATUS_SUCCESS);
+        }
+
+        while (request = ExInterlockedRemoveHeadList(
+            &device_extension->list_head,
+            &device_extension->list_lock
+            ))
+        {
+            irp = CONTAINING_RECORD(request, IRP, Tail.Overlay.ListEntry);
+
+            io_stack = IoGetCurrentIrpStackLocation(irp);
+
+            switch (io_stack->MajorFunction)
+            {
+            case IRP_MJ_READ:
+                HttpDiskGetBlock(
+                    &device_extension->socket,
+                    device_extension->address,
+                    device_extension->port,
+                    device_extension->host_name,
+                    device_extension->file_name,
+                    &io_stack->Parameters.Read.ByteOffset,
+                    io_stack->Parameters.Read.Length,
+                    &irp->IoStatus,
+                    MmGetSystemAddressForMdlSafe(irp->MdlAddress, NormalPagePriority)
+                    );
+                if (!NT_SUCCESS(irp->IoStatus.Status))
+                {
+                    HttpDiskGetBlock(
+                        &device_extension->socket,
+                        device_extension->address,
+                        device_extension->port,
+                        device_extension->host_name,
+                        device_extension->file_name,
+                        &io_stack->Parameters.Read.ByteOffset,
+                        io_stack->Parameters.Read.Length,
+                        &irp->IoStatus,
+                        MmGetSystemAddressForMdlSafe(irp->MdlAddress, NormalPagePriority)
+                        );
+                }
+                break;
+
+            case IRP_MJ_WRITE:
+                irp->IoStatus.Status = STATUS_MEDIA_WRITE_PROTECTED;
+                irp->IoStatus.Information = 0;
+                break;
+
+            case IRP_MJ_DEVICE_CONTROL:
+                switch (io_stack->Parameters.DeviceIoControl.IoControlCode)
+                {
+                case IOCTL_HTTP_DISK_CONNECT:
+                    irp->IoStatus.Status = HttpDiskConnect(device_object, irp);
+                    break;
+
+                case IOCTL_HTTP_DISK_DISCONNECT:
+                    irp->IoStatus.Status = HttpDiskDisconnect(device_object, irp);
+                    break;
+
+                default:
+                    irp->IoStatus.Status = STATUS_DRIVER_INTERNAL_ERROR;
+                }
+                break;
+
+            default:
+                irp->IoStatus.Status = STATUS_DRIVER_INTERNAL_ERROR;
+            }
+
+            IoCompleteRequest(
+                irp,
+                (CCHAR) (NT_SUCCESS(irp->IoStatus.Status) ?
+                IO_DISK_INCREMENT : IO_NO_INCREMENT)
+                );
+        }
     }
 }
 
 NTSTATUS
 HttpDiskConnect (
-  IN PDEVICE_OBJECT DeviceObject,
-  IN PIRP Irp
- )
+    IN PDEVICE_OBJECT   DeviceObject,
+    IN PIRP             Irp
   )
 {
-  PDEVICE_EXTENSION device_extension;
-  PHTTP_DISK_INFORMATION http_disk_information;
-  HTTP_HEADER http_header;
+    PDEVICE_EXTENSION       device_extension;
+    PHTTP_DISK_INFORMATION  http_disk_information;
+    HTTP_HEADER             http_header;
 
-  ASSERT ( DeviceObject != NULL );
-  ASSERT ( Irp != NULL );
+    ASSERT(DeviceObject != NULL);
+    ASSERT(Irp != NULL);
 
-  device_extension = ( PDEVICE_EXTENSION ) DeviceObject->DeviceExtension;
+    device_extension = (PDEVICE_EXTENSION) DeviceObject->DeviceExtension;
 
-  http_disk_information =
-    ( PHTTP_DISK_INFORMATION ) Irp->AssociatedIrp.SystemBuffer;
+    http_disk_information = (PHTTP_DISK_INFORMATION) Irp->AssociatedIrp.SystemBuffer;
 
-  device_extension->address = http_disk_information->Address;
+    device_extension->address = http_disk_information->Address;
 
-  device_extension->port = http_disk_information->Port;
+    device_extension->port = http_disk_information->Port;
 
-  device_extension->host_name =
-    ExAllocatePool ( NonPagedPool, http_disk_information->HostNameLength + 1 );
+    device_extension->host_name = ExAllocatePool(NonPagedPool, http_disk_information->HostNameLength + 1);
 
-  if ( device_extension->host_name == NULL )
+    if (device_extension->host_name == NULL)
     {
-      Irp->IoStatus.Status = STATUS_INSUFFICIENT_RESOURCES;
-      return Irp->IoStatus.Status;
+        Irp->IoStatus.Status = STATUS_INSUFFICIENT_RESOURCES;
+        return Irp->IoStatus.Status;
     }
 
-  RtlCopyMemory ( device_extension->host_name, http_disk_information->HostName,
-                 http_disk_information->HostNameLength );
+    RtlCopyMemory(
+        device_extension->host_name,
+        http_disk_information->HostName,
+        http_disk_information->HostNameLength
+        );
 
-  device_extension->host_name[http_disk_information->HostNameLength] = '\0';
+    device_extension->host_name[http_disk_information->HostNameLength] = '\0';
 
-  device_extension->file_name =
-    ExAllocatePool ( NonPagedPool, http_disk_information->FileNameLength + 1 );
+    device_extension->file_name = ExAllocatePool(NonPagedPool, http_disk_information->FileNameLength + 1);
 
-  if ( device_extension->file_name == NULL )
+    if (device_extension->file_name == NULL)
     {
-      if ( device_extension->host_name != NULL )
-       {
-         ExFreePool ( device_extension->host_name );
-         device_extension->host_name = NULL;
-       }
-
-      Irp->IoStatus.Status = STATUS_INSUFFICIENT_RESOURCES;
-      return Irp->IoStatus.Status;
+        if (device_extension->host_name != NULL)
+        {
+            ExFreePool(device_extension->host_name);
+            device_extension->host_name = NULL;
+        }
+
+        Irp->IoStatus.Status = STATUS_INSUFFICIENT_RESOURCES;
+        return Irp->IoStatus.Status;
     }
 
-  RtlCopyMemory ( device_extension->file_name, http_disk_information->FileName,
-                 http_disk_information->FileNameLength );
+    RtlCopyMemory(
+        device_extension->file_name,
+        http_disk_information->FileName,
+        http_disk_information->FileNameLength
+        );
 
-  device_extension->file_name[http_disk_information->FileNameLength] = '\0';
+    device_extension->file_name[http_disk_information->FileNameLength] = '\0';
 
-  HttpDiskGetHeader ( device_extension->address, device_extension->port,
-                     device_extension->host_name, device_extension->file_name,
-                     &Irp->IoStatus, &http_header );
+    HttpDiskGetHeader(
+        device_extension->address,
+        device_extension->port,
+        device_extension->host_name,
+        device_extension->file_name,
+        &Irp->IoStatus,
+        &http_header
+        );
 
-  if ( !NT_SUCCESS ( Irp->IoStatus.Status ) )
+    if (!NT_SUCCESS(Irp->IoStatus.Status))
     {
-      HttpDiskGetHeader ( device_extension->address, device_extension->port,
-                         device_extension->host_name,
-                         device_extension->file_name, &Irp->IoStatus,
-                         &http_header );
+        HttpDiskGetHeader(
+            device_extension->address,
+            device_extension->port,
+            device_extension->host_name,
+            device_extension->file_name,
+            &Irp->IoStatus,
+            &http_header
+            );
     }
 
-  if ( !NT_SUCCESS ( Irp->IoStatus.Status ) )
+    if (!NT_SUCCESS(Irp->IoStatus.Status))
     {
-      if ( device_extension->host_name != NULL )
-       {
-         ExFreePool ( device_extension->host_name );
-         device_extension->host_name = NULL;
-       }
-
-      if ( device_extension->file_name != NULL )
-       {
-         ExFreePool ( device_extension->file_name );
-         device_extension->file_name = NULL;
-       }
-
-      return Irp->IoStatus.Status;
+        if (device_extension->host_name != NULL)
+        {
+            ExFreePool(device_extension->host_name);
+            device_extension->host_name = NULL;
+        }
+
+        if (device_extension->file_name != NULL)
+        {
+            ExFreePool(device_extension->file_name);
+            device_extension->file_name = NULL;
+        }
+
+        return Irp->IoStatus.Status;
     }
 
-  device_extension->file_size.QuadPart = http_header.ContentLength.QuadPart;
+    device_extension->file_size.QuadPart = http_header.ContentLength.QuadPart;
 
-  device_extension->media_in_device = TRUE;
+    device_extension->media_in_device = TRUE;
 
-  return Irp->IoStatus.Status;
+    return Irp->IoStatus.Status;
 }
 
 NTSTATUS
 HttpDiskDisconnect (
-  IN PDEVICE_OBJECT DeviceObject,
-  IN PIRP Irp
- )
+    IN PDEVICE_OBJECT   DeviceObject,
+    IN PIRP             Irp
   )
 {
-  PDEVICE_EXTENSION device_extension;
+    PDEVICE_EXTENSION device_extension;
 
-  ASSERT ( DeviceObject != NULL );
-  ASSERT ( Irp != NULL );
+    ASSERT(DeviceObject != NULL);
+    ASSERT(Irp != NULL);
 
-  device_extension = ( PDEVICE_EXTENSION ) DeviceObject->DeviceExtension;
+    device_extension = (PDEVICE_EXTENSION) DeviceObject->DeviceExtension;
 
-  device_extension->media_in_device = FALSE;
+    device_extension->media_in_device = FALSE;
 
-  if ( device_extension->host_name != NULL )
+    if (device_extension->host_name != NULL)
     {
-      ExFreePool ( device_extension->host_name );
-      device_extension->host_name = NULL;
+        ExFreePool(device_extension->host_name);
+        device_extension->host_name = NULL;
     }
 
-  if ( device_extension->file_name != NULL )
+    if (device_extension->file_name != NULL)
     {
-      ExFreePool ( device_extension->file_name );
-      device_extension->file_name = NULL;
+        ExFreePool(device_extension->file_name);
+        device_extension->file_name = NULL;
     }
 
-  if ( device_extension->socket > 0 )
+    if (device_extension->socket > 0)
     {
-      close ( device_extension->socket );
-      device_extension->socket = -1;
+        close(device_extension->socket);
+        device_extension->socket = -1;
     }
 
-  Irp->IoStatus.Status = STATUS_SUCCESS;
-  Irp->IoStatus.Information = 0;
+    Irp->IoStatus.Status = STATUS_SUCCESS;
+    Irp->IoStatus.Information = 0;
 
-  return STATUS_SUCCESS;
+    return STATUS_SUCCESS;
 }
 
 NTSTATUS
 HttpDiskGetHeader (
-  IN ULONG Address,
-  IN USHORT Port,
-  IN PUCHAR HostName,
-  IN PUCHAR FileName,
-  OUT PIO_STATUS_BLOCK IoStatus,
-  OUT PHTTP_HEADER HttpHeader
- )
+    IN ULONG                Address,
+    IN USHORT               Port,
+    IN PUCHAR               HostName,
+    IN PUCHAR               FileName,
+    OUT PIO_STATUS_BLOCK    IoStatus,
+    OUT PHTTP_HEADER        HttpHeader
   )
 {
-  int kSocket;
-  struct sockaddr_in toAddr;
-  int status,
-   nSent,
-   nRecv;
-  char *buffer,
-  *pStr;
-
-  ASSERT ( HostName != NULL );
-  ASSERT ( FileName != NULL );
-  ASSERT ( IoStatus != NULL );
-  ASSERT ( HttpHeader != NULL );
-
-  buffer = ExAllocatePool ( PagedPool, BUFFER_SIZE );
-
-  if ( buffer == NULL )
+    int                 kSocket;
+    struct sockaddr_in  toAddr;
+    int                 status, nSent, nRecv;
+    char                *buffer, *pStr;
+
+    ASSERT(HostName != NULL);
+    ASSERT(FileName != NULL);
+    ASSERT(IoStatus != NULL);
+    ASSERT(HttpHeader != NULL);
+
+    buffer = ExAllocatePool(PagedPool, BUFFER_SIZE);
+
+    if (buffer == NULL)
     {
-      IoStatus->Status = STATUS_INSUFFICIENT_RESOURCES;
-      return IoStatus->Status;
+        IoStatus->Status = STATUS_INSUFFICIENT_RESOURCES;
+        return IoStatus->Status;
     }
 
-  kSocket = socket ( AF_INET, SOCK_STREAM, 0 );
+    kSocket = socket(AF_INET, SOCK_STREAM, 0);
 
-  if ( kSocket < 0 )
+    if (kSocket < 0)
     {
-      DbgPrint ( "HttpDisk: socket() error: %#x\n", kSocket );
-      ExFreePool ( buffer );
-      IoStatus->Status = kSocket;
-      return IoStatus->Status;
+        DbgPrint("HttpDisk: socket() error: %#x\n", kSocket);
+        ExFreePool(buffer);
+        IoStatus->Status = kSocket;
+        return IoStatus->Status;
     }
 
-  toAddr.sin_family = AF_INET;
-  toAddr.sin_port = Port;
-  toAddr.sin_addr.s_addr = Address;
+    toAddr.sin_family = AF_INET;
+    toAddr.sin_port = Port;
+    toAddr.sin_addr.s_addr = Address;
 
-  status =
-    connect ( kSocket, ( struct sockaddr * )&toAddr, sizeof ( toAddr ) );
+    status = connect(kSocket, (struct sockaddr*) &toAddr, sizeof(toAddr));
 
-  if ( status < 0 )
+    if (status < 0)
     {
-      DbgPrint ( "HttpDisk: connect() error: %#x\n", status );
-      ExFreePool ( buffer );
-      close ( kSocket );
-      IoStatus->Status = status;
-      return IoStatus->Status;
+        DbgPrint("HttpDisk: connect() error: %#x\n", status);
+        ExFreePool(buffer);
+        close(kSocket);
+        IoStatus->Status = status;
+        return IoStatus->Status;
     }
 
-  // Example request:
-  //  HEAD 'FileName' HTTP/1.1
-  //  Host: 'HostName'
-  //  Accept: */*
-  //  User-Agent: HttpDisk/1.2
-  //  Connection: close
-  //
-  // Interesting lines in answer:
-  //  HTTP/1.1 200 OK
-  //  Accept-Ranges: bytes
-  //  Content-Length: 'total file size'
-
-  _snprintf ( buffer, BUFFER_SIZE,
-             "HEAD %s HTTP/1.1\r\nHost: %s\r\nAccept: */*\r\nUser-Agent: HttpDisk/1.2\r\nConnection: close\r\n\r\n",
-             FileName, HostName );
-
-  nSent = send ( kSocket, buffer, strlen ( buffer ), 0 );
-
-  if ( nSent < 0 )
+    // Example request:
+    //  HEAD 'FileName' HTTP/1.1
+    //  Host: 'HostName'
+    //  Accept: */*
+    //  User-Agent: HttpDisk/1.2
+    //  Connection: close
+    //
+    // Interesting lines in answer:
+    //  HTTP/1.1 200 OK
+    //  Accept-Ranges: bytes
+    //  Content-Length: 'total file size'
+
+    _snprintf(
+        buffer,
+        BUFFER_SIZE,
+        "HEAD %s HTTP/1.1\r\nHost: %s\r\nAccept: */*\r\nUser-Agent: HttpDisk/1.2\r\nConnection: close\r\n\r\n",
+        FileName,
+        HostName
+        );
+
+    nSent = send(kSocket, buffer, strlen(buffer), 0);
+
+    if (nSent < 0)
     {
-      DbgPrint ( "HttpDisk: send() error: %#x\n", nSent );
-      ExFreePool ( buffer );
-      close ( kSocket );
-      IoStatus->Status = nSent;
-      return IoStatus->Status;
+        DbgPrint("HttpDisk: send() error: %#x\n", nSent);
+        ExFreePool(buffer);
+        close(kSocket);
+        IoStatus->Status = nSent;
+        return IoStatus->Status;
     }
 
-  nRecv = recv ( kSocket, buffer, BUFFER_SIZE, 0 );
+    nRecv = recv(kSocket, buffer, BUFFER_SIZE, 0);
 
-  if ( nRecv < 0 )
+    if (nRecv < 0)
     {
-      DbgPrint ( "HttpDisk: recv() error: %#x\n", nRecv );
-      ExFreePool ( buffer );
-      close ( kSocket );
-      IoStatus->Status = nRecv;
-      return IoStatus->Status;
+        DbgPrint("HttpDisk: recv() error: %#x\n", nRecv);
+        ExFreePool(buffer);
+        close(kSocket);
+        IoStatus->Status = nRecv;
+        return IoStatus->Status;
     }
 
-  close ( kSocket );
+    close(kSocket);
 
-  buffer[BUFFER_SIZE - 1] = '\0';
+    buffer[BUFFER_SIZE - 1] = '\0';
 
-  if ( _strnicmp ( buffer, "HTTP/1.1 200 OK", 15 ) )
+    if (_strnicmp(buffer, "HTTP/1.1 200 OK", 15))
     {
-      DbgPrint ( "HttpDisk: Invalid HTTP response:\n%s", buffer );
-      ExFreePool ( buffer );
-      IoStatus->Status = STATUS_NO_SUCH_FILE;
-      return IoStatus->Status;
+        DbgPrint("HttpDisk: Invalid HTTP response:\n%s", buffer);
+        ExFreePool(buffer);
+        IoStatus->Status = STATUS_NO_SUCH_FILE;
+        return IoStatus->Status;
     }
 
-  pStr = strstr ( buffer, "Content-Length:" );
+    pStr = strstr(buffer, "Content-Length:");
 
-  if ( pStr == NULL || pStr + 16 >= buffer + BUFFER_SIZE )
+    if (pStr == NULL || pStr + 16 >= buffer + BUFFER_SIZE)
     {
-      DbgPrint ( "HttpDisk: Invalid HTTP response:\n%s", buffer );
-      ExFreePool ( buffer );
-      IoStatus->Status = STATUS_NO_SUCH_FILE;
-      return IoStatus->Status;
+        DbgPrint("HttpDisk: Invalid HTTP response:\n%s", buffer);
+        ExFreePool(buffer);
+        IoStatus->Status = STATUS_NO_SUCH_FILE;
+        return IoStatus->Status;
     }
 
-  HttpHeader->ContentLength.QuadPart = _atoi64 ( pStr + 16 );
+    HttpHeader->ContentLength.QuadPart = _atoi64(pStr + 16);
 
-  if ( HttpHeader->ContentLength.QuadPart == 0 )
+    if (HttpHeader->ContentLength.QuadPart == 0)
     {
-      DbgPrint ( "HttpDisk: Invalid HTTP response:\n%s", buffer );
-      ExFreePool ( buffer );
-      IoStatus->Status = STATUS_NO_SUCH_FILE;
-      return IoStatus->Status;
+        DbgPrint("HttpDisk: Invalid HTTP response:\n%s", buffer);
+        ExFreePool(buffer);
+        IoStatus->Status = STATUS_NO_SUCH_FILE;
+        return IoStatus->Status;
     }
 
-  ExFreePool ( buffer );
+    ExFreePool(buffer);
 
-  IoStatus->Status = STATUS_SUCCESS;
-  IoStatus->Information = 0;
+    IoStatus->Status = STATUS_SUCCESS;
+    IoStatus->Information = 0;
 
-  return STATUS_SUCCESS;
+    return STATUS_SUCCESS;
 }
 
 NTSTATUS
 HttpDiskGetBlock (
-  IN int *Socket,
-  IN ULONG Address,
-  IN USHORT Port,
-  IN PUCHAR HostName,
-  IN PUCHAR FileName,
-  IN PLARGE_INTEGER Offset,
-  IN ULONG Length,
-  OUT PIO_STATUS_BLOCK IoStatus,
-  OUT PVOID SystemBuffer
- )
+    IN int                  *Socket,
+    IN ULONG                Address,
+    IN USHORT               Port,
+    IN PUCHAR               HostName,
+    IN PUCHAR               FileName,
+    IN PLARGE_INTEGER       Offset,
+    IN ULONG                Length,
+    OUT PIO_STATUS_BLOCK    IoStatus,
+    OUT PVOID               SystemBuffer
   )
 {
-  struct sockaddr_in toAddr;
-  int status,
-   nSent,
-   nRecv;
-  unsigned int dataLen;
-  char *buffer,
-  *pData;
-
-  ASSERT ( Socket != NULL );
-  ASSERT ( HostName != NULL );
-  ASSERT ( FileName != NULL );
-  ASSERT ( Offset != NULL );
-  ASSERT ( IoStatus != NULL );
-  ASSERT ( SystemBuffer != NULL );
-
-  IoStatus->Information = 0;
-
-  buffer = ExAllocatePool ( PagedPool, BUFFER_SIZE + 1 );
-
-  if ( buffer == NULL )
+    struct sockaddr_in  toAddr;
+    int                 status, nSent, nRecv;
+    unsigned int        dataLen;
+    char                *buffer, *pData;
+
+    ASSERT(Socket != NULL);
+    ASSERT(HostName != NULL);
+    ASSERT(FileName != NULL);
+    ASSERT(Offset != NULL);
+    ASSERT(IoStatus != NULL);
+    ASSERT(SystemBuffer != NULL);
+
+    IoStatus->Information = 0;
+
+    buffer = ExAllocatePool(PagedPool, BUFFER_SIZE + 1);
+
+    if (buffer == NULL)
     {
-      IoStatus->Status = STATUS_INSUFFICIENT_RESOURCES;
-      return IoStatus->Status;
+        IoStatus->Status = STATUS_INSUFFICIENT_RESOURCES;
+        return IoStatus->Status;
     }
 
-  // Example request:
-  //  GET 'FileName' HTTP/1.1
-  //  Host: 'HostName'
-  //  Range: bytes='Offset'-'Offset + Length - 1'
-  //  Accept: */*
-  //  User-Agent: HttpDisk/1.2
-  //
-  // Interesting lines in answer:
-  //  HTTP/1.1 206 Partial content
-  //  Content-Length: 'requested size'
-  //  Content-Range: bytes 'start'-'end'/'total file size'
-  //  Data follows after '\r\n\r\n'
-
-  _snprintf ( buffer, BUFFER_SIZE,
-             "GET %s HTTP/1.1\r\nHost: %s\r\nRange: bytes=%I64u-%I64u\r\nAccept: */*\r\nUser-Agent: HttpDisk/1.2\r\n\r\n",
-             FileName, HostName, Offset->QuadPart,
-             Offset->QuadPart + Length - 1 );
-
-  if ( *Socket < 0 )
+    // Example request:
+    //  GET 'FileName' HTTP/1.1
+    //  Host: 'HostName'
+    //  Range: bytes='Offset'-'Offset + Length - 1'
+    //  Accept: */*
+    //  User-Agent: HttpDisk/1.2
+    //
+    // Interesting lines in answer:
+    //  HTTP/1.1 206 Partial content
+    //  Content-Length: 'requested size'
+    //  Content-Range: bytes 'start'-'end'/'total file size'
+    //  Data follows after '\r\n\r\n'
+
+    _snprintf(
+        buffer,
+        BUFFER_SIZE,
+        "GET %s HTTP/1.1\r\nHost: %s\r\nRange: bytes=%I64u-%I64u\r\nAccept: */*\r\nUser-Agent: HttpDisk/1.2\r\n\r\n",
+        FileName,
+        HostName,
+        Offset->QuadPart,
+        Offset->QuadPart + Length - 1
+        );
+
+    if (*Socket < 0)
     {
-      *Socket = socket ( AF_INET, SOCK_STREAM, 0 );
-
-      if ( *Socket < 0 )
-       {
-         ExFreePool ( buffer );
-         *Socket = -1;
-         IoStatus->Status = STATUS_INSUFFICIENT_RESOURCES;
-         return IoStatus->Status;
-       }
-
-      toAddr.sin_family = AF_INET;
-      toAddr.sin_port = Port;
-      toAddr.sin_addr.s_addr = Address;
-
-      status =
-       connect ( *Socket, ( struct sockaddr * )&toAddr, sizeof ( toAddr ) );
-
-      if ( status < 0 )
-       {
-         DbgPrint ( "HttpDisk: connect() error: %#x\n", status );
-         ExFreePool ( buffer );
-         close ( *Socket );
-         *Socket = -1;
-         IoStatus->Status = status;
-         return IoStatus->Status;
-       }
+        *Socket = socket(AF_INET, SOCK_STREAM, 0);
+
+        if (*Socket < 0)
+        {
+            ExFreePool(buffer);
+            *Socket = -1;
+            IoStatus->Status = STATUS_INSUFFICIENT_RESOURCES;
+            return IoStatus->Status;
+        }
+
+        toAddr.sin_family = AF_INET;
+        toAddr.sin_port = Port;
+        toAddr.sin_addr.s_addr = Address;
+
+        status = connect(*Socket, (struct sockaddr*) &toAddr, sizeof(toAddr));
+
+        if (status < 0)
+        {
+            DbgPrint("HttpDisk: connect() error: %#x\n", status);
+            ExFreePool(buffer);
+            close(*Socket);
+            *Socket = -1;
+            IoStatus->Status = status;
+            return IoStatus->Status;
+        }
     }
 
-  nSent = send ( *Socket, buffer, strlen ( buffer ), 0 );
+    nSent = send(*Socket, buffer, strlen(buffer), 0);
 
-  if ( nSent < 0 )
+    if (nSent < 0)
     {
-      KdPrint ( ( "HttpDisk: send() error: %#x\n", nSent ) );
-
-      close ( *Socket );
-
-      *Socket = socket ( AF_INET, SOCK_STREAM, 0 );
-
-      if ( *Socket < 0 )
-       {
-         ExFreePool ( buffer );
-         *Socket = -1;
-         IoStatus->Status = STATUS_INSUFFICIENT_RESOURCES;
-         return IoStatus->Status;
-       }
-
-      toAddr.sin_family = AF_INET;
-      toAddr.sin_port = Port;
-      toAddr.sin_addr.s_addr = Address;
-
-      status =
-       connect ( *Socket, ( struct sockaddr * )&toAddr, sizeof ( toAddr ) );
-
-      if ( status < 0 )
-       {
-         DbgPrint ( "HttpDisk: connect() error: %#x\n", status );
-         ExFreePool ( buffer );
-         close ( *Socket );
-         *Socket = -1;
-         IoStatus->Status = status;
-         return IoStatus->Status;
-       }
-
-      nSent = send ( *Socket, buffer, strlen ( buffer ), 0 );
-
-      if ( nSent < 0 )
-       {
-         DbgPrint ( "HttpDisk: send() error: %#x\n", nSent );
-         ExFreePool ( buffer );
-         close ( *Socket );
-         *Socket = -1;
-         IoStatus->Status = nSent;
-         return IoStatus->Status;
-       }
+        KdPrint(("HttpDisk: send() error: %#x\n", nSent));
+
+        close(*Socket);
+
+        *Socket = socket(AF_INET, SOCK_STREAM, 0);
+
+        if (*Socket < 0)
+        {
+            ExFreePool(buffer);
+            *Socket = -1;
+            IoStatus->Status = STATUS_INSUFFICIENT_RESOURCES;
+            return IoStatus->Status;
+        }
+
+        toAddr.sin_family = AF_INET;
+        toAddr.sin_port = Port;
+        toAddr.sin_addr.s_addr = Address;
+
+        status = connect(*Socket, (struct sockaddr*) &toAddr, sizeof(toAddr));
+
+        if (status < 0)
+        {
+            DbgPrint("HttpDisk: connect() error: %#x\n", status);
+            ExFreePool(buffer);
+            close(*Socket);
+            *Socket = -1;
+            IoStatus->Status = status;
+            return IoStatus->Status;
+        }
+
+        nSent = send(*Socket, buffer, strlen(buffer), 0);
+
+        if (nSent < 0)
+        {
+            DbgPrint("HttpDisk: send() error: %#x\n", nSent);
+            ExFreePool(buffer);
+            close(*Socket);
+            *Socket = -1;
+            IoStatus->Status = nSent;
+            return IoStatus->Status;
+        }
     }
 
-  nRecv = recv ( *Socket, buffer, BUFFER_SIZE, 0 );
+    nRecv = recv(*Socket, buffer, BUFFER_SIZE, 0);
 
-  if ( nRecv < 0 )
+    if (nRecv < 0)
     {
-      KdPrint ( ( "HttpDisk: recv() error: %#x\n", nRecv ) );
-
-      close ( *Socket );
-
-      *Socket = socket ( AF_INET, SOCK_STREAM, 0 );
-
-      if ( *Socket < 0 )
-       {
-         ExFreePool ( buffer );
-         *Socket = -1;
-         IoStatus->Status = STATUS_INSUFFICIENT_RESOURCES;
-         return IoStatus->Status;
-       }
-
-      toAddr.sin_family = AF_INET;
-      toAddr.sin_port = Port;
-      toAddr.sin_addr.s_addr = Address;
-
-      status =
-       connect ( *Socket, ( struct sockaddr * )&toAddr, sizeof ( toAddr ) );
-
-      if ( status < 0 )
-       {
-         DbgPrint ( "HttpDisk: connect() error: %#x\n", status );
-         ExFreePool ( buffer );
-         close ( *Socket );
-         *Socket = -1;
-         IoStatus->Status = status;
-         return IoStatus->Status;
-       }
-
-      nSent = send ( *Socket, buffer, strlen ( buffer ), 0 );
-
-      if ( nSent < 0 )
-       {
-         DbgPrint ( "HttpDisk: send() error: %#x\n", nSent );
-         ExFreePool ( buffer );
-         close ( *Socket );
-         *Socket = -1;
-         IoStatus->Status = nSent;
-         return IoStatus->Status;
-       }
-
-      nRecv = recv ( *Socket, buffer, BUFFER_SIZE, 0 );
-
-      if ( nRecv < 0 )
-       {
-         DbgPrint ( "HttpDisk: recv() error: %#x\n", nRecv );
-         ExFreePool ( buffer );
-         close ( *Socket );
-         *Socket = -1;
-         IoStatus->Status = nRecv;
-         return IoStatus->Status;
-       }
+        KdPrint(("HttpDisk: recv() error: %#x\n", nRecv));
+
+        close(*Socket);
+
+        *Socket = socket(AF_INET, SOCK_STREAM, 0);
+
+        if (*Socket < 0)
+        {
+            ExFreePool(buffer);
+            *Socket = -1;
+            IoStatus->Status = STATUS_INSUFFICIENT_RESOURCES;
+            return IoStatus->Status;
+        }
+
+        toAddr.sin_family = AF_INET;
+        toAddr.sin_port = Port;
+        toAddr.sin_addr.s_addr = Address;
+
+        status = connect(*Socket, (struct sockaddr*) &toAddr, sizeof(toAddr));
+
+        if (status < 0)
+        {
+            DbgPrint("HttpDisk: connect() error: %#x\n", status);
+            ExFreePool(buffer);
+            close(*Socket);
+            *Socket = -1;
+            IoStatus->Status = status;
+            return IoStatus->Status;
+        }
+
+        nSent = send(*Socket, buffer, strlen(buffer), 0);
+
+        if (nSent < 0)
+        {
+            DbgPrint("HttpDisk: send() error: %#x\n", nSent);
+            ExFreePool(buffer);
+            close(*Socket);
+            *Socket = -1;
+            IoStatus->Status = nSent;
+            return IoStatus->Status;
+        }
+
+        nRecv = recv(*Socket, buffer, BUFFER_SIZE, 0);
+
+        if (nRecv < 0)
+        {
+            DbgPrint("HttpDisk: recv() error: %#x\n", nRecv);
+            ExFreePool(buffer);
+            close(*Socket);
+            *Socket = -1;
+            IoStatus->Status = nRecv;
+            return IoStatus->Status;
+        }
     }
 
-  buffer[BUFFER_SIZE] = '\0';
+    buffer[BUFFER_SIZE] = '\0';
 
-  if ( _strnicmp ( buffer, "HTTP/1.1 206 Partial Content", 28 ) )
+    if (_strnicmp(buffer, "HTTP/1.1 206 Partial Content", 28))
     {
-      DbgPrint ( "HttpDisk: Invalid HTTP response:\n%s", buffer );
-      ExFreePool ( buffer );
-      close ( *Socket );
-      *Socket = -1;
-      IoStatus->Status = STATUS_UNSUCCESSFUL;
-      return IoStatus->Status;
+        DbgPrint("HttpDisk: Invalid HTTP response:\n%s", buffer);
+        ExFreePool(buffer);
+        close(*Socket);
+        *Socket = -1;
+        IoStatus->Status = STATUS_UNSUCCESSFUL;
+        return IoStatus->Status;
     }
 
-  pData = strstr ( buffer, "\r\n\r\n" ) + 4;
+    pData = strstr(buffer, "\r\n\r\n") + 4;
 
-  if ( pData == NULL || pData < buffer || pData >= buffer + BUFFER_SIZE )
+    if (pData == NULL || pData < buffer || pData >= buffer + BUFFER_SIZE)
     {
-      DbgPrint ( "HttpDisk: Invalid HTTP response:\n%s", buffer );
-      ExFreePool ( buffer );
-      close ( *Socket );
-      *Socket = -1;
-      IoStatus->Status = STATUS_UNSUCCESSFUL;
-      return IoStatus->Status;
+        DbgPrint("HttpDisk: Invalid HTTP response:\n%s", buffer);
+        ExFreePool(buffer);
+        close(*Socket);
+        *Socket = -1;
+        IoStatus->Status = STATUS_UNSUCCESSFUL;
+        return IoStatus->Status;
     }
 
-  dataLen = nRecv - ( pData - buffer );
+    dataLen = nRecv - (pData - buffer);
 
-  if ( dataLen > Length || pData + dataLen > buffer + BUFFER_SIZE )
+    if (dataLen > Length || pData + dataLen > buffer + BUFFER_SIZE)
     {
-      DbgPrint ( "HttpDisk: Invalid data length %u in HTTP response:\n%s",
-                dataLen, buffer );
-      ExFreePool ( buffer );
-      close ( *Socket );
-      *Socket = -1;
-      IoStatus->Status = STATUS_UNSUCCESSFUL;
-      return IoStatus->Status;
+        DbgPrint("HttpDisk: Invalid data length %u in HTTP response:\n%s", dataLen, buffer);
+        ExFreePool(buffer);
+        close(*Socket);
+        *Socket = -1;
+        IoStatus->Status = STATUS_UNSUCCESSFUL;
+        return IoStatus->Status;
     }
 
-  if ( dataLen > 0 )
+    if (dataLen > 0)
     {
-      RtlCopyMemory ( SystemBuffer, pData, dataLen );
+        RtlCopyMemory(
+            SystemBuffer,
+            pData,
+            dataLen
+            );
     }
 
-  while ( dataLen < Length )
+    while (dataLen < Length)
     {
-      nRecv = recv ( *Socket, buffer, BUFFER_SIZE, 0 );
-      if ( nRecv < 0 )
-       {
-         DbgPrint ( "HttpDisk: recv() error: %#x\n", nRecv );
-         close ( *Socket );
-         *Socket = -1;
-         break;
-       }
-      if ( nRecv < 1 || dataLen + nRecv > Length || nRecv > BUFFER_SIZE )
-       {
-         DbgPrint ( "HttpDisk: Invalid data length %u+%u\n", dataLen, nRecv );
-         close ( *Socket );
-         *Socket = -1;
-         break;
-       }
-      RtlCopyMemory ( ( PVOID ) ( ( PUCHAR ) SystemBuffer + dataLen ), buffer,
-                     nRecv );
-      dataLen += nRecv;
+        nRecv = recv(*Socket, buffer, BUFFER_SIZE, 0);
+        if (nRecv < 0)
+        {
+            DbgPrint("HttpDisk: recv() error: %#x\n", nRecv);
+            close(*Socket);
+            *Socket = -1;
+            break;
+        }
+        if (nRecv < 1 || dataLen + nRecv > Length || nRecv > BUFFER_SIZE)
+        {
+            DbgPrint("HttpDisk: Invalid data length %u+%u\n", dataLen, nRecv);
+            close(*Socket);
+            *Socket = -1;
+            break;
+        }
+        RtlCopyMemory(
+            (PVOID)((PUCHAR) SystemBuffer + dataLen),
+            buffer,
+            nRecv
+        );
+        dataLen += nRecv;
     }
 
-  if ( dataLen != Length )
+    if (dataLen != Length)
     {
-      DbgPrint
-       ( "HttpDisk: received data length: %u, expected data length: %u\n",
-         dataLen, Length );
+        DbgPrint("HttpDisk: received data length: %u, expected data length: %u\n", dataLen, Length);
     }
 
-  ExFreePool ( buffer );
-  IoStatus->Status = STATUS_SUCCESS;
-  IoStatus->Information = dataLen;
-  return IoStatus->Status;
+    ExFreePool(buffer);
+    IoStatus->Status = STATUS_SUCCESS;
+    IoStatus->Information = dataLen;
+    return IoStatus->Status;
 }
index d5ec67f..d52d3a8 100644 (file)
 #include "ktdi.h"
 #include "ksocket.h"
 
-typedef struct _STREAM_SOCKET
+typedef struct _STREAM_SOCKET {
+    HANDLE              connectionHandle;
+    PFILE_OBJECT        connectionFileObject;
+    KEVENT              disconnectEvent;
+} STREAM_SOCKET, *PSTREAM_SOCKET;
+
+typedef struct _SOCKET {
+    int                 type;
+    BOOLEAN             isBound;
+    BOOLEAN             isConnected;
+    BOOLEAN             isListening;
+    BOOLEAN             isShuttingdown;
+    BOOLEAN             isShared;
+    HANDLE              addressHandle;
+    PFILE_OBJECT        addressFileObject;
+    PSTREAM_SOCKET      streamSocket;
+    struct sockaddr     peer;
+} SOCKET, *PSOCKET;
+
+NTSTATUS event_disconnect(PVOID TdiEventContext, CONNECTION_CONTEXT ConnectionContext, LONG DisconnectDataLength,
+                          PVOID DisconnectData, LONG DisconnectInformationLength, PVOID DisconnectInformation,
+                          ULONG DisconnectFlags)
 {
-  HANDLE connectionHandle;
-  PFILE_OBJECT connectionFileObject;
-  KEVENT disconnectEvent;
-} STREAM_SOCKET,
-*PSTREAM_SOCKET;
-
-typedef struct _SOCKET
-{
-  int type;
-  BOOLEAN isBound;
-  BOOLEAN isConnected;
-  BOOLEAN isListening;
-  BOOLEAN isShuttingdown;
-  BOOLEAN isShared;
-  HANDLE addressHandle;
-  PFILE_OBJECT addressFileObject;
-  PSTREAM_SOCKET streamSocket;
-  struct sockaddr peer;
-} SOCKET,
-*PSOCKET;
-
-NTSTATUS
-event_disconnect (
-  PVOID TdiEventContext,
-  CONNECTION_CONTEXT ConnectionContext,
-  LONG DisconnectDataLength,
-  PVOID DisconnectData,
-  LONG DisconnectInformationLength,
-  PVOID DisconnectInformation,
-  ULONG DisconnectFlags
- )
-{
-  PSOCKET s = ( PSOCKET ) TdiEventContext;
-  PSTREAM_SOCKET streamSocket = ( PSTREAM_SOCKET ) ConnectionContext;
-  KeSetEvent ( &streamSocket->disconnectEvent, 0, FALSE );
-  return STATUS_SUCCESS;
+    PSOCKET s = (PSOCKET) TdiEventContext;
+    PSTREAM_SOCKET streamSocket = (PSTREAM_SOCKET) ConnectionContext;
+    KeSetEvent(&streamSocket->disconnectEvent, 0, FALSE);
+    return STATUS_SUCCESS;
 }
 
-int __cdecl
-accept (
-  int socket,
-  struct sockaddr *addr,
-  int *addrlen
- )
+int __cdecl accept(int socket, struct sockaddr *addr, int *addrlen)
 {
-  return -1;
+    return -1;
 }
 
-int __cdecl
-bind (
-  int socket,
-  const struct sockaddr *addr,
-  int addrlen
- )
+int __cdecl bind(int socket, const struct sockaddr *addr, int addrlen)
 {
-  PSOCKET s = ( PSOCKET ) - socket;
-  const struct sockaddr_in *localAddr = ( const struct sockaddr_in * )addr;
-  UNICODE_STRING devName;
-  NTSTATUS status;
+    PSOCKET s = (PSOCKET) -socket;
+    const struct sockaddr_in* localAddr = (const struct sockaddr_in*) addr;
+    UNICODE_STRING devName;
+    NTSTATUS status;
 
-  if ( s->isBound || addr == NULL || addrlen < sizeof ( struct sockaddr_in ) )
+    if (s->isBound || addr == NULL || addrlen < sizeof(struct sockaddr_in))
     {
-      return -1;
+        return -1;
     }
 
-  if ( s->type == SOCK_DGRAM )
+    if (s->type == SOCK_DGRAM)
     {
-      RtlInitUnicodeString ( &devName, L"\\Device\\Udp" );
+        RtlInitUnicodeString(&devName, L"\\Device\\Udp");
     }
-  else if ( s->type == SOCK_STREAM )
+    else if (s->type == SOCK_STREAM)
     {
-      RtlInitUnicodeString ( &devName, L"\\Device\\Tcp" );
+        RtlInitUnicodeString(&devName, L"\\Device\\Tcp");
     }
-  else
+    else
     {
-      return -1;
+        return -1;
     }
 
-  status =
-    tdi_open_transport_address ( &devName, localAddr->sin_addr.s_addr,
-                                localAddr->sin_port, s->isShared,
-                                &s->addressHandle, &s->addressFileObject );
+    status = tdi_open_transport_address(
+        &devName,
+        localAddr->sin_addr.s_addr,
+        localAddr->sin_port,
+        s->isShared,
+        &s->addressHandle,
+        &s->addressFileObject
+        );
 
-  if ( !NT_SUCCESS ( status ) )
+    if (!NT_SUCCESS(status))
     {
-      s->addressFileObject = NULL;
-      s->addressHandle = ( HANDLE ) - 1;
-      return status;
+        s->addressFileObject = NULL;
+        s->addressHandle = (HANDLE) -1;
+        return status;
     }
 
-  if ( s->type == SOCK_STREAM )
+    if (s->type == SOCK_STREAM)
     {
-      tdi_set_event_handler ( s->addressFileObject, TDI_EVENT_DISCONNECT,
-                             event_disconnect, s );
+        tdi_set_event_handler(s->addressFileObject, TDI_EVENT_DISCONNECT, event_disconnect, s);
     }
 
-  s->isBound = TRUE;
+    s->isBound = TRUE;
 
-  return 0;
+    return 0;
 }
 
-int __cdecl
-close (
-  int socket
- )
+int __cdecl close(int socket)
 {
-  PSOCKET s = ( PSOCKET ) - socket;
-
-  if ( s->isBound )
-    {
-      if ( s->type == SOCK_STREAM && s->streamSocket )
-       {
-         if ( s->isConnected )
-           {
-             if ( !s->isShuttingdown )
-               {
-                 tdi_disconnect ( s->streamSocket->connectionFileObject,
-                                  TDI_DISCONNECT_RELEASE );
-               }
-             //KeWaitForSingleObject(&s->streamSocket->disconnectEvent, Executive, KernelMode, FALSE, NULL);
-           }
-         if ( s->streamSocket->connectionFileObject )
-           {
-             tdi_disassociate_address ( s->
-                                        streamSocket->connectionFileObject );
-             ObDereferenceObject ( s->streamSocket->connectionFileObject );
-           }
-         if ( s->streamSocket->connectionHandle != ( HANDLE ) - 1 )
-           {
-             ZwClose ( s->streamSocket->connectionHandle );
-           }
-         ExFreePool ( s->streamSocket );
-       }
-
-      if ( s->type == SOCK_DGRAM || s->type == SOCK_STREAM )
-       {
-         ObDereferenceObject ( s->addressFileObject );
-         if ( s->addressHandle != ( HANDLE ) - 1 )
-           {
-             ZwClose ( s->addressHandle );
-           }
-       }
-    }
-
-  ExFreePool ( s );
-
-  return 0;
+    PSOCKET s = (PSOCKET) -socket;
+
+    if (s->isBound)
+    {
+        if (s->type == SOCK_STREAM && s->streamSocket)
+        {
+            if (s->isConnected)
+            {
+                if (!s->isShuttingdown)
+                {
+                    tdi_disconnect(s->streamSocket->connectionFileObject, TDI_DISCONNECT_RELEASE);
+                }
+                //KeWaitForSingleObject(&s->streamSocket->disconnectEvent, Executive, KernelMode, FALSE, NULL);
+            }
+            if (s->streamSocket->connectionFileObject)
+            {
+                tdi_disassociate_address(s->streamSocket->connectionFileObject);
+                ObDereferenceObject(s->streamSocket->connectionFileObject);
+            }
+            if (s->streamSocket->connectionHandle != (HANDLE) -1)
+            {
+                ZwClose(s->streamSocket->connectionHandle);
+            }
+            ExFreePool(s->streamSocket);
+        }
+
+        if (s->type == SOCK_DGRAM || s->type == SOCK_STREAM)
+        {
+            ObDereferenceObject(s->addressFileObject);
+            if (s->addressHandle != (HANDLE) -1)
+            {
+                ZwClose(s->addressHandle);
+            }
+        }
+    }
+
+    ExFreePool(s);
+
+    return 0;
 }
 
-int __cdecl
-connect (
-  int socket,
-  const struct sockaddr *addr,
-  int addrlen
- )
+int __cdecl connect(int socket, const struct sockaddr *addr, int addrlen)
 {
-  PSOCKET s = ( PSOCKET ) - socket;
-  const struct sockaddr_in *remoteAddr = ( const struct sockaddr_in * )addr;
-  UNICODE_STRING devName;
-  NTSTATUS status;
-
-  if ( addr == NULL || addrlen < sizeof ( struct sockaddr_in ) )
-    {
-      return -1;
-    }
-
-  if ( !s->isBound )
-    {
-      struct sockaddr_in localAddr;
-
-      localAddr.sin_family = AF_INET;
-      localAddr.sin_port = 0;
-      localAddr.sin_addr.s_addr = INADDR_ANY;
-
-      status =
-       bind ( socket, ( struct sockaddr * )&localAddr, sizeof ( localAddr ) );
-
-      if ( !NT_SUCCESS ( status ) )
-       {
-         return status;
-       }
-    }
-
-  if ( s->type == SOCK_STREAM )
-    {
-      if ( s->isConnected || s->isListening )
-       {
-         return -1;
-       }
-
-      if ( !s->streamSocket )
-       {
-         s->streamSocket =
-           ( PSTREAM_SOCKET ) ExAllocatePool ( NonPagedPool,
-                                               sizeof ( STREAM_SOCKET ) );
-
-         if ( !s->streamSocket )
-           {
-             return STATUS_INSUFFICIENT_RESOURCES;
-           }
-
-         RtlZeroMemory ( s->streamSocket, sizeof ( STREAM_SOCKET ) );
-         s->streamSocket->connectionHandle = ( HANDLE ) - 1;
-         KeInitializeEvent ( &s->streamSocket->disconnectEvent,
-                             NotificationEvent, FALSE );
-       }
-
-      RtlInitUnicodeString ( &devName, L"\\Device\\Tcp" );
-
-      status =
-       tdi_open_connection_endpoint ( &devName, s->streamSocket, s->isShared,
-                                      &s->streamSocket->connectionHandle,
-                                      &s->
-                                      streamSocket->connectionFileObject );
-
-      if ( !NT_SUCCESS ( status ) )
-       {
-         s->streamSocket->connectionFileObject = NULL;
-         s->streamSocket->connectionHandle = ( HANDLE ) - 1;
-         return status;
-       }
-
-      status =
-       tdi_associate_address ( s->streamSocket->connectionFileObject,
-                               s->addressHandle );
-
-      if ( !NT_SUCCESS ( status ) )
-       {
-         ObDereferenceObject ( s->streamSocket->connectionFileObject );
-         s->streamSocket->connectionFileObject = NULL;
-         ZwClose ( s->streamSocket->connectionHandle );
-         s->streamSocket->connectionHandle = ( HANDLE ) - 1;
-         return status;
-       }
-
-      status =
-       tdi_connect ( s->streamSocket->connectionFileObject,
-                     remoteAddr->sin_addr.s_addr, remoteAddr->sin_port );
-
-      if ( !NT_SUCCESS ( status ) )
-       {
-         tdi_disassociate_address ( s->streamSocket->connectionFileObject );
-         ObDereferenceObject ( s->streamSocket->connectionFileObject );
-         s->streamSocket->connectionFileObject = NULL;
-         ZwClose ( s->streamSocket->connectionHandle );
-         s->streamSocket->connectionHandle = ( HANDLE ) - 1;
-         return status;
-       }
-      else
-       {
-         s->peer = *addr;
-         s->isConnected = TRUE;
-         return 0;
-       }
-    }
-  else if ( s->type == SOCK_DGRAM )
-    {
-      s->peer = *addr;
-      if ( remoteAddr->sin_addr.s_addr == 0 && remoteAddr->sin_port == 0 )
-       {
-         s->isConnected = FALSE;
-       }
-      else
-       {
-         s->isConnected = TRUE;
-       }
-      return 0;
-    }
-  else
-    {
-      return -1;
+    PSOCKET s = (PSOCKET) -socket;
+    const struct sockaddr_in* remoteAddr = (const struct sockaddr_in*) addr;
+    UNICODE_STRING devName;
+    NTSTATUS status;
+
+    if (addr == NULL || addrlen < sizeof(struct sockaddr_in))
+    {
+        return -1;
+    }
+
+    if (!s->isBound)
+    {
+        struct sockaddr_in localAddr;
+
+        localAddr.sin_family = AF_INET;
+        localAddr.sin_port = 0;
+        localAddr.sin_addr.s_addr = INADDR_ANY;
+
+        status = bind(socket, (struct sockaddr*) &localAddr, sizeof(localAddr));
+
+        if (!NT_SUCCESS(status))
+        {
+            return status;
+        }
+    }
+
+    if (s->type == SOCK_STREAM)
+    {
+        if (s->isConnected || s->isListening)
+        {
+            return -1;
+        }
+
+        if (!s->streamSocket)
+        {
+            s->streamSocket = (PSTREAM_SOCKET) ExAllocatePool(NonPagedPool, sizeof(STREAM_SOCKET));
+
+            if (!s->streamSocket)
+            {
+                return STATUS_INSUFFICIENT_RESOURCES;
+            }
+
+            RtlZeroMemory(s->streamSocket, sizeof(STREAM_SOCKET));
+            s->streamSocket->connectionHandle = (HANDLE) -1;
+            KeInitializeEvent(&s->streamSocket->disconnectEvent, NotificationEvent, FALSE);
+        }
+
+        RtlInitUnicodeString(&devName, L"\\Device\\Tcp");
+
+        status = tdi_open_connection_endpoint(
+            &devName,
+            s->streamSocket,
+            s->isShared,
+            &s->streamSocket->connectionHandle,
+            &s->streamSocket->connectionFileObject
+            );
+
+        if (!NT_SUCCESS(status))
+        {
+            s->streamSocket->connectionFileObject = NULL;
+            s->streamSocket->connectionHandle = (HANDLE) -1;
+            return status;
+        }
+
+        status = tdi_associate_address(s->streamSocket->connectionFileObject, s->addressHandle);
+
+        if (!NT_SUCCESS(status))
+        {
+            ObDereferenceObject(s->streamSocket->connectionFileObject);
+            s->streamSocket->connectionFileObject = NULL;
+            ZwClose(s->streamSocket->connectionHandle);
+            s->streamSocket->connectionHandle = (HANDLE) -1;
+            return status;
+        }
+
+        status = tdi_connect(
+            s->streamSocket->connectionFileObject,
+            remoteAddr->sin_addr.s_addr,
+            remoteAddr->sin_port
+            );
+
+        if (!NT_SUCCESS(status))
+        {
+            tdi_disassociate_address(s->streamSocket->connectionFileObject);
+            ObDereferenceObject(s->streamSocket->connectionFileObject);
+            s->streamSocket->connectionFileObject = NULL;
+            ZwClose(s->streamSocket->connectionHandle);
+            s->streamSocket->connectionHandle = (HANDLE) -1;
+            return status;
+        }
+        else
+        {
+            s->peer = *addr;
+            s->isConnected = TRUE;
+            return 0;
+        }
+    }
+    else if (s->type == SOCK_DGRAM)
+    {
+        s->peer = *addr;
+        if (remoteAddr->sin_addr.s_addr == 0 && remoteAddr->sin_port == 0)
+        {
+            s->isConnected = FALSE;
+        }
+        else
+        {
+            s->isConnected = TRUE;
+        }
+        return 0;
+    }
+    else
+    {
+        return -1;
     }
 }
 
-int __cdecl
-getpeername (
-  int socket,
-  struct sockaddr *addr,
-  int *addrlen
- )
+int __cdecl getpeername(int socket, struct sockaddr *addr, int *addrlen)
 {
-  PSOCKET s = ( PSOCKET ) - socket;
+    PSOCKET s = (PSOCKET) -socket;
 
-  if ( !s->isConnected || addr == NULL || addrlen == NULL
-       || *addrlen < sizeof ( struct sockaddr_in ) )
+    if (!s->isConnected || addr == NULL || addrlen == NULL || *addrlen < sizeof(struct sockaddr_in))
     {
-      return -1;
+        return -1;
     }
 
-  *addr = s->peer;
-  *addrlen = sizeof ( s->peer );
+    *addr = s->peer;
+    *addrlen = sizeof(s->peer);
 
-  return 0;
+    return 0;
 }
 
-int __cdecl
-getsockname (
-  int socket,
-  struct sockaddr *addr,
-  int *addrlen
- )
+int __cdecl getsockname(int socket, struct sockaddr *addr, int *addrlen)
 {
-  PSOCKET s = ( PSOCKET ) - socket;
-  struct sockaddr_in *localAddr = ( struct sockaddr_in * )addr;
+    PSOCKET s = (PSOCKET) -socket;
+    struct sockaddr_in* localAddr = (struct sockaddr_in*) addr;
 
-  if ( !s->isBound || addr == NULL || addrlen == NULL
-       || *addrlen < sizeof ( struct sockaddr_in ) )
+    if (!s->isBound || addr == NULL || addrlen == NULL || *addrlen < sizeof(struct sockaddr_in))
     {
-      return -1;
+        return -1;
     }
 
-  if ( s->type == SOCK_DGRAM )
+    if (s->type == SOCK_DGRAM)
     {
-      *addrlen = sizeof ( struct sockaddr_in );
+        *addrlen = sizeof(struct sockaddr_in);
 
-      return tdi_query_address ( s->addressFileObject,
-                                &localAddr->sin_addr.s_addr,
-                                &localAddr->sin_port );
+        return tdi_query_address(
+            s->addressFileObject,
+            &localAddr->sin_addr.s_addr,
+            &localAddr->sin_port
+            );
     }
-  else if ( s->type == SOCK_STREAM )
+    else if (s->type == SOCK_STREAM)
     {
-      *addrlen = sizeof ( struct sockaddr_in );
+        *addrlen = sizeof(struct sockaddr_in);
 
-      return tdi_query_address ( s->streamSocket
-                                && s->streamSocket->
-                                connectionFileObject ? s->streamSocket->
-                                connectionFileObject : s->addressFileObject,
-                                &localAddr->sin_addr.s_addr,
-                                &localAddr->sin_port );
+        return tdi_query_address(
+            s->streamSocket && s->streamSocket->connectionFileObject ? s->streamSocket->connectionFileObject : s->addressFileObject,
+            &localAddr->sin_addr.s_addr,
+            &localAddr->sin_port
+            );
     }
-  else
+    else
     {
-      return -1;
+        return -1;
     }
 }
 
-int __cdecl
-getsockopt (
-  int socket,
-  int level,
-  int optname,
-  char *optval,
-  int *optlen
- )
+int __cdecl getsockopt(int socket, int level, int optname, char *optval, int *optlen)
 {
-  return -1;
+    return -1;
 }
 
-int __cdecl
-listen (
-  int socket,
-  int backlog
- )
+int __cdecl listen(int socket, int backlog)
 {
-  return -1;
+    return -1;
 }
 
-int __cdecl
-recv (
-  int socket,
-  char *buf,
-  int len,
-  int flags
- )
+int __cdecl recv(int socket, char *buf, int len, int flags)
 {
-  PSOCKET s = ( PSOCKET ) - socket;
+    PSOCKET s = (PSOCKET) -socket;
 
-  if ( s->type == SOCK_DGRAM )
+    if (s->type == SOCK_DGRAM)
     {
-      return recvfrom ( socket, buf, len, flags, 0, 0 );
+        return recvfrom(socket, buf, len, flags, 0, 0);
     }
-  else if ( s->type == SOCK_STREAM )
+    else if (s->type == SOCK_STREAM)
     {
-      if ( !s->isConnected )
-       {
-         return -1;
-       }
+        if (!s->isConnected)
+        {
+            return -1;
+        }
 
-      return tdi_recv_stream ( s->streamSocket->connectionFileObject, buf, len,
-                              flags ==
-                              MSG_OOB ? TDI_RECEIVE_EXPEDITED :
-                              TDI_RECEIVE_NORMAL );
+        return tdi_recv_stream(
+            s->streamSocket->connectionFileObject,
+            buf,
+            len,
+            flags == MSG_OOB ? TDI_RECEIVE_EXPEDITED : TDI_RECEIVE_NORMAL
+            );
     }
-  else
+    else
     {
-      return -1;
+        return -1;
     }
 }
 
-int __cdecl
-recvfrom (
-  int socket,
-  char *buf,
-  int len,
-  int flags,
-  struct sockaddr *addr,
-  int *addrlen
- )
+int __cdecl recvfrom(int socket, char *buf, int len, int flags, struct sockaddr *addr, int *addrlen)
 {
-  PSOCKET s = ( PSOCKET ) - socket;
-  struct sockaddr_in *returnAddr = ( struct sockaddr_in * )addr;
+    PSOCKET s = (PSOCKET) -socket;
+    struct sockaddr_in* returnAddr = (struct sockaddr_in*) addr;
 
-  if ( s->type == SOCK_STREAM )
+    if (s->type == SOCK_STREAM)
     {
-      return recv ( socket, buf, len, flags );
+        return recv(socket, buf, len, flags);
     }
-  else if ( s->type == SOCK_DGRAM )
+    else if (s->type == SOCK_DGRAM)
     {
-      u_long *sin_addr = 0;
-      u_short *sin_port = 0;
+        u_long* sin_addr = 0;
+        u_short* sin_port = 0;
 
-      if ( !s->isBound )
-       {
-         return -1;
-       }
+        if (!s->isBound)
+        {
+            return -1;
+        }
 
-      if ( addr != NULL && addrlen != NULL
-          && *addrlen >= sizeof ( struct sockaddr_in ) )
-       {
-         sin_addr = &returnAddr->sin_addr.s_addr;
-         sin_port = &returnAddr->sin_port;
-         *addrlen = sizeof ( struct sockaddr_in );
-       }
+        if (addr != NULL && addrlen != NULL && *addrlen >= sizeof(struct sockaddr_in))
+        {
+            sin_addr = &returnAddr->sin_addr.s_addr;
+            sin_port = &returnAddr->sin_port;
+            *addrlen = sizeof(struct sockaddr_in);
+        }
 
-      return tdi_recv_dgram ( s->addressFileObject, sin_addr, sin_port, buf,
-                             len, TDI_RECEIVE_NORMAL );
+        return tdi_recv_dgram(
+            s->addressFileObject,
+            sin_addr,
+            sin_port,
+            buf,
+            len,
+            TDI_RECEIVE_NORMAL
+            );
     }
-  else
+    else
     {
-      return -1;
+        return -1;
     }
 }
 
-int __cdecl
-select (
-  int nfds,
-  fd_set * readfds,
-  fd_set * writefds,
-  fd_set * exceptfds,
-  const struct timeval *timeout
- )
+int __cdecl select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, const struct timeval *timeout)
 {
-  return -1;
+    return -1;
 }
 
-int __cdecl
-send (
-  int socket,
-  const char *buf,
-  int len,
-  int flags
- )
+int __cdecl send(int socket, const char *buf, int len, int flags)
 {
-  PSOCKET s = ( PSOCKET ) - socket;
+    PSOCKET s = (PSOCKET) -socket;
 
-  if ( !s->isConnected )
+    if (!s->isConnected)
     {
-      return -1;
+        return -1;
     }
 
-  if ( s->type == SOCK_DGRAM )
+    if (s->type == SOCK_DGRAM)
     {
-      return sendto ( socket, buf, len, flags, &s->peer, sizeof ( s->peer ) );
+        return sendto(socket, buf, len, flags, &s->peer, sizeof(s->peer));
     }
-  else if ( s->type == SOCK_STREAM )
+    else if (s->type == SOCK_STREAM)
     {
-      return tdi_send_stream ( s->streamSocket->connectionFileObject, buf, len,
-                              flags == MSG_OOB ? TDI_SEND_EXPEDITED : 0 );
+        return tdi_send_stream(
+            s->streamSocket->connectionFileObject,
+            buf,
+            len,
+            flags == MSG_OOB ? TDI_SEND_EXPEDITED : 0
+            );
     }
-  else
+    else
     {
-      return -1;
+        return -1;
     }
 }
 
-int __cdecl
-sendto (
-  int socket,
-  const char *buf,
-  int len,
-  int flags,
-  const struct sockaddr *addr,
-  int addrlen
- )
+int __cdecl sendto(int socket, const char *buf, int len, int flags, const struct sockaddr *addr, int addrlen)
 {
-  PSOCKET s = ( PSOCKET ) - socket;
-  const struct sockaddr_in *remoteAddr = ( const struct sockaddr_in * )addr;
+    PSOCKET s = (PSOCKET) -socket;
+    const struct sockaddr_in* remoteAddr = (const struct sockaddr_in*) addr;
 
-  if ( s->type == SOCK_STREAM )
+    if (s->type == SOCK_STREAM)
     {
-      return send ( socket, buf, len, flags );
+        return send(socket, buf, len, flags);
     }
-  else if ( s->type == SOCK_DGRAM )
+    else if (s->type == SOCK_DGRAM)
     {
-      if ( addr == NULL || addrlen < sizeof ( struct sockaddr_in ) )
-       {
-         return -1;
-       }
+        if (addr == NULL || addrlen < sizeof(struct sockaddr_in))
+        {
+            return -1;
+        }
 
-      if ( !s->isBound )
-       {
-         struct sockaddr_in localAddr;
-         NTSTATUS status;
+        if (!s->isBound)
+        {
+            struct sockaddr_in localAddr;
+            NTSTATUS status;
 
-         localAddr.sin_family = AF_INET;
-         localAddr.sin_port = 0;
-         localAddr.sin_addr.s_addr = INADDR_ANY;
+            localAddr.sin_family = AF_INET;
+            localAddr.sin_port = 0;
+            localAddr.sin_addr.s_addr = INADDR_ANY;
 
-         status =
-           bind ( socket, ( struct sockaddr * )&localAddr,
-                  sizeof ( localAddr ) );
+            status = bind(socket, (struct sockaddr*) &localAddr, sizeof(localAddr));
 
-         if ( !NT_SUCCESS ( status ) )
-           {
-             return status;
-           }
-       }
+            if (!NT_SUCCESS(status))
+            {
+                return status;
+            }
+        }
 
-      return tdi_send_dgram ( s->addressFileObject,
-                             remoteAddr->sin_addr.s_addr,
-                             remoteAddr->sin_port, buf, len );
+        return tdi_send_dgram(
+            s->addressFileObject,
+            remoteAddr->sin_addr.s_addr,
+            remoteAddr->sin_port,
+            buf,
+            len
+            );
     }
-  else
+    else
     {
-      return -1;
+        return -1;
     }
 }
 
-int __cdecl
-setsockopt (
-  int socket,
-  int level,
-  int optname,
-  const char *optval,
-  int optlen
- )
+int __cdecl setsockopt(int socket, int level, int optname, const char *optval, int optlen)
 {
-  return -1;
+    return -1;
 }
 
-int __cdecl
-shutdown (
-  int socket,
-  int how
- )
+int __cdecl shutdown(int socket, int how)
 {
-  PSOCKET s = ( PSOCKET ) - socket;
+    PSOCKET s = (PSOCKET) -socket;
 
-  if ( !s->isConnected )
+    if (!s->isConnected)
     {
-      return -1;
+        return -1;
     }
 
-  if ( s->type == SOCK_STREAM )
+    if (s->type == SOCK_STREAM)
     {
-      s->isShuttingdown = TRUE;
-      return tdi_disconnect ( s->streamSocket->connectionFileObject,
-                             TDI_DISCONNECT_RELEASE );
+        s->isShuttingdown = TRUE;
+        return tdi_disconnect(s->streamSocket->connectionFileObject, TDI_DISCONNECT_RELEASE);
     }
-  else
+    else
     {
-      return -1;
+        return -1;
     }
 }
 
-int __cdecl
-socket (
-  int af,
-  int type,
-  int protocol
- )
+int __cdecl socket(int af, int type, int protocol)
 {
-  PSOCKET s;
+    PSOCKET s;
 
-  if ( af != AF_INET || ( type != SOCK_DGRAM && type != SOCK_STREAM )
-       || ( type == SOCK_DGRAM && protocol != IPPROTO_UDP && protocol != 0 )
-       || ( type == SOCK_STREAM && protocol != IPPROTO_TCP && protocol != 0 ) )
+    if (af != AF_INET ||
+       (type != SOCK_DGRAM && type != SOCK_STREAM) ||
+       (type == SOCK_DGRAM && protocol != IPPROTO_UDP && protocol != 0) ||
+       (type == SOCK_STREAM && protocol != IPPROTO_TCP && protocol != 0)
+       )
     {
-      return STATUS_INVALID_PARAMETER;
+        return STATUS_INVALID_PARAMETER;
     }
 
-  s = ( PSOCKET ) ExAllocatePool ( NonPagedPool, sizeof ( SOCKET ) );
+    s = (PSOCKET) ExAllocatePool(NonPagedPool, sizeof(SOCKET));
 
-  if ( !s )
+    if (!s)
     {
-      return STATUS_INSUFFICIENT_RESOURCES;
+        return STATUS_INSUFFICIENT_RESOURCES;
     }
 
-  RtlZeroMemory ( s, sizeof ( SOCKET ) );
+    RtlZeroMemory(s, sizeof(SOCKET));
 
-  s->type = type;
-  s->addressHandle = ( HANDLE ) - 1;
+    s->type = type;
+    s->addressHandle = (HANDLE) -1;
 
-  return -( int )s;
+    return -(int)s;
 }
index 7e4f8e5..7c4b00d 100644 (file)
 */
 
 #if !defined(KSOCKET_H)
-#  define KSOCKET_H
+#define KSOCKET_H
 
-#  if defined(__cplusplus)
-extern "C"
-{
-#  endif
+#if defined(__cplusplus)
+extern "C" {
+#endif
 
-  typedef unsigned char u_char;
-  typedef unsigned short u_short;
-  typedef unsigned int u_int;
-  typedef unsigned long u_long;
+typedef unsigned char   u_char;
+typedef unsigned short  u_short;
+typedef unsigned int    u_int;
+typedef unsigned long   u_long;
 
-#  define AF_INET             2
+#define AF_INET             2
 
-#  define SOCK_STREAM         1
-#  define SOCK_DGRAM          2
-#  define SOCK_RAW            3
+#define SOCK_STREAM         1
+#define SOCK_DGRAM          2
+#define SOCK_RAW            3
 
-#  define IPPROTO_ICMP        1
-#  define IPPROTO_TCP         6
-#  define IPPROTO_UDP         17
+#define IPPROTO_ICMP        1
+#define IPPROTO_TCP         6
+#define IPPROTO_UDP         17
 
-#  define INADDR_ANY          0x00000000
-#  define INADDR_LOOPBACK     0x7f000001
-#  define INADDR_BROADCAST    0xffffffff
-#  define INADDR_NONE         0xffffffff
+#define INADDR_ANY          0x00000000
+#define INADDR_LOOPBACK     0x7f000001
+#define INADDR_BROADCAST    0xffffffff
+#define INADDR_NONE         0xffffffff
 
-#  define MSG_OOB             0x1
+#define MSG_OOB             0x1
 
-#  define SOMAXCONN           5
+#define SOMAXCONN           5
 
-#  define SD_RECEIVE          0x00
-#  define SD_SEND             0x01
-#  define SD_BOTH             0x02
+#define SD_RECEIVE          0x00
+#define SD_SEND             0x01
+#define SD_BOTH             0x02
 
-#  ifndef FD_SETSIZE
-#    define FD_SETSIZE          64
-#  endif
+#ifndef FD_SETSIZE
+#define FD_SETSIZE          64
+#endif
 
-  typedef struct fd_set
-  {
-    u_int fd_count;
-    int fd_array[FD_SETSIZE];
-  } fd_set;
+typedef struct fd_set {
+    u_int   fd_count;
+    int     fd_array[FD_SETSIZE];
+} fd_set;
 
-  struct hostent
-  {
-    char *h_name;
-    char **h_aliases;
-    short h_addrtype;
-    short h_length;
-    char **h_addr_list;
-  };
+struct hostent {
+    char    *h_name;
+    char    **h_aliases;
+    short   h_addrtype;
+    short   h_length;
+    char    **h_addr_list;
+};
 
-#  define h_addr h_addr_list[0]
+#define h_addr h_addr_list[0]
 
-  struct in_addr
-  {
-    union
-    {
-      struct
-      {
-       u_char s_b1,
-        s_b2,
-        s_b3,
-        s_b4;
-      } S_un_b;
-      struct
-      {
-       u_short s_w1,
-        s_w2;
-      } S_un_w;
-      u_long S_addr;
+struct in_addr {
+    union {
+        struct { u_char s_b1, s_b2, s_b3, s_b4; }   S_un_b;
+        struct { u_short s_w1, s_w2; }              S_un_w;
+        u_long                                      S_addr;
     } S_un;
-  };
+};
 
-#  define s_addr S_un.S_addr
+#define s_addr S_un.S_addr
 
-  struct protoent
-  {
-    char *p_name;
-    char **p_aliases;
-    short p_proto;
-  };
+struct protoent {
+    char    *p_name;
+    char    **p_aliases;
+    short   p_proto;
+};
 
-  struct servent
-  {
-    char *s_name;
-    char **s_aliases;
-    short s_port;
-    char *s_proto;
-  };
+struct servent {
+    char    *s_name;
+    char    **s_aliases;
+    short   s_port;
+    char    *s_proto;
+};
 
-  struct sockaddr
-  {
+struct sockaddr {
     u_short sa_family;
-    char sa_data[14];
-  };
+    char    sa_data[14];
+};
 
-  struct sockaddr_in
-  {
-    short sin_family;
-    u_short sin_port;
-    struct in_addr sin_addr;
-    char sin_zero[8];
-  };
+struct sockaddr_in {
+    short           sin_family;
+    u_short         sin_port;
+    struct in_addr  sin_addr;
+    char            sin_zero[8];
+};
 
-  struct timeval
-  {
+struct timeval {
     long tv_sec;
     long tv_usec;
-  };
-
-  int __cdecl accept (
-  int socket,
-  struct sockaddr *addr,
-  int *addrlen
-   );
-  int __cdecl bind (
-  int socket,
-  const struct sockaddr *addr,
-  int addrlen
-   );
-  int __cdecl close (
-  int socket
-   );
-  int __cdecl connect (
-  int socket,
-  const struct sockaddr *addr,
-  int addrlen
-   );
-  struct hostent *__cdecl gethostbyaddr (
-  const char *addr,
-  int addrlen,
-  int type
-   );
-  struct hostent *__cdecl gethostbyname (
-  const char *name
-   );
-  int __cdecl gethostname (
-  char *name,
-  int namelen
-   );
-  int __cdecl getpeername (
-  int socket,
-  struct sockaddr *addr,
-  int *addrlen
-   );
-  struct protoent *__cdecl getprotobyname (
-  const char *name
-   );
-  struct protoent *__cdecl getprotobynumber (
-  int number
-   );
-  struct servent *__cdecl getservbyname (
-  const char *name,
-  const char *proto
-   );
-  struct servent *__cdecl getservbyport (
-  int port,
-  const char *proto
-   );
-  int __cdecl getsockname (
-  int socket,
-  struct sockaddr *addr,
-  int *addrlen
-   );
-  int __cdecl getsockopt (
-  int socket,
-  int level,
-  int optname,
-  char *optval,
-  int *optlen
-   );
-  u_long __cdecl htonl (
-  u_long hostlong
-   );
-  u_short __cdecl htons (
-  u_short hostshort
-   );
-  u_long __cdecl inet_addr (
-  const char *name
-   );
-  int __cdecl inet_aton (
-  const char *name,
-  struct in_addr *addr
-   );
-  char *__cdecl inet_ntoa (
-  struct in_addr addr
-   );
-  int __cdecl listen (
-  int socket,
-  int backlog
-   );
-  u_long __cdecl ntohl (
-  u_long netlong
-   );
-  u_short __cdecl ntohs (
-  u_short netshort
-   );
-  int __cdecl recv (
-  int socket,
-  char *buf,
-  int len,
-  int flags
-   );
-  int __cdecl recvfrom (
-  int socket,
-  char *buf,
-  int len,
-  int flags,
-  struct sockaddr *addr,
-  int *addrlen
-   );
-  int __cdecl select (
-  int nfds,
-  fd_set * readfds,
-  fd_set * writefds,
-  fd_set * exceptfds,
-  const struct timeval *timeout
-   );
-  int __cdecl send (
-  int socket,
-  const char *buf,
-  int len,
-  int flags
-   );
-  int __cdecl sendto (
-  int socket,
-  const char *buf,
-  int len,
-  int flags,
-  const struct sockaddr *addr,
-  int addrlen
-   );
-  int __cdecl setsockopt (
-  int socket,
-  int level,
-  int optname,
-  const char *optval,
-  int optlen
-   );
-  int __cdecl shutdown (
-  int socket,
-  int how
-   );
-  int __cdecl socket (
-  int af,
-  int type,
-  int protocol
-   );
-
-#  if defined(__cplusplus)
+};
+
+int __cdecl accept(int socket, struct sockaddr *addr, int *addrlen);
+int __cdecl bind(int socket, const struct sockaddr *addr, int addrlen);
+int __cdecl close(int socket);
+int __cdecl connect(int socket, const struct sockaddr *addr, int addrlen);
+struct hostent * __cdecl gethostbyaddr(const char *addr, int addrlen, int type);
+struct hostent * __cdecl gethostbyname(const char *name);
+int __cdecl gethostname(char *name, int namelen);
+int __cdecl getpeername(int socket, struct sockaddr *addr, int *addrlen);
+struct protoent * __cdecl getprotobyname(const char *name);
+struct protoent * __cdecl getprotobynumber(int number);
+struct servent * __cdecl getservbyname(const char *name, const char *proto);
+struct servent * __cdecl getservbyport(int port, const char *proto);
+int __cdecl getsockname(int socket, struct sockaddr *addr, int *addrlen);
+int __cdecl getsockopt(int socket, int level, int optname, char *optval, int *optlen);
+u_long __cdecl htonl(u_long hostlong);
+u_short __cdecl htons(u_short hostshort);
+u_long __cdecl inet_addr(const char *name);
+int __cdecl inet_aton(const char *name, struct in_addr *addr);
+char * __cdecl inet_ntoa(struct in_addr addr);
+int __cdecl listen(int socket, int backlog);
+u_long __cdecl ntohl(u_long netlong);
+u_short __cdecl ntohs(u_short netshort);
+int __cdecl recv(int socket, char *buf, int len, int flags);
+int __cdecl recvfrom(int socket, char *buf, int len, int flags, struct sockaddr *addr, int *addrlen);
+int __cdecl select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, const struct timeval *timeout);
+int __cdecl send(int socket, const char *buf, int len, int flags);
+int __cdecl sendto(int socket, const char *buf, int len, int flags, const struct sockaddr *addr, int addrlen);
+int __cdecl setsockopt(int socket, int level, int optname, const char *optval, int optlen);
+int __cdecl shutdown(int socket, int how);
+int __cdecl socket(int af, int type, int protocol);
+
+#if defined(__cplusplus)
 }
-#  endif
+#endif
 
-#endif                         // !defined(KSOCKET_H)
+#endif // !defined(KSOCKET_H)
index 653cffe..606bee8 100644 (file)
 #include <tdikrnl.h>
 #include "ktdi.h"
 
-NTSTATUS
-tdi_open_transport_address (
-  PUNICODE_STRING devName,
-  ULONG addr,
-  USHORT port,
-  BOOLEAN shared,
-  PHANDLE addressHandle,
-  PFILE_OBJECT * addressFileObject
- )
+NTSTATUS tdi_open_transport_address(PUNICODE_STRING devName, ULONG addr, USHORT port, BOOLEAN shared, PHANDLE addressHandle, PFILE_OBJECT *addressFileObject)
 {
-  OBJECT_ATTRIBUTES attr;
-  PFILE_FULL_EA_INFORMATION eaBuffer;
-  ULONG eaSize;
-  PTA_IP_ADDRESS localAddr;
-  IO_STATUS_BLOCK iosb;
-  NTSTATUS status;
+    OBJECT_ATTRIBUTES           attr;
+    PFILE_FULL_EA_INFORMATION   eaBuffer;
+    ULONG                       eaSize;
+    PTA_IP_ADDRESS              localAddr;
+    IO_STATUS_BLOCK             iosb;
+    NTSTATUS                    status;
 
 #if (VER_PRODUCTBUILD >= 2195)
-  InitializeObjectAttributes ( &attr, devName,
-                              OBJ_CASE_INSENSITIVE | OBJ_KERNEL_HANDLE, NULL,
-                              NULL );
+    InitializeObjectAttributes(&attr, devName, OBJ_CASE_INSENSITIVE | OBJ_KERNEL_HANDLE, NULL, NULL);
 #else
-  InitializeObjectAttributes ( &attr, devName, OBJ_CASE_INSENSITIVE, NULL,
-                              NULL );
+    InitializeObjectAttributes(&attr, devName, OBJ_CASE_INSENSITIVE, NULL, NULL);
 #endif
 
-  eaSize =
-    FIELD_OFFSET ( FILE_FULL_EA_INFORMATION,
-                  EaName[0] ) + TDI_TRANSPORT_ADDRESS_LENGTH + 1 +
-    sizeof ( TA_IP_ADDRESS );
+    eaSize = FIELD_OFFSET(FILE_FULL_EA_INFORMATION, EaName[0]) +
+             TDI_TRANSPORT_ADDRESS_LENGTH                      +
+             1                                                 +
+             sizeof(TA_IP_ADDRESS);
 
-  eaBuffer =
-    ( PFILE_FULL_EA_INFORMATION ) ExAllocatePool ( PagedPool, eaSize );
+    eaBuffer = (PFILE_FULL_EA_INFORMATION) ExAllocatePool(PagedPool, eaSize);
 
-  if ( eaBuffer == NULL )
+    if (eaBuffer == NULL)
     {
-      return STATUS_INSUFFICIENT_RESOURCES;
+        return STATUS_INSUFFICIENT_RESOURCES;
     }
 
-  eaBuffer->NextEntryOffset = 0;
-  eaBuffer->Flags = 0;
-  eaBuffer->EaNameLength = TDI_TRANSPORT_ADDRESS_LENGTH;
-  eaBuffer->EaValueLength = sizeof ( TA_IP_ADDRESS );
+    eaBuffer->NextEntryOffset = 0;
+    eaBuffer->Flags = 0;
+    eaBuffer->EaNameLength = TDI_TRANSPORT_ADDRESS_LENGTH;
+    eaBuffer->EaValueLength = sizeof(TA_IP_ADDRESS);
 
-  RtlCopyMemory ( eaBuffer->EaName, TdiTransportAddress,
-                 eaBuffer->EaNameLength + 1 );
+    RtlCopyMemory(eaBuffer->EaName, TdiTransportAddress, eaBuffer->EaNameLength + 1);
 
-  localAddr =
-    ( PTA_IP_ADDRESS ) ( eaBuffer->EaName + eaBuffer->EaNameLength + 1 );
+    localAddr = (PTA_IP_ADDRESS)(eaBuffer->EaName + eaBuffer->EaNameLength + 1);
 
-  localAddr->TAAddressCount = 1;
-  localAddr->Address[0].AddressLength = TDI_ADDRESS_LENGTH_IP;
-  localAddr->Address[0].AddressType = TDI_ADDRESS_TYPE_IP;
-  localAddr->Address[0].Address[0].sin_port = port;
-  localAddr->Address[0].Address[0].in_addr = addr;
+    localAddr->TAAddressCount = 1;
+    localAddr->Address[0].AddressLength = TDI_ADDRESS_LENGTH_IP;
+    localAddr->Address[0].AddressType = TDI_ADDRESS_TYPE_IP;
+    localAddr->Address[0].Address[0].sin_port = port;
+    localAddr->Address[0].Address[0].in_addr = addr;
 
-  RtlZeroMemory ( localAddr->Address[0].Address[0].sin_zero,
-                 sizeof ( localAddr->Address[0].Address[0].sin_zero ) );
+    RtlZeroMemory(localAddr->Address[0].Address[0].sin_zero, sizeof(localAddr->Address[0].Address[0].sin_zero));
 
-  status =
-    ZwCreateFile ( addressHandle, GENERIC_READ | GENERIC_WRITE, &attr, &iosb,
-                  NULL, FILE_ATTRIBUTE_NORMAL,
-                  shared ? FILE_SHARE_READ | FILE_SHARE_WRITE : 0, FILE_OPEN,
-                  0, eaBuffer, eaSize );
+    status = ZwCreateFile(
+        addressHandle,
+        GENERIC_READ | GENERIC_WRITE,
+        &attr,
+        &iosb,
+        NULL,
+        FILE_ATTRIBUTE_NORMAL,
+        shared ? FILE_SHARE_READ | FILE_SHARE_WRITE : 0,
+        FILE_OPEN,
+        0,
+        eaBuffer,
+        eaSize
+        );
 
-  ExFreePool ( eaBuffer );
+    ExFreePool(eaBuffer);
 
-  if ( !NT_SUCCESS ( status ) )
+    if (!NT_SUCCESS(status))
     {
-      return status;
+        return status;
     }
 
-  status =
-    ObReferenceObjectByHandle ( *addressHandle, FILE_ALL_ACCESS, NULL,
-                               KernelMode, addressFileObject, NULL );
+    status = ObReferenceObjectByHandle(*addressHandle, FILE_ALL_ACCESS, NULL, KernelMode, addressFileObject, NULL);
 
-  if ( !NT_SUCCESS ( status ) )
+    if (!NT_SUCCESS(status))
     {
-      ZwClose ( *addressHandle );
-      return status;
+        ZwClose(*addressHandle);
+        return status;
     }
 
-  return STATUS_SUCCESS;
+    return STATUS_SUCCESS;
 }
 
-NTSTATUS
-tdi_open_connection_endpoint (
-  PUNICODE_STRING devName,
-  PVOID connectionContext,
-  BOOLEAN shared,
-  PHANDLE connectionHandle,
-  PFILE_OBJECT * connectionFileObject
- )
+NTSTATUS tdi_open_connection_endpoint(PUNICODE_STRING devName, PVOID connectionContext, BOOLEAN shared, PHANDLE connectionHandle, PFILE_OBJECT *connectionFileObject)
 {
-  OBJECT_ATTRIBUTES attr;
-  PFILE_FULL_EA_INFORMATION eaBuffer;
-  ULONG eaSize;
-  PVOID *context;
-  IO_STATUS_BLOCK iosb;
-  NTSTATUS status;
+    OBJECT_ATTRIBUTES           attr;
+    PFILE_FULL_EA_INFORMATION   eaBuffer;
+    ULONG                       eaSize;
+    PVOID                       *context;
+    IO_STATUS_BLOCK             iosb;
+    NTSTATUS                    status;
 
 #if (VER_PRODUCTBUILD >= 2195)
-  InitializeObjectAttributes ( &attr, devName,
-                              OBJ_CASE_INSENSITIVE | OBJ_KERNEL_HANDLE, NULL,
-                              NULL );
+    InitializeObjectAttributes(&attr, devName, OBJ_CASE_INSENSITIVE | OBJ_KERNEL_HANDLE, NULL, NULL);
 #else
-  InitializeObjectAttributes ( &attr, devName, OBJ_CASE_INSENSITIVE, NULL,
-                              NULL );
+    InitializeObjectAttributes(&attr, devName, OBJ_CASE_INSENSITIVE, NULL, NULL);
 #endif
 
-  eaSize =
-    FIELD_OFFSET ( FILE_FULL_EA_INFORMATION,
-                  EaName[0] ) + TDI_CONNECTION_CONTEXT_LENGTH + 1 +
-    sizeof ( int );
+    eaSize = FIELD_OFFSET(FILE_FULL_EA_INFORMATION, EaName[0]) +
+             TDI_CONNECTION_CONTEXT_LENGTH                     +
+             1                                                 +
+             sizeof(int);
 
-  eaBuffer =
-    ( PFILE_FULL_EA_INFORMATION ) ExAllocatePool ( PagedPool, eaSize );
+    eaBuffer = (PFILE_FULL_EA_INFORMATION) ExAllocatePool(PagedPool, eaSize);
 
-  if ( eaBuffer == NULL )
+    if (eaBuffer == NULL)
     {
-      return STATUS_INSUFFICIENT_RESOURCES;
+        return STATUS_INSUFFICIENT_RESOURCES;
     }
 
-  eaBuffer->NextEntryOffset = 0;
-  eaBuffer->Flags = 0;
-  eaBuffer->EaNameLength = TDI_CONNECTION_CONTEXT_LENGTH;
-  eaBuffer->EaValueLength = sizeof ( int );
+    eaBuffer->NextEntryOffset = 0;
+    eaBuffer->Flags = 0;
+    eaBuffer->EaNameLength = TDI_CONNECTION_CONTEXT_LENGTH;
+    eaBuffer->EaValueLength = sizeof(int);
 
-  RtlCopyMemory ( eaBuffer->EaName, TdiConnectionContext,
-                 eaBuffer->EaNameLength + 1 );
+    RtlCopyMemory(eaBuffer->EaName, TdiConnectionContext, eaBuffer->EaNameLength + 1);
 
-  context = ( PVOID * ) & ( eaBuffer->EaName[eaBuffer->EaNameLength + 1] );
+    context = (PVOID*) &(eaBuffer->EaName[eaBuffer->EaNameLength + 1]);
 
-  *context = connectionContext;
+    *context = connectionContext;
 
-  status =
-    ZwCreateFile ( connectionHandle, GENERIC_READ | GENERIC_WRITE, &attr,
-                  &iosb, NULL, FILE_ATTRIBUTE_NORMAL,
-                  shared ? FILE_SHARE_READ | FILE_SHARE_WRITE : 0, FILE_OPEN,
-                  0, eaBuffer, eaSize );
+    status = ZwCreateFile(
+        connectionHandle,
+        GENERIC_READ | GENERIC_WRITE,
+        &attr,
+        &iosb,
+        NULL,
+        FILE_ATTRIBUTE_NORMAL,
+        shared ? FILE_SHARE_READ | FILE_SHARE_WRITE : 0,
+        FILE_OPEN,
+        0,
+        eaBuffer,
+        eaSize
+        );
 
-  ExFreePool ( eaBuffer );
+    ExFreePool(eaBuffer);
 
-  if ( !NT_SUCCESS ( status ) )
+    if (!NT_SUCCESS(status))
     {
-      return status;
+        return status;
     }
 
-  status =
-    ObReferenceObjectByHandle ( *connectionHandle, FILE_ALL_ACCESS, NULL,
-                               KernelMode, connectionFileObject, NULL );
+    status = ObReferenceObjectByHandle(*connectionHandle, FILE_ALL_ACCESS, NULL, KernelMode, connectionFileObject, NULL);
 
-  if ( !NT_SUCCESS ( status ) )
+    if (!NT_SUCCESS(status))
     {
-      ZwClose ( *connectionHandle );
-      return status;
+        ZwClose(*connectionHandle);
+        return status;
     }
 
-  return STATUS_SUCCESS;
+    return STATUS_SUCCESS;
 }
 
-NTSTATUS
-tdi_set_event_handler (
-  PFILE_OBJECT addressFileObject,
-  LONG eventType,
-  PVOID eventHandler,
-  PVOID eventContext
- )
+NTSTATUS tdi_set_event_handler(PFILE_OBJECT addressFileObject, LONG eventType, PVOID eventHandler, PVOID eventContext)
 {
-  PDEVICE_OBJECT devObj;
-  KEVENT event;
-  PIRP irp;
-  IO_STATUS_BLOCK iosb;
-  NTSTATUS status;
+    PDEVICE_OBJECT  devObj;
+    KEVENT          event;
+    PIRP            irp;
+    IO_STATUS_BLOCK iosb;
+    NTSTATUS        status;
 
-  devObj = IoGetRelatedDeviceObject ( addressFileObject );
+    devObj = IoGetRelatedDeviceObject(addressFileObject);
 
-  KeInitializeEvent ( &event, NotificationEvent, FALSE );
+    KeInitializeEvent(&event, NotificationEvent, FALSE);
 
-  irp =
-    TdiBuildInternalDeviceControlIrp ( TDI_SET_EVENT_HANDLER, devObj,
-                                      addressFileObject, &event, &iosb );
+    irp = TdiBuildInternalDeviceControlIrp(TDI_SET_EVENT_HANDLER, devObj, addressFileObject, &event, &iosb);
 
-  if ( irp == NULL )
+    if (irp == NULL)
     {
-      return STATUS_INSUFFICIENT_RESOURCES;
+        return STATUS_INSUFFICIENT_RESOURCES;
     }
 
-  TdiBuildSetEventHandler ( irp, devObj, addressFileObject, NULL, NULL,
-                           eventType, eventHandler, eventContext );
+    TdiBuildSetEventHandler(irp, devObj, addressFileObject, NULL, NULL, eventType, eventHandler, eventContext);
 
-  status = IoCallDriver ( devObj, irp );
+    status = IoCallDriver(devObj, irp);
 
-  if ( status == STATUS_PENDING )
+    if (status == STATUS_PENDING)
     {
-      KeWaitForSingleObject ( &event, Executive, KernelMode, FALSE, NULL );
-      status = iosb.Status;
+        KeWaitForSingleObject(&event, Executive, KernelMode, FALSE, NULL);
+        status = iosb.Status;
     }
 
-  return status;
+    return status;
 }
 
-NTSTATUS
-tdi_unset_event_handler (
-  PFILE_OBJECT addressFileObject,
-  LONG eventType
- )
+NTSTATUS tdi_unset_event_handler(PFILE_OBJECT addressFileObject, LONG eventType)
 {
-  return tdi_set_event_handler ( addressFileObject, eventType, NULL, NULL );
+    return tdi_set_event_handler(addressFileObject, eventType, NULL, NULL);
 }
 
-NTSTATUS
-tdi_associate_address (
-  PFILE_OBJECT connectionFileObject,
-  HANDLE addressHandle
- )
+NTSTATUS tdi_associate_address(PFILE_OBJECT connectionFileObject, HANDLE addressHandle)
 {
-  PDEVICE_OBJECT devObj;
-  KEVENT event;
-  PIRP irp;
-  IO_STATUS_BLOCK iosb;
-  NTSTATUS status;
+    PDEVICE_OBJECT  devObj;
+    KEVENT          event;
+    PIRP            irp;
+    IO_STATUS_BLOCK iosb;
+    NTSTATUS        status;
 
-  devObj = IoGetRelatedDeviceObject ( connectionFileObject );
+    devObj = IoGetRelatedDeviceObject(connectionFileObject);
 
-  KeInitializeEvent ( &event, NotificationEvent, FALSE );
+    KeInitializeEvent(&event, NotificationEvent, FALSE);
 
-  irp =
-    TdiBuildInternalDeviceControlIrp ( TDI_ASSOCIATE_ADDRESS, devObj,
-                                      connectionFileObject, &event, &iosb );
+    irp = TdiBuildInternalDeviceControlIrp(TDI_ASSOCIATE_ADDRESS, devObj, connectionFileObject, &event, &iosb);
 
-  if ( irp == NULL )
+    if (irp == NULL)
     {
-      return STATUS_INSUFFICIENT_RESOURCES;
+        return STATUS_INSUFFICIENT_RESOURCES;
     }
 
-  TdiBuildAssociateAddress ( irp, devObj, connectionFileObject, NULL, NULL,
-                            addressHandle );
+    TdiBuildAssociateAddress(irp, devObj, connectionFileObject, NULL, NULL, addressHandle);
 
-  status = IoCallDriver ( devObj, irp );
+    status = IoCallDriver(devObj, irp);
 
-  if ( status == STATUS_PENDING )
+    if (status == STATUS_PENDING)
     {
-      KeWaitForSingleObject ( &event, Executive, KernelMode, FALSE, NULL );
-      status = iosb.Status;
+        KeWaitForSingleObject(&event, Executive, KernelMode, FALSE, NULL);
+        status = iosb.Status;
     }
 
-  return status;
+    return status;
 }
 
-NTSTATUS
-tdi_disassociate_address (
-  PFILE_OBJECT connectionFileObject
- )
+NTSTATUS tdi_disassociate_address(PFILE_OBJECT connectionFileObject)
 {
-  PDEVICE_OBJECT devObj;
-  KEVENT event;
-  PIRP irp;
-  IO_STATUS_BLOCK iosb;
-  NTSTATUS status;
+    PDEVICE_OBJECT  devObj;
+    KEVENT          event;
+    PIRP            irp;
+    IO_STATUS_BLOCK iosb;
+    NTSTATUS        status;
 
-  devObj = IoGetRelatedDeviceObject ( connectionFileObject );
+    devObj = IoGetRelatedDeviceObject(connectionFileObject);
 
-  KeInitializeEvent ( &event, NotificationEvent, FALSE );
+    KeInitializeEvent(&event, NotificationEvent, FALSE);
 
-  irp =
-    TdiBuildInternalDeviceControlIrp ( TDI_DISASSOCIATE_ADDRESS, devObj,
-                                      connectionFileObject, &event, &iosb );
+    irp = TdiBuildInternalDeviceControlIrp(TDI_DISASSOCIATE_ADDRESS, devObj, connectionFileObject, &event, &iosb);
 
-  if ( irp == NULL )
+    if (irp == NULL)
     {
-      return STATUS_INSUFFICIENT_RESOURCES;
+        return STATUS_INSUFFICIENT_RESOURCES;
     }
 
-  TdiBuildDisassociateAddress ( irp, devObj, connectionFileObject, NULL,
-                               NULL );
+    TdiBuildDisassociateAddress(irp, devObj, connectionFileObject, NULL, NULL);
 
-  status = IoCallDriver ( devObj, irp );
+    status = IoCallDriver(devObj, irp);
 
-  if ( status == STATUS_PENDING )
+    if (status == STATUS_PENDING)
     {
-      KeWaitForSingleObject ( &event, Executive, KernelMode, FALSE, NULL );
-      status = iosb.Status;
+        KeWaitForSingleObject(&event, Executive, KernelMode, FALSE, NULL);
+        status = iosb.Status;
     }
 
-  return status;
+    return status;
 }
 
-NTSTATUS
-tdi_connect (
-  PFILE_OBJECT connectionFileObject,
-  ULONG addr,
-  USHORT port
- )
+NTSTATUS tdi_connect(PFILE_OBJECT connectionFileObject, ULONG addr, USHORT port)
 {
-  PDEVICE_OBJECT devObj;
-  KEVENT event;
-  PTDI_CONNECTION_INFORMATION remoteInfo;
-  PTA_IP_ADDRESS remoteAddr;
-  PTDI_CONNECTION_INFORMATION returnInfo;
-  PTA_IP_ADDRESS returnAddr;
-  PIRP irp;
-  IO_STATUS_BLOCK iosb;
-  NTSTATUS status;
+    PDEVICE_OBJECT              devObj;
+    KEVENT                      event;
+    PTDI_CONNECTION_INFORMATION remoteInfo;
+    PTA_IP_ADDRESS              remoteAddr;
+    PTDI_CONNECTION_INFORMATION returnInfo;
+    PTA_IP_ADDRESS              returnAddr;
+    PIRP                        irp;
+    IO_STATUS_BLOCK             iosb;
+    NTSTATUS                    status;
 
-  devObj = IoGetRelatedDeviceObject ( connectionFileObject );
+    devObj = IoGetRelatedDeviceObject(connectionFileObject);
 
-  KeInitializeEvent ( &event, NotificationEvent, FALSE );
+    KeInitializeEvent(&event, NotificationEvent, FALSE);
 
-  remoteInfo =
-    ( PTDI_CONNECTION_INFORMATION ) ExAllocatePool ( NonPagedPool,
-                                                    2 *
-                                                    sizeof
-                                                    ( TDI_CONNECTION_INFORMATION )
-                                                    +
-                                                    2 *
-                                                    sizeof
-                                                    ( TA_IP_ADDRESS ) );
+    remoteInfo = (PTDI_CONNECTION_INFORMATION) ExAllocatePool(NonPagedPool, 2 * sizeof(TDI_CONNECTION_INFORMATION) + 2 * sizeof(TA_IP_ADDRESS));
 
-  if ( remoteInfo == NULL )
+    if (remoteInfo == NULL)
     {
-      return STATUS_INSUFFICIENT_RESOURCES;
+        return STATUS_INSUFFICIENT_RESOURCES;
     }
 
-  RtlZeroMemory ( remoteInfo,
-                 2 * sizeof ( TDI_CONNECTION_INFORMATION ) +
-                 2 * sizeof ( TA_IP_ADDRESS ) );
+    RtlZeroMemory(remoteInfo, 2 * sizeof(TDI_CONNECTION_INFORMATION) + 2 * sizeof(TA_IP_ADDRESS));
 
-  remoteInfo->RemoteAddressLength = sizeof ( TA_IP_ADDRESS );
-  remoteInfo->RemoteAddress =
-    ( PUCHAR ) remoteInfo + sizeof ( TDI_CONNECTION_INFORMATION );
+    remoteInfo->RemoteAddressLength = sizeof(TA_IP_ADDRESS);
+    remoteInfo->RemoteAddress = (PUCHAR)remoteInfo + sizeof(TDI_CONNECTION_INFORMATION);
 
-  remoteAddr = ( PTA_IP_ADDRESS ) remoteInfo->RemoteAddress;
+    remoteAddr = (PTA_IP_ADDRESS) remoteInfo->RemoteAddress;
 
-  remoteAddr->TAAddressCount = 1;
-  remoteAddr->Address[0].AddressLength = TDI_ADDRESS_LENGTH_IP;
-  remoteAddr->Address[0].AddressType = TDI_ADDRESS_TYPE_IP;
-  remoteAddr->Address[0].Address[0].sin_port = port;
-  remoteAddr->Address[0].Address[0].in_addr = addr;
+    remoteAddr->TAAddressCount = 1;
+    remoteAddr->Address[0].AddressLength = TDI_ADDRESS_LENGTH_IP;
+    remoteAddr->Address[0].AddressType = TDI_ADDRESS_TYPE_IP;
+    remoteAddr->Address[0].Address[0].sin_port = port;
+    remoteAddr->Address[0].Address[0].in_addr = addr;
 
-  returnInfo =
-    ( PTDI_CONNECTION_INFORMATION ) ( ( PUCHAR ) remoteInfo +
-                                     sizeof ( TDI_CONNECTION_INFORMATION ) +
-                                     sizeof ( TA_IP_ADDRESS ) );
+    returnInfo = (PTDI_CONNECTION_INFORMATION)((PUCHAR)remoteInfo + sizeof(TDI_CONNECTION_INFORMATION) + sizeof(TA_IP_ADDRESS));
 
-  returnInfo->RemoteAddressLength = sizeof ( TA_IP_ADDRESS );
-  returnInfo->RemoteAddress =
-    ( PUCHAR ) returnInfo + sizeof ( TDI_CONNECTION_INFORMATION );
+    returnInfo->RemoteAddressLength = sizeof(TA_IP_ADDRESS);
+    returnInfo->RemoteAddress = (PUCHAR)returnInfo + sizeof(TDI_CONNECTION_INFORMATION);
 
-  returnAddr = ( PTA_IP_ADDRESS ) returnInfo->RemoteAddress;
+    returnAddr = (PTA_IP_ADDRESS) returnInfo->RemoteAddress;
 
-  returnAddr->TAAddressCount = 1;
-  returnAddr->Address[0].AddressLength = TDI_ADDRESS_LENGTH_IP;
-  returnAddr->Address[0].AddressType = TDI_ADDRESS_TYPE_IP;
+    returnAddr->TAAddressCount = 1;
+    returnAddr->Address[0].AddressLength = TDI_ADDRESS_LENGTH_IP;
+    returnAddr->Address[0].AddressType = TDI_ADDRESS_TYPE_IP;
 
-  irp =
-    TdiBuildInternalDeviceControlIrp ( TDI_CONNECT, devObj,
-                                      connectionFileObject, &event, &iosb );
+    irp = TdiBuildInternalDeviceControlIrp(TDI_CONNECT, devObj, connectionFileObject, &event, &iosb);
 
-  if ( irp == NULL )
+    if (irp == NULL)
     {
-      ExFreePool ( remoteInfo );
-      return STATUS_INSUFFICIENT_RESOURCES;
+        ExFreePool(remoteInfo);
+        return STATUS_INSUFFICIENT_RESOURCES;
     }
 
-  TdiBuildConnect ( irp, devObj, connectionFileObject, NULL, NULL, NULL,
-                   remoteInfo, returnInfo );
+    TdiBuildConnect(irp, devObj, connectionFileObject, NULL, NULL, NULL, remoteInfo, returnInfo);
 
-  status = IoCallDriver ( devObj, irp );
+    status = IoCallDriver(devObj, irp);
 
-  if ( status == STATUS_PENDING )
+    if (status == STATUS_PENDING)
     {
-      KeWaitForSingleObject ( &event, Executive, KernelMode, FALSE, NULL );
-      status = iosb.Status;
+        KeWaitForSingleObject(&event, Executive, KernelMode, FALSE, NULL);
+        status = iosb.Status;
     }
 
-  ExFreePool ( remoteInfo );
+    ExFreePool(remoteInfo);
 
-  return status;
+    return status;
 }
 
-NTSTATUS
-tdi_disconnect (
-  PFILE_OBJECT connectionFileObject,
-  ULONG flags
- )
+NTSTATUS tdi_disconnect(PFILE_OBJECT connectionFileObject, ULONG flags)
 {
-  PDEVICE_OBJECT devObj;
-  KEVENT event;
-  PIRP irp;
-  IO_STATUS_BLOCK iosb;
-  NTSTATUS status;
+    PDEVICE_OBJECT  devObj;
+    KEVENT          event;
+    PIRP            irp;
+    IO_STATUS_BLOCK iosb;
+    NTSTATUS        status;
 
-  devObj = IoGetRelatedDeviceObject ( connectionFileObject );
+    devObj = IoGetRelatedDeviceObject(connectionFileObject);
 
-  KeInitializeEvent ( &event, NotificationEvent, FALSE );
+    KeInitializeEvent(&event, NotificationEvent, FALSE);
 
-  irp =
-    TdiBuildInternalDeviceControlIrp ( TDI_DISCONNECT, devObj,
-                                      connectionFileObject, &event, &iosb );
+    irp = TdiBuildInternalDeviceControlIrp(TDI_DISCONNECT, devObj, connectionFileObject, &event, &iosb);
 
-  if ( irp == NULL )
+    if (irp == NULL)
     {
-      return STATUS_INSUFFICIENT_RESOURCES;
+        return STATUS_INSUFFICIENT_RESOURCES;
     }
 
-  TdiBuildDisconnect ( irp, devObj, connectionFileObject, NULL, NULL, NULL,
-                      flags, NULL, NULL );
+    TdiBuildDisconnect(irp, devObj, connectionFileObject, NULL, NULL, NULL, flags, NULL, NULL);
 
-  status = IoCallDriver ( devObj, irp );
+    status = IoCallDriver(devObj, irp);
 
-  if ( status == STATUS_PENDING )
+    if (status == STATUS_PENDING)
     {
-      KeWaitForSingleObject ( &event, Executive, KernelMode, FALSE, NULL );
-      status = iosb.Status;
+        KeWaitForSingleObject(&event, Executive, KernelMode, FALSE, NULL);
+        status = iosb.Status;
     }
 
-  return status;
+    return status;
 }
 
-NTSTATUS
-tdi_send_dgram (
-  PFILE_OBJECT addressFileObject,
-  ULONG addr,
-  USHORT port,
-  const char *buf,
-  int len
- )
+NTSTATUS tdi_send_dgram(PFILE_OBJECT addressFileObject, ULONG addr, USHORT port, const char *buf, int len)
 {
-  PDEVICE_OBJECT devObj;
-  KEVENT event;
-  PTDI_CONNECTION_INFORMATION remoteInfo;
-  PTA_IP_ADDRESS remoteAddr;
-  PIRP irp;
-  PMDL mdl;
-  IO_STATUS_BLOCK iosb;
-  NTSTATUS status;
+    PDEVICE_OBJECT              devObj;
+    KEVENT                      event;
+    PTDI_CONNECTION_INFORMATION remoteInfo;
+    PTA_IP_ADDRESS              remoteAddr;
+    PIRP                        irp;
+    PMDL                        mdl;
+    IO_STATUS_BLOCK             iosb;
+    NTSTATUS                    status;
 
-  devObj = IoGetRelatedDeviceObject ( addressFileObject );
+    devObj = IoGetRelatedDeviceObject(addressFileObject);
 
-  KeInitializeEvent ( &event, NotificationEvent, FALSE );
+    KeInitializeEvent(&event, NotificationEvent, FALSE);
 
-  remoteInfo =
-    ( PTDI_CONNECTION_INFORMATION ) ExAllocatePool ( NonPagedPool,
-                                                    sizeof
-                                                    ( TDI_CONNECTION_INFORMATION )
-                                                    +
-                                                    sizeof
-                                                    ( TA_IP_ADDRESS ) );
+    remoteInfo = (PTDI_CONNECTION_INFORMATION) ExAllocatePool(NonPagedPool, sizeof(TDI_CONNECTION_INFORMATION) + sizeof(TA_IP_ADDRESS));
 
-  if ( remoteInfo == NULL )
+    if (remoteInfo == NULL)
     {
-      return STATUS_INSUFFICIENT_RESOURCES;
+        return STATUS_INSUFFICIENT_RESOURCES;
     }
 
-  RtlZeroMemory ( remoteInfo,
-                 sizeof ( TDI_CONNECTION_INFORMATION ) +
-                 sizeof ( TA_IP_ADDRESS ) );
+    RtlZeroMemory(remoteInfo, sizeof(TDI_CONNECTION_INFORMATION) + sizeof(TA_IP_ADDRESS));
 
-  remoteInfo->RemoteAddressLength = sizeof ( TA_IP_ADDRESS );
-  remoteInfo->RemoteAddress =
-    ( PUCHAR ) remoteInfo + sizeof ( TDI_CONNECTION_INFORMATION );
+    remoteInfo->RemoteAddressLength = sizeof(TA_IP_ADDRESS);
+    remoteInfo->RemoteAddress = (PUCHAR)remoteInfo + sizeof(TDI_CONNECTION_INFORMATION);
 
-  remoteAddr = ( PTA_IP_ADDRESS ) remoteInfo->RemoteAddress;
+    remoteAddr = (PTA_IP_ADDRESS) remoteInfo->RemoteAddress;
 
-  remoteAddr->TAAddressCount = 1;
-  remoteAddr->Address[0].AddressLength = TDI_ADDRESS_LENGTH_IP;
-  remoteAddr->Address[0].AddressType = TDI_ADDRESS_TYPE_IP;
-  remoteAddr->Address[0].Address[0].sin_port = port;
-  remoteAddr->Address[0].Address[0].in_addr = addr;
+    remoteAddr->TAAddressCount = 1;
+    remoteAddr->Address[0].AddressLength = TDI_ADDRESS_LENGTH_IP;
+    remoteAddr->Address[0].AddressType = TDI_ADDRESS_TYPE_IP;
+    remoteAddr->Address[0].Address[0].sin_port = port;
+    remoteAddr->Address[0].Address[0].in_addr = addr;
 
-  irp =
-    TdiBuildInternalDeviceControlIrp ( TDI_SEND_DATAGRAM, devObj,
-                                      addressFileObject, &event, &iosb );
+    irp = TdiBuildInternalDeviceControlIrp(TDI_SEND_DATAGRAM, devObj, addressFileObject, &event, &iosb);
 
-  if ( irp == NULL )
+    if (irp == NULL)
     {
-      ExFreePool ( remoteInfo );
-      return STATUS_INSUFFICIENT_RESOURCES;
+        ExFreePool(remoteInfo);
+        return STATUS_INSUFFICIENT_RESOURCES;
     }
 
-  if ( len )
+    if (len)
     {
-      mdl = IoAllocateMdl ( ( void * )buf, len, FALSE, FALSE, NULL );
+        mdl = IoAllocateMdl((void*) buf, len, FALSE, FALSE, NULL);
 
-      if ( mdl == NULL )
-       {
-         IoFreeIrp ( irp );
-         ExFreePool ( remoteInfo );
-         return STATUS_INSUFFICIENT_RESOURCES;
-       }
+        if (mdl == NULL)
+        {
+            IoFreeIrp(irp);
+            ExFreePool(remoteInfo);
+            return STATUS_INSUFFICIENT_RESOURCES;
+        }
 
-      __try
-      {
-       MmProbeAndLockPages ( mdl, KernelMode, IoReadAccess );
-       status = STATUS_SUCCESS;
-      }
-      __except ( EXCEPTION_EXECUTE_HANDLER )
-      {
-       IoFreeMdl ( mdl );
-       IoFreeIrp ( irp );
-       ExFreePool ( remoteInfo );
-       status = STATUS_INVALID_USER_BUFFER;
-      }
+        __try
+        {
+            MmProbeAndLockPages(mdl, KernelMode, IoReadAccess);
+            status = STATUS_SUCCESS;
+        }
+        __except (EXCEPTION_EXECUTE_HANDLER)
+        {
+            IoFreeMdl(mdl);
+            IoFreeIrp(irp);
+            ExFreePool(remoteInfo);
+            status = STATUS_INVALID_USER_BUFFER;
+        }
 
-      if ( !NT_SUCCESS ( status ) )
-       {
-         return status;
-       }
+        if (!NT_SUCCESS(status))
+        {
+            return status;
+        }
     }
 
-  TdiBuildSendDatagram ( irp, devObj, addressFileObject, NULL, NULL,
-                        len ? mdl : 0, len, remoteInfo );
+    TdiBuildSendDatagram(irp, devObj, addressFileObject, NULL, NULL, len ? mdl : 0, len, remoteInfo);
 
-  status = IoCallDriver ( devObj, irp );
+    status = IoCallDriver(devObj, irp);
 
-  if ( status == STATUS_PENDING )
+    if (status == STATUS_PENDING)
     {
-      KeWaitForSingleObject ( &event, Executive, KernelMode, FALSE, NULL );
-      status = iosb.Status;
+        KeWaitForSingleObject(&event, Executive, KernelMode, FALSE, NULL);
+        status = iosb.Status;
     }
 
-  ExFreePool ( remoteInfo );
+    ExFreePool(remoteInfo);
 
-  return NT_SUCCESS ( status ) ? iosb.Information : status;
+    return NT_SUCCESS(status) ? iosb.Information : status;
 }
 
-NTSTATUS
-tdi_recv_dgram (
-  PFILE_OBJECT addressFileObject,
-  PULONG addr,
-  PUSHORT port,
-  char *buf,
-  int len,
-  ULONG flags
- )
+NTSTATUS tdi_recv_dgram(PFILE_OBJECT addressFileObject, PULONG addr, PUSHORT port, char *buf, int len, ULONG flags)
 {
-  PDEVICE_OBJECT devObj;
-  KEVENT event;
-  PTDI_CONNECTION_INFORMATION remoteInfo;
-  PTDI_CONNECTION_INFORMATION returnInfo;
-  PTA_IP_ADDRESS returnAddr;
-  PIRP irp;
-  PMDL mdl;
-  IO_STATUS_BLOCK iosb;
-  NTSTATUS status;
+    PDEVICE_OBJECT              devObj;
+    KEVENT                      event;
+    PTDI_CONNECTION_INFORMATION remoteInfo;
+    PTDI_CONNECTION_INFORMATION returnInfo;
+    PTA_IP_ADDRESS              returnAddr;
+    PIRP                        irp;
+    PMDL                        mdl;
+    IO_STATUS_BLOCK             iosb;
+    NTSTATUS                    status;
 
-  devObj = IoGetRelatedDeviceObject ( addressFileObject );
+    devObj = IoGetRelatedDeviceObject(addressFileObject);
 
-  KeInitializeEvent ( &event, NotificationEvent, FALSE );
+    KeInitializeEvent(&event, NotificationEvent, FALSE);
 
-  remoteInfo =
-    ( PTDI_CONNECTION_INFORMATION ) ExAllocatePool ( NonPagedPool,
-                                                    2 *
-                                                    sizeof
-                                                    ( TDI_CONNECTION_INFORMATION )
-                                                    +
-                                                    sizeof
-                                                    ( TA_IP_ADDRESS ) );
+    remoteInfo = (PTDI_CONNECTION_INFORMATION) ExAllocatePool(NonPagedPool, 2 * sizeof(TDI_CONNECTION_INFORMATION) + sizeof(TA_IP_ADDRESS));
 
-  if ( remoteInfo == NULL )
+    if (remoteInfo == NULL)
     {
-      return STATUS_INSUFFICIENT_RESOURCES;
+        return STATUS_INSUFFICIENT_RESOURCES;
     }
 
-  RtlZeroMemory ( remoteInfo,
-                 2 * sizeof ( TDI_CONNECTION_INFORMATION ) +
-                 sizeof ( TA_IP_ADDRESS ) );
+    RtlZeroMemory(remoteInfo, 2 * sizeof(TDI_CONNECTION_INFORMATION) + sizeof(TA_IP_ADDRESS));
 
-  remoteInfo->RemoteAddressLength = 0;
-  remoteInfo->RemoteAddress = NULL;
+    remoteInfo->RemoteAddressLength = 0;
+    remoteInfo->RemoteAddress = NULL;
 
-  returnInfo =
-    ( PTDI_CONNECTION_INFORMATION ) ( ( PUCHAR ) remoteInfo +
-                                     sizeof ( TDI_CONNECTION_INFORMATION ) );
+    returnInfo = (PTDI_CONNECTION_INFORMATION)((PUCHAR)remoteInfo + sizeof(TDI_CONNECTION_INFORMATION));
 
-  returnInfo->RemoteAddressLength = sizeof ( TA_IP_ADDRESS );
-  returnInfo->RemoteAddress =
-    ( PUCHAR ) returnInfo + sizeof ( TDI_CONNECTION_INFORMATION );
+    returnInfo->RemoteAddressLength = sizeof(TA_IP_ADDRESS);
+    returnInfo->RemoteAddress = (PUCHAR)returnInfo + sizeof(TDI_CONNECTION_INFORMATION);
 
-  returnAddr = ( PTA_IP_ADDRESS ) returnInfo->RemoteAddress;
+    returnAddr = (PTA_IP_ADDRESS) returnInfo->RemoteAddress;
 
-  returnAddr->TAAddressCount = 1;
-  returnAddr->Address[0].AddressLength = TDI_ADDRESS_LENGTH_IP;
-  returnAddr->Address[0].AddressType = TDI_ADDRESS_TYPE_IP;
+    returnAddr->TAAddressCount = 1;
+    returnAddr->Address[0].AddressLength = TDI_ADDRESS_LENGTH_IP;
+    returnAddr->Address[0].AddressType = TDI_ADDRESS_TYPE_IP;
 
-  irp =
-    TdiBuildInternalDeviceControlIrp ( TDI_RECEIVE_DATAGRAM, devObj,
-                                      addressFileObject, &event, &iosb );
+    irp = TdiBuildInternalDeviceControlIrp(TDI_RECEIVE_DATAGRAM, devObj, addressFileObject, &event, &iosb);
 
-  if ( irp == NULL )
+    if (irp == NULL)
     {
-      ExFreePool ( remoteInfo );
-      return STATUS_INSUFFICIENT_RESOURCES;
+        ExFreePool(remoteInfo);
+        return STATUS_INSUFFICIENT_RESOURCES;
     }
 
-  if ( len )
+    if (len)
     {
-      mdl = IoAllocateMdl ( ( void * )buf, len, FALSE, FALSE, NULL );
+        mdl = IoAllocateMdl((void*) buf, len, FALSE, FALSE, NULL);
 
-      if ( mdl == NULL )
-       {
-         IoFreeIrp ( irp );
-         ExFreePool ( remoteInfo );
-         return STATUS_INSUFFICIENT_RESOURCES;
-       }
+        if (mdl == NULL)
+        {
+            IoFreeIrp(irp);
+            ExFreePool(remoteInfo);
+            return STATUS_INSUFFICIENT_RESOURCES;
+        }
 
-      __try
-      {
-       MmProbeAndLockPages ( mdl, KernelMode, IoWriteAccess );
-       status = STATUS_SUCCESS;
-      }
-      __except ( EXCEPTION_EXECUTE_HANDLER )
-      {
-       IoFreeMdl ( mdl );
-       IoFreeIrp ( irp );
-       ExFreePool ( remoteInfo );
-       status = STATUS_INVALID_USER_BUFFER;
-      }
+        __try
+        {
+            MmProbeAndLockPages(mdl, KernelMode, IoWriteAccess);
+            status = STATUS_SUCCESS;
+        }
+        __except (EXCEPTION_EXECUTE_HANDLER)
+        {
+            IoFreeMdl(mdl);
+            IoFreeIrp(irp);
+            ExFreePool(remoteInfo);
+            status = STATUS_INVALID_USER_BUFFER;
+        }
 
-      if ( !NT_SUCCESS ( status ) )
-       {
-         return status;
-       }
+        if (!NT_SUCCESS(status))
+        {
+            return status;
+        }
     }
 
-  TdiBuildReceiveDatagram ( irp, devObj, addressFileObject, NULL, NULL,
-                           len ? mdl : 0, len, remoteInfo, returnInfo,
-                           flags );
+    TdiBuildReceiveDatagram(irp, devObj, addressFileObject, NULL, NULL, len ? mdl : 0, len, remoteInfo, returnInfo, flags);
 
-  status = IoCallDriver ( devObj, irp );
+    status = IoCallDriver(devObj, irp);
 
-  if ( status == STATUS_PENDING )
+    if (status == STATUS_PENDING)
     {
-      KeWaitForSingleObject ( &event, Executive, KernelMode, FALSE, NULL );
-      status = iosb.Status;
+        KeWaitForSingleObject(&event, Executive, KernelMode, FALSE, NULL);
+        status = iosb.Status;
     }
 
-  if ( addr )
+    if (addr)
     {
-      *addr = returnAddr->Address[0].Address[0].in_addr;
+        *addr = returnAddr->Address[0].Address[0].in_addr;
     }
 
-  if ( port )
+    if (port)
     {
-      *port = returnAddr->Address[0].Address[0].sin_port;
+        *port = returnAddr->Address[0].Address[0].sin_port;
     }
 
-  ExFreePool ( remoteInfo );
+    ExFreePool(remoteInfo);
 
-  return NT_SUCCESS ( status ) ? iosb.Information : status;
+    return NT_SUCCESS(status) ? iosb.Information : status;
 }
 
-NTSTATUS
-tdi_send_stream (
-  PFILE_OBJECT connectionFileObject,
-  const char *buf,
-  int len,
-  ULONG flags
- )
+NTSTATUS tdi_send_stream(PFILE_OBJECT connectionFileObject, const char *buf, int len, ULONG flags)
 {
-  PDEVICE_OBJECT devObj;
-  KEVENT event;
-  PIRP irp;
-  PMDL mdl;
-  IO_STATUS_BLOCK iosb;
-  NTSTATUS status;
+    PDEVICE_OBJECT  devObj;
+    KEVENT          event;
+    PIRP            irp;
+    PMDL            mdl;
+    IO_STATUS_BLOCK iosb;
+    NTSTATUS        status;
 
-  devObj = IoGetRelatedDeviceObject ( connectionFileObject );
+    devObj = IoGetRelatedDeviceObject(connectionFileObject);
 
-  KeInitializeEvent ( &event, NotificationEvent, FALSE );
+    KeInitializeEvent(&event, NotificationEvent, FALSE);
 
-  irp =
-    TdiBuildInternalDeviceControlIrp ( TDI_SEND, devObj, connectionFileObject,
-                                      &event, &iosb );
+    irp = TdiBuildInternalDeviceControlIrp(TDI_SEND, devObj, connectionFileObject, &event, &iosb);
 
-  if ( irp == NULL )
+    if (irp == NULL)
     {
-      return STATUS_INSUFFICIENT_RESOURCES;
+        return STATUS_INSUFFICIENT_RESOURCES;
     }
 
-  if ( len )
+    if (len)
     {
-      mdl = IoAllocateMdl ( ( void * )buf, len, FALSE, FALSE, NULL );
+        mdl = IoAllocateMdl((void*) buf, len, FALSE, FALSE, NULL);
 
-      if ( mdl == NULL )
-       {
-         IoFreeIrp ( irp );
-         return STATUS_INSUFFICIENT_RESOURCES;
-       }
+        if (mdl == NULL)
+        {
+            IoFreeIrp(irp);
+            return STATUS_INSUFFICIENT_RESOURCES;
+        }
 
-      __try
-      {
-       MmProbeAndLockPages ( mdl, KernelMode, IoReadAccess );
-       status = STATUS_SUCCESS;
-      }
-      __except ( EXCEPTION_EXECUTE_HANDLER )
-      {
-       IoFreeMdl ( mdl );
-       IoFreeIrp ( irp );
-       status = STATUS_INVALID_USER_BUFFER;
-      }
+        __try
+        {
+            MmProbeAndLockPages(mdl, KernelMode, IoReadAccess);
+            status = STATUS_SUCCESS;
+        }
+        __except (EXCEPTION_EXECUTE_HANDLER)
+        {
+            IoFreeMdl(mdl);
+            IoFreeIrp(irp);
+            status = STATUS_INVALID_USER_BUFFER;
+        }
 
-      if ( !NT_SUCCESS ( status ) )
-       {
-         return status;
-       }
+        if (!NT_SUCCESS(status))
+        {
+            return status;
+        }
     }
 
-  TdiBuildSend ( irp, devObj, connectionFileObject, NULL, NULL, len ? mdl : 0,
-                flags, len );
+    TdiBuildSend(irp, devObj, connectionFileObject, NULL, NULL, len ? mdl : 0, flags, len);
 
-  status = IoCallDriver ( devObj, irp );
+    status = IoCallDriver(devObj, irp);
 
-  if ( status == STATUS_PENDING )
+    if (status == STATUS_PENDING)
     {
-      KeWaitForSingleObject ( &event, Executive, KernelMode, FALSE, NULL );
-      status = iosb.Status;
+        KeWaitForSingleObject(&event, Executive, KernelMode, FALSE, NULL);
+        status = iosb.Status;
     }
 
-  return NT_SUCCESS ( status ) ? iosb.Information : status;
+    return NT_SUCCESS(status) ? iosb.Information : status;
 }
 
-NTSTATUS
-tdi_recv_stream (
-  PFILE_OBJECT connectionFileObject,
-  char *buf,
-  int len,
-  ULONG flags
- )
+NTSTATUS tdi_recv_stream(PFILE_OBJECT connectionFileObject, char *buf, int len, ULONG flags)
 {
-  PDEVICE_OBJECT devObj;
-  KEVENT event;
-  PIRP irp;
-  PMDL mdl;
-  IO_STATUS_BLOCK iosb;
-  NTSTATUS status;
+    PDEVICE_OBJECT  devObj;
+    KEVENT          event;
+    PIRP            irp;
+    PMDL            mdl;
+    IO_STATUS_BLOCK iosb;
+    NTSTATUS        status;
 
-  devObj = IoGetRelatedDeviceObject ( connectionFileObject );
+    devObj = IoGetRelatedDeviceObject(connectionFileObject);
 
-  KeInitializeEvent ( &event, NotificationEvent, FALSE );
+    KeInitializeEvent(&event, NotificationEvent, FALSE);
 
-  irp =
-    TdiBuildInternalDeviceControlIrp ( TDI_RECEIVE, devObj,
-                                      connectionFileObject, &event, &iosb );
+    irp = TdiBuildInternalDeviceControlIrp(TDI_RECEIVE, devObj, connectionFileObject, &event, &iosb);
 
-  if ( irp == NULL )
+    if (irp == NULL)
     {
-      return STATUS_INSUFFICIENT_RESOURCES;
+        return STATUS_INSUFFICIENT_RESOURCES;
     }
 
-  if ( len )
+    if (len)
     {
-      mdl = IoAllocateMdl ( ( void * )buf, len, FALSE, FALSE, NULL );
+        mdl = IoAllocateMdl((void*) buf, len, FALSE, FALSE, NULL);
 
-      if ( mdl == NULL )
-       {
-         IoFreeIrp ( irp );
-         return STATUS_INSUFFICIENT_RESOURCES;
-       }
+        if (mdl == NULL)
+        {
+            IoFreeIrp(irp);
+            return STATUS_INSUFFICIENT_RESOURCES;
+        }
 
-      __try
-      {
-       MmProbeAndLockPages ( mdl, KernelMode, IoWriteAccess );
-       status = STATUS_SUCCESS;
-      }
-      __except ( EXCEPTION_EXECUTE_HANDLER )
-      {
-       IoFreeMdl ( mdl );
-       IoFreeIrp ( irp );
-       status = STATUS_INVALID_USER_BUFFER;
-      }
+        __try
+        {
+            MmProbeAndLockPages(mdl, KernelMode, IoWriteAccess);
+            status = STATUS_SUCCESS;
+        }
+        __except (EXCEPTION_EXECUTE_HANDLER)
+        {
+            IoFreeMdl(mdl);
+            IoFreeIrp(irp);
+            status = STATUS_INVALID_USER_BUFFER;
+        }
 
-      if ( !NT_SUCCESS ( status ) )
-       {
-         return status;
-       }
+        if (!NT_SUCCESS(status))
+        {
+            return status;
+        }
     }
 
-  TdiBuildReceive ( irp, devObj, connectionFileObject, NULL, NULL,
-                   len ? mdl : 0, flags, len );
+    TdiBuildReceive(irp, devObj, connectionFileObject, NULL, NULL, len ? mdl : 0, flags, len);
 
-  status = IoCallDriver ( devObj, irp );
+    status = IoCallDriver(devObj, irp);
 
-  if ( status == STATUS_PENDING )
+    if (status == STATUS_PENDING)
     {
-      KeWaitForSingleObject ( &event, Executive, KernelMode, FALSE, NULL );
-      status = iosb.Status;
+        KeWaitForSingleObject(&event, Executive, KernelMode, FALSE, NULL);
+        status = iosb.Status;
     }
 
-  return NT_SUCCESS ( status ) ? iosb.Information : status;
+    return NT_SUCCESS(status) ? iosb.Information : status;
 }
 
-NTSTATUS
-tdi_query_address (
-  PFILE_OBJECT addressFileObject,
-  PULONG addr,
-  PUSHORT port
- )
+NTSTATUS tdi_query_address(PFILE_OBJECT addressFileObject, PULONG addr, PUSHORT port)
 {
-  PDEVICE_OBJECT devObj;
-  KEVENT event;
-  PTRANSPORT_ADDRESS localInfo;
-  PTA_IP_ADDRESS localAddr;
-  PIRP irp;
-  PMDL mdl;
-  IO_STATUS_BLOCK iosb;
-  NTSTATUS status;
+    PDEVICE_OBJECT              devObj;
+    KEVENT                      event;
+    PTRANSPORT_ADDRESS          localInfo;
+    PTA_IP_ADDRESS              localAddr;
+    PIRP                        irp;
+    PMDL                        mdl;
+    IO_STATUS_BLOCK             iosb;
+    NTSTATUS                    status;
 
-  devObj = IoGetRelatedDeviceObject ( addressFileObject );
+    devObj = IoGetRelatedDeviceObject(addressFileObject);
 
-  KeInitializeEvent ( &event, NotificationEvent, FALSE );
+    KeInitializeEvent(&event, NotificationEvent, FALSE);
 
-  localInfo =
-    ( PTRANSPORT_ADDRESS ) ExAllocatePool ( NonPagedPool,
-                                           sizeof ( TDI_ADDRESS_INFO ) * 10 );
+    localInfo = (PTRANSPORT_ADDRESS) ExAllocatePool(NonPagedPool, sizeof(TDI_ADDRESS_INFO)*10);
 
-  if ( localInfo == NULL )
+    if (localInfo == NULL)
     {
-      return STATUS_INSUFFICIENT_RESOURCES;
+        return STATUS_INSUFFICIENT_RESOURCES;
     }
 
-  RtlZeroMemory ( localInfo, sizeof ( TDI_ADDRESS_INFO ) * 10 );
+    RtlZeroMemory(localInfo, sizeof(TDI_ADDRESS_INFO)*10);
 
-  irp =
-    TdiBuildInternalDeviceControlIrp ( TDI_QUERY_INFORMATION, devObj,
-                                      addressFileObject, &event, &iosb );
+    irp = TdiBuildInternalDeviceControlIrp(TDI_QUERY_INFORMATION, devObj, addressFileObject, &event, &iosb);
 
-  if ( irp == NULL )
+    if (irp == NULL)
     {
-      ExFreePool ( localInfo );
-      return STATUS_INSUFFICIENT_RESOURCES;
+        ExFreePool(localInfo);
+        return STATUS_INSUFFICIENT_RESOURCES;
     }
 
-  {
-    mdl =
-      IoAllocateMdl ( ( void * )localInfo, sizeof ( TDI_ADDRESS_INFO ) * 10,
-                     FALSE, FALSE, NULL );
+    {
+        mdl = IoAllocateMdl((void*) localInfo, sizeof(TDI_ADDRESS_INFO)*10, FALSE, FALSE, NULL);
 
-    if ( mdl == NULL )
-      {
-       IoFreeIrp ( irp );
-       ExFreePool ( localInfo );
-       return STATUS_INSUFFICIENT_RESOURCES;
-      }
+        if (mdl == NULL)
+        {
+            IoFreeIrp(irp);
+            ExFreePool(localInfo);
+            return STATUS_INSUFFICIENT_RESOURCES;
+        }
 
-    __try
-    {
-      MmProbeAndLockPages ( mdl, KernelMode, IoWriteAccess );
-      status = STATUS_SUCCESS;
-    }
-    __except ( EXCEPTION_EXECUTE_HANDLER )
-    {
-      IoFreeMdl ( mdl );
-      IoFreeIrp ( irp );
-      ExFreePool ( localInfo );
-      status = STATUS_INVALID_USER_BUFFER;
-    }
+        __try
+        {
+            MmProbeAndLockPages(mdl, KernelMode, IoWriteAccess);
+            status = STATUS_SUCCESS;
+        }
+        __except (EXCEPTION_EXECUTE_HANDLER)
+        {
+            IoFreeMdl(mdl);
+            IoFreeIrp(irp);
+            ExFreePool(localInfo);
+            status = STATUS_INVALID_USER_BUFFER;
+        }
 
-    if ( !NT_SUCCESS ( status ) )
-      {
-       return status;
-      }
-  }
+        if (!NT_SUCCESS(status))
+        {
+            return status;
+        }
+    }
 
-  TdiBuildQueryInformation ( irp, devObj, addressFileObject, NULL, NULL,
-                            TDI_QUERY_ADDRESS_INFO, mdl );
+    TdiBuildQueryInformation(irp, devObj, addressFileObject, NULL, NULL, TDI_QUERY_ADDRESS_INFO, mdl);
 
-  status = IoCallDriver ( devObj, irp );
+    status = IoCallDriver(devObj, irp);
 
-  if ( status == STATUS_PENDING )
+    if (status == STATUS_PENDING)
     {
-      KeWaitForSingleObject ( &event, Executive, KernelMode, FALSE, NULL );
-      status = iosb.Status;
+        KeWaitForSingleObject(&event, Executive, KernelMode, FALSE, NULL);
+        status = iosb.Status;
     }
 
-  localAddr = ( PTA_IP_ADDRESS ) & localInfo->Address[0];
+    localAddr = (PTA_IP_ADDRESS)&localInfo->Address[0];
 
-  if ( addr )
+    if (addr)
     {
-      *addr = localAddr->Address[0].Address[0].in_addr;
+        *addr = localAddr->Address[0].Address[0].in_addr;
     }
 
-  if ( port )
+    if (port)
     {
-      *port = localAddr->Address[0].Address[0].sin_port;
+        *port = localAddr->Address[0].Address[0].sin_port;
     }
 
-  ExFreePool ( localInfo );
+    ExFreePool(localInfo);
 
-  return status;
+    return status;
 }
index 41155b2..09ec2e5 100644 (file)
     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */
 
-NTSTATUS tdi_open_transport_address (
-  PUNICODE_STRING devName,
-  ULONG addr,
-  USHORT port,
-  BOOLEAN shared,
-  PHANDLE addressHandle,
-  PFILE_OBJECT * addressFileObject
- );
-NTSTATUS tdi_open_connection_endpoint (
-  PUNICODE_STRING devName,
-  PVOID connectionContext,
-  BOOLEAN shared,
-  PHANDLE connectionHandle,
-  PFILE_OBJECT * connectionFileObject
- );
-NTSTATUS tdi_set_event_handler (
-  PFILE_OBJECT addressFileObject,
-  LONG eventType,
-  PVOID eventHandler,
-  PVOID eventContext
- );
-NTSTATUS tdi_unset_event_handler (
-  PFILE_OBJECT addressFileObject,
-  LONG eventType
- );
-NTSTATUS tdi_associate_address (
-  PFILE_OBJECT connectionFileObject,
-  HANDLE addressHandle
- );
-NTSTATUS tdi_disassociate_address (
-  PFILE_OBJECT connectionFileObject
- );
-NTSTATUS tdi_connect (
-  PFILE_OBJECT connectionFileObject,
-  ULONG addr,
-  USHORT port
- );
-NTSTATUS tdi_disconnect (
-  PFILE_OBJECT connectionFileObject,
-  ULONG flags
- );
-NTSTATUS tdi_send_dgram (
-  PFILE_OBJECT addressFileObject,
-  ULONG addr,
-  USHORT port,
-  const char *buf,
-  int len
- );
-NTSTATUS tdi_recv_dgram (
-  PFILE_OBJECT addressFileObject,
-  PULONG addr,
-  PUSHORT port,
-  char *buf,
-  int len,
-  ULONG flags
- );
-NTSTATUS tdi_send_stream (
-  PFILE_OBJECT connectionFileObject,
-  const char *buf,
-  int len,
-  ULONG flags
- );
-NTSTATUS tdi_recv_stream (
-  PFILE_OBJECT connectionFileObject,
-  char *buf,
-  int len,
-  ULONG flags
- );
-NTSTATUS tdi_query_address (
-  PFILE_OBJECT addressFileObject,
-  PULONG addr,
-  PUSHORT port
- );
+NTSTATUS tdi_open_transport_address(PUNICODE_STRING devName, ULONG addr, USHORT port, BOOLEAN shared, PHANDLE addressHandle, PFILE_OBJECT *addressFileObject);
+NTSTATUS tdi_open_connection_endpoint(PUNICODE_STRING devName, PVOID connectionContext, BOOLEAN shared, PHANDLE connectionHandle, PFILE_OBJECT *connectionFileObject);
+NTSTATUS tdi_set_event_handler(PFILE_OBJECT addressFileObject, LONG eventType, PVOID eventHandler, PVOID eventContext);
+NTSTATUS tdi_unset_event_handler(PFILE_OBJECT addressFileObject, LONG eventType);
+NTSTATUS tdi_associate_address(PFILE_OBJECT connectionFileObject, HANDLE addressHandle);
+NTSTATUS tdi_disassociate_address(PFILE_OBJECT connectionFileObject);
+NTSTATUS tdi_connect(PFILE_OBJECT connectionFileObject, ULONG addr, USHORT port);
+NTSTATUS tdi_disconnect(PFILE_OBJECT connectionFileObject, ULONG flags);
+NTSTATUS tdi_send_dgram(PFILE_OBJECT addressFileObject, ULONG addr, USHORT port, const char *buf, int len);
+NTSTATUS tdi_recv_dgram(PFILE_OBJECT addressFileObject, PULONG addr, PUSHORT port, char *buf, int len, ULONG flags);
+NTSTATUS tdi_send_stream(PFILE_OBJECT connectionFileObject, const char *buf, int len, ULONG flags);
+NTSTATUS tdi_recv_stream(PFILE_OBJECT connectionFileObject, char *buf, int len, ULONG flags);
+NTSTATUS tdi_query_address(PFILE_OBJECT addressFileObject, PULONG addr, PUSHORT port);
index 500955b..73a5e8e 100644 (file)
 #include <stdlib.h>
 #include "httpdisk.h"
 
-int
-HttpDiskSyntax (
-  void
- )
+int HttpDiskSyntax(void)
 {
-  fprintf ( stderr, "syntax:\n" );
-  fprintf ( stderr, "httpdisk /mount  <devicenumber> <url> [/cd] <drive:>\n" );
-  fprintf ( stderr, "httpdisk /umount <drive:>\n" );
-  fprintf ( stderr, "\n" );
-  fprintf ( stderr, "example:\n" );
-  fprintf ( stderr,
-           "httpdisk /mount  0 http://server.domain.com/path/diskimage.img d:\n" );
-  fprintf ( stderr,
-           "httpdisk /mount  1 http://server.domain.com/path/cdimage.iso /cd e:\n" );
-  fprintf ( stderr, "...\n" );
-  fprintf ( stderr, "httpdisk /umount d:\n" );
-  fprintf ( stderr, "httpdisk /umount e:\n" );
-
-  return -1;
+    fprintf(stderr, "syntax:\n");
+    fprintf(stderr, "httpdisk /mount  <devicenumber> <url> [/cd] <drive:>\n");
+    fprintf(stderr, "httpdisk /umount <drive:>\n");
+    fprintf(stderr, "\n");
+    fprintf(stderr, "example:\n");
+    fprintf(stderr, "httpdisk /mount  0 http://server.domain.com/path/diskimage.img d:\n");
+    fprintf(stderr, "httpdisk /mount  1 http://server.domain.com/path/cdimage.iso /cd e:\n");
+    fprintf(stderr, "...\n");
+    fprintf(stderr, "httpdisk /umount d:\n");
+    fprintf(stderr, "httpdisk /umount e:\n");
+
+    return -1;
 }
 
-void
-PrintLastError (
-  char *Prefix
- )
+void PrintLastError(char* Prefix)
 {
-  LPVOID lpMsgBuf;
-
-  FormatMessage ( FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM |
-                 FORMAT_MESSAGE_IGNORE_INSERTS, NULL, GetLastError (  ), 0,
-                 ( LPTSTR ) & lpMsgBuf, 0, NULL );
-
-  fprintf ( stderr, "%s: %s", Prefix, ( LPTSTR ) lpMsgBuf );
-
-  LocalFree ( lpMsgBuf );
+    LPVOID lpMsgBuf;
+
+    FormatMessage( 
+        FORMAT_MESSAGE_ALLOCATE_BUFFER |
+        FORMAT_MESSAGE_FROM_SYSTEM |
+        FORMAT_MESSAGE_IGNORE_INSERTS,
+        NULL,
+        GetLastError(),
+        0,
+        (LPTSTR) &lpMsgBuf,
+        0,
+        NULL
+        );
+
+    fprintf(stderr, "%s: %s", Prefix, (LPTSTR) lpMsgBuf);
+
+    LocalFree(lpMsgBuf);
 }
 
 int
-HttpDiskMount (
-  int DeviceNumber,
-  PHTTP_DISK_INFORMATION HttpDiskInformation,
-  char DriveLetter,
-  BOOLEAN CdImage
- )
+HttpDiskMount(
+    int                     DeviceNumber,
+    PHTTP_DISK_INFORMATION  HttpDiskInformation,
+    char                    DriveLetter,
+    BOOLEAN                 CdImage
+)
 {
-  char VolumeName[] = "\\\\.\\ :";
-  char DeviceName[255];
-  HANDLE Device;
-  DWORD BytesReturned;
-
-  VolumeName[4] = DriveLetter;
-
-  Device =
-    CreateFile ( VolumeName, GENERIC_READ | GENERIC_WRITE,
-                FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING,
-                FILE_FLAG_NO_BUFFERING, NULL );
-
-  if ( Device != INVALID_HANDLE_VALUE )
+    char    VolumeName[] = "\\\\.\\ :";
+    char    DeviceName[255];
+    HANDLE  Device;
+    DWORD   BytesReturned;
+
+    VolumeName[4] = DriveLetter;
+
+    Device = CreateFile(
+        VolumeName,
+        GENERIC_READ | GENERIC_WRITE,
+        FILE_SHARE_READ | FILE_SHARE_WRITE,
+        NULL,
+        OPEN_EXISTING,
+        FILE_FLAG_NO_BUFFERING,
+        NULL
+        );
+
+    if (Device != INVALID_HANDLE_VALUE)
     {
-      SetLastError ( ERROR_BUSY );
-      PrintLastError ( &VolumeName[4] );
-      return -1;
+        SetLastError(ERROR_BUSY);
+        PrintLastError(&VolumeName[4]);
+        return -1;
     }
 
-  if ( CdImage )
+    if (CdImage)
     {
-      sprintf ( DeviceName, DEVICE_NAME_PREFIX "Cd" "%u", DeviceNumber );
+        sprintf(DeviceName, DEVICE_NAME_PREFIX "Cd" "%u", DeviceNumber);
     }
-  else
+    else
     {
-      sprintf ( DeviceName, DEVICE_NAME_PREFIX "Disk" "%u", DeviceNumber );
+        sprintf(DeviceName, DEVICE_NAME_PREFIX "Disk" "%u", DeviceNumber);
     }
 
-  if ( !DefineDosDevice ( DDD_RAW_TARGET_PATH, &VolumeName[4], DeviceName ) )
+    if (!DefineDosDevice(
+        DDD_RAW_TARGET_PATH,
+        &VolumeName[4],
+        DeviceName
+        ))
     {
-      PrintLastError ( &VolumeName[4] );
-      return -1;
+        PrintLastError(&VolumeName[4]);
+        return -1;
     }
 
-  Device =
-    CreateFile ( VolumeName, GENERIC_READ | GENERIC_WRITE,
-                FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING,
-                FILE_FLAG_NO_BUFFERING, NULL );
-
-  if ( Device == INVALID_HANDLE_VALUE )
+    Device = CreateFile(
+        VolumeName,
+        GENERIC_READ | GENERIC_WRITE,
+        FILE_SHARE_READ | FILE_SHARE_WRITE,
+        NULL,
+        OPEN_EXISTING,
+        FILE_FLAG_NO_BUFFERING,
+        NULL
+        );
+
+    if (Device == INVALID_HANDLE_VALUE)
     {
-      PrintLastError ( &VolumeName[4] );
-      DefineDosDevice ( DDD_REMOVE_DEFINITION, &VolumeName[4], NULL );
-      return -1;
+        PrintLastError(&VolumeName[4]);
+        DefineDosDevice(DDD_REMOVE_DEFINITION, &VolumeName[4], NULL);
+        return -1;
     }
 
-  if ( !DeviceIoControl
-       ( Device, IOCTL_HTTP_DISK_CONNECT, HttpDiskInformation,
-        sizeof ( HTTP_DISK_INFORMATION ) +
-        HttpDiskInformation->FileNameLength - 1, NULL, 0, &BytesReturned,
-        NULL ) )
+    if (!DeviceIoControl(
+        Device,
+        IOCTL_HTTP_DISK_CONNECT,
+        HttpDiskInformation,
+        sizeof(HTTP_DISK_INFORMATION) + HttpDiskInformation->FileNameLength - 1,
+        NULL,
+        0,
+        &BytesReturned,
+        NULL
+        ))
     {
-      PrintLastError ( "HttpDisk" );
-      DefineDosDevice ( DDD_REMOVE_DEFINITION, &VolumeName[4], NULL );
-      return -1;
+        PrintLastError("HttpDisk");
+        DefineDosDevice(DDD_REMOVE_DEFINITION, &VolumeName[4], NULL);
+        return -1;
     }
 
-  return 0;
+    return 0;
 }
 
-int
-HttpDiskUmount (
-  char DriveLetter
- )
+int HttpDiskUmount(char DriveLetter)
 {
-  char VolumeName[] = "\\\\.\\ :";
-  HANDLE Device;
-  DWORD BytesReturned;
-
-  VolumeName[4] = DriveLetter;
-
-  Device =
-    CreateFile ( VolumeName, GENERIC_READ | GENERIC_WRITE,
-                FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING,
-                FILE_FLAG_NO_BUFFERING, NULL );
-
-  if ( Device == INVALID_HANDLE_VALUE )
+    char    VolumeName[] = "\\\\.\\ :";
+    HANDLE  Device;
+    DWORD   BytesReturned;
+
+    VolumeName[4] = DriveLetter;
+
+    Device = CreateFile(
+        VolumeName,
+        GENERIC_READ | GENERIC_WRITE,
+        FILE_SHARE_READ | FILE_SHARE_WRITE,
+        NULL,
+        OPEN_EXISTING,
+        FILE_FLAG_NO_BUFFERING,
+        NULL
+        );
+
+    if (Device == INVALID_HANDLE_VALUE)
     {
-      PrintLastError ( &VolumeName[4] );
-      return -1;
+        PrintLastError(&VolumeName[4]);
+        return -1;
     }
 
-  if ( !DeviceIoControl
-       ( Device, FSCTL_LOCK_VOLUME, NULL, 0, NULL, 0, &BytesReturned, NULL ) )
+    if (!DeviceIoControl(
+        Device,
+        FSCTL_LOCK_VOLUME,
+        NULL,
+        0,
+        NULL,
+        0,
+        &BytesReturned,
+        NULL
+        ))
     {
-      PrintLastError ( &VolumeName[4] );
-      return -1;
+        PrintLastError(&VolumeName[4]);
+        return -1;
     }
 
-  if ( !DeviceIoControl
-       ( Device, IOCTL_HTTP_DISK_DISCONNECT, NULL, 0, NULL, 0, &BytesReturned,
-        NULL ) )
+    if (!DeviceIoControl(
+        Device,
+        IOCTL_HTTP_DISK_DISCONNECT,
+        NULL,
+        0,
+        NULL,
+        0,
+        &BytesReturned,
+        NULL
+        ))
     {
-      PrintLastError ( "HttpDisk" );
-      return -1;
+        PrintLastError("HttpDisk");
+        return -1;
     }
 
-  if ( !DeviceIoControl
-       ( Device, FSCTL_DISMOUNT_VOLUME, NULL, 0, NULL, 0, &BytesReturned,
-        NULL ) )
+    if (!DeviceIoControl(
+        Device,
+        FSCTL_DISMOUNT_VOLUME,
+        NULL,
+        0,
+        NULL,
+        0,
+        &BytesReturned,
+        NULL
+        ))
     {
-      PrintLastError ( &VolumeName[4] );
-      return -1;
+        PrintLastError(&VolumeName[4]);
+        return -1;
     }
 
-  if ( !DeviceIoControl
-       ( Device, FSCTL_UNLOCK_VOLUME, NULL, 0, NULL, 0, &BytesReturned,
-        NULL ) )
+    if (!DeviceIoControl(
+        Device,
+        FSCTL_UNLOCK_VOLUME,
+        NULL,
+        0,
+        NULL,
+        0,
+        &BytesReturned,
+        NULL
+        ))
     {
-      PrintLastError ( &VolumeName[4] );
-      return -1;
+        PrintLastError(&VolumeName[4]);
+        return -1;
     }
 
-  CloseHandle ( Device );
+    CloseHandle(Device);
 
-  if ( !DefineDosDevice ( DDD_REMOVE_DEFINITION, &VolumeName[4], NULL ) )
+    if (!DefineDosDevice(
+        DDD_REMOVE_DEFINITION,
+        &VolumeName[4],
+        NULL
+        ))
     {
-      PrintLastError ( &VolumeName[4] );
-      return -1;
+        PrintLastError(&VolumeName[4]);
+        return -1;
     }
 
-  return 0;
+    return 0;
 }
 
-int __cdecl
-main (
-  int argc,
-  char *argv[]
- )
+int __cdecl main(int argc, char* argv[])
 {
-  char *Command;
-  int DeviceNumber;
-  char *Url;
-  char *Option;
-  char DriveLetter;
-  BOOLEAN CdImage;
-  PHTTP_DISK_INFORMATION HttpDiskInformation;
-  char *FileName;
-  char *PortStr;
-  struct hostent *HostEnt;
-  WSADATA wsaData;
-
-  Command = argv[1];
-
-  if ( ( argc == 5 || argc == 6 ) && !strcmp ( Command, "/mount" ) )
+    char*                   Command;
+    int                     DeviceNumber;
+    char*                   Url;
+    char*                   Option;
+    char                    DriveLetter;
+    BOOLEAN                 CdImage;
+    PHTTP_DISK_INFORMATION  HttpDiskInformation;
+    char*                   FileName;
+    char*                   PortStr;
+    struct hostent*         HostEnt;
+    WSADATA                 wsaData;
+
+    Command = argv[1];
+
+    if ((argc == 5 || argc == 6) && !strcmp(Command, "/mount"))
     {
-      DeviceNumber = atoi ( argv[2] );
-      Url = argv[3];
-
-      if ( argc > 5 )
-       {
-         Option = argv[4];
-         DriveLetter = argv[5][0];
-
-         if ( !strcmp ( Option, "/cd" ) )
-           {
-             CdImage = TRUE;
-           }
-         else
-           {
-             return HttpDiskSyntax (  );
-           }
-       }
-      else
-       {
-         Option = NULL;
-         DriveLetter = argv[4][0];
-         CdImage = FALSE;
-       }
-
-      HttpDiskInformation =
-       malloc ( sizeof ( HTTP_DISK_INFORMATION ) + strlen ( Url ) );
-
-      memset ( HttpDiskInformation, 0,
-              sizeof ( HTTP_DISK_INFORMATION ) + strlen ( Url ) );
-
-      if ( strstr ( Url, "//" ) )
-       {
-         if ( strlen ( Url ) > 7 && !strncmp ( Url, "http://", 7 ) )
-           {
-             Url += 7;
-           }
-         else
-           {
-             fprintf ( stderr, "Invalid protocol.\n" );
-             return -1;
-           }
-       }
-
-      FileName = strstr ( Url, "/" );
-
-      if ( !FileName )
-       {
-         fprintf ( stderr, "%s: Invalid url.\n", Url );
-         return -1;
-       }
-
-      strcpy ( HttpDiskInformation->FileName, FileName );
-
-      HttpDiskInformation->FileNameLength =
-       ( USHORT ) strlen ( HttpDiskInformation->FileName );
-
-      *FileName = '\0';
-
-      PortStr = strstr ( Url, ":" );
-
-      if ( PortStr )
-       {
-         HttpDiskInformation->Port =
-           htons ( ( USHORT ) atoi ( PortStr + 1 ) );
-
-         if ( HttpDiskInformation->Port == 0 )
-           {
-             fprintf ( stderr, "%s: Invalid port.\n", PortStr + 1 );
-             return -1;
-           }
-
-         *PortStr = '\0';
-       }
-      else
-       {
-         HttpDiskInformation->Port = htons ( 80 );
-       }
-
-      HttpDiskInformation->HostNameLength = ( USHORT ) strlen ( Url );
-
-      if ( HttpDiskInformation->HostNameLength > 255 )
-       {
-         fprintf ( stderr, "%s: Host name to long.\n", Url );
-         return -1;
-       }
-
-      strcpy ( HttpDiskInformation->HostName, Url );
-
-      HttpDiskInformation->Address = inet_addr ( Url );
-
-      if ( HttpDiskInformation->Address == INADDR_NONE )
-       {
-         if ( WSAStartup ( MAKEWORD ( 1, 1 ), &wsaData ) != 0 )
-           {
-             PrintLastError ( "HttpDisk" );
-             return -1;
-           }
-
-         HostEnt = gethostbyname ( Url );
-
-         if ( !HostEnt )
-           {
-             PrintLastError ( Url );
-             return -1;
-           }
-
-         HttpDiskInformation->Address =
-           ( ( struct in_addr * )HostEnt->h_addr )->s_addr;
-       }
-
-      return HttpDiskMount ( DeviceNumber, HttpDiskInformation, DriveLetter,
-                            CdImage );
+        DeviceNumber = atoi(argv[2]);
+        Url = argv[3];
+
+        if (argc > 5)
+        {
+            Option = argv[4];
+            DriveLetter = argv[5][0];
+
+            if (!strcmp(Option, "/cd"))
+            {
+                CdImage = TRUE;
+            }
+            else
+            {
+                return HttpDiskSyntax();
+            }
+        }
+        else
+        {
+            Option = NULL;
+            DriveLetter = argv[4][0];
+            CdImage = FALSE;
+        }
+
+        HttpDiskInformation = malloc(sizeof(HTTP_DISK_INFORMATION) + strlen(Url));
+
+        memset(
+            HttpDiskInformation,
+            0,
+            sizeof(HTTP_DISK_INFORMATION) + strlen(Url)
+            );
+
+        if (strstr(Url, "//"))
+        {
+            if (strlen(Url) > 7 && !strncmp(Url, "http://", 7))
+            {
+                Url += 7;
+            }
+            else
+            {
+                fprintf(stderr, "Invalid protocol.\n");
+                return -1;
+            }
+        }
+
+        FileName = strstr(Url, "/");
+
+        if (!FileName)
+        {
+            fprintf(stderr, "%s: Invalid url.\n", Url);
+            return -1;
+        }
+
+        strcpy(HttpDiskInformation->FileName, FileName);
+
+        HttpDiskInformation->FileNameLength = (USHORT) strlen(HttpDiskInformation->FileName);
+
+        *FileName = '\0';
+
+        PortStr = strstr(Url, ":");
+
+        if (PortStr)
+        {
+            HttpDiskInformation->Port = htons((USHORT) atoi(PortStr + 1));
+
+            if (HttpDiskInformation->Port == 0)
+            {
+                fprintf(stderr, "%s: Invalid port.\n", PortStr + 1);
+                return -1;
+            }
+
+            *PortStr = '\0';
+        }
+        else
+        {
+            HttpDiskInformation->Port = htons(80);
+        }
+
+        HttpDiskInformation->HostNameLength = (USHORT) strlen(Url);
+
+        if (HttpDiskInformation->HostNameLength > 255)
+        {
+            fprintf(stderr, "%s: Host name to long.\n", Url);
+            return -1;
+        }
+
+        strcpy(HttpDiskInformation->HostName, Url);
+
+        HttpDiskInformation->Address = inet_addr(Url);
+
+        if (HttpDiskInformation->Address == INADDR_NONE)
+        {
+            if (WSAStartup(MAKEWORD(1, 1), &wsaData) != 0)
+            {
+                PrintLastError("HttpDisk");
+                return -1;
+            }
+
+            HostEnt = gethostbyname(Url);
+
+            if (!HostEnt)
+            {
+                PrintLastError(Url);
+                return -1;
+            }
+
+            HttpDiskInformation->Address = ((struct in_addr*) HostEnt->h_addr)->s_addr;
+        }
+
+        return HttpDiskMount(DeviceNumber, HttpDiskInformation, DriveLetter, CdImage);
     }
-  else if ( argc == 3 && !strcmp ( Command, "/umount" ) )
+    else if (argc == 3 && !strcmp(Command, "/umount"))
     {
-      DriveLetter = argv[2][0];
-      return HttpDiskUmount ( DriveLetter );
+        DriveLetter = argv[2][0];
+        return HttpDiskUmount(DriveLetter);
     }
-  else
+    else
     {
-      return HttpDiskSyntax (  );
+        return HttpDiskSyntax();
     }
 }
index 445dfb8..c2beefb 100644 (file)
 */
 
 #ifndef _HTTP_DISK_
-#  define _HTTP_DISK_
-
-#  ifndef __T
-#    ifdef _NTDDK_
-#      define __T(x)  L ## x
-#    else
-#      define __T(x)  x
-#    endif
-#  endif
-
-#  ifndef _T
-#    define _T(x)   __T(x)
-#  endif
-
-#  define DEVICE_BASE_NAME    _T("\\HttpDisk")
-#  define DEVICE_DIR_NAME     _T("\\Device")      DEVICE_BASE_NAME
-#  define DEVICE_NAME_PREFIX  DEVICE_DIR_NAME     _T("\\Http")
-
-#  define FILE_DEVICE_HTTP_DISK       0x8000
-
-#  define IOCTL_HTTP_DISK_CONNECT     CTL_CODE(FILE_DEVICE_HTTP_DISK, 0x800, METHOD_BUFFERED, FILE_READ_ACCESS | FILE_WRITE_ACCESS)
-#  define IOCTL_HTTP_DISK_DISCONNECT  CTL_CODE(FILE_DEVICE_HTTP_DISK, 0x801, METHOD_BUFFERED, FILE_READ_ACCESS | FILE_WRITE_ACCESS)
-
-typedef struct _HTTP_DISK_INFORMATION
-{
-  ULONG Address;
-  USHORT Port;
-  USHORT HostNameLength;
-  UCHAR HostName[256];
-  USHORT FileNameLength;
-  UCHAR FileName[1];
-} HTTP_DISK_INFORMATION,
-*PHTTP_DISK_INFORMATION;
+#define _HTTP_DISK_
+
+#ifndef __T
+#ifdef _NTDDK_
+#define __T(x)  L ## x
+#else
+#define __T(x)  x
+#endif
+#endif
+
+#ifndef _T
+#define _T(x)   __T(x)
+#endif
+
+#define DEVICE_BASE_NAME    _T("\\HttpDisk")
+#define DEVICE_DIR_NAME     _T("\\Device")      DEVICE_BASE_NAME
+#define DEVICE_NAME_PREFIX  DEVICE_DIR_NAME     _T("\\Http")
+
+#define FILE_DEVICE_HTTP_DISK       0x8000
+
+#define IOCTL_HTTP_DISK_CONNECT     CTL_CODE(FILE_DEVICE_HTTP_DISK, 0x800, METHOD_BUFFERED, FILE_READ_ACCESS | FILE_WRITE_ACCESS)
+#define IOCTL_HTTP_DISK_DISCONNECT  CTL_CODE(FILE_DEVICE_HTTP_DISK, 0x801, METHOD_BUFFERED, FILE_READ_ACCESS | FILE_WRITE_ACCESS)
+
+typedef struct _HTTP_DISK_INFORMATION {
+    ULONG   Address;
+    USHORT  Port;
+    USHORT  HostNameLength;
+    UCHAR   HostName[256];
+    USHORT  FileNameLength;
+    UCHAR   FileName[1];
+} HTTP_DISK_INFORMATION, *PHTTP_DISK_INFORMATION;
 
 #endif