Stub implementation and declaration for NtCreateNamedPipeFile.
[wine.git] / dlls / ntdll / file.c
blob0d4bdec917cf8596f69327a9e0818f6c05027b7f
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 static const WCHAR pipeW[] = {'\\','?','?','\\','p','i','p','e','\\'};
134 ANSI_STRING unix_name;
135 int created = FALSE;
137 TRACE("handle=%p access=%08lx name=%s objattr=%08lx root=%p sec=%p io=%p alloc_size=%p\n"
138 "attr=%08lx sharing=%08lx disp=%ld options=%08lx ea=%p.0x%08lx\n",
139 handle, access, debugstr_us(attr->ObjectName), attr->Attributes,
140 attr->RootDirectory, attr->SecurityDescriptor, io, alloc_size,
141 attributes, sharing, disposition, options, ea_buffer, ea_length );
143 if (attr->RootDirectory)
145 FIXME( "RootDirectory %p not supported\n", attr->RootDirectory );
146 return STATUS_OBJECT_NAME_NOT_FOUND;
148 if (alloc_size) FIXME( "alloc_size not supported\n" );
150 /* check for named pipe */
152 if (attr->ObjectName->Length > sizeof(pipeW) &&
153 !memicmpW( attr->ObjectName->Buffer, pipeW, sizeof(pipeW)/sizeof(WCHAR) ))
155 SERVER_START_REQ( open_named_pipe )
157 req->access = access;
158 req->inherit = (attr->Attributes & OBJ_INHERIT) != 0;
159 wine_server_add_data( req, attr->ObjectName->Buffer + 4,
160 attr->ObjectName->Length - 4*sizeof(WCHAR) );
161 io->u.Status = wine_server_call( req );
162 *handle = reply->handle;
164 SERVER_END_REQ;
165 return io->u.Status;
168 io->u.Status = wine_nt_to_unix_file_name( attr->ObjectName, &unix_name, disposition,
169 !(attr->Attributes & OBJ_CASE_INSENSITIVE) );
171 if (io->u.Status == STATUS_NO_SUCH_FILE &&
172 disposition != FILE_OPEN && disposition != FILE_OVERWRITE)
174 created = TRUE;
175 io->u.Status = STATUS_SUCCESS;
178 if (io->u.Status == STATUS_SUCCESS)
180 SERVER_START_REQ( create_file )
182 req->access = access;
183 req->inherit = (attr->Attributes & OBJ_INHERIT) != 0;
184 req->sharing = sharing;
185 req->create = disposition;
186 req->options = options;
187 req->attrs = attributes;
188 wine_server_add_data( req, unix_name.Buffer, unix_name.Length );
189 io->u.Status = wine_server_call( req );
190 *handle = reply->handle;
192 SERVER_END_REQ;
193 RtlFreeAnsiString( &unix_name );
195 else WARN("%s not found (%lx)\n", debugstr_us(attr->ObjectName), io->u.Status );
197 if (io->u.Status == STATUS_SUCCESS)
199 if (created) io->Information = FILE_CREATED;
200 else switch(disposition)
202 case FILE_SUPERSEDE:
203 io->Information = FILE_SUPERSEDED;
204 break;
205 case FILE_CREATE:
206 io->Information = FILE_CREATED;
207 break;
208 case FILE_OPEN:
209 case FILE_OPEN_IF:
210 io->Information = FILE_OPENED;
211 break;
212 case FILE_OVERWRITE:
213 case FILE_OVERWRITE_IF:
214 io->Information = FILE_OVERWRITTEN;
215 break;
219 return io->u.Status;
222 /***********************************************************************
223 * Asynchronous file I/O *
225 static DWORD fileio_get_async_count(const async_private *ovp);
226 static void CALLBACK fileio_call_completion_func(ULONG_PTR data);
227 static void fileio_async_cleanup(async_private *ovp);
229 static async_ops fileio_async_ops =
231 fileio_get_async_count, /* get_count */
232 fileio_call_completion_func, /* call_completion */
233 fileio_async_cleanup /* cleanup */
236 static async_ops fileio_nocomp_async_ops =
238 fileio_get_async_count, /* get_count */
239 NULL, /* call_completion */
240 fileio_async_cleanup /* cleanup */
243 typedef struct async_fileio
245 struct async_private async;
246 PIO_APC_ROUTINE apc;
247 void* apc_user;
248 char *buffer;
249 unsigned int count;
250 unsigned long offset;
251 enum fd_type fd_type;
252 } async_fileio;
254 static DWORD fileio_get_async_count(const struct async_private *ovp)
256 async_fileio *fileio = (async_fileio*) ovp;
258 if (fileio->count < fileio->async.iosb->Information)
259 return 0;
260 return fileio->count - fileio->async.iosb->Information;
263 static void CALLBACK fileio_call_completion_func(ULONG_PTR data)
265 async_fileio *ovp = (async_fileio*) data;
266 TRACE("data: %p\n", ovp);
268 ovp->apc( ovp->apc_user, ovp->async.iosb, ovp->async.iosb->Information );
270 fileio_async_cleanup( &ovp->async );
273 static void fileio_async_cleanup( struct async_private *ovp )
275 RtlFreeHeap( GetProcessHeap(), 0, ovp );
278 /***********************************************************************
279 * FILE_GetNtStatus(void)
281 * Retrieve the Nt Status code from errno.
282 * Try to be consistent with FILE_SetDosError().
284 NTSTATUS FILE_GetNtStatus(void)
286 int err = errno;
288 TRACE( "errno = %d\n", errno );
289 switch (err)
291 case EAGAIN: return STATUS_SHARING_VIOLATION;
292 case EBADF: return STATUS_INVALID_HANDLE;
293 case ENOSPC: return STATUS_DISK_FULL;
294 case EPERM:
295 case EROFS:
296 case EACCES: return STATUS_ACCESS_DENIED;
297 case ENOTDIR: return STATUS_OBJECT_PATH_NOT_FOUND;
298 case ENOENT: return STATUS_OBJECT_NAME_NOT_FOUND;
299 case EISDIR: return STATUS_FILE_IS_A_DIRECTORY;
300 case EMFILE:
301 case ENFILE: return STATUS_TOO_MANY_OPENED_FILES;
302 case EINVAL: return STATUS_INVALID_PARAMETER;
303 case ENOTEMPTY: return STATUS_DIRECTORY_NOT_EMPTY;
304 case EPIPE: return STATUS_PIPE_BROKEN;
305 case EIO: return STATUS_DEVICE_NOT_READY;
306 #ifdef ENOMEDIUM
307 case ENOMEDIUM: return STATUS_NO_MEDIA_IN_DEVICE;
308 #endif
309 case ENOTTY:
310 case EOPNOTSUPP:return STATUS_NOT_SUPPORTED;
311 case ENOEXEC: /* ?? */
312 case ESPIPE: /* ?? */
313 case EEXIST: /* ?? */
314 default:
315 FIXME( "Converting errno %d to STATUS_UNSUCCESSFUL\n", err );
316 return STATUS_UNSUCCESSFUL;
320 /***********************************************************************
321 * FILE_AsyncReadService (INTERNAL)
323 * This function is called while the client is waiting on the
324 * server, so we can't make any server calls here.
326 static void FILE_AsyncReadService(async_private *ovp)
328 async_fileio *fileio = (async_fileio*) ovp;
329 IO_STATUS_BLOCK* io_status = fileio->async.iosb;
330 int result;
331 int already = io_status->Information;
333 TRACE("%p %p\n", io_status, fileio->buffer );
335 /* check to see if the data is ready (non-blocking) */
337 if ( fileio->fd_type == FD_TYPE_SOCKET )
338 result = read(ovp->fd, &fileio->buffer[already], fileio->count - already);
339 else
341 result = pread(ovp->fd, &fileio->buffer[already], fileio->count - already,
342 fileio->offset + already);
343 if ((result < 0) && (errno == ESPIPE))
344 result = read(ovp->fd, &fileio->buffer[already], fileio->count - already);
347 if ((result < 0) && ((errno == EAGAIN) || (errno == EINTR)))
349 TRACE("Deferred read %d\n",errno);
350 io_status->u.Status = STATUS_PENDING;
351 return;
354 /* check to see if the transfer is complete */
355 if (result < 0)
357 io_status->u.Status = FILE_GetNtStatus();
358 return;
360 else if (result == 0)
362 io_status->u.Status = io_status->Information ? STATUS_SUCCESS : STATUS_END_OF_FILE;
363 return;
366 io_status->Information += result;
367 if (io_status->Information >= fileio->count || fileio->fd_type == FD_TYPE_SOCKET )
368 io_status->u.Status = STATUS_SUCCESS;
369 else
370 io_status->u.Status = STATUS_PENDING;
372 TRACE("read %d more bytes %ld/%d so far\n",
373 result, io_status->Information, fileio->count);
377 /******************************************************************************
378 * NtReadFile [NTDLL.@]
379 * ZwReadFile [NTDLL.@]
381 * Read from an open file handle.
383 * PARAMS
384 * FileHandle [I] Handle returned from ZwOpenFile() or ZwCreateFile()
385 * Event [I] Event to signal upon completion (or NULL)
386 * ApcRoutine [I] Callback to call upon completion (or NULL)
387 * ApcContext [I] Context for ApcRoutine (or NULL)
388 * IoStatusBlock [O] Receives information about the operation on return
389 * Buffer [O] Destination for the data read
390 * Length [I] Size of Buffer
391 * ByteOffset [O] Destination for the new file pointer position (or NULL)
392 * Key [O] Function unknown (may be NULL)
394 * RETURNS
395 * Success: 0. IoStatusBlock is updated, and the Information member contains
396 * The number of bytes read.
397 * Failure: An NTSTATUS error code describing the error.
399 NTSTATUS WINAPI NtReadFile(HANDLE hFile, HANDLE hEvent,
400 PIO_APC_ROUTINE apc, void* apc_user,
401 PIO_STATUS_BLOCK io_status, void* buffer, ULONG length,
402 PLARGE_INTEGER offset, PULONG key)
404 int unix_handle, flags;
405 enum fd_type type;
407 TRACE("(%p,%p,%p,%p,%p,%p,0x%08lx,%p,%p),partial stub!\n",
408 hFile,hEvent,apc,apc_user,io_status,buffer,length,offset,key);
410 io_status->Information = 0;
411 io_status->u.Status = wine_server_handle_to_fd( hFile, GENERIC_READ, &unix_handle, &type, &flags );
412 if (io_status->u.Status) return io_status->u.Status;
414 if (flags & FD_FLAG_RECV_SHUTDOWN)
416 wine_server_release_fd( hFile, unix_handle );
417 return STATUS_PIPE_DISCONNECTED;
420 if (flags & FD_FLAG_TIMEOUT)
422 if (hEvent)
424 /* this shouldn't happen, but check it */
425 FIXME("NIY-hEvent\n");
426 wine_server_release_fd( hFile, unix_handle );
427 return STATUS_NOT_IMPLEMENTED;
429 io_status->u.Status = NtCreateEvent(&hEvent, SYNCHRONIZE, NULL, 0, 0);
430 if (io_status->u.Status)
432 wine_server_release_fd( hFile, unix_handle );
433 return io_status->u.Status;
437 if (flags & (FD_FLAG_OVERLAPPED|FD_FLAG_TIMEOUT))
439 async_fileio* ovp;
440 NTSTATUS ret;
442 if (!(ovp = RtlAllocateHeap(GetProcessHeap(), 0, sizeof(async_fileio))))
444 wine_server_release_fd( hFile, unix_handle );
445 return STATUS_NO_MEMORY;
447 ovp->async.ops = (apc ? &fileio_async_ops : &fileio_nocomp_async_ops );
448 ovp->async.handle = hFile;
449 ovp->async.fd = unix_handle; /* FIXME */
450 ovp->async.type = ASYNC_TYPE_READ;
451 ovp->async.func = FILE_AsyncReadService;
452 ovp->async.event = hEvent;
453 ovp->async.iosb = io_status;
454 ovp->count = length;
455 if ( offset == NULL )
456 ovp->offset = 0;
457 else
459 ovp->offset = offset->u.LowPart;
460 if (offset->u.HighPart) FIXME("NIY-high part\n");
462 ovp->apc = apc;
463 ovp->apc_user = apc_user;
464 ovp->buffer = buffer;
465 ovp->fd_type = type;
467 io_status->Information = 0;
468 ret = register_new_async(&ovp->async);
469 if (ret != STATUS_SUCCESS)
470 return ret;
471 if (flags & FD_FLAG_TIMEOUT)
473 NtWaitForSingleObject(hEvent, TRUE, NULL);
474 NtClose(hEvent);
476 else
478 LARGE_INTEGER timeout;
480 /* let some APC be run, this will read some already pending data */
481 timeout.u.LowPart = timeout.u.HighPart = 0;
482 NtDelayExecution( TRUE, &timeout );
484 return io_status->u.Status;
487 if (offset)
489 FILE_POSITION_INFORMATION fpi;
491 fpi.CurrentByteOffset = *offset;
492 io_status->u.Status = NtSetInformationFile(hFile, io_status, &fpi, sizeof(fpi),
493 FilePositionInformation);
494 if (io_status->u.Status)
496 wine_server_release_fd( hFile, unix_handle );
497 return io_status->u.Status;
500 /* code for synchronous reads */
501 while ((io_status->Information = read( unix_handle, buffer, length )) == -1)
503 if ((errno == EAGAIN) || (errno == EINTR)) continue;
504 if (errno == EFAULT) FIXME( "EFAULT handling broken for now\n" );
505 io_status->u.Status = FILE_GetNtStatus();
506 break;
508 wine_server_release_fd( hFile, unix_handle );
509 return io_status->u.Status;
512 /***********************************************************************
513 * FILE_AsyncWriteService (INTERNAL)
515 * This function is called while the client is waiting on the
516 * server, so we can't make any server calls here.
518 static void FILE_AsyncWriteService(struct async_private *ovp)
520 async_fileio *fileio = (async_fileio *) ovp;
521 PIO_STATUS_BLOCK io_status = fileio->async.iosb;
522 int result;
523 int already = io_status->Information;
525 TRACE("(%p %p)\n",io_status,fileio->buffer);
527 /* write some data (non-blocking) */
529 if ( fileio->fd_type == FD_TYPE_SOCKET )
530 result = write(ovp->fd, &fileio->buffer[already], fileio->count - already);
531 else
533 result = pwrite(ovp->fd, &fileio->buffer[already], fileio->count - already,
534 fileio->offset + already);
535 if ((result < 0) && (errno == ESPIPE))
536 result = write(ovp->fd, &fileio->buffer[already], fileio->count - already);
539 if ((result < 0) && ((errno == EAGAIN) || (errno == EINTR)))
541 io_status->u.Status = STATUS_PENDING;
542 return;
545 /* check to see if the transfer is complete */
546 if (result < 0)
548 io_status->u.Status = FILE_GetNtStatus();
549 return;
552 io_status->Information += result;
553 io_status->u.Status = (io_status->Information < fileio->count) ? STATUS_PENDING : STATUS_SUCCESS;
554 TRACE("wrote %d more bytes %ld/%d so far\n",result,io_status->Information,fileio->count);
557 /******************************************************************************
558 * NtWriteFile [NTDLL.@]
559 * ZwWriteFile [NTDLL.@]
561 * Write to an open file handle.
563 * PARAMS
564 * FileHandle [I] Handle returned from ZwOpenFile() or ZwCreateFile()
565 * Event [I] Event to signal upon completion (or NULL)
566 * ApcRoutine [I] Callback to call upon completion (or NULL)
567 * ApcContext [I] Context for ApcRoutine (or NULL)
568 * IoStatusBlock [O] Receives information about the operation on return
569 * Buffer [I] Source for the data to write
570 * Length [I] Size of Buffer
571 * ByteOffset [O] Destination for the new file pointer position (or NULL)
572 * Key [O] Function unknown (may be NULL)
574 * RETURNS
575 * Success: 0. IoStatusBlock is updated, and the Information member contains
576 * The number of bytes written.
577 * Failure: An NTSTATUS error code describing the error.
579 NTSTATUS WINAPI NtWriteFile(HANDLE hFile, HANDLE hEvent,
580 PIO_APC_ROUTINE apc, void* apc_user,
581 PIO_STATUS_BLOCK io_status,
582 const void* buffer, ULONG length,
583 PLARGE_INTEGER offset, PULONG key)
585 int unix_handle, flags;
586 enum fd_type type;
588 TRACE("(%p,%p,%p,%p,%p,%p,0x%08lx,%p,%p)!\n",
589 hFile,hEvent,apc,apc_user,io_status,buffer,length,offset,key);
591 TRACE("(%p,%p,%p,%p,%p,%p,0x%08lx,%p,%p),partial stub!\n",
592 hFile,hEvent,apc,apc_user,io_status,buffer,length,offset,key);
594 io_status->Information = 0;
595 io_status->u.Status = wine_server_handle_to_fd( hFile, GENERIC_WRITE, &unix_handle, &type, &flags );
596 if (io_status->u.Status) return io_status->u.Status;
598 if (flags & FD_FLAG_SEND_SHUTDOWN)
600 wine_server_release_fd( hFile, unix_handle );
601 return STATUS_PIPE_DISCONNECTED;
604 if (flags & (FD_FLAG_OVERLAPPED|FD_FLAG_TIMEOUT))
606 async_fileio* ovp;
607 NTSTATUS ret;
609 if (!(ovp = RtlAllocateHeap(GetProcessHeap(), 0, sizeof(async_fileio))))
611 wine_server_release_fd( hFile, unix_handle );
612 return STATUS_NO_MEMORY;
614 ovp->async.ops = (apc ? &fileio_async_ops : &fileio_nocomp_async_ops );
615 ovp->async.handle = hFile;
616 ovp->async.fd = unix_handle; /* FIXME */
617 ovp->async.type = ASYNC_TYPE_WRITE;
618 ovp->async.func = FILE_AsyncWriteService;
619 ovp->async.event = hEvent;
620 ovp->async.iosb = io_status;
621 ovp->count = length;
622 if (offset) {
623 ovp->offset = offset->u.LowPart;
624 if (offset->u.HighPart) FIXME("NIY-high part\n");
625 } else {
626 ovp->offset = 0;
628 ovp->apc = apc;
629 ovp->apc_user = apc_user;
630 ovp->buffer = (void*)buffer;
631 ovp->fd_type = type;
633 io_status->Information = 0;
634 ret = register_new_async(&ovp->async);
635 if (ret != STATUS_SUCCESS)
636 return ret;
637 if (flags & FD_FLAG_TIMEOUT)
639 NtWaitForSingleObject(hEvent, TRUE, NULL);
640 NtClose(hEvent);
642 else
644 LARGE_INTEGER timeout;
646 /* let some APC be run, this will write as much data as possible */
647 timeout.u.LowPart = timeout.u.HighPart = 0;
648 NtDelayExecution( TRUE, &timeout );
650 return io_status->u.Status;
653 if (offset)
655 FILE_POSITION_INFORMATION fpi;
657 fpi.CurrentByteOffset = *offset;
658 io_status->u.Status = NtSetInformationFile(hFile, io_status, &fpi, sizeof(fpi),
659 FilePositionInformation);
660 if (io_status->u.Status)
662 wine_server_release_fd( hFile, unix_handle );
663 return io_status->u.Status;
667 /* synchronous file write */
668 while ((io_status->Information = write( unix_handle, buffer, length )) == -1)
670 if ((errno == EAGAIN) || (errno == EINTR)) continue;
671 if (errno == EFAULT) FIXME( "EFAULT handling broken for now\n" );
672 if (errno == ENOSPC) io_status->u.Status = STATUS_DISK_FULL;
673 else io_status->u.Status = FILE_GetNtStatus();
674 break;
676 wine_server_release_fd( hFile, unix_handle );
677 return io_status->u.Status;
680 /**************************************************************************
681 * NtDeviceIoControlFile [NTDLL.@]
682 * ZwDeviceIoControlFile [NTDLL.@]
684 * Perform an I/O control operation on an open file handle.
686 * PARAMS
687 * DeviceHandle [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 * IoControlCode [I] Control code for the operation to perform
693 * InputBuffer [I] Source for any input data required (or NULL)
694 * InputBufferSize [I] Size of InputBuffer
695 * OutputBuffer [O] Source for any output data returned (or NULL)
696 * OutputBufferSize [I] Size of OutputBuffer
698 * RETURNS
699 * Success: 0. IoStatusBlock is updated.
700 * Failure: An NTSTATUS error code describing the error.
702 NTSTATUS WINAPI NtDeviceIoControlFile(HANDLE DeviceHandle, HANDLE hEvent,
703 PIO_APC_ROUTINE UserApcRoutine,
704 PVOID UserApcContext,
705 PIO_STATUS_BLOCK IoStatusBlock,
706 ULONG IoControlCode,
707 PVOID InputBuffer,
708 ULONG InputBufferSize,
709 PVOID OutputBuffer,
710 ULONG OutputBufferSize)
712 TRACE("(%p,%p,%p,%p,%p,0x%08lx,%p,0x%08lx,%p,0x%08lx)\n",
713 DeviceHandle, hEvent, UserApcRoutine, UserApcContext,
714 IoStatusBlock, IoControlCode,
715 InputBuffer, InputBufferSize, OutputBuffer, OutputBufferSize);
717 if (CDROM_DeviceIoControl(DeviceHandle, hEvent,
718 UserApcRoutine, UserApcContext,
719 IoStatusBlock, IoControlCode,
720 InputBuffer, InputBufferSize,
721 OutputBuffer, OutputBufferSize) == STATUS_NO_SUCH_DEVICE)
723 /* it wasn't a CDROM */
724 FIXME("Unimplemented dwIoControlCode=%08lx\n", IoControlCode);
725 IoStatusBlock->u.Status = STATUS_NOT_IMPLEMENTED;
726 IoStatusBlock->Information = 0;
727 if (hEvent) NtSetEvent(hEvent, NULL);
729 return IoStatusBlock->u.Status;
732 /******************************************************************************
733 * NtFsControlFile [NTDLL.@]
734 * ZwFsControlFile [NTDLL.@]
736 NTSTATUS WINAPI NtFsControlFile(
737 IN HANDLE DeviceHandle,
738 IN HANDLE Event OPTIONAL,
739 IN PIO_APC_ROUTINE ApcRoutine OPTIONAL,
740 IN PVOID ApcContext OPTIONAL,
741 OUT PIO_STATUS_BLOCK IoStatusBlock,
742 IN ULONG IoControlCode,
743 IN PVOID InputBuffer,
744 IN ULONG InputBufferSize,
745 OUT PVOID OutputBuffer,
746 IN ULONG OutputBufferSize)
748 FIXME("(%p,%p,%p,%p,%p,0x%08lx,%p,0x%08lx,%p,0x%08lx): stub\n",
749 DeviceHandle,Event,ApcRoutine,ApcContext,IoStatusBlock,IoControlCode,
750 InputBuffer,InputBufferSize,OutputBuffer,OutputBufferSize);
751 return 0;
754 /******************************************************************************
755 * NtSetVolumeInformationFile [NTDLL.@]
756 * ZwSetVolumeInformationFile [NTDLL.@]
758 * Set volume information for an open file handle.
760 * PARAMS
761 * FileHandle [I] Handle returned from ZwOpenFile() or ZwCreateFile()
762 * IoStatusBlock [O] Receives information about the operation on return
763 * FsInformation [I] Source for volume information
764 * Length [I] Size of FsInformation
765 * FsInformationClass [I] Type of volume information to set
767 * RETURNS
768 * Success: 0. IoStatusBlock is updated.
769 * Failure: An NTSTATUS error code describing the error.
771 NTSTATUS WINAPI NtSetVolumeInformationFile(
772 IN HANDLE FileHandle,
773 PIO_STATUS_BLOCK IoStatusBlock,
774 PVOID FsInformation,
775 ULONG Length,
776 FS_INFORMATION_CLASS FsInformationClass)
778 FIXME("(%p,%p,%p,0x%08lx,0x%08x) stub\n",
779 FileHandle,IoStatusBlock,FsInformation,Length,FsInformationClass);
780 return 0;
783 /******************************************************************************
784 * NtQueryInformationFile [NTDLL.@]
785 * ZwQueryInformationFile [NTDLL.@]
787 * Get information about an open file handle.
789 * PARAMS
790 * hFile [I] Handle returned from ZwOpenFile() or ZwCreateFile()
791 * io [O] Receives information about the operation on return
792 * ptr [O] Destination for file information
793 * len [I] Size of FileInformation
794 * class [I] Type of file information to get
796 * RETURNS
797 * Success: 0. IoStatusBlock and FileInformation are updated.
798 * Failure: An NTSTATUS error code describing the error.
800 NTSTATUS WINAPI NtQueryInformationFile( HANDLE hFile, PIO_STATUS_BLOCK io,
801 PVOID ptr, LONG len, FILE_INFORMATION_CLASS class )
803 static const size_t info_sizes[] =
806 sizeof(FILE_DIRECTORY_INFORMATION), /* FileDirectoryInformation */
807 sizeof(FILE_FULL_DIRECTORY_INFORMATION), /* FileFullDirectoryInformation */
808 sizeof(FILE_BOTH_DIRECTORY_INFORMATION), /* FileBothDirectoryInformation */
809 sizeof(FILE_BASIC_INFORMATION), /* FileBasicInformation */
810 sizeof(FILE_STANDARD_INFORMATION), /* FileStandardInformation */
811 sizeof(FILE_INTERNAL_INFORMATION), /* FileInternalInformation */
812 sizeof(FILE_EA_INFORMATION), /* FileEaInformation */
813 sizeof(FILE_ACCESS_INFORMATION), /* FileAccessInformation */
814 sizeof(FILE_NAME_INFORMATION)-sizeof(WCHAR), /* FileNameInformation */
815 sizeof(FILE_RENAME_INFORMATION)-sizeof(WCHAR), /* FileRenameInformation */
816 0, /* FileLinkInformation */
817 sizeof(FILE_NAMES_INFORMATION)-sizeof(WCHAR), /* FileNamesInformation */
818 sizeof(FILE_DISPOSITION_INFORMATION), /* FileDispositionInformation */
819 sizeof(FILE_POSITION_INFORMATION), /* FilePositionInformation */
820 sizeof(FILE_FULL_EA_INFORMATION), /* FileFullEaInformation */
821 sizeof(FILE_MODE_INFORMATION), /* FileModeInformation */
822 sizeof(FILE_ALIGNMENT_INFORMATION), /* FileAlignmentInformation */
823 sizeof(FILE_ALL_INFORMATION)-sizeof(WCHAR), /* FileAllInformation */
824 sizeof(FILE_ALLOCATION_INFORMATION), /* FileAllocationInformation */
825 sizeof(FILE_END_OF_FILE_INFORMATION), /* FileEndOfFileInformation */
826 0, /* FileAlternateNameInformation */
827 sizeof(FILE_STREAM_INFORMATION)-sizeof(WCHAR), /* FileStreamInformation */
828 0, /* FilePipeInformation */
829 0, /* FilePipeLocalInformation */
830 0, /* FilePipeRemoteInformation */
831 0, /* FileMailslotQueryInformation */
832 0, /* FileMailslotSetInformation */
833 0, /* FileCompressionInformation */
834 0, /* FileObjectIdInformation */
835 0, /* FileCompletionInformation */
836 0, /* FileMoveClusterInformation */
837 0, /* FileQuotaInformation */
838 0, /* FileReparsePointInformation */
839 0, /* FileNetworkOpenInformation */
840 0, /* FileAttributeTagInformation */
841 0 /* FileTrackingInformation */
844 struct stat st;
845 int fd;
847 TRACE("(%p,%p,%p,0x%08lx,0x%08x)\n", hFile, io, ptr, len, class);
849 io->Information = 0;
851 if (class <= 0 || class >= FileMaximumInformation)
852 return io->u.Status = STATUS_INVALID_INFO_CLASS;
853 if (!info_sizes[class])
855 FIXME("Unsupported class (%d)\n", class);
856 return io->u.Status = STATUS_NOT_IMPLEMENTED;
858 if (len < info_sizes[class])
859 return io->u.Status = STATUS_INFO_LENGTH_MISMATCH;
861 if ((io->u.Status = wine_server_handle_to_fd( hFile, 0, &fd, NULL, NULL )))
862 return io->u.Status;
864 switch (class)
866 case FileBasicInformation:
868 FILE_BASIC_INFORMATION *info = ptr;
870 if (fstat( fd, &st ) == -1)
871 io->u.Status = FILE_GetNtStatus();
872 else if (!S_ISREG(st.st_mode) && !S_ISDIR(st.st_mode))
873 io->u.Status = STATUS_INVALID_INFO_CLASS;
874 else
876 if (S_ISDIR(st.st_mode)) info->FileAttributes = FILE_ATTRIBUTE_DIRECTORY;
877 else info->FileAttributes = FILE_ATTRIBUTE_ARCHIVE;
878 if (!(st.st_mode & S_IWUSR)) info->FileAttributes |= FILE_ATTRIBUTE_READONLY;
879 RtlSecondsSince1970ToTime( st.st_mtime, &info->CreationTime);
880 RtlSecondsSince1970ToTime( st.st_mtime, &info->LastWriteTime);
881 RtlSecondsSince1970ToTime( st.st_ctime, &info->ChangeTime);
882 RtlSecondsSince1970ToTime( st.st_atime, &info->LastAccessTime);
885 break;
886 case FileStandardInformation:
888 FILE_STANDARD_INFORMATION *info = ptr;
890 if (fstat( fd, &st ) == -1) io->u.Status = FILE_GetNtStatus();
891 else
893 if ((info->Directory = S_ISDIR(st.st_mode)))
895 info->AllocationSize.QuadPart = 0;
896 info->EndOfFile.QuadPart = 0;
897 info->NumberOfLinks = 1;
898 info->DeletePending = FALSE;
900 else
902 info->AllocationSize.QuadPart = (ULONGLONG)st.st_blocks * 512;
903 info->EndOfFile.QuadPart = st.st_size;
904 info->NumberOfLinks = st.st_nlink;
905 info->DeletePending = FALSE; /* FIXME */
909 break;
910 case FilePositionInformation:
912 FILE_POSITION_INFORMATION *info = ptr;
913 off_t res = lseek( fd, 0, SEEK_CUR );
914 if (res == (off_t)-1) io->u.Status = FILE_GetNtStatus();
915 else info->CurrentByteOffset.QuadPart = res;
917 break;
918 case FileInternalInformation:
920 FILE_INTERNAL_INFORMATION *info = ptr;
922 if (fstat( fd, &st ) == -1) io->u.Status = FILE_GetNtStatus();
923 else info->IndexNumber.QuadPart = st.st_ino;
925 break;
926 case FileEaInformation:
928 FILE_EA_INFORMATION *info = ptr;
929 info->EaSize = 0;
931 break;
932 case FileEndOfFileInformation:
934 FILE_END_OF_FILE_INFORMATION *info = ptr;
936 if (fstat( fd, &st ) == -1) io->u.Status = FILE_GetNtStatus();
937 else info->EndOfFile.QuadPart = S_ISDIR(st.st_mode) ? 0 : st.st_size;
939 break;
940 case FileAllInformation:
942 FILE_ALL_INFORMATION *info = ptr;
944 if (fstat( fd, &st ) == -1) io->u.Status = FILE_GetNtStatus();
945 else if (!S_ISREG(st.st_mode) && !S_ISDIR(st.st_mode))
946 io->u.Status = STATUS_INVALID_INFO_CLASS;
947 else
949 if ((info->StandardInformation.Directory = S_ISDIR(st.st_mode)))
951 info->BasicInformation.FileAttributes = FILE_ATTRIBUTE_DIRECTORY;
952 info->StandardInformation.AllocationSize.QuadPart = 0;
953 info->StandardInformation.EndOfFile.QuadPart = 0;
954 info->StandardInformation.NumberOfLinks = 1;
955 info->StandardInformation.DeletePending = FALSE;
957 else
959 info->BasicInformation.FileAttributes = FILE_ATTRIBUTE_ARCHIVE;
960 info->StandardInformation.AllocationSize.QuadPart = (ULONGLONG)st.st_blocks * 512;
961 info->StandardInformation.EndOfFile.QuadPart = st.st_size;
962 info->StandardInformation.NumberOfLinks = st.st_nlink;
963 info->StandardInformation.DeletePending = FALSE; /* FIXME */
965 if (!(st.st_mode & S_IWUSR))
966 info->BasicInformation.FileAttributes |= FILE_ATTRIBUTE_READONLY;
967 RtlSecondsSince1970ToTime( st.st_mtime, &info->BasicInformation.CreationTime);
968 RtlSecondsSince1970ToTime( st.st_mtime, &info->BasicInformation.LastWriteTime);
969 RtlSecondsSince1970ToTime( st.st_ctime, &info->BasicInformation.ChangeTime);
970 RtlSecondsSince1970ToTime( st.st_atime, &info->BasicInformation.LastAccessTime);
971 info->InternalInformation.IndexNumber.QuadPart = st.st_ino;
972 info->EaInformation.EaSize = 0;
973 info->AccessInformation.AccessFlags = 0; /* FIXME */
974 info->PositionInformation.CurrentByteOffset.QuadPart = lseek( fd, 0, SEEK_CUR );
975 info->ModeInformation.Mode = 0; /* FIXME */
976 info->AlignmentInformation.AlignmentRequirement = 1; /* FIXME */
977 info->NameInformation.FileNameLength = 0;
978 io->Information = sizeof(*info) - sizeof(WCHAR);
981 break;
982 default:
983 FIXME("Unsupported class (%d)\n", class);
984 io->u.Status = STATUS_NOT_IMPLEMENTED;
985 break;
987 wine_server_release_fd( hFile, fd );
988 if (io->u.Status == STATUS_SUCCESS && !io->Information) io->Information = info_sizes[class];
989 return io->u.Status;
992 /******************************************************************************
993 * NtSetInformationFile [NTDLL.@]
994 * ZwSetInformationFile [NTDLL.@]
996 * Set information about an open file handle.
998 * PARAMS
999 * handle [I] Handle returned from ZwOpenFile() or ZwCreateFile()
1000 * io [O] Receives information about the operation on return
1001 * ptr [I] Source for file information
1002 * len [I] Size of FileInformation
1003 * class [I] Type of file information to set
1005 * RETURNS
1006 * Success: 0. io is updated.
1007 * Failure: An NTSTATUS error code describing the error.
1009 NTSTATUS WINAPI NtSetInformationFile(HANDLE handle, PIO_STATUS_BLOCK io,
1010 PVOID ptr, ULONG len, FILE_INFORMATION_CLASS class)
1012 int fd;
1014 TRACE("(%p,%p,%p,0x%08lx,0x%08x)\n", handle, io, ptr, len, class);
1016 if ((io->u.Status = wine_server_handle_to_fd( handle, 0, &fd, NULL, NULL )))
1017 return io->u.Status;
1019 io->u.Status = STATUS_SUCCESS;
1020 switch (class)
1022 case FileBasicInformation:
1023 if (len >= sizeof(FILE_BASIC_INFORMATION))
1025 struct stat st;
1026 const FILE_BASIC_INFORMATION *info = ptr;
1028 #ifdef HAVE_FUTIMES
1029 if (info->LastAccessTime.QuadPart || info->LastWriteTime.QuadPart)
1031 ULONGLONG sec, nsec;
1032 struct timeval tv[2];
1034 if (!info->LastAccessTime.QuadPart || !info->LastWriteTime.QuadPart)
1037 tv[0].tv_sec = tv[0].tv_usec = 0;
1038 tv[1].tv_sec = tv[1].tv_usec = 0;
1039 if (!fstat( fd, &st ))
1041 tv[0].tv_sec = st.st_atime;
1042 tv[1].tv_sec = st.st_mtime;
1045 if (info->LastAccessTime.QuadPart)
1047 sec = RtlLargeIntegerDivide( info->LastAccessTime.QuadPart, 10000000, &nsec );
1048 tv[0].tv_sec = sec - SECS_1601_TO_1970;
1049 tv[0].tv_usec = (UINT)nsec / 10;
1051 if (info->LastWriteTime.QuadPart)
1053 sec = RtlLargeIntegerDivide( info->LastWriteTime.QuadPart, 10000000, &nsec );
1054 tv[1].tv_sec = sec - SECS_1601_TO_1970;
1055 tv[1].tv_usec = (UINT)nsec / 10;
1057 if (futimes( fd, tv ) == -1) io->u.Status = FILE_GetNtStatus();
1059 #endif /* HAVE_FUTIMES */
1060 if (io->u.Status == STATUS_SUCCESS && info->FileAttributes)
1062 if (fstat( fd, &st ) == -1) io->u.Status = FILE_GetNtStatus();
1063 else
1065 if (info->FileAttributes & FILE_ATTRIBUTE_READONLY)
1067 st.st_mode &= ~0222; /* clear write permission bits */
1069 else
1071 /* add write permission only where we already have read permission */
1072 st.st_mode |= (0600 | ((st.st_mode & 044) >> 1)) & (~FILE_umask);
1074 if (fchmod( fd, st.st_mode ) == -1) io->u.Status = FILE_GetNtStatus();
1078 else io->u.Status = STATUS_INVALID_PARAMETER_3;
1079 break;
1081 case FilePositionInformation:
1082 if (len >= sizeof(FILE_POSITION_INFORMATION))
1084 const FILE_POSITION_INFORMATION *info = ptr;
1086 if (lseek( fd, info->CurrentByteOffset.QuadPart, SEEK_SET ) == (off_t)-1)
1087 io->u.Status = FILE_GetNtStatus();
1089 else io->u.Status = STATUS_INVALID_PARAMETER_3;
1090 break;
1092 case FileEndOfFileInformation:
1093 if (len >= sizeof(FILE_END_OF_FILE_INFORMATION))
1095 struct stat st;
1096 const FILE_END_OF_FILE_INFORMATION *info = ptr;
1098 /* first try normal truncate */
1099 if (ftruncate( fd, (off_t)info->EndOfFile.QuadPart ) != -1) break;
1101 /* now check for the need to extend the file */
1102 if (fstat( fd, &st ) != -1 && (off_t)info->EndOfFile.QuadPart > st.st_size)
1104 static const char zero;
1106 /* extend the file one byte beyond the requested size and then truncate it */
1107 /* this should work around ftruncate implementations that can't extend files */
1108 if (pwrite( fd, &zero, 1, (off_t)info->EndOfFile.QuadPart ) != -1 &&
1109 ftruncate( fd, (off_t)info->EndOfFile.QuadPart ) != -1) break;
1111 io->u.Status = FILE_GetNtStatus();
1113 else io->u.Status = STATUS_INVALID_PARAMETER_3;
1114 break;
1116 default:
1117 FIXME("Unsupported class (%d)\n", class);
1118 io->u.Status = STATUS_NOT_IMPLEMENTED;
1119 break;
1121 wine_server_release_fd( handle, fd );
1122 io->Information = 0;
1123 return io->u.Status;
1127 /******************************************************************************
1128 * NtQueryFullAttributesFile (NTDLL.@)
1130 NTSTATUS WINAPI NtQueryFullAttributesFile( const OBJECT_ATTRIBUTES *attr,
1131 FILE_NETWORK_OPEN_INFORMATION *info )
1133 ANSI_STRING unix_name;
1134 NTSTATUS status;
1136 if (!(status = wine_nt_to_unix_file_name( attr->ObjectName, &unix_name, FILE_OPEN,
1137 !(attr->Attributes & OBJ_CASE_INSENSITIVE) )))
1139 struct stat st;
1141 if (stat( unix_name.Buffer, &st ) == -1)
1142 status = FILE_GetNtStatus();
1143 else if (!S_ISREG(st.st_mode) && !S_ISDIR(st.st_mode))
1144 status = STATUS_INVALID_INFO_CLASS;
1145 else
1147 if (S_ISDIR(st.st_mode))
1149 info->FileAttributes = FILE_ATTRIBUTE_DIRECTORY;
1150 info->AllocationSize.QuadPart = 0;
1151 info->EndOfFile.QuadPart = 0;
1153 else
1155 info->FileAttributes = FILE_ATTRIBUTE_ARCHIVE;
1156 info->AllocationSize.QuadPart = (ULONGLONG)st.st_blocks * 512;
1157 info->EndOfFile.QuadPart = st.st_size;
1159 if (!(st.st_mode & S_IWUSR)) info->FileAttributes |= FILE_ATTRIBUTE_READONLY;
1160 RtlSecondsSince1970ToTime( st.st_mtime, &info->CreationTime );
1161 RtlSecondsSince1970ToTime( st.st_mtime, &info->LastWriteTime );
1162 RtlSecondsSince1970ToTime( st.st_ctime, &info->ChangeTime );
1163 RtlSecondsSince1970ToTime( st.st_atime, &info->LastAccessTime );
1164 if (DIR_is_hidden_file( attr->ObjectName ))
1165 info->FileAttributes |= FILE_ATTRIBUTE_HIDDEN;
1167 RtlFreeAnsiString( &unix_name );
1169 else WARN("%s not found (%lx)\n", debugstr_us(attr->ObjectName), status );
1170 return status;
1174 /******************************************************************************
1175 * NtQueryAttributesFile (NTDLL.@)
1176 * ZwQueryAttributesFile (NTDLL.@)
1178 NTSTATUS WINAPI NtQueryAttributesFile( const OBJECT_ATTRIBUTES *attr, FILE_BASIC_INFORMATION *info )
1180 FILE_NETWORK_OPEN_INFORMATION full_info;
1181 NTSTATUS status;
1183 if (!(status = NtQueryFullAttributesFile( attr, &full_info )))
1185 info->CreationTime.QuadPart = full_info.CreationTime.QuadPart;
1186 info->LastAccessTime.QuadPart = full_info.LastAccessTime.QuadPart;
1187 info->LastWriteTime.QuadPart = full_info.LastWriteTime.QuadPart;
1188 info->ChangeTime.QuadPart = full_info.ChangeTime.QuadPart;
1189 info->FileAttributes = full_info.FileAttributes;
1191 return status;
1195 /******************************************************************************
1196 * NtQueryVolumeInformationFile [NTDLL.@]
1197 * ZwQueryVolumeInformationFile [NTDLL.@]
1199 * Get volume information for an open file handle.
1201 * PARAMS
1202 * handle [I] Handle returned from ZwOpenFile() or ZwCreateFile()
1203 * io [O] Receives information about the operation on return
1204 * buffer [O] Destination for volume information
1205 * length [I] Size of FsInformation
1206 * info_class [I] Type of volume information to set
1208 * RETURNS
1209 * Success: 0. io and buffer are updated.
1210 * Failure: An NTSTATUS error code describing the error.
1212 NTSTATUS WINAPI NtQueryVolumeInformationFile( HANDLE handle, PIO_STATUS_BLOCK io,
1213 PVOID buffer, ULONG length,
1214 FS_INFORMATION_CLASS info_class )
1216 int fd;
1217 struct stat st;
1219 if ((io->u.Status = wine_server_handle_to_fd( handle, 0, &fd, NULL, NULL )) != STATUS_SUCCESS)
1220 return io->u.Status;
1222 io->u.Status = STATUS_NOT_IMPLEMENTED;
1223 io->Information = 0;
1225 switch( info_class )
1227 case FileFsVolumeInformation:
1228 FIXME( "%p: volume info not supported\n", handle );
1229 break;
1230 case FileFsLabelInformation:
1231 FIXME( "%p: label info not supported\n", handle );
1232 break;
1233 case FileFsSizeInformation:
1234 if (length < sizeof(FILE_FS_SIZE_INFORMATION))
1235 io->u.Status = STATUS_BUFFER_TOO_SMALL;
1236 else
1238 FILE_FS_SIZE_INFORMATION *info = buffer;
1239 struct statvfs stvfs;
1241 if (fstat( fd, &st ) < 0)
1243 io->u.Status = FILE_GetNtStatus();
1244 break;
1246 if (!S_ISREG(st.st_mode) && !S_ISDIR(st.st_mode))
1248 io->u.Status = STATUS_INVALID_DEVICE_REQUEST;
1249 break;
1251 if (fstatvfs( fd, &stvfs ) < 0) io->u.Status = FILE_GetNtStatus();
1252 else
1254 info->TotalAllocationUnits.QuadPart = stvfs.f_blocks;
1255 info->AvailableAllocationUnits.QuadPart = stvfs.f_bavail;
1256 info->SectorsPerAllocationUnit = 1;
1257 info->BytesPerSector = stvfs.f_frsize;
1258 io->Information = sizeof(*info);
1259 io->u.Status = STATUS_SUCCESS;
1262 break;
1263 case FileFsDeviceInformation:
1264 if (length < sizeof(FILE_FS_DEVICE_INFORMATION))
1265 io->u.Status = STATUS_BUFFER_TOO_SMALL;
1266 else
1268 FILE_FS_DEVICE_INFORMATION *info = buffer;
1270 info->Characteristics = 0;
1271 if (fstat( fd, &st ) < 0)
1273 io->u.Status = FILE_GetNtStatus();
1274 break;
1276 if (S_ISCHR( st.st_mode ))
1278 info->DeviceType = FILE_DEVICE_UNKNOWN;
1279 #ifdef linux
1280 switch(major(st.st_rdev))
1282 case MEM_MAJOR:
1283 info->DeviceType = FILE_DEVICE_NULL;
1284 break;
1285 case TTY_MAJOR:
1286 info->DeviceType = FILE_DEVICE_SERIAL_PORT;
1287 break;
1288 case LP_MAJOR:
1289 info->DeviceType = FILE_DEVICE_PARALLEL_PORT;
1290 break;
1292 #endif
1294 else if (S_ISBLK( st.st_mode ))
1296 info->DeviceType = FILE_DEVICE_DISK;
1298 else if (S_ISFIFO( st.st_mode ) || S_ISSOCK( st.st_mode ))
1300 info->DeviceType = FILE_DEVICE_NAMED_PIPE;
1302 else /* regular file or directory */
1304 #if defined(linux) && defined(HAVE_FSTATFS)
1305 struct statfs stfs;
1307 /* check for floppy disk */
1308 if (major(st.st_dev) == FLOPPY_MAJOR)
1309 info->Characteristics |= FILE_REMOVABLE_MEDIA;
1311 if (fstatfs( fd, &stfs ) < 0) stfs.f_type = 0;
1312 switch (stfs.f_type)
1314 case 0x9660: /* iso9660 */
1315 case 0x15013346: /* udf */
1316 info->DeviceType = FILE_DEVICE_CD_ROM_FILE_SYSTEM;
1317 info->Characteristics |= FILE_REMOVABLE_MEDIA|FILE_READ_ONLY_DEVICE;
1318 break;
1319 case 0x6969: /* nfs */
1320 case 0x517B: /* smbfs */
1321 case 0x564c: /* ncpfs */
1322 info->DeviceType = FILE_DEVICE_NETWORK_FILE_SYSTEM;
1323 info->Characteristics |= FILE_REMOTE_DEVICE;
1324 break;
1325 case 0x01021994: /* tmpfs */
1326 case 0x28cd3d45: /* cramfs */
1327 case 0x1373: /* devfs */
1328 case 0x9fa0: /* procfs */
1329 info->DeviceType = FILE_DEVICE_VIRTUAL_DISK;
1330 break;
1331 default:
1332 info->DeviceType = FILE_DEVICE_DISK_FILE_SYSTEM;
1333 break;
1335 #else
1336 static int warned;
1337 if (!warned++) FIXME( "device info not properly supported on this platform\n" );
1338 info->DeviceType = FILE_DEVICE_DISK_FILE_SYSTEM;
1339 #endif
1340 info->Characteristics |= FILE_DEVICE_IS_MOUNTED;
1342 io->Information = sizeof(*info);
1343 io->u.Status = STATUS_SUCCESS;
1345 break;
1346 case FileFsAttributeInformation:
1347 FIXME( "%p: attribute info not supported\n", handle );
1348 break;
1349 case FileFsControlInformation:
1350 FIXME( "%p: control info not supported\n", handle );
1351 break;
1352 case FileFsFullSizeInformation:
1353 FIXME( "%p: full size info not supported\n", handle );
1354 break;
1355 case FileFsObjectIdInformation:
1356 FIXME( "%p: object id info not supported\n", handle );
1357 break;
1358 case FileFsMaximumInformation:
1359 FIXME( "%p: maximum info not supported\n", handle );
1360 break;
1361 default:
1362 io->u.Status = STATUS_INVALID_PARAMETER;
1363 break;
1365 wine_server_release_fd( handle, fd );
1366 return io->u.Status;
1370 /******************************************************************
1371 * NtFlushBuffersFile (NTDLL.@)
1373 * Flush any buffered data on an open file handle.
1375 * PARAMS
1376 * FileHandle [I] Handle returned from ZwOpenFile() or ZwCreateFile()
1377 * IoStatusBlock [O] Receives information about the operation on return
1379 * RETURNS
1380 * Success: 0. IoStatusBlock is updated.
1381 * Failure: An NTSTATUS error code describing the error.
1383 NTSTATUS WINAPI NtFlushBuffersFile( HANDLE hFile, IO_STATUS_BLOCK* IoStatusBlock )
1385 NTSTATUS ret;
1386 HANDLE hEvent = NULL;
1388 SERVER_START_REQ( flush_file )
1390 req->handle = hFile;
1391 ret = wine_server_call( req );
1392 hEvent = reply->event;
1394 SERVER_END_REQ;
1395 if (!ret && hEvent)
1397 ret = NtWaitForSingleObject( hEvent, FALSE, NULL );
1398 NtClose( hEvent );
1400 return ret;
1403 /******************************************************************
1404 * NtLockFile (NTDLL.@)
1408 NTSTATUS WINAPI NtLockFile( HANDLE hFile, HANDLE lock_granted_event,
1409 PIO_APC_ROUTINE apc, void* apc_user,
1410 PIO_STATUS_BLOCK io_status, PLARGE_INTEGER offset,
1411 PLARGE_INTEGER count, ULONG* key, BOOLEAN dont_wait,
1412 BOOLEAN exclusive )
1414 NTSTATUS ret;
1415 HANDLE handle;
1416 BOOLEAN async;
1418 if (apc || io_status || key)
1420 FIXME("Unimplemented yet parameter\n");
1421 return STATUS_NOT_IMPLEMENTED;
1424 for (;;)
1426 SERVER_START_REQ( lock_file )
1428 req->handle = hFile;
1429 req->offset_low = offset->u.LowPart;
1430 req->offset_high = offset->u.HighPart;
1431 req->count_low = count->u.LowPart;
1432 req->count_high = count->u.HighPart;
1433 req->shared = !exclusive;
1434 req->wait = !dont_wait;
1435 ret = wine_server_call( req );
1436 handle = reply->handle;
1437 async = reply->overlapped;
1439 SERVER_END_REQ;
1440 if (ret != STATUS_PENDING)
1442 if (!ret && lock_granted_event) NtSetEvent(lock_granted_event, NULL);
1443 return ret;
1446 if (async)
1448 FIXME( "Async I/O lock wait not implemented, might deadlock\n" );
1449 if (handle) NtClose( handle );
1450 return STATUS_PENDING;
1452 if (handle)
1454 NtWaitForSingleObject( handle, FALSE, NULL );
1455 NtClose( handle );
1457 else
1459 LARGE_INTEGER time;
1461 /* Unix lock conflict, sleep a bit and retry */
1462 time.QuadPart = 100 * (ULONGLONG)10000;
1463 time.QuadPart = -time.QuadPart;
1464 NtDelayExecution( FALSE, &time );
1470 /******************************************************************
1471 * NtUnlockFile (NTDLL.@)
1475 NTSTATUS WINAPI NtUnlockFile( HANDLE hFile, PIO_STATUS_BLOCK io_status,
1476 PLARGE_INTEGER offset, PLARGE_INTEGER count,
1477 PULONG key )
1479 NTSTATUS status;
1481 TRACE( "%p %lx%08lx %lx%08lx\n",
1482 hFile, offset->u.HighPart, offset->u.LowPart, count->u.HighPart, count->u.LowPart );
1484 if (io_status || key)
1486 FIXME("Unimplemented yet parameter\n");
1487 return STATUS_NOT_IMPLEMENTED;
1490 SERVER_START_REQ( unlock_file )
1492 req->handle = hFile;
1493 req->offset_low = offset->u.LowPart;
1494 req->offset_high = offset->u.HighPart;
1495 req->count_low = count->u.LowPart;
1496 req->count_high = count->u.HighPart;
1497 status = wine_server_call( req );
1499 SERVER_END_REQ;
1500 return status;
1503 /******************************************************************
1504 * NtCreateNamedPipeFile (NTDLL.@)
1508 NTSTATUS WINAPI NtCreateNamedPipeFile( PHANDLE FileHandle, ULONG DesiredAccess,
1509 POBJECT_ATTRIBUTES ObjectAttributes, PIO_STATUS_BLOCK IoStatusBlock,
1510 ULONG ShareAccess, ULONG CreateDisposition, ULONG CreateOptions,
1511 ULONG NamedPipeType, ULONG ReadMode, ULONG CompletionMode,
1512 ULONG MaximumInstances, ULONG InboundQuota, ULONG OutboundQuota,
1513 PLARGE_INTEGER DefaultTimeout)
1515 FIXME("(%p %lx %p %p %lx %ld %lx %ld %ld %ld %ld %ld %ld %p): stub\n",
1516 FileHandle, DesiredAccess, ObjectAttributes, IoStatusBlock,
1517 ShareAccess, CreateDisposition, CreateOptions, NamedPipeType,
1518 ReadMode, CompletionMode, MaximumInstances, InboundQuota,
1519 OutboundQuota, DefaultTimeout);
1520 return STATUS_NOT_IMPLEMENTED;