Added auto-detection of DOS drive devices based on finding the
[wine/multimedia.git] / dlls / ntdll / file.c
blobed354fb96483c77bde50502b9d3fe4860d048707
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 #define NONAMELESSUNION
61 #define NONAMELESSSTRUCT
62 #include "wine/unicode.h"
63 #include "wine/debug.h"
64 #include "wine/server.h"
65 #include "async.h"
66 #include "ntdll_misc.h"
68 #include "winternl.h"
69 #include "winioctl.h"
71 WINE_DEFAULT_DEBUG_CHANNEL(ntdll);
73 mode_t FILE_umask = 0;
75 #define SECSPERDAY 86400
76 #define SECS_1601_TO_1970 ((369 * 365 + 89) * (ULONGLONG)SECSPERDAY)
78 /**************************************************************************
79 * NtOpenFile [NTDLL.@]
80 * ZwOpenFile [NTDLL.@]
82 * Open a file.
84 * PARAMS
85 * handle [O] Variable that receives the file handle on return
86 * access [I] Access desired by the caller to the file
87 * attr [I] Structue describing the file to be opened
88 * io [O] Receives details about the result of the operation
89 * sharing [I] Type of shared access the caller requires
90 * options [I] Options for the file open
92 * RETURNS
93 * Success: 0. FileHandle and IoStatusBlock are updated.
94 * Failure: An NTSTATUS error code describing the error.
96 NTSTATUS WINAPI NtOpenFile( PHANDLE handle, ACCESS_MASK access,
97 POBJECT_ATTRIBUTES attr, PIO_STATUS_BLOCK io,
98 ULONG sharing, ULONG options )
100 return NtCreateFile( handle, access, attr, io, NULL, 0,
101 sharing, FILE_OPEN, options, NULL, 0 );
104 /**************************************************************************
105 * NtCreateFile [NTDLL.@]
106 * ZwCreateFile [NTDLL.@]
108 * Either create a new file or directory, or open an existing file, device,
109 * directory or volume.
111 * PARAMS
112 * handle [O] Points to a variable which receives the file handle on return
113 * access [I] Desired access to the file
114 * attr [I] Structure describing the file
115 * io [O] Receives information about the operation on return
116 * alloc_size [I] Initial size of the file in bytes
117 * attributes [I] Attributes to create the file with
118 * sharing [I] Type of shared access the caller would like to the file
119 * disposition [I] Specifies what to do, depending on whether the file already exists
120 * options [I] Options for creating a new file
121 * ea_buffer [I] Undocumented
122 * ea_length [I] Undocumented
124 * RETURNS
125 * Success: 0. handle and io are updated.
126 * Failure: An NTSTATUS error code describing the error.
128 NTSTATUS WINAPI NtCreateFile( PHANDLE handle, ACCESS_MASK access, POBJECT_ATTRIBUTES attr,
129 PIO_STATUS_BLOCK io, PLARGE_INTEGER alloc_size,
130 ULONG attributes, ULONG sharing, ULONG disposition,
131 ULONG options, PVOID ea_buffer, ULONG ea_length )
133 ANSI_STRING unix_name;
134 int created = FALSE;
136 TRACE("handle=%p access=%08lx name=%s objattr=%08lx root=%p sec=%p io=%p alloc_size=%p\n"
137 "attr=%08lx sharing=%08lx disp=%ld options=%08lx ea=%p.0x%08lx\n",
138 handle, access, debugstr_us(attr->ObjectName), attr->Attributes,
139 attr->RootDirectory, attr->SecurityDescriptor, io, alloc_size,
140 attributes, sharing, disposition, options, ea_buffer, ea_length );
142 if (attr->RootDirectory)
144 FIXME( "RootDirectory %p not supported\n", attr->RootDirectory );
145 return STATUS_OBJECT_NAME_NOT_FOUND;
147 if (alloc_size) FIXME( "alloc_size not supported\n" );
149 io->u.Status = wine_nt_to_unix_file_name( attr->ObjectName, &unix_name, disposition,
150 !(attr->Attributes & OBJ_CASE_INSENSITIVE) );
152 if (io->u.Status == STATUS_NO_SUCH_FILE &&
153 disposition != FILE_OPEN && disposition != FILE_OVERWRITE)
155 created = TRUE;
156 io->u.Status = STATUS_SUCCESS;
159 if (io->u.Status == STATUS_SUCCESS)
161 SERVER_START_REQ( create_file )
163 req->access = access;
164 req->inherit = (attr->Attributes & OBJ_INHERIT) != 0;
165 req->sharing = sharing;
166 req->create = disposition;
167 req->options = options;
168 req->attrs = attributes;
169 wine_server_add_data( req, unix_name.Buffer, unix_name.Length );
170 io->u.Status = wine_server_call( req );
171 *handle = reply->handle;
173 SERVER_END_REQ;
174 RtlFreeAnsiString( &unix_name );
176 else WARN("%s not found (%lx)\n", debugstr_us(attr->ObjectName), io->u.Status );
178 if (io->u.Status == STATUS_SUCCESS)
180 if (created) io->Information = FILE_CREATED;
181 else switch(disposition)
183 case FILE_SUPERSEDE:
184 io->Information = FILE_SUPERSEDED;
185 break;
186 case FILE_CREATE:
187 io->Information = FILE_CREATED;
188 break;
189 case FILE_OPEN:
190 case FILE_OPEN_IF:
191 io->Information = FILE_OPENED;
192 break;
193 case FILE_OVERWRITE:
194 case FILE_OVERWRITE_IF:
195 io->Information = FILE_OVERWRITTEN;
196 break;
200 return io->u.Status;
203 /***********************************************************************
204 * Asynchronous file I/O *
206 static DWORD fileio_get_async_count(const async_private *ovp);
207 static void CALLBACK fileio_call_completion_func(ULONG_PTR data);
208 static void fileio_async_cleanup(async_private *ovp);
210 static async_ops fileio_async_ops =
212 fileio_get_async_count, /* get_count */
213 fileio_call_completion_func, /* call_completion */
214 fileio_async_cleanup /* cleanup */
217 static async_ops fileio_nocomp_async_ops =
219 fileio_get_async_count, /* get_count */
220 NULL, /* call_completion */
221 fileio_async_cleanup /* cleanup */
224 typedef struct async_fileio
226 struct async_private async;
227 PIO_APC_ROUTINE apc;
228 void* apc_user;
229 char *buffer;
230 unsigned int count;
231 unsigned long offset;
232 enum fd_type fd_type;
233 } async_fileio;
235 static DWORD fileio_get_async_count(const struct async_private *ovp)
237 async_fileio *fileio = (async_fileio*) ovp;
239 if (fileio->count < fileio->async.iosb->Information)
240 return 0;
241 return fileio->count - fileio->async.iosb->Information;
244 static void CALLBACK fileio_call_completion_func(ULONG_PTR data)
246 async_fileio *ovp = (async_fileio*) data;
247 TRACE("data: %p\n", ovp);
249 ovp->apc( ovp->apc_user, ovp->async.iosb, ovp->async.iosb->Information );
251 fileio_async_cleanup( &ovp->async );
254 static void fileio_async_cleanup( struct async_private *ovp )
256 RtlFreeHeap( GetProcessHeap(), 0, ovp );
259 /***********************************************************************
260 * FILE_GetNtStatus(void)
262 * Retrieve the Nt Status code from errno.
263 * Try to be consistent with FILE_SetDosError().
265 NTSTATUS FILE_GetNtStatus(void)
267 int err = errno;
269 TRACE( "errno = %d\n", errno );
270 switch (err)
272 case EAGAIN: return STATUS_SHARING_VIOLATION;
273 case EBADF: return STATUS_INVALID_HANDLE;
274 case ENOSPC: return STATUS_DISK_FULL;
275 case EPERM:
276 case EROFS:
277 case EACCES: return STATUS_ACCESS_DENIED;
278 case ENOTDIR: return STATUS_OBJECT_PATH_NOT_FOUND;
279 case ENOENT: return STATUS_OBJECT_NAME_NOT_FOUND;
280 case EISDIR: return STATUS_FILE_IS_A_DIRECTORY;
281 case EMFILE:
282 case ENFILE: return STATUS_TOO_MANY_OPENED_FILES;
283 case EINVAL: return STATUS_INVALID_PARAMETER;
284 case ENOTEMPTY: return STATUS_DIRECTORY_NOT_EMPTY;
285 case EPIPE: return STATUS_PIPE_BROKEN;
286 case EIO: return STATUS_DEVICE_NOT_READY;
287 #ifdef ENOMEDIUM
288 case ENOMEDIUM: return STATUS_NO_MEDIA_IN_DEVICE;
289 #endif
290 case ENOTTY:
291 case EOPNOTSUPP:return STATUS_NOT_SUPPORTED;
292 case ENOEXEC: /* ?? */
293 case ESPIPE: /* ?? */
294 case EEXIST: /* ?? */
295 default:
296 FIXME( "Converting errno %d to STATUS_UNSUCCESSFUL\n", err );
297 return STATUS_UNSUCCESSFUL;
301 /***********************************************************************
302 * FILE_AsyncReadService (INTERNAL)
304 * This function is called while the client is waiting on the
305 * server, so we can't make any server calls here.
307 static void FILE_AsyncReadService(async_private *ovp)
309 async_fileio *fileio = (async_fileio*) ovp;
310 IO_STATUS_BLOCK* io_status = fileio->async.iosb;
311 int result;
312 int already = io_status->Information;
314 TRACE("%p %p\n", io_status, fileio->buffer );
316 /* check to see if the data is ready (non-blocking) */
318 if ( fileio->fd_type == FD_TYPE_SOCKET )
319 result = read(ovp->fd, &fileio->buffer[already], fileio->count - already);
320 else
322 result = pread(ovp->fd, &fileio->buffer[already], fileio->count - already,
323 fileio->offset + already);
324 if ((result < 0) && (errno == ESPIPE))
325 result = read(ovp->fd, &fileio->buffer[already], fileio->count - already);
328 if ((result < 0) && ((errno == EAGAIN) || (errno == EINTR)))
330 TRACE("Deferred read %d\n",errno);
331 io_status->u.Status = STATUS_PENDING;
332 return;
335 /* check to see if the transfer is complete */
336 if (result < 0)
338 io_status->u.Status = FILE_GetNtStatus();
339 return;
341 else if (result == 0)
343 io_status->u.Status = io_status->Information ? STATUS_SUCCESS : STATUS_END_OF_FILE;
344 return;
347 io_status->Information += result;
348 if (io_status->Information >= fileio->count || fileio->fd_type == FD_TYPE_SOCKET )
349 io_status->u.Status = STATUS_SUCCESS;
350 else
351 io_status->u.Status = STATUS_PENDING;
353 TRACE("read %d more bytes %ld/%d so far\n",
354 result, io_status->Information, fileio->count);
358 /******************************************************************************
359 * NtReadFile [NTDLL.@]
360 * ZwReadFile [NTDLL.@]
362 * Read from an open file handle.
364 * PARAMS
365 * FileHandle [I] Handle returned from ZwOpenFile() or ZwCreateFile()
366 * Event [I] Event to signal upon completion (or NULL)
367 * ApcRoutine [I] Callback to call upon completion (or NULL)
368 * ApcContext [I] Context for ApcRoutine (or NULL)
369 * IoStatusBlock [O] Receives information about the operation on return
370 * Buffer [O] Destination for the data read
371 * Length [I] Size of Buffer
372 * ByteOffset [O] Destination for the new file pointer position (or NULL)
373 * Key [O] Function unknown (may be NULL)
375 * RETURNS
376 * Success: 0. IoStatusBlock is updated, and the Information member contains
377 * The number of bytes read.
378 * Failure: An NTSTATUS error code describing the error.
380 NTSTATUS WINAPI NtReadFile(HANDLE hFile, HANDLE hEvent,
381 PIO_APC_ROUTINE apc, void* apc_user,
382 PIO_STATUS_BLOCK io_status, void* buffer, ULONG length,
383 PLARGE_INTEGER offset, PULONG key)
385 int unix_handle, flags;
386 enum fd_type type;
388 TRACE("(%p,%p,%p,%p,%p,%p,0x%08lx,%p,%p),partial stub!\n",
389 hFile,hEvent,apc,apc_user,io_status,buffer,length,offset,key);
391 io_status->Information = 0;
392 io_status->u.Status = wine_server_handle_to_fd( hFile, GENERIC_READ, &unix_handle, &type, &flags );
393 if (io_status->u.Status) return io_status->u.Status;
395 if (flags & FD_FLAG_RECV_SHUTDOWN)
397 wine_server_release_fd( hFile, unix_handle );
398 return STATUS_PIPE_DISCONNECTED;
401 if (flags & FD_FLAG_TIMEOUT)
403 if (hEvent)
405 /* this shouldn't happen, but check it */
406 FIXME("NIY-hEvent\n");
407 wine_server_release_fd( hFile, unix_handle );
408 return STATUS_NOT_IMPLEMENTED;
410 io_status->u.Status = NtCreateEvent(&hEvent, SYNCHRONIZE, NULL, 0, 0);
411 if (io_status->u.Status)
413 wine_server_release_fd( hFile, unix_handle );
414 return io_status->u.Status;
418 if (flags & (FD_FLAG_OVERLAPPED|FD_FLAG_TIMEOUT))
420 async_fileio* ovp;
421 NTSTATUS ret;
423 if (!(ovp = RtlAllocateHeap(GetProcessHeap(), 0, sizeof(async_fileio))))
425 wine_server_release_fd( hFile, unix_handle );
426 return STATUS_NO_MEMORY;
428 ovp->async.ops = (apc ? &fileio_async_ops : &fileio_nocomp_async_ops );
429 ovp->async.handle = hFile;
430 ovp->async.fd = unix_handle; /* FIXME */
431 ovp->async.type = ASYNC_TYPE_READ;
432 ovp->async.func = FILE_AsyncReadService;
433 ovp->async.event = hEvent;
434 ovp->async.iosb = io_status;
435 ovp->count = length;
436 if ( offset == NULL )
437 ovp->offset = 0;
438 else
440 ovp->offset = offset->u.LowPart;
441 if (offset->u.HighPart) FIXME("NIY-high part\n");
443 ovp->apc = apc;
444 ovp->apc_user = apc_user;
445 ovp->buffer = buffer;
446 ovp->fd_type = type;
448 io_status->Information = 0;
449 ret = register_new_async(&ovp->async);
450 if (ret != STATUS_SUCCESS)
451 return ret;
452 if (flags & FD_FLAG_TIMEOUT)
454 NtWaitForSingleObject(hEvent, TRUE, NULL);
455 NtClose(hEvent);
457 else
459 LARGE_INTEGER timeout;
461 /* let some APC be run, this will read some already pending data */
462 timeout.u.LowPart = timeout.u.HighPart = 0;
463 NtDelayExecution( TRUE, &timeout );
465 return io_status->u.Status;
467 switch (type)
469 case FD_TYPE_SMB:
470 FIXME("NIY-SMB\n");
471 /* FIXME */
472 /* return SMB_ReadFile(hFile, unix_handle, buffer, length, io_status); */
473 wine_server_release_fd( hFile, unix_handle );
474 return STATUS_INVALID_HANDLE;
476 case FD_TYPE_DEFAULT:
477 /* normal unix file */
478 break;
480 default:
481 FIXME("Unsupported type of fd %d\n", type);
482 wine_server_release_fd( hFile, unix_handle );
483 return STATUS_INVALID_HANDLE;
486 if (offset)
488 FILE_POSITION_INFORMATION fpi;
490 fpi.CurrentByteOffset = *offset;
491 io_status->u.Status = NtSetInformationFile(hFile, io_status, &fpi, sizeof(fpi),
492 FilePositionInformation);
493 if (io_status->u.Status)
495 wine_server_release_fd( hFile, unix_handle );
496 return io_status->u.Status;
499 /* code for synchronous reads */
500 while ((io_status->Information = read( unix_handle, buffer, length )) == -1)
502 if ((errno == EAGAIN) || (errno == EINTR)) continue;
503 if (errno == EFAULT) FIXME( "EFAULT handling broken for now\n" );
504 io_status->u.Status = FILE_GetNtStatus();
505 break;
507 wine_server_release_fd( hFile, unix_handle );
508 return io_status->u.Status;
511 /***********************************************************************
512 * FILE_AsyncWriteService (INTERNAL)
514 * This function is called while the client is waiting on the
515 * server, so we can't make any server calls here.
517 static void FILE_AsyncWriteService(struct async_private *ovp)
519 async_fileio *fileio = (async_fileio *) ovp;
520 PIO_STATUS_BLOCK io_status = fileio->async.iosb;
521 int result;
522 int already = io_status->Information;
524 TRACE("(%p %p)\n",io_status,fileio->buffer);
526 /* write some data (non-blocking) */
528 if ( fileio->fd_type == FD_TYPE_SOCKET )
529 result = write(ovp->fd, &fileio->buffer[already], fileio->count - already);
530 else
532 result = pwrite(ovp->fd, &fileio->buffer[already], fileio->count - already,
533 fileio->offset + already);
534 if ((result < 0) && (errno == ESPIPE))
535 result = write(ovp->fd, &fileio->buffer[already], fileio->count - already);
538 if ((result < 0) && ((errno == EAGAIN) || (errno == EINTR)))
540 io_status->u.Status = STATUS_PENDING;
541 return;
544 /* check to see if the transfer is complete */
545 if (result < 0)
547 io_status->u.Status = FILE_GetNtStatus();
548 return;
551 io_status->Information += result;
552 io_status->u.Status = (io_status->Information < fileio->count) ? STATUS_PENDING : STATUS_SUCCESS;
553 TRACE("wrote %d more bytes %ld/%d so far\n",result,io_status->Information,fileio->count);
556 /******************************************************************************
557 * NtWriteFile [NTDLL.@]
558 * ZwWriteFile [NTDLL.@]
560 * Write to an open file handle.
562 * PARAMS
563 * FileHandle [I] Handle returned from ZwOpenFile() or ZwCreateFile()
564 * Event [I] Event to signal upon completion (or NULL)
565 * ApcRoutine [I] Callback to call upon completion (or NULL)
566 * ApcContext [I] Context for ApcRoutine (or NULL)
567 * IoStatusBlock [O] Receives information about the operation on return
568 * Buffer [I] Source for the data to write
569 * Length [I] Size of Buffer
570 * ByteOffset [O] Destination for the new file pointer position (or NULL)
571 * Key [O] Function unknown (may be NULL)
573 * RETURNS
574 * Success: 0. IoStatusBlock is updated, and the Information member contains
575 * The number of bytes written.
576 * Failure: An NTSTATUS error code describing the error.
578 NTSTATUS WINAPI NtWriteFile(HANDLE hFile, HANDLE hEvent,
579 PIO_APC_ROUTINE apc, void* apc_user,
580 PIO_STATUS_BLOCK io_status,
581 const void* buffer, ULONG length,
582 PLARGE_INTEGER offset, PULONG key)
584 int unix_handle, flags;
585 enum fd_type type;
587 TRACE("(%p,%p,%p,%p,%p,%p,0x%08lx,%p,%p)!\n",
588 hFile,hEvent,apc,apc_user,io_status,buffer,length,offset,key);
590 TRACE("(%p,%p,%p,%p,%p,%p,0x%08lx,%p,%p),partial stub!\n",
591 hFile,hEvent,apc,apc_user,io_status,buffer,length,offset,key);
593 io_status->Information = 0;
594 io_status->u.Status = wine_server_handle_to_fd( hFile, GENERIC_WRITE, &unix_handle, &type, &flags );
595 if (io_status->u.Status) return io_status->u.Status;
597 if (flags & FD_FLAG_SEND_SHUTDOWN)
599 wine_server_release_fd( hFile, unix_handle );
600 return STATUS_PIPE_DISCONNECTED;
603 if (flags & (FD_FLAG_OVERLAPPED|FD_FLAG_TIMEOUT))
605 async_fileio* ovp;
606 NTSTATUS ret;
608 if (!(ovp = RtlAllocateHeap(GetProcessHeap(), 0, sizeof(async_fileio))))
610 wine_server_release_fd( hFile, unix_handle );
611 return STATUS_NO_MEMORY;
613 ovp->async.ops = (apc ? &fileio_async_ops : &fileio_nocomp_async_ops );
614 ovp->async.handle = hFile;
615 ovp->async.fd = unix_handle; /* FIXME */
616 ovp->async.type = ASYNC_TYPE_WRITE;
617 ovp->async.func = FILE_AsyncWriteService;
618 ovp->async.event = hEvent;
619 ovp->async.iosb = io_status;
620 ovp->count = length;
621 if (offset) {
622 ovp->offset = offset->u.LowPart;
623 if (offset->u.HighPart) FIXME("NIY-high part\n");
624 } else {
625 ovp->offset = 0;
627 ovp->apc = apc;
628 ovp->apc_user = apc_user;
629 ovp->buffer = (void*)buffer;
630 ovp->fd_type = type;
632 io_status->Information = 0;
633 ret = register_new_async(&ovp->async);
634 if (ret != STATUS_SUCCESS)
635 return ret;
636 if (flags & FD_FLAG_TIMEOUT)
638 NtWaitForSingleObject(hEvent, TRUE, NULL);
639 NtClose(hEvent);
641 else
643 LARGE_INTEGER timeout;
645 /* let some APC be run, this will write as much data as possible */
646 timeout.u.LowPart = timeout.u.HighPart = 0;
647 NtDelayExecution( TRUE, &timeout );
649 return io_status->u.Status;
651 switch (type)
653 case FD_TYPE_SMB:
654 FIXME("NIY-SMB\n");
655 wine_server_release_fd( hFile, unix_handle );
656 return STATUS_NOT_IMPLEMENTED;
658 case FD_TYPE_DEFAULT:
659 /* normal unix files */
660 if (unix_handle == -1) return STATUS_INVALID_HANDLE;
661 break;
663 default:
664 FIXME("Unsupported type of fd %d\n", type);
665 wine_server_release_fd( hFile, unix_handle );
666 return STATUS_INVALID_HANDLE;
669 if (offset)
671 FILE_POSITION_INFORMATION fpi;
673 fpi.CurrentByteOffset = *offset;
674 io_status->u.Status = NtSetInformationFile(hFile, io_status, &fpi, sizeof(fpi),
675 FilePositionInformation);
676 if (io_status->u.Status)
678 wine_server_release_fd( hFile, unix_handle );
679 return io_status->u.Status;
683 /* synchronous file write */
684 while ((io_status->Information = write( unix_handle, buffer, length )) == -1)
686 if ((errno == EAGAIN) || (errno == EINTR)) continue;
687 if (errno == EFAULT) FIXME( "EFAULT handling broken for now\n" );
688 if (errno == ENOSPC) io_status->u.Status = STATUS_DISK_FULL;
689 else io_status->u.Status = FILE_GetNtStatus();
690 break;
692 wine_server_release_fd( hFile, unix_handle );
693 return io_status->u.Status;
696 /**************************************************************************
697 * NtDeviceIoControlFile [NTDLL.@]
698 * ZwDeviceIoControlFile [NTDLL.@]
700 * Perform an I/O control operation on an open file handle.
702 * PARAMS
703 * DeviceHandle [I] Handle returned from ZwOpenFile() or ZwCreateFile()
704 * Event [I] Event to signal upon completion (or NULL)
705 * ApcRoutine [I] Callback to call upon completion (or NULL)
706 * ApcContext [I] Context for ApcRoutine (or NULL)
707 * IoStatusBlock [O] Receives information about the operation on return
708 * IoControlCode [I] Control code for the operation to perform
709 * InputBuffer [I] Source for any input data required (or NULL)
710 * InputBufferSize [I] Size of InputBuffer
711 * OutputBuffer [O] Source for any output data returned (or NULL)
712 * OutputBufferSize [I] Size of OutputBuffer
714 * RETURNS
715 * Success: 0. IoStatusBlock is updated.
716 * Failure: An NTSTATUS error code describing the error.
718 NTSTATUS WINAPI NtDeviceIoControlFile(HANDLE DeviceHandle, HANDLE hEvent,
719 PIO_APC_ROUTINE UserApcRoutine,
720 PVOID UserApcContext,
721 PIO_STATUS_BLOCK IoStatusBlock,
722 ULONG IoControlCode,
723 PVOID InputBuffer,
724 ULONG InputBufferSize,
725 PVOID OutputBuffer,
726 ULONG OutputBufferSize)
728 TRACE("(%p,%p,%p,%p,%p,0x%08lx,%p,0x%08lx,%p,0x%08lx)\n",
729 DeviceHandle, hEvent, UserApcRoutine, UserApcContext,
730 IoStatusBlock, IoControlCode,
731 InputBuffer, InputBufferSize, OutputBuffer, OutputBufferSize);
733 if (CDROM_DeviceIoControl(DeviceHandle, hEvent,
734 UserApcRoutine, UserApcContext,
735 IoStatusBlock, IoControlCode,
736 InputBuffer, InputBufferSize,
737 OutputBuffer, OutputBufferSize) == STATUS_NO_SUCH_DEVICE)
739 /* it wasn't a CDROM */
740 FIXME("Unimplemented dwIoControlCode=%08lx\n", IoControlCode);
741 IoStatusBlock->u.Status = STATUS_NOT_IMPLEMENTED;
742 IoStatusBlock->Information = 0;
743 if (hEvent) NtSetEvent(hEvent, NULL);
745 return IoStatusBlock->u.Status;
748 /******************************************************************************
749 * NtFsControlFile [NTDLL.@]
750 * ZwFsControlFile [NTDLL.@]
752 NTSTATUS WINAPI NtFsControlFile(
753 IN HANDLE DeviceHandle,
754 IN HANDLE Event OPTIONAL,
755 IN PIO_APC_ROUTINE ApcRoutine OPTIONAL,
756 IN PVOID ApcContext OPTIONAL,
757 OUT PIO_STATUS_BLOCK IoStatusBlock,
758 IN ULONG IoControlCode,
759 IN PVOID InputBuffer,
760 IN ULONG InputBufferSize,
761 OUT PVOID OutputBuffer,
762 IN ULONG OutputBufferSize)
764 FIXME("(%p,%p,%p,%p,%p,0x%08lx,%p,0x%08lx,%p,0x%08lx): stub\n",
765 DeviceHandle,Event,ApcRoutine,ApcContext,IoStatusBlock,IoControlCode,
766 InputBuffer,InputBufferSize,OutputBuffer,OutputBufferSize);
767 return 0;
770 /******************************************************************************
771 * NtSetVolumeInformationFile [NTDLL.@]
772 * ZwSetVolumeInformationFile [NTDLL.@]
774 * Set volume information for an open file handle.
776 * PARAMS
777 * FileHandle [I] Handle returned from ZwOpenFile() or ZwCreateFile()
778 * IoStatusBlock [O] Receives information about the operation on return
779 * FsInformation [I] Source for volume information
780 * Length [I] Size of FsInformation
781 * FsInformationClass [I] Type of volume information to set
783 * RETURNS
784 * Success: 0. IoStatusBlock is updated.
785 * Failure: An NTSTATUS error code describing the error.
787 NTSTATUS WINAPI NtSetVolumeInformationFile(
788 IN HANDLE FileHandle,
789 PIO_STATUS_BLOCK IoStatusBlock,
790 PVOID FsInformation,
791 ULONG Length,
792 FS_INFORMATION_CLASS FsInformationClass)
794 FIXME("(%p,%p,%p,0x%08lx,0x%08x) stub\n",
795 FileHandle,IoStatusBlock,FsInformation,Length,FsInformationClass);
796 return 0;
799 /******************************************************************************
800 * NtQueryInformationFile [NTDLL.@]
801 * ZwQueryInformationFile [NTDLL.@]
803 * Get information about an open file handle.
805 * PARAMS
806 * hFile [I] Handle returned from ZwOpenFile() or ZwCreateFile()
807 * io [O] Receives information about the operation on return
808 * ptr [O] Destination for file information
809 * len [I] Size of FileInformation
810 * class [I] Type of file information to get
812 * RETURNS
813 * Success: 0. IoStatusBlock and FileInformation are updated.
814 * Failure: An NTSTATUS error code describing the error.
816 NTSTATUS WINAPI NtQueryInformationFile( HANDLE hFile, PIO_STATUS_BLOCK io,
817 PVOID ptr, LONG len, FILE_INFORMATION_CLASS class )
819 int fd;
821 TRACE("(%p,%p,%p,0x%08lx,0x%08x)\n", hFile, io, ptr, len, class);
823 io->Information = 0;
824 if ((io->u.Status = wine_server_handle_to_fd( hFile, 0, &fd, NULL, NULL )))
825 return io->u.Status;
827 switch (class)
829 case FileBasicInformation:
831 FILE_BASIC_INFORMATION *info = ptr;
833 if (len < sizeof(*info)) io->u.Status = STATUS_INFO_LENGTH_MISMATCH;
834 else
836 struct stat st;
838 if (fstat( fd, &st ) == -1)
839 io->u.Status = FILE_GetNtStatus();
840 else if (!S_ISREG(st.st_mode) && !S_ISDIR(st.st_mode))
841 io->u.Status = STATUS_INVALID_INFO_CLASS;
842 else
844 if (S_ISDIR(st.st_mode)) info->FileAttributes = FILE_ATTRIBUTE_DIRECTORY;
845 else info->FileAttributes = FILE_ATTRIBUTE_ARCHIVE;
846 if (!(st.st_mode & S_IWUSR)) info->FileAttributes |= FILE_ATTRIBUTE_READONLY;
847 RtlSecondsSince1970ToTime( st.st_mtime, &info->CreationTime);
848 RtlSecondsSince1970ToTime( st.st_mtime, &info->LastWriteTime);
849 RtlSecondsSince1970ToTime( st.st_ctime, &info->ChangeTime);
850 RtlSecondsSince1970ToTime( st.st_atime, &info->LastAccessTime);
854 break;
855 case FileStandardInformation:
857 FILE_STANDARD_INFORMATION *info = ptr;
859 if (len < sizeof(*info)) io->u.Status = STATUS_INFO_LENGTH_MISMATCH;
860 else
862 struct stat st;
864 if (fstat( fd, &st ) == -1) io->u.Status = FILE_GetNtStatus();
865 else
867 if ((info->Directory = S_ISDIR(st.st_mode)))
869 info->AllocationSize.QuadPart = 0;
870 info->EndOfFile.QuadPart = 0;
871 info->NumberOfLinks = 1;
872 info->DeletePending = FALSE;
874 else
876 info->AllocationSize.QuadPart = (ULONGLONG)st.st_blocks * 512;
877 info->EndOfFile.QuadPart = st.st_size;
878 info->NumberOfLinks = st.st_nlink;
879 info->DeletePending = FALSE; /* FIXME */
881 io->Information = sizeof(*info);
885 break;
886 case FilePositionInformation:
888 FILE_POSITION_INFORMATION *info = ptr;
890 if (len < sizeof(*info)) io->u.Status = STATUS_INFO_LENGTH_MISMATCH;
891 else
893 off_t res = lseek( fd, 0, SEEK_CUR );
894 if (res == (off_t)-1) io->u.Status = FILE_GetNtStatus();
895 else
897 info->CurrentByteOffset.QuadPart = res;
898 io->Information = sizeof(*info);
902 break;
903 default:
904 FIXME("Unsupported class (%d)\n", class);
905 io->u.Status = STATUS_NOT_IMPLEMENTED;
906 break;
908 wine_server_release_fd( hFile, fd );
909 return io->u.Status;
912 /******************************************************************************
913 * NtSetInformationFile [NTDLL.@]
914 * ZwSetInformationFile [NTDLL.@]
916 * Set information about an open file handle.
918 * PARAMS
919 * handle [I] Handle returned from ZwOpenFile() or ZwCreateFile()
920 * io [O] Receives information about the operation on return
921 * ptr [I] Source for file information
922 * len [I] Size of FileInformation
923 * class [I] Type of file information to set
925 * RETURNS
926 * Success: 0. io is updated.
927 * Failure: An NTSTATUS error code describing the error.
929 NTSTATUS WINAPI NtSetInformationFile(HANDLE handle, PIO_STATUS_BLOCK io,
930 PVOID ptr, ULONG len, FILE_INFORMATION_CLASS class)
932 int fd;
934 TRACE("(%p,%p,%p,0x%08lx,0x%08x)\n", handle, io, ptr, len, class);
936 if ((io->u.Status = wine_server_handle_to_fd( handle, 0, &fd, NULL, NULL )))
937 return io->u.Status;
939 io->u.Status = STATUS_SUCCESS;
940 switch (class)
942 case FileBasicInformation:
943 if (len >= sizeof(FILE_BASIC_INFORMATION))
945 struct stat st;
946 const FILE_BASIC_INFORMATION *info = ptr;
948 #ifdef HAVE_FUTIMES
949 if (info->LastAccessTime.QuadPart || info->LastWriteTime.QuadPart)
951 ULONGLONG sec, nsec;
952 struct timeval tv[2];
954 if (!info->LastAccessTime.QuadPart || !info->LastWriteTime.QuadPart)
957 tv[0].tv_sec = tv[0].tv_usec = 0;
958 tv[1].tv_sec = tv[1].tv_usec = 0;
959 if (!fstat( fd, &st ))
961 tv[0].tv_sec = st.st_atime;
962 tv[1].tv_sec = st.st_mtime;
965 if (info->LastAccessTime.QuadPart)
967 sec = RtlLargeIntegerDivide( info->LastAccessTime.QuadPart, 10000000, &nsec );
968 tv[0].tv_sec = sec - SECS_1601_TO_1970;
969 tv[0].tv_usec = (UINT)nsec / 10;
971 if (info->LastWriteTime.QuadPart)
973 sec = RtlLargeIntegerDivide( info->LastWriteTime.QuadPart, 10000000, &nsec );
974 tv[1].tv_sec = sec - SECS_1601_TO_1970;
975 tv[1].tv_usec = (UINT)nsec / 10;
977 if (futimes( fd, tv ) == -1) io->u.Status = FILE_GetNtStatus();
979 #endif /* HAVE_FUTIMES */
980 if (io->u.Status == STATUS_SUCCESS && info->FileAttributes)
982 if (fstat( fd, &st ) == -1) io->u.Status = FILE_GetNtStatus();
983 else
985 if (info->FileAttributes & FILE_ATTRIBUTE_READONLY)
987 st.st_mode &= ~0222; /* clear write permission bits */
989 else
991 /* add write permission only where we already have read permission */
992 st.st_mode |= (0600 | ((st.st_mode & 044) >> 1)) & (~FILE_umask);
994 if (fchmod( fd, st.st_mode ) == -1) io->u.Status = FILE_GetNtStatus();
998 else io->u.Status = STATUS_INVALID_PARAMETER_3;
999 break;
1001 case FilePositionInformation:
1002 if (len >= sizeof(FILE_POSITION_INFORMATION))
1004 const FILE_POSITION_INFORMATION *info = ptr;
1006 if (lseek( fd, info->CurrentByteOffset.QuadPart, SEEK_SET ) == (off_t)-1)
1007 io->u.Status = FILE_GetNtStatus();
1009 else io->u.Status = STATUS_INVALID_PARAMETER_3;
1010 break;
1012 default:
1013 FIXME("Unsupported class (%d)\n", class);
1014 io->u.Status = STATUS_NOT_IMPLEMENTED;
1015 break;
1017 wine_server_release_fd( handle, fd );
1018 io->Information = 0;
1019 return io->u.Status;
1023 /******************************************************************************
1024 * NtQueryFullAttributesFile (NTDLL.@)
1026 NTSTATUS WINAPI NtQueryFullAttributesFile( const OBJECT_ATTRIBUTES *attr,
1027 FILE_NETWORK_OPEN_INFORMATION *info )
1029 ANSI_STRING unix_name;
1030 NTSTATUS status;
1032 if (!(status = wine_nt_to_unix_file_name( attr->ObjectName, &unix_name, FILE_OPEN,
1033 !(attr->Attributes & OBJ_CASE_INSENSITIVE) )))
1035 struct stat st;
1037 if (stat( unix_name.Buffer, &st ) == -1)
1038 status = FILE_GetNtStatus();
1039 else if (!S_ISREG(st.st_mode) && !S_ISDIR(st.st_mode))
1040 status = STATUS_INVALID_INFO_CLASS;
1041 else
1043 if (S_ISDIR(st.st_mode))
1045 info->FileAttributes = FILE_ATTRIBUTE_DIRECTORY;
1046 info->AllocationSize.QuadPart = 0;
1047 info->EndOfFile.QuadPart = 0;
1049 else
1051 info->FileAttributes = FILE_ATTRIBUTE_ARCHIVE;
1052 info->AllocationSize.QuadPart = (ULONGLONG)st.st_blocks * 512;
1053 info->EndOfFile.QuadPart = st.st_size;
1055 if (!(st.st_mode & S_IWUSR)) info->FileAttributes |= FILE_ATTRIBUTE_READONLY;
1056 RtlSecondsSince1970ToTime( st.st_mtime, &info->CreationTime );
1057 RtlSecondsSince1970ToTime( st.st_mtime, &info->LastWriteTime );
1058 RtlSecondsSince1970ToTime( st.st_ctime, &info->ChangeTime );
1059 RtlSecondsSince1970ToTime( st.st_atime, &info->LastAccessTime );
1060 if (DIR_is_hidden_file( attr->ObjectName ))
1061 info->FileAttributes |= FILE_ATTRIBUTE_HIDDEN;
1063 RtlFreeAnsiString( &unix_name );
1065 else WARN("%s not found (%lx)\n", debugstr_us(attr->ObjectName), status );
1066 return status;
1070 /******************************************************************************
1071 * NtQueryAttributesFile (NTDLL.@)
1072 * ZwQueryAttributesFile (NTDLL.@)
1074 NTSTATUS WINAPI NtQueryAttributesFile( const OBJECT_ATTRIBUTES *attr, FILE_BASIC_INFORMATION *info )
1076 FILE_NETWORK_OPEN_INFORMATION full_info;
1077 NTSTATUS status;
1079 if (!(status = NtQueryFullAttributesFile( attr, &full_info )))
1081 info->CreationTime.QuadPart = full_info.CreationTime.QuadPart;
1082 info->LastAccessTime.QuadPart = full_info.LastAccessTime.QuadPart;
1083 info->LastWriteTime.QuadPart = full_info.LastWriteTime.QuadPart;
1084 info->ChangeTime.QuadPart = full_info.ChangeTime.QuadPart;
1085 info->FileAttributes = full_info.FileAttributes;
1087 return status;
1091 /******************************************************************************
1092 * NtQueryVolumeInformationFile [NTDLL.@]
1093 * ZwQueryVolumeInformationFile [NTDLL.@]
1095 * Get volume information for an open file handle.
1097 * PARAMS
1098 * handle [I] Handle returned from ZwOpenFile() or ZwCreateFile()
1099 * io [O] Receives information about the operation on return
1100 * buffer [O] Destination for volume information
1101 * length [I] Size of FsInformation
1102 * info_class [I] Type of volume information to set
1104 * RETURNS
1105 * Success: 0. io and buffer are updated.
1106 * Failure: An NTSTATUS error code describing the error.
1108 NTSTATUS WINAPI NtQueryVolumeInformationFile( HANDLE handle, PIO_STATUS_BLOCK io,
1109 PVOID buffer, ULONG length,
1110 FS_INFORMATION_CLASS info_class )
1112 int fd;
1113 struct stat st;
1115 if ((io->u.Status = wine_server_handle_to_fd( handle, 0, &fd, NULL, NULL )) != STATUS_SUCCESS)
1116 return io->u.Status;
1118 io->u.Status = STATUS_NOT_IMPLEMENTED;
1119 io->Information = 0;
1121 switch( info_class )
1123 case FileFsVolumeInformation:
1124 FIXME( "%p: volume info not supported\n", handle );
1125 break;
1126 case FileFsLabelInformation:
1127 FIXME( "%p: label info not supported\n", handle );
1128 break;
1129 case FileFsSizeInformation:
1130 if (length < sizeof(FILE_FS_SIZE_INFORMATION))
1131 io->u.Status = STATUS_BUFFER_TOO_SMALL;
1132 else
1134 FILE_FS_SIZE_INFORMATION *info = buffer;
1135 struct statvfs stvfs;
1137 if (fstat( fd, &st ) < 0)
1139 io->u.Status = FILE_GetNtStatus();
1140 break;
1142 if (!S_ISREG(st.st_mode) && !S_ISDIR(st.st_mode))
1144 io->u.Status = STATUS_INVALID_DEVICE_REQUEST;
1145 break;
1147 if (fstatvfs( fd, &stvfs ) < 0) io->u.Status = FILE_GetNtStatus();
1148 else
1150 info->TotalAllocationUnits.QuadPart = stvfs.f_blocks;
1151 info->AvailableAllocationUnits.QuadPart = stvfs.f_bavail;
1152 info->SectorsPerAllocationUnit = 1;
1153 info->BytesPerSector = stvfs.f_frsize;
1154 io->Information = sizeof(*info);
1155 io->u.Status = STATUS_SUCCESS;
1158 break;
1159 case FileFsDeviceInformation:
1160 if (length < sizeof(FILE_FS_DEVICE_INFORMATION))
1161 io->u.Status = STATUS_BUFFER_TOO_SMALL;
1162 else
1164 FILE_FS_DEVICE_INFORMATION *info = buffer;
1166 #if defined(linux) && defined(HAVE_FSTATFS)
1167 struct statfs stfs;
1169 info->Characteristics = 0;
1171 if (fstat( fd, &st ) < 0)
1173 io->u.Status = FILE_GetNtStatus();
1174 break;
1176 if (S_ISCHR( st.st_mode ))
1178 switch(major(st.st_rdev))
1180 case MEM_MAJOR:
1181 info->DeviceType = FILE_DEVICE_NULL;
1182 break;
1183 case TTY_MAJOR:
1184 info->DeviceType = FILE_DEVICE_SERIAL_PORT;
1185 break;
1186 case LP_MAJOR:
1187 info->DeviceType = FILE_DEVICE_PARALLEL_PORT;
1188 break;
1189 default:
1190 info->DeviceType = FILE_DEVICE_UNKNOWN;
1191 break;
1194 else if (S_ISBLK( st.st_mode ))
1196 info->DeviceType = FILE_DEVICE_DISK;
1198 else if (S_ISFIFO( st.st_mode ) || S_ISSOCK( st.st_mode ))
1200 info->DeviceType = FILE_DEVICE_NAMED_PIPE;
1202 else /* regular file or directory */
1204 info->Characteristics |= FILE_DEVICE_IS_MOUNTED;
1206 /* check for floppy disk */
1207 if (major(st.st_dev) == FLOPPY_MAJOR)
1208 info->Characteristics |= FILE_REMOVABLE_MEDIA;
1210 if (fstatfs( fd, &stfs ) < 0) stfs.f_type = 0;
1211 switch (stfs.f_type)
1213 case 0x9660: /* iso9660 */
1214 case 0x15013346: /* udf */
1215 info->DeviceType = FILE_DEVICE_CD_ROM_FILE_SYSTEM;
1216 info->Characteristics |= FILE_REMOVABLE_MEDIA|FILE_READ_ONLY_DEVICE;
1217 break;
1218 case 0x6969: /* nfs */
1219 case 0x517B: /* smbfs */
1220 case 0x564c: /* ncpfs */
1221 info->DeviceType = FILE_DEVICE_NETWORK_FILE_SYSTEM;
1222 info->Characteristics |= FILE_REMOTE_DEVICE;
1223 break;
1224 case 0x01021994: /* tmpfs */
1225 case 0x28cd3d45: /* cramfs */
1226 case 0x1373: /* devfs */
1227 case 0x9fa0: /* procfs */
1228 info->DeviceType = FILE_DEVICE_VIRTUAL_DISK;
1229 break;
1230 default:
1231 info->DeviceType = FILE_DEVICE_DISK_FILE_SYSTEM;
1232 break;
1235 #else
1236 static int warned;
1237 if (!warned++) FIXME( "device info not supported on this platform\n" );
1238 info->DeviceType = FILE_DEVICE_DISK_FILE_SYSTEM;
1239 info->Characteristics = 0;
1240 #endif
1241 io->Information = sizeof(*info);
1242 io->u.Status = STATUS_SUCCESS;
1244 break;
1245 case FileFsAttributeInformation:
1246 FIXME( "%p: attribute info not supported\n", handle );
1247 break;
1248 case FileFsControlInformation:
1249 FIXME( "%p: control info not supported\n", handle );
1250 break;
1251 case FileFsFullSizeInformation:
1252 FIXME( "%p: full size info not supported\n", handle );
1253 break;
1254 case FileFsObjectIdInformation:
1255 FIXME( "%p: object id info not supported\n", handle );
1256 break;
1257 case FileFsMaximumInformation:
1258 FIXME( "%p: maximum info not supported\n", handle );
1259 break;
1260 default:
1261 io->u.Status = STATUS_INVALID_PARAMETER;
1262 break;
1264 wine_server_release_fd( handle, fd );
1265 return io->u.Status;
1269 /******************************************************************
1270 * NtFlushBuffersFile (NTDLL.@)
1272 * Flush any buffered data on an open file handle.
1274 * PARAMS
1275 * FileHandle [I] Handle returned from ZwOpenFile() or ZwCreateFile()
1276 * IoStatusBlock [O] Receives information about the operation on return
1278 * RETURNS
1279 * Success: 0. IoStatusBlock is updated.
1280 * Failure: An NTSTATUS error code describing the error.
1282 NTSTATUS WINAPI NtFlushBuffersFile( HANDLE hFile, IO_STATUS_BLOCK* IoStatusBlock )
1284 NTSTATUS ret;
1285 HANDLE hEvent = NULL;
1287 SERVER_START_REQ( flush_file )
1289 req->handle = hFile;
1290 ret = wine_server_call( req );
1291 hEvent = reply->event;
1293 SERVER_END_REQ;
1294 if (!ret && hEvent)
1296 ret = NtWaitForSingleObject( hEvent, FALSE, NULL );
1297 NtClose( hEvent );
1299 return ret;
1302 /******************************************************************
1303 * NtLockFile (NTDLL.@)
1307 NTSTATUS WINAPI NtLockFile( HANDLE hFile, HANDLE lock_granted_event,
1308 PIO_APC_ROUTINE apc, void* apc_user,
1309 PIO_STATUS_BLOCK io_status, PLARGE_INTEGER offset,
1310 PLARGE_INTEGER count, ULONG* key, BOOLEAN dont_wait,
1311 BOOLEAN exclusive )
1313 NTSTATUS ret;
1314 HANDLE handle;
1315 BOOLEAN async;
1317 if (apc || io_status || key)
1319 FIXME("Unimplemented yet parameter\n");
1320 return STATUS_NOT_IMPLEMENTED;
1323 for (;;)
1325 SERVER_START_REQ( lock_file )
1327 req->handle = hFile;
1328 req->offset_low = offset->u.LowPart;
1329 req->offset_high = offset->u.HighPart;
1330 req->count_low = count->u.LowPart;
1331 req->count_high = count->u.HighPart;
1332 req->shared = !exclusive;
1333 req->wait = !dont_wait;
1334 ret = wine_server_call( req );
1335 handle = reply->handle;
1336 async = reply->overlapped;
1338 SERVER_END_REQ;
1339 if (ret != STATUS_PENDING)
1341 if (!ret && lock_granted_event) NtSetEvent(lock_granted_event, NULL);
1342 return ret;
1345 if (async)
1347 FIXME( "Async I/O lock wait not implemented, might deadlock\n" );
1348 if (handle) NtClose( handle );
1349 return STATUS_PENDING;
1351 if (handle)
1353 NtWaitForSingleObject( handle, FALSE, NULL );
1354 NtClose( handle );
1356 else
1358 LARGE_INTEGER time;
1360 /* Unix lock conflict, sleep a bit and retry */
1361 time.QuadPart = 100 * (ULONGLONG)10000;
1362 time.QuadPart = -time.QuadPart;
1363 NtDelayExecution( FALSE, &time );
1369 /******************************************************************
1370 * NtUnlockFile (NTDLL.@)
1374 NTSTATUS WINAPI NtUnlockFile( HANDLE hFile, PIO_STATUS_BLOCK io_status,
1375 PLARGE_INTEGER offset, PLARGE_INTEGER count,
1376 PULONG key )
1378 NTSTATUS status;
1380 TRACE( "%p %lx%08lx %lx%08lx\n",
1381 hFile, offset->u.HighPart, offset->u.LowPart, count->u.HighPart, count->u.LowPart );
1383 if (io_status || key)
1385 FIXME("Unimplemented yet parameter\n");
1386 return STATUS_NOT_IMPLEMENTED;
1389 SERVER_START_REQ( unlock_file )
1391 req->handle = hFile;
1392 req->offset_low = offset->u.LowPart;
1393 req->offset_high = offset->u.HighPart;
1394 req->count_low = count->u.LowPart;
1395 req->count_high = count->u.HighPart;
1396 status = wine_server_call( req );
1398 SERVER_END_REQ;
1399 return status;