Revert 18883 and 18912, as they break named pipes
(These changes were correct per se, but another problem surfaced: see http://www.reactos.org/archives/public/ros-dev/2005-November/005958.html)
Modified: trunk/reactos/drivers/fs/np/create.c
Modified: trunk/reactos/lib/kernel32/file/npipe.c
Modified: trunk/reactos/lib/kernel32/file/pipe.c

Modified: trunk/reactos/drivers/fs/np/create.c
--- trunk/reactos/drivers/fs/np/create.c	2005-11-04 18:58:38 UTC (rev 19001)
+++ trunk/reactos/drivers/fs/np/create.c	2005-11-04 19:31:47 UTC (rev 19002)
@@ -113,6 +113,7 @@
   PNPFS_FCB ClientFcb;
   PNPFS_FCB ServerFcb = NULL;
   PNPFS_DEVICE_EXTENSION DeviceExt;
+  BOOLEAN SpecialAccess;
 
   DPRINT("NpfsCreate(DeviceObject %p Irp %p)\n", DeviceObject, Irp);
 
@@ -124,6 +125,12 @@
 
   Irp->IoStatus.Information = 0;
 
+  SpecialAccess = ((IoStack->Parameters.CreatePipe.ShareAccess & 3) == 3);
+  if (SpecialAccess)
+    {
+      DPRINT("NpfsCreate() open client end for special use!\n");
+    }
+
   /*
    * Step 1. Find the pipe we're trying to open.
    */
@@ -165,7 +172,7 @@
   ClientFcb->Pipe = Pipe;
   ClientFcb->PipeEnd = FILE_PIPE_CLIENT_END;
   ClientFcb->OtherSide = NULL;
-  ClientFcb->PipeState = FILE_PIPE_DISCONNECTED_STATE;
+  ClientFcb->PipeState = SpecialAccess ? 0 : FILE_PIPE_DISCONNECTED_STATE;
   InitializeListHead(&ClientFcb->ReadRequestListHead);
 
   DPRINT("Fcb: %x\n", ClientFcb);
@@ -204,56 +211,67 @@
    * Step 3. Search for listening server FCB.
    */
 
-  /*
-   * WARNING: Point of no return! Once we get the server FCB it's
-   * possible that we completed a wait request and so we have to
-   * complete even this request.
-   */
-
-  ServerFcb = NpfsFindListeningServerInstance(Pipe);
-  if (ServerFcb == NULL)
+  if (!SpecialAccess)
     {
-      PLIST_ENTRY CurrentEntry;
-      PNPFS_FCB Fcb;
-
       /*
-       * If no waiting server FCB was found then try to pick
-       * one of the listing server FCB on the pipe.
+       * WARNING: Point of no return! Once we get the server FCB it's
+       * possible that we completed a wait request and so we have to
+       * complete even this request.
        */
 
-      CurrentEntry = Pipe->ServerFcbListHead.Flink;
-      while (CurrentEntry != &Pipe->ServerFcbListHead)
+      ServerFcb = NpfsFindListeningServerInstance(Pipe);
+      if (ServerFcb == NULL)
         {
-          Fcb = CONTAINING_RECORD(CurrentEntry, NPFS_FCB, FcbListEntry);
-          if (Fcb->PipeState == FILE_PIPE_LISTENING_STATE)
+          PLIST_ENTRY CurrentEntry;
+          PNPFS_FCB Fcb;
+
+          /*
+           * If no waiting server FCB was found then try to pick
+           * one of the listing server FCB on the pipe.
+           */
+
+          CurrentEntry = Pipe->ServerFcbListHead.Flink;
+          while (CurrentEntry != &Pipe->ServerFcbListHead)
             {
-              ServerFcb = Fcb;
-              break;
+              Fcb = CONTAINING_RECORD(CurrentEntry, NPFS_FCB, FcbListEntry);
+              if (Fcb->PipeState == FILE_PIPE_LISTENING_STATE)
+                {
+                  ServerFcb = Fcb;
+                  break;
+                }
+              CurrentEntry = CurrentEntry->Flink;
             }
-          CurrentEntry = CurrentEntry->Flink;
-        }
 
-      /*
-       * No one is listening to me?! I'm so lonely... :(
-       */
+          /*
+           * No one is listening to me?! I'm so lonely... :(
+           */
 
-      if (ServerFcb == NULL)
+          if (ServerFcb == NULL)
+            {
+              /* Not found, bail out with error for FILE_OPEN requests. */
+              DPRINT("No listening server fcb found!\n");
+              if (ClientFcb->Data)
+                ExFreePool(ClientFcb->Data);
+              KeUnlockMutex(&Pipe->FcbListLock);
+              Irp->IoStatus.Status = STATUS_PIPE_BUSY;
+              IoCompleteRequest(Irp, IO_NO_INCREMENT);
+              return STATUS_PIPE_BUSY;
+            }
+        }
+      else
         {
-          /* Not found, bail out with error for FILE_OPEN requests. */
-          DPRINT("No listening server fcb found!\n");
-          if (ClientFcb->Data)
-            ExFreePool(ClientFcb->Data);
-          KeUnlockMutex(&Pipe->FcbListLock);
-          Irp->IoStatus.Status = STATUS_PIPE_NOT_AVAILABLE;
-          IoCompleteRequest(Irp, IO_NO_INCREMENT);
-          return STATUS_PIPE_NOT_AVAILABLE;
+          /* Signal the server thread and remove it from the waiter list */
+          /* FIXME: Merge this with the NpfsFindListeningServerInstance routine. */
+          NpfsSignalAndRemoveListeningServerInstance(Pipe, ServerFcb);
         }
     }
