2 * Copyright 1999, 2000 Juergen Schmied
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
25 #define WIN32_NO_STATUS
26 #define NONAMELESSUNION
27 #include "wine/debug.h"
28 #include "wine/server.h"
29 #include "ntdll_misc.h"
33 #include "ddk/ntddk.h"
34 #include "ddk/ntddser.h"
35 #define WINE_MOUNTMGR_EXTENSIONS
36 #include "ddk/mountmgr.h"
38 WINE_DEFAULT_DEBUG_CHANNEL(ntdll
);
41 /******************************************************************************
42 * NtReadFile [NTDLL.@]
43 * ZwReadFile [NTDLL.@]
45 * Read from an open file handle.
48 * FileHandle [I] Handle returned from ZwOpenFile() or ZwCreateFile()
49 * Event [I] Event to signal upon completion (or NULL)
50 * ApcRoutine [I] Callback to call upon completion (or NULL)
51 * ApcContext [I] Context for ApcRoutine (or NULL)
52 * IoStatusBlock [O] Receives information about the operation on return
53 * Buffer [O] Destination for the data read
54 * Length [I] Size of Buffer
55 * ByteOffset [O] Destination for the new file pointer position (or NULL)
56 * Key [O] Function unknown (may be NULL)
59 * Success: 0. IoStatusBlock is updated, and the Information member contains
60 * The number of bytes read.
61 * Failure: An NTSTATUS error code describing the error.
63 NTSTATUS WINAPI
NtReadFile(HANDLE hFile
, HANDLE hEvent
,
64 PIO_APC_ROUTINE apc
, void* apc_user
,
65 PIO_STATUS_BLOCK io_status
, void* buffer
, ULONG length
,
66 PLARGE_INTEGER offset
, PULONG key
)
68 return unix_funcs
->NtReadFile( hFile
, hEvent
, apc
, apc_user
, io_status
, buffer
, length
, offset
, key
);
72 /******************************************************************************
73 * NtReadFileScatter [NTDLL.@]
74 * ZwReadFileScatter [NTDLL.@]
76 NTSTATUS WINAPI
NtReadFileScatter( HANDLE file
, HANDLE event
, PIO_APC_ROUTINE apc
, void *apc_user
,
77 PIO_STATUS_BLOCK io_status
, FILE_SEGMENT_ELEMENT
*segments
,
78 ULONG length
, PLARGE_INTEGER offset
, PULONG key
)
80 return unix_funcs
->NtReadFileScatter( file
, event
, apc
, apc_user
, io_status
,
81 segments
, length
, offset
, key
);
86 /******************************************************************************
87 * NtWriteFile [NTDLL.@]
88 * ZwWriteFile [NTDLL.@]
90 * Write to an open file handle.
93 * FileHandle [I] Handle returned from ZwOpenFile() or ZwCreateFile()
94 * Event [I] Event to signal upon completion (or NULL)
95 * ApcRoutine [I] Callback to call upon completion (or NULL)
96 * ApcContext [I] Context for ApcRoutine (or NULL)
97 * IoStatusBlock [O] Receives information about the operation on return
98 * Buffer [I] Source for the data to write
99 * Length [I] Size of Buffer
100 * ByteOffset [O] Destination for the new file pointer position (or NULL)
101 * Key [O] Function unknown (may be NULL)
104 * Success: 0. IoStatusBlock is updated, and the Information member contains
105 * The number of bytes written.
106 * Failure: An NTSTATUS error code describing the error.
108 NTSTATUS WINAPI
NtWriteFile(HANDLE hFile
, HANDLE hEvent
,
109 PIO_APC_ROUTINE apc
, void* apc_user
,
110 PIO_STATUS_BLOCK io_status
,
111 const void* buffer
, ULONG length
,
112 PLARGE_INTEGER offset
, PULONG key
)
114 return unix_funcs
->NtWriteFile( hFile
, hEvent
, apc
, apc_user
, io_status
, buffer
, length
, offset
, key
);
118 /******************************************************************************
119 * NtWriteFileGather [NTDLL.@]
120 * ZwWriteFileGather [NTDLL.@]
122 NTSTATUS WINAPI
NtWriteFileGather( HANDLE file
, HANDLE event
, PIO_APC_ROUTINE apc
, void *apc_user
,
123 PIO_STATUS_BLOCK io_status
, FILE_SEGMENT_ELEMENT
*segments
,
124 ULONG length
, PLARGE_INTEGER offset
, PULONG key
)
126 return unix_funcs
->NtWriteFileGather( file
, event
, apc
, apc_user
, io_status
,
127 segments
, length
, offset
, key
);
131 /**************************************************************************
132 * NtDeviceIoControlFile [NTDLL.@]
133 * ZwDeviceIoControlFile [NTDLL.@]
135 * Perform an I/O control operation on an open file handle.
138 * handle [I] Handle returned from ZwOpenFile() or ZwCreateFile()
139 * event [I] Event to signal upon completion (or NULL)
140 * apc [I] Callback to call upon completion (or NULL)
141 * apc_context [I] Context for ApcRoutine (or NULL)
142 * io [O] Receives information about the operation on return
143 * code [I] Control code for the operation to perform
144 * in_buffer [I] Source for any input data required (or NULL)
145 * in_size [I] Size of InputBuffer
146 * out_buffer [O] Source for any output data returned (or NULL)
147 * out_size [I] Size of OutputBuffer
150 * Success: 0. IoStatusBlock is updated.
151 * Failure: An NTSTATUS error code describing the error.
153 NTSTATUS WINAPI
NtDeviceIoControlFile(HANDLE handle
, HANDLE event
,
154 PIO_APC_ROUTINE apc
, PVOID apc_context
,
155 PIO_STATUS_BLOCK io
, ULONG code
,
156 PVOID in_buffer
, ULONG in_size
,
157 PVOID out_buffer
, ULONG out_size
)
159 return unix_funcs
->NtDeviceIoControlFile( handle
, event
, apc
, apc_context
, io
, code
,
160 in_buffer
, in_size
, out_buffer
, out_size
);
164 /**************************************************************************
165 * NtFsControlFile [NTDLL.@]
166 * ZwFsControlFile [NTDLL.@]
168 * Perform a file system control operation on an open file handle.
171 * handle [I] Handle returned from ZwOpenFile() or ZwCreateFile()
172 * event [I] Event to signal upon completion (or NULL)
173 * apc [I] Callback to call upon completion (or NULL)
174 * apc_context [I] Context for ApcRoutine (or NULL)
175 * io [O] Receives information about the operation on return
176 * code [I] Control code for the operation to perform
177 * in_buffer [I] Source for any input data required (or NULL)
178 * in_size [I] Size of InputBuffer
179 * out_buffer [O] Source for any output data returned (or NULL)
180 * out_size [I] Size of OutputBuffer
183 * Success: 0. IoStatusBlock is updated.
184 * Failure: An NTSTATUS error code describing the error.
186 NTSTATUS WINAPI
NtFsControlFile(HANDLE handle
, HANDLE event
, PIO_APC_ROUTINE apc
,
187 PVOID apc_context
, PIO_STATUS_BLOCK io
, ULONG code
,
188 PVOID in_buffer
, ULONG in_size
, PVOID out_buffer
, ULONG out_size
)
190 return unix_funcs
->NtFsControlFile( handle
, event
, apc
, apc_context
, io
, code
,
191 in_buffer
, in_size
, out_buffer
, out_size
);
195 /******************************************************************************
196 * NtNotifyChangeDirectoryFile [NTDLL.@]
198 NTSTATUS WINAPI
NtNotifyChangeDirectoryFile( HANDLE handle
, HANDLE event
, PIO_APC_ROUTINE apc
,
199 void *apc_context
, PIO_STATUS_BLOCK iosb
, void *buffer
,
200 ULONG buffer_size
, ULONG filter
, BOOLEAN subtree
)
202 return unix_funcs
->NtNotifyChangeDirectoryFile( handle
, event
, apc
, apc_context
, iosb
,
203 buffer
, buffer_size
, filter
, subtree
);
207 /******************************************************************************
208 * NtSetVolumeInformationFile [NTDLL.@]
209 * ZwSetVolumeInformationFile [NTDLL.@]
211 NTSTATUS WINAPI
NtSetVolumeInformationFile( HANDLE handle
, IO_STATUS_BLOCK
*io
, void *info
,
212 ULONG length
, FS_INFORMATION_CLASS
class )
214 return unix_funcs
->NtSetVolumeInformationFile( handle
, io
, info
, length
, class );
217 NTSTATUS
server_get_unix_name( HANDLE handle
, ANSI_STRING
*unix_name
)
219 data_size_t size
= 1024;
225 name
= RtlAllocateHeap( GetProcessHeap(), 0, size
+ 1 );
226 if (!name
) return STATUS_NO_MEMORY
;
227 unix_name
->MaximumLength
= size
+ 1;
229 SERVER_START_REQ( get_handle_unix_name
)
231 req
->handle
= wine_server_obj_handle( handle
);
232 wine_server_set_reply( req
, name
, size
);
233 ret
= wine_server_call( req
);
234 size
= reply
->name_len
;
241 unix_name
->Buffer
= name
;
242 unix_name
->Length
= size
;
245 RtlFreeHeap( GetProcessHeap(), 0, name
);
246 if (ret
!= STATUS_BUFFER_OVERFLOW
) break;
252 /******************************************************************************
253 * NtQueryInformationFile [NTDLL.@]
254 * ZwQueryInformationFile [NTDLL.@]
256 * Get information about an open file handle.
259 * hFile [I] Handle returned from ZwOpenFile() or ZwCreateFile()
260 * io [O] Receives information about the operation on return
261 * ptr [O] Destination for file information
262 * len [I] Size of FileInformation
263 * class [I] Type of file information to get
266 * Success: 0. IoStatusBlock and FileInformation are updated.
267 * Failure: An NTSTATUS error code describing the error.
269 NTSTATUS WINAPI
NtQueryInformationFile( HANDLE hFile
, PIO_STATUS_BLOCK io
,
270 PVOID ptr
, LONG len
, FILE_INFORMATION_CLASS
class )
272 return unix_funcs
->NtQueryInformationFile( hFile
, io
, ptr
, len
, class );
275 /******************************************************************************
276 * NtSetInformationFile [NTDLL.@]
277 * ZwSetInformationFile [NTDLL.@]
279 * Set information about an open file handle.
282 * handle [I] Handle returned from ZwOpenFile() or ZwCreateFile()
283 * io [O] Receives information about the operation on return
284 * ptr [I] Source for file information
285 * len [I] Size of FileInformation
286 * class [I] Type of file information to set
289 * Success: 0. io is updated.
290 * Failure: An NTSTATUS error code describing the error.
292 NTSTATUS WINAPI
NtSetInformationFile(HANDLE handle
, PIO_STATUS_BLOCK io
,
293 PVOID ptr
, ULONG len
, FILE_INFORMATION_CLASS
class)
295 return unix_funcs
->NtSetInformationFile( handle
, io
, ptr
, len
, class );
299 /******************************************************************************
300 * NtQueryFullAttributesFile (NTDLL.@)
302 NTSTATUS WINAPI
NtQueryFullAttributesFile( const OBJECT_ATTRIBUTES
*attr
,
303 FILE_NETWORK_OPEN_INFORMATION
*info
)
305 return unix_funcs
->NtQueryFullAttributesFile( attr
, info
);
309 /******************************************************************************
310 * NtQueryAttributesFile (NTDLL.@)
311 * ZwQueryAttributesFile (NTDLL.@)
313 NTSTATUS WINAPI
NtQueryAttributesFile( const OBJECT_ATTRIBUTES
*attr
, FILE_BASIC_INFORMATION
*info
)
315 return unix_funcs
->NtQueryAttributesFile( attr
, info
);
319 /******************************************************************************
320 * NtQueryVolumeInformationFile [NTDLL.@]
321 * ZwQueryVolumeInformationFile [NTDLL.@]
323 * Get volume information for an open file handle.
326 * handle [I] Handle returned from ZwOpenFile() or ZwCreateFile()
327 * io [O] Receives information about the operation on return
328 * buffer [O] Destination for volume information
329 * length [I] Size of FsInformation
330 * info_class [I] Type of volume information to set
333 * Success: 0. io and buffer are updated.
334 * Failure: An NTSTATUS error code describing the error.
336 NTSTATUS WINAPI
NtQueryVolumeInformationFile( HANDLE handle
, PIO_STATUS_BLOCK io
,
337 PVOID buffer
, ULONG length
,
338 FS_INFORMATION_CLASS info_class
)
340 return unix_funcs
->NtQueryVolumeInformationFile( handle
, io
, buffer
, length
, info_class
);
344 /******************************************************************
345 * NtQueryEaFile (NTDLL.@)
347 * Read extended attributes from NTFS files.
350 * hFile [I] File handle, must be opened with FILE_READ_EA access
351 * iosb [O] Receives information about the operation on return
352 * buffer [O] Output buffer
353 * length [I] Length of output buffer
354 * single_entry [I] Only read and return one entry
355 * ea_list [I] Optional list with names of EAs to return
356 * ea_list_len [I] Length of ea_list in bytes
357 * ea_index [I] Optional pointer to 1-based index of attribute to return
358 * restart [I] restart EA scan
361 * Success: 0. Attributes read into buffer
362 * Failure: An NTSTATUS error code describing the error.
364 NTSTATUS WINAPI
NtQueryEaFile( HANDLE hFile
, PIO_STATUS_BLOCK iosb
, PVOID buffer
, ULONG length
,
365 BOOLEAN single_entry
, PVOID ea_list
, ULONG ea_list_len
,
366 PULONG ea_index
, BOOLEAN restart
)
368 FIXME("(%p,%p,%p,%d,%d,%p,%d,%p,%d) stub\n",
369 hFile
, iosb
, buffer
, length
, single_entry
, ea_list
,
370 ea_list_len
, ea_index
, restart
);
371 return STATUS_ACCESS_DENIED
;
375 /******************************************************************
376 * NtSetEaFile (NTDLL.@)
378 * Update extended attributes for NTFS files.
381 * hFile [I] File handle, must be opened with FILE_READ_EA access
382 * iosb [O] Receives information about the operation on return
383 * buffer [I] Buffer with EA information
384 * length [I] Length of buffer
387 * Success: 0. Attributes are updated
388 * Failure: An NTSTATUS error code describing the error.
390 NTSTATUS WINAPI
NtSetEaFile( HANDLE hFile
, PIO_STATUS_BLOCK iosb
, PVOID buffer
, ULONG length
)
392 FIXME("(%p,%p,%p,%d) stub\n", hFile
, iosb
, buffer
, length
);
393 return STATUS_ACCESS_DENIED
;
397 /******************************************************************
398 * NtFlushBuffersFile (NTDLL.@)
400 * Flush any buffered data on an open file handle.
403 * FileHandle [I] Handle returned from ZwOpenFile() or ZwCreateFile()
404 * IoStatusBlock [O] Receives information about the operation on return
407 * Success: 0. IoStatusBlock is updated.
408 * Failure: An NTSTATUS error code describing the error.
410 NTSTATUS WINAPI
NtFlushBuffersFile( HANDLE hFile
, IO_STATUS_BLOCK
*io
)
412 return unix_funcs
->NtFlushBuffersFile( hFile
, io
);
415 /******************************************************************
416 * NtLockFile (NTDLL.@)
420 NTSTATUS WINAPI
NtLockFile( HANDLE hFile
, HANDLE lock_granted_event
,
421 PIO_APC_ROUTINE apc
, void* apc_user
,
422 PIO_STATUS_BLOCK io_status
, PLARGE_INTEGER offset
,
423 PLARGE_INTEGER count
, ULONG
* key
, BOOLEAN dont_wait
,
429 static BOOLEAN warn
= TRUE
;
431 if (apc
|| io_status
|| key
)
433 FIXME("Unimplemented yet parameter\n");
434 return STATUS_NOT_IMPLEMENTED
;
437 if (apc_user
&& warn
)
439 FIXME("I/O completion on lock not implemented yet\n");
445 SERVER_START_REQ( lock_file
)
447 req
->handle
= wine_server_obj_handle( hFile
);
448 req
->offset
= offset
->QuadPart
;
449 req
->count
= count
->QuadPart
;
450 req
->shared
= !exclusive
;
451 req
->wait
= !dont_wait
;
452 ret
= wine_server_call( req
);
453 handle
= wine_server_ptr_handle( reply
->handle
);
454 async
= reply
->overlapped
;
457 if (ret
!= STATUS_PENDING
)
459 if (!ret
&& lock_granted_event
) NtSetEvent(lock_granted_event
, NULL
);
465 FIXME( "Async I/O lock wait not implemented, might deadlock\n" );
466 if (handle
) NtClose( handle
);
467 return STATUS_PENDING
;
471 NtWaitForSingleObject( handle
, FALSE
, NULL
);
478 /* Unix lock conflict, sleep a bit and retry */
479 time
.QuadPart
= 100 * (ULONGLONG
)10000;
480 time
.QuadPart
= -time
.QuadPart
;
481 NtDelayExecution( FALSE
, &time
);
487 /******************************************************************
488 * NtUnlockFile (NTDLL.@)
492 NTSTATUS WINAPI
NtUnlockFile( HANDLE hFile
, PIO_STATUS_BLOCK io_status
,
493 PLARGE_INTEGER offset
, PLARGE_INTEGER count
,
498 TRACE( "%p %x%08x %x%08x\n",
499 hFile
, offset
->u
.HighPart
, offset
->u
.LowPart
, count
->u
.HighPart
, count
->u
.LowPart
);
501 if (io_status
|| key
)
503 FIXME("Unimplemented yet parameter\n");
504 return STATUS_NOT_IMPLEMENTED
;
507 SERVER_START_REQ( unlock_file
)
509 req
->handle
= wine_server_obj_handle( hFile
);
510 req
->offset
= offset
->QuadPart
;
511 req
->count
= count
->QuadPart
;
512 status
= wine_server_call( req
);
518 /******************************************************************
519 * NtCreateNamedPipeFile (NTDLL.@)
521 NTSTATUS WINAPI
NtCreateNamedPipeFile( PHANDLE handle
, ULONG access
,
522 POBJECT_ATTRIBUTES attr
, PIO_STATUS_BLOCK iosb
,
523 ULONG sharing
, ULONG dispo
, ULONG options
,
524 ULONG pipe_type
, ULONG read_mode
,
525 ULONG completion_mode
, ULONG max_inst
,
526 ULONG inbound_quota
, ULONG outbound_quota
,
527 PLARGE_INTEGER timeout
)
529 return unix_funcs
->NtCreateNamedPipeFile( handle
, access
, attr
, iosb
, sharing
, dispo
, options
,
530 pipe_type
, read_mode
, completion_mode
, max_inst
,
531 inbound_quota
, outbound_quota
, timeout
);
534 /******************************************************************
535 * NtDeleteFile (NTDLL.@)
537 NTSTATUS WINAPI
NtDeleteFile( OBJECT_ATTRIBUTES
*attr
)
539 return unix_funcs
->NtDeleteFile( attr
);
542 /******************************************************************
543 * NtCancelIoFileEx (NTDLL.@)
547 NTSTATUS WINAPI
NtCancelIoFileEx( HANDLE hFile
, PIO_STATUS_BLOCK iosb
, PIO_STATUS_BLOCK io_status
)
549 TRACE("%p %p %p\n", hFile
, iosb
, io_status
);
551 SERVER_START_REQ( cancel_async
)
553 req
->handle
= wine_server_obj_handle( hFile
);
554 req
->iosb
= wine_server_client_ptr( iosb
);
555 req
->only_thread
= FALSE
;
556 io_status
->u
.Status
= wine_server_call( req
);
560 return io_status
->u
.Status
;
563 /******************************************************************
564 * NtCancelIoFile (NTDLL.@)
568 NTSTATUS WINAPI
NtCancelIoFile( HANDLE hFile
, PIO_STATUS_BLOCK io_status
)
570 TRACE("%p %p\n", hFile
, io_status
);
572 SERVER_START_REQ( cancel_async
)
574 req
->handle
= wine_server_obj_handle( hFile
);
576 req
->only_thread
= TRUE
;
577 io_status
->u
.Status
= wine_server_call( req
);
581 return io_status
->u
.Status
;
584 /******************************************************************************
585 * NtCreateMailslotFile [NTDLL.@]
586 * ZwCreateMailslotFile [NTDLL.@]
588 NTSTATUS WINAPI
NtCreateMailslotFile( HANDLE
*handle
, ULONG access
, OBJECT_ATTRIBUTES
*attr
,
589 IO_STATUS_BLOCK
*io
, ULONG options
, ULONG quota
, ULONG msg_size
,
590 LARGE_INTEGER
*timeout
)
592 return unix_funcs
->NtCreateMailslotFile( handle
, access
, attr
, io
, options
, quota
, msg_size
, timeout
);