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"
65 #include "ntdll_misc.h"
70 WINE_DEFAULT_DEBUG_CHANNEL(ntdll
);
72 mode_t FILE_umask
= 0;
74 #define SECSPERDAY 86400
75 #define SECS_1601_TO_1970 ((369 * 365 + 89) * (ULONGLONG)SECSPERDAY)
77 /**************************************************************************
78 * NtOpenFile [NTDLL.@]
79 * ZwOpenFile [NTDLL.@]
84 * handle [O] Variable that receives the file handle on return
85 * access [I] Access desired by the caller to the file
86 * attr [I] Structure describing the file to be opened
87 * io [O] Receives details about the result of the operation
88 * sharing [I] Type of shared access the caller requires
89 * options [I] Options for the file open
92 * Success: 0. FileHandle and IoStatusBlock are updated.
93 * Failure: An NTSTATUS error code describing the error.
95 NTSTATUS WINAPI
NtOpenFile( PHANDLE handle
, ACCESS_MASK access
,
96 POBJECT_ATTRIBUTES attr
, PIO_STATUS_BLOCK io
,
97 ULONG sharing
, ULONG options
)
99 return NtCreateFile( handle
, access
, attr
, io
, NULL
, 0,
100 sharing
, FILE_OPEN
, options
, NULL
, 0 );
103 /**************************************************************************
104 * NtCreateFile [NTDLL.@]
105 * ZwCreateFile [NTDLL.@]
107 * Either create a new file or directory, or open an existing file, device,
108 * directory or volume.
111 * handle [O] Points to a variable which receives the file handle on return
112 * access [I] Desired access to the file
113 * attr [I] Structure describing the file
114 * io [O] Receives information about the operation on return
115 * alloc_size [I] Initial size of the file in bytes
116 * attributes [I] Attributes to create the file with
117 * sharing [I] Type of shared access the caller would like to the file
118 * disposition [I] Specifies what to do, depending on whether the file already exists
119 * options [I] Options for creating a new file
120 * ea_buffer [I] Undocumented
121 * ea_length [I] Undocumented
124 * Success: 0. handle and io are updated.
125 * Failure: An NTSTATUS error code describing the error.
127 NTSTATUS WINAPI
NtCreateFile( PHANDLE handle
, ACCESS_MASK access
, POBJECT_ATTRIBUTES attr
,
128 PIO_STATUS_BLOCK io
, PLARGE_INTEGER alloc_size
,
129 ULONG attributes
, ULONG sharing
, ULONG disposition
,
130 ULONG options
, PVOID ea_buffer
, ULONG ea_length
)
132 static const WCHAR pipeW
[] = {'\\','?','?','\\','p','i','p','e','\\'};
133 ANSI_STRING unix_name
;
136 TRACE("handle=%p access=%08lx name=%s objattr=%08lx root=%p sec=%p io=%p alloc_size=%p\n"
137 "attr=%08lx sharing=%08lx disp=%ld options=%08lx ea=%p.0x%08lx\n",
138 handle
, access
, debugstr_us(attr
->ObjectName
), attr
->Attributes
,
139 attr
->RootDirectory
, attr
->SecurityDescriptor
, io
, alloc_size
,
140 attributes
, sharing
, disposition
, options
, ea_buffer
, ea_length
);
142 if (attr
->RootDirectory
)
144 FIXME( "RootDirectory %p not supported\n", attr
->RootDirectory
);
145 return STATUS_OBJECT_NAME_NOT_FOUND
;
147 if (alloc_size
) FIXME( "alloc_size not supported\n" );
149 /* check for named pipe */
151 if (attr
->ObjectName
->Length
> sizeof(pipeW
) &&
152 !memicmpW( attr
->ObjectName
->Buffer
, pipeW
, sizeof(pipeW
)/sizeof(WCHAR
) ))
154 SERVER_START_REQ( open_named_pipe
)
156 req
->access
= access
;
157 req
->inherit
= (attr
->Attributes
& OBJ_INHERIT
) != 0;
158 wine_server_add_data( req
, attr
->ObjectName
->Buffer
+ 4,
159 attr
->ObjectName
->Length
- 4*sizeof(WCHAR
) );
160 io
->u
.Status
= wine_server_call( req
);
161 *handle
= reply
->handle
;
167 io
->u
.Status
= wine_nt_to_unix_file_name( attr
->ObjectName
, &unix_name
, disposition
,
168 !(attr
->Attributes
& OBJ_CASE_INSENSITIVE
) );
170 if (io
->u
.Status
== STATUS_NO_SUCH_FILE
&&
171 disposition
!= FILE_OPEN
&& disposition
!= FILE_OVERWRITE
)
174 io
->u
.Status
= STATUS_SUCCESS
;
177 if (io
->u
.Status
== STATUS_SUCCESS
)
179 SERVER_START_REQ( create_file
)
181 req
->access
= access
;
182 req
->inherit
= (attr
->Attributes
& OBJ_INHERIT
) != 0;
183 req
->sharing
= sharing
;
184 req
->create
= disposition
;
185 req
->options
= options
;
186 req
->attrs
= attributes
;
187 wine_server_add_data( req
, unix_name
.Buffer
, unix_name
.Length
);
188 io
->u
.Status
= wine_server_call( req
);
189 *handle
= reply
->handle
;
192 RtlFreeAnsiString( &unix_name
);
194 else WARN("%s not found (%lx)\n", debugstr_us(attr
->ObjectName
), io
->u
.Status
);
196 if (io
->u
.Status
== STATUS_SUCCESS
)
198 if (created
) io
->Information
= FILE_CREATED
;
199 else switch(disposition
)
202 io
->Information
= FILE_SUPERSEDED
;
205 io
->Information
= FILE_CREATED
;
209 io
->Information
= FILE_OPENED
;
212 case FILE_OVERWRITE_IF
:
213 io
->Information
= FILE_OVERWRITTEN
;
221 /***********************************************************************
222 * Asynchronous file I/O *
224 static void WINAPI
FILE_AsyncReadService(void*, PIO_STATUS_BLOCK
, ULONG
);
225 static void WINAPI
FILE_AsyncWriteService(void*, PIO_STATUS_BLOCK
, ULONG
);
227 typedef struct async_fileio
235 int queue_apc_on_error
;
241 static void fileio_terminate(async_fileio
*fileio
, IO_STATUS_BLOCK
* iosb
)
243 TRACE("data: %p\n", fileio
);
245 wine_server_release_fd( fileio
->handle
, fileio
->fd
);
246 if ( fileio
->event
!= INVALID_HANDLE_VALUE
)
247 NtSetEvent( fileio
->event
, NULL
);
250 (iosb
->u
.Status
== STATUS_SUCCESS
|| fileio
->queue_apc_on_error
))
251 fileio
->apc( fileio
->apc_user
, iosb
, iosb
->Information
);
253 RtlFreeHeap( GetProcessHeap(), 0, fileio
);
257 static ULONG
fileio_queue_async(async_fileio
* fileio
, IO_STATUS_BLOCK
* iosb
,
260 PIO_APC_ROUTINE apc
= do_read
? FILE_AsyncReadService
: FILE_AsyncWriteService
;
263 SERVER_START_REQ( register_async
)
265 req
->handle
= fileio
->handle
;
268 req
->io_user
= fileio
;
269 req
->type
= do_read
? ASYNC_TYPE_READ
: ASYNC_TYPE_WRITE
;
270 req
->count
= (fileio
->count
< iosb
->Information
) ?
271 0 : fileio
->count
- iosb
->Information
;
272 status
= wine_server_call( req
);
276 if ( status
) iosb
->u
.Status
= status
;
277 if ( iosb
->u
.Status
!= STATUS_PENDING
)
279 (apc
)( fileio
, iosb
, iosb
->u
.Status
);
280 return iosb
->u
.Status
;
282 NtCurrentTeb()->num_async_io
++;
283 return STATUS_SUCCESS
;
286 /***********************************************************************
287 * FILE_GetNtStatus(void)
289 * Retrieve the Nt Status code from errno.
290 * Try to be consistent with FILE_SetDosError().
292 NTSTATUS
FILE_GetNtStatus(void)
296 TRACE( "errno = %d\n", errno
);
299 case EAGAIN
: return STATUS_SHARING_VIOLATION
;
300 case EBADF
: return STATUS_INVALID_HANDLE
;
301 case ENOSPC
: return STATUS_DISK_FULL
;
304 case EACCES
: return STATUS_ACCESS_DENIED
;
305 case ENOTDIR
: return STATUS_OBJECT_PATH_NOT_FOUND
;
306 case ENOENT
: return STATUS_OBJECT_NAME_NOT_FOUND
;
307 case EISDIR
: return STATUS_FILE_IS_A_DIRECTORY
;
309 case ENFILE
: return STATUS_TOO_MANY_OPENED_FILES
;
310 case EINVAL
: return STATUS_INVALID_PARAMETER
;
311 case ENOTEMPTY
: return STATUS_DIRECTORY_NOT_EMPTY
;
312 case EPIPE
: return STATUS_PIPE_BROKEN
;
313 case EIO
: return STATUS_DEVICE_NOT_READY
;
315 case ENOMEDIUM
: return STATUS_NO_MEDIA_IN_DEVICE
;
318 case EOPNOTSUPP
:return STATUS_NOT_SUPPORTED
;
319 case ECONNRESET
:return STATUS_PIPE_DISCONNECTED
;
320 case ENOEXEC
: /* ?? */
321 case ESPIPE
: /* ?? */
322 case EEXIST
: /* ?? */
324 FIXME( "Converting errno %d to STATUS_UNSUCCESSFUL\n", err
);
325 return STATUS_UNSUCCESSFUL
;
329 /***********************************************************************
330 * FILE_AsyncReadService (INTERNAL)
332 * This function is called while the client is waiting on the
333 * server, so we can't make any server calls here.
335 static void WINAPI
FILE_AsyncReadService(void *user
, PIO_STATUS_BLOCK iosb
, ULONG status
)
337 async_fileio
*fileio
= (async_fileio
*)user
;
339 int already
= iosb
->Information
;
341 TRACE("%p %p %lu\n", iosb
, fileio
->buffer
, status
);
345 case STATUS_ALERTED
: /* got some new data */
346 if (iosb
->u
.Status
!= STATUS_PENDING
) FIXME("unexpected status %08lx\n", iosb
->u
.Status
);
347 /* check to see if the data is ready (non-blocking) */
348 if ( fileio
->avail_mode
)
349 result
= read(fileio
->fd
, &fileio
->buffer
[already
],
350 fileio
->count
- already
);
353 result
= pread(fileio
->fd
, &fileio
->buffer
[already
],
354 fileio
->count
- already
,
355 fileio
->offset
+ already
);
356 if ((result
< 0) && (errno
== ESPIPE
))
357 result
= read(fileio
->fd
, &fileio
->buffer
[already
],
358 fileio
->count
- already
);
363 if (errno
== EAGAIN
|| errno
== EINTR
)
365 TRACE("Deferred read %d\n", errno
);
366 iosb
->u
.Status
= STATUS_PENDING
;
368 else /* check to see if the transfer is complete */
369 iosb
->u
.Status
= FILE_GetNtStatus();
371 else if (result
== 0)
373 iosb
->u
.Status
= iosb
->Information
? STATUS_SUCCESS
: STATUS_END_OF_FILE
;
377 iosb
->Information
+= result
;
378 if (iosb
->Information
>= fileio
->count
|| fileio
->avail_mode
)
379 iosb
->u
.Status
= STATUS_SUCCESS
;
382 /* if we only have to read the available data, and none is available,
383 * simply cancel the request. If data was available, it has been read
384 * while in by previous call (NtDelayExecution)
386 iosb
->u
.Status
= (fileio
->avail_mode
) ? STATUS_SUCCESS
: STATUS_PENDING
;
389 TRACE("read %d more bytes %ld/%d so far (%s)\n",
390 result
, iosb
->Information
, fileio
->count
,
391 (iosb
->u
.Status
== STATUS_SUCCESS
) ? "success" : "pending");
393 /* queue another async operation ? */
394 if (iosb
->u
.Status
== STATUS_PENDING
)
395 fileio_queue_async(fileio
, iosb
, TRUE
);
397 fileio_terminate(fileio
, iosb
);
400 iosb
->u
.Status
= status
;
401 fileio_terminate(fileio
, iosb
);
407 /******************************************************************************
408 * NtReadFile [NTDLL.@]
409 * ZwReadFile [NTDLL.@]
411 * Read from an open file handle.
414 * FileHandle [I] Handle returned from ZwOpenFile() or ZwCreateFile()
415 * Event [I] Event to signal upon completion (or NULL)
416 * ApcRoutine [I] Callback to call upon completion (or NULL)
417 * ApcContext [I] Context for ApcRoutine (or NULL)
418 * IoStatusBlock [O] Receives information about the operation on return
419 * Buffer [O] Destination for the data read
420 * Length [I] Size of Buffer
421 * ByteOffset [O] Destination for the new file pointer position (or NULL)
422 * Key [O] Function unknown (may be NULL)
425 * Success: 0. IoStatusBlock is updated, and the Information member contains
426 * The number of bytes read.
427 * Failure: An NTSTATUS error code describing the error.
429 NTSTATUS WINAPI
NtReadFile(HANDLE hFile
, HANDLE hEvent
,
430 PIO_APC_ROUTINE apc
, void* apc_user
,
431 PIO_STATUS_BLOCK io_status
, void* buffer
, ULONG length
,
432 PLARGE_INTEGER offset
, PULONG key
)
434 int unix_handle
, flags
;
436 TRACE("(%p,%p,%p,%p,%p,%p,0x%08lx,%p,%p),partial stub!\n",
437 hFile
,hEvent
,apc
,apc_user
,io_status
,buffer
,length
,offset
,key
);
439 io_status
->Information
= 0;
440 io_status
->u
.Status
= wine_server_handle_to_fd( hFile
, GENERIC_READ
, &unix_handle
, &flags
);
441 if (io_status
->u
.Status
) return io_status
->u
.Status
;
443 if (flags
& FD_FLAG_RECV_SHUTDOWN
)
445 wine_server_release_fd( hFile
, unix_handle
);
446 return STATUS_PIPE_DISCONNECTED
;
449 if (flags
& FD_FLAG_TIMEOUT
)
453 /* this shouldn't happen, but check it */
454 FIXME("NIY-hEvent\n");
455 wine_server_release_fd( hFile
, unix_handle
);
456 return STATUS_NOT_IMPLEMENTED
;
458 io_status
->u
.Status
= NtCreateEvent(&hEvent
, EVENT_ALL_ACCESS
, NULL
, 0, 0);
459 if (io_status
->u
.Status
)
461 wine_server_release_fd( hFile
, unix_handle
);
462 return io_status
->u
.Status
;
466 if (flags
& (FD_FLAG_OVERLAPPED
|FD_FLAG_TIMEOUT
))
468 async_fileio
* fileio
;
471 if (!(fileio
= RtlAllocateHeap(GetProcessHeap(), 0, sizeof(async_fileio
))))
473 wine_server_release_fd( hFile
, unix_handle
);
474 if (flags
& FD_FLAG_TIMEOUT
) NtClose(hEvent
);
475 return STATUS_NO_MEMORY
;
477 fileio
->handle
= hFile
;
478 fileio
->count
= length
;
479 if ( offset
== NULL
)
483 fileio
->offset
= offset
->QuadPart
;
484 if (offset
->u
.HighPart
&& fileio
->offset
== offset
->u
.LowPart
)
485 FIXME("High part of offset is lost\n");
488 fileio
->apc_user
= apc_user
;
489 fileio
->buffer
= buffer
;
490 fileio
->queue_apc_on_error
= 0;
491 fileio
->avail_mode
= (flags
& FD_FLAG_AVAILABLE
);
492 fileio
->fd
= unix_handle
; /* FIXME */
493 fileio
->event
= hEvent
;
494 NtResetEvent(hEvent
, NULL
);
496 io_status
->u
.Status
= STATUS_PENDING
;
497 ret
= fileio_queue_async(fileio
, io_status
, TRUE
);
498 if (ret
!= STATUS_SUCCESS
)
500 wine_server_release_fd( hFile
, unix_handle
);
501 if (flags
& FD_FLAG_TIMEOUT
) NtClose(hEvent
);
502 RtlFreeHeap(GetProcessHeap(), 0, fileio
);
505 if (flags
& FD_FLAG_TIMEOUT
)
507 ret
= NtWaitForSingleObject(hEvent
, TRUE
, NULL
);
509 if (ret
!= STATUS_USER_APC
)
510 fileio
->queue_apc_on_error
= 1;
514 LARGE_INTEGER timeout
;
516 /* let some APC be run, this will read some already pending data */
517 timeout
.u
.LowPart
= timeout
.u
.HighPart
= 0;
518 ret
= NtDelayExecution( TRUE
, &timeout
);
519 /* the apc didn't run and therefore the completion routine now
520 * needs to be sent errors.
521 * Note that there is no race between setting this flag and
522 * returning errors because apc's are run only during alertable
524 if (ret
!= STATUS_USER_APC
)
525 fileio
->queue_apc_on_error
= 1;
527 TRACE("= 0x%08lx\n", io_status
->u
.Status
);
528 return io_status
->u
.Status
;
533 FILE_POSITION_INFORMATION fpi
;
535 fpi
.CurrentByteOffset
= *offset
;
536 io_status
->u
.Status
= NtSetInformationFile(hFile
, io_status
, &fpi
, sizeof(fpi
),
537 FilePositionInformation
);
538 if (io_status
->u
.Status
)
540 wine_server_release_fd( hFile
, unix_handle
);
541 return io_status
->u
.Status
;
544 /* code for synchronous reads */
545 while ((io_status
->Information
= read( unix_handle
, buffer
, length
)) == -1)
547 if ((errno
== EAGAIN
) || (errno
== EINTR
)) continue;
550 io_status
->Information
= 0;
551 io_status
->u
.Status
= STATUS_ACCESS_VIOLATION
;
553 else io_status
->u
.Status
= FILE_GetNtStatus();
556 wine_server_release_fd( hFile
, unix_handle
);
557 TRACE("= 0x%08lx\n", io_status
->u
.Status
);
558 return io_status
->u
.Status
;
561 /***********************************************************************
562 * FILE_AsyncWriteService (INTERNAL)
564 * This function is called while the client is waiting on the
565 * server, so we can't make any server calls here.
567 static void WINAPI
FILE_AsyncWriteService(void *ovp
, IO_STATUS_BLOCK
*iosb
, ULONG status
)
569 async_fileio
*fileio
= (async_fileio
*) ovp
;
571 int already
= iosb
->Information
;
573 TRACE("(%p %p %lu)\n",iosb
, fileio
->buffer
, status
);
578 /* write some data (non-blocking) */
579 if ( fileio
->avail_mode
)
580 result
= write(fileio
->fd
, &fileio
->buffer
[already
],
581 fileio
->count
- already
);
584 result
= pwrite(fileio
->fd
, &fileio
->buffer
[already
],
585 fileio
->count
- already
, fileio
->offset
+ already
);
586 if ((result
< 0) && (errno
== ESPIPE
))
587 result
= write(fileio
->fd
, &fileio
->buffer
[already
],
588 fileio
->count
- already
);
593 if (errno
== EAGAIN
|| errno
== EINTR
) iosb
->u
.Status
= STATUS_PENDING
;
594 else iosb
->u
.Status
= FILE_GetNtStatus();
598 iosb
->Information
+= result
;
599 iosb
->u
.Status
= (iosb
->Information
< fileio
->count
) ? STATUS_PENDING
: STATUS_SUCCESS
;
600 TRACE("wrote %d more bytes %ld/%d so far\n",
601 result
, iosb
->Information
, fileio
->count
);
603 if (iosb
->u
.Status
== STATUS_PENDING
)
604 fileio_queue_async(fileio
, iosb
, FALSE
);
607 iosb
->u
.Status
= status
;
608 fileio_terminate(fileio
, iosb
);
613 /******************************************************************************
614 * NtWriteFile [NTDLL.@]
615 * ZwWriteFile [NTDLL.@]
617 * Write to an open file handle.
620 * FileHandle [I] Handle returned from ZwOpenFile() or ZwCreateFile()
621 * Event [I] Event to signal upon completion (or NULL)
622 * ApcRoutine [I] Callback to call upon completion (or NULL)
623 * ApcContext [I] Context for ApcRoutine (or NULL)
624 * IoStatusBlock [O] Receives information about the operation on return
625 * Buffer [I] Source for the data to write
626 * Length [I] Size of Buffer
627 * ByteOffset [O] Destination for the new file pointer position (or NULL)
628 * Key [O] Function unknown (may be NULL)
631 * Success: 0. IoStatusBlock is updated, and the Information member contains
632 * The number of bytes written.
633 * Failure: An NTSTATUS error code describing the error.
635 NTSTATUS WINAPI
NtWriteFile(HANDLE hFile
, HANDLE hEvent
,
636 PIO_APC_ROUTINE apc
, void* apc_user
,
637 PIO_STATUS_BLOCK io_status
,
638 const void* buffer
, ULONG length
,
639 PLARGE_INTEGER offset
, PULONG key
)
641 int unix_handle
, flags
;
643 TRACE("(%p,%p,%p,%p,%p,%p,0x%08lx,%p,%p)!\n",
644 hFile
,hEvent
,apc
,apc_user
,io_status
,buffer
,length
,offset
,key
);
646 io_status
->Information
= 0;
647 io_status
->u
.Status
= wine_server_handle_to_fd( hFile
, GENERIC_WRITE
, &unix_handle
, &flags
);
648 if (io_status
->u
.Status
) return io_status
->u
.Status
;
650 if (flags
& FD_FLAG_SEND_SHUTDOWN
)
652 wine_server_release_fd( hFile
, unix_handle
);
653 return STATUS_PIPE_DISCONNECTED
;
656 if (flags
& FD_FLAG_TIMEOUT
)
660 /* this shouldn't happen, but check it */
661 FIXME("NIY-hEvent\n");
662 wine_server_release_fd( hFile
, unix_handle
);
663 return STATUS_NOT_IMPLEMENTED
;
665 io_status
->u
.Status
= NtCreateEvent(&hEvent
, EVENT_ALL_ACCESS
, NULL
, 0, 0);
666 if (io_status
->u
.Status
)
668 wine_server_release_fd( hFile
, unix_handle
);
669 return io_status
->u
.Status
;
673 if (flags
& (FD_FLAG_OVERLAPPED
|FD_FLAG_TIMEOUT
))
675 async_fileio
* fileio
;
678 if (!(fileio
= RtlAllocateHeap(GetProcessHeap(), 0, sizeof(async_fileio
))))
680 wine_server_release_fd( hFile
, unix_handle
);
681 if (flags
& FD_FLAG_TIMEOUT
) NtClose(hEvent
);
682 return STATUS_NO_MEMORY
;
684 fileio
->handle
= hFile
;
685 fileio
->count
= length
;
688 fileio
->offset
= offset
->QuadPart
;
689 if (offset
->u
.HighPart
&& fileio
->offset
== offset
->u
.LowPart
)
690 FIXME("High part of offset is lost\n");
697 fileio
->apc_user
= apc_user
;
698 fileio
->buffer
= (void*)buffer
;
699 fileio
->queue_apc_on_error
= 0;
700 fileio
->avail_mode
= (flags
& FD_FLAG_AVAILABLE
);
701 fileio
->fd
= unix_handle
; /* FIXME */
702 fileio
->event
= hEvent
;
703 NtResetEvent(hEvent
, NULL
);
705 io_status
->Information
= 0;
706 io_status
->u
.Status
= STATUS_PENDING
;
707 ret
= fileio_queue_async(fileio
, io_status
, FALSE
);
708 if (ret
!= STATUS_SUCCESS
)
710 wine_server_release_fd( hFile
, unix_handle
);
711 if (flags
& FD_FLAG_TIMEOUT
) NtClose(hEvent
);
712 RtlFreeHeap(GetProcessHeap(), 0, fileio
);
715 if (flags
& FD_FLAG_TIMEOUT
)
717 ret
= NtWaitForSingleObject(hEvent
, TRUE
, NULL
);
719 if (ret
!= STATUS_USER_APC
)
720 fileio
->queue_apc_on_error
= 1;
724 LARGE_INTEGER timeout
;
726 /* let some APC be run, this will write as much data as possible */
727 timeout
.u
.LowPart
= timeout
.u
.HighPart
= 0;
728 ret
= NtDelayExecution( TRUE
, &timeout
);
729 /* the apc didn't run and therefore the completion routine now
730 * needs to be sent errors.
731 * Note that there is no race between setting this flag and
732 * returning errors because apc's are run only during alertable
734 if (ret
!= STATUS_USER_APC
)
735 fileio
->queue_apc_on_error
= 1;
737 return io_status
->u
.Status
;
742 FILE_POSITION_INFORMATION fpi
;
744 fpi
.CurrentByteOffset
= *offset
;
745 io_status
->u
.Status
= NtSetInformationFile(hFile
, io_status
, &fpi
, sizeof(fpi
),
746 FilePositionInformation
);
747 if (io_status
->u
.Status
)
749 wine_server_release_fd( hFile
, unix_handle
);
750 return io_status
->u
.Status
;
754 /* synchronous file write */
755 while ((io_status
->Information
= write( unix_handle
, buffer
, length
)) == -1)
757 if ((errno
== EAGAIN
) || (errno
== EINTR
)) continue;
760 io_status
->Information
= 0;
761 io_status
->u
.Status
= STATUS_INVALID_USER_BUFFER
;
763 else if (errno
== ENOSPC
) io_status
->u
.Status
= STATUS_DISK_FULL
;
764 else io_status
->u
.Status
= FILE_GetNtStatus();
767 wine_server_release_fd( hFile
, unix_handle
);
768 return io_status
->u
.Status
;
771 /**************************************************************************
772 * NtDeviceIoControlFile [NTDLL.@]
773 * ZwDeviceIoControlFile [NTDLL.@]
775 * Perform an I/O control operation on an open file handle.
778 * DeviceHandle [I] Handle returned from ZwOpenFile() or ZwCreateFile()
779 * Event [I] Event to signal upon completion (or NULL)
780 * ApcRoutine [I] Callback to call upon completion (or NULL)
781 * ApcContext [I] Context for ApcRoutine (or NULL)
782 * IoStatusBlock [O] Receives information about the operation on return
783 * IoControlCode [I] Control code for the operation to perform
784 * InputBuffer [I] Source for any input data required (or NULL)
785 * InputBufferSize [I] Size of InputBuffer
786 * OutputBuffer [O] Source for any output data returned (or NULL)
787 * OutputBufferSize [I] Size of OutputBuffer
790 * Success: 0. IoStatusBlock is updated.
791 * Failure: An NTSTATUS error code describing the error.
793 NTSTATUS WINAPI
NtDeviceIoControlFile(HANDLE DeviceHandle
, HANDLE hEvent
,
794 PIO_APC_ROUTINE UserApcRoutine
,
795 PVOID UserApcContext
,
796 PIO_STATUS_BLOCK IoStatusBlock
,
799 ULONG InputBufferSize
,
801 ULONG OutputBufferSize
)
803 TRACE("(%p,%p,%p,%p,%p,0x%08lx,%p,0x%08lx,%p,0x%08lx)\n",
804 DeviceHandle
, hEvent
, UserApcRoutine
, UserApcContext
,
805 IoStatusBlock
, IoControlCode
,
806 InputBuffer
, InputBufferSize
, OutputBuffer
, OutputBufferSize
);
808 if (CDROM_DeviceIoControl(DeviceHandle
, hEvent
,
809 UserApcRoutine
, UserApcContext
,
810 IoStatusBlock
, IoControlCode
,
811 InputBuffer
, InputBufferSize
,
812 OutputBuffer
, OutputBufferSize
) == STATUS_NO_SUCH_DEVICE
)
814 /* it wasn't a CDROM */
815 FIXME("Unimplemented dwIoControlCode=%08lx\n", IoControlCode
);
816 IoStatusBlock
->u
.Status
= STATUS_NOT_IMPLEMENTED
;
817 IoStatusBlock
->Information
= 0;
818 if (hEvent
) NtSetEvent(hEvent
, NULL
);
820 return IoStatusBlock
->u
.Status
;
823 /******************************************************************************
824 * NtFsControlFile [NTDLL.@]
825 * ZwFsControlFile [NTDLL.@]
827 NTSTATUS WINAPI
NtFsControlFile(
828 IN HANDLE DeviceHandle
,
829 IN HANDLE Event OPTIONAL
,
830 IN PIO_APC_ROUTINE ApcRoutine OPTIONAL
,
831 IN PVOID ApcContext OPTIONAL
,
832 OUT PIO_STATUS_BLOCK IoStatusBlock
,
833 IN ULONG IoControlCode
,
834 IN PVOID InputBuffer
,
835 IN ULONG InputBufferSize
,
836 OUT PVOID OutputBuffer
,
837 IN ULONG OutputBufferSize
)
839 FIXME("(%p,%p,%p,%p,%p,0x%08lx,%p,0x%08lx,%p,0x%08lx): stub\n",
840 DeviceHandle
,Event
,ApcRoutine
,ApcContext
,IoStatusBlock
,IoControlCode
,
841 InputBuffer
,InputBufferSize
,OutputBuffer
,OutputBufferSize
);
845 /******************************************************************************
846 * NtSetVolumeInformationFile [NTDLL.@]
847 * ZwSetVolumeInformationFile [NTDLL.@]
849 * Set volume information for an open file handle.
852 * FileHandle [I] Handle returned from ZwOpenFile() or ZwCreateFile()
853 * IoStatusBlock [O] Receives information about the operation on return
854 * FsInformation [I] Source for volume information
855 * Length [I] Size of FsInformation
856 * FsInformationClass [I] Type of volume information to set
859 * Success: 0. IoStatusBlock is updated.
860 * Failure: An NTSTATUS error code describing the error.
862 NTSTATUS WINAPI
NtSetVolumeInformationFile(
863 IN HANDLE FileHandle
,
864 PIO_STATUS_BLOCK IoStatusBlock
,
867 FS_INFORMATION_CLASS FsInformationClass
)
869 FIXME("(%p,%p,%p,0x%08lx,0x%08x) stub\n",
870 FileHandle
,IoStatusBlock
,FsInformation
,Length
,FsInformationClass
);
874 /******************************************************************************
875 * NtQueryInformationFile [NTDLL.@]
876 * ZwQueryInformationFile [NTDLL.@]
878 * Get information about an open file handle.
881 * hFile [I] Handle returned from ZwOpenFile() or ZwCreateFile()
882 * io [O] Receives information about the operation on return
883 * ptr [O] Destination for file information
884 * len [I] Size of FileInformation
885 * class [I] Type of file information to get
888 * Success: 0. IoStatusBlock and FileInformation are updated.
889 * Failure: An NTSTATUS error code describing the error.
891 NTSTATUS WINAPI
NtQueryInformationFile( HANDLE hFile
, PIO_STATUS_BLOCK io
,
892 PVOID ptr
, LONG len
, FILE_INFORMATION_CLASS
class )
894 static const size_t info_sizes
[] =
897 sizeof(FILE_DIRECTORY_INFORMATION
), /* FileDirectoryInformation */
898 sizeof(FILE_FULL_DIRECTORY_INFORMATION
), /* FileFullDirectoryInformation */
899 sizeof(FILE_BOTH_DIRECTORY_INFORMATION
), /* FileBothDirectoryInformation */
900 sizeof(FILE_BASIC_INFORMATION
), /* FileBasicInformation */
901 sizeof(FILE_STANDARD_INFORMATION
), /* FileStandardInformation */
902 sizeof(FILE_INTERNAL_INFORMATION
), /* FileInternalInformation */
903 sizeof(FILE_EA_INFORMATION
), /* FileEaInformation */
904 sizeof(FILE_ACCESS_INFORMATION
), /* FileAccessInformation */
905 sizeof(FILE_NAME_INFORMATION
)-sizeof(WCHAR
), /* FileNameInformation */
906 sizeof(FILE_RENAME_INFORMATION
)-sizeof(WCHAR
), /* FileRenameInformation */
907 0, /* FileLinkInformation */
908 sizeof(FILE_NAMES_INFORMATION
)-sizeof(WCHAR
), /* FileNamesInformation */
909 sizeof(FILE_DISPOSITION_INFORMATION
), /* FileDispositionInformation */
910 sizeof(FILE_POSITION_INFORMATION
), /* FilePositionInformation */
911 sizeof(FILE_FULL_EA_INFORMATION
), /* FileFullEaInformation */
912 sizeof(FILE_MODE_INFORMATION
), /* FileModeInformation */
913 sizeof(FILE_ALIGNMENT_INFORMATION
), /* FileAlignmentInformation */
914 sizeof(FILE_ALL_INFORMATION
)-sizeof(WCHAR
), /* FileAllInformation */
915 sizeof(FILE_ALLOCATION_INFORMATION
), /* FileAllocationInformation */
916 sizeof(FILE_END_OF_FILE_INFORMATION
), /* FileEndOfFileInformation */
917 0, /* FileAlternateNameInformation */
918 sizeof(FILE_STREAM_INFORMATION
)-sizeof(WCHAR
), /* FileStreamInformation */
919 0, /* FilePipeInformation */
920 0, /* FilePipeLocalInformation */
921 0, /* FilePipeRemoteInformation */
922 0, /* FileMailslotQueryInformation */
923 0, /* FileMailslotSetInformation */
924 0, /* FileCompressionInformation */
925 0, /* FileObjectIdInformation */
926 0, /* FileCompletionInformation */
927 0, /* FileMoveClusterInformation */
928 0, /* FileQuotaInformation */
929 0, /* FileReparsePointInformation */
930 0, /* FileNetworkOpenInformation */
931 0, /* FileAttributeTagInformation */
932 0 /* FileTrackingInformation */
938 TRACE("(%p,%p,%p,0x%08lx,0x%08x)\n", hFile
, io
, ptr
, len
, class);
942 if (class <= 0 || class >= FileMaximumInformation
)
943 return io
->u
.Status
= STATUS_INVALID_INFO_CLASS
;
944 if (!info_sizes
[class])
946 FIXME("Unsupported class (%d)\n", class);
947 return io
->u
.Status
= STATUS_NOT_IMPLEMENTED
;
949 if (len
< info_sizes
[class])
950 return io
->u
.Status
= STATUS_INFO_LENGTH_MISMATCH
;
952 if ((io
->u
.Status
= wine_server_handle_to_fd( hFile
, 0, &fd
, NULL
)))
957 case FileBasicInformation
:
959 FILE_BASIC_INFORMATION
*info
= ptr
;
961 if (fstat( fd
, &st
) == -1)
962 io
->u
.Status
= FILE_GetNtStatus();
963 else if (!S_ISREG(st
.st_mode
) && !S_ISDIR(st
.st_mode
))
964 io
->u
.Status
= STATUS_INVALID_INFO_CLASS
;
967 if (S_ISDIR(st
.st_mode
)) info
->FileAttributes
= FILE_ATTRIBUTE_DIRECTORY
;
968 else info
->FileAttributes
= FILE_ATTRIBUTE_ARCHIVE
;
969 if (!(st
.st_mode
& S_IWUSR
)) info
->FileAttributes
|= FILE_ATTRIBUTE_READONLY
;
970 RtlSecondsSince1970ToTime( st
.st_mtime
, &info
->CreationTime
);
971 RtlSecondsSince1970ToTime( st
.st_mtime
, &info
->LastWriteTime
);
972 RtlSecondsSince1970ToTime( st
.st_ctime
, &info
->ChangeTime
);
973 RtlSecondsSince1970ToTime( st
.st_atime
, &info
->LastAccessTime
);
977 case FileStandardInformation
:
979 FILE_STANDARD_INFORMATION
*info
= ptr
;
981 if (fstat( fd
, &st
) == -1) io
->u
.Status
= FILE_GetNtStatus();
984 if ((info
->Directory
= S_ISDIR(st
.st_mode
)))
986 info
->AllocationSize
.QuadPart
= 0;
987 info
->EndOfFile
.QuadPart
= 0;
988 info
->NumberOfLinks
= 1;
989 info
->DeletePending
= FALSE
;
993 info
->AllocationSize
.QuadPart
= (ULONGLONG
)st
.st_blocks
* 512;
994 info
->EndOfFile
.QuadPart
= st
.st_size
;
995 info
->NumberOfLinks
= st
.st_nlink
;
996 info
->DeletePending
= FALSE
; /* FIXME */
1001 case FilePositionInformation
:
1003 FILE_POSITION_INFORMATION
*info
= ptr
;
1004 off_t res
= lseek( fd
, 0, SEEK_CUR
);
1005 if (res
== (off_t
)-1) io
->u
.Status
= FILE_GetNtStatus();
1006 else info
->CurrentByteOffset
.QuadPart
= res
;
1009 case FileInternalInformation
:
1011 FILE_INTERNAL_INFORMATION
*info
= ptr
;
1013 if (fstat( fd
, &st
) == -1) io
->u
.Status
= FILE_GetNtStatus();
1014 else info
->IndexNumber
.QuadPart
= st
.st_ino
;
1017 case FileEaInformation
:
1019 FILE_EA_INFORMATION
*info
= ptr
;
1023 case FileEndOfFileInformation
:
1025 FILE_END_OF_FILE_INFORMATION
*info
= ptr
;
1027 if (fstat( fd
, &st
) == -1) io
->u
.Status
= FILE_GetNtStatus();
1028 else info
->EndOfFile
.QuadPart
= S_ISDIR(st
.st_mode
) ? 0 : st
.st_size
;
1031 case FileAllInformation
:
1033 FILE_ALL_INFORMATION
*info
= ptr
;
1035 if (fstat( fd
, &st
) == -1) io
->u
.Status
= FILE_GetNtStatus();
1036 else if (!S_ISREG(st
.st_mode
) && !S_ISDIR(st
.st_mode
))
1037 io
->u
.Status
= STATUS_INVALID_INFO_CLASS
;
1040 if ((info
->StandardInformation
.Directory
= S_ISDIR(st
.st_mode
)))
1042 info
->BasicInformation
.FileAttributes
= FILE_ATTRIBUTE_DIRECTORY
;
1043 info
->StandardInformation
.AllocationSize
.QuadPart
= 0;
1044 info
->StandardInformation
.EndOfFile
.QuadPart
= 0;
1045 info
->StandardInformation
.NumberOfLinks
= 1;
1046 info
->StandardInformation
.DeletePending
= FALSE
;
1050 info
->BasicInformation
.FileAttributes
= FILE_ATTRIBUTE_ARCHIVE
;
1051 info
->StandardInformation
.AllocationSize
.QuadPart
= (ULONGLONG
)st
.st_blocks
* 512;
1052 info
->StandardInformation
.EndOfFile
.QuadPart
= st
.st_size
;
1053 info
->StandardInformation
.NumberOfLinks
= st
.st_nlink
;
1054 info
->StandardInformation
.DeletePending
= FALSE
; /* FIXME */
1056 if (!(st
.st_mode
& S_IWUSR
))
1057 info
->BasicInformation
.FileAttributes
|= FILE_ATTRIBUTE_READONLY
;
1058 RtlSecondsSince1970ToTime( st
.st_mtime
, &info
->BasicInformation
.CreationTime
);
1059 RtlSecondsSince1970ToTime( st
.st_mtime
, &info
->BasicInformation
.LastWriteTime
);
1060 RtlSecondsSince1970ToTime( st
.st_ctime
, &info
->BasicInformation
.ChangeTime
);
1061 RtlSecondsSince1970ToTime( st
.st_atime
, &info
->BasicInformation
.LastAccessTime
);
1062 info
->InternalInformation
.IndexNumber
.QuadPart
= st
.st_ino
;
1063 info
->EaInformation
.EaSize
= 0;
1064 info
->AccessInformation
.AccessFlags
= 0; /* FIXME */
1065 info
->PositionInformation
.CurrentByteOffset
.QuadPart
= lseek( fd
, 0, SEEK_CUR
);
1066 info
->ModeInformation
.Mode
= 0; /* FIXME */
1067 info
->AlignmentInformation
.AlignmentRequirement
= 1; /* FIXME */
1068 info
->NameInformation
.FileNameLength
= 0;
1069 io
->Information
= sizeof(*info
) - sizeof(WCHAR
);
1074 FIXME("Unsupported class (%d)\n", class);
1075 io
->u
.Status
= STATUS_NOT_IMPLEMENTED
;
1078 wine_server_release_fd( hFile
, fd
);
1079 if (io
->u
.Status
== STATUS_SUCCESS
&& !io
->Information
) io
->Information
= info_sizes
[class];
1080 return io
->u
.Status
;
1083 /******************************************************************************
1084 * NtSetInformationFile [NTDLL.@]
1085 * ZwSetInformationFile [NTDLL.@]
1087 * Set information about an open file handle.
1090 * handle [I] Handle returned from ZwOpenFile() or ZwCreateFile()
1091 * io [O] Receives information about the operation on return
1092 * ptr [I] Source for file information
1093 * len [I] Size of FileInformation
1094 * class [I] Type of file information to set
1097 * Success: 0. io is updated.
1098 * Failure: An NTSTATUS error code describing the error.
1100 NTSTATUS WINAPI
NtSetInformationFile(HANDLE handle
, PIO_STATUS_BLOCK io
,
1101 PVOID ptr
, ULONG len
, FILE_INFORMATION_CLASS
class)
1105 TRACE("(%p,%p,%p,0x%08lx,0x%08x)\n", handle
, io
, ptr
, len
, class);
1107 if ((io
->u
.Status
= wine_server_handle_to_fd( handle
, 0, &fd
, NULL
)))
1108 return io
->u
.Status
;
1110 io
->u
.Status
= STATUS_SUCCESS
;
1113 case FileBasicInformation
:
1114 if (len
>= sizeof(FILE_BASIC_INFORMATION
))
1117 const FILE_BASIC_INFORMATION
*info
= ptr
;
1119 if (info
->LastAccessTime
.QuadPart
|| info
->LastWriteTime
.QuadPart
)
1121 ULONGLONG sec
, nsec
;
1122 struct timeval tv
[2];
1124 if (!info
->LastAccessTime
.QuadPart
|| !info
->LastWriteTime
.QuadPart
)
1127 tv
[0].tv_sec
= tv
[0].tv_usec
= 0;
1128 tv
[1].tv_sec
= tv
[1].tv_usec
= 0;
1129 if (!fstat( fd
, &st
))
1131 tv
[0].tv_sec
= st
.st_atime
;
1132 tv
[1].tv_sec
= st
.st_mtime
;
1135 if (info
->LastAccessTime
.QuadPart
)
1137 sec
= RtlLargeIntegerDivide( info
->LastAccessTime
.QuadPart
, 10000000, &nsec
);
1138 tv
[0].tv_sec
= sec
- SECS_1601_TO_1970
;
1139 tv
[0].tv_usec
= (UINT
)nsec
/ 10;
1141 if (info
->LastWriteTime
.QuadPart
)
1143 sec
= RtlLargeIntegerDivide( info
->LastWriteTime
.QuadPart
, 10000000, &nsec
);
1144 tv
[1].tv_sec
= sec
- SECS_1601_TO_1970
;
1145 tv
[1].tv_usec
= (UINT
)nsec
/ 10;
1147 if (futimes( fd
, tv
) == -1) io
->u
.Status
= FILE_GetNtStatus();
1150 if (io
->u
.Status
== STATUS_SUCCESS
&& info
->FileAttributes
)
1152 if (fstat( fd
, &st
) == -1) io
->u
.Status
= FILE_GetNtStatus();
1155 if (info
->FileAttributes
& FILE_ATTRIBUTE_READONLY
)
1157 if (S_ISDIR( st
.st_mode
))
1158 WARN("FILE_ATTRIBUTE_READONLY ignored for directory.\n");
1160 st
.st_mode
&= ~0222; /* clear write permission bits */
1164 /* add write permission only where we already have read permission */
1165 st
.st_mode
|= (0600 | ((st
.st_mode
& 044) >> 1)) & (~FILE_umask
);
1167 if (fchmod( fd
, st
.st_mode
) == -1) io
->u
.Status
= FILE_GetNtStatus();
1171 else io
->u
.Status
= STATUS_INVALID_PARAMETER_3
;
1174 case FilePositionInformation
:
1175 if (len
>= sizeof(FILE_POSITION_INFORMATION
))
1177 const FILE_POSITION_INFORMATION
*info
= ptr
;
1179 if (lseek( fd
, info
->CurrentByteOffset
.QuadPart
, SEEK_SET
) == (off_t
)-1)
1180 io
->u
.Status
= FILE_GetNtStatus();
1182 else io
->u
.Status
= STATUS_INVALID_PARAMETER_3
;
1185 case FileEndOfFileInformation
:
1186 if (len
>= sizeof(FILE_END_OF_FILE_INFORMATION
))
1189 const FILE_END_OF_FILE_INFORMATION
*info
= ptr
;
1191 /* first try normal truncate */
1192 if (ftruncate( fd
, (off_t
)info
->EndOfFile
.QuadPart
) != -1) break;
1194 /* now check for the need to extend the file */
1195 if (fstat( fd
, &st
) != -1 && (off_t
)info
->EndOfFile
.QuadPart
> st
.st_size
)
1197 static const char zero
;
1199 /* extend the file one byte beyond the requested size and then truncate it */
1200 /* this should work around ftruncate implementations that can't extend files */
1201 if (pwrite( fd
, &zero
, 1, (off_t
)info
->EndOfFile
.QuadPart
) != -1 &&
1202 ftruncate( fd
, (off_t
)info
->EndOfFile
.QuadPart
) != -1) break;
1204 io
->u
.Status
= FILE_GetNtStatus();
1206 else io
->u
.Status
= STATUS_INVALID_PARAMETER_3
;
1210 FIXME("Unsupported class (%d)\n", class);
1211 io
->u
.Status
= STATUS_NOT_IMPLEMENTED
;
1214 wine_server_release_fd( handle
, fd
);
1215 io
->Information
= 0;
1216 return io
->u
.Status
;
1220 /******************************************************************************
1221 * NtQueryFullAttributesFile (NTDLL.@)
1223 NTSTATUS WINAPI
NtQueryFullAttributesFile( const OBJECT_ATTRIBUTES
*attr
,
1224 FILE_NETWORK_OPEN_INFORMATION
*info
)
1226 ANSI_STRING unix_name
;
1229 if (!(status
= wine_nt_to_unix_file_name( attr
->ObjectName
, &unix_name
, FILE_OPEN
,
1230 !(attr
->Attributes
& OBJ_CASE_INSENSITIVE
) )))
1234 if (stat( unix_name
.Buffer
, &st
) == -1)
1235 status
= FILE_GetNtStatus();
1236 else if (!S_ISREG(st
.st_mode
) && !S_ISDIR(st
.st_mode
))
1237 status
= STATUS_INVALID_INFO_CLASS
;
1240 if (S_ISDIR(st
.st_mode
))
1242 info
->FileAttributes
= FILE_ATTRIBUTE_DIRECTORY
;
1243 info
->AllocationSize
.QuadPart
= 0;
1244 info
->EndOfFile
.QuadPart
= 0;
1248 info
->FileAttributes
= FILE_ATTRIBUTE_ARCHIVE
;
1249 info
->AllocationSize
.QuadPart
= (ULONGLONG
)st
.st_blocks
* 512;
1250 info
->EndOfFile
.QuadPart
= st
.st_size
;
1252 if (!(st
.st_mode
& S_IWUSR
)) info
->FileAttributes
|= FILE_ATTRIBUTE_READONLY
;
1253 RtlSecondsSince1970ToTime( st
.st_mtime
, &info
->CreationTime
);
1254 RtlSecondsSince1970ToTime( st
.st_mtime
, &info
->LastWriteTime
);
1255 RtlSecondsSince1970ToTime( st
.st_ctime
, &info
->ChangeTime
);
1256 RtlSecondsSince1970ToTime( st
.st_atime
, &info
->LastAccessTime
);
1257 if (DIR_is_hidden_file( attr
->ObjectName
))
1258 info
->FileAttributes
|= FILE_ATTRIBUTE_HIDDEN
;
1260 RtlFreeAnsiString( &unix_name
);
1262 else WARN("%s not found (%lx)\n", debugstr_us(attr
->ObjectName
), status
);
1267 /******************************************************************************
1268 * NtQueryAttributesFile (NTDLL.@)
1269 * ZwQueryAttributesFile (NTDLL.@)
1271 NTSTATUS WINAPI
NtQueryAttributesFile( const OBJECT_ATTRIBUTES
*attr
, FILE_BASIC_INFORMATION
*info
)
1273 FILE_NETWORK_OPEN_INFORMATION full_info
;
1276 if (!(status
= NtQueryFullAttributesFile( attr
, &full_info
)))
1278 info
->CreationTime
.QuadPart
= full_info
.CreationTime
.QuadPart
;
1279 info
->LastAccessTime
.QuadPart
= full_info
.LastAccessTime
.QuadPart
;
1280 info
->LastWriteTime
.QuadPart
= full_info
.LastWriteTime
.QuadPart
;
1281 info
->ChangeTime
.QuadPart
= full_info
.ChangeTime
.QuadPart
;
1282 info
->FileAttributes
= full_info
.FileAttributes
;
1288 /******************************************************************************
1289 * NtQueryVolumeInformationFile [NTDLL.@]
1290 * ZwQueryVolumeInformationFile [NTDLL.@]
1292 * Get volume information for an open file handle.
1295 * handle [I] Handle returned from ZwOpenFile() or ZwCreateFile()
1296 * io [O] Receives information about the operation on return
1297 * buffer [O] Destination for volume information
1298 * length [I] Size of FsInformation
1299 * info_class [I] Type of volume information to set
1302 * Success: 0. io and buffer are updated.
1303 * Failure: An NTSTATUS error code describing the error.
1305 NTSTATUS WINAPI
NtQueryVolumeInformationFile( HANDLE handle
, PIO_STATUS_BLOCK io
,
1306 PVOID buffer
, ULONG length
,
1307 FS_INFORMATION_CLASS info_class
)
1312 if ((io
->u
.Status
= wine_server_handle_to_fd( handle
, 0, &fd
, NULL
)) != STATUS_SUCCESS
)
1313 return io
->u
.Status
;
1315 io
->u
.Status
= STATUS_NOT_IMPLEMENTED
;
1316 io
->Information
= 0;
1318 switch( info_class
)
1320 case FileFsVolumeInformation
:
1321 FIXME( "%p: volume info not supported\n", handle
);
1323 case FileFsLabelInformation
:
1324 FIXME( "%p: label info not supported\n", handle
);
1326 case FileFsSizeInformation
:
1327 if (length
< sizeof(FILE_FS_SIZE_INFORMATION
))
1328 io
->u
.Status
= STATUS_BUFFER_TOO_SMALL
;
1331 FILE_FS_SIZE_INFORMATION
*info
= buffer
;
1333 if (fstat( fd
, &st
) < 0)
1335 io
->u
.Status
= FILE_GetNtStatus();
1338 if (!S_ISREG(st
.st_mode
) && !S_ISDIR(st
.st_mode
))
1340 io
->u
.Status
= STATUS_INVALID_DEVICE_REQUEST
;
1344 /* Linux's fstatvfs is buggy */
1345 #if !defined(linux) || !defined(HAVE_FSTATFS)
1346 struct statvfs stfs
;
1348 if (fstatvfs( fd
, &stfs
) < 0)
1350 io
->u
.Status
= FILE_GetNtStatus();
1353 info
->BytesPerSector
= stfs
.f_frsize
;
1356 if (fstatfs( fd
, &stfs
) < 0)
1358 io
->u
.Status
= FILE_GetNtStatus();
1361 info
->BytesPerSector
= stfs
.f_bsize
;
1363 info
->TotalAllocationUnits
.QuadPart
= stfs
.f_blocks
;
1364 info
->AvailableAllocationUnits
.QuadPart
= stfs
.f_bavail
;
1365 info
->SectorsPerAllocationUnit
= 1;
1366 io
->Information
= sizeof(*info
);
1367 io
->u
.Status
= STATUS_SUCCESS
;
1371 case FileFsDeviceInformation
:
1372 if (length
< sizeof(FILE_FS_DEVICE_INFORMATION
))
1373 io
->u
.Status
= STATUS_BUFFER_TOO_SMALL
;
1376 FILE_FS_DEVICE_INFORMATION
*info
= buffer
;
1378 info
->Characteristics
= 0;
1379 if (fstat( fd
, &st
) < 0)
1381 io
->u
.Status
= FILE_GetNtStatus();
1384 if (S_ISCHR( st
.st_mode
))
1386 info
->DeviceType
= FILE_DEVICE_UNKNOWN
;
1388 switch(major(st
.st_rdev
))
1391 info
->DeviceType
= FILE_DEVICE_NULL
;
1394 info
->DeviceType
= FILE_DEVICE_SERIAL_PORT
;
1397 info
->DeviceType
= FILE_DEVICE_PARALLEL_PORT
;
1402 else if (S_ISBLK( st
.st_mode
))
1404 info
->DeviceType
= FILE_DEVICE_DISK
;
1406 else if (S_ISFIFO( st
.st_mode
) || S_ISSOCK( st
.st_mode
))
1408 info
->DeviceType
= FILE_DEVICE_NAMED_PIPE
;
1410 else /* regular file or directory */
1412 #if defined(linux) && defined(HAVE_FSTATFS)
1415 /* check for floppy disk */
1416 if (major(st
.st_dev
) == FLOPPY_MAJOR
)
1417 info
->Characteristics
|= FILE_REMOVABLE_MEDIA
;
1419 if (fstatfs( fd
, &stfs
) < 0) stfs
.f_type
= 0;
1420 switch (stfs
.f_type
)
1422 case 0x9660: /* iso9660 */
1423 case 0x15013346: /* udf */
1424 info
->DeviceType
= FILE_DEVICE_CD_ROM_FILE_SYSTEM
;
1425 info
->Characteristics
|= FILE_REMOVABLE_MEDIA
|FILE_READ_ONLY_DEVICE
;
1427 case 0x6969: /* nfs */
1428 case 0x517B: /* smbfs */
1429 case 0x564c: /* ncpfs */
1430 info
->DeviceType
= FILE_DEVICE_NETWORK_FILE_SYSTEM
;
1431 info
->Characteristics
|= FILE_REMOTE_DEVICE
;
1433 case 0x01021994: /* tmpfs */
1434 case 0x28cd3d45: /* cramfs */
1435 case 0x1373: /* devfs */
1436 case 0x9fa0: /* procfs */
1437 info
->DeviceType
= FILE_DEVICE_VIRTUAL_DISK
;
1440 info
->DeviceType
= FILE_DEVICE_DISK_FILE_SYSTEM
;
1443 #elif defined (__APPLE__)
1444 #include <IOKit/IOKitLib.h>
1445 #include <CoreFoundation/CFNumber.h> /* for kCFBooleanTrue, kCFBooleanFalse */
1449 info
->DeviceType
= FILE_DEVICE_DISK_FILE_SYSTEM
;
1451 if (fstatfs( fd
, &stfs
) < 0) break;
1453 /* stfs.f_type is reserved (always set to 0) so use IOKit */
1454 kern_return_t kernResult
= KERN_FAILURE
;
1455 mach_port_t masterPort
;
1457 char bsdName
[6]; /* disk#\0 */
1459 strncpy(bsdName
, stfs
.f_mntfromname
+strlen(_PATH_DEV
) , 5);
1462 kernResult
= IOMasterPort(MACH_PORT_NULL
, &masterPort
);
1464 if (kernResult
== KERN_SUCCESS
)
1466 CFMutableDictionaryRef matching
= IOBSDNameMatching(masterPort
, 0, bsdName
);
1470 CFMutableDictionaryRef properties
;
1471 io_service_t devService
= IOServiceGetMatchingService(masterPort
, matching
);
1473 if (IORegistryEntryCreateCFProperties(devService
,
1475 kCFAllocatorDefault
, 0) != KERN_SUCCESS
)
1478 CFDictionaryGetValue(properties
, CFSTR("Removable")),
1480 ) info
->Characteristics
|= FILE_REMOVABLE_MEDIA
;
1483 CFDictionaryGetValue(properties
, CFSTR("Writable")),
1485 ) info
->Characteristics
|= FILE_READ_ONLY_DEVICE
;
1488 NB : mounted disk image (.img/.dmg) don't provide specific type
1491 if ( (type
= CFDictionaryGetValue(properties
, CFSTR("Type"))) )
1493 if ( CFStringCompare(type
, CFSTR("CD-ROM"), 0) == kCFCompareEqualTo
1494 || CFStringCompare(type
, CFSTR("DVD-ROM"), 0) == kCFCompareEqualTo
1497 info
->DeviceType
= FILE_DEVICE_CD_ROM_FILE_SYSTEM
;
1502 CFRelease(properties
);
1507 if (!warned
++) FIXME( "device info not properly supported on this platform\n" );
1508 info
->DeviceType
= FILE_DEVICE_DISK_FILE_SYSTEM
;
1510 info
->Characteristics
|= FILE_DEVICE_IS_MOUNTED
;
1512 io
->Information
= sizeof(*info
);
1513 io
->u
.Status
= STATUS_SUCCESS
;
1516 case FileFsAttributeInformation
:
1517 FIXME( "%p: attribute info not supported\n", handle
);
1519 case FileFsControlInformation
:
1520 FIXME( "%p: control info not supported\n", handle
);
1522 case FileFsFullSizeInformation
:
1523 FIXME( "%p: full size info not supported\n", handle
);
1525 case FileFsObjectIdInformation
:
1526 FIXME( "%p: object id info not supported\n", handle
);
1528 case FileFsMaximumInformation
:
1529 FIXME( "%p: maximum info not supported\n", handle
);
1532 io
->u
.Status
= STATUS_INVALID_PARAMETER
;
1535 wine_server_release_fd( handle
, fd
);
1536 return io
->u
.Status
;
1540 /******************************************************************
1541 * NtFlushBuffersFile (NTDLL.@)
1543 * Flush any buffered data on an open file handle.
1546 * FileHandle [I] Handle returned from ZwOpenFile() or ZwCreateFile()
1547 * IoStatusBlock [O] Receives information about the operation on return
1550 * Success: 0. IoStatusBlock is updated.
1551 * Failure: An NTSTATUS error code describing the error.
1553 NTSTATUS WINAPI
NtFlushBuffersFile( HANDLE hFile
, IO_STATUS_BLOCK
* IoStatusBlock
)
1556 HANDLE hEvent
= NULL
;
1558 SERVER_START_REQ( flush_file
)
1560 req
->handle
= hFile
;
1561 ret
= wine_server_call( req
);
1562 hEvent
= reply
->event
;
1567 ret
= NtWaitForSingleObject( hEvent
, FALSE
, NULL
);
1573 /******************************************************************
1574 * NtLockFile (NTDLL.@)
1578 NTSTATUS WINAPI
NtLockFile( HANDLE hFile
, HANDLE lock_granted_event
,
1579 PIO_APC_ROUTINE apc
, void* apc_user
,
1580 PIO_STATUS_BLOCK io_status
, PLARGE_INTEGER offset
,
1581 PLARGE_INTEGER count
, ULONG
* key
, BOOLEAN dont_wait
,
1588 if (apc
|| io_status
|| key
)
1590 FIXME("Unimplemented yet parameter\n");
1591 return STATUS_NOT_IMPLEMENTED
;
1596 SERVER_START_REQ( lock_file
)
1598 req
->handle
= hFile
;
1599 req
->offset_low
= offset
->u
.LowPart
;
1600 req
->offset_high
= offset
->u
.HighPart
;
1601 req
->count_low
= count
->u
.LowPart
;
1602 req
->count_high
= count
->u
.HighPart
;
1603 req
->shared
= !exclusive
;
1604 req
->wait
= !dont_wait
;
1605 ret
= wine_server_call( req
);
1606 handle
= reply
->handle
;
1607 async
= reply
->overlapped
;
1610 if (ret
!= STATUS_PENDING
)
1612 if (!ret
&& lock_granted_event
) NtSetEvent(lock_granted_event
, NULL
);
1618 FIXME( "Async I/O lock wait not implemented, might deadlock\n" );
1619 if (handle
) NtClose( handle
);
1620 return STATUS_PENDING
;
1624 NtWaitForSingleObject( handle
, FALSE
, NULL
);
1631 /* Unix lock conflict, sleep a bit and retry */
1632 time
.QuadPart
= 100 * (ULONGLONG
)10000;
1633 time
.QuadPart
= -time
.QuadPart
;
1634 NtDelayExecution( FALSE
, &time
);
1640 /******************************************************************
1641 * NtUnlockFile (NTDLL.@)
1645 NTSTATUS WINAPI
NtUnlockFile( HANDLE hFile
, PIO_STATUS_BLOCK io_status
,
1646 PLARGE_INTEGER offset
, PLARGE_INTEGER count
,
1651 TRACE( "%p %lx%08lx %lx%08lx\n",
1652 hFile
, offset
->u
.HighPart
, offset
->u
.LowPart
, count
->u
.HighPart
, count
->u
.LowPart
);
1654 if (io_status
|| key
)
1656 FIXME("Unimplemented yet parameter\n");
1657 return STATUS_NOT_IMPLEMENTED
;
1660 SERVER_START_REQ( unlock_file
)
1662 req
->handle
= hFile
;
1663 req
->offset_low
= offset
->u
.LowPart
;
1664 req
->offset_high
= offset
->u
.HighPart
;
1665 req
->count_low
= count
->u
.LowPart
;
1666 req
->count_high
= count
->u
.HighPart
;
1667 status
= wine_server_call( req
);
1673 /******************************************************************
1674 * NtCreateNamedPipeFile (NTDLL.@)
1678 NTSTATUS WINAPI
NtCreateNamedPipeFile( PHANDLE FileHandle
, ULONG DesiredAccess
,
1679 POBJECT_ATTRIBUTES ObjectAttributes
, PIO_STATUS_BLOCK IoStatusBlock
,
1680 ULONG ShareAccess
, ULONG CreateDisposition
, ULONG CreateOptions
,
1681 ULONG NamedPipeType
, ULONG ReadMode
, ULONG CompletionMode
,
1682 ULONG MaximumInstances
, ULONG InboundQuota
, ULONG OutboundQuota
,
1683 PLARGE_INTEGER DefaultTimeout
)
1685 FIXME("(%p %lx %p %p %lx %ld %lx %ld %ld %ld %ld %ld %ld %p): stub\n",
1686 FileHandle
, DesiredAccess
, ObjectAttributes
, IoStatusBlock
,
1687 ShareAccess
, CreateDisposition
, CreateOptions
, NamedPipeType
,
1688 ReadMode
, CompletionMode
, MaximumInstances
, InboundQuota
,
1689 OutboundQuota
, DefaultTimeout
);
1690 return STATUS_NOT_IMPLEMENTED
;
1693 /******************************************************************
1694 * NtDeleteFile (NTDLL.@)
1698 NTSTATUS WINAPI
NtDeleteFile( POBJECT_ATTRIBUTES ObjectAttributes
)
1704 TRACE("%p\n", ObjectAttributes
);
1705 status
= NtCreateFile( &hFile
, GENERIC_READ
| GENERIC_WRITE
, ObjectAttributes
,
1707 FILE_SHARE_READ
| FILE_SHARE_WRITE
| FILE_SHARE_DELETE
,
1708 FILE_OPEN
, FILE_DELETE_ON_CLOSE
, NULL
, 0 );
1709 if (status
== STATUS_SUCCESS
) status
= NtClose(hFile
);
1713 /******************************************************************
1714 * NtCancelIoFile (NTDLL.@)
1718 NTSTATUS WINAPI
NtCancelIoFile( HANDLE hFile
, PIO_STATUS_BLOCK io_status
)
1720 LARGE_INTEGER timeout
;
1722 TRACE("%p %p\n", hFile
, io_status
);
1724 SERVER_START_REQ( cancel_async
)
1726 req
->handle
= hFile
;
1727 wine_server_call( req
);
1730 /* Let some APC be run, so that we can run the remaining APCs on hFile
1731 * either the cancelation of the pending one, but also the execution
1732 * of the queued APC, but not yet run. This is needed to ensure proper
1733 * clean-up of allocated data.
1735 timeout
.u
.LowPart
= timeout
.u
.HighPart
= 0;
1736 return io_status
->u
.Status
= NtDelayExecution( TRUE
, &timeout
);