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
20 #include "wine/port.h"
30 #ifdef HAVE_LINUX_MAJOR_H
31 # include <linux/major.h>
33 #ifdef HAVE_SYS_STATVFS_H
34 # include <sys/statvfs.h>
36 #ifdef HAVE_SYS_PARAM_H
37 # include <sys/param.h>
39 #ifdef HAVE_SYS_SYSCALL_H
40 # include <sys/syscall.h>
42 #ifdef HAVE_SYS_TIME_H
43 # include <sys/time.h>
45 #ifdef HAVE_SYS_IOCTL_H
46 #include <sys/ioctl.h>
48 #ifdef HAVE_SYS_FILIO_H
49 # include <sys/filio.h>
54 #ifdef HAVE_SYS_POLL_H
57 #ifdef HAVE_SYS_SOCKET_H
58 #include <sys/socket.h>
61 # include <sys/mkdev.h>
62 #elif defined(MAJOR_IN_SYSMACROS)
63 # include <sys/sysmacros.h>
69 /* Work around a conflict with Solaris' system list defined in sys/list.h. */
71 #define list_next SYSLIST_NEXT
72 #define list_prev SYSLIST_PREV
73 #define list_head SYSLIST_HEAD
74 #define list_tail SYSLIST_TAIL
75 #define list_move_tail SYSLIST_MOVE_TAIL
76 #define list_remove SYSLIST_REMOVE
86 #ifdef HAVE_SYS_MOUNT_H
87 # include <sys/mount.h>
89 #ifdef HAVE_SYS_STATFS_H
90 # include <sys/statfs.h>
95 #ifdef HAVE_VALGRIND_MEMCHECK_H
96 # include <valgrind/memcheck.h>
100 #define WIN32_NO_STATUS
101 #define NONAMELESSUNION
102 #include "wine/unicode.h"
103 #include "wine/debug.h"
104 #include "wine/server.h"
105 #include "ntdll_misc.h"
107 #include "winternl.h"
108 #include "winioctl.h"
109 #include "ddk/ntddk.h"
110 #include "ddk/ntddser.h"
112 WINE_DEFAULT_DEBUG_CHANNEL(ntdll
);
113 WINE_DECLARE_DEBUG_CHANNEL(winediag
);
115 mode_t FILE_umask
= 0;
117 #define SECSPERDAY 86400
118 #define SECS_1601_TO_1970 ((369 * 365 + 89) * (ULONGLONG)SECSPERDAY)
120 #define FILE_WRITE_TO_END_OF_FILE ((LONGLONG)-1)
121 #define FILE_USE_FILE_POINTER_POSITION ((LONGLONG)-2)
123 static const WCHAR ntfsW
[] = {'N','T','F','S'};
125 /* fetch the attributes of a file */
126 static inline ULONG
get_file_attributes( const struct stat
*st
)
130 if (S_ISDIR(st
->st_mode
))
131 attr
= FILE_ATTRIBUTE_DIRECTORY
;
133 attr
= FILE_ATTRIBUTE_ARCHIVE
;
134 if (!(st
->st_mode
& (S_IWUSR
| S_IWGRP
| S_IWOTH
)))
135 attr
|= FILE_ATTRIBUTE_READONLY
;
139 /* get the stat info and file attributes for a file (by file descriptor) */
140 int fd_get_file_info( int fd
, struct stat
*st
, ULONG
*attr
)
145 ret
= fstat( fd
, st
);
146 if (ret
== -1) return ret
;
147 *attr
|= get_file_attributes( st
);
151 /* get the stat info and file attributes for a file (by name) */
152 int get_file_info( const char *path
, struct stat
*st
, ULONG
*attr
)
157 ret
= lstat( path
, st
);
158 if (ret
== -1) return ret
;
159 if (S_ISLNK( st
->st_mode
))
161 ret
= stat( path
, st
);
162 if (ret
== -1) return ret
;
163 /* is a symbolic link and a directory, consider these "reparse points" */
164 if (S_ISDIR( st
->st_mode
)) *attr
|= FILE_ATTRIBUTE_REPARSE_POINT
;
166 *attr
|= get_file_attributes( st
);
170 /**************************************************************************
171 * FILE_CreateFile (internal)
174 * Parameter set fully identical with NtCreateFile
176 static NTSTATUS
FILE_CreateFile( PHANDLE handle
, ACCESS_MASK access
, POBJECT_ATTRIBUTES attr
,
177 PIO_STATUS_BLOCK io
, PLARGE_INTEGER alloc_size
,
178 ULONG attributes
, ULONG sharing
, ULONG disposition
,
179 ULONG options
, PVOID ea_buffer
, ULONG ea_length
)
181 ANSI_STRING unix_name
;
182 BOOL created
= FALSE
;
184 TRACE("handle=%p access=%08x name=%s objattr=%08x root=%p sec=%p io=%p alloc_size=%p "
185 "attr=%08x sharing=%08x disp=%d options=%08x ea=%p.0x%08x\n",
186 handle
, access
, debugstr_us(attr
->ObjectName
), attr
->Attributes
,
187 attr
->RootDirectory
, attr
->SecurityDescriptor
, io
, alloc_size
,
188 attributes
, sharing
, disposition
, options
, ea_buffer
, ea_length
);
190 if (!attr
|| !attr
->ObjectName
) return STATUS_INVALID_PARAMETER
;
192 if (alloc_size
) FIXME( "alloc_size not supported\n" );
194 if (options
& FILE_OPEN_BY_FILE_ID
)
195 io
->u
.Status
= file_id_to_unix_file_name( attr
, &unix_name
);
197 io
->u
.Status
= nt_to_unix_file_name_attr( attr
, &unix_name
, disposition
);
199 if (io
->u
.Status
== STATUS_BAD_DEVICE_TYPE
)
201 SERVER_START_REQ( open_file_object
)
203 req
->access
= access
;
204 req
->attributes
= attr
->Attributes
;
205 req
->rootdir
= wine_server_obj_handle( attr
->RootDirectory
);
206 req
->sharing
= sharing
;
207 req
->options
= options
;
208 wine_server_add_data( req
, attr
->ObjectName
->Buffer
, attr
->ObjectName
->Length
);
209 io
->u
.Status
= wine_server_call( req
);
210 *handle
= wine_server_ptr_handle( reply
->handle
);
213 if (io
->u
.Status
== STATUS_SUCCESS
) io
->Information
= FILE_OPENED
;
217 if (io
->u
.Status
== STATUS_NO_SUCH_FILE
&&
218 disposition
!= FILE_OPEN
&& disposition
!= FILE_OVERWRITE
)
221 io
->u
.Status
= STATUS_SUCCESS
;
224 if (io
->u
.Status
== STATUS_SUCCESS
)
226 static UNICODE_STRING empty_string
;
227 OBJECT_ATTRIBUTES unix_attr
= *attr
;
229 struct object_attributes
*objattr
;
231 unix_attr
.ObjectName
= &empty_string
; /* we send the unix name instead */
232 if ((io
->u
.Status
= alloc_object_attributes( &unix_attr
, &objattr
, &len
)))
234 RtlFreeAnsiString( &unix_name
);
238 SERVER_START_REQ( create_file
)
240 req
->access
= access
;
241 req
->sharing
= sharing
;
242 req
->create
= disposition
;
243 req
->options
= options
;
244 req
->attrs
= attributes
;
245 wine_server_add_data( req
, objattr
, len
);
246 wine_server_add_data( req
, unix_name
.Buffer
, unix_name
.Length
);
247 io
->u
.Status
= wine_server_call( req
);
248 *handle
= wine_server_ptr_handle( reply
->handle
);
251 RtlFreeHeap( GetProcessHeap(), 0, objattr
);
252 RtlFreeAnsiString( &unix_name
);
254 else WARN("%s not found (%x)\n", debugstr_us(attr
->ObjectName
), io
->u
.Status
);
256 if (io
->u
.Status
== STATUS_SUCCESS
)
258 if (created
) io
->Information
= FILE_CREATED
;
259 else switch(disposition
)
262 io
->Information
= FILE_SUPERSEDED
;
265 io
->Information
= FILE_CREATED
;
269 io
->Information
= FILE_OPENED
;
272 case FILE_OVERWRITE_IF
:
273 io
->Information
= FILE_OVERWRITTEN
;
277 else if (io
->u
.Status
== STATUS_TOO_MANY_OPENED_FILES
)
280 if (!once
++) ERR_(winediag
)( "Too many open files, ulimit -n probably needs to be increased\n" );
286 /**************************************************************************
287 * NtOpenFile [NTDLL.@]
288 * ZwOpenFile [NTDLL.@]
293 * handle [O] Variable that receives the file handle on return
294 * access [I] Access desired by the caller to the file
295 * attr [I] Structure describing the file to be opened
296 * io [O] Receives details about the result of the operation
297 * sharing [I] Type of shared access the caller requires
298 * options [I] Options for the file open
301 * Success: 0. FileHandle and IoStatusBlock are updated.
302 * Failure: An NTSTATUS error code describing the error.
304 NTSTATUS WINAPI
NtOpenFile( PHANDLE handle
, ACCESS_MASK access
,
305 POBJECT_ATTRIBUTES attr
, PIO_STATUS_BLOCK io
,
306 ULONG sharing
, ULONG options
)
308 return FILE_CreateFile( handle
, access
, attr
, io
, NULL
, 0,
309 sharing
, FILE_OPEN
, options
, NULL
, 0 );
312 /**************************************************************************
313 * NtCreateFile [NTDLL.@]
314 * ZwCreateFile [NTDLL.@]
316 * Either create a new file or directory, or open an existing file, device,
317 * directory or volume.
320 * handle [O] Points to a variable which receives the file handle on return
321 * access [I] Desired access to the file
322 * attr [I] Structure describing the file
323 * io [O] Receives information about the operation on return
324 * alloc_size [I] Initial size of the file in bytes
325 * attributes [I] Attributes to create the file with
326 * sharing [I] Type of shared access the caller would like to the file
327 * disposition [I] Specifies what to do, depending on whether the file already exists
328 * options [I] Options for creating a new file
329 * ea_buffer [I] Pointer to an extended attributes buffer
330 * ea_length [I] Length of ea_buffer
333 * Success: 0. handle and io are updated.
334 * Failure: An NTSTATUS error code describing the error.
336 NTSTATUS WINAPI
NtCreateFile( PHANDLE handle
, ACCESS_MASK access
, POBJECT_ATTRIBUTES attr
,
337 PIO_STATUS_BLOCK io
, PLARGE_INTEGER alloc_size
,
338 ULONG attributes
, ULONG sharing
, ULONG disposition
,
339 ULONG options
, PVOID ea_buffer
, ULONG ea_length
)
341 return FILE_CreateFile( handle
, access
, attr
, io
, alloc_size
, attributes
,
342 sharing
, disposition
, options
, ea_buffer
, ea_length
);
345 /***********************************************************************
346 * Asynchronous file I/O *
349 typedef NTSTATUS
async_callback_t( void *user
, IO_STATUS_BLOCK
*io
, NTSTATUS status
);
353 async_callback_t
*callback
; /* must be the first field */
354 struct async_fileio
*next
;
358 struct async_fileio_read
360 struct async_fileio io
;
362 unsigned int already
;
367 struct async_fileio_write
369 struct async_fileio io
;
371 unsigned int already
;
377 struct async_fileio io
;
378 HANDLE event
; /* async event */
379 void *buffer
; /* buffer for output */
380 ULONG size
; /* size of buffer */
383 static struct async_fileio
*fileio_freelist
;
385 static void release_fileio( struct async_fileio
*io
)
389 struct async_fileio
*next
= fileio_freelist
;
391 if (interlocked_cmpxchg_ptr( (void **)&fileio_freelist
, io
, next
) == next
) return;
395 static struct async_fileio
*alloc_fileio( DWORD size
, async_callback_t callback
, HANDLE handle
)
397 /* first free remaining previous fileinfos */
399 struct async_fileio
*io
= interlocked_xchg_ptr( (void **)&fileio_freelist
, NULL
);
403 struct async_fileio
*next
= io
->next
;
404 RtlFreeHeap( GetProcessHeap(), 0, io
);
408 if ((io
= RtlAllocateHeap( GetProcessHeap(), 0, size
)))
410 io
->callback
= callback
;
416 static async_data_t
server_async( HANDLE handle
, struct async_fileio
*user
, HANDLE event
,
417 PIO_APC_ROUTINE apc
, void *apc_context
, IO_STATUS_BLOCK
*io
)
420 async
.handle
= wine_server_obj_handle( handle
);
421 async
.user
= wine_server_client_ptr( user
);
422 async
.iosb
= wine_server_client_ptr( io
);
423 async
.event
= wine_server_obj_handle( event
);
424 async
.apc
= wine_server_client_ptr( apc
);
425 async
.apc_context
= wine_server_client_ptr( apc_context
);
429 /* callback for irp async I/O completion */
430 static NTSTATUS
irp_completion( void *user
, IO_STATUS_BLOCK
*io
, NTSTATUS status
)
432 struct async_irp
*async
= user
;
433 ULONG information
= 0;
435 if (status
== STATUS_ALERTED
)
437 SERVER_START_REQ( get_async_result
)
439 req
->user_arg
= wine_server_client_ptr( async
);
440 wine_server_set_reply( req
, async
->buffer
, async
->size
);
441 status
= virtual_locked_server_call( req
);
442 information
= reply
->size
;
446 if (status
!= STATUS_PENDING
)
448 io
->u
.Status
= status
;
449 io
->Information
= information
;
450 release_fileio( &async
->io
);
455 /***********************************************************************
456 * FILE_GetNtStatus(void)
458 * Retrieve the Nt Status code from errno.
459 * Try to be consistent with FILE_SetDosError().
461 NTSTATUS
FILE_GetNtStatus(void)
465 TRACE( "errno = %d\n", errno
);
468 case EAGAIN
: return STATUS_SHARING_VIOLATION
;
469 case EBADF
: return STATUS_INVALID_HANDLE
;
470 case EBUSY
: return STATUS_DEVICE_BUSY
;
471 case ENOSPC
: return STATUS_DISK_FULL
;
474 case EACCES
: return STATUS_ACCESS_DENIED
;
475 case ENOTDIR
: return STATUS_OBJECT_PATH_NOT_FOUND
;
476 case ENOENT
: return STATUS_OBJECT_NAME_NOT_FOUND
;
477 case EISDIR
: return STATUS_FILE_IS_A_DIRECTORY
;
479 case ENFILE
: return STATUS_TOO_MANY_OPENED_FILES
;
480 case EINVAL
: return STATUS_INVALID_PARAMETER
;
481 case ENOTEMPTY
: return STATUS_DIRECTORY_NOT_EMPTY
;
482 case EPIPE
: return STATUS_PIPE_DISCONNECTED
;
483 case EIO
: return STATUS_DEVICE_NOT_READY
;
485 case ENOMEDIUM
: return STATUS_NO_MEDIA_IN_DEVICE
;
487 case ENXIO
: return STATUS_NO_SUCH_DEVICE
;
489 case EOPNOTSUPP
:return STATUS_NOT_SUPPORTED
;
490 case ECONNRESET
:return STATUS_PIPE_DISCONNECTED
;
491 case EFAULT
: return STATUS_ACCESS_VIOLATION
;
492 case ESPIPE
: return STATUS_ILLEGAL_FUNCTION
;
493 #ifdef ETIME /* Missing on FreeBSD */
494 case ETIME
: return STATUS_IO_TIMEOUT
;
496 case ENOEXEC
: /* ?? */
497 case EEXIST
: /* ?? */
499 FIXME( "Converting errno %d to STATUS_UNSUCCESSFUL\n", err
);
500 return STATUS_UNSUCCESSFUL
;
504 /***********************************************************************
505 * FILE_AsyncReadService (INTERNAL)
507 static NTSTATUS
FILE_AsyncReadService( void *user
, IO_STATUS_BLOCK
*iosb
, NTSTATUS status
)
509 struct async_fileio_read
*fileio
= user
;
510 int fd
, needs_close
, result
;
514 case STATUS_ALERTED
: /* got some new data */
515 /* check to see if the data is ready (non-blocking) */
516 if ((status
= server_get_unix_fd( fileio
->io
.handle
, FILE_READ_DATA
, &fd
,
517 &needs_close
, NULL
, NULL
)))
520 result
= virtual_locked_read(fd
, &fileio
->buffer
[fileio
->already
], fileio
->count
-fileio
->already
);
521 if (needs_close
) close( fd
);
525 if (errno
== EAGAIN
|| errno
== EINTR
)
526 status
= STATUS_PENDING
;
527 else /* check to see if the transfer is complete */
528 status
= FILE_GetNtStatus();
530 else if (result
== 0)
532 status
= fileio
->already
? STATUS_SUCCESS
: STATUS_PIPE_BROKEN
;
536 fileio
->already
+= result
;
537 if (fileio
->already
>= fileio
->count
|| fileio
->avail_mode
)
538 status
= STATUS_SUCCESS
;
540 status
= STATUS_PENDING
;
545 case STATUS_IO_TIMEOUT
:
546 if (fileio
->already
) status
= STATUS_SUCCESS
;
549 if (status
!= STATUS_PENDING
)
551 iosb
->u
.Status
= status
;
552 iosb
->Information
= fileio
->already
;
553 release_fileio( &fileio
->io
);
558 /* do a read call through the server */
559 static NTSTATUS
server_read_file( HANDLE handle
, HANDLE event
, PIO_APC_ROUTINE apc
, void *apc_context
,
560 IO_STATUS_BLOCK
*io
, void *buffer
, ULONG size
,
561 LARGE_INTEGER
*offset
, ULONG
*key
)
563 struct async_irp
*async
;
568 if (!(async
= (struct async_irp
*)alloc_fileio( sizeof(*async
), irp_completion
, handle
)))
569 return STATUS_NO_MEMORY
;
571 async
->event
= event
;
572 async
->buffer
= buffer
;
575 SERVER_START_REQ( read
)
577 req
->async
= server_async( handle
, &async
->io
, event
, apc
, apc_context
, io
);
578 req
->pos
= offset
? offset
->QuadPart
: 0;
579 wine_server_set_reply( req
, buffer
, size
);
580 status
= virtual_locked_server_call( req
);
581 wait_handle
= wine_server_ptr_handle( reply
->wait
);
582 options
= reply
->options
;
583 if (wait_handle
&& status
!= STATUS_PENDING
)
585 io
->u
.Status
= status
;
586 io
->Information
= wine_server_reply_size( reply
);
591 if (status
!= STATUS_PENDING
) RtlFreeHeap( GetProcessHeap(), 0, async
);
595 NtWaitForSingleObject( wait_handle
, (options
& FILE_SYNCHRONOUS_IO_ALERT
), NULL
);
596 status
= io
->u
.Status
;
602 /* do a write call through the server */
603 static NTSTATUS
server_write_file( HANDLE handle
, HANDLE event
, PIO_APC_ROUTINE apc
, void *apc_context
,
604 IO_STATUS_BLOCK
*io
, const void *buffer
, ULONG size
,
605 LARGE_INTEGER
*offset
, ULONG
*key
)
607 struct async_irp
*async
;
612 if (!(async
= (struct async_irp
*)alloc_fileio( sizeof(*async
), irp_completion
, handle
)))
613 return STATUS_NO_MEMORY
;
615 async
->event
= event
;
616 async
->buffer
= NULL
;
619 SERVER_START_REQ( write
)
621 req
->async
= server_async( handle
, &async
->io
, event
, apc
, apc_context
, io
);
622 req
->pos
= offset
? offset
->QuadPart
: 0;
623 wine_server_add_data( req
, buffer
, size
);
624 status
= wine_server_call( req
);
625 wait_handle
= wine_server_ptr_handle( reply
->wait
);
626 options
= reply
->options
;
627 if (wait_handle
&& status
!= STATUS_PENDING
)
629 io
->u
.Status
= status
;
630 io
->Information
= reply
->size
;
635 if (status
!= STATUS_PENDING
) RtlFreeHeap( GetProcessHeap(), 0, async
);
639 NtWaitForSingleObject( wait_handle
, (options
& FILE_SYNCHRONOUS_IO_ALERT
), NULL
);
640 status
= io
->u
.Status
;
648 int interval
; /* max interval between two bytes */
649 int total
; /* total timeout for the whole operation */
650 int end_time
; /* absolute time of end of operation */
653 /* retrieve the I/O timeouts to use for a given handle */
654 static NTSTATUS
get_io_timeouts( HANDLE handle
, enum server_fd_type type
, ULONG count
, BOOL is_read
,
655 struct io_timeouts
*timeouts
)
657 NTSTATUS status
= STATUS_SUCCESS
;
659 timeouts
->interval
= timeouts
->total
= -1;
665 /* GetCommTimeouts */
669 status
= NtDeviceIoControlFile( handle
, NULL
, NULL
, NULL
, &io
,
670 IOCTL_SERIAL_GET_TIMEOUTS
, NULL
, 0, &st
, sizeof(st
) );
675 if (st
.ReadIntervalTimeout
)
676 timeouts
->interval
= st
.ReadIntervalTimeout
;
678 if (st
.ReadTotalTimeoutMultiplier
|| st
.ReadTotalTimeoutConstant
)
680 timeouts
->total
= st
.ReadTotalTimeoutConstant
;
681 if (st
.ReadTotalTimeoutMultiplier
!= MAXDWORD
)
682 timeouts
->total
+= count
* st
.ReadTotalTimeoutMultiplier
;
684 else if (st
.ReadIntervalTimeout
== MAXDWORD
)
685 timeouts
->interval
= timeouts
->total
= 0;
689 if (st
.WriteTotalTimeoutMultiplier
|| st
.WriteTotalTimeoutConstant
)
691 timeouts
->total
= st
.WriteTotalTimeoutConstant
;
692 if (st
.WriteTotalTimeoutMultiplier
!= MAXDWORD
)
693 timeouts
->total
+= count
* st
.WriteTotalTimeoutMultiplier
;
698 case FD_TYPE_MAILSLOT
:
701 timeouts
->interval
= 0; /* return as soon as we got something */
702 SERVER_START_REQ( set_mailslot_info
)
704 req
->handle
= wine_server_obj_handle( handle
);
706 if (!(status
= wine_server_call( req
)) &&
707 reply
->read_timeout
!= TIMEOUT_INFINITE
)
708 timeouts
->total
= reply
->read_timeout
/ -10000;
715 if (is_read
) timeouts
->interval
= 0; /* return as soon as we got something */
720 if (timeouts
->total
!= -1) timeouts
->end_time
= NtGetTickCount() + timeouts
->total
;
721 return STATUS_SUCCESS
;
725 /* retrieve the timeout for the next wait, in milliseconds */
726 static inline int get_next_io_timeout( const struct io_timeouts
*timeouts
, ULONG already
)
730 if (timeouts
->total
!= -1)
732 ret
= timeouts
->end_time
- NtGetTickCount();
733 if (ret
< 0) ret
= 0;
735 if (already
&& timeouts
->interval
!= -1)
737 if (ret
== -1 || ret
> timeouts
->interval
) ret
= timeouts
->interval
;
743 /* retrieve the avail_mode flag for async reads */
744 static NTSTATUS
get_io_avail_mode( HANDLE handle
, enum server_fd_type type
, BOOL
*avail_mode
)
746 NTSTATUS status
= STATUS_SUCCESS
;
752 /* GetCommTimeouts */
756 status
= NtDeviceIoControlFile( handle
, NULL
, NULL
, NULL
, &io
,
757 IOCTL_SERIAL_GET_TIMEOUTS
, NULL
, 0, &st
, sizeof(st
) );
759 *avail_mode
= (!st
.ReadTotalTimeoutMultiplier
&&
760 !st
.ReadTotalTimeoutConstant
&&
761 st
.ReadIntervalTimeout
== MAXDWORD
);
764 case FD_TYPE_MAILSLOT
:
776 /* register an async I/O for a file read; helper for NtReadFile */
777 static NTSTATUS
register_async_file_read( HANDLE handle
, HANDLE event
,
778 PIO_APC_ROUTINE apc
, void *apc_user
,
779 IO_STATUS_BLOCK
*iosb
, void *buffer
,
780 ULONG already
, ULONG length
, BOOL avail_mode
)
782 struct async_fileio_read
*fileio
;
785 if (!(fileio
= (struct async_fileio_read
*)alloc_fileio( sizeof(*fileio
), FILE_AsyncReadService
, handle
)))
786 return STATUS_NO_MEMORY
;
788 fileio
->already
= already
;
789 fileio
->count
= length
;
790 fileio
->buffer
= buffer
;
791 fileio
->avail_mode
= avail_mode
;
793 SERVER_START_REQ( register_async
)
795 req
->type
= ASYNC_TYPE_READ
;
797 req
->async
= server_async( handle
, &fileio
->io
, event
, apc
, apc_user
, iosb
);
798 status
= wine_server_call( req
);
802 if (status
!= STATUS_PENDING
) RtlFreeHeap( GetProcessHeap(), 0, fileio
);
807 /******************************************************************************
808 * NtReadFile [NTDLL.@]
809 * ZwReadFile [NTDLL.@]
811 * Read from an open file handle.
814 * FileHandle [I] Handle returned from ZwOpenFile() or ZwCreateFile()
815 * Event [I] Event to signal upon completion (or NULL)
816 * ApcRoutine [I] Callback to call upon completion (or NULL)
817 * ApcContext [I] Context for ApcRoutine (or NULL)
818 * IoStatusBlock [O] Receives information about the operation on return
819 * Buffer [O] Destination for the data read
820 * Length [I] Size of Buffer
821 * ByteOffset [O] Destination for the new file pointer position (or NULL)
822 * Key [O] Function unknown (may be NULL)
825 * Success: 0. IoStatusBlock is updated, and the Information member contains
826 * The number of bytes read.
827 * Failure: An NTSTATUS error code describing the error.
829 NTSTATUS WINAPI
NtReadFile(HANDLE hFile
, HANDLE hEvent
,
830 PIO_APC_ROUTINE apc
, void* apc_user
,
831 PIO_STATUS_BLOCK io_status
, void* buffer
, ULONG length
,
832 PLARGE_INTEGER offset
, PULONG key
)
834 int result
, unix_handle
, needs_close
;
835 unsigned int options
;
836 struct io_timeouts timeouts
;
839 enum server_fd_type type
;
840 ULONG_PTR cvalue
= apc
? 0 : (ULONG_PTR
)apc_user
;
841 BOOL send_completion
= FALSE
, async_read
, timeout_init_done
= FALSE
;
843 TRACE("(%p,%p,%p,%p,%p,%p,0x%08x,%p,%p),partial stub!\n",
844 hFile
,hEvent
,apc
,apc_user
,io_status
,buffer
,length
,offset
,key
);
846 if (!io_status
) return STATUS_ACCESS_VIOLATION
;
848 status
= server_get_unix_fd( hFile
, FILE_READ_DATA
, &unix_handle
,
849 &needs_close
, &type
, &options
);
850 if (status
&& status
!= STATUS_BAD_DEVICE_TYPE
) return status
;
852 if (!virtual_check_buffer_for_write( buffer
, length
)) return STATUS_ACCESS_VIOLATION
;
854 if (status
== STATUS_BAD_DEVICE_TYPE
)
855 return server_read_file( hFile
, hEvent
, apc
, apc_user
, io_status
, buffer
, length
, offset
, key
);
857 async_read
= !(options
& (FILE_SYNCHRONOUS_IO_ALERT
| FILE_SYNCHRONOUS_IO_NONALERT
));
859 if (type
== FD_TYPE_FILE
)
861 if (async_read
&& (!offset
|| offset
->QuadPart
< 0))
863 status
= STATUS_INVALID_PARAMETER
;
867 if (offset
&& offset
->QuadPart
!= FILE_USE_FILE_POINTER_POSITION
)
869 /* async I/O doesn't make sense on regular files */
870 while ((result
= virtual_locked_pread( unix_handle
, buffer
, length
, offset
->QuadPart
)) == -1)
874 status
= FILE_GetNtStatus();
879 /* update file pointer position */
880 lseek( unix_handle
, offset
->QuadPart
+ result
, SEEK_SET
);
883 status
= (total
|| !length
) ? STATUS_SUCCESS
: STATUS_END_OF_FILE
;
887 else if (type
== FD_TYPE_SERIAL
|| type
== FD_TYPE_DEVICE
)
889 if (async_read
&& (!offset
|| offset
->QuadPart
< 0))
891 status
= STATUS_INVALID_PARAMETER
;
896 if (type
== FD_TYPE_SERIAL
&& async_read
&& length
)
898 /* an asynchronous serial port read with a read interval timeout needs to
899 skip the synchronous read to make sure that the server starts the read
900 interval timer after the first read */
901 if ((status
= get_io_timeouts( hFile
, type
, length
, TRUE
, &timeouts
))) goto err
;
902 if (timeouts
.interval
)
904 status
= register_async_file_read( hFile
, hEvent
, apc
, apc_user
, io_status
,
905 buffer
, total
, length
, FALSE
);
912 if ((result
= virtual_locked_read( unix_handle
, (char *)buffer
+ total
, length
- total
)) >= 0)
915 if (!result
|| total
== length
)
919 status
= STATUS_SUCCESS
;
927 status
= length
? STATUS_END_OF_FILE
: STATUS_SUCCESS
;
932 status
= STATUS_SUCCESS
;
937 status
= STATUS_PIPE_BROKEN
;
941 else if (type
== FD_TYPE_FILE
) continue; /* no async I/O on regular files */
943 else if (errno
!= EAGAIN
)
945 if (errno
== EINTR
) continue;
946 if (!total
) status
= FILE_GetNtStatus();
954 if ((status
= get_io_avail_mode( hFile
, type
, &avail_mode
)))
956 if (total
&& avail_mode
)
958 status
= STATUS_SUCCESS
;
961 status
= register_async_file_read( hFile
, hEvent
, apc
, apc_user
, io_status
,
962 buffer
, total
, length
, avail_mode
);
965 else /* synchronous read, wait for the fd to become ready */
970 if (!timeout_init_done
)
972 timeout_init_done
= TRUE
;
973 if ((status
= get_io_timeouts( hFile
, type
, length
, TRUE
, &timeouts
)))
975 if (hEvent
) NtResetEvent( hEvent
, NULL
);
977 timeout
= get_next_io_timeout( &timeouts
, total
);
979 pfd
.fd
= unix_handle
;
982 if (!timeout
|| !(ret
= poll( &pfd
, 1, timeout
)))
984 if (total
) /* return with what we got so far */
985 status
= STATUS_SUCCESS
;
987 status
= (type
== FD_TYPE_MAILSLOT
) ? STATUS_IO_TIMEOUT
: STATUS_TIMEOUT
;
990 if (ret
== -1 && errno
!= EINTR
)
992 status
= FILE_GetNtStatus();
995 /* will now restart the read */
1000 send_completion
= cvalue
!= 0;
1003 if (needs_close
) close( unix_handle
);
1004 if (status
== STATUS_SUCCESS
|| (status
== STATUS_END_OF_FILE
&& !async_read
))
1006 io_status
->u
.Status
= status
;
1007 io_status
->Information
= total
;
1008 TRACE("= SUCCESS (%u)\n", total
);
1009 if (hEvent
) NtSetEvent( hEvent
, NULL
);
1010 if (apc
&& !status
) NtQueueApcThread( GetCurrentThread(), (PNTAPCFUNC
)apc
,
1011 (ULONG_PTR
)apc_user
, (ULONG_PTR
)io_status
, 0 );
1015 TRACE("= 0x%08x\n", status
);
1016 if (status
!= STATUS_PENDING
&& hEvent
) NtResetEvent( hEvent
, NULL
);
1019 if (send_completion
) NTDLL_AddCompletion( hFile
, cvalue
, status
, total
);
1025 /******************************************************************************
1026 * NtReadFileScatter [NTDLL.@]
1027 * ZwReadFileScatter [NTDLL.@]
1029 NTSTATUS WINAPI
NtReadFileScatter( HANDLE file
, HANDLE event
, PIO_APC_ROUTINE apc
, void *apc_user
,
1030 PIO_STATUS_BLOCK io_status
, FILE_SEGMENT_ELEMENT
*segments
,
1031 ULONG length
, PLARGE_INTEGER offset
, PULONG key
)
1033 int result
, unix_handle
, needs_close
;
1034 unsigned int options
;
1036 ULONG pos
= 0, total
= 0;
1037 enum server_fd_type type
;
1038 ULONG_PTR cvalue
= apc
? 0 : (ULONG_PTR
)apc_user
;
1039 BOOL send_completion
= FALSE
;
1041 TRACE( "(%p,%p,%p,%p,%p,%p,0x%08x,%p,%p),partial stub!\n",
1042 file
, event
, apc
, apc_user
, io_status
, segments
, length
, offset
, key
);
1044 if (length
% page_size
) return STATUS_INVALID_PARAMETER
;
1045 if (!io_status
) return STATUS_ACCESS_VIOLATION
;
1047 status
= server_get_unix_fd( file
, FILE_READ_DATA
, &unix_handle
,
1048 &needs_close
, &type
, &options
);
1049 if (status
) return status
;
1051 if ((type
!= FD_TYPE_FILE
) ||
1052 (options
& (FILE_SYNCHRONOUS_IO_ALERT
| FILE_SYNCHRONOUS_IO_NONALERT
)) ||
1053 !(options
& FILE_NO_INTERMEDIATE_BUFFERING
))
1055 status
= STATUS_INVALID_PARAMETER
;
1061 if (offset
&& offset
->QuadPart
!= FILE_USE_FILE_POINTER_POSITION
)
1062 result
= pread( unix_handle
, (char *)segments
->Buffer
+ pos
,
1063 page_size
- pos
, offset
->QuadPart
+ total
);
1065 result
= read( unix_handle
, (char *)segments
->Buffer
+ pos
, page_size
- pos
);
1069 if (errno
== EINTR
) continue;
1070 status
= FILE_GetNtStatus();
1075 status
= STATUS_END_OF_FILE
;
1080 if ((pos
+= result
) == page_size
)
1087 send_completion
= cvalue
!= 0;
1090 if (needs_close
) close( unix_handle
);
1091 if (status
== STATUS_SUCCESS
)
1093 io_status
->u
.Status
= status
;
1094 io_status
->Information
= total
;
1095 TRACE("= SUCCESS (%u)\n", total
);
1096 if (event
) NtSetEvent( event
, NULL
);
1097 if (apc
) NtQueueApcThread( GetCurrentThread(), (PNTAPCFUNC
)apc
,
1098 (ULONG_PTR
)apc_user
, (ULONG_PTR
)io_status
, 0 );
1102 TRACE("= 0x%08x\n", status
);
1103 if (status
!= STATUS_PENDING
&& event
) NtResetEvent( event
, NULL
);
1106 if (send_completion
) NTDLL_AddCompletion( file
, cvalue
, status
, total
);
1112 /***********************************************************************
1113 * FILE_AsyncWriteService (INTERNAL)
1115 static NTSTATUS
FILE_AsyncWriteService( void *user
, IO_STATUS_BLOCK
*iosb
, NTSTATUS status
)
1117 struct async_fileio_write
*fileio
= user
;
1118 int result
, fd
, needs_close
;
1119 enum server_fd_type type
;
1123 case STATUS_ALERTED
:
1124 /* write some data (non-blocking) */
1125 if ((status
= server_get_unix_fd( fileio
->io
.handle
, FILE_WRITE_DATA
, &fd
,
1126 &needs_close
, &type
, NULL
)))
1129 if (!fileio
->count
&& (type
== FD_TYPE_MAILSLOT
|| type
== FD_TYPE_SOCKET
))
1130 result
= send( fd
, fileio
->buffer
, 0, 0 );
1132 result
= write( fd
, &fileio
->buffer
[fileio
->already
], fileio
->count
- fileio
->already
);
1134 if (needs_close
) close( fd
);
1138 if (errno
== EAGAIN
|| errno
== EINTR
) status
= STATUS_PENDING
;
1139 else status
= FILE_GetNtStatus();
1143 fileio
->already
+= result
;
1144 status
= (fileio
->already
< fileio
->count
) ? STATUS_PENDING
: STATUS_SUCCESS
;
1148 case STATUS_TIMEOUT
:
1149 case STATUS_IO_TIMEOUT
:
1150 if (fileio
->already
) status
= STATUS_SUCCESS
;
1153 if (status
!= STATUS_PENDING
)
1155 iosb
->u
.Status
= status
;
1156 iosb
->Information
= fileio
->already
;
1157 release_fileio( &fileio
->io
);
1162 static NTSTATUS
set_pending_write( HANDLE device
)
1166 SERVER_START_REQ( set_serial_info
)
1168 req
->handle
= wine_server_obj_handle( device
);
1169 req
->flags
= SERIALINFO_PENDING_WRITE
;
1170 status
= wine_server_call( req
);
1176 /******************************************************************************
1177 * NtWriteFile [NTDLL.@]
1178 * ZwWriteFile [NTDLL.@]
1180 * Write to an open file handle.
1183 * FileHandle [I] Handle returned from ZwOpenFile() or ZwCreateFile()
1184 * Event [I] Event to signal upon completion (or NULL)
1185 * ApcRoutine [I] Callback to call upon completion (or NULL)
1186 * ApcContext [I] Context for ApcRoutine (or NULL)
1187 * IoStatusBlock [O] Receives information about the operation on return
1188 * Buffer [I] Source for the data to write
1189 * Length [I] Size of Buffer
1190 * ByteOffset [O] Destination for the new file pointer position (or NULL)
1191 * Key [O] Function unknown (may be NULL)
1194 * Success: 0. IoStatusBlock is updated, and the Information member contains
1195 * The number of bytes written.
1196 * Failure: An NTSTATUS error code describing the error.
1198 NTSTATUS WINAPI
NtWriteFile(HANDLE hFile
, HANDLE hEvent
,
1199 PIO_APC_ROUTINE apc
, void* apc_user
,
1200 PIO_STATUS_BLOCK io_status
,
1201 const void* buffer
, ULONG length
,
1202 PLARGE_INTEGER offset
, PULONG key
)
1204 int result
, unix_handle
, needs_close
;
1205 unsigned int options
;
1206 struct io_timeouts timeouts
;
1209 enum server_fd_type type
;
1210 ULONG_PTR cvalue
= apc
? 0 : (ULONG_PTR
)apc_user
;
1211 BOOL send_completion
= FALSE
, async_write
, append_write
= FALSE
, timeout_init_done
= FALSE
;
1212 LARGE_INTEGER offset_eof
;
1214 TRACE("(%p,%p,%p,%p,%p,%p,0x%08x,%p,%p)!\n",
1215 hFile
,hEvent
,apc
,apc_user
,io_status
,buffer
,length
,offset
,key
);
1217 if (!io_status
) return STATUS_ACCESS_VIOLATION
;
1219 status
= server_get_unix_fd( hFile
, FILE_WRITE_DATA
, &unix_handle
,
1220 &needs_close
, &type
, &options
);
1221 if (status
== STATUS_ACCESS_DENIED
)
1223 status
= server_get_unix_fd( hFile
, FILE_APPEND_DATA
, &unix_handle
,
1224 &needs_close
, &type
, &options
);
1225 append_write
= TRUE
;
1227 if (status
&& status
!= STATUS_BAD_DEVICE_TYPE
) return status
;
1229 if (!virtual_check_buffer_for_read( buffer
, length
))
1231 status
= STATUS_INVALID_USER_BUFFER
;
1235 if (status
== STATUS_BAD_DEVICE_TYPE
)
1236 return server_write_file( hFile
, hEvent
, apc
, apc_user
, io_status
, buffer
, length
, offset
, key
);
1238 async_write
= !(options
& (FILE_SYNCHRONOUS_IO_ALERT
| FILE_SYNCHRONOUS_IO_NONALERT
));
1240 if (type
== FD_TYPE_FILE
)
1243 (!offset
|| (offset
->QuadPart
< 0 && offset
->QuadPart
!= FILE_WRITE_TO_END_OF_FILE
)))
1245 status
= STATUS_INVALID_PARAMETER
;
1251 offset_eof
.QuadPart
= FILE_WRITE_TO_END_OF_FILE
;
1252 offset
= &offset_eof
;
1255 if (offset
&& offset
->QuadPart
!= FILE_USE_FILE_POINTER_POSITION
)
1257 off_t off
= offset
->QuadPart
;
1259 if (offset
->QuadPart
== FILE_WRITE_TO_END_OF_FILE
)
1263 if (fstat( unix_handle
, &st
) == -1)
1265 status
= FILE_GetNtStatus();
1270 else if (offset
->QuadPart
< 0)
1272 status
= STATUS_INVALID_PARAMETER
;
1276 /* async I/O doesn't make sense on regular files */
1277 while ((result
= pwrite( unix_handle
, buffer
, length
, off
)) == -1)
1281 if (errno
== EFAULT
) status
= STATUS_INVALID_USER_BUFFER
;
1282 else status
= FILE_GetNtStatus();
1288 /* update file pointer position */
1289 lseek( unix_handle
, off
+ result
, SEEK_SET
);
1292 status
= STATUS_SUCCESS
;
1296 else if (type
== FD_TYPE_SERIAL
|| type
== FD_TYPE_DEVICE
)
1299 (!offset
|| (offset
->QuadPart
< 0 && offset
->QuadPart
!= FILE_WRITE_TO_END_OF_FILE
)))
1301 status
= STATUS_INVALID_PARAMETER
;
1308 /* zero-length writes on sockets may not work with plain write(2) */
1309 if (!length
&& (type
== FD_TYPE_MAILSLOT
|| type
== FD_TYPE_SOCKET
))
1310 result
= send( unix_handle
, buffer
, 0, 0 );
1312 result
= write( unix_handle
, (const char *)buffer
+ total
, length
- total
);
1317 if (total
== length
)
1319 status
= STATUS_SUCCESS
;
1322 if (type
== FD_TYPE_FILE
) continue; /* no async I/O on regular files */
1324 else if (errno
!= EAGAIN
)
1326 if (errno
== EINTR
) continue;
1329 if (errno
== EFAULT
) status
= STATUS_INVALID_USER_BUFFER
;
1330 else status
= FILE_GetNtStatus();
1337 struct async_fileio_write
*fileio
;
1339 fileio
= (struct async_fileio_write
*)alloc_fileio( sizeof(*fileio
), FILE_AsyncWriteService
, hFile
);
1342 status
= STATUS_NO_MEMORY
;
1345 fileio
->already
= total
;
1346 fileio
->count
= length
;
1347 fileio
->buffer
= buffer
;
1349 SERVER_START_REQ( register_async
)
1351 req
->type
= ASYNC_TYPE_WRITE
;
1352 req
->count
= length
;
1353 req
->async
= server_async( hFile
, &fileio
->io
, hEvent
, apc
, apc_user
, io_status
);
1354 status
= wine_server_call( req
);
1358 if (status
!= STATUS_PENDING
) RtlFreeHeap( GetProcessHeap(), 0, fileio
);
1361 else /* synchronous write, wait for the fd to become ready */
1366 if (!timeout_init_done
)
1368 timeout_init_done
= TRUE
;
1369 if ((status
= get_io_timeouts( hFile
, type
, length
, FALSE
, &timeouts
)))
1371 if (hEvent
) NtResetEvent( hEvent
, NULL
);
1373 timeout
= get_next_io_timeout( &timeouts
, total
);
1375 pfd
.fd
= unix_handle
;
1376 pfd
.events
= POLLOUT
;
1378 if (!timeout
|| !(ret
= poll( &pfd
, 1, timeout
)))
1380 /* return with what we got so far */
1381 status
= total
? STATUS_SUCCESS
: STATUS_TIMEOUT
;
1384 if (ret
== -1 && errno
!= EINTR
)
1386 status
= FILE_GetNtStatus();
1389 /* will now restart the write */
1394 send_completion
= cvalue
!= 0;
1397 if (needs_close
) close( unix_handle
);
1399 if (type
== FD_TYPE_SERIAL
&& (status
== STATUS_SUCCESS
|| status
== STATUS_PENDING
))
1400 set_pending_write( hFile
);
1402 if (status
== STATUS_SUCCESS
)
1404 io_status
->u
.Status
= status
;
1405 io_status
->Information
= total
;
1406 TRACE("= SUCCESS (%u)\n", total
);
1407 if (hEvent
) NtSetEvent( hEvent
, NULL
);
1408 if (apc
) NtQueueApcThread( GetCurrentThread(), (PNTAPCFUNC
)apc
,
1409 (ULONG_PTR
)apc_user
, (ULONG_PTR
)io_status
, 0 );
1413 TRACE("= 0x%08x\n", status
);
1414 if (status
!= STATUS_PENDING
&& hEvent
) NtResetEvent( hEvent
, NULL
);
1417 if (send_completion
) NTDLL_AddCompletion( hFile
, cvalue
, status
, total
);
1423 /******************************************************************************
1424 * NtWriteFileGather [NTDLL.@]
1425 * ZwWriteFileGather [NTDLL.@]
1427 NTSTATUS WINAPI
NtWriteFileGather( HANDLE file
, HANDLE event
, PIO_APC_ROUTINE apc
, void *apc_user
,
1428 PIO_STATUS_BLOCK io_status
, FILE_SEGMENT_ELEMENT
*segments
,
1429 ULONG length
, PLARGE_INTEGER offset
, PULONG key
)
1431 int result
, unix_handle
, needs_close
;
1432 unsigned int options
;
1434 ULONG pos
= 0, total
= 0;
1435 enum server_fd_type type
;
1436 ULONG_PTR cvalue
= apc
? 0 : (ULONG_PTR
)apc_user
;
1437 BOOL send_completion
= FALSE
;
1439 TRACE( "(%p,%p,%p,%p,%p,%p,0x%08x,%p,%p),partial stub!\n",
1440 file
, event
, apc
, apc_user
, io_status
, segments
, length
, offset
, key
);
1442 if (length
% page_size
) return STATUS_INVALID_PARAMETER
;
1443 if (!io_status
) return STATUS_ACCESS_VIOLATION
;
1445 status
= server_get_unix_fd( file
, FILE_WRITE_DATA
, &unix_handle
,
1446 &needs_close
, &type
, &options
);
1447 if (status
) return status
;
1449 if ((type
!= FD_TYPE_FILE
) ||
1450 (options
& (FILE_SYNCHRONOUS_IO_ALERT
| FILE_SYNCHRONOUS_IO_NONALERT
)) ||
1451 !(options
& FILE_NO_INTERMEDIATE_BUFFERING
))
1453 status
= STATUS_INVALID_PARAMETER
;
1459 if (offset
&& offset
->QuadPart
!= FILE_USE_FILE_POINTER_POSITION
)
1460 result
= pwrite( unix_handle
, (char *)segments
->Buffer
+ pos
,
1461 page_size
- pos
, offset
->QuadPart
+ total
);
1463 result
= write( unix_handle
, (char *)segments
->Buffer
+ pos
, page_size
- pos
);
1467 if (errno
== EINTR
) continue;
1468 if (errno
== EFAULT
)
1470 status
= STATUS_INVALID_USER_BUFFER
;
1473 status
= FILE_GetNtStatus();
1478 status
= STATUS_DISK_FULL
;
1483 if ((pos
+= result
) == page_size
)
1490 send_completion
= cvalue
!= 0;
1493 if (needs_close
) close( unix_handle
);
1494 if (status
== STATUS_SUCCESS
)
1496 io_status
->u
.Status
= status
;
1497 io_status
->Information
= total
;
1498 TRACE("= SUCCESS (%u)\n", total
);
1499 if (event
) NtSetEvent( event
, NULL
);
1500 if (apc
) NtQueueApcThread( GetCurrentThread(), (PNTAPCFUNC
)apc
,
1501 (ULONG_PTR
)apc_user
, (ULONG_PTR
)io_status
, 0 );
1505 TRACE("= 0x%08x\n", status
);
1506 if (status
!= STATUS_PENDING
&& event
) NtResetEvent( event
, NULL
);
1509 if (send_completion
) NTDLL_AddCompletion( file
, cvalue
, status
, total
);
1515 /* do an ioctl call through the server */
1516 static NTSTATUS
server_ioctl_file( HANDLE handle
, HANDLE event
,
1517 PIO_APC_ROUTINE apc
, PVOID apc_context
,
1518 IO_STATUS_BLOCK
*io
, ULONG code
,
1519 const void *in_buffer
, ULONG in_size
,
1520 PVOID out_buffer
, ULONG out_size
)
1522 struct async_irp
*async
;
1527 if (!(async
= (struct async_irp
*)alloc_fileio( sizeof(*async
), irp_completion
, handle
)))
1528 return STATUS_NO_MEMORY
;
1529 async
->event
= event
;
1530 async
->buffer
= out_buffer
;
1531 async
->size
= out_size
;
1533 SERVER_START_REQ( ioctl
)
1536 req
->async
= server_async( handle
, &async
->io
, event
, apc
, apc_context
, io
);
1537 wine_server_add_data( req
, in_buffer
, in_size
);
1538 if ((code
& 3) != METHOD_BUFFERED
)
1539 wine_server_add_data( req
, out_buffer
, out_size
);
1540 wine_server_set_reply( req
, out_buffer
, out_size
);
1541 status
= virtual_locked_server_call( req
);
1542 wait_handle
= wine_server_ptr_handle( reply
->wait
);
1543 options
= reply
->options
;
1544 if (wait_handle
&& status
!= STATUS_PENDING
)
1546 io
->u
.Status
= status
;
1547 io
->Information
= wine_server_reply_size( reply
);
1552 if (status
== STATUS_NOT_SUPPORTED
)
1553 FIXME("Unsupported ioctl %x (device=%x access=%x func=%x method=%x)\n",
1554 code
, code
>> 16, (code
>> 14) & 3, (code
>> 2) & 0xfff, code
& 3);
1556 if (status
!= STATUS_PENDING
) RtlFreeHeap( GetProcessHeap(), 0, async
);
1560 NtWaitForSingleObject( wait_handle
, (options
& FILE_SYNCHRONOUS_IO_ALERT
), NULL
);
1561 status
= io
->u
.Status
;
1567 /* Tell Valgrind to ignore any holes in structs we will be passing to the
1569 static void ignore_server_ioctl_struct_holes (ULONG code
, const void *in_buffer
,
1572 #ifdef VALGRIND_MAKE_MEM_DEFINED
1573 # define IGNORE_STRUCT_HOLE(buf, size, t, f1, f2) \
1575 if (FIELD_OFFSET(t, f1) + sizeof(((t *)0)->f1) < FIELD_OFFSET(t, f2)) \
1576 if ((size) >= FIELD_OFFSET(t, f2)) \
1577 VALGRIND_MAKE_MEM_DEFINED( \
1578 (const char *)(buf) + FIELD_OFFSET(t, f1) + sizeof(((t *)0)->f1), \
1579 FIELD_OFFSET(t, f2) - FIELD_OFFSET(t, f1) + sizeof(((t *)0)->f1)); \
1584 case FSCTL_PIPE_WAIT
:
1585 IGNORE_STRUCT_HOLE(in_buffer
, in_size
, FILE_PIPE_WAIT_FOR_BUFFER
, TimeoutSpecified
, Name
);
1592 /**************************************************************************
1593 * NtDeviceIoControlFile [NTDLL.@]
1594 * ZwDeviceIoControlFile [NTDLL.@]
1596 * Perform an I/O control operation on an open file handle.
1599 * handle [I] Handle returned from ZwOpenFile() or ZwCreateFile()
1600 * event [I] Event to signal upon completion (or NULL)
1601 * apc [I] Callback to call upon completion (or NULL)
1602 * apc_context [I] Context for ApcRoutine (or NULL)
1603 * io [O] Receives information about the operation on return
1604 * code [I] Control code for the operation to perform
1605 * in_buffer [I] Source for any input data required (or NULL)
1606 * in_size [I] Size of InputBuffer
1607 * out_buffer [O] Source for any output data returned (or NULL)
1608 * out_size [I] Size of OutputBuffer
1611 * Success: 0. IoStatusBlock is updated.
1612 * Failure: An NTSTATUS error code describing the error.
1614 NTSTATUS WINAPI
NtDeviceIoControlFile(HANDLE handle
, HANDLE event
,
1615 PIO_APC_ROUTINE apc
, PVOID apc_context
,
1616 PIO_STATUS_BLOCK io
, ULONG code
,
1617 PVOID in_buffer
, ULONG in_size
,
1618 PVOID out_buffer
, ULONG out_size
)
1620 ULONG device
= (code
>> 16);
1621 NTSTATUS status
= STATUS_NOT_SUPPORTED
;
1623 TRACE("(%p,%p,%p,%p,%p,0x%08x,%p,0x%08x,%p,0x%08x)\n",
1624 handle
, event
, apc
, apc_context
, io
, code
,
1625 in_buffer
, in_size
, out_buffer
, out_size
);
1629 case FILE_DEVICE_DISK
:
1630 case FILE_DEVICE_CD_ROM
:
1631 case FILE_DEVICE_DVD
:
1632 case FILE_DEVICE_CONTROLLER
:
1633 case FILE_DEVICE_MASS_STORAGE
:
1634 status
= CDROM_DeviceIoControl(handle
, event
, apc
, apc_context
, io
, code
,
1635 in_buffer
, in_size
, out_buffer
, out_size
);
1637 case FILE_DEVICE_SERIAL_PORT
:
1638 status
= COMM_DeviceIoControl(handle
, event
, apc
, apc_context
, io
, code
,
1639 in_buffer
, in_size
, out_buffer
, out_size
);
1641 case FILE_DEVICE_TAPE
:
1642 status
= TAPE_DeviceIoControl(handle
, event
, apc
, apc_context
, io
, code
,
1643 in_buffer
, in_size
, out_buffer
, out_size
);
1647 if (status
== STATUS_NOT_SUPPORTED
|| status
== STATUS_BAD_DEVICE_TYPE
)
1648 return server_ioctl_file( handle
, event
, apc
, apc_context
, io
, code
,
1649 in_buffer
, in_size
, out_buffer
, out_size
);
1651 if (status
!= STATUS_PENDING
) io
->u
.Status
= status
;
1656 /**************************************************************************
1657 * NtFsControlFile [NTDLL.@]
1658 * ZwFsControlFile [NTDLL.@]
1660 * Perform a file system control operation on an open file handle.
1663 * handle [I] Handle returned from ZwOpenFile() or ZwCreateFile()
1664 * event [I] Event to signal upon completion (or NULL)
1665 * apc [I] Callback to call upon completion (or NULL)
1666 * apc_context [I] Context for ApcRoutine (or NULL)
1667 * io [O] Receives information about the operation on return
1668 * code [I] Control code for the operation to perform
1669 * in_buffer [I] Source for any input data required (or NULL)
1670 * in_size [I] Size of InputBuffer
1671 * out_buffer [O] Source for any output data returned (or NULL)
1672 * out_size [I] Size of OutputBuffer
1675 * Success: 0. IoStatusBlock is updated.
1676 * Failure: An NTSTATUS error code describing the error.
1678 NTSTATUS WINAPI
NtFsControlFile(HANDLE handle
, HANDLE event
, PIO_APC_ROUTINE apc
,
1679 PVOID apc_context
, PIO_STATUS_BLOCK io
, ULONG code
,
1680 PVOID in_buffer
, ULONG in_size
, PVOID out_buffer
, ULONG out_size
)
1684 TRACE("(%p,%p,%p,%p,%p,0x%08x,%p,0x%08x,%p,0x%08x)\n",
1685 handle
, event
, apc
, apc_context
, io
, code
,
1686 in_buffer
, in_size
, out_buffer
, out_size
);
1688 if (!io
) return STATUS_INVALID_PARAMETER
;
1690 ignore_server_ioctl_struct_holes( code
, in_buffer
, in_size
);
1694 case FSCTL_DISMOUNT_VOLUME
:
1695 status
= server_ioctl_file( handle
, event
, apc
, apc_context
, io
, code
,
1696 in_buffer
, in_size
, out_buffer
, out_size
);
1697 if (!status
) status
= DIR_unmount_device( handle
);
1700 case FSCTL_PIPE_DISCONNECT
:
1701 status
= server_ioctl_file( handle
, event
, apc
, apc_context
, io
, code
,
1702 in_buffer
, in_size
, out_buffer
, out_size
);
1705 int fd
= server_remove_fd_from_cache( handle
);
1706 if (fd
!= -1) close( fd
);
1710 case FSCTL_PIPE_IMPERSONATE
:
1711 FIXME("FSCTL_PIPE_IMPERSONATE: impersonating self\n");
1712 status
= RtlImpersonateSelf( SecurityImpersonation
);
1715 case FSCTL_IS_VOLUME_MOUNTED
:
1716 case FSCTL_LOCK_VOLUME
:
1717 case FSCTL_UNLOCK_VOLUME
:
1718 FIXME("stub! return success - Unsupported fsctl %x (device=%x access=%x func=%x method=%x)\n",
1719 code
, code
>> 16, (code
>> 14) & 3, (code
>> 2) & 0xfff, code
& 3);
1720 status
= STATUS_SUCCESS
;
1723 case FSCTL_GET_RETRIEVAL_POINTERS
:
1725 RETRIEVAL_POINTERS_BUFFER
*buffer
= (RETRIEVAL_POINTERS_BUFFER
*)out_buffer
;
1727 FIXME("stub: FSCTL_GET_RETRIEVAL_POINTERS\n");
1729 if (out_size
>= sizeof(RETRIEVAL_POINTERS_BUFFER
))
1731 buffer
->ExtentCount
= 1;
1732 buffer
->StartingVcn
.QuadPart
= 1;
1733 buffer
->Extents
[0].NextVcn
.QuadPart
= 0;
1734 buffer
->Extents
[0].Lcn
.QuadPart
= 0;
1735 io
->Information
= sizeof(RETRIEVAL_POINTERS_BUFFER
);
1736 status
= STATUS_SUCCESS
;
1740 io
->Information
= 0;
1741 status
= STATUS_BUFFER_TOO_SMALL
;
1745 case FSCTL_SET_SPARSE
:
1746 TRACE("FSCTL_SET_SPARSE: Ignoring request\n");
1747 io
->Information
= 0;
1748 status
= STATUS_SUCCESS
;
1751 return server_ioctl_file( handle
, event
, apc
, apc_context
, io
, code
,
1752 in_buffer
, in_size
, out_buffer
, out_size
);
1755 if (status
!= STATUS_PENDING
) io
->u
.Status
= status
;
1760 struct read_changes_fileio
1762 struct async_fileio io
;
1769 static NTSTATUS
read_changes_apc( void *user
, IO_STATUS_BLOCK
*iosb
, NTSTATUS status
)
1771 struct read_changes_fileio
*fileio
= user
;
1774 if (status
== STATUS_ALERTED
)
1776 SERVER_START_REQ( read_change
)
1778 req
->handle
= wine_server_obj_handle( fileio
->io
.handle
);
1779 wine_server_set_reply( req
, fileio
->data
, fileio
->data_size
);
1780 status
= wine_server_call( req
);
1781 size
= wine_server_reply_size( reply
);
1785 if (status
== STATUS_SUCCESS
&& fileio
->buffer
)
1787 FILE_NOTIFY_INFORMATION
*pfni
= fileio
->buffer
;
1788 int i
, left
= fileio
->buffer_size
;
1789 DWORD
*last_entry_offset
= NULL
;
1790 struct filesystem_event
*event
= (struct filesystem_event
*)fileio
->data
;
1792 while (size
&& left
>= sizeof(*pfni
))
1794 /* convert to an NT style path */
1795 for (i
= 0; i
< event
->len
; i
++)
1796 if (event
->name
[i
] == '/') event
->name
[i
] = '\\';
1798 pfni
->Action
= event
->action
;
1799 pfni
->FileNameLength
= ntdll_umbstowcs( 0, event
->name
, event
->len
, pfni
->FileName
,
1800 (left
- offsetof(FILE_NOTIFY_INFORMATION
, FileName
)) / sizeof(WCHAR
));
1801 last_entry_offset
= &pfni
->NextEntryOffset
;
1803 if (pfni
->FileNameLength
== -1 || pfni
->FileNameLength
== -2) break;
1805 i
= offsetof(FILE_NOTIFY_INFORMATION
, FileName
[pfni
->FileNameLength
]);
1806 pfni
->FileNameLength
*= sizeof(WCHAR
);
1807 pfni
->NextEntryOffset
= i
;
1808 pfni
= (FILE_NOTIFY_INFORMATION
*)((char*)pfni
+ i
);
1811 i
= (offsetof(struct filesystem_event
, name
[event
->len
])
1812 + sizeof(int)-1) / sizeof(int) * sizeof(int);
1813 event
= (struct filesystem_event
*)((char*)event
+ i
);
1819 status
= STATUS_NOTIFY_ENUM_DIR
;
1824 if (last_entry_offset
) *last_entry_offset
= 0;
1825 size
= fileio
->buffer_size
- left
;
1830 status
= STATUS_NOTIFY_ENUM_DIR
;
1835 if (status
!= STATUS_PENDING
)
1837 iosb
->u
.Status
= status
;
1838 iosb
->Information
= size
;
1839 release_fileio( &fileio
->io
);
1844 #define FILE_NOTIFY_ALL ( \
1845 FILE_NOTIFY_CHANGE_FILE_NAME | \
1846 FILE_NOTIFY_CHANGE_DIR_NAME | \
1847 FILE_NOTIFY_CHANGE_ATTRIBUTES | \
1848 FILE_NOTIFY_CHANGE_SIZE | \
1849 FILE_NOTIFY_CHANGE_LAST_WRITE | \
1850 FILE_NOTIFY_CHANGE_LAST_ACCESS | \
1851 FILE_NOTIFY_CHANGE_CREATION | \
1852 FILE_NOTIFY_CHANGE_SECURITY )
1854 /******************************************************************************
1855 * NtNotifyChangeDirectoryFile [NTDLL.@]
1857 NTSTATUS WINAPI
NtNotifyChangeDirectoryFile( HANDLE handle
, HANDLE event
, PIO_APC_ROUTINE apc
,
1858 void *apc_context
, PIO_STATUS_BLOCK iosb
, void *buffer
,
1859 ULONG buffer_size
, ULONG filter
, BOOLEAN subtree
)
1861 struct read_changes_fileio
*fileio
;
1863 ULONG size
= max( 4096, buffer_size
);
1865 TRACE( "%p %p %p %p %p %p %u %u %d\n",
1866 handle
, event
, apc
, apc_context
, iosb
, buffer
, buffer_size
, filter
, subtree
);
1868 if (!iosb
) return STATUS_ACCESS_VIOLATION
;
1869 if (filter
== 0 || (filter
& ~FILE_NOTIFY_ALL
)) return STATUS_INVALID_PARAMETER
;
1871 fileio
= (struct read_changes_fileio
*)alloc_fileio( offsetof(struct read_changes_fileio
, data
[size
]),
1872 read_changes_apc
, handle
);
1873 if (!fileio
) return STATUS_NO_MEMORY
;
1875 fileio
->buffer
= buffer
;
1876 fileio
->buffer_size
= buffer_size
;
1877 fileio
->data_size
= size
;
1879 SERVER_START_REQ( read_directory_changes
)
1881 req
->filter
= filter
;
1882 req
->want_data
= (buffer
!= NULL
);
1883 req
->subtree
= subtree
;
1884 req
->async
= server_async( handle
, &fileio
->io
, event
, apc
, apc_context
, iosb
);
1885 status
= wine_server_call( req
);
1889 if (status
!= STATUS_PENDING
) RtlFreeHeap( GetProcessHeap(), 0, fileio
);
1893 /******************************************************************************
1894 * NtSetVolumeInformationFile [NTDLL.@]
1895 * ZwSetVolumeInformationFile [NTDLL.@]
1897 * Set volume information for an open file handle.
1900 * FileHandle [I] Handle returned from ZwOpenFile() or ZwCreateFile()
1901 * IoStatusBlock [O] Receives information about the operation on return
1902 * FsInformation [I] Source for volume information
1903 * Length [I] Size of FsInformation
1904 * FsInformationClass [I] Type of volume information to set
1907 * Success: 0. IoStatusBlock is updated.
1908 * Failure: An NTSTATUS error code describing the error.
1910 NTSTATUS WINAPI
NtSetVolumeInformationFile(
1911 IN HANDLE FileHandle
,
1912 PIO_STATUS_BLOCK IoStatusBlock
,
1913 PVOID FsInformation
,
1915 FS_INFORMATION_CLASS FsInformationClass
)
1917 FIXME("(%p,%p,%p,0x%08x,0x%08x) stub\n",
1918 FileHandle
,IoStatusBlock
,FsInformation
,Length
,FsInformationClass
);
1922 #if defined(__ANDROID__) && !defined(HAVE_FUTIMENS)
1923 static int futimens( int fd
, const struct timespec spec
[2] )
1925 return syscall( __NR_utimensat
, fd
, NULL
, spec
, 0 );
1927 #define HAVE_FUTIMENS
1928 #endif /* __ANDROID__ */
1931 #define UTIME_OMIT ((1 << 30) - 2)
1934 static NTSTATUS
set_file_times( int fd
, const LARGE_INTEGER
*mtime
, const LARGE_INTEGER
*atime
)
1936 NTSTATUS status
= STATUS_SUCCESS
;
1938 #ifdef HAVE_FUTIMENS
1939 struct timespec tv
[2];
1941 tv
[0].tv_sec
= tv
[1].tv_sec
= 0;
1942 tv
[0].tv_nsec
= tv
[1].tv_nsec
= UTIME_OMIT
;
1943 if (atime
->QuadPart
)
1945 tv
[0].tv_sec
= atime
->QuadPart
/ 10000000 - SECS_1601_TO_1970
;
1946 tv
[0].tv_nsec
= (atime
->QuadPart
% 10000000) * 100;
1948 if (mtime
->QuadPart
)
1950 tv
[1].tv_sec
= mtime
->QuadPart
/ 10000000 - SECS_1601_TO_1970
;
1951 tv
[1].tv_nsec
= (mtime
->QuadPart
% 10000000) * 100;
1953 if (futimens( fd
, tv
) == -1) status
= FILE_GetNtStatus();
1955 #elif defined(HAVE_FUTIMES) || defined(HAVE_FUTIMESAT)
1956 struct timeval tv
[2];
1959 if (!atime
->QuadPart
|| !mtime
->QuadPart
)
1962 tv
[0].tv_sec
= tv
[0].tv_usec
= 0;
1963 tv
[1].tv_sec
= tv
[1].tv_usec
= 0;
1964 if (!fstat( fd
, &st
))
1966 tv
[0].tv_sec
= st
.st_atime
;
1967 tv
[1].tv_sec
= st
.st_mtime
;
1968 #ifdef HAVE_STRUCT_STAT_ST_ATIM
1969 tv
[0].tv_usec
= st
.st_atim
.tv_nsec
/ 1000;
1970 #elif defined(HAVE_STRUCT_STAT_ST_ATIMESPEC)
1971 tv
[0].tv_usec
= st
.st_atimespec
.tv_nsec
/ 1000;
1973 #ifdef HAVE_STRUCT_STAT_ST_MTIM
1974 tv
[1].tv_usec
= st
.st_mtim
.tv_nsec
/ 1000;
1975 #elif defined(HAVE_STRUCT_STAT_ST_MTIMESPEC)
1976 tv
[1].tv_usec
= st
.st_mtimespec
.tv_nsec
/ 1000;
1980 if (atime
->QuadPart
)
1982 tv
[0].tv_sec
= atime
->QuadPart
/ 10000000 - SECS_1601_TO_1970
;
1983 tv
[0].tv_usec
= (atime
->QuadPart
% 10000000) / 10;
1985 if (mtime
->QuadPart
)
1987 tv
[1].tv_sec
= mtime
->QuadPart
/ 10000000 - SECS_1601_TO_1970
;
1988 tv
[1].tv_usec
= (mtime
->QuadPart
% 10000000) / 10;
1991 if (futimes( fd
, tv
) == -1) status
= FILE_GetNtStatus();
1992 #elif defined(HAVE_FUTIMESAT)
1993 if (futimesat( fd
, NULL
, tv
) == -1) status
= FILE_GetNtStatus();
1996 #else /* HAVE_FUTIMES || HAVE_FUTIMESAT */
1997 FIXME( "setting file times not supported\n" );
1998 status
= STATUS_NOT_IMPLEMENTED
;
2003 static inline void get_file_times( const struct stat
*st
, LARGE_INTEGER
*mtime
, LARGE_INTEGER
*ctime
,
2004 LARGE_INTEGER
*atime
, LARGE_INTEGER
*creation
)
2006 RtlSecondsSince1970ToTime( st
->st_mtime
, mtime
);
2007 RtlSecondsSince1970ToTime( st
->st_ctime
, ctime
);
2008 RtlSecondsSince1970ToTime( st
->st_atime
, atime
);
2009 #ifdef HAVE_STRUCT_STAT_ST_MTIM
2010 mtime
->QuadPart
+= st
->st_mtim
.tv_nsec
/ 100;
2011 #elif defined(HAVE_STRUCT_STAT_ST_MTIMESPEC)
2012 mtime
->QuadPart
+= st
->st_mtimespec
.tv_nsec
/ 100;
2014 #ifdef HAVE_STRUCT_STAT_ST_CTIM
2015 ctime
->QuadPart
+= st
->st_ctim
.tv_nsec
/ 100;
2016 #elif defined(HAVE_STRUCT_STAT_ST_CTIMESPEC)
2017 ctime
->QuadPart
+= st
->st_ctimespec
.tv_nsec
/ 100;
2019 #ifdef HAVE_STRUCT_STAT_ST_ATIM
2020 atime
->QuadPart
+= st
->st_atim
.tv_nsec
/ 100;
2021 #elif defined(HAVE_STRUCT_STAT_ST_ATIMESPEC)
2022 atime
->QuadPart
+= st
->st_atimespec
.tv_nsec
/ 100;
2024 #ifdef HAVE_STRUCT_STAT_ST_BIRTHTIME
2025 RtlSecondsSince1970ToTime( st
->st_birthtime
, creation
);
2026 #ifdef HAVE_STRUCT_STAT_ST_BIRTHTIM
2027 creation
->QuadPart
+= st
->st_birthtim
.tv_nsec
/ 100;
2028 #elif defined(HAVE_STRUCT_STAT_ST_BIRTHTIMESPEC)
2029 creation
->QuadPart
+= st
->st_birthtimespec
.tv_nsec
/ 100;
2031 #elif defined(HAVE_STRUCT_STAT___ST_BIRTHTIME)
2032 RtlSecondsSince1970ToTime( st
->__st_birthtime
, creation
);
2033 #ifdef HAVE_STRUCT_STAT___ST_BIRTHTIM
2034 creation
->QuadPart
+= st
->__st_birthtim
.tv_nsec
/ 100;
2041 /* fill in the file information that depends on the stat and attribute info */
2042 NTSTATUS
fill_file_info( const struct stat
*st
, ULONG attr
, void *ptr
,
2043 FILE_INFORMATION_CLASS
class )
2047 case FileBasicInformation
:
2049 FILE_BASIC_INFORMATION
*info
= ptr
;
2051 get_file_times( st
, &info
->LastWriteTime
, &info
->ChangeTime
,
2052 &info
->LastAccessTime
, &info
->CreationTime
);
2053 info
->FileAttributes
= attr
;
2056 case FileStandardInformation
:
2058 FILE_STANDARD_INFORMATION
*info
= ptr
;
2060 if ((info
->Directory
= S_ISDIR(st
->st_mode
)))
2062 info
->AllocationSize
.QuadPart
= 0;
2063 info
->EndOfFile
.QuadPart
= 0;
2064 info
->NumberOfLinks
= 1;
2068 info
->AllocationSize
.QuadPart
= (ULONGLONG
)st
->st_blocks
* 512;
2069 info
->EndOfFile
.QuadPart
= st
->st_size
;
2070 info
->NumberOfLinks
= st
->st_nlink
;
2074 case FileInternalInformation
:
2076 FILE_INTERNAL_INFORMATION
*info
= ptr
;
2077 info
->IndexNumber
.QuadPart
= st
->st_ino
;
2080 case FileEndOfFileInformation
:
2082 FILE_END_OF_FILE_INFORMATION
*info
= ptr
;
2083 info
->EndOfFile
.QuadPart
= S_ISDIR(st
->st_mode
) ? 0 : st
->st_size
;
2086 case FileAllInformation
:
2088 FILE_ALL_INFORMATION
*info
= ptr
;
2089 fill_file_info( st
, attr
, &info
->BasicInformation
, FileBasicInformation
);
2090 fill_file_info( st
, attr
, &info
->StandardInformation
, FileStandardInformation
);
2091 fill_file_info( st
, attr
, &info
->InternalInformation
, FileInternalInformation
);
2094 /* all directory structures start with the FileDirectoryInformation layout */
2095 case FileBothDirectoryInformation
:
2096 case FileFullDirectoryInformation
:
2097 case FileDirectoryInformation
:
2099 FILE_DIRECTORY_INFORMATION
*info
= ptr
;
2101 get_file_times( st
, &info
->LastWriteTime
, &info
->ChangeTime
,
2102 &info
->LastAccessTime
, &info
->CreationTime
);
2103 if (S_ISDIR(st
->st_mode
))
2105 info
->AllocationSize
.QuadPart
= 0;
2106 info
->EndOfFile
.QuadPart
= 0;
2110 info
->AllocationSize
.QuadPart
= (ULONGLONG
)st
->st_blocks
* 512;
2111 info
->EndOfFile
.QuadPart
= st
->st_size
;
2113 info
->FileAttributes
= attr
;
2116 case FileIdFullDirectoryInformation
:
2118 FILE_ID_FULL_DIRECTORY_INFORMATION
*info
= ptr
;
2119 info
->FileId
.QuadPart
= st
->st_ino
;
2120 fill_file_info( st
, attr
, info
, FileDirectoryInformation
);
2123 case FileIdBothDirectoryInformation
:
2125 FILE_ID_BOTH_DIRECTORY_INFORMATION
*info
= ptr
;
2126 info
->FileId
.QuadPart
= st
->st_ino
;
2127 fill_file_info( st
, attr
, info
, FileDirectoryInformation
);
2130 case FileIdGlobalTxDirectoryInformation
:
2132 FILE_ID_GLOBAL_TX_DIR_INFORMATION
*info
= ptr
;
2133 info
->FileId
.QuadPart
= st
->st_ino
;
2134 fill_file_info( st
, attr
, info
, FileDirectoryInformation
);
2139 return STATUS_INVALID_INFO_CLASS
;
2141 return STATUS_SUCCESS
;
2144 NTSTATUS
server_get_unix_name( HANDLE handle
, ANSI_STRING
*unix_name
)
2146 data_size_t size
= 1024;
2152 name
= RtlAllocateHeap( GetProcessHeap(), 0, size
+ 1 );
2153 if (!name
) return STATUS_NO_MEMORY
;
2154 unix_name
->MaximumLength
= size
+ 1;
2156 SERVER_START_REQ( get_handle_unix_name
)
2158 req
->handle
= wine_server_obj_handle( handle
);
2159 wine_server_set_reply( req
, name
, size
);
2160 ret
= wine_server_call( req
);
2161 size
= reply
->name_len
;
2168 unix_name
->Buffer
= name
;
2169 unix_name
->Length
= size
;
2172 RtlFreeHeap( GetProcessHeap(), 0, name
);
2173 if (ret
!= STATUS_BUFFER_OVERFLOW
) break;
2178 static NTSTATUS
fill_name_info( const ANSI_STRING
*unix_name
, FILE_NAME_INFORMATION
*info
, LONG
*name_len
)
2180 UNICODE_STRING nt_name
;
2183 if (!(status
= wine_unix_to_nt_file_name( unix_name
, &nt_name
)))
2185 const WCHAR
*ptr
= nt_name
.Buffer
;
2186 const WCHAR
*end
= ptr
+ (nt_name
.Length
/ sizeof(WCHAR
));
2188 /* Skip the volume mount point. */
2189 while (ptr
!= end
&& *ptr
== '\\') ++ptr
;
2190 while (ptr
!= end
&& *ptr
!= '\\') ++ptr
;
2191 while (ptr
!= end
&& *ptr
== '\\') ++ptr
;
2192 while (ptr
!= end
&& *ptr
!= '\\') ++ptr
;
2194 info
->FileNameLength
= (end
- ptr
) * sizeof(WCHAR
);
2195 if (*name_len
< info
->FileNameLength
) status
= STATUS_BUFFER_OVERFLOW
;
2196 else *name_len
= info
->FileNameLength
;
2198 memcpy( info
->FileName
, ptr
, *name_len
);
2199 RtlFreeUnicodeString( &nt_name
);
2205 /******************************************************************************
2206 * NtQueryInformationFile [NTDLL.@]
2207 * ZwQueryInformationFile [NTDLL.@]
2209 * Get information about an open file handle.
2212 * hFile [I] Handle returned from ZwOpenFile() or ZwCreateFile()
2213 * io [O] Receives information about the operation on return
2214 * ptr [O] Destination for file information
2215 * len [I] Size of FileInformation
2216 * class [I] Type of file information to get
2219 * Success: 0. IoStatusBlock and FileInformation are updated.
2220 * Failure: An NTSTATUS error code describing the error.
2222 NTSTATUS WINAPI
NtQueryInformationFile( HANDLE hFile
, PIO_STATUS_BLOCK io
,
2223 PVOID ptr
, LONG len
, FILE_INFORMATION_CLASS
class )
2225 static const size_t info_sizes
[] =
2228 sizeof(FILE_DIRECTORY_INFORMATION
), /* FileDirectoryInformation */
2229 sizeof(FILE_FULL_DIRECTORY_INFORMATION
), /* FileFullDirectoryInformation */
2230 sizeof(FILE_BOTH_DIRECTORY_INFORMATION
), /* FileBothDirectoryInformation */
2231 sizeof(FILE_BASIC_INFORMATION
), /* FileBasicInformation */
2232 sizeof(FILE_STANDARD_INFORMATION
), /* FileStandardInformation */
2233 sizeof(FILE_INTERNAL_INFORMATION
), /* FileInternalInformation */
2234 sizeof(FILE_EA_INFORMATION
), /* FileEaInformation */
2235 sizeof(FILE_ACCESS_INFORMATION
), /* FileAccessInformation */
2236 sizeof(FILE_NAME_INFORMATION
), /* FileNameInformation */
2237 sizeof(FILE_RENAME_INFORMATION
)-sizeof(WCHAR
), /* FileRenameInformation */
2238 0, /* FileLinkInformation */
2239 sizeof(FILE_NAMES_INFORMATION
)-sizeof(WCHAR
), /* FileNamesInformation */
2240 sizeof(FILE_DISPOSITION_INFORMATION
), /* FileDispositionInformation */
2241 sizeof(FILE_POSITION_INFORMATION
), /* FilePositionInformation */
2242 sizeof(FILE_FULL_EA_INFORMATION
), /* FileFullEaInformation */
2243 sizeof(FILE_MODE_INFORMATION
), /* FileModeInformation */
2244 sizeof(FILE_ALIGNMENT_INFORMATION
), /* FileAlignmentInformation */
2245 sizeof(FILE_ALL_INFORMATION
), /* FileAllInformation */
2246 sizeof(FILE_ALLOCATION_INFORMATION
), /* FileAllocationInformation */
2247 sizeof(FILE_END_OF_FILE_INFORMATION
), /* FileEndOfFileInformation */
2248 0, /* FileAlternateNameInformation */
2249 sizeof(FILE_STREAM_INFORMATION
)-sizeof(WCHAR
), /* FileStreamInformation */
2250 sizeof(FILE_PIPE_INFORMATION
), /* FilePipeInformation */
2251 sizeof(FILE_PIPE_LOCAL_INFORMATION
), /* FilePipeLocalInformation */
2252 0, /* FilePipeRemoteInformation */
2253 sizeof(FILE_MAILSLOT_QUERY_INFORMATION
), /* FileMailslotQueryInformation */
2254 0, /* FileMailslotSetInformation */
2255 0, /* FileCompressionInformation */
2256 0, /* FileObjectIdInformation */
2257 0, /* FileCompletionInformation */
2258 0, /* FileMoveClusterInformation */
2259 0, /* FileQuotaInformation */
2260 0, /* FileReparsePointInformation */
2261 sizeof(FILE_NETWORK_OPEN_INFORMATION
), /* FileNetworkOpenInformation */
2262 0, /* FileAttributeTagInformation */
2263 0, /* FileTrackingInformation */
2264 0, /* FileIdBothDirectoryInformation */
2265 0, /* FileIdFullDirectoryInformation */
2266 0, /* FileValidDataLengthInformation */
2267 0, /* FileShortNameInformation */
2268 0, /* FileIoCompletionNotificationInformation, */
2269 0, /* FileIoStatusBlockRangeInformation */
2270 0, /* FileIoPriorityHintInformation */
2271 0, /* FileSfioReserveInformation */
2272 0, /* FileSfioVolumeInformation */
2273 0, /* FileHardLinkInformation */
2274 0, /* FileProcessIdsUsingFileInformation */
2275 0, /* FileNormalizedNameInformation */
2276 0, /* FileNetworkPhysicalNameInformation */
2277 0, /* FileIdGlobalTxDirectoryInformation */
2278 0, /* FileIsRemoteDeviceInformation */
2279 0, /* FileAttributeCacheInformation */
2280 0, /* FileNumaNodeInformation */
2281 0, /* FileStandardLinkInformation */
2282 0, /* FileRemoteProtocolInformation */
2283 0, /* FileRenameInformationBypassAccessCheck */
2284 0, /* FileLinkInformationBypassAccessCheck */
2285 0, /* FileVolumeNameInformation */
2286 sizeof(FILE_ID_INFORMATION
), /* FileIdInformation */
2287 0, /* FileIdExtdDirectoryInformation */
2288 0, /* FileReplaceCompletionInformation */
2289 0, /* FileHardLinkFullIdInformation */
2290 0, /* FileIdExtdBothDirectoryInformation */
2294 int fd
, needs_close
= FALSE
;
2297 TRACE("(%p,%p,%p,0x%08x,0x%08x)\n", hFile
, io
, ptr
, len
, class);
2299 io
->Information
= 0;
2301 if (class <= 0 || class >= FileMaximumInformation
)
2302 return io
->u
.Status
= STATUS_INVALID_INFO_CLASS
;
2303 if (!info_sizes
[class])
2305 FIXME("Unsupported class (%d)\n", class);
2306 return io
->u
.Status
= STATUS_NOT_IMPLEMENTED
;
2308 if (len
< info_sizes
[class])
2309 return io
->u
.Status
= STATUS_INFO_LENGTH_MISMATCH
;
2311 if (class != FilePipeInformation
&& class != FilePipeLocalInformation
)
2313 if ((io
->u
.Status
= server_get_unix_fd( hFile
, 0, &fd
, &needs_close
, NULL
, NULL
)))
2314 return io
->u
.Status
;
2319 case FileBasicInformation
:
2320 if (fd_get_file_info( fd
, &st
, &attr
) == -1)
2321 io
->u
.Status
= FILE_GetNtStatus();
2322 else if (!S_ISREG(st
.st_mode
) && !S_ISDIR(st
.st_mode
))
2323 io
->u
.Status
= STATUS_INVALID_INFO_CLASS
;
2325 fill_file_info( &st
, attr
, ptr
, class );
2327 case FileStandardInformation
:
2329 FILE_STANDARD_INFORMATION
*info
= ptr
;
2331 if (fd_get_file_info( fd
, &st
, &attr
) == -1) io
->u
.Status
= FILE_GetNtStatus();
2334 fill_file_info( &st
, attr
, info
, class );
2335 info
->DeletePending
= FALSE
; /* FIXME */
2339 case FilePositionInformation
:
2341 FILE_POSITION_INFORMATION
*info
= ptr
;
2342 off_t res
= lseek( fd
, 0, SEEK_CUR
);
2343 if (res
== (off_t
)-1) io
->u
.Status
= FILE_GetNtStatus();
2344 else info
->CurrentByteOffset
.QuadPart
= res
;
2347 case FileInternalInformation
:
2348 if (fd_get_file_info( fd
, &st
, &attr
) == -1) io
->u
.Status
= FILE_GetNtStatus();
2349 else fill_file_info( &st
, attr
, ptr
, class );
2351 case FileEaInformation
:
2353 FILE_EA_INFORMATION
*info
= ptr
;
2357 case FileAccessInformation
:
2359 FILE_ACCESS_INFORMATION
*info
= ptr
;
2360 SERVER_START_REQ( get_object_info
)
2362 req
->handle
= wine_server_obj_handle( hFile
);
2363 io
->u
.Status
= wine_server_call( req
);
2364 if (io
->u
.Status
== STATUS_SUCCESS
)
2365 info
->AccessFlags
= reply
->access
;
2370 case FileEndOfFileInformation
:
2371 if (fd_get_file_info( fd
, &st
, &attr
) == -1) io
->u
.Status
= FILE_GetNtStatus();
2372 else fill_file_info( &st
, attr
, ptr
, class );
2374 case FileAllInformation
:
2376 FILE_ALL_INFORMATION
*info
= ptr
;
2377 ANSI_STRING unix_name
;
2379 if (fd_get_file_info( fd
, &st
, &attr
) == -1) io
->u
.Status
= FILE_GetNtStatus();
2380 else if (!S_ISREG(st
.st_mode
) && !S_ISDIR(st
.st_mode
))
2381 io
->u
.Status
= STATUS_INVALID_INFO_CLASS
;
2382 else if (!(io
->u
.Status
= server_get_unix_name( hFile
, &unix_name
)))
2384 LONG name_len
= len
- FIELD_OFFSET(FILE_ALL_INFORMATION
, NameInformation
.FileName
);
2386 fill_file_info( &st
, attr
, info
, FileAllInformation
);
2387 info
->StandardInformation
.DeletePending
= FALSE
; /* FIXME */
2388 info
->EaInformation
.EaSize
= 0;
2389 info
->AccessInformation
.AccessFlags
= 0; /* FIXME */
2390 info
->PositionInformation
.CurrentByteOffset
.QuadPart
= lseek( fd
, 0, SEEK_CUR
);
2391 info
->ModeInformation
.Mode
= 0; /* FIXME */
2392 info
->AlignmentInformation
.AlignmentRequirement
= 1; /* FIXME */
2394 io
->u
.Status
= fill_name_info( &unix_name
, &info
->NameInformation
, &name_len
);
2395 RtlFreeAnsiString( &unix_name
);
2396 io
->Information
= FIELD_OFFSET(FILE_ALL_INFORMATION
, NameInformation
.FileName
) + name_len
;
2400 case FileMailslotQueryInformation
:
2402 FILE_MAILSLOT_QUERY_INFORMATION
*info
= ptr
;
2404 SERVER_START_REQ( set_mailslot_info
)
2406 req
->handle
= wine_server_obj_handle( hFile
);
2408 io
->u
.Status
= wine_server_call( req
);
2409 if( io
->u
.Status
== STATUS_SUCCESS
)
2411 info
->MaximumMessageSize
= reply
->max_msgsize
;
2412 info
->MailslotQuota
= 0;
2413 info
->NextMessageSize
= 0;
2414 info
->MessagesAvailable
= 0;
2415 info
->ReadTimeout
.QuadPart
= reply
->read_timeout
;
2422 ULONG size
= info
->MaximumMessageSize
? info
->MaximumMessageSize
: 0x10000;
2423 if (size
> 0x10000) size
= 0x10000;
2424 if ((tmpbuf
= RtlAllocateHeap( GetProcessHeap(), 0, size
)))
2426 if (!server_get_unix_fd( hFile
, FILE_READ_DATA
, &fd
, &needs_close
, NULL
, NULL
))
2428 int res
= recv( fd
, tmpbuf
, size
, MSG_PEEK
);
2429 info
->MessagesAvailable
= (res
> 0);
2430 info
->NextMessageSize
= (res
>= 0) ? res
: MAILSLOT_NO_MESSAGE
;
2431 if (needs_close
) close( fd
);
2433 RtlFreeHeap( GetProcessHeap(), 0, tmpbuf
);
2438 case FilePipeInformation
:
2440 FILE_PIPE_INFORMATION
* pi
= ptr
;
2442 SERVER_START_REQ( get_named_pipe_info
)
2444 req
->handle
= wine_server_obj_handle( hFile
);
2445 if (!(io
->u
.Status
= wine_server_call( req
)))
2447 pi
->ReadMode
= (reply
->flags
& NAMED_PIPE_MESSAGE_STREAM_READ
) ?
2448 FILE_PIPE_MESSAGE_MODE
: FILE_PIPE_BYTE_STREAM_MODE
;
2449 pi
->CompletionMode
= (reply
->flags
& NAMED_PIPE_NONBLOCKING_MODE
) ?
2450 FILE_PIPE_COMPLETE_OPERATION
: FILE_PIPE_QUEUE_OPERATION
;
2456 case FilePipeLocalInformation
:
2458 FILE_PIPE_LOCAL_INFORMATION
* pli
= ptr
;
2460 SERVER_START_REQ( get_named_pipe_info
)
2462 req
->handle
= wine_server_obj_handle( hFile
);
2463 if (!(io
->u
.Status
= wine_server_call( req
)))
2465 pli
->NamedPipeType
= (reply
->flags
& NAMED_PIPE_MESSAGE_STREAM_WRITE
) ?
2466 FILE_PIPE_TYPE_MESSAGE
: FILE_PIPE_TYPE_BYTE
;
2467 switch (reply
->sharing
)
2469 case FILE_SHARE_READ
:
2470 pli
->NamedPipeConfiguration
= FILE_PIPE_OUTBOUND
;
2472 case FILE_SHARE_WRITE
:
2473 pli
->NamedPipeConfiguration
= FILE_PIPE_INBOUND
;
2475 case FILE_SHARE_READ
| FILE_SHARE_WRITE
:
2476 pli
->NamedPipeConfiguration
= FILE_PIPE_FULL_DUPLEX
;
2479 pli
->MaximumInstances
= reply
->maxinstances
;
2480 pli
->CurrentInstances
= reply
->instances
;
2481 pli
->InboundQuota
= reply
->insize
;
2482 pli
->ReadDataAvailable
= 0; /* FIXME */
2483 pli
->OutboundQuota
= reply
->outsize
;
2484 pli
->WriteQuotaAvailable
= 0; /* FIXME */
2485 pli
->NamedPipeState
= 0; /* FIXME */
2486 pli
->NamedPipeEnd
= (reply
->flags
& NAMED_PIPE_SERVER_END
) ?
2487 FILE_PIPE_SERVER_END
: FILE_PIPE_CLIENT_END
;
2493 case FileNameInformation
:
2495 FILE_NAME_INFORMATION
*info
= ptr
;
2496 ANSI_STRING unix_name
;
2498 if (!(io
->u
.Status
= server_get_unix_name( hFile
, &unix_name
)))
2500 LONG name_len
= len
- FIELD_OFFSET(FILE_NAME_INFORMATION
, FileName
);
2501 io
->u
.Status
= fill_name_info( &unix_name
, info
, &name_len
);
2502 RtlFreeAnsiString( &unix_name
);
2503 io
->Information
= FIELD_OFFSET(FILE_NAME_INFORMATION
, FileName
) + name_len
;
2507 case FileNetworkOpenInformation
:
2509 FILE_NETWORK_OPEN_INFORMATION
*info
= ptr
;
2510 ANSI_STRING unix_name
;
2512 if (!(io
->u
.Status
= server_get_unix_name( hFile
, &unix_name
)))
2517 if (get_file_info( unix_name
.Buffer
, &st
, &attributes
) == -1)
2518 io
->u
.Status
= FILE_GetNtStatus();
2519 else if (!S_ISREG(st
.st_mode
) && !S_ISDIR(st
.st_mode
))
2520 io
->u
.Status
= STATUS_INVALID_INFO_CLASS
;
2523 FILE_BASIC_INFORMATION basic
;
2524 FILE_STANDARD_INFORMATION std
;
2526 fill_file_info( &st
, attributes
, &basic
, FileBasicInformation
);
2527 fill_file_info( &st
, attributes
, &std
, FileStandardInformation
);
2529 info
->CreationTime
= basic
.CreationTime
;
2530 info
->LastAccessTime
= basic
.LastAccessTime
;
2531 info
->LastWriteTime
= basic
.LastWriteTime
;
2532 info
->ChangeTime
= basic
.ChangeTime
;
2533 info
->AllocationSize
= std
.AllocationSize
;
2534 info
->EndOfFile
= std
.EndOfFile
;
2535 info
->FileAttributes
= basic
.FileAttributes
;
2537 RtlFreeAnsiString( &unix_name
);
2541 case FileIdInformation
:
2542 if (fd_get_file_info( fd
, &st
, &attr
) == -1) io
->u
.Status
= FILE_GetNtStatus();
2545 FILE_ID_INFORMATION
*info
= ptr
;
2546 info
->VolumeSerialNumber
= 0; /* FIXME */
2547 memset( &info
->FileId
, 0, sizeof(info
->FileId
) );
2548 *(ULONGLONG
*)&info
->FileId
= st
.st_ino
;
2552 FIXME("Unsupported class (%d)\n", class);
2553 io
->u
.Status
= STATUS_NOT_IMPLEMENTED
;
2556 if (needs_close
) close( fd
);
2557 if (io
->u
.Status
== STATUS_SUCCESS
&& !io
->Information
) io
->Information
= info_sizes
[class];
2558 return io
->u
.Status
;
2561 /******************************************************************************
2562 * NtSetInformationFile [NTDLL.@]
2563 * ZwSetInformationFile [NTDLL.@]
2565 * Set information about an open file handle.
2568 * handle [I] Handle returned from ZwOpenFile() or ZwCreateFile()
2569 * io [O] Receives information about the operation on return
2570 * ptr [I] Source for file information
2571 * len [I] Size of FileInformation
2572 * class [I] Type of file information to set
2575 * Success: 0. io is updated.
2576 * Failure: An NTSTATUS error code describing the error.
2578 NTSTATUS WINAPI
NtSetInformationFile(HANDLE handle
, PIO_STATUS_BLOCK io
,
2579 PVOID ptr
, ULONG len
, FILE_INFORMATION_CLASS
class)
2581 int fd
, needs_close
;
2583 TRACE("(%p,%p,%p,0x%08x,0x%08x)\n", handle
, io
, ptr
, len
, class);
2585 io
->u
.Status
= STATUS_SUCCESS
;
2588 case FileBasicInformation
:
2589 if (len
>= sizeof(FILE_BASIC_INFORMATION
))
2592 const FILE_BASIC_INFORMATION
*info
= ptr
;
2594 if ((io
->u
.Status
= server_get_unix_fd( handle
, 0, &fd
, &needs_close
, NULL
, NULL
)))
2595 return io
->u
.Status
;
2597 if (info
->LastAccessTime
.QuadPart
|| info
->LastWriteTime
.QuadPart
)
2598 io
->u
.Status
= set_file_times( fd
, &info
->LastWriteTime
, &info
->LastAccessTime
);
2600 if (io
->u
.Status
== STATUS_SUCCESS
&& info
->FileAttributes
)
2602 if (fstat( fd
, &st
) == -1) io
->u
.Status
= FILE_GetNtStatus();
2605 if (info
->FileAttributes
& FILE_ATTRIBUTE_READONLY
)
2607 if (S_ISDIR( st
.st_mode
))
2608 WARN("FILE_ATTRIBUTE_READONLY ignored for directory.\n");
2610 st
.st_mode
&= ~0222; /* clear write permission bits */
2614 /* add write permission only where we already have read permission */
2615 st
.st_mode
|= (0600 | ((st
.st_mode
& 044) >> 1)) & (~FILE_umask
);
2617 if (fchmod( fd
, st
.st_mode
) == -1) io
->u
.Status
= FILE_GetNtStatus();
2621 if (needs_close
) close( fd
);
2623 else io
->u
.Status
= STATUS_INVALID_PARAMETER_3
;
2626 case FilePositionInformation
:
2627 if (len
>= sizeof(FILE_POSITION_INFORMATION
))
2629 const FILE_POSITION_INFORMATION
*info
= ptr
;
2631 if ((io
->u
.Status
= server_get_unix_fd( handle
, 0, &fd
, &needs_close
, NULL
, NULL
)))
2632 return io
->u
.Status
;
2634 if (lseek( fd
, info
->CurrentByteOffset
.QuadPart
, SEEK_SET
) == (off_t
)-1)
2635 io
->u
.Status
= FILE_GetNtStatus();
2637 if (needs_close
) close( fd
);
2639 else io
->u
.Status
= STATUS_INVALID_PARAMETER_3
;
2642 case FileEndOfFileInformation
:
2643 if (len
>= sizeof(FILE_END_OF_FILE_INFORMATION
))
2646 const FILE_END_OF_FILE_INFORMATION
*info
= ptr
;
2648 if ((io
->u
.Status
= server_get_unix_fd( handle
, 0, &fd
, &needs_close
, NULL
, NULL
)))
2649 return io
->u
.Status
;
2651 /* first try normal truncate */
2652 if (ftruncate( fd
, (off_t
)info
->EndOfFile
.QuadPart
) != -1) break;
2654 /* now check for the need to extend the file */
2655 if (fstat( fd
, &st
) != -1 && (off_t
)info
->EndOfFile
.QuadPart
> st
.st_size
)
2657 static const char zero
;
2659 /* extend the file one byte beyond the requested size and then truncate it */
2660 /* this should work around ftruncate implementations that can't extend files */
2661 if (pwrite( fd
, &zero
, 1, (off_t
)info
->EndOfFile
.QuadPart
) != -1 &&
2662 ftruncate( fd
, (off_t
)info
->EndOfFile
.QuadPart
) != -1) break;
2664 io
->u
.Status
= FILE_GetNtStatus();
2666 if (needs_close
) close( fd
);
2668 else io
->u
.Status
= STATUS_INVALID_PARAMETER_3
;
2671 case FilePipeInformation
:
2672 if (len
>= sizeof(FILE_PIPE_INFORMATION
))
2674 FILE_PIPE_INFORMATION
*info
= ptr
;
2676 if ((info
->CompletionMode
| info
->ReadMode
) & ~1)
2678 io
->u
.Status
= STATUS_INVALID_PARAMETER
;
2682 SERVER_START_REQ( set_named_pipe_info
)
2684 req
->handle
= wine_server_obj_handle( handle
);
2685 req
->flags
= (info
->CompletionMode
? NAMED_PIPE_NONBLOCKING_MODE
: 0) |
2686 (info
->ReadMode
? NAMED_PIPE_MESSAGE_STREAM_READ
: 0);
2687 io
->u
.Status
= wine_server_call( req
);
2691 else io
->u
.Status
= STATUS_INVALID_PARAMETER_3
;
2694 case FileMailslotSetInformation
:
2696 FILE_MAILSLOT_SET_INFORMATION
*info
= ptr
;
2698 SERVER_START_REQ( set_mailslot_info
)
2700 req
->handle
= wine_server_obj_handle( handle
);
2701 req
->flags
= MAILSLOT_SET_READ_TIMEOUT
;
2702 req
->read_timeout
= info
->ReadTimeout
.QuadPart
;
2703 io
->u
.Status
= wine_server_call( req
);
2709 case FileCompletionInformation
:
2710 if (len
>= sizeof(FILE_COMPLETION_INFORMATION
))
2712 FILE_COMPLETION_INFORMATION
*info
= ptr
;
2714 SERVER_START_REQ( set_completion_info
)
2716 req
->handle
= wine_server_obj_handle( handle
);
2717 req
->chandle
= wine_server_obj_handle( info
->CompletionPort
);
2718 req
->ckey
= info
->CompletionKey
;
2719 io
->u
.Status
= wine_server_call( req
);
2723 io
->u
.Status
= STATUS_INVALID_PARAMETER_3
;
2726 case FileAllInformation
:
2727 io
->u
.Status
= STATUS_INVALID_INFO_CLASS
;
2730 case FileValidDataLengthInformation
:
2731 if (len
>= sizeof(FILE_VALID_DATA_LENGTH_INFORMATION
))
2734 const FILE_VALID_DATA_LENGTH_INFORMATION
*info
= ptr
;
2736 if ((io
->u
.Status
= server_get_unix_fd( handle
, FILE_WRITE_DATA
, &fd
, &needs_close
, NULL
, NULL
)))
2737 return io
->u
.Status
;
2739 if (fstat( fd
, &st
) == -1) io
->u
.Status
= FILE_GetNtStatus();
2740 else if (info
->ValidDataLength
.QuadPart
<= 0 || (off_t
)info
->ValidDataLength
.QuadPart
> st
.st_size
)
2741 io
->u
.Status
= STATUS_INVALID_PARAMETER
;
2744 #ifdef HAVE_FALLOCATE
2745 if (fallocate( fd
, 0, 0, (off_t
)info
->ValidDataLength
.QuadPart
) == -1)
2747 NTSTATUS status
= FILE_GetNtStatus();
2748 if (status
== STATUS_NOT_SUPPORTED
) WARN( "fallocate not supported on this filesystem\n" );
2749 else io
->u
.Status
= status
;
2752 FIXME( "setting valid data length not supported\n" );
2755 if (needs_close
) close( fd
);
2757 else io
->u
.Status
= STATUS_INVALID_PARAMETER_3
;
2760 case FileDispositionInformation
:
2761 if (len
>= sizeof(FILE_DISPOSITION_INFORMATION
))
2763 FILE_DISPOSITION_INFORMATION
*info
= ptr
;
2765 SERVER_START_REQ( set_fd_disp_info
)
2767 req
->handle
= wine_server_obj_handle( handle
);
2768 req
->unlink
= info
->DoDeleteFile
;
2769 io
->u
.Status
= wine_server_call( req
);
2773 io
->u
.Status
= STATUS_INVALID_PARAMETER_3
;
2776 case FileRenameInformation
:
2777 if (len
>= sizeof(FILE_RENAME_INFORMATION
))
2779 FILE_RENAME_INFORMATION
*info
= ptr
;
2780 UNICODE_STRING name_str
;
2781 OBJECT_ATTRIBUTES attr
;
2782 ANSI_STRING unix_name
;
2784 name_str
.Buffer
= info
->FileName
;
2785 name_str
.Length
= info
->FileNameLength
;
2786 name_str
.MaximumLength
= info
->FileNameLength
+ sizeof(WCHAR
);
2788 attr
.Length
= sizeof(attr
);
2789 attr
.ObjectName
= &name_str
;
2790 attr
.RootDirectory
= info
->RootDir
;
2791 attr
.Attributes
= OBJ_CASE_INSENSITIVE
;
2793 io
->u
.Status
= nt_to_unix_file_name_attr( &attr
, &unix_name
, FILE_OPEN_IF
);
2794 if (io
->u
.Status
!= STATUS_SUCCESS
&& io
->u
.Status
!= STATUS_NO_SUCH_FILE
)
2797 if (!info
->Replace
&& io
->u
.Status
== STATUS_SUCCESS
)
2799 RtlFreeAnsiString( &unix_name
);
2800 io
->u
.Status
= STATUS_OBJECT_NAME_COLLISION
;
2804 SERVER_START_REQ( set_fd_name_info
)
2806 req
->handle
= wine_server_obj_handle( handle
);
2807 req
->rootdir
= wine_server_obj_handle( attr
.RootDirectory
);
2809 wine_server_add_data( req
, unix_name
.Buffer
, unix_name
.Length
);
2810 io
->u
.Status
= wine_server_call( req
);
2814 RtlFreeAnsiString( &unix_name
);
2816 else io
->u
.Status
= STATUS_INVALID_PARAMETER_3
;
2819 case FileLinkInformation
:
2820 if (len
>= sizeof(FILE_LINK_INFORMATION
))
2822 FILE_LINK_INFORMATION
*info
= ptr
;
2823 UNICODE_STRING name_str
;
2824 OBJECT_ATTRIBUTES attr
;
2825 ANSI_STRING unix_name
;
2827 name_str
.Buffer
= info
->FileName
;
2828 name_str
.Length
= info
->FileNameLength
;
2829 name_str
.MaximumLength
= info
->FileNameLength
+ sizeof(WCHAR
);
2831 attr
.Length
= sizeof(attr
);
2832 attr
.ObjectName
= &name_str
;
2833 attr
.RootDirectory
= info
->RootDirectory
;
2834 attr
.Attributes
= OBJ_CASE_INSENSITIVE
;
2836 io
->u
.Status
= nt_to_unix_file_name_attr( &attr
, &unix_name
, FILE_OPEN_IF
);
2837 if (io
->u
.Status
!= STATUS_SUCCESS
&& io
->u
.Status
!= STATUS_NO_SUCH_FILE
)
2840 if (!info
->ReplaceIfExists
&& io
->u
.Status
== STATUS_SUCCESS
)
2842 RtlFreeAnsiString( &unix_name
);
2843 io
->u
.Status
= STATUS_OBJECT_NAME_COLLISION
;
2847 SERVER_START_REQ( set_fd_name_info
)
2849 req
->handle
= wine_server_obj_handle( handle
);
2850 req
->rootdir
= wine_server_obj_handle( attr
.RootDirectory
);
2852 wine_server_add_data( req
, unix_name
.Buffer
, unix_name
.Length
);
2853 io
->u
.Status
= wine_server_call( req
);
2857 RtlFreeAnsiString( &unix_name
);
2859 else io
->u
.Status
= STATUS_INVALID_PARAMETER_3
;
2863 FIXME("Unsupported class (%d)\n", class);
2864 io
->u
.Status
= STATUS_NOT_IMPLEMENTED
;
2867 io
->Information
= 0;
2868 return io
->u
.Status
;
2872 /******************************************************************************
2873 * NtQueryFullAttributesFile (NTDLL.@)
2875 NTSTATUS WINAPI
NtQueryFullAttributesFile( const OBJECT_ATTRIBUTES
*attr
,
2876 FILE_NETWORK_OPEN_INFORMATION
*info
)
2878 ANSI_STRING unix_name
;
2881 if (!(status
= nt_to_unix_file_name_attr( attr
, &unix_name
, FILE_OPEN
)))
2886 if (get_file_info( unix_name
.Buffer
, &st
, &attributes
) == -1)
2887 status
= FILE_GetNtStatus();
2888 else if (!S_ISREG(st
.st_mode
) && !S_ISDIR(st
.st_mode
))
2889 status
= STATUS_INVALID_INFO_CLASS
;
2892 FILE_BASIC_INFORMATION basic
;
2893 FILE_STANDARD_INFORMATION std
;
2895 fill_file_info( &st
, attributes
, &basic
, FileBasicInformation
);
2896 fill_file_info( &st
, attributes
, &std
, FileStandardInformation
);
2898 info
->CreationTime
= basic
.CreationTime
;
2899 info
->LastAccessTime
= basic
.LastAccessTime
;
2900 info
->LastWriteTime
= basic
.LastWriteTime
;
2901 info
->ChangeTime
= basic
.ChangeTime
;
2902 info
->AllocationSize
= std
.AllocationSize
;
2903 info
->EndOfFile
= std
.EndOfFile
;
2904 info
->FileAttributes
= basic
.FileAttributes
;
2905 if (DIR_is_hidden_file( attr
->ObjectName
))
2906 info
->FileAttributes
|= FILE_ATTRIBUTE_HIDDEN
;
2908 RtlFreeAnsiString( &unix_name
);
2910 else WARN("%s not found (%x)\n", debugstr_us(attr
->ObjectName
), status
);
2915 /******************************************************************************
2916 * NtQueryAttributesFile (NTDLL.@)
2917 * ZwQueryAttributesFile (NTDLL.@)
2919 NTSTATUS WINAPI
NtQueryAttributesFile( const OBJECT_ATTRIBUTES
*attr
, FILE_BASIC_INFORMATION
*info
)
2921 ANSI_STRING unix_name
;
2924 if (!(status
= nt_to_unix_file_name_attr( attr
, &unix_name
, FILE_OPEN
)))
2929 if (get_file_info( unix_name
.Buffer
, &st
, &attributes
) == -1)
2930 status
= FILE_GetNtStatus();
2931 else if (!S_ISREG(st
.st_mode
) && !S_ISDIR(st
.st_mode
))
2932 status
= STATUS_INVALID_INFO_CLASS
;
2935 status
= fill_file_info( &st
, attributes
, info
, FileBasicInformation
);
2936 if (DIR_is_hidden_file( attr
->ObjectName
))
2937 info
->FileAttributes
|= FILE_ATTRIBUTE_HIDDEN
;
2939 RtlFreeAnsiString( &unix_name
);
2941 else WARN("%s not found (%x)\n", debugstr_us(attr
->ObjectName
), status
);
2946 #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__DragonFly__) || defined(__APPLE__)
2947 /* helper for FILE_GetDeviceInfo to hide some platform differences in fstatfs */
2948 static inline void get_device_info_fstatfs( FILE_FS_DEVICE_INFORMATION
*info
, const char *fstypename
,
2949 unsigned int flags
)
2951 if (!strcmp("cd9660", fstypename
) || !strcmp("udf", fstypename
))
2953 info
->DeviceType
= FILE_DEVICE_CD_ROM_FILE_SYSTEM
;
2954 /* Don't assume read-only, let the mount options set it below */
2955 info
->Characteristics
|= FILE_REMOVABLE_MEDIA
;
2957 else if (!strcmp("nfs", fstypename
) || !strcmp("nwfs", fstypename
) ||
2958 !strcmp("smbfs", fstypename
) || !strcmp("afpfs", fstypename
))
2960 info
->DeviceType
= FILE_DEVICE_NETWORK_FILE_SYSTEM
;
2961 info
->Characteristics
|= FILE_REMOTE_DEVICE
;
2963 else if (!strcmp("procfs", fstypename
))
2964 info
->DeviceType
= FILE_DEVICE_VIRTUAL_DISK
;
2966 info
->DeviceType
= FILE_DEVICE_DISK_FILE_SYSTEM
;
2968 if (flags
& MNT_RDONLY
)
2969 info
->Characteristics
|= FILE_READ_ONLY_DEVICE
;
2971 if (!(flags
& MNT_LOCAL
))
2973 info
->DeviceType
= FILE_DEVICE_NETWORK_FILE_SYSTEM
;
2974 info
->Characteristics
|= FILE_REMOTE_DEVICE
;
2979 static inline BOOL
is_device_placeholder( int fd
)
2981 static const char wine_placeholder
[] = "Wine device placeholder";
2982 char buffer
[sizeof(wine_placeholder
)-1];
2984 if (pread( fd
, buffer
, sizeof(wine_placeholder
) - 1, 0 ) != sizeof(wine_placeholder
) - 1)
2986 return !memcmp( buffer
, wine_placeholder
, sizeof(wine_placeholder
) - 1 );
2989 /******************************************************************************
2992 * Implementation of the FileFsDeviceInformation query for NtQueryVolumeInformationFile.
2994 static NTSTATUS
get_device_info( int fd
, FILE_FS_DEVICE_INFORMATION
*info
)
2998 info
->Characteristics
= 0;
2999 if (fstat( fd
, &st
) < 0) return FILE_GetNtStatus();
3000 if (S_ISCHR( st
.st_mode
))
3002 info
->DeviceType
= FILE_DEVICE_UNKNOWN
;
3004 switch(major(st
.st_rdev
))
3007 info
->DeviceType
= FILE_DEVICE_NULL
;
3010 info
->DeviceType
= FILE_DEVICE_SERIAL_PORT
;
3013 info
->DeviceType
= FILE_DEVICE_PARALLEL_PORT
;
3015 case SCSI_TAPE_MAJOR
:
3016 info
->DeviceType
= FILE_DEVICE_TAPE
;
3021 else if (S_ISBLK( st
.st_mode
))
3023 info
->DeviceType
= FILE_DEVICE_DISK
;
3025 else if (S_ISFIFO( st
.st_mode
) || S_ISSOCK( st
.st_mode
))
3027 info
->DeviceType
= FILE_DEVICE_NAMED_PIPE
;
3029 else if (is_device_placeholder( fd
))
3031 info
->DeviceType
= FILE_DEVICE_DISK
;
3033 else /* regular file or directory */
3035 #if defined(linux) && defined(HAVE_FSTATFS)
3038 /* check for floppy disk */
3039 if (major(st
.st_dev
) == FLOPPY_MAJOR
)
3040 info
->Characteristics
|= FILE_REMOVABLE_MEDIA
;
3042 if (fstatfs( fd
, &stfs
) < 0) stfs
.f_type
= 0;
3043 switch (stfs
.f_type
)
3045 case 0x9660: /* iso9660 */
3046 case 0x9fa1: /* supermount */
3047 case 0x15013346: /* udf */
3048 info
->DeviceType
= FILE_DEVICE_CD_ROM_FILE_SYSTEM
;
3049 info
->Characteristics
|= FILE_REMOVABLE_MEDIA
|FILE_READ_ONLY_DEVICE
;
3051 case 0x6969: /* nfs */
3052 case 0xff534d42: /* cifs */
3053 case 0xfe534d42: /* smb2 */
3054 case 0x517b: /* smbfs */
3055 case 0x564c: /* ncpfs */
3056 info
->DeviceType
= FILE_DEVICE_NETWORK_FILE_SYSTEM
;
3057 info
->Characteristics
|= FILE_REMOTE_DEVICE
;
3059 case 0x01021994: /* tmpfs */
3060 case 0x28cd3d45: /* cramfs */
3061 case 0x1373: /* devfs */
3062 case 0x9fa0: /* procfs */
3063 info
->DeviceType
= FILE_DEVICE_VIRTUAL_DISK
;
3066 info
->DeviceType
= FILE_DEVICE_DISK_FILE_SYSTEM
;
3069 #elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__OpenBSD__) || defined(__DragonFly__) || defined(__APPLE__)
3072 if (fstatfs( fd
, &stfs
) < 0)
3073 info
->DeviceType
= FILE_DEVICE_DISK_FILE_SYSTEM
;
3075 get_device_info_fstatfs( info
, stfs
.f_fstypename
, stfs
.f_flags
);
3076 #elif defined(__NetBSD__)
3077 struct statvfs stfs
;
3079 if (fstatvfs( fd
, &stfs
) < 0)
3080 info
->DeviceType
= FILE_DEVICE_DISK_FILE_SYSTEM
;
3082 get_device_info_fstatfs( info
, stfs
.f_fstypename
, stfs
.f_flag
);
3084 /* Use dkio to work out device types */
3086 # include <sys/dkio.h>
3087 # include <sys/vtoc.h>
3088 struct dk_cinfo dkinf
;
3089 int retval
= ioctl(fd
, DKIOCINFO
, &dkinf
);
3091 WARN("Unable to get disk device type information - assuming a disk like device\n");
3092 info
->DeviceType
= FILE_DEVICE_DISK_FILE_SYSTEM
;
3094 switch (dkinf
.dki_ctype
)
3097 info
->DeviceType
= FILE_DEVICE_CD_ROM_FILE_SYSTEM
;
3098 info
->Characteristics
|= FILE_REMOVABLE_MEDIA
|FILE_READ_ONLY_DEVICE
;
3102 case DKC_INTEL82072
:
3103 case DKC_INTEL82077
:
3104 info
->DeviceType
= FILE_DEVICE_DISK_FILE_SYSTEM
;
3105 info
->Characteristics
|= FILE_REMOVABLE_MEDIA
;
3108 info
->DeviceType
= FILE_DEVICE_VIRTUAL_DISK
;
3111 info
->DeviceType
= FILE_DEVICE_DISK_FILE_SYSTEM
;
3116 if (!warned
++) FIXME( "device info not properly supported on this platform\n" );
3117 info
->DeviceType
= FILE_DEVICE_DISK_FILE_SYSTEM
;
3119 info
->Characteristics
|= FILE_DEVICE_IS_MOUNTED
;
3121 return STATUS_SUCCESS
;
3125 /******************************************************************************
3126 * NtQueryVolumeInformationFile [NTDLL.@]
3127 * ZwQueryVolumeInformationFile [NTDLL.@]
3129 * Get volume information for an open file handle.
3132 * handle [I] Handle returned from ZwOpenFile() or ZwCreateFile()
3133 * io [O] Receives information about the operation on return
3134 * buffer [O] Destination for volume information
3135 * length [I] Size of FsInformation
3136 * info_class [I] Type of volume information to set
3139 * Success: 0. io and buffer are updated.
3140 * Failure: An NTSTATUS error code describing the error.
3142 NTSTATUS WINAPI
NtQueryVolumeInformationFile( HANDLE handle
, PIO_STATUS_BLOCK io
,
3143 PVOID buffer
, ULONG length
,
3144 FS_INFORMATION_CLASS info_class
)
3146 int fd
, needs_close
;
3150 io
->u
.Status
= server_get_unix_fd( handle
, 0, &fd
, &needs_close
, NULL
, NULL
);
3151 if (io
->u
.Status
== STATUS_BAD_DEVICE_TYPE
)
3153 SERVER_START_REQ( get_volume_info
)
3155 req
->handle
= wine_server_obj_handle( handle
);
3156 req
->info_class
= info_class
;
3157 wine_server_set_reply( req
, buffer
, length
);
3158 io
->u
.Status
= wine_server_call( req
);
3159 if (!io
->u
.Status
) io
->Information
= wine_server_reply_size( reply
);
3162 return io
->u
.Status
;
3164 else if (io
->u
.Status
) return io
->u
.Status
;
3166 io
->u
.Status
= STATUS_NOT_IMPLEMENTED
;
3167 io
->Information
= 0;
3169 switch( info_class
)
3171 case FileFsVolumeInformation
:
3172 if (!once
++) FIXME( "%p: volume info not supported\n", handle
);
3174 case FileFsLabelInformation
:
3175 FIXME( "%p: label info not supported\n", handle
);
3177 case FileFsSizeInformation
:
3178 if (length
< sizeof(FILE_FS_SIZE_INFORMATION
))
3179 io
->u
.Status
= STATUS_BUFFER_TOO_SMALL
;
3182 FILE_FS_SIZE_INFORMATION
*info
= buffer
;
3184 if (fstat( fd
, &st
) < 0)
3186 io
->u
.Status
= FILE_GetNtStatus();
3189 if (!S_ISREG(st
.st_mode
) && !S_ISDIR(st
.st_mode
))
3191 io
->u
.Status
= STATUS_INVALID_DEVICE_REQUEST
;
3196 /* Linux's fstatvfs is buggy */
3197 #if !defined(linux) || !defined(HAVE_FSTATFS)
3198 struct statvfs stfs
;
3200 if (fstatvfs( fd
, &stfs
) < 0)
3202 io
->u
.Status
= FILE_GetNtStatus();
3205 bsize
= stfs
.f_frsize
;
3208 if (fstatfs( fd
, &stfs
) < 0)
3210 io
->u
.Status
= FILE_GetNtStatus();
3213 bsize
= stfs
.f_bsize
;
3215 if (bsize
== 2048) /* assume CD-ROM */
3217 info
->BytesPerSector
= 2048;
3218 info
->SectorsPerAllocationUnit
= 1;
3222 info
->BytesPerSector
= 512;
3223 info
->SectorsPerAllocationUnit
= 8;
3225 info
->TotalAllocationUnits
.QuadPart
= bsize
* stfs
.f_blocks
/ (info
->BytesPerSector
* info
->SectorsPerAllocationUnit
);
3226 info
->AvailableAllocationUnits
.QuadPart
= bsize
* stfs
.f_bavail
/ (info
->BytesPerSector
* info
->SectorsPerAllocationUnit
);
3227 io
->Information
= sizeof(*info
);
3228 io
->u
.Status
= STATUS_SUCCESS
;
3232 case FileFsDeviceInformation
:
3233 if (length
< sizeof(FILE_FS_DEVICE_INFORMATION
))
3234 io
->u
.Status
= STATUS_BUFFER_TOO_SMALL
;
3237 FILE_FS_DEVICE_INFORMATION
*info
= buffer
;
3239 if ((io
->u
.Status
= get_device_info( fd
, info
)) == STATUS_SUCCESS
)
3240 io
->Information
= sizeof(*info
);
3243 case FileFsAttributeInformation
:
3244 if (length
< offsetof( FILE_FS_ATTRIBUTE_INFORMATION
, FileSystemName
[sizeof(ntfsW
)/sizeof(WCHAR
)] ))
3245 io
->u
.Status
= STATUS_BUFFER_TOO_SMALL
;
3248 FILE_FS_ATTRIBUTE_INFORMATION
*info
= buffer
;
3250 FIXME( "%p: faking attribute info\n", handle
);
3251 info
->FileSystemAttribute
= FILE_SUPPORTS_ENCRYPTION
| FILE_FILE_COMPRESSION
|
3252 FILE_PERSISTENT_ACLS
| FILE_UNICODE_ON_DISK
|
3253 FILE_CASE_PRESERVED_NAMES
| FILE_CASE_SENSITIVE_SEARCH
;
3254 info
->MaximumComponentNameLength
= MAXIMUM_FILENAME_LENGTH
- 1;
3255 info
->FileSystemNameLength
= sizeof(ntfsW
);
3256 memcpy(info
->FileSystemName
, ntfsW
, sizeof(ntfsW
));
3258 io
->Information
= sizeof(*info
);
3259 io
->u
.Status
= STATUS_SUCCESS
;
3262 case FileFsControlInformation
:
3263 FIXME( "%p: control info not supported\n", handle
);
3265 case FileFsFullSizeInformation
:
3266 FIXME( "%p: full size info not supported\n", handle
);
3268 case FileFsObjectIdInformation
:
3269 FIXME( "%p: object id info not supported\n", handle
);
3271 case FileFsMaximumInformation
:
3272 FIXME( "%p: maximum info not supported\n", handle
);
3275 io
->u
.Status
= STATUS_INVALID_PARAMETER
;
3278 if (needs_close
) close( fd
);
3279 return io
->u
.Status
;
3283 /******************************************************************
3284 * NtQueryEaFile (NTDLL.@)
3286 * Read extended attributes from NTFS files.
3289 * hFile [I] File handle, must be opened with FILE_READ_EA access
3290 * iosb [O] Receives information about the operation on return
3291 * buffer [O] Output buffer
3292 * length [I] Length of output buffer
3293 * single_entry [I] Only read and return one entry
3294 * ea_list [I] Optional list with names of EAs to return
3295 * ea_list_len [I] Length of ea_list in bytes
3296 * ea_index [I] Optional pointer to 1-based index of attribute to return
3297 * restart [I] restart EA scan
3300 * Success: 0. Atrributes read into buffer
3301 * Failure: An NTSTATUS error code describing the error.
3303 NTSTATUS WINAPI
NtQueryEaFile( HANDLE hFile
, PIO_STATUS_BLOCK iosb
, PVOID buffer
, ULONG length
,
3304 BOOLEAN single_entry
, PVOID ea_list
, ULONG ea_list_len
,
3305 PULONG ea_index
, BOOLEAN restart
)
3307 FIXME("(%p,%p,%p,%d,%d,%p,%d,%p,%d) stub\n",
3308 hFile
, iosb
, buffer
, length
, single_entry
, ea_list
,
3309 ea_list_len
, ea_index
, restart
);
3310 return STATUS_ACCESS_DENIED
;
3314 /******************************************************************
3315 * NtSetEaFile (NTDLL.@)
3317 * Update extended attributes for NTFS files.
3320 * hFile [I] File handle, must be opened with FILE_READ_EA access
3321 * iosb [O] Receives information about the operation on return
3322 * buffer [I] Buffer with EA information
3323 * length [I] Length of buffer
3326 * Success: 0. Attributes are updated
3327 * Failure: An NTSTATUS error code describing the error.
3329 NTSTATUS WINAPI
NtSetEaFile( HANDLE hFile
, PIO_STATUS_BLOCK iosb
, PVOID buffer
, ULONG length
)
3331 FIXME("(%p,%p,%p,%d) stub\n", hFile
, iosb
, buffer
, length
);
3332 return STATUS_ACCESS_DENIED
;
3336 /******************************************************************
3337 * NtFlushBuffersFile (NTDLL.@)
3339 * Flush any buffered data on an open file handle.
3342 * FileHandle [I] Handle returned from ZwOpenFile() or ZwCreateFile()
3343 * IoStatusBlock [O] Receives information about the operation on return
3346 * Success: 0. IoStatusBlock is updated.
3347 * Failure: An NTSTATUS error code describing the error.
3349 NTSTATUS WINAPI
NtFlushBuffersFile( HANDLE hFile
, IO_STATUS_BLOCK
* IoStatusBlock
)
3352 HANDLE hEvent
= NULL
;
3353 enum server_fd_type type
;
3354 int fd
, needs_close
;
3356 ret
= server_get_unix_fd( hFile
, FILE_WRITE_DATA
, &fd
, &needs_close
, &type
, NULL
);
3357 if (ret
== STATUS_ACCESS_DENIED
)
3358 ret
= server_get_unix_fd( hFile
, FILE_APPEND_DATA
, &fd
, &needs_close
, &type
, NULL
);
3360 if (!ret
&& type
== FD_TYPE_SERIAL
)
3362 ret
= COMM_FlushBuffersFile( fd
);
3364 else if (ret
!= STATUS_ACCESS_DENIED
)
3366 SERVER_START_REQ( flush
)
3368 req
->async
= server_async( hFile
, NULL
, NULL
, NULL
, NULL
, IoStatusBlock
);
3369 ret
= wine_server_call( req
);
3370 hEvent
= wine_server_ptr_handle( reply
->event
);
3376 NtWaitForSingleObject( hEvent
, FALSE
, NULL
);
3377 ret
= STATUS_SUCCESS
;
3381 if (needs_close
) close( fd
);
3385 /******************************************************************
3386 * NtLockFile (NTDLL.@)
3390 NTSTATUS WINAPI
NtLockFile( HANDLE hFile
, HANDLE lock_granted_event
,
3391 PIO_APC_ROUTINE apc
, void* apc_user
,
3392 PIO_STATUS_BLOCK io_status
, PLARGE_INTEGER offset
,
3393 PLARGE_INTEGER count
, ULONG
* key
, BOOLEAN dont_wait
,
3399 static BOOLEAN warn
= TRUE
;
3401 if (apc
|| io_status
|| key
)
3403 FIXME("Unimplemented yet parameter\n");
3404 return STATUS_NOT_IMPLEMENTED
;
3407 if (apc_user
&& warn
)
3409 FIXME("I/O completion on lock not implemented yet\n");
3415 SERVER_START_REQ( lock_file
)
3417 req
->handle
= wine_server_obj_handle( hFile
);
3418 req
->offset
= offset
->QuadPart
;
3419 req
->count
= count
->QuadPart
;
3420 req
->shared
= !exclusive
;
3421 req
->wait
= !dont_wait
;
3422 ret
= wine_server_call( req
);
3423 handle
= wine_server_ptr_handle( reply
->handle
);
3424 async
= reply
->overlapped
;
3427 if (ret
!= STATUS_PENDING
)
3429 if (!ret
&& lock_granted_event
) NtSetEvent(lock_granted_event
, NULL
);
3435 FIXME( "Async I/O lock wait not implemented, might deadlock\n" );
3436 if (handle
) NtClose( handle
);
3437 return STATUS_PENDING
;
3441 NtWaitForSingleObject( handle
, FALSE
, NULL
);
3448 /* Unix lock conflict, sleep a bit and retry */
3449 time
.QuadPart
= 100 * (ULONGLONG
)10000;
3450 time
.QuadPart
= -time
.QuadPart
;
3451 NtDelayExecution( FALSE
, &time
);
3457 /******************************************************************
3458 * NtUnlockFile (NTDLL.@)
3462 NTSTATUS WINAPI
NtUnlockFile( HANDLE hFile
, PIO_STATUS_BLOCK io_status
,
3463 PLARGE_INTEGER offset
, PLARGE_INTEGER count
,
3468 TRACE( "%p %x%08x %x%08x\n",
3469 hFile
, offset
->u
.HighPart
, offset
->u
.LowPart
, count
->u
.HighPart
, count
->u
.LowPart
);
3471 if (io_status
|| key
)
3473 FIXME("Unimplemented yet parameter\n");
3474 return STATUS_NOT_IMPLEMENTED
;
3477 SERVER_START_REQ( unlock_file
)
3479 req
->handle
= wine_server_obj_handle( hFile
);
3480 req
->offset
= offset
->QuadPart
;
3481 req
->count
= count
->QuadPart
;
3482 status
= wine_server_call( req
);
3488 /******************************************************************
3489 * NtCreateNamedPipeFile (NTDLL.@)
3493 NTSTATUS WINAPI
NtCreateNamedPipeFile( PHANDLE handle
, ULONG access
,
3494 POBJECT_ATTRIBUTES attr
, PIO_STATUS_BLOCK iosb
,
3495 ULONG sharing
, ULONG dispo
, ULONG options
,
3496 ULONG pipe_type
, ULONG read_mode
,
3497 ULONG completion_mode
, ULONG max_inst
,
3498 ULONG inbound_quota
, ULONG outbound_quota
,
3499 PLARGE_INTEGER timeout
)
3503 struct object_attributes
*objattr
;
3505 TRACE("(%p %x %s %p %x %d %x %d %d %d %d %d %d %p)\n",
3506 handle
, access
, debugstr_w(attr
->ObjectName
->Buffer
), iosb
, sharing
, dispo
,
3507 options
, pipe_type
, read_mode
, completion_mode
, max_inst
, inbound_quota
,
3508 outbound_quota
, timeout
);
3510 if (!attr
) return STATUS_INVALID_PARAMETER
;
3512 /* assume we only get relative timeout */
3513 if (timeout
->QuadPart
> 0)
3514 FIXME("Wrong time %s\n", wine_dbgstr_longlong(timeout
->QuadPart
));
3516 if ((status
= alloc_object_attributes( attr
, &objattr
, &len
))) return status
;
3518 SERVER_START_REQ( create_named_pipe
)
3520 req
->access
= access
;
3521 req
->options
= options
;
3522 req
->sharing
= sharing
;
3524 (pipe_type
? NAMED_PIPE_MESSAGE_STREAM_WRITE
: 0) |
3525 (read_mode
? NAMED_PIPE_MESSAGE_STREAM_READ
: 0) |
3526 (completion_mode
? NAMED_PIPE_NONBLOCKING_MODE
: 0);
3527 req
->maxinstances
= max_inst
;
3528 req
->outsize
= outbound_quota
;
3529 req
->insize
= inbound_quota
;
3530 req
->timeout
= timeout
->QuadPart
;
3531 wine_server_add_data( req
, objattr
, len
);
3532 status
= wine_server_call( req
);
3533 if (!status
) *handle
= wine_server_ptr_handle( reply
->handle
);
3537 RtlFreeHeap( GetProcessHeap(), 0, objattr
);
3541 /******************************************************************
3542 * NtDeleteFile (NTDLL.@)
3546 NTSTATUS WINAPI
NtDeleteFile( POBJECT_ATTRIBUTES ObjectAttributes
)
3552 TRACE("%p\n", ObjectAttributes
);
3553 status
= NtCreateFile( &hFile
, GENERIC_READ
| GENERIC_WRITE
| DELETE
,
3554 ObjectAttributes
, &io
, NULL
, 0,
3555 FILE_SHARE_READ
| FILE_SHARE_WRITE
| FILE_SHARE_DELETE
,
3556 FILE_OPEN
, FILE_DELETE_ON_CLOSE
, NULL
, 0 );
3557 if (status
== STATUS_SUCCESS
) status
= NtClose(hFile
);
3561 /******************************************************************
3562 * NtCancelIoFileEx (NTDLL.@)
3566 NTSTATUS WINAPI
NtCancelIoFileEx( HANDLE hFile
, PIO_STATUS_BLOCK iosb
, PIO_STATUS_BLOCK io_status
)
3568 TRACE("%p %p %p\n", hFile
, iosb
, io_status
);
3570 SERVER_START_REQ( cancel_async
)
3572 req
->handle
= wine_server_obj_handle( hFile
);
3573 req
->iosb
= wine_server_client_ptr( iosb
);
3574 req
->only_thread
= FALSE
;
3575 io_status
->u
.Status
= wine_server_call( req
);
3579 return io_status
->u
.Status
;
3582 /******************************************************************
3583 * NtCancelIoFile (NTDLL.@)
3587 NTSTATUS WINAPI
NtCancelIoFile( HANDLE hFile
, PIO_STATUS_BLOCK io_status
)
3589 TRACE("%p %p\n", hFile
, io_status
);
3591 SERVER_START_REQ( cancel_async
)
3593 req
->handle
= wine_server_obj_handle( hFile
);
3595 req
->only_thread
= TRUE
;
3596 io_status
->u
.Status
= wine_server_call( req
);
3600 return io_status
->u
.Status
;
3603 /******************************************************************************
3604 * NtCreateMailslotFile [NTDLL.@]
3605 * ZwCreateMailslotFile [NTDLL.@]
3608 * pHandle [O] pointer to receive the handle created
3609 * DesiredAccess [I] access mode (read, write, etc)
3610 * ObjectAttributes [I] fully qualified NT path of the mailslot
3611 * IoStatusBlock [O] receives completion status and other info
3614 * MaxMessageSize [I]
3620 NTSTATUS WINAPI
NtCreateMailslotFile(PHANDLE pHandle
, ULONG DesiredAccess
,
3621 POBJECT_ATTRIBUTES attr
, PIO_STATUS_BLOCK IoStatusBlock
,
3622 ULONG CreateOptions
, ULONG MailslotQuota
, ULONG MaxMessageSize
,
3623 PLARGE_INTEGER TimeOut
)
3625 LARGE_INTEGER timeout
;
3628 struct object_attributes
*objattr
;
3630 TRACE("%p %08x %p %p %08x %08x %08x %p\n",
3631 pHandle
, DesiredAccess
, attr
, IoStatusBlock
,
3632 CreateOptions
, MailslotQuota
, MaxMessageSize
, TimeOut
);
3634 if (!pHandle
) return STATUS_ACCESS_VIOLATION
;
3635 if (!attr
) return STATUS_INVALID_PARAMETER
;
3637 if ((ret
= alloc_object_attributes( attr
, &objattr
, &len
))) return ret
;
3640 * For a NULL TimeOut pointer set the default timeout value
3643 timeout
.QuadPart
= -1;
3645 timeout
.QuadPart
= TimeOut
->QuadPart
;
3647 SERVER_START_REQ( create_mailslot
)
3649 req
->access
= DesiredAccess
;
3650 req
->max_msgsize
= MaxMessageSize
;
3651 req
->read_timeout
= timeout
.QuadPart
;
3652 wine_server_add_data( req
, objattr
, len
);
3653 ret
= wine_server_call( req
);
3654 if( ret
== STATUS_SUCCESS
)
3655 *pHandle
= wine_server_ptr_handle( reply
->handle
);
3659 RtlFreeHeap( GetProcessHeap(), 0, objattr
);