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>
32 #include "wine/unicode.h"
33 #include "wine/debug.h"
34 #include "wine/server.h"
35 #include "ntdll_misc.h"
36 #include "file.h" /* FIXME */
41 WINE_DEFAULT_DEBUG_CHANNEL(ntdll);
44 /**************************************************************************
45 * NtOpenFile [NTDLL.@]
46 * ZwOpenFile [NTDLL.@]
47 * FUNCTION: Opens a file
49 * FileHandle Variable that receives the file handle on return
50 * DesiredAccess Access desired by the caller to the file
51 * ObjectAttributes Structue describing the file to be opened
52 * IoStatusBlock Receives details about the result of the operation
53 * ShareAccess Type of shared access the caller requires
54 * OpenOptions Options for the file open
56 NTSTATUS WINAPI NtOpenFile(
57 OUT PHANDLE FileHandle,
58 ACCESS_MASK DesiredAccess,
59 POBJECT_ATTRIBUTES ObjectAttributes,
60 OUT PIO_STATUS_BLOCK IoStatusBlock,
65 static const WCHAR szDosDevices[] = {'\\','D','o','s','D','e','v','i','c','e','s','\\',0};
66 DOS_FULL_NAME full_name;
69 FIXME("(%p,0x%08lx,%p,%p,0x%08lx,0x%08lx) partial stub\n",
70 FileHandle, DesiredAccess, ObjectAttributes,
71 IoStatusBlock, ShareAccess, OpenOptions);
73 dump_ObjectAttributes (ObjectAttributes);
75 if(ObjectAttributes->RootDirectory)
77 FIXME("Object root directory unknown %x\n",
78 ObjectAttributes->RootDirectory);
79 return STATUS_OBJECT_NAME_NOT_FOUND;
82 filename = ObjectAttributes->ObjectName->Buffer;
84 /* FIXME: DOSFS stuff should call here, not vice-versa */
85 if(strncmpW(filename, szDosDevices, strlenW(szDosDevices)))
86 return STATUS_OBJECT_NAME_NOT_FOUND;
88 /* FIXME: this calls SetLastError() -> bad */
89 if(!DOSFS_GetFullName(&filename[strlenW(szDosDevices)], TRUE,
91 return STATUS_OBJECT_NAME_NOT_FOUND;
93 /* FIXME: modify server protocol so
94 create file takes an OBJECT_ATTRIBUTES structure */
95 SERVER_START_REQ( create_file )
97 req->access = DesiredAccess;
99 req->sharing = ShareAccess;
100 req->create = OPEN_EXISTING;
102 req->drive_type = GetDriveTypeW( full_name.short_name );
103 wine_server_add_data( req, full_name.long_name, strlen(full_name.long_name) );
105 r = wine_server_call( req );
106 *FileHandle = reply->handle;
113 /**************************************************************************
114 * NtCreateFile [NTDLL.@]
115 * ZwCreateFile [NTDLL.@]
116 * FUNCTION: Either causes a new file or directory to be created, or it opens
117 * an existing file, device, directory or volume, giving the caller a handle
118 * for the file object. This handle can be used by subsequent calls to
119 * manipulate data within the file or the file object's state of attributes.
121 * FileHandle Points to a variable which receives the file handle on return
122 * DesiredAccess Desired access to the file
123 * ObjectAttributes Structure describing the file
124 * IoStatusBlock Receives information about the operation on return
125 * AllocationSize Initial size of the file in bytes
126 * FileAttributes Attributes to create the file with
127 * ShareAccess Type of shared access the caller would like to the file
128 * CreateDisposition Specifies what to do, depending on whether the file already exists
129 * CreateOptions Options for creating a new file
130 * EaBuffer Undocumented
131 * EaLength Undocumented
133 NTSTATUS WINAPI NtCreateFile(
134 OUT PHANDLE FileHandle,
135 ACCESS_MASK DesiredAccess,
136 POBJECT_ATTRIBUTES ObjectAttributes,
137 OUT PIO_STATUS_BLOCK IoStatusBlock,
138 PLARGE_INTEGER AllocateSize,
139 ULONG FileAttributes,
141 ULONG CreateDisposition,
146 FIXME("(%p,0x%08lx,%p,%p,%p,0x%08lx,0x%08lx,0x%08lx,0x%08lx,%p,0x%08lx) stub\n",
147 FileHandle,DesiredAccess,ObjectAttributes,
148 IoStatusBlock,AllocateSize,FileAttributes,
149 ShareAccess,CreateDisposition,CreateOptions,EaBuffer,EaLength);
150 dump_ObjectAttributes (ObjectAttributes);
154 /* set the last error depending on errno */
155 NTSTATUS NTFILE_errno_to_status(int val)
159 case EAGAIN: return ( STATUS_SHARING_VIOLATION );
161 case EBADF: return ( STATUS_INVALID_HANDLE );
162 case ENOSPC: return ( STATUS_DISK_FULL );
165 case EPERM: return ( STATUS_ACCESS_DENIED );
166 case EROFS: return ( STATUS_MEDIA_WRITE_PROTECTED );
167 case EBUSY: return ( STATUS_FILE_LOCK_CONFLICT );
168 case ENOENT: return ( STATUS_NO_SUCH_FILE );
169 case EISDIR: return ( STATUS_FILE_IS_A_DIRECTORY );
171 case EMFILE: return ( STATUS_NO_MORE_FILES );
172 case EEXIST: return ( STATUS_OBJECT_NAME_COLLISION );
173 case EINVAL: return ( STATUS_INVALID_PARAMETER );
174 case ENOTEMPTY: return ( STATUS_DIRECTORY_NOT_EMPTY );
175 case EIO: return ( STATUS_ACCESS_VIOLATION );
177 perror("file_set_error");
178 return ( STATUS_INVALID_PARAMETER );
182 /******************************************************************************
183 * NtReadFile [NTDLL.@]
184 * ZwReadFile [NTDLL.@]
187 * HANDLE32 FileHandle
188 * HANDLE32 Event OPTIONAL
189 * PIO_APC_ROUTINE ApcRoutine OPTIONAL
190 * PVOID ApcContext OPTIONAL
191 * PIO_STATUS_BLOCK IoStatusBlock
194 * PLARGE_INTEGER ByteOffset OPTIONAL
195 * PULONG Key OPTIONAL
197 * IoStatusBlock->Information contains the number of bytes read on return.
199 NTSTATUS WINAPI NtReadFile (
202 PIO_APC_ROUTINE ApcRoutine,
204 PIO_STATUS_BLOCK IoStatusBlock,
207 PLARGE_INTEGER ByteOffset,
210 int fd, result, flags, ret;
213 FIXME("(0x%08x,0x%08x,%p,%p,%p,%p,0x%08lx,%p,%p),partial stub!\n",
214 FileHandle,EventHandle,ApcRoutine,ApcContext,IoStatusBlock,Buffer,Length,ByteOffset,Key);
216 if (IsBadWritePtr( Buffer, Length ) ||
217 IsBadWritePtr( IoStatusBlock, sizeof *IoStatusBlock) ||
218 IsBadWritePtr( ByteOffset, sizeof *ByteOffset) )
219 return STATUS_ACCESS_VIOLATION;
221 IoStatusBlock->Information = 0;
223 ret = wine_server_handle_to_fd( FileHandle, GENERIC_READ, &fd, &type, &flags );
227 /* FIXME: this code only does synchronous reads so far */
229 /* FIXME: depending on how libc implements this, between two processes
230 there could be a race condition between the seek and read here */
233 result = pread( fd, Buffer, Length, ByteOffset->QuadPart);
235 while ( (result == -1) && ((errno == EAGAIN) || (errno == EINTR)) );
241 return IoStatusBlock->u.Status = NTFILE_errno_to_status(errno);
244 IoStatusBlock->Information = result;
245 IoStatusBlock->u.Status = 0;
247 return STATUS_SUCCESS;
250 /******************************************************************************
251 * NtWriteFile [NTDLL.@]
252 * ZwWriteFile [NTDLL.@]
255 * HANDLE32 FileHandle
256 * HANDLE32 Event OPTIONAL
257 * PIO_APC_ROUTINE ApcRoutine OPTIONAL
258 * PVOID ApcContext OPTIONAL
259 * PIO_STATUS_BLOCK IoStatusBlock
262 * PLARGE_INTEGER ByteOffset OPTIONAL
263 * PULONG Key OPTIONAL
265 NTSTATUS WINAPI NtWriteFile (
268 PIO_APC_ROUTINE ApcRoutine,
270 PIO_STATUS_BLOCK IoStatusBlock,
273 PLARGE_INTEGER ByteOffset,
276 FIXME("(0x%08x,0x%08x,%p,%p,%p,%p,0x%08lx,%p,%p),stub!\n",
277 FileHandle,EventHandle,ApcRoutine,ApcContext,IoStatusBlock,Buffer,Length,ByteOffset,Key);
281 /**************************************************************************
282 * NtDeviceIoControlFile [NTDLL.@]
283 * ZwDeviceIoControlFile [NTDLL.@]
285 NTSTATUS WINAPI NtDeviceIoControlFile(
286 IN HANDLE DeviceHandle,
287 IN HANDLE Event OPTIONAL,
288 IN PIO_APC_ROUTINE UserApcRoutine OPTIONAL,
289 IN PVOID UserApcContext OPTIONAL,
290 OUT PIO_STATUS_BLOCK IoStatusBlock,
291 IN ULONG IoControlCode,
292 IN PVOID InputBuffer,
293 IN ULONG InputBufferSize,
294 OUT PVOID OutputBuffer,
295 IN ULONG OutputBufferSize)
297 FIXME("(0x%08x,0x%08x,%p,%p,%p,0x%08lx,%p,0x%08lx,%p,0x%08lx): empty stub\n",
298 DeviceHandle, Event, UserApcRoutine, UserApcContext,
299 IoStatusBlock, IoControlCode, InputBuffer, InputBufferSize, OutputBuffer, OutputBufferSize);
303 /******************************************************************************
304 * NtFsControlFile [NTDLL.@]
305 * ZwFsControlFile [NTDLL.@]
307 NTSTATUS WINAPI NtFsControlFile(
308 IN HANDLE DeviceHandle,
309 IN HANDLE Event OPTIONAL,
310 IN PIO_APC_ROUTINE ApcRoutine OPTIONAL,
311 IN PVOID ApcContext OPTIONAL,
312 OUT PIO_STATUS_BLOCK IoStatusBlock,
313 IN ULONG IoControlCode,
314 IN PVOID InputBuffer,
315 IN ULONG InputBufferSize,
316 OUT PVOID OutputBuffer,
317 IN ULONG OutputBufferSize)
319 FIXME("(0x%08x,0x%08x,%p,%p,%p,0x%08lx,%p,0x%08lx,%p,0x%08lx): stub\n",
320 DeviceHandle,Event,ApcRoutine,ApcContext,IoStatusBlock,IoControlCode,
321 InputBuffer,InputBufferSize,OutputBuffer,OutputBufferSize);
325 /******************************************************************************
326 * NtSetVolumeInformationFile [NTDLL.@]
327 * ZwSetVolumeInformationFile [NTDLL.@]
329 NTSTATUS WINAPI NtSetVolumeInformationFile(
330 IN HANDLE FileHandle,
331 PIO_STATUS_BLOCK IoStatusBlock,
334 FS_INFORMATION_CLASS FsInformationClass)
336 FIXME("(0x%08x,%p,%p,0x%08lx,0x%08x) stub\n",
337 FileHandle,IoStatusBlock,FsInformation,Length,FsInformationClass);
341 /******************************************************************************
342 * NtQueryInformationFile [NTDLL.@]
343 * ZwQueryInformationFile [NTDLL.@]
345 NTSTATUS WINAPI NtQueryInformationFile(
347 PIO_STATUS_BLOCK IoStatusBlock,
348 PVOID FileInformation,
350 FILE_INFORMATION_CLASS FileInformationClass)
352 FIXME("(0x%08x,%p,%p,0x%08lx,0x%08x),stub!\n",
353 FileHandle,IoStatusBlock,FileInformation,Length,FileInformationClass);
357 /******************************************************************************
358 * NtSetInformationFile [NTDLL.@]
359 * ZwSetInformationFile [NTDLL.@]
361 NTSTATUS WINAPI NtSetInformationFile(
363 PIO_STATUS_BLOCK IoStatusBlock,
364 PVOID FileInformation,
366 FILE_INFORMATION_CLASS FileInformationClass)
368 FIXME("(0x%08x,%p,%p,0x%08lx,0x%08x)\n",
369 FileHandle,IoStatusBlock,FileInformation,Length,FileInformationClass);
373 /******************************************************************************
374 * NtQueryDirectoryFile [NTDLL.@]
375 * ZwQueryDirectoryFile [NTDLL.@]
376 * ZwQueryDirectoryFile
378 NTSTATUS WINAPI NtQueryDirectoryFile(
379 IN HANDLE FileHandle,
380 IN HANDLE Event OPTIONAL,
381 IN PIO_APC_ROUTINE ApcRoutine OPTIONAL,
382 IN PVOID ApcContext OPTIONAL,
383 OUT PIO_STATUS_BLOCK IoStatusBlock,
384 OUT PVOID FileInformation,
386 IN FILE_INFORMATION_CLASS FileInformationClass,
387 IN BOOLEAN ReturnSingleEntry,
388 IN PUNICODE_STRING FileName OPTIONAL,
389 IN BOOLEAN RestartScan)
391 FIXME("(0x%08x 0x%08x %p %p %p %p 0x%08lx 0x%08x 0x%08x %p 0x%08x\n",
392 FileHandle, Event, ApcRoutine, ApcContext, IoStatusBlock, FileInformation,
393 Length, FileInformationClass, ReturnSingleEntry,
394 debugstr_us(FileName),RestartScan);
398 /******************************************************************************
399 * NtQueryVolumeInformationFile [NTDLL.@]
400 * ZwQueryVolumeInformationFile [NTDLL.@]
402 NTSTATUS WINAPI NtQueryVolumeInformationFile (
403 IN HANDLE FileHandle,
404 OUT PIO_STATUS_BLOCK IoStatusBlock,
405 OUT PVOID FSInformation,
407 IN FS_INFORMATION_CLASS FSInformationClass)
411 FIXME("(0x%08x %p %p 0x%08lx 0x%08x) stub!\n",
412 FileHandle, IoStatusBlock, FSInformation, Length, FSInformationClass);
414 switch ( FSInformationClass )
416 case FileFsVolumeInformation:
417 len = sizeof( FILE_FS_VOLUME_INFORMATION );
419 case FileFsLabelInformation:
423 case FileFsSizeInformation:
424 len = sizeof( FILE_FS_SIZE_INFORMATION );
427 case FileFsDeviceInformation:
428 len = sizeof( FILE_FS_DEVICE_INFORMATION );
430 case FileFsAttributeInformation:
431 len = sizeof( FILE_FS_ATTRIBUTE_INFORMATION );
434 case FileFsControlInformation:
438 case FileFsFullSizeInformation:
442 case FileFsObjectIdInformation:
446 case FileFsMaximumInformation:
452 return STATUS_BUFFER_TOO_SMALL;
454 switch ( FSInformationClass )
456 case FileFsVolumeInformation:
458 case FileFsLabelInformation:
461 case FileFsSizeInformation:
464 case FileFsDeviceInformation:
467 FILE_FS_DEVICE_INFORMATION * DeviceInfo = FSInformation;
468 DeviceInfo->DeviceType = FILE_DEVICE_DISK;
469 DeviceInfo->Characteristics = 0;
472 case FileFsAttributeInformation:
475 case FileFsControlInformation:
478 case FileFsFullSizeInformation:
481 case FileFsObjectIdInformation:
484 case FileFsMaximumInformation:
487 IoStatusBlock->DUMMYUNIONNAME.Status = STATUS_SUCCESS;
488 IoStatusBlock->Information = len;
489 return STATUS_SUCCESS;