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
= wine_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
= 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
= wine_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;
716 if (is_read
) timeouts
->interval
= 0; /* return as soon as we got something */
721 if (timeouts
->total
!= -1) timeouts
->end_time
= NtGetTickCount() + timeouts
->total
;
722 return STATUS_SUCCESS
;
726 /* retrieve the timeout for the next wait, in milliseconds */
727 static inline int get_next_io_timeout( const struct io_timeouts
*timeouts
, ULONG already
)
731 if (timeouts
->total
!= -1)
733 ret
= timeouts
->end_time
- NtGetTickCount();
734 if (ret
< 0) ret
= 0;
736 if (already
&& timeouts
->interval
!= -1)
738 if (ret
== -1 || ret
> timeouts
->interval
) ret
= timeouts
->interval
;
744 /* retrieve the avail_mode flag for async reads */
745 static NTSTATUS
get_io_avail_mode( HANDLE handle
, enum server_fd_type type
, BOOL
*avail_mode
)
747 NTSTATUS status
= STATUS_SUCCESS
;
753 /* GetCommTimeouts */
757 status
= NtDeviceIoControlFile( handle
, NULL
, NULL
, NULL
, &io
,
758 IOCTL_SERIAL_GET_TIMEOUTS
, NULL
, 0, &st
, sizeof(st
) );
760 *avail_mode
= (!st
.ReadTotalTimeoutMultiplier
&&
761 !st
.ReadTotalTimeoutConstant
&&
762 st
.ReadIntervalTimeout
== MAXDWORD
);
765 case FD_TYPE_MAILSLOT
:
778 /* register an async I/O for a file read; helper for NtReadFile */
779 static NTSTATUS
register_async_file_read( HANDLE handle
, HANDLE event
,
780 PIO_APC_ROUTINE apc
, void *apc_user
,
781 IO_STATUS_BLOCK
*iosb
, void *buffer
,
782 ULONG already
, ULONG length
, BOOL avail_mode
)
784 struct async_fileio_read
*fileio
;
787 if (!(fileio
= (struct async_fileio_read
*)alloc_fileio( sizeof(*fileio
), FILE_AsyncReadService
, handle
)))
788 return STATUS_NO_MEMORY
;
790 fileio
->already
= already
;
791 fileio
->count
= length
;
792 fileio
->buffer
= buffer
;
793 fileio
->avail_mode
= avail_mode
;
795 SERVER_START_REQ( register_async
)
797 req
->type
= ASYNC_TYPE_READ
;
799 req
->async
= server_async( handle
, &fileio
->io
, event
, apc
, apc_user
, iosb
);
800 status
= wine_server_call( req
);
804 if (status
!= STATUS_PENDING
) RtlFreeHeap( GetProcessHeap(), 0, fileio
);
809 /******************************************************************************
810 * NtReadFile [NTDLL.@]
811 * ZwReadFile [NTDLL.@]
813 * Read from an open file handle.
816 * FileHandle [I] Handle returned from ZwOpenFile() or ZwCreateFile()
817 * Event [I] Event to signal upon completion (or NULL)
818 * ApcRoutine [I] Callback to call upon completion (or NULL)
819 * ApcContext [I] Context for ApcRoutine (or NULL)
820 * IoStatusBlock [O] Receives information about the operation on return
821 * Buffer [O] Destination for the data read
822 * Length [I] Size of Buffer
823 * ByteOffset [O] Destination for the new file pointer position (or NULL)
824 * Key [O] Function unknown (may be NULL)
827 * Success: 0. IoStatusBlock is updated, and the Information member contains
828 * The number of bytes read.
829 * Failure: An NTSTATUS error code describing the error.
831 NTSTATUS WINAPI
NtReadFile(HANDLE hFile
, HANDLE hEvent
,
832 PIO_APC_ROUTINE apc
, void* apc_user
,
833 PIO_STATUS_BLOCK io_status
, void* buffer
, ULONG length
,
834 PLARGE_INTEGER offset
, PULONG key
)
836 int result
, unix_handle
, needs_close
;
837 unsigned int options
;
838 struct io_timeouts timeouts
;
841 enum server_fd_type type
;
842 ULONG_PTR cvalue
= apc
? 0 : (ULONG_PTR
)apc_user
;
843 BOOL send_completion
= FALSE
, async_read
, timeout_init_done
= FALSE
;
845 TRACE("(%p,%p,%p,%p,%p,%p,0x%08x,%p,%p),partial stub!\n",
846 hFile
,hEvent
,apc
,apc_user
,io_status
,buffer
,length
,offset
,key
);
848 if (!io_status
) return STATUS_ACCESS_VIOLATION
;
850 status
= server_get_unix_fd( hFile
, FILE_READ_DATA
, &unix_handle
,
851 &needs_close
, &type
, &options
);
852 if (status
&& status
!= STATUS_BAD_DEVICE_TYPE
) return status
;
854 if (!virtual_check_buffer_for_write( buffer
, length
)) return STATUS_ACCESS_VIOLATION
;
856 if (status
== STATUS_BAD_DEVICE_TYPE
)
857 return server_read_file( hFile
, hEvent
, apc
, apc_user
, io_status
, buffer
, length
, offset
, key
);
859 async_read
= !(options
& (FILE_SYNCHRONOUS_IO_ALERT
| FILE_SYNCHRONOUS_IO_NONALERT
));
861 if (type
== FD_TYPE_FILE
)
863 if (async_read
&& (!offset
|| offset
->QuadPart
< 0))
865 status
= STATUS_INVALID_PARAMETER
;
869 if (offset
&& offset
->QuadPart
!= FILE_USE_FILE_POINTER_POSITION
)
871 /* async I/O doesn't make sense on regular files */
872 while ((result
= pread( unix_handle
, buffer
, length
, offset
->QuadPart
)) == -1)
876 status
= FILE_GetNtStatus();
881 /* update file pointer position */
882 lseek( unix_handle
, offset
->QuadPart
+ result
, SEEK_SET
);
885 status
= (total
|| !length
) ? STATUS_SUCCESS
: STATUS_END_OF_FILE
;
889 else if (type
== FD_TYPE_SERIAL
|| type
== FD_TYPE_DEVICE
)
891 if (async_read
&& (!offset
|| offset
->QuadPart
< 0))
893 status
= STATUS_INVALID_PARAMETER
;
898 if (type
== FD_TYPE_SERIAL
&& async_read
&& length
)
900 /* an asynchronous serial port read with a read interval timeout needs to
901 skip the synchronous read to make sure that the server starts the read
902 interval timer after the first read */
903 if ((status
= get_io_timeouts( hFile
, type
, length
, TRUE
, &timeouts
))) goto err
;
904 if (timeouts
.interval
)
906 status
= register_async_file_read( hFile
, hEvent
, apc
, apc_user
, io_status
,
907 buffer
, total
, length
, FALSE
);
914 if ((result
= read( unix_handle
, (char *)buffer
+ total
, length
- total
)) >= 0)
917 if (!result
|| total
== length
)
921 status
= STATUS_SUCCESS
;
929 status
= length
? STATUS_END_OF_FILE
: STATUS_SUCCESS
;
934 status
= STATUS_SUCCESS
;
939 status
= STATUS_PIPE_BROKEN
;
943 else if (type
== FD_TYPE_FILE
) continue; /* no async I/O on regular files */
945 else if (errno
!= EAGAIN
)
947 if (errno
== EINTR
) continue;
948 if (!total
) status
= FILE_GetNtStatus();
956 if ((status
= get_io_avail_mode( hFile
, type
, &avail_mode
)))
958 if (total
&& avail_mode
)
960 status
= STATUS_SUCCESS
;
963 status
= register_async_file_read( hFile
, hEvent
, apc
, apc_user
, io_status
,
964 buffer
, total
, length
, avail_mode
);
967 else /* synchronous read, wait for the fd to become ready */
972 if (!timeout_init_done
)
974 timeout_init_done
= TRUE
;
975 if ((status
= get_io_timeouts( hFile
, type
, length
, TRUE
, &timeouts
)))
977 if (hEvent
) NtResetEvent( hEvent
, NULL
);
979 timeout
= get_next_io_timeout( &timeouts
, total
);
981 pfd
.fd
= unix_handle
;
984 if (!timeout
|| !(ret
= poll( &pfd
, 1, timeout
)))
986 if (total
) /* return with what we got so far */
987 status
= STATUS_SUCCESS
;
989 status
= (type
== FD_TYPE_MAILSLOT
) ? STATUS_IO_TIMEOUT
: STATUS_TIMEOUT
;
992 if (ret
== -1 && errno
!= EINTR
)
994 status
= FILE_GetNtStatus();
997 /* will now restart the read */
1002 send_completion
= cvalue
!= 0;
1005 if (needs_close
) close( unix_handle
);
1006 if (status
== STATUS_SUCCESS
|| (status
== STATUS_END_OF_FILE
&& !async_read
))
1008 io_status
->u
.Status
= status
;
1009 io_status
->Information
= total
;
1010 TRACE("= SUCCESS (%u)\n", total
);
1011 if (hEvent
) NtSetEvent( hEvent
, NULL
);
1012 if (apc
&& !status
) NtQueueApcThread( GetCurrentThread(), (PNTAPCFUNC
)apc
,
1013 (ULONG_PTR
)apc_user
, (ULONG_PTR
)io_status
, 0 );
1017 TRACE("= 0x%08x\n", status
);
1018 if (status
!= STATUS_PENDING
&& hEvent
) NtResetEvent( hEvent
, NULL
);
1021 if (send_completion
) NTDLL_AddCompletion( hFile
, cvalue
, status
, total
);
1027 /******************************************************************************
1028 * NtReadFileScatter [NTDLL.@]
1029 * ZwReadFileScatter [NTDLL.@]
1031 NTSTATUS WINAPI
NtReadFileScatter( HANDLE file
, HANDLE event
, PIO_APC_ROUTINE apc
, void *apc_user
,
1032 PIO_STATUS_BLOCK io_status
, FILE_SEGMENT_ELEMENT
*segments
,
1033 ULONG length
, PLARGE_INTEGER offset
, PULONG key
)
1035 int result
, unix_handle
, needs_close
;
1036 unsigned int options
;
1038 ULONG pos
= 0, total
= 0;
1039 enum server_fd_type type
;
1040 ULONG_PTR cvalue
= apc
? 0 : (ULONG_PTR
)apc_user
;
1041 BOOL send_completion
= FALSE
;
1043 TRACE( "(%p,%p,%p,%p,%p,%p,0x%08x,%p,%p),partial stub!\n",
1044 file
, event
, apc
, apc_user
, io_status
, segments
, length
, offset
, key
);
1046 if (length
% page_size
) return STATUS_INVALID_PARAMETER
;
1047 if (!io_status
) return STATUS_ACCESS_VIOLATION
;
1049 status
= server_get_unix_fd( file
, FILE_READ_DATA
, &unix_handle
,
1050 &needs_close
, &type
, &options
);
1051 if (status
) return status
;
1053 if ((type
!= FD_TYPE_FILE
) ||
1054 (options
& (FILE_SYNCHRONOUS_IO_ALERT
| FILE_SYNCHRONOUS_IO_NONALERT
)) ||
1055 !(options
& FILE_NO_INTERMEDIATE_BUFFERING
))
1057 status
= STATUS_INVALID_PARAMETER
;
1063 if (offset
&& offset
->QuadPart
!= FILE_USE_FILE_POINTER_POSITION
)
1064 result
= pread( unix_handle
, (char *)segments
->Buffer
+ pos
,
1065 page_size
- pos
, offset
->QuadPart
+ total
);
1067 result
= read( unix_handle
, (char *)segments
->Buffer
+ pos
, page_size
- pos
);
1071 if (errno
== EINTR
) continue;
1072 status
= FILE_GetNtStatus();
1077 status
= STATUS_END_OF_FILE
;
1082 if ((pos
+= result
) == page_size
)
1089 send_completion
= cvalue
!= 0;
1092 if (needs_close
) close( unix_handle
);
1093 if (status
== STATUS_SUCCESS
)
1095 io_status
->u
.Status
= status
;
1096 io_status
->Information
= total
;
1097 TRACE("= SUCCESS (%u)\n", total
);
1098 if (event
) NtSetEvent( event
, NULL
);
1099 if (apc
) NtQueueApcThread( GetCurrentThread(), (PNTAPCFUNC
)apc
,
1100 (ULONG_PTR
)apc_user
, (ULONG_PTR
)io_status
, 0 );
1104 TRACE("= 0x%08x\n", status
);
1105 if (status
!= STATUS_PENDING
&& event
) NtResetEvent( event
, NULL
);
1108 if (send_completion
) NTDLL_AddCompletion( file
, cvalue
, status
, total
);
1114 /***********************************************************************
1115 * FILE_AsyncWriteService (INTERNAL)
1117 static NTSTATUS
FILE_AsyncWriteService( void *user
, IO_STATUS_BLOCK
*iosb
, NTSTATUS status
)
1119 struct async_fileio_write
*fileio
= user
;
1120 int result
, fd
, needs_close
;
1121 enum server_fd_type type
;
1125 case STATUS_ALERTED
:
1126 /* write some data (non-blocking) */
1127 if ((status
= server_get_unix_fd( fileio
->io
.handle
, FILE_WRITE_DATA
, &fd
,
1128 &needs_close
, &type
, NULL
)))
1131 if (!fileio
->count
&& (type
== FD_TYPE_MAILSLOT
|| type
== FD_TYPE_PIPE
|| type
== FD_TYPE_SOCKET
))
1132 result
= send( fd
, fileio
->buffer
, 0, 0 );
1134 result
= write( fd
, &fileio
->buffer
[fileio
->already
], fileio
->count
- fileio
->already
);
1136 if (needs_close
) close( fd
);
1140 if (errno
== EAGAIN
|| errno
== EINTR
) status
= STATUS_PENDING
;
1141 else status
= FILE_GetNtStatus();
1145 fileio
->already
+= result
;
1146 status
= (fileio
->already
< fileio
->count
) ? STATUS_PENDING
: STATUS_SUCCESS
;
1150 case STATUS_TIMEOUT
:
1151 case STATUS_IO_TIMEOUT
:
1152 if (fileio
->already
) status
= STATUS_SUCCESS
;
1155 if (status
!= STATUS_PENDING
)
1157 iosb
->u
.Status
= status
;
1158 iosb
->Information
= fileio
->already
;
1159 release_fileio( &fileio
->io
);
1164 static NTSTATUS
set_pending_write( HANDLE device
)
1168 SERVER_START_REQ( set_serial_info
)
1170 req
->handle
= wine_server_obj_handle( device
);
1171 req
->flags
= SERIALINFO_PENDING_WRITE
;
1172 status
= wine_server_call( req
);
1178 /******************************************************************************
1179 * NtWriteFile [NTDLL.@]
1180 * ZwWriteFile [NTDLL.@]
1182 * Write to an open file handle.
1185 * FileHandle [I] Handle returned from ZwOpenFile() or ZwCreateFile()
1186 * Event [I] Event to signal upon completion (or NULL)
1187 * ApcRoutine [I] Callback to call upon completion (or NULL)
1188 * ApcContext [I] Context for ApcRoutine (or NULL)
1189 * IoStatusBlock [O] Receives information about the operation on return
1190 * Buffer [I] Source for the data to write
1191 * Length [I] Size of Buffer
1192 * ByteOffset [O] Destination for the new file pointer position (or NULL)
1193 * Key [O] Function unknown (may be NULL)
1196 * Success: 0. IoStatusBlock is updated, and the Information member contains
1197 * The number of bytes written.
1198 * Failure: An NTSTATUS error code describing the error.
1200 NTSTATUS WINAPI
NtWriteFile(HANDLE hFile
, HANDLE hEvent
,
1201 PIO_APC_ROUTINE apc
, void* apc_user
,
1202 PIO_STATUS_BLOCK io_status
,
1203 const void* buffer
, ULONG length
,
1204 PLARGE_INTEGER offset
, PULONG key
)
1206 int result
, unix_handle
, needs_close
;
1207 unsigned int options
;
1208 struct io_timeouts timeouts
;
1211 enum server_fd_type type
;
1212 ULONG_PTR cvalue
= apc
? 0 : (ULONG_PTR
)apc_user
;
1213 BOOL send_completion
= FALSE
, async_write
, append_write
= FALSE
, timeout_init_done
= FALSE
;
1214 LARGE_INTEGER offset_eof
;
1216 TRACE("(%p,%p,%p,%p,%p,%p,0x%08x,%p,%p)!\n",
1217 hFile
,hEvent
,apc
,apc_user
,io_status
,buffer
,length
,offset
,key
);
1219 if (!io_status
) return STATUS_ACCESS_VIOLATION
;
1221 status
= server_get_unix_fd( hFile
, FILE_WRITE_DATA
, &unix_handle
,
1222 &needs_close
, &type
, &options
);
1223 if (status
== STATUS_ACCESS_DENIED
)
1225 status
= server_get_unix_fd( hFile
, FILE_APPEND_DATA
, &unix_handle
,
1226 &needs_close
, &type
, &options
);
1227 append_write
= TRUE
;
1229 if (status
&& status
!= STATUS_BAD_DEVICE_TYPE
) return status
;
1231 if (!virtual_check_buffer_for_read( buffer
, length
))
1233 status
= STATUS_INVALID_USER_BUFFER
;
1237 if (status
== STATUS_BAD_DEVICE_TYPE
)
1238 return server_write_file( hFile
, hEvent
, apc
, apc_user
, io_status
, buffer
, length
, offset
, key
);
1240 async_write
= !(options
& (FILE_SYNCHRONOUS_IO_ALERT
| FILE_SYNCHRONOUS_IO_NONALERT
));
1242 if (type
== FD_TYPE_FILE
)
1245 (!offset
|| (offset
->QuadPart
< 0 && offset
->QuadPart
!= FILE_WRITE_TO_END_OF_FILE
)))
1247 status
= STATUS_INVALID_PARAMETER
;
1253 offset_eof
.QuadPart
= FILE_WRITE_TO_END_OF_FILE
;
1254 offset
= &offset_eof
;
1257 if (offset
&& offset
->QuadPart
!= FILE_USE_FILE_POINTER_POSITION
)
1259 off_t off
= offset
->QuadPart
;
1261 if (offset
->QuadPart
== FILE_WRITE_TO_END_OF_FILE
)
1265 if (fstat( unix_handle
, &st
) == -1)
1267 status
= FILE_GetNtStatus();
1272 else if (offset
->QuadPart
< 0)
1274 status
= STATUS_INVALID_PARAMETER
;
1278 /* async I/O doesn't make sense on regular files */
1279 while ((result
= pwrite( unix_handle
, buffer
, length
, off
)) == -1)
1283 if (errno
== EFAULT
) status
= STATUS_INVALID_USER_BUFFER
;
1284 else status
= FILE_GetNtStatus();
1290 /* update file pointer position */
1291 lseek( unix_handle
, off
+ result
, SEEK_SET
);
1294 status
= STATUS_SUCCESS
;
1298 else if (type
== FD_TYPE_SERIAL
|| type
== FD_TYPE_DEVICE
)
1301 (!offset
|| (offset
->QuadPart
< 0 && offset
->QuadPart
!= FILE_WRITE_TO_END_OF_FILE
)))
1303 status
= STATUS_INVALID_PARAMETER
;
1310 /* zero-length writes on sockets may not work with plain write(2) */
1311 if (!length
&& (type
== FD_TYPE_MAILSLOT
|| type
== FD_TYPE_PIPE
|| type
== FD_TYPE_SOCKET
))
1312 result
= send( unix_handle
, buffer
, 0, 0 );
1314 result
= write( unix_handle
, (const char *)buffer
+ total
, length
- total
);
1319 if (total
== length
)
1321 status
= STATUS_SUCCESS
;
1324 if (type
== FD_TYPE_FILE
) continue; /* no async I/O on regular files */
1326 else if (errno
!= EAGAIN
)
1328 if (errno
== EINTR
) continue;
1331 if (errno
== EFAULT
) status
= STATUS_INVALID_USER_BUFFER
;
1332 else status
= FILE_GetNtStatus();
1339 struct async_fileio_write
*fileio
;
1341 fileio
= (struct async_fileio_write
*)alloc_fileio( sizeof(*fileio
), FILE_AsyncWriteService
, hFile
);
1344 status
= STATUS_NO_MEMORY
;
1347 fileio
->already
= total
;
1348 fileio
->count
= length
;
1349 fileio
->buffer
= buffer
;
1351 SERVER_START_REQ( register_async
)
1353 req
->type
= ASYNC_TYPE_WRITE
;
1354 req
->count
= length
;
1355 req
->async
= server_async( hFile
, &fileio
->io
, hEvent
, apc
, apc_user
, io_status
);
1356 status
= wine_server_call( req
);
1360 if (status
!= STATUS_PENDING
) RtlFreeHeap( GetProcessHeap(), 0, fileio
);
1363 else /* synchronous write, wait for the fd to become ready */
1368 if (!timeout_init_done
)
1370 timeout_init_done
= TRUE
;
1371 if ((status
= get_io_timeouts( hFile
, type
, length
, FALSE
, &timeouts
)))
1373 if (hEvent
) NtResetEvent( hEvent
, NULL
);
1375 timeout
= get_next_io_timeout( &timeouts
, total
);
1377 pfd
.fd
= unix_handle
;
1378 pfd
.events
= POLLOUT
;
1380 if (!timeout
|| !(ret
= poll( &pfd
, 1, timeout
)))
1382 /* return with what we got so far */
1383 status
= total
? STATUS_SUCCESS
: STATUS_TIMEOUT
;
1386 if (ret
== -1 && errno
!= EINTR
)
1388 status
= FILE_GetNtStatus();
1391 /* will now restart the write */
1396 send_completion
= cvalue
!= 0;
1399 if (needs_close
) close( unix_handle
);
1401 if (type
== FD_TYPE_SERIAL
&& (status
== STATUS_SUCCESS
|| status
== STATUS_PENDING
))
1402 set_pending_write( hFile
);
1404 if (status
== STATUS_SUCCESS
)
1406 io_status
->u
.Status
= status
;
1407 io_status
->Information
= total
;
1408 TRACE("= SUCCESS (%u)\n", total
);
1409 if (hEvent
) NtSetEvent( hEvent
, NULL
);
1410 if (apc
) NtQueueApcThread( GetCurrentThread(), (PNTAPCFUNC
)apc
,
1411 (ULONG_PTR
)apc_user
, (ULONG_PTR
)io_status
, 0 );
1415 TRACE("= 0x%08x\n", status
);
1416 if (status
!= STATUS_PENDING
&& hEvent
) NtResetEvent( hEvent
, NULL
);
1419 if (send_completion
) NTDLL_AddCompletion( hFile
, cvalue
, status
, total
);
1425 /******************************************************************************
1426 * NtWriteFileGather [NTDLL.@]
1427 * ZwWriteFileGather [NTDLL.@]
1429 NTSTATUS WINAPI
NtWriteFileGather( HANDLE file
, HANDLE event
, PIO_APC_ROUTINE apc
, void *apc_user
,
1430 PIO_STATUS_BLOCK io_status
, FILE_SEGMENT_ELEMENT
*segments
,
1431 ULONG length
, PLARGE_INTEGER offset
, PULONG key
)
1433 int result
, unix_handle
, needs_close
;
1434 unsigned int options
;
1436 ULONG pos
= 0, total
= 0;
1437 enum server_fd_type type
;
1438 ULONG_PTR cvalue
= apc
? 0 : (ULONG_PTR
)apc_user
;
1439 BOOL send_completion
= FALSE
;
1441 TRACE( "(%p,%p,%p,%p,%p,%p,0x%08x,%p,%p),partial stub!\n",
1442 file
, event
, apc
, apc_user
, io_status
, segments
, length
, offset
, key
);
1444 if (length
% page_size
) return STATUS_INVALID_PARAMETER
;
1445 if (!io_status
) return STATUS_ACCESS_VIOLATION
;
1447 status
= server_get_unix_fd( file
, FILE_WRITE_DATA
, &unix_handle
,
1448 &needs_close
, &type
, &options
);
1449 if (status
) return status
;
1451 if ((type
!= FD_TYPE_FILE
) ||
1452 (options
& (FILE_SYNCHRONOUS_IO_ALERT
| FILE_SYNCHRONOUS_IO_NONALERT
)) ||
1453 !(options
& FILE_NO_INTERMEDIATE_BUFFERING
))
1455 status
= STATUS_INVALID_PARAMETER
;
1461 if (offset
&& offset
->QuadPart
!= FILE_USE_FILE_POINTER_POSITION
)
1462 result
= pwrite( unix_handle
, (char *)segments
->Buffer
+ pos
,
1463 page_size
- pos
, offset
->QuadPart
+ total
);
1465 result
= write( unix_handle
, (char *)segments
->Buffer
+ pos
, page_size
- pos
);
1469 if (errno
== EINTR
) continue;
1470 if (errno
== EFAULT
)
1472 status
= STATUS_INVALID_USER_BUFFER
;
1475 status
= FILE_GetNtStatus();
1480 status
= STATUS_DISK_FULL
;
1485 if ((pos
+= result
) == page_size
)
1492 send_completion
= cvalue
!= 0;
1495 if (needs_close
) close( unix_handle
);
1496 if (status
== STATUS_SUCCESS
)
1498 io_status
->u
.Status
= status
;
1499 io_status
->Information
= total
;
1500 TRACE("= SUCCESS (%u)\n", total
);
1501 if (event
) NtSetEvent( event
, NULL
);
1502 if (apc
) NtQueueApcThread( GetCurrentThread(), (PNTAPCFUNC
)apc
,
1503 (ULONG_PTR
)apc_user
, (ULONG_PTR
)io_status
, 0 );
1507 TRACE("= 0x%08x\n", status
);
1508 if (status
!= STATUS_PENDING
&& event
) NtResetEvent( event
, NULL
);
1511 if (send_completion
) NTDLL_AddCompletion( file
, cvalue
, status
, total
);
1517 /* do an ioctl call through the server */
1518 static NTSTATUS
server_ioctl_file( HANDLE handle
, HANDLE event
,
1519 PIO_APC_ROUTINE apc
, PVOID apc_context
,
1520 IO_STATUS_BLOCK
*io
, ULONG code
,
1521 const void *in_buffer
, ULONG in_size
,
1522 PVOID out_buffer
, ULONG out_size
)
1524 struct async_irp
*async
;
1529 if (!(async
= (struct async_irp
*)alloc_fileio( sizeof(*async
), irp_completion
, handle
)))
1530 return STATUS_NO_MEMORY
;
1531 async
->event
= event
;
1532 async
->buffer
= out_buffer
;
1533 async
->size
= out_size
;
1535 SERVER_START_REQ( ioctl
)
1538 req
->async
= server_async( handle
, &async
->io
, event
, apc
, apc_context
, io
);
1539 wine_server_add_data( req
, in_buffer
, in_size
);
1540 if ((code
& 3) != METHOD_BUFFERED
)
1541 wine_server_add_data( req
, out_buffer
, out_size
);
1542 wine_server_set_reply( req
, out_buffer
, out_size
);
1543 status
= wine_server_call( req
);
1544 wait_handle
= wine_server_ptr_handle( reply
->wait
);
1545 options
= reply
->options
;
1546 if (status
!= STATUS_PENDING
) io
->Information
= wine_server_reply_size( reply
);
1550 if (status
== STATUS_NOT_SUPPORTED
)
1551 FIXME("Unsupported ioctl %x (device=%x access=%x func=%x method=%x)\n",
1552 code
, code
>> 16, (code
>> 14) & 3, (code
>> 2) & 0xfff, code
& 3);
1554 if (status
!= STATUS_PENDING
) RtlFreeHeap( GetProcessHeap(), 0, async
);
1558 NtWaitForSingleObject( wait_handle
, (options
& FILE_SYNCHRONOUS_IO_ALERT
), NULL
);
1559 status
= io
->u
.Status
;
1560 NtClose( wait_handle
);
1563 if (status
!= STATUS_PENDING
&& code
!= FSCTL_PIPE_LISTEN
) io
->u
.Status
= 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_PEEK
:
1702 FILE_PIPE_PEEK_BUFFER
*buffer
= out_buffer
;
1703 int avail
= 0, fd
, needs_close
;
1705 if (out_size
< FIELD_OFFSET( FILE_PIPE_PEEK_BUFFER
, Data
))
1707 status
= STATUS_INFO_LENGTH_MISMATCH
;
1711 if ((status
= server_get_unix_fd( handle
, FILE_READ_DATA
, &fd
, &needs_close
, NULL
, NULL
)))
1713 if (status
== STATUS_BAD_DEVICE_TYPE
)
1714 return server_ioctl_file( handle
, event
, apc
, apc_context
, io
, code
,
1715 in_buffer
, in_size
, out_buffer
, out_size
);
1720 if (ioctl( fd
, FIONREAD
, &avail
) != 0)
1722 TRACE("FIONREAD failed reason: %s\n",strerror(errno
));
1723 if (needs_close
) close( fd
);
1724 status
= FILE_GetNtStatus();
1728 if (!avail
) /* check for closed pipe */
1730 struct pollfd pollfd
;
1734 pollfd
.events
= POLLIN
;
1736 ret
= poll( &pollfd
, 1, 0 );
1737 if (ret
== -1 || (ret
== 1 && (pollfd
.revents
& (POLLHUP
|POLLERR
))))
1739 if (needs_close
) close( fd
);
1740 status
= STATUS_PIPE_BROKEN
;
1744 buffer
->NamedPipeState
= 0; /* FIXME */
1745 buffer
->ReadDataAvailable
= avail
;
1746 buffer
->NumberOfMessages
= 0; /* FIXME */
1747 buffer
->MessageLength
= 0; /* FIXME */
1748 io
->Information
= FIELD_OFFSET( FILE_PIPE_PEEK_BUFFER
, Data
);
1749 status
= STATUS_SUCCESS
;
1752 ULONG data_size
= out_size
- FIELD_OFFSET( FILE_PIPE_PEEK_BUFFER
, Data
);
1755 int res
= recv( fd
, buffer
->Data
, data_size
, MSG_PEEK
);
1756 if (res
>= 0) io
->Information
+= res
;
1759 if (needs_close
) close( fd
);
1763 case FSCTL_PIPE_DISCONNECT
:
1764 status
= server_ioctl_file( handle
, event
, apc
, apc_context
, io
, code
,
1765 in_buffer
, in_size
, out_buffer
, out_size
);
1768 int fd
= server_remove_fd_from_cache( handle
);
1769 if (fd
!= -1) close( fd
);
1773 case FSCTL_PIPE_IMPERSONATE
:
1774 FIXME("FSCTL_PIPE_IMPERSONATE: impersonating self\n");
1775 status
= RtlImpersonateSelf( SecurityImpersonation
);
1778 case FSCTL_IS_VOLUME_MOUNTED
:
1779 case FSCTL_LOCK_VOLUME
:
1780 case FSCTL_UNLOCK_VOLUME
:
1781 FIXME("stub! return success - Unsupported fsctl %x (device=%x access=%x func=%x method=%x)\n",
1782 code
, code
>> 16, (code
>> 14) & 3, (code
>> 2) & 0xfff, code
& 3);
1783 status
= STATUS_SUCCESS
;
1786 case FSCTL_GET_RETRIEVAL_POINTERS
:
1788 RETRIEVAL_POINTERS_BUFFER
*buffer
= (RETRIEVAL_POINTERS_BUFFER
*)out_buffer
;
1790 FIXME("stub: FSCTL_GET_RETRIEVAL_POINTERS\n");
1792 if (out_size
>= sizeof(RETRIEVAL_POINTERS_BUFFER
))
1794 buffer
->ExtentCount
= 1;
1795 buffer
->StartingVcn
.QuadPart
= 1;
1796 buffer
->Extents
[0].NextVcn
.QuadPart
= 0;
1797 buffer
->Extents
[0].Lcn
.QuadPart
= 0;
1798 io
->Information
= sizeof(RETRIEVAL_POINTERS_BUFFER
);
1799 status
= STATUS_SUCCESS
;
1803 io
->Information
= 0;
1804 status
= STATUS_BUFFER_TOO_SMALL
;
1808 case FSCTL_SET_SPARSE
:
1809 TRACE("FSCTL_SET_SPARSE: Ignoring request\n");
1810 io
->Information
= 0;
1811 status
= STATUS_SUCCESS
;
1814 return server_ioctl_file( handle
, event
, apc
, apc_context
, io
, code
,
1815 in_buffer
, in_size
, out_buffer
, out_size
);
1818 if (status
!= STATUS_PENDING
) io
->u
.Status
= status
;
1823 struct read_changes_fileio
1825 struct async_fileio io
;
1832 static NTSTATUS
read_changes_apc( void *user
, IO_STATUS_BLOCK
*iosb
, NTSTATUS status
)
1834 struct read_changes_fileio
*fileio
= user
;
1837 if (status
== STATUS_ALERTED
)
1839 SERVER_START_REQ( read_change
)
1841 req
->handle
= wine_server_obj_handle( fileio
->io
.handle
);
1842 wine_server_set_reply( req
, fileio
->data
, fileio
->data_size
);
1843 status
= wine_server_call( req
);
1844 size
= wine_server_reply_size( reply
);
1848 if (status
== STATUS_SUCCESS
&& fileio
->buffer
)
1850 FILE_NOTIFY_INFORMATION
*pfni
= fileio
->buffer
;
1851 int i
, left
= fileio
->buffer_size
;
1852 DWORD
*last_entry_offset
= NULL
;
1853 struct filesystem_event
*event
= (struct filesystem_event
*)fileio
->data
;
1855 while (size
&& left
>= sizeof(*pfni
))
1857 /* convert to an NT style path */
1858 for (i
= 0; i
< event
->len
; i
++)
1859 if (event
->name
[i
] == '/') event
->name
[i
] = '\\';
1861 pfni
->Action
= event
->action
;
1862 pfni
->FileNameLength
= ntdll_umbstowcs( 0, event
->name
, event
->len
, pfni
->FileName
,
1863 (left
- offsetof(FILE_NOTIFY_INFORMATION
, FileName
)) / sizeof(WCHAR
));
1864 last_entry_offset
= &pfni
->NextEntryOffset
;
1866 if (pfni
->FileNameLength
== -1 || pfni
->FileNameLength
== -2) break;
1868 i
= offsetof(FILE_NOTIFY_INFORMATION
, FileName
[pfni
->FileNameLength
]);
1869 pfni
->FileNameLength
*= sizeof(WCHAR
);
1870 pfni
->NextEntryOffset
= i
;
1871 pfni
= (FILE_NOTIFY_INFORMATION
*)((char*)pfni
+ i
);
1874 i
= (offsetof(struct filesystem_event
, name
[event
->len
])
1875 + sizeof(int)-1) / sizeof(int) * sizeof(int);
1876 event
= (struct filesystem_event
*)((char*)event
+ i
);
1882 status
= STATUS_NOTIFY_ENUM_DIR
;
1887 if (last_entry_offset
) *last_entry_offset
= 0;
1888 size
= fileio
->buffer_size
- left
;
1893 status
= STATUS_NOTIFY_ENUM_DIR
;
1898 if (status
!= STATUS_PENDING
)
1900 iosb
->u
.Status
= status
;
1901 iosb
->Information
= size
;
1902 release_fileio( &fileio
->io
);
1907 #define FILE_NOTIFY_ALL ( \
1908 FILE_NOTIFY_CHANGE_FILE_NAME | \
1909 FILE_NOTIFY_CHANGE_DIR_NAME | \
1910 FILE_NOTIFY_CHANGE_ATTRIBUTES | \
1911 FILE_NOTIFY_CHANGE_SIZE | \
1912 FILE_NOTIFY_CHANGE_LAST_WRITE | \
1913 FILE_NOTIFY_CHANGE_LAST_ACCESS | \
1914 FILE_NOTIFY_CHANGE_CREATION | \
1915 FILE_NOTIFY_CHANGE_SECURITY )
1917 /******************************************************************************
1918 * NtNotifyChangeDirectoryFile [NTDLL.@]
1920 NTSTATUS WINAPI
NtNotifyChangeDirectoryFile( HANDLE handle
, HANDLE event
, PIO_APC_ROUTINE apc
,
1921 void *apc_context
, PIO_STATUS_BLOCK iosb
, void *buffer
,
1922 ULONG buffer_size
, ULONG filter
, BOOLEAN subtree
)
1924 struct read_changes_fileio
*fileio
;
1926 ULONG size
= max( 4096, buffer_size
);
1928 TRACE( "%p %p %p %p %p %p %u %u %d\n",
1929 handle
, event
, apc
, apc_context
, iosb
, buffer
, buffer_size
, filter
, subtree
);
1931 if (!iosb
) return STATUS_ACCESS_VIOLATION
;
1932 if (filter
== 0 || (filter
& ~FILE_NOTIFY_ALL
)) return STATUS_INVALID_PARAMETER
;
1934 fileio
= (struct read_changes_fileio
*)alloc_fileio( offsetof(struct read_changes_fileio
, data
[size
]),
1935 read_changes_apc
, handle
);
1936 if (!fileio
) return STATUS_NO_MEMORY
;
1938 fileio
->buffer
= buffer
;
1939 fileio
->buffer_size
= buffer_size
;
1940 fileio
->data_size
= size
;
1942 SERVER_START_REQ( read_directory_changes
)
1944 req
->filter
= filter
;
1945 req
->want_data
= (buffer
!= NULL
);
1946 req
->subtree
= subtree
;
1947 req
->async
= server_async( handle
, &fileio
->io
, event
, apc
, apc_context
, iosb
);
1948 status
= wine_server_call( req
);
1952 if (status
!= STATUS_PENDING
) RtlFreeHeap( GetProcessHeap(), 0, fileio
);
1956 /******************************************************************************
1957 * NtSetVolumeInformationFile [NTDLL.@]
1958 * ZwSetVolumeInformationFile [NTDLL.@]
1960 * Set volume information for an open file handle.
1963 * FileHandle [I] Handle returned from ZwOpenFile() or ZwCreateFile()
1964 * IoStatusBlock [O] Receives information about the operation on return
1965 * FsInformation [I] Source for volume information
1966 * Length [I] Size of FsInformation
1967 * FsInformationClass [I] Type of volume information to set
1970 * Success: 0. IoStatusBlock is updated.
1971 * Failure: An NTSTATUS error code describing the error.
1973 NTSTATUS WINAPI
NtSetVolumeInformationFile(
1974 IN HANDLE FileHandle
,
1975 PIO_STATUS_BLOCK IoStatusBlock
,
1976 PVOID FsInformation
,
1978 FS_INFORMATION_CLASS FsInformationClass
)
1980 FIXME("(%p,%p,%p,0x%08x,0x%08x) stub\n",
1981 FileHandle
,IoStatusBlock
,FsInformation
,Length
,FsInformationClass
);
1985 #if defined(__ANDROID__) && !defined(HAVE_FUTIMENS)
1986 static int futimens( int fd
, const struct timespec spec
[2] )
1988 return syscall( __NR_utimensat
, fd
, NULL
, spec
, 0 );
1990 #define HAVE_FUTIMENS
1991 #endif /* __ANDROID__ */
1994 #define UTIME_OMIT ((1 << 30) - 2)
1997 static NTSTATUS
set_file_times( int fd
, const LARGE_INTEGER
*mtime
, const LARGE_INTEGER
*atime
)
1999 NTSTATUS status
= STATUS_SUCCESS
;
2001 #ifdef HAVE_FUTIMENS
2002 struct timespec tv
[2];
2004 tv
[0].tv_sec
= tv
[1].tv_sec
= 0;
2005 tv
[0].tv_nsec
= tv
[1].tv_nsec
= UTIME_OMIT
;
2006 if (atime
->QuadPart
)
2008 tv
[0].tv_sec
= atime
->QuadPart
/ 10000000 - SECS_1601_TO_1970
;
2009 tv
[0].tv_nsec
= (atime
->QuadPart
% 10000000) * 100;
2011 if (mtime
->QuadPart
)
2013 tv
[1].tv_sec
= mtime
->QuadPart
/ 10000000 - SECS_1601_TO_1970
;
2014 tv
[1].tv_nsec
= (mtime
->QuadPart
% 10000000) * 100;
2016 if (futimens( fd
, tv
) == -1) status
= FILE_GetNtStatus();
2018 #elif defined(HAVE_FUTIMES) || defined(HAVE_FUTIMESAT)
2019 struct timeval tv
[2];
2022 if (!atime
->QuadPart
|| !mtime
->QuadPart
)
2025 tv
[0].tv_sec
= tv
[0].tv_usec
= 0;
2026 tv
[1].tv_sec
= tv
[1].tv_usec
= 0;
2027 if (!fstat( fd
, &st
))
2029 tv
[0].tv_sec
= st
.st_atime
;
2030 tv
[1].tv_sec
= st
.st_mtime
;
2031 #ifdef HAVE_STRUCT_STAT_ST_ATIM
2032 tv
[0].tv_usec
= st
.st_atim
.tv_nsec
/ 1000;
2033 #elif defined(HAVE_STRUCT_STAT_ST_ATIMESPEC)
2034 tv
[0].tv_usec
= st
.st_atimespec
.tv_nsec
/ 1000;
2036 #ifdef HAVE_STRUCT_STAT_ST_MTIM
2037 tv
[1].tv_usec
= st
.st_mtim
.tv_nsec
/ 1000;
2038 #elif defined(HAVE_STRUCT_STAT_ST_MTIMESPEC)
2039 tv
[1].tv_usec
= st
.st_mtimespec
.tv_nsec
/ 1000;
2043 if (atime
->QuadPart
)
2045 tv
[0].tv_sec
= atime
->QuadPart
/ 10000000 - SECS_1601_TO_1970
;
2046 tv
[0].tv_usec
= (atime
->QuadPart
% 10000000) / 10;
2048 if (mtime
->QuadPart
)
2050 tv
[1].tv_sec
= mtime
->QuadPart
/ 10000000 - SECS_1601_TO_1970
;
2051 tv
[1].tv_usec
= (mtime
->QuadPart
% 10000000) / 10;
2054 if (futimes( fd
, tv
) == -1) status
= FILE_GetNtStatus();
2055 #elif defined(HAVE_FUTIMESAT)
2056 if (futimesat( fd
, NULL
, tv
) == -1) status
= FILE_GetNtStatus();
2059 #else /* HAVE_FUTIMES || HAVE_FUTIMESAT */
2060 FIXME( "setting file times not supported\n" );
2061 status
= STATUS_NOT_IMPLEMENTED
;
2066 static inline void get_file_times( const struct stat
*st
, LARGE_INTEGER
*mtime
, LARGE_INTEGER
*ctime
,
2067 LARGE_INTEGER
*atime
, LARGE_INTEGER
*creation
)
2069 RtlSecondsSince1970ToTime( st
->st_mtime
, mtime
);
2070 RtlSecondsSince1970ToTime( st
->st_ctime
, ctime
);
2071 RtlSecondsSince1970ToTime( st
->st_atime
, atime
);
2072 #ifdef HAVE_STRUCT_STAT_ST_MTIM
2073 mtime
->QuadPart
+= st
->st_mtim
.tv_nsec
/ 100;
2074 #elif defined(HAVE_STRUCT_STAT_ST_MTIMESPEC)
2075 mtime
->QuadPart
+= st
->st_mtimespec
.tv_nsec
/ 100;
2077 #ifdef HAVE_STRUCT_STAT_ST_CTIM
2078 ctime
->QuadPart
+= st
->st_ctim
.tv_nsec
/ 100;
2079 #elif defined(HAVE_STRUCT_STAT_ST_CTIMESPEC)
2080 ctime
->QuadPart
+= st
->st_ctimespec
.tv_nsec
/ 100;
2082 #ifdef HAVE_STRUCT_STAT_ST_ATIM
2083 atime
->QuadPart
+= st
->st_atim
.tv_nsec
/ 100;
2084 #elif defined(HAVE_STRUCT_STAT_ST_ATIMESPEC)
2085 atime
->QuadPart
+= st
->st_atimespec
.tv_nsec
/ 100;
2087 #ifdef HAVE_STRUCT_STAT_ST_BIRTHTIME
2088 RtlSecondsSince1970ToTime( st
->st_birthtime
, creation
);
2089 #ifdef HAVE_STRUCT_STAT_ST_BIRTHTIM
2090 creation
->QuadPart
+= st
->st_birthtim
.tv_nsec
/ 100;
2091 #elif defined(HAVE_STRUCT_STAT_ST_BIRTHTIMESPEC)
2092 creation
->QuadPart
+= st
->st_birthtimespec
.tv_nsec
/ 100;
2094 #elif defined(HAVE_STRUCT_STAT___ST_BIRTHTIME)
2095 RtlSecondsSince1970ToTime( st
->__st_birthtime
, creation
);
2096 #ifdef HAVE_STRUCT_STAT___ST_BIRTHTIM
2097 creation
->QuadPart
+= st
->__st_birthtim
.tv_nsec
/ 100;
2104 /* fill in the file information that depends on the stat and attribute info */
2105 NTSTATUS
fill_file_info( const struct stat
*st
, ULONG attr
, void *ptr
,
2106 FILE_INFORMATION_CLASS
class )
2110 case FileBasicInformation
:
2112 FILE_BASIC_INFORMATION
*info
= ptr
;
2114 get_file_times( st
, &info
->LastWriteTime
, &info
->ChangeTime
,
2115 &info
->LastAccessTime
, &info
->CreationTime
);
2116 info
->FileAttributes
= attr
;
2119 case FileStandardInformation
:
2121 FILE_STANDARD_INFORMATION
*info
= ptr
;
2123 if ((info
->Directory
= S_ISDIR(st
->st_mode
)))
2125 info
->AllocationSize
.QuadPart
= 0;
2126 info
->EndOfFile
.QuadPart
= 0;
2127 info
->NumberOfLinks
= 1;
2131 info
->AllocationSize
.QuadPart
= (ULONGLONG
)st
->st_blocks
* 512;
2132 info
->EndOfFile
.QuadPart
= st
->st_size
;
2133 info
->NumberOfLinks
= st
->st_nlink
;
2137 case FileInternalInformation
:
2139 FILE_INTERNAL_INFORMATION
*info
= ptr
;
2140 info
->IndexNumber
.QuadPart
= st
->st_ino
;
2143 case FileEndOfFileInformation
:
2145 FILE_END_OF_FILE_INFORMATION
*info
= ptr
;
2146 info
->EndOfFile
.QuadPart
= S_ISDIR(st
->st_mode
) ? 0 : st
->st_size
;
2149 case FileAllInformation
:
2151 FILE_ALL_INFORMATION
*info
= ptr
;
2152 fill_file_info( st
, attr
, &info
->BasicInformation
, FileBasicInformation
);
2153 fill_file_info( st
, attr
, &info
->StandardInformation
, FileStandardInformation
);
2154 fill_file_info( st
, attr
, &info
->InternalInformation
, FileInternalInformation
);
2157 /* all directory structures start with the FileDirectoryInformation layout */
2158 case FileBothDirectoryInformation
:
2159 case FileFullDirectoryInformation
:
2160 case FileDirectoryInformation
:
2162 FILE_DIRECTORY_INFORMATION
*info
= ptr
;
2164 get_file_times( st
, &info
->LastWriteTime
, &info
->ChangeTime
,
2165 &info
->LastAccessTime
, &info
->CreationTime
);
2166 if (S_ISDIR(st
->st_mode
))
2168 info
->AllocationSize
.QuadPart
= 0;
2169 info
->EndOfFile
.QuadPart
= 0;
2173 info
->AllocationSize
.QuadPart
= (ULONGLONG
)st
->st_blocks
* 512;
2174 info
->EndOfFile
.QuadPart
= st
->st_size
;
2176 info
->FileAttributes
= attr
;
2179 case FileIdFullDirectoryInformation
:
2181 FILE_ID_FULL_DIRECTORY_INFORMATION
*info
= ptr
;
2182 info
->FileId
.QuadPart
= st
->st_ino
;
2183 fill_file_info( st
, attr
, info
, FileDirectoryInformation
);
2186 case FileIdBothDirectoryInformation
:
2188 FILE_ID_BOTH_DIRECTORY_INFORMATION
*info
= ptr
;
2189 info
->FileId
.QuadPart
= st
->st_ino
;
2190 fill_file_info( st
, attr
, info
, FileDirectoryInformation
);
2193 case FileIdGlobalTxDirectoryInformation
:
2195 FILE_ID_GLOBAL_TX_DIR_INFORMATION
*info
= ptr
;
2196 info
->FileId
.QuadPart
= st
->st_ino
;
2197 fill_file_info( st
, attr
, info
, FileDirectoryInformation
);
2202 return STATUS_INVALID_INFO_CLASS
;
2204 return STATUS_SUCCESS
;
2207 NTSTATUS
server_get_unix_name( HANDLE handle
, ANSI_STRING
*unix_name
)
2209 data_size_t size
= 1024;
2215 name
= RtlAllocateHeap( GetProcessHeap(), 0, size
+ 1 );
2216 if (!name
) return STATUS_NO_MEMORY
;
2217 unix_name
->MaximumLength
= size
+ 1;
2219 SERVER_START_REQ( get_handle_unix_name
)
2221 req
->handle
= wine_server_obj_handle( handle
);
2222 wine_server_set_reply( req
, name
, size
);
2223 ret
= wine_server_call( req
);
2224 size
= reply
->name_len
;
2231 unix_name
->Buffer
= name
;
2232 unix_name
->Length
= size
;
2235 RtlFreeHeap( GetProcessHeap(), 0, name
);
2236 if (ret
!= STATUS_BUFFER_OVERFLOW
) break;
2241 static NTSTATUS
fill_name_info( const ANSI_STRING
*unix_name
, FILE_NAME_INFORMATION
*info
, LONG
*name_len
)
2243 UNICODE_STRING nt_name
;
2246 if (!(status
= wine_unix_to_nt_file_name( unix_name
, &nt_name
)))
2248 const WCHAR
*ptr
= nt_name
.Buffer
;
2249 const WCHAR
*end
= ptr
+ (nt_name
.Length
/ sizeof(WCHAR
));
2251 /* Skip the volume mount point. */
2252 while (ptr
!= end
&& *ptr
== '\\') ++ptr
;
2253 while (ptr
!= end
&& *ptr
!= '\\') ++ptr
;
2254 while (ptr
!= end
&& *ptr
== '\\') ++ptr
;
2255 while (ptr
!= end
&& *ptr
!= '\\') ++ptr
;
2257 info
->FileNameLength
= (end
- ptr
) * sizeof(WCHAR
);
2258 if (*name_len
< info
->FileNameLength
) status
= STATUS_BUFFER_OVERFLOW
;
2259 else *name_len
= info
->FileNameLength
;
2261 memcpy( info
->FileName
, ptr
, *name_len
);
2262 RtlFreeUnicodeString( &nt_name
);
2268 /******************************************************************************
2269 * NtQueryInformationFile [NTDLL.@]
2270 * ZwQueryInformationFile [NTDLL.@]
2272 * Get information about an open file handle.
2275 * hFile [I] Handle returned from ZwOpenFile() or ZwCreateFile()
2276 * io [O] Receives information about the operation on return
2277 * ptr [O] Destination for file information
2278 * len [I] Size of FileInformation
2279 * class [I] Type of file information to get
2282 * Success: 0. IoStatusBlock and FileInformation are updated.
2283 * Failure: An NTSTATUS error code describing the error.
2285 NTSTATUS WINAPI
NtQueryInformationFile( HANDLE hFile
, PIO_STATUS_BLOCK io
,
2286 PVOID ptr
, LONG len
, FILE_INFORMATION_CLASS
class )
2288 static const size_t info_sizes
[] =
2291 sizeof(FILE_DIRECTORY_INFORMATION
), /* FileDirectoryInformation */
2292 sizeof(FILE_FULL_DIRECTORY_INFORMATION
), /* FileFullDirectoryInformation */
2293 sizeof(FILE_BOTH_DIRECTORY_INFORMATION
), /* FileBothDirectoryInformation */
2294 sizeof(FILE_BASIC_INFORMATION
), /* FileBasicInformation */
2295 sizeof(FILE_STANDARD_INFORMATION
), /* FileStandardInformation */
2296 sizeof(FILE_INTERNAL_INFORMATION
), /* FileInternalInformation */
2297 sizeof(FILE_EA_INFORMATION
), /* FileEaInformation */
2298 sizeof(FILE_ACCESS_INFORMATION
), /* FileAccessInformation */
2299 sizeof(FILE_NAME_INFORMATION
), /* FileNameInformation */
2300 sizeof(FILE_RENAME_INFORMATION
)-sizeof(WCHAR
), /* FileRenameInformation */
2301 0, /* FileLinkInformation */
2302 sizeof(FILE_NAMES_INFORMATION
)-sizeof(WCHAR
), /* FileNamesInformation */
2303 sizeof(FILE_DISPOSITION_INFORMATION
), /* FileDispositionInformation */
2304 sizeof(FILE_POSITION_INFORMATION
), /* FilePositionInformation */
2305 sizeof(FILE_FULL_EA_INFORMATION
), /* FileFullEaInformation */
2306 sizeof(FILE_MODE_INFORMATION
), /* FileModeInformation */
2307 sizeof(FILE_ALIGNMENT_INFORMATION
), /* FileAlignmentInformation */
2308 sizeof(FILE_ALL_INFORMATION
), /* FileAllInformation */
2309 sizeof(FILE_ALLOCATION_INFORMATION
), /* FileAllocationInformation */
2310 sizeof(FILE_END_OF_FILE_INFORMATION
), /* FileEndOfFileInformation */
2311 0, /* FileAlternateNameInformation */
2312 sizeof(FILE_STREAM_INFORMATION
)-sizeof(WCHAR
), /* FileStreamInformation */
2313 sizeof(FILE_PIPE_INFORMATION
), /* FilePipeInformation */
2314 sizeof(FILE_PIPE_LOCAL_INFORMATION
), /* FilePipeLocalInformation */
2315 0, /* FilePipeRemoteInformation */
2316 sizeof(FILE_MAILSLOT_QUERY_INFORMATION
), /* FileMailslotQueryInformation */
2317 0, /* FileMailslotSetInformation */
2318 0, /* FileCompressionInformation */
2319 0, /* FileObjectIdInformation */
2320 0, /* FileCompletionInformation */
2321 0, /* FileMoveClusterInformation */
2322 0, /* FileQuotaInformation */
2323 0, /* FileReparsePointInformation */
2324 sizeof(FILE_NETWORK_OPEN_INFORMATION
), /* FileNetworkOpenInformation */
2325 0, /* FileAttributeTagInformation */
2326 0, /* FileTrackingInformation */
2327 0, /* FileIdBothDirectoryInformation */
2328 0, /* FileIdFullDirectoryInformation */
2329 0, /* FileValidDataLengthInformation */
2330 0, /* FileShortNameInformation */
2331 0, /* FileIoCompletionNotificationInformation, */
2332 0, /* FileIoStatusBlockRangeInformation */
2333 0, /* FileIoPriorityHintInformation */
2334 0, /* FileSfioReserveInformation */
2335 0, /* FileSfioVolumeInformation */
2336 0, /* FileHardLinkInformation */
2337 0, /* FileProcessIdsUsingFileInformation */
2338 0, /* FileNormalizedNameInformation */
2339 0, /* FileNetworkPhysicalNameInformation */
2340 0, /* FileIdGlobalTxDirectoryInformation */
2341 0, /* FileIsRemoteDeviceInformation */
2342 0, /* FileAttributeCacheInformation */
2343 0, /* FileNumaNodeInformation */
2344 0, /* FileStandardLinkInformation */
2345 0, /* FileRemoteProtocolInformation */
2346 0, /* FileRenameInformationBypassAccessCheck */
2347 0, /* FileLinkInformationBypassAccessCheck */
2348 0, /* FileVolumeNameInformation */
2349 sizeof(FILE_ID_INFORMATION
), /* FileIdInformation */
2350 0, /* FileIdExtdDirectoryInformation */
2351 0, /* FileReplaceCompletionInformation */
2352 0, /* FileHardLinkFullIdInformation */
2353 0, /* FileIdExtdBothDirectoryInformation */
2357 int fd
, needs_close
= FALSE
;
2360 TRACE("(%p,%p,%p,0x%08x,0x%08x)\n", hFile
, io
, ptr
, len
, class);
2362 io
->Information
= 0;
2364 if (class <= 0 || class >= FileMaximumInformation
)
2365 return io
->u
.Status
= STATUS_INVALID_INFO_CLASS
;
2366 if (!info_sizes
[class])
2368 FIXME("Unsupported class (%d)\n", class);
2369 return io
->u
.Status
= STATUS_NOT_IMPLEMENTED
;
2371 if (len
< info_sizes
[class])
2372 return io
->u
.Status
= STATUS_INFO_LENGTH_MISMATCH
;
2374 if (class != FilePipeInformation
&& class != FilePipeLocalInformation
)
2376 if ((io
->u
.Status
= server_get_unix_fd( hFile
, 0, &fd
, &needs_close
, NULL
, NULL
)))
2377 return io
->u
.Status
;
2382 case FileBasicInformation
:
2383 if (fd_get_file_info( fd
, &st
, &attr
) == -1)
2384 io
->u
.Status
= FILE_GetNtStatus();
2385 else if (!S_ISREG(st
.st_mode
) && !S_ISDIR(st
.st_mode
))
2386 io
->u
.Status
= STATUS_INVALID_INFO_CLASS
;
2388 fill_file_info( &st
, attr
, ptr
, class );
2390 case FileStandardInformation
:
2392 FILE_STANDARD_INFORMATION
*info
= ptr
;
2394 if (fd_get_file_info( fd
, &st
, &attr
) == -1) io
->u
.Status
= FILE_GetNtStatus();
2397 fill_file_info( &st
, attr
, info
, class );
2398 info
->DeletePending
= FALSE
; /* FIXME */
2402 case FilePositionInformation
:
2404 FILE_POSITION_INFORMATION
*info
= ptr
;
2405 off_t res
= lseek( fd
, 0, SEEK_CUR
);
2406 if (res
== (off_t
)-1) io
->u
.Status
= FILE_GetNtStatus();
2407 else info
->CurrentByteOffset
.QuadPart
= res
;
2410 case FileInternalInformation
:
2411 if (fd_get_file_info( fd
, &st
, &attr
) == -1) io
->u
.Status
= FILE_GetNtStatus();
2412 else fill_file_info( &st
, attr
, ptr
, class );
2414 case FileEaInformation
:
2416 FILE_EA_INFORMATION
*info
= ptr
;
2420 case FileAccessInformation
:
2422 FILE_ACCESS_INFORMATION
*info
= ptr
;
2423 SERVER_START_REQ( get_object_info
)
2425 req
->handle
= wine_server_obj_handle( hFile
);
2426 io
->u
.Status
= wine_server_call( req
);
2427 if (io
->u
.Status
== STATUS_SUCCESS
)
2428 info
->AccessFlags
= reply
->access
;
2433 case FileEndOfFileInformation
:
2434 if (fd_get_file_info( fd
, &st
, &attr
) == -1) io
->u
.Status
= FILE_GetNtStatus();
2435 else fill_file_info( &st
, attr
, ptr
, class );
2437 case FileAllInformation
:
2439 FILE_ALL_INFORMATION
*info
= ptr
;
2440 ANSI_STRING unix_name
;
2442 if (fd_get_file_info( fd
, &st
, &attr
) == -1) io
->u
.Status
= FILE_GetNtStatus();
2443 else if (!S_ISREG(st
.st_mode
) && !S_ISDIR(st
.st_mode
))
2444 io
->u
.Status
= STATUS_INVALID_INFO_CLASS
;
2445 else if (!(io
->u
.Status
= server_get_unix_name( hFile
, &unix_name
)))
2447 LONG name_len
= len
- FIELD_OFFSET(FILE_ALL_INFORMATION
, NameInformation
.FileName
);
2449 fill_file_info( &st
, attr
, info
, FileAllInformation
);
2450 info
->StandardInformation
.DeletePending
= FALSE
; /* FIXME */
2451 info
->EaInformation
.EaSize
= 0;
2452 info
->AccessInformation
.AccessFlags
= 0; /* FIXME */
2453 info
->PositionInformation
.CurrentByteOffset
.QuadPart
= lseek( fd
, 0, SEEK_CUR
);
2454 info
->ModeInformation
.Mode
= 0; /* FIXME */
2455 info
->AlignmentInformation
.AlignmentRequirement
= 1; /* FIXME */
2457 io
->u
.Status
= fill_name_info( &unix_name
, &info
->NameInformation
, &name_len
);
2458 RtlFreeAnsiString( &unix_name
);
2459 io
->Information
= FIELD_OFFSET(FILE_ALL_INFORMATION
, NameInformation
.FileName
) + name_len
;
2463 case FileMailslotQueryInformation
:
2465 FILE_MAILSLOT_QUERY_INFORMATION
*info
= ptr
;
2467 SERVER_START_REQ( set_mailslot_info
)
2469 req
->handle
= wine_server_obj_handle( hFile
);
2471 io
->u
.Status
= wine_server_call( req
);
2472 if( io
->u
.Status
== STATUS_SUCCESS
)
2474 info
->MaximumMessageSize
= reply
->max_msgsize
;
2475 info
->MailslotQuota
= 0;
2476 info
->NextMessageSize
= 0;
2477 info
->MessagesAvailable
= 0;
2478 info
->ReadTimeout
.QuadPart
= reply
->read_timeout
;
2485 ULONG size
= info
->MaximumMessageSize
? info
->MaximumMessageSize
: 0x10000;
2486 if (size
> 0x10000) size
= 0x10000;
2487 if ((tmpbuf
= RtlAllocateHeap( GetProcessHeap(), 0, size
)))
2489 if (!server_get_unix_fd( hFile
, FILE_READ_DATA
, &fd
, &needs_close
, NULL
, NULL
))
2491 int res
= recv( fd
, tmpbuf
, size
, MSG_PEEK
);
2492 info
->MessagesAvailable
= (res
> 0);
2493 info
->NextMessageSize
= (res
>= 0) ? res
: MAILSLOT_NO_MESSAGE
;
2494 if (needs_close
) close( fd
);
2496 RtlFreeHeap( GetProcessHeap(), 0, tmpbuf
);
2501 case FilePipeInformation
:
2503 FILE_PIPE_INFORMATION
* pi
= ptr
;
2505 SERVER_START_REQ( get_named_pipe_info
)
2507 req
->handle
= wine_server_obj_handle( hFile
);
2508 if (!(io
->u
.Status
= wine_server_call( req
)))
2510 pi
->ReadMode
= (reply
->flags
& NAMED_PIPE_MESSAGE_STREAM_READ
) ?
2511 FILE_PIPE_MESSAGE_MODE
: FILE_PIPE_BYTE_STREAM_MODE
;
2512 pi
->CompletionMode
= (reply
->flags
& NAMED_PIPE_NONBLOCKING_MODE
) ?
2513 FILE_PIPE_COMPLETE_OPERATION
: FILE_PIPE_QUEUE_OPERATION
;
2519 case FilePipeLocalInformation
:
2521 FILE_PIPE_LOCAL_INFORMATION
* pli
= ptr
;
2523 SERVER_START_REQ( get_named_pipe_info
)
2525 req
->handle
= wine_server_obj_handle( hFile
);
2526 if (!(io
->u
.Status
= wine_server_call( req
)))
2528 pli
->NamedPipeType
= (reply
->flags
& NAMED_PIPE_MESSAGE_STREAM_WRITE
) ?
2529 FILE_PIPE_TYPE_MESSAGE
: FILE_PIPE_TYPE_BYTE
;
2530 switch (reply
->sharing
)
2532 case FILE_SHARE_READ
:
2533 pli
->NamedPipeConfiguration
= FILE_PIPE_OUTBOUND
;
2535 case FILE_SHARE_WRITE
:
2536 pli
->NamedPipeConfiguration
= FILE_PIPE_INBOUND
;
2538 case FILE_SHARE_READ
| FILE_SHARE_WRITE
:
2539 pli
->NamedPipeConfiguration
= FILE_PIPE_FULL_DUPLEX
;
2542 pli
->MaximumInstances
= reply
->maxinstances
;
2543 pli
->CurrentInstances
= reply
->instances
;
2544 pli
->InboundQuota
= reply
->insize
;
2545 pli
->ReadDataAvailable
= 0; /* FIXME */
2546 pli
->OutboundQuota
= reply
->outsize
;
2547 pli
->WriteQuotaAvailable
= 0; /* FIXME */
2548 pli
->NamedPipeState
= 0; /* FIXME */
2549 pli
->NamedPipeEnd
= (reply
->flags
& NAMED_PIPE_SERVER_END
) ?
2550 FILE_PIPE_SERVER_END
: FILE_PIPE_CLIENT_END
;
2556 case FileNameInformation
:
2558 FILE_NAME_INFORMATION
*info
= ptr
;
2559 ANSI_STRING unix_name
;
2561 if (!(io
->u
.Status
= server_get_unix_name( hFile
, &unix_name
)))
2563 LONG name_len
= len
- FIELD_OFFSET(FILE_NAME_INFORMATION
, FileName
);
2564 io
->u
.Status
= fill_name_info( &unix_name
, info
, &name_len
);
2565 RtlFreeAnsiString( &unix_name
);
2566 io
->Information
= FIELD_OFFSET(FILE_NAME_INFORMATION
, FileName
) + name_len
;
2570 case FileNetworkOpenInformation
:
2572 FILE_NETWORK_OPEN_INFORMATION
*info
= ptr
;
2573 ANSI_STRING unix_name
;
2575 if (!(io
->u
.Status
= server_get_unix_name( hFile
, &unix_name
)))
2580 if (get_file_info( unix_name
.Buffer
, &st
, &attributes
) == -1)
2581 io
->u
.Status
= FILE_GetNtStatus();
2582 else if (!S_ISREG(st
.st_mode
) && !S_ISDIR(st
.st_mode
))
2583 io
->u
.Status
= STATUS_INVALID_INFO_CLASS
;
2586 FILE_BASIC_INFORMATION basic
;
2587 FILE_STANDARD_INFORMATION std
;
2589 fill_file_info( &st
, attributes
, &basic
, FileBasicInformation
);
2590 fill_file_info( &st
, attributes
, &std
, FileStandardInformation
);
2592 info
->CreationTime
= basic
.CreationTime
;
2593 info
->LastAccessTime
= basic
.LastAccessTime
;
2594 info
->LastWriteTime
= basic
.LastWriteTime
;
2595 info
->ChangeTime
= basic
.ChangeTime
;
2596 info
->AllocationSize
= std
.AllocationSize
;
2597 info
->EndOfFile
= std
.EndOfFile
;
2598 info
->FileAttributes
= basic
.FileAttributes
;
2600 RtlFreeAnsiString( &unix_name
);
2604 case FileIdInformation
:
2605 if (fd_get_file_info( fd
, &st
, &attr
) == -1) io
->u
.Status
= FILE_GetNtStatus();
2608 FILE_ID_INFORMATION
*info
= ptr
;
2609 info
->VolumeSerialNumber
= 0; /* FIXME */
2610 memset( &info
->FileId
, 0, sizeof(info
->FileId
) );
2611 *(ULONGLONG
*)&info
->FileId
= st
.st_ino
;
2615 FIXME("Unsupported class (%d)\n", class);
2616 io
->u
.Status
= STATUS_NOT_IMPLEMENTED
;
2619 if (needs_close
) close( fd
);
2620 if (io
->u
.Status
== STATUS_SUCCESS
&& !io
->Information
) io
->Information
= info_sizes
[class];
2621 return io
->u
.Status
;
2624 /******************************************************************************
2625 * NtSetInformationFile [NTDLL.@]
2626 * ZwSetInformationFile [NTDLL.@]
2628 * Set information about an open file handle.
2631 * handle [I] Handle returned from ZwOpenFile() or ZwCreateFile()
2632 * io [O] Receives information about the operation on return
2633 * ptr [I] Source for file information
2634 * len [I] Size of FileInformation
2635 * class [I] Type of file information to set
2638 * Success: 0. io is updated.
2639 * Failure: An NTSTATUS error code describing the error.
2641 NTSTATUS WINAPI
NtSetInformationFile(HANDLE handle
, PIO_STATUS_BLOCK io
,
2642 PVOID ptr
, ULONG len
, FILE_INFORMATION_CLASS
class)
2644 int fd
, needs_close
;
2646 TRACE("(%p,%p,%p,0x%08x,0x%08x)\n", handle
, io
, ptr
, len
, class);
2648 io
->u
.Status
= STATUS_SUCCESS
;
2651 case FileBasicInformation
:
2652 if (len
>= sizeof(FILE_BASIC_INFORMATION
))
2655 const FILE_BASIC_INFORMATION
*info
= ptr
;
2657 if ((io
->u
.Status
= server_get_unix_fd( handle
, 0, &fd
, &needs_close
, NULL
, NULL
)))
2658 return io
->u
.Status
;
2660 if (info
->LastAccessTime
.QuadPart
|| info
->LastWriteTime
.QuadPart
)
2661 io
->u
.Status
= set_file_times( fd
, &info
->LastWriteTime
, &info
->LastAccessTime
);
2663 if (io
->u
.Status
== STATUS_SUCCESS
&& info
->FileAttributes
)
2665 if (fstat( fd
, &st
) == -1) io
->u
.Status
= FILE_GetNtStatus();
2668 if (info
->FileAttributes
& FILE_ATTRIBUTE_READONLY
)
2670 if (S_ISDIR( st
.st_mode
))
2671 WARN("FILE_ATTRIBUTE_READONLY ignored for directory.\n");
2673 st
.st_mode
&= ~0222; /* clear write permission bits */
2677 /* add write permission only where we already have read permission */
2678 st
.st_mode
|= (0600 | ((st
.st_mode
& 044) >> 1)) & (~FILE_umask
);
2680 if (fchmod( fd
, st
.st_mode
) == -1) io
->u
.Status
= FILE_GetNtStatus();
2684 if (needs_close
) close( fd
);
2686 else io
->u
.Status
= STATUS_INVALID_PARAMETER_3
;
2689 case FilePositionInformation
:
2690 if (len
>= sizeof(FILE_POSITION_INFORMATION
))
2692 const FILE_POSITION_INFORMATION
*info
= ptr
;
2694 if ((io
->u
.Status
= server_get_unix_fd( handle
, 0, &fd
, &needs_close
, NULL
, NULL
)))
2695 return io
->u
.Status
;
2697 if (lseek( fd
, info
->CurrentByteOffset
.QuadPart
, SEEK_SET
) == (off_t
)-1)
2698 io
->u
.Status
= FILE_GetNtStatus();
2700 if (needs_close
) close( fd
);
2702 else io
->u
.Status
= STATUS_INVALID_PARAMETER_3
;
2705 case FileEndOfFileInformation
:
2706 if (len
>= sizeof(FILE_END_OF_FILE_INFORMATION
))
2709 const FILE_END_OF_FILE_INFORMATION
*info
= ptr
;
2711 if ((io
->u
.Status
= server_get_unix_fd( handle
, 0, &fd
, &needs_close
, NULL
, NULL
)))
2712 return io
->u
.Status
;
2714 /* first try normal truncate */
2715 if (ftruncate( fd
, (off_t
)info
->EndOfFile
.QuadPart
) != -1) break;
2717 /* now check for the need to extend the file */
2718 if (fstat( fd
, &st
) != -1 && (off_t
)info
->EndOfFile
.QuadPart
> st
.st_size
)
2720 static const char zero
;
2722 /* extend the file one byte beyond the requested size and then truncate it */
2723 /* this should work around ftruncate implementations that can't extend files */
2724 if (pwrite( fd
, &zero
, 1, (off_t
)info
->EndOfFile
.QuadPart
) != -1 &&
2725 ftruncate( fd
, (off_t
)info
->EndOfFile
.QuadPart
) != -1) break;
2727 io
->u
.Status
= FILE_GetNtStatus();
2729 if (needs_close
) close( fd
);
2731 else io
->u
.Status
= STATUS_INVALID_PARAMETER_3
;
2734 case FilePipeInformation
:
2735 if (len
>= sizeof(FILE_PIPE_INFORMATION
))
2737 FILE_PIPE_INFORMATION
*info
= ptr
;
2739 if ((info
->CompletionMode
| info
->ReadMode
) & ~1)
2741 io
->u
.Status
= STATUS_INVALID_PARAMETER
;
2745 SERVER_START_REQ( set_named_pipe_info
)
2747 req
->handle
= wine_server_obj_handle( handle
);
2748 req
->flags
= (info
->CompletionMode
? NAMED_PIPE_NONBLOCKING_MODE
: 0) |
2749 (info
->ReadMode
? NAMED_PIPE_MESSAGE_STREAM_READ
: 0);
2750 io
->u
.Status
= wine_server_call( req
);
2754 else io
->u
.Status
= STATUS_INVALID_PARAMETER_3
;
2757 case FileMailslotSetInformation
:
2759 FILE_MAILSLOT_SET_INFORMATION
*info
= ptr
;
2761 SERVER_START_REQ( set_mailslot_info
)
2763 req
->handle
= wine_server_obj_handle( handle
);
2764 req
->flags
= MAILSLOT_SET_READ_TIMEOUT
;
2765 req
->read_timeout
= info
->ReadTimeout
.QuadPart
;
2766 io
->u
.Status
= wine_server_call( req
);
2772 case FileCompletionInformation
:
2773 if (len
>= sizeof(FILE_COMPLETION_INFORMATION
))
2775 FILE_COMPLETION_INFORMATION
*info
= ptr
;
2777 SERVER_START_REQ( set_completion_info
)
2779 req
->handle
= wine_server_obj_handle( handle
);
2780 req
->chandle
= wine_server_obj_handle( info
->CompletionPort
);
2781 req
->ckey
= info
->CompletionKey
;
2782 io
->u
.Status
= wine_server_call( req
);
2786 io
->u
.Status
= STATUS_INVALID_PARAMETER_3
;
2789 case FileAllInformation
:
2790 io
->u
.Status
= STATUS_INVALID_INFO_CLASS
;
2793 case FileValidDataLengthInformation
:
2794 if (len
>= sizeof(FILE_VALID_DATA_LENGTH_INFORMATION
))
2797 const FILE_VALID_DATA_LENGTH_INFORMATION
*info
= ptr
;
2799 if ((io
->u
.Status
= server_get_unix_fd( handle
, FILE_WRITE_DATA
, &fd
, &needs_close
, NULL
, NULL
)))
2800 return io
->u
.Status
;
2802 if (fstat( fd
, &st
) == -1) io
->u
.Status
= FILE_GetNtStatus();
2803 else if (info
->ValidDataLength
.QuadPart
<= 0 || (off_t
)info
->ValidDataLength
.QuadPart
> st
.st_size
)
2804 io
->u
.Status
= STATUS_INVALID_PARAMETER
;
2807 #ifdef HAVE_FALLOCATE
2808 if (fallocate( fd
, 0, 0, (off_t
)info
->ValidDataLength
.QuadPart
) == -1)
2810 NTSTATUS status
= FILE_GetNtStatus();
2811 if (status
== STATUS_NOT_SUPPORTED
) WARN( "fallocate not supported on this filesystem\n" );
2812 else io
->u
.Status
= status
;
2815 FIXME( "setting valid data length not supported\n" );
2818 if (needs_close
) close( fd
);
2820 else io
->u
.Status
= STATUS_INVALID_PARAMETER_3
;
2823 case FileDispositionInformation
:
2824 if (len
>= sizeof(FILE_DISPOSITION_INFORMATION
))
2826 FILE_DISPOSITION_INFORMATION
*info
= ptr
;
2828 SERVER_START_REQ( set_fd_disp_info
)
2830 req
->handle
= wine_server_obj_handle( handle
);
2831 req
->unlink
= info
->DoDeleteFile
;
2832 io
->u
.Status
= wine_server_call( req
);
2836 io
->u
.Status
= STATUS_INVALID_PARAMETER_3
;
2839 case FileRenameInformation
:
2840 if (len
>= sizeof(FILE_RENAME_INFORMATION
))
2842 FILE_RENAME_INFORMATION
*info
= ptr
;
2843 UNICODE_STRING name_str
;
2844 OBJECT_ATTRIBUTES attr
;
2845 ANSI_STRING unix_name
;
2847 name_str
.Buffer
= info
->FileName
;
2848 name_str
.Length
= info
->FileNameLength
;
2849 name_str
.MaximumLength
= info
->FileNameLength
+ sizeof(WCHAR
);
2851 attr
.Length
= sizeof(attr
);
2852 attr
.ObjectName
= &name_str
;
2853 attr
.RootDirectory
= info
->RootDir
;
2854 attr
.Attributes
= OBJ_CASE_INSENSITIVE
;
2856 io
->u
.Status
= nt_to_unix_file_name_attr( &attr
, &unix_name
, FILE_OPEN_IF
);
2857 if (io
->u
.Status
!= STATUS_SUCCESS
&& io
->u
.Status
!= STATUS_NO_SUCH_FILE
)
2860 if (!info
->Replace
&& io
->u
.Status
== STATUS_SUCCESS
)
2862 RtlFreeAnsiString( &unix_name
);
2863 io
->u
.Status
= STATUS_OBJECT_NAME_COLLISION
;
2867 SERVER_START_REQ( set_fd_name_info
)
2869 req
->handle
= wine_server_obj_handle( handle
);
2870 req
->rootdir
= wine_server_obj_handle( attr
.RootDirectory
);
2872 wine_server_add_data( req
, unix_name
.Buffer
, unix_name
.Length
);
2873 io
->u
.Status
= wine_server_call( req
);
2877 RtlFreeAnsiString( &unix_name
);
2879 else io
->u
.Status
= STATUS_INVALID_PARAMETER_3
;
2882 case FileLinkInformation
:
2883 if (len
>= sizeof(FILE_LINK_INFORMATION
))
2885 FILE_LINK_INFORMATION
*info
= ptr
;
2886 UNICODE_STRING name_str
;
2887 OBJECT_ATTRIBUTES attr
;
2888 ANSI_STRING unix_name
;
2890 name_str
.Buffer
= info
->FileName
;
2891 name_str
.Length
= info
->FileNameLength
;
2892 name_str
.MaximumLength
= info
->FileNameLength
+ sizeof(WCHAR
);
2894 attr
.Length
= sizeof(attr
);
2895 attr
.ObjectName
= &name_str
;
2896 attr
.RootDirectory
= info
->RootDirectory
;
2897 attr
.Attributes
= OBJ_CASE_INSENSITIVE
;
2899 io
->u
.Status
= nt_to_unix_file_name_attr( &attr
, &unix_name
, FILE_OPEN_IF
);
2900 if (io
->u
.Status
!= STATUS_SUCCESS
&& io
->u
.Status
!= STATUS_NO_SUCH_FILE
)
2903 if (!info
->ReplaceIfExists
&& io
->u
.Status
== STATUS_SUCCESS
)
2905 RtlFreeAnsiString( &unix_name
);
2906 io
->u
.Status
= STATUS_OBJECT_NAME_COLLISION
;
2910 SERVER_START_REQ( set_fd_name_info
)
2912 req
->handle
= wine_server_obj_handle( handle
);
2913 req
->rootdir
= wine_server_obj_handle( attr
.RootDirectory
);
2915 wine_server_add_data( req
, unix_name
.Buffer
, unix_name
.Length
);
2916 io
->u
.Status
= wine_server_call( req
);
2920 RtlFreeAnsiString( &unix_name
);
2922 else io
->u
.Status
= STATUS_INVALID_PARAMETER_3
;
2926 FIXME("Unsupported class (%d)\n", class);
2927 io
->u
.Status
= STATUS_NOT_IMPLEMENTED
;
2930 io
->Information
= 0;
2931 return io
->u
.Status
;
2935 /******************************************************************************
2936 * NtQueryFullAttributesFile (NTDLL.@)
2938 NTSTATUS WINAPI
NtQueryFullAttributesFile( const OBJECT_ATTRIBUTES
*attr
,
2939 FILE_NETWORK_OPEN_INFORMATION
*info
)
2941 ANSI_STRING unix_name
;
2944 if (!(status
= nt_to_unix_file_name_attr( attr
, &unix_name
, FILE_OPEN
)))
2949 if (get_file_info( unix_name
.Buffer
, &st
, &attributes
) == -1)
2950 status
= FILE_GetNtStatus();
2951 else if (!S_ISREG(st
.st_mode
) && !S_ISDIR(st
.st_mode
))
2952 status
= STATUS_INVALID_INFO_CLASS
;
2955 FILE_BASIC_INFORMATION basic
;
2956 FILE_STANDARD_INFORMATION std
;
2958 fill_file_info( &st
, attributes
, &basic
, FileBasicInformation
);
2959 fill_file_info( &st
, attributes
, &std
, FileStandardInformation
);
2961 info
->CreationTime
= basic
.CreationTime
;
2962 info
->LastAccessTime
= basic
.LastAccessTime
;
2963 info
->LastWriteTime
= basic
.LastWriteTime
;
2964 info
->ChangeTime
= basic
.ChangeTime
;
2965 info
->AllocationSize
= std
.AllocationSize
;
2966 info
->EndOfFile
= std
.EndOfFile
;
2967 info
->FileAttributes
= basic
.FileAttributes
;
2968 if (DIR_is_hidden_file( attr
->ObjectName
))
2969 info
->FileAttributes
|= FILE_ATTRIBUTE_HIDDEN
;
2971 RtlFreeAnsiString( &unix_name
);
2973 else WARN("%s not found (%x)\n", debugstr_us(attr
->ObjectName
), status
);
2978 /******************************************************************************
2979 * NtQueryAttributesFile (NTDLL.@)
2980 * ZwQueryAttributesFile (NTDLL.@)
2982 NTSTATUS WINAPI
NtQueryAttributesFile( const OBJECT_ATTRIBUTES
*attr
, FILE_BASIC_INFORMATION
*info
)
2984 ANSI_STRING unix_name
;
2987 if (!(status
= nt_to_unix_file_name_attr( attr
, &unix_name
, FILE_OPEN
)))
2992 if (get_file_info( unix_name
.Buffer
, &st
, &attributes
) == -1)
2993 status
= FILE_GetNtStatus();
2994 else if (!S_ISREG(st
.st_mode
) && !S_ISDIR(st
.st_mode
))
2995 status
= STATUS_INVALID_INFO_CLASS
;
2998 status
= fill_file_info( &st
, attributes
, info
, FileBasicInformation
);
2999 if (DIR_is_hidden_file( attr
->ObjectName
))
3000 info
->FileAttributes
|= FILE_ATTRIBUTE_HIDDEN
;
3002 RtlFreeAnsiString( &unix_name
);
3004 else WARN("%s not found (%x)\n", debugstr_us(attr
->ObjectName
), status
);
3009 #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__DragonFly__) || defined(__APPLE__)
3010 /* helper for FILE_GetDeviceInfo to hide some platform differences in fstatfs */
3011 static inline void get_device_info_fstatfs( FILE_FS_DEVICE_INFORMATION
*info
, const char *fstypename
,
3012 unsigned int flags
)
3014 if (!strcmp("cd9660", fstypename
) || !strcmp("udf", fstypename
))
3016 info
->DeviceType
= FILE_DEVICE_CD_ROM_FILE_SYSTEM
;
3017 /* Don't assume read-only, let the mount options set it below */
3018 info
->Characteristics
|= FILE_REMOVABLE_MEDIA
;
3020 else if (!strcmp("nfs", fstypename
) || !strcmp("nwfs", fstypename
) ||
3021 !strcmp("smbfs", fstypename
) || !strcmp("afpfs", fstypename
))
3023 info
->DeviceType
= FILE_DEVICE_NETWORK_FILE_SYSTEM
;
3024 info
->Characteristics
|= FILE_REMOTE_DEVICE
;
3026 else if (!strcmp("procfs", fstypename
))
3027 info
->DeviceType
= FILE_DEVICE_VIRTUAL_DISK
;
3029 info
->DeviceType
= FILE_DEVICE_DISK_FILE_SYSTEM
;
3031 if (flags
& MNT_RDONLY
)
3032 info
->Characteristics
|= FILE_READ_ONLY_DEVICE
;
3034 if (!(flags
& MNT_LOCAL
))
3036 info
->DeviceType
= FILE_DEVICE_NETWORK_FILE_SYSTEM
;
3037 info
->Characteristics
|= FILE_REMOTE_DEVICE
;
3042 static inline BOOL
is_device_placeholder( int fd
)
3044 static const char wine_placeholder
[] = "Wine device placeholder";
3045 char buffer
[sizeof(wine_placeholder
)-1];
3047 if (pread( fd
, buffer
, sizeof(wine_placeholder
) - 1, 0 ) != sizeof(wine_placeholder
) - 1)
3049 return !memcmp( buffer
, wine_placeholder
, sizeof(wine_placeholder
) - 1 );
3052 /******************************************************************************
3055 * Implementation of the FileFsDeviceInformation query for NtQueryVolumeInformationFile.
3057 static NTSTATUS
get_device_info( int fd
, FILE_FS_DEVICE_INFORMATION
*info
)
3061 info
->Characteristics
= 0;
3062 if (fstat( fd
, &st
) < 0) return FILE_GetNtStatus();
3063 if (S_ISCHR( st
.st_mode
))
3065 info
->DeviceType
= FILE_DEVICE_UNKNOWN
;
3067 switch(major(st
.st_rdev
))
3070 info
->DeviceType
= FILE_DEVICE_NULL
;
3073 info
->DeviceType
= FILE_DEVICE_SERIAL_PORT
;
3076 info
->DeviceType
= FILE_DEVICE_PARALLEL_PORT
;
3078 case SCSI_TAPE_MAJOR
:
3079 info
->DeviceType
= FILE_DEVICE_TAPE
;
3084 else if (S_ISBLK( st
.st_mode
))
3086 info
->DeviceType
= FILE_DEVICE_DISK
;
3088 else if (S_ISFIFO( st
.st_mode
) || S_ISSOCK( st
.st_mode
))
3090 info
->DeviceType
= FILE_DEVICE_NAMED_PIPE
;
3092 else if (is_device_placeholder( fd
))
3094 info
->DeviceType
= FILE_DEVICE_DISK
;
3096 else /* regular file or directory */
3098 #if defined(linux) && defined(HAVE_FSTATFS)
3101 /* check for floppy disk */
3102 if (major(st
.st_dev
) == FLOPPY_MAJOR
)
3103 info
->Characteristics
|= FILE_REMOVABLE_MEDIA
;
3105 if (fstatfs( fd
, &stfs
) < 0) stfs
.f_type
= 0;
3106 switch (stfs
.f_type
)
3108 case 0x9660: /* iso9660 */
3109 case 0x9fa1: /* supermount */
3110 case 0x15013346: /* udf */
3111 info
->DeviceType
= FILE_DEVICE_CD_ROM_FILE_SYSTEM
;
3112 info
->Characteristics
|= FILE_REMOVABLE_MEDIA
|FILE_READ_ONLY_DEVICE
;
3114 case 0x6969: /* nfs */
3115 case 0x517B: /* smbfs */
3116 case 0x564c: /* ncpfs */
3117 info
->DeviceType
= FILE_DEVICE_NETWORK_FILE_SYSTEM
;
3118 info
->Characteristics
|= FILE_REMOTE_DEVICE
;
3120 case 0x01021994: /* tmpfs */
3121 case 0x28cd3d45: /* cramfs */
3122 case 0x1373: /* devfs */
3123 case 0x9fa0: /* procfs */
3124 info
->DeviceType
= FILE_DEVICE_VIRTUAL_DISK
;
3127 info
->DeviceType
= FILE_DEVICE_DISK_FILE_SYSTEM
;
3130 #elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__OpenBSD__) || defined(__DragonFly__) || defined(__APPLE__)
3133 if (fstatfs( fd
, &stfs
) < 0)
3134 info
->DeviceType
= FILE_DEVICE_DISK_FILE_SYSTEM
;
3136 get_device_info_fstatfs( info
, stfs
.f_fstypename
, stfs
.f_flags
);
3137 #elif defined(__NetBSD__)
3138 struct statvfs stfs
;
3140 if (fstatvfs( fd
, &stfs
) < 0)
3141 info
->DeviceType
= FILE_DEVICE_DISK_FILE_SYSTEM
;
3143 get_device_info_fstatfs( info
, stfs
.f_fstypename
, stfs
.f_flag
);
3145 /* Use dkio to work out device types */
3147 # include <sys/dkio.h>
3148 # include <sys/vtoc.h>
3149 struct dk_cinfo dkinf
;
3150 int retval
= ioctl(fd
, DKIOCINFO
, &dkinf
);
3152 WARN("Unable to get disk device type information - assuming a disk like device\n");
3153 info
->DeviceType
= FILE_DEVICE_DISK_FILE_SYSTEM
;
3155 switch (dkinf
.dki_ctype
)
3158 info
->DeviceType
= FILE_DEVICE_CD_ROM_FILE_SYSTEM
;
3159 info
->Characteristics
|= FILE_REMOVABLE_MEDIA
|FILE_READ_ONLY_DEVICE
;
3163 case DKC_INTEL82072
:
3164 case DKC_INTEL82077
:
3165 info
->DeviceType
= FILE_DEVICE_DISK_FILE_SYSTEM
;
3166 info
->Characteristics
|= FILE_REMOVABLE_MEDIA
;
3169 info
->DeviceType
= FILE_DEVICE_VIRTUAL_DISK
;
3172 info
->DeviceType
= FILE_DEVICE_DISK_FILE_SYSTEM
;
3177 if (!warned
++) FIXME( "device info not properly supported on this platform\n" );
3178 info
->DeviceType
= FILE_DEVICE_DISK_FILE_SYSTEM
;
3180 info
->Characteristics
|= FILE_DEVICE_IS_MOUNTED
;
3182 return STATUS_SUCCESS
;
3186 /******************************************************************************
3187 * NtQueryVolumeInformationFile [NTDLL.@]
3188 * ZwQueryVolumeInformationFile [NTDLL.@]
3190 * Get volume information for an open file handle.
3193 * handle [I] Handle returned from ZwOpenFile() or ZwCreateFile()
3194 * io [O] Receives information about the operation on return
3195 * buffer [O] Destination for volume information
3196 * length [I] Size of FsInformation
3197 * info_class [I] Type of volume information to set
3200 * Success: 0. io and buffer are updated.
3201 * Failure: An NTSTATUS error code describing the error.
3203 NTSTATUS WINAPI
NtQueryVolumeInformationFile( HANDLE handle
, PIO_STATUS_BLOCK io
,
3204 PVOID buffer
, ULONG length
,
3205 FS_INFORMATION_CLASS info_class
)
3207 int fd
, needs_close
;
3211 if ((io
->u
.Status
= server_get_unix_fd( handle
, 0, &fd
, &needs_close
, NULL
, NULL
)) != STATUS_SUCCESS
)
3212 return io
->u
.Status
;
3214 io
->u
.Status
= STATUS_NOT_IMPLEMENTED
;
3215 io
->Information
= 0;
3217 switch( info_class
)
3219 case FileFsVolumeInformation
:
3220 if (!once
++) FIXME( "%p: volume info not supported\n", handle
);
3222 case FileFsLabelInformation
:
3223 FIXME( "%p: label info not supported\n", handle
);
3225 case FileFsSizeInformation
:
3226 if (length
< sizeof(FILE_FS_SIZE_INFORMATION
))
3227 io
->u
.Status
= STATUS_BUFFER_TOO_SMALL
;
3230 FILE_FS_SIZE_INFORMATION
*info
= buffer
;
3232 if (fstat( fd
, &st
) < 0)
3234 io
->u
.Status
= FILE_GetNtStatus();
3237 if (!S_ISREG(st
.st_mode
) && !S_ISDIR(st
.st_mode
))
3239 io
->u
.Status
= STATUS_INVALID_DEVICE_REQUEST
;
3244 /* Linux's fstatvfs is buggy */
3245 #if !defined(linux) || !defined(HAVE_FSTATFS)
3246 struct statvfs stfs
;
3248 if (fstatvfs( fd
, &stfs
) < 0)
3250 io
->u
.Status
= FILE_GetNtStatus();
3253 bsize
= stfs
.f_frsize
;
3256 if (fstatfs( fd
, &stfs
) < 0)
3258 io
->u
.Status
= FILE_GetNtStatus();
3261 bsize
= stfs
.f_bsize
;
3263 if (bsize
== 2048) /* assume CD-ROM */
3265 info
->BytesPerSector
= 2048;
3266 info
->SectorsPerAllocationUnit
= 1;
3270 info
->BytesPerSector
= 512;
3271 info
->SectorsPerAllocationUnit
= 8;
3273 info
->TotalAllocationUnits
.QuadPart
= bsize
* stfs
.f_blocks
/ (info
->BytesPerSector
* info
->SectorsPerAllocationUnit
);
3274 info
->AvailableAllocationUnits
.QuadPart
= bsize
* stfs
.f_bavail
/ (info
->BytesPerSector
* info
->SectorsPerAllocationUnit
);
3275 io
->Information
= sizeof(*info
);
3276 io
->u
.Status
= STATUS_SUCCESS
;
3280 case FileFsDeviceInformation
:
3281 if (length
< sizeof(FILE_FS_DEVICE_INFORMATION
))
3282 io
->u
.Status
= STATUS_BUFFER_TOO_SMALL
;
3285 FILE_FS_DEVICE_INFORMATION
*info
= buffer
;
3287 if ((io
->u
.Status
= get_device_info( fd
, info
)) == STATUS_SUCCESS
)
3288 io
->Information
= sizeof(*info
);
3291 case FileFsAttributeInformation
:
3292 if (length
< offsetof( FILE_FS_ATTRIBUTE_INFORMATION
, FileSystemName
[sizeof(ntfsW
)/sizeof(WCHAR
)] ))
3293 io
->u
.Status
= STATUS_BUFFER_TOO_SMALL
;
3296 FILE_FS_ATTRIBUTE_INFORMATION
*info
= buffer
;
3298 FIXME( "%p: faking attribute info\n", handle
);
3299 info
->FileSystemAttribute
= FILE_SUPPORTS_ENCRYPTION
| FILE_FILE_COMPRESSION
|
3300 FILE_PERSISTENT_ACLS
| FILE_UNICODE_ON_DISK
|
3301 FILE_CASE_PRESERVED_NAMES
| FILE_CASE_SENSITIVE_SEARCH
;
3302 info
->MaximumComponentNameLength
= MAXIMUM_FILENAME_LENGTH
- 1;
3303 info
->FileSystemNameLength
= sizeof(ntfsW
);
3304 memcpy(info
->FileSystemName
, ntfsW
, sizeof(ntfsW
));
3306 io
->Information
= sizeof(*info
);
3307 io
->u
.Status
= STATUS_SUCCESS
;
3310 case FileFsControlInformation
:
3311 FIXME( "%p: control info not supported\n", handle
);
3313 case FileFsFullSizeInformation
:
3314 FIXME( "%p: full size info not supported\n", handle
);
3316 case FileFsObjectIdInformation
:
3317 FIXME( "%p: object id info not supported\n", handle
);
3319 case FileFsMaximumInformation
:
3320 FIXME( "%p: maximum info not supported\n", handle
);
3323 io
->u
.Status
= STATUS_INVALID_PARAMETER
;
3326 if (needs_close
) close( fd
);
3327 return io
->u
.Status
;
3331 /******************************************************************
3332 * NtQueryEaFile (NTDLL.@)
3334 * Read extended attributes from NTFS files.
3337 * hFile [I] File handle, must be opened with FILE_READ_EA access
3338 * iosb [O] Receives information about the operation on return
3339 * buffer [O] Output buffer
3340 * length [I] Length of output buffer
3341 * single_entry [I] Only read and return one entry
3342 * ea_list [I] Optional list with names of EAs to return
3343 * ea_list_len [I] Length of ea_list in bytes
3344 * ea_index [I] Optional pointer to 1-based index of attribute to return
3345 * restart [I] restart EA scan
3348 * Success: 0. Atrributes read into buffer
3349 * Failure: An NTSTATUS error code describing the error.
3351 NTSTATUS WINAPI
NtQueryEaFile( HANDLE hFile
, PIO_STATUS_BLOCK iosb
, PVOID buffer
, ULONG length
,
3352 BOOLEAN single_entry
, PVOID ea_list
, ULONG ea_list_len
,
3353 PULONG ea_index
, BOOLEAN restart
)
3355 FIXME("(%p,%p,%p,%d,%d,%p,%d,%p,%d) stub\n",
3356 hFile
, iosb
, buffer
, length
, single_entry
, ea_list
,
3357 ea_list_len
, ea_index
, restart
);
3358 return STATUS_ACCESS_DENIED
;
3362 /******************************************************************
3363 * NtSetEaFile (NTDLL.@)
3365 * Update extended attributes for NTFS files.
3368 * hFile [I] File handle, must be opened with FILE_READ_EA access
3369 * iosb [O] Receives information about the operation on return
3370 * buffer [I] Buffer with EA information
3371 * length [I] Length of buffer
3374 * Success: 0. Attributes are updated
3375 * Failure: An NTSTATUS error code describing the error.
3377 NTSTATUS WINAPI
NtSetEaFile( HANDLE hFile
, PIO_STATUS_BLOCK iosb
, PVOID buffer
, ULONG length
)
3379 FIXME("(%p,%p,%p,%d) stub\n", hFile
, iosb
, buffer
, length
);
3380 return STATUS_ACCESS_DENIED
;
3384 /******************************************************************
3385 * NtFlushBuffersFile (NTDLL.@)
3387 * Flush any buffered data on an open file handle.
3390 * FileHandle [I] Handle returned from ZwOpenFile() or ZwCreateFile()
3391 * IoStatusBlock [O] Receives information about the operation on return
3394 * Success: 0. IoStatusBlock is updated.
3395 * Failure: An NTSTATUS error code describing the error.
3397 NTSTATUS WINAPI
NtFlushBuffersFile( HANDLE hFile
, IO_STATUS_BLOCK
* IoStatusBlock
)
3400 HANDLE hEvent
= NULL
;
3401 enum server_fd_type type
;
3402 int fd
, needs_close
;
3404 ret
= server_get_unix_fd( hFile
, FILE_WRITE_DATA
, &fd
, &needs_close
, &type
, NULL
);
3405 if (ret
== STATUS_ACCESS_DENIED
)
3406 ret
= server_get_unix_fd( hFile
, FILE_APPEND_DATA
, &fd
, &needs_close
, &type
, NULL
);
3408 if (!ret
&& type
== FD_TYPE_SERIAL
)
3410 ret
= COMM_FlushBuffersFile( fd
);
3412 else if (ret
!= STATUS_ACCESS_DENIED
)
3414 SERVER_START_REQ( flush
)
3416 req
->async
= server_async( hFile
, NULL
, NULL
, NULL
, NULL
, IoStatusBlock
);
3417 ret
= wine_server_call( req
);
3418 hEvent
= wine_server_ptr_handle( reply
->event
);
3424 NtWaitForSingleObject( hEvent
, FALSE
, NULL
);
3426 ret
= STATUS_SUCCESS
;
3430 if (needs_close
) close( fd
);
3434 /******************************************************************
3435 * NtLockFile (NTDLL.@)
3439 NTSTATUS WINAPI
NtLockFile( HANDLE hFile
, HANDLE lock_granted_event
,
3440 PIO_APC_ROUTINE apc
, void* apc_user
,
3441 PIO_STATUS_BLOCK io_status
, PLARGE_INTEGER offset
,
3442 PLARGE_INTEGER count
, ULONG
* key
, BOOLEAN dont_wait
,
3448 static BOOLEAN warn
= TRUE
;
3450 if (apc
|| io_status
|| key
)
3452 FIXME("Unimplemented yet parameter\n");
3453 return STATUS_NOT_IMPLEMENTED
;
3456 if (apc_user
&& warn
)
3458 FIXME("I/O completion on lock not implemented yet\n");
3464 SERVER_START_REQ( lock_file
)
3466 req
->handle
= wine_server_obj_handle( hFile
);
3467 req
->offset
= offset
->QuadPart
;
3468 req
->count
= count
->QuadPart
;
3469 req
->shared
= !exclusive
;
3470 req
->wait
= !dont_wait
;
3471 ret
= wine_server_call( req
);
3472 handle
= wine_server_ptr_handle( reply
->handle
);
3473 async
= reply
->overlapped
;
3476 if (ret
!= STATUS_PENDING
)
3478 if (!ret
&& lock_granted_event
) NtSetEvent(lock_granted_event
, NULL
);
3484 FIXME( "Async I/O lock wait not implemented, might deadlock\n" );
3485 if (handle
) NtClose( handle
);
3486 return STATUS_PENDING
;
3490 NtWaitForSingleObject( handle
, FALSE
, NULL
);
3497 /* Unix lock conflict, sleep a bit and retry */
3498 time
.QuadPart
= 100 * (ULONGLONG
)10000;
3499 time
.QuadPart
= -time
.QuadPart
;
3500 NtDelayExecution( FALSE
, &time
);
3506 /******************************************************************
3507 * NtUnlockFile (NTDLL.@)
3511 NTSTATUS WINAPI
NtUnlockFile( HANDLE hFile
, PIO_STATUS_BLOCK io_status
,
3512 PLARGE_INTEGER offset
, PLARGE_INTEGER count
,
3517 TRACE( "%p %x%08x %x%08x\n",
3518 hFile
, offset
->u
.HighPart
, offset
->u
.LowPart
, count
->u
.HighPart
, count
->u
.LowPart
);
3520 if (io_status
|| key
)
3522 FIXME("Unimplemented yet parameter\n");
3523 return STATUS_NOT_IMPLEMENTED
;
3526 SERVER_START_REQ( unlock_file
)
3528 req
->handle
= wine_server_obj_handle( hFile
);
3529 req
->offset
= offset
->QuadPart
;
3530 req
->count
= count
->QuadPart
;
3531 status
= wine_server_call( req
);
3537 /******************************************************************
3538 * NtCreateNamedPipeFile (NTDLL.@)
3542 NTSTATUS WINAPI
NtCreateNamedPipeFile( PHANDLE handle
, ULONG access
,
3543 POBJECT_ATTRIBUTES attr
, PIO_STATUS_BLOCK iosb
,
3544 ULONG sharing
, ULONG dispo
, ULONG options
,
3545 ULONG pipe_type
, ULONG read_mode
,
3546 ULONG completion_mode
, ULONG max_inst
,
3547 ULONG inbound_quota
, ULONG outbound_quota
,
3548 PLARGE_INTEGER timeout
)
3552 struct object_attributes
*objattr
;
3554 TRACE("(%p %x %s %p %x %d %x %d %d %d %d %d %d %p)\n",
3555 handle
, access
, debugstr_w(attr
->ObjectName
->Buffer
), iosb
, sharing
, dispo
,
3556 options
, pipe_type
, read_mode
, completion_mode
, max_inst
, inbound_quota
,
3557 outbound_quota
, timeout
);
3559 if (!attr
) return STATUS_INVALID_PARAMETER
;
3561 /* assume we only get relative timeout */
3562 if (timeout
->QuadPart
> 0)
3563 FIXME("Wrong time %s\n", wine_dbgstr_longlong(timeout
->QuadPart
));
3565 if ((status
= alloc_object_attributes( attr
, &objattr
, &len
))) return status
;
3567 SERVER_START_REQ( create_named_pipe
)
3569 req
->access
= access
;
3570 req
->options
= options
;
3571 req
->sharing
= sharing
;
3573 (pipe_type
? NAMED_PIPE_MESSAGE_STREAM_WRITE
: 0) |
3574 (read_mode
? NAMED_PIPE_MESSAGE_STREAM_READ
: 0) |
3575 (completion_mode
? NAMED_PIPE_NONBLOCKING_MODE
: 0);
3576 req
->maxinstances
= max_inst
;
3577 req
->outsize
= outbound_quota
;
3578 req
->insize
= inbound_quota
;
3579 req
->timeout
= timeout
->QuadPart
;
3580 wine_server_add_data( req
, objattr
, len
);
3581 status
= wine_server_call( req
);
3582 if (!status
) *handle
= wine_server_ptr_handle( reply
->handle
);
3586 RtlFreeHeap( GetProcessHeap(), 0, objattr
);
3590 /******************************************************************
3591 * NtDeleteFile (NTDLL.@)
3595 NTSTATUS WINAPI
NtDeleteFile( POBJECT_ATTRIBUTES ObjectAttributes
)
3601 TRACE("%p\n", ObjectAttributes
);
3602 status
= NtCreateFile( &hFile
, GENERIC_READ
| GENERIC_WRITE
| DELETE
,
3603 ObjectAttributes
, &io
, NULL
, 0,
3604 FILE_SHARE_READ
| FILE_SHARE_WRITE
| FILE_SHARE_DELETE
,
3605 FILE_OPEN
, FILE_DELETE_ON_CLOSE
, NULL
, 0 );
3606 if (status
== STATUS_SUCCESS
) status
= NtClose(hFile
);
3610 /******************************************************************
3611 * NtCancelIoFileEx (NTDLL.@)
3615 NTSTATUS WINAPI
NtCancelIoFileEx( HANDLE hFile
, PIO_STATUS_BLOCK iosb
, PIO_STATUS_BLOCK io_status
)
3617 TRACE("%p %p %p\n", hFile
, iosb
, io_status
);
3619 SERVER_START_REQ( cancel_async
)
3621 req
->handle
= wine_server_obj_handle( hFile
);
3622 req
->iosb
= wine_server_client_ptr( iosb
);
3623 req
->only_thread
= FALSE
;
3624 io_status
->u
.Status
= wine_server_call( req
);
3628 return io_status
->u
.Status
;
3631 /******************************************************************
3632 * NtCancelIoFile (NTDLL.@)
3636 NTSTATUS WINAPI
NtCancelIoFile( HANDLE hFile
, PIO_STATUS_BLOCK io_status
)
3638 TRACE("%p %p\n", hFile
, io_status
);
3640 SERVER_START_REQ( cancel_async
)
3642 req
->handle
= wine_server_obj_handle( hFile
);
3644 req
->only_thread
= TRUE
;
3645 io_status
->u
.Status
= wine_server_call( req
);
3649 return io_status
->u
.Status
;
3652 /******************************************************************************
3653 * NtCreateMailslotFile [NTDLL.@]
3654 * ZwCreateMailslotFile [NTDLL.@]
3657 * pHandle [O] pointer to receive the handle created
3658 * DesiredAccess [I] access mode (read, write, etc)
3659 * ObjectAttributes [I] fully qualified NT path of the mailslot
3660 * IoStatusBlock [O] receives completion status and other info
3663 * MaxMessageSize [I]
3669 NTSTATUS WINAPI
NtCreateMailslotFile(PHANDLE pHandle
, ULONG DesiredAccess
,
3670 POBJECT_ATTRIBUTES attr
, PIO_STATUS_BLOCK IoStatusBlock
,
3671 ULONG CreateOptions
, ULONG MailslotQuota
, ULONG MaxMessageSize
,
3672 PLARGE_INTEGER TimeOut
)
3674 LARGE_INTEGER timeout
;
3677 struct object_attributes
*objattr
;
3679 TRACE("%p %08x %p %p %08x %08x %08x %p\n",
3680 pHandle
, DesiredAccess
, attr
, IoStatusBlock
,
3681 CreateOptions
, MailslotQuota
, MaxMessageSize
, TimeOut
);
3683 if (!pHandle
) return STATUS_ACCESS_VIOLATION
;
3684 if (!attr
) return STATUS_INVALID_PARAMETER
;
3686 if ((ret
= alloc_object_attributes( attr
, &objattr
, &len
))) return ret
;
3689 * For a NULL TimeOut pointer set the default timeout value
3692 timeout
.QuadPart
= -1;
3694 timeout
.QuadPart
= TimeOut
->QuadPart
;
3696 SERVER_START_REQ( create_mailslot
)
3698 req
->access
= DesiredAccess
;
3699 req
->max_msgsize
= MaxMessageSize
;
3700 req
->read_timeout
= timeout
.QuadPart
;
3701 wine_server_add_data( req
, objattr
, len
);
3702 ret
= wine_server_call( req
);
3703 if( ret
== STATUS_SUCCESS
)
3704 *pHandle
= wine_server_ptr_handle( reply
->handle
);
3708 RtlFreeHeap( GetProcessHeap(), 0, objattr
);