server: Use attributes instead of inherit flag in file requests.
[wine/gsoc_dplay.git] / dlls / ntdll / file.c
blob2e702965cdd6388d438cde6d3dd0efd374db7b84
1 /*
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
19 #include "config.h"
20 #include "wine/port.h"
22 #include <stdlib.h>
23 #include <string.h>
24 #include <stdio.h>
25 #include <errno.h>
26 #include <assert.h>
27 #ifdef HAVE_UNISTD_H
28 # include <unistd.h>
29 #endif
30 #ifdef HAVE_SYS_ERRNO_H
31 #include <sys/errno.h>
32 #endif
33 #ifdef HAVE_LINUX_MAJOR_H
34 # include <linux/major.h>
35 #endif
36 #ifdef HAVE_SYS_STATVFS_H
37 # include <sys/statvfs.h>
38 #endif
39 #ifdef HAVE_SYS_PARAM_H
40 # include <sys/param.h>
41 #endif
42 #ifdef HAVE_SYS_TIME_H
43 # include <sys/time.h>
44 #endif
45 #ifdef HAVE_UTIME_H
46 # include <utime.h>
47 #endif
48 #ifdef STATFS_DEFINED_BY_SYS_VFS
49 # include <sys/vfs.h>
50 #else
51 # ifdef STATFS_DEFINED_BY_SYS_MOUNT
52 # include <sys/mount.h>
53 # else
54 # ifdef STATFS_DEFINED_BY_SYS_STATFS
55 # include <sys/statfs.h>
56 # endif
57 # endif
58 #endif
60 #ifdef HAVE_IOKIT_IOKITLIB_H
61 # include <IOKit/IOKitLib.h>
62 # include <CoreFoundation/CFNumber.h> /* for kCFBooleanTrue, kCFBooleanFalse */
63 # include <paths.h>
64 #endif
66 #define NONAMELESSUNION
67 #define NONAMELESSSTRUCT
68 #include "ntstatus.h"
69 #define WIN32_NO_STATUS
70 #include "wine/unicode.h"
71 #include "wine/debug.h"
72 #include "thread.h"
73 #include "wine/server.h"
74 #include "ntdll_misc.h"
76 #include "winternl.h"
77 #include "winioctl.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.@]
90 * Open a file.
92 * PARAMS
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
100 * RETURNS
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.
119 * PARAMS
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
132 * RETURNS
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;
144 int created = FALSE;
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;
172 SERVER_END_REQ;
173 return io->u.Status;
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;
192 SERVER_END_REQ;
193 return io->u.Status;
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)
208 created = TRUE;
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;
226 SERVER_END_REQ;
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)
236 case FILE_SUPERSEDE:
237 io->Information = FILE_SUPERSEDED;
238 break;
239 case FILE_CREATE:
240 io->Information = FILE_CREATED;
241 break;
242 case FILE_OPEN:
243 case FILE_OPEN_IF:
244 io->Information = FILE_OPENED;
245 break;
246 case FILE_OVERWRITE:
247 case FILE_OVERWRITE_IF:
248 io->Information = FILE_OVERWRITTEN;
249 break;
253 return io->u.Status;
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
264 HANDLE handle;
265 PIO_APC_ROUTINE apc;
266 void* apc_user;
267 char* buffer;
268 unsigned int count;
269 off_t offset;
270 int queue_apc_on_error;
271 BOOL avail_mode;
272 int fd;
273 HANDLE event;
274 } async_fileio;
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 );
284 if (fileio->apc &&
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,
293 BOOL do_read)
295 PIO_APC_ROUTINE apc = do_read ? FILE_AsyncReadService : FILE_AsyncWriteService;
296 NTSTATUS status;
298 SERVER_START_REQ( register_async )
300 req->handle = fileio->handle;
301 req->io_apc = apc;
302 req->io_sb = iosb;
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 );
309 SERVER_END_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)
329 int err = errno;
331 TRACE( "errno = %d\n", errno );
332 switch (err)
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;
338 case EPERM:
339 case EROFS:
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;
344 case EMFILE:
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;
350 #ifdef ENOMEDIUM
351 case ENOMEDIUM: return STATUS_NO_MEDIA_IN_DEVICE;
352 #endif
353 case ENOTTY:
354 case EOPNOTSUPP:return STATUS_NOT_SUPPORTED;
355 case ECONNRESET:return STATUS_PIPE_DISCONNECTED;
356 case ENOEXEC: /* ?? */
357 case ESPIPE: /* ?? */
358 case EEXIST: /* ?? */
359 default:
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;
374 int result;
375 int already = iosb->Information;
377 TRACE("%p %p 0x%lx\n", iosb, fileio->buffer, status);
379 switch (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);
387 else
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);
397 if (result < 0)
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;
411 else
413 iosb->Information += result;
414 if (iosb->Information >= fileio->count || fileio->avail_mode)
415 iosb->u.Status = STATUS_SUCCESS;
416 else
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);
432 else
433 fileio_terminate(fileio, iosb);
434 break;
435 default:
436 iosb->u.Status = status;
437 fileio_terminate(fileio, iosb);
438 break;
443 /******************************************************************************
444 * NtReadFile [NTDLL.@]
445 * ZwReadFile [NTDLL.@]
447 * Read from an open file handle.
449 * PARAMS
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)
460 * RETURNS
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)
489 if (hEvent)
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;
507 NTSTATUS ret;
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 )
518 fileio->offset = 0;
519 else
521 fileio->offset = offset->QuadPart;
522 if (offset->u.HighPart && fileio->offset == offset->u.LowPart)
523 FIXME("High part of offset is lost\n");
525 fileio->apc = apc;
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);
540 return ret;
542 if (flags & FD_FLAG_TIMEOUT)
546 ret = NtWaitForSingleObject(hEvent, TRUE, NULL);
548 while (ret == STATUS_USER_APC && io_status->u.Status == STATUS_PENDING);
549 NtClose(hEvent);
550 if (ret != STATUS_USER_APC)
551 fileio->queue_apc_on_error = 1;
553 else
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
564 * waits */
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;
572 if (offset)
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;
589 if (errno == EFAULT)
591 io_status->Information = 0;
592 io_status->u.Status = STATUS_ACCESS_VIOLATION;
594 else io_status->u.Status = FILE_GetNtStatus();
595 break;
597 if (io_status->u.Status == STATUS_SUCCESS && io_status->Information == 0)
599 struct stat st;
600 if (fstat( unix_handle, &st ) != -1 && S_ISSOCK( st.st_mode ))
601 io_status->u.Status = STATUS_PIPE_BROKEN;
602 else
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;
619 int result;
620 int already = iosb->Information;
622 TRACE("(%p %p 0x%lx)\n",iosb, fileio->buffer, status);
624 switch (status)
626 case STATUS_ALERTED:
627 /* write some data (non-blocking) */
628 if ( fileio->avail_mode )
629 result = write(fileio->fd, &fileio->buffer[already],
630 fileio->count - already);
631 else
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);
640 if (result < 0)
642 if (errno == EAGAIN || errno == EINTR) iosb->u.Status = STATUS_PENDING;
643 else iosb->u.Status = FILE_GetNtStatus();
645 else
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);
654 else
655 fileio_terminate(fileio, iosb);
656 break;
657 default:
658 iosb->u.Status = status;
659 fileio_terminate(fileio, iosb);
660 break;
664 /******************************************************************************
665 * NtWriteFile [NTDLL.@]
666 * ZwWriteFile [NTDLL.@]
668 * Write to an open file handle.
670 * PARAMS
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)
681 * RETURNS
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)
711 if (hEvent)
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;
729 NTSTATUS ret;
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;
739 if (offset)
741 fileio->offset = offset->QuadPart;
742 if (offset->u.HighPart && fileio->offset == offset->u.LowPart)
743 FIXME("High part of offset is lost\n");
745 else
747 fileio->offset = 0;
749 fileio->apc = apc;
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);
765 return ret;
767 if (flags & FD_FLAG_TIMEOUT)
771 ret = NtWaitForSingleObject(hEvent, TRUE, NULL);
773 while (ret == STATUS_USER_APC && io_status->u.Status == STATUS_PENDING);
774 NtClose(hEvent);
775 if (ret != STATUS_USER_APC)
776 fileio->queue_apc_on_error = 1;
778 else
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
789 * waits */
790 if (ret != STATUS_USER_APC)
791 fileio->queue_apc_on_error = 1;
793 return io_status->u.Status;
796 if (offset)
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;
814 if (errno == EFAULT)
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();
821 break;
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.
833 * PARAMS
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
845 * RETURNS
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,
853 ULONG IoControlCode,
854 PVOID InputBuffer,
855 ULONG InputBufferSize,
856 PVOID OutputBuffer,
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);
886 if (iosb)
887 iosb->u.Status = status;
888 NtSetEvent(event, NULL);
889 TRACE("done\n");
892 /**************************************************************************
893 * NtFsControlFile [NTDLL.@]
894 * ZwFsControlFile [NTDLL.@]
896 * Perform a file system control operation on an open file handle.
898 * PARAMS
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
910 * RETURNS
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)
918 NTSTATUS ret;
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 );
930 break;
932 case FSCTL_PIPE_LISTEN :
934 HANDLE internal_event;
936 if(!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);
951 SERVER_END_REQ;
953 if(ret == STATUS_SUCCESS)
955 if(Event)
956 ret = STATUS_PENDING;
957 else
960 ret = NtWaitForSingleObject(internal_event, TRUE, NULL);
961 while(ret == STATUS_USER_APC);
962 NtClose(internal_event);
965 break;
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);
974 SERVER_END_REQ;
975 break;
976 default :
977 FIXME("Unsupported FsControlCode %lx\n", FsControlCode);
978 ret = STATUS_NOT_SUPPORTED;
979 break;
981 IoStatusBlock->u.Status = ret;
982 return ret;
985 /******************************************************************************
986 * NtSetVolumeInformationFile [NTDLL.@]
987 * ZwSetVolumeInformationFile [NTDLL.@]
989 * Set volume information for an open file handle.
991 * PARAMS
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
998 * RETURNS
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,
1006 ULONG Length,
1007 FS_INFORMATION_CLASS FsInformationClass)
1009 FIXME("(%p,%p,%p,0x%08lx,0x%08x) stub\n",
1010 FileHandle,IoStatusBlock,FsInformation,Length,FsInformationClass);
1011 return 0;
1014 /******************************************************************************
1015 * NtQueryInformationFile [NTDLL.@]
1016 * ZwQueryInformationFile [NTDLL.@]
1018 * Get information about an open file handle.
1020 * PARAMS
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
1027 * RETURNS
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 */
1075 struct stat st;
1076 int fd;
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;
1095 switch (class)
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;
1105 else
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);
1117 break;
1118 case FileStandardInformation:
1120 FILE_STANDARD_INFORMATION *info = ptr;
1122 if (fstat( fd, &st ) == -1) io->u.Status = FILE_GetNtStatus();
1123 else
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;
1132 else
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 */
1141 break;
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;
1149 break;
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;
1157 break;
1158 case FileEaInformation:
1160 FILE_EA_INFORMATION *info = ptr;
1161 info->EaSize = 0;
1163 break;
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;
1171 break;
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;
1179 else
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;
1189 else
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);
1213 break;
1214 case FileMailslotQueryInformation:
1216 FILE_MAILSLOT_QUERY_INFORMATION *info = ptr;
1218 SERVER_START_REQ( set_mailslot_info )
1220 req->handle = hFile;
1221 req->flags = 0;
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;
1232 SERVER_END_REQ;
1234 break;
1235 default:
1236 FIXME("Unsupported class (%d)\n", class);
1237 io->u.Status = STATUS_NOT_IMPLEMENTED;
1238 break;
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.
1251 * PARAMS
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
1258 * RETURNS
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)
1265 int fd;
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;
1273 switch (class)
1275 case FileBasicInformation:
1276 if (len >= sizeof(FILE_BASIC_INFORMATION))
1278 struct stat st;
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();
1315 else
1317 if (info->FileAttributes & FILE_ATTRIBUTE_READONLY)
1319 if (S_ISDIR( st.st_mode))
1320 WARN("FILE_ATTRIBUTE_READONLY ignored for directory.\n");
1321 else
1322 st.st_mode &= ~0222; /* clear write permission bits */
1324 else
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;
1334 break;
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;
1345 break;
1347 case FileEndOfFileInformation:
1348 if (len >= sizeof(FILE_END_OF_FILE_INFORMATION))
1350 struct stat st;
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;
1369 break;
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 );
1382 SERVER_END_REQ;
1384 break;
1386 default:
1387 FIXME("Unsupported class (%d)\n", class);
1388 io->u.Status = STATUS_NOT_IMPLEMENTED;
1389 break;
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;
1404 NTSTATUS status;
1406 if (!(status = wine_nt_to_unix_file_name( attr->ObjectName, &unix_name, FILE_OPEN,
1407 !(attr->Attributes & OBJ_CASE_INSENSITIVE) )))
1409 struct stat st;
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;
1415 else
1417 if (S_ISDIR(st.st_mode))
1419 info->FileAttributes = FILE_ATTRIBUTE_DIRECTORY;
1420 info->AllocationSize.QuadPart = 0;
1421 info->EndOfFile.QuadPart = 0;
1423 else
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 );
1441 return 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;
1452 NTSTATUS status;
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;
1462 return status;
1466 /******************************************************************************
1467 * FILE_GetDeviceInfo
1469 * Implementation of the FileFsDeviceInformation query for NtQueryVolumeInformationFile.
1471 NTSTATUS FILE_GetDeviceInfo( int fd, FILE_FS_DEVICE_INFORMATION *info )
1473 struct stat st;
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;
1480 #ifdef linux
1481 switch(major(st.st_rdev))
1483 case MEM_MAJOR:
1484 info->DeviceType = FILE_DEVICE_NULL;
1485 break;
1486 case TTY_MAJOR:
1487 info->DeviceType = FILE_DEVICE_SERIAL_PORT;
1488 break;
1489 case LP_MAJOR:
1490 info->DeviceType = FILE_DEVICE_PARALLEL_PORT;
1491 break;
1493 #endif
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)
1506 struct statfs stfs;
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;
1519 break;
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;
1525 break;
1526 case 0x01021994: /* tmpfs */
1527 case 0x28cd3d45: /* cramfs */
1528 case 0x1373: /* devfs */
1529 case 0x9fa0: /* procfs */
1530 info->DeviceType = FILE_DEVICE_VIRTUAL_DISK;
1531 break;
1532 default:
1533 info->DeviceType = FILE_DEVICE_DISK_FILE_SYSTEM;
1534 break;
1536 #elif defined(__FreeBSD__)
1537 struct statfs stfs;
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
1550 * below
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;
1569 else
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__)
1579 struct statfs stfs;
1580 kern_return_t kernResult = KERN_FAILURE;
1581 mach_port_t masterPort;
1582 char bsdName[6]; /* disk#\0 */
1583 const char *name;
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);
1600 if (matching)
1602 CFStringRef type;
1603 CFMutableDictionaryRef properties;
1604 io_service_t devService = IOServiceGetMatchingService(masterPort, matching);
1606 if (IORegistryEntryCreateCFProperties(devService,
1607 &properties,
1608 kCFAllocatorDefault, 0) != KERN_SUCCESS)
1609 return FILE_GetNtStatus(); /* FIXME */
1610 if ( CFEqual(
1611 CFDictionaryGetValue(properties, CFSTR("Removable")),
1612 kCFBooleanTrue)
1613 ) info->Characteristics |= FILE_REMOVABLE_MEDIA;
1615 if ( CFEqual(
1616 CFDictionaryGetValue(properties, CFSTR("Writable")),
1617 kCFBooleanFalse)
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;
1633 if (properties)
1634 CFRelease(properties);
1637 #elif defined(sun)
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);
1644 if(retval==-1){
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)
1650 case DKC_CDROM:
1651 info->DeviceType = FILE_DEVICE_CD_ROM_FILE_SYSTEM;
1652 info->Characteristics |= FILE_REMOVABLE_MEDIA|FILE_READ_ONLY_DEVICE;
1653 break;
1654 case DKC_NCRFLOPPY:
1655 case DKC_SMSFLOPPY:
1656 case DKC_INTEL82072:
1657 case DKC_INTEL82077:
1658 info->DeviceType = FILE_DEVICE_DISK_FILE_SYSTEM;
1659 info->Characteristics |= FILE_REMOVABLE_MEDIA;
1660 break;
1661 case DKC_MD:
1662 info->DeviceType = FILE_DEVICE_VIRTUAL_DISK;
1663 break;
1664 default:
1665 info->DeviceType = FILE_DEVICE_DISK_FILE_SYSTEM;
1668 #else
1669 static int warned;
1670 if (!warned++) FIXME( "device info not properly supported on this platform\n" );
1671 info->DeviceType = FILE_DEVICE_DISK_FILE_SYSTEM;
1672 #endif
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.
1685 * PARAMS
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
1692 * RETURNS
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 )
1700 int fd;
1701 struct stat st;
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 );
1713 break;
1714 case FileFsLabelInformation:
1715 FIXME( "%p: label info not supported\n", handle );
1716 break;
1717 case FileFsSizeInformation:
1718 if (length < sizeof(FILE_FS_SIZE_INFORMATION))
1719 io->u.Status = STATUS_BUFFER_TOO_SMALL;
1720 else
1722 FILE_FS_SIZE_INFORMATION *info = buffer;
1724 if (fstat( fd, &st ) < 0)
1726 io->u.Status = FILE_GetNtStatus();
1727 break;
1729 if (!S_ISREG(st.st_mode) && !S_ISDIR(st.st_mode))
1731 io->u.Status = STATUS_INVALID_DEVICE_REQUEST;
1733 else
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();
1742 break;
1744 info->BytesPerSector = stfs.f_frsize;
1745 #else
1746 struct statfs stfs;
1747 if (fstatfs( fd, &stfs ) < 0)
1749 io->u.Status = FILE_GetNtStatus();
1750 break;
1752 info->BytesPerSector = stfs.f_bsize;
1753 #endif
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;
1761 break;
1762 case FileFsDeviceInformation:
1763 if (length < sizeof(FILE_FS_DEVICE_INFORMATION))
1764 io->u.Status = STATUS_BUFFER_TOO_SMALL;
1765 else
1767 FILE_FS_DEVICE_INFORMATION *info = buffer;
1769 if ((io->u.Status = FILE_GetDeviceInfo( fd, info )) == STATUS_SUCCESS)
1770 io->Information = sizeof(*info);
1772 break;
1773 case FileFsAttributeInformation:
1774 FIXME( "%p: attribute info not supported\n", handle );
1775 break;
1776 case FileFsControlInformation:
1777 FIXME( "%p: control info not supported\n", handle );
1778 break;
1779 case FileFsFullSizeInformation:
1780 FIXME( "%p: full size info not supported\n", handle );
1781 break;
1782 case FileFsObjectIdInformation:
1783 FIXME( "%p: object id info not supported\n", handle );
1784 break;
1785 case FileFsMaximumInformation:
1786 FIXME( "%p: maximum info not supported\n", handle );
1787 break;
1788 default:
1789 io->u.Status = STATUS_INVALID_PARAMETER;
1790 break;
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.
1802 * PARAMS
1803 * FileHandle [I] Handle returned from ZwOpenFile() or ZwCreateFile()
1804 * IoStatusBlock [O] Receives information about the operation on return
1806 * RETURNS
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 )
1812 NTSTATUS ret;
1813 HANDLE hEvent = NULL;
1815 SERVER_START_REQ( flush_file )
1817 req->handle = hFile;
1818 ret = wine_server_call( req );
1819 hEvent = reply->event;
1821 SERVER_END_REQ;
1822 if (!ret && hEvent)
1824 ret = NtWaitForSingleObject( hEvent, FALSE, NULL );
1825 NtClose( hEvent );
1827 return ret;
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,
1839 BOOLEAN exclusive )
1841 NTSTATUS ret;
1842 HANDLE handle;
1843 BOOLEAN async;
1845 if (apc || io_status || key)
1847 FIXME("Unimplemented yet parameter\n");
1848 return STATUS_NOT_IMPLEMENTED;
1851 for (;;)
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;
1866 SERVER_END_REQ;
1867 if (ret != STATUS_PENDING)
1869 if (!ret && lock_granted_event) NtSetEvent(lock_granted_event, NULL);
1870 return ret;
1873 if (async)
1875 FIXME( "Async I/O lock wait not implemented, might deadlock\n" );
1876 if (handle) NtClose( handle );
1877 return STATUS_PENDING;
1879 if (handle)
1881 NtWaitForSingleObject( handle, FALSE, NULL );
1882 NtClose( handle );
1884 else
1886 LARGE_INTEGER time;
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,
1904 PULONG key )
1906 NTSTATUS status;
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 );
1926 SERVER_END_REQ;
1927 return status;
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)
1943 NTSTATUS status;
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;
1965 req->flags =
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;
1978 SERVER_END_REQ;
1979 return status;
1982 /******************************************************************
1983 * NtDeleteFile (NTDLL.@)
1987 NTSTATUS WINAPI NtDeleteFile( POBJECT_ATTRIBUTES ObjectAttributes )
1989 NTSTATUS status;
1990 HANDLE hFile;
1991 IO_STATUS_BLOCK io;
1993 TRACE("%p\n", ObjectAttributes);
1994 status = NtCreateFile( &hFile, GENERIC_READ | GENERIC_WRITE, ObjectAttributes,
1995 &io, NULL, 0,
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);
1999 return status;
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 );
2018 SERVER_END_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.@]
2032 * PARAMS
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
2037 * CreateOptions [I]
2038 * MailslotQuota [I]
2039 * MaxMessageSize [I]
2040 * TimeOut [I]
2042 * RETURNS
2043 * An NT status code
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','\\'};
2052 NTSTATUS ret;
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;
2078 SERVER_END_REQ;
2080 return ret;