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] 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
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
;
254 static DWORD
fileio_get_async_count(const struct async_private
*ovp
)
256 const async_fileio
*fileio
= (const async_fileio
*) ovp
;
258 if (fileio
->count
< fileio
->async
.iosb
->Information
)
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)
288 TRACE( "errno = %d\n", errno
);
291 case EAGAIN
: return STATUS_SHARING_VIOLATION
;
292 case EBADF
: return STATUS_INVALID_HANDLE
;
293 case ENOSPC
: return STATUS_DISK_FULL
;
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
;
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
;
307 case ENOMEDIUM
: return STATUS_NO_MEDIA_IN_DEVICE
;
310 case EOPNOTSUPP
:return STATUS_NOT_SUPPORTED
;
311 case ENOEXEC
: /* ?? */
312 case ESPIPE
: /* ?? */
313 case EEXIST
: /* ?? */
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
;
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
->avail_mode
)
338 result
= read(ovp
->fd
, &fileio
->buffer
[already
], fileio
->count
- already
);
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
;
354 /* check to see if the transfer is complete */
357 io_status
->u
.Status
= FILE_GetNtStatus();
360 else if (result
== 0)
362 io_status
->u
.Status
= io_status
->Information
? STATUS_SUCCESS
: STATUS_END_OF_FILE
;
366 TRACE("status before: %s\n", (io_status
->u
.Status
== STATUS_SUCCESS
) ? "success" : "pending");
367 io_status
->Information
+= result
;
368 if (io_status
->Information
>= fileio
->count
|| fileio
->avail_mode
)
369 io_status
->u
.Status
= STATUS_SUCCESS
;
371 io_status
->u
.Status
= STATUS_PENDING
;
373 TRACE("read %d more bytes %ld/%d so far (%s)\n",
374 result
, io_status
->Information
, fileio
->count
, (io_status
->u
.Status
== STATUS_SUCCESS
) ? "success" : "pending");
378 /******************************************************************************
379 * NtReadFile [NTDLL.@]
380 * ZwReadFile [NTDLL.@]
382 * Read from an open file handle.
385 * FileHandle [I] Handle returned from ZwOpenFile() or ZwCreateFile()
386 * Event [I] Event to signal upon completion (or NULL)
387 * ApcRoutine [I] Callback to call upon completion (or NULL)
388 * ApcContext [I] Context for ApcRoutine (or NULL)
389 * IoStatusBlock [O] Receives information about the operation on return
390 * Buffer [O] Destination for the data read
391 * Length [I] Size of Buffer
392 * ByteOffset [O] Destination for the new file pointer position (or NULL)
393 * Key [O] Function unknown (may be NULL)
396 * Success: 0. IoStatusBlock is updated, and the Information member contains
397 * The number of bytes read.
398 * Failure: An NTSTATUS error code describing the error.
400 NTSTATUS WINAPI
NtReadFile(HANDLE hFile
, HANDLE hEvent
,
401 PIO_APC_ROUTINE apc
, void* apc_user
,
402 PIO_STATUS_BLOCK io_status
, void* buffer
, ULONG length
,
403 PLARGE_INTEGER offset
, PULONG key
)
405 int unix_handle
, flags
;
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
, &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
)
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
))
442 if (!(ovp
= RtlAllocateHeap(GetProcessHeap(), 0, sizeof(async_fileio
))))
444 wine_server_release_fd( hFile
, unix_handle
);
445 if (flags
& FD_FLAG_TIMEOUT
) NtClose(hEvent
);
446 return STATUS_NO_MEMORY
;
448 ovp
->async
.ops
= (apc
? &fileio_async_ops
: &fileio_nocomp_async_ops
);
449 ovp
->async
.handle
= hFile
;
450 ovp
->async
.fd
= unix_handle
; /* FIXME */
451 ovp
->async
.type
= ASYNC_TYPE_READ
;
452 ovp
->async
.func
= FILE_AsyncReadService
;
453 ovp
->async
.event
= hEvent
;
454 ovp
->async
.iosb
= io_status
;
456 if ( offset
== NULL
)
460 ovp
->offset
= offset
->QuadPart
;
461 if (offset
->u
.HighPart
&& ovp
->offset
== offset
->u
.LowPart
)
462 FIXME("High part of offset is lost\n");
465 ovp
->apc_user
= apc_user
;
466 ovp
->buffer
= buffer
;
467 ovp
->avail_mode
= (flags
& FD_FLAG_AVAILABLE
);
468 NtResetEvent(hEvent
, NULL
);
470 ret
= register_new_async(&ovp
->async
);
471 if (ret
!= STATUS_SUCCESS
)
473 wine_server_release_fd( hFile
, unix_handle
);
474 if (flags
& FD_FLAG_TIMEOUT
) NtClose(hEvent
);
475 RtlFreeHeap(GetProcessHeap(), 0, ovp
);
478 if (flags
& FD_FLAG_TIMEOUT
)
480 NtWaitForSingleObject(hEvent
, TRUE
, NULL
);
485 LARGE_INTEGER timeout
;
487 /* let some APC be run, this will read some already pending data */
488 timeout
.u
.LowPart
= timeout
.u
.HighPart
= 0;
489 NtDelayExecution( TRUE
, &timeout
);
490 /* if we only have to read the available data, and none is available,
491 * simply cancel the request. If data was available, it has been read
492 * while in by previous call (NtDelayExecution)
494 if ((flags
& FD_FLAG_AVAILABLE
) && io_status
->u
.Status
== STATUS_PENDING
)
496 io_status
->u
.Status
= STATUS_SUCCESS
;
497 register_old_async(&ovp
->async
);
500 return io_status
->u
.Status
;
505 FILE_POSITION_INFORMATION fpi
;
507 fpi
.CurrentByteOffset
= *offset
;
508 io_status
->u
.Status
= NtSetInformationFile(hFile
, io_status
, &fpi
, sizeof(fpi
),
509 FilePositionInformation
);
510 if (io_status
->u
.Status
)
512 wine_server_release_fd( hFile
, unix_handle
);
513 return io_status
->u
.Status
;
516 /* code for synchronous reads */
517 while ((io_status
->Information
= read( unix_handle
, buffer
, length
)) == -1)
519 if ((errno
== EAGAIN
) || (errno
== EINTR
)) continue;
520 if (errno
== EFAULT
) FIXME( "EFAULT handling broken for now\n" );
521 io_status
->u
.Status
= FILE_GetNtStatus();
524 wine_server_release_fd( hFile
, unix_handle
);
525 return io_status
->u
.Status
;
528 /***********************************************************************
529 * FILE_AsyncWriteService (INTERNAL)
531 * This function is called while the client is waiting on the
532 * server, so we can't make any server calls here.
534 static void FILE_AsyncWriteService(struct async_private
*ovp
)
536 async_fileio
*fileio
= (async_fileio
*) ovp
;
537 PIO_STATUS_BLOCK io_status
= fileio
->async
.iosb
;
539 int already
= io_status
->Information
;
541 TRACE("(%p %p)\n",io_status
,fileio
->buffer
);
543 /* write some data (non-blocking) */
545 if ( fileio
->avail_mode
)
546 result
= write(ovp
->fd
, &fileio
->buffer
[already
], fileio
->count
- already
);
549 result
= pwrite(ovp
->fd
, &fileio
->buffer
[already
], fileio
->count
- already
,
550 fileio
->offset
+ already
);
551 if ((result
< 0) && (errno
== ESPIPE
))
552 result
= write(ovp
->fd
, &fileio
->buffer
[already
], fileio
->count
- already
);
555 if ((result
< 0) && ((errno
== EAGAIN
) || (errno
== EINTR
)))
557 io_status
->u
.Status
= STATUS_PENDING
;
561 /* check to see if the transfer is complete */
564 io_status
->u
.Status
= FILE_GetNtStatus();
568 io_status
->Information
+= result
;
569 io_status
->u
.Status
= (io_status
->Information
< fileio
->count
) ? STATUS_PENDING
: STATUS_SUCCESS
;
570 TRACE("wrote %d more bytes %ld/%d so far\n",result
,io_status
->Information
,fileio
->count
);
573 /******************************************************************************
574 * NtWriteFile [NTDLL.@]
575 * ZwWriteFile [NTDLL.@]
577 * Write to an open file handle.
580 * FileHandle [I] Handle returned from ZwOpenFile() or ZwCreateFile()
581 * Event [I] Event to signal upon completion (or NULL)
582 * ApcRoutine [I] Callback to call upon completion (or NULL)
583 * ApcContext [I] Context for ApcRoutine (or NULL)
584 * IoStatusBlock [O] Receives information about the operation on return
585 * Buffer [I] Source for the data to write
586 * Length [I] Size of Buffer
587 * ByteOffset [O] Destination for the new file pointer position (or NULL)
588 * Key [O] Function unknown (may be NULL)
591 * Success: 0. IoStatusBlock is updated, and the Information member contains
592 * The number of bytes written.
593 * Failure: An NTSTATUS error code describing the error.
595 NTSTATUS WINAPI
NtWriteFile(HANDLE hFile
, HANDLE hEvent
,
596 PIO_APC_ROUTINE apc
, void* apc_user
,
597 PIO_STATUS_BLOCK io_status
,
598 const void* buffer
, ULONG length
,
599 PLARGE_INTEGER offset
, PULONG key
)
601 int unix_handle
, flags
;
603 TRACE("(%p,%p,%p,%p,%p,%p,0x%08lx,%p,%p)!\n",
604 hFile
,hEvent
,apc
,apc_user
,io_status
,buffer
,length
,offset
,key
);
606 io_status
->Information
= 0;
607 io_status
->u
.Status
= wine_server_handle_to_fd( hFile
, GENERIC_WRITE
, &unix_handle
, &flags
);
608 if (io_status
->u
.Status
) return io_status
->u
.Status
;
610 if (flags
& FD_FLAG_SEND_SHUTDOWN
)
612 wine_server_release_fd( hFile
, unix_handle
);
613 return STATUS_PIPE_DISCONNECTED
;
616 if (flags
& (FD_FLAG_OVERLAPPED
|FD_FLAG_TIMEOUT
))
621 if (!(ovp
= RtlAllocateHeap(GetProcessHeap(), 0, sizeof(async_fileio
))))
623 wine_server_release_fd( hFile
, unix_handle
);
624 return STATUS_NO_MEMORY
;
626 ovp
->async
.ops
= (apc
? &fileio_async_ops
: &fileio_nocomp_async_ops
);
627 ovp
->async
.handle
= hFile
;
628 ovp
->async
.fd
= unix_handle
; /* FIXME */
629 ovp
->async
.type
= ASYNC_TYPE_WRITE
;
630 ovp
->async
.func
= FILE_AsyncWriteService
;
631 ovp
->async
.event
= hEvent
;
632 ovp
->async
.iosb
= io_status
;
635 ovp
->offset
= offset
->QuadPart
;
636 if (offset
->u
.HighPart
&& ovp
->offset
== offset
->u
.LowPart
)
637 FIXME("High part of offset is lost\n");
642 ovp
->apc_user
= apc_user
;
643 ovp
->buffer
= (void*)buffer
;
644 ovp
->avail_mode
= (flags
& FD_FLAG_AVAILABLE
);
645 NtResetEvent(hEvent
, NULL
);
647 io_status
->Information
= 0;
648 ret
= register_new_async(&ovp
->async
);
649 if (ret
!= STATUS_SUCCESS
)
651 if (flags
& FD_FLAG_TIMEOUT
)
653 NtWaitForSingleObject(hEvent
, TRUE
, NULL
);
658 LARGE_INTEGER timeout
;
660 /* let some APC be run, this will write as much data as possible */
661 timeout
.u
.LowPart
= timeout
.u
.HighPart
= 0;
662 NtDelayExecution( TRUE
, &timeout
);
664 return io_status
->u
.Status
;
669 FILE_POSITION_INFORMATION fpi
;
671 fpi
.CurrentByteOffset
= *offset
;
672 io_status
->u
.Status
= NtSetInformationFile(hFile
, io_status
, &fpi
, sizeof(fpi
),
673 FilePositionInformation
);
674 if (io_status
->u
.Status
)
676 wine_server_release_fd( hFile
, unix_handle
);
677 return io_status
->u
.Status
;
681 /* synchronous file write */
682 while ((io_status
->Information
= write( unix_handle
, buffer
, length
)) == -1)
684 if ((errno
== EAGAIN
) || (errno
== EINTR
)) continue;
685 if (errno
== EFAULT
) FIXME( "EFAULT handling broken for now\n" );
686 if (errno
== ENOSPC
) io_status
->u
.Status
= STATUS_DISK_FULL
;
687 else io_status
->u
.Status
= FILE_GetNtStatus();
690 wine_server_release_fd( hFile
, unix_handle
);
691 return io_status
->u
.Status
;
694 /**************************************************************************
695 * NtDeviceIoControlFile [NTDLL.@]
696 * ZwDeviceIoControlFile [NTDLL.@]
698 * Perform an I/O control operation on an open file handle.
701 * DeviceHandle [I] Handle returned from ZwOpenFile() or ZwCreateFile()
702 * Event [I] Event to signal upon completion (or NULL)
703 * ApcRoutine [I] Callback to call upon completion (or NULL)
704 * ApcContext [I] Context for ApcRoutine (or NULL)
705 * IoStatusBlock [O] Receives information about the operation on return
706 * IoControlCode [I] Control code for the operation to perform
707 * InputBuffer [I] Source for any input data required (or NULL)
708 * InputBufferSize [I] Size of InputBuffer
709 * OutputBuffer [O] Source for any output data returned (or NULL)
710 * OutputBufferSize [I] Size of OutputBuffer
713 * Success: 0. IoStatusBlock is updated.
714 * Failure: An NTSTATUS error code describing the error.
716 NTSTATUS WINAPI
NtDeviceIoControlFile(HANDLE DeviceHandle
, HANDLE hEvent
,
717 PIO_APC_ROUTINE UserApcRoutine
,
718 PVOID UserApcContext
,
719 PIO_STATUS_BLOCK IoStatusBlock
,
722 ULONG InputBufferSize
,
724 ULONG OutputBufferSize
)
726 TRACE("(%p,%p,%p,%p,%p,0x%08lx,%p,0x%08lx,%p,0x%08lx)\n",
727 DeviceHandle
, hEvent
, UserApcRoutine
, UserApcContext
,
728 IoStatusBlock
, IoControlCode
,
729 InputBuffer
, InputBufferSize
, OutputBuffer
, OutputBufferSize
);
731 if (CDROM_DeviceIoControl(DeviceHandle
, hEvent
,
732 UserApcRoutine
, UserApcContext
,
733 IoStatusBlock
, IoControlCode
,
734 InputBuffer
, InputBufferSize
,
735 OutputBuffer
, OutputBufferSize
) == STATUS_NO_SUCH_DEVICE
)
737 /* it wasn't a CDROM */
738 FIXME("Unimplemented dwIoControlCode=%08lx\n", IoControlCode
);
739 IoStatusBlock
->u
.Status
= STATUS_NOT_IMPLEMENTED
;
740 IoStatusBlock
->Information
= 0;
741 if (hEvent
) NtSetEvent(hEvent
, NULL
);
743 return IoStatusBlock
->u
.Status
;
746 /******************************************************************************
747 * NtFsControlFile [NTDLL.@]
748 * ZwFsControlFile [NTDLL.@]
750 NTSTATUS WINAPI
NtFsControlFile(
751 IN HANDLE DeviceHandle
,
752 IN HANDLE Event OPTIONAL
,
753 IN PIO_APC_ROUTINE ApcRoutine OPTIONAL
,
754 IN PVOID ApcContext OPTIONAL
,
755 OUT PIO_STATUS_BLOCK IoStatusBlock
,
756 IN ULONG IoControlCode
,
757 IN PVOID InputBuffer
,
758 IN ULONG InputBufferSize
,
759 OUT PVOID OutputBuffer
,
760 IN ULONG OutputBufferSize
)
762 FIXME("(%p,%p,%p,%p,%p,0x%08lx,%p,0x%08lx,%p,0x%08lx): stub\n",
763 DeviceHandle
,Event
,ApcRoutine
,ApcContext
,IoStatusBlock
,IoControlCode
,
764 InputBuffer
,InputBufferSize
,OutputBuffer
,OutputBufferSize
);
768 /******************************************************************************
769 * NtSetVolumeInformationFile [NTDLL.@]
770 * ZwSetVolumeInformationFile [NTDLL.@]
772 * Set volume information for an open file handle.
775 * FileHandle [I] Handle returned from ZwOpenFile() or ZwCreateFile()
776 * IoStatusBlock [O] Receives information about the operation on return
777 * FsInformation [I] Source for volume information
778 * Length [I] Size of FsInformation
779 * FsInformationClass [I] Type of volume information to set
782 * Success: 0. IoStatusBlock is updated.
783 * Failure: An NTSTATUS error code describing the error.
785 NTSTATUS WINAPI
NtSetVolumeInformationFile(
786 IN HANDLE FileHandle
,
787 PIO_STATUS_BLOCK IoStatusBlock
,
790 FS_INFORMATION_CLASS FsInformationClass
)
792 FIXME("(%p,%p,%p,0x%08lx,0x%08x) stub\n",
793 FileHandle
,IoStatusBlock
,FsInformation
,Length
,FsInformationClass
);
797 /******************************************************************************
798 * NtQueryInformationFile [NTDLL.@]
799 * ZwQueryInformationFile [NTDLL.@]
801 * Get information about an open file handle.
804 * hFile [I] Handle returned from ZwOpenFile() or ZwCreateFile()
805 * io [O] Receives information about the operation on return
806 * ptr [O] Destination for file information
807 * len [I] Size of FileInformation
808 * class [I] Type of file information to get
811 * Success: 0. IoStatusBlock and FileInformation are updated.
812 * Failure: An NTSTATUS error code describing the error.
814 NTSTATUS WINAPI
NtQueryInformationFile( HANDLE hFile
, PIO_STATUS_BLOCK io
,
815 PVOID ptr
, LONG len
, FILE_INFORMATION_CLASS
class )
817 static const size_t info_sizes
[] =
820 sizeof(FILE_DIRECTORY_INFORMATION
), /* FileDirectoryInformation */
821 sizeof(FILE_FULL_DIRECTORY_INFORMATION
), /* FileFullDirectoryInformation */
822 sizeof(FILE_BOTH_DIRECTORY_INFORMATION
), /* FileBothDirectoryInformation */
823 sizeof(FILE_BASIC_INFORMATION
), /* FileBasicInformation */
824 sizeof(FILE_STANDARD_INFORMATION
), /* FileStandardInformation */
825 sizeof(FILE_INTERNAL_INFORMATION
), /* FileInternalInformation */
826 sizeof(FILE_EA_INFORMATION
), /* FileEaInformation */
827 sizeof(FILE_ACCESS_INFORMATION
), /* FileAccessInformation */
828 sizeof(FILE_NAME_INFORMATION
)-sizeof(WCHAR
), /* FileNameInformation */
829 sizeof(FILE_RENAME_INFORMATION
)-sizeof(WCHAR
), /* FileRenameInformation */
830 0, /* FileLinkInformation */
831 sizeof(FILE_NAMES_INFORMATION
)-sizeof(WCHAR
), /* FileNamesInformation */
832 sizeof(FILE_DISPOSITION_INFORMATION
), /* FileDispositionInformation */
833 sizeof(FILE_POSITION_INFORMATION
), /* FilePositionInformation */
834 sizeof(FILE_FULL_EA_INFORMATION
), /* FileFullEaInformation */
835 sizeof(FILE_MODE_INFORMATION
), /* FileModeInformation */
836 sizeof(FILE_ALIGNMENT_INFORMATION
), /* FileAlignmentInformation */
837 sizeof(FILE_ALL_INFORMATION
)-sizeof(WCHAR
), /* FileAllInformation */
838 sizeof(FILE_ALLOCATION_INFORMATION
), /* FileAllocationInformation */
839 sizeof(FILE_END_OF_FILE_INFORMATION
), /* FileEndOfFileInformation */
840 0, /* FileAlternateNameInformation */
841 sizeof(FILE_STREAM_INFORMATION
)-sizeof(WCHAR
), /* FileStreamInformation */
842 0, /* FilePipeInformation */
843 0, /* FilePipeLocalInformation */
844 0, /* FilePipeRemoteInformation */
845 0, /* FileMailslotQueryInformation */
846 0, /* FileMailslotSetInformation */
847 0, /* FileCompressionInformation */
848 0, /* FileObjectIdInformation */
849 0, /* FileCompletionInformation */
850 0, /* FileMoveClusterInformation */
851 0, /* FileQuotaInformation */
852 0, /* FileReparsePointInformation */
853 0, /* FileNetworkOpenInformation */
854 0, /* FileAttributeTagInformation */
855 0 /* FileTrackingInformation */
861 TRACE("(%p,%p,%p,0x%08lx,0x%08x)\n", hFile
, io
, ptr
, len
, class);
865 if (class <= 0 || class >= FileMaximumInformation
)
866 return io
->u
.Status
= STATUS_INVALID_INFO_CLASS
;
867 if (!info_sizes
[class])
869 FIXME("Unsupported class (%d)\n", class);
870 return io
->u
.Status
= STATUS_NOT_IMPLEMENTED
;
872 if (len
< info_sizes
[class])
873 return io
->u
.Status
= STATUS_INFO_LENGTH_MISMATCH
;
875 if ((io
->u
.Status
= wine_server_handle_to_fd( hFile
, 0, &fd
, NULL
)))
880 case FileBasicInformation
:
882 FILE_BASIC_INFORMATION
*info
= ptr
;
884 if (fstat( fd
, &st
) == -1)
885 io
->u
.Status
= FILE_GetNtStatus();
886 else if (!S_ISREG(st
.st_mode
) && !S_ISDIR(st
.st_mode
))
887 io
->u
.Status
= STATUS_INVALID_INFO_CLASS
;
890 if (S_ISDIR(st
.st_mode
)) info
->FileAttributes
= FILE_ATTRIBUTE_DIRECTORY
;
891 else info
->FileAttributes
= FILE_ATTRIBUTE_ARCHIVE
;
892 if (!(st
.st_mode
& S_IWUSR
)) info
->FileAttributes
|= FILE_ATTRIBUTE_READONLY
;
893 RtlSecondsSince1970ToTime( st
.st_mtime
, &info
->CreationTime
);
894 RtlSecondsSince1970ToTime( st
.st_mtime
, &info
->LastWriteTime
);
895 RtlSecondsSince1970ToTime( st
.st_ctime
, &info
->ChangeTime
);
896 RtlSecondsSince1970ToTime( st
.st_atime
, &info
->LastAccessTime
);
900 case FileStandardInformation
:
902 FILE_STANDARD_INFORMATION
*info
= ptr
;
904 if (fstat( fd
, &st
) == -1) io
->u
.Status
= FILE_GetNtStatus();
907 if ((info
->Directory
= S_ISDIR(st
.st_mode
)))
909 info
->AllocationSize
.QuadPart
= 0;
910 info
->EndOfFile
.QuadPart
= 0;
911 info
->NumberOfLinks
= 1;
912 info
->DeletePending
= FALSE
;
916 info
->AllocationSize
.QuadPart
= (ULONGLONG
)st
.st_blocks
* 512;
917 info
->EndOfFile
.QuadPart
= st
.st_size
;
918 info
->NumberOfLinks
= st
.st_nlink
;
919 info
->DeletePending
= FALSE
; /* FIXME */
924 case FilePositionInformation
:
926 FILE_POSITION_INFORMATION
*info
= ptr
;
927 off_t res
= lseek( fd
, 0, SEEK_CUR
);
928 if (res
== (off_t
)-1) io
->u
.Status
= FILE_GetNtStatus();
929 else info
->CurrentByteOffset
.QuadPart
= res
;
932 case FileInternalInformation
:
934 FILE_INTERNAL_INFORMATION
*info
= ptr
;
936 if (fstat( fd
, &st
) == -1) io
->u
.Status
= FILE_GetNtStatus();
937 else info
->IndexNumber
.QuadPart
= st
.st_ino
;
940 case FileEaInformation
:
942 FILE_EA_INFORMATION
*info
= ptr
;
946 case FileEndOfFileInformation
:
948 FILE_END_OF_FILE_INFORMATION
*info
= ptr
;
950 if (fstat( fd
, &st
) == -1) io
->u
.Status
= FILE_GetNtStatus();
951 else info
->EndOfFile
.QuadPart
= S_ISDIR(st
.st_mode
) ? 0 : st
.st_size
;
954 case FileAllInformation
:
956 FILE_ALL_INFORMATION
*info
= ptr
;
958 if (fstat( fd
, &st
) == -1) io
->u
.Status
= FILE_GetNtStatus();
959 else if (!S_ISREG(st
.st_mode
) && !S_ISDIR(st
.st_mode
))
960 io
->u
.Status
= STATUS_INVALID_INFO_CLASS
;
963 if ((info
->StandardInformation
.Directory
= S_ISDIR(st
.st_mode
)))
965 info
->BasicInformation
.FileAttributes
= FILE_ATTRIBUTE_DIRECTORY
;
966 info
->StandardInformation
.AllocationSize
.QuadPart
= 0;
967 info
->StandardInformation
.EndOfFile
.QuadPart
= 0;
968 info
->StandardInformation
.NumberOfLinks
= 1;
969 info
->StandardInformation
.DeletePending
= FALSE
;
973 info
->BasicInformation
.FileAttributes
= FILE_ATTRIBUTE_ARCHIVE
;
974 info
->StandardInformation
.AllocationSize
.QuadPart
= (ULONGLONG
)st
.st_blocks
* 512;
975 info
->StandardInformation
.EndOfFile
.QuadPart
= st
.st_size
;
976 info
->StandardInformation
.NumberOfLinks
= st
.st_nlink
;
977 info
->StandardInformation
.DeletePending
= FALSE
; /* FIXME */
979 if (!(st
.st_mode
& S_IWUSR
))
980 info
->BasicInformation
.FileAttributes
|= FILE_ATTRIBUTE_READONLY
;
981 RtlSecondsSince1970ToTime( st
.st_mtime
, &info
->BasicInformation
.CreationTime
);
982 RtlSecondsSince1970ToTime( st
.st_mtime
, &info
->BasicInformation
.LastWriteTime
);
983 RtlSecondsSince1970ToTime( st
.st_ctime
, &info
->BasicInformation
.ChangeTime
);
984 RtlSecondsSince1970ToTime( st
.st_atime
, &info
->BasicInformation
.LastAccessTime
);
985 info
->InternalInformation
.IndexNumber
.QuadPart
= st
.st_ino
;
986 info
->EaInformation
.EaSize
= 0;
987 info
->AccessInformation
.AccessFlags
= 0; /* FIXME */
988 info
->PositionInformation
.CurrentByteOffset
.QuadPart
= lseek( fd
, 0, SEEK_CUR
);
989 info
->ModeInformation
.Mode
= 0; /* FIXME */
990 info
->AlignmentInformation
.AlignmentRequirement
= 1; /* FIXME */
991 info
->NameInformation
.FileNameLength
= 0;
992 io
->Information
= sizeof(*info
) - sizeof(WCHAR
);
997 FIXME("Unsupported class (%d)\n", class);
998 io
->u
.Status
= STATUS_NOT_IMPLEMENTED
;
1001 wine_server_release_fd( hFile
, fd
);
1002 if (io
->u
.Status
== STATUS_SUCCESS
&& !io
->Information
) io
->Information
= info_sizes
[class];
1003 return io
->u
.Status
;
1006 /******************************************************************************
1007 * NtSetInformationFile [NTDLL.@]
1008 * ZwSetInformationFile [NTDLL.@]
1010 * Set information about an open file handle.
1013 * handle [I] Handle returned from ZwOpenFile() or ZwCreateFile()
1014 * io [O] Receives information about the operation on return
1015 * ptr [I] Source for file information
1016 * len [I] Size of FileInformation
1017 * class [I] Type of file information to set
1020 * Success: 0. io is updated.
1021 * Failure: An NTSTATUS error code describing the error.
1023 NTSTATUS WINAPI
NtSetInformationFile(HANDLE handle
, PIO_STATUS_BLOCK io
,
1024 PVOID ptr
, ULONG len
, FILE_INFORMATION_CLASS
class)
1028 TRACE("(%p,%p,%p,0x%08lx,0x%08x)\n", handle
, io
, ptr
, len
, class);
1030 if ((io
->u
.Status
= wine_server_handle_to_fd( handle
, 0, &fd
, NULL
)))
1031 return io
->u
.Status
;
1033 io
->u
.Status
= STATUS_SUCCESS
;
1036 case FileBasicInformation
:
1037 if (len
>= sizeof(FILE_BASIC_INFORMATION
))
1040 const FILE_BASIC_INFORMATION
*info
= ptr
;
1043 if (info
->LastAccessTime
.QuadPart
|| info
->LastWriteTime
.QuadPart
)
1045 ULONGLONG sec
, nsec
;
1046 struct timeval tv
[2];
1048 if (!info
->LastAccessTime
.QuadPart
|| !info
->LastWriteTime
.QuadPart
)
1051 tv
[0].tv_sec
= tv
[0].tv_usec
= 0;
1052 tv
[1].tv_sec
= tv
[1].tv_usec
= 0;
1053 if (!fstat( fd
, &st
))
1055 tv
[0].tv_sec
= st
.st_atime
;
1056 tv
[1].tv_sec
= st
.st_mtime
;
1059 if (info
->LastAccessTime
.QuadPart
)
1061 sec
= RtlLargeIntegerDivide( info
->LastAccessTime
.QuadPart
, 10000000, &nsec
);
1062 tv
[0].tv_sec
= sec
- SECS_1601_TO_1970
;
1063 tv
[0].tv_usec
= (UINT
)nsec
/ 10;
1065 if (info
->LastWriteTime
.QuadPart
)
1067 sec
= RtlLargeIntegerDivide( info
->LastWriteTime
.QuadPart
, 10000000, &nsec
);
1068 tv
[1].tv_sec
= sec
- SECS_1601_TO_1970
;
1069 tv
[1].tv_usec
= (UINT
)nsec
/ 10;
1071 if (futimes( fd
, tv
) == -1) io
->u
.Status
= FILE_GetNtStatus();
1073 #endif /* HAVE_FUTIMES */
1074 if (io
->u
.Status
== STATUS_SUCCESS
&& info
->FileAttributes
)
1076 if (fstat( fd
, &st
) == -1) io
->u
.Status
= FILE_GetNtStatus();
1079 if (info
->FileAttributes
& FILE_ATTRIBUTE_READONLY
)
1081 if (S_ISDIR( st
.st_mode
))
1082 WARN("FILE_ATTRIBUTE_READONLY ignored for directory.\n");
1084 st
.st_mode
&= ~0222; /* clear write permission bits */
1088 /* add write permission only where we already have read permission */
1089 st
.st_mode
|= (0600 | ((st
.st_mode
& 044) >> 1)) & (~FILE_umask
);
1091 if (fchmod( fd
, st
.st_mode
) == -1) io
->u
.Status
= FILE_GetNtStatus();
1095 else io
->u
.Status
= STATUS_INVALID_PARAMETER_3
;
1098 case FilePositionInformation
:
1099 if (len
>= sizeof(FILE_POSITION_INFORMATION
))
1101 const FILE_POSITION_INFORMATION
*info
= ptr
;
1103 if (lseek( fd
, info
->CurrentByteOffset
.QuadPart
, SEEK_SET
) == (off_t
)-1)
1104 io
->u
.Status
= FILE_GetNtStatus();
1106 else io
->u
.Status
= STATUS_INVALID_PARAMETER_3
;
1109 case FileEndOfFileInformation
:
1110 if (len
>= sizeof(FILE_END_OF_FILE_INFORMATION
))
1113 const FILE_END_OF_FILE_INFORMATION
*info
= ptr
;
1115 /* first try normal truncate */
1116 if (ftruncate( fd
, (off_t
)info
->EndOfFile
.QuadPart
) != -1) break;
1118 /* now check for the need to extend the file */
1119 if (fstat( fd
, &st
) != -1 && (off_t
)info
->EndOfFile
.QuadPart
> st
.st_size
)
1121 static const char zero
;
1123 /* extend the file one byte beyond the requested size and then truncate it */
1124 /* this should work around ftruncate implementations that can't extend files */
1125 if (pwrite( fd
, &zero
, 1, (off_t
)info
->EndOfFile
.QuadPart
) != -1 &&
1126 ftruncate( fd
, (off_t
)info
->EndOfFile
.QuadPart
) != -1) break;
1128 io
->u
.Status
= FILE_GetNtStatus();
1130 else io
->u
.Status
= STATUS_INVALID_PARAMETER_3
;
1134 FIXME("Unsupported class (%d)\n", class);
1135 io
->u
.Status
= STATUS_NOT_IMPLEMENTED
;
1138 wine_server_release_fd( handle
, fd
);
1139 io
->Information
= 0;
1140 return io
->u
.Status
;
1144 /******************************************************************************
1145 * NtQueryFullAttributesFile (NTDLL.@)
1147 NTSTATUS WINAPI
NtQueryFullAttributesFile( const OBJECT_ATTRIBUTES
*attr
,
1148 FILE_NETWORK_OPEN_INFORMATION
*info
)
1150 ANSI_STRING unix_name
;
1153 if (!(status
= wine_nt_to_unix_file_name( attr
->ObjectName
, &unix_name
, FILE_OPEN
,
1154 !(attr
->Attributes
& OBJ_CASE_INSENSITIVE
) )))
1158 if (stat( unix_name
.Buffer
, &st
) == -1)
1159 status
= FILE_GetNtStatus();
1160 else if (!S_ISREG(st
.st_mode
) && !S_ISDIR(st
.st_mode
))
1161 status
= STATUS_INVALID_INFO_CLASS
;
1164 if (S_ISDIR(st
.st_mode
))
1166 info
->FileAttributes
= FILE_ATTRIBUTE_DIRECTORY
;
1167 info
->AllocationSize
.QuadPart
= 0;
1168 info
->EndOfFile
.QuadPart
= 0;
1172 info
->FileAttributes
= FILE_ATTRIBUTE_ARCHIVE
;
1173 info
->AllocationSize
.QuadPart
= (ULONGLONG
)st
.st_blocks
* 512;
1174 info
->EndOfFile
.QuadPart
= st
.st_size
;
1176 if (!(st
.st_mode
& S_IWUSR
)) info
->FileAttributes
|= FILE_ATTRIBUTE_READONLY
;
1177 RtlSecondsSince1970ToTime( st
.st_mtime
, &info
->CreationTime
);
1178 RtlSecondsSince1970ToTime( st
.st_mtime
, &info
->LastWriteTime
);
1179 RtlSecondsSince1970ToTime( st
.st_ctime
, &info
->ChangeTime
);
1180 RtlSecondsSince1970ToTime( st
.st_atime
, &info
->LastAccessTime
);
1181 if (DIR_is_hidden_file( attr
->ObjectName
))
1182 info
->FileAttributes
|= FILE_ATTRIBUTE_HIDDEN
;
1184 RtlFreeAnsiString( &unix_name
);
1186 else WARN("%s not found (%lx)\n", debugstr_us(attr
->ObjectName
), status
);
1191 /******************************************************************************
1192 * NtQueryAttributesFile (NTDLL.@)
1193 * ZwQueryAttributesFile (NTDLL.@)
1195 NTSTATUS WINAPI
NtQueryAttributesFile( const OBJECT_ATTRIBUTES
*attr
, FILE_BASIC_INFORMATION
*info
)
1197 FILE_NETWORK_OPEN_INFORMATION full_info
;
1200 if (!(status
= NtQueryFullAttributesFile( attr
, &full_info
)))
1202 info
->CreationTime
.QuadPart
= full_info
.CreationTime
.QuadPart
;
1203 info
->LastAccessTime
.QuadPart
= full_info
.LastAccessTime
.QuadPart
;
1204 info
->LastWriteTime
.QuadPart
= full_info
.LastWriteTime
.QuadPart
;
1205 info
->ChangeTime
.QuadPart
= full_info
.ChangeTime
.QuadPart
;
1206 info
->FileAttributes
= full_info
.FileAttributes
;
1212 /******************************************************************************
1213 * NtQueryVolumeInformationFile [NTDLL.@]
1214 * ZwQueryVolumeInformationFile [NTDLL.@]
1216 * Get volume information for an open file handle.
1219 * handle [I] Handle returned from ZwOpenFile() or ZwCreateFile()
1220 * io [O] Receives information about the operation on return
1221 * buffer [O] Destination for volume information
1222 * length [I] Size of FsInformation
1223 * info_class [I] Type of volume information to set
1226 * Success: 0. io and buffer are updated.
1227 * Failure: An NTSTATUS error code describing the error.
1229 NTSTATUS WINAPI
NtQueryVolumeInformationFile( HANDLE handle
, PIO_STATUS_BLOCK io
,
1230 PVOID buffer
, ULONG length
,
1231 FS_INFORMATION_CLASS info_class
)
1236 if ((io
->u
.Status
= wine_server_handle_to_fd( handle
, 0, &fd
, NULL
)) != STATUS_SUCCESS
)
1237 return io
->u
.Status
;
1239 io
->u
.Status
= STATUS_NOT_IMPLEMENTED
;
1240 io
->Information
= 0;
1242 switch( info_class
)
1244 case FileFsVolumeInformation
:
1245 FIXME( "%p: volume info not supported\n", handle
);
1247 case FileFsLabelInformation
:
1248 FIXME( "%p: label info not supported\n", handle
);
1250 case FileFsSizeInformation
:
1251 if (length
< sizeof(FILE_FS_SIZE_INFORMATION
))
1252 io
->u
.Status
= STATUS_BUFFER_TOO_SMALL
;
1255 FILE_FS_SIZE_INFORMATION
*info
= buffer
;
1256 struct statvfs stvfs
;
1258 if (fstat( fd
, &st
) < 0)
1260 io
->u
.Status
= FILE_GetNtStatus();
1263 if (!S_ISREG(st
.st_mode
) && !S_ISDIR(st
.st_mode
))
1265 io
->u
.Status
= STATUS_INVALID_DEVICE_REQUEST
;
1268 if (fstatvfs( fd
, &stvfs
) < 0) io
->u
.Status
= FILE_GetNtStatus();
1271 info
->TotalAllocationUnits
.QuadPart
= stvfs
.f_blocks
;
1272 info
->AvailableAllocationUnits
.QuadPart
= stvfs
.f_bavail
;
1273 info
->SectorsPerAllocationUnit
= 1;
1274 info
->BytesPerSector
= stvfs
.f_frsize
;
1275 io
->Information
= sizeof(*info
);
1276 io
->u
.Status
= STATUS_SUCCESS
;
1280 case FileFsDeviceInformation
:
1281 if (length
< sizeof(FILE_FS_DEVICE_INFORMATION
))
1282 io
->u
.Status
= STATUS_BUFFER_TOO_SMALL
;
1285 FILE_FS_DEVICE_INFORMATION
*info
= buffer
;
1287 info
->Characteristics
= 0;
1288 if (fstat( fd
, &st
) < 0)
1290 io
->u
.Status
= FILE_GetNtStatus();
1293 if (S_ISCHR( st
.st_mode
))
1295 info
->DeviceType
= FILE_DEVICE_UNKNOWN
;
1297 switch(major(st
.st_rdev
))
1300 info
->DeviceType
= FILE_DEVICE_NULL
;
1303 info
->DeviceType
= FILE_DEVICE_SERIAL_PORT
;
1306 info
->DeviceType
= FILE_DEVICE_PARALLEL_PORT
;
1311 else if (S_ISBLK( st
.st_mode
))
1313 info
->DeviceType
= FILE_DEVICE_DISK
;
1315 else if (S_ISFIFO( st
.st_mode
) || S_ISSOCK( st
.st_mode
))
1317 info
->DeviceType
= FILE_DEVICE_NAMED_PIPE
;
1319 else /* regular file or directory */
1321 #if defined(linux) && defined(HAVE_FSTATFS)
1324 /* check for floppy disk */
1325 if (major(st
.st_dev
) == FLOPPY_MAJOR
)
1326 info
->Characteristics
|= FILE_REMOVABLE_MEDIA
;
1328 if (fstatfs( fd
, &stfs
) < 0) stfs
.f_type
= 0;
1329 switch (stfs
.f_type
)
1331 case 0x9660: /* iso9660 */
1332 case 0x15013346: /* udf */
1333 info
->DeviceType
= FILE_DEVICE_CD_ROM_FILE_SYSTEM
;
1334 info
->Characteristics
|= FILE_REMOVABLE_MEDIA
|FILE_READ_ONLY_DEVICE
;
1336 case 0x6969: /* nfs */
1337 case 0x517B: /* smbfs */
1338 case 0x564c: /* ncpfs */
1339 info
->DeviceType
= FILE_DEVICE_NETWORK_FILE_SYSTEM
;
1340 info
->Characteristics
|= FILE_REMOTE_DEVICE
;
1342 case 0x01021994: /* tmpfs */
1343 case 0x28cd3d45: /* cramfs */
1344 case 0x1373: /* devfs */
1345 case 0x9fa0: /* procfs */
1346 info
->DeviceType
= FILE_DEVICE_VIRTUAL_DISK
;
1349 info
->DeviceType
= FILE_DEVICE_DISK_FILE_SYSTEM
;
1354 if (!warned
++) FIXME( "device info not properly supported on this platform\n" );
1355 info
->DeviceType
= FILE_DEVICE_DISK_FILE_SYSTEM
;
1357 info
->Characteristics
|= FILE_DEVICE_IS_MOUNTED
;
1359 io
->Information
= sizeof(*info
);
1360 io
->u
.Status
= STATUS_SUCCESS
;
1363 case FileFsAttributeInformation
:
1364 FIXME( "%p: attribute info not supported\n", handle
);
1366 case FileFsControlInformation
:
1367 FIXME( "%p: control info not supported\n", handle
);
1369 case FileFsFullSizeInformation
:
1370 FIXME( "%p: full size info not supported\n", handle
);
1372 case FileFsObjectIdInformation
:
1373 FIXME( "%p: object id info not supported\n", handle
);
1375 case FileFsMaximumInformation
:
1376 FIXME( "%p: maximum info not supported\n", handle
);
1379 io
->u
.Status
= STATUS_INVALID_PARAMETER
;
1382 wine_server_release_fd( handle
, fd
);
1383 return io
->u
.Status
;
1387 /******************************************************************
1388 * NtFlushBuffersFile (NTDLL.@)
1390 * Flush any buffered data on an open file handle.
1393 * FileHandle [I] Handle returned from ZwOpenFile() or ZwCreateFile()
1394 * IoStatusBlock [O] Receives information about the operation on return
1397 * Success: 0. IoStatusBlock is updated.
1398 * Failure: An NTSTATUS error code describing the error.
1400 NTSTATUS WINAPI
NtFlushBuffersFile( HANDLE hFile
, IO_STATUS_BLOCK
* IoStatusBlock
)
1403 HANDLE hEvent
= NULL
;
1405 SERVER_START_REQ( flush_file
)
1407 req
->handle
= hFile
;
1408 ret
= wine_server_call( req
);
1409 hEvent
= reply
->event
;
1414 ret
= NtWaitForSingleObject( hEvent
, FALSE
, NULL
);
1420 /******************************************************************
1421 * NtLockFile (NTDLL.@)
1425 NTSTATUS WINAPI
NtLockFile( HANDLE hFile
, HANDLE lock_granted_event
,
1426 PIO_APC_ROUTINE apc
, void* apc_user
,
1427 PIO_STATUS_BLOCK io_status
, PLARGE_INTEGER offset
,
1428 PLARGE_INTEGER count
, ULONG
* key
, BOOLEAN dont_wait
,
1435 if (apc
|| io_status
|| key
)
1437 FIXME("Unimplemented yet parameter\n");
1438 return STATUS_NOT_IMPLEMENTED
;
1443 SERVER_START_REQ( lock_file
)
1445 req
->handle
= hFile
;
1446 req
->offset_low
= offset
->u
.LowPart
;
1447 req
->offset_high
= offset
->u
.HighPart
;
1448 req
->count_low
= count
->u
.LowPart
;
1449 req
->count_high
= count
->u
.HighPart
;
1450 req
->shared
= !exclusive
;
1451 req
->wait
= !dont_wait
;
1452 ret
= wine_server_call( req
);
1453 handle
= reply
->handle
;
1454 async
= reply
->overlapped
;
1457 if (ret
!= STATUS_PENDING
)
1459 if (!ret
&& lock_granted_event
) NtSetEvent(lock_granted_event
, NULL
);
1465 FIXME( "Async I/O lock wait not implemented, might deadlock\n" );
1466 if (handle
) NtClose( handle
);
1467 return STATUS_PENDING
;
1471 NtWaitForSingleObject( handle
, FALSE
, NULL
);
1478 /* Unix lock conflict, sleep a bit and retry */
1479 time
.QuadPart
= 100 * (ULONGLONG
)10000;
1480 time
.QuadPart
= -time
.QuadPart
;
1481 NtDelayExecution( FALSE
, &time
);
1487 /******************************************************************
1488 * NtUnlockFile (NTDLL.@)
1492 NTSTATUS WINAPI
NtUnlockFile( HANDLE hFile
, PIO_STATUS_BLOCK io_status
,
1493 PLARGE_INTEGER offset
, PLARGE_INTEGER count
,
1498 TRACE( "%p %lx%08lx %lx%08lx\n",
1499 hFile
, offset
->u
.HighPart
, offset
->u
.LowPart
, count
->u
.HighPart
, count
->u
.LowPart
);
1501 if (io_status
|| key
)
1503 FIXME("Unimplemented yet parameter\n");
1504 return STATUS_NOT_IMPLEMENTED
;
1507 SERVER_START_REQ( unlock_file
)
1509 req
->handle
= hFile
;
1510 req
->offset_low
= offset
->u
.LowPart
;
1511 req
->offset_high
= offset
->u
.HighPart
;
1512 req
->count_low
= count
->u
.LowPart
;
1513 req
->count_high
= count
->u
.HighPart
;
1514 status
= wine_server_call( req
);
1520 /******************************************************************
1521 * NtCreateNamedPipeFile (NTDLL.@)
1525 NTSTATUS WINAPI
NtCreateNamedPipeFile( PHANDLE FileHandle
, ULONG DesiredAccess
,
1526 POBJECT_ATTRIBUTES ObjectAttributes
, PIO_STATUS_BLOCK IoStatusBlock
,
1527 ULONG ShareAccess
, ULONG CreateDisposition
, ULONG CreateOptions
,
1528 ULONG NamedPipeType
, ULONG ReadMode
, ULONG CompletionMode
,
1529 ULONG MaximumInstances
, ULONG InboundQuota
, ULONG OutboundQuota
,
1530 PLARGE_INTEGER DefaultTimeout
)
1532 FIXME("(%p %lx %p %p %lx %ld %lx %ld %ld %ld %ld %ld %ld %p): stub\n",
1533 FileHandle
, DesiredAccess
, ObjectAttributes
, IoStatusBlock
,
1534 ShareAccess
, CreateDisposition
, CreateOptions
, NamedPipeType
,
1535 ReadMode
, CompletionMode
, MaximumInstances
, InboundQuota
,
1536 OutboundQuota
, DefaultTimeout
);
1537 return STATUS_NOT_IMPLEMENTED
;