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_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>
51 #ifdef HAVE_SYS_MOUNT_H
52 # include <sys/mount.h>
54 #ifdef HAVE_SYS_STATFS_H
55 # include <sys/statfs.h>
58 #define NONAMELESSUNION
59 #define NONAMELESSSTRUCT
61 #define WIN32_NO_STATUS
62 #include "wine/unicode.h"
63 #include "wine/debug.h"
65 #include "wine/server.h"
66 #include "ntdll_misc.h"
71 WINE_DEFAULT_DEBUG_CHANNEL(ntdll
);
73 mode_t FILE_umask
= 0;
75 #define SECSPERDAY 86400
76 #define SECS_1601_TO_1970 ((369 * 365 + 89) * (ULONGLONG)SECSPERDAY)
78 /**************************************************************************
79 * NtOpenFile [NTDLL.@]
80 * ZwOpenFile [NTDLL.@]
85 * handle [O] Variable that receives the file handle on return
86 * access [I] Access desired by the caller to the file
87 * attr [I] Structure describing the file to be opened
88 * io [O] Receives details about the result of the operation
89 * sharing [I] Type of shared access the caller requires
90 * options [I] Options for the file open
93 * Success: 0. FileHandle and IoStatusBlock are updated.
94 * Failure: An NTSTATUS error code describing the error.
96 NTSTATUS WINAPI
NtOpenFile( PHANDLE handle
, ACCESS_MASK access
,
97 POBJECT_ATTRIBUTES attr
, PIO_STATUS_BLOCK io
,
98 ULONG sharing
, ULONG options
)
100 return NtCreateFile( handle
, access
, attr
, io
, NULL
, 0,
101 sharing
, FILE_OPEN
, options
, NULL
, 0 );
104 /**************************************************************************
105 * NtCreateFile [NTDLL.@]
106 * ZwCreateFile [NTDLL.@]
108 * Either create a new file or directory, or open an existing file, device,
109 * directory or volume.
112 * handle [O] Points to a variable which receives the file handle on return
113 * access [I] Desired access to the file
114 * attr [I] Structure describing the file
115 * io [O] Receives information about the operation on return
116 * alloc_size [I] Initial size of the file in bytes
117 * attributes [I] Attributes to create the file with
118 * sharing [I] Type of shared access the caller would like to the file
119 * disposition [I] Specifies what to do, depending on whether the file already exists
120 * options [I] Options for creating a new file
121 * ea_buffer [I] Pointer to an extended attributes buffer
122 * ea_length [I] Length of ea_buffer
125 * Success: 0. handle and io are updated.
126 * Failure: An NTSTATUS error code describing the error.
128 NTSTATUS WINAPI
NtCreateFile( PHANDLE handle
, ACCESS_MASK access
, POBJECT_ATTRIBUTES attr
,
129 PIO_STATUS_BLOCK io
, PLARGE_INTEGER alloc_size
,
130 ULONG attributes
, ULONG sharing
, ULONG disposition
,
131 ULONG options
, PVOID ea_buffer
, ULONG ea_length
)
133 static const WCHAR pipeW
[] = {'\\','?','?','\\','p','i','p','e','\\'};
134 static const WCHAR mailslotW
[] = {'\\','?','?','\\','M','A','I','L','S','L','O','T','\\'};
135 ANSI_STRING unix_name
;
138 TRACE("handle=%p access=%08x name=%s objattr=%08x root=%p sec=%p io=%p alloc_size=%p\n"
139 "attr=%08x sharing=%08x disp=%d options=%08x ea=%p.0x%08x\n",
140 handle
, access
, debugstr_us(attr
->ObjectName
), attr
->Attributes
,
141 attr
->RootDirectory
, attr
->SecurityDescriptor
, io
, alloc_size
,
142 attributes
, sharing
, disposition
, options
, ea_buffer
, ea_length
);
144 if (!attr
|| !attr
->ObjectName
) return STATUS_INVALID_PARAMETER
;
146 if (alloc_size
) FIXME( "alloc_size not supported\n" );
148 /* check for named pipe */
150 if (attr
->ObjectName
->Length
> sizeof(pipeW
) &&
151 !memicmpW( attr
->ObjectName
->Buffer
, pipeW
, sizeof(pipeW
)/sizeof(WCHAR
) ))
153 SERVER_START_REQ( open_named_pipe
)
155 req
->access
= access
;
156 req
->attributes
= attr
->Attributes
;
157 req
->rootdir
= attr
->RootDirectory
;
158 req
->flags
= options
;
159 wine_server_add_data( req
, attr
->ObjectName
->Buffer
,
160 attr
->ObjectName
->Length
);
161 io
->u
.Status
= wine_server_call( req
);
162 *handle
= reply
->handle
;
168 /* check for mailslot */
170 if (attr
->ObjectName
->Length
> sizeof(mailslotW
) &&
171 !memicmpW( attr
->ObjectName
->Buffer
, mailslotW
, sizeof(mailslotW
)/sizeof(WCHAR
) ))
173 SERVER_START_REQ( open_mailslot
)
175 req
->access
= access
& GENERIC_WRITE
;
176 req
->attributes
= attr
->Attributes
;
177 req
->rootdir
= attr
->RootDirectory
;
178 req
->sharing
= sharing
;
179 wine_server_add_data( req
, attr
->ObjectName
->Buffer
,
180 attr
->ObjectName
->Length
);
181 io
->u
.Status
= wine_server_call( req
);
182 *handle
= reply
->handle
;
188 if (attr
->RootDirectory
)
190 FIXME( "RootDirectory %p not supported\n", attr
->RootDirectory
);
191 return STATUS_OBJECT_NAME_NOT_FOUND
;
194 io
->u
.Status
= wine_nt_to_unix_file_name( attr
->ObjectName
, &unix_name
, disposition
,
195 !(attr
->Attributes
& OBJ_CASE_INSENSITIVE
) );
197 if (io
->u
.Status
== STATUS_BAD_DEVICE_TYPE
)
199 SERVER_START_REQ( open_file_object
)
201 req
->access
= access
;
202 req
->attributes
= attr
->Attributes
;
203 req
->rootdir
= attr
->RootDirectory
;
204 req
->sharing
= sharing
;
205 wine_server_add_data( req
, attr
->ObjectName
->Buffer
, attr
->ObjectName
->Length
);
206 io
->u
.Status
= wine_server_call( req
);
207 *handle
= reply
->handle
;
213 if (io
->u
.Status
== STATUS_NO_SUCH_FILE
&&
214 disposition
!= FILE_OPEN
&& disposition
!= FILE_OVERWRITE
)
217 io
->u
.Status
= STATUS_SUCCESS
;
220 if (io
->u
.Status
== STATUS_SUCCESS
)
222 SERVER_START_REQ( create_file
)
224 req
->access
= access
;
225 req
->attributes
= attr
->Attributes
;
226 req
->sharing
= sharing
;
227 req
->create
= disposition
;
228 req
->options
= options
;
229 req
->attrs
= attributes
;
230 wine_server_add_data( req
, unix_name
.Buffer
, unix_name
.Length
);
231 io
->u
.Status
= wine_server_call( req
);
232 *handle
= reply
->handle
;
235 RtlFreeAnsiString( &unix_name
);
237 else WARN("%s not found (%x)\n", debugstr_us(attr
->ObjectName
), io
->u
.Status
);
239 if (io
->u
.Status
== STATUS_SUCCESS
)
241 if (created
) io
->Information
= FILE_CREATED
;
242 else switch(disposition
)
245 io
->Information
= FILE_SUPERSEDED
;
248 io
->Information
= FILE_CREATED
;
252 io
->Information
= FILE_OPENED
;
255 case FILE_OVERWRITE_IF
:
256 io
->Information
= FILE_OVERWRITTEN
;
264 /***********************************************************************
265 * Asynchronous file I/O *
267 static void WINAPI
FILE_AsyncReadService(void*, PIO_STATUS_BLOCK
, ULONG
);
268 static void WINAPI
FILE_AsyncWriteService(void*, PIO_STATUS_BLOCK
, ULONG
);
270 typedef struct async_fileio
278 int queue_apc_on_error
;
284 static void fileio_terminate(async_fileio
*fileio
, IO_STATUS_BLOCK
* iosb
)
286 TRACE("data: %p\n", fileio
);
288 wine_server_release_fd( fileio
->handle
, fileio
->fd
);
289 if ( fileio
->event
!= INVALID_HANDLE_VALUE
)
290 NtSetEvent( fileio
->event
, NULL
);
293 (iosb
->u
.Status
== STATUS_SUCCESS
|| fileio
->queue_apc_on_error
))
294 fileio
->apc( fileio
->apc_user
, iosb
, iosb
->Information
);
296 RtlFreeHeap( GetProcessHeap(), 0, fileio
);
300 static ULONG
fileio_queue_async(async_fileio
* fileio
, IO_STATUS_BLOCK
* iosb
,
303 PIO_APC_ROUTINE apc
= do_read
? FILE_AsyncReadService
: FILE_AsyncWriteService
;
306 SERVER_START_REQ( register_async
)
308 req
->handle
= fileio
->handle
;
311 req
->io_user
= fileio
;
312 req
->type
= do_read
? ASYNC_TYPE_READ
: ASYNC_TYPE_WRITE
;
313 req
->count
= (fileio
->count
< iosb
->Information
) ?
314 0 : fileio
->count
- iosb
->Information
;
315 status
= wine_server_call( req
);
319 if ( status
) iosb
->u
.Status
= status
;
320 if ( iosb
->u
.Status
!= STATUS_PENDING
)
322 (apc
)( fileio
, iosb
, iosb
->u
.Status
);
323 return iosb
->u
.Status
;
325 NtCurrentTeb()->num_async_io
++;
326 return STATUS_SUCCESS
;
329 /***********************************************************************
330 * FILE_GetNtStatus(void)
332 * Retrieve the Nt Status code from errno.
333 * Try to be consistent with FILE_SetDosError().
335 NTSTATUS
FILE_GetNtStatus(void)
339 TRACE( "errno = %d\n", errno
);
342 case EAGAIN
: return STATUS_SHARING_VIOLATION
;
343 case EBADF
: return STATUS_INVALID_HANDLE
;
344 case EBUSY
: return STATUS_DEVICE_BUSY
;
345 case ENOSPC
: return STATUS_DISK_FULL
;
348 case EACCES
: return STATUS_ACCESS_DENIED
;
349 case ENOTDIR
: return STATUS_OBJECT_PATH_NOT_FOUND
;
350 case ENOENT
: return STATUS_OBJECT_NAME_NOT_FOUND
;
351 case EISDIR
: return STATUS_FILE_IS_A_DIRECTORY
;
353 case ENFILE
: return STATUS_TOO_MANY_OPENED_FILES
;
354 case EINVAL
: return STATUS_INVALID_PARAMETER
;
355 case ENOTEMPTY
: return STATUS_DIRECTORY_NOT_EMPTY
;
356 case EPIPE
: return STATUS_PIPE_BROKEN
;
357 case EIO
: return STATUS_DEVICE_NOT_READY
;
359 case ENOMEDIUM
: return STATUS_NO_MEDIA_IN_DEVICE
;
361 case ENXIO
: return STATUS_NO_SUCH_DEVICE
;
363 case EOPNOTSUPP
:return STATUS_NOT_SUPPORTED
;
364 case ECONNRESET
:return STATUS_PIPE_DISCONNECTED
;
365 case ENOEXEC
: /* ?? */
366 case ESPIPE
: /* ?? */
367 case EEXIST
: /* ?? */
369 FIXME( "Converting errno %d to STATUS_UNSUCCESSFUL\n", err
);
370 return STATUS_UNSUCCESSFUL
;
374 /***********************************************************************
375 * FILE_AsyncReadService (INTERNAL)
377 * This function is called while the client is waiting on the
378 * server, so we can't make any server calls here.
380 static void WINAPI
FILE_AsyncReadService(void *user
, PIO_STATUS_BLOCK iosb
, ULONG status
)
382 async_fileio
*fileio
= (async_fileio
*)user
;
384 int already
= iosb
->Information
;
386 TRACE("%p %p 0x%x\n", iosb
, fileio
->buffer
, status
);
390 case STATUS_ALERTED
: /* got some new data */
391 if (iosb
->u
.Status
!= STATUS_PENDING
) FIXME("unexpected status %08x\n", iosb
->u
.Status
);
392 /* check to see if the data is ready (non-blocking) */
393 if ( fileio
->avail_mode
)
394 result
= read(fileio
->fd
, &fileio
->buffer
[already
],
395 fileio
->count
- already
);
398 result
= pread(fileio
->fd
, &fileio
->buffer
[already
],
399 fileio
->count
- already
,
400 fileio
->offset
+ already
);
401 if ((result
< 0) && (errno
== ESPIPE
))
402 result
= read(fileio
->fd
, &fileio
->buffer
[already
],
403 fileio
->count
- already
);
408 if (errno
== EAGAIN
|| errno
== EINTR
)
410 TRACE("Deferred read %d\n", errno
);
411 iosb
->u
.Status
= STATUS_PENDING
;
413 else /* check to see if the transfer is complete */
414 iosb
->u
.Status
= FILE_GetNtStatus();
416 else if (result
== 0)
418 iosb
->u
.Status
= iosb
->Information
? STATUS_SUCCESS
: STATUS_END_OF_FILE
;
422 iosb
->Information
+= result
;
423 if (iosb
->Information
>= fileio
->count
|| fileio
->avail_mode
)
424 iosb
->u
.Status
= STATUS_SUCCESS
;
427 /* if we only have to read the available data, and none is available,
428 * simply cancel the request. If data was available, it has been read
429 * while in by previous call (NtDelayExecution)
431 iosb
->u
.Status
= (fileio
->avail_mode
) ? STATUS_SUCCESS
: STATUS_PENDING
;
434 TRACE("read %d more bytes %ld/%d so far (%s)\n",
435 result
, iosb
->Information
, fileio
->count
,
436 (iosb
->u
.Status
== STATUS_SUCCESS
) ? "success" : "pending");
438 /* queue another async operation ? */
439 if (iosb
->u
.Status
== STATUS_PENDING
)
440 fileio_queue_async(fileio
, iosb
, TRUE
);
442 fileio_terminate(fileio
, iosb
);
445 iosb
->u
.Status
= status
;
446 fileio_terminate(fileio
, iosb
);
452 /******************************************************************************
453 * NtReadFile [NTDLL.@]
454 * ZwReadFile [NTDLL.@]
456 * Read from an open file handle.
459 * FileHandle [I] Handle returned from ZwOpenFile() or ZwCreateFile()
460 * Event [I] Event to signal upon completion (or NULL)
461 * ApcRoutine [I] Callback to call upon completion (or NULL)
462 * ApcContext [I] Context for ApcRoutine (or NULL)
463 * IoStatusBlock [O] Receives information about the operation on return
464 * Buffer [O] Destination for the data read
465 * Length [I] Size of Buffer
466 * ByteOffset [O] Destination for the new file pointer position (or NULL)
467 * Key [O] Function unknown (may be NULL)
470 * Success: 0. IoStatusBlock is updated, and the Information member contains
471 * The number of bytes read.
472 * Failure: An NTSTATUS error code describing the error.
474 NTSTATUS WINAPI
NtReadFile(HANDLE hFile
, HANDLE hEvent
,
475 PIO_APC_ROUTINE apc
, void* apc_user
,
476 PIO_STATUS_BLOCK io_status
, void* buffer
, ULONG length
,
477 PLARGE_INTEGER offset
, PULONG key
)
479 int unix_handle
, flags
;
481 TRACE("(%p,%p,%p,%p,%p,%p,0x%08x,%p,%p),partial stub!\n",
482 hFile
,hEvent
,apc
,apc_user
,io_status
,buffer
,length
,offset
,key
);
484 if (!io_status
) return STATUS_ACCESS_VIOLATION
;
486 io_status
->Information
= 0;
487 io_status
->u
.Status
= wine_server_handle_to_fd( hFile
, FILE_READ_DATA
, &unix_handle
, &flags
);
488 if (io_status
->u
.Status
) return io_status
->u
.Status
;
490 if (flags
& FD_FLAG_RECV_SHUTDOWN
)
492 wine_server_release_fd( hFile
, unix_handle
);
493 return STATUS_PIPE_DISCONNECTED
;
496 if (flags
& FD_FLAG_TIMEOUT
)
500 /* this shouldn't happen, but check it */
501 FIXME("NIY-hEvent\n");
502 wine_server_release_fd( hFile
, unix_handle
);
503 return STATUS_NOT_IMPLEMENTED
;
505 io_status
->u
.Status
= NtCreateEvent(&hEvent
, EVENT_ALL_ACCESS
, NULL
, 0, 0);
506 if (io_status
->u
.Status
)
508 wine_server_release_fd( hFile
, unix_handle
);
509 return io_status
->u
.Status
;
513 if (flags
& (FD_FLAG_OVERLAPPED
|FD_FLAG_TIMEOUT
))
515 async_fileio
* fileio
;
518 if (!(fileio
= RtlAllocateHeap(GetProcessHeap(), 0, sizeof(async_fileio
))))
520 wine_server_release_fd( hFile
, unix_handle
);
521 if (flags
& FD_FLAG_TIMEOUT
) NtClose(hEvent
);
522 return STATUS_NO_MEMORY
;
524 fileio
->handle
= hFile
;
525 fileio
->count
= length
;
526 if ( offset
== NULL
)
530 fileio
->offset
= offset
->QuadPart
;
531 if (offset
->u
.HighPart
&& fileio
->offset
== offset
->u
.LowPart
)
532 FIXME("High part of offset is lost\n");
535 fileio
->apc_user
= apc_user
;
536 fileio
->buffer
= buffer
;
537 fileio
->queue_apc_on_error
= 0;
538 fileio
->avail_mode
= (flags
& FD_FLAG_AVAILABLE
);
539 fileio
->fd
= unix_handle
; /* FIXME */
540 fileio
->event
= hEvent
;
541 NtResetEvent(hEvent
, NULL
);
543 io_status
->u
.Status
= STATUS_PENDING
;
544 ret
= fileio_queue_async(fileio
, io_status
, TRUE
);
545 if (ret
!= STATUS_SUCCESS
)
547 wine_server_release_fd( hFile
, unix_handle
);
548 if (flags
& FD_FLAG_TIMEOUT
) NtClose(hEvent
);
551 if (flags
& FD_FLAG_TIMEOUT
)
555 ret
= NtWaitForSingleObject(hEvent
, TRUE
, NULL
);
557 while (ret
== STATUS_USER_APC
&& io_status
->u
.Status
== STATUS_PENDING
);
559 if (ret
!= STATUS_USER_APC
)
560 fileio
->queue_apc_on_error
= 1;
564 LARGE_INTEGER timeout
;
566 /* let some APC be run, this will read some already pending data */
567 timeout
.u
.LowPart
= timeout
.u
.HighPart
= 0;
568 ret
= NtDelayExecution( TRUE
, &timeout
);
569 /* the apc didn't run and therefore the completion routine now
570 * needs to be sent errors.
571 * Note that there is no race between setting this flag and
572 * returning errors because apc's are run only during alertable
574 if (ret
!= STATUS_USER_APC
)
575 fileio
->queue_apc_on_error
= 1;
577 TRACE("= 0x%08x\n", io_status
->u
.Status
);
578 return io_status
->u
.Status
;
583 FILE_POSITION_INFORMATION fpi
;
585 fpi
.CurrentByteOffset
= *offset
;
586 io_status
->u
.Status
= NtSetInformationFile(hFile
, io_status
, &fpi
, sizeof(fpi
),
587 FilePositionInformation
);
588 if (io_status
->u
.Status
)
590 wine_server_release_fd( hFile
, unix_handle
);
591 return io_status
->u
.Status
;
594 /* code for synchronous reads */
595 while ((io_status
->Information
= read( unix_handle
, buffer
, length
)) == -1)
597 if ((errno
== EAGAIN
) || (errno
== EINTR
)) continue;
600 io_status
->Information
= 0;
601 io_status
->u
.Status
= STATUS_ACCESS_VIOLATION
;
603 else io_status
->u
.Status
= FILE_GetNtStatus();
606 if (io_status
->u
.Status
== STATUS_SUCCESS
&& io_status
->Information
== 0)
609 if (fstat( unix_handle
, &st
) != -1 && S_ISSOCK( st
.st_mode
))
610 io_status
->u
.Status
= STATUS_PIPE_BROKEN
;
612 io_status
->u
.Status
= STATUS_END_OF_FILE
;
614 wine_server_release_fd( hFile
, unix_handle
);
615 TRACE("= 0x%08x (%lu)\n", io_status
->u
.Status
, io_status
->Information
);
616 return io_status
->u
.Status
;
619 /***********************************************************************
620 * FILE_AsyncWriteService (INTERNAL)
622 * This function is called while the client is waiting on the
623 * server, so we can't make any server calls here.
625 static void WINAPI
FILE_AsyncWriteService(void *ovp
, IO_STATUS_BLOCK
*iosb
, ULONG status
)
627 async_fileio
*fileio
= (async_fileio
*) ovp
;
629 int already
= iosb
->Information
;
631 TRACE("(%p %p 0x%x)\n",iosb
, fileio
->buffer
, status
);
636 /* write some data (non-blocking) */
637 if ( fileio
->avail_mode
)
638 result
= write(fileio
->fd
, &fileio
->buffer
[already
],
639 fileio
->count
- already
);
642 result
= pwrite(fileio
->fd
, &fileio
->buffer
[already
],
643 fileio
->count
- already
, fileio
->offset
+ already
);
644 if ((result
< 0) && (errno
== ESPIPE
))
645 result
= write(fileio
->fd
, &fileio
->buffer
[already
],
646 fileio
->count
- already
);
651 if (errno
== EAGAIN
|| errno
== EINTR
) iosb
->u
.Status
= STATUS_PENDING
;
652 else iosb
->u
.Status
= FILE_GetNtStatus();
656 iosb
->Information
+= result
;
657 iosb
->u
.Status
= (iosb
->Information
< fileio
->count
) ? STATUS_PENDING
: STATUS_SUCCESS
;
658 TRACE("wrote %d more bytes %ld/%d so far\n",
659 result
, iosb
->Information
, fileio
->count
);
661 if (iosb
->u
.Status
== STATUS_PENDING
)
662 fileio_queue_async(fileio
, iosb
, FALSE
);
664 fileio_terminate(fileio
, iosb
);
667 iosb
->u
.Status
= status
;
668 fileio_terminate(fileio
, iosb
);
673 /******************************************************************************
674 * NtWriteFile [NTDLL.@]
675 * ZwWriteFile [NTDLL.@]
677 * Write to an open file handle.
680 * FileHandle [I] Handle returned from ZwOpenFile() or ZwCreateFile()
681 * Event [I] Event to signal upon completion (or NULL)
682 * ApcRoutine [I] Callback to call upon completion (or NULL)
683 * ApcContext [I] Context for ApcRoutine (or NULL)
684 * IoStatusBlock [O] Receives information about the operation on return
685 * Buffer [I] Source for the data to write
686 * Length [I] Size of Buffer
687 * ByteOffset [O] Destination for the new file pointer position (or NULL)
688 * Key [O] Function unknown (may be NULL)
691 * Success: 0. IoStatusBlock is updated, and the Information member contains
692 * The number of bytes written.
693 * Failure: An NTSTATUS error code describing the error.
695 NTSTATUS WINAPI
NtWriteFile(HANDLE hFile
, HANDLE hEvent
,
696 PIO_APC_ROUTINE apc
, void* apc_user
,
697 PIO_STATUS_BLOCK io_status
,
698 const void* buffer
, ULONG length
,
699 PLARGE_INTEGER offset
, PULONG key
)
701 int unix_handle
, flags
;
703 TRACE("(%p,%p,%p,%p,%p,%p,0x%08x,%p,%p)!\n",
704 hFile
,hEvent
,apc
,apc_user
,io_status
,buffer
,length
,offset
,key
);
706 if (!io_status
) return STATUS_ACCESS_VIOLATION
;
708 io_status
->Information
= 0;
709 io_status
->u
.Status
= wine_server_handle_to_fd( hFile
, FILE_WRITE_DATA
, &unix_handle
, &flags
);
710 if (io_status
->u
.Status
) return io_status
->u
.Status
;
712 if (flags
& FD_FLAG_SEND_SHUTDOWN
)
714 wine_server_release_fd( hFile
, unix_handle
);
715 return STATUS_PIPE_DISCONNECTED
;
718 if (flags
& FD_FLAG_TIMEOUT
)
722 /* this shouldn't happen, but check it */
723 FIXME("NIY-hEvent\n");
724 wine_server_release_fd( hFile
, unix_handle
);
725 return STATUS_NOT_IMPLEMENTED
;
727 io_status
->u
.Status
= NtCreateEvent(&hEvent
, EVENT_ALL_ACCESS
, NULL
, 0, 0);
728 if (io_status
->u
.Status
)
730 wine_server_release_fd( hFile
, unix_handle
);
731 return io_status
->u
.Status
;
735 if (flags
& (FD_FLAG_OVERLAPPED
|FD_FLAG_TIMEOUT
))
737 async_fileio
* fileio
;
740 if (!(fileio
= RtlAllocateHeap(GetProcessHeap(), 0, sizeof(async_fileio
))))
742 wine_server_release_fd( hFile
, unix_handle
);
743 if (flags
& FD_FLAG_TIMEOUT
) NtClose(hEvent
);
744 return STATUS_NO_MEMORY
;
746 fileio
->handle
= hFile
;
747 fileio
->count
= length
;
750 fileio
->offset
= offset
->QuadPart
;
751 if (offset
->u
.HighPart
&& fileio
->offset
== offset
->u
.LowPart
)
752 FIXME("High part of offset is lost\n");
759 fileio
->apc_user
= apc_user
;
760 fileio
->buffer
= (void*)buffer
;
761 fileio
->queue_apc_on_error
= 0;
762 fileio
->avail_mode
= (flags
& FD_FLAG_AVAILABLE
);
763 fileio
->fd
= unix_handle
; /* FIXME */
764 fileio
->event
= hEvent
;
765 NtResetEvent(hEvent
, NULL
);
767 io_status
->Information
= 0;
768 io_status
->u
.Status
= STATUS_PENDING
;
769 ret
= fileio_queue_async(fileio
, io_status
, FALSE
);
770 if (ret
!= STATUS_SUCCESS
)
772 wine_server_release_fd( hFile
, unix_handle
);
773 if (flags
& FD_FLAG_TIMEOUT
) NtClose(hEvent
);
776 if (flags
& FD_FLAG_TIMEOUT
)
780 ret
= NtWaitForSingleObject(hEvent
, TRUE
, NULL
);
782 while (ret
== STATUS_USER_APC
&& io_status
->u
.Status
== STATUS_PENDING
);
784 if (ret
!= STATUS_USER_APC
)
785 fileio
->queue_apc_on_error
= 1;
789 LARGE_INTEGER timeout
;
791 /* let some APC be run, this will write as much data as possible */
792 timeout
.u
.LowPart
= timeout
.u
.HighPart
= 0;
793 ret
= NtDelayExecution( TRUE
, &timeout
);
794 /* the apc didn't run and therefore the completion routine now
795 * needs to be sent errors.
796 * Note that there is no race between setting this flag and
797 * returning errors because apc's are run only during alertable
799 if (ret
!= STATUS_USER_APC
)
800 fileio
->queue_apc_on_error
= 1;
802 return io_status
->u
.Status
;
807 FILE_POSITION_INFORMATION fpi
;
809 fpi
.CurrentByteOffset
= *offset
;
810 io_status
->u
.Status
= NtSetInformationFile(hFile
, io_status
, &fpi
, sizeof(fpi
),
811 FilePositionInformation
);
812 if (io_status
->u
.Status
)
814 wine_server_release_fd( hFile
, unix_handle
);
815 return io_status
->u
.Status
;
819 /* synchronous file write */
820 while ((io_status
->Information
= write( unix_handle
, buffer
, length
)) == -1)
822 if ((errno
== EAGAIN
) || (errno
== EINTR
)) continue;
825 io_status
->Information
= 0;
826 io_status
->u
.Status
= STATUS_INVALID_USER_BUFFER
;
828 else if (errno
== ENOSPC
) io_status
->u
.Status
= STATUS_DISK_FULL
;
829 else io_status
->u
.Status
= FILE_GetNtStatus();
832 wine_server_release_fd( hFile
, unix_handle
);
833 return io_status
->u
.Status
;
836 /**************************************************************************
837 * NtDeviceIoControlFile [NTDLL.@]
838 * ZwDeviceIoControlFile [NTDLL.@]
840 * Perform an I/O control operation on an open file handle.
843 * handle [I] Handle returned from ZwOpenFile() or ZwCreateFile()
844 * event [I] Event to signal upon completion (or NULL)
845 * apc [I] Callback to call upon completion (or NULL)
846 * apc_context [I] Context for ApcRoutine (or NULL)
847 * io [O] Receives information about the operation on return
848 * code [I] Control code for the operation to perform
849 * in_buffer [I] Source for any input data required (or NULL)
850 * in_size [I] Size of InputBuffer
851 * out_buffer [O] Source for any output data returned (or NULL)
852 * out_size [I] Size of OutputBuffer
855 * Success: 0. IoStatusBlock is updated.
856 * Failure: An NTSTATUS error code describing the error.
858 NTSTATUS WINAPI
NtDeviceIoControlFile(HANDLE handle
, HANDLE event
,
859 PIO_APC_ROUTINE apc
, PVOID apc_context
,
860 PIO_STATUS_BLOCK io
, ULONG code
,
861 PVOID in_buffer
, ULONG in_size
,
862 PVOID out_buffer
, ULONG out_size
)
864 ULONG device
= (code
>> 16);
866 TRACE("(%p,%p,%p,%p,%p,0x%08x,%p,0x%08x,%p,0x%08x)\n",
867 handle
, event
, apc
, apc_context
, io
, code
,
868 in_buffer
, in_size
, out_buffer
, out_size
);
872 case FILE_DEVICE_DISK
:
873 case FILE_DEVICE_CD_ROM
:
874 case FILE_DEVICE_DVD
:
875 case FILE_DEVICE_CONTROLLER
:
876 case FILE_DEVICE_MASS_STORAGE
:
877 io
->u
.Status
= CDROM_DeviceIoControl(handle
, event
, apc
, apc_context
, io
, code
,
878 in_buffer
, in_size
, out_buffer
, out_size
);
880 case FILE_DEVICE_SERIAL_PORT
:
881 io
->u
.Status
= COMM_DeviceIoControl(handle
, event
, apc
, apc_context
, io
, code
,
882 in_buffer
, in_size
, out_buffer
, out_size
);
884 case FILE_DEVICE_TAPE
:
885 io
->u
.Status
= TAPE_DeviceIoControl(handle
, event
, apc
, apc_context
, io
, code
,
886 in_buffer
, in_size
, out_buffer
, out_size
);
889 FIXME("Unsupported ioctl %x (device=%x access=%x func=%x method=%x)\n",
890 code
, device
, (code
>> 14) & 3, (code
>> 2) & 0xfff, code
& 3);
891 io
->u
.Status
= STATUS_NOT_SUPPORTED
;
897 /***********************************************************************
898 * pipe_completion_wait (Internal)
900 static void CALLBACK
pipe_completion_wait(HANDLE event
, PIO_STATUS_BLOCK iosb
, ULONG status
)
902 TRACE("for %p/%p, status=%08x\n", event
, iosb
, status
);
905 iosb
->u
.Status
= status
;
906 NtSetEvent(event
, NULL
);
910 /**************************************************************************
911 * NtFsControlFile [NTDLL.@]
912 * ZwFsControlFile [NTDLL.@]
914 * Perform a file system control operation on an open file handle.
917 * handle [I] Handle returned from ZwOpenFile() or ZwCreateFile()
918 * event [I] Event to signal upon completion (or NULL)
919 * apc [I] Callback to call upon completion (or NULL)
920 * apc_context [I] Context for ApcRoutine (or NULL)
921 * io [O] Receives information about the operation on return
922 * code [I] Control code for the operation to perform
923 * in_buffer [I] Source for any input data required (or NULL)
924 * in_size [I] Size of InputBuffer
925 * out_buffer [O] Source for any output data returned (or NULL)
926 * out_size [I] Size of OutputBuffer
929 * Success: 0. IoStatusBlock is updated.
930 * Failure: An NTSTATUS error code describing the error.
932 NTSTATUS WINAPI
NtFsControlFile(HANDLE handle
, HANDLE event
, PIO_APC_ROUTINE apc
,
933 PVOID apc_context
, PIO_STATUS_BLOCK io
, ULONG code
,
934 PVOID in_buffer
, ULONG in_size
, PVOID out_buffer
, ULONG out_size
)
936 TRACE("(%p,%p,%p,%p,%p,0x%08x,%p,0x%08x,%p,0x%08x)\n",
937 handle
, event
, apc
, apc_context
, io
, code
,
938 in_buffer
, in_size
, out_buffer
, out_size
);
940 if (!io
) return STATUS_INVALID_PARAMETER
;
944 case FSCTL_DISMOUNT_VOLUME
:
945 io
->u
.Status
= DIR_unmount_device( handle
);
948 case FSCTL_PIPE_LISTEN
:
950 HANDLE internal_event
= 0;
954 io
->u
.Status
= NtCreateEvent(&internal_event
, EVENT_ALL_ACCESS
, NULL
, FALSE
, FALSE
);
955 if (io
->u
.Status
!= STATUS_SUCCESS
) return io
->u
.Status
;
957 SERVER_START_REQ(connect_named_pipe
)
959 req
->handle
= handle
;
960 req
->event
= event
? event
: internal_event
;
961 req
->func
= pipe_completion_wait
;
962 io
->u
.Status
= wine_server_call(req
);
966 if(io
->u
.Status
== STATUS_SUCCESS
)
968 if(event
) io
->u
.Status
= STATUS_PENDING
;
972 io
->u
.Status
= NtWaitForSingleObject(internal_event
, TRUE
, NULL
);
973 while(io
->u
.Status
== STATUS_USER_APC
);
976 if (internal_event
) NtClose(internal_event
);
980 case FSCTL_PIPE_WAIT
:
982 HANDLE internal_event
= 0;
983 FILE_PIPE_WAIT_FOR_BUFFER
*buff
= in_buffer
;
987 io
->u
.Status
= NtCreateEvent(&internal_event
, EVENT_ALL_ACCESS
, NULL
, FALSE
, FALSE
);
988 if (io
->u
.Status
!= STATUS_SUCCESS
) return io
->u
.Status
;
990 SERVER_START_REQ(wait_named_pipe
)
992 req
->handle
= handle
;
993 req
->timeout
= buff
->TimeoutSpecified
? buff
->Timeout
.QuadPart
/ -10000L
994 : NMPWAIT_USE_DEFAULT_WAIT
;
995 req
->event
= event
? event
: internal_event
;
996 req
->func
= pipe_completion_wait
;
997 wine_server_add_data( req
, buff
->Name
, buff
->NameLength
);
998 io
->u
.Status
= wine_server_call( req
);
1002 if(io
->u
.Status
== STATUS_SUCCESS
)
1005 io
->u
.Status
= STATUS_PENDING
;
1009 io
->u
.Status
= NtWaitForSingleObject(internal_event
, TRUE
, NULL
);
1010 while(io
->u
.Status
== STATUS_USER_APC
);
1013 if (internal_event
) NtClose(internal_event
);
1017 case FSCTL_PIPE_DISCONNECT
:
1018 SERVER_START_REQ(disconnect_named_pipe
)
1020 req
->handle
= handle
;
1021 io
->u
.Status
= wine_server_call(req
);
1022 if (!io
->u
.Status
&& reply
->fd
!= -1) close(reply
->fd
);
1027 case FSCTL_LOCK_VOLUME
:
1028 case FSCTL_UNLOCK_VOLUME
:
1029 FIXME("stub! return success - Unsupported fsctl %x (device=%x access=%x func=%x method=%x)\n",
1030 code
, code
>> 16, (code
>> 14) & 3, (code
>> 2) & 0xfff, code
& 3);
1031 io
->u
.Status
= STATUS_SUCCESS
;
1035 FIXME("Unsupported fsctl %x (device=%x access=%x func=%x method=%x)\n",
1036 code
, code
>> 16, (code
>> 14) & 3, (code
>> 2) & 0xfff, code
& 3);
1037 io
->u
.Status
= STATUS_NOT_SUPPORTED
;
1040 return io
->u
.Status
;
1043 /******************************************************************************
1044 * NtSetVolumeInformationFile [NTDLL.@]
1045 * ZwSetVolumeInformationFile [NTDLL.@]
1047 * Set volume information for an open file handle.
1050 * FileHandle [I] Handle returned from ZwOpenFile() or ZwCreateFile()
1051 * IoStatusBlock [O] Receives information about the operation on return
1052 * FsInformation [I] Source for volume information
1053 * Length [I] Size of FsInformation
1054 * FsInformationClass [I] Type of volume information to set
1057 * Success: 0. IoStatusBlock is updated.
1058 * Failure: An NTSTATUS error code describing the error.
1060 NTSTATUS WINAPI
NtSetVolumeInformationFile(
1061 IN HANDLE FileHandle
,
1062 PIO_STATUS_BLOCK IoStatusBlock
,
1063 PVOID FsInformation
,
1065 FS_INFORMATION_CLASS FsInformationClass
)
1067 FIXME("(%p,%p,%p,0x%08x,0x%08x) stub\n",
1068 FileHandle
,IoStatusBlock
,FsInformation
,Length
,FsInformationClass
);
1072 /******************************************************************************
1073 * NtQueryInformationFile [NTDLL.@]
1074 * ZwQueryInformationFile [NTDLL.@]
1076 * Get information about an open file handle.
1079 * hFile [I] Handle returned from ZwOpenFile() or ZwCreateFile()
1080 * io [O] Receives information about the operation on return
1081 * ptr [O] Destination for file information
1082 * len [I] Size of FileInformation
1083 * class [I] Type of file information to get
1086 * Success: 0. IoStatusBlock and FileInformation are updated.
1087 * Failure: An NTSTATUS error code describing the error.
1089 NTSTATUS WINAPI
NtQueryInformationFile( HANDLE hFile
, PIO_STATUS_BLOCK io
,
1090 PVOID ptr
, LONG len
, FILE_INFORMATION_CLASS
class )
1092 static const size_t info_sizes
[] =
1095 sizeof(FILE_DIRECTORY_INFORMATION
), /* FileDirectoryInformation */
1096 sizeof(FILE_FULL_DIRECTORY_INFORMATION
), /* FileFullDirectoryInformation */
1097 sizeof(FILE_BOTH_DIRECTORY_INFORMATION
), /* FileBothDirectoryInformation */
1098 sizeof(FILE_BASIC_INFORMATION
), /* FileBasicInformation */
1099 sizeof(FILE_STANDARD_INFORMATION
), /* FileStandardInformation */
1100 sizeof(FILE_INTERNAL_INFORMATION
), /* FileInternalInformation */
1101 sizeof(FILE_EA_INFORMATION
), /* FileEaInformation */
1102 sizeof(FILE_ACCESS_INFORMATION
), /* FileAccessInformation */
1103 sizeof(FILE_NAME_INFORMATION
)-sizeof(WCHAR
), /* FileNameInformation */
1104 sizeof(FILE_RENAME_INFORMATION
)-sizeof(WCHAR
), /* FileRenameInformation */
1105 0, /* FileLinkInformation */
1106 sizeof(FILE_NAMES_INFORMATION
)-sizeof(WCHAR
), /* FileNamesInformation */
1107 sizeof(FILE_DISPOSITION_INFORMATION
), /* FileDispositionInformation */
1108 sizeof(FILE_POSITION_INFORMATION
), /* FilePositionInformation */
1109 sizeof(FILE_FULL_EA_INFORMATION
), /* FileFullEaInformation */
1110 sizeof(FILE_MODE_INFORMATION
), /* FileModeInformation */
1111 sizeof(FILE_ALIGNMENT_INFORMATION
), /* FileAlignmentInformation */
1112 sizeof(FILE_ALL_INFORMATION
)-sizeof(WCHAR
), /* FileAllInformation */
1113 sizeof(FILE_ALLOCATION_INFORMATION
), /* FileAllocationInformation */
1114 sizeof(FILE_END_OF_FILE_INFORMATION
), /* FileEndOfFileInformation */
1115 0, /* FileAlternateNameInformation */
1116 sizeof(FILE_STREAM_INFORMATION
)-sizeof(WCHAR
), /* FileStreamInformation */
1117 0, /* FilePipeInformation */
1118 sizeof(FILE_PIPE_LOCAL_INFORMATION
), /* FilePipeLocalInformation */
1119 0, /* FilePipeRemoteInformation */
1120 sizeof(FILE_MAILSLOT_QUERY_INFORMATION
), /* FileMailslotQueryInformation */
1121 0, /* FileMailslotSetInformation */
1122 0, /* FileCompressionInformation */
1123 0, /* FileObjectIdInformation */
1124 0, /* FileCompletionInformation */
1125 0, /* FileMoveClusterInformation */
1126 0, /* FileQuotaInformation */
1127 0, /* FileReparsePointInformation */
1128 0, /* FileNetworkOpenInformation */
1129 0, /* FileAttributeTagInformation */
1130 0 /* FileTrackingInformation */
1136 TRACE("(%p,%p,%p,0x%08x,0x%08x)\n", hFile
, io
, ptr
, len
, class);
1138 io
->Information
= 0;
1140 if (class <= 0 || class >= FileMaximumInformation
)
1141 return io
->u
.Status
= STATUS_INVALID_INFO_CLASS
;
1142 if (!info_sizes
[class])
1144 FIXME("Unsupported class (%d)\n", class);
1145 return io
->u
.Status
= STATUS_NOT_IMPLEMENTED
;
1147 if (len
< info_sizes
[class])
1148 return io
->u
.Status
= STATUS_INFO_LENGTH_MISMATCH
;
1150 if (class != FilePipeLocalInformation
)
1152 if ((io
->u
.Status
= wine_server_handle_to_fd( hFile
, 0, &fd
, NULL
)))
1153 return io
->u
.Status
;
1158 case FileBasicInformation
:
1160 FILE_BASIC_INFORMATION
*info
= ptr
;
1162 if (fstat( fd
, &st
) == -1)
1163 io
->u
.Status
= FILE_GetNtStatus();
1164 else if (!S_ISREG(st
.st_mode
) && !S_ISDIR(st
.st_mode
))
1165 io
->u
.Status
= STATUS_INVALID_INFO_CLASS
;
1168 if (S_ISDIR(st
.st_mode
)) info
->FileAttributes
= FILE_ATTRIBUTE_DIRECTORY
;
1169 else info
->FileAttributes
= FILE_ATTRIBUTE_ARCHIVE
;
1170 if (!(st
.st_mode
& (S_IWUSR
| S_IWGRP
| S_IWOTH
)))
1171 info
->FileAttributes
|= FILE_ATTRIBUTE_READONLY
;
1172 RtlSecondsSince1970ToTime( st
.st_mtime
, &info
->CreationTime
);
1173 RtlSecondsSince1970ToTime( st
.st_mtime
, &info
->LastWriteTime
);
1174 RtlSecondsSince1970ToTime( st
.st_ctime
, &info
->ChangeTime
);
1175 RtlSecondsSince1970ToTime( st
.st_atime
, &info
->LastAccessTime
);
1179 case FileStandardInformation
:
1181 FILE_STANDARD_INFORMATION
*info
= ptr
;
1183 if (fstat( fd
, &st
) == -1) io
->u
.Status
= FILE_GetNtStatus();
1186 if ((info
->Directory
= S_ISDIR(st
.st_mode
)))
1188 info
->AllocationSize
.QuadPart
= 0;
1189 info
->EndOfFile
.QuadPart
= 0;
1190 info
->NumberOfLinks
= 1;
1191 info
->DeletePending
= FALSE
;
1195 info
->AllocationSize
.QuadPart
= (ULONGLONG
)st
.st_blocks
* 512;
1196 info
->EndOfFile
.QuadPart
= st
.st_size
;
1197 info
->NumberOfLinks
= st
.st_nlink
;
1198 info
->DeletePending
= FALSE
; /* FIXME */
1203 case FilePositionInformation
:
1205 FILE_POSITION_INFORMATION
*info
= ptr
;
1206 off_t res
= lseek( fd
, 0, SEEK_CUR
);
1207 if (res
== (off_t
)-1) io
->u
.Status
= FILE_GetNtStatus();
1208 else info
->CurrentByteOffset
.QuadPart
= res
;
1211 case FileInternalInformation
:
1213 FILE_INTERNAL_INFORMATION
*info
= ptr
;
1215 if (fstat( fd
, &st
) == -1) io
->u
.Status
= FILE_GetNtStatus();
1216 else info
->IndexNumber
.QuadPart
= st
.st_ino
;
1219 case FileEaInformation
:
1221 FILE_EA_INFORMATION
*info
= ptr
;
1225 case FileEndOfFileInformation
:
1227 FILE_END_OF_FILE_INFORMATION
*info
= ptr
;
1229 if (fstat( fd
, &st
) == -1) io
->u
.Status
= FILE_GetNtStatus();
1230 else info
->EndOfFile
.QuadPart
= S_ISDIR(st
.st_mode
) ? 0 : st
.st_size
;
1233 case FileAllInformation
:
1235 FILE_ALL_INFORMATION
*info
= ptr
;
1237 if (fstat( fd
, &st
) == -1) io
->u
.Status
= FILE_GetNtStatus();
1238 else if (!S_ISREG(st
.st_mode
) && !S_ISDIR(st
.st_mode
))
1239 io
->u
.Status
= STATUS_INVALID_INFO_CLASS
;
1242 if ((info
->StandardInformation
.Directory
= S_ISDIR(st
.st_mode
)))
1244 info
->BasicInformation
.FileAttributes
= FILE_ATTRIBUTE_DIRECTORY
;
1245 info
->StandardInformation
.AllocationSize
.QuadPart
= 0;
1246 info
->StandardInformation
.EndOfFile
.QuadPart
= 0;
1247 info
->StandardInformation
.NumberOfLinks
= 1;
1248 info
->StandardInformation
.DeletePending
= FALSE
;
1252 info
->BasicInformation
.FileAttributes
= FILE_ATTRIBUTE_ARCHIVE
;
1253 info
->StandardInformation
.AllocationSize
.QuadPart
= (ULONGLONG
)st
.st_blocks
* 512;
1254 info
->StandardInformation
.EndOfFile
.QuadPart
= st
.st_size
;
1255 info
->StandardInformation
.NumberOfLinks
= st
.st_nlink
;
1256 info
->StandardInformation
.DeletePending
= FALSE
; /* FIXME */
1258 if (!(st
.st_mode
& (S_IWUSR
| S_IWGRP
| S_IWOTH
)))
1259 info
->BasicInformation
.FileAttributes
|= FILE_ATTRIBUTE_READONLY
;
1260 RtlSecondsSince1970ToTime( st
.st_mtime
, &info
->BasicInformation
.CreationTime
);
1261 RtlSecondsSince1970ToTime( st
.st_mtime
, &info
->BasicInformation
.LastWriteTime
);
1262 RtlSecondsSince1970ToTime( st
.st_ctime
, &info
->BasicInformation
.ChangeTime
);
1263 RtlSecondsSince1970ToTime( st
.st_atime
, &info
->BasicInformation
.LastAccessTime
);
1264 info
->InternalInformation
.IndexNumber
.QuadPart
= st
.st_ino
;
1265 info
->EaInformation
.EaSize
= 0;
1266 info
->AccessInformation
.AccessFlags
= 0; /* FIXME */
1267 info
->PositionInformation
.CurrentByteOffset
.QuadPart
= lseek( fd
, 0, SEEK_CUR
);
1268 info
->ModeInformation
.Mode
= 0; /* FIXME */
1269 info
->AlignmentInformation
.AlignmentRequirement
= 1; /* FIXME */
1270 info
->NameInformation
.FileNameLength
= 0;
1271 io
->Information
= sizeof(*info
) - sizeof(WCHAR
);
1275 case FileMailslotQueryInformation
:
1277 FILE_MAILSLOT_QUERY_INFORMATION
*info
= ptr
;
1279 SERVER_START_REQ( set_mailslot_info
)
1281 req
->handle
= hFile
;
1283 io
->u
.Status
= wine_server_call( req
);
1284 if( io
->u
.Status
== STATUS_SUCCESS
)
1286 info
->MaximumMessageSize
= reply
->max_msgsize
;
1287 info
->MailslotQuota
= 0;
1288 info
->NextMessageSize
= reply
->next_msgsize
;
1289 info
->MessagesAvailable
= reply
->msg_count
;
1290 info
->ReadTimeout
.QuadPart
= reply
->read_timeout
* -10000;
1296 case FilePipeLocalInformation
:
1298 FILE_PIPE_LOCAL_INFORMATION
* pli
= ptr
;
1300 SERVER_START_REQ( get_named_pipe_info
)
1302 req
->handle
= hFile
;
1303 if (!(io
->u
.Status
= wine_server_call( req
)))
1305 pli
->NamedPipeType
= (reply
->flags
& NAMED_PIPE_MESSAGE_STREAM_WRITE
) ?
1306 FILE_PIPE_TYPE_MESSAGE
: FILE_PIPE_TYPE_BYTE
;
1307 pli
->NamedPipeConfiguration
= 0; /* FIXME */
1308 pli
->MaximumInstances
= reply
->maxinstances
;
1309 pli
->CurrentInstances
= reply
->instances
;
1310 pli
->InboundQuota
= reply
->insize
;
1311 pli
->ReadDataAvailable
= 0; /* FIXME */
1312 pli
->OutboundQuota
= reply
->outsize
;
1313 pli
->WriteQuotaAvailable
= 0; /* FIXME */
1314 pli
->NamedPipeState
= 0; /* FIXME */
1315 pli
->NamedPipeEnd
= (reply
->flags
& NAMED_PIPE_SERVER_END
) ?
1316 FILE_PIPE_SERVER_END
: FILE_PIPE_CLIENT_END
;
1323 FIXME("Unsupported class (%d)\n", class);
1324 io
->u
.Status
= STATUS_NOT_IMPLEMENTED
;
1327 if (fd
!= -1) wine_server_release_fd( hFile
, fd
);
1328 if (io
->u
.Status
== STATUS_SUCCESS
&& !io
->Information
) io
->Information
= info_sizes
[class];
1329 return io
->u
.Status
;
1332 /******************************************************************************
1333 * NtSetInformationFile [NTDLL.@]
1334 * ZwSetInformationFile [NTDLL.@]
1336 * Set information about an open file handle.
1339 * handle [I] Handle returned from ZwOpenFile() or ZwCreateFile()
1340 * io [O] Receives information about the operation on return
1341 * ptr [I] Source for file information
1342 * len [I] Size of FileInformation
1343 * class [I] Type of file information to set
1346 * Success: 0. io is updated.
1347 * Failure: An NTSTATUS error code describing the error.
1349 NTSTATUS WINAPI
NtSetInformationFile(HANDLE handle
, PIO_STATUS_BLOCK io
,
1350 PVOID ptr
, ULONG len
, FILE_INFORMATION_CLASS
class)
1354 TRACE("(%p,%p,%p,0x%08x,0x%08x)\n", handle
, io
, ptr
, len
, class);
1356 if ((io
->u
.Status
= wine_server_handle_to_fd( handle
, 0, &fd
, NULL
)))
1357 return io
->u
.Status
;
1359 io
->u
.Status
= STATUS_SUCCESS
;
1362 case FileBasicInformation
:
1363 if (len
>= sizeof(FILE_BASIC_INFORMATION
))
1366 const FILE_BASIC_INFORMATION
*info
= ptr
;
1368 if (info
->LastAccessTime
.QuadPart
|| info
->LastWriteTime
.QuadPart
)
1370 ULONGLONG sec
, nsec
;
1371 struct timeval tv
[2];
1373 if (!info
->LastAccessTime
.QuadPart
|| !info
->LastWriteTime
.QuadPart
)
1376 tv
[0].tv_sec
= tv
[0].tv_usec
= 0;
1377 tv
[1].tv_sec
= tv
[1].tv_usec
= 0;
1378 if (!fstat( fd
, &st
))
1380 tv
[0].tv_sec
= st
.st_atime
;
1381 tv
[1].tv_sec
= st
.st_mtime
;
1384 if (info
->LastAccessTime
.QuadPart
)
1386 sec
= RtlLargeIntegerDivide( info
->LastAccessTime
.QuadPart
, 10000000, &nsec
);
1387 tv
[0].tv_sec
= sec
- SECS_1601_TO_1970
;
1388 tv
[0].tv_usec
= (UINT
)nsec
/ 10;
1390 if (info
->LastWriteTime
.QuadPart
)
1392 sec
= RtlLargeIntegerDivide( info
->LastWriteTime
.QuadPart
, 10000000, &nsec
);
1393 tv
[1].tv_sec
= sec
- SECS_1601_TO_1970
;
1394 tv
[1].tv_usec
= (UINT
)nsec
/ 10;
1396 if (futimes( fd
, tv
) == -1) io
->u
.Status
= FILE_GetNtStatus();
1399 if (io
->u
.Status
== STATUS_SUCCESS
&& info
->FileAttributes
)
1401 if (fstat( fd
, &st
) == -1) io
->u
.Status
= FILE_GetNtStatus();
1404 if (info
->FileAttributes
& FILE_ATTRIBUTE_READONLY
)
1406 if (S_ISDIR( st
.st_mode
))
1407 WARN("FILE_ATTRIBUTE_READONLY ignored for directory.\n");
1409 st
.st_mode
&= ~0222; /* clear write permission bits */
1413 /* add write permission only where we already have read permission */
1414 st
.st_mode
|= (0600 | ((st
.st_mode
& 044) >> 1)) & (~FILE_umask
);
1416 if (fchmod( fd
, st
.st_mode
) == -1) io
->u
.Status
= FILE_GetNtStatus();
1420 else io
->u
.Status
= STATUS_INVALID_PARAMETER_3
;
1423 case FilePositionInformation
:
1424 if (len
>= sizeof(FILE_POSITION_INFORMATION
))
1426 const FILE_POSITION_INFORMATION
*info
= ptr
;
1428 if (lseek( fd
, info
->CurrentByteOffset
.QuadPart
, SEEK_SET
) == (off_t
)-1)
1429 io
->u
.Status
= FILE_GetNtStatus();
1431 else io
->u
.Status
= STATUS_INVALID_PARAMETER_3
;
1434 case FileEndOfFileInformation
:
1435 if (len
>= sizeof(FILE_END_OF_FILE_INFORMATION
))
1438 const FILE_END_OF_FILE_INFORMATION
*info
= ptr
;
1440 /* first try normal truncate */
1441 if (ftruncate( fd
, (off_t
)info
->EndOfFile
.QuadPart
) != -1) break;
1443 /* now check for the need to extend the file */
1444 if (fstat( fd
, &st
) != -1 && (off_t
)info
->EndOfFile
.QuadPart
> st
.st_size
)
1446 static const char zero
;
1448 /* extend the file one byte beyond the requested size and then truncate it */
1449 /* this should work around ftruncate implementations that can't extend files */
1450 if (pwrite( fd
, &zero
, 1, (off_t
)info
->EndOfFile
.QuadPart
) != -1 &&
1451 ftruncate( fd
, (off_t
)info
->EndOfFile
.QuadPart
) != -1) break;
1453 io
->u
.Status
= FILE_GetNtStatus();
1455 else io
->u
.Status
= STATUS_INVALID_PARAMETER_3
;
1458 case FileMailslotSetInformation
:
1460 FILE_MAILSLOT_SET_INFORMATION
*info
= ptr
;
1462 SERVER_START_REQ( set_mailslot_info
)
1464 req
->handle
= handle
;
1465 req
->flags
= MAILSLOT_SET_READ_TIMEOUT
;
1466 req
->read_timeout
= info
->ReadTimeout
.QuadPart
/ -10000;
1467 io
->u
.Status
= wine_server_call( req
);
1474 FIXME("Unsupported class (%d)\n", class);
1475 io
->u
.Status
= STATUS_NOT_IMPLEMENTED
;
1478 wine_server_release_fd( handle
, fd
);
1479 io
->Information
= 0;
1480 return io
->u
.Status
;
1484 /******************************************************************************
1485 * NtQueryFullAttributesFile (NTDLL.@)
1487 NTSTATUS WINAPI
NtQueryFullAttributesFile( const OBJECT_ATTRIBUTES
*attr
,
1488 FILE_NETWORK_OPEN_INFORMATION
*info
)
1490 ANSI_STRING unix_name
;
1493 if (!(status
= wine_nt_to_unix_file_name( attr
->ObjectName
, &unix_name
, FILE_OPEN
,
1494 !(attr
->Attributes
& OBJ_CASE_INSENSITIVE
) )))
1498 if (stat( unix_name
.Buffer
, &st
) == -1)
1499 status
= FILE_GetNtStatus();
1500 else if (!S_ISREG(st
.st_mode
) && !S_ISDIR(st
.st_mode
))
1501 status
= STATUS_INVALID_INFO_CLASS
;
1504 if (S_ISDIR(st
.st_mode
))
1506 info
->FileAttributes
= FILE_ATTRIBUTE_DIRECTORY
;
1507 info
->AllocationSize
.QuadPart
= 0;
1508 info
->EndOfFile
.QuadPart
= 0;
1512 info
->FileAttributes
= FILE_ATTRIBUTE_ARCHIVE
;
1513 info
->AllocationSize
.QuadPart
= (ULONGLONG
)st
.st_blocks
* 512;
1514 info
->EndOfFile
.QuadPart
= st
.st_size
;
1516 if (!(st
.st_mode
& (S_IWUSR
| S_IWGRP
| S_IWOTH
)))
1517 info
->FileAttributes
|= FILE_ATTRIBUTE_READONLY
;
1518 RtlSecondsSince1970ToTime( st
.st_mtime
, &info
->CreationTime
);
1519 RtlSecondsSince1970ToTime( st
.st_mtime
, &info
->LastWriteTime
);
1520 RtlSecondsSince1970ToTime( st
.st_ctime
, &info
->ChangeTime
);
1521 RtlSecondsSince1970ToTime( st
.st_atime
, &info
->LastAccessTime
);
1522 if (DIR_is_hidden_file( attr
->ObjectName
))
1523 info
->FileAttributes
|= FILE_ATTRIBUTE_HIDDEN
;
1525 RtlFreeAnsiString( &unix_name
);
1527 else WARN("%s not found (%x)\n", debugstr_us(attr
->ObjectName
), status
);
1532 /******************************************************************************
1533 * NtQueryAttributesFile (NTDLL.@)
1534 * ZwQueryAttributesFile (NTDLL.@)
1536 NTSTATUS WINAPI
NtQueryAttributesFile( const OBJECT_ATTRIBUTES
*attr
, FILE_BASIC_INFORMATION
*info
)
1538 FILE_NETWORK_OPEN_INFORMATION full_info
;
1541 if (!(status
= NtQueryFullAttributesFile( attr
, &full_info
)))
1543 info
->CreationTime
.QuadPart
= full_info
.CreationTime
.QuadPart
;
1544 info
->LastAccessTime
.QuadPart
= full_info
.LastAccessTime
.QuadPart
;
1545 info
->LastWriteTime
.QuadPart
= full_info
.LastWriteTime
.QuadPart
;
1546 info
->ChangeTime
.QuadPart
= full_info
.ChangeTime
.QuadPart
;
1547 info
->FileAttributes
= full_info
.FileAttributes
;
1553 /******************************************************************************
1554 * FILE_GetDeviceInfo
1556 * Implementation of the FileFsDeviceInformation query for NtQueryVolumeInformationFile.
1558 NTSTATUS
FILE_GetDeviceInfo( int fd
, FILE_FS_DEVICE_INFORMATION
*info
)
1562 info
->Characteristics
= 0;
1563 if (fstat( fd
, &st
) < 0) return FILE_GetNtStatus();
1564 if (S_ISCHR( st
.st_mode
))
1566 info
->DeviceType
= FILE_DEVICE_UNKNOWN
;
1568 switch(major(st
.st_rdev
))
1571 info
->DeviceType
= FILE_DEVICE_NULL
;
1574 info
->DeviceType
= FILE_DEVICE_SERIAL_PORT
;
1577 info
->DeviceType
= FILE_DEVICE_PARALLEL_PORT
;
1579 case SCSI_TAPE_MAJOR
:
1580 info
->DeviceType
= FILE_DEVICE_TAPE
;
1585 else if (S_ISBLK( st
.st_mode
))
1587 info
->DeviceType
= FILE_DEVICE_DISK
;
1589 else if (S_ISFIFO( st
.st_mode
) || S_ISSOCK( st
.st_mode
))
1591 info
->DeviceType
= FILE_DEVICE_NAMED_PIPE
;
1593 else /* regular file or directory */
1595 #if defined(linux) && defined(HAVE_FSTATFS)
1598 /* check for floppy disk */
1599 if (major(st
.st_dev
) == FLOPPY_MAJOR
)
1600 info
->Characteristics
|= FILE_REMOVABLE_MEDIA
;
1602 if (fstatfs( fd
, &stfs
) < 0) stfs
.f_type
= 0;
1603 switch (stfs
.f_type
)
1605 case 0x9660: /* iso9660 */
1606 case 0x9fa1: /* supermount */
1607 case 0x15013346: /* udf */
1608 info
->DeviceType
= FILE_DEVICE_CD_ROM_FILE_SYSTEM
;
1609 info
->Characteristics
|= FILE_REMOVABLE_MEDIA
|FILE_READ_ONLY_DEVICE
;
1611 case 0x6969: /* nfs */
1612 case 0x517B: /* smbfs */
1613 case 0x564c: /* ncpfs */
1614 info
->DeviceType
= FILE_DEVICE_NETWORK_FILE_SYSTEM
;
1615 info
->Characteristics
|= FILE_REMOTE_DEVICE
;
1617 case 0x01021994: /* tmpfs */
1618 case 0x28cd3d45: /* cramfs */
1619 case 0x1373: /* devfs */
1620 case 0x9fa0: /* procfs */
1621 info
->DeviceType
= FILE_DEVICE_VIRTUAL_DISK
;
1624 info
->DeviceType
= FILE_DEVICE_DISK_FILE_SYSTEM
;
1627 #elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__APPLE__)
1630 /* The proper way to do this in FreeBSD seems to be with the
1631 * name rather than the type, since their linux-compatible
1632 * fstatfs call converts the name to one of the Linux types.
1634 if (fstatfs( fd
, &stfs
) < 0)
1635 info
->DeviceType
= FILE_DEVICE_DISK_FILE_SYSTEM
;
1636 else if (!strncmp("cd9660", stfs
.f_fstypename
, sizeof(stfs
.f_fstypename
)) ||
1637 !strncmp("udf", stfs
.f_fstypename
, sizeof(stfs
.f_fstypename
)))
1639 info
->DeviceType
= FILE_DEVICE_CD_ROM_FILE_SYSTEM
;
1640 /* Don't assume read-only, let the mount options set it below */
1641 info
->Characteristics
|= FILE_REMOVABLE_MEDIA
;
1643 else if (!strncmp("nfs", stfs
.f_fstypename
, sizeof(stfs
.f_fstypename
)) ||
1644 !strncmp("nwfs", stfs
.f_fstypename
, sizeof(stfs
.f_fstypename
)))
1646 info
->DeviceType
= FILE_DEVICE_NETWORK_FILE_SYSTEM
;
1647 info
->Characteristics
|= FILE_REMOTE_DEVICE
;
1649 else if (!strncmp("procfs", stfs
.f_fstypename
,
1650 sizeof(stfs
.f_fstypename
)))
1651 info
->DeviceType
= FILE_DEVICE_VIRTUAL_DISK
;
1653 info
->DeviceType
= FILE_DEVICE_DISK_FILE_SYSTEM
;
1654 if (stfs
.f_flags
& MNT_RDONLY
)
1655 info
->Characteristics
|= FILE_READ_ONLY_DEVICE
;
1656 if (!(stfs
.f_flags
& MNT_LOCAL
))
1658 info
->DeviceType
= FILE_DEVICE_NETWORK_FILE_SYSTEM
;
1659 info
->Characteristics
|= FILE_REMOTE_DEVICE
;
1662 /* Use dkio to work out device types */
1664 # include <sys/dkio.h>
1665 # include <sys/vtoc.h>
1666 struct dk_cinfo dkinf
;
1667 int retval
= ioctl(fd
, DKIOCINFO
, &dkinf
);
1669 WARN("Unable to get disk device type information - assuming a disk like device\n");
1670 info
->DeviceType
= FILE_DEVICE_DISK_FILE_SYSTEM
;
1672 switch (dkinf
.dki_ctype
)
1675 info
->DeviceType
= FILE_DEVICE_CD_ROM_FILE_SYSTEM
;
1676 info
->Characteristics
|= FILE_REMOVABLE_MEDIA
|FILE_READ_ONLY_DEVICE
;
1680 case DKC_INTEL82072
:
1681 case DKC_INTEL82077
:
1682 info
->DeviceType
= FILE_DEVICE_DISK_FILE_SYSTEM
;
1683 info
->Characteristics
|= FILE_REMOVABLE_MEDIA
;
1686 info
->DeviceType
= FILE_DEVICE_VIRTUAL_DISK
;
1689 info
->DeviceType
= FILE_DEVICE_DISK_FILE_SYSTEM
;
1694 if (!warned
++) FIXME( "device info not properly supported on this platform\n" );
1695 info
->DeviceType
= FILE_DEVICE_DISK_FILE_SYSTEM
;
1697 info
->Characteristics
|= FILE_DEVICE_IS_MOUNTED
;
1699 return STATUS_SUCCESS
;
1703 /******************************************************************************
1704 * NtQueryVolumeInformationFile [NTDLL.@]
1705 * ZwQueryVolumeInformationFile [NTDLL.@]
1707 * Get volume information for an open file handle.
1710 * handle [I] Handle returned from ZwOpenFile() or ZwCreateFile()
1711 * io [O] Receives information about the operation on return
1712 * buffer [O] Destination for volume information
1713 * length [I] Size of FsInformation
1714 * info_class [I] Type of volume information to set
1717 * Success: 0. io and buffer are updated.
1718 * Failure: An NTSTATUS error code describing the error.
1720 NTSTATUS WINAPI
NtQueryVolumeInformationFile( HANDLE handle
, PIO_STATUS_BLOCK io
,
1721 PVOID buffer
, ULONG length
,
1722 FS_INFORMATION_CLASS info_class
)
1727 if ((io
->u
.Status
= wine_server_handle_to_fd( handle
, 0, &fd
, NULL
)) != STATUS_SUCCESS
)
1728 return io
->u
.Status
;
1730 io
->u
.Status
= STATUS_NOT_IMPLEMENTED
;
1731 io
->Information
= 0;
1733 switch( info_class
)
1735 case FileFsVolumeInformation
:
1736 FIXME( "%p: volume info not supported\n", handle
);
1738 case FileFsLabelInformation
:
1739 FIXME( "%p: label info not supported\n", handle
);
1741 case FileFsSizeInformation
:
1742 if (length
< sizeof(FILE_FS_SIZE_INFORMATION
))
1743 io
->u
.Status
= STATUS_BUFFER_TOO_SMALL
;
1746 FILE_FS_SIZE_INFORMATION
*info
= buffer
;
1748 if (fstat( fd
, &st
) < 0)
1750 io
->u
.Status
= FILE_GetNtStatus();
1753 if (!S_ISREG(st
.st_mode
) && !S_ISDIR(st
.st_mode
))
1755 io
->u
.Status
= STATUS_INVALID_DEVICE_REQUEST
;
1759 /* Linux's fstatvfs is buggy */
1760 #if !defined(linux) || !defined(HAVE_FSTATFS)
1761 struct statvfs stfs
;
1763 if (fstatvfs( fd
, &stfs
) < 0)
1765 io
->u
.Status
= FILE_GetNtStatus();
1768 info
->BytesPerSector
= stfs
.f_frsize
;
1771 if (fstatfs( fd
, &stfs
) < 0)
1773 io
->u
.Status
= FILE_GetNtStatus();
1776 info
->BytesPerSector
= stfs
.f_bsize
;
1778 info
->TotalAllocationUnits
.QuadPart
= stfs
.f_blocks
;
1779 info
->AvailableAllocationUnits
.QuadPart
= stfs
.f_bavail
;
1780 info
->SectorsPerAllocationUnit
= 1;
1781 io
->Information
= sizeof(*info
);
1782 io
->u
.Status
= STATUS_SUCCESS
;
1786 case FileFsDeviceInformation
:
1787 if (length
< sizeof(FILE_FS_DEVICE_INFORMATION
))
1788 io
->u
.Status
= STATUS_BUFFER_TOO_SMALL
;
1791 FILE_FS_DEVICE_INFORMATION
*info
= buffer
;
1793 if ((io
->u
.Status
= FILE_GetDeviceInfo( fd
, info
)) == STATUS_SUCCESS
)
1794 io
->Information
= sizeof(*info
);
1797 case FileFsAttributeInformation
:
1798 FIXME( "%p: attribute info not supported\n", handle
);
1800 case FileFsControlInformation
:
1801 FIXME( "%p: control info not supported\n", handle
);
1803 case FileFsFullSizeInformation
:
1804 FIXME( "%p: full size info not supported\n", handle
);
1806 case FileFsObjectIdInformation
:
1807 FIXME( "%p: object id info not supported\n", handle
);
1809 case FileFsMaximumInformation
:
1810 FIXME( "%p: maximum info not supported\n", handle
);
1813 io
->u
.Status
= STATUS_INVALID_PARAMETER
;
1816 wine_server_release_fd( handle
, fd
);
1817 return io
->u
.Status
;
1821 /******************************************************************
1822 * NtFlushBuffersFile (NTDLL.@)
1824 * Flush any buffered data on an open file handle.
1827 * FileHandle [I] Handle returned from ZwOpenFile() or ZwCreateFile()
1828 * IoStatusBlock [O] Receives information about the operation on return
1831 * Success: 0. IoStatusBlock is updated.
1832 * Failure: An NTSTATUS error code describing the error.
1834 NTSTATUS WINAPI
NtFlushBuffersFile( HANDLE hFile
, IO_STATUS_BLOCK
* IoStatusBlock
)
1837 HANDLE hEvent
= NULL
;
1839 SERVER_START_REQ( flush_file
)
1841 req
->handle
= hFile
;
1842 ret
= wine_server_call( req
);
1843 hEvent
= reply
->event
;
1848 ret
= NtWaitForSingleObject( hEvent
, FALSE
, NULL
);
1854 /******************************************************************
1855 * NtLockFile (NTDLL.@)
1859 NTSTATUS WINAPI
NtLockFile( HANDLE hFile
, HANDLE lock_granted_event
,
1860 PIO_APC_ROUTINE apc
, void* apc_user
,
1861 PIO_STATUS_BLOCK io_status
, PLARGE_INTEGER offset
,
1862 PLARGE_INTEGER count
, ULONG
* key
, BOOLEAN dont_wait
,
1869 if (apc
|| io_status
|| key
)
1871 FIXME("Unimplemented yet parameter\n");
1872 return STATUS_NOT_IMPLEMENTED
;
1877 SERVER_START_REQ( lock_file
)
1879 req
->handle
= hFile
;
1880 req
->offset_low
= offset
->u
.LowPart
;
1881 req
->offset_high
= offset
->u
.HighPart
;
1882 req
->count_low
= count
->u
.LowPart
;
1883 req
->count_high
= count
->u
.HighPart
;
1884 req
->shared
= !exclusive
;
1885 req
->wait
= !dont_wait
;
1886 ret
= wine_server_call( req
);
1887 handle
= reply
->handle
;
1888 async
= reply
->overlapped
;
1891 if (ret
!= STATUS_PENDING
)
1893 if (!ret
&& lock_granted_event
) NtSetEvent(lock_granted_event
, NULL
);
1899 FIXME( "Async I/O lock wait not implemented, might deadlock\n" );
1900 if (handle
) NtClose( handle
);
1901 return STATUS_PENDING
;
1905 NtWaitForSingleObject( handle
, FALSE
, NULL
);
1912 /* Unix lock conflict, sleep a bit and retry */
1913 time
.QuadPart
= 100 * (ULONGLONG
)10000;
1914 time
.QuadPart
= -time
.QuadPart
;
1915 NtDelayExecution( FALSE
, &time
);
1921 /******************************************************************
1922 * NtUnlockFile (NTDLL.@)
1926 NTSTATUS WINAPI
NtUnlockFile( HANDLE hFile
, PIO_STATUS_BLOCK io_status
,
1927 PLARGE_INTEGER offset
, PLARGE_INTEGER count
,
1932 TRACE( "%p %x%08x %x%08x\n",
1933 hFile
, offset
->u
.HighPart
, offset
->u
.LowPart
, count
->u
.HighPart
, count
->u
.LowPart
);
1935 if (io_status
|| key
)
1937 FIXME("Unimplemented yet parameter\n");
1938 return STATUS_NOT_IMPLEMENTED
;
1941 SERVER_START_REQ( unlock_file
)
1943 req
->handle
= hFile
;
1944 req
->offset_low
= offset
->u
.LowPart
;
1945 req
->offset_high
= offset
->u
.HighPart
;
1946 req
->count_low
= count
->u
.LowPart
;
1947 req
->count_high
= count
->u
.HighPart
;
1948 status
= wine_server_call( req
);
1954 /******************************************************************
1955 * NtCreateNamedPipeFile (NTDLL.@)
1959 NTSTATUS WINAPI
NtCreateNamedPipeFile( PHANDLE handle
, ULONG access
,
1960 POBJECT_ATTRIBUTES attr
, PIO_STATUS_BLOCK iosb
,
1961 ULONG sharing
, ULONG dispo
, ULONG options
,
1962 ULONG pipe_type
, ULONG read_mode
,
1963 ULONG completion_mode
, ULONG max_inst
,
1964 ULONG inbound_quota
, ULONG outbound_quota
,
1965 PLARGE_INTEGER timeout
)
1968 static const WCHAR leadin
[] = {'\\','?','?','\\','P','I','P','E','\\'};
1970 TRACE("(%p %x %s %p %x %d %x %d %d %d %d %d %d %p)\n",
1971 handle
, access
, debugstr_w(attr
->ObjectName
->Buffer
), iosb
, sharing
, dispo
,
1972 options
, pipe_type
, read_mode
, completion_mode
, max_inst
, inbound_quota
,
1973 outbound_quota
, timeout
);
1975 if (attr
->ObjectName
->Length
< sizeof(leadin
) ||
1976 strncmpiW( attr
->ObjectName
->Buffer
,
1977 leadin
, sizeof(leadin
)/sizeof(leadin
[0]) ))
1978 return STATUS_OBJECT_NAME_INVALID
;
1979 /* assume we only get relative timeout, and storable in a DWORD as ms */
1980 if (timeout
->QuadPart
> 0 || (timeout
->QuadPart
/ -10000) >> 32)
1981 FIXME("Wrong time %s\n", wine_dbgstr_longlong(timeout
->QuadPart
));
1983 SERVER_START_REQ( create_named_pipe
)
1985 req
->access
= access
;
1986 req
->attributes
= (attr
) ? attr
->Attributes
: 0;
1987 req
->rootdir
= attr
? attr
->RootDirectory
: 0;
1988 req
->options
= options
;
1990 (pipe_type
) ? NAMED_PIPE_MESSAGE_STREAM_WRITE
: 0 |
1991 (read_mode
) ? NAMED_PIPE_MESSAGE_STREAM_READ
: 0 |
1992 (completion_mode
) ? NAMED_PIPE_NONBLOCKING_MODE
: 0;
1993 req
->maxinstances
= max_inst
;
1994 req
->outsize
= outbound_quota
;
1995 req
->insize
= inbound_quota
;
1996 req
->timeout
= timeout
->QuadPart
/ -10000;
1997 wine_server_add_data( req
, attr
->ObjectName
->Buffer
,
1998 attr
->ObjectName
->Length
);
1999 status
= wine_server_call( req
);
2000 if (!status
) *handle
= reply
->handle
;
2006 /******************************************************************
2007 * NtDeleteFile (NTDLL.@)
2011 NTSTATUS WINAPI
NtDeleteFile( POBJECT_ATTRIBUTES ObjectAttributes
)
2017 TRACE("%p\n", ObjectAttributes
);
2018 status
= NtCreateFile( &hFile
, GENERIC_READ
| GENERIC_WRITE
| DELETE
,
2019 ObjectAttributes
, &io
, NULL
, 0,
2020 FILE_SHARE_READ
| FILE_SHARE_WRITE
| FILE_SHARE_DELETE
,
2021 FILE_OPEN
, FILE_DELETE_ON_CLOSE
, NULL
, 0 );
2022 if (status
== STATUS_SUCCESS
) status
= NtClose(hFile
);
2026 /******************************************************************
2027 * NtCancelIoFile (NTDLL.@)
2031 NTSTATUS WINAPI
NtCancelIoFile( HANDLE hFile
, PIO_STATUS_BLOCK io_status
)
2033 LARGE_INTEGER timeout
;
2035 TRACE("%p %p\n", hFile
, io_status
);
2037 SERVER_START_REQ( cancel_async
)
2039 req
->handle
= hFile
;
2040 wine_server_call( req
);
2043 /* Let some APC be run, so that we can run the remaining APCs on hFile
2044 * either the cancelation of the pending one, but also the execution
2045 * of the queued APC, but not yet run. This is needed to ensure proper
2046 * clean-up of allocated data.
2048 timeout
.u
.LowPart
= timeout
.u
.HighPart
= 0;
2049 return io_status
->u
.Status
= NtDelayExecution( TRUE
, &timeout
);
2052 /******************************************************************************
2053 * NtCreateMailslotFile [NTDLL.@]
2054 * ZwCreateMailslotFile [NTDLL.@]
2057 * pHandle [O] pointer to receive the handle created
2058 * DesiredAccess [I] access mode (read, write, etc)
2059 * ObjectAttributes [I] fully qualified NT path of the mailslot
2060 * IoStatusBlock [O] receives completion status and other info
2063 * MaxMessageSize [I]
2069 NTSTATUS WINAPI
NtCreateMailslotFile(PHANDLE pHandle
, ULONG DesiredAccess
,
2070 POBJECT_ATTRIBUTES attr
, PIO_STATUS_BLOCK IoStatusBlock
,
2071 ULONG CreateOptions
, ULONG MailslotQuota
, ULONG MaxMessageSize
,
2072 PLARGE_INTEGER TimeOut
)
2074 static const WCHAR leadin
[] = {
2075 '\\','?','?','\\','M','A','I','L','S','L','O','T','\\'};
2078 TRACE("%p %08x %p %p %08x %08x %08x %p\n",
2079 pHandle
, DesiredAccess
, attr
, IoStatusBlock
,
2080 CreateOptions
, MailslotQuota
, MaxMessageSize
, TimeOut
);
2082 if (attr
->ObjectName
->Length
< sizeof(leadin
) ||
2083 strncmpiW( attr
->ObjectName
->Buffer
,
2084 leadin
, sizeof(leadin
)/sizeof(leadin
[0]) ))
2086 return STATUS_OBJECT_NAME_INVALID
;
2089 SERVER_START_REQ( create_mailslot
)
2091 req
->access
= DesiredAccess
;
2092 req
->attributes
= (attr
) ? attr
->Attributes
: 0;
2093 req
->rootdir
= attr
? attr
->RootDirectory
: 0;
2094 req
->max_msgsize
= MaxMessageSize
;
2095 req
->read_timeout
= (TimeOut
->QuadPart
<= 0) ? TimeOut
->QuadPart
/ -10000 : -1;
2096 wine_server_add_data( req
, attr
->ObjectName
->Buffer
,
2097 attr
->ObjectName
->Length
);
2098 ret
= wine_server_call( req
);
2099 if( ret
== STATUS_SUCCESS
)
2100 *pHandle
= reply
->handle
;