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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 #include "wine/port.h"
30 #ifdef HAVE_SYS_ERRNO_H
31 #include <sys/errno.h>
33 #ifdef HAVE_LINUX_MAJOR_H
34 # include <linux/major.h>
36 #ifdef HAVE_SYS_STATVFS_H
37 # include <sys/statvfs.h>
39 #ifdef HAVE_SYS_PARAM_H
40 # include <sys/param.h>
42 #ifdef HAVE_SYS_TIME_H
43 # include <sys/time.h>
48 #ifdef STATFS_DEFINED_BY_SYS_VFS
51 # ifdef STATFS_DEFINED_BY_SYS_MOUNT
52 # include <sys/mount.h>
54 # ifdef STATFS_DEFINED_BY_SYS_STATFS
55 # include <sys/statfs.h>
60 #ifdef HAVE_IOKIT_IOKITLIB_H
61 # include <IOKit/IOKitLib.h>
62 # include <CoreFoundation/CFNumber.h> /* for kCFBooleanTrue, kCFBooleanFalse */
66 #define NONAMELESSUNION
67 #define NONAMELESSSTRUCT
69 #define WIN32_NO_STATUS
70 #include "wine/unicode.h"
71 #include "wine/debug.h"
73 #include "wine/server.h"
74 #include "ntdll_misc.h"
79 WINE_DEFAULT_DEBUG_CHANNEL(ntdll
);
81 mode_t FILE_umask
= 0;
83 #define SECSPERDAY 86400
84 #define SECS_1601_TO_1970 ((369 * 365 + 89) * (ULONGLONG)SECSPERDAY)
86 /**************************************************************************
87 * NtOpenFile [NTDLL.@]
88 * ZwOpenFile [NTDLL.@]
93 * handle [O] Variable that receives the file handle on return
94 * access [I] Access desired by the caller to the file
95 * attr [I] Structure describing the file to be opened
96 * io [O] Receives details about the result of the operation
97 * sharing [I] Type of shared access the caller requires
98 * options [I] Options for the file open
101 * Success: 0. FileHandle and IoStatusBlock are updated.
102 * Failure: An NTSTATUS error code describing the error.
104 NTSTATUS WINAPI
NtOpenFile( PHANDLE handle
, ACCESS_MASK access
,
105 POBJECT_ATTRIBUTES attr
, PIO_STATUS_BLOCK io
,
106 ULONG sharing
, ULONG options
)
108 return NtCreateFile( handle
, access
, attr
, io
, NULL
, 0,
109 sharing
, FILE_OPEN
, options
, NULL
, 0 );
112 /**************************************************************************
113 * NtCreateFile [NTDLL.@]
114 * ZwCreateFile [NTDLL.@]
116 * Either create a new file or directory, or open an existing file, device,
117 * directory or volume.
120 * handle [O] Points to a variable which receives the file handle on return
121 * access [I] Desired access to the file
122 * attr [I] Structure describing the file
123 * io [O] Receives information about the operation on return
124 * alloc_size [I] Initial size of the file in bytes
125 * attributes [I] Attributes to create the file with
126 * sharing [I] Type of shared access the caller would like to the file
127 * disposition [I] Specifies what to do, depending on whether the file already exists
128 * options [I] Options for creating a new file
129 * ea_buffer [I] Pointer to an extended attributes buffer
130 * ea_length [I] Length of ea_buffer
133 * Success: 0. handle and io are updated.
134 * Failure: An NTSTATUS error code describing the error.
136 NTSTATUS WINAPI
NtCreateFile( PHANDLE handle
, ACCESS_MASK access
, POBJECT_ATTRIBUTES attr
,
137 PIO_STATUS_BLOCK io
, PLARGE_INTEGER alloc_size
,
138 ULONG attributes
, ULONG sharing
, ULONG disposition
,
139 ULONG options
, PVOID ea_buffer
, ULONG ea_length
)
141 static const WCHAR pipeW
[] = {'\\','?','?','\\','p','i','p','e','\\'};
142 static const WCHAR mailslotW
[] = {'\\','?','?','\\','M','A','I','L','S','L','O','T','\\'};
143 ANSI_STRING unix_name
;
146 TRACE("handle=%p access=%08lx name=%s objattr=%08lx root=%p sec=%p io=%p alloc_size=%p\n"
147 "attr=%08lx sharing=%08lx disp=%ld options=%08lx ea=%p.0x%08lx\n",
148 handle
, access
, debugstr_us(attr
->ObjectName
), attr
->Attributes
,
149 attr
->RootDirectory
, attr
->SecurityDescriptor
, io
, alloc_size
,
150 attributes
, sharing
, disposition
, options
, ea_buffer
, ea_length
);
152 if (!attr
|| !attr
->ObjectName
) return STATUS_INVALID_PARAMETER
;
154 if (alloc_size
) FIXME( "alloc_size not supported\n" );
156 /* check for named pipe */
158 if (attr
->ObjectName
->Length
> sizeof(pipeW
) &&
159 !memicmpW( attr
->ObjectName
->Buffer
, pipeW
, sizeof(pipeW
)/sizeof(WCHAR
) ))
161 SERVER_START_REQ( open_named_pipe
)
163 req
->access
= access
;
164 req
->attributes
= (attr
) ? attr
->Attributes
: 0;
165 req
->rootdir
= attr
? attr
->RootDirectory
: 0;
166 req
->flags
= options
;
167 wine_server_add_data( req
, attr
->ObjectName
->Buffer
,
168 attr
->ObjectName
->Length
);
169 io
->u
.Status
= wine_server_call( req
);
170 *handle
= reply
->handle
;
176 /* check for mailslot */
178 if (attr
->ObjectName
->Length
> sizeof(mailslotW
) &&
179 !memicmpW( attr
->ObjectName
->Buffer
, mailslotW
, sizeof(mailslotW
)/sizeof(WCHAR
) ))
181 SERVER_START_REQ( open_mailslot
)
183 req
->access
= access
& GENERIC_WRITE
;
184 req
->attributes
= (attr
) ? attr
->Attributes
: 0;
185 req
->rootdir
= attr
? attr
->RootDirectory
: 0;
186 req
->sharing
= sharing
;
187 wine_server_add_data( req
, attr
->ObjectName
->Buffer
,
188 attr
->ObjectName
->Length
);
189 io
->u
.Status
= wine_server_call( req
);
190 *handle
= reply
->handle
;
196 if (attr
->RootDirectory
)
198 FIXME( "RootDirectory %p not supported\n", attr
->RootDirectory
);
199 return STATUS_OBJECT_NAME_NOT_FOUND
;
202 io
->u
.Status
= wine_nt_to_unix_file_name( attr
->ObjectName
, &unix_name
, disposition
,
203 !(attr
->Attributes
& OBJ_CASE_INSENSITIVE
) );
205 if (io
->u
.Status
== STATUS_NO_SUCH_FILE
&&
206 disposition
!= FILE_OPEN
&& disposition
!= FILE_OVERWRITE
)
209 io
->u
.Status
= STATUS_SUCCESS
;
212 if (io
->u
.Status
== STATUS_SUCCESS
)
214 SERVER_START_REQ( create_file
)
216 req
->access
= access
;
217 req
->attributes
= attr
->Attributes
;
218 req
->sharing
= sharing
;
219 req
->create
= disposition
;
220 req
->options
= options
;
221 req
->attrs
= attributes
;
222 wine_server_add_data( req
, unix_name
.Buffer
, unix_name
.Length
);
223 io
->u
.Status
= wine_server_call( req
);
224 *handle
= reply
->handle
;
227 RtlFreeAnsiString( &unix_name
);
229 else WARN("%s not found (%lx)\n", debugstr_us(attr
->ObjectName
), io
->u
.Status
);
231 if (io
->u
.Status
== STATUS_SUCCESS
)
233 if (created
) io
->Information
= FILE_CREATED
;
234 else switch(disposition
)
237 io
->Information
= FILE_SUPERSEDED
;
240 io
->Information
= FILE_CREATED
;
244 io
->Information
= FILE_OPENED
;
247 case FILE_OVERWRITE_IF
:
248 io
->Information
= FILE_OVERWRITTEN
;
256 /***********************************************************************
257 * Asynchronous file I/O *
259 static void WINAPI
FILE_AsyncReadService(void*, PIO_STATUS_BLOCK
, ULONG
);
260 static void WINAPI
FILE_AsyncWriteService(void*, PIO_STATUS_BLOCK
, ULONG
);
262 typedef struct async_fileio
270 int queue_apc_on_error
;
276 static void fileio_terminate(async_fileio
*fileio
, IO_STATUS_BLOCK
* iosb
)
278 TRACE("data: %p\n", fileio
);
280 wine_server_release_fd( fileio
->handle
, fileio
->fd
);
281 if ( fileio
->event
!= INVALID_HANDLE_VALUE
)
282 NtSetEvent( fileio
->event
, NULL
);
285 (iosb
->u
.Status
== STATUS_SUCCESS
|| fileio
->queue_apc_on_error
))
286 fileio
->apc( fileio
->apc_user
, iosb
, iosb
->Information
);
288 RtlFreeHeap( GetProcessHeap(), 0, fileio
);
292 static ULONG
fileio_queue_async(async_fileio
* fileio
, IO_STATUS_BLOCK
* iosb
,
295 PIO_APC_ROUTINE apc
= do_read
? FILE_AsyncReadService
: FILE_AsyncWriteService
;
298 SERVER_START_REQ( register_async
)
300 req
->handle
= fileio
->handle
;
303 req
->io_user
= fileio
;
304 req
->type
= do_read
? ASYNC_TYPE_READ
: ASYNC_TYPE_WRITE
;
305 req
->count
= (fileio
->count
< iosb
->Information
) ?
306 0 : fileio
->count
- iosb
->Information
;
307 status
= wine_server_call( req
);
311 if ( status
) iosb
->u
.Status
= status
;
312 if ( iosb
->u
.Status
!= STATUS_PENDING
)
314 (apc
)( fileio
, iosb
, iosb
->u
.Status
);
315 return iosb
->u
.Status
;
317 NtCurrentTeb()->num_async_io
++;
318 return STATUS_SUCCESS
;
321 /***********************************************************************
322 * FILE_GetNtStatus(void)
324 * Retrieve the Nt Status code from errno.
325 * Try to be consistent with FILE_SetDosError().
327 NTSTATUS
FILE_GetNtStatus(void)
331 TRACE( "errno = %d\n", errno
);
334 case EAGAIN
: return STATUS_SHARING_VIOLATION
;
335 case EBADF
: return STATUS_INVALID_HANDLE
;
336 case EBUSY
: return STATUS_DEVICE_BUSY
;
337 case ENOSPC
: return STATUS_DISK_FULL
;
340 case EACCES
: return STATUS_ACCESS_DENIED
;
341 case ENOTDIR
: return STATUS_OBJECT_PATH_NOT_FOUND
;
342 case ENOENT
: return STATUS_OBJECT_NAME_NOT_FOUND
;
343 case EISDIR
: return STATUS_FILE_IS_A_DIRECTORY
;
345 case ENFILE
: return STATUS_TOO_MANY_OPENED_FILES
;
346 case EINVAL
: return STATUS_INVALID_PARAMETER
;
347 case ENOTEMPTY
: return STATUS_DIRECTORY_NOT_EMPTY
;
348 case EPIPE
: return STATUS_PIPE_BROKEN
;
349 case EIO
: return STATUS_DEVICE_NOT_READY
;
351 case ENOMEDIUM
: return STATUS_NO_MEDIA_IN_DEVICE
;
354 case EOPNOTSUPP
:return STATUS_NOT_SUPPORTED
;
355 case ECONNRESET
:return STATUS_PIPE_DISCONNECTED
;
356 case ENOEXEC
: /* ?? */
357 case ESPIPE
: /* ?? */
358 case EEXIST
: /* ?? */
360 FIXME( "Converting errno %d to STATUS_UNSUCCESSFUL\n", err
);
361 return STATUS_UNSUCCESSFUL
;
365 /***********************************************************************
366 * FILE_AsyncReadService (INTERNAL)
368 * This function is called while the client is waiting on the
369 * server, so we can't make any server calls here.
371 static void WINAPI
FILE_AsyncReadService(void *user
, PIO_STATUS_BLOCK iosb
, ULONG status
)
373 async_fileio
*fileio
= (async_fileio
*)user
;
375 int already
= iosb
->Information
;
377 TRACE("%p %p 0x%lx\n", iosb
, fileio
->buffer
, status
);
381 case STATUS_ALERTED
: /* got some new data */
382 if (iosb
->u
.Status
!= STATUS_PENDING
) FIXME("unexpected status %08lx\n", iosb
->u
.Status
);
383 /* check to see if the data is ready (non-blocking) */
384 if ( fileio
->avail_mode
)
385 result
= read(fileio
->fd
, &fileio
->buffer
[already
],
386 fileio
->count
- already
);
389 result
= pread(fileio
->fd
, &fileio
->buffer
[already
],
390 fileio
->count
- already
,
391 fileio
->offset
+ already
);
392 if ((result
< 0) && (errno
== ESPIPE
))
393 result
= read(fileio
->fd
, &fileio
->buffer
[already
],
394 fileio
->count
- already
);
399 if (errno
== EAGAIN
|| errno
== EINTR
)
401 TRACE("Deferred read %d\n", errno
);
402 iosb
->u
.Status
= STATUS_PENDING
;
404 else /* check to see if the transfer is complete */
405 iosb
->u
.Status
= FILE_GetNtStatus();
407 else if (result
== 0)
409 iosb
->u
.Status
= iosb
->Information
? STATUS_SUCCESS
: STATUS_END_OF_FILE
;
413 iosb
->Information
+= result
;
414 if (iosb
->Information
>= fileio
->count
|| fileio
->avail_mode
)
415 iosb
->u
.Status
= STATUS_SUCCESS
;
418 /* if we only have to read the available data, and none is available,
419 * simply cancel the request. If data was available, it has been read
420 * while in by previous call (NtDelayExecution)
422 iosb
->u
.Status
= (fileio
->avail_mode
) ? STATUS_SUCCESS
: STATUS_PENDING
;
425 TRACE("read %d more bytes %ld/%d so far (%s)\n",
426 result
, iosb
->Information
, fileio
->count
,
427 (iosb
->u
.Status
== STATUS_SUCCESS
) ? "success" : "pending");
429 /* queue another async operation ? */
430 if (iosb
->u
.Status
== STATUS_PENDING
)
431 fileio_queue_async(fileio
, iosb
, TRUE
);
433 fileio_terminate(fileio
, iosb
);
436 iosb
->u
.Status
= status
;
437 fileio_terminate(fileio
, iosb
);
443 /******************************************************************************
444 * NtReadFile [NTDLL.@]
445 * ZwReadFile [NTDLL.@]
447 * Read from an open file handle.
450 * FileHandle [I] Handle returned from ZwOpenFile() or ZwCreateFile()
451 * Event [I] Event to signal upon completion (or NULL)
452 * ApcRoutine [I] Callback to call upon completion (or NULL)
453 * ApcContext [I] Context for ApcRoutine (or NULL)
454 * IoStatusBlock [O] Receives information about the operation on return
455 * Buffer [O] Destination for the data read
456 * Length [I] Size of Buffer
457 * ByteOffset [O] Destination for the new file pointer position (or NULL)
458 * Key [O] Function unknown (may be NULL)
461 * Success: 0. IoStatusBlock is updated, and the Information member contains
462 * The number of bytes read.
463 * Failure: An NTSTATUS error code describing the error.
465 NTSTATUS WINAPI
NtReadFile(HANDLE hFile
, HANDLE hEvent
,
466 PIO_APC_ROUTINE apc
, void* apc_user
,
467 PIO_STATUS_BLOCK io_status
, void* buffer
, ULONG length
,
468 PLARGE_INTEGER offset
, PULONG key
)
470 int unix_handle
, flags
;
472 TRACE("(%p,%p,%p,%p,%p,%p,0x%08lx,%p,%p),partial stub!\n",
473 hFile
,hEvent
,apc
,apc_user
,io_status
,buffer
,length
,offset
,key
);
475 if (!io_status
) return STATUS_ACCESS_VIOLATION
;
477 io_status
->Information
= 0;
478 io_status
->u
.Status
= wine_server_handle_to_fd( hFile
, GENERIC_READ
, &unix_handle
, &flags
);
479 if (io_status
->u
.Status
) return io_status
->u
.Status
;
481 if (flags
& FD_FLAG_RECV_SHUTDOWN
)
483 wine_server_release_fd( hFile
, unix_handle
);
484 return STATUS_PIPE_DISCONNECTED
;
487 if (flags
& FD_FLAG_TIMEOUT
)
491 /* this shouldn't happen, but check it */
492 FIXME("NIY-hEvent\n");
493 wine_server_release_fd( hFile
, unix_handle
);
494 return STATUS_NOT_IMPLEMENTED
;
496 io_status
->u
.Status
= NtCreateEvent(&hEvent
, EVENT_ALL_ACCESS
, NULL
, 0, 0);
497 if (io_status
->u
.Status
)
499 wine_server_release_fd( hFile
, unix_handle
);
500 return io_status
->u
.Status
;
504 if (flags
& (FD_FLAG_OVERLAPPED
|FD_FLAG_TIMEOUT
))
506 async_fileio
* fileio
;
509 if (!(fileio
= RtlAllocateHeap(GetProcessHeap(), 0, sizeof(async_fileio
))))
511 wine_server_release_fd( hFile
, unix_handle
);
512 if (flags
& FD_FLAG_TIMEOUT
) NtClose(hEvent
);
513 return STATUS_NO_MEMORY
;
515 fileio
->handle
= hFile
;
516 fileio
->count
= length
;
517 if ( offset
== NULL
)
521 fileio
->offset
= offset
->QuadPart
;
522 if (offset
->u
.HighPart
&& fileio
->offset
== offset
->u
.LowPart
)
523 FIXME("High part of offset is lost\n");
526 fileio
->apc_user
= apc_user
;
527 fileio
->buffer
= buffer
;
528 fileio
->queue_apc_on_error
= 0;
529 fileio
->avail_mode
= (flags
& FD_FLAG_AVAILABLE
);
530 fileio
->fd
= unix_handle
; /* FIXME */
531 fileio
->event
= hEvent
;
532 NtResetEvent(hEvent
, NULL
);
534 io_status
->u
.Status
= STATUS_PENDING
;
535 ret
= fileio_queue_async(fileio
, io_status
, TRUE
);
536 if (ret
!= STATUS_SUCCESS
)
538 wine_server_release_fd( hFile
, unix_handle
);
539 if (flags
& FD_FLAG_TIMEOUT
) NtClose(hEvent
);
542 if (flags
& FD_FLAG_TIMEOUT
)
546 ret
= NtWaitForSingleObject(hEvent
, TRUE
, NULL
);
548 while (ret
== STATUS_USER_APC
&& io_status
->u
.Status
== STATUS_PENDING
);
550 if (ret
!= STATUS_USER_APC
)
551 fileio
->queue_apc_on_error
= 1;
555 LARGE_INTEGER timeout
;
557 /* let some APC be run, this will read some already pending data */
558 timeout
.u
.LowPart
= timeout
.u
.HighPart
= 0;
559 ret
= NtDelayExecution( TRUE
, &timeout
);
560 /* the apc didn't run and therefore the completion routine now
561 * needs to be sent errors.
562 * Note that there is no race between setting this flag and
563 * returning errors because apc's are run only during alertable
565 if (ret
!= STATUS_USER_APC
)
566 fileio
->queue_apc_on_error
= 1;
568 TRACE("= 0x%08lx\n", io_status
->u
.Status
);
569 return io_status
->u
.Status
;
574 FILE_POSITION_INFORMATION fpi
;
576 fpi
.CurrentByteOffset
= *offset
;
577 io_status
->u
.Status
= NtSetInformationFile(hFile
, io_status
, &fpi
, sizeof(fpi
),
578 FilePositionInformation
);
579 if (io_status
->u
.Status
)
581 wine_server_release_fd( hFile
, unix_handle
);
582 return io_status
->u
.Status
;
585 /* code for synchronous reads */
586 while ((io_status
->Information
= read( unix_handle
, buffer
, length
)) == -1)
588 if ((errno
== EAGAIN
) || (errno
== EINTR
)) continue;
591 io_status
->Information
= 0;
592 io_status
->u
.Status
= STATUS_ACCESS_VIOLATION
;
594 else io_status
->u
.Status
= FILE_GetNtStatus();
597 if (io_status
->u
.Status
== STATUS_SUCCESS
&& io_status
->Information
== 0)
600 if (fstat( unix_handle
, &st
) != -1 && S_ISSOCK( st
.st_mode
))
601 io_status
->u
.Status
= STATUS_PIPE_BROKEN
;
603 io_status
->u
.Status
= STATUS_END_OF_FILE
;
605 wine_server_release_fd( hFile
, unix_handle
);
606 TRACE("= 0x%08lx (%lu)\n", io_status
->u
.Status
, io_status
->Information
);
607 return io_status
->u
.Status
;
610 /***********************************************************************
611 * FILE_AsyncWriteService (INTERNAL)
613 * This function is called while the client is waiting on the
614 * server, so we can't make any server calls here.
616 static void WINAPI
FILE_AsyncWriteService(void *ovp
, IO_STATUS_BLOCK
*iosb
, ULONG status
)
618 async_fileio
*fileio
= (async_fileio
*) ovp
;
620 int already
= iosb
->Information
;
622 TRACE("(%p %p 0x%lx)\n",iosb
, fileio
->buffer
, status
);
627 /* write some data (non-blocking) */
628 if ( fileio
->avail_mode
)
629 result
= write(fileio
->fd
, &fileio
->buffer
[already
],
630 fileio
->count
- already
);
633 result
= pwrite(fileio
->fd
, &fileio
->buffer
[already
],
634 fileio
->count
- already
, fileio
->offset
+ already
);
635 if ((result
< 0) && (errno
== ESPIPE
))
636 result
= write(fileio
->fd
, &fileio
->buffer
[already
],
637 fileio
->count
- already
);
642 if (errno
== EAGAIN
|| errno
== EINTR
) iosb
->u
.Status
= STATUS_PENDING
;
643 else iosb
->u
.Status
= FILE_GetNtStatus();
647 iosb
->Information
+= result
;
648 iosb
->u
.Status
= (iosb
->Information
< fileio
->count
) ? STATUS_PENDING
: STATUS_SUCCESS
;
649 TRACE("wrote %d more bytes %ld/%d so far\n",
650 result
, iosb
->Information
, fileio
->count
);
652 if (iosb
->u
.Status
== STATUS_PENDING
)
653 fileio_queue_async(fileio
, iosb
, FALSE
);
655 fileio_terminate(fileio
, iosb
);
658 iosb
->u
.Status
= status
;
659 fileio_terminate(fileio
, iosb
);
664 /******************************************************************************
665 * NtWriteFile [NTDLL.@]
666 * ZwWriteFile [NTDLL.@]
668 * Write to an open file handle.
671 * FileHandle [I] Handle returned from ZwOpenFile() or ZwCreateFile()
672 * Event [I] Event to signal upon completion (or NULL)
673 * ApcRoutine [I] Callback to call upon completion (or NULL)
674 * ApcContext [I] Context for ApcRoutine (or NULL)
675 * IoStatusBlock [O] Receives information about the operation on return
676 * Buffer [I] Source for the data to write
677 * Length [I] Size of Buffer
678 * ByteOffset [O] Destination for the new file pointer position (or NULL)
679 * Key [O] Function unknown (may be NULL)
682 * Success: 0. IoStatusBlock is updated, and the Information member contains
683 * The number of bytes written.
684 * Failure: An NTSTATUS error code describing the error.
686 NTSTATUS WINAPI
NtWriteFile(HANDLE hFile
, HANDLE hEvent
,
687 PIO_APC_ROUTINE apc
, void* apc_user
,
688 PIO_STATUS_BLOCK io_status
,
689 const void* buffer
, ULONG length
,
690 PLARGE_INTEGER offset
, PULONG key
)
692 int unix_handle
, flags
;
694 TRACE("(%p,%p,%p,%p,%p,%p,0x%08lx,%p,%p)!\n",
695 hFile
,hEvent
,apc
,apc_user
,io_status
,buffer
,length
,offset
,key
);
697 if (!io_status
) return STATUS_ACCESS_VIOLATION
;
699 io_status
->Information
= 0;
700 io_status
->u
.Status
= wine_server_handle_to_fd( hFile
, GENERIC_WRITE
, &unix_handle
, &flags
);
701 if (io_status
->u
.Status
) return io_status
->u
.Status
;
703 if (flags
& FD_FLAG_SEND_SHUTDOWN
)
705 wine_server_release_fd( hFile
, unix_handle
);
706 return STATUS_PIPE_DISCONNECTED
;
709 if (flags
& FD_FLAG_TIMEOUT
)
713 /* this shouldn't happen, but check it */
714 FIXME("NIY-hEvent\n");
715 wine_server_release_fd( hFile
, unix_handle
);
716 return STATUS_NOT_IMPLEMENTED
;
718 io_status
->u
.Status
= NtCreateEvent(&hEvent
, EVENT_ALL_ACCESS
, NULL
, 0, 0);
719 if (io_status
->u
.Status
)
721 wine_server_release_fd( hFile
, unix_handle
);
722 return io_status
->u
.Status
;
726 if (flags
& (FD_FLAG_OVERLAPPED
|FD_FLAG_TIMEOUT
))
728 async_fileio
* fileio
;
731 if (!(fileio
= RtlAllocateHeap(GetProcessHeap(), 0, sizeof(async_fileio
))))
733 wine_server_release_fd( hFile
, unix_handle
);
734 if (flags
& FD_FLAG_TIMEOUT
) NtClose(hEvent
);
735 return STATUS_NO_MEMORY
;
737 fileio
->handle
= hFile
;
738 fileio
->count
= length
;
741 fileio
->offset
= offset
->QuadPart
;
742 if (offset
->u
.HighPart
&& fileio
->offset
== offset
->u
.LowPart
)
743 FIXME("High part of offset is lost\n");
750 fileio
->apc_user
= apc_user
;
751 fileio
->buffer
= (void*)buffer
;
752 fileio
->queue_apc_on_error
= 0;
753 fileio
->avail_mode
= (flags
& FD_FLAG_AVAILABLE
);
754 fileio
->fd
= unix_handle
; /* FIXME */
755 fileio
->event
= hEvent
;
756 NtResetEvent(hEvent
, NULL
);
758 io_status
->Information
= 0;
759 io_status
->u
.Status
= STATUS_PENDING
;
760 ret
= fileio_queue_async(fileio
, io_status
, FALSE
);
761 if (ret
!= STATUS_SUCCESS
)
763 wine_server_release_fd( hFile
, unix_handle
);
764 if (flags
& FD_FLAG_TIMEOUT
) NtClose(hEvent
);
767 if (flags
& FD_FLAG_TIMEOUT
)
771 ret
= NtWaitForSingleObject(hEvent
, TRUE
, NULL
);
773 while (ret
== STATUS_USER_APC
&& io_status
->u
.Status
== STATUS_PENDING
);
775 if (ret
!= STATUS_USER_APC
)
776 fileio
->queue_apc_on_error
= 1;
780 LARGE_INTEGER timeout
;
782 /* let some APC be run, this will write as much data as possible */
783 timeout
.u
.LowPart
= timeout
.u
.HighPart
= 0;
784 ret
= NtDelayExecution( TRUE
, &timeout
);
785 /* the apc didn't run and therefore the completion routine now
786 * needs to be sent errors.
787 * Note that there is no race between setting this flag and
788 * returning errors because apc's are run only during alertable
790 if (ret
!= STATUS_USER_APC
)
791 fileio
->queue_apc_on_error
= 1;
793 return io_status
->u
.Status
;
798 FILE_POSITION_INFORMATION fpi
;
800 fpi
.CurrentByteOffset
= *offset
;
801 io_status
->u
.Status
= NtSetInformationFile(hFile
, io_status
, &fpi
, sizeof(fpi
),
802 FilePositionInformation
);
803 if (io_status
->u
.Status
)
805 wine_server_release_fd( hFile
, unix_handle
);
806 return io_status
->u
.Status
;
810 /* synchronous file write */
811 while ((io_status
->Information
= write( unix_handle
, buffer
, length
)) == -1)
813 if ((errno
== EAGAIN
) || (errno
== EINTR
)) continue;
816 io_status
->Information
= 0;
817 io_status
->u
.Status
= STATUS_INVALID_USER_BUFFER
;
819 else if (errno
== ENOSPC
) io_status
->u
.Status
= STATUS_DISK_FULL
;
820 else io_status
->u
.Status
= FILE_GetNtStatus();
823 wine_server_release_fd( hFile
, unix_handle
);
824 return io_status
->u
.Status
;
827 /**************************************************************************
828 * NtDeviceIoControlFile [NTDLL.@]
829 * ZwDeviceIoControlFile [NTDLL.@]
831 * Perform an I/O control operation on an open file handle.
834 * DeviceHandle [I] Handle returned from ZwOpenFile() or ZwCreateFile()
835 * Event [I] Event to signal upon completion (or NULL)
836 * ApcRoutine [I] Callback to call upon completion (or NULL)
837 * ApcContext [I] Context for ApcRoutine (or NULL)
838 * IoStatusBlock [O] Receives information about the operation on return
839 * IoControlCode [I] Control code for the operation to perform
840 * InputBuffer [I] Source for any input data required (or NULL)
841 * InputBufferSize [I] Size of InputBuffer
842 * OutputBuffer [O] Source for any output data returned (or NULL)
843 * OutputBufferSize [I] Size of OutputBuffer
846 * Success: 0. IoStatusBlock is updated.
847 * Failure: An NTSTATUS error code describing the error.
849 NTSTATUS WINAPI
NtDeviceIoControlFile(HANDLE DeviceHandle
, HANDLE hEvent
,
850 PIO_APC_ROUTINE UserApcRoutine
,
851 PVOID UserApcContext
,
852 PIO_STATUS_BLOCK IoStatusBlock
,
855 ULONG InputBufferSize
,
857 ULONG OutputBufferSize
)
859 TRACE("(%p,%p,%p,%p,%p,0x%08lx,%p,0x%08lx,%p,0x%08lx)\n",
860 DeviceHandle
, hEvent
, UserApcRoutine
, UserApcContext
,
861 IoStatusBlock
, IoControlCode
,
862 InputBuffer
, InputBufferSize
, OutputBuffer
, OutputBufferSize
);
864 if (CDROM_DeviceIoControl(DeviceHandle
, hEvent
,
865 UserApcRoutine
, UserApcContext
,
866 IoStatusBlock
, IoControlCode
,
867 InputBuffer
, InputBufferSize
,
868 OutputBuffer
, OutputBufferSize
) == STATUS_NO_SUCH_DEVICE
)
870 /* it wasn't a CDROM */
871 FIXME("Unimplemented dwIoControlCode=%08lx\n", IoControlCode
);
872 IoStatusBlock
->u
.Status
= STATUS_NOT_IMPLEMENTED
;
873 IoStatusBlock
->Information
= 0;
874 if (hEvent
) NtSetEvent(hEvent
, NULL
);
876 return IoStatusBlock
->u
.Status
;
879 /***********************************************************************
880 * pipe_completion_wait (Internal)
882 static void CALLBACK
pipe_completion_wait(HANDLE event
, PIO_STATUS_BLOCK iosb
, ULONG status
)
884 TRACE("for %p/%p, status=%08lx\n", event
, iosb
, status
);
887 iosb
->u
.Status
= status
;
888 NtSetEvent(event
, NULL
);
892 /**************************************************************************
893 * NtFsControlFile [NTDLL.@]
894 * ZwFsControlFile [NTDLL.@]
896 * Perform a file system control operation on an open file handle.
899 * DeviceHandle [I] Handle returned from ZwOpenFile() or ZwCreateFile()
900 * Event [I] Event to signal upon completion (or NULL)
901 * ApcRoutine [I] Callback to call upon completion (or NULL)
902 * ApcContext [I] Context for ApcRoutine (or NULL)
903 * IoStatusBlock [O] Receives information about the operation on return
904 * FsControlCode [I] Control code for the operation to perform
905 * InputBuffer [I] Source for any input data required (or NULL)
906 * InputBufferSize [I] Size of InputBuffer
907 * OutputBuffer [O] Source for any output data returned (or NULL)
908 * OutputBufferSize [I] Size of OutputBuffer
911 * Success: 0. IoStatusBlock is updated.
912 * Failure: An NTSTATUS error code describing the error.
914 NTSTATUS WINAPI
NtFsControlFile(HANDLE DeviceHandle
, HANDLE Event OPTIONAL
, PIO_APC_ROUTINE ApcRoutine
,
915 PVOID ApcContext
, PIO_STATUS_BLOCK IoStatusBlock
, ULONG FsControlCode
,
916 PVOID InputBuffer
, ULONG InputBufferSize
, PVOID OutputBuffer
, ULONG OutputBufferSize
)
920 TRACE("(%p,%p,%p,%p,%p,0x%08lx,%p,0x%08lx,%p,0x%08lx)\n",
921 DeviceHandle
,Event
,ApcRoutine
,ApcContext
,IoStatusBlock
,FsControlCode
,
922 InputBuffer
,InputBufferSize
,OutputBuffer
,OutputBufferSize
);
924 if(!IoStatusBlock
) return STATUS_INVALID_PARAMETER
;
926 switch(FsControlCode
)
928 case FSCTL_DISMOUNT_VOLUME
:
929 ret
= DIR_unmount_device( DeviceHandle
);
932 case FSCTL_PIPE_LISTEN
:
934 HANDLE internal_event
;
938 OBJECT_ATTRIBUTES obj
;
939 InitializeObjectAttributes(&obj
, NULL
, 0, 0, NULL
);
940 ret
= NtCreateEvent(&internal_event
, EVENT_ALL_ACCESS
, &obj
, FALSE
, FALSE
);
941 if(ret
!= STATUS_SUCCESS
) return ret
;
944 SERVER_START_REQ(connect_named_pipe
)
946 req
->handle
= DeviceHandle
;
947 req
->event
= Event
? Event
: internal_event
;
948 req
->func
= pipe_completion_wait
;
949 ret
= wine_server_call(req
);
953 if(ret
== STATUS_SUCCESS
)
956 ret
= STATUS_PENDING
;
960 ret
= NtWaitForSingleObject(internal_event
, TRUE
, NULL
);
961 while(ret
== STATUS_USER_APC
);
962 NtClose(internal_event
);
967 case FSCTL_PIPE_DISCONNECT
:
968 SERVER_START_REQ(disconnect_named_pipe
)
970 req
->handle
= DeviceHandle
;
971 ret
= wine_server_call(req
);
972 if (!ret
&& reply
->fd
!= -1) close(reply
->fd
);
977 FIXME("Unsupported FsControlCode %lx\n", FsControlCode
);
978 ret
= STATUS_NOT_SUPPORTED
;
981 IoStatusBlock
->u
.Status
= ret
;
985 /******************************************************************************
986 * NtSetVolumeInformationFile [NTDLL.@]
987 * ZwSetVolumeInformationFile [NTDLL.@]
989 * Set volume information for an open file handle.
992 * FileHandle [I] Handle returned from ZwOpenFile() or ZwCreateFile()
993 * IoStatusBlock [O] Receives information about the operation on return
994 * FsInformation [I] Source for volume information
995 * Length [I] Size of FsInformation
996 * FsInformationClass [I] Type of volume information to set
999 * Success: 0. IoStatusBlock is updated.
1000 * Failure: An NTSTATUS error code describing the error.
1002 NTSTATUS WINAPI
NtSetVolumeInformationFile(
1003 IN HANDLE FileHandle
,
1004 PIO_STATUS_BLOCK IoStatusBlock
,
1005 PVOID FsInformation
,
1007 FS_INFORMATION_CLASS FsInformationClass
)
1009 FIXME("(%p,%p,%p,0x%08lx,0x%08x) stub\n",
1010 FileHandle
,IoStatusBlock
,FsInformation
,Length
,FsInformationClass
);
1014 /******************************************************************************
1015 * NtQueryInformationFile [NTDLL.@]
1016 * ZwQueryInformationFile [NTDLL.@]
1018 * Get information about an open file handle.
1021 * hFile [I] Handle returned from ZwOpenFile() or ZwCreateFile()
1022 * io [O] Receives information about the operation on return
1023 * ptr [O] Destination for file information
1024 * len [I] Size of FileInformation
1025 * class [I] Type of file information to get
1028 * Success: 0. IoStatusBlock and FileInformation are updated.
1029 * Failure: An NTSTATUS error code describing the error.
1031 NTSTATUS WINAPI
NtQueryInformationFile( HANDLE hFile
, PIO_STATUS_BLOCK io
,
1032 PVOID ptr
, LONG len
, FILE_INFORMATION_CLASS
class )
1034 static const size_t info_sizes
[] =
1037 sizeof(FILE_DIRECTORY_INFORMATION
), /* FileDirectoryInformation */
1038 sizeof(FILE_FULL_DIRECTORY_INFORMATION
), /* FileFullDirectoryInformation */
1039 sizeof(FILE_BOTH_DIRECTORY_INFORMATION
), /* FileBothDirectoryInformation */
1040 sizeof(FILE_BASIC_INFORMATION
), /* FileBasicInformation */
1041 sizeof(FILE_STANDARD_INFORMATION
), /* FileStandardInformation */
1042 sizeof(FILE_INTERNAL_INFORMATION
), /* FileInternalInformation */
1043 sizeof(FILE_EA_INFORMATION
), /* FileEaInformation */
1044 sizeof(FILE_ACCESS_INFORMATION
), /* FileAccessInformation */
1045 sizeof(FILE_NAME_INFORMATION
)-sizeof(WCHAR
), /* FileNameInformation */
1046 sizeof(FILE_RENAME_INFORMATION
)-sizeof(WCHAR
), /* FileRenameInformation */
1047 0, /* FileLinkInformation */
1048 sizeof(FILE_NAMES_INFORMATION
)-sizeof(WCHAR
), /* FileNamesInformation */
1049 sizeof(FILE_DISPOSITION_INFORMATION
), /* FileDispositionInformation */
1050 sizeof(FILE_POSITION_INFORMATION
), /* FilePositionInformation */
1051 sizeof(FILE_FULL_EA_INFORMATION
), /* FileFullEaInformation */
1052 sizeof(FILE_MODE_INFORMATION
), /* FileModeInformation */
1053 sizeof(FILE_ALIGNMENT_INFORMATION
), /* FileAlignmentInformation */
1054 sizeof(FILE_ALL_INFORMATION
)-sizeof(WCHAR
), /* FileAllInformation */
1055 sizeof(FILE_ALLOCATION_INFORMATION
), /* FileAllocationInformation */
1056 sizeof(FILE_END_OF_FILE_INFORMATION
), /* FileEndOfFileInformation */
1057 0, /* FileAlternateNameInformation */
1058 sizeof(FILE_STREAM_INFORMATION
)-sizeof(WCHAR
), /* FileStreamInformation */
1059 0, /* FilePipeInformation */
1060 0, /* FilePipeLocalInformation */
1061 0, /* FilePipeRemoteInformation */
1062 sizeof(FILE_MAILSLOT_QUERY_INFORMATION
), /* FileMailslotQueryInformation */
1063 0, /* FileMailslotSetInformation */
1064 0, /* FileCompressionInformation */
1065 0, /* FileObjectIdInformation */
1066 0, /* FileCompletionInformation */
1067 0, /* FileMoveClusterInformation */
1068 0, /* FileQuotaInformation */
1069 0, /* FileReparsePointInformation */
1070 0, /* FileNetworkOpenInformation */
1071 0, /* FileAttributeTagInformation */
1072 0 /* FileTrackingInformation */
1078 TRACE("(%p,%p,%p,0x%08lx,0x%08x)\n", hFile
, io
, ptr
, len
, class);
1080 io
->Information
= 0;
1082 if (class <= 0 || class >= FileMaximumInformation
)
1083 return io
->u
.Status
= STATUS_INVALID_INFO_CLASS
;
1084 if (!info_sizes
[class])
1086 FIXME("Unsupported class (%d)\n", class);
1087 return io
->u
.Status
= STATUS_NOT_IMPLEMENTED
;
1089 if (len
< info_sizes
[class])
1090 return io
->u
.Status
= STATUS_INFO_LENGTH_MISMATCH
;
1092 if ((io
->u
.Status
= wine_server_handle_to_fd( hFile
, 0, &fd
, NULL
)))
1093 return io
->u
.Status
;
1097 case FileBasicInformation
:
1099 FILE_BASIC_INFORMATION
*info
= ptr
;
1101 if (fstat( fd
, &st
) == -1)
1102 io
->u
.Status
= FILE_GetNtStatus();
1103 else if (!S_ISREG(st
.st_mode
) && !S_ISDIR(st
.st_mode
))
1104 io
->u
.Status
= STATUS_INVALID_INFO_CLASS
;
1107 if (S_ISDIR(st
.st_mode
)) info
->FileAttributes
= FILE_ATTRIBUTE_DIRECTORY
;
1108 else info
->FileAttributes
= FILE_ATTRIBUTE_ARCHIVE
;
1109 if (!(st
.st_mode
& (S_IWUSR
| S_IWGRP
| S_IWOTH
)))
1110 info
->FileAttributes
|= FILE_ATTRIBUTE_READONLY
;
1111 RtlSecondsSince1970ToTime( st
.st_mtime
, &info
->CreationTime
);
1112 RtlSecondsSince1970ToTime( st
.st_mtime
, &info
->LastWriteTime
);
1113 RtlSecondsSince1970ToTime( st
.st_ctime
, &info
->ChangeTime
);
1114 RtlSecondsSince1970ToTime( st
.st_atime
, &info
->LastAccessTime
);
1118 case FileStandardInformation
:
1120 FILE_STANDARD_INFORMATION
*info
= ptr
;
1122 if (fstat( fd
, &st
) == -1) io
->u
.Status
= FILE_GetNtStatus();
1125 if ((info
->Directory
= S_ISDIR(st
.st_mode
)))
1127 info
->AllocationSize
.QuadPart
= 0;
1128 info
->EndOfFile
.QuadPart
= 0;
1129 info
->NumberOfLinks
= 1;
1130 info
->DeletePending
= FALSE
;
1134 info
->AllocationSize
.QuadPart
= (ULONGLONG
)st
.st_blocks
* 512;
1135 info
->EndOfFile
.QuadPart
= st
.st_size
;
1136 info
->NumberOfLinks
= st
.st_nlink
;
1137 info
->DeletePending
= FALSE
; /* FIXME */
1142 case FilePositionInformation
:
1144 FILE_POSITION_INFORMATION
*info
= ptr
;
1145 off_t res
= lseek( fd
, 0, SEEK_CUR
);
1146 if (res
== (off_t
)-1) io
->u
.Status
= FILE_GetNtStatus();
1147 else info
->CurrentByteOffset
.QuadPart
= res
;
1150 case FileInternalInformation
:
1152 FILE_INTERNAL_INFORMATION
*info
= ptr
;
1154 if (fstat( fd
, &st
) == -1) io
->u
.Status
= FILE_GetNtStatus();
1155 else info
->IndexNumber
.QuadPart
= st
.st_ino
;
1158 case FileEaInformation
:
1160 FILE_EA_INFORMATION
*info
= ptr
;
1164 case FileEndOfFileInformation
:
1166 FILE_END_OF_FILE_INFORMATION
*info
= ptr
;
1168 if (fstat( fd
, &st
) == -1) io
->u
.Status
= FILE_GetNtStatus();
1169 else info
->EndOfFile
.QuadPart
= S_ISDIR(st
.st_mode
) ? 0 : st
.st_size
;
1172 case FileAllInformation
:
1174 FILE_ALL_INFORMATION
*info
= ptr
;
1176 if (fstat( fd
, &st
) == -1) io
->u
.Status
= FILE_GetNtStatus();
1177 else if (!S_ISREG(st
.st_mode
) && !S_ISDIR(st
.st_mode
))
1178 io
->u
.Status
= STATUS_INVALID_INFO_CLASS
;
1181 if ((info
->StandardInformation
.Directory
= S_ISDIR(st
.st_mode
)))
1183 info
->BasicInformation
.FileAttributes
= FILE_ATTRIBUTE_DIRECTORY
;
1184 info
->StandardInformation
.AllocationSize
.QuadPart
= 0;
1185 info
->StandardInformation
.EndOfFile
.QuadPart
= 0;
1186 info
->StandardInformation
.NumberOfLinks
= 1;
1187 info
->StandardInformation
.DeletePending
= FALSE
;
1191 info
->BasicInformation
.FileAttributes
= FILE_ATTRIBUTE_ARCHIVE
;
1192 info
->StandardInformation
.AllocationSize
.QuadPart
= (ULONGLONG
)st
.st_blocks
* 512;
1193 info
->StandardInformation
.EndOfFile
.QuadPart
= st
.st_size
;
1194 info
->StandardInformation
.NumberOfLinks
= st
.st_nlink
;
1195 info
->StandardInformation
.DeletePending
= FALSE
; /* FIXME */
1197 if (!(st
.st_mode
& (S_IWUSR
| S_IWGRP
| S_IWOTH
)))
1198 info
->BasicInformation
.FileAttributes
|= FILE_ATTRIBUTE_READONLY
;
1199 RtlSecondsSince1970ToTime( st
.st_mtime
, &info
->BasicInformation
.CreationTime
);
1200 RtlSecondsSince1970ToTime( st
.st_mtime
, &info
->BasicInformation
.LastWriteTime
);
1201 RtlSecondsSince1970ToTime( st
.st_ctime
, &info
->BasicInformation
.ChangeTime
);
1202 RtlSecondsSince1970ToTime( st
.st_atime
, &info
->BasicInformation
.LastAccessTime
);
1203 info
->InternalInformation
.IndexNumber
.QuadPart
= st
.st_ino
;
1204 info
->EaInformation
.EaSize
= 0;
1205 info
->AccessInformation
.AccessFlags
= 0; /* FIXME */
1206 info
->PositionInformation
.CurrentByteOffset
.QuadPart
= lseek( fd
, 0, SEEK_CUR
);
1207 info
->ModeInformation
.Mode
= 0; /* FIXME */
1208 info
->AlignmentInformation
.AlignmentRequirement
= 1; /* FIXME */
1209 info
->NameInformation
.FileNameLength
= 0;
1210 io
->Information
= sizeof(*info
) - sizeof(WCHAR
);
1214 case FileMailslotQueryInformation
:
1216 FILE_MAILSLOT_QUERY_INFORMATION
*info
= ptr
;
1218 SERVER_START_REQ( set_mailslot_info
)
1220 req
->handle
= hFile
;
1222 io
->u
.Status
= wine_server_call( req
);
1223 if( io
->u
.Status
== STATUS_SUCCESS
)
1225 info
->MaximumMessageSize
= reply
->max_msgsize
;
1226 info
->MailslotQuota
= 0;
1227 info
->NextMessageSize
= reply
->next_msgsize
;
1228 info
->MessagesAvailable
= reply
->msg_count
;
1229 info
->ReadTimeout
.QuadPart
= reply
->read_timeout
* -10000;
1236 FIXME("Unsupported class (%d)\n", class);
1237 io
->u
.Status
= STATUS_NOT_IMPLEMENTED
;
1240 wine_server_release_fd( hFile
, fd
);
1241 if (io
->u
.Status
== STATUS_SUCCESS
&& !io
->Information
) io
->Information
= info_sizes
[class];
1242 return io
->u
.Status
;
1245 /******************************************************************************
1246 * NtSetInformationFile [NTDLL.@]
1247 * ZwSetInformationFile [NTDLL.@]
1249 * Set information about an open file handle.
1252 * handle [I] Handle returned from ZwOpenFile() or ZwCreateFile()
1253 * io [O] Receives information about the operation on return
1254 * ptr [I] Source for file information
1255 * len [I] Size of FileInformation
1256 * class [I] Type of file information to set
1259 * Success: 0. io is updated.
1260 * Failure: An NTSTATUS error code describing the error.
1262 NTSTATUS WINAPI
NtSetInformationFile(HANDLE handle
, PIO_STATUS_BLOCK io
,
1263 PVOID ptr
, ULONG len
, FILE_INFORMATION_CLASS
class)
1267 TRACE("(%p,%p,%p,0x%08lx,0x%08x)\n", handle
, io
, ptr
, len
, class);
1269 if ((io
->u
.Status
= wine_server_handle_to_fd( handle
, 0, &fd
, NULL
)))
1270 return io
->u
.Status
;
1272 io
->u
.Status
= STATUS_SUCCESS
;
1275 case FileBasicInformation
:
1276 if (len
>= sizeof(FILE_BASIC_INFORMATION
))
1279 const FILE_BASIC_INFORMATION
*info
= ptr
;
1281 if (info
->LastAccessTime
.QuadPart
|| info
->LastWriteTime
.QuadPart
)
1283 ULONGLONG sec
, nsec
;
1284 struct timeval tv
[2];
1286 if (!info
->LastAccessTime
.QuadPart
|| !info
->LastWriteTime
.QuadPart
)
1289 tv
[0].tv_sec
= tv
[0].tv_usec
= 0;
1290 tv
[1].tv_sec
= tv
[1].tv_usec
= 0;
1291 if (!fstat( fd
, &st
))
1293 tv
[0].tv_sec
= st
.st_atime
;
1294 tv
[1].tv_sec
= st
.st_mtime
;
1297 if (info
->LastAccessTime
.QuadPart
)
1299 sec
= RtlLargeIntegerDivide( info
->LastAccessTime
.QuadPart
, 10000000, &nsec
);
1300 tv
[0].tv_sec
= sec
- SECS_1601_TO_1970
;
1301 tv
[0].tv_usec
= (UINT
)nsec
/ 10;
1303 if (info
->LastWriteTime
.QuadPart
)
1305 sec
= RtlLargeIntegerDivide( info
->LastWriteTime
.QuadPart
, 10000000, &nsec
);
1306 tv
[1].tv_sec
= sec
- SECS_1601_TO_1970
;
1307 tv
[1].tv_usec
= (UINT
)nsec
/ 10;
1309 if (futimes( fd
, tv
) == -1) io
->u
.Status
= FILE_GetNtStatus();
1312 if (io
->u
.Status
== STATUS_SUCCESS
&& info
->FileAttributes
)
1314 if (fstat( fd
, &st
) == -1) io
->u
.Status
= FILE_GetNtStatus();
1317 if (info
->FileAttributes
& FILE_ATTRIBUTE_READONLY
)
1319 if (S_ISDIR( st
.st_mode
))
1320 WARN("FILE_ATTRIBUTE_READONLY ignored for directory.\n");
1322 st
.st_mode
&= ~0222; /* clear write permission bits */
1326 /* add write permission only where we already have read permission */
1327 st
.st_mode
|= (0600 | ((st
.st_mode
& 044) >> 1)) & (~FILE_umask
);
1329 if (fchmod( fd
, st
.st_mode
) == -1) io
->u
.Status
= FILE_GetNtStatus();
1333 else io
->u
.Status
= STATUS_INVALID_PARAMETER_3
;
1336 case FilePositionInformation
:
1337 if (len
>= sizeof(FILE_POSITION_INFORMATION
))
1339 const FILE_POSITION_INFORMATION
*info
= ptr
;
1341 if (lseek( fd
, info
->CurrentByteOffset
.QuadPart
, SEEK_SET
) == (off_t
)-1)
1342 io
->u
.Status
= FILE_GetNtStatus();
1344 else io
->u
.Status
= STATUS_INVALID_PARAMETER_3
;
1347 case FileEndOfFileInformation
:
1348 if (len
>= sizeof(FILE_END_OF_FILE_INFORMATION
))
1351 const FILE_END_OF_FILE_INFORMATION
*info
= ptr
;
1353 /* first try normal truncate */
1354 if (ftruncate( fd
, (off_t
)info
->EndOfFile
.QuadPart
) != -1) break;
1356 /* now check for the need to extend the file */
1357 if (fstat( fd
, &st
) != -1 && (off_t
)info
->EndOfFile
.QuadPart
> st
.st_size
)
1359 static const char zero
;
1361 /* extend the file one byte beyond the requested size and then truncate it */
1362 /* this should work around ftruncate implementations that can't extend files */
1363 if (pwrite( fd
, &zero
, 1, (off_t
)info
->EndOfFile
.QuadPart
) != -1 &&
1364 ftruncate( fd
, (off_t
)info
->EndOfFile
.QuadPart
) != -1) break;
1366 io
->u
.Status
= FILE_GetNtStatus();
1368 else io
->u
.Status
= STATUS_INVALID_PARAMETER_3
;
1371 case FileMailslotSetInformation
:
1373 FILE_MAILSLOT_SET_INFORMATION
*info
= ptr
;
1375 SERVER_START_REQ( set_mailslot_info
)
1377 req
->handle
= handle
;
1378 req
->flags
= MAILSLOT_SET_READ_TIMEOUT
;
1379 req
->read_timeout
= info
->ReadTimeout
.QuadPart
/ -10000;
1380 io
->u
.Status
= wine_server_call( req
);
1387 FIXME("Unsupported class (%d)\n", class);
1388 io
->u
.Status
= STATUS_NOT_IMPLEMENTED
;
1391 wine_server_release_fd( handle
, fd
);
1392 io
->Information
= 0;
1393 return io
->u
.Status
;
1397 /******************************************************************************
1398 * NtQueryFullAttributesFile (NTDLL.@)
1400 NTSTATUS WINAPI
NtQueryFullAttributesFile( const OBJECT_ATTRIBUTES
*attr
,
1401 FILE_NETWORK_OPEN_INFORMATION
*info
)
1403 ANSI_STRING unix_name
;
1406 if (!(status
= wine_nt_to_unix_file_name( attr
->ObjectName
, &unix_name
, FILE_OPEN
,
1407 !(attr
->Attributes
& OBJ_CASE_INSENSITIVE
) )))
1411 if (stat( unix_name
.Buffer
, &st
) == -1)
1412 status
= FILE_GetNtStatus();
1413 else if (!S_ISREG(st
.st_mode
) && !S_ISDIR(st
.st_mode
))
1414 status
= STATUS_INVALID_INFO_CLASS
;
1417 if (S_ISDIR(st
.st_mode
))
1419 info
->FileAttributes
= FILE_ATTRIBUTE_DIRECTORY
;
1420 info
->AllocationSize
.QuadPart
= 0;
1421 info
->EndOfFile
.QuadPart
= 0;
1425 info
->FileAttributes
= FILE_ATTRIBUTE_ARCHIVE
;
1426 info
->AllocationSize
.QuadPart
= (ULONGLONG
)st
.st_blocks
* 512;
1427 info
->EndOfFile
.QuadPart
= st
.st_size
;
1429 if (!(st
.st_mode
& (S_IWUSR
| S_IWGRP
| S_IWOTH
)))
1430 info
->FileAttributes
|= FILE_ATTRIBUTE_READONLY
;
1431 RtlSecondsSince1970ToTime( st
.st_mtime
, &info
->CreationTime
);
1432 RtlSecondsSince1970ToTime( st
.st_mtime
, &info
->LastWriteTime
);
1433 RtlSecondsSince1970ToTime( st
.st_ctime
, &info
->ChangeTime
);
1434 RtlSecondsSince1970ToTime( st
.st_atime
, &info
->LastAccessTime
);
1435 if (DIR_is_hidden_file( attr
->ObjectName
))
1436 info
->FileAttributes
|= FILE_ATTRIBUTE_HIDDEN
;
1438 RtlFreeAnsiString( &unix_name
);
1440 else WARN("%s not found (%lx)\n", debugstr_us(attr
->ObjectName
), status
);
1445 /******************************************************************************
1446 * NtQueryAttributesFile (NTDLL.@)
1447 * ZwQueryAttributesFile (NTDLL.@)
1449 NTSTATUS WINAPI
NtQueryAttributesFile( const OBJECT_ATTRIBUTES
*attr
, FILE_BASIC_INFORMATION
*info
)
1451 FILE_NETWORK_OPEN_INFORMATION full_info
;
1454 if (!(status
= NtQueryFullAttributesFile( attr
, &full_info
)))
1456 info
->CreationTime
.QuadPart
= full_info
.CreationTime
.QuadPart
;
1457 info
->LastAccessTime
.QuadPart
= full_info
.LastAccessTime
.QuadPart
;
1458 info
->LastWriteTime
.QuadPart
= full_info
.LastWriteTime
.QuadPart
;
1459 info
->ChangeTime
.QuadPart
= full_info
.ChangeTime
.QuadPart
;
1460 info
->FileAttributes
= full_info
.FileAttributes
;
1466 /******************************************************************************
1467 * FILE_GetDeviceInfo
1469 * Implementation of the FileFsDeviceInformation query for NtQueryVolumeInformationFile.
1471 NTSTATUS
FILE_GetDeviceInfo( int fd
, FILE_FS_DEVICE_INFORMATION
*info
)
1475 info
->Characteristics
= 0;
1476 if (fstat( fd
, &st
) < 0) return FILE_GetNtStatus();
1477 if (S_ISCHR( st
.st_mode
))
1479 info
->DeviceType
= FILE_DEVICE_UNKNOWN
;
1481 switch(major(st
.st_rdev
))
1484 info
->DeviceType
= FILE_DEVICE_NULL
;
1487 info
->DeviceType
= FILE_DEVICE_SERIAL_PORT
;
1490 info
->DeviceType
= FILE_DEVICE_PARALLEL_PORT
;
1495 else if (S_ISBLK( st
.st_mode
))
1497 info
->DeviceType
= FILE_DEVICE_DISK
;
1499 else if (S_ISFIFO( st
.st_mode
) || S_ISSOCK( st
.st_mode
))
1501 info
->DeviceType
= FILE_DEVICE_NAMED_PIPE
;
1503 else /* regular file or directory */
1505 #if defined(linux) && defined(HAVE_FSTATFS)
1508 /* check for floppy disk */
1509 if (major(st
.st_dev
) == FLOPPY_MAJOR
)
1510 info
->Characteristics
|= FILE_REMOVABLE_MEDIA
;
1512 if (fstatfs( fd
, &stfs
) < 0) stfs
.f_type
= 0;
1513 switch (stfs
.f_type
)
1515 case 0x9660: /* iso9660 */
1516 case 0x15013346: /* udf */
1517 info
->DeviceType
= FILE_DEVICE_CD_ROM_FILE_SYSTEM
;
1518 info
->Characteristics
|= FILE_REMOVABLE_MEDIA
|FILE_READ_ONLY_DEVICE
;
1520 case 0x6969: /* nfs */
1521 case 0x517B: /* smbfs */
1522 case 0x564c: /* ncpfs */
1523 info
->DeviceType
= FILE_DEVICE_NETWORK_FILE_SYSTEM
;
1524 info
->Characteristics
|= FILE_REMOTE_DEVICE
;
1526 case 0x01021994: /* tmpfs */
1527 case 0x28cd3d45: /* cramfs */
1528 case 0x1373: /* devfs */
1529 case 0x9fa0: /* procfs */
1530 info
->DeviceType
= FILE_DEVICE_VIRTUAL_DISK
;
1533 info
->DeviceType
= FILE_DEVICE_DISK_FILE_SYSTEM
;
1536 #elif defined(__FreeBSD__)
1539 /* The proper way to do this in FreeBSD seems to be with the
1540 * name rather than the type, since their linux-compatible
1541 * fstatfs call converts the name to one of the Linux types.
1543 if (fstatfs( fd
, &stfs
) < 0)
1544 info
->DeviceType
= FILE_DEVICE_DISK_FILE_SYSTEM
;
1545 else if (!strncmp("cd9660", stfs
.f_fstypename
,
1546 sizeof(stfs
.f_fstypename
)))
1548 info
->DeviceType
= FILE_DEVICE_CD_ROM_FILE_SYSTEM
;
1549 /* Don't assume read-only, let the mount options set it
1552 info
->Characteristics
|= FILE_REMOVABLE_MEDIA
;
1554 else if (!strncmp("nfs", stfs
.f_fstypename
,
1555 sizeof(stfs
.f_fstypename
)))
1557 info
->DeviceType
= FILE_DEVICE_NETWORK_FILE_SYSTEM
;
1558 info
->Characteristics
|= FILE_REMOTE_DEVICE
;
1560 else if (!strncmp("nwfs", stfs
.f_fstypename
,
1561 sizeof(stfs
.f_fstypename
)))
1563 info
->DeviceType
= FILE_DEVICE_NETWORK_FILE_SYSTEM
;
1564 info
->Characteristics
|= FILE_REMOTE_DEVICE
;
1566 else if (!strncmp("procfs", stfs
.f_fstypename
,
1567 sizeof(stfs
.f_fstypename
)))
1568 info
->DeviceType
= FILE_DEVICE_VIRTUAL_DISK
;
1570 info
->DeviceType
= FILE_DEVICE_DISK_FILE_SYSTEM
;
1571 if (stfs
.f_flags
& MNT_RDONLY
)
1572 info
->Characteristics
|= FILE_READ_ONLY_DEVICE
;
1573 if (!(stfs
.f_flags
& MNT_LOCAL
))
1575 info
->DeviceType
= FILE_DEVICE_NETWORK_FILE_SYSTEM
;
1576 info
->Characteristics
|= FILE_REMOTE_DEVICE
;
1578 #elif defined (__APPLE__)
1580 kern_return_t kernResult
= KERN_FAILURE
;
1581 mach_port_t masterPort
;
1582 char bsdName
[6]; /* disk#\0 */
1585 info
->DeviceType
= FILE_DEVICE_DISK_FILE_SYSTEM
;
1587 if (fstatfs( fd
, &stfs
) < 0) return FILE_GetNtStatus();
1589 /* stfs.f_type is reserved (always set to 0) so use IOKit */
1590 name
= stfs
.f_mntfromname
+ strlen(_PATH_DEV
);
1591 memcpy( bsdName
, name
, min(strlen(name
)+1,sizeof(bsdName
)) );
1592 bsdName
[sizeof(bsdName
)-1] = 0;
1594 kernResult
= IOMasterPort(MACH_PORT_NULL
, &masterPort
);
1596 if (kernResult
== KERN_SUCCESS
)
1598 CFMutableDictionaryRef matching
= IOBSDNameMatching(masterPort
, 0, bsdName
);
1603 CFMutableDictionaryRef properties
;
1604 io_service_t devService
= IOServiceGetMatchingService(masterPort
, matching
);
1606 if (IORegistryEntryCreateCFProperties(devService
,
1608 kCFAllocatorDefault
, 0) != KERN_SUCCESS
)
1609 return FILE_GetNtStatus(); /* FIXME */
1611 CFDictionaryGetValue(properties
, CFSTR("Removable")),
1613 ) info
->Characteristics
|= FILE_REMOVABLE_MEDIA
;
1616 CFDictionaryGetValue(properties
, CFSTR("Writable")),
1618 ) info
->Characteristics
|= FILE_READ_ONLY_DEVICE
;
1621 NB : mounted disk image (.img/.dmg) don't provide specific type
1623 if ( (type
= CFDictionaryGetValue(properties
, CFSTR("Type"))) )
1625 if ( CFStringCompare(type
, CFSTR("CD-ROM"), 0) == kCFCompareEqualTo
1626 || CFStringCompare(type
, CFSTR("DVD-ROM"), 0) == kCFCompareEqualTo
1629 info
->DeviceType
= FILE_DEVICE_CD_ROM_FILE_SYSTEM
;
1634 CFRelease(properties
);
1638 /* Use dkio to work out device types */
1640 # include <sys/dkio.h>
1641 # include <sys/vtoc.h>
1642 struct dk_cinfo dkinf
;
1643 int retval
= ioctl(fd
, DKIOCINFO
, &dkinf
);
1645 WARN("Unable to get disk device type information - assuming a disk like device\n");
1646 info
->DeviceType
= FILE_DEVICE_DISK_FILE_SYSTEM
;
1648 switch (dkinf
.dki_ctype
)
1651 info
->DeviceType
= FILE_DEVICE_CD_ROM_FILE_SYSTEM
;
1652 info
->Characteristics
|= FILE_REMOVABLE_MEDIA
|FILE_READ_ONLY_DEVICE
;
1656 case DKC_INTEL82072
:
1657 case DKC_INTEL82077
:
1658 info
->DeviceType
= FILE_DEVICE_DISK_FILE_SYSTEM
;
1659 info
->Characteristics
|= FILE_REMOVABLE_MEDIA
;
1662 info
->DeviceType
= FILE_DEVICE_VIRTUAL_DISK
;
1665 info
->DeviceType
= FILE_DEVICE_DISK_FILE_SYSTEM
;
1670 if (!warned
++) FIXME( "device info not properly supported on this platform\n" );
1671 info
->DeviceType
= FILE_DEVICE_DISK_FILE_SYSTEM
;
1673 info
->Characteristics
|= FILE_DEVICE_IS_MOUNTED
;
1675 return STATUS_SUCCESS
;
1679 /******************************************************************************
1680 * NtQueryVolumeInformationFile [NTDLL.@]
1681 * ZwQueryVolumeInformationFile [NTDLL.@]
1683 * Get volume information for an open file handle.
1686 * handle [I] Handle returned from ZwOpenFile() or ZwCreateFile()
1687 * io [O] Receives information about the operation on return
1688 * buffer [O] Destination for volume information
1689 * length [I] Size of FsInformation
1690 * info_class [I] Type of volume information to set
1693 * Success: 0. io and buffer are updated.
1694 * Failure: An NTSTATUS error code describing the error.
1696 NTSTATUS WINAPI
NtQueryVolumeInformationFile( HANDLE handle
, PIO_STATUS_BLOCK io
,
1697 PVOID buffer
, ULONG length
,
1698 FS_INFORMATION_CLASS info_class
)
1703 if ((io
->u
.Status
= wine_server_handle_to_fd( handle
, 0, &fd
, NULL
)) != STATUS_SUCCESS
)
1704 return io
->u
.Status
;
1706 io
->u
.Status
= STATUS_NOT_IMPLEMENTED
;
1707 io
->Information
= 0;
1709 switch( info_class
)
1711 case FileFsVolumeInformation
:
1712 FIXME( "%p: volume info not supported\n", handle
);
1714 case FileFsLabelInformation
:
1715 FIXME( "%p: label info not supported\n", handle
);
1717 case FileFsSizeInformation
:
1718 if (length
< sizeof(FILE_FS_SIZE_INFORMATION
))
1719 io
->u
.Status
= STATUS_BUFFER_TOO_SMALL
;
1722 FILE_FS_SIZE_INFORMATION
*info
= buffer
;
1724 if (fstat( fd
, &st
) < 0)
1726 io
->u
.Status
= FILE_GetNtStatus();
1729 if (!S_ISREG(st
.st_mode
) && !S_ISDIR(st
.st_mode
))
1731 io
->u
.Status
= STATUS_INVALID_DEVICE_REQUEST
;
1735 /* Linux's fstatvfs is buggy */
1736 #if !defined(linux) || !defined(HAVE_FSTATFS)
1737 struct statvfs stfs
;
1739 if (fstatvfs( fd
, &stfs
) < 0)
1741 io
->u
.Status
= FILE_GetNtStatus();
1744 info
->BytesPerSector
= stfs
.f_frsize
;
1747 if (fstatfs( fd
, &stfs
) < 0)
1749 io
->u
.Status
= FILE_GetNtStatus();
1752 info
->BytesPerSector
= stfs
.f_bsize
;
1754 info
->TotalAllocationUnits
.QuadPart
= stfs
.f_blocks
;
1755 info
->AvailableAllocationUnits
.QuadPart
= stfs
.f_bavail
;
1756 info
->SectorsPerAllocationUnit
= 1;
1757 io
->Information
= sizeof(*info
);
1758 io
->u
.Status
= STATUS_SUCCESS
;
1762 case FileFsDeviceInformation
:
1763 if (length
< sizeof(FILE_FS_DEVICE_INFORMATION
))
1764 io
->u
.Status
= STATUS_BUFFER_TOO_SMALL
;
1767 FILE_FS_DEVICE_INFORMATION
*info
= buffer
;
1769 if ((io
->u
.Status
= FILE_GetDeviceInfo( fd
, info
)) == STATUS_SUCCESS
)
1770 io
->Information
= sizeof(*info
);
1773 case FileFsAttributeInformation
:
1774 FIXME( "%p: attribute info not supported\n", handle
);
1776 case FileFsControlInformation
:
1777 FIXME( "%p: control info not supported\n", handle
);
1779 case FileFsFullSizeInformation
:
1780 FIXME( "%p: full size info not supported\n", handle
);
1782 case FileFsObjectIdInformation
:
1783 FIXME( "%p: object id info not supported\n", handle
);
1785 case FileFsMaximumInformation
:
1786 FIXME( "%p: maximum info not supported\n", handle
);
1789 io
->u
.Status
= STATUS_INVALID_PARAMETER
;
1792 wine_server_release_fd( handle
, fd
);
1793 return io
->u
.Status
;
1797 /******************************************************************
1798 * NtFlushBuffersFile (NTDLL.@)
1800 * Flush any buffered data on an open file handle.
1803 * FileHandle [I] Handle returned from ZwOpenFile() or ZwCreateFile()
1804 * IoStatusBlock [O] Receives information about the operation on return
1807 * Success: 0. IoStatusBlock is updated.
1808 * Failure: An NTSTATUS error code describing the error.
1810 NTSTATUS WINAPI
NtFlushBuffersFile( HANDLE hFile
, IO_STATUS_BLOCK
* IoStatusBlock
)
1813 HANDLE hEvent
= NULL
;
1815 SERVER_START_REQ( flush_file
)
1817 req
->handle
= hFile
;
1818 ret
= wine_server_call( req
);
1819 hEvent
= reply
->event
;
1824 ret
= NtWaitForSingleObject( hEvent
, FALSE
, NULL
);
1830 /******************************************************************
1831 * NtLockFile (NTDLL.@)
1835 NTSTATUS WINAPI
NtLockFile( HANDLE hFile
, HANDLE lock_granted_event
,
1836 PIO_APC_ROUTINE apc
, void* apc_user
,
1837 PIO_STATUS_BLOCK io_status
, PLARGE_INTEGER offset
,
1838 PLARGE_INTEGER count
, ULONG
* key
, BOOLEAN dont_wait
,
1845 if (apc
|| io_status
|| key
)
1847 FIXME("Unimplemented yet parameter\n");
1848 return STATUS_NOT_IMPLEMENTED
;
1853 SERVER_START_REQ( lock_file
)
1855 req
->handle
= hFile
;
1856 req
->offset_low
= offset
->u
.LowPart
;
1857 req
->offset_high
= offset
->u
.HighPart
;
1858 req
->count_low
= count
->u
.LowPart
;
1859 req
->count_high
= count
->u
.HighPart
;
1860 req
->shared
= !exclusive
;
1861 req
->wait
= !dont_wait
;
1862 ret
= wine_server_call( req
);
1863 handle
= reply
->handle
;
1864 async
= reply
->overlapped
;
1867 if (ret
!= STATUS_PENDING
)
1869 if (!ret
&& lock_granted_event
) NtSetEvent(lock_granted_event
, NULL
);
1875 FIXME( "Async I/O lock wait not implemented, might deadlock\n" );
1876 if (handle
) NtClose( handle
);
1877 return STATUS_PENDING
;
1881 NtWaitForSingleObject( handle
, FALSE
, NULL
);
1888 /* Unix lock conflict, sleep a bit and retry */
1889 time
.QuadPart
= 100 * (ULONGLONG
)10000;
1890 time
.QuadPart
= -time
.QuadPart
;
1891 NtDelayExecution( FALSE
, &time
);
1897 /******************************************************************
1898 * NtUnlockFile (NTDLL.@)
1902 NTSTATUS WINAPI
NtUnlockFile( HANDLE hFile
, PIO_STATUS_BLOCK io_status
,
1903 PLARGE_INTEGER offset
, PLARGE_INTEGER count
,
1908 TRACE( "%p %lx%08lx %lx%08lx\n",
1909 hFile
, offset
->u
.HighPart
, offset
->u
.LowPart
, count
->u
.HighPart
, count
->u
.LowPart
);
1911 if (io_status
|| key
)
1913 FIXME("Unimplemented yet parameter\n");
1914 return STATUS_NOT_IMPLEMENTED
;
1917 SERVER_START_REQ( unlock_file
)
1919 req
->handle
= hFile
;
1920 req
->offset_low
= offset
->u
.LowPart
;
1921 req
->offset_high
= offset
->u
.HighPart
;
1922 req
->count_low
= count
->u
.LowPart
;
1923 req
->count_high
= count
->u
.HighPart
;
1924 status
= wine_server_call( req
);
1930 /******************************************************************
1931 * NtCreateNamedPipeFile (NTDLL.@)
1935 NTSTATUS WINAPI
NtCreateNamedPipeFile( PHANDLE handle
, ULONG access
,
1936 POBJECT_ATTRIBUTES attr
, PIO_STATUS_BLOCK iosb
,
1937 ULONG sharing
, ULONG dispo
, ULONG options
,
1938 ULONG pipe_type
, ULONG read_mode
,
1939 ULONG completion_mode
, ULONG max_inst
,
1940 ULONG inbound_quota
, ULONG outbound_quota
,
1941 PLARGE_INTEGER timeout
)
1944 static const WCHAR leadin
[] = {'\\','?','?','\\','P','I','P','E','\\'};
1946 TRACE("(%p %lx %s %p %lx %ld %lx %ld %ld %ld %ld %ld %ld %p)\n",
1947 handle
, access
, debugstr_w(attr
->ObjectName
->Buffer
), iosb
, sharing
, dispo
,
1948 options
, pipe_type
, read_mode
, completion_mode
, max_inst
, inbound_quota
,
1949 outbound_quota
, timeout
);
1951 if (attr
->ObjectName
->Length
< sizeof(leadin
) ||
1952 strncmpiW( attr
->ObjectName
->Buffer
,
1953 leadin
, sizeof(leadin
)/sizeof(leadin
[0]) ))
1954 return STATUS_OBJECT_NAME_INVALID
;
1955 /* assume we only get relative timeout, and storable in a DWORD as ms */
1956 if (timeout
->QuadPart
> 0 || (timeout
->QuadPart
/ -10000) >> 32)
1957 FIXME("Wrong time %s\n", wine_dbgstr_longlong(timeout
->QuadPart
));
1959 SERVER_START_REQ( create_named_pipe
)
1961 req
->access
= access
;
1962 req
->attributes
= (attr
) ? attr
->Attributes
: 0;
1963 req
->rootdir
= attr
? attr
->RootDirectory
: 0;
1964 req
->options
= options
;
1966 (pipe_type
) ? NAMED_PIPE_MESSAGE_STREAM_WRITE
: 0 |
1967 (read_mode
) ? NAMED_PIPE_MESSAGE_STREAM_READ
: 0 |
1968 (completion_mode
) ? NAMED_PIPE_NONBLOCKING_MODE
: 0;
1969 req
->maxinstances
= max_inst
;
1970 req
->outsize
= outbound_quota
;
1971 req
->insize
= inbound_quota
;
1972 req
->timeout
= timeout
->QuadPart
/ -10000;
1973 wine_server_add_data( req
, attr
->ObjectName
->Buffer
,
1974 attr
->ObjectName
->Length
);
1975 status
= wine_server_call( req
);
1976 if (!status
) *handle
= reply
->handle
;
1982 /******************************************************************
1983 * NtDeleteFile (NTDLL.@)
1987 NTSTATUS WINAPI
NtDeleteFile( POBJECT_ATTRIBUTES ObjectAttributes
)
1993 TRACE("%p\n", ObjectAttributes
);
1994 status
= NtCreateFile( &hFile
, GENERIC_READ
| GENERIC_WRITE
, ObjectAttributes
,
1996 FILE_SHARE_READ
| FILE_SHARE_WRITE
| FILE_SHARE_DELETE
,
1997 FILE_OPEN
, FILE_DELETE_ON_CLOSE
, NULL
, 0 );
1998 if (status
== STATUS_SUCCESS
) status
= NtClose(hFile
);
2002 /******************************************************************
2003 * NtCancelIoFile (NTDLL.@)
2007 NTSTATUS WINAPI
NtCancelIoFile( HANDLE hFile
, PIO_STATUS_BLOCK io_status
)
2009 LARGE_INTEGER timeout
;
2011 TRACE("%p %p\n", hFile
, io_status
);
2013 SERVER_START_REQ( cancel_async
)
2015 req
->handle
= hFile
;
2016 wine_server_call( req
);
2019 /* Let some APC be run, so that we can run the remaining APCs on hFile
2020 * either the cancelation of the pending one, but also the execution
2021 * of the queued APC, but not yet run. This is needed to ensure proper
2022 * clean-up of allocated data.
2024 timeout
.u
.LowPart
= timeout
.u
.HighPart
= 0;
2025 return io_status
->u
.Status
= NtDelayExecution( TRUE
, &timeout
);
2028 /******************************************************************************
2029 * NtCreateMailslotFile [NTDLL.@]
2030 * ZwCreateMailslotFile [NTDLL.@]
2033 * pHandle [O] pointer to receive the handle created
2034 * DesiredAccess [I] access mode (read, write, etc)
2035 * ObjectAttributes [I] fully qualified NT path of the mailslot
2036 * IoStatusBlock [O] receives completion status and other info
2039 * MaxMessageSize [I]
2045 NTSTATUS WINAPI
NtCreateMailslotFile(PHANDLE pHandle
, ULONG DesiredAccess
,
2046 POBJECT_ATTRIBUTES attr
, PIO_STATUS_BLOCK IoStatusBlock
,
2047 ULONG CreateOptions
, ULONG MailslotQuota
, ULONG MaxMessageSize
,
2048 PLARGE_INTEGER TimeOut
)
2050 static const WCHAR leadin
[] = {
2051 '\\','?','?','\\','M','A','I','L','S','L','O','T','\\'};
2054 TRACE("%p %08lx %p %p %08lx %08lx %08lx %p\n",
2055 pHandle
, DesiredAccess
, attr
, IoStatusBlock
,
2056 CreateOptions
, MailslotQuota
, MaxMessageSize
, TimeOut
);
2058 if (attr
->ObjectName
->Length
< sizeof(leadin
) ||
2059 strncmpiW( attr
->ObjectName
->Buffer
,
2060 leadin
, sizeof(leadin
)/sizeof(leadin
[0]) ))
2062 return STATUS_OBJECT_NAME_INVALID
;
2065 SERVER_START_REQ( create_mailslot
)
2067 req
->access
= DesiredAccess
;
2068 req
->attributes
= (attr
) ? attr
->Attributes
: 0;
2069 req
->rootdir
= attr
? attr
->RootDirectory
: 0;
2070 req
->max_msgsize
= MaxMessageSize
;
2071 req
->read_timeout
= (TimeOut
->QuadPart
<= 0) ? TimeOut
->QuadPart
/ -10000 : -1;
2072 wine_server_add_data( req
, attr
->ObjectName
->Buffer
,
2073 attr
->ObjectName
->Length
);
2074 ret
= wine_server_call( req
);
2075 if( ret
== STATUS_SUCCESS
)
2076 *pHandle
= reply
->handle
;