2 * Copyright 1999, 2000 Juergen Schmied
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 #include "wine/port.h"
30 #ifdef HAVE_SYS_ERRNO_H
31 #include <sys/errno.h>
33 #ifdef HAVE_LINUX_MAJOR_H
34 # include <linux/major.h>
36 #ifdef HAVE_SYS_STATVFS_H
37 # include <sys/statvfs.h>
39 #ifdef HAVE_SYS_PARAM_H
40 # include <sys/param.h>
42 #ifdef HAVE_SYS_TIME_H
43 # include <sys/time.h>
48 #ifdef STATFS_DEFINED_BY_SYS_VFS
51 # ifdef STATFS_DEFINED_BY_SYS_MOUNT
52 # include <sys/mount.h>
54 # ifdef STATFS_DEFINED_BY_SYS_STATFS
55 # include <sys/statfs.h>
60 #ifdef HAVE_IOKIT_IOKITLIB_H
61 # include <IOKit/IOKitLib.h>
62 # include <CoreFoundation/CFNumber.h> /* for kCFBooleanTrue, kCFBooleanFalse */
66 #define NONAMELESSUNION
67 #define NONAMELESSSTRUCT
69 #define WIN32_NO_STATUS
70 #include "wine/unicode.h"
71 #include "wine/debug.h"
73 #include "wine/server.h"
74 #include "ntdll_misc.h"
79 WINE_DEFAULT_DEBUG_CHANNEL(ntdll);
81 mode_t FILE_umask = 0;
83 #define SECSPERDAY 86400
84 #define SECS_1601_TO_1970 ((369 * 365 + 89) * (ULONGLONG)SECSPERDAY)
86 /**************************************************************************
87 * NtOpenFile [NTDLL.@]
88 * ZwOpenFile [NTDLL.@]
93 * handle [O] Variable that receives the file handle on return
94 * access [I] Access desired by the caller to the file
95 * attr [I] Structure describing the file to be opened
96 * io [O] Receives details about the result of the operation
97 * sharing [I] Type of shared access the caller requires
98 * options [I] Options for the file open
101 * Success: 0. FileHandle and IoStatusBlock are updated.
102 * Failure: An NTSTATUS error code describing the error.
104 NTSTATUS WINAPI NtOpenFile( PHANDLE handle, ACCESS_MASK access,
105 POBJECT_ATTRIBUTES attr, PIO_STATUS_BLOCK io,
106 ULONG sharing, ULONG options )
108 return NtCreateFile( handle, access, attr, io, NULL, 0,
109 sharing, FILE_OPEN, options, NULL, 0 );
112 /**************************************************************************
113 * NtCreateFile [NTDLL.@]
114 * ZwCreateFile [NTDLL.@]
116 * Either create a new file or directory, or open an existing file, device,
117 * directory or volume.
120 * handle [O] Points to a variable which receives the file handle on return
121 * access [I] Desired access to the file
122 * attr [I] Structure describing the file
123 * io [O] Receives information about the operation on return
124 * alloc_size [I] Initial size of the file in bytes
125 * attributes [I] Attributes to create the file with
126 * sharing [I] Type of shared access the caller would like to the file
127 * disposition [I] Specifies what to do, depending on whether the file already exists
128 * options [I] Options for creating a new file
129 * ea_buffer [I] Pointer to an extended attributes buffer
130 * ea_length [I] Length of ea_buffer
133 * Success: 0. handle and io are updated.
134 * Failure: An NTSTATUS error code describing the error.
136 NTSTATUS WINAPI NtCreateFile( PHANDLE handle, ACCESS_MASK access, POBJECT_ATTRIBUTES attr,
137 PIO_STATUS_BLOCK io, PLARGE_INTEGER alloc_size,
138 ULONG attributes, ULONG sharing, ULONG disposition,
139 ULONG options, PVOID ea_buffer, ULONG ea_length )
141 static const WCHAR pipeW[] = {'\\','?','?','\\','p','i','p','e','\\'};
142 static const WCHAR mailslotW[] = {'\\','?','?','\\','M','A','I','L','S','L','O','T','\\'};
143 ANSI_STRING unix_name;
146 TRACE("handle=%p access=%08lx name=%s objattr=%08lx root=%p sec=%p io=%p alloc_size=%p\n"
147 "attr=%08lx sharing=%08lx disp=%ld options=%08lx ea=%p.0x%08lx\n",
148 handle, access, debugstr_us(attr->ObjectName), attr->Attributes,
149 attr->RootDirectory, attr->SecurityDescriptor, io, alloc_size,
150 attributes, sharing, disposition, options, ea_buffer, ea_length );
152 if (!attr || !attr->ObjectName) return STATUS_INVALID_PARAMETER;
154 if (alloc_size) FIXME( "alloc_size not supported\n" );
156 /* check for named pipe */
158 if (attr->ObjectName->Length > sizeof(pipeW) &&
159 !memicmpW( attr->ObjectName->Buffer, pipeW, sizeof(pipeW)/sizeof(WCHAR) ))
161 SERVER_START_REQ( open_named_pipe )
163 req->access = access;
164 req->attributes = (attr) ? attr->Attributes : 0;
165 req->rootdir = attr ? attr->RootDirectory : 0;
166 req->flags = options;
167 wine_server_add_data( req, attr->ObjectName->Buffer,
168 attr->ObjectName->Length );
169 io->u.Status = wine_server_call( req );
170 *handle = reply->handle;
176 /* check for mailslot */
178 if (attr->ObjectName->Length > sizeof(mailslotW) &&
179 !memicmpW( attr->ObjectName->Buffer, mailslotW, sizeof(mailslotW)/sizeof(WCHAR) ))
181 SERVER_START_REQ( open_mailslot )
183 req->access = access & GENERIC_WRITE;
184 req->attributes = (attr) ? attr->Attributes : 0;
185 req->rootdir = attr ? attr->RootDirectory : 0;
186 req->sharing = sharing;
187 wine_server_add_data( req, attr->ObjectName->Buffer,
188 attr->ObjectName->Length );
189 io->u.Status = wine_server_call( req );
190 *handle = reply->handle;
196 if (attr->RootDirectory)
198 FIXME( "RootDirectory %p not supported\n", attr->RootDirectory );
199 return STATUS_OBJECT_NAME_NOT_FOUND;
202 io->u.Status = wine_nt_to_unix_file_name( attr->ObjectName, &unix_name, disposition,
203 !(attr->Attributes & OBJ_CASE_INSENSITIVE) );
205 if (io->u.Status == STATUS_BAD_DEVICE_TYPE)
207 SERVER_START_REQ( open_file_object )
209 req->access = access;
210 req->attributes = attr->Attributes;
211 req->rootdir = attr->RootDirectory;
212 req->sharing = sharing;
213 wine_server_add_data( req, attr->ObjectName->Buffer, attr->ObjectName->Length );
214 io->u.Status = wine_server_call( req );
215 *handle = reply->handle;
221 if (io->u.Status == STATUS_NO_SUCH_FILE &&
222 disposition != FILE_OPEN && disposition != FILE_OVERWRITE)
225 io->u.Status = STATUS_SUCCESS;
228 if (io->u.Status == STATUS_SUCCESS)
230 SERVER_START_REQ( create_file )
232 req->access = access;
233 req->attributes = attr->Attributes;
234 req->sharing = sharing;
235 req->create = disposition;
236 req->options = options;
237 req->attrs = attributes;
238 wine_server_add_data( req, unix_name.Buffer, unix_name.Length );
239 io->u.Status = wine_server_call( req );
240 *handle = reply->handle;
243 RtlFreeAnsiString( &unix_name );
245 else WARN("%s not found (%lx)\n", debugstr_us(attr->ObjectName), io->u.Status );
247 if (io->u.Status == STATUS_SUCCESS)
249 if (created) io->Information = FILE_CREATED;
250 else switch(disposition)
253 io->Information = FILE_SUPERSEDED;
256 io->Information = FILE_CREATED;
260 io->Information = FILE_OPENED;
263 case FILE_OVERWRITE_IF:
264 io->Information = FILE_OVERWRITTEN;
272 /***********************************************************************
273 * Asynchronous file I/O *
275 static void WINAPI FILE_AsyncReadService(void*, PIO_STATUS_BLOCK, ULONG);
276 static void WINAPI FILE_AsyncWriteService(void*, PIO_STATUS_BLOCK, ULONG);
278 typedef struct async_fileio
286 int queue_apc_on_error;
292 static void fileio_terminate(async_fileio *fileio, IO_STATUS_BLOCK* iosb)
294 TRACE("data: %p\n", fileio);
296 wine_server_release_fd( fileio->handle, fileio->fd );
297 if ( fileio->event != INVALID_HANDLE_VALUE )
298 NtSetEvent( fileio->event, NULL );
301 (iosb->u.Status == STATUS_SUCCESS || fileio->queue_apc_on_error))
302 fileio->apc( fileio->apc_user, iosb, iosb->Information );
304 RtlFreeHeap( GetProcessHeap(), 0, fileio );
308 static ULONG fileio_queue_async(async_fileio* fileio, IO_STATUS_BLOCK* iosb,
311 PIO_APC_ROUTINE apc = do_read ? FILE_AsyncReadService : FILE_AsyncWriteService;
314 SERVER_START_REQ( register_async )
316 req->handle = fileio->handle;
319 req->io_user = fileio;
320 req->type = do_read ? ASYNC_TYPE_READ : ASYNC_TYPE_WRITE;
321 req->count = (fileio->count < iosb->Information) ?
322 0 : fileio->count - iosb->Information;
323 status = wine_server_call( req );
327 if ( status ) iosb->u.Status = status;
328 if ( iosb->u.Status != STATUS_PENDING )
330 (apc)( fileio, iosb, iosb->u.Status );
331 return iosb->u.Status;
333 NtCurrentTeb()->num_async_io++;
334 return STATUS_SUCCESS;
337 /***********************************************************************
338 * FILE_GetNtStatus(void)
340 * Retrieve the Nt Status code from errno.
341 * Try to be consistent with FILE_SetDosError().
343 NTSTATUS FILE_GetNtStatus(void)
347 TRACE( "errno = %d\n", errno );
350 case EAGAIN: return STATUS_SHARING_VIOLATION;
351 case EBADF: return STATUS_INVALID_HANDLE;
352 case EBUSY: return STATUS_DEVICE_BUSY;
353 case ENOSPC: return STATUS_DISK_FULL;
356 case EACCES: return STATUS_ACCESS_DENIED;
357 case ENOTDIR: return STATUS_OBJECT_PATH_NOT_FOUND;
358 case ENOENT: return STATUS_OBJECT_NAME_NOT_FOUND;
359 case EISDIR: return STATUS_FILE_IS_A_DIRECTORY;
361 case ENFILE: return STATUS_TOO_MANY_OPENED_FILES;
362 case EINVAL: return STATUS_INVALID_PARAMETER;
363 case ENOTEMPTY: return STATUS_DIRECTORY_NOT_EMPTY;
364 case EPIPE: return STATUS_PIPE_BROKEN;
365 case EIO: return STATUS_DEVICE_NOT_READY;
367 case ENOMEDIUM: return STATUS_NO_MEDIA_IN_DEVICE;
370 case EOPNOTSUPP:return STATUS_NOT_SUPPORTED;
371 case ECONNRESET:return STATUS_PIPE_DISCONNECTED;
372 case ENOEXEC: /* ?? */
373 case ESPIPE: /* ?? */
374 case EEXIST: /* ?? */
376 FIXME( "Converting errno %d to STATUS_UNSUCCESSFUL\n", err );
377 return STATUS_UNSUCCESSFUL;
381 /***********************************************************************
382 * FILE_AsyncReadService (INTERNAL)
384 * This function is called while the client is waiting on the
385 * server, so we can't make any server calls here.
387 static void WINAPI FILE_AsyncReadService(void *user, PIO_STATUS_BLOCK iosb, ULONG status)
389 async_fileio *fileio = (async_fileio*)user;
391 int already = iosb->Information;
393 TRACE("%p %p 0x%lx\n", iosb, fileio->buffer, status);
397 case STATUS_ALERTED: /* got some new data */
398 if (iosb->u.Status != STATUS_PENDING) FIXME("unexpected status %08lx\n", iosb->u.Status);
399 /* check to see if the data is ready (non-blocking) */
400 if ( fileio->avail_mode )
401 result = read(fileio->fd, &fileio->buffer[already],
402 fileio->count - already);
405 result = pread(fileio->fd, &fileio->buffer[already],
406 fileio->count - already,
407 fileio->offset + already);
408 if ((result < 0) && (errno == ESPIPE))
409 result = read(fileio->fd, &fileio->buffer[already],
410 fileio->count - already);
415 if (errno == EAGAIN || errno == EINTR)
417 TRACE("Deferred read %d\n", errno);
418 iosb->u.Status = STATUS_PENDING;
420 else /* check to see if the transfer is complete */
421 iosb->u.Status = FILE_GetNtStatus();
423 else if (result == 0)
425 iosb->u.Status = iosb->Information ? STATUS_SUCCESS : STATUS_END_OF_FILE;
429 iosb->Information += result;
430 if (iosb->Information >= fileio->count || fileio->avail_mode)
431 iosb->u.Status = STATUS_SUCCESS;
434 /* if we only have to read the available data, and none is available,
435 * simply cancel the request. If data was available, it has been read
436 * while in by previous call (NtDelayExecution)
438 iosb->u.Status = (fileio->avail_mode) ? STATUS_SUCCESS : STATUS_PENDING;
441 TRACE("read %d more bytes %ld/%d so far (%s)\n",
442 result, iosb->Information, fileio->count,
443 (iosb->u.Status == STATUS_SUCCESS) ? "success" : "pending");
445 /* queue another async operation ? */
446 if (iosb->u.Status == STATUS_PENDING)
447 fileio_queue_async(fileio, iosb, TRUE);
449 fileio_terminate(fileio, iosb);
452 iosb->u.Status = status;
453 fileio_terminate(fileio, iosb);
459 /******************************************************************************
460 * NtReadFile [NTDLL.@]
461 * ZwReadFile [NTDLL.@]
463 * Read from an open file handle.
466 * FileHandle [I] Handle returned from ZwOpenFile() or ZwCreateFile()
467 * Event [I] Event to signal upon completion (or NULL)
468 * ApcRoutine [I] Callback to call upon completion (or NULL)
469 * ApcContext [I] Context for ApcRoutine (or NULL)
470 * IoStatusBlock [O] Receives information about the operation on return
471 * Buffer [O] Destination for the data read
472 * Length [I] Size of Buffer
473 * ByteOffset [O] Destination for the new file pointer position (or NULL)
474 * Key [O] Function unknown (may be NULL)
477 * Success: 0. IoStatusBlock is updated, and the Information member contains
478 * The number of bytes read.
479 * Failure: An NTSTATUS error code describing the error.
481 NTSTATUS WINAPI NtReadFile(HANDLE hFile, HANDLE hEvent,
482 PIO_APC_ROUTINE apc, void* apc_user,
483 PIO_STATUS_BLOCK io_status, void* buffer, ULONG length,
484 PLARGE_INTEGER offset, PULONG key)
486 int unix_handle, flags;
488 TRACE("(%p,%p,%p,%p,%p,%p,0x%08lx,%p,%p),partial stub!\n",
489 hFile,hEvent,apc,apc_user,io_status,buffer,length,offset,key);
491 if (!io_status) return STATUS_ACCESS_VIOLATION;
493 io_status->Information = 0;
494 io_status->u.Status = wine_server_handle_to_fd( hFile, FILE_READ_DATA, &unix_handle, &flags );
495 if (io_status->u.Status) return io_status->u.Status;
497 if (flags & FD_FLAG_RECV_SHUTDOWN)
499 wine_server_release_fd( hFile, unix_handle );
500 return STATUS_PIPE_DISCONNECTED;
503 if (flags & FD_FLAG_TIMEOUT)
507 /* this shouldn't happen, but check it */
508 FIXME("NIY-hEvent\n");
509 wine_server_release_fd( hFile, unix_handle );
510 return STATUS_NOT_IMPLEMENTED;
512 io_status->u.Status = NtCreateEvent(&hEvent, EVENT_ALL_ACCESS, NULL, 0, 0);
513 if (io_status->u.Status)
515 wine_server_release_fd( hFile, unix_handle );
516 return io_status->u.Status;
520 if (flags & (FD_FLAG_OVERLAPPED|FD_FLAG_TIMEOUT))
522 async_fileio* fileio;
525 if (!(fileio = RtlAllocateHeap(GetProcessHeap(), 0, sizeof(async_fileio))))
527 wine_server_release_fd( hFile, unix_handle );
528 if (flags & FD_FLAG_TIMEOUT) NtClose(hEvent);
529 return STATUS_NO_MEMORY;
531 fileio->handle = hFile;
532 fileio->count = length;
533 if ( offset == NULL )
537 fileio->offset = offset->QuadPart;
538 if (offset->u.HighPart && fileio->offset == offset->u.LowPart)
539 FIXME("High part of offset is lost\n");
542 fileio->apc_user = apc_user;
543 fileio->buffer = buffer;
544 fileio->queue_apc_on_error = 0;
545 fileio->avail_mode = (flags & FD_FLAG_AVAILABLE);
546 fileio->fd = unix_handle; /* FIXME */
547 fileio->event = hEvent;
548 NtResetEvent(hEvent, NULL);
550 io_status->u.Status = STATUS_PENDING;
551 ret = fileio_queue_async(fileio, io_status, TRUE);
552 if (ret != STATUS_SUCCESS)
554 wine_server_release_fd( hFile, unix_handle );
555 if (flags & FD_FLAG_TIMEOUT) NtClose(hEvent);
558 if (flags & FD_FLAG_TIMEOUT)
562 ret = NtWaitForSingleObject(hEvent, TRUE, NULL);
564 while (ret == STATUS_USER_APC && io_status->u.Status == STATUS_PENDING);
566 if (ret != STATUS_USER_APC)
567 fileio->queue_apc_on_error = 1;
571 LARGE_INTEGER timeout;
573 /* let some APC be run, this will read some already pending data */
574 timeout.u.LowPart = timeout.u.HighPart = 0;
575 ret = NtDelayExecution( TRUE, &timeout );
576 /* the apc didn't run and therefore the completion routine now
577 * needs to be sent errors.
578 * Note that there is no race between setting this flag and
579 * returning errors because apc's are run only during alertable
581 if (ret != STATUS_USER_APC)
582 fileio->queue_apc_on_error = 1;
584 TRACE("= 0x%08lx\n", io_status->u.Status);
585 return io_status->u.Status;
590 FILE_POSITION_INFORMATION fpi;
592 fpi.CurrentByteOffset = *offset;
593 io_status->u.Status = NtSetInformationFile(hFile, io_status, &fpi, sizeof(fpi),
594 FilePositionInformation);
595 if (io_status->u.Status)
597 wine_server_release_fd( hFile, unix_handle );
598 return io_status->u.Status;
601 /* code for synchronous reads */
602 while ((io_status->Information = read( unix_handle, buffer, length )) == -1)
604 if ((errno == EAGAIN) || (errno == EINTR)) continue;
607 io_status->Information = 0;
608 io_status->u.Status = STATUS_ACCESS_VIOLATION;
610 else io_status->u.Status = FILE_GetNtStatus();
613 if (io_status->u.Status == STATUS_SUCCESS && io_status->Information == 0)
616 if (fstat( unix_handle, &st ) != -1 && S_ISSOCK( st.st_mode ))
617 io_status->u.Status = STATUS_PIPE_BROKEN;
619 io_status->u.Status = STATUS_END_OF_FILE;
621 wine_server_release_fd( hFile, unix_handle );
622 TRACE("= 0x%08lx (%lu)\n", io_status->u.Status, io_status->Information);
623 return io_status->u.Status;
626 /***********************************************************************
627 * FILE_AsyncWriteService (INTERNAL)
629 * This function is called while the client is waiting on the
630 * server, so we can't make any server calls here.
632 static void WINAPI FILE_AsyncWriteService(void *ovp, IO_STATUS_BLOCK *iosb, ULONG status)
634 async_fileio *fileio = (async_fileio *) ovp;
636 int already = iosb->Information;
638 TRACE("(%p %p 0x%lx)\n",iosb, fileio->buffer, status);
643 /* write some data (non-blocking) */
644 if ( fileio->avail_mode )
645 result = write(fileio->fd, &fileio->buffer[already],
646 fileio->count - already);
649 result = pwrite(fileio->fd, &fileio->buffer[already],
650 fileio->count - already, fileio->offset + already);
651 if ((result < 0) && (errno == ESPIPE))
652 result = write(fileio->fd, &fileio->buffer[already],
653 fileio->count - already);
658 if (errno == EAGAIN || errno == EINTR) iosb->u.Status = STATUS_PENDING;
659 else iosb->u.Status = FILE_GetNtStatus();
663 iosb->Information += result;
664 iosb->u.Status = (iosb->Information < fileio->count) ? STATUS_PENDING : STATUS_SUCCESS;
665 TRACE("wrote %d more bytes %ld/%d so far\n",
666 result, iosb->Information, fileio->count);
668 if (iosb->u.Status == STATUS_PENDING)
669 fileio_queue_async(fileio, iosb, FALSE);
671 fileio_terminate(fileio, iosb);
674 iosb->u.Status = status;
675 fileio_terminate(fileio, iosb);
680 /******************************************************************************
681 * NtWriteFile [NTDLL.@]
682 * ZwWriteFile [NTDLL.@]
684 * Write to an open file handle.
687 * FileHandle [I] Handle returned from ZwOpenFile() or ZwCreateFile()
688 * Event [I] Event to signal upon completion (or NULL)
689 * ApcRoutine [I] Callback to call upon completion (or NULL)
690 * ApcContext [I] Context for ApcRoutine (or NULL)
691 * IoStatusBlock [O] Receives information about the operation on return
692 * Buffer [I] Source for the data to write
693 * Length [I] Size of Buffer
694 * ByteOffset [O] Destination for the new file pointer position (or NULL)
695 * Key [O] Function unknown (may be NULL)
698 * Success: 0. IoStatusBlock is updated, and the Information member contains
699 * The number of bytes written.
700 * Failure: An NTSTATUS error code describing the error.
702 NTSTATUS WINAPI NtWriteFile(HANDLE hFile, HANDLE hEvent,
703 PIO_APC_ROUTINE apc, void* apc_user,
704 PIO_STATUS_BLOCK io_status,
705 const void* buffer, ULONG length,
706 PLARGE_INTEGER offset, PULONG key)
708 int unix_handle, flags;
710 TRACE("(%p,%p,%p,%p,%p,%p,0x%08lx,%p,%p)!\n",
711 hFile,hEvent,apc,apc_user,io_status,buffer,length,offset,key);
713 if (!io_status) return STATUS_ACCESS_VIOLATION;
715 io_status->Information = 0;
716 io_status->u.Status = wine_server_handle_to_fd( hFile, FILE_WRITE_DATA, &unix_handle, &flags );
717 if (io_status->u.Status) return io_status->u.Status;
719 if (flags & FD_FLAG_SEND_SHUTDOWN)
721 wine_server_release_fd( hFile, unix_handle );
722 return STATUS_PIPE_DISCONNECTED;
725 if (flags & FD_FLAG_TIMEOUT)
729 /* this shouldn't happen, but check it */
730 FIXME("NIY-hEvent\n");
731 wine_server_release_fd( hFile, unix_handle );
732 return STATUS_NOT_IMPLEMENTED;
734 io_status->u.Status = NtCreateEvent(&hEvent, EVENT_ALL_ACCESS, NULL, 0, 0);
735 if (io_status->u.Status)
737 wine_server_release_fd( hFile, unix_handle );
738 return io_status->u.Status;
742 if (flags & (FD_FLAG_OVERLAPPED|FD_FLAG_TIMEOUT))
744 async_fileio* fileio;
747 if (!(fileio = RtlAllocateHeap(GetProcessHeap(), 0, sizeof(async_fileio))))
749 wine_server_release_fd( hFile, unix_handle );
750 if (flags & FD_FLAG_TIMEOUT) NtClose(hEvent);
751 return STATUS_NO_MEMORY;
753 fileio->handle = hFile;
754 fileio->count = length;
757 fileio->offset = offset->QuadPart;
758 if (offset->u.HighPart && fileio->offset == offset->u.LowPart)
759 FIXME("High part of offset is lost\n");
766 fileio->apc_user = apc_user;
767 fileio->buffer = (void*)buffer;
768 fileio->queue_apc_on_error = 0;
769 fileio->avail_mode = (flags & FD_FLAG_AVAILABLE);
770 fileio->fd = unix_handle; /* FIXME */
771 fileio->event = hEvent;
772 NtResetEvent(hEvent, NULL);
774 io_status->Information = 0;
775 io_status->u.Status = STATUS_PENDING;
776 ret = fileio_queue_async(fileio, io_status, FALSE);
777 if (ret != STATUS_SUCCESS)
779 wine_server_release_fd( hFile, unix_handle );
780 if (flags & FD_FLAG_TIMEOUT) NtClose(hEvent);
783 if (flags & FD_FLAG_TIMEOUT)
787 ret = NtWaitForSingleObject(hEvent, TRUE, NULL);
789 while (ret == STATUS_USER_APC && io_status->u.Status == STATUS_PENDING);
791 if (ret != STATUS_USER_APC)
792 fileio->queue_apc_on_error = 1;
796 LARGE_INTEGER timeout;
798 /* let some APC be run, this will write as much data as possible */
799 timeout.u.LowPart = timeout.u.HighPart = 0;
800 ret = NtDelayExecution( TRUE, &timeout );
801 /* the apc didn't run and therefore the completion routine now
802 * needs to be sent errors.
803 * Note that there is no race between setting this flag and
804 * returning errors because apc's are run only during alertable
806 if (ret != STATUS_USER_APC)
807 fileio->queue_apc_on_error = 1;
809 return io_status->u.Status;
814 FILE_POSITION_INFORMATION fpi;
816 fpi.CurrentByteOffset = *offset;
817 io_status->u.Status = NtSetInformationFile(hFile, io_status, &fpi, sizeof(fpi),
818 FilePositionInformation);
819 if (io_status->u.Status)
821 wine_server_release_fd( hFile, unix_handle );
822 return io_status->u.Status;
826 /* synchronous file write */
827 while ((io_status->Information = write( unix_handle, buffer, length )) == -1)
829 if ((errno == EAGAIN) || (errno == EINTR)) continue;
832 io_status->Information = 0;
833 io_status->u.Status = STATUS_INVALID_USER_BUFFER;
835 else if (errno == ENOSPC) io_status->u.Status = STATUS_DISK_FULL;
836 else io_status->u.Status = FILE_GetNtStatus();
839 wine_server_release_fd( hFile, unix_handle );
840 return io_status->u.Status;
843 /**************************************************************************
844 * NtDeviceIoControlFile [NTDLL.@]
845 * ZwDeviceIoControlFile [NTDLL.@]
847 * Perform an I/O control operation on an open file handle.
850 * DeviceHandle [I] Handle returned from ZwOpenFile() or ZwCreateFile()
851 * Event [I] Event to signal upon completion (or NULL)
852 * ApcRoutine [I] Callback to call upon completion (or NULL)
853 * ApcContext [I] Context for ApcRoutine (or NULL)
854 * IoStatusBlock [O] Receives information about the operation on return
855 * IoControlCode [I] Control code for the operation to perform
856 * InputBuffer [I] Source for any input data required (or NULL)
857 * InputBufferSize [I] Size of InputBuffer
858 * OutputBuffer [O] Source for any output data returned (or NULL)
859 * OutputBufferSize [I] Size of OutputBuffer
862 * Success: 0. IoStatusBlock is updated.
863 * Failure: An NTSTATUS error code describing the error.
865 NTSTATUS WINAPI NtDeviceIoControlFile(HANDLE DeviceHandle, HANDLE hEvent,
866 PIO_APC_ROUTINE UserApcRoutine,
867 PVOID UserApcContext,
868 PIO_STATUS_BLOCK IoStatusBlock,
871 ULONG InputBufferSize,
873 ULONG OutputBufferSize)
877 TRACE("(%p,%p,%p,%p,%p,0x%08lx,%p,0x%08lx,%p,0x%08lx)\n",
878 DeviceHandle, hEvent, UserApcRoutine, UserApcContext,
879 IoStatusBlock, IoControlCode,
880 InputBuffer, InputBufferSize, OutputBuffer, OutputBufferSize);
882 if ((IoControlCode >> 16) == FILE_DEVICE_SERIAL_PORT)
883 ret = COMM_DeviceIoControl(DeviceHandle, hEvent,
884 UserApcRoutine, UserApcContext,
885 IoStatusBlock, IoControlCode,
886 InputBuffer, InputBufferSize,
887 OutputBuffer, OutputBufferSize);
888 else ret = CDROM_DeviceIoControl(DeviceHandle, hEvent,
889 UserApcRoutine, UserApcContext,
890 IoStatusBlock, IoControlCode,
891 InputBuffer, InputBufferSize,
892 OutputBuffer, OutputBufferSize);
893 if (ret == STATUS_NO_SUCH_DEVICE)
895 /* it wasn't a supported device (CDROM, COMM) */
896 FIXME("Unimplemented dwIoControlCode=%08lx\n", IoControlCode);
897 IoStatusBlock->u.Status = STATUS_NOT_IMPLEMENTED;
898 IoStatusBlock->Information = 0;
899 if (hEvent) NtSetEvent(hEvent, NULL);
901 return IoStatusBlock->u.Status;
904 /***********************************************************************
905 * pipe_completion_wait (Internal)
907 static void CALLBACK pipe_completion_wait(HANDLE event, PIO_STATUS_BLOCK iosb, ULONG status)
909 TRACE("for %p/%p, status=%08lx\n", event, iosb, status);
912 iosb->u.Status = status;
913 NtSetEvent(event, NULL);
917 /**************************************************************************
918 * NtFsControlFile [NTDLL.@]
919 * ZwFsControlFile [NTDLL.@]
921 * Perform a file system control operation on an open file handle.
924 * DeviceHandle [I] Handle returned from ZwOpenFile() or ZwCreateFile()
925 * Event [I] Event to signal upon completion (or NULL)
926 * ApcRoutine [I] Callback to call upon completion (or NULL)
927 * ApcContext [I] Context for ApcRoutine (or NULL)
928 * IoStatusBlock [O] Receives information about the operation on return
929 * FsControlCode [I] Control code for the operation to perform
930 * InputBuffer [I] Source for any input data required (or NULL)
931 * InputBufferSize [I] Size of InputBuffer
932 * OutputBuffer [O] Source for any output data returned (or NULL)
933 * OutputBufferSize [I] Size of OutputBuffer
936 * Success: 0. IoStatusBlock is updated.
937 * Failure: An NTSTATUS error code describing the error.
939 NTSTATUS WINAPI NtFsControlFile(HANDLE DeviceHandle, HANDLE Event OPTIONAL, PIO_APC_ROUTINE ApcRoutine,
940 PVOID ApcContext, PIO_STATUS_BLOCK IoStatusBlock, ULONG FsControlCode,
941 PVOID InputBuffer, ULONG InputBufferSize, PVOID OutputBuffer, ULONG OutputBufferSize)
943 NTSTATUS ret = STATUS_NOT_SUPPORTED;
944 HANDLE internal_event;
946 TRACE("(%p,%p,%p,%p,%p,0x%08lx,%p,0x%08lx,%p,0x%08lx)\n",
947 DeviceHandle,Event,ApcRoutine,ApcContext,IoStatusBlock,FsControlCode,
948 InputBuffer,InputBufferSize,OutputBuffer,OutputBufferSize);
950 if(!IoStatusBlock) return STATUS_INVALID_PARAMETER;
952 switch(FsControlCode)
954 case FSCTL_DISMOUNT_VOLUME:
955 ret = DIR_unmount_device( DeviceHandle );
958 case FSCTL_PIPE_LISTEN :
959 case FSCTL_PIPE_WAIT :
961 OBJECT_ATTRIBUTES obj;
965 InitializeObjectAttributes(&obj, NULL, 0, 0, NULL);
966 ret = NtCreateEvent(&internal_event, EVENT_ALL_ACCESS, &obj, FALSE, FALSE);
967 if(ret != STATUS_SUCCESS) return ret;
969 switch(FsControlCode)
971 case FSCTL_PIPE_LISTEN :
972 SERVER_START_REQ(connect_named_pipe)
974 req->handle = DeviceHandle;
975 req->event = Event ? Event : internal_event;
976 req->func = pipe_completion_wait;
977 ret = wine_server_call(req);
981 case FSCTL_PIPE_WAIT :
983 FILE_PIPE_WAIT_FOR_BUFFER *buff = InputBuffer;
985 SERVER_START_REQ(wait_named_pipe)
987 req->handle = DeviceHandle;
988 req->timeout = buff->TimeoutSpecified ? buff->Timeout.QuadPart / -10000L
989 : NMPWAIT_USE_DEFAULT_WAIT;
990 req->event = Event ? Event : internal_event;
991 req->func = pipe_completion_wait;
992 wine_server_add_data( req, buff->Name, buff->NameLength );
993 ret = wine_server_call( req );
999 if(ret == STATUS_SUCCESS)
1002 ret = STATUS_PENDING;
1006 ret = NtWaitForSingleObject(internal_event, TRUE, NULL);
1007 while(ret == STATUS_USER_APC);
1008 NtClose(internal_event);
1013 case FSCTL_PIPE_DISCONNECT :
1014 SERVER_START_REQ(disconnect_named_pipe)
1016 req->handle = DeviceHandle;
1017 ret = wine_server_call(req);
1018 if (!ret && reply->fd != -1) close(reply->fd);
1023 FIXME("Unsupported FsControlCode %lx\n", FsControlCode);
1026 IoStatusBlock->u.Status = ret;
1030 /******************************************************************************
1031 * NtSetVolumeInformationFile [NTDLL.@]
1032 * ZwSetVolumeInformationFile [NTDLL.@]
1034 * Set volume information for an open file handle.
1037 * FileHandle [I] Handle returned from ZwOpenFile() or ZwCreateFile()
1038 * IoStatusBlock [O] Receives information about the operation on return
1039 * FsInformation [I] Source for volume information
1040 * Length [I] Size of FsInformation
1041 * FsInformationClass [I] Type of volume information to set
1044 * Success: 0. IoStatusBlock is updated.
1045 * Failure: An NTSTATUS error code describing the error.
1047 NTSTATUS WINAPI NtSetVolumeInformationFile(
1048 IN HANDLE FileHandle,
1049 PIO_STATUS_BLOCK IoStatusBlock,
1050 PVOID FsInformation,
1052 FS_INFORMATION_CLASS FsInformationClass)
1054 FIXME("(%p,%p,%p,0x%08lx,0x%08x) stub\n",
1055 FileHandle,IoStatusBlock,FsInformation,Length,FsInformationClass);
1059 /******************************************************************************
1060 * NtQueryInformationFile [NTDLL.@]
1061 * ZwQueryInformationFile [NTDLL.@]
1063 * Get information about an open file handle.
1066 * hFile [I] Handle returned from ZwOpenFile() or ZwCreateFile()
1067 * io [O] Receives information about the operation on return
1068 * ptr [O] Destination for file information
1069 * len [I] Size of FileInformation
1070 * class [I] Type of file information to get
1073 * Success: 0. IoStatusBlock and FileInformation are updated.
1074 * Failure: An NTSTATUS error code describing the error.
1076 NTSTATUS WINAPI NtQueryInformationFile( HANDLE hFile, PIO_STATUS_BLOCK io,
1077 PVOID ptr, LONG len, FILE_INFORMATION_CLASS class )
1079 static const size_t info_sizes[] =
1082 sizeof(FILE_DIRECTORY_INFORMATION), /* FileDirectoryInformation */
1083 sizeof(FILE_FULL_DIRECTORY_INFORMATION), /* FileFullDirectoryInformation */
1084 sizeof(FILE_BOTH_DIRECTORY_INFORMATION), /* FileBothDirectoryInformation */
1085 sizeof(FILE_BASIC_INFORMATION), /* FileBasicInformation */
1086 sizeof(FILE_STANDARD_INFORMATION), /* FileStandardInformation */
1087 sizeof(FILE_INTERNAL_INFORMATION), /* FileInternalInformation */
1088 sizeof(FILE_EA_INFORMATION), /* FileEaInformation */
1089 sizeof(FILE_ACCESS_INFORMATION), /* FileAccessInformation */
1090 sizeof(FILE_NAME_INFORMATION)-sizeof(WCHAR), /* FileNameInformation */
1091 sizeof(FILE_RENAME_INFORMATION)-sizeof(WCHAR), /* FileRenameInformation */
1092 0, /* FileLinkInformation */
1093 sizeof(FILE_NAMES_INFORMATION)-sizeof(WCHAR), /* FileNamesInformation */
1094 sizeof(FILE_DISPOSITION_INFORMATION), /* FileDispositionInformation */
1095 sizeof(FILE_POSITION_INFORMATION), /* FilePositionInformation */
1096 sizeof(FILE_FULL_EA_INFORMATION), /* FileFullEaInformation */
1097 sizeof(FILE_MODE_INFORMATION), /* FileModeInformation */
1098 sizeof(FILE_ALIGNMENT_INFORMATION), /* FileAlignmentInformation */
1099 sizeof(FILE_ALL_INFORMATION)-sizeof(WCHAR), /* FileAllInformation */
1100 sizeof(FILE_ALLOCATION_INFORMATION), /* FileAllocationInformation */
1101 sizeof(FILE_END_OF_FILE_INFORMATION), /* FileEndOfFileInformation */
1102 0, /* FileAlternateNameInformation */
1103 sizeof(FILE_STREAM_INFORMATION)-sizeof(WCHAR), /* FileStreamInformation */
1104 0, /* FilePipeInformation */
1105 0, /* FilePipeLocalInformation */
1106 0, /* FilePipeRemoteInformation */
1107 sizeof(FILE_MAILSLOT_QUERY_INFORMATION), /* FileMailslotQueryInformation */
1108 0, /* FileMailslotSetInformation */
1109 0, /* FileCompressionInformation */
1110 0, /* FileObjectIdInformation */
1111 0, /* FileCompletionInformation */
1112 0, /* FileMoveClusterInformation */
1113 0, /* FileQuotaInformation */
1114 0, /* FileReparsePointInformation */
1115 0, /* FileNetworkOpenInformation */
1116 0, /* FileAttributeTagInformation */
1117 0 /* FileTrackingInformation */
1123 TRACE("(%p,%p,%p,0x%08lx,0x%08x)\n", hFile, io, ptr, len, class);
1125 io->Information = 0;
1127 if (class <= 0 || class >= FileMaximumInformation)
1128 return io->u.Status = STATUS_INVALID_INFO_CLASS;
1129 if (!info_sizes[class])
1131 FIXME("Unsupported class (%d)\n", class);
1132 return io->u.Status = STATUS_NOT_IMPLEMENTED;
1134 if (len < info_sizes[class])
1135 return io->u.Status = STATUS_INFO_LENGTH_MISMATCH;
1137 if ((io->u.Status = wine_server_handle_to_fd( hFile, 0, &fd, NULL )))
1138 return io->u.Status;
1142 case FileBasicInformation:
1144 FILE_BASIC_INFORMATION *info = ptr;
1146 if (fstat( fd, &st ) == -1)
1147 io->u.Status = FILE_GetNtStatus();
1148 else if (!S_ISREG(st.st_mode) && !S_ISDIR(st.st_mode))
1149 io->u.Status = STATUS_INVALID_INFO_CLASS;
1152 if (S_ISDIR(st.st_mode)) info->FileAttributes = FILE_ATTRIBUTE_DIRECTORY;
1153 else info->FileAttributes = FILE_ATTRIBUTE_ARCHIVE;
1154 if (!(st.st_mode & (S_IWUSR | S_IWGRP | S_IWOTH)))
1155 info->FileAttributes |= FILE_ATTRIBUTE_READONLY;
1156 RtlSecondsSince1970ToTime( st.st_mtime, &info->CreationTime);
1157 RtlSecondsSince1970ToTime( st.st_mtime, &info->LastWriteTime);
1158 RtlSecondsSince1970ToTime( st.st_ctime, &info->ChangeTime);
1159 RtlSecondsSince1970ToTime( st.st_atime, &info->LastAccessTime);
1163 case FileStandardInformation:
1165 FILE_STANDARD_INFORMATION *info = ptr;
1167 if (fstat( fd, &st ) == -1) io->u.Status = FILE_GetNtStatus();
1170 if ((info->Directory = S_ISDIR(st.st_mode)))
1172 info->AllocationSize.QuadPart = 0;
1173 info->EndOfFile.QuadPart = 0;
1174 info->NumberOfLinks = 1;
1175 info->DeletePending = FALSE;
1179 info->AllocationSize.QuadPart = (ULONGLONG)st.st_blocks * 512;
1180 info->EndOfFile.QuadPart = st.st_size;
1181 info->NumberOfLinks = st.st_nlink;
1182 info->DeletePending = FALSE; /* FIXME */
1187 case FilePositionInformation:
1189 FILE_POSITION_INFORMATION *info = ptr;
1190 off_t res = lseek( fd, 0, SEEK_CUR );
1191 if (res == (off_t)-1) io->u.Status = FILE_GetNtStatus();
1192 else info->CurrentByteOffset.QuadPart = res;
1195 case FileInternalInformation:
1197 FILE_INTERNAL_INFORMATION *info = ptr;
1199 if (fstat( fd, &st ) == -1) io->u.Status = FILE_GetNtStatus();
1200 else info->IndexNumber.QuadPart = st.st_ino;
1203 case FileEaInformation:
1205 FILE_EA_INFORMATION *info = ptr;
1209 case FileEndOfFileInformation:
1211 FILE_END_OF_FILE_INFORMATION *info = ptr;
1213 if (fstat( fd, &st ) == -1) io->u.Status = FILE_GetNtStatus();
1214 else info->EndOfFile.QuadPart = S_ISDIR(st.st_mode) ? 0 : st.st_size;
1217 case FileAllInformation:
1219 FILE_ALL_INFORMATION *info = ptr;
1221 if (fstat( fd, &st ) == -1) io->u.Status = FILE_GetNtStatus();
1222 else if (!S_ISREG(st.st_mode) && !S_ISDIR(st.st_mode))
1223 io->u.Status = STATUS_INVALID_INFO_CLASS;
1226 if ((info->StandardInformation.Directory = S_ISDIR(st.st_mode)))
1228 info->BasicInformation.FileAttributes = FILE_ATTRIBUTE_DIRECTORY;
1229 info->StandardInformation.AllocationSize.QuadPart = 0;
1230 info->StandardInformation.EndOfFile.QuadPart = 0;
1231 info->StandardInformation.NumberOfLinks = 1;
1232 info->StandardInformation.DeletePending = FALSE;
1236 info->BasicInformation.FileAttributes = FILE_ATTRIBUTE_ARCHIVE;
1237 info->StandardInformation.AllocationSize.QuadPart = (ULONGLONG)st.st_blocks * 512;
1238 info->StandardInformation.EndOfFile.QuadPart = st.st_size;
1239 info->StandardInformation.NumberOfLinks = st.st_nlink;
1240 info->StandardInformation.DeletePending = FALSE; /* FIXME */
1242 if (!(st.st_mode & (S_IWUSR | S_IWGRP | S_IWOTH)))
1243 info->BasicInformation.FileAttributes |= FILE_ATTRIBUTE_READONLY;
1244 RtlSecondsSince1970ToTime( st.st_mtime, &info->BasicInformation.CreationTime);
1245 RtlSecondsSince1970ToTime( st.st_mtime, &info->BasicInformation.LastWriteTime);
1246 RtlSecondsSince1970ToTime( st.st_ctime, &info->BasicInformation.ChangeTime);
1247 RtlSecondsSince1970ToTime( st.st_atime, &info->BasicInformation.LastAccessTime);
1248 info->InternalInformation.IndexNumber.QuadPart = st.st_ino;
1249 info->EaInformation.EaSize = 0;
1250 info->AccessInformation.AccessFlags = 0; /* FIXME */
1251 info->PositionInformation.CurrentByteOffset.QuadPart = lseek( fd, 0, SEEK_CUR );
1252 info->ModeInformation.Mode = 0; /* FIXME */
1253 info->AlignmentInformation.AlignmentRequirement = 1; /* FIXME */
1254 info->NameInformation.FileNameLength = 0;
1255 io->Information = sizeof(*info) - sizeof(WCHAR);
1259 case FileMailslotQueryInformation:
1261 FILE_MAILSLOT_QUERY_INFORMATION *info = ptr;
1263 SERVER_START_REQ( set_mailslot_info )
1265 req->handle = hFile;
1267 io->u.Status = wine_server_call( req );
1268 if( io->u.Status == STATUS_SUCCESS )
1270 info->MaximumMessageSize = reply->max_msgsize;
1271 info->MailslotQuota = 0;
1272 info->NextMessageSize = reply->next_msgsize;
1273 info->MessagesAvailable = reply->msg_count;
1274 info->ReadTimeout.QuadPart = reply->read_timeout * -10000;
1281 FIXME("Unsupported class (%d)\n", class);
1282 io->u.Status = STATUS_NOT_IMPLEMENTED;
1285 wine_server_release_fd( hFile, fd );
1286 if (io->u.Status == STATUS_SUCCESS && !io->Information) io->Information = info_sizes[class];
1287 return io->u.Status;
1290 /******************************************************************************
1291 * NtSetInformationFile [NTDLL.@]
1292 * ZwSetInformationFile [NTDLL.@]
1294 * Set information about an open file handle.
1297 * handle [I] Handle returned from ZwOpenFile() or ZwCreateFile()
1298 * io [O] Receives information about the operation on return
1299 * ptr [I] Source for file information
1300 * len [I] Size of FileInformation
1301 * class [I] Type of file information to set
1304 * Success: 0. io is updated.
1305 * Failure: An NTSTATUS error code describing the error.
1307 NTSTATUS WINAPI NtSetInformationFile(HANDLE handle, PIO_STATUS_BLOCK io,
1308 PVOID ptr, ULONG len, FILE_INFORMATION_CLASS class)
1312 TRACE("(%p,%p,%p,0x%08lx,0x%08x)\n", handle, io, ptr, len, class);
1314 if ((io->u.Status = wine_server_handle_to_fd( handle, 0, &fd, NULL )))
1315 return io->u.Status;
1317 io->u.Status = STATUS_SUCCESS;
1320 case FileBasicInformation:
1321 if (len >= sizeof(FILE_BASIC_INFORMATION))
1324 const FILE_BASIC_INFORMATION *info = ptr;
1326 if (info->LastAccessTime.QuadPart || info->LastWriteTime.QuadPart)
1328 ULONGLONG sec, nsec;
1329 struct timeval tv[2];
1331 if (!info->LastAccessTime.QuadPart || !info->LastWriteTime.QuadPart)
1334 tv[0].tv_sec = tv[0].tv_usec = 0;
1335 tv[1].tv_sec = tv[1].tv_usec = 0;
1336 if (!fstat( fd, &st ))
1338 tv[0].tv_sec = st.st_atime;
1339 tv[1].tv_sec = st.st_mtime;
1342 if (info->LastAccessTime.QuadPart)
1344 sec = RtlLargeIntegerDivide( info->LastAccessTime.QuadPart, 10000000, &nsec );
1345 tv[0].tv_sec = sec - SECS_1601_TO_1970;
1346 tv[0].tv_usec = (UINT)nsec / 10;
1348 if (info->LastWriteTime.QuadPart)
1350 sec = RtlLargeIntegerDivide( info->LastWriteTime.QuadPart, 10000000, &nsec );
1351 tv[1].tv_sec = sec - SECS_1601_TO_1970;
1352 tv[1].tv_usec = (UINT)nsec / 10;
1354 if (futimes( fd, tv ) == -1) io->u.Status = FILE_GetNtStatus();
1357 if (io->u.Status == STATUS_SUCCESS && info->FileAttributes)
1359 if (fstat( fd, &st ) == -1) io->u.Status = FILE_GetNtStatus();
1362 if (info->FileAttributes & FILE_ATTRIBUTE_READONLY)
1364 if (S_ISDIR( st.st_mode))
1365 WARN("FILE_ATTRIBUTE_READONLY ignored for directory.\n");
1367 st.st_mode &= ~0222; /* clear write permission bits */
1371 /* add write permission only where we already have read permission */
1372 st.st_mode |= (0600 | ((st.st_mode & 044) >> 1)) & (~FILE_umask);
1374 if (fchmod( fd, st.st_mode ) == -1) io->u.Status = FILE_GetNtStatus();
1378 else io->u.Status = STATUS_INVALID_PARAMETER_3;
1381 case FilePositionInformation:
1382 if (len >= sizeof(FILE_POSITION_INFORMATION))
1384 const FILE_POSITION_INFORMATION *info = ptr;
1386 if (lseek( fd, info->CurrentByteOffset.QuadPart, SEEK_SET ) == (off_t)-1)
1387 io->u.Status = FILE_GetNtStatus();
1389 else io->u.Status = STATUS_INVALID_PARAMETER_3;
1392 case FileEndOfFileInformation:
1393 if (len >= sizeof(FILE_END_OF_FILE_INFORMATION))
1396 const FILE_END_OF_FILE_INFORMATION *info = ptr;
1398 /* first try normal truncate */
1399 if (ftruncate( fd, (off_t)info->EndOfFile.QuadPart ) != -1) break;
1401 /* now check for the need to extend the file */
1402 if (fstat( fd, &st ) != -1 && (off_t)info->EndOfFile.QuadPart > st.st_size)
1404 static const char zero;
1406 /* extend the file one byte beyond the requested size and then truncate it */
1407 /* this should work around ftruncate implementations that can't extend files */
1408 if (pwrite( fd, &zero, 1, (off_t)info->EndOfFile.QuadPart ) != -1 &&
1409 ftruncate( fd, (off_t)info->EndOfFile.QuadPart ) != -1) break;
1411 io->u.Status = FILE_GetNtStatus();
1413 else io->u.Status = STATUS_INVALID_PARAMETER_3;
1416 case FileMailslotSetInformation:
1418 FILE_MAILSLOT_SET_INFORMATION *info = ptr;
1420 SERVER_START_REQ( set_mailslot_info )
1422 req->handle = handle;
1423 req->flags = MAILSLOT_SET_READ_TIMEOUT;
1424 req->read_timeout = info->ReadTimeout.QuadPart / -10000;
1425 io->u.Status = wine_server_call( req );
1432 FIXME("Unsupported class (%d)\n", class);
1433 io->u.Status = STATUS_NOT_IMPLEMENTED;
1436 wine_server_release_fd( handle, fd );
1437 io->Information = 0;
1438 return io->u.Status;
1442 /******************************************************************************
1443 * NtQueryFullAttributesFile (NTDLL.@)
1445 NTSTATUS WINAPI NtQueryFullAttributesFile( const OBJECT_ATTRIBUTES *attr,
1446 FILE_NETWORK_OPEN_INFORMATION *info )
1448 ANSI_STRING unix_name;
1451 if (!(status = wine_nt_to_unix_file_name( attr->ObjectName, &unix_name, FILE_OPEN,
1452 !(attr->Attributes & OBJ_CASE_INSENSITIVE) )))
1456 if (stat( unix_name.Buffer, &st ) == -1)
1457 status = FILE_GetNtStatus();
1458 else if (!S_ISREG(st.st_mode) && !S_ISDIR(st.st_mode))
1459 status = STATUS_INVALID_INFO_CLASS;
1462 if (S_ISDIR(st.st_mode))
1464 info->FileAttributes = FILE_ATTRIBUTE_DIRECTORY;
1465 info->AllocationSize.QuadPart = 0;
1466 info->EndOfFile.QuadPart = 0;
1470 info->FileAttributes = FILE_ATTRIBUTE_ARCHIVE;
1471 info->AllocationSize.QuadPart = (ULONGLONG)st.st_blocks * 512;
1472 info->EndOfFile.QuadPart = st.st_size;
1474 if (!(st.st_mode & (S_IWUSR | S_IWGRP | S_IWOTH)))
1475 info->FileAttributes |= FILE_ATTRIBUTE_READONLY;
1476 RtlSecondsSince1970ToTime( st.st_mtime, &info->CreationTime );
1477 RtlSecondsSince1970ToTime( st.st_mtime, &info->LastWriteTime );
1478 RtlSecondsSince1970ToTime( st.st_ctime, &info->ChangeTime );
1479 RtlSecondsSince1970ToTime( st.st_atime, &info->LastAccessTime );
1480 if (DIR_is_hidden_file( attr->ObjectName ))
1481 info->FileAttributes |= FILE_ATTRIBUTE_HIDDEN;
1483 RtlFreeAnsiString( &unix_name );
1485 else WARN("%s not found (%lx)\n", debugstr_us(attr->ObjectName), status );
1490 /******************************************************************************
1491 * NtQueryAttributesFile (NTDLL.@)
1492 * ZwQueryAttributesFile (NTDLL.@)
1494 NTSTATUS WINAPI NtQueryAttributesFile( const OBJECT_ATTRIBUTES *attr, FILE_BASIC_INFORMATION *info )
1496 FILE_NETWORK_OPEN_INFORMATION full_info;
1499 if (!(status = NtQueryFullAttributesFile( attr, &full_info )))
1501 info->CreationTime.QuadPart = full_info.CreationTime.QuadPart;
1502 info->LastAccessTime.QuadPart = full_info.LastAccessTime.QuadPart;
1503 info->LastWriteTime.QuadPart = full_info.LastWriteTime.QuadPart;
1504 info->ChangeTime.QuadPart = full_info.ChangeTime.QuadPart;
1505 info->FileAttributes = full_info.FileAttributes;
1511 /******************************************************************************
1512 * FILE_GetDeviceInfo
1514 * Implementation of the FileFsDeviceInformation query for NtQueryVolumeInformationFile.
1516 NTSTATUS FILE_GetDeviceInfo( int fd, FILE_FS_DEVICE_INFORMATION *info )
1520 info->Characteristics = 0;
1521 if (fstat( fd, &st ) < 0) return FILE_GetNtStatus();
1522 if (S_ISCHR( st.st_mode ))
1524 info->DeviceType = FILE_DEVICE_UNKNOWN;
1526 switch(major(st.st_rdev))
1529 info->DeviceType = FILE_DEVICE_NULL;
1532 info->DeviceType = FILE_DEVICE_SERIAL_PORT;
1535 info->DeviceType = FILE_DEVICE_PARALLEL_PORT;
1540 else if (S_ISBLK( st.st_mode ))
1542 info->DeviceType = FILE_DEVICE_DISK;
1544 else if (S_ISFIFO( st.st_mode ) || S_ISSOCK( st.st_mode ))
1546 info->DeviceType = FILE_DEVICE_NAMED_PIPE;
1548 else /* regular file or directory */
1550 #if defined(linux) && defined(HAVE_FSTATFS)
1553 /* check for floppy disk */
1554 if (major(st.st_dev) == FLOPPY_MAJOR)
1555 info->Characteristics |= FILE_REMOVABLE_MEDIA;
1557 if (fstatfs( fd, &stfs ) < 0) stfs.f_type = 0;
1558 switch (stfs.f_type)
1560 case 0x9660: /* iso9660 */
1561 case 0x15013346: /* udf */
1562 info->DeviceType = FILE_DEVICE_CD_ROM_FILE_SYSTEM;
1563 info->Characteristics |= FILE_REMOVABLE_MEDIA|FILE_READ_ONLY_DEVICE;
1565 case 0x6969: /* nfs */
1566 case 0x517B: /* smbfs */
1567 case 0x564c: /* ncpfs */
1568 info->DeviceType = FILE_DEVICE_NETWORK_FILE_SYSTEM;
1569 info->Characteristics |= FILE_REMOTE_DEVICE;
1571 case 0x01021994: /* tmpfs */
1572 case 0x28cd3d45: /* cramfs */
1573 case 0x1373: /* devfs */
1574 case 0x9fa0: /* procfs */
1575 info->DeviceType = FILE_DEVICE_VIRTUAL_DISK;
1578 info->DeviceType = FILE_DEVICE_DISK_FILE_SYSTEM;
1581 #elif defined(__FreeBSD__)
1584 /* The proper way to do this in FreeBSD seems to be with the
1585 * name rather than the type, since their linux-compatible
1586 * fstatfs call converts the name to one of the Linux types.
1588 if (fstatfs( fd, &stfs ) < 0)
1589 info->DeviceType = FILE_DEVICE_DISK_FILE_SYSTEM;
1590 else if (!strncmp("cd9660", stfs.f_fstypename,
1591 sizeof(stfs.f_fstypename)))
1593 info->DeviceType = FILE_DEVICE_CD_ROM_FILE_SYSTEM;
1594 /* Don't assume read-only, let the mount options set it
1597 info->Characteristics |= FILE_REMOVABLE_MEDIA;
1599 else if (!strncmp("nfs", stfs.f_fstypename,
1600 sizeof(stfs.f_fstypename)))
1602 info->DeviceType = FILE_DEVICE_NETWORK_FILE_SYSTEM;
1603 info->Characteristics |= FILE_REMOTE_DEVICE;
1605 else if (!strncmp("nwfs", stfs.f_fstypename,
1606 sizeof(stfs.f_fstypename)))
1608 info->DeviceType = FILE_DEVICE_NETWORK_FILE_SYSTEM;
1609 info->Characteristics |= FILE_REMOTE_DEVICE;
1611 else if (!strncmp("procfs", stfs.f_fstypename,
1612 sizeof(stfs.f_fstypename)))
1613 info->DeviceType = FILE_DEVICE_VIRTUAL_DISK;
1615 info->DeviceType = FILE_DEVICE_DISK_FILE_SYSTEM;
1616 if (stfs.f_flags & MNT_RDONLY)
1617 info->Characteristics |= FILE_READ_ONLY_DEVICE;
1618 if (!(stfs.f_flags & MNT_LOCAL))
1620 info->DeviceType = FILE_DEVICE_NETWORK_FILE_SYSTEM;
1621 info->Characteristics |= FILE_REMOTE_DEVICE;
1623 #elif defined (__APPLE__)
1625 kern_return_t kernResult = KERN_FAILURE;
1626 mach_port_t masterPort;
1627 char bsdName[6]; /* disk#\0 */
1630 info->DeviceType = FILE_DEVICE_DISK_FILE_SYSTEM;
1632 if (fstatfs( fd, &stfs ) < 0) return FILE_GetNtStatus();
1634 /* stfs.f_type is reserved (always set to 0) so use IOKit */
1635 name = stfs.f_mntfromname + strlen(_PATH_DEV);
1636 memcpy( bsdName, name, min(strlen(name)+1,sizeof(bsdName)) );
1637 bsdName[sizeof(bsdName)-1] = 0;
1639 kernResult = IOMasterPort(MACH_PORT_NULL, &masterPort);
1641 if (kernResult == KERN_SUCCESS)
1643 CFMutableDictionaryRef matching = IOBSDNameMatching(masterPort, 0, bsdName);
1648 CFMutableDictionaryRef properties;
1649 io_service_t devService = IOServiceGetMatchingService(masterPort, matching);
1651 if (IORegistryEntryCreateCFProperties(devService,
1653 kCFAllocatorDefault, 0) != KERN_SUCCESS)
1654 return FILE_GetNtStatus(); /* FIXME */
1656 CFDictionaryGetValue(properties, CFSTR("Removable")),
1658 ) info->Characteristics |= FILE_REMOVABLE_MEDIA;
1661 CFDictionaryGetValue(properties, CFSTR("Writable")),
1663 ) info->Characteristics |= FILE_READ_ONLY_DEVICE;
1666 NB : mounted disk image (.img/.dmg) don't provide specific type
1668 if ( (type = CFDictionaryGetValue(properties, CFSTR("Type"))) )
1670 if ( CFStringCompare(type, CFSTR("CD-ROM"), 0) == kCFCompareEqualTo
1671 || CFStringCompare(type, CFSTR("DVD-ROM"), 0) == kCFCompareEqualTo
1674 info->DeviceType = FILE_DEVICE_CD_ROM_FILE_SYSTEM;
1679 CFRelease(properties);
1683 /* Use dkio to work out device types */
1685 # include <sys/dkio.h>
1686 # include <sys/vtoc.h>
1687 struct dk_cinfo dkinf;
1688 int retval = ioctl(fd, DKIOCINFO, &dkinf);
1690 WARN("Unable to get disk device type information - assuming a disk like device\n");
1691 info->DeviceType = FILE_DEVICE_DISK_FILE_SYSTEM;
1693 switch (dkinf.dki_ctype)
1696 info->DeviceType = FILE_DEVICE_CD_ROM_FILE_SYSTEM;
1697 info->Characteristics |= FILE_REMOVABLE_MEDIA|FILE_READ_ONLY_DEVICE;
1701 case DKC_INTEL82072:
1702 case DKC_INTEL82077:
1703 info->DeviceType = FILE_DEVICE_DISK_FILE_SYSTEM;
1704 info->Characteristics |= FILE_REMOVABLE_MEDIA;
1707 info->DeviceType = FILE_DEVICE_VIRTUAL_DISK;
1710 info->DeviceType = FILE_DEVICE_DISK_FILE_SYSTEM;
1715 if (!warned++) FIXME( "device info not properly supported on this platform\n" );
1716 info->DeviceType = FILE_DEVICE_DISK_FILE_SYSTEM;
1718 info->Characteristics |= FILE_DEVICE_IS_MOUNTED;
1720 return STATUS_SUCCESS;
1724 /******************************************************************************
1725 * NtQueryVolumeInformationFile [NTDLL.@]
1726 * ZwQueryVolumeInformationFile [NTDLL.@]
1728 * Get volume information for an open file handle.
1731 * handle [I] Handle returned from ZwOpenFile() or ZwCreateFile()
1732 * io [O] Receives information about the operation on return
1733 * buffer [O] Destination for volume information
1734 * length [I] Size of FsInformation
1735 * info_class [I] Type of volume information to set
1738 * Success: 0. io and buffer are updated.
1739 * Failure: An NTSTATUS error code describing the error.
1741 NTSTATUS WINAPI NtQueryVolumeInformationFile( HANDLE handle, PIO_STATUS_BLOCK io,
1742 PVOID buffer, ULONG length,
1743 FS_INFORMATION_CLASS info_class )
1748 if ((io->u.Status = wine_server_handle_to_fd( handle, 0, &fd, NULL )) != STATUS_SUCCESS)
1749 return io->u.Status;
1751 io->u.Status = STATUS_NOT_IMPLEMENTED;
1752 io->Information = 0;
1754 switch( info_class )
1756 case FileFsVolumeInformation:
1757 FIXME( "%p: volume info not supported\n", handle );
1759 case FileFsLabelInformation:
1760 FIXME( "%p: label info not supported\n", handle );
1762 case FileFsSizeInformation:
1763 if (length < sizeof(FILE_FS_SIZE_INFORMATION))
1764 io->u.Status = STATUS_BUFFER_TOO_SMALL;
1767 FILE_FS_SIZE_INFORMATION *info = buffer;
1769 if (fstat( fd, &st ) < 0)
1771 io->u.Status = FILE_GetNtStatus();
1774 if (!S_ISREG(st.st_mode) && !S_ISDIR(st.st_mode))
1776 io->u.Status = STATUS_INVALID_DEVICE_REQUEST;
1780 /* Linux's fstatvfs is buggy */
1781 #if !defined(linux) || !defined(HAVE_FSTATFS)
1782 struct statvfs stfs;
1784 if (fstatvfs( fd, &stfs ) < 0)
1786 io->u.Status = FILE_GetNtStatus();
1789 info->BytesPerSector = stfs.f_frsize;
1792 if (fstatfs( fd, &stfs ) < 0)
1794 io->u.Status = FILE_GetNtStatus();
1797 info->BytesPerSector = stfs.f_bsize;
1799 info->TotalAllocationUnits.QuadPart = stfs.f_blocks;
1800 info->AvailableAllocationUnits.QuadPart = stfs.f_bavail;
1801 info->SectorsPerAllocationUnit = 1;
1802 io->Information = sizeof(*info);
1803 io->u.Status = STATUS_SUCCESS;
1807 case FileFsDeviceInformation:
1808 if (length < sizeof(FILE_FS_DEVICE_INFORMATION))
1809 io->u.Status = STATUS_BUFFER_TOO_SMALL;
1812 FILE_FS_DEVICE_INFORMATION *info = buffer;
1814 if ((io->u.Status = FILE_GetDeviceInfo( fd, info )) == STATUS_SUCCESS)
1815 io->Information = sizeof(*info);
1818 case FileFsAttributeInformation:
1819 FIXME( "%p: attribute info not supported\n", handle );
1821 case FileFsControlInformation:
1822 FIXME( "%p: control info not supported\n", handle );
1824 case FileFsFullSizeInformation:
1825 FIXME( "%p: full size info not supported\n", handle );
1827 case FileFsObjectIdInformation:
1828 FIXME( "%p: object id info not supported\n", handle );
1830 case FileFsMaximumInformation:
1831 FIXME( "%p: maximum info not supported\n", handle );
1834 io->u.Status = STATUS_INVALID_PARAMETER;
1837 wine_server_release_fd( handle, fd );
1838 return io->u.Status;
1842 /******************************************************************
1843 * NtFlushBuffersFile (NTDLL.@)
1845 * Flush any buffered data on an open file handle.
1848 * FileHandle [I] Handle returned from ZwOpenFile() or ZwCreateFile()
1849 * IoStatusBlock [O] Receives information about the operation on return
1852 * Success: 0. IoStatusBlock is updated.
1853 * Failure: An NTSTATUS error code describing the error.
1855 NTSTATUS WINAPI NtFlushBuffersFile( HANDLE hFile, IO_STATUS_BLOCK* IoStatusBlock )
1858 HANDLE hEvent = NULL;
1860 SERVER_START_REQ( flush_file )
1862 req->handle = hFile;
1863 ret = wine_server_call( req );
1864 hEvent = reply->event;
1869 ret = NtWaitForSingleObject( hEvent, FALSE, NULL );
1875 /******************************************************************
1876 * NtLockFile (NTDLL.@)
1880 NTSTATUS WINAPI NtLockFile( HANDLE hFile, HANDLE lock_granted_event,
1881 PIO_APC_ROUTINE apc, void* apc_user,
1882 PIO_STATUS_BLOCK io_status, PLARGE_INTEGER offset,
1883 PLARGE_INTEGER count, ULONG* key, BOOLEAN dont_wait,
1890 if (apc || io_status || key)
1892 FIXME("Unimplemented yet parameter\n");
1893 return STATUS_NOT_IMPLEMENTED;
1898 SERVER_START_REQ( lock_file )
1900 req->handle = hFile;
1901 req->offset_low = offset->u.LowPart;
1902 req->offset_high = offset->u.HighPart;
1903 req->count_low = count->u.LowPart;
1904 req->count_high = count->u.HighPart;
1905 req->shared = !exclusive;
1906 req->wait = !dont_wait;
1907 ret = wine_server_call( req );
1908 handle = reply->handle;
1909 async = reply->overlapped;
1912 if (ret != STATUS_PENDING)
1914 if (!ret && lock_granted_event) NtSetEvent(lock_granted_event, NULL);
1920 FIXME( "Async I/O lock wait not implemented, might deadlock\n" );
1921 if (handle) NtClose( handle );
1922 return STATUS_PENDING;
1926 NtWaitForSingleObject( handle, FALSE, NULL );
1933 /* Unix lock conflict, sleep a bit and retry */
1934 time.QuadPart = 100 * (ULONGLONG)10000;
1935 time.QuadPart = -time.QuadPart;
1936 NtDelayExecution( FALSE, &time );
1942 /******************************************************************
1943 * NtUnlockFile (NTDLL.@)
1947 NTSTATUS WINAPI NtUnlockFile( HANDLE hFile, PIO_STATUS_BLOCK io_status,
1948 PLARGE_INTEGER offset, PLARGE_INTEGER count,
1953 TRACE( "%p %lx%08lx %lx%08lx\n",
1954 hFile, offset->u.HighPart, offset->u.LowPart, count->u.HighPart, count->u.LowPart );
1956 if (io_status || key)
1958 FIXME("Unimplemented yet parameter\n");
1959 return STATUS_NOT_IMPLEMENTED;
1962 SERVER_START_REQ( unlock_file )
1964 req->handle = hFile;
1965 req->offset_low = offset->u.LowPart;
1966 req->offset_high = offset->u.HighPart;
1967 req->count_low = count->u.LowPart;
1968 req->count_high = count->u.HighPart;
1969 status = wine_server_call( req );
1975 /******************************************************************
1976 * NtCreateNamedPipeFile (NTDLL.@)
1980 NTSTATUS WINAPI NtCreateNamedPipeFile( PHANDLE handle, ULONG access,
1981 POBJECT_ATTRIBUTES attr, PIO_STATUS_BLOCK iosb,
1982 ULONG sharing, ULONG dispo, ULONG options,
1983 ULONG pipe_type, ULONG read_mode,
1984 ULONG completion_mode, ULONG max_inst,
1985 ULONG inbound_quota, ULONG outbound_quota,
1986 PLARGE_INTEGER timeout)
1989 static const WCHAR leadin[] = {'\\','?','?','\\','P','I','P','E','\\'};
1991 TRACE("(%p %lx %s %p %lx %ld %lx %ld %ld %ld %ld %ld %ld %p)\n",
1992 handle, access, debugstr_w(attr->ObjectName->Buffer), iosb, sharing, dispo,
1993 options, pipe_type, read_mode, completion_mode, max_inst, inbound_quota,
1994 outbound_quota, timeout);
1996 if (attr->ObjectName->Length < sizeof(leadin) ||
1997 strncmpiW( attr->ObjectName->Buffer,
1998 leadin, sizeof(leadin)/sizeof(leadin[0]) ))
1999 return STATUS_OBJECT_NAME_INVALID;
2000 /* assume we only get relative timeout, and storable in a DWORD as ms */
2001 if (timeout->QuadPart > 0 || (timeout->QuadPart / -10000) >> 32)
2002 FIXME("Wrong time %s\n", wine_dbgstr_longlong(timeout->QuadPart));
2004 SERVER_START_REQ( create_named_pipe )
2006 req->access = access;
2007 req->attributes = (attr) ? attr->Attributes : 0;
2008 req->rootdir = attr ? attr->RootDirectory : 0;
2009 req->options = options;
2011 (pipe_type) ? NAMED_PIPE_MESSAGE_STREAM_WRITE : 0 |
2012 (read_mode) ? NAMED_PIPE_MESSAGE_STREAM_READ : 0 |
2013 (completion_mode) ? NAMED_PIPE_NONBLOCKING_MODE : 0;
2014 req->maxinstances = max_inst;
2015 req->outsize = outbound_quota;
2016 req->insize = inbound_quota;
2017 req->timeout = timeout->QuadPart / -10000;
2018 wine_server_add_data( req, attr->ObjectName->Buffer,
2019 attr->ObjectName->Length );
2020 status = wine_server_call( req );
2021 if (!status) *handle = reply->handle;
2027 /******************************************************************
2028 * NtDeleteFile (NTDLL.@)
2032 NTSTATUS WINAPI NtDeleteFile( POBJECT_ATTRIBUTES ObjectAttributes )
2038 TRACE("%p\n", ObjectAttributes);
2039 status = NtCreateFile( &hFile, GENERIC_READ | GENERIC_WRITE, ObjectAttributes,
2041 FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,
2042 FILE_OPEN, FILE_DELETE_ON_CLOSE, NULL, 0 );
2043 if (status == STATUS_SUCCESS) status = NtClose(hFile);
2047 /******************************************************************
2048 * NtCancelIoFile (NTDLL.@)
2052 NTSTATUS WINAPI NtCancelIoFile( HANDLE hFile, PIO_STATUS_BLOCK io_status )
2054 LARGE_INTEGER timeout;
2056 TRACE("%p %p\n", hFile, io_status );
2058 SERVER_START_REQ( cancel_async )
2060 req->handle = hFile;
2061 wine_server_call( req );
2064 /* Let some APC be run, so that we can run the remaining APCs on hFile
2065 * either the cancelation of the pending one, but also the execution
2066 * of the queued APC, but not yet run. This is needed to ensure proper
2067 * clean-up of allocated data.
2069 timeout.u.LowPart = timeout.u.HighPart = 0;
2070 return io_status->u.Status = NtDelayExecution( TRUE, &timeout );
2073 /******************************************************************************
2074 * NtCreateMailslotFile [NTDLL.@]
2075 * ZwCreateMailslotFile [NTDLL.@]
2078 * pHandle [O] pointer to receive the handle created
2079 * DesiredAccess [I] access mode (read, write, etc)
2080 * ObjectAttributes [I] fully qualified NT path of the mailslot
2081 * IoStatusBlock [O] receives completion status and other info
2084 * MaxMessageSize [I]
2090 NTSTATUS WINAPI NtCreateMailslotFile(PHANDLE pHandle, ULONG DesiredAccess,
2091 POBJECT_ATTRIBUTES attr, PIO_STATUS_BLOCK IoStatusBlock,
2092 ULONG CreateOptions, ULONG MailslotQuota, ULONG MaxMessageSize,
2093 PLARGE_INTEGER TimeOut)
2095 static const WCHAR leadin[] = {
2096 '\\','?','?','\\','M','A','I','L','S','L','O','T','\\'};
2099 TRACE("%p %08lx %p %p %08lx %08lx %08lx %p\n",
2100 pHandle, DesiredAccess, attr, IoStatusBlock,
2101 CreateOptions, MailslotQuota, MaxMessageSize, TimeOut);
2103 if (attr->ObjectName->Length < sizeof(leadin) ||
2104 strncmpiW( attr->ObjectName->Buffer,
2105 leadin, sizeof(leadin)/sizeof(leadin[0]) ))
2107 return STATUS_OBJECT_NAME_INVALID;
2110 SERVER_START_REQ( create_mailslot )
2112 req->access = DesiredAccess;
2113 req->attributes = (attr) ? attr->Attributes : 0;
2114 req->rootdir = attr ? attr->RootDirectory : 0;
2115 req->max_msgsize = MaxMessageSize;
2116 req->read_timeout = (TimeOut->QuadPart <= 0) ? TimeOut->QuadPart / -10000 : -1;
2117 wine_server_add_data( req, attr->ObjectName->Buffer,
2118 attr->ObjectName->Length );
2119 ret = wine_server_call( req );
2120 if( ret == STATUS_SUCCESS )
2121 *pHandle = reply->handle;