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"
29 #ifdef HAVE_SYS_ERRNO_H
30 #include <sys/errno.h>
33 #define NONAMELESSUNION
34 #define NONAMELESSSTRUCT
35 #include "wine/unicode.h"
36 #include "wine/debug.h"
37 #include "wine/server.h"
38 #include "ntdll_misc.h"
39 #include "file.h" /* FIXME */
44 WINE_DEFAULT_DEBUG_CHANNEL(ntdll
);
47 /**************************************************************************
48 * NtOpenFile [NTDLL.@]
49 * ZwOpenFile [NTDLL.@]
50 * FUNCTION: Opens a file
52 * FileHandle Variable that receives the file handle on return
53 * DesiredAccess Access desired by the caller to the file
54 * ObjectAttributes Structue describing the file to be opened
55 * IoStatusBlock Receives details about the result of the operation
56 * ShareAccess Type of shared access the caller requires
57 * OpenOptions Options for the file open
59 NTSTATUS WINAPI
NtOpenFile(
60 OUT PHANDLE FileHandle
,
61 ACCESS_MASK DesiredAccess
,
62 POBJECT_ATTRIBUTES ObjectAttributes
,
63 OUT PIO_STATUS_BLOCK IoStatusBlock
,
68 static const WCHAR szDosDevices
[] = {'\\','D','o','s','D','e','v','i','c','e','s','\\',0};
69 DOS_FULL_NAME full_name
;
72 FIXME("(%p,0x%08lx,%p,%p,0x%08lx,0x%08lx) partial stub\n",
73 FileHandle
, DesiredAccess
, ObjectAttributes
,
74 IoStatusBlock
, ShareAccess
, OpenOptions
);
76 dump_ObjectAttributes (ObjectAttributes
);
78 if(ObjectAttributes
->RootDirectory
)
80 FIXME("Object root directory unknown %p\n",
81 ObjectAttributes
->RootDirectory
);
82 return STATUS_OBJECT_NAME_NOT_FOUND
;
85 filename
= ObjectAttributes
->ObjectName
->Buffer
;
87 /* FIXME: DOSFS stuff should call here, not vice-versa */
88 if(strncmpW(filename
, szDosDevices
, strlenW(szDosDevices
)))
89 return STATUS_OBJECT_NAME_NOT_FOUND
;
91 /* FIXME: this calls SetLastError() -> bad */
92 if(!DOSFS_GetFullName(&filename
[strlenW(szDosDevices
)], TRUE
,
94 return STATUS_OBJECT_NAME_NOT_FOUND
;
96 /* FIXME: modify server protocol so
97 create file takes an OBJECT_ATTRIBUTES structure */
98 SERVER_START_REQ( create_file
)
100 req
->access
= DesiredAccess
;
102 req
->sharing
= ShareAccess
;
103 req
->create
= OPEN_EXISTING
;
105 req
->drive_type
= GetDriveTypeW( full_name
.short_name
);
106 wine_server_add_data( req
, full_name
.long_name
, strlen(full_name
.long_name
) );
108 r
= wine_server_call( req
);
109 *FileHandle
= reply
->handle
;
116 /**************************************************************************
117 * NtCreateFile [NTDLL.@]
118 * ZwCreateFile [NTDLL.@]
119 * FUNCTION: Either causes a new file or directory to be created, or it opens
120 * an existing file, device, directory or volume, giving the caller a handle
121 * for the file object. This handle can be used by subsequent calls to
122 * manipulate data within the file or the file object's state of attributes.
124 * FileHandle Points to a variable which receives the file handle on return
125 * DesiredAccess Desired access to the file
126 * ObjectAttributes Structure describing the file
127 * IoStatusBlock Receives information about the operation on return
128 * AllocationSize Initial size of the file in bytes
129 * FileAttributes Attributes to create the file with
130 * ShareAccess Type of shared access the caller would like to the file
131 * CreateDisposition Specifies what to do, depending on whether the file already exists
132 * CreateOptions Options for creating a new file
133 * EaBuffer Undocumented
134 * EaLength Undocumented
136 NTSTATUS WINAPI
NtCreateFile(
137 OUT PHANDLE FileHandle
,
138 ACCESS_MASK DesiredAccess
,
139 POBJECT_ATTRIBUTES ObjectAttributes
,
140 OUT PIO_STATUS_BLOCK IoStatusBlock
,
141 PLARGE_INTEGER AllocateSize
,
142 ULONG FileAttributes
,
144 ULONG CreateDisposition
,
149 FIXME("(%p,0x%08lx,%p,%p,%p,0x%08lx,0x%08lx,0x%08lx,0x%08lx,%p,0x%08lx) stub\n",
150 FileHandle
,DesiredAccess
,ObjectAttributes
,
151 IoStatusBlock
,AllocateSize
,FileAttributes
,
152 ShareAccess
,CreateDisposition
,CreateOptions
,EaBuffer
,EaLength
);
153 dump_ObjectAttributes (ObjectAttributes
);
157 /* set the last error depending on errno */
158 NTSTATUS
NTFILE_errno_to_status(int val
)
162 case EAGAIN
: return ( STATUS_SHARING_VIOLATION
);
164 case EBADF
: return ( STATUS_INVALID_HANDLE
);
165 case ENOSPC
: return ( STATUS_DISK_FULL
);
168 case EPERM
: return ( STATUS_ACCESS_DENIED
);
169 case EROFS
: return ( STATUS_MEDIA_WRITE_PROTECTED
);
170 case EBUSY
: return ( STATUS_FILE_LOCK_CONFLICT
);
171 case ENOENT
: return ( STATUS_NO_SUCH_FILE
);
172 case EISDIR
: return ( STATUS_FILE_IS_A_DIRECTORY
);
174 case EMFILE
: return ( STATUS_NO_MORE_FILES
);
175 case EEXIST
: return ( STATUS_OBJECT_NAME_COLLISION
);
176 case EINVAL
: return ( STATUS_INVALID_PARAMETER
);
177 case ENOTEMPTY
: return ( STATUS_DIRECTORY_NOT_EMPTY
);
178 case EIO
: return ( STATUS_ACCESS_VIOLATION
);
180 perror("file_set_error");
181 return ( STATUS_INVALID_PARAMETER
);
185 /******************************************************************************
186 * NtReadFile [NTDLL.@]
187 * ZwReadFile [NTDLL.@]
190 * HANDLE32 FileHandle
191 * HANDLE32 Event OPTIONAL
192 * PIO_APC_ROUTINE ApcRoutine OPTIONAL
193 * PVOID ApcContext OPTIONAL
194 * PIO_STATUS_BLOCK IoStatusBlock
197 * PLARGE_INTEGER ByteOffset OPTIONAL
198 * PULONG Key OPTIONAL
200 * IoStatusBlock->Information contains the number of bytes read on return.
202 NTSTATUS WINAPI
NtReadFile (
205 PIO_APC_ROUTINE ApcRoutine
,
207 PIO_STATUS_BLOCK IoStatusBlock
,
210 PLARGE_INTEGER ByteOffset
,
213 int fd
, result
, flags
, ret
;
216 FIXME("(%p,%p,%p,%p,%p,%p,0x%08lx,%p,%p),partial stub!\n",
217 FileHandle
,EventHandle
,ApcRoutine
,ApcContext
,IoStatusBlock
,Buffer
,Length
,ByteOffset
,Key
);
219 if (IsBadWritePtr( Buffer
, Length
) ||
220 IsBadWritePtr( IoStatusBlock
, sizeof *IoStatusBlock
) ||
221 IsBadWritePtr( ByteOffset
, sizeof *ByteOffset
) )
222 return STATUS_ACCESS_VIOLATION
;
224 IoStatusBlock
->Information
= 0;
226 ret
= wine_server_handle_to_fd( FileHandle
, GENERIC_READ
, &fd
, &type
, &flags
);
230 /* FIXME: this code only does synchronous reads so far */
232 /* FIXME: depending on how libc implements this, between two processes
233 there could be a race condition between the seek and read here */
236 result
= pread( fd
, Buffer
, Length
, ByteOffset
->QuadPart
);
238 while ( (result
== -1) && ((errno
== EAGAIN
) || (errno
== EINTR
)) );
244 return IoStatusBlock
->u
.Status
= NTFILE_errno_to_status(errno
);
247 IoStatusBlock
->Information
= result
;
248 IoStatusBlock
->u
.Status
= 0;
250 return STATUS_SUCCESS
;
253 /******************************************************************************
254 * NtWriteFile [NTDLL.@]
255 * ZwWriteFile [NTDLL.@]
258 * HANDLE32 FileHandle
259 * HANDLE32 Event OPTIONAL
260 * PIO_APC_ROUTINE ApcRoutine OPTIONAL
261 * PVOID ApcContext OPTIONAL
262 * PIO_STATUS_BLOCK IoStatusBlock
265 * PLARGE_INTEGER ByteOffset OPTIONAL
266 * PULONG Key OPTIONAL
268 NTSTATUS WINAPI
NtWriteFile (
271 PIO_APC_ROUTINE ApcRoutine
,
273 PIO_STATUS_BLOCK IoStatusBlock
,
276 PLARGE_INTEGER ByteOffset
,
279 FIXME("(%p,%p,%p,%p,%p,%p,0x%08lx,%p,%p),stub!\n",
280 FileHandle
,EventHandle
,ApcRoutine
,ApcContext
,IoStatusBlock
,Buffer
,Length
,ByteOffset
,Key
);
284 /**************************************************************************
285 * NtDeviceIoControlFile [NTDLL.@]
286 * ZwDeviceIoControlFile [NTDLL.@]
288 NTSTATUS WINAPI
NtDeviceIoControlFile(
289 IN HANDLE DeviceHandle
,
290 IN HANDLE Event OPTIONAL
,
291 IN PIO_APC_ROUTINE UserApcRoutine OPTIONAL
,
292 IN PVOID UserApcContext OPTIONAL
,
293 OUT PIO_STATUS_BLOCK IoStatusBlock
,
294 IN ULONG IoControlCode
,
295 IN PVOID InputBuffer
,
296 IN ULONG InputBufferSize
,
297 OUT PVOID OutputBuffer
,
298 IN ULONG OutputBufferSize
)
300 FIXME("(%p,%p,%p,%p,%p,0x%08lx,%p,0x%08lx,%p,0x%08lx): empty stub\n",
301 DeviceHandle
, Event
, UserApcRoutine
, UserApcContext
,
302 IoStatusBlock
, IoControlCode
, InputBuffer
, InputBufferSize
, OutputBuffer
, OutputBufferSize
);
306 /******************************************************************************
307 * NtFsControlFile [NTDLL.@]
308 * ZwFsControlFile [NTDLL.@]
310 NTSTATUS WINAPI
NtFsControlFile(
311 IN HANDLE DeviceHandle
,
312 IN HANDLE Event OPTIONAL
,
313 IN PIO_APC_ROUTINE ApcRoutine OPTIONAL
,
314 IN PVOID ApcContext OPTIONAL
,
315 OUT PIO_STATUS_BLOCK IoStatusBlock
,
316 IN ULONG IoControlCode
,
317 IN PVOID InputBuffer
,
318 IN ULONG InputBufferSize
,
319 OUT PVOID OutputBuffer
,
320 IN ULONG OutputBufferSize
)
322 FIXME("(%p,%p,%p,%p,%p,0x%08lx,%p,0x%08lx,%p,0x%08lx): stub\n",
323 DeviceHandle
,Event
,ApcRoutine
,ApcContext
,IoStatusBlock
,IoControlCode
,
324 InputBuffer
,InputBufferSize
,OutputBuffer
,OutputBufferSize
);
328 /******************************************************************************
329 * NtSetVolumeInformationFile [NTDLL.@]
330 * ZwSetVolumeInformationFile [NTDLL.@]
332 NTSTATUS WINAPI
NtSetVolumeInformationFile(
333 IN HANDLE FileHandle
,
334 PIO_STATUS_BLOCK IoStatusBlock
,
337 FS_INFORMATION_CLASS FsInformationClass
)
339 FIXME("(%p,%p,%p,0x%08lx,0x%08x) stub\n",
340 FileHandle
,IoStatusBlock
,FsInformation
,Length
,FsInformationClass
);
344 /******************************************************************************
345 * NtQueryInformationFile [NTDLL.@]
346 * ZwQueryInformationFile [NTDLL.@]
348 NTSTATUS WINAPI
NtQueryInformationFile(
350 PIO_STATUS_BLOCK IoStatusBlock
,
351 PVOID FileInformation
,
353 FILE_INFORMATION_CLASS FileInformationClass
)
355 FIXME("(%p,%p,%p,0x%08lx,0x%08x),stub!\n",
356 FileHandle
,IoStatusBlock
,FileInformation
,Length
,FileInformationClass
);
360 /******************************************************************************
361 * NtSetInformationFile [NTDLL.@]
362 * ZwSetInformationFile [NTDLL.@]
364 NTSTATUS WINAPI
NtSetInformationFile(
366 PIO_STATUS_BLOCK IoStatusBlock
,
367 PVOID FileInformation
,
369 FILE_INFORMATION_CLASS FileInformationClass
)
371 FIXME("(%p,%p,%p,0x%08lx,0x%08x)\n",
372 FileHandle
,IoStatusBlock
,FileInformation
,Length
,FileInformationClass
);
376 /******************************************************************************
377 * NtQueryDirectoryFile [NTDLL.@]
378 * ZwQueryDirectoryFile [NTDLL.@]
379 * ZwQueryDirectoryFile
381 NTSTATUS WINAPI
NtQueryDirectoryFile(
382 IN HANDLE FileHandle
,
383 IN HANDLE Event OPTIONAL
,
384 IN PIO_APC_ROUTINE ApcRoutine OPTIONAL
,
385 IN PVOID ApcContext OPTIONAL
,
386 OUT PIO_STATUS_BLOCK IoStatusBlock
,
387 OUT PVOID FileInformation
,
389 IN FILE_INFORMATION_CLASS FileInformationClass
,
390 IN BOOLEAN ReturnSingleEntry
,
391 IN PUNICODE_STRING FileName OPTIONAL
,
392 IN BOOLEAN RestartScan
)
394 FIXME("(%p %p %p %p %p %p 0x%08lx 0x%08x 0x%08x %p 0x%08x\n",
395 FileHandle
, Event
, ApcRoutine
, ApcContext
, IoStatusBlock
, FileInformation
,
396 Length
, FileInformationClass
, ReturnSingleEntry
,
397 debugstr_us(FileName
),RestartScan
);
401 /******************************************************************************
402 * NtQueryVolumeInformationFile [NTDLL.@]
403 * ZwQueryVolumeInformationFile [NTDLL.@]
405 NTSTATUS WINAPI
NtQueryVolumeInformationFile (
406 IN HANDLE FileHandle
,
407 OUT PIO_STATUS_BLOCK IoStatusBlock
,
408 OUT PVOID FSInformation
,
410 IN FS_INFORMATION_CLASS FSInformationClass
)
414 FIXME("(%p %p %p 0x%08lx 0x%08x) stub!\n",
415 FileHandle
, IoStatusBlock
, FSInformation
, Length
, FSInformationClass
);
417 switch ( FSInformationClass
)
419 case FileFsVolumeInformation
:
420 len
= sizeof( FILE_FS_VOLUME_INFORMATION
);
422 case FileFsLabelInformation
:
426 case FileFsSizeInformation
:
427 len
= sizeof( FILE_FS_SIZE_INFORMATION
);
430 case FileFsDeviceInformation
:
431 len
= sizeof( FILE_FS_DEVICE_INFORMATION
);
433 case FileFsAttributeInformation
:
434 len
= sizeof( FILE_FS_ATTRIBUTE_INFORMATION
);
437 case FileFsControlInformation
:
441 case FileFsFullSizeInformation
:
445 case FileFsObjectIdInformation
:
449 case FileFsMaximumInformation
:
455 return STATUS_BUFFER_TOO_SMALL
;
457 switch ( FSInformationClass
)
459 case FileFsVolumeInformation
:
461 case FileFsLabelInformation
:
464 case FileFsSizeInformation
:
467 case FileFsDeviceInformation
:
470 FILE_FS_DEVICE_INFORMATION
* DeviceInfo
= FSInformation
;
471 DeviceInfo
->DeviceType
= FILE_DEVICE_DISK
;
472 DeviceInfo
->Characteristics
= 0;
475 case FileFsAttributeInformation
:
478 case FileFsControlInformation
:
481 case FileFsFullSizeInformation
:
484 case FileFsObjectIdInformation
:
487 case FileFsMaximumInformation
:
490 IoStatusBlock
->DUMMYUNIONNAME
.Status
= STATUS_SUCCESS
;
491 IoStatusBlock
->Information
= len
;
492 return STATUS_SUCCESS
;