-  else
+  else if (IsListEmpty(&Pipe->ServerFcbListHead))
     {
-      /* Signal the server thread and remove it from the waiter list */
-      /* FIXME: Merge this with the NpfsFindListeningServerInstance routine. */
-      NpfsSignalAndRemoveListeningServerInstance(Pipe, ServerFcb);
+      DPRINT("No server fcb found!\n");
+      KeUnlockMutex(&Pipe->FcbListLock);
+      Irp->IoStatus.Status = STATUS_UNSUCCESSFUL;
+      IoCompleteRequest(Irp, IO_NO_INCREMENT);
+      return STATUS_UNSUCCESSFUL;
     }
 
   /*

Modified: trunk/reactos/lib/kernel32/file/npipe.c
--- trunk/reactos/lib/kernel32/file/npipe.c	2005-11-04 18:58:38 UTC (rev 19001)
+++ trunk/reactos/lib/kernel32/file/npipe.c	2005-11-04 19:31:47 UTC (rev 19002)
@@ -15,12 +15,6 @@
 #define NDEBUG
 #include "../include/debug.h"
 
-/* FIXME - defined in ntifs.h */
-#if !defined(FILE_PIPE_BYTE_STREAM_TYPE) && !defined(FILE_PIPE_MESSAGE_TYPE)
-#define FILE_PIPE_BYTE_STREAM_TYPE      0x00000000
-#define FILE_PIPE_MESSAGE_TYPE          0x00000001
-#endif
-
 /* FUNCTIONS ****************************************************************/
 
 /*
@@ -78,6 +72,7 @@
    HANDLE PipeHandle;
    ACCESS_MASK DesiredAccess;
    ULONG CreateOptions;
+   ULONG CreateDisposition;
    ULONG WriteModeMessage;
    ULONG ReadModeMessage;
    ULONG NonBlocking;
@@ -85,12 +80,6 @@
    ULONG ShareAccess, Attributes;
    LARGE_INTEGER DefaultTimeOut;
    PSECURITY_DESCRIPTOR SecurityDescriptor = NULL;
-   
-   if (nMaxInstances == 0 || nMaxInstances > PIPE_UNLIMITED_INSTANCES)
-   {
-       SetLastError(ERROR_INVALID_PARAMETER);
-       return INVALID_HANDLE_VALUE;
-   }
 
    Result = RtlDosPathNameToNtPathName_U((LPWSTR)lpName,
 					 &NamedPipeName,
@@ -119,41 +108,78 @@
 			      NULL,
 			      SecurityDescriptor);
 
-   DesiredAccess = SYNCHRONIZE | (dwOpenMode & (WRITE_DAC | WRITE_OWNER | ACCESS_SYSTEM_SECURITY));
+   DesiredAccess = 0;
    ShareAccess = 0;
+   CreateDisposition = FILE_OPEN_IF;
    CreateOptions = 0;
-
    if (dwOpenMode & FILE_FLAG_WRITE_THROUGH)
-       CreateOptions |= FILE_WRITE_THROUGH;
+     {
+	CreateOptions = CreateOptions | FILE_WRITE_THROUGH;
+     }
    if (!(dwOpenMode & FILE_FLAG_OVERLAPPED))
-       CreateOptions |= FILE_SYNCHRONOUS_IO_NONALERT;
+     {
+	CreateOptions = CreateOptions | FILE_SYNCHRONOUS_IO_NONALERT;
+     }
+   if (dwOpenMode & PIPE_ACCESS_DUPLEX)
+     {
+	CreateOptions = CreateOptions | FILE_PIPE_FULL_DUPLEX;
+	DesiredAccess |= (FILE_GENERIC_READ | FILE_GENERIC_WRITE);
+     }
+   else if (dwOpenMode & PIPE_ACCESS_INBOUND)
+     {
+	CreateOptions = CreateOptions | FILE_PIPE_INBOUND;
+	DesiredAccess |= FILE_GENERIC_READ;
+     }
+   else if (dwOpenMode & PIPE_ACCESS_OUTBOUND)
+     {
+	CreateOptions = CreateOptions | FILE_PIPE_OUTBOUND;
+	DesiredAccess |= FILE_GENERIC_WRITE;
+     }
 
-   if (dwOpenMode & PIPE_ACCESS_INBOUND)
+   if (dwPipeMode & PIPE_TYPE_BYTE)
      {
-	   ShareAccess |= FILE_SHARE_WRITE;
-	   DesiredAccess |= GENERIC_READ;
+	WriteModeMessage = FILE_PIPE_BYTE_STREAM_MODE;
      }
-   if (dwOpenMode & PIPE_ACCESS_OUTBOUND)
+   else if (dwPipeMode & PIPE_TYPE_MESSAGE)
      {
-	   ShareAccess |= FILE_SHARE_READ;
-	   DesiredAccess |= GENERIC_WRITE;
+	WriteModeMessage = FILE_PIPE_MESSAGE_MODE;
      }
-
-   if (dwPipeMode & PIPE_TYPE_MESSAGE)
-       WriteModeMessage = FILE_PIPE_MESSAGE_TYPE;
    else
-       WriteModeMessage = FILE_PIPE_BYTE_STREAM_TYPE;
+     {
+	WriteModeMessage = FILE_PIPE_BYTE_STREAM_MODE;
+     }
 
-   if (dwPipeMode & PIPE_READMODE_MESSAGE)
-       ReadModeMessage = FILE_PIPE_MESSAGE_MODE;
+   if (dwPipeMode & PIPE_READMODE_BYTE)
+     {
+	ReadModeMessage = FILE_PIPE_BYTE_STREAM_MODE;
+     }
+   else if (dwPipeMode & PIPE_READMODE_MESSAGE)
+     {
+	ReadModeMessage = FILE_PIPE_MESSAGE_MODE;
+     }
    else
-       ReadModeMessage = FILE_PIPE_BYTE_STREAM_MODE;
+     {
+	ReadModeMessage = FILE_PIPE_BYTE_STREAM_MODE;
+     }
 
-   if (dwPipeMode & PIPE_NOWAIT)
-       NonBlocking = FILE_PIPE_COMPLETE_OPERATION;
+   if (dwPipeMode & PIPE_WAIT)
+     {
+	NonBlocking = FILE_PIPE_QUEUE_OPERATION;
+     }
+   else if (dwPipeMode & PIPE_NOWAIT)
+     {
+	NonBlocking = FILE_PIPE_COMPLETE_OPERATION;
+     }
    else
-       NonBlocking = FILE_PIPE_QUEUE_OPERATION;
+     {
+	NonBlocking = FILE_PIPE_QUEUE_OPERATION;
+     }
 
+   if (nMaxInstances >= PIPE_UNLIMITED_INSTANCES)
+     {
+	nMaxInstances = 0xFFFFFFFF;
+     }
+
    DefaultTimeOut.QuadPart = nDefaultTimeOut * -10000LL;
 
    Status = NtCreateNamedPipeFile(&PipeHandle,
@@ -161,7 +187,7 @@
 				  &ObjectAttributes,
 				  &Iosb,
 				  ShareAccess,
-				  FILE_OPEN_IF,
+				  CreateDisposition,
 				  CreateOptions,
 				  WriteModeMessage,
 				  ReadModeMessage,

Modified: trunk/reactos/lib/kernel32/file/pipe.c
--- trunk/reactos/lib/kernel32/file/pipe.c	2005-11-04 18:58:38 UTC (rev 19001)
+++ trunk/reactos/lib/kernel32/file/pipe.c	2005-11-04 19:31:47 UTC (rev 19002)
@@ -59,9 +59,6 @@
 	  Attributes |= OBJ_INHERIT;
      }
 
-   /* use default buffer size if desired */
-   if (nSize == 0) nSize = 0x1000;
-
    InitializeObjectAttributes(&ObjectAttributes,
 			      &PipeName,
 			      Attributes,
@@ -69,7 +66,7 @@
 			      SecurityDescriptor);
 
    Status = NtCreateNamedPipeFile(&ReadPipeHandle,
-				  FILE_GENERIC_READ | FILE_WRITE_ATTRIBUTES | SYNCHRONIZE,
+				  FILE_GENERIC_READ,
 				  &ObjectAttributes,
 				  &StatusBlock,
 				  FILE_SHARE_READ | FILE_SHARE_WRITE,
@@ -89,10 +86,10 @@
      }
 
    Status = NtOpenFile(&WritePipeHandle,
-		       FILE_GENERIC_WRITE | SYNCHRONIZE,
+		       FILE_GENERIC_WRITE,
 		       &ObjectAttributes,
 		       &StatusBlock,
-		       FILE_SHARE_READ | FILE_SHARE_WRITE,
+		       0,
 		       FILE_SYNCHRONOUS_IO_NONALERT | FILE_NON_DIRECTORY_FILE);
    if (!NT_SUCCESS(Status))
      {