3 * COPYRIGHT: See COPYING in the top level directory
4 * PROJECT: ReactOS system libraries
5 * FILE: lib/kernel32/file/create.c
6 * PURPOSE: Directory functions
7 * PROGRAMMER: Ariadne ( ariadne@xs4all.nl)
11 /* INCLUDES *****************************************************************/
16 DEBUG_CHANNEL(kernel32file
);
18 /* GLOBALS ******************************************************************/
20 LONG ProcessPipeId
= 0;
22 /* FUNCTIONS ****************************************************************/
29 CreatePipe(PHANDLE hReadPipe
,
31 LPSECURITY_ATTRIBUTES lpPipeAttributes
,
35 UNICODE_STRING PipeName
;
36 OBJECT_ATTRIBUTES ObjectAttributes
;
37 IO_STATUS_BLOCK StatusBlock
;
38 LARGE_INTEGER DefaultTimeout
;
40 HANDLE ReadPipeHandle
;
41 HANDLE WritePipeHandle
;
44 PSECURITY_DESCRIPTOR SecurityDescriptor
= NULL
;
46 /* Set the timeout to 120 seconds */
47 DefaultTimeout
.QuadPart
= -1200000000;
49 /* Use default buffer size if desired */
50 if (!nSize
) nSize
= 0x1000;
52 /* Increase the Pipe ID */
53 PipeId
= InterlockedIncrement(&ProcessPipeId
);
55 /* Create the pipe name */
57 L
"\\Device\\NamedPipe\\Win32Pipes.%08x.%08x",
58 NtCurrentTeb()->ClientId
.UniqueProcess
,
60 RtlInitUnicodeString(&PipeName
, Buffer
);
62 /* Always use case insensitive */
63 Attributes
= OBJ_CASE_INSENSITIVE
;
65 /* Check if we got attributes */
68 /* Use the attributes' SD instead */
69 SecurityDescriptor
= lpPipeAttributes
->lpSecurityDescriptor
;
71 /* Set OBJ_INHERIT if requested */
72 if (lpPipeAttributes
->bInheritHandle
) Attributes
|= OBJ_INHERIT
;
75 /* Initialize the attributes */
76 InitializeObjectAttributes(&ObjectAttributes
,
82 /* Create the named pipe */
83 Status
= NtCreateNamedPipeFile(&ReadPipeHandle
,
84 GENERIC_READ
|FILE_WRITE_ATTRIBUTES
| SYNCHRONIZE
,
87 FILE_SHARE_READ
| FILE_SHARE_WRITE
,
89 FILE_SYNCHRONOUS_IO_NONALERT
,
90 FILE_PIPE_BYTE_STREAM_TYPE
,
91 FILE_PIPE_BYTE_STREAM_MODE
,
92 FILE_PIPE_QUEUE_OPERATION
,
97 if (!NT_SUCCESS(Status
))
99 /* Convert error and fail */
100 WARN("Status: %lx\n", Status
);
101 BaseSetLastNTError(Status
);
105 /* Now try opening it for write access */
106 Status
= NtOpenFile(&WritePipeHandle
,
107 FILE_GENERIC_WRITE
| SYNCHRONIZE
,
111 FILE_SYNCHRONOUS_IO_NONALERT
| FILE_NON_DIRECTORY_FILE
);
112 if (!NT_SUCCESS(Status
))
114 /* Convert error and fail */
115 WARN("Status: %lx\n", Status
);
116 NtClose(ReadPipeHandle
);
117 BaseSetLastNTError(Status
);
121 /* Return both handles */
122 *hReadPipe
= ReadPipeHandle
;
123 *hWritePipe
= WritePipeHandle
;