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>
66 #ifdef HAVE_SYS_MOUNT_H
67 # include <sys/mount.h>
69 #ifdef HAVE_SYS_STATFS_H
70 # include <sys/statfs.h>
75 #ifdef HAVE_VALGRIND_MEMCHECK_H
76 # include <valgrind/memcheck.h>
80 #define WIN32_NO_STATUS
81 #define NONAMELESSUNION
82 #include "wine/unicode.h"
83 #include "wine/debug.h"
84 #include "wine/server.h"
85 #include "ntdll_misc.h"
89 #include "ddk/ntddk.h"
90 #include "ddk/ntddser.h"
92 WINE_DEFAULT_DEBUG_CHANNEL(ntdll
);
93 WINE_DECLARE_DEBUG_CHANNEL(winediag
);
95 mode_t FILE_umask
= 0;
97 #define SECSPERDAY 86400
98 #define SECS_1601_TO_1970 ((369 * 365 + 89) * (ULONGLONG)SECSPERDAY)
100 #define FILE_WRITE_TO_END_OF_FILE ((LONGLONG)-1)
101 #define FILE_USE_FILE_POINTER_POSITION ((LONGLONG)-2)
103 static const WCHAR ntfsW
[] = {'N','T','F','S'};
105 /* fetch the attributes of a file */
106 static inline ULONG
get_file_attributes( const struct stat
*st
)
110 if (S_ISDIR(st
->st_mode
))
111 attr
= FILE_ATTRIBUTE_DIRECTORY
;
113 attr
= FILE_ATTRIBUTE_ARCHIVE
;
114 if (!(st
->st_mode
& (S_IWUSR
| S_IWGRP
| S_IWOTH
)))
115 attr
|= FILE_ATTRIBUTE_READONLY
;
119 /* get the stat info and file attributes for a file (by file descriptor) */
120 int fd_get_file_info( int fd
, struct stat
*st
, ULONG
*attr
)
125 ret
= fstat( fd
, st
);
126 if (ret
== -1) return ret
;
127 *attr
|= get_file_attributes( st
);
131 /* get the stat info and file attributes for a file (by name) */
132 int get_file_info( const char *path
, struct stat
*st
, ULONG
*attr
)
137 ret
= lstat( path
, st
);
138 if (ret
== -1) return ret
;
139 if (S_ISLNK( st
->st_mode
))
141 ret
= stat( path
, st
);
142 if (ret
== -1) return ret
;
143 /* is a symbolic link and a directory, consider these "reparse points" */
144 if (S_ISDIR( st
->st_mode
)) *attr
|= FILE_ATTRIBUTE_REPARSE_POINT
;
146 *attr
|= get_file_attributes( st
);
150 /**************************************************************************
151 * FILE_CreateFile (internal)
154 * Parameter set fully identical with NtCreateFile
156 static NTSTATUS
FILE_CreateFile( PHANDLE handle
, ACCESS_MASK access
, POBJECT_ATTRIBUTES attr
,
157 PIO_STATUS_BLOCK io
, PLARGE_INTEGER alloc_size
,
158 ULONG attributes
, ULONG sharing
, ULONG disposition
,
159 ULONG options
, PVOID ea_buffer
, ULONG ea_length
)
161 ANSI_STRING unix_name
;
162 BOOL created
= FALSE
;
164 TRACE("handle=%p access=%08x name=%s objattr=%08x root=%p sec=%p io=%p alloc_size=%p "
165 "attr=%08x sharing=%08x disp=%d options=%08x ea=%p.0x%08x\n",
166 handle
, access
, debugstr_us(attr
->ObjectName
), attr
->Attributes
,
167 attr
->RootDirectory
, attr
->SecurityDescriptor
, io
, alloc_size
,
168 attributes
, sharing
, disposition
, options
, ea_buffer
, ea_length
);
170 if (!attr
|| !attr
->ObjectName
) return STATUS_INVALID_PARAMETER
;
172 if (alloc_size
) FIXME( "alloc_size not supported\n" );
174 if (options
& FILE_OPEN_BY_FILE_ID
)
175 io
->u
.Status
= file_id_to_unix_file_name( attr
, &unix_name
);
177 io
->u
.Status
= nt_to_unix_file_name_attr( attr
, &unix_name
, disposition
);
179 if (io
->u
.Status
== STATUS_BAD_DEVICE_TYPE
)
181 SERVER_START_REQ( open_file_object
)
183 req
->access
= access
;
184 req
->attributes
= attr
->Attributes
;
185 req
->rootdir
= wine_server_obj_handle( attr
->RootDirectory
);
186 req
->sharing
= sharing
;
187 req
->options
= options
;
188 wine_server_add_data( req
, attr
->ObjectName
->Buffer
, attr
->ObjectName
->Length
);
189 io
->u
.Status
= wine_server_call( req
);
190 *handle
= wine_server_ptr_handle( reply
->handle
);
193 if (io
->u
.Status
== STATUS_SUCCESS
) io
->Information
= FILE_OPENED
;
197 if (io
->u
.Status
== STATUS_NO_SUCH_FILE
&&
198 disposition
!= FILE_OPEN
&& disposition
!= FILE_OVERWRITE
)
201 io
->u
.Status
= STATUS_SUCCESS
;
204 if (io
->u
.Status
== STATUS_SUCCESS
)
206 struct security_descriptor
*sd
;
207 struct object_attributes objattr
;
209 objattr
.rootdir
= wine_server_obj_handle( attr
->RootDirectory
);
210 objattr
.name_len
= 0;
211 io
->u
.Status
= NTDLL_create_struct_sd( attr
->SecurityDescriptor
, &sd
, &objattr
.sd_len
);
212 if (io
->u
.Status
!= STATUS_SUCCESS
)
214 RtlFreeAnsiString( &unix_name
);
218 SERVER_START_REQ( create_file
)
220 req
->access
= access
;
221 req
->attributes
= attr
->Attributes
;
222 req
->sharing
= sharing
;
223 req
->create
= disposition
;
224 req
->options
= options
;
225 req
->attrs
= attributes
;
226 wine_server_add_data( req
, &objattr
, sizeof(objattr
) );
227 if (objattr
.sd_len
) wine_server_add_data( req
, sd
, objattr
.sd_len
);
228 wine_server_add_data( req
, unix_name
.Buffer
, unix_name
.Length
);
229 io
->u
.Status
= wine_server_call( req
);
230 *handle
= wine_server_ptr_handle( reply
->handle
);
233 NTDLL_free_struct_sd( sd
);
234 RtlFreeAnsiString( &unix_name
);
236 else WARN("%s not found (%x)\n", debugstr_us(attr
->ObjectName
), io
->u
.Status
);
238 if (io
->u
.Status
== STATUS_SUCCESS
)
240 if (created
) io
->Information
= FILE_CREATED
;
241 else switch(disposition
)
244 io
->Information
= FILE_SUPERSEDED
;
247 io
->Information
= FILE_CREATED
;
251 io
->Information
= FILE_OPENED
;
254 case FILE_OVERWRITE_IF
:
255 io
->Information
= FILE_OVERWRITTEN
;
259 else if (io
->u
.Status
== STATUS_TOO_MANY_OPENED_FILES
)
262 if (!once
++) ERR_(winediag
)( "Too many open files, ulimit -n probably needs to be increased\n" );
268 /**************************************************************************
269 * NtOpenFile [NTDLL.@]
270 * ZwOpenFile [NTDLL.@]
275 * handle [O] Variable that receives the file handle on return
276 * access [I] Access desired by the caller to the file
277 * attr [I] Structure describing the file to be opened
278 * io [O] Receives details about the result of the operation
279 * sharing [I] Type of shared access the caller requires
280 * options [I] Options for the file open
283 * Success: 0. FileHandle and IoStatusBlock are updated.
284 * Failure: An NTSTATUS error code describing the error.
286 NTSTATUS WINAPI
NtOpenFile( PHANDLE handle
, ACCESS_MASK access
,
287 POBJECT_ATTRIBUTES attr
, PIO_STATUS_BLOCK io
,
288 ULONG sharing
, ULONG options
)
290 return FILE_CreateFile( handle
, access
, attr
, io
, NULL
, 0,
291 sharing
, FILE_OPEN
, options
, NULL
, 0 );
294 /**************************************************************************
295 * NtCreateFile [NTDLL.@]
296 * ZwCreateFile [NTDLL.@]
298 * Either create a new file or directory, or open an existing file, device,
299 * directory or volume.
302 * handle [O] Points to a variable which receives the file handle on return
303 * access [I] Desired access to the file
304 * attr [I] Structure describing the file
305 * io [O] Receives information about the operation on return
306 * alloc_size [I] Initial size of the file in bytes
307 * attributes [I] Attributes to create the file with
308 * sharing [I] Type of shared access the caller would like to the file
309 * disposition [I] Specifies what to do, depending on whether the file already exists
310 * options [I] Options for creating a new file
311 * ea_buffer [I] Pointer to an extended attributes buffer
312 * ea_length [I] Length of ea_buffer
315 * Success: 0. handle and io are updated.
316 * Failure: An NTSTATUS error code describing the error.
318 NTSTATUS WINAPI
NtCreateFile( PHANDLE handle
, ACCESS_MASK access
, POBJECT_ATTRIBUTES attr
,
319 PIO_STATUS_BLOCK io
, PLARGE_INTEGER alloc_size
,
320 ULONG attributes
, ULONG sharing
, ULONG disposition
,
321 ULONG options
, PVOID ea_buffer
, ULONG ea_length
)
323 return FILE_CreateFile( handle
, access
, attr
, io
, alloc_size
, attributes
,
324 sharing
, disposition
, options
, ea_buffer
, ea_length
);
327 /***********************************************************************
328 * Asynchronous file I/O *
333 struct async_fileio
*next
;
339 struct async_fileio_read
341 struct async_fileio io
;
343 unsigned int already
;
348 struct async_fileio_write
350 struct async_fileio io
;
352 unsigned int already
;
356 static struct async_fileio
*fileio_freelist
;
358 static void release_fileio( struct async_fileio
*io
)
362 struct async_fileio
*next
= fileio_freelist
;
364 if (interlocked_cmpxchg_ptr( (void **)&fileio_freelist
, io
, next
) == next
) return;
368 static struct async_fileio
*alloc_fileio( DWORD size
, HANDLE handle
, PIO_APC_ROUTINE apc
, void *arg
)
370 /* first free remaining previous fileinfos */
372 struct async_fileio
*io
= interlocked_xchg_ptr( (void **)&fileio_freelist
, NULL
);
376 struct async_fileio
*next
= io
->next
;
377 RtlFreeHeap( GetProcessHeap(), 0, io
);
381 if ((io
= RtlAllocateHeap( GetProcessHeap(), 0, size
)))
390 /***********************************************************************
391 * FILE_GetNtStatus(void)
393 * Retrieve the Nt Status code from errno.
394 * Try to be consistent with FILE_SetDosError().
396 NTSTATUS
FILE_GetNtStatus(void)
400 TRACE( "errno = %d\n", errno
);
403 case EAGAIN
: return STATUS_SHARING_VIOLATION
;
404 case EBADF
: return STATUS_INVALID_HANDLE
;
405 case EBUSY
: return STATUS_DEVICE_BUSY
;
406 case ENOSPC
: return STATUS_DISK_FULL
;
409 case EACCES
: return STATUS_ACCESS_DENIED
;
410 case ENOTDIR
: return STATUS_OBJECT_PATH_NOT_FOUND
;
411 case ENOENT
: return STATUS_OBJECT_NAME_NOT_FOUND
;
412 case EISDIR
: return STATUS_FILE_IS_A_DIRECTORY
;
414 case ENFILE
: return STATUS_TOO_MANY_OPENED_FILES
;
415 case EINVAL
: return STATUS_INVALID_PARAMETER
;
416 case ENOTEMPTY
: return STATUS_DIRECTORY_NOT_EMPTY
;
417 case EPIPE
: return STATUS_PIPE_DISCONNECTED
;
418 case EIO
: return STATUS_DEVICE_NOT_READY
;
420 case ENOMEDIUM
: return STATUS_NO_MEDIA_IN_DEVICE
;
422 case ENXIO
: return STATUS_NO_SUCH_DEVICE
;
424 case EOPNOTSUPP
:return STATUS_NOT_SUPPORTED
;
425 case ECONNRESET
:return STATUS_PIPE_DISCONNECTED
;
426 case EFAULT
: return STATUS_ACCESS_VIOLATION
;
427 case ESPIPE
: return STATUS_ILLEGAL_FUNCTION
;
428 #ifdef ETIME /* Missing on FreeBSD */
429 case ETIME
: return STATUS_IO_TIMEOUT
;
431 case ENOEXEC
: /* ?? */
432 case EEXIST
: /* ?? */
434 FIXME( "Converting errno %d to STATUS_UNSUCCESSFUL\n", err
);
435 return STATUS_UNSUCCESSFUL
;
439 /***********************************************************************
440 * FILE_AsyncReadService (INTERNAL)
442 static NTSTATUS
FILE_AsyncReadService( void *user
, IO_STATUS_BLOCK
*iosb
,
443 NTSTATUS status
, void **apc
, void **arg
)
445 struct async_fileio_read
*fileio
= user
;
446 int fd
, needs_close
, result
;
450 case STATUS_ALERTED
: /* got some new data */
451 /* check to see if the data is ready (non-blocking) */
452 if ((status
= server_get_unix_fd( fileio
->io
.handle
, FILE_READ_DATA
, &fd
,
453 &needs_close
, NULL
, NULL
)))
456 result
= read(fd
, &fileio
->buffer
[fileio
->already
], fileio
->count
- fileio
->already
);
457 if (needs_close
) close( fd
);
461 if (errno
== EAGAIN
|| errno
== EINTR
)
462 status
= STATUS_PENDING
;
463 else /* check to see if the transfer is complete */
464 status
= FILE_GetNtStatus();
466 else if (result
== 0)
468 status
= fileio
->already
? STATUS_SUCCESS
: STATUS_PIPE_BROKEN
;
472 fileio
->already
+= result
;
473 if (fileio
->already
>= fileio
->count
|| fileio
->avail_mode
)
474 status
= STATUS_SUCCESS
;
477 /* if we only have to read the available data, and none is available,
478 * simply cancel the request. If data was available, it has been read
479 * while in by previous call (NtDelayExecution)
481 status
= (fileio
->avail_mode
) ? STATUS_SUCCESS
: STATUS_PENDING
;
487 case STATUS_IO_TIMEOUT
:
488 if (fileio
->already
) status
= STATUS_SUCCESS
;
491 if (status
!= STATUS_PENDING
)
493 iosb
->u
.Status
= status
;
494 iosb
->Information
= fileio
->already
;
495 *apc
= fileio
->io
.apc
;
496 *arg
= fileio
->io
.apc_arg
;
497 release_fileio( &fileio
->io
);
504 int interval
; /* max interval between two bytes */
505 int total
; /* total timeout for the whole operation */
506 int end_time
; /* absolute time of end of operation */
509 /* retrieve the I/O timeouts to use for a given handle */
510 static NTSTATUS
get_io_timeouts( HANDLE handle
, enum server_fd_type type
, ULONG count
, BOOL is_read
,
511 struct io_timeouts
*timeouts
)
513 NTSTATUS status
= STATUS_SUCCESS
;
515 timeouts
->interval
= timeouts
->total
= -1;
521 /* GetCommTimeouts */
525 status
= NtDeviceIoControlFile( handle
, NULL
, NULL
, NULL
, &io
,
526 IOCTL_SERIAL_GET_TIMEOUTS
, NULL
, 0, &st
, sizeof(st
) );
531 if (st
.ReadIntervalTimeout
)
532 timeouts
->interval
= st
.ReadIntervalTimeout
;
534 if (st
.ReadTotalTimeoutMultiplier
|| st
.ReadTotalTimeoutConstant
)
536 timeouts
->total
= st
.ReadTotalTimeoutConstant
;
537 if (st
.ReadTotalTimeoutMultiplier
!= MAXDWORD
)
538 timeouts
->total
+= count
* st
.ReadTotalTimeoutMultiplier
;
540 else if (st
.ReadIntervalTimeout
== MAXDWORD
)
541 timeouts
->interval
= timeouts
->total
= 0;
545 if (st
.WriteTotalTimeoutMultiplier
|| st
.WriteTotalTimeoutConstant
)
547 timeouts
->total
= st
.WriteTotalTimeoutConstant
;
548 if (st
.WriteTotalTimeoutMultiplier
!= MAXDWORD
)
549 timeouts
->total
+= count
* st
.WriteTotalTimeoutMultiplier
;
554 case FD_TYPE_MAILSLOT
:
557 timeouts
->interval
= 0; /* return as soon as we got something */
558 SERVER_START_REQ( set_mailslot_info
)
560 req
->handle
= wine_server_obj_handle( handle
);
562 if (!(status
= wine_server_call( req
)) &&
563 reply
->read_timeout
!= TIMEOUT_INFINITE
)
564 timeouts
->total
= reply
->read_timeout
/ -10000;
572 if (is_read
) timeouts
->interval
= 0; /* return as soon as we got something */
577 if (timeouts
->total
!= -1) timeouts
->end_time
= NtGetTickCount() + timeouts
->total
;
578 return STATUS_SUCCESS
;
582 /* retrieve the timeout for the next wait, in milliseconds */
583 static inline int get_next_io_timeout( const struct io_timeouts
*timeouts
, ULONG already
)
587 if (timeouts
->total
!= -1)
589 ret
= timeouts
->end_time
- NtGetTickCount();
590 if (ret
< 0) ret
= 0;
592 if (already
&& timeouts
->interval
!= -1)
594 if (ret
== -1 || ret
> timeouts
->interval
) ret
= timeouts
->interval
;
600 /* retrieve the avail_mode flag for async reads */
601 static NTSTATUS
get_io_avail_mode( HANDLE handle
, enum server_fd_type type
, BOOL
*avail_mode
)
603 NTSTATUS status
= STATUS_SUCCESS
;
609 /* GetCommTimeouts */
613 status
= NtDeviceIoControlFile( handle
, NULL
, NULL
, NULL
, &io
,
614 IOCTL_SERIAL_GET_TIMEOUTS
, NULL
, 0, &st
, sizeof(st
) );
616 *avail_mode
= (!st
.ReadTotalTimeoutMultiplier
&&
617 !st
.ReadTotalTimeoutConstant
&&
618 st
.ReadIntervalTimeout
== MAXDWORD
);
621 case FD_TYPE_MAILSLOT
:
635 /******************************************************************************
636 * NtReadFile [NTDLL.@]
637 * ZwReadFile [NTDLL.@]
639 * Read from an open file handle.
642 * FileHandle [I] Handle returned from ZwOpenFile() or ZwCreateFile()
643 * Event [I] Event to signal upon completion (or NULL)
644 * ApcRoutine [I] Callback to call upon completion (or NULL)
645 * ApcContext [I] Context for ApcRoutine (or NULL)
646 * IoStatusBlock [O] Receives information about the operation on return
647 * Buffer [O] Destination for the data read
648 * Length [I] Size of Buffer
649 * ByteOffset [O] Destination for the new file pointer position (or NULL)
650 * Key [O] Function unknown (may be NULL)
653 * Success: 0. IoStatusBlock is updated, and the Information member contains
654 * The number of bytes read.
655 * Failure: An NTSTATUS error code describing the error.
657 NTSTATUS WINAPI
NtReadFile(HANDLE hFile
, HANDLE hEvent
,
658 PIO_APC_ROUTINE apc
, void* apc_user
,
659 PIO_STATUS_BLOCK io_status
, void* buffer
, ULONG length
,
660 PLARGE_INTEGER offset
, PULONG key
)
662 int result
, unix_handle
, needs_close
;
663 unsigned int options
;
664 struct io_timeouts timeouts
;
667 enum server_fd_type type
;
668 ULONG_PTR cvalue
= apc
? 0 : (ULONG_PTR
)apc_user
;
669 BOOL send_completion
= FALSE
, async_read
, timeout_init_done
= FALSE
;
671 TRACE("(%p,%p,%p,%p,%p,%p,0x%08x,%p,%p),partial stub!\n",
672 hFile
,hEvent
,apc
,apc_user
,io_status
,buffer
,length
,offset
,key
);
674 if (!io_status
) return STATUS_ACCESS_VIOLATION
;
676 status
= server_get_unix_fd( hFile
, FILE_READ_DATA
, &unix_handle
,
677 &needs_close
, &type
, &options
);
678 if (status
) return status
;
680 async_read
= !(options
& (FILE_SYNCHRONOUS_IO_ALERT
| FILE_SYNCHRONOUS_IO_NONALERT
));
682 if (!virtual_check_buffer_for_write( buffer
, length
))
684 status
= STATUS_ACCESS_VIOLATION
;
688 if (type
== FD_TYPE_FILE
)
690 if (async_read
&& (!offset
|| offset
->QuadPart
< 0))
692 status
= STATUS_INVALID_PARAMETER
;
696 if (offset
&& offset
->QuadPart
!= FILE_USE_FILE_POINTER_POSITION
)
698 /* async I/O doesn't make sense on regular files */
699 while ((result
= pread( unix_handle
, buffer
, length
, offset
->QuadPart
)) == -1)
703 status
= FILE_GetNtStatus();
708 /* update file pointer position */
709 lseek( unix_handle
, offset
->QuadPart
+ result
, SEEK_SET
);
712 status
= (total
|| !length
) ? STATUS_SUCCESS
: STATUS_END_OF_FILE
;
716 else if (type
== FD_TYPE_SERIAL
)
718 if (async_read
&& (!offset
|| offset
->QuadPart
< 0))
720 status
= STATUS_INVALID_PARAMETER
;
727 if ((result
= read( unix_handle
, (char *)buffer
+ total
, length
- total
)) >= 0)
730 if (!result
|| total
== length
)
734 status
= STATUS_SUCCESS
;
741 status
= length
? STATUS_END_OF_FILE
: STATUS_SUCCESS
;
746 status
= STATUS_PIPE_BROKEN
;
750 else if (type
== FD_TYPE_FILE
) continue; /* no async I/O on regular files */
752 else if (errno
!= EAGAIN
)
754 if (errno
== EINTR
) continue;
755 if (!total
) status
= FILE_GetNtStatus();
761 struct async_fileio_read
*fileio
;
764 if ((status
= get_io_avail_mode( hFile
, type
, &avail_mode
)))
766 if (total
&& avail_mode
)
768 status
= STATUS_SUCCESS
;
772 fileio
= (struct async_fileio_read
*)alloc_fileio( sizeof(*fileio
), hFile
, apc
, apc_user
);
775 status
= STATUS_NO_MEMORY
;
778 fileio
->already
= total
;
779 fileio
->count
= length
;
780 fileio
->buffer
= buffer
;
781 fileio
->avail_mode
= avail_mode
;
783 SERVER_START_REQ( register_async
)
785 req
->type
= ASYNC_TYPE_READ
;
787 req
->async
.handle
= wine_server_obj_handle( hFile
);
788 req
->async
.event
= wine_server_obj_handle( hEvent
);
789 req
->async
.callback
= wine_server_client_ptr( FILE_AsyncReadService
);
790 req
->async
.iosb
= wine_server_client_ptr( io_status
);
791 req
->async
.arg
= wine_server_client_ptr( fileio
);
792 req
->async
.cvalue
= cvalue
;
793 status
= wine_server_call( req
);
797 if (status
!= STATUS_PENDING
) RtlFreeHeap( GetProcessHeap(), 0, fileio
);
800 else /* synchronous read, wait for the fd to become ready */
805 if (!timeout_init_done
)
807 timeout_init_done
= TRUE
;
808 if ((status
= get_io_timeouts( hFile
, type
, length
, TRUE
, &timeouts
)))
810 if (hEvent
) NtResetEvent( hEvent
, NULL
);
812 timeout
= get_next_io_timeout( &timeouts
, total
);
814 pfd
.fd
= unix_handle
;
817 if (!timeout
|| !(ret
= poll( &pfd
, 1, timeout
)))
819 if (total
) /* return with what we got so far */
820 status
= STATUS_SUCCESS
;
822 status
= (type
== FD_TYPE_MAILSLOT
) ? STATUS_IO_TIMEOUT
: STATUS_TIMEOUT
;
825 if (ret
== -1 && errno
!= EINTR
)
827 status
= FILE_GetNtStatus();
830 /* will now restart the read */
835 send_completion
= cvalue
!= 0;
838 if (needs_close
) close( unix_handle
);
839 if (status
== STATUS_SUCCESS
|| (status
== STATUS_END_OF_FILE
&& !async_read
))
841 io_status
->u
.Status
= status
;
842 io_status
->Information
= total
;
843 TRACE("= SUCCESS (%u)\n", total
);
844 if (hEvent
) NtSetEvent( hEvent
, NULL
);
845 if (apc
&& !status
) NtQueueApcThread( GetCurrentThread(), (PNTAPCFUNC
)apc
,
846 (ULONG_PTR
)apc_user
, (ULONG_PTR
)io_status
, 0 );
850 TRACE("= 0x%08x\n", status
);
851 if (status
!= STATUS_PENDING
&& hEvent
) NtResetEvent( hEvent
, NULL
);
854 if (send_completion
) NTDLL_AddCompletion( hFile
, cvalue
, status
, total
);
860 /******************************************************************************
861 * NtReadFileScatter [NTDLL.@]
862 * ZwReadFileScatter [NTDLL.@]
864 NTSTATUS WINAPI
NtReadFileScatter( HANDLE file
, HANDLE event
, PIO_APC_ROUTINE apc
, void *apc_user
,
865 PIO_STATUS_BLOCK io_status
, FILE_SEGMENT_ELEMENT
*segments
,
866 ULONG length
, PLARGE_INTEGER offset
, PULONG key
)
868 int result
, unix_handle
, needs_close
;
869 unsigned int options
;
871 ULONG pos
= 0, total
= 0;
872 enum server_fd_type type
;
873 ULONG_PTR cvalue
= apc
? 0 : (ULONG_PTR
)apc_user
;
874 BOOL send_completion
= FALSE
;
876 TRACE( "(%p,%p,%p,%p,%p,%p,0x%08x,%p,%p),partial stub!\n",
877 file
, event
, apc
, apc_user
, io_status
, segments
, length
, offset
, key
);
879 if (length
% page_size
) return STATUS_INVALID_PARAMETER
;
880 if (!io_status
) return STATUS_ACCESS_VIOLATION
;
882 status
= server_get_unix_fd( file
, FILE_READ_DATA
, &unix_handle
,
883 &needs_close
, &type
, &options
);
884 if (status
) return status
;
886 if ((type
!= FD_TYPE_FILE
) ||
887 (options
& (FILE_SYNCHRONOUS_IO_ALERT
| FILE_SYNCHRONOUS_IO_NONALERT
)) ||
888 !(options
& FILE_NO_INTERMEDIATE_BUFFERING
))
890 status
= STATUS_INVALID_PARAMETER
;
896 if (offset
&& offset
->QuadPart
!= FILE_USE_FILE_POINTER_POSITION
)
897 result
= pread( unix_handle
, (char *)segments
->Buffer
+ pos
,
898 page_size
- pos
, offset
->QuadPart
+ total
);
900 result
= read( unix_handle
, (char *)segments
->Buffer
+ pos
, page_size
- pos
);
904 if (errno
== EINTR
) continue;
905 status
= FILE_GetNtStatus();
910 status
= STATUS_END_OF_FILE
;
915 if ((pos
+= result
) == page_size
)
922 send_completion
= cvalue
!= 0;
925 if (needs_close
) close( unix_handle
);
926 if (status
== STATUS_SUCCESS
)
928 io_status
->u
.Status
= status
;
929 io_status
->Information
= total
;
930 TRACE("= SUCCESS (%u)\n", total
);
931 if (event
) NtSetEvent( event
, NULL
);
932 if (apc
) NtQueueApcThread( GetCurrentThread(), (PNTAPCFUNC
)apc
,
933 (ULONG_PTR
)apc_user
, (ULONG_PTR
)io_status
, 0 );
937 TRACE("= 0x%08x\n", status
);
938 if (status
!= STATUS_PENDING
&& event
) NtResetEvent( event
, NULL
);
941 if (send_completion
) NTDLL_AddCompletion( file
, cvalue
, status
, total
);
947 /***********************************************************************
948 * FILE_AsyncWriteService (INTERNAL)
950 static NTSTATUS
FILE_AsyncWriteService( void *user
, IO_STATUS_BLOCK
*iosb
,
951 NTSTATUS status
, void **apc
, void **arg
)
953 struct async_fileio_write
*fileio
= user
;
954 int result
, fd
, needs_close
;
955 enum server_fd_type type
;
960 /* write some data (non-blocking) */
961 if ((status
= server_get_unix_fd( fileio
->io
.handle
, FILE_WRITE_DATA
, &fd
,
962 &needs_close
, &type
, NULL
)))
965 if (!fileio
->count
&& (type
== FD_TYPE_MAILSLOT
|| type
== FD_TYPE_PIPE
|| type
== FD_TYPE_SOCKET
))
966 result
= send( fd
, fileio
->buffer
, 0, 0 );
968 result
= write( fd
, &fileio
->buffer
[fileio
->already
], fileio
->count
- fileio
->already
);
970 if (needs_close
) close( fd
);
974 if (errno
== EAGAIN
|| errno
== EINTR
) status
= STATUS_PENDING
;
975 else status
= FILE_GetNtStatus();
979 fileio
->already
+= result
;
980 status
= (fileio
->already
< fileio
->count
) ? STATUS_PENDING
: STATUS_SUCCESS
;
985 case STATUS_IO_TIMEOUT
:
986 if (fileio
->already
) status
= STATUS_SUCCESS
;
989 if (status
!= STATUS_PENDING
)
991 iosb
->u
.Status
= status
;
992 iosb
->Information
= fileio
->already
;
993 *apc
= fileio
->io
.apc
;
994 *arg
= fileio
->io
.apc_arg
;
995 release_fileio( &fileio
->io
);
1000 static NTSTATUS
set_pending_write( HANDLE device
)
1004 SERVER_START_REQ( set_serial_info
)
1006 req
->handle
= wine_server_obj_handle( device
);
1007 req
->flags
= SERIALINFO_PENDING_WRITE
;
1008 status
= wine_server_call( req
);
1014 /******************************************************************************
1015 * NtWriteFile [NTDLL.@]
1016 * ZwWriteFile [NTDLL.@]
1018 * Write to an open file handle.
1021 * FileHandle [I] Handle returned from ZwOpenFile() or ZwCreateFile()
1022 * Event [I] Event to signal upon completion (or NULL)
1023 * ApcRoutine [I] Callback to call upon completion (or NULL)
1024 * ApcContext [I] Context for ApcRoutine (or NULL)
1025 * IoStatusBlock [O] Receives information about the operation on return
1026 * Buffer [I] Source for the data to write
1027 * Length [I] Size of Buffer
1028 * ByteOffset [O] Destination for the new file pointer position (or NULL)
1029 * Key [O] Function unknown (may be NULL)
1032 * Success: 0. IoStatusBlock is updated, and the Information member contains
1033 * The number of bytes written.
1034 * Failure: An NTSTATUS error code describing the error.
1036 NTSTATUS WINAPI
NtWriteFile(HANDLE hFile
, HANDLE hEvent
,
1037 PIO_APC_ROUTINE apc
, void* apc_user
,
1038 PIO_STATUS_BLOCK io_status
,
1039 const void* buffer
, ULONG length
,
1040 PLARGE_INTEGER offset
, PULONG key
)
1042 int result
, unix_handle
, needs_close
;
1043 unsigned int options
;
1044 struct io_timeouts timeouts
;
1047 enum server_fd_type type
;
1048 ULONG_PTR cvalue
= apc
? 0 : (ULONG_PTR
)apc_user
;
1049 BOOL send_completion
= FALSE
, async_write
, append_write
= FALSE
, timeout_init_done
= FALSE
;
1050 LARGE_INTEGER offset_eof
;
1052 TRACE("(%p,%p,%p,%p,%p,%p,0x%08x,%p,%p)!\n",
1053 hFile
,hEvent
,apc
,apc_user
,io_status
,buffer
,length
,offset
,key
);
1055 if (!io_status
) return STATUS_ACCESS_VIOLATION
;
1057 status
= server_get_unix_fd( hFile
, FILE_WRITE_DATA
, &unix_handle
,
1058 &needs_close
, &type
, &options
);
1059 if (status
== STATUS_ACCESS_DENIED
)
1061 status
= server_get_unix_fd( hFile
, FILE_APPEND_DATA
, &unix_handle
,
1062 &needs_close
, &type
, &options
);
1063 append_write
= TRUE
;
1065 if (status
) return status
;
1067 if (!virtual_check_buffer_for_read( buffer
, length
))
1069 status
= STATUS_INVALID_USER_BUFFER
;
1073 async_write
= !(options
& (FILE_SYNCHRONOUS_IO_ALERT
| FILE_SYNCHRONOUS_IO_NONALERT
));
1075 if (type
== FD_TYPE_FILE
)
1078 (!offset
|| (offset
->QuadPart
< 0 && offset
->QuadPart
!= FILE_WRITE_TO_END_OF_FILE
)))
1080 status
= STATUS_INVALID_PARAMETER
;
1086 offset_eof
.QuadPart
= FILE_WRITE_TO_END_OF_FILE
;
1087 offset
= &offset_eof
;
1090 if (offset
&& offset
->QuadPart
!= FILE_USE_FILE_POINTER_POSITION
)
1092 off_t off
= offset
->QuadPart
;
1094 if (offset
->QuadPart
== FILE_WRITE_TO_END_OF_FILE
)
1098 if (fstat( unix_handle
, &st
) == -1)
1100 status
= FILE_GetNtStatus();
1105 else if (offset
->QuadPart
< 0)
1107 status
= STATUS_INVALID_PARAMETER
;
1111 /* async I/O doesn't make sense on regular files */
1112 while ((result
= pwrite( unix_handle
, buffer
, length
, off
)) == -1)
1116 if (errno
== EFAULT
) status
= STATUS_INVALID_USER_BUFFER
;
1117 else status
= FILE_GetNtStatus();
1123 /* update file pointer position */
1124 lseek( unix_handle
, off
+ result
, SEEK_SET
);
1127 status
= STATUS_SUCCESS
;
1131 else if (type
== FD_TYPE_SERIAL
)
1134 (!offset
|| (offset
->QuadPart
< 0 && offset
->QuadPart
!= FILE_WRITE_TO_END_OF_FILE
)))
1136 status
= STATUS_INVALID_PARAMETER
;
1143 /* zero-length writes on sockets may not work with plain write(2) */
1144 if (!length
&& (type
== FD_TYPE_MAILSLOT
|| type
== FD_TYPE_PIPE
|| type
== FD_TYPE_SOCKET
))
1145 result
= send( unix_handle
, buffer
, 0, 0 );
1147 result
= write( unix_handle
, (const char *)buffer
+ total
, length
- total
);
1152 if (total
== length
)
1154 status
= STATUS_SUCCESS
;
1157 if (type
== FD_TYPE_FILE
) continue; /* no async I/O on regular files */
1159 else if (errno
!= EAGAIN
)
1161 if (errno
== EINTR
) continue;
1164 if (errno
== EFAULT
) status
= STATUS_INVALID_USER_BUFFER
;
1165 else status
= FILE_GetNtStatus();
1172 struct async_fileio_write
*fileio
;
1174 fileio
= (struct async_fileio_write
*)alloc_fileio( sizeof(*fileio
), hFile
, apc
, apc_user
);
1177 status
= STATUS_NO_MEMORY
;
1180 fileio
->already
= total
;
1181 fileio
->count
= length
;
1182 fileio
->buffer
= buffer
;
1184 SERVER_START_REQ( register_async
)
1186 req
->type
= ASYNC_TYPE_WRITE
;
1187 req
->count
= length
;
1188 req
->async
.handle
= wine_server_obj_handle( hFile
);
1189 req
->async
.event
= wine_server_obj_handle( hEvent
);
1190 req
->async
.callback
= wine_server_client_ptr( FILE_AsyncWriteService
);
1191 req
->async
.iosb
= wine_server_client_ptr( io_status
);
1192 req
->async
.arg
= wine_server_client_ptr( fileio
);
1193 req
->async
.cvalue
= cvalue
;
1194 status
= wine_server_call( req
);
1198 if (status
!= STATUS_PENDING
) RtlFreeHeap( GetProcessHeap(), 0, fileio
);
1201 else /* synchronous write, wait for the fd to become ready */
1206 if (!timeout_init_done
)
1208 timeout_init_done
= TRUE
;
1209 if ((status
= get_io_timeouts( hFile
, type
, length
, FALSE
, &timeouts
)))
1211 if (hEvent
) NtResetEvent( hEvent
, NULL
);
1213 timeout
= get_next_io_timeout( &timeouts
, total
);
1215 pfd
.fd
= unix_handle
;
1216 pfd
.events
= POLLOUT
;
1218 if (!timeout
|| !(ret
= poll( &pfd
, 1, timeout
)))
1220 /* return with what we got so far */
1221 status
= total
? STATUS_SUCCESS
: STATUS_TIMEOUT
;
1224 if (ret
== -1 && errno
!= EINTR
)
1226 status
= FILE_GetNtStatus();
1229 /* will now restart the write */
1234 send_completion
= cvalue
!= 0;
1237 if (needs_close
) close( unix_handle
);
1239 if (type
== FD_TYPE_SERIAL
&& (status
== STATUS_SUCCESS
|| status
== STATUS_PENDING
))
1240 set_pending_write( hFile
);
1242 if (status
== STATUS_SUCCESS
)
1244 io_status
->u
.Status
= status
;
1245 io_status
->Information
= total
;
1246 TRACE("= SUCCESS (%u)\n", total
);
1247 if (hEvent
) NtSetEvent( hEvent
, NULL
);
1248 if (apc
) NtQueueApcThread( GetCurrentThread(), (PNTAPCFUNC
)apc
,
1249 (ULONG_PTR
)apc_user
, (ULONG_PTR
)io_status
, 0 );
1253 TRACE("= 0x%08x\n", status
);
1254 if (status
!= STATUS_PENDING
&& hEvent
) NtResetEvent( hEvent
, NULL
);
1257 if (send_completion
) NTDLL_AddCompletion( hFile
, cvalue
, status
, total
);
1263 /******************************************************************************
1264 * NtWriteFileGather [NTDLL.@]
1265 * ZwWriteFileGather [NTDLL.@]
1267 NTSTATUS WINAPI
NtWriteFileGather( HANDLE file
, HANDLE event
, PIO_APC_ROUTINE apc
, void *apc_user
,
1268 PIO_STATUS_BLOCK io_status
, FILE_SEGMENT_ELEMENT
*segments
,
1269 ULONG length
, PLARGE_INTEGER offset
, PULONG key
)
1271 int result
, unix_handle
, needs_close
;
1272 unsigned int options
;
1274 ULONG pos
= 0, total
= 0;
1275 enum server_fd_type type
;
1276 ULONG_PTR cvalue
= apc
? 0 : (ULONG_PTR
)apc_user
;
1277 BOOL send_completion
= FALSE
;
1279 TRACE( "(%p,%p,%p,%p,%p,%p,0x%08x,%p,%p),partial stub!\n",
1280 file
, event
, apc
, apc_user
, io_status
, segments
, length
, offset
, key
);
1282 if (length
% page_size
) return STATUS_INVALID_PARAMETER
;
1283 if (!io_status
) return STATUS_ACCESS_VIOLATION
;
1285 status
= server_get_unix_fd( file
, FILE_WRITE_DATA
, &unix_handle
,
1286 &needs_close
, &type
, &options
);
1287 if (status
) return status
;
1289 if ((type
!= FD_TYPE_FILE
) ||
1290 (options
& (FILE_SYNCHRONOUS_IO_ALERT
| FILE_SYNCHRONOUS_IO_NONALERT
)) ||
1291 !(options
& FILE_NO_INTERMEDIATE_BUFFERING
))
1293 status
= STATUS_INVALID_PARAMETER
;
1299 if (offset
&& offset
->QuadPart
!= FILE_USE_FILE_POINTER_POSITION
)
1300 result
= pwrite( unix_handle
, (char *)segments
->Buffer
+ pos
,
1301 page_size
- pos
, offset
->QuadPart
+ total
);
1303 result
= write( unix_handle
, (char *)segments
->Buffer
+ pos
, page_size
- pos
);
1307 if (errno
== EINTR
) continue;
1308 if (errno
== EFAULT
)
1310 status
= STATUS_INVALID_USER_BUFFER
;
1313 status
= FILE_GetNtStatus();
1318 status
= STATUS_DISK_FULL
;
1323 if ((pos
+= result
) == page_size
)
1330 send_completion
= cvalue
!= 0;
1333 if (needs_close
) close( unix_handle
);
1334 if (status
== STATUS_SUCCESS
)
1336 io_status
->u
.Status
= status
;
1337 io_status
->Information
= total
;
1338 TRACE("= SUCCESS (%u)\n", total
);
1339 if (event
) NtSetEvent( event
, NULL
);
1340 if (apc
) NtQueueApcThread( GetCurrentThread(), (PNTAPCFUNC
)apc
,
1341 (ULONG_PTR
)apc_user
, (ULONG_PTR
)io_status
, 0 );
1345 TRACE("= 0x%08x\n", status
);
1346 if (status
!= STATUS_PENDING
&& event
) NtResetEvent( event
, NULL
);
1349 if (send_completion
) NTDLL_AddCompletion( file
, cvalue
, status
, total
);
1357 struct async_fileio io
;
1358 HANDLE event
; /* async event */
1359 void *buffer
; /* buffer for output */
1360 ULONG size
; /* size of buffer */
1363 /* callback for ioctl async I/O completion */
1364 static NTSTATUS
ioctl_completion( void *user
, IO_STATUS_BLOCK
*io
,
1365 NTSTATUS status
, void **apc
, void **arg
)
1367 struct async_ioctl
*async
= user
;
1369 if (status
== STATUS_ALERTED
)
1371 SERVER_START_REQ( get_irp_result
)
1373 req
->handle
= wine_server_obj_handle( async
->io
.handle
);
1374 req
->user_arg
= wine_server_client_ptr( async
);
1375 wine_server_set_reply( req
, async
->buffer
, async
->size
);
1376 status
= wine_server_call( req
);
1377 if (status
!= STATUS_PENDING
) io
->Information
= wine_server_reply_size( reply
);
1381 if (status
!= STATUS_PENDING
)
1383 io
->u
.Status
= status
;
1384 *apc
= async
->io
.apc
;
1385 *arg
= async
->io
.apc_arg
;
1386 release_fileio( &async
->io
);
1391 /* do an ioctl call through the server */
1392 static NTSTATUS
server_ioctl_file( HANDLE handle
, HANDLE event
,
1393 PIO_APC_ROUTINE apc
, PVOID apc_context
,
1394 IO_STATUS_BLOCK
*io
, ULONG code
,
1395 const void *in_buffer
, ULONG in_size
,
1396 PVOID out_buffer
, ULONG out_size
)
1398 struct async_ioctl
*async
;
1402 ULONG_PTR cvalue
= apc
? 0 : (ULONG_PTR
)apc_context
;
1404 if (!(async
= (struct async_ioctl
*)alloc_fileio( sizeof(*async
), handle
, apc
, apc_context
)))
1405 return STATUS_NO_MEMORY
;
1406 async
->event
= event
;
1407 async
->buffer
= out_buffer
;
1408 async
->size
= out_size
;
1410 SERVER_START_REQ( ioctl
)
1413 req
->blocking
= !apc
&& !event
&& !cvalue
;
1414 req
->async
.handle
= wine_server_obj_handle( handle
);
1415 req
->async
.callback
= wine_server_client_ptr( ioctl_completion
);
1416 req
->async
.iosb
= wine_server_client_ptr( io
);
1417 req
->async
.arg
= wine_server_client_ptr( async
);
1418 req
->async
.event
= wine_server_obj_handle( event
);
1419 req
->async
.cvalue
= cvalue
;
1420 wine_server_add_data( req
, in_buffer
, in_size
);
1421 wine_server_set_reply( req
, out_buffer
, out_size
);
1422 status
= wine_server_call( req
);
1423 wait_handle
= wine_server_ptr_handle( reply
->wait
);
1424 options
= reply
->options
;
1425 if (status
!= STATUS_PENDING
) io
->Information
= wine_server_reply_size( reply
);
1429 if (status
== STATUS_NOT_SUPPORTED
)
1430 FIXME("Unsupported ioctl %x (device=%x access=%x func=%x method=%x)\n",
1431 code
, code
>> 16, (code
>> 14) & 3, (code
>> 2) & 0xfff, code
& 3);
1433 if (status
!= STATUS_PENDING
) RtlFreeHeap( GetProcessHeap(), 0, async
);
1437 NtWaitForSingleObject( wait_handle
, (options
& FILE_SYNCHRONOUS_IO_ALERT
), NULL
);
1438 status
= io
->u
.Status
;
1439 NtClose( wait_handle
);
1445 /* Tell Valgrind to ignore any holes in structs we will be passing to the
1447 static void ignore_server_ioctl_struct_holes (ULONG code
, const void *in_buffer
,
1450 #ifdef VALGRIND_MAKE_MEM_DEFINED
1451 # define IGNORE_STRUCT_HOLE(buf, size, t, f1, f2) \
1453 if (FIELD_OFFSET(t, f1) + sizeof(((t *)0)->f1) < FIELD_OFFSET(t, f2)) \
1454 if ((size) >= FIELD_OFFSET(t, f2)) \
1455 VALGRIND_MAKE_MEM_DEFINED( \
1456 (const char *)(buf) + FIELD_OFFSET(t, f1) + sizeof(((t *)0)->f1), \
1457 FIELD_OFFSET(t, f2) - FIELD_OFFSET(t, f1) + sizeof(((t *)0)->f1)); \
1462 case FSCTL_PIPE_WAIT
:
1463 IGNORE_STRUCT_HOLE(in_buffer
, in_size
, FILE_PIPE_WAIT_FOR_BUFFER
, TimeoutSpecified
, Name
);
1470 /**************************************************************************
1471 * NtDeviceIoControlFile [NTDLL.@]
1472 * ZwDeviceIoControlFile [NTDLL.@]
1474 * Perform an I/O control operation on an open file handle.
1477 * handle [I] Handle returned from ZwOpenFile() or ZwCreateFile()
1478 * event [I] Event to signal upon completion (or NULL)
1479 * apc [I] Callback to call upon completion (or NULL)
1480 * apc_context [I] Context for ApcRoutine (or NULL)
1481 * io [O] Receives information about the operation on return
1482 * code [I] Control code for the operation to perform
1483 * in_buffer [I] Source for any input data required (or NULL)
1484 * in_size [I] Size of InputBuffer
1485 * out_buffer [O] Source for any output data returned (or NULL)
1486 * out_size [I] Size of OutputBuffer
1489 * Success: 0. IoStatusBlock is updated.
1490 * Failure: An NTSTATUS error code describing the error.
1492 NTSTATUS WINAPI
NtDeviceIoControlFile(HANDLE handle
, HANDLE event
,
1493 PIO_APC_ROUTINE apc
, PVOID apc_context
,
1494 PIO_STATUS_BLOCK io
, ULONG code
,
1495 PVOID in_buffer
, ULONG in_size
,
1496 PVOID out_buffer
, ULONG out_size
)
1498 ULONG device
= (code
>> 16);
1499 NTSTATUS status
= STATUS_NOT_SUPPORTED
;
1501 TRACE("(%p,%p,%p,%p,%p,0x%08x,%p,0x%08x,%p,0x%08x)\n",
1502 handle
, event
, apc
, apc_context
, io
, code
,
1503 in_buffer
, in_size
, out_buffer
, out_size
);
1507 case FILE_DEVICE_DISK
:
1508 case FILE_DEVICE_CD_ROM
:
1509 case FILE_DEVICE_DVD
:
1510 case FILE_DEVICE_CONTROLLER
:
1511 case FILE_DEVICE_MASS_STORAGE
:
1512 status
= CDROM_DeviceIoControl(handle
, event
, apc
, apc_context
, io
, code
,
1513 in_buffer
, in_size
, out_buffer
, out_size
);
1515 case FILE_DEVICE_SERIAL_PORT
:
1516 status
= COMM_DeviceIoControl(handle
, event
, apc
, apc_context
, io
, code
,
1517 in_buffer
, in_size
, out_buffer
, out_size
);
1519 case FILE_DEVICE_TAPE
:
1520 status
= TAPE_DeviceIoControl(handle
, event
, apc
, apc_context
, io
, code
,
1521 in_buffer
, in_size
, out_buffer
, out_size
);
1525 if (status
== STATUS_NOT_SUPPORTED
|| status
== STATUS_BAD_DEVICE_TYPE
)
1526 status
= server_ioctl_file( handle
, event
, apc
, apc_context
, io
, code
,
1527 in_buffer
, in_size
, out_buffer
, out_size
);
1529 if (status
!= STATUS_PENDING
) io
->u
.Status
= status
;
1534 /**************************************************************************
1535 * NtFsControlFile [NTDLL.@]
1536 * ZwFsControlFile [NTDLL.@]
1538 * Perform a file system control operation on an open file handle.
1541 * handle [I] Handle returned from ZwOpenFile() or ZwCreateFile()
1542 * event [I] Event to signal upon completion (or NULL)
1543 * apc [I] Callback to call upon completion (or NULL)
1544 * apc_context [I] Context for ApcRoutine (or NULL)
1545 * io [O] Receives information about the operation on return
1546 * code [I] Control code for the operation to perform
1547 * in_buffer [I] Source for any input data required (or NULL)
1548 * in_size [I] Size of InputBuffer
1549 * out_buffer [O] Source for any output data returned (or NULL)
1550 * out_size [I] Size of OutputBuffer
1553 * Success: 0. IoStatusBlock is updated.
1554 * Failure: An NTSTATUS error code describing the error.
1556 NTSTATUS WINAPI
NtFsControlFile(HANDLE handle
, HANDLE event
, PIO_APC_ROUTINE apc
,
1557 PVOID apc_context
, PIO_STATUS_BLOCK io
, ULONG code
,
1558 PVOID in_buffer
, ULONG in_size
, PVOID out_buffer
, ULONG out_size
)
1562 TRACE("(%p,%p,%p,%p,%p,0x%08x,%p,0x%08x,%p,0x%08x)\n",
1563 handle
, event
, apc
, apc_context
, io
, code
,
1564 in_buffer
, in_size
, out_buffer
, out_size
);
1566 if (!io
) return STATUS_INVALID_PARAMETER
;
1568 ignore_server_ioctl_struct_holes( code
, in_buffer
, in_size
);
1572 case FSCTL_DISMOUNT_VOLUME
:
1573 status
= server_ioctl_file( handle
, event
, apc
, apc_context
, io
, code
,
1574 in_buffer
, in_size
, out_buffer
, out_size
);
1575 if (!status
) status
= DIR_unmount_device( handle
);
1578 case FSCTL_PIPE_PEEK
:
1580 FILE_PIPE_PEEK_BUFFER
*buffer
= out_buffer
;
1581 int avail
= 0, fd
, needs_close
;
1583 if (out_size
< FIELD_OFFSET( FILE_PIPE_PEEK_BUFFER
, Data
))
1585 status
= STATUS_INFO_LENGTH_MISMATCH
;
1589 if ((status
= server_get_unix_fd( handle
, FILE_READ_DATA
, &fd
, &needs_close
, NULL
, NULL
)))
1593 if (ioctl( fd
, FIONREAD
, &avail
) != 0)
1595 TRACE("FIONREAD failed reason: %s\n",strerror(errno
));
1596 if (needs_close
) close( fd
);
1597 status
= FILE_GetNtStatus();
1601 if (!avail
) /* check for closed pipe */
1603 struct pollfd pollfd
;
1607 pollfd
.events
= POLLIN
;
1609 ret
= poll( &pollfd
, 1, 0 );
1610 if (ret
== -1 || (ret
== 1 && (pollfd
.revents
& (POLLHUP
|POLLERR
))))
1612 if (needs_close
) close( fd
);
1613 status
= STATUS_PIPE_BROKEN
;
1617 buffer
->NamedPipeState
= 0; /* FIXME */
1618 buffer
->ReadDataAvailable
= avail
;
1619 buffer
->NumberOfMessages
= 0; /* FIXME */
1620 buffer
->MessageLength
= 0; /* FIXME */
1621 io
->Information
= FIELD_OFFSET( FILE_PIPE_PEEK_BUFFER
, Data
);
1622 status
= STATUS_SUCCESS
;
1625 ULONG data_size
= out_size
- FIELD_OFFSET( FILE_PIPE_PEEK_BUFFER
, Data
);
1628 int res
= recv( fd
, buffer
->Data
, data_size
, MSG_PEEK
);
1629 if (res
>= 0) io
->Information
+= res
;
1632 if (needs_close
) close( fd
);
1636 case FSCTL_PIPE_DISCONNECT
:
1637 status
= server_ioctl_file( handle
, event
, apc
, apc_context
, io
, code
,
1638 in_buffer
, in_size
, out_buffer
, out_size
);
1641 int fd
= server_remove_fd_from_cache( handle
);
1642 if (fd
!= -1) close( fd
);
1646 case FSCTL_PIPE_IMPERSONATE
:
1647 FIXME("FSCTL_PIPE_IMPERSONATE: impersonating self\n");
1648 status
= RtlImpersonateSelf( SecurityImpersonation
);
1651 case FSCTL_IS_VOLUME_MOUNTED
:
1652 case FSCTL_LOCK_VOLUME
:
1653 case FSCTL_UNLOCK_VOLUME
:
1654 FIXME("stub! return success - Unsupported fsctl %x (device=%x access=%x func=%x method=%x)\n",
1655 code
, code
>> 16, (code
>> 14) & 3, (code
>> 2) & 0xfff, code
& 3);
1656 status
= STATUS_SUCCESS
;
1659 case FSCTL_GET_RETRIEVAL_POINTERS
:
1661 RETRIEVAL_POINTERS_BUFFER
*buffer
= (RETRIEVAL_POINTERS_BUFFER
*)out_buffer
;
1663 FIXME("stub: FSCTL_GET_RETRIEVAL_POINTERS\n");
1665 if (out_size
>= sizeof(RETRIEVAL_POINTERS_BUFFER
))
1667 buffer
->ExtentCount
= 1;
1668 buffer
->StartingVcn
.QuadPart
= 1;
1669 buffer
->Extents
[0].NextVcn
.QuadPart
= 0;
1670 buffer
->Extents
[0].Lcn
.QuadPart
= 0;
1671 io
->Information
= sizeof(RETRIEVAL_POINTERS_BUFFER
);
1672 status
= STATUS_SUCCESS
;
1676 io
->Information
= 0;
1677 status
= STATUS_BUFFER_TOO_SMALL
;
1681 case FSCTL_PIPE_LISTEN
:
1682 case FSCTL_PIPE_WAIT
:
1684 status
= server_ioctl_file( handle
, event
, apc
, apc_context
, io
, code
,
1685 in_buffer
, in_size
, out_buffer
, out_size
);
1689 if (status
!= STATUS_PENDING
) io
->u
.Status
= status
;
1694 struct read_changes_fileio
1696 struct async_fileio io
;
1703 static NTSTATUS
read_changes_apc( void *user
, IO_STATUS_BLOCK
*iosb
,
1704 NTSTATUS status
, void **apc
, void **arg
)
1706 struct read_changes_fileio
*fileio
= user
;
1710 SERVER_START_REQ( read_change
)
1712 req
->handle
= wine_server_obj_handle( fileio
->io
.handle
);
1713 wine_server_set_reply( req
, fileio
->data
, fileio
->data_size
);
1714 ret
= wine_server_call( req
);
1715 size
= wine_server_reply_size( reply
);
1719 if (ret
== STATUS_SUCCESS
&& fileio
->buffer
)
1721 FILE_NOTIFY_INFORMATION
*pfni
= fileio
->buffer
;
1722 int i
, left
= fileio
->buffer_size
;
1723 DWORD
*last_entry_offset
= NULL
;
1724 struct filesystem_event
*event
= (struct filesystem_event
*)fileio
->data
;
1726 while (size
&& left
>= sizeof(*pfni
))
1728 /* convert to an NT style path */
1729 for (i
=0; i
<event
->len
; i
++)
1730 if (event
->name
[i
] == '/') event
->name
[i
] = '\\';
1732 pfni
->Action
= event
->action
;
1733 pfni
->FileNameLength
= ntdll_umbstowcs( 0, event
->name
, event
->len
, pfni
->FileName
,
1734 (left
- offsetof(FILE_NOTIFY_INFORMATION
, FileName
)) / sizeof(WCHAR
));
1735 last_entry_offset
= &pfni
->NextEntryOffset
;
1737 if (pfni
->FileNameLength
== -1 || pfni
->FileNameLength
== -2) break;
1739 i
= offsetof(FILE_NOTIFY_INFORMATION
, FileName
[pfni
->FileNameLength
]);
1740 pfni
->FileNameLength
*= sizeof(WCHAR
);
1741 pfni
->NextEntryOffset
= i
;
1742 pfni
= (FILE_NOTIFY_INFORMATION
*)((char*)pfni
+ i
);
1745 i
= (offsetof(struct filesystem_event
, name
[event
->len
])
1746 + sizeof(int)-1) / sizeof(int) * sizeof(int);
1747 event
= (struct filesystem_event
*)((char*)event
+ i
);
1753 ret
= STATUS_NOTIFY_ENUM_DIR
;
1758 *last_entry_offset
= 0;
1759 size
= fileio
->buffer_size
- left
;
1764 ret
= STATUS_NOTIFY_ENUM_DIR
;
1768 iosb
->u
.Status
= ret
;
1769 iosb
->Information
= size
;
1770 *apc
= fileio
->io
.apc
;
1771 *arg
= fileio
->io
.apc_arg
;
1772 release_fileio( &fileio
->io
);
1776 #define FILE_NOTIFY_ALL ( \
1777 FILE_NOTIFY_CHANGE_FILE_NAME | \
1778 FILE_NOTIFY_CHANGE_DIR_NAME | \
1779 FILE_NOTIFY_CHANGE_ATTRIBUTES | \
1780 FILE_NOTIFY_CHANGE_SIZE | \
1781 FILE_NOTIFY_CHANGE_LAST_WRITE | \
1782 FILE_NOTIFY_CHANGE_LAST_ACCESS | \
1783 FILE_NOTIFY_CHANGE_CREATION | \
1784 FILE_NOTIFY_CHANGE_SECURITY )
1786 /******************************************************************************
1787 * NtNotifyChangeDirectoryFile [NTDLL.@]
1789 NTSTATUS WINAPI
NtNotifyChangeDirectoryFile( HANDLE handle
, HANDLE event
, PIO_APC_ROUTINE apc
,
1790 void *apc_context
, PIO_STATUS_BLOCK iosb
, void *buffer
,
1791 ULONG buffer_size
, ULONG filter
, BOOLEAN subtree
)
1793 struct read_changes_fileio
*fileio
;
1795 ULONG size
= max( 4096, buffer_size
);
1796 ULONG_PTR cvalue
= apc
? 0 : (ULONG_PTR
)apc_context
;
1798 TRACE( "%p %p %p %p %p %p %u %u %d\n",
1799 handle
, event
, apc
, apc_context
, iosb
, buffer
, buffer_size
, filter
, subtree
);
1801 if (!iosb
) return STATUS_ACCESS_VIOLATION
;
1802 if (filter
== 0 || (filter
& ~FILE_NOTIFY_ALL
)) return STATUS_INVALID_PARAMETER
;
1804 fileio
= (struct read_changes_fileio
*)alloc_fileio( offsetof(struct read_changes_fileio
, data
[size
]),
1805 handle
, apc
, apc_context
);
1806 if (!fileio
) return STATUS_NO_MEMORY
;
1808 fileio
->buffer
= buffer
;
1809 fileio
->buffer_size
= buffer_size
;
1810 fileio
->data_size
= size
;
1812 SERVER_START_REQ( read_directory_changes
)
1814 req
->filter
= filter
;
1815 req
->want_data
= (buffer
!= NULL
);
1816 req
->subtree
= subtree
;
1817 req
->async
.handle
= wine_server_obj_handle( handle
);
1818 req
->async
.callback
= wine_server_client_ptr( read_changes_apc
);
1819 req
->async
.iosb
= wine_server_client_ptr( iosb
);
1820 req
->async
.arg
= wine_server_client_ptr( fileio
);
1821 req
->async
.event
= wine_server_obj_handle( event
);
1822 req
->async
.cvalue
= cvalue
;
1823 status
= wine_server_call( req
);
1827 if (status
!= STATUS_PENDING
) RtlFreeHeap( GetProcessHeap(), 0, fileio
);
1831 /******************************************************************************
1832 * NtSetVolumeInformationFile [NTDLL.@]
1833 * ZwSetVolumeInformationFile [NTDLL.@]
1835 * Set volume information for an open file handle.
1838 * FileHandle [I] Handle returned from ZwOpenFile() or ZwCreateFile()
1839 * IoStatusBlock [O] Receives information about the operation on return
1840 * FsInformation [I] Source for volume information
1841 * Length [I] Size of FsInformation
1842 * FsInformationClass [I] Type of volume information to set
1845 * Success: 0. IoStatusBlock is updated.
1846 * Failure: An NTSTATUS error code describing the error.
1848 NTSTATUS WINAPI
NtSetVolumeInformationFile(
1849 IN HANDLE FileHandle
,
1850 PIO_STATUS_BLOCK IoStatusBlock
,
1851 PVOID FsInformation
,
1853 FS_INFORMATION_CLASS FsInformationClass
)
1855 FIXME("(%p,%p,%p,0x%08x,0x%08x) stub\n",
1856 FileHandle
,IoStatusBlock
,FsInformation
,Length
,FsInformationClass
);
1860 #if defined(__ANDROID__) && !defined(HAVE_FUTIMENS)
1861 static int futimens( int fd
, const struct timespec spec
[2] )
1863 return syscall( __NR_utimensat
, fd
, NULL
, spec
, 0 );
1865 #define HAVE_FUTIMENS
1866 #endif /* __ANDROID__ */
1869 #define UTIME_OMIT ((1 << 30) - 2)
1872 static NTSTATUS
set_file_times( int fd
, const LARGE_INTEGER
*mtime
, const LARGE_INTEGER
*atime
)
1874 NTSTATUS status
= STATUS_SUCCESS
;
1876 #ifdef HAVE_FUTIMENS
1877 struct timespec tv
[2];
1879 tv
[0].tv_sec
= tv
[1].tv_sec
= 0;
1880 tv
[0].tv_nsec
= tv
[1].tv_nsec
= UTIME_OMIT
;
1881 if (atime
->QuadPart
)
1883 tv
[0].tv_sec
= atime
->QuadPart
/ 10000000 - SECS_1601_TO_1970
;
1884 tv
[0].tv_nsec
= (atime
->QuadPart
% 10000000) * 100;
1886 if (mtime
->QuadPart
)
1888 tv
[1].tv_sec
= mtime
->QuadPart
/ 10000000 - SECS_1601_TO_1970
;
1889 tv
[1].tv_nsec
= (mtime
->QuadPart
% 10000000) * 100;
1891 if (futimens( fd
, tv
) == -1) status
= FILE_GetNtStatus();
1893 #elif defined(HAVE_FUTIMES) || defined(HAVE_FUTIMESAT)
1894 struct timeval tv
[2];
1897 if (!atime
->QuadPart
|| !mtime
->QuadPart
)
1900 tv
[0].tv_sec
= tv
[0].tv_usec
= 0;
1901 tv
[1].tv_sec
= tv
[1].tv_usec
= 0;
1902 if (!fstat( fd
, &st
))
1904 tv
[0].tv_sec
= st
.st_atime
;
1905 tv
[1].tv_sec
= st
.st_mtime
;
1906 #ifdef HAVE_STRUCT_STAT_ST_ATIM
1907 tv
[0].tv_usec
= st
.st_atim
.tv_nsec
/ 1000;
1908 #elif defined(HAVE_STRUCT_STAT_ST_ATIMESPEC)
1909 tv
[0].tv_usec
= st
.st_atimespec
.tv_nsec
/ 1000;
1911 #ifdef HAVE_STRUCT_STAT_ST_MTIM
1912 tv
[1].tv_usec
= st
.st_mtim
.tv_nsec
/ 1000;
1913 #elif defined(HAVE_STRUCT_STAT_ST_MTIMESPEC)
1914 tv
[1].tv_usec
= st
.st_mtimespec
.tv_nsec
/ 1000;
1918 if (atime
->QuadPart
)
1920 tv
[0].tv_sec
= atime
->QuadPart
/ 10000000 - SECS_1601_TO_1970
;
1921 tv
[0].tv_usec
= (atime
->QuadPart
% 10000000) / 10;
1923 if (mtime
->QuadPart
)
1925 tv
[1].tv_sec
= mtime
->QuadPart
/ 10000000 - SECS_1601_TO_1970
;
1926 tv
[1].tv_usec
= (mtime
->QuadPart
% 10000000) / 10;
1929 if (futimes( fd
, tv
) == -1) status
= FILE_GetNtStatus();
1930 #elif defined(HAVE_FUTIMESAT)
1931 if (futimesat( fd
, NULL
, tv
) == -1) status
= FILE_GetNtStatus();
1934 #else /* HAVE_FUTIMES || HAVE_FUTIMESAT */
1935 FIXME( "setting file times not supported\n" );
1936 status
= STATUS_NOT_IMPLEMENTED
;
1941 static inline void get_file_times( const struct stat
*st
, LARGE_INTEGER
*mtime
, LARGE_INTEGER
*ctime
,
1942 LARGE_INTEGER
*atime
, LARGE_INTEGER
*creation
)
1944 RtlSecondsSince1970ToTime( st
->st_mtime
, mtime
);
1945 RtlSecondsSince1970ToTime( st
->st_ctime
, ctime
);
1946 RtlSecondsSince1970ToTime( st
->st_atime
, atime
);
1947 #ifdef HAVE_STRUCT_STAT_ST_MTIM
1948 mtime
->QuadPart
+= st
->st_mtim
.tv_nsec
/ 100;
1949 #elif defined(HAVE_STRUCT_STAT_ST_MTIMESPEC)
1950 mtime
->QuadPart
+= st
->st_mtimespec
.tv_nsec
/ 100;
1952 #ifdef HAVE_STRUCT_STAT_ST_CTIM
1953 ctime
->QuadPart
+= st
->st_ctim
.tv_nsec
/ 100;
1954 #elif defined(HAVE_STRUCT_STAT_ST_CTIMESPEC)
1955 ctime
->QuadPart
+= st
->st_ctimespec
.tv_nsec
/ 100;
1957 #ifdef HAVE_STRUCT_STAT_ST_ATIM
1958 atime
->QuadPart
+= st
->st_atim
.tv_nsec
/ 100;
1959 #elif defined(HAVE_STRUCT_STAT_ST_ATIMESPEC)
1960 atime
->QuadPart
+= st
->st_atimespec
.tv_nsec
/ 100;
1962 #ifdef HAVE_STRUCT_STAT_ST_BIRTHTIME
1963 RtlSecondsSince1970ToTime( st
->st_birthtime
, creation
);
1964 #ifdef HAVE_STRUCT_STAT_ST_BIRTHTIM
1965 creation
->QuadPart
+= st
->st_birthtim
.tv_nsec
/ 100;
1966 #elif defined(HAVE_STRUCT_STAT_ST_BIRTHTIMESPEC)
1967 creation
->QuadPart
+= st
->st_birthtimespec
.tv_nsec
/ 100;
1969 #elif defined(HAVE_STRUCT_STAT___ST_BIRTHTIME)
1970 RtlSecondsSince1970ToTime( st
->__st_birthtime
, creation
);
1971 #ifdef HAVE_STRUCT_STAT___ST_BIRTHTIM
1972 creation
->QuadPart
+= st
->__st_birthtim
.tv_nsec
/ 100;
1979 /* fill in the file information that depends on the stat and attribute info */
1980 NTSTATUS
fill_file_info( const struct stat
*st
, ULONG attr
, void *ptr
,
1981 FILE_INFORMATION_CLASS
class )
1985 case FileBasicInformation
:
1987 FILE_BASIC_INFORMATION
*info
= ptr
;
1989 get_file_times( st
, &info
->LastWriteTime
, &info
->ChangeTime
,
1990 &info
->LastAccessTime
, &info
->CreationTime
);
1991 info
->FileAttributes
= attr
;
1994 case FileStandardInformation
:
1996 FILE_STANDARD_INFORMATION
*info
= ptr
;
1998 if ((info
->Directory
= S_ISDIR(st
->st_mode
)))
2000 info
->AllocationSize
.QuadPart
= 0;
2001 info
->EndOfFile
.QuadPart
= 0;
2002 info
->NumberOfLinks
= 1;
2006 info
->AllocationSize
.QuadPart
= (ULONGLONG
)st
->st_blocks
* 512;
2007 info
->EndOfFile
.QuadPart
= st
->st_size
;
2008 info
->NumberOfLinks
= st
->st_nlink
;
2012 case FileInternalInformation
:
2014 FILE_INTERNAL_INFORMATION
*info
= ptr
;
2015 info
->IndexNumber
.QuadPart
= st
->st_ino
;
2018 case FileEndOfFileInformation
:
2020 FILE_END_OF_FILE_INFORMATION
*info
= ptr
;
2021 info
->EndOfFile
.QuadPart
= S_ISDIR(st
->st_mode
) ? 0 : st
->st_size
;
2024 case FileAllInformation
:
2026 FILE_ALL_INFORMATION
*info
= ptr
;
2027 fill_file_info( st
, attr
, &info
->BasicInformation
, FileBasicInformation
);
2028 fill_file_info( st
, attr
, &info
->StandardInformation
, FileStandardInformation
);
2029 fill_file_info( st
, attr
, &info
->InternalInformation
, FileInternalInformation
);
2032 /* all directory structures start with the FileDirectoryInformation layout */
2033 case FileBothDirectoryInformation
:
2034 case FileFullDirectoryInformation
:
2035 case FileDirectoryInformation
:
2037 FILE_DIRECTORY_INFORMATION
*info
= ptr
;
2039 get_file_times( st
, &info
->LastWriteTime
, &info
->ChangeTime
,
2040 &info
->LastAccessTime
, &info
->CreationTime
);
2041 if (S_ISDIR(st
->st_mode
))
2043 info
->AllocationSize
.QuadPart
= 0;
2044 info
->EndOfFile
.QuadPart
= 0;
2048 info
->AllocationSize
.QuadPart
= (ULONGLONG
)st
->st_blocks
* 512;
2049 info
->EndOfFile
.QuadPart
= st
->st_size
;
2051 info
->FileAttributes
= attr
;
2054 case FileIdFullDirectoryInformation
:
2056 FILE_ID_FULL_DIRECTORY_INFORMATION
*info
= ptr
;
2057 info
->FileId
.QuadPart
= st
->st_ino
;
2058 fill_file_info( st
, attr
, info
, FileDirectoryInformation
);
2061 case FileIdBothDirectoryInformation
:
2063 FILE_ID_BOTH_DIRECTORY_INFORMATION
*info
= ptr
;
2064 info
->FileId
.QuadPart
= st
->st_ino
;
2065 fill_file_info( st
, attr
, info
, FileDirectoryInformation
);
2070 return STATUS_INVALID_INFO_CLASS
;
2072 return STATUS_SUCCESS
;
2075 NTSTATUS
server_get_unix_name( HANDLE handle
, ANSI_STRING
*unix_name
)
2077 data_size_t size
= 1024;
2083 name
= RtlAllocateHeap( GetProcessHeap(), 0, size
+ 1 );
2084 if (!name
) return STATUS_NO_MEMORY
;
2085 unix_name
->MaximumLength
= size
+ 1;
2087 SERVER_START_REQ( get_handle_unix_name
)
2089 req
->handle
= wine_server_obj_handle( handle
);
2090 wine_server_set_reply( req
, name
, size
);
2091 ret
= wine_server_call( req
);
2092 size
= reply
->name_len
;
2099 unix_name
->Buffer
= name
;
2100 unix_name
->Length
= size
;
2103 RtlFreeHeap( GetProcessHeap(), 0, name
);
2104 if (ret
!= STATUS_BUFFER_OVERFLOW
) break;
2109 static NTSTATUS
fill_name_info( const ANSI_STRING
*unix_name
, FILE_NAME_INFORMATION
*info
, LONG
*name_len
)
2111 UNICODE_STRING nt_name
;
2114 if (!(status
= wine_unix_to_nt_file_name( unix_name
, &nt_name
)))
2116 const WCHAR
*ptr
= nt_name
.Buffer
;
2117 const WCHAR
*end
= ptr
+ (nt_name
.Length
/ sizeof(WCHAR
));
2119 /* Skip the volume mount point. */
2120 while (ptr
!= end
&& *ptr
== '\\') ++ptr
;
2121 while (ptr
!= end
&& *ptr
!= '\\') ++ptr
;
2122 while (ptr
!= end
&& *ptr
== '\\') ++ptr
;
2123 while (ptr
!= end
&& *ptr
!= '\\') ++ptr
;
2125 info
->FileNameLength
= (end
- ptr
) * sizeof(WCHAR
);
2126 if (*name_len
< info
->FileNameLength
) status
= STATUS_BUFFER_OVERFLOW
;
2127 else *name_len
= info
->FileNameLength
;
2129 memcpy( info
->FileName
, ptr
, *name_len
);
2130 RtlFreeUnicodeString( &nt_name
);
2136 /******************************************************************************
2137 * NtQueryInformationFile [NTDLL.@]
2138 * ZwQueryInformationFile [NTDLL.@]
2140 * Get information about an open file handle.
2143 * hFile [I] Handle returned from ZwOpenFile() or ZwCreateFile()
2144 * io [O] Receives information about the operation on return
2145 * ptr [O] Destination for file information
2146 * len [I] Size of FileInformation
2147 * class [I] Type of file information to get
2150 * Success: 0. IoStatusBlock and FileInformation are updated.
2151 * Failure: An NTSTATUS error code describing the error.
2153 NTSTATUS WINAPI
NtQueryInformationFile( HANDLE hFile
, PIO_STATUS_BLOCK io
,
2154 PVOID ptr
, LONG len
, FILE_INFORMATION_CLASS
class )
2156 static const size_t info_sizes
[] =
2159 sizeof(FILE_DIRECTORY_INFORMATION
), /* FileDirectoryInformation */
2160 sizeof(FILE_FULL_DIRECTORY_INFORMATION
), /* FileFullDirectoryInformation */
2161 sizeof(FILE_BOTH_DIRECTORY_INFORMATION
), /* FileBothDirectoryInformation */
2162 sizeof(FILE_BASIC_INFORMATION
), /* FileBasicInformation */
2163 sizeof(FILE_STANDARD_INFORMATION
), /* FileStandardInformation */
2164 sizeof(FILE_INTERNAL_INFORMATION
), /* FileInternalInformation */
2165 sizeof(FILE_EA_INFORMATION
), /* FileEaInformation */
2166 sizeof(FILE_ACCESS_INFORMATION
), /* FileAccessInformation */
2167 sizeof(FILE_NAME_INFORMATION
), /* FileNameInformation */
2168 sizeof(FILE_RENAME_INFORMATION
)-sizeof(WCHAR
), /* FileRenameInformation */
2169 0, /* FileLinkInformation */
2170 sizeof(FILE_NAMES_INFORMATION
)-sizeof(WCHAR
), /* FileNamesInformation */
2171 sizeof(FILE_DISPOSITION_INFORMATION
), /* FileDispositionInformation */
2172 sizeof(FILE_POSITION_INFORMATION
), /* FilePositionInformation */
2173 sizeof(FILE_FULL_EA_INFORMATION
), /* FileFullEaInformation */
2174 sizeof(FILE_MODE_INFORMATION
), /* FileModeInformation */
2175 sizeof(FILE_ALIGNMENT_INFORMATION
), /* FileAlignmentInformation */
2176 sizeof(FILE_ALL_INFORMATION
), /* FileAllInformation */
2177 sizeof(FILE_ALLOCATION_INFORMATION
), /* FileAllocationInformation */
2178 sizeof(FILE_END_OF_FILE_INFORMATION
), /* FileEndOfFileInformation */
2179 0, /* FileAlternateNameInformation */
2180 sizeof(FILE_STREAM_INFORMATION
)-sizeof(WCHAR
), /* FileStreamInformation */
2181 sizeof(FILE_PIPE_INFORMATION
), /* FilePipeInformation */
2182 sizeof(FILE_PIPE_LOCAL_INFORMATION
), /* FilePipeLocalInformation */
2183 0, /* FilePipeRemoteInformation */
2184 sizeof(FILE_MAILSLOT_QUERY_INFORMATION
), /* FileMailslotQueryInformation */
2185 0, /* FileMailslotSetInformation */
2186 0, /* FileCompressionInformation */
2187 0, /* FileObjectIdInformation */
2188 0, /* FileCompletionInformation */
2189 0, /* FileMoveClusterInformation */
2190 0, /* FileQuotaInformation */
2191 0, /* FileReparsePointInformation */
2192 sizeof(FILE_NETWORK_OPEN_INFORMATION
), /* FileNetworkOpenInformation */
2193 0, /* FileAttributeTagInformation */
2194 0, /* FileTrackingInformation */
2195 0, /* FileIdBothDirectoryInformation */
2196 0, /* FileIdFullDirectoryInformation */
2197 0, /* FileValidDataLengthInformation */
2198 0, /* FileShortNameInformation */
2199 0, /* FileIoCompletionNotificationInformation, */
2200 0, /* FileIoStatusBlockRangeInformation */
2201 0, /* FileIoPriorityHintInformation */
2202 0, /* FileSfioReserveInformation */
2203 0, /* FileSfioVolumeInformation */
2204 0, /* FileHardLinkInformation */
2205 0, /* FileProcessIdsUsingFileInformation */
2206 0, /* FileNormalizedNameInformation */
2207 0, /* FileNetworkPhysicalNameInformation */
2208 0, /* FileIdGlobalTxDirectoryInformation */
2209 0, /* FileIsRemoteDeviceInformation */
2210 0, /* FileAttributeCacheInformation */
2211 0, /* FileNumaNodeInformation */
2212 0, /* FileStandardLinkInformation */
2213 0, /* FileRemoteProtocolInformation */
2214 0, /* FileReplaceCompletionInformation */
2218 int fd
, needs_close
= FALSE
;
2221 TRACE("(%p,%p,%p,0x%08x,0x%08x)\n", hFile
, io
, ptr
, len
, class);
2223 io
->Information
= 0;
2225 if (class <= 0 || class >= FileMaximumInformation
)
2226 return io
->u
.Status
= STATUS_INVALID_INFO_CLASS
;
2227 if (!info_sizes
[class])
2229 FIXME("Unsupported class (%d)\n", class);
2230 return io
->u
.Status
= STATUS_NOT_IMPLEMENTED
;
2232 if (len
< info_sizes
[class])
2233 return io
->u
.Status
= STATUS_INFO_LENGTH_MISMATCH
;
2235 if (class != FilePipeInformation
&& class != FilePipeLocalInformation
)
2237 if ((io
->u
.Status
= server_get_unix_fd( hFile
, 0, &fd
, &needs_close
, NULL
, NULL
)))
2238 return io
->u
.Status
;
2243 case FileBasicInformation
:
2244 if (fd_get_file_info( fd
, &st
, &attr
) == -1)
2245 io
->u
.Status
= FILE_GetNtStatus();
2246 else if (!S_ISREG(st
.st_mode
) && !S_ISDIR(st
.st_mode
))
2247 io
->u
.Status
= STATUS_INVALID_INFO_CLASS
;
2249 fill_file_info( &st
, attr
, ptr
, class );
2251 case FileStandardInformation
:
2253 FILE_STANDARD_INFORMATION
*info
= ptr
;
2255 if (fd_get_file_info( fd
, &st
, &attr
) == -1) io
->u
.Status
= FILE_GetNtStatus();
2258 fill_file_info( &st
, attr
, info
, class );
2259 info
->DeletePending
= FALSE
; /* FIXME */
2263 case FilePositionInformation
:
2265 FILE_POSITION_INFORMATION
*info
= ptr
;
2266 off_t res
= lseek( fd
, 0, SEEK_CUR
);
2267 if (res
== (off_t
)-1) io
->u
.Status
= FILE_GetNtStatus();
2268 else info
->CurrentByteOffset
.QuadPart
= res
;
2271 case FileInternalInformation
:
2272 if (fd_get_file_info( fd
, &st
, &attr
) == -1) io
->u
.Status
= FILE_GetNtStatus();
2273 else fill_file_info( &st
, attr
, ptr
, class );
2275 case FileEaInformation
:
2277 FILE_EA_INFORMATION
*info
= ptr
;
2281 case FileEndOfFileInformation
:
2282 if (fd_get_file_info( fd
, &st
, &attr
) == -1) io
->u
.Status
= FILE_GetNtStatus();
2283 else fill_file_info( &st
, attr
, ptr
, class );
2285 case FileAllInformation
:
2287 FILE_ALL_INFORMATION
*info
= ptr
;
2288 ANSI_STRING unix_name
;
2290 if (fd_get_file_info( fd
, &st
, &attr
) == -1) io
->u
.Status
= FILE_GetNtStatus();
2291 else if (!S_ISREG(st
.st_mode
) && !S_ISDIR(st
.st_mode
))
2292 io
->u
.Status
= STATUS_INVALID_INFO_CLASS
;
2293 else if (!(io
->u
.Status
= server_get_unix_name( hFile
, &unix_name
)))
2295 LONG name_len
= len
- FIELD_OFFSET(FILE_ALL_INFORMATION
, NameInformation
.FileName
);
2297 fill_file_info( &st
, attr
, info
, FileAllInformation
);
2298 info
->StandardInformation
.DeletePending
= FALSE
; /* FIXME */
2299 info
->EaInformation
.EaSize
= 0;
2300 info
->AccessInformation
.AccessFlags
= 0; /* FIXME */
2301 info
->PositionInformation
.CurrentByteOffset
.QuadPart
= lseek( fd
, 0, SEEK_CUR
);
2302 info
->ModeInformation
.Mode
= 0; /* FIXME */
2303 info
->AlignmentInformation
.AlignmentRequirement
= 1; /* FIXME */
2305 io
->u
.Status
= fill_name_info( &unix_name
, &info
->NameInformation
, &name_len
);
2306 RtlFreeAnsiString( &unix_name
);
2307 io
->Information
= FIELD_OFFSET(FILE_ALL_INFORMATION
, NameInformation
.FileName
) + name_len
;
2311 case FileMailslotQueryInformation
:
2313 FILE_MAILSLOT_QUERY_INFORMATION
*info
= ptr
;
2315 SERVER_START_REQ( set_mailslot_info
)
2317 req
->handle
= wine_server_obj_handle( hFile
);
2319 io
->u
.Status
= wine_server_call( req
);
2320 if( io
->u
.Status
== STATUS_SUCCESS
)
2322 info
->MaximumMessageSize
= reply
->max_msgsize
;
2323 info
->MailslotQuota
= 0;
2324 info
->NextMessageSize
= 0;
2325 info
->MessagesAvailable
= 0;
2326 info
->ReadTimeout
.QuadPart
= reply
->read_timeout
;
2333 ULONG size
= info
->MaximumMessageSize
? info
->MaximumMessageSize
: 0x10000;
2334 if (size
> 0x10000) size
= 0x10000;
2335 if ((tmpbuf
= RtlAllocateHeap( GetProcessHeap(), 0, size
)))
2337 if (!server_get_unix_fd( hFile
, FILE_READ_DATA
, &fd
, &needs_close
, NULL
, NULL
))
2339 int res
= recv( fd
, tmpbuf
, size
, MSG_PEEK
);
2340 info
->MessagesAvailable
= (res
> 0);
2341 info
->NextMessageSize
= (res
>= 0) ? res
: MAILSLOT_NO_MESSAGE
;
2342 if (needs_close
) close( fd
);
2344 RtlFreeHeap( GetProcessHeap(), 0, tmpbuf
);
2349 case FilePipeInformation
:
2351 FILE_PIPE_INFORMATION
* pi
= ptr
;
2353 SERVER_START_REQ( get_named_pipe_info
)
2355 req
->handle
= wine_server_obj_handle( hFile
);
2356 if (!(io
->u
.Status
= wine_server_call( req
)))
2358 pi
->ReadMode
= (reply
->flags
& NAMED_PIPE_MESSAGE_STREAM_READ
) ?
2359 FILE_PIPE_MESSAGE_MODE
: FILE_PIPE_BYTE_STREAM_MODE
;
2360 pi
->CompletionMode
= (reply
->flags
& NAMED_PIPE_NONBLOCKING_MODE
) ?
2361 FILE_PIPE_COMPLETE_OPERATION
: FILE_PIPE_QUEUE_OPERATION
;
2367 case FilePipeLocalInformation
:
2369 FILE_PIPE_LOCAL_INFORMATION
* pli
= ptr
;
2371 SERVER_START_REQ( get_named_pipe_info
)
2373 req
->handle
= wine_server_obj_handle( hFile
);
2374 if (!(io
->u
.Status
= wine_server_call( req
)))
2376 pli
->NamedPipeType
= (reply
->flags
& NAMED_PIPE_MESSAGE_STREAM_WRITE
) ?
2377 FILE_PIPE_TYPE_MESSAGE
: FILE_PIPE_TYPE_BYTE
;
2378 switch (reply
->sharing
)
2380 case FILE_SHARE_READ
:
2381 pli
->NamedPipeConfiguration
= FILE_PIPE_OUTBOUND
;
2383 case FILE_SHARE_WRITE
:
2384 pli
->NamedPipeConfiguration
= FILE_PIPE_INBOUND
;
2386 case FILE_SHARE_READ
| FILE_SHARE_WRITE
:
2387 pli
->NamedPipeConfiguration
= FILE_PIPE_FULL_DUPLEX
;
2390 pli
->MaximumInstances
= reply
->maxinstances
;
2391 pli
->CurrentInstances
= reply
->instances
;
2392 pli
->InboundQuota
= reply
->insize
;
2393 pli
->ReadDataAvailable
= 0; /* FIXME */
2394 pli
->OutboundQuota
= reply
->outsize
;
2395 pli
->WriteQuotaAvailable
= 0; /* FIXME */
2396 pli
->NamedPipeState
= 0; /* FIXME */
2397 pli
->NamedPipeEnd
= (reply
->flags
& NAMED_PIPE_SERVER_END
) ?
2398 FILE_PIPE_SERVER_END
: FILE_PIPE_CLIENT_END
;
2404 case FileNameInformation
:
2406 FILE_NAME_INFORMATION
*info
= ptr
;
2407 ANSI_STRING unix_name
;
2409 if (!(io
->u
.Status
= server_get_unix_name( hFile
, &unix_name
)))
2411 LONG name_len
= len
- FIELD_OFFSET(FILE_NAME_INFORMATION
, FileName
);
2412 io
->u
.Status
= fill_name_info( &unix_name
, info
, &name_len
);
2413 RtlFreeAnsiString( &unix_name
);
2414 io
->Information
= FIELD_OFFSET(FILE_NAME_INFORMATION
, FileName
) + name_len
;
2418 case FileNetworkOpenInformation
:
2420 FILE_NETWORK_OPEN_INFORMATION
*info
= ptr
;
2421 ANSI_STRING unix_name
;
2423 if (!(io
->u
.Status
= server_get_unix_name( hFile
, &unix_name
)))
2428 if (get_file_info( unix_name
.Buffer
, &st
, &attributes
) == -1)
2429 io
->u
.Status
= FILE_GetNtStatus();
2430 else if (!S_ISREG(st
.st_mode
) && !S_ISDIR(st
.st_mode
))
2431 io
->u
.Status
= STATUS_INVALID_INFO_CLASS
;
2434 FILE_BASIC_INFORMATION basic
;
2435 FILE_STANDARD_INFORMATION std
;
2437 fill_file_info( &st
, attributes
, &basic
, FileBasicInformation
);
2438 fill_file_info( &st
, attributes
, &std
, FileStandardInformation
);
2440 info
->CreationTime
= basic
.CreationTime
;
2441 info
->LastAccessTime
= basic
.LastAccessTime
;
2442 info
->LastWriteTime
= basic
.LastWriteTime
;
2443 info
->ChangeTime
= basic
.ChangeTime
;
2444 info
->AllocationSize
= std
.AllocationSize
;
2445 info
->EndOfFile
= std
.EndOfFile
;
2446 info
->FileAttributes
= basic
.FileAttributes
;
2448 RtlFreeAnsiString( &unix_name
);
2453 FIXME("Unsupported class (%d)\n", class);
2454 io
->u
.Status
= STATUS_NOT_IMPLEMENTED
;
2457 if (needs_close
) close( fd
);
2458 if (io
->u
.Status
== STATUS_SUCCESS
&& !io
->Information
) io
->Information
= info_sizes
[class];
2459 return io
->u
.Status
;
2462 /******************************************************************************
2463 * NtSetInformationFile [NTDLL.@]
2464 * ZwSetInformationFile [NTDLL.@]
2466 * Set information about an open file handle.
2469 * handle [I] Handle returned from ZwOpenFile() or ZwCreateFile()
2470 * io [O] Receives information about the operation on return
2471 * ptr [I] Source for file information
2472 * len [I] Size of FileInformation
2473 * class [I] Type of file information to set
2476 * Success: 0. io is updated.
2477 * Failure: An NTSTATUS error code describing the error.
2479 NTSTATUS WINAPI
NtSetInformationFile(HANDLE handle
, PIO_STATUS_BLOCK io
,
2480 PVOID ptr
, ULONG len
, FILE_INFORMATION_CLASS
class)
2482 int fd
, needs_close
;
2484 TRACE("(%p,%p,%p,0x%08x,0x%08x)\n", handle
, io
, ptr
, len
, class);
2486 io
->u
.Status
= STATUS_SUCCESS
;
2489 case FileBasicInformation
:
2490 if (len
>= sizeof(FILE_BASIC_INFORMATION
))
2493 const FILE_BASIC_INFORMATION
*info
= ptr
;
2495 if ((io
->u
.Status
= server_get_unix_fd( handle
, 0, &fd
, &needs_close
, NULL
, NULL
)))
2496 return io
->u
.Status
;
2498 if (info
->LastAccessTime
.QuadPart
|| info
->LastWriteTime
.QuadPart
)
2499 io
->u
.Status
= set_file_times( fd
, &info
->LastWriteTime
, &info
->LastAccessTime
);
2501 if (io
->u
.Status
== STATUS_SUCCESS
&& info
->FileAttributes
)
2503 if (fstat( fd
, &st
) == -1) io
->u
.Status
= FILE_GetNtStatus();
2506 if (info
->FileAttributes
& FILE_ATTRIBUTE_READONLY
)
2508 if (S_ISDIR( st
.st_mode
))
2509 WARN("FILE_ATTRIBUTE_READONLY ignored for directory.\n");
2511 st
.st_mode
&= ~0222; /* clear write permission bits */
2515 /* add write permission only where we already have read permission */
2516 st
.st_mode
|= (0600 | ((st
.st_mode
& 044) >> 1)) & (~FILE_umask
);
2518 if (fchmod( fd
, st
.st_mode
) == -1) io
->u
.Status
= FILE_GetNtStatus();
2522 if (needs_close
) close( fd
);
2524 else io
->u
.Status
= STATUS_INVALID_PARAMETER_3
;
2527 case FilePositionInformation
:
2528 if (len
>= sizeof(FILE_POSITION_INFORMATION
))
2530 const FILE_POSITION_INFORMATION
*info
= ptr
;
2532 if ((io
->u
.Status
= server_get_unix_fd( handle
, 0, &fd
, &needs_close
, NULL
, NULL
)))
2533 return io
->u
.Status
;
2535 if (lseek( fd
, info
->CurrentByteOffset
.QuadPart
, SEEK_SET
) == (off_t
)-1)
2536 io
->u
.Status
= FILE_GetNtStatus();
2538 if (needs_close
) close( fd
);
2540 else io
->u
.Status
= STATUS_INVALID_PARAMETER_3
;
2543 case FileEndOfFileInformation
:
2544 if (len
>= sizeof(FILE_END_OF_FILE_INFORMATION
))
2547 const FILE_END_OF_FILE_INFORMATION
*info
= ptr
;
2549 if ((io
->u
.Status
= server_get_unix_fd( handle
, 0, &fd
, &needs_close
, NULL
, NULL
)))
2550 return io
->u
.Status
;
2552 /* first try normal truncate */
2553 if (ftruncate( fd
, (off_t
)info
->EndOfFile
.QuadPart
) != -1) break;
2555 /* now check for the need to extend the file */
2556 if (fstat( fd
, &st
) != -1 && (off_t
)info
->EndOfFile
.QuadPart
> st
.st_size
)
2558 static const char zero
;
2560 /* extend the file one byte beyond the requested size and then truncate it */
2561 /* this should work around ftruncate implementations that can't extend files */
2562 if (pwrite( fd
, &zero
, 1, (off_t
)info
->EndOfFile
.QuadPart
) != -1 &&
2563 ftruncate( fd
, (off_t
)info
->EndOfFile
.QuadPart
) != -1) break;
2565 io
->u
.Status
= FILE_GetNtStatus();
2567 if (needs_close
) close( fd
);
2569 else io
->u
.Status
= STATUS_INVALID_PARAMETER_3
;
2572 case FilePipeInformation
:
2573 if (len
>= sizeof(FILE_PIPE_INFORMATION
))
2575 FILE_PIPE_INFORMATION
*info
= ptr
;
2577 if ((info
->CompletionMode
| info
->ReadMode
) & ~1)
2579 io
->u
.Status
= STATUS_INVALID_PARAMETER
;
2583 SERVER_START_REQ( set_named_pipe_info
)
2585 req
->handle
= wine_server_obj_handle( handle
);
2586 req
->flags
= (info
->CompletionMode
? NAMED_PIPE_NONBLOCKING_MODE
: 0) |
2587 (info
->ReadMode
? NAMED_PIPE_MESSAGE_STREAM_READ
: 0);
2588 io
->u
.Status
= wine_server_call( req
);
2592 else io
->u
.Status
= STATUS_INVALID_PARAMETER_3
;
2595 case FileMailslotSetInformation
:
2597 FILE_MAILSLOT_SET_INFORMATION
*info
= ptr
;
2599 SERVER_START_REQ( set_mailslot_info
)
2601 req
->handle
= wine_server_obj_handle( handle
);
2602 req
->flags
= MAILSLOT_SET_READ_TIMEOUT
;
2603 req
->read_timeout
= info
->ReadTimeout
.QuadPart
;
2604 io
->u
.Status
= wine_server_call( req
);
2610 case FileCompletionInformation
:
2611 if (len
>= sizeof(FILE_COMPLETION_INFORMATION
))
2613 FILE_COMPLETION_INFORMATION
*info
= ptr
;
2615 SERVER_START_REQ( set_completion_info
)
2617 req
->handle
= wine_server_obj_handle( handle
);
2618 req
->chandle
= wine_server_obj_handle( info
->CompletionPort
);
2619 req
->ckey
= info
->CompletionKey
;
2620 io
->u
.Status
= wine_server_call( req
);
2624 io
->u
.Status
= STATUS_INVALID_PARAMETER_3
;
2627 case FileAllInformation
:
2628 io
->u
.Status
= STATUS_INVALID_INFO_CLASS
;
2631 case FileValidDataLengthInformation
:
2632 if (len
>= sizeof(FILE_VALID_DATA_LENGTH_INFORMATION
))
2635 const FILE_VALID_DATA_LENGTH_INFORMATION
*info
= ptr
;
2637 if ((io
->u
.Status
= server_get_unix_fd( handle
, FILE_WRITE_DATA
, &fd
, &needs_close
, NULL
, NULL
)))
2638 return io
->u
.Status
;
2640 if (fstat( fd
, &st
) == -1) io
->u
.Status
= FILE_GetNtStatus();
2641 else if (info
->ValidDataLength
.QuadPart
<= 0 || (off_t
)info
->ValidDataLength
.QuadPart
> st
.st_size
)
2642 io
->u
.Status
= STATUS_INVALID_PARAMETER
;
2645 #ifdef HAVE_FALLOCATE
2646 if (fallocate( fd
, 0, 0, (off_t
)info
->ValidDataLength
.QuadPart
) == -1)
2648 NTSTATUS status
= FILE_GetNtStatus();
2649 if (status
== STATUS_NOT_SUPPORTED
) WARN( "fallocate not supported on this filesystem\n" );
2650 else io
->u
.Status
= status
;
2653 FIXME( "setting valid data length not supported\n" );
2656 if (needs_close
) close( fd
);
2658 else io
->u
.Status
= STATUS_INVALID_PARAMETER_3
;
2662 FIXME("Unsupported class (%d)\n", class);
2663 io
->u
.Status
= STATUS_NOT_IMPLEMENTED
;
2666 io
->Information
= 0;
2667 return io
->u
.Status
;
2671 /******************************************************************************
2672 * NtQueryFullAttributesFile (NTDLL.@)
2674 NTSTATUS WINAPI
NtQueryFullAttributesFile( const OBJECT_ATTRIBUTES
*attr
,
2675 FILE_NETWORK_OPEN_INFORMATION
*info
)
2677 ANSI_STRING unix_name
;
2680 if (!(status
= nt_to_unix_file_name_attr( attr
, &unix_name
, FILE_OPEN
)))
2685 if (get_file_info( unix_name
.Buffer
, &st
, &attributes
) == -1)
2686 status
= FILE_GetNtStatus();
2687 else if (!S_ISREG(st
.st_mode
) && !S_ISDIR(st
.st_mode
))
2688 status
= STATUS_INVALID_INFO_CLASS
;
2691 FILE_BASIC_INFORMATION basic
;
2692 FILE_STANDARD_INFORMATION std
;
2694 fill_file_info( &st
, attributes
, &basic
, FileBasicInformation
);
2695 fill_file_info( &st
, attributes
, &std
, FileStandardInformation
);
2697 info
->CreationTime
= basic
.CreationTime
;
2698 info
->LastAccessTime
= basic
.LastAccessTime
;
2699 info
->LastWriteTime
= basic
.LastWriteTime
;
2700 info
->ChangeTime
= basic
.ChangeTime
;
2701 info
->AllocationSize
= std
.AllocationSize
;
2702 info
->EndOfFile
= std
.EndOfFile
;
2703 info
->FileAttributes
= basic
.FileAttributes
;
2704 if (DIR_is_hidden_file( attr
->ObjectName
))
2705 info
->FileAttributes
|= FILE_ATTRIBUTE_HIDDEN
;
2707 RtlFreeAnsiString( &unix_name
);
2709 else WARN("%s not found (%x)\n", debugstr_us(attr
->ObjectName
), status
);
2714 /******************************************************************************
2715 * NtQueryAttributesFile (NTDLL.@)
2716 * ZwQueryAttributesFile (NTDLL.@)
2718 NTSTATUS WINAPI
NtQueryAttributesFile( const OBJECT_ATTRIBUTES
*attr
, FILE_BASIC_INFORMATION
*info
)
2720 ANSI_STRING unix_name
;
2723 if (!(status
= nt_to_unix_file_name_attr( attr
, &unix_name
, FILE_OPEN
)))
2728 if (get_file_info( unix_name
.Buffer
, &st
, &attributes
) == -1)
2729 status
= FILE_GetNtStatus();
2730 else if (!S_ISREG(st
.st_mode
) && !S_ISDIR(st
.st_mode
))
2731 status
= STATUS_INVALID_INFO_CLASS
;
2734 status
= fill_file_info( &st
, attributes
, info
, FileBasicInformation
);
2735 if (DIR_is_hidden_file( attr
->ObjectName
))
2736 info
->FileAttributes
|= FILE_ATTRIBUTE_HIDDEN
;
2738 RtlFreeAnsiString( &unix_name
);
2740 else WARN("%s not found (%x)\n", debugstr_us(attr
->ObjectName
), status
);
2745 #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__DragonFly__) || defined(__APPLE__)
2746 /* helper for FILE_GetDeviceInfo to hide some platform differences in fstatfs */
2747 static inline void get_device_info_fstatfs( FILE_FS_DEVICE_INFORMATION
*info
, const char *fstypename
,
2748 unsigned int flags
)
2750 if (!strcmp("cd9660", fstypename
) || !strcmp("udf", fstypename
))
2752 info
->DeviceType
= FILE_DEVICE_CD_ROM_FILE_SYSTEM
;
2753 /* Don't assume read-only, let the mount options set it below */
2754 info
->Characteristics
|= FILE_REMOVABLE_MEDIA
;
2756 else if (!strcmp("nfs", fstypename
) || !strcmp("nwfs", fstypename
) ||
2757 !strcmp("smbfs", fstypename
) || !strcmp("afpfs", fstypename
))
2759 info
->DeviceType
= FILE_DEVICE_NETWORK_FILE_SYSTEM
;
2760 info
->Characteristics
|= FILE_REMOTE_DEVICE
;
2762 else if (!strcmp("procfs", fstypename
))
2763 info
->DeviceType
= FILE_DEVICE_VIRTUAL_DISK
;
2765 info
->DeviceType
= FILE_DEVICE_DISK_FILE_SYSTEM
;
2767 if (flags
& MNT_RDONLY
)
2768 info
->Characteristics
|= FILE_READ_ONLY_DEVICE
;
2770 if (!(flags
& MNT_LOCAL
))
2772 info
->DeviceType
= FILE_DEVICE_NETWORK_FILE_SYSTEM
;
2773 info
->Characteristics
|= FILE_REMOTE_DEVICE
;
2778 static inline BOOL
is_device_placeholder( int fd
)
2780 static const char wine_placeholder
[] = "Wine device placeholder";
2781 char buffer
[sizeof(wine_placeholder
)-1];
2783 if (pread( fd
, buffer
, sizeof(wine_placeholder
) - 1, 0 ) != sizeof(wine_placeholder
) - 1)
2785 return !memcmp( buffer
, wine_placeholder
, sizeof(wine_placeholder
) - 1 );
2788 /******************************************************************************
2791 * Implementation of the FileFsDeviceInformation query for NtQueryVolumeInformationFile.
2793 static NTSTATUS
get_device_info( int fd
, FILE_FS_DEVICE_INFORMATION
*info
)
2797 info
->Characteristics
= 0;
2798 if (fstat( fd
, &st
) < 0) return FILE_GetNtStatus();
2799 if (S_ISCHR( st
.st_mode
))
2801 info
->DeviceType
= FILE_DEVICE_UNKNOWN
;
2803 switch(major(st
.st_rdev
))
2806 info
->DeviceType
= FILE_DEVICE_NULL
;
2809 info
->DeviceType
= FILE_DEVICE_SERIAL_PORT
;
2812 info
->DeviceType
= FILE_DEVICE_PARALLEL_PORT
;
2814 case SCSI_TAPE_MAJOR
:
2815 info
->DeviceType
= FILE_DEVICE_TAPE
;
2820 else if (S_ISBLK( st
.st_mode
))
2822 info
->DeviceType
= FILE_DEVICE_DISK
;
2824 else if (S_ISFIFO( st
.st_mode
) || S_ISSOCK( st
.st_mode
))
2826 info
->DeviceType
= FILE_DEVICE_NAMED_PIPE
;
2828 else if (is_device_placeholder( fd
))
2830 info
->DeviceType
= FILE_DEVICE_DISK
;
2832 else /* regular file or directory */
2834 #if defined(linux) && defined(HAVE_FSTATFS)
2837 /* check for floppy disk */
2838 if (major(st
.st_dev
) == FLOPPY_MAJOR
)
2839 info
->Characteristics
|= FILE_REMOVABLE_MEDIA
;
2841 if (fstatfs( fd
, &stfs
) < 0) stfs
.f_type
= 0;
2842 switch (stfs
.f_type
)
2844 case 0x9660: /* iso9660 */
2845 case 0x9fa1: /* supermount */
2846 case 0x15013346: /* udf */
2847 info
->DeviceType
= FILE_DEVICE_CD_ROM_FILE_SYSTEM
;
2848 info
->Characteristics
|= FILE_REMOVABLE_MEDIA
|FILE_READ_ONLY_DEVICE
;
2850 case 0x6969: /* nfs */
2851 case 0x517B: /* smbfs */
2852 case 0x564c: /* ncpfs */
2853 info
->DeviceType
= FILE_DEVICE_NETWORK_FILE_SYSTEM
;
2854 info
->Characteristics
|= FILE_REMOTE_DEVICE
;
2856 case 0x01021994: /* tmpfs */
2857 case 0x28cd3d45: /* cramfs */
2858 case 0x1373: /* devfs */
2859 case 0x9fa0: /* procfs */
2860 info
->DeviceType
= FILE_DEVICE_VIRTUAL_DISK
;
2863 info
->DeviceType
= FILE_DEVICE_DISK_FILE_SYSTEM
;
2866 #elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__OpenBSD__) || defined(__DragonFly__) || defined(__APPLE__)
2869 if (fstatfs( fd
, &stfs
) < 0)
2870 info
->DeviceType
= FILE_DEVICE_DISK_FILE_SYSTEM
;
2872 get_device_info_fstatfs( info
, stfs
.f_fstypename
, stfs
.f_flags
);
2873 #elif defined(__NetBSD__)
2874 struct statvfs stfs
;
2876 if (fstatvfs( fd
, &stfs
) < 0)
2877 info
->DeviceType
= FILE_DEVICE_DISK_FILE_SYSTEM
;
2879 get_device_info_fstatfs( info
, stfs
.f_fstypename
, stfs
.f_flag
);
2881 /* Use dkio to work out device types */
2883 # include <sys/dkio.h>
2884 # include <sys/vtoc.h>
2885 struct dk_cinfo dkinf
;
2886 int retval
= ioctl(fd
, DKIOCINFO
, &dkinf
);
2888 WARN("Unable to get disk device type information - assuming a disk like device\n");
2889 info
->DeviceType
= FILE_DEVICE_DISK_FILE_SYSTEM
;
2891 switch (dkinf
.dki_ctype
)
2894 info
->DeviceType
= FILE_DEVICE_CD_ROM_FILE_SYSTEM
;
2895 info
->Characteristics
|= FILE_REMOVABLE_MEDIA
|FILE_READ_ONLY_DEVICE
;
2899 case DKC_INTEL82072
:
2900 case DKC_INTEL82077
:
2901 info
->DeviceType
= FILE_DEVICE_DISK_FILE_SYSTEM
;
2902 info
->Characteristics
|= FILE_REMOVABLE_MEDIA
;
2905 info
->DeviceType
= FILE_DEVICE_VIRTUAL_DISK
;
2908 info
->DeviceType
= FILE_DEVICE_DISK_FILE_SYSTEM
;
2913 if (!warned
++) FIXME( "device info not properly supported on this platform\n" );
2914 info
->DeviceType
= FILE_DEVICE_DISK_FILE_SYSTEM
;
2916 info
->Characteristics
|= FILE_DEVICE_IS_MOUNTED
;
2918 return STATUS_SUCCESS
;
2922 /******************************************************************************
2923 * NtQueryVolumeInformationFile [NTDLL.@]
2924 * ZwQueryVolumeInformationFile [NTDLL.@]
2926 * Get volume information for an open file handle.
2929 * handle [I] Handle returned from ZwOpenFile() or ZwCreateFile()
2930 * io [O] Receives information about the operation on return
2931 * buffer [O] Destination for volume information
2932 * length [I] Size of FsInformation
2933 * info_class [I] Type of volume information to set
2936 * Success: 0. io and buffer are updated.
2937 * Failure: An NTSTATUS error code describing the error.
2939 NTSTATUS WINAPI
NtQueryVolumeInformationFile( HANDLE handle
, PIO_STATUS_BLOCK io
,
2940 PVOID buffer
, ULONG length
,
2941 FS_INFORMATION_CLASS info_class
)
2943 int fd
, needs_close
;
2947 if ((io
->u
.Status
= server_get_unix_fd( handle
, 0, &fd
, &needs_close
, NULL
, NULL
)) != STATUS_SUCCESS
)
2948 return io
->u
.Status
;
2950 io
->u
.Status
= STATUS_NOT_IMPLEMENTED
;
2951 io
->Information
= 0;
2953 switch( info_class
)
2955 case FileFsVolumeInformation
:
2956 if (!once
++) FIXME( "%p: volume info not supported\n", handle
);
2958 case FileFsLabelInformation
:
2959 FIXME( "%p: label info not supported\n", handle
);
2961 case FileFsSizeInformation
:
2962 if (length
< sizeof(FILE_FS_SIZE_INFORMATION
))
2963 io
->u
.Status
= STATUS_BUFFER_TOO_SMALL
;
2966 FILE_FS_SIZE_INFORMATION
*info
= buffer
;
2968 if (fstat( fd
, &st
) < 0)
2970 io
->u
.Status
= FILE_GetNtStatus();
2973 if (!S_ISREG(st
.st_mode
) && !S_ISDIR(st
.st_mode
))
2975 io
->u
.Status
= STATUS_INVALID_DEVICE_REQUEST
;
2980 /* Linux's fstatvfs is buggy */
2981 #if !defined(linux) || !defined(HAVE_FSTATFS)
2982 struct statvfs stfs
;
2984 if (fstatvfs( fd
, &stfs
) < 0)
2986 io
->u
.Status
= FILE_GetNtStatus();
2989 bsize
= stfs
.f_frsize
;
2992 if (fstatfs( fd
, &stfs
) < 0)
2994 io
->u
.Status
= FILE_GetNtStatus();
2997 bsize
= stfs
.f_bsize
;
2999 if (bsize
== 2048) /* assume CD-ROM */
3001 info
->BytesPerSector
= 2048;
3002 info
->SectorsPerAllocationUnit
= 1;
3006 info
->BytesPerSector
= 512;
3007 info
->SectorsPerAllocationUnit
= 8;
3009 info
->TotalAllocationUnits
.QuadPart
= bsize
* stfs
.f_blocks
/ (info
->BytesPerSector
* info
->SectorsPerAllocationUnit
);
3010 info
->AvailableAllocationUnits
.QuadPart
= bsize
* stfs
.f_bavail
/ (info
->BytesPerSector
* info
->SectorsPerAllocationUnit
);
3011 io
->Information
= sizeof(*info
);
3012 io
->u
.Status
= STATUS_SUCCESS
;
3016 case FileFsDeviceInformation
:
3017 if (length
< sizeof(FILE_FS_DEVICE_INFORMATION
))
3018 io
->u
.Status
= STATUS_BUFFER_TOO_SMALL
;
3021 FILE_FS_DEVICE_INFORMATION
*info
= buffer
;
3023 if ((io
->u
.Status
= get_device_info( fd
, info
)) == STATUS_SUCCESS
)
3024 io
->Information
= sizeof(*info
);
3027 case FileFsAttributeInformation
:
3028 if (length
< offsetof( FILE_FS_ATTRIBUTE_INFORMATION
, FileSystemName
[sizeof(ntfsW
)/sizeof(WCHAR
)] ))
3029 io
->u
.Status
= STATUS_BUFFER_TOO_SMALL
;
3032 FILE_FS_ATTRIBUTE_INFORMATION
*info
= buffer
;
3034 FIXME( "%p: faking attribute info\n", handle
);
3035 info
->FileSystemAttribute
= FILE_SUPPORTS_ENCRYPTION
| FILE_FILE_COMPRESSION
|
3036 FILE_PERSISTENT_ACLS
| FILE_UNICODE_ON_DISK
|
3037 FILE_CASE_PRESERVED_NAMES
| FILE_CASE_SENSITIVE_SEARCH
;
3038 info
->MaximumComponentNameLength
= MAXIMUM_FILENAME_LENGTH
- 1;
3039 info
->FileSystemNameLength
= sizeof(ntfsW
);
3040 memcpy(info
->FileSystemName
, ntfsW
, sizeof(ntfsW
));
3042 io
->Information
= sizeof(*info
);
3043 io
->u
.Status
= STATUS_SUCCESS
;
3046 case FileFsControlInformation
:
3047 FIXME( "%p: control info not supported\n", handle
);
3049 case FileFsFullSizeInformation
:
3050 FIXME( "%p: full size info not supported\n", handle
);
3052 case FileFsObjectIdInformation
:
3053 FIXME( "%p: object id info not supported\n", handle
);
3055 case FileFsMaximumInformation
:
3056 FIXME( "%p: maximum info not supported\n", handle
);
3059 io
->u
.Status
= STATUS_INVALID_PARAMETER
;
3062 if (needs_close
) close( fd
);
3063 return io
->u
.Status
;
3067 /******************************************************************
3068 * NtQueryEaFile (NTDLL.@)
3070 * Read extended attributes from NTFS files.
3073 * hFile [I] File handle, must be opened with FILE_READ_EA access
3074 * iosb [O] Receives information about the operation on return
3075 * buffer [O] Output buffer
3076 * length [I] Length of output buffer
3077 * single_entry [I] Only read and return one entry
3078 * ea_list [I] Optional list with names of EAs to return
3079 * ea_list_len [I] Length of ea_list in bytes
3080 * ea_index [I] Optional pointer to 1-based index of attribute to return
3081 * restart [I] restart EA scan
3084 * Success: 0. Atrributes read into buffer
3085 * Failure: An NTSTATUS error code describing the error.
3087 NTSTATUS WINAPI
NtQueryEaFile( HANDLE hFile
, PIO_STATUS_BLOCK iosb
, PVOID buffer
, ULONG length
,
3088 BOOLEAN single_entry
, PVOID ea_list
, ULONG ea_list_len
,
3089 PULONG ea_index
, BOOLEAN restart
)
3091 FIXME("(%p,%p,%p,%d,%d,%p,%d,%p,%d) stub\n",
3092 hFile
, iosb
, buffer
, length
, single_entry
, ea_list
,
3093 ea_list_len
, ea_index
, restart
);
3094 return STATUS_ACCESS_DENIED
;
3098 /******************************************************************
3099 * NtSetEaFile (NTDLL.@)
3101 * Update extended attributes for NTFS files.
3104 * hFile [I] File handle, must be opened with FILE_READ_EA access
3105 * iosb [O] Receives information about the operation on return
3106 * buffer [I] Buffer with EA information
3107 * length [I] Length of buffer
3110 * Success: 0. Attributes are updated
3111 * Failure: An NTSTATUS error code describing the error.
3113 NTSTATUS WINAPI
NtSetEaFile( HANDLE hFile
, PIO_STATUS_BLOCK iosb
, PVOID buffer
, ULONG length
)
3115 FIXME("(%p,%p,%p,%d) stub\n", hFile
, iosb
, buffer
, length
);
3116 return STATUS_ACCESS_DENIED
;
3120 /******************************************************************
3121 * NtFlushBuffersFile (NTDLL.@)
3123 * Flush any buffered data on an open file handle.
3126 * FileHandle [I] Handle returned from ZwOpenFile() or ZwCreateFile()
3127 * IoStatusBlock [O] Receives information about the operation on return
3130 * Success: 0. IoStatusBlock is updated.
3131 * Failure: An NTSTATUS error code describing the error.
3133 NTSTATUS WINAPI
NtFlushBuffersFile( HANDLE hFile
, IO_STATUS_BLOCK
* IoStatusBlock
)
3136 HANDLE hEvent
= NULL
;
3137 enum server_fd_type type
;
3138 int fd
, needs_close
;
3140 ret
= server_get_unix_fd( hFile
, FILE_WRITE_DATA
, &fd
, &needs_close
, &type
, NULL
);
3142 if (!ret
&& type
== FD_TYPE_SERIAL
)
3144 ret
= COMM_FlushBuffersFile( fd
);
3148 SERVER_START_REQ( flush_file
)
3150 req
->handle
= wine_server_obj_handle( hFile
);
3151 ret
= wine_server_call( req
);
3152 hEvent
= wine_server_ptr_handle( reply
->event
);
3157 ret
= NtWaitForSingleObject( hEvent
, FALSE
, NULL
);
3162 if (needs_close
) close( fd
);
3166 /******************************************************************
3167 * NtLockFile (NTDLL.@)
3171 NTSTATUS WINAPI
NtLockFile( HANDLE hFile
, HANDLE lock_granted_event
,
3172 PIO_APC_ROUTINE apc
, void* apc_user
,
3173 PIO_STATUS_BLOCK io_status
, PLARGE_INTEGER offset
,
3174 PLARGE_INTEGER count
, ULONG
* key
, BOOLEAN dont_wait
,
3180 static BOOLEAN warn
= TRUE
;
3182 if (apc
|| io_status
|| key
)
3184 FIXME("Unimplemented yet parameter\n");
3185 return STATUS_NOT_IMPLEMENTED
;
3188 if (apc_user
&& warn
)
3190 FIXME("I/O completion on lock not implemented yet\n");
3196 SERVER_START_REQ( lock_file
)
3198 req
->handle
= wine_server_obj_handle( hFile
);
3199 req
->offset
= offset
->QuadPart
;
3200 req
->count
= count
->QuadPart
;
3201 req
->shared
= !exclusive
;
3202 req
->wait
= !dont_wait
;
3203 ret
= wine_server_call( req
);
3204 handle
= wine_server_ptr_handle( reply
->handle
);
3205 async
= reply
->overlapped
;
3208 if (ret
!= STATUS_PENDING
)
3210 if (!ret
&& lock_granted_event
) NtSetEvent(lock_granted_event
, NULL
);
3216 FIXME( "Async I/O lock wait not implemented, might deadlock\n" );
3217 if (handle
) NtClose( handle
);
3218 return STATUS_PENDING
;
3222 NtWaitForSingleObject( handle
, FALSE
, NULL
);
3229 /* Unix lock conflict, sleep a bit and retry */
3230 time
.QuadPart
= 100 * (ULONGLONG
)10000;
3231 time
.QuadPart
= -time
.QuadPart
;
3232 NtDelayExecution( FALSE
, &time
);
3238 /******************************************************************
3239 * NtUnlockFile (NTDLL.@)
3243 NTSTATUS WINAPI
NtUnlockFile( HANDLE hFile
, PIO_STATUS_BLOCK io_status
,
3244 PLARGE_INTEGER offset
, PLARGE_INTEGER count
,
3249 TRACE( "%p %x%08x %x%08x\n",
3250 hFile
, offset
->u
.HighPart
, offset
->u
.LowPart
, count
->u
.HighPart
, count
->u
.LowPart
);
3252 if (io_status
|| key
)
3254 FIXME("Unimplemented yet parameter\n");
3255 return STATUS_NOT_IMPLEMENTED
;
3258 SERVER_START_REQ( unlock_file
)
3260 req
->handle
= wine_server_obj_handle( hFile
);
3261 req
->offset
= offset
->QuadPart
;
3262 req
->count
= count
->QuadPart
;
3263 status
= wine_server_call( req
);
3269 /******************************************************************
3270 * NtCreateNamedPipeFile (NTDLL.@)
3274 NTSTATUS WINAPI
NtCreateNamedPipeFile( PHANDLE handle
, ULONG access
,
3275 POBJECT_ATTRIBUTES attr
, PIO_STATUS_BLOCK iosb
,
3276 ULONG sharing
, ULONG dispo
, ULONG options
,
3277 ULONG pipe_type
, ULONG read_mode
,
3278 ULONG completion_mode
, ULONG max_inst
,
3279 ULONG inbound_quota
, ULONG outbound_quota
,
3280 PLARGE_INTEGER timeout
)
3282 struct security_descriptor
*sd
= NULL
;
3283 struct object_attributes objattr
;
3286 TRACE("(%p %x %s %p %x %d %x %d %d %d %d %d %d %p)\n",
3287 handle
, access
, debugstr_w(attr
->ObjectName
->Buffer
), iosb
, sharing
, dispo
,
3288 options
, pipe_type
, read_mode
, completion_mode
, max_inst
, inbound_quota
,
3289 outbound_quota
, timeout
);
3291 /* assume we only get relative timeout */
3292 if (timeout
->QuadPart
> 0)
3293 FIXME("Wrong time %s\n", wine_dbgstr_longlong(timeout
->QuadPart
));
3295 objattr
.rootdir
= wine_server_obj_handle( attr
->RootDirectory
);
3297 objattr
.name_len
= attr
->ObjectName
->Length
;
3299 status
= NTDLL_create_struct_sd( attr
->SecurityDescriptor
, &sd
, &objattr
.sd_len
);
3300 if (status
!= STATUS_SUCCESS
) return status
;
3302 SERVER_START_REQ( create_named_pipe
)
3304 req
->access
= access
;
3305 req
->attributes
= attr
->Attributes
;
3306 req
->options
= options
;
3307 req
->sharing
= sharing
;
3309 (pipe_type
? NAMED_PIPE_MESSAGE_STREAM_WRITE
: 0) |
3310 (read_mode
? NAMED_PIPE_MESSAGE_STREAM_READ
: 0) |
3311 (completion_mode
? NAMED_PIPE_NONBLOCKING_MODE
: 0);
3312 req
->maxinstances
= max_inst
;
3313 req
->outsize
= outbound_quota
;
3314 req
->insize
= inbound_quota
;
3315 req
->timeout
= timeout
->QuadPart
;
3316 wine_server_add_data( req
, &objattr
, sizeof(objattr
) );
3317 if (objattr
.sd_len
) wine_server_add_data( req
, sd
, objattr
.sd_len
);
3318 wine_server_add_data( req
, attr
->ObjectName
->Buffer
, attr
->ObjectName
->Length
);
3319 status
= wine_server_call( req
);
3320 if (!status
) *handle
= wine_server_ptr_handle( reply
->handle
);
3324 NTDLL_free_struct_sd( sd
);
3328 /******************************************************************
3329 * NtDeleteFile (NTDLL.@)
3333 NTSTATUS WINAPI
NtDeleteFile( POBJECT_ATTRIBUTES ObjectAttributes
)
3339 TRACE("%p\n", ObjectAttributes
);
3340 status
= NtCreateFile( &hFile
, GENERIC_READ
| GENERIC_WRITE
| DELETE
,
3341 ObjectAttributes
, &io
, NULL
, 0,
3342 FILE_SHARE_READ
| FILE_SHARE_WRITE
| FILE_SHARE_DELETE
,
3343 FILE_OPEN
, FILE_DELETE_ON_CLOSE
, NULL
, 0 );
3344 if (status
== STATUS_SUCCESS
) status
= NtClose(hFile
);
3348 /******************************************************************
3349 * NtCancelIoFileEx (NTDLL.@)
3353 NTSTATUS WINAPI
NtCancelIoFileEx( HANDLE hFile
, PIO_STATUS_BLOCK iosb
, PIO_STATUS_BLOCK io_status
)
3355 LARGE_INTEGER timeout
;
3357 TRACE("%p %p %p\n", hFile
, iosb
, io_status
);
3359 SERVER_START_REQ( cancel_async
)
3361 req
->handle
= wine_server_obj_handle( hFile
);
3362 req
->iosb
= wine_server_client_ptr( iosb
);
3363 req
->only_thread
= FALSE
;
3364 io_status
->u
.Status
= wine_server_call( req
);
3367 if (io_status
->u
.Status
)
3368 return io_status
->u
.Status
;
3370 /* Let some APC be run, so that we can run the remaining APCs on hFile
3371 * either the cancelation of the pending one, but also the execution
3372 * of the queued APC, but not yet run. This is needed to ensure proper
3373 * clean-up of allocated data.
3375 timeout
.QuadPart
= 0;
3376 NtDelayExecution( TRUE
, &timeout
);
3377 return io_status
->u
.Status
;
3380 /******************************************************************
3381 * NtCancelIoFile (NTDLL.@)
3385 NTSTATUS WINAPI
NtCancelIoFile( HANDLE hFile
, PIO_STATUS_BLOCK io_status
)
3387 LARGE_INTEGER timeout
;
3389 TRACE("%p %p\n", hFile
, io_status
);
3391 SERVER_START_REQ( cancel_async
)
3393 req
->handle
= wine_server_obj_handle( hFile
);
3395 req
->only_thread
= TRUE
;
3396 io_status
->u
.Status
= wine_server_call( req
);
3399 if (io_status
->u
.Status
)
3400 return io_status
->u
.Status
;
3402 /* Let some APC be run, so that we can run the remaining APCs on hFile
3403 * either the cancelation of the pending one, but also the execution
3404 * of the queued APC, but not yet run. This is needed to ensure proper
3405 * clean-up of allocated data.
3407 timeout
.QuadPart
= 0;
3408 NtDelayExecution( TRUE
, &timeout
);
3409 return io_status
->u
.Status
;
3412 /******************************************************************************
3413 * NtCreateMailslotFile [NTDLL.@]
3414 * ZwCreateMailslotFile [NTDLL.@]
3417 * pHandle [O] pointer to receive the handle created
3418 * DesiredAccess [I] access mode (read, write, etc)
3419 * ObjectAttributes [I] fully qualified NT path of the mailslot
3420 * IoStatusBlock [O] receives completion status and other info
3423 * MaxMessageSize [I]
3429 NTSTATUS WINAPI
NtCreateMailslotFile(PHANDLE pHandle
, ULONG DesiredAccess
,
3430 POBJECT_ATTRIBUTES attr
, PIO_STATUS_BLOCK IoStatusBlock
,
3431 ULONG CreateOptions
, ULONG MailslotQuota
, ULONG MaxMessageSize
,
3432 PLARGE_INTEGER TimeOut
)
3434 LARGE_INTEGER timeout
;
3437 TRACE("%p %08x %p %p %08x %08x %08x %p\n",
3438 pHandle
, DesiredAccess
, attr
, IoStatusBlock
,
3439 CreateOptions
, MailslotQuota
, MaxMessageSize
, TimeOut
);
3441 if (!pHandle
) return STATUS_ACCESS_VIOLATION
;
3442 if (!attr
) return STATUS_INVALID_PARAMETER
;
3443 if (!attr
->ObjectName
) return STATUS_OBJECT_PATH_SYNTAX_BAD
;
3446 * For a NULL TimeOut pointer set the default timeout value
3449 timeout
.QuadPart
= -1;
3451 timeout
.QuadPart
= TimeOut
->QuadPart
;
3453 SERVER_START_REQ( create_mailslot
)
3455 req
->access
= DesiredAccess
;
3456 req
->attributes
= attr
->Attributes
;
3457 req
->rootdir
= wine_server_obj_handle( attr
->RootDirectory
);
3458 req
->max_msgsize
= MaxMessageSize
;
3459 req
->read_timeout
= timeout
.QuadPart
;
3460 wine_server_add_data( req
, attr
->ObjectName
->Buffer
,
3461 attr
->ObjectName
->Length
);
3462 ret
= wine_server_call( req
);
3463 if( ret
== STATUS_SUCCESS
)
3464 *pHandle
= wine_server_ptr_handle( reply
->handle
);