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 #define NONAMELESSUNION
61 #define NONAMELESSSTRUCT
62 #include "wine/unicode.h"
63 #include "wine/debug.h"
64 #include "wine/server.h"
66 #include "ntdll_misc.h"
71 WINE_DEFAULT_DEBUG_CHANNEL(ntdll
);
73 mode_t FILE_umask
= 0;
75 #define SECSPERDAY 86400
76 #define SECS_1601_TO_1970 ((369 * 365 + 89) * (ULONGLONG)SECSPERDAY)
78 /**************************************************************************
79 * NtOpenFile [NTDLL.@]
80 * ZwOpenFile [NTDLL.@]
85 * handle [O] Variable that receives the file handle on return
86 * access [I] Access desired by the caller to the file
87 * attr [I] Structure describing the file to be opened
88 * io [O] Receives details about the result of the operation
89 * sharing [I] Type of shared access the caller requires
90 * options [I] Options for the file open
93 * Success: 0. FileHandle and IoStatusBlock are updated.
94 * Failure: An NTSTATUS error code describing the error.
96 NTSTATUS WINAPI
NtOpenFile( PHANDLE handle
, ACCESS_MASK access
,
97 POBJECT_ATTRIBUTES attr
, PIO_STATUS_BLOCK io
,
98 ULONG sharing
, ULONG options
)
100 return NtCreateFile( handle
, access
, attr
, io
, NULL
, 0,
101 sharing
, FILE_OPEN
, options
, NULL
, 0 );
104 /**************************************************************************
105 * NtCreateFile [NTDLL.@]
106 * ZwCreateFile [NTDLL.@]
108 * Either create a new file or directory, or open an existing file, device,
109 * directory or volume.
112 * handle [O] Points to a variable which receives the file handle on return
113 * access [I] Desired access to the file
114 * attr [I] Structure describing the file
115 * io [O] Receives information about the operation on return
116 * alloc_size [I] Initial size of the file in bytes
117 * attributes [I] Attributes to create the file with
118 * sharing [I] Type of shared access the caller would like to the file
119 * disposition [I] Specifies what to do, depending on whether the file already exists
120 * options [I] Options for creating a new file
121 * ea_buffer [I] Undocumented
122 * ea_length [I] Undocumented
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
;
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
;
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
)
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
;
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
)
203 io
->Information
= FILE_SUPERSEDED
;
206 io
->Information
= FILE_CREATED
;
210 io
->Information
= FILE_OPENED
;
213 case FILE_OVERWRITE_IF
:
214 io
->Information
= FILE_OVERWRITTEN
;
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
;
251 int queue_apc_on_error
;
255 static DWORD
fileio_get_async_count(const struct async_private
*ovp
)
257 const async_fileio
*fileio
= (const async_fileio
*) ovp
;
259 if (fileio
->count
< fileio
->async
.iosb
->Information
)
261 return fileio
->count
- fileio
->async
.iosb
->Information
;
264 static void CALLBACK
fileio_call_completion_func(ULONG_PTR data
)
266 async_fileio
*ovp
= (async_fileio
*) data
;
267 TRACE("data: %p\n", ovp
);
269 if ((ovp
->async
.iosb
->u
.Status
== STATUS_SUCCESS
) || ovp
->queue_apc_on_error
)
270 ovp
->apc( ovp
->apc_user
, ovp
->async
.iosb
, ovp
->async
.iosb
->Information
);
272 fileio_async_cleanup( &ovp
->async
);
275 static void fileio_async_cleanup( struct async_private
*ovp
)
277 RtlFreeHeap( GetProcessHeap(), 0, ovp
);
280 /***********************************************************************
281 * FILE_GetNtStatus(void)
283 * Retrieve the Nt Status code from errno.
284 * Try to be consistent with FILE_SetDosError().
286 NTSTATUS
FILE_GetNtStatus(void)
290 TRACE( "errno = %d\n", errno
);
293 case EAGAIN
: return STATUS_SHARING_VIOLATION
;
294 case EBADF
: return STATUS_INVALID_HANDLE
;
295 case ENOSPC
: return STATUS_DISK_FULL
;
298 case EACCES
: return STATUS_ACCESS_DENIED
;
299 case ENOTDIR
: return STATUS_OBJECT_PATH_NOT_FOUND
;
300 case ENOENT
: return STATUS_OBJECT_NAME_NOT_FOUND
;
301 case EISDIR
: return STATUS_FILE_IS_A_DIRECTORY
;
303 case ENFILE
: return STATUS_TOO_MANY_OPENED_FILES
;
304 case EINVAL
: return STATUS_INVALID_PARAMETER
;
305 case ENOTEMPTY
: return STATUS_DIRECTORY_NOT_EMPTY
;
306 case EPIPE
: return STATUS_PIPE_BROKEN
;
307 case EIO
: return STATUS_DEVICE_NOT_READY
;
309 case ENOMEDIUM
: return STATUS_NO_MEDIA_IN_DEVICE
;
312 case EOPNOTSUPP
:return STATUS_NOT_SUPPORTED
;
313 case ECONNRESET
:return STATUS_PIPE_DISCONNECTED
;
314 case ENOEXEC
: /* ?? */
315 case ESPIPE
: /* ?? */
316 case EEXIST
: /* ?? */
318 FIXME( "Converting errno %d to STATUS_UNSUCCESSFUL\n", err
);
319 return STATUS_UNSUCCESSFUL
;
323 /***********************************************************************
324 * FILE_AsyncReadService (INTERNAL)
326 * This function is called while the client is waiting on the
327 * server, so we can't make any server calls here.
329 static void FILE_AsyncReadService(async_private
*ovp
)
331 async_fileio
*fileio
= (async_fileio
*) ovp
;
332 IO_STATUS_BLOCK
* io_status
= fileio
->async
.iosb
;
334 int already
= io_status
->Information
;
336 TRACE("%p %p\n", io_status
, fileio
->buffer
);
338 /* check to see if the data is ready (non-blocking) */
340 if ( fileio
->avail_mode
)
341 result
= read(ovp
->fd
, &fileio
->buffer
[already
], fileio
->count
- already
);
344 result
= pread(ovp
->fd
, &fileio
->buffer
[already
], fileio
->count
- already
,
345 fileio
->offset
+ already
);
346 if ((result
< 0) && (errno
== ESPIPE
))
347 result
= read(ovp
->fd
, &fileio
->buffer
[already
], fileio
->count
- already
);
350 if ((result
< 0) && ((errno
== EAGAIN
) || (errno
== EINTR
)))
352 TRACE("Deferred read %d\n",errno
);
353 io_status
->u
.Status
= STATUS_PENDING
;
357 /* check to see if the transfer is complete */
360 io_status
->u
.Status
= FILE_GetNtStatus();
363 else if (result
== 0)
365 io_status
->u
.Status
= io_status
->Information
? STATUS_SUCCESS
: STATUS_END_OF_FILE
;
369 TRACE("status before: %s\n", (io_status
->u
.Status
== STATUS_SUCCESS
) ? "success" : "pending");
370 io_status
->Information
+= result
;
371 if (io_status
->Information
>= fileio
->count
|| fileio
->avail_mode
)
372 io_status
->u
.Status
= STATUS_SUCCESS
;
374 io_status
->u
.Status
= STATUS_PENDING
;
376 TRACE("read %d more bytes %ld/%d so far (%s)\n",
377 result
, io_status
->Information
, fileio
->count
, (io_status
->u
.Status
== STATUS_SUCCESS
) ? "success" : "pending");
381 /******************************************************************************
382 * NtReadFile [NTDLL.@]
383 * ZwReadFile [NTDLL.@]
385 * Read from an open file handle.
388 * FileHandle [I] Handle returned from ZwOpenFile() or ZwCreateFile()
389 * Event [I] Event to signal upon completion (or NULL)
390 * ApcRoutine [I] Callback to call upon completion (or NULL)
391 * ApcContext [I] Context for ApcRoutine (or NULL)
392 * IoStatusBlock [O] Receives information about the operation on return
393 * Buffer [O] Destination for the data read
394 * Length [I] Size of Buffer
395 * ByteOffset [O] Destination for the new file pointer position (or NULL)
396 * Key [O] Function unknown (may be NULL)
399 * Success: 0. IoStatusBlock is updated, and the Information member contains
400 * The number of bytes read.
401 * Failure: An NTSTATUS error code describing the error.
403 NTSTATUS WINAPI
NtReadFile(HANDLE hFile
, HANDLE hEvent
,
404 PIO_APC_ROUTINE apc
, void* apc_user
,
405 PIO_STATUS_BLOCK io_status
, void* buffer
, ULONG length
,
406 PLARGE_INTEGER offset
, PULONG key
)
408 int unix_handle
, flags
;
410 TRACE("(%p,%p,%p,%p,%p,%p,0x%08lx,%p,%p),partial stub!\n",
411 hFile
,hEvent
,apc
,apc_user
,io_status
,buffer
,length
,offset
,key
);
413 io_status
->Information
= 0;
414 io_status
->u
.Status
= wine_server_handle_to_fd( hFile
, GENERIC_READ
, &unix_handle
, &flags
);
415 if (io_status
->u
.Status
) return io_status
->u
.Status
;
417 if (flags
& FD_FLAG_RECV_SHUTDOWN
)
419 wine_server_release_fd( hFile
, unix_handle
);
420 return STATUS_PIPE_DISCONNECTED
;
423 if (flags
& FD_FLAG_TIMEOUT
)
427 /* this shouldn't happen, but check it */
428 FIXME("NIY-hEvent\n");
429 wine_server_release_fd( hFile
, unix_handle
);
430 return STATUS_NOT_IMPLEMENTED
;
432 io_status
->u
.Status
= NtCreateEvent(&hEvent
, SYNCHRONIZE
, NULL
, 0, 0);
433 if (io_status
->u
.Status
)
435 wine_server_release_fd( hFile
, unix_handle
);
436 return io_status
->u
.Status
;
440 if (flags
& (FD_FLAG_OVERLAPPED
|FD_FLAG_TIMEOUT
))
445 if (!(ovp
= RtlAllocateHeap(GetProcessHeap(), 0, sizeof(async_fileio
))))
447 wine_server_release_fd( hFile
, unix_handle
);
448 if (flags
& FD_FLAG_TIMEOUT
) NtClose(hEvent
);
449 return STATUS_NO_MEMORY
;
451 ovp
->async
.ops
= (apc
? &fileio_async_ops
: &fileio_nocomp_async_ops
);
452 ovp
->async
.handle
= hFile
;
453 ovp
->async
.fd
= unix_handle
; /* FIXME */
454 ovp
->async
.type
= ASYNC_TYPE_READ
;
455 ovp
->async
.func
= FILE_AsyncReadService
;
456 ovp
->async
.event
= hEvent
;
457 ovp
->async
.iosb
= io_status
;
459 if ( offset
== NULL
)
463 ovp
->offset
= offset
->QuadPart
;
464 if (offset
->u
.HighPart
&& ovp
->offset
== offset
->u
.LowPart
)
465 FIXME("High part of offset is lost\n");
468 ovp
->apc_user
= apc_user
;
469 ovp
->buffer
= buffer
;
470 ovp
->queue_apc_on_error
= 0;
471 ovp
->avail_mode
= (flags
& FD_FLAG_AVAILABLE
);
472 NtResetEvent(hEvent
, NULL
);
474 ret
= register_new_async(&ovp
->async
);
475 if (ret
!= STATUS_SUCCESS
)
477 wine_server_release_fd( hFile
, unix_handle
);
478 if (flags
& FD_FLAG_TIMEOUT
) NtClose(hEvent
);
479 RtlFreeHeap(GetProcessHeap(), 0, ovp
);
482 if (flags
& FD_FLAG_TIMEOUT
)
484 ret
= NtWaitForSingleObject(hEvent
, TRUE
, NULL
);
486 if (ret
!= STATUS_USER_APC
)
487 ovp
->queue_apc_on_error
= 1;
491 LARGE_INTEGER timeout
;
493 /* let some APC be run, this will read some already pending data */
494 timeout
.u
.LowPart
= timeout
.u
.HighPart
= 0;
495 ret
= NtDelayExecution( TRUE
, &timeout
);
496 /* the apc didn't run and therefore the completion routine now
497 * needs to be sent errors.
498 * Note that there is no race between setting this flag and
499 * returning errors because apc's are run only during alertable
501 if (ret
!= STATUS_USER_APC
)
502 ovp
->queue_apc_on_error
= 1;
503 /* if we only have to read the available data, and none is available,
504 * simply cancel the request. If data was available, it has been read
505 * while in by previous call (NtDelayExecution)
507 if ((flags
& FD_FLAG_AVAILABLE
) && io_status
->u
.Status
== STATUS_PENDING
)
509 io_status
->u
.Status
= STATUS_SUCCESS
;
510 register_old_async(&ovp
->async
);
513 TRACE("= 0x%08lx\n", io_status
->u
.Status
);
514 return io_status
->u
.Status
;
519 FILE_POSITION_INFORMATION fpi
;
521 fpi
.CurrentByteOffset
= *offset
;
522 io_status
->u
.Status
= NtSetInformationFile(hFile
, io_status
, &fpi
, sizeof(fpi
),
523 FilePositionInformation
);
524 if (io_status
->u
.Status
)
526 wine_server_release_fd( hFile
, unix_handle
);
527 return io_status
->u
.Status
;
530 /* code for synchronous reads */
531 while ((io_status
->Information
= read( unix_handle
, buffer
, length
)) == -1)
533 if ((errno
== EAGAIN
) || (errno
== EINTR
)) continue;
534 if (errno
== EFAULT
) FIXME( "EFAULT handling broken for now\n" );
535 io_status
->u
.Status
= FILE_GetNtStatus();
538 wine_server_release_fd( hFile
, unix_handle
);
539 TRACE("= 0x%08lx\n", io_status
->u
.Status
);
540 return io_status
->u
.Status
;
543 /***********************************************************************
544 * FILE_AsyncWriteService (INTERNAL)
546 * This function is called while the client is waiting on the
547 * server, so we can't make any server calls here.
549 static void FILE_AsyncWriteService(struct async_private
*ovp
)
551 async_fileio
*fileio
= (async_fileio
*) ovp
;
552 PIO_STATUS_BLOCK io_status
= fileio
->async
.iosb
;
554 int already
= io_status
->Information
;
556 TRACE("(%p %p)\n",io_status
,fileio
->buffer
);
558 /* write some data (non-blocking) */
560 if ( fileio
->avail_mode
)
561 result
= write(ovp
->fd
, &fileio
->buffer
[already
], fileio
->count
- already
);
564 result
= pwrite(ovp
->fd
, &fileio
->buffer
[already
], fileio
->count
- already
,
565 fileio
->offset
+ already
);
566 if ((result
< 0) && (errno
== ESPIPE
))
567 result
= write(ovp
->fd
, &fileio
->buffer
[already
], fileio
->count
- already
);
570 if ((result
< 0) && ((errno
== EAGAIN
) || (errno
== EINTR
)))
572 io_status
->u
.Status
= STATUS_PENDING
;
576 /* check to see if the transfer is complete */
579 io_status
->u
.Status
= FILE_GetNtStatus();
583 io_status
->Information
+= result
;
584 io_status
->u
.Status
= (io_status
->Information
< fileio
->count
) ? STATUS_PENDING
: STATUS_SUCCESS
;
585 TRACE("wrote %d more bytes %ld/%d so far\n",result
,io_status
->Information
,fileio
->count
);
588 /******************************************************************************
589 * NtWriteFile [NTDLL.@]
590 * ZwWriteFile [NTDLL.@]
592 * Write to an open file handle.
595 * FileHandle [I] Handle returned from ZwOpenFile() or ZwCreateFile()
596 * Event [I] Event to signal upon completion (or NULL)
597 * ApcRoutine [I] Callback to call upon completion (or NULL)
598 * ApcContext [I] Context for ApcRoutine (or NULL)
599 * IoStatusBlock [O] Receives information about the operation on return
600 * Buffer [I] Source for the data to write
601 * Length [I] Size of Buffer
602 * ByteOffset [O] Destination for the new file pointer position (or NULL)
603 * Key [O] Function unknown (may be NULL)
606 * Success: 0. IoStatusBlock is updated, and the Information member contains
607 * The number of bytes written.
608 * Failure: An NTSTATUS error code describing the error.
610 NTSTATUS WINAPI
NtWriteFile(HANDLE hFile
, HANDLE hEvent
,
611 PIO_APC_ROUTINE apc
, void* apc_user
,
612 PIO_STATUS_BLOCK io_status
,
613 const void* buffer
, ULONG length
,
614 PLARGE_INTEGER offset
, PULONG key
)
616 int unix_handle
, flags
;
618 TRACE("(%p,%p,%p,%p,%p,%p,0x%08lx,%p,%p)!\n",
619 hFile
,hEvent
,apc
,apc_user
,io_status
,buffer
,length
,offset
,key
);
621 io_status
->Information
= 0;
622 io_status
->u
.Status
= wine_server_handle_to_fd( hFile
, GENERIC_WRITE
, &unix_handle
, &flags
);
623 if (io_status
->u
.Status
) return io_status
->u
.Status
;
625 if (flags
& FD_FLAG_SEND_SHUTDOWN
)
627 wine_server_release_fd( hFile
, unix_handle
);
628 return STATUS_PIPE_DISCONNECTED
;
631 if (flags
& (FD_FLAG_OVERLAPPED
|FD_FLAG_TIMEOUT
))
636 if (!(ovp
= RtlAllocateHeap(GetProcessHeap(), 0, sizeof(async_fileio
))))
638 wine_server_release_fd( hFile
, unix_handle
);
639 return STATUS_NO_MEMORY
;
641 ovp
->async
.ops
= (apc
? &fileio_async_ops
: &fileio_nocomp_async_ops
);
642 ovp
->async
.handle
= hFile
;
643 ovp
->async
.fd
= unix_handle
; /* FIXME */
644 ovp
->async
.type
= ASYNC_TYPE_WRITE
;
645 ovp
->async
.func
= FILE_AsyncWriteService
;
646 ovp
->async
.event
= hEvent
;
647 ovp
->async
.iosb
= io_status
;
650 ovp
->offset
= offset
->QuadPart
;
651 if (offset
->u
.HighPart
&& ovp
->offset
== offset
->u
.LowPart
)
652 FIXME("High part of offset is lost\n");
657 ovp
->apc_user
= apc_user
;
658 ovp
->buffer
= (void*)buffer
;
659 ovp
->queue_apc_on_error
= 0;
660 ovp
->avail_mode
= (flags
& FD_FLAG_AVAILABLE
);
661 NtResetEvent(hEvent
, NULL
);
663 io_status
->Information
= 0;
664 ret
= register_new_async(&ovp
->async
);
665 if (ret
!= STATUS_SUCCESS
)
667 if (flags
& FD_FLAG_TIMEOUT
)
669 ret
= NtWaitForSingleObject(hEvent
, TRUE
, NULL
);
671 if (ret
!= STATUS_USER_APC
)
672 ovp
->queue_apc_on_error
= 1;
676 LARGE_INTEGER timeout
;
678 /* let some APC be run, this will write as much data as possible */
679 timeout
.u
.LowPart
= timeout
.u
.HighPart
= 0;
680 ret
= NtDelayExecution( TRUE
, &timeout
);
681 /* the apc didn't run and therefore the completion routine now
682 * needs to be sent errors.
683 * Note that there is no race between setting this flag and
684 * returning errors because apc's are run only during alertable
686 if (ret
!= STATUS_USER_APC
)
687 ovp
->queue_apc_on_error
= 1;
689 return io_status
->u
.Status
;
694 FILE_POSITION_INFORMATION fpi
;
696 fpi
.CurrentByteOffset
= *offset
;
697 io_status
->u
.Status
= NtSetInformationFile(hFile
, io_status
, &fpi
, sizeof(fpi
),
698 FilePositionInformation
);
699 if (io_status
->u
.Status
)
701 wine_server_release_fd( hFile
, unix_handle
);
702 return io_status
->u
.Status
;
706 /* synchronous file write */
707 while ((io_status
->Information
= write( unix_handle
, buffer
, length
)) == -1)
709 if ((errno
== EAGAIN
) || (errno
== EINTR
)) continue;
710 if (errno
== EFAULT
) FIXME( "EFAULT handling broken for now\n" );
711 if (errno
== ENOSPC
) io_status
->u
.Status
= STATUS_DISK_FULL
;
712 else io_status
->u
.Status
= FILE_GetNtStatus();
715 wine_server_release_fd( hFile
, unix_handle
);
716 return io_status
->u
.Status
;
719 /**************************************************************************
720 * NtDeviceIoControlFile [NTDLL.@]
721 * ZwDeviceIoControlFile [NTDLL.@]
723 * Perform an I/O control operation on an open file handle.
726 * DeviceHandle [I] Handle returned from ZwOpenFile() or ZwCreateFile()
727 * Event [I] Event to signal upon completion (or NULL)
728 * ApcRoutine [I] Callback to call upon completion (or NULL)
729 * ApcContext [I] Context for ApcRoutine (or NULL)
730 * IoStatusBlock [O] Receives information about the operation on return
731 * IoControlCode [I] Control code for the operation to perform
732 * InputBuffer [I] Source for any input data required (or NULL)
733 * InputBufferSize [I] Size of InputBuffer
734 * OutputBuffer [O] Source for any output data returned (or NULL)
735 * OutputBufferSize [I] Size of OutputBuffer
738 * Success: 0. IoStatusBlock is updated.
739 * Failure: An NTSTATUS error code describing the error.
741 NTSTATUS WINAPI
NtDeviceIoControlFile(HANDLE DeviceHandle
, HANDLE hEvent
,
742 PIO_APC_ROUTINE UserApcRoutine
,
743 PVOID UserApcContext
,
744 PIO_STATUS_BLOCK IoStatusBlock
,
747 ULONG InputBufferSize
,
749 ULONG OutputBufferSize
)
751 TRACE("(%p,%p,%p,%p,%p,0x%08lx,%p,0x%08lx,%p,0x%08lx)\n",
752 DeviceHandle
, hEvent
, UserApcRoutine
, UserApcContext
,
753 IoStatusBlock
, IoControlCode
,
754 InputBuffer
, InputBufferSize
, OutputBuffer
, OutputBufferSize
);
756 if (CDROM_DeviceIoControl(DeviceHandle
, hEvent
,
757 UserApcRoutine
, UserApcContext
,
758 IoStatusBlock
, IoControlCode
,
759 InputBuffer
, InputBufferSize
,
760 OutputBuffer
, OutputBufferSize
) == STATUS_NO_SUCH_DEVICE
)
762 /* it wasn't a CDROM */
763 FIXME("Unimplemented dwIoControlCode=%08lx\n", IoControlCode
);
764 IoStatusBlock
->u
.Status
= STATUS_NOT_IMPLEMENTED
;
765 IoStatusBlock
->Information
= 0;
766 if (hEvent
) NtSetEvent(hEvent
, NULL
);
768 return IoStatusBlock
->u
.Status
;
771 /******************************************************************************
772 * NtFsControlFile [NTDLL.@]
773 * ZwFsControlFile [NTDLL.@]
775 NTSTATUS WINAPI
NtFsControlFile(
776 IN HANDLE DeviceHandle
,
777 IN HANDLE Event OPTIONAL
,
778 IN PIO_APC_ROUTINE ApcRoutine OPTIONAL
,
779 IN PVOID ApcContext OPTIONAL
,
780 OUT PIO_STATUS_BLOCK IoStatusBlock
,
781 IN ULONG IoControlCode
,
782 IN PVOID InputBuffer
,
783 IN ULONG InputBufferSize
,
784 OUT PVOID OutputBuffer
,
785 IN ULONG OutputBufferSize
)
787 FIXME("(%p,%p,%p,%p,%p,0x%08lx,%p,0x%08lx,%p,0x%08lx): stub\n",
788 DeviceHandle
,Event
,ApcRoutine
,ApcContext
,IoStatusBlock
,IoControlCode
,
789 InputBuffer
,InputBufferSize
,OutputBuffer
,OutputBufferSize
);
793 /******************************************************************************
794 * NtSetVolumeInformationFile [NTDLL.@]
795 * ZwSetVolumeInformationFile [NTDLL.@]
797 * Set volume information for an open file handle.
800 * FileHandle [I] Handle returned from ZwOpenFile() or ZwCreateFile()
801 * IoStatusBlock [O] Receives information about the operation on return
802 * FsInformation [I] Source for volume information
803 * Length [I] Size of FsInformation
804 * FsInformationClass [I] Type of volume information to set
807 * Success: 0. IoStatusBlock is updated.
808 * Failure: An NTSTATUS error code describing the error.
810 NTSTATUS WINAPI
NtSetVolumeInformationFile(
811 IN HANDLE FileHandle
,
812 PIO_STATUS_BLOCK IoStatusBlock
,
815 FS_INFORMATION_CLASS FsInformationClass
)
817 FIXME("(%p,%p,%p,0x%08lx,0x%08x) stub\n",
818 FileHandle
,IoStatusBlock
,FsInformation
,Length
,FsInformationClass
);
822 /******************************************************************************
823 * NtQueryInformationFile [NTDLL.@]
824 * ZwQueryInformationFile [NTDLL.@]
826 * Get information about an open file handle.
829 * hFile [I] Handle returned from ZwOpenFile() or ZwCreateFile()
830 * io [O] Receives information about the operation on return
831 * ptr [O] Destination for file information
832 * len [I] Size of FileInformation
833 * class [I] Type of file information to get
836 * Success: 0. IoStatusBlock and FileInformation are updated.
837 * Failure: An NTSTATUS error code describing the error.
839 NTSTATUS WINAPI
NtQueryInformationFile( HANDLE hFile
, PIO_STATUS_BLOCK io
,
840 PVOID ptr
, LONG len
, FILE_INFORMATION_CLASS
class )
842 static const size_t info_sizes
[] =
845 sizeof(FILE_DIRECTORY_INFORMATION
), /* FileDirectoryInformation */
846 sizeof(FILE_FULL_DIRECTORY_INFORMATION
), /* FileFullDirectoryInformation */
847 sizeof(FILE_BOTH_DIRECTORY_INFORMATION
), /* FileBothDirectoryInformation */
848 sizeof(FILE_BASIC_INFORMATION
), /* FileBasicInformation */
849 sizeof(FILE_STANDARD_INFORMATION
), /* FileStandardInformation */
850 sizeof(FILE_INTERNAL_INFORMATION
), /* FileInternalInformation */
851 sizeof(FILE_EA_INFORMATION
), /* FileEaInformation */
852 sizeof(FILE_ACCESS_INFORMATION
), /* FileAccessInformation */
853 sizeof(FILE_NAME_INFORMATION
)-sizeof(WCHAR
), /* FileNameInformation */
854 sizeof(FILE_RENAME_INFORMATION
)-sizeof(WCHAR
), /* FileRenameInformation */
855 0, /* FileLinkInformation */
856 sizeof(FILE_NAMES_INFORMATION
)-sizeof(WCHAR
), /* FileNamesInformation */
857 sizeof(FILE_DISPOSITION_INFORMATION
), /* FileDispositionInformation */
858 sizeof(FILE_POSITION_INFORMATION
), /* FilePositionInformation */
859 sizeof(FILE_FULL_EA_INFORMATION
), /* FileFullEaInformation */
860 sizeof(FILE_MODE_INFORMATION
), /* FileModeInformation */
861 sizeof(FILE_ALIGNMENT_INFORMATION
), /* FileAlignmentInformation */
862 sizeof(FILE_ALL_INFORMATION
)-sizeof(WCHAR
), /* FileAllInformation */
863 sizeof(FILE_ALLOCATION_INFORMATION
), /* FileAllocationInformation */
864 sizeof(FILE_END_OF_FILE_INFORMATION
), /* FileEndOfFileInformation */
865 0, /* FileAlternateNameInformation */
866 sizeof(FILE_STREAM_INFORMATION
)-sizeof(WCHAR
), /* FileStreamInformation */
867 0, /* FilePipeInformation */
868 0, /* FilePipeLocalInformation */
869 0, /* FilePipeRemoteInformation */
870 0, /* FileMailslotQueryInformation */
871 0, /* FileMailslotSetInformation */
872 0, /* FileCompressionInformation */
873 0, /* FileObjectIdInformation */
874 0, /* FileCompletionInformation */
875 0, /* FileMoveClusterInformation */
876 0, /* FileQuotaInformation */
877 0, /* FileReparsePointInformation */
878 0, /* FileNetworkOpenInformation */
879 0, /* FileAttributeTagInformation */
880 0 /* FileTrackingInformation */
886 TRACE("(%p,%p,%p,0x%08lx,0x%08x)\n", hFile
, io
, ptr
, len
, class);
890 if (class <= 0 || class >= FileMaximumInformation
)
891 return io
->u
.Status
= STATUS_INVALID_INFO_CLASS
;
892 if (!info_sizes
[class])
894 FIXME("Unsupported class (%d)\n", class);
895 return io
->u
.Status
= STATUS_NOT_IMPLEMENTED
;
897 if (len
< info_sizes
[class])
898 return io
->u
.Status
= STATUS_INFO_LENGTH_MISMATCH
;
900 if ((io
->u
.Status
= wine_server_handle_to_fd( hFile
, 0, &fd
, NULL
)))
905 case FileBasicInformation
:
907 FILE_BASIC_INFORMATION
*info
= ptr
;
909 if (fstat( fd
, &st
) == -1)
910 io
->u
.Status
= FILE_GetNtStatus();
911 else if (!S_ISREG(st
.st_mode
) && !S_ISDIR(st
.st_mode
))
912 io
->u
.Status
= STATUS_INVALID_INFO_CLASS
;
915 if (S_ISDIR(st
.st_mode
)) info
->FileAttributes
= FILE_ATTRIBUTE_DIRECTORY
;
916 else info
->FileAttributes
= FILE_ATTRIBUTE_ARCHIVE
;
917 if (!(st
.st_mode
& S_IWUSR
)) info
->FileAttributes
|= FILE_ATTRIBUTE_READONLY
;
918 RtlSecondsSince1970ToTime( st
.st_mtime
, &info
->CreationTime
);
919 RtlSecondsSince1970ToTime( st
.st_mtime
, &info
->LastWriteTime
);
920 RtlSecondsSince1970ToTime( st
.st_ctime
, &info
->ChangeTime
);
921 RtlSecondsSince1970ToTime( st
.st_atime
, &info
->LastAccessTime
);
925 case FileStandardInformation
:
927 FILE_STANDARD_INFORMATION
*info
= ptr
;
929 if (fstat( fd
, &st
) == -1) io
->u
.Status
= FILE_GetNtStatus();
932 if ((info
->Directory
= S_ISDIR(st
.st_mode
)))
934 info
->AllocationSize
.QuadPart
= 0;
935 info
->EndOfFile
.QuadPart
= 0;
936 info
->NumberOfLinks
= 1;
937 info
->DeletePending
= FALSE
;
941 info
->AllocationSize
.QuadPart
= (ULONGLONG
)st
.st_blocks
* 512;
942 info
->EndOfFile
.QuadPart
= st
.st_size
;
943 info
->NumberOfLinks
= st
.st_nlink
;
944 info
->DeletePending
= FALSE
; /* FIXME */
949 case FilePositionInformation
:
951 FILE_POSITION_INFORMATION
*info
= ptr
;
952 off_t res
= lseek( fd
, 0, SEEK_CUR
);
953 if (res
== (off_t
)-1) io
->u
.Status
= FILE_GetNtStatus();
954 else info
->CurrentByteOffset
.QuadPart
= res
;
957 case FileInternalInformation
:
959 FILE_INTERNAL_INFORMATION
*info
= ptr
;
961 if (fstat( fd
, &st
) == -1) io
->u
.Status
= FILE_GetNtStatus();
962 else info
->IndexNumber
.QuadPart
= st
.st_ino
;
965 case FileEaInformation
:
967 FILE_EA_INFORMATION
*info
= ptr
;
971 case FileEndOfFileInformation
:
973 FILE_END_OF_FILE_INFORMATION
*info
= ptr
;
975 if (fstat( fd
, &st
) == -1) io
->u
.Status
= FILE_GetNtStatus();
976 else info
->EndOfFile
.QuadPart
= S_ISDIR(st
.st_mode
) ? 0 : st
.st_size
;
979 case FileAllInformation
:
981 FILE_ALL_INFORMATION
*info
= ptr
;
983 if (fstat( fd
, &st
) == -1) io
->u
.Status
= FILE_GetNtStatus();
984 else if (!S_ISREG(st
.st_mode
) && !S_ISDIR(st
.st_mode
))
985 io
->u
.Status
= STATUS_INVALID_INFO_CLASS
;
988 if ((info
->StandardInformation
.Directory
= S_ISDIR(st
.st_mode
)))
990 info
->BasicInformation
.FileAttributes
= FILE_ATTRIBUTE_DIRECTORY
;
991 info
->StandardInformation
.AllocationSize
.QuadPart
= 0;
992 info
->StandardInformation
.EndOfFile
.QuadPart
= 0;
993 info
->StandardInformation
.NumberOfLinks
= 1;
994 info
->StandardInformation
.DeletePending
= FALSE
;
998 info
->BasicInformation
.FileAttributes
= FILE_ATTRIBUTE_ARCHIVE
;
999 info
->StandardInformation
.AllocationSize
.QuadPart
= (ULONGLONG
)st
.st_blocks
* 512;
1000 info
->StandardInformation
.EndOfFile
.QuadPart
= st
.st_size
;
1001 info
->StandardInformation
.NumberOfLinks
= st
.st_nlink
;
1002 info
->StandardInformation
.DeletePending
= FALSE
; /* FIXME */
1004 if (!(st
.st_mode
& S_IWUSR
))
1005 info
->BasicInformation
.FileAttributes
|= FILE_ATTRIBUTE_READONLY
;
1006 RtlSecondsSince1970ToTime( st
.st_mtime
, &info
->BasicInformation
.CreationTime
);
1007 RtlSecondsSince1970ToTime( st
.st_mtime
, &info
->BasicInformation
.LastWriteTime
);
1008 RtlSecondsSince1970ToTime( st
.st_ctime
, &info
->BasicInformation
.ChangeTime
);
1009 RtlSecondsSince1970ToTime( st
.st_atime
, &info
->BasicInformation
.LastAccessTime
);
1010 info
->InternalInformation
.IndexNumber
.QuadPart
= st
.st_ino
;
1011 info
->EaInformation
.EaSize
= 0;
1012 info
->AccessInformation
.AccessFlags
= 0; /* FIXME */
1013 info
->PositionInformation
.CurrentByteOffset
.QuadPart
= lseek( fd
, 0, SEEK_CUR
);
1014 info
->ModeInformation
.Mode
= 0; /* FIXME */
1015 info
->AlignmentInformation
.AlignmentRequirement
= 1; /* FIXME */
1016 info
->NameInformation
.FileNameLength
= 0;
1017 io
->Information
= sizeof(*info
) - sizeof(WCHAR
);
1022 FIXME("Unsupported class (%d)\n", class);
1023 io
->u
.Status
= STATUS_NOT_IMPLEMENTED
;
1026 wine_server_release_fd( hFile
, fd
);
1027 if (io
->u
.Status
== STATUS_SUCCESS
&& !io
->Information
) io
->Information
= info_sizes
[class];
1028 return io
->u
.Status
;
1031 /******************************************************************************
1032 * NtSetInformationFile [NTDLL.@]
1033 * ZwSetInformationFile [NTDLL.@]
1035 * Set information about an open file handle.
1038 * handle [I] Handle returned from ZwOpenFile() or ZwCreateFile()
1039 * io [O] Receives information about the operation on return
1040 * ptr [I] Source for file information
1041 * len [I] Size of FileInformation
1042 * class [I] Type of file information to set
1045 * Success: 0. io is updated.
1046 * Failure: An NTSTATUS error code describing the error.
1048 NTSTATUS WINAPI
NtSetInformationFile(HANDLE handle
, PIO_STATUS_BLOCK io
,
1049 PVOID ptr
, ULONG len
, FILE_INFORMATION_CLASS
class)
1053 TRACE("(%p,%p,%p,0x%08lx,0x%08x)\n", handle
, io
, ptr
, len
, class);
1055 if ((io
->u
.Status
= wine_server_handle_to_fd( handle
, 0, &fd
, NULL
)))
1056 return io
->u
.Status
;
1058 io
->u
.Status
= STATUS_SUCCESS
;
1061 case FileBasicInformation
:
1062 if (len
>= sizeof(FILE_BASIC_INFORMATION
))
1065 const FILE_BASIC_INFORMATION
*info
= ptr
;
1067 if (info
->LastAccessTime
.QuadPart
|| info
->LastWriteTime
.QuadPart
)
1069 ULONGLONG sec
, nsec
;
1070 struct timeval tv
[2];
1072 if (!info
->LastAccessTime
.QuadPart
|| !info
->LastWriteTime
.QuadPart
)
1075 tv
[0].tv_sec
= tv
[0].tv_usec
= 0;
1076 tv
[1].tv_sec
= tv
[1].tv_usec
= 0;
1077 if (!fstat( fd
, &st
))
1079 tv
[0].tv_sec
= st
.st_atime
;
1080 tv
[1].tv_sec
= st
.st_mtime
;
1083 if (info
->LastAccessTime
.QuadPart
)
1085 sec
= RtlLargeIntegerDivide( info
->LastAccessTime
.QuadPart
, 10000000, &nsec
);
1086 tv
[0].tv_sec
= sec
- SECS_1601_TO_1970
;
1087 tv
[0].tv_usec
= (UINT
)nsec
/ 10;
1089 if (info
->LastWriteTime
.QuadPart
)
1091 sec
= RtlLargeIntegerDivide( info
->LastWriteTime
.QuadPart
, 10000000, &nsec
);
1092 tv
[1].tv_sec
= sec
- SECS_1601_TO_1970
;
1093 tv
[1].tv_usec
= (UINT
)nsec
/ 10;
1095 if (futimes( fd
, tv
) == -1) io
->u
.Status
= FILE_GetNtStatus();
1098 if (io
->u
.Status
== STATUS_SUCCESS
&& info
->FileAttributes
)
1100 if (fstat( fd
, &st
) == -1) io
->u
.Status
= FILE_GetNtStatus();
1103 if (info
->FileAttributes
& FILE_ATTRIBUTE_READONLY
)
1105 if (S_ISDIR( st
.st_mode
))
1106 WARN("FILE_ATTRIBUTE_READONLY ignored for directory.\n");
1108 st
.st_mode
&= ~0222; /* clear write permission bits */
1112 /* add write permission only where we already have read permission */
1113 st
.st_mode
|= (0600 | ((st
.st_mode
& 044) >> 1)) & (~FILE_umask
);
1115 if (fchmod( fd
, st
.st_mode
) == -1) io
->u
.Status
= FILE_GetNtStatus();
1119 else io
->u
.Status
= STATUS_INVALID_PARAMETER_3
;
1122 case FilePositionInformation
:
1123 if (len
>= sizeof(FILE_POSITION_INFORMATION
))
1125 const FILE_POSITION_INFORMATION
*info
= ptr
;
1127 if (lseek( fd
, info
->CurrentByteOffset
.QuadPart
, SEEK_SET
) == (off_t
)-1)
1128 io
->u
.Status
= FILE_GetNtStatus();
1130 else io
->u
.Status
= STATUS_INVALID_PARAMETER_3
;
1133 case FileEndOfFileInformation
:
1134 if (len
>= sizeof(FILE_END_OF_FILE_INFORMATION
))
1137 const FILE_END_OF_FILE_INFORMATION
*info
= ptr
;
1139 /* first try normal truncate */
1140 if (ftruncate( fd
, (off_t
)info
->EndOfFile
.QuadPart
) != -1) break;
1142 /* now check for the need to extend the file */
1143 if (fstat( fd
, &st
) != -1 && (off_t
)info
->EndOfFile
.QuadPart
> st
.st_size
)
1145 static const char zero
;
1147 /* extend the file one byte beyond the requested size and then truncate it */
1148 /* this should work around ftruncate implementations that can't extend files */
1149 if (pwrite( fd
, &zero
, 1, (off_t
)info
->EndOfFile
.QuadPart
) != -1 &&
1150 ftruncate( fd
, (off_t
)info
->EndOfFile
.QuadPart
) != -1) break;
1152 io
->u
.Status
= FILE_GetNtStatus();
1154 else io
->u
.Status
= STATUS_INVALID_PARAMETER_3
;
1158 FIXME("Unsupported class (%d)\n", class);
1159 io
->u
.Status
= STATUS_NOT_IMPLEMENTED
;
1162 wine_server_release_fd( handle
, fd
);
1163 io
->Information
= 0;
1164 return io
->u
.Status
;
1168 /******************************************************************************
1169 * NtQueryFullAttributesFile (NTDLL.@)
1171 NTSTATUS WINAPI
NtQueryFullAttributesFile( const OBJECT_ATTRIBUTES
*attr
,
1172 FILE_NETWORK_OPEN_INFORMATION
*info
)
1174 ANSI_STRING unix_name
;
1177 if (!(status
= wine_nt_to_unix_file_name( attr
->ObjectName
, &unix_name
, FILE_OPEN
,
1178 !(attr
->Attributes
& OBJ_CASE_INSENSITIVE
) )))
1182 if (stat( unix_name
.Buffer
, &st
) == -1)
1183 status
= FILE_GetNtStatus();
1184 else if (!S_ISREG(st
.st_mode
) && !S_ISDIR(st
.st_mode
))
1185 status
= STATUS_INVALID_INFO_CLASS
;
1188 if (S_ISDIR(st
.st_mode
))
1190 info
->FileAttributes
= FILE_ATTRIBUTE_DIRECTORY
;
1191 info
->AllocationSize
.QuadPart
= 0;
1192 info
->EndOfFile
.QuadPart
= 0;
1196 info
->FileAttributes
= FILE_ATTRIBUTE_ARCHIVE
;
1197 info
->AllocationSize
.QuadPart
= (ULONGLONG
)st
.st_blocks
* 512;
1198 info
->EndOfFile
.QuadPart
= st
.st_size
;
1200 if (!(st
.st_mode
& S_IWUSR
)) info
->FileAttributes
|= FILE_ATTRIBUTE_READONLY
;
1201 RtlSecondsSince1970ToTime( st
.st_mtime
, &info
->CreationTime
);
1202 RtlSecondsSince1970ToTime( st
.st_mtime
, &info
->LastWriteTime
);
1203 RtlSecondsSince1970ToTime( st
.st_ctime
, &info
->ChangeTime
);
1204 RtlSecondsSince1970ToTime( st
.st_atime
, &info
->LastAccessTime
);
1205 if (DIR_is_hidden_file( attr
->ObjectName
))
1206 info
->FileAttributes
|= FILE_ATTRIBUTE_HIDDEN
;
1208 RtlFreeAnsiString( &unix_name
);
1210 else WARN("%s not found (%lx)\n", debugstr_us(attr
->ObjectName
), status
);
1215 /******************************************************************************
1216 * NtQueryAttributesFile (NTDLL.@)
1217 * ZwQueryAttributesFile (NTDLL.@)
1219 NTSTATUS WINAPI
NtQueryAttributesFile( const OBJECT_ATTRIBUTES
*attr
, FILE_BASIC_INFORMATION
*info
)
1221 FILE_NETWORK_OPEN_INFORMATION full_info
;
1224 if (!(status
= NtQueryFullAttributesFile( attr
, &full_info
)))
1226 info
->CreationTime
.QuadPart
= full_info
.CreationTime
.QuadPart
;
1227 info
->LastAccessTime
.QuadPart
= full_info
.LastAccessTime
.QuadPart
;
1228 info
->LastWriteTime
.QuadPart
= full_info
.LastWriteTime
.QuadPart
;
1229 info
->ChangeTime
.QuadPart
= full_info
.ChangeTime
.QuadPart
;
1230 info
->FileAttributes
= full_info
.FileAttributes
;
1236 /******************************************************************************
1237 * NtQueryVolumeInformationFile [NTDLL.@]
1238 * ZwQueryVolumeInformationFile [NTDLL.@]
1240 * Get volume information for an open file handle.
1243 * handle [I] Handle returned from ZwOpenFile() or ZwCreateFile()
1244 * io [O] Receives information about the operation on return
1245 * buffer [O] Destination for volume information
1246 * length [I] Size of FsInformation
1247 * info_class [I] Type of volume information to set
1250 * Success: 0. io and buffer are updated.
1251 * Failure: An NTSTATUS error code describing the error.
1253 NTSTATUS WINAPI
NtQueryVolumeInformationFile( HANDLE handle
, PIO_STATUS_BLOCK io
,
1254 PVOID buffer
, ULONG length
,
1255 FS_INFORMATION_CLASS info_class
)
1260 if ((io
->u
.Status
= wine_server_handle_to_fd( handle
, 0, &fd
, NULL
)) != STATUS_SUCCESS
)
1261 return io
->u
.Status
;
1263 io
->u
.Status
= STATUS_NOT_IMPLEMENTED
;
1264 io
->Information
= 0;
1266 switch( info_class
)
1268 case FileFsVolumeInformation
:
1269 FIXME( "%p: volume info not supported\n", handle
);
1271 case FileFsLabelInformation
:
1272 FIXME( "%p: label info not supported\n", handle
);
1274 case FileFsSizeInformation
:
1275 if (length
< sizeof(FILE_FS_SIZE_INFORMATION
))
1276 io
->u
.Status
= STATUS_BUFFER_TOO_SMALL
;
1279 FILE_FS_SIZE_INFORMATION
*info
= buffer
;
1280 struct statvfs stvfs
;
1282 if (fstat( fd
, &st
) < 0)
1284 io
->u
.Status
= FILE_GetNtStatus();
1287 if (!S_ISREG(st
.st_mode
) && !S_ISDIR(st
.st_mode
))
1289 io
->u
.Status
= STATUS_INVALID_DEVICE_REQUEST
;
1292 if (fstatvfs( fd
, &stvfs
) < 0) io
->u
.Status
= FILE_GetNtStatus();
1295 info
->TotalAllocationUnits
.QuadPart
= stvfs
.f_blocks
;
1296 info
->AvailableAllocationUnits
.QuadPart
= stvfs
.f_bavail
;
1297 info
->SectorsPerAllocationUnit
= 1;
1298 info
->BytesPerSector
= stvfs
.f_frsize
;
1299 io
->Information
= sizeof(*info
);
1300 io
->u
.Status
= STATUS_SUCCESS
;
1304 case FileFsDeviceInformation
:
1305 if (length
< sizeof(FILE_FS_DEVICE_INFORMATION
))
1306 io
->u
.Status
= STATUS_BUFFER_TOO_SMALL
;
1309 FILE_FS_DEVICE_INFORMATION
*info
= buffer
;
1311 info
->Characteristics
= 0;
1312 if (fstat( fd
, &st
) < 0)
1314 io
->u
.Status
= FILE_GetNtStatus();
1317 if (S_ISCHR( st
.st_mode
))
1319 info
->DeviceType
= FILE_DEVICE_UNKNOWN
;
1321 switch(major(st
.st_rdev
))
1324 info
->DeviceType
= FILE_DEVICE_NULL
;
1327 info
->DeviceType
= FILE_DEVICE_SERIAL_PORT
;
1330 info
->DeviceType
= FILE_DEVICE_PARALLEL_PORT
;
1335 else if (S_ISBLK( st
.st_mode
))
1337 info
->DeviceType
= FILE_DEVICE_DISK
;
1339 else if (S_ISFIFO( st
.st_mode
) || S_ISSOCK( st
.st_mode
))
1341 info
->DeviceType
= FILE_DEVICE_NAMED_PIPE
;
1343 else /* regular file or directory */
1345 #if defined(linux) && defined(HAVE_FSTATFS)
1348 /* check for floppy disk */
1349 if (major(st
.st_dev
) == FLOPPY_MAJOR
)
1350 info
->Characteristics
|= FILE_REMOVABLE_MEDIA
;
1352 if (fstatfs( fd
, &stfs
) < 0) stfs
.f_type
= 0;
1353 switch (stfs
.f_type
)
1355 case 0x9660: /* iso9660 */
1356 case 0x15013346: /* udf */
1357 info
->DeviceType
= FILE_DEVICE_CD_ROM_FILE_SYSTEM
;
1358 info
->Characteristics
|= FILE_REMOVABLE_MEDIA
|FILE_READ_ONLY_DEVICE
;
1360 case 0x6969: /* nfs */
1361 case 0x517B: /* smbfs */
1362 case 0x564c: /* ncpfs */
1363 info
->DeviceType
= FILE_DEVICE_NETWORK_FILE_SYSTEM
;
1364 info
->Characteristics
|= FILE_REMOTE_DEVICE
;
1366 case 0x01021994: /* tmpfs */
1367 case 0x28cd3d45: /* cramfs */
1368 case 0x1373: /* devfs */
1369 case 0x9fa0: /* procfs */
1370 info
->DeviceType
= FILE_DEVICE_VIRTUAL_DISK
;
1373 info
->DeviceType
= FILE_DEVICE_DISK_FILE_SYSTEM
;
1376 #elif defined (__APPLE__)
1377 #include <IOKit/IOKitLib.h>
1378 #include <CoreFoundation/CFNumber.h> /* for kCFBooleanTrue, kCFBooleanFalse */
1382 info
->DeviceType
= FILE_DEVICE_DISK_FILE_SYSTEM
;
1384 if (fstatfs( fd
, &stfs
) < 0) break;
1386 /* stfs.f_type is reserved (always set to 0) so use IOKit */
1387 kern_return_t kernResult
= KERN_FAILURE
;
1388 mach_port_t masterPort
;
1390 char bsdName
[6]; /* disk#\0 */
1392 strncpy(bsdName
, stfs
.f_mntfromname
+strlen(_PATH_DEV
) , 5);
1395 kernResult
= IOMasterPort(MACH_PORT_NULL
, &masterPort
);
1397 if (kernResult
== KERN_SUCCESS
)
1399 CFMutableDictionaryRef matching
= IOBSDNameMatching(masterPort
, 0, bsdName
);
1403 CFMutableDictionaryRef properties
;
1404 io_service_t devService
= IOServiceGetMatchingService(masterPort
, matching
);
1406 if (IORegistryEntryCreateCFProperties(devService
,
1408 kCFAllocatorDefault
, 0) != KERN_SUCCESS
)
1411 CFDictionaryGetValue(properties
, CFSTR("Removable")),
1413 ) info
->Characteristics
|= FILE_REMOVABLE_MEDIA
;
1416 CFDictionaryGetValue(properties
, CFSTR("Writable")),
1418 ) info
->Characteristics
|= FILE_READ_ONLY_DEVICE
;
1421 NB : mounted disk image (.img/.dmg) don't provide specific type
1424 if ( (type
= CFDictionaryGetValue(properties
, CFSTR("Type"))) )
1426 if ( CFStringCompare(type
, CFSTR("CD-ROM"), 0) == kCFCompareEqualTo
1427 || CFStringCompare(type
, CFSTR("DVD-ROM"), 0) == kCFCompareEqualTo
1430 info
->DeviceType
= FILE_DEVICE_CD_ROM_FILE_SYSTEM
;
1435 CFRelease(properties
);
1440 if (!warned
++) FIXME( "device info not properly supported on this platform\n" );
1441 info
->DeviceType
= FILE_DEVICE_DISK_FILE_SYSTEM
;
1443 info
->Characteristics
|= FILE_DEVICE_IS_MOUNTED
;
1445 io
->Information
= sizeof(*info
);
1446 io
->u
.Status
= STATUS_SUCCESS
;
1449 case FileFsAttributeInformation
:
1450 FIXME( "%p: attribute info not supported\n", handle
);
1452 case FileFsControlInformation
:
1453 FIXME( "%p: control info not supported\n", handle
);
1455 case FileFsFullSizeInformation
:
1456 FIXME( "%p: full size info not supported\n", handle
);
1458 case FileFsObjectIdInformation
:
1459 FIXME( "%p: object id info not supported\n", handle
);
1461 case FileFsMaximumInformation
:
1462 FIXME( "%p: maximum info not supported\n", handle
);
1465 io
->u
.Status
= STATUS_INVALID_PARAMETER
;
1468 wine_server_release_fd( handle
, fd
);
1469 return io
->u
.Status
;
1473 /******************************************************************
1474 * NtFlushBuffersFile (NTDLL.@)
1476 * Flush any buffered data on an open file handle.
1479 * FileHandle [I] Handle returned from ZwOpenFile() or ZwCreateFile()
1480 * IoStatusBlock [O] Receives information about the operation on return
1483 * Success: 0. IoStatusBlock is updated.
1484 * Failure: An NTSTATUS error code describing the error.
1486 NTSTATUS WINAPI
NtFlushBuffersFile( HANDLE hFile
, IO_STATUS_BLOCK
* IoStatusBlock
)
1489 HANDLE hEvent
= NULL
;
1491 SERVER_START_REQ( flush_file
)
1493 req
->handle
= hFile
;
1494 ret
= wine_server_call( req
);
1495 hEvent
= reply
->event
;
1500 ret
= NtWaitForSingleObject( hEvent
, FALSE
, NULL
);
1506 /******************************************************************
1507 * NtLockFile (NTDLL.@)
1511 NTSTATUS WINAPI
NtLockFile( HANDLE hFile
, HANDLE lock_granted_event
,
1512 PIO_APC_ROUTINE apc
, void* apc_user
,
1513 PIO_STATUS_BLOCK io_status
, PLARGE_INTEGER offset
,
1514 PLARGE_INTEGER count
, ULONG
* key
, BOOLEAN dont_wait
,
1521 if (apc
|| io_status
|| key
)
1523 FIXME("Unimplemented yet parameter\n");
1524 return STATUS_NOT_IMPLEMENTED
;
1529 SERVER_START_REQ( lock_file
)
1531 req
->handle
= hFile
;
1532 req
->offset_low
= offset
->u
.LowPart
;
1533 req
->offset_high
= offset
->u
.HighPart
;
1534 req
->count_low
= count
->u
.LowPart
;
1535 req
->count_high
= count
->u
.HighPart
;
1536 req
->shared
= !exclusive
;
1537 req
->wait
= !dont_wait
;
1538 ret
= wine_server_call( req
);
1539 handle
= reply
->handle
;
1540 async
= reply
->overlapped
;
1543 if (ret
!= STATUS_PENDING
)
1545 if (!ret
&& lock_granted_event
) NtSetEvent(lock_granted_event
, NULL
);
1551 FIXME( "Async I/O lock wait not implemented, might deadlock\n" );
1552 if (handle
) NtClose( handle
);
1553 return STATUS_PENDING
;
1557 NtWaitForSingleObject( handle
, FALSE
, NULL
);
1564 /* Unix lock conflict, sleep a bit and retry */
1565 time
.QuadPart
= 100 * (ULONGLONG
)10000;
1566 time
.QuadPart
= -time
.QuadPart
;
1567 NtDelayExecution( FALSE
, &time
);
1573 /******************************************************************
1574 * NtUnlockFile (NTDLL.@)
1578 NTSTATUS WINAPI
NtUnlockFile( HANDLE hFile
, PIO_STATUS_BLOCK io_status
,
1579 PLARGE_INTEGER offset
, PLARGE_INTEGER count
,
1584 TRACE( "%p %lx%08lx %lx%08lx\n",
1585 hFile
, offset
->u
.HighPart
, offset
->u
.LowPart
, count
->u
.HighPart
, count
->u
.LowPart
);
1587 if (io_status
|| key
)
1589 FIXME("Unimplemented yet parameter\n");
1590 return STATUS_NOT_IMPLEMENTED
;
1593 SERVER_START_REQ( unlock_file
)
1595 req
->handle
= hFile
;
1596 req
->offset_low
= offset
->u
.LowPart
;
1597 req
->offset_high
= offset
->u
.HighPart
;
1598 req
->count_low
= count
->u
.LowPart
;
1599 req
->count_high
= count
->u
.HighPart
;
1600 status
= wine_server_call( req
);
1606 /******************************************************************
1607 * NtCreateNamedPipeFile (NTDLL.@)
1611 NTSTATUS WINAPI
NtCreateNamedPipeFile( PHANDLE FileHandle
, ULONG DesiredAccess
,
1612 POBJECT_ATTRIBUTES ObjectAttributes
, PIO_STATUS_BLOCK IoStatusBlock
,
1613 ULONG ShareAccess
, ULONG CreateDisposition
, ULONG CreateOptions
,
1614 ULONG NamedPipeType
, ULONG ReadMode
, ULONG CompletionMode
,
1615 ULONG MaximumInstances
, ULONG InboundQuota
, ULONG OutboundQuota
,
1616 PLARGE_INTEGER DefaultTimeout
)
1618 FIXME("(%p %lx %p %p %lx %ld %lx %ld %ld %ld %ld %ld %ld %p): stub\n",
1619 FileHandle
, DesiredAccess
, ObjectAttributes
, IoStatusBlock
,
1620 ShareAccess
, CreateDisposition
, CreateOptions
, NamedPipeType
,
1621 ReadMode
, CompletionMode
, MaximumInstances
, InboundQuota
,
1622 OutboundQuota
, DefaultTimeout
);
1623 return STATUS_NOT_IMPLEMENTED
;
1626 /******************************************************************
1627 * NtDeleteFile (NTDLL.@)
1631 NTSTATUS WINAPI
NtDeleteFile( POBJECT_ATTRIBUTES ObjectAttributes
)
1633 FIXME("%p\n", ObjectAttributes
);
1634 return STATUS_NOT_IMPLEMENTED
;
1637 /******************************************************************
1638 * NtCancelIoFile (NTDLL.@)
1642 NTSTATUS WINAPI
NtCancelIoFile( HANDLE FileHandle
,
1643 PIO_STATUS_BLOCK IoStatusBlock
)
1645 FIXME("%p %p\n", FileHandle
, IoStatusBlock
);
1646 return STATUS_NOT_IMPLEMENTED
;