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 STATFS_DEFINED_BY_SYS_VFS
45 # ifdef STATFS_DEFINED_BY_SYS_MOUNT
46 # include <sys/mount.h>
48 # ifdef STATFS_DEFINED_BY_SYS_STATFS
49 # include <sys/statfs.h>
54 #define NONAMELESSUNION
55 #define NONAMELESSSTRUCT
56 #include "wine/unicode.h"
57 #include "wine/debug.h"
58 #include "wine/server.h"
60 #include "ntdll_misc.h"
65 WINE_DEFAULT_DEBUG_CHANNEL(ntdll
);
67 /**************************************************************************
68 * NtOpenFile [NTDLL.@]
69 * ZwOpenFile [NTDLL.@]
74 * handle [O] Variable that receives the file handle on return
75 * access [I] Access desired by the caller to the file
76 * attr [I] Structue describing the file to be opened
77 * io [O] Receives details about the result of the operation
78 * sharing [I] Type of shared access the caller requires
79 * options [I] Options for the file open
82 * Success: 0. FileHandle and IoStatusBlock are updated.
83 * Failure: An NTSTATUS error code describing the error.
85 NTSTATUS WINAPI
NtOpenFile( PHANDLE handle
, ACCESS_MASK access
,
86 POBJECT_ATTRIBUTES attr
, PIO_STATUS_BLOCK io
,
87 ULONG sharing
, ULONG options
)
89 return NtCreateFile( handle
, access
, attr
, io
, NULL
, 0,
90 sharing
, FILE_OPEN
, options
, NULL
, 0 );
93 /**************************************************************************
94 * NtCreateFile [NTDLL.@]
95 * ZwCreateFile [NTDLL.@]
97 * Either create a new file or directory, or open an existing file, device,
98 * directory or volume.
101 * handle [O] Points to a variable which receives the file handle on return
102 * access [I] Desired access to the file
103 * attr [I] Structure describing the file
104 * io [O] Receives information about the operation on return
105 * alloc_size [I] Initial size of the file in bytes
106 * attributes [I] Attributes to create the file with
107 * sharing [I] Type of shared access the caller would like to the file
108 * disposition [I] Specifies what to do, depending on whether the file already exists
109 * options [I] Options for creating a new file
110 * ea_buffer [I] Undocumented
111 * ea_length [I] Undocumented
114 * Success: 0. handle and io are updated.
115 * Failure: An NTSTATUS error code describing the error.
117 NTSTATUS WINAPI
NtCreateFile( PHANDLE handle
, ACCESS_MASK access
, POBJECT_ATTRIBUTES attr
,
118 PIO_STATUS_BLOCK io
, PLARGE_INTEGER alloc_size
,
119 ULONG attributes
, ULONG sharing
, ULONG disposition
,
120 ULONG options
, PVOID ea_buffer
, ULONG ea_length
)
122 ANSI_STRING unix_name
;
124 TRACE("handle=%p access=%08lx name=%s objattr=%08lx root=%p sec=%p io=%p alloc_size=%p\n"
125 "attr=%08lx sharing=%08lx disp=%ld options=%08lx ea=%p.0x%08lx\n",
126 handle
, access
, debugstr_us(attr
->ObjectName
), attr
->Attributes
,
127 attr
->RootDirectory
, attr
->SecurityDescriptor
, io
, alloc_size
,
128 attributes
, sharing
, disposition
, options
, ea_buffer
, ea_length
);
130 if (attr
->RootDirectory
)
132 FIXME( "RootDirectory %p not supported\n", attr
->RootDirectory
);
133 return STATUS_OBJECT_NAME_NOT_FOUND
;
135 if (alloc_size
) FIXME( "alloc_size not supported\n" );
137 if (!(io
->u
.Status
= DIR_nt_to_unix( attr
->ObjectName
, &unix_name
,
138 (disposition
== FILE_OPEN
|| disposition
== FILE_OVERWRITE
),
139 !(attr
->Attributes
& OBJ_CASE_INSENSITIVE
) )))
141 SERVER_START_REQ( create_file
)
143 req
->access
= access
;
144 req
->inherit
= (attr
->Attributes
& OBJ_INHERIT
) != 0;
145 req
->sharing
= sharing
;
146 req
->create
= disposition
;
147 req
->options
= options
;
148 req
->attrs
= attributes
;
149 wine_server_add_data( req
, unix_name
.Buffer
, unix_name
.Length
);
150 io
->u
.Status
= wine_server_call( req
);
151 *handle
= reply
->handle
;
154 RtlFreeAnsiString( &unix_name
);
156 else WARN("%s not found (%lx)\n", debugstr_us(attr
->ObjectName
), io
->u
.Status
);
160 /***********************************************************************
161 * Asynchronous file I/O *
163 static DWORD
fileio_get_async_count(const async_private
*ovp
);
164 static void CALLBACK
fileio_call_completion_func(ULONG_PTR data
);
165 static void fileio_async_cleanup(async_private
*ovp
);
167 static async_ops fileio_async_ops
=
169 fileio_get_async_count
, /* get_count */
170 fileio_call_completion_func
, /* call_completion */
171 fileio_async_cleanup
/* cleanup */
174 static async_ops fileio_nocomp_async_ops
=
176 fileio_get_async_count
, /* get_count */
177 NULL
, /* call_completion */
178 fileio_async_cleanup
/* cleanup */
181 typedef struct async_fileio
183 struct async_private async
;
188 unsigned long offset
;
189 enum fd_type fd_type
;
192 static DWORD
fileio_get_async_count(const struct async_private
*ovp
)
194 async_fileio
*fileio
= (async_fileio
*) ovp
;
196 if (fileio
->count
< fileio
->async
.iosb
->Information
)
198 return fileio
->count
- fileio
->async
.iosb
->Information
;
201 static void CALLBACK
fileio_call_completion_func(ULONG_PTR data
)
203 async_fileio
*ovp
= (async_fileio
*) data
;
204 TRACE("data: %p\n", ovp
);
206 ovp
->apc( ovp
->apc_user
, ovp
->async
.iosb
, ovp
->async
.iosb
->Information
);
208 fileio_async_cleanup( &ovp
->async
);
211 static void fileio_async_cleanup( struct async_private
*ovp
)
213 RtlFreeHeap( GetProcessHeap(), 0, ovp
);
216 /***********************************************************************
217 * FILE_GetNtStatus(void)
219 * Retrieve the Nt Status code from errno.
220 * Try to be consistent with FILE_SetDosError().
222 NTSTATUS
FILE_GetNtStatus(void)
226 TRACE( "errno = %d\n", errno
);
229 case EAGAIN
: return STATUS_SHARING_VIOLATION
;
230 case EBADF
: return STATUS_INVALID_HANDLE
;
231 case ENOSPC
: return STATUS_DISK_FULL
;
234 case EACCES
: return STATUS_ACCESS_DENIED
;
235 case ENOTDIR
: return STATUS_OBJECT_PATH_NOT_FOUND
;
236 case ENOENT
: return STATUS_OBJECT_NAME_NOT_FOUND
;
237 case EISDIR
: return STATUS_FILE_IS_A_DIRECTORY
;
239 case ENFILE
: return STATUS_TOO_MANY_OPENED_FILES
;
240 case EINVAL
: return STATUS_INVALID_PARAMETER
;
241 case ENOTEMPTY
: return STATUS_DIRECTORY_NOT_EMPTY
;
242 case EPIPE
: return STATUS_PIPE_BROKEN
;
243 case EIO
: return STATUS_DEVICE_NOT_READY
;
244 case ENOEXEC
: /* ?? */
245 case ESPIPE
: /* ?? */
246 case EEXIST
: /* ?? */
248 FIXME( "Converting errno %d to STATUS_UNSUCCESSFUL\n", err
);
249 return STATUS_UNSUCCESSFUL
;
253 /***********************************************************************
254 * FILE_AsyncReadService (INTERNAL)
256 * This function is called while the client is waiting on the
257 * server, so we can't make any server calls here.
259 static void FILE_AsyncReadService(async_private
*ovp
)
261 async_fileio
*fileio
= (async_fileio
*) ovp
;
262 IO_STATUS_BLOCK
* io_status
= fileio
->async
.iosb
;
264 int already
= io_status
->Information
;
266 TRACE("%p %p\n", io_status
, fileio
->buffer
);
268 /* check to see if the data is ready (non-blocking) */
270 if ( fileio
->fd_type
== FD_TYPE_SOCKET
)
271 result
= read(ovp
->fd
, &fileio
->buffer
[already
], fileio
->count
- already
);
274 result
= pread(ovp
->fd
, &fileio
->buffer
[already
], fileio
->count
- already
,
275 fileio
->offset
+ already
);
276 if ((result
< 0) && (errno
== ESPIPE
))
277 result
= read(ovp
->fd
, &fileio
->buffer
[already
], fileio
->count
- already
);
280 if ((result
< 0) && ((errno
== EAGAIN
) || (errno
== EINTR
)))
282 TRACE("Deferred read %d\n",errno
);
283 io_status
->u
.Status
= STATUS_PENDING
;
287 /* check to see if the transfer is complete */
290 io_status
->u
.Status
= FILE_GetNtStatus();
293 else if (result
== 0)
295 io_status
->u
.Status
= io_status
->Information
? STATUS_SUCCESS
: STATUS_END_OF_FILE
;
299 io_status
->Information
+= result
;
300 if (io_status
->Information
>= fileio
->count
|| fileio
->fd_type
== FD_TYPE_SOCKET
)
301 io_status
->u
.Status
= STATUS_SUCCESS
;
303 io_status
->u
.Status
= STATUS_PENDING
;
305 TRACE("read %d more bytes %ld/%d so far\n",
306 result
, io_status
->Information
, fileio
->count
);
310 /******************************************************************************
311 * NtReadFile [NTDLL.@]
312 * ZwReadFile [NTDLL.@]
314 * Read from an open file handle.
317 * FileHandle [I] Handle returned from ZwOpenFile() or ZwCreateFile()
318 * Event [I] Event to signal upon completion (or NULL)
319 * ApcRoutine [I] Callback to call upon completion (or NULL)
320 * ApcContext [I] Context for ApcRoutine (or NULL)
321 * IoStatusBlock [O] Receives information about the operation on return
322 * Buffer [O] Destination for the data read
323 * Length [I] Size of Buffer
324 * ByteOffset [O] Destination for the new file pointer position (or NULL)
325 * Key [O] Function unknown (may be NULL)
328 * Success: 0. IoStatusBlock is updated, and the Information member contains
329 * The number of bytes read.
330 * Failure: An NTSTATUS error code describing the error.
332 NTSTATUS WINAPI
NtReadFile(HANDLE hFile
, HANDLE hEvent
,
333 PIO_APC_ROUTINE apc
, void* apc_user
,
334 PIO_STATUS_BLOCK io_status
, void* buffer
, ULONG length
,
335 PLARGE_INTEGER offset
, PULONG key
)
337 int unix_handle
, flags
;
340 TRACE("(%p,%p,%p,%p,%p,%p,0x%08lx,%p,%p),partial stub!\n",
341 hFile
,hEvent
,apc
,apc_user
,io_status
,buffer
,length
,offset
,key
);
343 io_status
->Information
= 0;
344 io_status
->u
.Status
= wine_server_handle_to_fd( hFile
, GENERIC_READ
, &unix_handle
, &type
, &flags
);
345 if (io_status
->u
.Status
) return io_status
->u
.Status
;
347 if (flags
& FD_FLAG_RECV_SHUTDOWN
)
349 wine_server_release_fd( hFile
, unix_handle
);
350 return STATUS_PIPE_DISCONNECTED
;
353 if (flags
& FD_FLAG_TIMEOUT
)
357 /* this shouldn't happen, but check it */
358 FIXME("NIY-hEvent\n");
359 wine_server_release_fd( hFile
, unix_handle
);
360 return STATUS_NOT_IMPLEMENTED
;
362 io_status
->u
.Status
= NtCreateEvent(&hEvent
, SYNCHRONIZE
, NULL
, 0, 0);
363 if (io_status
->u
.Status
)
365 wine_server_release_fd( hFile
, unix_handle
);
366 return io_status
->u
.Status
;
370 if (flags
& (FD_FLAG_OVERLAPPED
|FD_FLAG_TIMEOUT
))
375 if (!(ovp
= RtlAllocateHeap(GetProcessHeap(), 0, sizeof(async_fileio
))))
377 wine_server_release_fd( hFile
, unix_handle
);
378 return STATUS_NO_MEMORY
;
380 ovp
->async
.ops
= (apc
? &fileio_async_ops
: &fileio_nocomp_async_ops
);
381 ovp
->async
.handle
= hFile
;
382 ovp
->async
.fd
= unix_handle
; /* FIXME */
383 ovp
->async
.type
= ASYNC_TYPE_READ
;
384 ovp
->async
.func
= FILE_AsyncReadService
;
385 ovp
->async
.event
= hEvent
;
386 ovp
->async
.iosb
= io_status
;
388 if ( offset
== NULL
)
392 ovp
->offset
= offset
->u
.LowPart
;
393 if (offset
->u
.HighPart
) FIXME("NIY-high part\n");
396 ovp
->apc_user
= apc_user
;
397 ovp
->buffer
= buffer
;
400 io_status
->Information
= 0;
401 ret
= register_new_async(&ovp
->async
);
402 if (ret
!= STATUS_SUCCESS
)
404 if (flags
& FD_FLAG_TIMEOUT
)
406 NtWaitForSingleObject(hEvent
, TRUE
, NULL
);
411 LARGE_INTEGER timeout
;
413 /* let some APC be run, this will read some already pending data */
414 timeout
.u
.LowPart
= timeout
.u
.HighPart
= 0;
415 NtDelayExecution( TRUE
, &timeout
);
417 return io_status
->u
.Status
;
424 /* return SMB_ReadFile(hFile, unix_handle, buffer, length, io_status); */
425 wine_server_release_fd( hFile
, unix_handle
);
426 return STATUS_INVALID_HANDLE
;
428 case FD_TYPE_DEFAULT
:
429 /* normal unix file */
433 FIXME("Unsupported type of fd %d\n", type
);
434 wine_server_release_fd( hFile
, unix_handle
);
435 return STATUS_INVALID_HANDLE
;
440 FILE_POSITION_INFORMATION fpi
;
442 fpi
.CurrentByteOffset
= *offset
;
443 io_status
->u
.Status
= NtSetInformationFile(hFile
, io_status
, &fpi
, sizeof(fpi
),
444 FilePositionInformation
);
445 if (io_status
->u
.Status
)
447 wine_server_release_fd( hFile
, unix_handle
);
448 return io_status
->u
.Status
;
451 /* code for synchronous reads */
452 while ((io_status
->Information
= read( unix_handle
, buffer
, length
)) == -1)
454 if ((errno
== EAGAIN
) || (errno
== EINTR
)) continue;
455 if (errno
== EFAULT
) FIXME( "EFAULT handling broken for now\n" );
456 io_status
->u
.Status
= FILE_GetNtStatus();
459 wine_server_release_fd( hFile
, unix_handle
);
460 return io_status
->u
.Status
;
463 /***********************************************************************
464 * FILE_AsyncWriteService (INTERNAL)
466 * This function is called while the client is waiting on the
467 * server, so we can't make any server calls here.
469 static void FILE_AsyncWriteService(struct async_private
*ovp
)
471 async_fileio
*fileio
= (async_fileio
*) ovp
;
472 PIO_STATUS_BLOCK io_status
= fileio
->async
.iosb
;
474 int already
= io_status
->Information
;
476 TRACE("(%p %p)\n",io_status
,fileio
->buffer
);
478 /* write some data (non-blocking) */
480 if ( fileio
->fd_type
== FD_TYPE_SOCKET
)
481 result
= write(ovp
->fd
, &fileio
->buffer
[already
], fileio
->count
- already
);
484 result
= pwrite(ovp
->fd
, &fileio
->buffer
[already
], fileio
->count
- already
,
485 fileio
->offset
+ already
);
486 if ((result
< 0) && (errno
== ESPIPE
))
487 result
= write(ovp
->fd
, &fileio
->buffer
[already
], fileio
->count
- already
);
490 if ((result
< 0) && ((errno
== EAGAIN
) || (errno
== EINTR
)))
492 io_status
->u
.Status
= STATUS_PENDING
;
496 /* check to see if the transfer is complete */
499 io_status
->u
.Status
= FILE_GetNtStatus();
503 io_status
->Information
+= result
;
504 io_status
->u
.Status
= (io_status
->Information
< fileio
->count
) ? STATUS_PENDING
: STATUS_SUCCESS
;
505 TRACE("wrote %d more bytes %ld/%d so far\n",result
,io_status
->Information
,fileio
->count
);
508 /******************************************************************************
509 * NtWriteFile [NTDLL.@]
510 * ZwWriteFile [NTDLL.@]
512 * Write to an open file handle.
515 * FileHandle [I] Handle returned from ZwOpenFile() or ZwCreateFile()
516 * Event [I] Event to signal upon completion (or NULL)
517 * ApcRoutine [I] Callback to call upon completion (or NULL)
518 * ApcContext [I] Context for ApcRoutine (or NULL)
519 * IoStatusBlock [O] Receives information about the operation on return
520 * Buffer [I] Source for the data to write
521 * Length [I] Size of Buffer
522 * ByteOffset [O] Destination for the new file pointer position (or NULL)
523 * Key [O] Function unknown (may be NULL)
526 * Success: 0. IoStatusBlock is updated, and the Information member contains
527 * The number of bytes written.
528 * Failure: An NTSTATUS error code describing the error.
530 NTSTATUS WINAPI
NtWriteFile(HANDLE hFile
, HANDLE hEvent
,
531 PIO_APC_ROUTINE apc
, void* apc_user
,
532 PIO_STATUS_BLOCK io_status
,
533 const void* buffer
, ULONG length
,
534 PLARGE_INTEGER offset
, PULONG key
)
536 int unix_handle
, flags
;
539 TRACE("(%p,%p,%p,%p,%p,%p,0x%08lx,%p,%p)!\n",
540 hFile
,hEvent
,apc
,apc_user
,io_status
,buffer
,length
,offset
,key
);
542 TRACE("(%p,%p,%p,%p,%p,%p,0x%08lx,%p,%p),partial stub!\n",
543 hFile
,hEvent
,apc
,apc_user
,io_status
,buffer
,length
,offset
,key
);
545 io_status
->Information
= 0;
546 io_status
->u
.Status
= wine_server_handle_to_fd( hFile
, GENERIC_WRITE
, &unix_handle
, &type
, &flags
);
547 if (io_status
->u
.Status
) return io_status
->u
.Status
;
549 if (flags
& FD_FLAG_SEND_SHUTDOWN
)
551 wine_server_release_fd( hFile
, unix_handle
);
552 return STATUS_PIPE_DISCONNECTED
;
555 if (flags
& (FD_FLAG_OVERLAPPED
|FD_FLAG_TIMEOUT
))
560 if (!(ovp
= RtlAllocateHeap(GetProcessHeap(), 0, sizeof(async_fileio
))))
562 wine_server_release_fd( hFile
, unix_handle
);
563 return STATUS_NO_MEMORY
;
565 ovp
->async
.ops
= (apc
? &fileio_async_ops
: &fileio_nocomp_async_ops
);
566 ovp
->async
.handle
= hFile
;
567 ovp
->async
.fd
= unix_handle
; /* FIXME */
568 ovp
->async
.type
= ASYNC_TYPE_WRITE
;
569 ovp
->async
.func
= FILE_AsyncWriteService
;
570 ovp
->async
.event
= hEvent
;
571 ovp
->async
.iosb
= io_status
;
574 ovp
->offset
= offset
->u
.LowPart
;
575 if (offset
->u
.HighPart
) FIXME("NIY-high part\n");
580 ovp
->apc_user
= apc_user
;
581 ovp
->buffer
= (void*)buffer
;
584 io_status
->Information
= 0;
585 ret
= register_new_async(&ovp
->async
);
586 if (ret
!= STATUS_SUCCESS
)
588 if (flags
& FD_FLAG_TIMEOUT
)
590 NtWaitForSingleObject(hEvent
, TRUE
, NULL
);
595 LARGE_INTEGER timeout
;
597 /* let some APC be run, this will write as much data as possible */
598 timeout
.u
.LowPart
= timeout
.u
.HighPart
= 0;
599 NtDelayExecution( TRUE
, &timeout
);
601 return io_status
->u
.Status
;
607 wine_server_release_fd( hFile
, unix_handle
);
608 return STATUS_NOT_IMPLEMENTED
;
610 case FD_TYPE_DEFAULT
:
611 /* normal unix files */
612 if (unix_handle
== -1) return STATUS_INVALID_HANDLE
;
616 FIXME("Unsupported type of fd %d\n", type
);
617 wine_server_release_fd( hFile
, unix_handle
);
618 return STATUS_INVALID_HANDLE
;
623 FILE_POSITION_INFORMATION fpi
;
625 fpi
.CurrentByteOffset
= *offset
;
626 io_status
->u
.Status
= NtSetInformationFile(hFile
, io_status
, &fpi
, sizeof(fpi
),
627 FilePositionInformation
);
628 if (io_status
->u
.Status
)
630 wine_server_release_fd( hFile
, unix_handle
);
631 return io_status
->u
.Status
;
635 /* synchronous file write */
636 while ((io_status
->Information
= write( unix_handle
, buffer
, length
)) == -1)
638 if ((errno
== EAGAIN
) || (errno
== EINTR
)) continue;
639 if (errno
== EFAULT
) FIXME( "EFAULT handling broken for now\n" );
640 if (errno
== ENOSPC
) io_status
->u
.Status
= STATUS_DISK_FULL
;
641 else io_status
->u
.Status
= FILE_GetNtStatus();
644 wine_server_release_fd( hFile
, unix_handle
);
645 return io_status
->u
.Status
;
648 /**************************************************************************
649 * NtDeviceIoControlFile [NTDLL.@]
650 * ZwDeviceIoControlFile [NTDLL.@]
652 * Perform an I/O control operation on an open file handle.
655 * DeviceHandle [I] Handle returned from ZwOpenFile() or ZwCreateFile()
656 * Event [I] Event to signal upon completion (or NULL)
657 * ApcRoutine [I] Callback to call upon completion (or NULL)
658 * ApcContext [I] Context for ApcRoutine (or NULL)
659 * IoStatusBlock [O] Receives information about the operation on return
660 * IoControlCode [I] Control code for the operation to perform
661 * InputBuffer [I] Source for any input data required (or NULL)
662 * InputBufferSize [I] Size of InputBuffer
663 * OutputBuffer [O] Source for any output data returned (or NULL)
664 * OutputBufferSize [I] Size of OutputBuffer
667 * Success: 0. IoStatusBlock is updated.
668 * Failure: An NTSTATUS error code describing the error.
670 NTSTATUS WINAPI
NtDeviceIoControlFile(HANDLE DeviceHandle
, HANDLE hEvent
,
671 PIO_APC_ROUTINE UserApcRoutine
,
672 PVOID UserApcContext
,
673 PIO_STATUS_BLOCK IoStatusBlock
,
676 ULONG InputBufferSize
,
678 ULONG OutputBufferSize
)
680 TRACE("(%p,%p,%p,%p,%p,0x%08lx,%p,0x%08lx,%p,0x%08lx)\n",
681 DeviceHandle
, hEvent
, UserApcRoutine
, UserApcContext
,
682 IoStatusBlock
, IoControlCode
,
683 InputBuffer
, InputBufferSize
, OutputBuffer
, OutputBufferSize
);
685 if (CDROM_DeviceIoControl(DeviceHandle
, hEvent
,
686 UserApcRoutine
, UserApcContext
,
687 IoStatusBlock
, IoControlCode
,
688 InputBuffer
, InputBufferSize
,
689 OutputBuffer
, OutputBufferSize
) == STATUS_NO_SUCH_DEVICE
)
691 /* it wasn't a CDROM */
692 FIXME("Unimplemented dwIoControlCode=%08lx\n", IoControlCode
);
693 IoStatusBlock
->u
.Status
= STATUS_NOT_IMPLEMENTED
;
694 IoStatusBlock
->Information
= 0;
695 if (hEvent
) NtSetEvent(hEvent
, NULL
);
697 return IoStatusBlock
->u
.Status
;
700 /******************************************************************************
701 * NtFsControlFile [NTDLL.@]
702 * ZwFsControlFile [NTDLL.@]
704 NTSTATUS WINAPI
NtFsControlFile(
705 IN HANDLE DeviceHandle
,
706 IN HANDLE Event OPTIONAL
,
707 IN PIO_APC_ROUTINE ApcRoutine OPTIONAL
,
708 IN PVOID ApcContext OPTIONAL
,
709 OUT PIO_STATUS_BLOCK IoStatusBlock
,
710 IN ULONG IoControlCode
,
711 IN PVOID InputBuffer
,
712 IN ULONG InputBufferSize
,
713 OUT PVOID OutputBuffer
,
714 IN ULONG OutputBufferSize
)
716 FIXME("(%p,%p,%p,%p,%p,0x%08lx,%p,0x%08lx,%p,0x%08lx): stub\n",
717 DeviceHandle
,Event
,ApcRoutine
,ApcContext
,IoStatusBlock
,IoControlCode
,
718 InputBuffer
,InputBufferSize
,OutputBuffer
,OutputBufferSize
);
722 /******************************************************************************
723 * NtSetVolumeInformationFile [NTDLL.@]
724 * ZwSetVolumeInformationFile [NTDLL.@]
726 * Set volume information for an open file handle.
729 * FileHandle [I] Handle returned from ZwOpenFile() or ZwCreateFile()
730 * IoStatusBlock [O] Receives information about the operation on return
731 * FsInformation [I] Source for volume information
732 * Length [I] Size of FsInformation
733 * FsInformationClass [I] Type of volume information to set
736 * Success: 0. IoStatusBlock is updated.
737 * Failure: An NTSTATUS error code describing the error.
739 NTSTATUS WINAPI
NtSetVolumeInformationFile(
740 IN HANDLE FileHandle
,
741 PIO_STATUS_BLOCK IoStatusBlock
,
744 FS_INFORMATION_CLASS FsInformationClass
)
746 FIXME("(%p,%p,%p,0x%08lx,0x%08x) stub\n",
747 FileHandle
,IoStatusBlock
,FsInformation
,Length
,FsInformationClass
);
751 /******************************************************************************
752 * NtQueryInformationFile [NTDLL.@]
753 * ZwQueryInformationFile [NTDLL.@]
755 * Get information about an open file handle.
758 * hFile [I] Handle returned from ZwOpenFile() or ZwCreateFile()
759 * io [O] Receives information about the operation on return
760 * ptr [O] Destination for file information
761 * len [I] Size of FileInformation
762 * class [I] Type of file information to get
765 * Success: 0. IoStatusBlock and FileInformation are updated.
766 * Failure: An NTSTATUS error code describing the error.
768 NTSTATUS WINAPI
NtQueryInformationFile( HANDLE hFile
, PIO_STATUS_BLOCK io
,
769 PVOID ptr
, LONG len
, FILE_INFORMATION_CLASS
class )
773 TRACE("(%p,%p,%p,0x%08lx,0x%08x)\n", hFile
, io
, ptr
, len
, class);
776 if ((io
->u
.Status
= wine_server_handle_to_fd( hFile
, 0, &fd
, NULL
, NULL
)))
781 case FileBasicInformation
:
783 FILE_BASIC_INFORMATION
*info
= ptr
;
785 if (len
< sizeof(*info
)) io
->u
.Status
= STATUS_INFO_LENGTH_MISMATCH
;
790 if (fstat( fd
, &st
) == -1)
791 io
->u
.Status
= FILE_GetNtStatus();
792 else if (!S_ISREG(st
.st_mode
) && !S_ISDIR(st
.st_mode
))
793 io
->u
.Status
= STATUS_INVALID_INFO_CLASS
;
796 if (S_ISDIR(st
.st_mode
)) info
->FileAttributes
= FILE_ATTRIBUTE_DIRECTORY
;
797 else info
->FileAttributes
= FILE_ATTRIBUTE_ARCHIVE
;
798 if (!(st
.st_mode
& S_IWUSR
)) info
->FileAttributes
|= FILE_ATTRIBUTE_READONLY
;
799 RtlSecondsSince1970ToTime( st
.st_mtime
, &info
->CreationTime
);
800 RtlSecondsSince1970ToTime( st
.st_mtime
, &info
->LastWriteTime
);
801 RtlSecondsSince1970ToTime( st
.st_ctime
, &info
->ChangeTime
);
802 RtlSecondsSince1970ToTime( st
.st_atime
, &info
->LastAccessTime
);
807 case FileStandardInformation
:
809 FILE_STANDARD_INFORMATION
*info
= ptr
;
811 if (len
< sizeof(*info
)) io
->u
.Status
= STATUS_INFO_LENGTH_MISMATCH
;
816 if (fstat( fd
, &st
) == -1) io
->u
.Status
= FILE_GetNtStatus();
819 if ((info
->Directory
= S_ISDIR(st
.st_mode
)))
821 info
->AllocationSize
.QuadPart
= 0;
822 info
->EndOfFile
.QuadPart
= 0;
823 info
->NumberOfLinks
= 1;
824 info
->DeletePending
= FALSE
;
828 info
->AllocationSize
.QuadPart
= (ULONGLONG
)st
.st_blocks
* 512;
829 info
->EndOfFile
.QuadPart
= st
.st_size
;
830 info
->NumberOfLinks
= st
.st_nlink
;
831 info
->DeletePending
= FALSE
; /* FIXME */
833 io
->Information
= sizeof(*info
);
838 case FilePositionInformation
:
840 FILE_POSITION_INFORMATION
*info
= ptr
;
842 if (len
< sizeof(*info
)) io
->u
.Status
= STATUS_INFO_LENGTH_MISMATCH
;
845 off_t res
= lseek( fd
, 0, SEEK_CUR
);
846 if (res
== (off_t
)-1) io
->u
.Status
= FILE_GetNtStatus();
849 info
->CurrentByteOffset
.QuadPart
= res
;
850 io
->Information
= sizeof(*info
);
856 FIXME("Unsupported class (%d)\n", class);
857 io
->u
.Status
= STATUS_NOT_IMPLEMENTED
;
860 wine_server_release_fd( hFile
, fd
);
864 /******************************************************************************
865 * NtSetInformationFile [NTDLL.@]
866 * ZwSetInformationFile [NTDLL.@]
868 * Set information about an open file handle.
871 * FileHandle [I] Handle returned from ZwOpenFile() or ZwCreateFile()
872 * IoStatusBlock [O] Receives information about the operation on return
873 * FileInformation [I] Source for file information
874 * Length [I] Size of FileInformation
875 * FileInformationClass [I] Type of file information to set
878 * Success: 0. IoStatusBlock is updated.
879 * Failure: An NTSTATUS error code describing the error.
881 NTSTATUS WINAPI
NtSetInformationFile(HANDLE hFile
, PIO_STATUS_BLOCK io_status
,
882 PVOID ptr
, ULONG len
,
883 FILE_INFORMATION_CLASS
class)
885 NTSTATUS status
= STATUS_INVALID_PARAMETER_3
;
887 TRACE("(%p,%p,%p,0x%08lx,0x%08x)\n", hFile
, io_status
, ptr
, len
, class);
891 case FilePositionInformation
:
892 if (len
>= sizeof(FILE_POSITION_INFORMATION
))
895 FILE_POSITION_INFORMATION
* fpi
= (FILE_POSITION_INFORMATION
*)ptr
;
897 if (!(status
= wine_server_handle_to_fd( hFile
, 0, &fd
, NULL
, NULL
)))
899 if (lseek( fd
, fpi
->CurrentByteOffset
.QuadPart
, SEEK_SET
) == (off_t
)-1)
900 status
= FILE_GetNtStatus();
901 wine_server_release_fd( hFile
, fd
);
906 FIXME("Unsupported class (%d)\n", class);
907 return STATUS_NOT_IMPLEMENTED
;
909 io_status
->u
.Status
= status
;
910 io_status
->Information
= 0;
915 /******************************************************************************
916 * NtQueryVolumeInformationFile [NTDLL.@]
917 * ZwQueryVolumeInformationFile [NTDLL.@]
919 * Get volume information for an open file handle.
922 * handle [I] Handle returned from ZwOpenFile() or ZwCreateFile()
923 * io [O] Receives information about the operation on return
924 * buffer [O] Destination for volume information
925 * length [I] Size of FsInformation
926 * info_class [I] Type of volume information to set
929 * Success: 0. io and buffer are updated.
930 * Failure: An NTSTATUS error code describing the error.
932 NTSTATUS WINAPI
NtQueryVolumeInformationFile( HANDLE handle
, PIO_STATUS_BLOCK io
,
933 PVOID buffer
, ULONG length
,
934 FS_INFORMATION_CLASS info_class
)
939 if ((io
->u
.Status
= wine_server_handle_to_fd( handle
, 0, &fd
, NULL
, NULL
)) != STATUS_SUCCESS
)
942 io
->u
.Status
= STATUS_NOT_IMPLEMENTED
;
947 case FileFsVolumeInformation
:
948 FIXME( "%p: volume info not supported\n", handle
);
950 case FileFsLabelInformation
:
951 FIXME( "%p: label info not supported\n", handle
);
953 case FileFsSizeInformation
:
954 if (length
< sizeof(FILE_FS_SIZE_INFORMATION
))
955 io
->u
.Status
= STATUS_BUFFER_TOO_SMALL
;
958 FILE_FS_SIZE_INFORMATION
*info
= buffer
;
959 struct statvfs stvfs
;
961 if (fstat( fd
, &st
) < 0)
963 io
->u
.Status
= FILE_GetNtStatus();
966 if (!S_ISREG(st
.st_mode
) && !S_ISDIR(st
.st_mode
))
968 io
->u
.Status
= STATUS_INVALID_DEVICE_REQUEST
;
971 if (fstatvfs( fd
, &stvfs
) < 0) io
->u
.Status
= FILE_GetNtStatus();
974 info
->TotalAllocationUnits
.QuadPart
= stvfs
.f_blocks
;
975 info
->AvailableAllocationUnits
.QuadPart
= stvfs
.f_bavail
;
976 info
->SectorsPerAllocationUnit
= 1;
977 info
->BytesPerSector
= stvfs
.f_frsize
;
978 io
->Information
= sizeof(*info
);
979 io
->u
.Status
= STATUS_SUCCESS
;
983 case FileFsDeviceInformation
:
984 if (length
< sizeof(FILE_FS_DEVICE_INFORMATION
))
985 io
->u
.Status
= STATUS_BUFFER_TOO_SMALL
;
988 FILE_FS_DEVICE_INFORMATION
*info
= buffer
;
990 #if defined(linux) && defined(HAVE_FSTATFS)
993 info
->Characteristics
= 0;
995 if (fstat( fd
, &st
) < 0)
997 io
->u
.Status
= FILE_GetNtStatus();
1000 if (S_ISCHR( st
.st_mode
))
1002 switch(major(st
.st_rdev
))
1005 info
->DeviceType
= FILE_DEVICE_NULL
;
1008 info
->DeviceType
= FILE_DEVICE_SERIAL_PORT
;
1011 info
->DeviceType
= FILE_DEVICE_PARALLEL_PORT
;
1014 info
->DeviceType
= FILE_DEVICE_UNKNOWN
;
1018 else if (S_ISBLK( st
.st_mode
))
1020 info
->DeviceType
= FILE_DEVICE_DISK
;
1022 else if (S_ISFIFO( st
.st_mode
) || S_ISSOCK( st
.st_mode
))
1024 info
->DeviceType
= FILE_DEVICE_NAMED_PIPE
;
1026 else /* regular file or directory */
1028 info
->Characteristics
|= FILE_DEVICE_IS_MOUNTED
;
1030 /* check for floppy disk */
1031 if (major(st
.st_dev
) == FLOPPY_MAJOR
)
1032 info
->Characteristics
|= FILE_REMOVABLE_MEDIA
;
1034 if (fstatfs( fd
, &stfs
) < 0) stfs
.f_type
= 0;
1035 switch (stfs
.f_type
)
1037 case 0x9660: /* iso9660 */
1038 case 0x15013346: /* udf */
1039 info
->DeviceType
= FILE_DEVICE_CD_ROM_FILE_SYSTEM
;
1040 info
->Characteristics
|= FILE_REMOVABLE_MEDIA
|FILE_READ_ONLY_DEVICE
;
1042 case 0x6969: /* nfs */
1043 case 0x517B: /* smbfs */
1044 case 0x564c: /* ncpfs */
1045 info
->DeviceType
= FILE_DEVICE_NETWORK_FILE_SYSTEM
;
1046 info
->Characteristics
|= FILE_REMOTE_DEVICE
;
1048 case 0x01021994: /* tmpfs */
1049 case 0x28cd3d45: /* cramfs */
1050 case 0x1373: /* devfs */
1051 case 0x9fa0: /* procfs */
1052 info
->DeviceType
= FILE_DEVICE_VIRTUAL_DISK
;
1055 info
->DeviceType
= FILE_DEVICE_DISK_FILE_SYSTEM
;
1061 if (!warned
++) FIXME( "device info not supported on this platform\n" );
1062 info
->DeviceType
= FILE_DEVICE_DISK_FILE_SYSTEM
;
1063 info
->Characteristics
= 0;
1065 io
->Information
= sizeof(*info
);
1066 io
->u
.Status
= STATUS_SUCCESS
;
1069 case FileFsAttributeInformation
:
1070 FIXME( "%p: attribute info not supported\n", handle
);
1072 case FileFsControlInformation
:
1073 FIXME( "%p: control info not supported\n", handle
);
1075 case FileFsFullSizeInformation
:
1076 FIXME( "%p: full size info not supported\n", handle
);
1078 case FileFsObjectIdInformation
:
1079 FIXME( "%p: object id info not supported\n", handle
);
1081 case FileFsMaximumInformation
:
1082 FIXME( "%p: maximum info not supported\n", handle
);
1085 io
->u
.Status
= STATUS_INVALID_PARAMETER
;
1088 wine_server_release_fd( handle
, fd
);
1089 return io
->u
.Status
;
1093 /******************************************************************
1094 * NtFlushBuffersFile (NTDLL.@)
1096 * Flush any buffered data on an open file handle.
1099 * FileHandle [I] Handle returned from ZwOpenFile() or ZwCreateFile()
1100 * IoStatusBlock [O] Receives information about the operation on return
1103 * Success: 0. IoStatusBlock is updated.
1104 * Failure: An NTSTATUS error code describing the error.
1106 NTSTATUS WINAPI
NtFlushBuffersFile( HANDLE hFile
, IO_STATUS_BLOCK
* IoStatusBlock
)
1109 HANDLE hEvent
= NULL
;
1111 SERVER_START_REQ( flush_file
)
1113 req
->handle
= hFile
;
1114 ret
= wine_server_call( req
);
1115 hEvent
= reply
->event
;
1120 ret
= NtWaitForSingleObject( hEvent
, FALSE
, NULL
);
1126 /******************************************************************
1127 * NtLockFile (NTDLL.@)
1131 NTSTATUS WINAPI
NtLockFile( HANDLE hFile
, HANDLE lock_granted_event
,
1132 PIO_APC_ROUTINE apc
, void* apc_user
,
1133 PIO_STATUS_BLOCK io_status
, PLARGE_INTEGER offset
,
1134 PLARGE_INTEGER count
, ULONG
* key
, BOOLEAN dont_wait
,
1141 if (apc
|| io_status
|| key
)
1143 FIXME("Unimplemented yet parameter\n");
1144 return STATUS_NOT_IMPLEMENTED
;
1149 SERVER_START_REQ( lock_file
)
1151 req
->handle
= hFile
;
1152 req
->offset_low
= offset
->u
.LowPart
;
1153 req
->offset_high
= offset
->u
.HighPart
;
1154 req
->count_low
= count
->u
.LowPart
;
1155 req
->count_high
= count
->u
.HighPart
;
1156 req
->shared
= !exclusive
;
1157 req
->wait
= !dont_wait
;
1158 ret
= wine_server_call( req
);
1159 handle
= reply
->handle
;
1160 async
= reply
->overlapped
;
1163 if (ret
!= STATUS_PENDING
)
1165 if (!ret
&& lock_granted_event
) NtSetEvent(lock_granted_event
, NULL
);
1171 FIXME( "Async I/O lock wait not implemented, might deadlock\n" );
1172 if (handle
) NtClose( handle
);
1173 return STATUS_PENDING
;
1177 NtWaitForSingleObject( handle
, FALSE
, NULL
);
1184 /* Unix lock conflict, sleep a bit and retry */
1185 time
.QuadPart
= 100 * (ULONGLONG
)10000;
1186 time
.QuadPart
= -time
.QuadPart
;
1187 NtDelayExecution( FALSE
, &time
);
1193 /******************************************************************
1194 * NtUnlockFile (NTDLL.@)
1198 NTSTATUS WINAPI
NtUnlockFile( HANDLE hFile
, PIO_STATUS_BLOCK io_status
,
1199 PLARGE_INTEGER offset
, PLARGE_INTEGER count
,
1204 TRACE( "%p %lx%08lx %lx%08lx\n",
1205 hFile
, offset
->u
.HighPart
, offset
->u
.LowPart
, count
->u
.HighPart
, count
->u
.LowPart
);
1207 if (io_status
|| key
)
1209 FIXME("Unimplemented yet parameter\n");
1210 return STATUS_NOT_IMPLEMENTED
;
1213 SERVER_START_REQ( unlock_file
)
1215 req
->handle
= hFile
;
1216 req
->offset_low
= offset
->u
.LowPart
;
1217 req
->offset_high
= offset
->u
.HighPart
;
1218 req
->count_low
= count
->u
.LowPart
;
1219 req
->count_high
= count
->u
.HighPart
;
1220 status
= wine_server_call( req
);