2002-03-10 00:29:33 +01:00
|
|
|
/*
|
|
|
|
* Copyright 1999, 2000 Juergen Schmied
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
2006-05-18 14:49:52 +02:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
2002-03-10 00:29:33 +01:00
|
|
|
*/
|
|
|
|
|
2002-06-14 02:36:20 +02:00
|
|
|
#include "config.h"
|
|
|
|
#include "wine/port.h"
|
|
|
|
|
1999-03-09 18:47:51 +01:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
2002-06-14 02:36:20 +02:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <errno.h>
|
2003-06-26 04:08:17 +02:00
|
|
|
#include <assert.h>
|
2002-08-17 02:43:16 +02:00
|
|
|
#ifdef HAVE_UNISTD_H
|
|
|
|
# include <unistd.h>
|
|
|
|
#endif
|
2004-04-07 05:58:55 +02:00
|
|
|
#ifdef HAVE_LINUX_MAJOR_H
|
|
|
|
# include <linux/major.h>
|
|
|
|
#endif
|
2004-04-06 06:19:41 +02:00
|
|
|
#ifdef HAVE_SYS_STATVFS_H
|
|
|
|
# include <sys/statvfs.h>
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_SYS_PARAM_H
|
|
|
|
# include <sys/param.h>
|
|
|
|
#endif
|
2013-10-29 10:24:34 +01:00
|
|
|
#ifdef HAVE_SYS_SYSCALL_H
|
|
|
|
# include <sys/syscall.h>
|
|
|
|
#endif
|
2004-04-20 02:36:29 +02:00
|
|
|
#ifdef HAVE_SYS_TIME_H
|
|
|
|
# include <sys/time.h>
|
|
|
|
#endif
|
2006-11-09 09:18:43 +01:00
|
|
|
#ifdef HAVE_SYS_IOCTL_H
|
|
|
|
#include <sys/ioctl.h>
|
|
|
|
#endif
|
2008-08-26 20:40:57 +02:00
|
|
|
#ifdef HAVE_SYS_FILIO_H
|
|
|
|
# include <sys/filio.h>
|
|
|
|
#endif
|
2006-11-01 16:24:36 +01:00
|
|
|
#ifdef HAVE_POLL_H
|
|
|
|
#include <poll.h>
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_SYS_POLL_H
|
|
|
|
#include <sys/poll.h>
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_SYS_SOCKET_H
|
|
|
|
#include <sys/socket.h>
|
|
|
|
#endif
|
2016-04-17 21:25:38 +02:00
|
|
|
#ifdef MAJOR_IN_MKDEV
|
|
|
|
# include <sys/mkdev.h>
|
|
|
|
#elif defined(MAJOR_IN_SYSMACROS)
|
|
|
|
# include <sys/sysmacros.h>
|
|
|
|
#endif
|
2004-04-20 02:36:29 +02:00
|
|
|
#ifdef HAVE_UTIME_H
|
|
|
|
# include <utime.h>
|
|
|
|
#endif
|
2006-02-06 21:53:27 +01:00
|
|
|
#ifdef HAVE_SYS_VFS_H
|
2015-10-05 10:01:56 +02:00
|
|
|
/* Work around a conflict with Solaris' system list defined in sys/list.h. */
|
|
|
|
#define list SYSLIST
|
|
|
|
#define list_next SYSLIST_NEXT
|
|
|
|
#define list_prev SYSLIST_PREV
|
|
|
|
#define list_head SYSLIST_HEAD
|
|
|
|
#define list_tail SYSLIST_TAIL
|
|
|
|
#define list_move_tail SYSLIST_MOVE_TAIL
|
|
|
|
#define list_remove SYSLIST_REMOVE
|
2004-04-06 06:19:41 +02:00
|
|
|
# include <sys/vfs.h>
|
2015-10-05 10:01:56 +02:00
|
|
|
#undef list
|
|
|
|
#undef list_next
|
|
|
|
#undef list_prev
|
|
|
|
#undef list_head
|
|
|
|
#undef list_tail
|
|
|
|
#undef list_move_tail
|
|
|
|
#undef list_remove
|
2006-02-06 21:53:27 +01:00
|
|
|
#endif
|
|
|
|
#ifdef HAVE_SYS_MOUNT_H
|
|
|
|
# include <sys/mount.h>
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_SYS_STATFS_H
|
|
|
|
# include <sys/statfs.h>
|
2004-04-06 06:19:41 +02:00
|
|
|
#endif
|
2009-01-20 17:52:38 +01:00
|
|
|
#ifdef HAVE_TERMIOS_H
|
|
|
|
#include <termios.h>
|
|
|
|
#endif
|
2009-12-14 15:32:50 +01:00
|
|
|
#ifdef HAVE_VALGRIND_MEMCHECK_H
|
|
|
|
# include <valgrind/memcheck.h>
|
|
|
|
#endif
|
2003-01-07 21:36:20 +01:00
|
|
|
|
2005-11-28 17:32:54 +01:00
|
|
|
#include "ntstatus.h"
|
|
|
|
#define WIN32_NO_STATUS
|
2015-03-14 03:38:17 +01:00
|
|
|
#define NONAMELESSUNION
|
2002-03-10 00:29:33 +01:00
|
|
|
#include "wine/debug.h"
|
2002-06-14 02:36:20 +02:00
|
|
|
#include "wine/server.h"
|
- implementation of RtlReg* (read access), RtlEvent*, RtlSemaphore*,
NtAllocateLocallyUniqueId
- implementation or stubs for NtAccessCheck, NtSetSecurityObject,
RtlClearBits, RtlEqualPrefixSid, RtlFindClearBits,
RtlFormatCurrentUserKeyPath, RtlGetControlSecurityDescriptor,
RtlIdentifierAuthoritySid, RtlImpersonateSelf, RtlInitializeBitMap,
RtlInitializeGenericTable, RtlMakeSelfRelativeSD,
RtlPrefixUnicodeString, RtlSetBits, RtlUnicodeToMultiByteN,
RtlUpcaseUnicodeStringToOemString, RtlUpcaseUnicodeToOemN,
RtlValidSid, RtlxUnicodeStringToOemSize
- corrected most RtlString* functions, added documentation
- more fixes and partial implementations
2000-01-23 23:35:33 +01:00
|
|
|
#include "ntdll_misc.h"
|
1999-03-09 18:47:51 +01:00
|
|
|
|
2002-09-13 00:07:02 +02:00
|
|
|
#include "winternl.h"
|
2002-05-09 21:40:30 +02:00
|
|
|
#include "winioctl.h"
|
2012-12-04 10:40:16 +01:00
|
|
|
#include "ddk/ntddk.h"
|
2007-04-06 16:05:53 +02:00
|
|
|
#include "ddk/ntddser.h"
|
2020-03-27 16:32:31 +01:00
|
|
|
#define WINE_MOUNTMGR_EXTENSIONS
|
|
|
|
#include "ddk/mountmgr.h"
|
1999-03-09 18:47:51 +01:00
|
|
|
|
2002-03-10 00:29:33 +01:00
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(ntdll);
|
2010-06-11 11:13:17 +02:00
|
|
|
WINE_DECLARE_DEBUG_CHANNEL(winediag);
|
1999-04-19 16:56:29 +02:00
|
|
|
|
2004-04-20 02:36:29 +02:00
|
|
|
mode_t FILE_umask = 0;
|
|
|
|
|
|
|
|
#define SECSPERDAY 86400
|
|
|
|
#define SECS_1601_TO_1970 ((369 * 365 + 89) * (ULONGLONG)SECSPERDAY)
|
|
|
|
|
2013-10-09 16:13:41 +02:00
|
|
|
#define FILE_WRITE_TO_END_OF_FILE ((LONGLONG)-1)
|
|
|
|
#define FILE_USE_FILE_POINTER_POSITION ((LONGLONG)-2)
|
|
|
|
|
2014-08-20 04:31:00 +02:00
|
|
|
/* fetch the attributes of a file */
|
|
|
|
static inline ULONG get_file_attributes( const struct stat *st )
|
|
|
|
{
|
|
|
|
ULONG attr;
|
|
|
|
|
|
|
|
if (S_ISDIR(st->st_mode))
|
|
|
|
attr = FILE_ATTRIBUTE_DIRECTORY;
|
|
|
|
else
|
|
|
|
attr = FILE_ATTRIBUTE_ARCHIVE;
|
|
|
|
if (!(st->st_mode & (S_IWUSR | S_IWGRP | S_IWOTH)))
|
|
|
|
attr |= FILE_ATTRIBUTE_READONLY;
|
|
|
|
return attr;
|
|
|
|
}
|
|
|
|
|
2020-03-20 18:15:26 +01:00
|
|
|
static BOOL fd_is_mount_point( int fd, const struct stat *st )
|
|
|
|
{
|
|
|
|
struct stat parent;
|
|
|
|
return S_ISDIR( st->st_mode ) && !fstatat( fd, "..", &parent, 0 )
|
|
|
|
&& (parent.st_dev != st->st_dev || parent.st_ino == st->st_ino);
|
|
|
|
}
|
|
|
|
|
2014-08-20 04:31:00 +02:00
|
|
|
/* get the stat info and file attributes for a file (by file descriptor) */
|
2020-03-20 18:15:26 +01:00
|
|
|
int fd_get_file_info( int fd, unsigned int options, struct stat *st, ULONG *attr )
|
2014-08-20 04:31:00 +02:00
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
*attr = 0;
|
|
|
|
ret = fstat( fd, st );
|
|
|
|
if (ret == -1) return ret;
|
|
|
|
*attr |= get_file_attributes( st );
|
2020-03-20 18:15:26 +01:00
|
|
|
/* consider mount points to be reparse points (IO_REPARSE_TAG_MOUNT_POINT) */
|
|
|
|
if ((options & FILE_OPEN_REPARSE_POINT) && fd_is_mount_point( fd, st ))
|
|
|
|
*attr |= FILE_ATTRIBUTE_REPARSE_POINT;
|
2014-08-20 04:31:00 +02:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* get the stat info and file attributes for a file (by name) */
|
|
|
|
int get_file_info( const char *path, struct stat *st, ULONG *attr )
|
|
|
|
{
|
2020-03-20 18:15:25 +01:00
|
|
|
char *parent_path;
|
2014-08-20 04:31:00 +02:00
|
|
|
int ret;
|
|
|
|
|
|
|
|
*attr = 0;
|
|
|
|
ret = lstat( path, st );
|
|
|
|
if (ret == -1) return ret;
|
|
|
|
if (S_ISLNK( st->st_mode ))
|
|
|
|
{
|
|
|
|
ret = stat( path, st );
|
|
|
|
if (ret == -1) return ret;
|
|
|
|
/* is a symbolic link and a directory, consider these "reparse points" */
|
|
|
|
if (S_ISDIR( st->st_mode )) *attr |= FILE_ATTRIBUTE_REPARSE_POINT;
|
|
|
|
}
|
2020-03-20 18:15:25 +01:00
|
|
|
else if (S_ISDIR( st->st_mode ) && (parent_path = RtlAllocateHeap( GetProcessHeap(), 0, strlen(path) + 4 )))
|
|
|
|
{
|
|
|
|
struct stat parent_st;
|
|
|
|
|
|
|
|
/* consider mount points to be reparse points (IO_REPARSE_TAG_MOUNT_POINT) */
|
|
|
|
strcpy( parent_path, path );
|
|
|
|
strcat( parent_path, "/.." );
|
|
|
|
if (!stat( parent_path, &parent_st )
|
|
|
|
&& (st->st_dev != parent_st.st_dev || st->st_ino == parent_st.st_ino))
|
|
|
|
*attr |= FILE_ATTRIBUTE_REPARSE_POINT;
|
|
|
|
|
|
|
|
RtlFreeHeap( GetProcessHeap(), 0, parent_path );
|
|
|
|
}
|
2014-08-20 04:31:00 +02:00
|
|
|
*attr |= get_file_attributes( st );
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
1999-03-09 18:47:51 +01:00
|
|
|
/**************************************************************************
|
2009-06-05 11:56:54 +02:00
|
|
|
* FILE_CreateFile (internal)
|
|
|
|
* Open a file.
|
2003-07-19 00:55:28 +02:00
|
|
|
*
|
2009-06-05 11:56:54 +02:00
|
|
|
* Parameter set fully identical with NtCreateFile
|
1999-03-09 18:47:51 +01:00
|
|
|
*/
|
2009-06-05 11:56:54 +02:00
|
|
|
static NTSTATUS FILE_CreateFile( PHANDLE handle, ACCESS_MASK access, POBJECT_ATTRIBUTES attr,
|
|
|
|
PIO_STATUS_BLOCK io, PLARGE_INTEGER alloc_size,
|
|
|
|
ULONG attributes, ULONG sharing, ULONG disposition,
|
|
|
|
ULONG options, PVOID ea_buffer, ULONG ea_length )
|
1999-03-09 18:47:51 +01:00
|
|
|
{
|
2004-04-13 01:31:09 +02:00
|
|
|
ANSI_STRING unix_name;
|
2013-11-01 00:21:24 +01:00
|
|
|
BOOL created = FALSE;
|
2004-04-13 01:31:09 +02:00
|
|
|
|
2009-12-07 21:25:20 +01:00
|
|
|
TRACE("handle=%p access=%08x name=%s objattr=%08x root=%p sec=%p io=%p alloc_size=%p "
|
2006-10-16 13:49:06 +02:00
|
|
|
"attr=%08x sharing=%08x disp=%d options=%08x ea=%p.0x%08x\n",
|
2004-04-13 01:31:09 +02:00
|
|
|
handle, access, debugstr_us(attr->ObjectName), attr->Attributes,
|
|
|
|
attr->RootDirectory, attr->SecurityDescriptor, io, alloc_size,
|
|
|
|
attributes, sharing, disposition, options, ea_buffer, ea_length );
|
|
|
|
|
2005-03-21 11:28:23 +01:00
|
|
|
if (!attr || !attr->ObjectName) return STATUS_INVALID_PARAMETER;
|
|
|
|
|
2004-04-13 01:31:09 +02:00
|
|
|
if (alloc_size) FIXME( "alloc_size not supported\n" );
|
|
|
|
|
2009-12-02 17:35:43 +01:00
|
|
|
if (options & FILE_OPEN_BY_FILE_ID)
|
|
|
|
io->u.Status = file_id_to_unix_file_name( attr, &unix_name );
|
|
|
|
else
|
|
|
|
io->u.Status = nt_to_unix_file_name_attr( attr, &unix_name, disposition );
|
|
|
|
|
|
|
|
if (io->u.Status == STATUS_BAD_DEVICE_TYPE)
|
2005-12-12 14:27:45 +01:00
|
|
|
{
|
|
|
|
SERVER_START_REQ( open_file_object )
|
|
|
|
{
|
|
|
|
req->access = access;
|
|
|
|
req->attributes = attr->Attributes;
|
2008-12-08 16:05:17 +01:00
|
|
|
req->rootdir = wine_server_obj_handle( attr->RootDirectory );
|
2005-12-12 14:27:45 +01:00
|
|
|
req->sharing = sharing;
|
2007-03-22 11:52:40 +01:00
|
|
|
req->options = options;
|
2005-12-12 14:27:45 +01:00
|
|
|
wine_server_add_data( req, attr->ObjectName->Buffer, attr->ObjectName->Length );
|
|
|
|
io->u.Status = wine_server_call( req );
|
2008-12-08 16:05:17 +01:00
|
|
|
*handle = wine_server_ptr_handle( reply->handle );
|
2005-12-12 14:27:45 +01:00
|
|
|
}
|
|
|
|
SERVER_END_REQ;
|
2008-01-07 12:17:42 +01:00
|
|
|
if (io->u.Status == STATUS_SUCCESS) io->Information = FILE_OPENED;
|
2005-12-12 14:27:45 +01:00
|
|
|
return io->u.Status;
|
|
|
|
}
|
|
|
|
|
2004-04-27 04:15:52 +02:00
|
|
|
if (io->u.Status == STATUS_NO_SUCH_FILE &&
|
|
|
|
disposition != FILE_OPEN && disposition != FILE_OVERWRITE)
|
2004-04-22 00:26:44 +02:00
|
|
|
{
|
|
|
|
created = TRUE;
|
|
|
|
io->u.Status = STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (io->u.Status == STATUS_SUCCESS)
|
2004-04-13 01:31:09 +02:00
|
|
|
{
|
2016-01-28 13:24:12 +01:00
|
|
|
static UNICODE_STRING empty_string;
|
2016-01-15 09:40:56 +01:00
|
|
|
OBJECT_ATTRIBUTES unix_attr = *attr;
|
|
|
|
data_size_t len;
|
|
|
|
struct object_attributes *objattr;
|
2007-10-26 18:02:16 +02:00
|
|
|
|
2016-01-28 13:24:12 +01:00
|
|
|
unix_attr.ObjectName = &empty_string; /* we send the unix name instead */
|
2016-01-15 09:40:56 +01:00
|
|
|
if ((io->u.Status = alloc_object_attributes( &unix_attr, &objattr, &len )))
|
2007-10-26 18:02:16 +02:00
|
|
|
{
|
2009-12-02 17:38:05 +01:00
|
|
|
RtlFreeAnsiString( &unix_name );
|
|
|
|
return io->u.Status;
|
2007-10-26 18:02:16 +02:00
|
|
|
}
|
|
|
|
|
2004-04-13 01:31:09 +02:00
|
|
|
SERVER_START_REQ( create_file )
|
|
|
|
{
|
|
|
|
req->access = access;
|
|
|
|
req->sharing = sharing;
|
|
|
|
req->create = disposition;
|
|
|
|
req->options = options;
|
|
|
|
req->attrs = attributes;
|
2016-01-15 09:40:56 +01:00
|
|
|
wine_server_add_data( req, objattr, len );
|
2004-04-13 01:31:09 +02:00
|
|
|
wine_server_add_data( req, unix_name.Buffer, unix_name.Length );
|
|
|
|
io->u.Status = wine_server_call( req );
|
2008-12-08 16:05:17 +01:00
|
|
|
*handle = wine_server_ptr_handle( reply->handle );
|
2004-04-13 01:31:09 +02:00
|
|
|
}
|
|
|
|
SERVER_END_REQ;
|
2016-01-15 09:40:56 +01:00
|
|
|
RtlFreeHeap( GetProcessHeap(), 0, objattr );
|
2004-04-13 01:31:09 +02:00
|
|
|
RtlFreeAnsiString( &unix_name );
|
|
|
|
}
|
2006-10-16 13:49:06 +02:00
|
|
|
else WARN("%s not found (%x)\n", debugstr_us(attr->ObjectName), io->u.Status );
|
2004-04-22 00:26:44 +02:00
|
|
|
|
|
|
|
if (io->u.Status == STATUS_SUCCESS)
|
|
|
|
{
|
|
|
|
if (created) io->Information = FILE_CREATED;
|
|
|
|
else switch(disposition)
|
|
|
|
{
|
|
|
|
case FILE_SUPERSEDE:
|
|
|
|
io->Information = FILE_SUPERSEDED;
|
|
|
|
break;
|
|
|
|
case FILE_CREATE:
|
|
|
|
io->Information = FILE_CREATED;
|
|
|
|
break;
|
|
|
|
case FILE_OPEN:
|
|
|
|
case FILE_OPEN_IF:
|
|
|
|
io->Information = FILE_OPENED;
|
|
|
|
break;
|
|
|
|
case FILE_OVERWRITE:
|
|
|
|
case FILE_OVERWRITE_IF:
|
|
|
|
io->Information = FILE_OVERWRITTEN;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2010-06-11 11:13:17 +02:00
|
|
|
else if (io->u.Status == STATUS_TOO_MANY_OPENED_FILES)
|
|
|
|
{
|
|
|
|
static int once;
|
|
|
|
if (!once++) ERR_(winediag)( "Too many open files, ulimit -n probably needs to be increased\n" );
|
|
|
|
}
|
2004-04-22 00:26:44 +02:00
|
|
|
|
2004-04-13 01:31:09 +02:00
|
|
|
return io->u.Status;
|
1999-03-09 18:47:51 +01:00
|
|
|
}
|
|
|
|
|
2009-06-05 11:56:54 +02:00
|
|
|
/**************************************************************************
|
|
|
|
* NtOpenFile [NTDLL.@]
|
|
|
|
* ZwOpenFile [NTDLL.@]
|
|
|
|
*
|
|
|
|
* Open a file.
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* handle [O] Variable that receives the file handle on return
|
|
|
|
* access [I] Access desired by the caller to the file
|
|
|
|
* attr [I] Structure describing the file to be opened
|
|
|
|
* io [O] Receives details about the result of the operation
|
|
|
|
* sharing [I] Type of shared access the caller requires
|
|
|
|
* options [I] Options for the file open
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Success: 0. FileHandle and IoStatusBlock are updated.
|
|
|
|
* Failure: An NTSTATUS error code describing the error.
|
|
|
|
*/
|
|
|
|
NTSTATUS WINAPI NtOpenFile( PHANDLE handle, ACCESS_MASK access,
|
|
|
|
POBJECT_ATTRIBUTES attr, PIO_STATUS_BLOCK io,
|
|
|
|
ULONG sharing, ULONG options )
|
|
|
|
{
|
|
|
|
return FILE_CreateFile( handle, access, attr, io, NULL, 0,
|
|
|
|
sharing, FILE_OPEN, options, NULL, 0 );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
* NtCreateFile [NTDLL.@]
|
|
|
|
* ZwCreateFile [NTDLL.@]
|
|
|
|
*
|
|
|
|
* Either create a new file or directory, or open an existing file, device,
|
|
|
|
* directory or volume.
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* handle [O] Points to a variable which receives the file handle on return
|
|
|
|
* access [I] Desired access to the file
|
|
|
|
* attr [I] Structure describing the file
|
|
|
|
* io [O] Receives information about the operation on return
|
|
|
|
* alloc_size [I] Initial size of the file in bytes
|
|
|
|
* attributes [I] Attributes to create the file with
|
|
|
|
* sharing [I] Type of shared access the caller would like to the file
|
|
|
|
* disposition [I] Specifies what to do, depending on whether the file already exists
|
|
|
|
* options [I] Options for creating a new file
|
|
|
|
* ea_buffer [I] Pointer to an extended attributes buffer
|
|
|
|
* ea_length [I] Length of ea_buffer
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Success: 0. handle and io are updated.
|
|
|
|
* Failure: An NTSTATUS error code describing the error.
|
|
|
|
*/
|
|
|
|
NTSTATUS WINAPI NtCreateFile( PHANDLE handle, ACCESS_MASK access, POBJECT_ATTRIBUTES attr,
|
|
|
|
PIO_STATUS_BLOCK io, PLARGE_INTEGER alloc_size,
|
|
|
|
ULONG attributes, ULONG sharing, ULONG disposition,
|
|
|
|
ULONG options, PVOID ea_buffer, ULONG ea_length )
|
|
|
|
{
|
|
|
|
return FILE_CreateFile( handle, access, attr, io, alloc_size, attributes,
|
|
|
|
sharing, disposition, options, ea_buffer, ea_length );
|
|
|
|
}
|
|
|
|
|
2003-06-26 04:08:17 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* Asynchronous file I/O *
|
|
|
|
*/
|
|
|
|
|
2017-04-10 13:41:29 +02:00
|
|
|
typedef NTSTATUS async_callback_t( void *user, IO_STATUS_BLOCK *io, NTSTATUS status );
|
2017-04-10 13:20:38 +02:00
|
|
|
|
2007-06-03 12:05:02 +02:00
|
|
|
struct async_fileio
|
2003-06-26 04:08:17 +02:00
|
|
|
{
|
2017-04-10 13:20:38 +02:00
|
|
|
async_callback_t *callback; /* must be the first field */
|
2015-03-02 09:53:40 +01:00
|
|
|
struct async_fileio *next;
|
|
|
|
HANDLE handle;
|
2007-06-03 12:05:02 +02:00
|
|
|
};
|
|
|
|
|
2015-03-02 08:56:47 +01:00
|
|
|
struct async_fileio_read
|
2007-06-03 12:05:02 +02:00
|
|
|
{
|
|
|
|
struct async_fileio io;
|
2005-01-14 20:54:38 +01:00
|
|
|
char* buffer;
|
2007-04-05 11:03:38 +02:00
|
|
|
unsigned int already;
|
2005-01-14 20:54:38 +01:00
|
|
|
unsigned int count;
|
|
|
|
BOOL avail_mode;
|
2015-03-02 08:56:47 +01:00
|
|
|
};
|
2003-06-26 04:08:17 +02:00
|
|
|
|
2015-03-02 08:56:47 +01:00
|
|
|
struct async_fileio_write
|
2003-06-26 04:08:17 +02:00
|
|
|
{
|
2007-06-03 12:05:02 +02:00
|
|
|
struct async_fileio io;
|
2007-04-10 17:19:24 +02:00
|
|
|
const char *buffer;
|
|
|
|
unsigned int already;
|
|
|
|
unsigned int count;
|
2015-03-02 08:56:47 +01:00
|
|
|
};
|
2005-01-14 20:54:38 +01:00
|
|
|
|
2015-05-05 06:35:57 +02:00
|
|
|
struct async_irp
|
|
|
|
{
|
|
|
|
struct async_fileio io;
|
|
|
|
void *buffer; /* buffer for output */
|
|
|
|
ULONG size; /* size of buffer */
|
|
|
|
};
|
|
|
|
|
2015-03-02 09:53:40 +01:00
|
|
|
static struct async_fileio *fileio_freelist;
|
|
|
|
|
|
|
|
static void release_fileio( struct async_fileio *io )
|
|
|
|
{
|
|
|
|
for (;;)
|
|
|
|
{
|
|
|
|
struct async_fileio *next = fileio_freelist;
|
|
|
|
io->next = next;
|
2020-05-02 15:10:04 +02:00
|
|
|
if (InterlockedCompareExchangePointer( (void **)&fileio_freelist, io, next ) == next) return;
|
2015-03-02 09:53:40 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-04-10 13:21:56 +02:00
|
|
|
static struct async_fileio *alloc_fileio( DWORD size, async_callback_t callback, HANDLE handle )
|
2015-03-02 09:53:40 +01:00
|
|
|
{
|
|
|
|
/* first free remaining previous fileinfos */
|
|
|
|
|
2020-05-02 15:10:04 +02:00
|
|
|
struct async_fileio *io = InterlockedExchangePointer( (void **)&fileio_freelist, NULL );
|
2015-03-02 09:53:40 +01:00
|
|
|
|
|
|
|
while (io)
|
|
|
|
{
|
|
|
|
struct async_fileio *next = io->next;
|
|
|
|
RtlFreeHeap( GetProcessHeap(), 0, io );
|
|
|
|
io = next;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((io = RtlAllocateHeap( GetProcessHeap(), 0, size )))
|
|
|
|
{
|
2017-04-10 13:20:38 +02:00
|
|
|
io->callback = callback;
|
|
|
|
io->handle = handle;
|
2015-03-02 09:53:40 +01:00
|
|
|
}
|
|
|
|
return io;
|
|
|
|
}
|
2003-06-26 04:08:17 +02:00
|
|
|
|
2017-04-10 13:21:04 +02:00
|
|
|
static async_data_t server_async( HANDLE handle, struct async_fileio *user, HANDLE event,
|
|
|
|
PIO_APC_ROUTINE apc, void *apc_context, IO_STATUS_BLOCK *io )
|
|
|
|
{
|
|
|
|
async_data_t async;
|
2017-04-10 13:21:31 +02:00
|
|
|
async.handle = wine_server_obj_handle( handle );
|
|
|
|
async.user = wine_server_client_ptr( user );
|
|
|
|
async.iosb = wine_server_client_ptr( io );
|
|
|
|
async.event = wine_server_obj_handle( event );
|
|
|
|
async.apc = wine_server_client_ptr( apc );
|
|
|
|
async.apc_context = wine_server_client_ptr( apc_context );
|
2017-04-10 13:21:04 +02:00
|
|
|
return async;
|
|
|
|
}
|
|
|
|
|
2019-05-23 19:35:51 +02:00
|
|
|
static NTSTATUS wait_async( HANDLE handle, BOOL alertable, IO_STATUS_BLOCK *io )
|
|
|
|
{
|
2019-05-23 19:36:27 +02:00
|
|
|
if (NtWaitForSingleObject( handle, alertable, NULL )) return STATUS_PENDING;
|
2019-05-23 19:35:51 +02:00
|
|
|
return io->u.Status;
|
|
|
|
}
|
|
|
|
|
2015-05-05 06:35:57 +02:00
|
|
|
/* callback for irp async I/O completion */
|
2017-04-10 13:41:29 +02:00
|
|
|
static NTSTATUS irp_completion( void *user, IO_STATUS_BLOCK *io, NTSTATUS status )
|
2015-05-05 06:35:57 +02:00
|
|
|
{
|
|
|
|
struct async_irp *async = user;
|
2017-01-26 00:51:58 +01:00
|
|
|
ULONG information = 0;
|
2015-05-05 06:35:57 +02:00
|
|
|
|
|
|
|
if (status == STATUS_ALERTED)
|
|
|
|
{
|
2016-12-04 21:22:05 +01:00
|
|
|
SERVER_START_REQ( get_async_result )
|
2015-05-05 06:35:57 +02:00
|
|
|
{
|
|
|
|
req->user_arg = wine_server_client_ptr( async );
|
|
|
|
wine_server_set_reply( req, async->buffer, async->size );
|
2020-06-02 17:08:59 +02:00
|
|
|
status = unix_funcs->virtual_locked_server_call( req );
|
2017-01-26 00:51:58 +01:00
|
|
|
information = reply->size;
|
2015-05-05 06:35:57 +02:00
|
|
|
}
|
|
|
|
SERVER_END_REQ;
|
|
|
|
}
|
|
|
|
if (status != STATUS_PENDING)
|
|
|
|
{
|
|
|
|
io->u.Status = status;
|
2017-01-26 00:51:58 +01:00
|
|
|
io->Information = information;
|
2015-05-05 06:35:57 +02:00
|
|
|
release_fileio( &async->io );
|
|
|
|
}
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
2003-06-26 04:08:17 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* FILE_GetNtStatus(void)
|
|
|
|
*
|
|
|
|
* Retrieve the Nt Status code from errno.
|
|
|
|
* Try to be consistent with FILE_SetDosError().
|
|
|
|
*/
|
2004-03-16 02:32:02 +01:00
|
|
|
NTSTATUS FILE_GetNtStatus(void)
|
2003-06-26 04:08:17 +02:00
|
|
|
{
|
|
|
|
int err = errno;
|
|
|
|
|
|
|
|
TRACE( "errno = %d\n", errno );
|
|
|
|
switch (err)
|
|
|
|
{
|
2004-04-17 01:32:40 +02:00
|
|
|
case EAGAIN: return STATUS_SHARING_VIOLATION;
|
|
|
|
case EBADF: return STATUS_INVALID_HANDLE;
|
2005-10-28 18:45:24 +02:00
|
|
|
case EBUSY: return STATUS_DEVICE_BUSY;
|
2004-04-17 01:32:40 +02:00
|
|
|
case ENOSPC: return STATUS_DISK_FULL;
|
2003-06-26 04:08:17 +02:00
|
|
|
case EPERM:
|
|
|
|
case EROFS:
|
2004-04-17 01:32:40 +02:00
|
|
|
case EACCES: return STATUS_ACCESS_DENIED;
|
|
|
|
case ENOTDIR: return STATUS_OBJECT_PATH_NOT_FOUND;
|
|
|
|
case ENOENT: return STATUS_OBJECT_NAME_NOT_FOUND;
|
|
|
|
case EISDIR: return STATUS_FILE_IS_A_DIRECTORY;
|
2003-06-26 04:08:17 +02:00
|
|
|
case EMFILE:
|
2004-04-17 01:32:40 +02:00
|
|
|
case ENFILE: return STATUS_TOO_MANY_OPENED_FILES;
|
|
|
|
case EINVAL: return STATUS_INVALID_PARAMETER;
|
|
|
|
case ENOTEMPTY: return STATUS_DIRECTORY_NOT_EMPTY;
|
2007-04-10 21:30:37 +02:00
|
|
|
case EPIPE: return STATUS_PIPE_DISCONNECTED;
|
2004-04-17 01:32:40 +02:00
|
|
|
case EIO: return STATUS_DEVICE_NOT_READY;
|
2004-04-29 22:04:48 +02:00
|
|
|
#ifdef ENOMEDIUM
|
|
|
|
case ENOMEDIUM: return STATUS_NO_MEDIA_IN_DEVICE;
|
|
|
|
#endif
|
2006-10-03 15:06:41 +02:00
|
|
|
case ENXIO: return STATUS_NO_SUCH_DEVICE;
|
2004-04-29 22:04:48 +02:00
|
|
|
case ENOTTY:
|
|
|
|
case EOPNOTSUPP:return STATUS_NOT_SUPPORTED;
|
2004-08-19 04:41:55 +02:00
|
|
|
case ECONNRESET:return STATUS_PIPE_DISCONNECTED;
|
2006-11-20 14:15:43 +01:00
|
|
|
case EFAULT: return STATUS_ACCESS_VIOLATION;
|
2006-12-31 10:28:23 +01:00
|
|
|
case ESPIPE: return STATUS_ILLEGAL_FUNCTION;
|
2019-12-11 10:28:59 +01:00
|
|
|
case ELOOP: return STATUS_REPARSE_POINT_NOT_RESOLVED;
|
2011-10-09 15:29:28 +02:00
|
|
|
#ifdef ETIME /* Missing on FreeBSD */
|
2011-10-03 17:45:27 +02:00
|
|
|
case ETIME: return STATUS_IO_TIMEOUT;
|
2011-10-09 15:29:28 +02:00
|
|
|
#endif
|
2004-04-17 01:32:40 +02:00
|
|
|
case ENOEXEC: /* ?? */
|
|
|
|
case EEXIST: /* ?? */
|
2003-06-26 04:08:17 +02:00
|
|
|
default:
|
|
|
|
FIXME( "Converting errno %d to STATUS_UNSUCCESSFUL\n", err );
|
2004-04-17 01:32:40 +02:00
|
|
|
return STATUS_UNSUCCESSFUL;
|
2003-06-26 04:08:17 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* FILE_AsyncReadService (INTERNAL)
|
|
|
|
*/
|
2017-04-10 13:41:29 +02:00
|
|
|
static NTSTATUS FILE_AsyncReadService( void *user, IO_STATUS_BLOCK *iosb, NTSTATUS status )
|
2002-06-14 02:36:20 +02:00
|
|
|
{
|
2015-03-02 08:56:47 +01:00
|
|
|
struct async_fileio_read *fileio = user;
|
2006-11-03 11:56:51 +01:00
|
|
|
int fd, needs_close, result;
|
2003-06-26 04:08:17 +02:00
|
|
|
|
2005-01-14 20:54:38 +01:00
|
|
|
switch (status)
|
2003-06-26 04:08:17 +02:00
|
|
|
{
|
2005-01-14 20:54:38 +01:00
|
|
|
case STATUS_ALERTED: /* got some new data */
|
|
|
|
/* check to see if the data is ready (non-blocking) */
|
2020-05-29 15:35:16 +02:00
|
|
|
if ((status = unix_funcs->server_get_unix_fd( fileio->io.handle, FILE_READ_DATA, &fd,
|
|
|
|
&needs_close, NULL, NULL )))
|
2006-11-03 11:56:51 +01:00
|
|
|
break;
|
2007-04-10 17:07:27 +02:00
|
|
|
|
2020-06-02 17:08:59 +02:00
|
|
|
result = unix_funcs->virtual_locked_read(fd, &fileio->buffer[fileio->already], fileio->count-fileio->already);
|
2006-11-03 11:56:51 +01:00
|
|
|
if (needs_close) close( fd );
|
2003-06-26 04:08:17 +02:00
|
|
|
|
2005-01-14 20:54:38 +01:00
|
|
|
if (result < 0)
|
|
|
|
{
|
|
|
|
if (errno == EAGAIN || errno == EINTR)
|
2007-04-05 10:55:40 +02:00
|
|
|
status = STATUS_PENDING;
|
2005-01-14 20:54:38 +01:00
|
|
|
else /* check to see if the transfer is complete */
|
2007-04-05 10:55:40 +02:00
|
|
|
status = FILE_GetNtStatus();
|
2005-01-14 20:54:38 +01:00
|
|
|
}
|
|
|
|
else if (result == 0)
|
|
|
|
{
|
2007-04-06 16:05:53 +02:00
|
|
|
status = fileio->already ? STATUS_SUCCESS : STATUS_PIPE_BROKEN;
|
2005-01-14 20:54:38 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2007-04-05 11:03:38 +02:00
|
|
|
fileio->already += result;
|
|
|
|
if (fileio->already >= fileio->count || fileio->avail_mode)
|
2007-04-05 10:55:40 +02:00
|
|
|
status = STATUS_SUCCESS;
|
2005-01-14 20:54:38 +01:00
|
|
|
else
|
2016-01-11 10:02:32 +01:00
|
|
|
status = STATUS_PENDING;
|
2005-01-14 20:54:38 +01:00
|
|
|
}
|
|
|
|
break;
|
2007-04-10 17:07:27 +02:00
|
|
|
|
|
|
|
case STATUS_TIMEOUT:
|
|
|
|
case STATUS_IO_TIMEOUT:
|
|
|
|
if (fileio->already) status = STATUS_SUCCESS;
|
2005-01-14 20:54:38 +01:00
|
|
|
break;
|
2003-06-26 04:08:17 +02:00
|
|
|
}
|
2007-04-10 17:19:24 +02:00
|
|
|
if (status != STATUS_PENDING)
|
|
|
|
{
|
|
|
|
iosb->u.Status = status;
|
2008-12-30 20:51:55 +01:00
|
|
|
iosb->Information = fileio->already;
|
2015-03-03 08:14:02 +01:00
|
|
|
release_fileio( &fileio->io );
|
2007-04-10 17:19:24 +02:00
|
|
|
}
|
2007-04-10 17:07:27 +02:00
|
|
|
return status;
|
2002-06-14 02:36:20 +02:00
|
|
|
}
|
|
|
|
|
2015-05-05 06:35:57 +02:00
|
|
|
/* do a read call through the server */
|
|
|
|
static NTSTATUS server_read_file( HANDLE handle, HANDLE event, PIO_APC_ROUTINE apc, void *apc_context,
|
|
|
|
IO_STATUS_BLOCK *io, void *buffer, ULONG size,
|
|
|
|
LARGE_INTEGER *offset, ULONG *key )
|
|
|
|
{
|
|
|
|
struct async_irp *async;
|
|
|
|
NTSTATUS status;
|
|
|
|
HANDLE wait_handle;
|
|
|
|
ULONG options;
|
|
|
|
|
2017-04-10 13:21:56 +02:00
|
|
|
if (!(async = (struct async_irp *)alloc_fileio( sizeof(*async), irp_completion, handle )))
|
2015-05-05 06:35:57 +02:00
|
|
|
return STATUS_NO_MEMORY;
|
|
|
|
|
|
|
|
async->buffer = buffer;
|
|
|
|
async->size = size;
|
|
|
|
|
|
|
|
SERVER_START_REQ( read )
|
|
|
|
{
|
2017-04-12 13:55:17 +02:00
|
|
|
req->async = server_async( handle, &async->io, event, apc, apc_context, io );
|
|
|
|
req->pos = offset ? offset->QuadPart : 0;
|
2015-05-05 06:35:57 +02:00
|
|
|
wine_server_set_reply( req, buffer, size );
|
2020-06-02 17:08:59 +02:00
|
|
|
status = unix_funcs->virtual_locked_server_call( req );
|
2015-05-05 06:35:57 +02:00
|
|
|
wait_handle = wine_server_ptr_handle( reply->wait );
|
|
|
|
options = reply->options;
|
2017-06-26 12:18:08 +02:00
|
|
|
if (wait_handle && status != STATUS_PENDING)
|
|
|
|
{
|
|
|
|
io->u.Status = status;
|
|
|
|
io->Information = wine_server_reply_size( reply );
|
|
|
|
}
|
2015-05-05 06:35:57 +02:00
|
|
|
}
|
|
|
|
SERVER_END_REQ;
|
|
|
|
|
|
|
|
if (status != STATUS_PENDING) RtlFreeHeap( GetProcessHeap(), 0, async );
|
|
|
|
|
2019-05-23 19:35:51 +02:00
|
|
|
if (wait_handle) status = wait_async( wait_handle, (options & FILE_SYNCHRONOUS_IO_ALERT), io );
|
2015-05-05 06:35:57 +02:00
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* do a write call through the server */
|
|
|
|
static NTSTATUS server_write_file( HANDLE handle, HANDLE event, PIO_APC_ROUTINE apc, void *apc_context,
|
|
|
|
IO_STATUS_BLOCK *io, const void *buffer, ULONG size,
|
|
|
|
LARGE_INTEGER *offset, ULONG *key )
|
|
|
|
{
|
|
|
|
struct async_irp *async;
|
|
|
|
NTSTATUS status;
|
|
|
|
HANDLE wait_handle;
|
|
|
|
ULONG options;
|
|
|
|
|
2017-04-10 13:21:56 +02:00
|
|
|
if (!(async = (struct async_irp *)alloc_fileio( sizeof(*async), irp_completion, handle )))
|
2015-05-05 06:35:57 +02:00
|
|
|
return STATUS_NO_MEMORY;
|
|
|
|
|
|
|
|
async->buffer = NULL;
|
|
|
|
async->size = 0;
|
|
|
|
|
|
|
|
SERVER_START_REQ( write )
|
|
|
|
{
|
2017-04-12 13:55:17 +02:00
|
|
|
req->async = server_async( handle, &async->io, event, apc, apc_context, io );
|
|
|
|
req->pos = offset ? offset->QuadPart : 0;
|
2015-05-05 06:35:57 +02:00
|
|
|
wine_server_add_data( req, buffer, size );
|
|
|
|
status = wine_server_call( req );
|
|
|
|
wait_handle = wine_server_ptr_handle( reply->wait );
|
|
|
|
options = reply->options;
|
2017-06-26 12:18:23 +02:00
|
|
|
if (wait_handle && status != STATUS_PENDING)
|
|
|
|
{
|
|
|
|
io->u.Status = status;
|
|
|
|
io->Information = reply->size;
|
|
|
|
}
|
2015-05-05 06:35:57 +02:00
|
|
|
}
|
|
|
|
SERVER_END_REQ;
|
|
|
|
|
|
|
|
if (status != STATUS_PENDING) RtlFreeHeap( GetProcessHeap(), 0, async );
|
|
|
|
|
2019-05-23 19:35:51 +02:00
|
|
|
if (wait_handle) status = wait_async( wait_handle, (options & FILE_SYNCHRONOUS_IO_ALERT), io );
|
2015-05-05 06:35:57 +02:00
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
2007-04-06 16:05:53 +02:00
|
|
|
struct io_timeouts
|
|
|
|
{
|
|
|
|
int interval; /* max interval between two bytes */
|
|
|
|
int total; /* total timeout for the whole operation */
|
|
|
|
int end_time; /* absolute time of end of operation */
|
|
|
|
};
|
|
|
|
|
|
|
|
/* retrieve the I/O timeouts to use for a given handle */
|
|
|
|
static NTSTATUS get_io_timeouts( HANDLE handle, enum server_fd_type type, ULONG count, BOOL is_read,
|
|
|
|
struct io_timeouts *timeouts )
|
|
|
|
{
|
|
|
|
NTSTATUS status = STATUS_SUCCESS;
|
|
|
|
|
|
|
|
timeouts->interval = timeouts->total = -1;
|
|
|
|
|
|
|
|
switch(type)
|
|
|
|
{
|
|
|
|
case FD_TYPE_SERIAL:
|
|
|
|
{
|
|
|
|
/* GetCommTimeouts */
|
|
|
|
SERIAL_TIMEOUTS st;
|
|
|
|
IO_STATUS_BLOCK io;
|
|
|
|
|
|
|
|
status = NtDeviceIoControlFile( handle, NULL, NULL, NULL, &io,
|
|
|
|
IOCTL_SERIAL_GET_TIMEOUTS, NULL, 0, &st, sizeof(st) );
|
|
|
|
if (status) break;
|
|
|
|
|
|
|
|
if (is_read)
|
|
|
|
{
|
|
|
|
if (st.ReadIntervalTimeout)
|
|
|
|
timeouts->interval = st.ReadIntervalTimeout;
|
|
|
|
|
|
|
|
if (st.ReadTotalTimeoutMultiplier || st.ReadTotalTimeoutConstant)
|
|
|
|
{
|
|
|
|
timeouts->total = st.ReadTotalTimeoutConstant;
|
|
|
|
if (st.ReadTotalTimeoutMultiplier != MAXDWORD)
|
|
|
|
timeouts->total += count * st.ReadTotalTimeoutMultiplier;
|
|
|
|
}
|
|
|
|
else if (st.ReadIntervalTimeout == MAXDWORD)
|
2008-05-07 13:29:18 +02:00
|
|
|
timeouts->interval = timeouts->total = 0;
|
2007-04-06 16:05:53 +02:00
|
|
|
}
|
|
|
|
else /* write */
|
|
|
|
{
|
|
|
|
if (st.WriteTotalTimeoutMultiplier || st.WriteTotalTimeoutConstant)
|
|
|
|
{
|
|
|
|
timeouts->total = st.WriteTotalTimeoutConstant;
|
|
|
|
if (st.WriteTotalTimeoutMultiplier != MAXDWORD)
|
|
|
|
timeouts->total += count * st.WriteTotalTimeoutMultiplier;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case FD_TYPE_MAILSLOT:
|
|
|
|
if (is_read)
|
|
|
|
{
|
|
|
|
timeouts->interval = 0; /* return as soon as we got something */
|
|
|
|
SERVER_START_REQ( set_mailslot_info )
|
|
|
|
{
|
2008-12-08 16:05:17 +01:00
|
|
|
req->handle = wine_server_obj_handle( handle );
|
2007-04-06 16:05:53 +02:00
|
|
|
req->flags = 0;
|
2007-04-17 20:08:59 +02:00
|
|
|
if (!(status = wine_server_call( req )) &&
|
|
|
|
reply->read_timeout != TIMEOUT_INFINITE)
|
|
|
|
timeouts->total = reply->read_timeout / -10000;
|
2007-04-06 16:05:53 +02:00
|
|
|
}
|
|
|
|
SERVER_END_REQ;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case FD_TYPE_SOCKET:
|
2007-04-23 15:13:22 +02:00
|
|
|
case FD_TYPE_CHAR:
|
2007-04-06 16:05:53 +02:00
|
|
|
if (is_read) timeouts->interval = 0; /* return as soon as we got something */
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (timeouts->total != -1) timeouts->end_time = NtGetTickCount() + timeouts->total;
|
|
|
|
return STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* retrieve the timeout for the next wait, in milliseconds */
|
2007-06-23 19:34:32 +02:00
|
|
|
static inline int get_next_io_timeout( const struct io_timeouts *timeouts, ULONG already )
|
2007-04-06 16:05:53 +02:00
|
|
|
{
|
|
|
|
int ret = -1;
|
|
|
|
|
|
|
|
if (timeouts->total != -1)
|
|
|
|
{
|
|
|
|
ret = timeouts->end_time - NtGetTickCount();
|
|
|
|
if (ret < 0) ret = 0;
|
|
|
|
}
|
|
|
|
if (already && timeouts->interval != -1)
|
|
|
|
{
|
|
|
|
if (ret == -1 || ret > timeouts->interval) ret = timeouts->interval;
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2002-06-14 02:36:20 +02:00
|
|
|
|
2007-04-10 17:27:50 +02:00
|
|
|
/* retrieve the avail_mode flag for async reads */
|
|
|
|
static NTSTATUS get_io_avail_mode( HANDLE handle, enum server_fd_type type, BOOL *avail_mode )
|
|
|
|
{
|
|
|
|
NTSTATUS status = STATUS_SUCCESS;
|
|
|
|
|
|
|
|
switch(type)
|
|
|
|
{
|
|
|
|
case FD_TYPE_SERIAL:
|
|
|
|
{
|
|
|
|
/* GetCommTimeouts */
|
|
|
|
SERIAL_TIMEOUTS st;
|
|
|
|
IO_STATUS_BLOCK io;
|
|
|
|
|
|
|
|
status = NtDeviceIoControlFile( handle, NULL, NULL, NULL, &io,
|
|
|
|
IOCTL_SERIAL_GET_TIMEOUTS, NULL, 0, &st, sizeof(st) );
|
|
|
|
if (status) break;
|
|
|
|
*avail_mode = (!st.ReadTotalTimeoutMultiplier &&
|
|
|
|
!st.ReadTotalTimeoutConstant &&
|
|
|
|
st.ReadIntervalTimeout == MAXDWORD);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case FD_TYPE_MAILSLOT:
|
|
|
|
case FD_TYPE_SOCKET:
|
2007-04-23 15:13:22 +02:00
|
|
|
case FD_TYPE_CHAR:
|
2007-04-10 17:27:50 +02:00
|
|
|
*avail_mode = TRUE;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
*avail_mode = FALSE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
2016-06-09 08:31:00 +02:00
|
|
|
/* register an async I/O for a file read; helper for NtReadFile */
|
|
|
|
static NTSTATUS register_async_file_read( HANDLE handle, HANDLE event,
|
|
|
|
PIO_APC_ROUTINE apc, void *apc_user,
|
|
|
|
IO_STATUS_BLOCK *iosb, void *buffer,
|
|
|
|
ULONG already, ULONG length, BOOL avail_mode )
|
|
|
|
{
|
|
|
|
struct async_fileio_read *fileio;
|
|
|
|
NTSTATUS status;
|
|
|
|
|
2017-04-10 13:21:56 +02:00
|
|
|
if (!(fileio = (struct async_fileio_read *)alloc_fileio( sizeof(*fileio), FILE_AsyncReadService, handle )))
|
2016-06-09 08:31:00 +02:00
|
|
|
return STATUS_NO_MEMORY;
|
|
|
|
|
|
|
|
fileio->already = already;
|
|
|
|
fileio->count = length;
|
|
|
|
fileio->buffer = buffer;
|
|
|
|
fileio->avail_mode = avail_mode;
|
|
|
|
|
|
|
|
SERVER_START_REQ( register_async )
|
|
|
|
{
|
|
|
|
req->type = ASYNC_TYPE_READ;
|
|
|
|
req->count = length;
|
2017-04-10 13:21:04 +02:00
|
|
|
req->async = server_async( handle, &fileio->io, event, apc, apc_user, iosb );
|
2016-06-09 08:31:00 +02:00
|
|
|
status = wine_server_call( req );
|
|
|
|
}
|
|
|
|
SERVER_END_REQ;
|
|
|
|
|
|
|
|
if (status != STATUS_PENDING) RtlFreeHeap( GetProcessHeap(), 0, fileio );
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
2007-04-10 17:27:50 +02:00
|
|
|
|
1999-03-09 18:47:51 +01:00
|
|
|
/******************************************************************************
|
2001-06-21 01:03:14 +02:00
|
|
|
* NtReadFile [NTDLL.@]
|
2001-07-11 20:56:41 +02:00
|
|
|
* ZwReadFile [NTDLL.@]
|
1999-03-09 18:47:51 +01:00
|
|
|
*
|
2003-07-19 00:55:28 +02:00
|
|
|
* Read from an open file handle.
|
2002-06-14 02:36:20 +02:00
|
|
|
*
|
2003-07-19 00:55:28 +02:00
|
|
|
* PARAMS
|
|
|
|
* FileHandle [I] Handle returned from ZwOpenFile() or ZwCreateFile()
|
|
|
|
* Event [I] Event to signal upon completion (or NULL)
|
|
|
|
* ApcRoutine [I] Callback to call upon completion (or NULL)
|
|
|
|
* ApcContext [I] Context for ApcRoutine (or NULL)
|
|
|
|
* IoStatusBlock [O] Receives information about the operation on return
|
|
|
|
* Buffer [O] Destination for the data read
|
|
|
|
* Length [I] Size of Buffer
|
|
|
|
* ByteOffset [O] Destination for the new file pointer position (or NULL)
|
|
|
|
* Key [O] Function unknown (may be NULL)
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Success: 0. IoStatusBlock is updated, and the Information member contains
|
|
|
|
* The number of bytes read.
|
|
|
|
* Failure: An NTSTATUS error code describing the error.
|
1999-03-09 18:47:51 +01:00
|
|
|
*/
|
2003-07-19 00:55:28 +02:00
|
|
|
NTSTATUS WINAPI NtReadFile(HANDLE hFile, HANDLE hEvent,
|
|
|
|
PIO_APC_ROUTINE apc, void* apc_user,
|
2003-06-26 04:08:17 +02:00
|
|
|
PIO_STATUS_BLOCK io_status, void* buffer, ULONG length,
|
|
|
|
PLARGE_INTEGER offset, PULONG key)
|
2002-06-14 02:36:20 +02:00
|
|
|
{
|
2013-11-01 00:21:24 +01:00
|
|
|
int result, unix_handle, needs_close;
|
2007-04-10 22:32:46 +02:00
|
|
|
unsigned int options;
|
2007-04-06 16:05:53 +02:00
|
|
|
struct io_timeouts timeouts;
|
2019-02-21 15:10:14 +01:00
|
|
|
NTSTATUS status, ret_status;
|
2007-04-06 16:05:53 +02:00
|
|
|
ULONG total = 0;
|
2006-11-20 14:15:43 +01:00
|
|
|
enum server_fd_type type;
|
2007-11-09 23:12:07 +01:00
|
|
|
ULONG_PTR cvalue = apc ? 0 : (ULONG_PTR)apc_user;
|
2013-11-01 00:21:24 +01:00
|
|
|
BOOL send_completion = FALSE, async_read, timeout_init_done = FALSE;
|
2003-06-26 04:08:17 +02:00
|
|
|
|
2018-11-01 12:41:16 +01:00
|
|
|
TRACE("(%p,%p,%p,%p,%p,%p,0x%08x,%p,%p)\n",
|
2003-06-26 04:08:17 +02:00
|
|
|
hFile,hEvent,apc,apc_user,io_status,buffer,length,offset,key);
|
|
|
|
|
2005-04-25 18:02:16 +02:00
|
|
|
if (!io_status) return STATUS_ACCESS_VIOLATION;
|
|
|
|
|
2020-05-29 15:35:16 +02:00
|
|
|
status = unix_funcs->server_get_unix_fd( hFile, FILE_READ_DATA, &unix_handle,
|
|
|
|
&needs_close, &type, &options );
|
2017-01-26 00:51:24 +01:00
|
|
|
if (status && status != STATUS_BAD_DEVICE_TYPE) return status;
|
|
|
|
|
2020-06-02 17:08:59 +02:00
|
|
|
if (!unix_funcs->virtual_check_buffer_for_write( buffer, length )) return STATUS_ACCESS_VIOLATION;
|
2017-01-26 00:51:24 +01:00
|
|
|
|
2015-05-05 06:35:57 +02:00
|
|
|
if (status == STATUS_BAD_DEVICE_TYPE)
|
|
|
|
return server_read_file( hFile, hEvent, apc, apc_user, io_status, buffer, length, offset, key );
|
|
|
|
|
2013-10-30 06:24:45 +01:00
|
|
|
async_read = !(options & (FILE_SYNCHRONOUS_IO_ALERT | FILE_SYNCHRONOUS_IO_NONALERT));
|
|
|
|
|
2013-09-02 11:30:27 +02:00
|
|
|
if (type == FD_TYPE_FILE)
|
2006-11-20 14:15:43 +01:00
|
|
|
{
|
2013-09-30 13:19:34 +02:00
|
|
|
if (async_read && (!offset || offset->QuadPart < 0))
|
2006-11-20 14:15:43 +01:00
|
|
|
{
|
2013-09-02 11:30:27 +02:00
|
|
|
status = STATUS_INVALID_PARAMETER;
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
2013-10-09 16:13:41 +02:00
|
|
|
if (offset && offset->QuadPart != FILE_USE_FILE_POINTER_POSITION)
|
2013-09-02 11:30:27 +02:00
|
|
|
{
|
|
|
|
/* async I/O doesn't make sense on regular files */
|
2020-06-02 17:08:59 +02:00
|
|
|
while ((result = unix_funcs->virtual_locked_pread( unix_handle, buffer, length, offset->QuadPart )) == -1)
|
2006-11-20 14:15:43 +01:00
|
|
|
{
|
2013-09-02 11:30:27 +02:00
|
|
|
if (errno != EINTR)
|
|
|
|
{
|
|
|
|
status = FILE_GetNtStatus();
|
|
|
|
goto done;
|
|
|
|
}
|
2006-11-20 14:15:43 +01:00
|
|
|
}
|
2013-09-30 13:19:34 +02:00
|
|
|
if (!async_read)
|
2013-09-02 11:30:27 +02:00
|
|
|
/* update file pointer position */
|
|
|
|
lseek( unix_handle, offset->QuadPart + result, SEEK_SET );
|
2007-04-06 16:05:53 +02:00
|
|
|
|
2013-09-02 11:30:27 +02:00
|
|
|
total = result;
|
2013-10-30 06:24:25 +01:00
|
|
|
status = (total || !length) ? STATUS_SUCCESS : STATUS_END_OF_FILE;
|
2013-09-02 11:30:27 +02:00
|
|
|
goto done;
|
|
|
|
}
|
2007-04-06 16:05:53 +02:00
|
|
|
}
|
2015-05-21 10:27:03 +02:00
|
|
|
else if (type == FD_TYPE_SERIAL || type == FD_TYPE_DEVICE)
|
2013-09-19 09:10:09 +02:00
|
|
|
{
|
2013-09-30 13:19:34 +02:00
|
|
|
if (async_read && (!offset || offset->QuadPart < 0))
|
2013-09-19 09:10:09 +02:00
|
|
|
{
|
|
|
|
status = STATUS_INVALID_PARAMETER;
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
}
|
2007-04-06 16:05:53 +02:00
|
|
|
|
2016-05-27 07:34:26 +02:00
|
|
|
if (type == FD_TYPE_SERIAL && async_read && length)
|
|
|
|
{
|
|
|
|
/* an asynchronous serial port read with a read interval timeout needs to
|
|
|
|
skip the synchronous read to make sure that the server starts the read
|
|
|
|
interval timer after the first read */
|
|
|
|
if ((status = get_io_timeouts( hFile, type, length, TRUE, &timeouts ))) goto err;
|
|
|
|
if (timeouts.interval)
|
|
|
|
{
|
|
|
|
status = register_async_file_read( hFile, hEvent, apc, apc_user, io_status,
|
|
|
|
buffer, total, length, FALSE );
|
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-04-06 16:05:53 +02:00
|
|
|
for (;;)
|
|
|
|
{
|
2020-06-02 17:08:59 +02:00
|
|
|
if ((result = unix_funcs->virtual_locked_read( unix_handle, (char *)buffer + total, length - total )) >= 0)
|
2007-04-06 16:05:53 +02:00
|
|
|
{
|
|
|
|
total += result;
|
|
|
|
if (!result || total == length)
|
2006-11-20 14:15:43 +01:00
|
|
|
{
|
2007-04-06 16:05:53 +02:00
|
|
|
if (total)
|
2008-05-07 20:18:09 +02:00
|
|
|
{
|
2007-04-06 16:05:53 +02:00
|
|
|
status = STATUS_SUCCESS;
|
2008-05-07 20:18:09 +02:00
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
switch (type)
|
|
|
|
{
|
|
|
|
case FD_TYPE_FILE:
|
|
|
|
case FD_TYPE_CHAR:
|
2015-05-21 10:27:03 +02:00
|
|
|
case FD_TYPE_DEVICE:
|
2013-10-30 06:24:25 +01:00
|
|
|
status = length ? STATUS_END_OF_FILE : STATUS_SUCCESS;
|
2008-05-07 20:18:09 +02:00
|
|
|
goto done;
|
|
|
|
case FD_TYPE_SERIAL:
|
2016-02-25 06:55:35 +01:00
|
|
|
if (!length)
|
|
|
|
{
|
|
|
|
status = STATUS_SUCCESS;
|
|
|
|
goto done;
|
|
|
|
}
|
2008-05-07 20:18:09 +02:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
status = STATUS_PIPE_BROKEN;
|
2017-09-22 12:13:25 +02:00
|
|
|
goto err;
|
2008-05-07 20:18:09 +02:00
|
|
|
}
|
2006-11-20 14:15:43 +01:00
|
|
|
}
|
2008-11-12 19:15:31 +01:00
|
|
|
else if (type == FD_TYPE_FILE) continue; /* no async I/O on regular files */
|
2006-11-20 14:15:43 +01:00
|
|
|
}
|
2009-01-14 20:17:52 +01:00
|
|
|
else if (errno != EAGAIN)
|
2006-11-20 14:15:43 +01:00
|
|
|
{
|
2007-04-06 16:05:53 +02:00
|
|
|
if (errno == EINTR) continue;
|
2009-01-14 20:17:52 +01:00
|
|
|
if (!total) status = FILE_GetNtStatus();
|
2017-09-22 12:13:25 +02:00
|
|
|
goto err;
|
2006-11-20 14:15:43 +01:00
|
|
|
}
|
2003-12-02 00:01:12 +01:00
|
|
|
|
2013-09-30 13:19:34 +02:00
|
|
|
if (async_read)
|
2003-06-26 04:08:17 +02:00
|
|
|
{
|
2007-04-10 17:27:50 +02:00
|
|
|
BOOL avail_mode;
|
2003-07-19 00:55:28 +02:00
|
|
|
|
2007-04-10 17:27:50 +02:00
|
|
|
if ((status = get_io_avail_mode( hFile, type, &avail_mode )))
|
2007-11-09 23:12:07 +01:00
|
|
|
goto err;
|
2007-04-10 17:27:50 +02:00
|
|
|
if (total && avail_mode)
|
2007-04-06 16:05:53 +02:00
|
|
|
{
|
|
|
|
status = STATUS_SUCCESS;
|
|
|
|
goto done;
|
|
|
|
}
|
2016-06-09 08:31:00 +02:00
|
|
|
status = register_async_file_read( hFile, hEvent, apc, apc_user, io_status,
|
|
|
|
buffer, total, length, avail_mode );
|
2007-11-09 23:12:07 +01:00
|
|
|
goto err;
|
2004-08-18 01:37:55 +02:00
|
|
|
}
|
2007-04-06 16:05:53 +02:00
|
|
|
else /* synchronous read, wait for the fd to become ready */
|
2003-08-18 21:45:53 +02:00
|
|
|
{
|
2007-04-06 16:05:53 +02:00
|
|
|
struct pollfd pfd;
|
|
|
|
int ret, timeout;
|
|
|
|
|
|
|
|
if (!timeout_init_done)
|
|
|
|
{
|
2013-11-01 00:21:24 +01:00
|
|
|
timeout_init_done = TRUE;
|
2007-04-06 16:05:53 +02:00
|
|
|
if ((status = get_io_timeouts( hFile, type, length, TRUE, &timeouts )))
|
2007-11-09 23:12:07 +01:00
|
|
|
goto err;
|
2007-04-06 16:05:53 +02:00
|
|
|
if (hEvent) NtResetEvent( hEvent, NULL );
|
|
|
|
}
|
|
|
|
timeout = get_next_io_timeout( &timeouts, total );
|
|
|
|
|
|
|
|
pfd.fd = unix_handle;
|
|
|
|
pfd.events = POLLIN;
|
|
|
|
|
|
|
|
if (!timeout || !(ret = poll( &pfd, 1, timeout )))
|
|
|
|
{
|
|
|
|
if (total) /* return with what we got so far */
|
|
|
|
status = STATUS_SUCCESS;
|
|
|
|
else
|
|
|
|
status = (type == FD_TYPE_MAILSLOT) ? STATUS_IO_TIMEOUT : STATUS_TIMEOUT;
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
if (ret == -1 && errno != EINTR)
|
|
|
|
{
|
|
|
|
status = FILE_GetNtStatus();
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
/* will now restart the read */
|
2003-08-18 21:45:53 +02:00
|
|
|
}
|
2003-06-26 04:08:17 +02:00
|
|
|
}
|
2002-06-14 02:36:20 +02:00
|
|
|
|
2007-04-06 16:05:53 +02:00
|
|
|
done:
|
2010-06-21 16:16:04 +02:00
|
|
|
send_completion = cvalue != 0;
|
2007-11-09 23:12:07 +01:00
|
|
|
|
|
|
|
err:
|
2007-04-06 16:05:53 +02:00
|
|
|
if (needs_close) close( unix_handle );
|
2020-04-20 01:06:00 +02:00
|
|
|
if (status == STATUS_SUCCESS || (status == STATUS_END_OF_FILE && (!async_read || type == FD_TYPE_FILE)))
|
2003-06-26 04:08:17 +02:00
|
|
|
{
|
2007-04-06 16:05:53 +02:00
|
|
|
io_status->u.Status = status;
|
|
|
|
io_status->Information = total;
|
|
|
|
TRACE("= SUCCESS (%u)\n", total);
|
|
|
|
if (hEvent) NtSetEvent( hEvent, NULL );
|
2020-04-20 01:06:00 +02:00
|
|
|
if (apc && (!status || async_read)) NtQueueApcThread( GetCurrentThread(), (PNTAPCFUNC)apc,
|
2013-10-30 06:24:45 +01:00
|
|
|
(ULONG_PTR)apc_user, (ULONG_PTR)io_status, 0 );
|
2003-06-26 04:08:17 +02:00
|
|
|
}
|
2007-04-06 16:05:53 +02:00
|
|
|
else
|
2005-11-14 16:11:11 +01:00
|
|
|
{
|
2007-04-06 16:05:53 +02:00
|
|
|
TRACE("= 0x%08x\n", status);
|
|
|
|
if (status != STATUS_PENDING && hEvent) NtResetEvent( hEvent, NULL );
|
2005-11-14 16:11:11 +01:00
|
|
|
}
|
2010-06-21 16:16:04 +02:00
|
|
|
|
2020-04-20 01:06:00 +02:00
|
|
|
ret_status = async_read && type == FD_TYPE_FILE && (status == STATUS_SUCCESS || status == STATUS_END_OF_FILE)
|
2019-02-21 15:10:14 +01:00
|
|
|
? STATUS_PENDING : status;
|
|
|
|
|
|
|
|
if (send_completion) NTDLL_AddCompletion( hFile, cvalue, status, total, ret_status == STATUS_PENDING );
|
|
|
|
return ret_status;
|
2003-06-26 04:08:17 +02:00
|
|
|
}
|
2002-06-14 02:36:20 +02:00
|
|
|
|
2008-03-14 20:29:00 +01:00
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* NtReadFileScatter [NTDLL.@]
|
|
|
|
* ZwReadFileScatter [NTDLL.@]
|
|
|
|
*/
|
|
|
|
NTSTATUS WINAPI NtReadFileScatter( HANDLE file, HANDLE event, PIO_APC_ROUTINE apc, void *apc_user,
|
|
|
|
PIO_STATUS_BLOCK io_status, FILE_SEGMENT_ELEMENT *segments,
|
|
|
|
ULONG length, PLARGE_INTEGER offset, PULONG key )
|
|
|
|
{
|
|
|
|
int result, unix_handle, needs_close;
|
|
|
|
unsigned int options;
|
|
|
|
NTSTATUS status;
|
|
|
|
ULONG pos = 0, total = 0;
|
|
|
|
enum server_fd_type type;
|
|
|
|
ULONG_PTR cvalue = apc ? 0 : (ULONG_PTR)apc_user;
|
2010-06-21 16:16:04 +02:00
|
|
|
BOOL send_completion = FALSE;
|
2008-03-14 20:29:00 +01:00
|
|
|
|
|
|
|
TRACE( "(%p,%p,%p,%p,%p,%p,0x%08x,%p,%p),partial stub!\n",
|
|
|
|
file, event, apc, apc_user, io_status, segments, length, offset, key);
|
|
|
|
|
|
|
|
if (!io_status) return STATUS_ACCESS_VIOLATION;
|
|
|
|
|
2020-05-29 15:35:16 +02:00
|
|
|
status = unix_funcs->server_get_unix_fd( file, FILE_READ_DATA, &unix_handle,
|
|
|
|
&needs_close, &type, &options );
|
2008-03-14 20:29:00 +01:00
|
|
|
if (status) return status;
|
|
|
|
|
|
|
|
if ((type != FD_TYPE_FILE) ||
|
|
|
|
(options & (FILE_SYNCHRONOUS_IO_ALERT | FILE_SYNCHRONOUS_IO_NONALERT)) ||
|
|
|
|
!(options & FILE_NO_INTERMEDIATE_BUFFERING))
|
|
|
|
{
|
|
|
|
status = STATUS_INVALID_PARAMETER;
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
|
|
|
while (length)
|
|
|
|
{
|
2013-10-09 16:13:41 +02:00
|
|
|
if (offset && offset->QuadPart != FILE_USE_FILE_POINTER_POSITION)
|
2008-03-14 20:29:00 +01:00
|
|
|
result = pread( unix_handle, (char *)segments->Buffer + pos,
|
2017-12-06 22:08:00 +01:00
|
|
|
min( length - pos, page_size - pos ), offset->QuadPart + total );
|
2008-03-14 20:29:00 +01:00
|
|
|
else
|
2017-12-06 22:08:00 +01:00
|
|
|
result = read( unix_handle, (char *)segments->Buffer + pos, min( length - pos, page_size - pos ) );
|
2008-03-14 20:29:00 +01:00
|
|
|
|
|
|
|
if (result == -1)
|
|
|
|
{
|
|
|
|
if (errno == EINTR) continue;
|
|
|
|
status = FILE_GetNtStatus();
|
|
|
|
break;
|
|
|
|
}
|
2017-12-06 22:07:54 +01:00
|
|
|
if (!result) break;
|
2008-03-14 20:29:00 +01:00
|
|
|
total += result;
|
|
|
|
length -= result;
|
|
|
|
if ((pos += result) == page_size)
|
|
|
|
{
|
|
|
|
pos = 0;
|
|
|
|
segments++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-06 22:07:54 +01:00
|
|
|
if (total == 0) status = STATUS_END_OF_FILE;
|
|
|
|
|
2010-06-21 16:16:04 +02:00
|
|
|
send_completion = cvalue != 0;
|
2008-03-14 20:29:00 +01:00
|
|
|
|
|
|
|
if (needs_close) close( unix_handle );
|
2010-06-21 16:16:04 +02:00
|
|
|
|
2017-12-06 22:07:45 +01:00
|
|
|
io_status->u.Status = status;
|
|
|
|
io_status->Information = total;
|
|
|
|
TRACE("= 0x%08x (%u)\n", status, total);
|
|
|
|
if (event) NtSetEvent( event, NULL );
|
|
|
|
if (apc) NtQueueApcThread( GetCurrentThread(), (PNTAPCFUNC)apc,
|
|
|
|
(ULONG_PTR)apc_user, (ULONG_PTR)io_status, 0 );
|
2019-02-21 15:10:14 +01:00
|
|
|
if (send_completion) NTDLL_AddCompletion( file, cvalue, status, total, TRUE );
|
2010-06-21 16:16:04 +02:00
|
|
|
|
2017-12-06 22:07:45 +01:00
|
|
|
return STATUS_PENDING;
|
|
|
|
|
|
|
|
error:
|
|
|
|
if (needs_close) close( unix_handle );
|
|
|
|
|
|
|
|
TRACE("= 0x%08x\n", status);
|
|
|
|
if (event) NtResetEvent( event, NULL );
|
|
|
|
|
2008-03-14 20:29:00 +01:00
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-06-26 04:08:17 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* FILE_AsyncWriteService (INTERNAL)
|
|
|
|
*/
|
2017-04-10 13:41:29 +02:00
|
|
|
static NTSTATUS FILE_AsyncWriteService( void *user, IO_STATUS_BLOCK *iosb, NTSTATUS status )
|
2003-06-26 04:08:17 +02:00
|
|
|
{
|
2015-03-02 08:56:47 +01:00
|
|
|
struct async_fileio_write *fileio = user;
|
2006-11-03 11:56:51 +01:00
|
|
|
int result, fd, needs_close;
|
2007-04-09 12:21:24 +02:00
|
|
|
enum server_fd_type type;
|
2002-06-14 02:36:20 +02:00
|
|
|
|
2005-01-14 20:54:38 +01:00
|
|
|
switch (status)
|
2003-06-26 04:08:17 +02:00
|
|
|
{
|
2005-01-14 20:54:38 +01:00
|
|
|
case STATUS_ALERTED:
|
|
|
|
/* write some data (non-blocking) */
|
2020-05-29 15:35:16 +02:00
|
|
|
if ((status = unix_funcs->server_get_unix_fd( fileio->io.handle, FILE_WRITE_DATA, &fd,
|
|
|
|
&needs_close, &type, NULL )))
|
2006-11-03 11:56:51 +01:00
|
|
|
break;
|
2007-04-10 17:07:27 +02:00
|
|
|
|
2017-10-09 14:28:56 +02:00
|
|
|
if (!fileio->count && (type == FD_TYPE_MAILSLOT || type == FD_TYPE_SOCKET))
|
2007-04-09 12:21:24 +02:00
|
|
|
result = send( fd, fileio->buffer, 0, 0 );
|
|
|
|
else
|
|
|
|
result = write( fd, &fileio->buffer[fileio->already], fileio->count - fileio->already );
|
|
|
|
|
2006-11-03 11:56:51 +01:00
|
|
|
if (needs_close) close( fd );
|
2002-06-14 02:36:20 +02:00
|
|
|
|
2005-01-14 20:54:38 +01:00
|
|
|
if (result < 0)
|
|
|
|
{
|
2007-04-05 10:55:40 +02:00
|
|
|
if (errno == EAGAIN || errno == EINTR) status = STATUS_PENDING;
|
|
|
|
else status = FILE_GetNtStatus();
|
2005-01-14 20:54:38 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2007-04-05 11:03:38 +02:00
|
|
|
fileio->already += result;
|
|
|
|
status = (fileio->already < fileio->count) ? STATUS_PENDING : STATUS_SUCCESS;
|
2005-01-14 20:54:38 +01:00
|
|
|
}
|
|
|
|
break;
|
2007-04-10 17:07:27 +02:00
|
|
|
|
|
|
|
case STATUS_TIMEOUT:
|
|
|
|
case STATUS_IO_TIMEOUT:
|
|
|
|
if (fileio->already) status = STATUS_SUCCESS;
|
2005-01-14 20:54:38 +01:00
|
|
|
break;
|
2003-06-26 04:08:17 +02:00
|
|
|
}
|
2007-04-10 17:19:24 +02:00
|
|
|
if (status != STATUS_PENDING)
|
|
|
|
{
|
|
|
|
iosb->u.Status = status;
|
2008-12-30 20:51:55 +01:00
|
|
|
iosb->Information = fileio->already;
|
2015-03-03 08:14:02 +01:00
|
|
|
release_fileio( &fileio->io );
|
2007-04-10 17:19:24 +02:00
|
|
|
}
|
2007-04-10 17:07:27 +02:00
|
|
|
return status;
|
2002-06-14 02:36:20 +02:00
|
|
|
}
|
|
|
|
|
2013-10-25 05:14:42 +02:00
|
|
|
static NTSTATUS set_pending_write( HANDLE device )
|
|
|
|
{
|
|
|
|
NTSTATUS status;
|
|
|
|
|
|
|
|
SERVER_START_REQ( set_serial_info )
|
|
|
|
{
|
|
|
|
req->handle = wine_server_obj_handle( device );
|
|
|
|
req->flags = SERIALINFO_PENDING_WRITE;
|
|
|
|
status = wine_server_call( req );
|
|
|
|
}
|
|
|
|
SERVER_END_REQ;
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
2002-06-14 02:36:20 +02:00
|
|
|
/******************************************************************************
|
|
|
|
* NtWriteFile [NTDLL.@]
|
|
|
|
* ZwWriteFile [NTDLL.@]
|
|
|
|
*
|
2003-07-19 00:55:28 +02:00
|
|
|
* Write to an open file handle.
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* FileHandle [I] Handle returned from ZwOpenFile() or ZwCreateFile()
|
|
|
|
* Event [I] Event to signal upon completion (or NULL)
|
|
|
|
* ApcRoutine [I] Callback to call upon completion (or NULL)
|
|
|
|
* ApcContext [I] Context for ApcRoutine (or NULL)
|
|
|
|
* IoStatusBlock [O] Receives information about the operation on return
|
|
|
|
* Buffer [I] Source for the data to write
|
|
|
|
* Length [I] Size of Buffer
|
|
|
|
* ByteOffset [O] Destination for the new file pointer position (or NULL)
|
|
|
|
* Key [O] Function unknown (may be NULL)
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Success: 0. IoStatusBlock is updated, and the Information member contains
|
|
|
|
* The number of bytes written.
|
|
|
|
* Failure: An NTSTATUS error code describing the error.
|
2002-06-14 02:36:20 +02:00
|
|
|
*/
|
2003-06-26 04:08:17 +02:00
|
|
|
NTSTATUS WINAPI NtWriteFile(HANDLE hFile, HANDLE hEvent,
|
|
|
|
PIO_APC_ROUTINE apc, void* apc_user,
|
|
|
|
PIO_STATUS_BLOCK io_status,
|
|
|
|
const void* buffer, ULONG length,
|
|
|
|
PLARGE_INTEGER offset, PULONG key)
|
1999-03-09 18:47:51 +01:00
|
|
|
{
|
2013-11-01 00:21:24 +01:00
|
|
|
int result, unix_handle, needs_close;
|
2007-04-10 22:32:46 +02:00
|
|
|
unsigned int options;
|
2007-04-06 16:06:16 +02:00
|
|
|
struct io_timeouts timeouts;
|
2019-03-05 13:16:46 +01:00
|
|
|
NTSTATUS status, ret_status;
|
2007-04-06 16:06:16 +02:00
|
|
|
ULONG total = 0;
|
2006-11-20 14:15:43 +01:00
|
|
|
enum server_fd_type type;
|
2007-11-09 23:12:07 +01:00
|
|
|
ULONG_PTR cvalue = apc ? 0 : (ULONG_PTR)apc_user;
|
2013-11-01 00:21:24 +01:00
|
|
|
BOOL send_completion = FALSE, async_write, append_write = FALSE, timeout_init_done = FALSE;
|
2013-10-07 07:40:10 +02:00
|
|
|
LARGE_INTEGER offset_eof;
|
2003-06-26 04:08:17 +02:00
|
|
|
|
2018-11-01 12:41:16 +01:00
|
|
|
TRACE("(%p,%p,%p,%p,%p,%p,0x%08x,%p,%p)\n",
|
2003-06-26 04:08:17 +02:00
|
|
|
hFile,hEvent,apc,apc_user,io_status,buffer,length,offset,key);
|
|
|
|
|
2005-04-25 18:02:16 +02:00
|
|
|
if (!io_status) return STATUS_ACCESS_VIOLATION;
|
|
|
|
|
2020-05-29 15:35:16 +02:00
|
|
|
status = unix_funcs->server_get_unix_fd( hFile, FILE_WRITE_DATA, &unix_handle,
|
|
|
|
&needs_close, &type, &options );
|
2013-10-07 07:40:10 +02:00
|
|
|
if (status == STATUS_ACCESS_DENIED)
|
|
|
|
{
|
2020-05-29 15:35:16 +02:00
|
|
|
status = unix_funcs->server_get_unix_fd( hFile, FILE_APPEND_DATA, &unix_handle,
|
|
|
|
&needs_close, &type, &options );
|
2013-10-07 07:40:10 +02:00
|
|
|
append_write = TRUE;
|
|
|
|
}
|
2017-01-26 00:51:35 +01:00
|
|
|
if (status && status != STATUS_BAD_DEVICE_TYPE) return status;
|
2003-06-26 04:08:17 +02:00
|
|
|
|
2019-03-05 13:16:46 +01:00
|
|
|
async_write = !(options & (FILE_SYNCHRONOUS_IO_ALERT | FILE_SYNCHRONOUS_IO_NONALERT));
|
|
|
|
|
2020-06-02 17:08:59 +02:00
|
|
|
if (!unix_funcs->virtual_check_buffer_for_read( buffer, length ))
|
2009-01-14 20:17:52 +01:00
|
|
|
{
|
|
|
|
status = STATUS_INVALID_USER_BUFFER;
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
2017-01-26 00:51:35 +01:00
|
|
|
if (status == STATUS_BAD_DEVICE_TYPE)
|
|
|
|
return server_write_file( hFile, hEvent, apc, apc_user, io_status, buffer, length, offset, key );
|
|
|
|
|
2013-09-02 11:29:38 +02:00
|
|
|
if (type == FD_TYPE_FILE)
|
2006-11-20 14:15:43 +01:00
|
|
|
{
|
2013-10-09 11:19:50 +02:00
|
|
|
if (async_write &&
|
2013-10-09 16:13:41 +02:00
|
|
|
(!offset || (offset->QuadPart < 0 && offset->QuadPart != FILE_WRITE_TO_END_OF_FILE)))
|
2006-11-20 14:15:43 +01:00
|
|
|
{
|
2013-09-02 11:29:38 +02:00
|
|
|
status = STATUS_INVALID_PARAMETER;
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
2013-10-07 07:40:10 +02:00
|
|
|
if (append_write)
|
|
|
|
{
|
2013-10-09 16:13:41 +02:00
|
|
|
offset_eof.QuadPart = FILE_WRITE_TO_END_OF_FILE;
|
2013-10-07 07:40:10 +02:00
|
|
|
offset = &offset_eof;
|
|
|
|
}
|
|
|
|
|
2013-10-09 16:13:41 +02:00
|
|
|
if (offset && offset->QuadPart != FILE_USE_FILE_POINTER_POSITION)
|
2013-09-02 11:29:38 +02:00
|
|
|
{
|
2013-09-10 13:20:03 +02:00
|
|
|
off_t off = offset->QuadPart;
|
|
|
|
|
2013-10-09 16:13:41 +02:00
|
|
|
if (offset->QuadPart == FILE_WRITE_TO_END_OF_FILE)
|
2013-09-10 13:20:03 +02:00
|
|
|
{
|
|
|
|
struct stat st;
|
|
|
|
|
|
|
|
if (fstat( unix_handle, &st ) == -1)
|
|
|
|
{
|
|
|
|
status = FILE_GetNtStatus();
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
off = st.st_size;
|
|
|
|
}
|
2013-09-13 08:45:44 +02:00
|
|
|
else if (offset->QuadPart < 0)
|
|
|
|
{
|
|
|
|
status = STATUS_INVALID_PARAMETER;
|
|
|
|
goto done;
|
|
|
|
}
|
2013-09-10 13:20:03 +02:00
|
|
|
|
2013-09-02 11:29:38 +02:00
|
|
|
/* async I/O doesn't make sense on regular files */
|
2013-09-10 13:20:03 +02:00
|
|
|
while ((result = pwrite( unix_handle, buffer, length, off )) == -1)
|
2006-11-20 14:15:43 +01:00
|
|
|
{
|
2013-09-02 11:29:38 +02:00
|
|
|
if (errno != EINTR)
|
|
|
|
{
|
|
|
|
if (errno == EFAULT) status = STATUS_INVALID_USER_BUFFER;
|
|
|
|
else status = FILE_GetNtStatus();
|
|
|
|
goto done;
|
|
|
|
}
|
2006-11-20 14:15:43 +01:00
|
|
|
}
|
2007-04-06 16:06:16 +02:00
|
|
|
|
2013-09-30 13:19:20 +02:00
|
|
|
if (!async_write)
|
2013-09-02 11:29:38 +02:00
|
|
|
/* update file pointer position */
|
2013-09-10 13:20:03 +02:00
|
|
|
lseek( unix_handle, off + result, SEEK_SET );
|
2007-04-06 16:06:16 +02:00
|
|
|
|
2013-09-02 11:29:38 +02:00
|
|
|
total = result;
|
|
|
|
status = STATUS_SUCCESS;
|
|
|
|
goto done;
|
|
|
|
}
|
2007-04-06 16:06:16 +02:00
|
|
|
}
|
2015-05-21 10:27:03 +02:00
|
|
|
else if (type == FD_TYPE_SERIAL || type == FD_TYPE_DEVICE)
|
2013-09-25 06:03:25 +02:00
|
|
|
{
|
2013-09-30 13:19:20 +02:00
|
|
|
if (async_write &&
|
2013-10-09 16:13:41 +02:00
|
|
|
(!offset || (offset->QuadPart < 0 && offset->QuadPart != FILE_WRITE_TO_END_OF_FILE)))
|
2013-09-25 06:03:25 +02:00
|
|
|
{
|
|
|
|
status = STATUS_INVALID_PARAMETER;
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
}
|
2007-04-06 16:06:16 +02:00
|
|
|
|
|
|
|
for (;;)
|
|
|
|
{
|
2007-04-09 12:21:24 +02:00
|
|
|
/* zero-length writes on sockets may not work with plain write(2) */
|
2017-10-09 14:28:56 +02:00
|
|
|
if (!length && (type == FD_TYPE_MAILSLOT || type == FD_TYPE_SOCKET))
|
2007-04-09 12:21:24 +02:00
|
|
|
result = send( unix_handle, buffer, 0, 0 );
|
|
|
|
else
|
|
|
|
result = write( unix_handle, (const char *)buffer + total, length - total );
|
|
|
|
|
|
|
|
if (result >= 0)
|
2007-04-06 16:06:16 +02:00
|
|
|
{
|
|
|
|
total += result;
|
|
|
|
if (total == length)
|
2006-11-20 14:15:43 +01:00
|
|
|
{
|
2007-04-05 10:55:40 +02:00
|
|
|
status = STATUS_SUCCESS;
|
2006-11-20 14:15:43 +01:00
|
|
|
goto done;
|
|
|
|
}
|
2008-11-12 19:15:31 +01:00
|
|
|
if (type == FD_TYPE_FILE) continue; /* no async I/O on regular files */
|
2006-11-20 14:15:43 +01:00
|
|
|
}
|
2009-01-14 20:17:52 +01:00
|
|
|
else if (errno != EAGAIN)
|
2006-11-20 14:15:43 +01:00
|
|
|
{
|
2007-04-06 16:06:16 +02:00
|
|
|
if (errno == EINTR) continue;
|
2009-01-14 20:17:52 +01:00
|
|
|
if (!total)
|
2006-11-20 14:15:43 +01:00
|
|
|
{
|
2009-01-14 20:17:52 +01:00
|
|
|
if (errno == EFAULT) status = STATUS_INVALID_USER_BUFFER;
|
|
|
|
else status = FILE_GetNtStatus();
|
2006-11-20 14:15:43 +01:00
|
|
|
}
|
2017-09-22 12:13:25 +02:00
|
|
|
goto err;
|
2006-11-20 14:15:43 +01:00
|
|
|
}
|
2003-12-02 00:01:12 +01:00
|
|
|
|
2013-09-30 13:19:20 +02:00
|
|
|
if (async_write)
|
2004-11-09 21:12:18 +01:00
|
|
|
{
|
2015-03-02 08:56:47 +01:00
|
|
|
struct async_fileio_write *fileio;
|
2003-06-26 04:08:17 +02:00
|
|
|
|
2017-04-10 13:21:56 +02:00
|
|
|
fileio = (struct async_fileio_write *)alloc_fileio( sizeof(*fileio), FILE_AsyncWriteService, hFile );
|
2015-03-02 09:53:40 +01:00
|
|
|
if (!fileio)
|
2007-04-06 16:06:16 +02:00
|
|
|
{
|
|
|
|
status = STATUS_NO_MEMORY;
|
2007-11-09 23:12:07 +01:00
|
|
|
goto err;
|
2007-04-06 16:06:16 +02:00
|
|
|
}
|
|
|
|
fileio->already = total;
|
|
|
|
fileio->count = length;
|
2007-04-10 17:19:24 +02:00
|
|
|
fileio->buffer = buffer;
|
|
|
|
|
|
|
|
SERVER_START_REQ( register_async )
|
|
|
|
{
|
|
|
|
req->type = ASYNC_TYPE_WRITE;
|
|
|
|
req->count = length;
|
2017-04-10 13:21:04 +02:00
|
|
|
req->async = server_async( hFile, &fileio->io, hEvent, apc, apc_user, io_status );
|
2007-04-10 17:19:24 +02:00
|
|
|
status = wine_server_call( req );
|
|
|
|
}
|
|
|
|
SERVER_END_REQ;
|
|
|
|
|
|
|
|
if (status != STATUS_PENDING) RtlFreeHeap( GetProcessHeap(), 0, fileio );
|
2007-11-09 23:12:07 +01:00
|
|
|
goto err;
|
2005-01-14 20:54:38 +01:00
|
|
|
}
|
2007-04-06 16:06:16 +02:00
|
|
|
else /* synchronous write, wait for the fd to become ready */
|
2003-08-18 21:45:53 +02:00
|
|
|
{
|
2007-04-06 16:06:16 +02:00
|
|
|
struct pollfd pfd;
|
|
|
|
int ret, timeout;
|
|
|
|
|
|
|
|
if (!timeout_init_done)
|
|
|
|
{
|
2013-11-01 00:21:24 +01:00
|
|
|
timeout_init_done = TRUE;
|
2007-04-06 16:06:16 +02:00
|
|
|
if ((status = get_io_timeouts( hFile, type, length, FALSE, &timeouts )))
|
2007-11-09 23:12:07 +01:00
|
|
|
goto err;
|
2007-04-06 16:06:16 +02:00
|
|
|
if (hEvent) NtResetEvent( hEvent, NULL );
|
|
|
|
}
|
|
|
|
timeout = get_next_io_timeout( &timeouts, total );
|
|
|
|
|
|
|
|
pfd.fd = unix_handle;
|
2007-05-03 13:14:25 +02:00
|
|
|
pfd.events = POLLOUT;
|
2007-04-06 16:06:16 +02:00
|
|
|
|
|
|
|
if (!timeout || !(ret = poll( &pfd, 1, timeout )))
|
|
|
|
{
|
|
|
|
/* return with what we got so far */
|
|
|
|
status = total ? STATUS_SUCCESS : STATUS_TIMEOUT;
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
if (ret == -1 && errno != EINTR)
|
|
|
|
{
|
|
|
|
status = FILE_GetNtStatus();
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
/* will now restart the write */
|
2003-08-18 21:45:53 +02:00
|
|
|
}
|
2003-06-26 04:08:17 +02:00
|
|
|
}
|
|
|
|
|
2006-11-03 11:38:44 +01:00
|
|
|
done:
|
2010-06-21 16:16:04 +02:00
|
|
|
send_completion = cvalue != 0;
|
2007-11-09 23:12:07 +01:00
|
|
|
|
|
|
|
err:
|
2006-11-03 11:38:44 +01:00
|
|
|
if (needs_close) close( unix_handle );
|
2013-10-25 05:14:42 +02:00
|
|
|
|
|
|
|
if (type == FD_TYPE_SERIAL && (status == STATUS_SUCCESS || status == STATUS_PENDING))
|
|
|
|
set_pending_write( hFile );
|
|
|
|
|
2007-04-06 16:06:16 +02:00
|
|
|
if (status == STATUS_SUCCESS)
|
|
|
|
{
|
|
|
|
io_status->u.Status = status;
|
|
|
|
io_status->Information = total;
|
|
|
|
TRACE("= SUCCESS (%u)\n", total);
|
|
|
|
if (hEvent) NtSetEvent( hEvent, NULL );
|
|
|
|
if (apc) NtQueueApcThread( GetCurrentThread(), (PNTAPCFUNC)apc,
|
|
|
|
(ULONG_PTR)apc_user, (ULONG_PTR)io_status, 0 );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
TRACE("= 0x%08x\n", status);
|
|
|
|
if (status != STATUS_PENDING && hEvent) NtResetEvent( hEvent, NULL );
|
|
|
|
}
|
2010-06-21 16:16:04 +02:00
|
|
|
|
2019-03-05 13:16:46 +01:00
|
|
|
ret_status = async_write && type == FD_TYPE_FILE && status == STATUS_SUCCESS ? STATUS_PENDING : status;
|
|
|
|
if (send_completion) NTDLL_AddCompletion( hFile, cvalue, status, total, ret_status == STATUS_PENDING );
|
2010-06-21 16:16:04 +02:00
|
|
|
|
2019-03-05 13:16:46 +01:00
|
|
|
return ret_status;
|
1999-03-09 18:47:51 +01:00
|
|
|
}
|
|
|
|
|
2007-04-16 14:45:03 +02:00
|
|
|
|
2008-03-14 20:30:12 +01:00
|
|
|
/******************************************************************************
|
|
|
|
* NtWriteFileGather [NTDLL.@]
|
|
|
|
* ZwWriteFileGather [NTDLL.@]
|
|
|
|
*/
|
|
|
|
NTSTATUS WINAPI NtWriteFileGather( HANDLE file, HANDLE event, PIO_APC_ROUTINE apc, void *apc_user,
|
|
|
|
PIO_STATUS_BLOCK io_status, FILE_SEGMENT_ELEMENT *segments,
|
|
|
|
ULONG length, PLARGE_INTEGER offset, PULONG key )
|
|
|
|
{
|
|
|
|
int result, unix_handle, needs_close;
|
|
|
|
unsigned int options;
|
|
|
|
NTSTATUS status;
|
|
|
|
ULONG pos = 0, total = 0;
|
|
|
|
enum server_fd_type type;
|
|
|
|
ULONG_PTR cvalue = apc ? 0 : (ULONG_PTR)apc_user;
|
2010-06-21 16:16:04 +02:00
|
|
|
BOOL send_completion = FALSE;
|
2008-03-14 20:30:12 +01:00
|
|
|
|
|
|
|
TRACE( "(%p,%p,%p,%p,%p,%p,0x%08x,%p,%p),partial stub!\n",
|
|
|
|
file, event, apc, apc_user, io_status, segments, length, offset, key);
|
|
|
|
|
|
|
|
if (length % page_size) return STATUS_INVALID_PARAMETER;
|
|
|
|
if (!io_status) return STATUS_ACCESS_VIOLATION;
|
|
|
|
|
2020-05-29 15:35:16 +02:00
|
|
|
status = unix_funcs->server_get_unix_fd( file, FILE_WRITE_DATA, &unix_handle,
|
|
|
|
&needs_close, &type, &options );
|
2008-03-14 20:30:12 +01:00
|
|
|
if (status) return status;
|
|
|
|
|
|
|
|
if ((type != FD_TYPE_FILE) ||
|
|
|
|
(options & (FILE_SYNCHRONOUS_IO_ALERT | FILE_SYNCHRONOUS_IO_NONALERT)) ||
|
|
|
|
!(options & FILE_NO_INTERMEDIATE_BUFFERING))
|
|
|
|
{
|
|
|
|
status = STATUS_INVALID_PARAMETER;
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
|
|
|
while (length)
|
|
|
|
{
|
2013-10-09 16:13:41 +02:00
|
|
|
if (offset && offset->QuadPart != FILE_USE_FILE_POINTER_POSITION)
|
2008-03-14 20:30:12 +01:00
|
|
|
result = pwrite( unix_handle, (char *)segments->Buffer + pos,
|
|
|
|
page_size - pos, offset->QuadPart + total );
|
|
|
|
else
|
|
|
|
result = write( unix_handle, (char *)segments->Buffer + pos, page_size - pos );
|
|
|
|
|
|
|
|
if (result == -1)
|
|
|
|
{
|
|
|
|
if (errno == EINTR) continue;
|
|
|
|
if (errno == EFAULT)
|
|
|
|
{
|
|
|
|
status = STATUS_INVALID_USER_BUFFER;
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
status = FILE_GetNtStatus();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (!result)
|
|
|
|
{
|
|
|
|
status = STATUS_DISK_FULL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
total += result;
|
|
|
|
length -= result;
|
|
|
|
if ((pos += result) == page_size)
|
|
|
|
{
|
|
|
|
pos = 0;
|
|
|
|
segments++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-06-21 16:16:04 +02:00
|
|
|
send_completion = cvalue != 0;
|
2008-03-14 20:30:12 +01:00
|
|
|
|
|
|
|
error:
|
|
|
|
if (needs_close) close( unix_handle );
|
|
|
|
if (status == STATUS_SUCCESS)
|
|
|
|
{
|
|
|
|
io_status->u.Status = status;
|
|
|
|
io_status->Information = total;
|
|
|
|
TRACE("= SUCCESS (%u)\n", total);
|
|
|
|
if (event) NtSetEvent( event, NULL );
|
|
|
|
if (apc) NtQueueApcThread( GetCurrentThread(), (PNTAPCFUNC)apc,
|
|
|
|
(ULONG_PTR)apc_user, (ULONG_PTR)io_status, 0 );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
TRACE("= 0x%08x\n", status);
|
|
|
|
if (status != STATUS_PENDING && event) NtResetEvent( event, NULL );
|
|
|
|
}
|
2010-06-21 16:16:04 +02:00
|
|
|
|
2019-02-21 15:10:14 +01:00
|
|
|
if (send_completion) NTDLL_AddCompletion( file, cvalue, status, total, FALSE );
|
2010-06-21 16:16:04 +02:00
|
|
|
|
2008-03-14 20:30:12 +01:00
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-12-03 14:25:04 +01:00
|
|
|
/* do an ioctl call through the server */
|
2007-04-16 14:45:03 +02:00
|
|
|
static NTSTATUS server_ioctl_file( HANDLE handle, HANDLE event,
|
|
|
|
PIO_APC_ROUTINE apc, PVOID apc_context,
|
|
|
|
IO_STATUS_BLOCK *io, ULONG code,
|
2007-06-23 19:34:32 +02:00
|
|
|
const void *in_buffer, ULONG in_size,
|
2007-04-16 14:45:03 +02:00
|
|
|
PVOID out_buffer, ULONG out_size )
|
|
|
|
{
|
2015-05-05 06:35:57 +02:00
|
|
|
struct async_irp *async;
|
2007-04-16 14:45:03 +02:00
|
|
|
NTSTATUS status;
|
2007-05-03 17:43:18 +02:00
|
|
|
HANDLE wait_handle;
|
|
|
|
ULONG options;
|
2007-04-16 14:45:03 +02:00
|
|
|
|
2017-04-10 13:21:56 +02:00
|
|
|
if (!(async = (struct async_irp *)alloc_fileio( sizeof(*async), irp_completion, handle )))
|
2007-05-08 20:45:44 +02:00
|
|
|
return STATUS_NO_MEMORY;
|
2007-06-03 12:05:02 +02:00
|
|
|
async->buffer = out_buffer;
|
|
|
|
async->size = out_size;
|
2007-05-08 20:45:44 +02:00
|
|
|
|
2007-04-16 14:45:03 +02:00
|
|
|
SERVER_START_REQ( ioctl )
|
|
|
|
{
|
2017-04-12 13:55:17 +02:00
|
|
|
req->code = code;
|
|
|
|
req->async = server_async( handle, &async->io, event, apc, apc_context, io );
|
2007-04-16 14:45:03 +02:00
|
|
|
wine_server_add_data( req, in_buffer, in_size );
|
2016-10-16 08:51:06 +02:00
|
|
|
if ((code & 3) != METHOD_BUFFERED)
|
|
|
|
wine_server_add_data( req, out_buffer, out_size );
|
2007-04-16 14:45:03 +02:00
|
|
|
wine_server_set_reply( req, out_buffer, out_size );
|
2020-06-02 17:08:59 +02:00
|
|
|
status = unix_funcs->virtual_locked_server_call( req );
|
2008-12-08 16:05:17 +01:00
|
|
|
wait_handle = wine_server_ptr_handle( reply->wait );
|
2007-05-03 17:43:18 +02:00
|
|
|
options = reply->options;
|
2017-06-26 12:20:10 +02:00
|
|
|
if (wait_handle && status != STATUS_PENDING)
|
|
|
|
{
|
|
|
|
io->u.Status = status;
|
|
|
|
io->Information = wine_server_reply_size( reply );
|
|
|
|
}
|
2007-04-16 14:45:03 +02:00
|
|
|
}
|
|
|
|
SERVER_END_REQ;
|
|
|
|
|
|
|
|
if (status == STATUS_NOT_SUPPORTED)
|
|
|
|
FIXME("Unsupported ioctl %x (device=%x access=%x func=%x method=%x)\n",
|
|
|
|
code, code >> 16, (code >> 14) & 3, (code >> 2) & 0xfff, code & 3);
|
|
|
|
|
2007-05-08 20:45:44 +02:00
|
|
|
if (status != STATUS_PENDING) RtlFreeHeap( GetProcessHeap(), 0, async );
|
|
|
|
|
2019-05-23 19:35:51 +02:00
|
|
|
if (wait_handle) status = wait_async( wait_handle, (options & FILE_SYNCHRONOUS_IO_ALERT), io );
|
2007-04-16 14:45:03 +02:00
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
2009-12-14 15:32:50 +01:00
|
|
|
/* Tell Valgrind to ignore any holes in structs we will be passing to the
|
|
|
|
* server */
|
|
|
|
static void ignore_server_ioctl_struct_holes (ULONG code, const void *in_buffer,
|
|
|
|
ULONG in_size)
|
|
|
|
{
|
|
|
|
#ifdef VALGRIND_MAKE_MEM_DEFINED
|
|
|
|
# define IGNORE_STRUCT_HOLE(buf, size, t, f1, f2) \
|
|
|
|
do { \
|
2011-01-28 22:58:18 +01:00
|
|
|
if (FIELD_OFFSET(t, f1) + sizeof(((t *)0)->f1) < FIELD_OFFSET(t, f2)) \
|
|
|
|
if ((size) >= FIELD_OFFSET(t, f2)) \
|
|
|
|
VALGRIND_MAKE_MEM_DEFINED( \
|
|
|
|
(const char *)(buf) + FIELD_OFFSET(t, f1) + sizeof(((t *)0)->f1), \
|
|
|
|
FIELD_OFFSET(t, f2) - FIELD_OFFSET(t, f1) + sizeof(((t *)0)->f1)); \
|
2009-12-14 15:32:50 +01:00
|
|
|
} while (0)
|
|
|
|
|
|
|
|
switch (code)
|
|
|
|
{
|
|
|
|
case FSCTL_PIPE_WAIT:
|
|
|
|
IGNORE_STRUCT_HOLE(in_buffer, in_size, FILE_PIPE_WAIT_FOR_BUFFER, TimeoutSpecified, Name);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2007-04-16 14:45:03 +02:00
|
|
|
|
1999-03-09 18:47:51 +01:00
|
|
|
/**************************************************************************
|
2001-06-19 20:20:47 +02:00
|
|
|
* NtDeviceIoControlFile [NTDLL.@]
|
2001-07-11 20:56:41 +02:00
|
|
|
* ZwDeviceIoControlFile [NTDLL.@]
|
2003-07-19 00:55:28 +02:00
|
|
|
*
|
|
|
|
* Perform an I/O control operation on an open file handle.
|
|
|
|
*
|
|
|
|
* PARAMS
|
2006-01-18 17:18:22 +01:00
|
|
|
* handle [I] Handle returned from ZwOpenFile() or ZwCreateFile()
|
|
|
|
* event [I] Event to signal upon completion (or NULL)
|
|
|
|
* apc [I] Callback to call upon completion (or NULL)
|
|
|
|
* apc_context [I] Context for ApcRoutine (or NULL)
|
|
|
|
* io [O] Receives information about the operation on return
|
|
|
|
* code [I] Control code for the operation to perform
|
|
|
|
* in_buffer [I] Source for any input data required (or NULL)
|
|
|
|
* in_size [I] Size of InputBuffer
|
|
|
|
* out_buffer [O] Source for any output data returned (or NULL)
|
|
|
|
* out_size [I] Size of OutputBuffer
|
2003-07-19 00:55:28 +02:00
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Success: 0. IoStatusBlock is updated.
|
|
|
|
* Failure: An NTSTATUS error code describing the error.
|
1999-03-09 18:47:51 +01:00
|
|
|
*/
|
2006-01-18 17:18:22 +01:00
|
|
|
NTSTATUS WINAPI NtDeviceIoControlFile(HANDLE handle, HANDLE event,
|
|
|
|
PIO_APC_ROUTINE apc, PVOID apc_context,
|
|
|
|
PIO_STATUS_BLOCK io, ULONG code,
|
|
|
|
PVOID in_buffer, ULONG in_size,
|
|
|
|
PVOID out_buffer, ULONG out_size)
|
1999-03-09 18:47:51 +01:00
|
|
|
{
|
2006-01-18 17:18:22 +01:00
|
|
|
ULONG device = (code >> 16);
|
2007-11-09 23:11:48 +01:00
|
|
|
NTSTATUS status = STATUS_NOT_SUPPORTED;
|
2006-01-12 13:32:51 +01:00
|
|
|
|
2006-10-16 13:49:06 +02:00
|
|
|
TRACE("(%p,%p,%p,%p,%p,0x%08x,%p,0x%08x,%p,0x%08x)\n",
|
2006-01-18 17:18:22 +01:00
|
|
|
handle, event, apc, apc_context, io, code,
|
|
|
|
in_buffer, in_size, out_buffer, out_size);
|
|
|
|
|
|
|
|
switch(device)
|
2003-06-24 21:28:21 +02:00
|
|
|
{
|
2006-01-18 17:18:22 +01:00
|
|
|
case FILE_DEVICE_DISK:
|
|
|
|
case FILE_DEVICE_CD_ROM:
|
|
|
|
case FILE_DEVICE_DVD:
|
|
|
|
case FILE_DEVICE_CONTROLLER:
|
|
|
|
case FILE_DEVICE_MASS_STORAGE:
|
2007-04-16 14:45:03 +02:00
|
|
|
status = CDROM_DeviceIoControl(handle, event, apc, apc_context, io, code,
|
|
|
|
in_buffer, in_size, out_buffer, out_size);
|
2006-01-18 17:18:22 +01:00
|
|
|
break;
|
|
|
|
case FILE_DEVICE_SERIAL_PORT:
|
2007-04-16 14:45:03 +02:00
|
|
|
status = COMM_DeviceIoControl(handle, event, apc, apc_context, io, code,
|
|
|
|
in_buffer, in_size, out_buffer, out_size);
|
2006-01-18 17:18:22 +01:00
|
|
|
break;
|
2006-01-26 13:23:08 +01:00
|
|
|
case FILE_DEVICE_TAPE:
|
2007-04-16 14:45:03 +02:00
|
|
|
status = TAPE_DeviceIoControl(handle, event, apc, apc_context, io, code,
|
|
|
|
in_buffer, in_size, out_buffer, out_size);
|
2006-01-26 13:23:08 +01:00
|
|
|
break;
|
2007-11-09 23:11:48 +01:00
|
|
|
}
|
|
|
|
|
2008-01-16 14:57:20 +01:00
|
|
|
if (status == STATUS_NOT_SUPPORTED || status == STATUS_BAD_DEVICE_TYPE)
|
2017-06-26 12:19:56 +02:00
|
|
|
return server_ioctl_file( handle, event, apc, apc_context, io, code,
|
|
|
|
in_buffer, in_size, out_buffer, out_size );
|
2007-11-09 23:11:48 +01:00
|
|
|
|
2007-04-16 14:45:03 +02:00
|
|
|
if (status != STATUS_PENDING) io->u.Status = status;
|
|
|
|
return status;
|
1999-03-09 18:47:51 +01:00
|
|
|
}
|
|
|
|
|
2005-09-06 16:09:42 +02:00
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
* NtFsControlFile [NTDLL.@]
|
|
|
|
* ZwFsControlFile [NTDLL.@]
|
|
|
|
*
|
|
|
|
* Perform a file system control operation on an open file handle.
|
|
|
|
*
|
|
|
|
* PARAMS
|
2006-01-18 17:18:22 +01:00
|
|
|
* handle [I] Handle returned from ZwOpenFile() or ZwCreateFile()
|
|
|
|
* event [I] Event to signal upon completion (or NULL)
|
|
|
|
* apc [I] Callback to call upon completion (or NULL)
|
|
|
|
* apc_context [I] Context for ApcRoutine (or NULL)
|
|
|
|
* io [O] Receives information about the operation on return
|
|
|
|
* code [I] Control code for the operation to perform
|
|
|
|
* in_buffer [I] Source for any input data required (or NULL)
|
|
|
|
* in_size [I] Size of InputBuffer
|
|
|
|
* out_buffer [O] Source for any output data returned (or NULL)
|
|
|
|
* out_size [I] Size of OutputBuffer
|
2005-09-06 16:09:42 +02:00
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Success: 0. IoStatusBlock is updated.
|
|
|
|
* Failure: An NTSTATUS error code describing the error.
|
1999-03-09 18:47:51 +01:00
|
|
|
*/
|
2006-01-18 17:18:22 +01:00
|
|
|
NTSTATUS WINAPI NtFsControlFile(HANDLE handle, HANDLE event, PIO_APC_ROUTINE apc,
|
|
|
|
PVOID apc_context, PIO_STATUS_BLOCK io, ULONG code,
|
|
|
|
PVOID in_buffer, ULONG in_size, PVOID out_buffer, ULONG out_size)
|
1999-03-09 18:47:51 +01:00
|
|
|
{
|
2007-04-05 10:55:40 +02:00
|
|
|
NTSTATUS status;
|
|
|
|
|
2006-10-16 13:49:06 +02:00
|
|
|
TRACE("(%p,%p,%p,%p,%p,0x%08x,%p,0x%08x,%p,0x%08x)\n",
|
2006-01-18 17:18:22 +01:00
|
|
|
handle, event, apc, apc_context, io, code,
|
|
|
|
in_buffer, in_size, out_buffer, out_size);
|
2005-08-18 12:59:26 +02:00
|
|
|
|
2006-01-18 17:18:22 +01:00
|
|
|
if (!io) return STATUS_INVALID_PARAMETER;
|
2005-08-18 12:59:26 +02:00
|
|
|
|
2009-12-14 15:32:50 +01:00
|
|
|
ignore_server_ioctl_struct_holes( code, in_buffer, in_size );
|
|
|
|
|
2006-01-18 17:18:22 +01:00
|
|
|
switch(code)
|
2005-08-18 12:59:26 +02:00
|
|
|
{
|
2006-01-18 17:18:22 +01:00
|
|
|
case FSCTL_DISMOUNT_VOLUME:
|
2007-04-16 14:54:52 +02:00
|
|
|
status = server_ioctl_file( handle, event, apc, apc_context, io, code,
|
|
|
|
in_buffer, in_size, out_buffer, out_size );
|
|
|
|
if (!status) status = DIR_unmount_device( handle );
|
2017-06-26 12:19:56 +02:00
|
|
|
return status;
|
2005-10-28 18:45:24 +02:00
|
|
|
|
2007-09-13 15:03:48 +02:00
|
|
|
case FSCTL_PIPE_IMPERSONATE:
|
2007-09-17 13:42:01 +02:00
|
|
|
FIXME("FSCTL_PIPE_IMPERSONATE: impersonating self\n");
|
2007-09-13 15:03:48 +02:00
|
|
|
status = RtlImpersonateSelf( SecurityImpersonation );
|
|
|
|
break;
|
|
|
|
|
2013-12-20 02:47:02 +01:00
|
|
|
case FSCTL_IS_VOLUME_MOUNTED:
|
2006-05-09 22:55:38 +02:00
|
|
|
case FSCTL_LOCK_VOLUME:
|
|
|
|
case FSCTL_UNLOCK_VOLUME:
|
2006-10-16 13:49:06 +02:00
|
|
|
FIXME("stub! return success - Unsupported fsctl %x (device=%x access=%x func=%x method=%x)\n",
|
2006-05-09 22:55:38 +02:00
|
|
|
code, code >> 16, (code >> 14) & 3, (code >> 2) & 0xfff, code & 3);
|
2007-04-05 10:55:40 +02:00
|
|
|
status = STATUS_SUCCESS;
|
2006-05-09 22:55:38 +02:00
|
|
|
break;
|
|
|
|
|
2010-11-20 15:48:02 +01:00
|
|
|
case FSCTL_GET_RETRIEVAL_POINTERS:
|
|
|
|
{
|
|
|
|
RETRIEVAL_POINTERS_BUFFER *buffer = (RETRIEVAL_POINTERS_BUFFER *)out_buffer;
|
|
|
|
|
|
|
|
FIXME("stub: FSCTL_GET_RETRIEVAL_POINTERS\n");
|
|
|
|
|
|
|
|
if (out_size >= sizeof(RETRIEVAL_POINTERS_BUFFER))
|
|
|
|
{
|
|
|
|
buffer->ExtentCount = 1;
|
|
|
|
buffer->StartingVcn.QuadPart = 1;
|
|
|
|
buffer->Extents[0].NextVcn.QuadPart = 0;
|
|
|
|
buffer->Extents[0].Lcn.QuadPart = 0;
|
|
|
|
io->Information = sizeof(RETRIEVAL_POINTERS_BUFFER);
|
|
|
|
status = STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
io->Information = 0;
|
|
|
|
status = STATUS_BUFFER_TOO_SMALL;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2015-10-20 20:08:54 +02:00
|
|
|
case FSCTL_SET_SPARSE:
|
|
|
|
TRACE("FSCTL_SET_SPARSE: Ignoring request\n");
|
|
|
|
io->Information = 0;
|
|
|
|
status = STATUS_SUCCESS;
|
|
|
|
break;
|
2006-01-18 17:18:22 +01:00
|
|
|
default:
|
2017-06-26 12:19:56 +02:00
|
|
|
return server_ioctl_file( handle, event, apc, apc_context, io, code,
|
|
|
|
in_buffer, in_size, out_buffer, out_size );
|
2005-08-18 12:59:26 +02:00
|
|
|
}
|
2007-04-05 10:55:40 +02:00
|
|
|
|
|
|
|
if (status != STATUS_PENDING) io->u.Status = status;
|
|
|
|
return status;
|
1999-03-09 18:47:51 +01:00
|
|
|
}
|
|
|
|
|
2015-03-02 12:56:40 +01:00
|
|
|
|
|
|
|
struct read_changes_fileio
|
|
|
|
{
|
|
|
|
struct async_fileio io;
|
|
|
|
void *buffer;
|
|
|
|
ULONG buffer_size;
|
|
|
|
ULONG data_size;
|
|
|
|
char data[1];
|
|
|
|
};
|
|
|
|
|
2017-04-10 13:41:29 +02:00
|
|
|
static NTSTATUS read_changes_apc( void *user, IO_STATUS_BLOCK *iosb, NTSTATUS status )
|
2015-03-02 12:56:40 +01:00
|
|
|
{
|
|
|
|
struct read_changes_fileio *fileio = user;
|
2015-05-07 09:02:26 +02:00
|
|
|
int size = 0;
|
2015-03-02 12:56:40 +01:00
|
|
|
|
2015-05-07 09:02:26 +02:00
|
|
|
if (status == STATUS_ALERTED)
|
2015-03-02 12:56:40 +01:00
|
|
|
{
|
2015-05-07 09:02:26 +02:00
|
|
|
SERVER_START_REQ( read_change )
|
2015-03-02 12:56:40 +01:00
|
|
|
{
|
2015-05-07 09:02:26 +02:00
|
|
|
req->handle = wine_server_obj_handle( fileio->io.handle );
|
|
|
|
wine_server_set_reply( req, fileio->data, fileio->data_size );
|
|
|
|
status = wine_server_call( req );
|
|
|
|
size = wine_server_reply_size( reply );
|
2015-03-02 12:56:40 +01:00
|
|
|
}
|
2015-05-07 09:02:26 +02:00
|
|
|
SERVER_END_REQ;
|
2015-03-02 12:56:40 +01:00
|
|
|
|
2015-05-07 09:02:26 +02:00
|
|
|
if (status == STATUS_SUCCESS && fileio->buffer)
|
2015-03-02 12:56:40 +01:00
|
|
|
{
|
2015-05-07 09:02:26 +02:00
|
|
|
FILE_NOTIFY_INFORMATION *pfni = fileio->buffer;
|
|
|
|
int i, left = fileio->buffer_size;
|
|
|
|
DWORD *last_entry_offset = NULL;
|
|
|
|
struct filesystem_event *event = (struct filesystem_event*)fileio->data;
|
|
|
|
|
|
|
|
while (size && left >= sizeof(*pfni))
|
|
|
|
{
|
2020-03-23 01:11:29 +01:00
|
|
|
DWORD len = (left - offsetof(FILE_NOTIFY_INFORMATION, FileName)) / sizeof(WCHAR);
|
|
|
|
|
2015-05-07 09:02:26 +02:00
|
|
|
/* convert to an NT style path */
|
|
|
|
for (i = 0; i < event->len; i++)
|
|
|
|
if (event->name[i] == '/') event->name[i] = '\\';
|
|
|
|
|
|
|
|
pfni->Action = event->action;
|
2020-03-23 01:11:29 +01:00
|
|
|
pfni->FileNameLength = ntdll_umbstowcs( event->name, event->len, pfni->FileName, len );
|
2015-05-07 09:02:26 +02:00
|
|
|
last_entry_offset = &pfni->NextEntryOffset;
|
|
|
|
|
2020-03-23 01:11:29 +01:00
|
|
|
if (pfni->FileNameLength == len) break;
|
2015-05-07 09:02:26 +02:00
|
|
|
|
|
|
|
i = offsetof(FILE_NOTIFY_INFORMATION, FileName[pfni->FileNameLength]);
|
|
|
|
pfni->FileNameLength *= sizeof(WCHAR);
|
|
|
|
pfni->NextEntryOffset = i;
|
|
|
|
pfni = (FILE_NOTIFY_INFORMATION*)((char*)pfni + i);
|
|
|
|
left -= i;
|
|
|
|
|
|
|
|
i = (offsetof(struct filesystem_event, name[event->len])
|
|
|
|
+ sizeof(int)-1) / sizeof(int) * sizeof(int);
|
|
|
|
event = (struct filesystem_event*)((char*)event + i);
|
|
|
|
size -= i;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (size)
|
|
|
|
{
|
|
|
|
status = STATUS_NOTIFY_ENUM_DIR;
|
|
|
|
size = 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (last_entry_offset) *last_entry_offset = 0;
|
|
|
|
size = fileio->buffer_size - left;
|
|
|
|
}
|
2015-03-02 12:56:40 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-05-07 09:02:26 +02:00
|
|
|
status = STATUS_NOTIFY_ENUM_DIR;
|
|
|
|
size = 0;
|
2015-03-02 12:56:40 +01:00
|
|
|
}
|
|
|
|
}
|
2015-05-07 09:02:26 +02:00
|
|
|
|
|
|
|
if (status != STATUS_PENDING)
|
2015-03-02 12:56:40 +01:00
|
|
|
{
|
2015-05-07 09:02:26 +02:00
|
|
|
iosb->u.Status = status;
|
|
|
|
iosb->Information = size;
|
|
|
|
release_fileio( &fileio->io );
|
2015-03-02 12:56:40 +01:00
|
|
|
}
|
2015-05-07 09:02:26 +02:00
|
|
|
return status;
|
2015-03-02 12:56:40 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
#define FILE_NOTIFY_ALL ( \
|
|
|
|
FILE_NOTIFY_CHANGE_FILE_NAME | \
|
|
|
|
FILE_NOTIFY_CHANGE_DIR_NAME | \
|
|
|
|
FILE_NOTIFY_CHANGE_ATTRIBUTES | \
|
|
|
|
FILE_NOTIFY_CHANGE_SIZE | \
|
|
|
|
FILE_NOTIFY_CHANGE_LAST_WRITE | \
|
|
|
|
FILE_NOTIFY_CHANGE_LAST_ACCESS | \
|
|
|
|
FILE_NOTIFY_CHANGE_CREATION | \
|
|
|
|
FILE_NOTIFY_CHANGE_SECURITY )
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* NtNotifyChangeDirectoryFile [NTDLL.@]
|
|
|
|
*/
|
|
|
|
NTSTATUS WINAPI NtNotifyChangeDirectoryFile( HANDLE handle, HANDLE event, PIO_APC_ROUTINE apc,
|
|
|
|
void *apc_context, PIO_STATUS_BLOCK iosb, void *buffer,
|
|
|
|
ULONG buffer_size, ULONG filter, BOOLEAN subtree )
|
|
|
|
{
|
|
|
|
struct read_changes_fileio *fileio;
|
|
|
|
NTSTATUS status;
|
|
|
|
ULONG size = max( 4096, buffer_size );
|
|
|
|
|
|
|
|
TRACE( "%p %p %p %p %p %p %u %u %d\n",
|
|
|
|
handle, event, apc, apc_context, iosb, buffer, buffer_size, filter, subtree );
|
|
|
|
|
|
|
|
if (!iosb) return STATUS_ACCESS_VIOLATION;
|
|
|
|
if (filter == 0 || (filter & ~FILE_NOTIFY_ALL)) return STATUS_INVALID_PARAMETER;
|
|
|
|
|
2015-03-02 09:53:40 +01:00
|
|
|
fileio = (struct read_changes_fileio *)alloc_fileio( offsetof(struct read_changes_fileio, data[size]),
|
2017-04-10 13:21:56 +02:00
|
|
|
read_changes_apc, handle );
|
2015-03-02 09:53:40 +01:00
|
|
|
if (!fileio) return STATUS_NO_MEMORY;
|
2015-03-02 12:56:40 +01:00
|
|
|
|
|
|
|
fileio->buffer = buffer;
|
|
|
|
fileio->buffer_size = buffer_size;
|
|
|
|
fileio->data_size = size;
|
|
|
|
|
|
|
|
SERVER_START_REQ( read_directory_changes )
|
|
|
|
{
|
2017-04-10 13:21:04 +02:00
|
|
|
req->filter = filter;
|
|
|
|
req->want_data = (buffer != NULL);
|
|
|
|
req->subtree = subtree;
|
|
|
|
req->async = server_async( handle, &fileio->io, event, apc, apc_context, iosb );
|
2015-03-02 12:56:40 +01:00
|
|
|
status = wine_server_call( req );
|
|
|
|
}
|
|
|
|
SERVER_END_REQ;
|
|
|
|
|
|
|
|
if (status != STATUS_PENDING) RtlFreeHeap( GetProcessHeap(), 0, fileio );
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
1999-03-09 18:47:51 +01:00
|
|
|
/******************************************************************************
|
2001-06-21 01:03:14 +02:00
|
|
|
* NtSetVolumeInformationFile [NTDLL.@]
|
2001-07-11 20:56:41 +02:00
|
|
|
* ZwSetVolumeInformationFile [NTDLL.@]
|
2003-07-19 00:55:28 +02:00
|
|
|
*
|
|
|
|
* Set volume information for an open file handle.
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* FileHandle [I] Handle returned from ZwOpenFile() or ZwCreateFile()
|
|
|
|
* IoStatusBlock [O] Receives information about the operation on return
|
|
|
|
* FsInformation [I] Source for volume information
|
|
|
|
* Length [I] Size of FsInformation
|
|
|
|
* FsInformationClass [I] Type of volume information to set
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Success: 0. IoStatusBlock is updated.
|
|
|
|
* Failure: An NTSTATUS error code describing the error.
|
1999-03-09 18:47:51 +01:00
|
|
|
*/
|
|
|
|
NTSTATUS WINAPI NtSetVolumeInformationFile(
|
|
|
|
IN HANDLE FileHandle,
|
1999-07-31 19:32:05 +02:00
|
|
|
PIO_STATUS_BLOCK IoStatusBlock,
|
|
|
|
PVOID FsInformation,
|
|
|
|
ULONG Length,
|
2002-06-01 01:06:46 +02:00
|
|
|
FS_INFORMATION_CLASS FsInformationClass)
|
1999-03-09 18:47:51 +01:00
|
|
|
{
|
2006-10-16 13:49:06 +02:00
|
|
|
FIXME("(%p,%p,%p,0x%08x,0x%08x) stub\n",
|
1999-07-31 19:32:05 +02:00
|
|
|
FileHandle,IoStatusBlock,FsInformation,Length,FsInformationClass);
|
1999-03-09 18:47:51 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-10-29 10:24:34 +01:00
|
|
|
#if defined(__ANDROID__) && !defined(HAVE_FUTIMENS)
|
|
|
|
static int futimens( int fd, const struct timespec spec[2] )
|
|
|
|
{
|
|
|
|
return syscall( __NR_utimensat, fd, NULL, spec, 0 );
|
|
|
|
}
|
|
|
|
#define HAVE_FUTIMENS
|
|
|
|
#endif /* __ANDROID__ */
|
|
|
|
|
2014-12-22 12:50:32 +01:00
|
|
|
#ifndef UTIME_OMIT
|
|
|
|
#define UTIME_OMIT ((1 << 30) - 2)
|
|
|
|
#endif
|
|
|
|
|
2019-11-07 16:24:34 +01:00
|
|
|
static BOOL set_file_times_precise( int fd, const LARGE_INTEGER *mtime,
|
|
|
|
const LARGE_INTEGER *atime, NTSTATUS *status )
|
2012-10-30 11:44:10 +01:00
|
|
|
{
|
2012-10-26 01:52:25 +02:00
|
|
|
#ifdef HAVE_FUTIMENS
|
|
|
|
struct timespec tv[2];
|
|
|
|
|
|
|
|
tv[0].tv_sec = tv[1].tv_sec = 0;
|
|
|
|
tv[0].tv_nsec = tv[1].tv_nsec = UTIME_OMIT;
|
|
|
|
if (atime->QuadPart)
|
|
|
|
{
|
|
|
|
tv[0].tv_sec = atime->QuadPart / 10000000 - SECS_1601_TO_1970;
|
|
|
|
tv[0].tv_nsec = (atime->QuadPart % 10000000) * 100;
|
|
|
|
}
|
|
|
|
if (mtime->QuadPart)
|
|
|
|
{
|
|
|
|
tv[1].tv_sec = mtime->QuadPart / 10000000 - SECS_1601_TO_1970;
|
|
|
|
tv[1].tv_nsec = (mtime->QuadPart % 10000000) * 100;
|
|
|
|
}
|
2019-11-07 16:24:34 +01:00
|
|
|
#ifdef __APPLE__
|
|
|
|
if (!&futimens) return FALSE;
|
|
|
|
#endif
|
|
|
|
if (futimens( fd, tv ) == -1) *status = FILE_GetNtStatus();
|
|
|
|
else *status = STATUS_SUCCESS;
|
|
|
|
return TRUE;
|
|
|
|
#else
|
|
|
|
return FALSE;
|
|
|
|
#endif
|
|
|
|
}
|
2012-10-26 01:52:25 +02:00
|
|
|
|
2019-11-07 16:24:34 +01:00
|
|
|
static NTSTATUS set_file_times( int fd, const LARGE_INTEGER *mtime, const LARGE_INTEGER *atime )
|
|
|
|
{
|
|
|
|
NTSTATUS status = STATUS_SUCCESS;
|
|
|
|
#if defined(HAVE_FUTIMES) || defined(HAVE_FUTIMESAT)
|
2012-10-30 11:44:10 +01:00
|
|
|
struct timeval tv[2];
|
|
|
|
struct stat st;
|
2019-11-07 16:24:34 +01:00
|
|
|
#endif
|
|
|
|
|
|
|
|
if (set_file_times_precise( fd, mtime, atime, &status ))
|
|
|
|
return status;
|
2012-10-30 11:44:10 +01:00
|
|
|
|
2019-11-07 16:24:34 +01:00
|
|
|
#if defined(HAVE_FUTIMES) || defined(HAVE_FUTIMESAT)
|
2012-10-30 11:44:10 +01:00
|
|
|
if (!atime->QuadPart || !mtime->QuadPart)
|
|
|
|
{
|
|
|
|
|
|
|
|
tv[0].tv_sec = tv[0].tv_usec = 0;
|
|
|
|
tv[1].tv_sec = tv[1].tv_usec = 0;
|
|
|
|
if (!fstat( fd, &st ))
|
|
|
|
{
|
|
|
|
tv[0].tv_sec = st.st_atime;
|
|
|
|
tv[1].tv_sec = st.st_mtime;
|
|
|
|
#ifdef HAVE_STRUCT_STAT_ST_ATIM
|
|
|
|
tv[0].tv_usec = st.st_atim.tv_nsec / 1000;
|
2012-11-30 05:50:45 +01:00
|
|
|
#elif defined(HAVE_STRUCT_STAT_ST_ATIMESPEC)
|
|
|
|
tv[0].tv_usec = st.st_atimespec.tv_nsec / 1000;
|
2012-10-30 11:44:10 +01:00
|
|
|
#endif
|
|
|
|
#ifdef HAVE_STRUCT_STAT_ST_MTIM
|
|
|
|
tv[1].tv_usec = st.st_mtim.tv_nsec / 1000;
|
2012-11-30 05:50:45 +01:00
|
|
|
#elif defined(HAVE_STRUCT_STAT_ST_MTIMESPEC)
|
|
|
|
tv[1].tv_usec = st.st_mtimespec.tv_nsec / 1000;
|
2012-10-30 11:44:10 +01:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (atime->QuadPart)
|
|
|
|
{
|
|
|
|
tv[0].tv_sec = atime->QuadPart / 10000000 - SECS_1601_TO_1970;
|
|
|
|
tv[0].tv_usec = (atime->QuadPart % 10000000) / 10;
|
|
|
|
}
|
|
|
|
if (mtime->QuadPart)
|
|
|
|
{
|
|
|
|
tv[1].tv_sec = mtime->QuadPart / 10000000 - SECS_1601_TO_1970;
|
|
|
|
tv[1].tv_usec = (mtime->QuadPart % 10000000) / 10;
|
|
|
|
}
|
2012-10-30 11:50:42 +01:00
|
|
|
#ifdef HAVE_FUTIMES
|
|
|
|
if (futimes( fd, tv ) == -1) status = FILE_GetNtStatus();
|
|
|
|
#elif defined(HAVE_FUTIMESAT)
|
|
|
|
if (futimesat( fd, NULL, tv ) == -1) status = FILE_GetNtStatus();
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#else /* HAVE_FUTIMES || HAVE_FUTIMESAT */
|
|
|
|
FIXME( "setting file times not supported\n" );
|
|
|
|
status = STATUS_NOT_IMPLEMENTED;
|
|
|
|
#endif
|
|
|
|
return status;
|
2012-10-30 11:44:10 +01:00
|
|
|
}
|
|
|
|
|
2009-11-18 17:23:55 +01:00
|
|
|
static inline void get_file_times( const struct stat *st, LARGE_INTEGER *mtime, LARGE_INTEGER *ctime,
|
|
|
|
LARGE_INTEGER *atime, LARGE_INTEGER *creation )
|
|
|
|
{
|
|
|
|
RtlSecondsSince1970ToTime( st->st_mtime, mtime );
|
|
|
|
RtlSecondsSince1970ToTime( st->st_ctime, ctime );
|
|
|
|
RtlSecondsSince1970ToTime( st->st_atime, atime );
|
|
|
|
#ifdef HAVE_STRUCT_STAT_ST_MTIM
|
|
|
|
mtime->QuadPart += st->st_mtim.tv_nsec / 100;
|
2012-11-30 05:50:45 +01:00
|
|
|
#elif defined(HAVE_STRUCT_STAT_ST_MTIMESPEC)
|
|
|
|
mtime->QuadPart += st->st_mtimespec.tv_nsec / 100;
|
2009-11-18 17:23:55 +01:00
|
|
|
#endif
|
|
|
|
#ifdef HAVE_STRUCT_STAT_ST_CTIM
|
|
|
|
ctime->QuadPart += st->st_ctim.tv_nsec / 100;
|
2012-11-30 05:50:45 +01:00
|
|
|
#elif defined(HAVE_STRUCT_STAT_ST_CTIMESPEC)
|
|
|
|
ctime->QuadPart += st->st_ctimespec.tv_nsec / 100;
|
2009-11-18 17:23:55 +01:00
|
|
|
#endif
|
|
|
|
#ifdef HAVE_STRUCT_STAT_ST_ATIM
|
|
|
|
atime->QuadPart += st->st_atim.tv_nsec / 100;
|
2012-11-30 05:50:45 +01:00
|
|
|
#elif defined(HAVE_STRUCT_STAT_ST_ATIMESPEC)
|
|
|
|
atime->QuadPart += st->st_atimespec.tv_nsec / 100;
|
2009-11-18 17:23:55 +01:00
|
|
|
#endif
|
2012-11-30 05:50:46 +01:00
|
|
|
#ifdef HAVE_STRUCT_STAT_ST_BIRTHTIME
|
|
|
|
RtlSecondsSince1970ToTime( st->st_birthtime, creation );
|
|
|
|
#ifdef HAVE_STRUCT_STAT_ST_BIRTHTIM
|
|
|
|
creation->QuadPart += st->st_birthtim.tv_nsec / 100;
|
|
|
|
#elif defined(HAVE_STRUCT_STAT_ST_BIRTHTIMESPEC)
|
|
|
|
creation->QuadPart += st->st_birthtimespec.tv_nsec / 100;
|
|
|
|
#endif
|
|
|
|
#elif defined(HAVE_STRUCT_STAT___ST_BIRTHTIME)
|
|
|
|
RtlSecondsSince1970ToTime( st->__st_birthtime, creation );
|
|
|
|
#ifdef HAVE_STRUCT_STAT___ST_BIRTHTIM
|
|
|
|
creation->QuadPart += st->__st_birthtim.tv_nsec / 100;
|
|
|
|
#endif
|
|
|
|
#else
|
2009-11-18 17:23:55 +01:00
|
|
|
*creation = *mtime;
|
2012-11-30 05:50:46 +01:00
|
|
|
#endif
|
2009-11-18 17:23:55 +01:00
|
|
|
}
|
|
|
|
|
2014-08-20 04:31:00 +02:00
|
|
|
/* fill in the file information that depends on the stat and attribute info */
|
|
|
|
NTSTATUS fill_file_info( const struct stat *st, ULONG attr, void *ptr,
|
|
|
|
FILE_INFORMATION_CLASS class )
|
2009-11-18 17:01:15 +01:00
|
|
|
{
|
|
|
|
switch (class)
|
|
|
|
{
|
|
|
|
case FileBasicInformation:
|
|
|
|
{
|
|
|
|
FILE_BASIC_INFORMATION *info = ptr;
|
|
|
|
|
2009-11-18 17:23:55 +01:00
|
|
|
get_file_times( st, &info->LastWriteTime, &info->ChangeTime,
|
|
|
|
&info->LastAccessTime, &info->CreationTime );
|
2014-08-20 04:31:00 +02:00
|
|
|
info->FileAttributes = attr;
|
2009-11-18 17:01:15 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case FileStandardInformation:
|
|
|
|
{
|
|
|
|
FILE_STANDARD_INFORMATION *info = ptr;
|
|
|
|
|
|
|
|
if ((info->Directory = S_ISDIR(st->st_mode)))
|
|
|
|
{
|
|
|
|
info->AllocationSize.QuadPart = 0;
|
|
|
|
info->EndOfFile.QuadPart = 0;
|
|
|
|
info->NumberOfLinks = 1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
info->AllocationSize.QuadPart = (ULONGLONG)st->st_blocks * 512;
|
|
|
|
info->EndOfFile.QuadPart = st->st_size;
|
|
|
|
info->NumberOfLinks = st->st_nlink;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case FileInternalInformation:
|
|
|
|
{
|
|
|
|
FILE_INTERNAL_INFORMATION *info = ptr;
|
|
|
|
info->IndexNumber.QuadPart = st->st_ino;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case FileEndOfFileInformation:
|
|
|
|
{
|
|
|
|
FILE_END_OF_FILE_INFORMATION *info = ptr;
|
|
|
|
info->EndOfFile.QuadPart = S_ISDIR(st->st_mode) ? 0 : st->st_size;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case FileAllInformation:
|
|
|
|
{
|
|
|
|
FILE_ALL_INFORMATION *info = ptr;
|
2014-08-20 04:31:00 +02:00
|
|
|
fill_file_info( st, attr, &info->BasicInformation, FileBasicInformation );
|
|
|
|
fill_file_info( st, attr, &info->StandardInformation, FileStandardInformation );
|
|
|
|
fill_file_info( st, attr, &info->InternalInformation, FileInternalInformation );
|
2009-11-18 17:01:15 +01:00
|
|
|
}
|
|
|
|
break;
|
2009-11-18 17:23:55 +01:00
|
|
|
/* all directory structures start with the FileDirectoryInformation layout */
|
|
|
|
case FileBothDirectoryInformation:
|
|
|
|
case FileFullDirectoryInformation:
|
|
|
|
case FileDirectoryInformation:
|
|
|
|
{
|
|
|
|
FILE_DIRECTORY_INFORMATION *info = ptr;
|
|
|
|
|
|
|
|
get_file_times( st, &info->LastWriteTime, &info->ChangeTime,
|
|
|
|
&info->LastAccessTime, &info->CreationTime );
|
|
|
|
if (S_ISDIR(st->st_mode))
|
|
|
|
{
|
|
|
|
info->AllocationSize.QuadPart = 0;
|
|
|
|
info->EndOfFile.QuadPart = 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
info->AllocationSize.QuadPart = (ULONGLONG)st->st_blocks * 512;
|
|
|
|
info->EndOfFile.QuadPart = st->st_size;
|
|
|
|
}
|
2014-08-20 04:31:00 +02:00
|
|
|
info->FileAttributes = attr;
|
2009-11-18 17:23:55 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case FileIdFullDirectoryInformation:
|
|
|
|
{
|
|
|
|
FILE_ID_FULL_DIRECTORY_INFORMATION *info = ptr;
|
|
|
|
info->FileId.QuadPart = st->st_ino;
|
2014-08-20 04:31:00 +02:00
|
|
|
fill_file_info( st, attr, info, FileDirectoryInformation );
|
2009-11-18 17:23:55 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case FileIdBothDirectoryInformation:
|
|
|
|
{
|
|
|
|
FILE_ID_BOTH_DIRECTORY_INFORMATION *info = ptr;
|
|
|
|
info->FileId.QuadPart = st->st_ino;
|
2014-08-20 04:31:00 +02:00
|
|
|
fill_file_info( st, attr, info, FileDirectoryInformation );
|
2009-11-18 17:23:55 +01:00
|
|
|
}
|
|
|
|
break;
|
2016-05-04 09:05:35 +02:00
|
|
|
case FileIdGlobalTxDirectoryInformation:
|
|
|
|
{
|
|
|
|
FILE_ID_GLOBAL_TX_DIR_INFORMATION *info = ptr;
|
|
|
|
info->FileId.QuadPart = st->st_ino;
|
|
|
|
fill_file_info( st, attr, info, FileDirectoryInformation );
|
|
|
|
}
|
|
|
|
break;
|
2009-11-18 17:01:15 +01:00
|
|
|
|
|
|
|
default:
|
|
|
|
return STATUS_INVALID_INFO_CLASS;
|
|
|
|
}
|
|
|
|
return STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2010-01-08 13:16:57 +01:00
|
|
|
NTSTATUS server_get_unix_name( HANDLE handle, ANSI_STRING *unix_name )
|
2009-11-12 15:10:13 +01:00
|
|
|
{
|
|
|
|
data_size_t size = 1024;
|
|
|
|
NTSTATUS ret;
|
|
|
|
char *name;
|
|
|
|
|
|
|
|
for (;;)
|
|
|
|
{
|
|
|
|
name = RtlAllocateHeap( GetProcessHeap(), 0, size + 1 );
|
|
|
|
if (!name) return STATUS_NO_MEMORY;
|
|
|
|
unix_name->MaximumLength = size + 1;
|
|
|
|
|
|
|
|
SERVER_START_REQ( get_handle_unix_name )
|
|
|
|
{
|
|
|
|
req->handle = wine_server_obj_handle( handle );
|
|
|
|
wine_server_set_reply( req, name, size );
|
|
|
|
ret = wine_server_call( req );
|
|
|
|
size = reply->name_len;
|
|
|
|
}
|
|
|
|
SERVER_END_REQ;
|
|
|
|
|
|
|
|
if (!ret)
|
|
|
|
{
|
|
|
|
name[size] = 0;
|
|
|
|
unix_name->Buffer = name;
|
|
|
|
unix_name->Length = size;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
RtlFreeHeap( GetProcessHeap(), 0, name );
|
|
|
|
if (ret != STATUS_BUFFER_OVERFLOW) break;
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2009-12-01 11:27:45 +01:00
|
|
|
static NTSTATUS fill_name_info( const ANSI_STRING *unix_name, FILE_NAME_INFORMATION *info, LONG *name_len )
|
|
|
|
{
|
|
|
|
UNICODE_STRING nt_name;
|
|
|
|
NTSTATUS status;
|
|
|
|
|
|
|
|
if (!(status = wine_unix_to_nt_file_name( unix_name, &nt_name )))
|
|
|
|
{
|
|
|
|
const WCHAR *ptr = nt_name.Buffer;
|
|
|
|
const WCHAR *end = ptr + (nt_name.Length / sizeof(WCHAR));
|
|
|
|
|
|
|
|
/* Skip the volume mount point. */
|
|
|
|
while (ptr != end && *ptr == '\\') ++ptr;
|
|
|
|
while (ptr != end && *ptr != '\\') ++ptr;
|
|
|
|
while (ptr != end && *ptr == '\\') ++ptr;
|
|
|
|
while (ptr != end && *ptr != '\\') ++ptr;
|
|
|
|
|
|
|
|
info->FileNameLength = (end - ptr) * sizeof(WCHAR);
|
|
|
|
if (*name_len < info->FileNameLength) status = STATUS_BUFFER_OVERFLOW;
|
|
|
|
else *name_len = info->FileNameLength;
|
|
|
|
|
|
|
|
memcpy( info->FileName, ptr, *name_len );
|
|
|
|
RtlFreeUnicodeString( &nt_name );
|
|
|
|
}
|
|
|
|
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
2017-12-21 16:12:01 +01:00
|
|
|
static NTSTATUS server_get_file_info( HANDLE handle, IO_STATUS_BLOCK *io, void *buffer,
|
|
|
|
ULONG length, FILE_INFORMATION_CLASS info_class )
|
|
|
|
{
|
|
|
|
SERVER_START_REQ( get_file_info )
|
|
|
|
{
|
|
|
|
req->handle = wine_server_obj_handle( handle );
|
|
|
|
req->info_class = info_class;
|
|
|
|
wine_server_set_reply( req, buffer, length );
|
|
|
|
io->u.Status = wine_server_call( req );
|
|
|
|
io->Information = wine_server_reply_size( reply );
|
|
|
|
}
|
|
|
|
SERVER_END_REQ;
|
2018-10-23 17:45:06 +02:00
|
|
|
if (io->u.Status == STATUS_NOT_IMPLEMENTED)
|
2018-10-15 13:40:36 +02:00
|
|
|
FIXME( "Unsupported info class %x\n", info_class );
|
2017-12-21 16:12:01 +01:00
|
|
|
return io->u.Status;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2020-04-08 23:06:04 +02:00
|
|
|
/* Find a DOS device which can act as the root of "path".
|
|
|
|
* Similar to find_drive_root(), but returns -1 instead of crossing volumes. */
|
|
|
|
static int find_dos_device( const char *path )
|
|
|
|
{
|
|
|
|
int len = strlen(path);
|
|
|
|
int drive;
|
|
|
|
char *buffer;
|
|
|
|
struct stat st;
|
|
|
|
struct drive_info info[MAX_DOS_DRIVES];
|
|
|
|
dev_t dev_id;
|
|
|
|
|
|
|
|
if (!DIR_get_drives_info( info )) return -1;
|
|
|
|
|
|
|
|
if (stat( path, &st ) < 0) return -1;
|
|
|
|
dev_id = st.st_dev;
|
|
|
|
|
|
|
|
/* strip off trailing slashes */
|
|
|
|
while (len > 1 && path[len - 1] == '/') len--;
|
|
|
|
|
|
|
|
/* make a copy of the path */
|
|
|
|
if (!(buffer = RtlAllocateHeap( GetProcessHeap(), 0, len + 1 ))) return -1;
|
|
|
|
memcpy( buffer, path, len );
|
|
|
|
buffer[len] = 0;
|
|
|
|
|
|
|
|
for (;;)
|
|
|
|
{
|
|
|
|
if (!stat( buffer, &st ) && S_ISDIR( st.st_mode ))
|
|
|
|
{
|
|
|
|
if (st.st_dev != dev_id) break;
|
|
|
|
|
|
|
|
for (drive = 0; drive < MAX_DOS_DRIVES; drive++)
|
|
|
|
{
|
|
|
|
if ((info[drive].dev == st.st_dev) && (info[drive].ino == st.st_ino))
|
|
|
|
{
|
|
|
|
if (len == 1) len = 0; /* preserve root slash in returned path */
|
|
|
|
TRACE( "%s -> drive %c:, root=%s, name=%s\n",
|
|
|
|
debugstr_a(path), 'A' + drive, debugstr_a(buffer), debugstr_a(path + len));
|
|
|
|
RtlFreeHeap( GetProcessHeap(), 0, buffer );
|
|
|
|
return drive;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (len <= 1) break; /* reached root */
|
|
|
|
while (path[len - 1] != '/') len--;
|
|
|
|
while (path[len - 1] == '/') len--;
|
|
|
|
buffer[len] = 0;
|
|
|
|
}
|
|
|
|
RtlFreeHeap( GetProcessHeap(), 0, buffer );
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct mountmgr_unix_drive *get_mountmgr_fs_info( HANDLE handle, int fd )
|
|
|
|
{
|
|
|
|
struct mountmgr_unix_drive *drive;
|
|
|
|
OBJECT_ATTRIBUTES attr;
|
|
|
|
UNICODE_STRING string;
|
|
|
|
ANSI_STRING unix_name;
|
|
|
|
IO_STATUS_BLOCK io;
|
|
|
|
HANDLE mountmgr;
|
|
|
|
NTSTATUS status;
|
|
|
|
int letter;
|
|
|
|
|
|
|
|
if (server_get_unix_name( handle, &unix_name ))
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
letter = find_dos_device( unix_name.Buffer );
|
|
|
|
RtlFreeAnsiString( &unix_name );
|
|
|
|
|
|
|
|
if (!(drive = RtlAllocateHeap( GetProcessHeap(), 0, 1024 )))
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
if (letter == -1)
|
|
|
|
{
|
|
|
|
struct stat st;
|
|
|
|
|
|
|
|
if (fstat( fd, &st ) == -1)
|
|
|
|
{
|
|
|
|
RtlFreeHeap( GetProcessHeap(), 0, drive );
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
drive->unix_dev = st.st_dev;
|
|
|
|
drive->letter = 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
drive->letter = 'a' + letter;
|
|
|
|
|
|
|
|
RtlInitUnicodeString( &string, MOUNTMGR_DEVICE_NAME );
|
|
|
|
InitializeObjectAttributes( &attr, &string, 0, NULL, NULL );
|
|
|
|
if (NtOpenFile( &mountmgr, GENERIC_READ | SYNCHRONIZE, &attr, &io,
|
|
|
|
FILE_SHARE_READ | FILE_SHARE_WRITE, FILE_SYNCHRONOUS_IO_NONALERT ))
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
status = NtDeviceIoControlFile( mountmgr, NULL, NULL, NULL, &io, IOCTL_MOUNTMGR_QUERY_UNIX_DRIVE,
|
|
|
|
drive, sizeof(*drive), drive, 1024 );
|
|
|
|
if (status == STATUS_BUFFER_OVERFLOW)
|
|
|
|
{
|
|
|
|
if (!(drive = RtlReAllocateHeap( GetProcessHeap(), 0, drive, drive->size )))
|
|
|
|
{
|
|
|
|
RtlFreeHeap( GetProcessHeap(), 0, drive );
|
|
|
|
NtClose( mountmgr );
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
status = NtDeviceIoControlFile( mountmgr, NULL, NULL, NULL, &io, IOCTL_MOUNTMGR_QUERY_UNIX_DRIVE,
|
|
|
|
drive, sizeof(*drive), drive, drive->size );
|
|
|
|
}
|
|
|
|
NtClose( mountmgr );
|
|
|
|
|
|
|
|
if (status)
|
|
|
|
{
|
|
|
|
WARN("failed to retrieve filesystem type from mountmgr, status %#x\n", status);
|
|
|
|
RtlFreeHeap( GetProcessHeap(), 0, drive );
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return drive;
|
|
|
|
}
|
|
|
|
|
1999-03-09 18:47:51 +01:00
|
|
|
/******************************************************************************
|
2001-06-21 01:03:14 +02:00
|
|
|
* NtQueryInformationFile [NTDLL.@]
|
2001-07-11 20:56:41 +02:00
|
|
|
* ZwQueryInformationFile [NTDLL.@]
|
2003-07-19 00:55:28 +02:00
|
|
|
*
|
|
|
|
* Get information about an open file handle.
|
|
|
|
*
|
|
|
|
* PARAMS
|
2004-04-08 06:39:59 +02:00
|
|
|
* hFile [I] Handle returned from ZwOpenFile() or ZwCreateFile()
|
|
|
|
* io [O] Receives information about the operation on return
|
|
|
|
* ptr [O] Destination for file information
|
|
|
|
* len [I] Size of FileInformation
|
|
|
|
* class [I] Type of file information to get
|
2003-07-19 00:55:28 +02:00
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Success: 0. IoStatusBlock and FileInformation are updated.
|
|
|
|
* Failure: An NTSTATUS error code describing the error.
|
1999-03-09 18:47:51 +01:00
|
|
|
*/
|
2004-04-08 06:39:59 +02:00
|
|
|
NTSTATUS WINAPI NtQueryInformationFile( HANDLE hFile, PIO_STATUS_BLOCK io,
|
|
|
|
PVOID ptr, LONG len, FILE_INFORMATION_CLASS class )
|
1999-03-09 18:47:51 +01:00
|
|
|
{
|
2004-04-30 23:03:09 +02:00
|
|
|
static const size_t info_sizes[] =
|
|
|
|
{
|
|
|
|
0,
|
|
|
|
sizeof(FILE_DIRECTORY_INFORMATION), /* FileDirectoryInformation */
|
|
|
|
sizeof(FILE_FULL_DIRECTORY_INFORMATION), /* FileFullDirectoryInformation */
|
|
|
|
sizeof(FILE_BOTH_DIRECTORY_INFORMATION), /* FileBothDirectoryInformation */
|
|
|
|
sizeof(FILE_BASIC_INFORMATION), /* FileBasicInformation */
|
|
|
|
sizeof(FILE_STANDARD_INFORMATION), /* FileStandardInformation */
|
|
|
|
sizeof(FILE_INTERNAL_INFORMATION), /* FileInternalInformation */
|
|
|
|
sizeof(FILE_EA_INFORMATION), /* FileEaInformation */
|
2018-10-23 17:45:21 +02:00
|
|
|
0, /* FileAccessInformation */
|
2009-11-12 15:10:15 +01:00
|
|
|
sizeof(FILE_NAME_INFORMATION), /* FileNameInformation */
|
2004-04-30 23:03:09 +02:00
|
|
|
sizeof(FILE_RENAME_INFORMATION)-sizeof(WCHAR), /* FileRenameInformation */
|
|
|
|
0, /* FileLinkInformation */
|
|
|
|
sizeof(FILE_NAMES_INFORMATION)-sizeof(WCHAR), /* FileNamesInformation */
|
|
|
|
sizeof(FILE_DISPOSITION_INFORMATION), /* FileDispositionInformation */
|
|
|
|
sizeof(FILE_POSITION_INFORMATION), /* FilePositionInformation */
|
|
|
|
sizeof(FILE_FULL_EA_INFORMATION), /* FileFullEaInformation */
|
2018-10-29 15:48:30 +01:00
|
|
|
0, /* FileModeInformation */
|
2004-04-30 23:03:09 +02:00
|
|
|
sizeof(FILE_ALIGNMENT_INFORMATION), /* FileAlignmentInformation */
|
2009-12-01 11:27:44 +01:00
|
|
|
sizeof(FILE_ALL_INFORMATION), /* FileAllInformation */
|
2004-04-30 23:03:09 +02:00
|
|
|
sizeof(FILE_ALLOCATION_INFORMATION), /* FileAllocationInformation */
|
|
|
|
sizeof(FILE_END_OF_FILE_INFORMATION), /* FileEndOfFileInformation */
|
|
|
|
0, /* FileAlternateNameInformation */
|
|
|
|
sizeof(FILE_STREAM_INFORMATION)-sizeof(WCHAR), /* FileStreamInformation */
|
2014-08-11 16:22:02 +02:00
|
|
|
sizeof(FILE_PIPE_INFORMATION), /* FilePipeInformation */
|
2006-05-26 12:10:11 +02:00
|
|
|
sizeof(FILE_PIPE_LOCAL_INFORMATION), /* FilePipeLocalInformation */
|
2004-04-30 23:03:09 +02:00
|
|
|
0, /* FilePipeRemoteInformation */
|
2005-04-11 16:20:49 +02:00
|
|
|
sizeof(FILE_MAILSLOT_QUERY_INFORMATION), /* FileMailslotQueryInformation */
|
2004-04-30 23:03:09 +02:00
|
|
|
0, /* FileMailslotSetInformation */
|
|
|
|
0, /* FileCompressionInformation */
|
|
|
|
0, /* FileObjectIdInformation */
|
|
|
|
0, /* FileCompletionInformation */
|
|
|
|
0, /* FileMoveClusterInformation */
|
|
|
|
0, /* FileQuotaInformation */
|
|
|
|
0, /* FileReparsePointInformation */
|
2015-03-09 22:17:08 +01:00
|
|
|
sizeof(FILE_NETWORK_OPEN_INFORMATION), /* FileNetworkOpenInformation */
|
2019-09-26 20:34:33 +02:00
|
|
|
sizeof(FILE_ATTRIBUTE_TAG_INFORMATION), /* FileAttributeTagInformation */
|
2009-11-18 15:15:32 +01:00
|
|
|
0, /* FileTrackingInformation */
|
|
|
|
0, /* FileIdBothDirectoryInformation */
|
|
|
|
0, /* FileIdFullDirectoryInformation */
|
|
|
|
0, /* FileValidDataLengthInformation */
|
|
|
|
0, /* FileShortNameInformation */
|
2015-02-26 05:27:14 +01:00
|
|
|
0, /* FileIoCompletionNotificationInformation, */
|
|
|
|
0, /* FileIoStatusBlockRangeInformation */
|
|
|
|
0, /* FileIoPriorityHintInformation */
|
2009-11-18 15:15:32 +01:00
|
|
|
0, /* FileSfioReserveInformation */
|
|
|
|
0, /* FileSfioVolumeInformation */
|
|
|
|
0, /* FileHardLinkInformation */
|
2015-02-26 05:27:14 +01:00
|
|
|
0, /* FileProcessIdsUsingFileInformation */
|
2009-11-18 15:15:32 +01:00
|
|
|
0, /* FileNormalizedNameInformation */
|
2015-02-26 05:27:14 +01:00
|
|
|
0, /* FileNetworkPhysicalNameInformation */
|
2009-11-18 15:15:32 +01:00
|
|
|
0, /* FileIdGlobalTxDirectoryInformation */
|
2015-02-26 05:27:14 +01:00
|
|
|
0, /* FileIsRemoteDeviceInformation */
|
|
|
|
0, /* FileAttributeCacheInformation */
|
|
|
|
0, /* FileNumaNodeInformation */
|
|
|
|
0, /* FileStandardLinkInformation */
|
|
|
|
0, /* FileRemoteProtocolInformation */
|
2017-02-07 16:11:00 +01:00
|
|
|
0, /* FileRenameInformationBypassAccessCheck */
|
|
|
|
0, /* FileLinkInformationBypassAccessCheck */
|
|
|
|
0, /* FileVolumeNameInformation */
|
2017-02-16 18:17:51 +01:00
|
|
|
sizeof(FILE_ID_INFORMATION), /* FileIdInformation */
|
2017-02-07 16:11:00 +01:00
|
|
|
0, /* FileIdExtdDirectoryInformation */
|
2015-02-26 05:27:14 +01:00
|
|
|
0, /* FileReplaceCompletionInformation */
|
2017-02-07 16:11:00 +01:00
|
|
|
0, /* FileHardLinkFullIdInformation */
|
|
|
|
0, /* FileIdExtdBothDirectoryInformation */
|
2004-04-30 23:03:09 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
struct stat st;
|
2007-02-08 20:20:34 +01:00
|
|
|
int fd, needs_close = FALSE;
|
2014-08-20 04:31:00 +02:00
|
|
|
ULONG attr;
|
2020-03-20 18:15:26 +01:00
|
|
|
unsigned int options;
|
2004-04-08 06:39:59 +02:00
|
|
|
|
2006-10-16 13:49:06 +02:00
|
|
|
TRACE("(%p,%p,%p,0x%08x,0x%08x)\n", hFile, io, ptr, len, class);
|
2003-06-24 04:32:01 +02:00
|
|
|
|
2004-04-08 06:39:59 +02:00
|
|
|
io->Information = 0;
|
2004-04-30 23:03:09 +02:00
|
|
|
|
|
|
|
if (class <= 0 || class >= FileMaximumInformation)
|
|
|
|
return io->u.Status = STATUS_INVALID_INFO_CLASS;
|
|
|
|
if (!info_sizes[class])
|
2018-10-23 17:45:06 +02:00
|
|
|
return server_get_file_info( hFile, io, ptr, len, class );
|
2004-04-30 23:03:09 +02:00
|
|
|
if (len < info_sizes[class])
|
|
|
|
return io->u.Status = STATUS_INFO_LENGTH_MISMATCH;
|
|
|
|
|
2020-05-29 15:35:16 +02:00
|
|
|
if ((io->u.Status = unix_funcs->server_get_unix_fd( hFile, 0, &fd, &needs_close, NULL, &options )))
|
2006-05-26 12:10:11 +02:00
|
|
|
{
|
2018-10-23 17:45:21 +02:00
|
|
|
if (io->u.Status != STATUS_BAD_DEVICE_TYPE) return io->u.Status;
|
|
|
|
return server_get_file_info( hFile, io, ptr, len, class );
|
2006-11-03 11:38:44 +01:00
|
|
|
}
|
2003-06-24 04:32:01 +02:00
|
|
|
|
|
|
|
switch (class)
|
|
|
|
{
|
|
|
|
case FileBasicInformation:
|
2020-03-20 18:15:26 +01:00
|
|
|
if (fd_get_file_info( fd, options, &st, &attr ) == -1)
|
2009-11-18 17:01:15 +01:00
|
|
|
io->u.Status = FILE_GetNtStatus();
|
|
|
|
else if (!S_ISREG(st.st_mode) && !S_ISDIR(st.st_mode))
|
|
|
|
io->u.Status = STATUS_INVALID_INFO_CLASS;
|
|
|
|
else
|
2014-08-20 04:31:00 +02:00
|
|
|
fill_file_info( &st, attr, ptr, class );
|
2003-06-24 04:32:01 +02:00
|
|
|
break;
|
|
|
|
case FileStandardInformation:
|
|
|
|
{
|
2004-04-08 06:39:59 +02:00
|
|
|
FILE_STANDARD_INFORMATION *info = ptr;
|
2003-06-24 04:32:01 +02:00
|
|
|
|
2020-03-20 18:15:26 +01:00
|
|
|
if (fd_get_file_info( fd, options, &st, &attr ) == -1) io->u.Status = FILE_GetNtStatus();
|
2004-04-08 06:39:59 +02:00
|
|
|
else
|
2003-06-24 04:32:01 +02:00
|
|
|
{
|
2014-08-20 04:31:00 +02:00
|
|
|
fill_file_info( &st, attr, info, class );
|
2009-11-18 17:01:15 +01:00
|
|
|
info->DeletePending = FALSE; /* FIXME */
|
2003-06-24 04:32:01 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case FilePositionInformation:
|
|
|
|
{
|
2004-04-08 06:39:59 +02:00
|
|
|
FILE_POSITION_INFORMATION *info = ptr;
|
2004-04-30 23:03:09 +02:00
|
|
|
off_t res = lseek( fd, 0, SEEK_CUR );
|
|
|
|
if (res == (off_t)-1) io->u.Status = FILE_GetNtStatus();
|
|
|
|
else info->CurrentByteOffset.QuadPart = res;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case FileInternalInformation:
|
2020-03-20 18:15:26 +01:00
|
|
|
if (fd_get_file_info( fd, options, &st, &attr ) == -1) io->u.Status = FILE_GetNtStatus();
|
2014-08-20 04:31:00 +02:00
|
|
|
else fill_file_info( &st, attr, ptr, class );
|
2004-04-30 23:03:09 +02:00
|
|
|
break;
|
|
|
|
case FileEaInformation:
|
|
|
|
{
|
|
|
|
FILE_EA_INFORMATION *info = ptr;
|
|
|
|
info->EaSize = 0;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case FileEndOfFileInformation:
|
2020-03-20 18:15:26 +01:00
|
|
|
if (fd_get_file_info( fd, options, &st, &attr ) == -1) io->u.Status = FILE_GetNtStatus();
|
2014-08-20 04:31:00 +02:00
|
|
|
else fill_file_info( &st, attr, ptr, class );
|
2004-04-30 23:03:09 +02:00
|
|
|
break;
|
|
|
|
case FileAllInformation:
|
|
|
|
{
|
|
|
|
FILE_ALL_INFORMATION *info = ptr;
|
2009-12-01 11:27:45 +01:00
|
|
|
ANSI_STRING unix_name;
|
2004-04-30 23:03:09 +02:00
|
|
|
|
2020-03-20 18:15:26 +01:00
|
|
|
if (fd_get_file_info( fd, options, &st, &attr ) == -1) io->u.Status = FILE_GetNtStatus();
|
2004-04-30 23:03:09 +02:00
|
|
|
else if (!S_ISREG(st.st_mode) && !S_ISDIR(st.st_mode))
|
|
|
|
io->u.Status = STATUS_INVALID_INFO_CLASS;
|
2009-12-01 11:27:45 +01:00
|
|
|
else if (!(io->u.Status = server_get_unix_name( hFile, &unix_name )))
|
2003-06-24 04:32:01 +02:00
|
|
|
{
|
2009-12-01 11:27:45 +01:00
|
|
|
LONG name_len = len - FIELD_OFFSET(FILE_ALL_INFORMATION, NameInformation.FileName);
|
|
|
|
|
2014-08-20 04:31:00 +02:00
|
|
|
fill_file_info( &st, attr, info, FileAllInformation );
|
2009-11-18 17:01:15 +01:00
|
|
|
info->StandardInformation.DeletePending = FALSE; /* FIXME */
|
2004-04-30 23:03:09 +02:00
|
|
|
info->EaInformation.EaSize = 0;
|
|
|
|
info->AccessInformation.AccessFlags = 0; /* FIXME */
|
|
|
|
info->PositionInformation.CurrentByteOffset.QuadPart = lseek( fd, 0, SEEK_CUR );
|
|
|
|
info->ModeInformation.Mode = 0; /* FIXME */
|
|
|
|
info->AlignmentInformation.AlignmentRequirement = 1; /* FIXME */
|
2009-12-01 11:27:45 +01:00
|
|
|
|
|
|
|
io->u.Status = fill_name_info( &unix_name, &info->NameInformation, &name_len );
|
|
|
|
RtlFreeAnsiString( &unix_name );
|
|
|
|
io->Information = FIELD_OFFSET(FILE_ALL_INFORMATION, NameInformation.FileName) + name_len;
|
2003-06-24 04:32:01 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2005-04-11 16:20:49 +02:00
|
|
|
case FileMailslotQueryInformation:
|
|
|
|
{
|
|
|
|
FILE_MAILSLOT_QUERY_INFORMATION *info = ptr;
|
|
|
|
|
|
|
|
SERVER_START_REQ( set_mailslot_info )
|
|
|
|
{
|
2008-12-08 16:05:17 +01:00
|
|
|
req->handle = wine_server_obj_handle( hFile );
|
2005-04-11 16:20:49 +02:00
|
|
|
req->flags = 0;
|
|
|
|
io->u.Status = wine_server_call( req );
|
|
|
|
if( io->u.Status == STATUS_SUCCESS )
|
|
|
|
{
|
|
|
|
info->MaximumMessageSize = reply->max_msgsize;
|
|
|
|
info->MailslotQuota = 0;
|
2006-11-03 17:53:04 +01:00
|
|
|
info->NextMessageSize = 0;
|
|
|
|
info->MessagesAvailable = 0;
|
2007-04-17 20:08:59 +02:00
|
|
|
info->ReadTimeout.QuadPart = reply->read_timeout;
|
2005-04-11 16:20:49 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
SERVER_END_REQ;
|
2006-11-03 17:53:04 +01:00
|
|
|
if (!io->u.Status)
|
|
|
|
{
|
2007-05-22 11:59:36 +02:00
|
|
|
char *tmpbuf;
|
2006-11-03 17:53:04 +01:00
|
|
|
ULONG size = info->MaximumMessageSize ? info->MaximumMessageSize : 0x10000;
|
2007-05-22 11:59:36 +02:00
|
|
|
if (size > 0x10000) size = 0x10000;
|
|
|
|
if ((tmpbuf = RtlAllocateHeap( GetProcessHeap(), 0, size )))
|
2006-11-03 17:53:04 +01:00
|
|
|
{
|
2020-05-29 15:35:16 +02:00
|
|
|
if (!unix_funcs->server_get_unix_fd( hFile, FILE_READ_DATA, &fd, &needs_close, NULL, NULL ))
|
2006-11-03 17:53:04 +01:00
|
|
|
{
|
|
|
|
int res = recv( fd, tmpbuf, size, MSG_PEEK );
|
|
|
|
info->MessagesAvailable = (res > 0);
|
|
|
|
info->NextMessageSize = (res >= 0) ? res : MAILSLOT_NO_MESSAGE;
|
|
|
|
if (needs_close) close( fd );
|
|
|
|
}
|
|
|
|
RtlFreeHeap( GetProcessHeap(), 0, tmpbuf );
|
|
|
|
}
|
|
|
|
}
|
2005-04-11 16:20:49 +02:00
|
|
|
}
|
|
|
|
break;
|
2009-11-12 15:10:13 +01:00
|
|
|
case FileNameInformation:
|
|
|
|
{
|
|
|
|
FILE_NAME_INFORMATION *info = ptr;
|
|
|
|
ANSI_STRING unix_name;
|
|
|
|
|
|
|
|
if (!(io->u.Status = server_get_unix_name( hFile, &unix_name )))
|
|
|
|
{
|
|
|
|
LONG name_len = len - FIELD_OFFSET(FILE_NAME_INFORMATION, FileName);
|
2009-12-01 11:27:45 +01:00
|
|
|
io->u.Status = fill_name_info( &unix_name, info, &name_len );
|
2009-11-12 15:10:13 +01:00
|
|
|
RtlFreeAnsiString( &unix_name );
|
2009-12-01 11:27:45 +01:00
|
|
|
io->Information = FIELD_OFFSET(FILE_NAME_INFORMATION, FileName) + name_len;
|
2009-11-12 15:10:13 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2015-03-09 22:17:08 +01:00
|
|
|
case FileNetworkOpenInformation:
|
|
|
|
{
|
|
|
|
FILE_NETWORK_OPEN_INFORMATION *info = ptr;
|
|
|
|
ANSI_STRING unix_name;
|
|
|
|
|
|
|
|
if (!(io->u.Status = server_get_unix_name( hFile, &unix_name )))
|
|
|
|
{
|
|
|
|
ULONG attributes;
|
|
|
|
struct stat st;
|
|
|
|
|
|
|
|
if (get_file_info( unix_name.Buffer, &st, &attributes ) == -1)
|
|
|
|
io->u.Status = FILE_GetNtStatus();
|
|
|
|
else if (!S_ISREG(st.st_mode) && !S_ISDIR(st.st_mode))
|
|
|
|
io->u.Status = STATUS_INVALID_INFO_CLASS;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
FILE_BASIC_INFORMATION basic;
|
|
|
|
FILE_STANDARD_INFORMATION std;
|
|
|
|
|
|
|
|
fill_file_info( &st, attributes, &basic, FileBasicInformation );
|
|
|
|
fill_file_info( &st, attributes, &std, FileStandardInformation );
|
|
|
|
|
|
|
|
info->CreationTime = basic.CreationTime;
|
|
|
|
info->LastAccessTime = basic.LastAccessTime;
|
|
|
|
info->LastWriteTime = basic.LastWriteTime;
|
|
|
|
info->ChangeTime = basic.ChangeTime;
|
|
|
|
info->AllocationSize = std.AllocationSize;
|
|
|
|
info->EndOfFile = std.EndOfFile;
|
|
|
|
info->FileAttributes = basic.FileAttributes;
|
|
|
|
}
|
|
|
|
RtlFreeAnsiString( &unix_name );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2017-02-16 18:17:51 +01:00
|
|
|
case FileIdInformation:
|
2020-03-20 18:15:26 +01:00
|
|
|
if (fd_get_file_info( fd, options, &st, &attr ) == -1) io->u.Status = FILE_GetNtStatus();
|
2017-02-16 18:17:51 +01:00
|
|
|
else
|
|
|
|
{
|
2020-04-08 23:06:04 +02:00
|
|
|
struct mountmgr_unix_drive *drive;
|
2017-02-16 18:17:51 +01:00
|
|
|
FILE_ID_INFORMATION *info = ptr;
|
2020-04-08 23:06:04 +02:00
|
|
|
|
|
|
|
info->VolumeSerialNumber = 0;
|
|
|
|
if ((drive = get_mountmgr_fs_info( hFile, fd )))
|
|
|
|
{
|
|
|
|
info->VolumeSerialNumber = drive->serial;
|
|
|
|
RtlFreeHeap( GetProcessHeap(), 0, drive );
|
|
|
|
}
|
2017-02-16 18:17:51 +01:00
|
|
|
memset( &info->FileId, 0, sizeof(info->FileId) );
|
|
|
|
*(ULONGLONG *)&info->FileId = st.st_ino;
|
|
|
|
}
|
|
|
|
break;
|
2019-09-26 20:34:33 +02:00
|
|
|
case FileAttributeTagInformation:
|
2020-03-20 18:15:26 +01:00
|
|
|
if (fd_get_file_info( fd, options, &st, &attr ) == -1) io->u.Status = FILE_GetNtStatus();
|
2019-09-26 20:34:33 +02:00
|
|
|
else
|
|
|
|
{
|
|
|
|
FILE_ATTRIBUTE_TAG_INFORMATION *info = ptr;
|
|
|
|
info->FileAttributes = attr;
|
|
|
|
info->ReparseTag = 0; /* FIXME */
|
2020-03-20 18:15:26 +01:00
|
|
|
if ((options & FILE_OPEN_REPARSE_POINT) && fd_is_mount_point( fd, &st ))
|
|
|
|
info->ReparseTag = IO_REPARSE_TAG_MOUNT_POINT;
|
2019-09-26 20:34:33 +02:00
|
|
|
}
|
|
|
|
break;
|
2003-06-24 04:32:01 +02:00
|
|
|
default:
|
|
|
|
FIXME("Unsupported class (%d)\n", class);
|
2004-04-08 06:39:59 +02:00
|
|
|
io->u.Status = STATUS_NOT_IMPLEMENTED;
|
|
|
|
break;
|
2003-06-24 04:32:01 +02:00
|
|
|
}
|
2006-11-03 11:38:44 +01:00
|
|
|
if (needs_close) close( fd );
|
2004-04-30 23:03:09 +02:00
|
|
|
if (io->u.Status == STATUS_SUCCESS && !io->Information) io->Information = info_sizes[class];
|
2004-04-08 06:39:59 +02:00
|
|
|
return io->u.Status;
|
1999-03-09 18:47:51 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************************
|
2001-06-21 01:03:14 +02:00
|
|
|
* NtSetInformationFile [NTDLL.@]
|
2001-07-11 20:56:41 +02:00
|
|
|
* ZwSetInformationFile [NTDLL.@]
|
2003-07-19 00:55:28 +02:00
|
|
|
*
|
|
|
|
* Set information about an open file handle.
|
|
|
|
*
|
|
|
|
* PARAMS
|
2004-04-20 02:36:29 +02:00
|
|
|
* handle [I] Handle returned from ZwOpenFile() or ZwCreateFile()
|
|
|
|
* io [O] Receives information about the operation on return
|
|
|
|
* ptr [I] Source for file information
|
|
|
|
* len [I] Size of FileInformation
|
|
|
|
* class [I] Type of file information to set
|
2003-07-19 00:55:28 +02:00
|
|
|
*
|
|
|
|
* RETURNS
|
2004-04-20 02:36:29 +02:00
|
|
|
* Success: 0. io is updated.
|
2003-07-19 00:55:28 +02:00
|
|
|
* Failure: An NTSTATUS error code describing the error.
|
1999-03-09 18:47:51 +01:00
|
|
|
*/
|
2004-04-20 02:36:29 +02:00
|
|
|
NTSTATUS WINAPI NtSetInformationFile(HANDLE handle, PIO_STATUS_BLOCK io,
|
|
|
|
PVOID ptr, ULONG len, FILE_INFORMATION_CLASS class)
|
1999-03-09 18:47:51 +01:00
|
|
|
{
|
2006-11-03 11:38:44 +01:00
|
|
|
int fd, needs_close;
|
2003-06-24 04:32:01 +02:00
|
|
|
|
2006-10-16 13:49:06 +02:00
|
|
|
TRACE("(%p,%p,%p,0x%08x,0x%08x)\n", handle, io, ptr, len, class);
|
2004-04-20 02:36:29 +02:00
|
|
|
|
|
|
|
io->u.Status = STATUS_SUCCESS;
|
2003-06-24 04:32:01 +02:00
|
|
|
switch (class)
|
2003-07-19 00:55:28 +02:00
|
|
|
{
|
2004-04-20 02:36:29 +02:00
|
|
|
case FileBasicInformation:
|
|
|
|
if (len >= sizeof(FILE_BASIC_INFORMATION))
|
2003-06-24 04:32:01 +02:00
|
|
|
{
|
2004-04-20 02:36:29 +02:00
|
|
|
struct stat st;
|
|
|
|
const FILE_BASIC_INFORMATION *info = ptr;
|
2019-08-09 08:50:34 +02:00
|
|
|
LARGE_INTEGER mtime, atime;
|
2003-06-24 04:32:01 +02:00
|
|
|
|
2020-05-29 15:35:16 +02:00
|
|
|
if ((io->u.Status = unix_funcs->server_get_unix_fd( handle, 0, &fd, &needs_close, NULL, NULL )))
|
2008-02-04 21:18:27 +01:00
|
|
|
return io->u.Status;
|
|
|
|
|
2019-08-09 08:50:34 +02:00
|
|
|
mtime.QuadPart = info->LastWriteTime.QuadPart == -1 ? 0 : info->LastWriteTime.QuadPart;
|
|
|
|
atime.QuadPart = info->LastAccessTime.QuadPart == -1 ? 0 : info->LastAccessTime.QuadPart;
|
|
|
|
|
|
|
|
if (atime.QuadPart || mtime.QuadPart)
|
|
|
|
io->u.Status = set_file_times( fd, &mtime, &atime );
|
2004-10-07 06:25:05 +02:00
|
|
|
|
2004-04-20 02:36:29 +02:00
|
|
|
if (io->u.Status == STATUS_SUCCESS && info->FileAttributes)
|
|
|
|
{
|
|
|
|
if (fstat( fd, &st ) == -1) io->u.Status = FILE_GetNtStatus();
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (info->FileAttributes & FILE_ATTRIBUTE_READONLY)
|
|
|
|
{
|
2004-08-18 22:57:30 +02:00
|
|
|
if (S_ISDIR( st.st_mode))
|
|
|
|
WARN("FILE_ATTRIBUTE_READONLY ignored for directory.\n");
|
|
|
|
else
|
|
|
|
st.st_mode &= ~0222; /* clear write permission bits */
|
2004-04-20 02:36:29 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* add write permission only where we already have read permission */
|
|
|
|
st.st_mode |= (0600 | ((st.st_mode & 044) >> 1)) & (~FILE_umask);
|
|
|
|
}
|
|
|
|
if (fchmod( fd, st.st_mode ) == -1) io->u.Status = FILE_GetNtStatus();
|
|
|
|
}
|
|
|
|
}
|
2008-02-04 21:18:27 +01:00
|
|
|
|
|
|
|
if (needs_close) close( fd );
|
2004-04-20 02:36:29 +02:00
|
|
|
}
|
|
|
|
else io->u.Status = STATUS_INVALID_PARAMETER_3;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case FilePositionInformation:
|
|
|
|
if (len >= sizeof(FILE_POSITION_INFORMATION))
|
|
|
|
{
|
|
|
|
const FILE_POSITION_INFORMATION *info = ptr;
|
|
|
|
|
2020-05-29 15:35:16 +02:00
|
|
|
if ((io->u.Status = unix_funcs->server_get_unix_fd( handle, 0, &fd, &needs_close, NULL, NULL )))
|
2008-02-04 21:18:27 +01:00
|
|
|
return io->u.Status;
|
|
|
|
|
2004-04-20 02:36:29 +02:00
|
|
|
if (lseek( fd, info->CurrentByteOffset.QuadPart, SEEK_SET ) == (off_t)-1)
|
|
|
|
io->u.Status = FILE_GetNtStatus();
|
2008-02-04 21:18:27 +01:00
|
|
|
|
|
|
|
if (needs_close) close( fd );
|
2003-06-24 04:32:01 +02:00
|
|
|
}
|
2004-04-20 02:36:29 +02:00
|
|
|
else io->u.Status = STATUS_INVALID_PARAMETER_3;
|
2003-06-24 04:32:01 +02:00
|
|
|
break;
|
2004-04-20 02:36:29 +02:00
|
|
|
|
2004-05-01 04:44:00 +02:00
|
|
|
case FileEndOfFileInformation:
|
|
|
|
if (len >= sizeof(FILE_END_OF_FILE_INFORMATION))
|
|
|
|
{
|
2004-06-18 01:05:48 +02:00
|
|
|
struct stat st;
|
2004-05-01 04:44:00 +02:00
|
|
|
const FILE_END_OF_FILE_INFORMATION *info = ptr;
|
|
|
|
|
2020-05-29 15:35:16 +02:00
|
|
|
if ((io->u.Status = unix_funcs->server_get_unix_fd( handle, 0, &fd, &needs_close, NULL, NULL )))
|
2008-02-04 21:18:27 +01:00
|
|
|
return io->u.Status;
|
|
|
|
|
2004-06-18 01:05:48 +02:00
|
|
|
/* first try normal truncate */
|
|
|
|
if (ftruncate( fd, (off_t)info->EndOfFile.QuadPart ) != -1) break;
|
|
|
|
|
|
|
|
/* now check for the need to extend the file */
|
|
|
|
if (fstat( fd, &st ) != -1 && (off_t)info->EndOfFile.QuadPart > st.st_size)
|
2004-05-01 04:44:00 +02:00
|
|
|
{
|
|
|
|
static const char zero;
|
|
|
|
|
|
|
|
/* extend the file one byte beyond the requested size and then truncate it */
|
|
|
|
/* this should work around ftruncate implementations that can't extend files */
|
2004-06-18 01:05:48 +02:00
|
|
|
if (pwrite( fd, &zero, 1, (off_t)info->EndOfFile.QuadPart ) != -1 &&
|
|
|
|
ftruncate( fd, (off_t)info->EndOfFile.QuadPart ) != -1) break;
|
2004-05-01 04:44:00 +02:00
|
|
|
}
|
2004-06-18 01:05:48 +02:00
|
|
|
io->u.Status = FILE_GetNtStatus();
|
2008-02-04 21:18:27 +01:00
|
|
|
|
|
|
|
if (needs_close) close( fd );
|
2004-05-01 04:44:00 +02:00
|
|
|
}
|
|
|
|
else io->u.Status = STATUS_INVALID_PARAMETER_3;
|
|
|
|
break;
|
|
|
|
|
2014-08-11 17:06:49 +02:00
|
|
|
case FilePipeInformation:
|
|
|
|
if (len >= sizeof(FILE_PIPE_INFORMATION))
|
|
|
|
{
|
|
|
|
FILE_PIPE_INFORMATION *info = ptr;
|
|
|
|
|
|
|
|
if ((info->CompletionMode | info->ReadMode) & ~1)
|
|
|
|
{
|
|
|
|
io->u.Status = STATUS_INVALID_PARAMETER;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
SERVER_START_REQ( set_named_pipe_info )
|
|
|
|
{
|
|
|
|
req->handle = wine_server_obj_handle( handle );
|
|
|
|
req->flags = (info->CompletionMode ? NAMED_PIPE_NONBLOCKING_MODE : 0) |
|
|
|
|
(info->ReadMode ? NAMED_PIPE_MESSAGE_STREAM_READ : 0);
|
|
|
|
io->u.Status = wine_server_call( req );
|
|
|
|
}
|
|
|
|
SERVER_END_REQ;
|
|
|
|
}
|
|
|
|
else io->u.Status = STATUS_INVALID_PARAMETER_3;
|
|
|
|
break;
|
|
|
|
|
2005-04-11 16:20:49 +02:00
|
|
|
case FileMailslotSetInformation:
|
|
|
|
{
|
|
|
|
FILE_MAILSLOT_SET_INFORMATION *info = ptr;
|
|
|
|
|
|
|
|
SERVER_START_REQ( set_mailslot_info )
|
|
|
|
{
|
2008-12-08 16:05:17 +01:00
|
|
|
req->handle = wine_server_obj_handle( handle );
|
2005-04-11 16:20:49 +02:00
|
|
|
req->flags = MAILSLOT_SET_READ_TIMEOUT;
|
2007-04-17 20:08:59 +02:00
|
|
|
req->read_timeout = info->ReadTimeout.QuadPart;
|
2005-04-11 16:20:49 +02:00
|
|
|
io->u.Status = wine_server_call( req );
|
|
|
|
}
|
|
|
|
SERVER_END_REQ;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2007-09-27 22:03:39 +02:00
|
|
|
case FileCompletionInformation:
|
|
|
|
if (len >= sizeof(FILE_COMPLETION_INFORMATION))
|
|
|
|
{
|
2009-03-17 00:12:11 +01:00
|
|
|
FILE_COMPLETION_INFORMATION *info = ptr;
|
2007-09-27 22:03:39 +02:00
|
|
|
|
|
|
|
SERVER_START_REQ( set_completion_info )
|
|
|
|
{
|
2008-12-08 16:05:17 +01:00
|
|
|
req->handle = wine_server_obj_handle( handle );
|
|
|
|
req->chandle = wine_server_obj_handle( info->CompletionPort );
|
2007-09-27 22:03:39 +02:00
|
|
|
req->ckey = info->CompletionKey;
|
|
|
|
io->u.Status = wine_server_call( req );
|
|
|
|
}
|
|
|
|
SERVER_END_REQ;
|
|
|
|
} else
|
|
|
|
io->u.Status = STATUS_INVALID_PARAMETER_3;
|
|
|
|
break;
|
|
|
|
|
2018-10-25 14:55:24 +02:00
|
|
|
case FileIoCompletionNotificationInformation:
|
|
|
|
if (len >= sizeof(FILE_IO_COMPLETION_NOTIFICATION_INFORMATION))
|
|
|
|
{
|
|
|
|
FILE_IO_COMPLETION_NOTIFICATION_INFORMATION *info = ptr;
|
|
|
|
|
2018-11-01 12:40:04 +01:00
|
|
|
if (info->Flags & FILE_SKIP_SET_USER_EVENT_ON_FAST_IO)
|
|
|
|
FIXME( "FILE_SKIP_SET_USER_EVENT_ON_FAST_IO not supported\n" );
|
2018-10-25 14:55:24 +02:00
|
|
|
|
|
|
|
SERVER_START_REQ( set_fd_completion_mode )
|
|
|
|
{
|
|
|
|
req->handle = wine_server_obj_handle( handle );
|
|
|
|
req->flags = info->Flags;
|
|
|
|
io->u.Status = wine_server_call( req );
|
|
|
|
}
|
|
|
|
SERVER_END_REQ;
|
|
|
|
} else
|
|
|
|
io->u.Status = STATUS_INFO_LENGTH_MISMATCH;
|
|
|
|
break;
|
|
|
|
|
2018-11-18 21:13:50 +01:00
|
|
|
case FileIoPriorityHintInformation:
|
|
|
|
if (len >= sizeof(FILE_IO_PRIORITY_HINT_INFO))
|
|
|
|
{
|
|
|
|
FILE_IO_PRIORITY_HINT_INFO *info = ptr;
|
|
|
|
if (info->PriorityHint < MaximumIoPriorityHintType)
|
|
|
|
TRACE( "ignoring FileIoPriorityHintInformation %u\n", info->PriorityHint );
|
|
|
|
else
|
|
|
|
io->u.Status = STATUS_INVALID_PARAMETER;
|
|
|
|
}
|
|
|
|
else io->u.Status = STATUS_INFO_LENGTH_MISMATCH;
|
|
|
|
break;
|
|
|
|
|
2010-07-25 22:13:37 +02:00
|
|
|
case FileAllInformation:
|
|
|
|
io->u.Status = STATUS_INVALID_INFO_CLASS;
|
|
|
|
break;
|
|
|
|
|
2012-12-04 10:40:16 +01:00
|
|
|
case FileValidDataLengthInformation:
|
|
|
|
if (len >= sizeof(FILE_VALID_DATA_LENGTH_INFORMATION))
|
|
|
|
{
|
|
|
|
struct stat st;
|
|
|
|
const FILE_VALID_DATA_LENGTH_INFORMATION *info = ptr;
|
|
|
|
|
2020-05-29 15:35:16 +02:00
|
|
|
if ((io->u.Status = unix_funcs->server_get_unix_fd( handle, FILE_WRITE_DATA, &fd, &needs_close, NULL, NULL )))
|
2012-12-04 10:40:16 +01:00
|
|
|
return io->u.Status;
|
|
|
|
|
|
|
|
if (fstat( fd, &st ) == -1) io->u.Status = FILE_GetNtStatus();
|
|
|
|
else if (info->ValidDataLength.QuadPart <= 0 || (off_t)info->ValidDataLength.QuadPart > st.st_size)
|
|
|
|
io->u.Status = STATUS_INVALID_PARAMETER;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
#ifdef HAVE_FALLOCATE
|
|
|
|
if (fallocate( fd, 0, 0, (off_t)info->ValidDataLength.QuadPart ) == -1)
|
|
|
|
{
|
|
|
|
NTSTATUS status = FILE_GetNtStatus();
|
|
|
|
if (status == STATUS_NOT_SUPPORTED) WARN( "fallocate not supported on this filesystem\n" );
|
|
|
|
else io->u.Status = status;
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
FIXME( "setting valid data length not supported\n" );
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
if (needs_close) close( fd );
|
|
|
|
}
|
|
|
|
else io->u.Status = STATUS_INVALID_PARAMETER_3;
|
|
|
|
break;
|
|
|
|
|
2015-08-19 11:18:01 +02:00
|
|
|
case FileDispositionInformation:
|
|
|
|
if (len >= sizeof(FILE_DISPOSITION_INFORMATION))
|
|
|
|
{
|
|
|
|
FILE_DISPOSITION_INFORMATION *info = ptr;
|
|
|
|
|
2015-08-20 10:25:15 +02:00
|
|
|
SERVER_START_REQ( set_fd_disp_info )
|
2015-08-19 11:18:01 +02:00
|
|
|
{
|
|
|
|
req->handle = wine_server_obj_handle( handle );
|
|
|
|
req->unlink = info->DoDeleteFile;
|
|
|
|
io->u.Status = wine_server_call( req );
|
|
|
|
}
|
|
|
|
SERVER_END_REQ;
|
|
|
|
} else
|
|
|
|
io->u.Status = STATUS_INVALID_PARAMETER_3;
|
|
|
|
break;
|
|
|
|
|
2015-08-20 10:25:15 +02:00
|
|
|
case FileRenameInformation:
|
|
|
|
if (len >= sizeof(FILE_RENAME_INFORMATION))
|
|
|
|
{
|
|
|
|
FILE_RENAME_INFORMATION *info = ptr;
|
|
|
|
UNICODE_STRING name_str;
|
|
|
|
OBJECT_ATTRIBUTES attr;
|
|
|
|
ANSI_STRING unix_name;
|
|
|
|
|
|
|
|
name_str.Buffer = info->FileName;
|
|
|
|
name_str.Length = info->FileNameLength;
|
|
|
|
name_str.MaximumLength = info->FileNameLength + sizeof(WCHAR);
|
|
|
|
|
|
|
|
attr.Length = sizeof(attr);
|
|
|
|
attr.ObjectName = &name_str;
|
2020-03-06 03:47:12 +01:00
|
|
|
attr.RootDirectory = info->RootDirectory;
|
2015-08-20 10:25:15 +02:00
|
|
|
attr.Attributes = OBJ_CASE_INSENSITIVE;
|
|
|
|
|
|
|
|
io->u.Status = nt_to_unix_file_name_attr( &attr, &unix_name, FILE_OPEN_IF );
|
|
|
|
if (io->u.Status != STATUS_SUCCESS && io->u.Status != STATUS_NO_SUCH_FILE)
|
|
|
|
break;
|
|
|
|
|
|
|
|
SERVER_START_REQ( set_fd_name_info )
|
|
|
|
{
|
|
|
|
req->handle = wine_server_obj_handle( handle );
|
|
|
|
req->rootdir = wine_server_obj_handle( attr.RootDirectory );
|
2015-08-21 07:25:12 +02:00
|
|
|
req->link = FALSE;
|
2020-03-11 04:38:23 +01:00
|
|
|
req->replace = info->ReplaceIfExists;
|
2015-08-21 07:25:12 +02:00
|
|
|
wine_server_add_data( req, unix_name.Buffer, unix_name.Length );
|
|
|
|
io->u.Status = wine_server_call( req );
|
|
|
|
}
|
|
|
|
SERVER_END_REQ;
|
|
|
|
|
|
|
|
RtlFreeAnsiString( &unix_name );
|
|
|
|
}
|
|
|
|
else io->u.Status = STATUS_INVALID_PARAMETER_3;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case FileLinkInformation:
|
|
|
|
if (len >= sizeof(FILE_LINK_INFORMATION))
|
|
|
|
{
|
|
|
|
FILE_LINK_INFORMATION *info = ptr;
|
|
|
|
UNICODE_STRING name_str;
|
|
|
|
OBJECT_ATTRIBUTES attr;
|
|
|
|
ANSI_STRING unix_name;
|
|
|
|
|
|
|
|
name_str.Buffer = info->FileName;
|
|
|
|
name_str.Length = info->FileNameLength;
|
|
|
|
name_str.MaximumLength = info->FileNameLength + sizeof(WCHAR);
|
|
|
|
|
|
|
|
attr.Length = sizeof(attr);
|
|
|
|
attr.ObjectName = &name_str;
|
|
|
|
attr.RootDirectory = info->RootDirectory;
|
|
|
|
attr.Attributes = OBJ_CASE_INSENSITIVE;
|
|
|
|
|
|
|
|
io->u.Status = nt_to_unix_file_name_attr( &attr, &unix_name, FILE_OPEN_IF );
|
|
|
|
if (io->u.Status != STATUS_SUCCESS && io->u.Status != STATUS_NO_SUCH_FILE)
|
|
|
|
break;
|
|
|
|
|
|
|
|
SERVER_START_REQ( set_fd_name_info )
|
|
|
|
{
|
|
|
|
req->handle = wine_server_obj_handle( handle );
|
|
|
|
req->rootdir = wine_server_obj_handle( attr.RootDirectory );
|
|
|
|
req->link = TRUE;
|
2020-03-11 04:38:23 +01:00
|
|
|
req->replace = info->ReplaceIfExists;
|
2015-08-20 10:25:15 +02:00
|
|
|
wine_server_add_data( req, unix_name.Buffer, unix_name.Length );
|
|
|
|
io->u.Status = wine_server_call( req );
|
|
|
|
}
|
|
|
|
SERVER_END_REQ;
|
|
|
|
|
|
|
|
RtlFreeAnsiString( &unix_name );
|
|
|
|
}
|
|
|
|
else io->u.Status = STATUS_INVALID_PARAMETER_3;
|
|
|
|
break;
|
|
|
|
|
2003-06-24 04:32:01 +02:00
|
|
|
default:
|
|
|
|
FIXME("Unsupported class (%d)\n", class);
|
2004-04-20 02:36:29 +02:00
|
|
|
io->u.Status = STATUS_NOT_IMPLEMENTED;
|
|
|
|
break;
|
2003-06-24 04:32:01 +02:00
|
|
|
}
|
2004-04-20 02:36:29 +02:00
|
|
|
io->Information = 0;
|
|
|
|
return io->u.Status;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/******************************************************************************
|
2009-11-18 17:01:15 +01:00
|
|
|
* NtQueryFullAttributesFile (NTDLL.@)
|
2004-04-20 02:36:29 +02:00
|
|
|
*/
|
2009-11-18 17:01:15 +01:00
|
|
|
NTSTATUS WINAPI NtQueryFullAttributesFile( const OBJECT_ATTRIBUTES *attr,
|
|
|
|
FILE_NETWORK_OPEN_INFORMATION *info )
|
2004-04-20 02:36:29 +02:00
|
|
|
{
|
|
|
|
ANSI_STRING unix_name;
|
|
|
|
NTSTATUS status;
|
|
|
|
|
2009-12-01 17:07:55 +01:00
|
|
|
if (!(status = nt_to_unix_file_name_attr( attr, &unix_name, FILE_OPEN )))
|
2004-04-20 02:36:29 +02:00
|
|
|
{
|
2014-08-20 04:31:00 +02:00
|
|
|
ULONG attributes;
|
2004-04-20 02:36:29 +02:00
|
|
|
struct stat st;
|
|
|
|
|
2014-08-20 04:31:00 +02:00
|
|
|
if (get_file_info( unix_name.Buffer, &st, &attributes ) == -1)
|
2004-04-20 02:36:29 +02:00
|
|
|
status = FILE_GetNtStatus();
|
|
|
|
else if (!S_ISREG(st.st_mode) && !S_ISDIR(st.st_mode))
|
|
|
|
status = STATUS_INVALID_INFO_CLASS;
|
|
|
|
else
|
|
|
|
{
|
2009-11-18 17:01:15 +01:00
|
|
|
FILE_BASIC_INFORMATION basic;
|
|
|
|
FILE_STANDARD_INFORMATION std;
|
|
|
|
|
2014-08-20 04:31:00 +02:00
|
|
|
fill_file_info( &st, attributes, &basic, FileBasicInformation );
|
|
|
|
fill_file_info( &st, attributes, &std, FileStandardInformation );
|
2009-11-18 17:01:15 +01:00
|
|
|
|
|
|
|
info->CreationTime = basic.CreationTime;
|
|
|
|
info->LastAccessTime = basic.LastAccessTime;
|
|
|
|
info->LastWriteTime = basic.LastWriteTime;
|
|
|
|
info->ChangeTime = basic.ChangeTime;
|
|
|
|
info->AllocationSize = std.AllocationSize;
|
|
|
|
info->EndOfFile = std.EndOfFile;
|
|
|
|
info->FileAttributes = basic.FileAttributes;
|
2004-04-20 02:36:29 +02:00
|
|
|
if (DIR_is_hidden_file( attr->ObjectName ))
|
|
|
|
info->FileAttributes |= FILE_ATTRIBUTE_HIDDEN;
|
|
|
|
}
|
|
|
|
RtlFreeAnsiString( &unix_name );
|
|
|
|
}
|
2006-10-16 13:49:06 +02:00
|
|
|
else WARN("%s not found (%x)\n", debugstr_us(attr->ObjectName), status );
|
2003-06-24 04:32:01 +02:00
|
|
|
return status;
|
1999-03-09 18:47:51 +01:00
|
|
|
}
|
|
|
|
|
2004-04-06 06:19:41 +02:00
|
|
|
|
2004-04-20 06:06:49 +02:00
|
|
|
/******************************************************************************
|
|
|
|
* NtQueryAttributesFile (NTDLL.@)
|
|
|
|
* ZwQueryAttributesFile (NTDLL.@)
|
|
|
|
*/
|
|
|
|
NTSTATUS WINAPI NtQueryAttributesFile( const OBJECT_ATTRIBUTES *attr, FILE_BASIC_INFORMATION *info )
|
|
|
|
{
|
2009-11-18 17:01:15 +01:00
|
|
|
ANSI_STRING unix_name;
|
2004-04-20 06:06:49 +02:00
|
|
|
NTSTATUS status;
|
|
|
|
|
2009-12-01 17:07:55 +01:00
|
|
|
if (!(status = nt_to_unix_file_name_attr( attr, &unix_name, FILE_OPEN )))
|
2004-04-20 06:06:49 +02:00
|
|
|
{
|
2014-08-20 04:31:00 +02:00
|
|
|
ULONG attributes;
|
2009-11-18 17:01:15 +01:00
|
|
|
struct stat st;
|
|
|
|
|
2014-08-20 04:31:00 +02:00
|
|
|
if (get_file_info( unix_name.Buffer, &st, &attributes ) == -1)
|
2009-11-18 17:01:15 +01:00
|
|
|
status = FILE_GetNtStatus();
|
|
|
|
else if (!S_ISREG(st.st_mode) && !S_ISDIR(st.st_mode))
|
|
|
|
status = STATUS_INVALID_INFO_CLASS;
|
|
|
|
else
|
|
|
|
{
|
2014-08-20 04:31:00 +02:00
|
|
|
status = fill_file_info( &st, attributes, info, FileBasicInformation );
|
2009-11-18 17:01:15 +01:00
|
|
|
if (DIR_is_hidden_file( attr->ObjectName ))
|
|
|
|
info->FileAttributes |= FILE_ATTRIBUTE_HIDDEN;
|
|
|
|
}
|
|
|
|
RtlFreeAnsiString( &unix_name );
|
2004-04-20 06:06:49 +02:00
|
|
|
}
|
2009-11-18 17:01:15 +01:00
|
|
|
else WARN("%s not found (%x)\n", debugstr_us(attr->ObjectName), status );
|
2004-04-20 06:06:49 +02:00
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-06-02 18:53:57 +02:00
|
|
|
#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__DragonFly__) || defined(__APPLE__)
|
2006-11-01 13:15:57 +01:00
|
|
|
/* helper for FILE_GetDeviceInfo to hide some platform differences in fstatfs */
|
2006-11-03 15:20:21 +01:00
|
|
|
static inline void get_device_info_fstatfs( FILE_FS_DEVICE_INFORMATION *info, const char *fstypename,
|
2007-08-29 12:02:13 +02:00
|
|
|
unsigned int flags )
|
2006-11-01 13:15:57 +01:00
|
|
|
{
|
2007-08-29 12:02:13 +02:00
|
|
|
if (!strcmp("cd9660", fstypename) || !strcmp("udf", fstypename))
|
2006-11-01 13:15:57 +01:00
|
|
|
{
|
|
|
|
info->DeviceType = FILE_DEVICE_CD_ROM_FILE_SYSTEM;
|
|
|
|
/* Don't assume read-only, let the mount options set it below */
|
|
|
|
info->Characteristics |= FILE_REMOVABLE_MEDIA;
|
|
|
|
}
|
2007-08-29 12:02:13 +02:00
|
|
|
else if (!strcmp("nfs", fstypename) || !strcmp("nwfs", fstypename) ||
|
|
|
|
!strcmp("smbfs", fstypename) || !strcmp("afpfs", fstypename))
|
2006-11-01 13:15:57 +01:00
|
|
|
{
|
|
|
|
info->DeviceType = FILE_DEVICE_NETWORK_FILE_SYSTEM;
|
|
|
|
info->Characteristics |= FILE_REMOTE_DEVICE;
|
|
|
|
}
|
2007-08-29 12:02:13 +02:00
|
|
|
else if (!strcmp("procfs", fstypename))
|
2006-11-01 13:15:57 +01:00
|
|
|
info->DeviceType = FILE_DEVICE_VIRTUAL_DISK;
|
|
|
|
else
|
|
|
|
info->DeviceType = FILE_DEVICE_DISK_FILE_SYSTEM;
|
|
|
|
|
|
|
|
if (flags & MNT_RDONLY)
|
|
|
|
info->Characteristics |= FILE_READ_ONLY_DEVICE;
|
|
|
|
|
|
|
|
if (!(flags & MNT_LOCAL))
|
|
|
|
{
|
|
|
|
info->DeviceType = FILE_DEVICE_NETWORK_FILE_SYSTEM;
|
|
|
|
info->Characteristics |= FILE_REMOTE_DEVICE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2013-11-01 00:21:24 +01:00
|
|
|
static inline BOOL is_device_placeholder( int fd )
|
2007-11-09 23:11:48 +01:00
|
|
|
{
|
|
|
|
static const char wine_placeholder[] = "Wine device placeholder";
|
|
|
|
char buffer[sizeof(wine_placeholder)-1];
|
|
|
|
|
|
|
|
if (pread( fd, buffer, sizeof(wine_placeholder) - 1, 0 ) != sizeof(wine_placeholder) - 1)
|
2013-11-01 00:21:24 +01:00
|
|
|
return FALSE;
|
2007-11-09 23:11:48 +01:00
|
|
|
return !memcmp( buffer, wine_placeholder, sizeof(wine_placeholder) - 1 );
|
|
|
|
}
|
|
|
|
|
2005-08-24 20:27:27 +02:00
|
|
|
/******************************************************************************
|
2006-11-03 15:20:21 +01:00
|
|
|
* get_device_info
|
2005-08-24 20:27:27 +02:00
|
|
|
*
|
|
|
|
* Implementation of the FileFsDeviceInformation query for NtQueryVolumeInformationFile.
|
|
|
|
*/
|
2006-11-03 15:20:21 +01:00
|
|
|
static NTSTATUS get_device_info( int fd, FILE_FS_DEVICE_INFORMATION *info )
|
2005-08-24 20:27:27 +02:00
|
|
|
{
|
|
|
|
struct stat st;
|
|
|
|
|
|
|
|
info->Characteristics = 0;
|
|
|
|
if (fstat( fd, &st ) < 0) return FILE_GetNtStatus();
|
|
|
|
if (S_ISCHR( st.st_mode ))
|
|
|
|
{
|
|
|
|
info->DeviceType = FILE_DEVICE_UNKNOWN;
|
|
|
|
#ifdef linux
|
|
|
|
switch(major(st.st_rdev))
|
|
|
|
{
|
|
|
|
case MEM_MAJOR:
|
|
|
|
info->DeviceType = FILE_DEVICE_NULL;
|
|
|
|
break;
|
|
|
|
case TTY_MAJOR:
|
|
|
|
info->DeviceType = FILE_DEVICE_SERIAL_PORT;
|
|
|
|
break;
|
|
|
|
case LP_MAJOR:
|
|
|
|
info->DeviceType = FILE_DEVICE_PARALLEL_PORT;
|
|
|
|
break;
|
2006-01-26 13:23:08 +01:00
|
|
|
case SCSI_TAPE_MAJOR:
|
|
|
|
info->DeviceType = FILE_DEVICE_TAPE;
|
|
|
|
break;
|
2005-08-24 20:27:27 +02:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
else if (S_ISBLK( st.st_mode ))
|
|
|
|
{
|
|
|
|
info->DeviceType = FILE_DEVICE_DISK;
|
|
|
|
}
|
|
|
|
else if (S_ISFIFO( st.st_mode ) || S_ISSOCK( st.st_mode ))
|
|
|
|
{
|
|
|
|
info->DeviceType = FILE_DEVICE_NAMED_PIPE;
|
|
|
|
}
|
2007-11-09 23:11:48 +01:00
|
|
|
else if (is_device_placeholder( fd ))
|
|
|
|
{
|
|
|
|
info->DeviceType = FILE_DEVICE_DISK;
|
|
|
|
}
|
2005-08-24 20:27:27 +02:00
|
|
|
else /* regular file or directory */
|
|
|
|
{
|
|
|
|
#if defined(linux) && defined(HAVE_FSTATFS)
|
|
|
|
struct statfs stfs;
|
|
|
|
|
|
|
|
/* check for floppy disk */
|
|
|
|
if (major(st.st_dev) == FLOPPY_MAJOR)
|
|
|
|
info->Characteristics |= FILE_REMOVABLE_MEDIA;
|
|
|
|
|
|
|
|
if (fstatfs( fd, &stfs ) < 0) stfs.f_type = 0;
|
|
|
|
switch (stfs.f_type)
|
|
|
|
{
|
|
|
|
case 0x9660: /* iso9660 */
|
2006-05-25 02:18:45 +02:00
|
|
|
case 0x9fa1: /* supermount */
|
2005-08-24 20:27:27 +02:00
|
|
|
case 0x15013346: /* udf */
|
|
|
|
info->DeviceType = FILE_DEVICE_CD_ROM_FILE_SYSTEM;
|
|
|
|
info->Characteristics |= FILE_REMOVABLE_MEDIA|FILE_READ_ONLY_DEVICE;
|
|
|
|
break;
|
|
|
|
case 0x6969: /* nfs */
|
2017-10-01 14:23:10 +02:00
|
|
|
case 0xff534d42: /* cifs */
|
|
|
|
case 0xfe534d42: /* smb2 */
|
|
|
|
case 0x517b: /* smbfs */
|
2005-08-24 20:27:27 +02:00
|
|
|
case 0x564c: /* ncpfs */
|
|
|
|
info->DeviceType = FILE_DEVICE_NETWORK_FILE_SYSTEM;
|
|
|
|
info->Characteristics |= FILE_REMOTE_DEVICE;
|
|
|
|
break;
|
|
|
|
case 0x01021994: /* tmpfs */
|
|
|
|
case 0x28cd3d45: /* cramfs */
|
|
|
|
case 0x1373: /* devfs */
|
|
|
|
case 0x9fa0: /* procfs */
|
|
|
|
info->DeviceType = FILE_DEVICE_VIRTUAL_DISK;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
info->DeviceType = FILE_DEVICE_DISK_FILE_SYSTEM;
|
|
|
|
break;
|
|
|
|
}
|
2012-06-02 18:53:57 +02:00
|
|
|
#elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__OpenBSD__) || defined(__DragonFly__) || defined(__APPLE__)
|
2005-08-24 20:27:27 +02:00
|
|
|
struct statfs stfs;
|
|
|
|
|
|
|
|
if (fstatfs( fd, &stfs ) < 0)
|
|
|
|
info->DeviceType = FILE_DEVICE_DISK_FILE_SYSTEM;
|
|
|
|
else
|
2007-08-29 12:02:13 +02:00
|
|
|
get_device_info_fstatfs( info, stfs.f_fstypename, stfs.f_flags );
|
2006-11-01 13:15:57 +01:00
|
|
|
#elif defined(__NetBSD__)
|
|
|
|
struct statvfs stfs;
|
|
|
|
|
|
|
|
if (fstatvfs( fd, &stfs) < 0)
|
2005-08-24 20:27:27 +02:00
|
|
|
info->DeviceType = FILE_DEVICE_DISK_FILE_SYSTEM;
|
2006-11-01 13:15:57 +01:00
|
|
|
else
|
2007-08-29 12:02:13 +02:00
|
|
|
get_device_info_fstatfs( info, stfs.f_fstypename, stfs.f_flag );
|
2005-08-24 20:27:27 +02:00
|
|
|
#elif defined(sun)
|
|
|
|
/* Use dkio to work out device types */
|
|
|
|
{
|
|
|
|
# include <sys/dkio.h>
|
|
|
|
# include <sys/vtoc.h>
|
|
|
|
struct dk_cinfo dkinf;
|
|
|
|
int retval = ioctl(fd, DKIOCINFO, &dkinf);
|
|
|
|
if(retval==-1){
|
|
|
|
WARN("Unable to get disk device type information - assuming a disk like device\n");
|
|
|
|
info->DeviceType = FILE_DEVICE_DISK_FILE_SYSTEM;
|
|
|
|
}
|
|
|
|
switch (dkinf.dki_ctype)
|
|
|
|
{
|
|
|
|
case DKC_CDROM:
|
|
|
|
info->DeviceType = FILE_DEVICE_CD_ROM_FILE_SYSTEM;
|
|
|
|
info->Characteristics |= FILE_REMOVABLE_MEDIA|FILE_READ_ONLY_DEVICE;
|
|
|
|
break;
|
|
|
|
case DKC_NCRFLOPPY:
|
|
|
|
case DKC_SMSFLOPPY:
|
|
|
|
case DKC_INTEL82072:
|
|
|
|
case DKC_INTEL82077:
|
|
|
|
info->DeviceType = FILE_DEVICE_DISK_FILE_SYSTEM;
|
|
|
|
info->Characteristics |= FILE_REMOVABLE_MEDIA;
|
|
|
|
break;
|
|
|
|
case DKC_MD:
|
|
|
|
info->DeviceType = FILE_DEVICE_VIRTUAL_DISK;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
info->DeviceType = FILE_DEVICE_DISK_FILE_SYSTEM;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
static int warned;
|
|
|
|
if (!warned++) FIXME( "device info not properly supported on this platform\n" );
|
|
|
|
info->DeviceType = FILE_DEVICE_DISK_FILE_SYSTEM;
|
|
|
|
#endif
|
|
|
|
info->Characteristics |= FILE_DEVICE_IS_MOUNTED;
|
|
|
|
}
|
|
|
|
return STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
|
- implementation of RtlReg* (read access), RtlEvent*, RtlSemaphore*,
NtAllocateLocallyUniqueId
- implementation or stubs for NtAccessCheck, NtSetSecurityObject,
RtlClearBits, RtlEqualPrefixSid, RtlFindClearBits,
RtlFormatCurrentUserKeyPath, RtlGetControlSecurityDescriptor,
RtlIdentifierAuthoritySid, RtlImpersonateSelf, RtlInitializeBitMap,
RtlInitializeGenericTable, RtlMakeSelfRelativeSD,
RtlPrefixUnicodeString, RtlSetBits, RtlUnicodeToMultiByteN,
RtlUpcaseUnicodeStringToOemString, RtlUpcaseUnicodeToOemN,
RtlValidSid, RtlxUnicodeStringToOemSize
- corrected most RtlString* functions, added documentation
- more fixes and partial implementations
2000-01-23 23:35:33 +01:00
|
|
|
/******************************************************************************
|
2001-06-21 01:03:14 +02:00
|
|
|
* NtQueryVolumeInformationFile [NTDLL.@]
|
2001-07-11 20:56:41 +02:00
|
|
|
* ZwQueryVolumeInformationFile [NTDLL.@]
|
2003-07-19 00:55:28 +02:00
|
|
|
*
|
|
|
|
* Get volume information for an open file handle.
|
|
|
|
*
|
|
|
|
* PARAMS
|
2004-04-06 06:19:41 +02:00
|
|
|
* handle [I] Handle returned from ZwOpenFile() or ZwCreateFile()
|
|
|
|
* io [O] Receives information about the operation on return
|
|
|
|
* buffer [O] Destination for volume information
|
|
|
|
* length [I] Size of FsInformation
|
|
|
|
* info_class [I] Type of volume information to set
|
2003-07-19 00:55:28 +02:00
|
|
|
*
|
|
|
|
* RETURNS
|
2004-04-06 06:19:41 +02:00
|
|
|
* Success: 0. io and buffer are updated.
|
2003-07-19 00:55:28 +02:00
|
|
|
* Failure: An NTSTATUS error code describing the error.
|
- implementation of RtlReg* (read access), RtlEvent*, RtlSemaphore*,
NtAllocateLocallyUniqueId
- implementation or stubs for NtAccessCheck, NtSetSecurityObject,
RtlClearBits, RtlEqualPrefixSid, RtlFindClearBits,
RtlFormatCurrentUserKeyPath, RtlGetControlSecurityDescriptor,
RtlIdentifierAuthoritySid, RtlImpersonateSelf, RtlInitializeBitMap,
RtlInitializeGenericTable, RtlMakeSelfRelativeSD,
RtlPrefixUnicodeString, RtlSetBits, RtlUnicodeToMultiByteN,
RtlUpcaseUnicodeStringToOemString, RtlUpcaseUnicodeToOemN,
RtlValidSid, RtlxUnicodeStringToOemSize
- corrected most RtlString* functions, added documentation
- more fixes and partial implementations
2000-01-23 23:35:33 +01:00
|
|
|
*/
|
2004-04-06 06:19:41 +02:00
|
|
|
NTSTATUS WINAPI NtQueryVolumeInformationFile( HANDLE handle, PIO_STATUS_BLOCK io,
|
|
|
|
PVOID buffer, ULONG length,
|
|
|
|
FS_INFORMATION_CLASS info_class )
|
- implementation of RtlReg* (read access), RtlEvent*, RtlSemaphore*,
NtAllocateLocallyUniqueId
- implementation or stubs for NtAccessCheck, NtSetSecurityObject,
RtlClearBits, RtlEqualPrefixSid, RtlFindClearBits,
RtlFormatCurrentUserKeyPath, RtlGetControlSecurityDescriptor,
RtlIdentifierAuthoritySid, RtlImpersonateSelf, RtlInitializeBitMap,
RtlInitializeGenericTable, RtlMakeSelfRelativeSD,
RtlPrefixUnicodeString, RtlSetBits, RtlUnicodeToMultiByteN,
RtlUpcaseUnicodeStringToOemString, RtlUpcaseUnicodeToOemN,
RtlValidSid, RtlxUnicodeStringToOemSize
- corrected most RtlString* functions, added documentation
- more fixes and partial implementations
2000-01-23 23:35:33 +01:00
|
|
|
{
|
2006-11-03 11:38:44 +01:00
|
|
|
int fd, needs_close;
|
2004-04-07 05:58:55 +02:00
|
|
|
struct stat st;
|
2002-05-09 21:40:30 +02:00
|
|
|
|
2020-05-29 15:35:16 +02:00
|
|
|
io->u.Status = unix_funcs->server_get_unix_fd( handle, 0, &fd, &needs_close, NULL, NULL );
|
2017-10-02 16:42:16 +02:00
|
|
|
if (io->u.Status == STATUS_BAD_DEVICE_TYPE)
|
|
|
|
{
|
|
|
|
SERVER_START_REQ( get_volume_info )
|
|
|
|
{
|
|
|
|
req->handle = wine_server_obj_handle( handle );
|
|
|
|
req->info_class = info_class;
|
|
|
|
wine_server_set_reply( req, buffer, length );
|
|
|
|
io->u.Status = wine_server_call( req );
|
|
|
|
if (!io->u.Status) io->Information = wine_server_reply_size( reply );
|
|
|
|
}
|
|
|
|
SERVER_END_REQ;
|
2004-04-06 06:19:41 +02:00
|
|
|
return io->u.Status;
|
2017-10-02 16:42:16 +02:00
|
|
|
}
|
|
|
|
else if (io->u.Status) return io->u.Status;
|
2002-05-09 21:40:30 +02:00
|
|
|
|
2004-04-06 06:19:41 +02:00
|
|
|
io->u.Status = STATUS_NOT_IMPLEMENTED;
|
|
|
|
io->Information = 0;
|
2002-05-09 21:40:30 +02:00
|
|
|
|
2004-04-06 06:19:41 +02:00
|
|
|
switch( info_class )
|
|
|
|
{
|
|
|
|
case FileFsLabelInformation:
|
|
|
|
FIXME( "%p: label info not supported\n", handle );
|
|
|
|
break;
|
|
|
|
case FileFsSizeInformation:
|
|
|
|
if (length < sizeof(FILE_FS_SIZE_INFORMATION))
|
|
|
|
io->u.Status = STATUS_BUFFER_TOO_SMALL;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
FILE_FS_SIZE_INFORMATION *info = buffer;
|
2002-05-09 21:40:30 +02:00
|
|
|
|
2004-04-07 05:58:55 +02:00
|
|
|
if (fstat( fd, &st ) < 0)
|
|
|
|
{
|
|
|
|
io->u.Status = FILE_GetNtStatus();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (!S_ISREG(st.st_mode) && !S_ISDIR(st.st_mode))
|
|
|
|
{
|
|
|
|
io->u.Status = STATUS_INVALID_DEVICE_REQUEST;
|
|
|
|
}
|
2004-04-06 06:19:41 +02:00
|
|
|
else
|
|
|
|
{
|
2008-09-16 11:32:38 +02:00
|
|
|
ULONGLONG bsize;
|
2005-01-06 21:44:52 +01:00
|
|
|
/* Linux's fstatvfs is buggy */
|
|
|
|
#if !defined(linux) || !defined(HAVE_FSTATFS)
|
|
|
|
struct statvfs stfs;
|
|
|
|
|
|
|
|
if (fstatvfs( fd, &stfs ) < 0)
|
|
|
|
{
|
|
|
|
io->u.Status = FILE_GetNtStatus();
|
|
|
|
break;
|
|
|
|
}
|
2008-09-16 11:32:38 +02:00
|
|
|
bsize = stfs.f_frsize;
|
2005-01-06 21:44:52 +01:00
|
|
|
#else
|
|
|
|
struct statfs stfs;
|
|
|
|
if (fstatfs( fd, &stfs ) < 0)
|
|
|
|
{
|
|
|
|
io->u.Status = FILE_GetNtStatus();
|
|
|
|
break;
|
|
|
|
}
|
2008-09-16 11:32:38 +02:00
|
|
|
bsize = stfs.f_bsize;
|
2005-01-06 21:44:52 +01:00
|
|
|
#endif
|
2008-10-06 17:52:23 +02:00
|
|
|
if (bsize == 2048) /* assume CD-ROM */
|
|
|
|
{
|
|
|
|
info->BytesPerSector = 2048;
|
|
|
|
info->SectorsPerAllocationUnit = 1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
info->BytesPerSector = 512;
|
|
|
|
info->SectorsPerAllocationUnit = 8;
|
|
|
|
}
|
|
|
|
info->TotalAllocationUnits.QuadPart = bsize * stfs.f_blocks / (info->BytesPerSector * info->SectorsPerAllocationUnit);
|
|
|
|
info->AvailableAllocationUnits.QuadPart = bsize * stfs.f_bavail / (info->BytesPerSector * info->SectorsPerAllocationUnit);
|
2004-04-06 06:19:41 +02:00
|
|
|
io->Information = sizeof(*info);
|
|
|
|
io->u.Status = STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case FileFsDeviceInformation:
|
|
|
|
if (length < sizeof(FILE_FS_DEVICE_INFORMATION))
|
|
|
|
io->u.Status = STATUS_BUFFER_TOO_SMALL;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
FILE_FS_DEVICE_INFORMATION *info = buffer;
|
|
|
|
|
2006-11-03 15:20:21 +01:00
|
|
|
if ((io->u.Status = get_device_info( fd, info )) == STATUS_SUCCESS)
|
2005-08-24 20:27:27 +02:00
|
|
|
io->Information = sizeof(*info);
|
2004-04-06 06:19:41 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case FileFsAttributeInformation:
|
2020-03-27 16:32:31 +01:00
|
|
|
{
|
|
|
|
static const WCHAR fatW[] = {'F','A','T'};
|
|
|
|
static const WCHAR fat32W[] = {'F','A','T','3','2'};
|
|
|
|
static const WCHAR ntfsW[] = {'N','T','F','S'};
|
|
|
|
static const WCHAR cdfsW[] = {'C','D','F','S'};
|
|
|
|
static const WCHAR udfW[] = {'U','D','F'};
|
|
|
|
|
|
|
|
FILE_FS_ATTRIBUTE_INFORMATION *info = buffer;
|
|
|
|
struct mountmgr_unix_drive *drive;
|
|
|
|
enum mountmgr_fs_type fs_type = MOUNTMGR_FS_TYPE_NTFS;
|
|
|
|
|
|
|
|
if (length < sizeof(FILE_FS_ATTRIBUTE_INFORMATION))
|
|
|
|
{
|
|
|
|
io->u.Status = STATUS_INFO_LENGTH_MISMATCH;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((drive = get_mountmgr_fs_info( handle, fd )))
|
|
|
|
{
|
|
|
|
fs_type = drive->fs_type;
|
|
|
|
RtlFreeHeap( GetProcessHeap(), 0, drive );
|
|
|
|
}
|
2013-03-25 16:07:33 +01:00
|
|
|
else
|
|
|
|
{
|
2020-03-27 16:32:31 +01:00
|
|
|
struct statfs stfs;
|
2013-03-25 16:07:33 +01:00
|
|
|
|
2020-03-27 16:32:31 +01:00
|
|
|
if (!fstatfs( fd, &stfs ))
|
|
|
|
{
|
|
|
|
#if defined(linux) && defined(HAVE_FSTATFS)
|
|
|
|
switch (stfs.f_type)
|
|
|
|
{
|
|
|
|
case 0x9660:
|
|
|
|
fs_type = MOUNTMGR_FS_TYPE_ISO9660;
|
|
|
|
break;
|
|
|
|
case 0x15013346:
|
|
|
|
fs_type = MOUNTMGR_FS_TYPE_UDF;
|
|
|
|
break;
|
|
|
|
case 0x4d44:
|
|
|
|
fs_type = MOUNTMGR_FS_TYPE_FAT32;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
#elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__OpenBSD__) || defined(__DragonFly__) || defined(__APPLE__)
|
|
|
|
if (!strcmp( stfs.f_fstypename, "cd9660" ))
|
|
|
|
fs_type = MOUNTMGR_FS_TYPE_ISO9660;
|
|
|
|
else if (!strcmp( stfs.f_fstypename, "udf" ))
|
|
|
|
fs_type = MOUNTMGR_FS_TYPE_UDF;
|
|
|
|
else if (!strcmp( stfs.f_fstypename, "msdos" ))
|
|
|
|
fs_type = MOUNTMGR_FS_TYPE_FAT32;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
2013-03-25 16:07:33 +01:00
|
|
|
|
2020-03-27 16:32:31 +01:00
|
|
|
switch (fs_type)
|
|
|
|
{
|
|
|
|
case MOUNTMGR_FS_TYPE_ISO9660:
|
|
|
|
info->FileSystemAttributes = FILE_READ_ONLY_VOLUME;
|
|
|
|
info->MaximumComponentNameLength = 221;
|
|
|
|
info->FileSystemNameLength = min( sizeof(cdfsW), length - offsetof( FILE_FS_ATTRIBUTE_INFORMATION, FileSystemName ) );
|
|
|
|
memcpy(info->FileSystemName, cdfsW, info->FileSystemNameLength);
|
|
|
|
break;
|
|
|
|
case MOUNTMGR_FS_TYPE_UDF:
|
|
|
|
info->FileSystemAttributes = FILE_READ_ONLY_VOLUME | FILE_UNICODE_ON_DISK | FILE_CASE_SENSITIVE_SEARCH;
|
|
|
|
info->MaximumComponentNameLength = 255;
|
|
|
|
info->FileSystemNameLength = min( sizeof(udfW), length - offsetof( FILE_FS_ATTRIBUTE_INFORMATION, FileSystemName ) );
|
|
|
|
memcpy(info->FileSystemName, udfW, info->FileSystemNameLength);
|
|
|
|
break;
|
|
|
|
case MOUNTMGR_FS_TYPE_FAT:
|
|
|
|
info->FileSystemAttributes = FILE_CASE_PRESERVED_NAMES; /* FIXME */
|
|
|
|
info->MaximumComponentNameLength = 255;
|
|
|
|
info->FileSystemNameLength = min( sizeof(fatW), length - offsetof( FILE_FS_ATTRIBUTE_INFORMATION, FileSystemName ) );
|
|
|
|
memcpy(info->FileSystemName, fatW, info->FileSystemNameLength);
|
|
|
|
break;
|
|
|
|
case MOUNTMGR_FS_TYPE_FAT32:
|
|
|
|
info->FileSystemAttributes = FILE_CASE_PRESERVED_NAMES; /* FIXME */
|
|
|
|
info->MaximumComponentNameLength = 255;
|
|
|
|
info->FileSystemNameLength = min( sizeof(fat32W), length - offsetof( FILE_FS_ATTRIBUTE_INFORMATION, FileSystemName ) );
|
|
|
|
memcpy(info->FileSystemName, fat32W, info->FileSystemNameLength);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
info->FileSystemAttributes = FILE_CASE_PRESERVED_NAMES | FILE_PERSISTENT_ACLS;
|
|
|
|
info->MaximumComponentNameLength = 255;
|
|
|
|
info->FileSystemNameLength = min( sizeof(ntfsW), length - offsetof( FILE_FS_ATTRIBUTE_INFORMATION, FileSystemName ) );
|
|
|
|
memcpy(info->FileSystemName, ntfsW, info->FileSystemNameLength);
|
|
|
|
break;
|
2013-03-25 16:07:33 +01:00
|
|
|
}
|
2020-03-27 16:32:31 +01:00
|
|
|
|
|
|
|
io->Information = offsetof( FILE_FS_ATTRIBUTE_INFORMATION, FileSystemName ) + info->FileSystemNameLength;
|
|
|
|
io->u.Status = STATUS_SUCCESS;
|
2004-04-06 06:19:41 +02:00
|
|
|
break;
|
2020-03-27 16:32:31 +01:00
|
|
|
}
|
2020-03-27 16:32:33 +01:00
|
|
|
case FileFsVolumeInformation:
|
|
|
|
{
|
|
|
|
FILE_FS_VOLUME_INFORMATION *info = buffer;
|
|
|
|
struct mountmgr_unix_drive *drive;
|
|
|
|
const WCHAR *label;
|
|
|
|
|
|
|
|
if (length < sizeof(FILE_FS_VOLUME_INFORMATION))
|
|
|
|
{
|
|
|
|
io->u.Status = STATUS_INFO_LENGTH_MISMATCH;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!(drive = get_mountmgr_fs_info( handle, fd )))
|
|
|
|
{
|
|
|
|
io->u.Status = STATUS_NOT_IMPLEMENTED;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
label = (WCHAR *)((char *)drive + drive->label_offset);
|
|
|
|
info->VolumeCreationTime.QuadPart = 0; /* FIXME */
|
|
|
|
info->VolumeSerialNumber = drive->serial;
|
|
|
|
info->VolumeLabelLength = min( wcslen( label ) * sizeof(WCHAR),
|
|
|
|
length - offsetof( FILE_FS_VOLUME_INFORMATION, VolumeLabel ) );
|
|
|
|
info->SupportsObjects = (drive->fs_type == MOUNTMGR_FS_TYPE_NTFS);
|
|
|
|
memcpy( info->VolumeLabel, label, info->VolumeLabelLength );
|
|
|
|
RtlFreeHeap( GetProcessHeap(), 0, drive );
|
|
|
|
|
|
|
|
io->Information = offsetof( FILE_FS_VOLUME_INFORMATION, VolumeLabel ) + info->VolumeLabelLength;
|
|
|
|
io->u.Status = STATUS_SUCCESS;
|
|
|
|
break;
|
|
|
|
}
|
2004-04-06 06:19:41 +02:00
|
|
|
case FileFsControlInformation:
|
|
|
|
FIXME( "%p: control info not supported\n", handle );
|
|
|
|
break;
|
|
|
|
case FileFsFullSizeInformation:
|
|
|
|
FIXME( "%p: full size info not supported\n", handle );
|
|
|
|
break;
|
|
|
|
case FileFsObjectIdInformation:
|
|
|
|
FIXME( "%p: object id info not supported\n", handle );
|
|
|
|
break;
|
|
|
|
case FileFsMaximumInformation:
|
|
|
|
FIXME( "%p: maximum info not supported\n", handle );
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
io->u.Status = STATUS_INVALID_PARAMETER;
|
|
|
|
break;
|
|
|
|
}
|
2006-11-03 11:38:44 +01:00
|
|
|
if (needs_close) close( fd );
|
2004-04-06 06:19:41 +02:00
|
|
|
return io->u.Status;
|
- implementation of RtlReg* (read access), RtlEvent*, RtlSemaphore*,
NtAllocateLocallyUniqueId
- implementation or stubs for NtAccessCheck, NtSetSecurityObject,
RtlClearBits, RtlEqualPrefixSid, RtlFindClearBits,
RtlFormatCurrentUserKeyPath, RtlGetControlSecurityDescriptor,
RtlIdentifierAuthoritySid, RtlImpersonateSelf, RtlInitializeBitMap,
RtlInitializeGenericTable, RtlMakeSelfRelativeSD,
RtlPrefixUnicodeString, RtlSetBits, RtlUnicodeToMultiByteN,
RtlUpcaseUnicodeStringToOemString, RtlUpcaseUnicodeToOemN,
RtlValidSid, RtlxUnicodeStringToOemSize
- corrected most RtlString* functions, added documentation
- more fixes and partial implementations
2000-01-23 23:35:33 +01:00
|
|
|
}
|
2003-04-22 06:04:17 +02:00
|
|
|
|
2004-04-06 06:19:41 +02:00
|
|
|
|
2008-09-23 19:12:19 +02:00
|
|
|
/******************************************************************
|
|
|
|
* NtQueryEaFile (NTDLL.@)
|
|
|
|
*
|
|
|
|
* Read extended attributes from NTFS files.
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* hFile [I] File handle, must be opened with FILE_READ_EA access
|
|
|
|
* iosb [O] Receives information about the operation on return
|
|
|
|
* buffer [O] Output buffer
|
|
|
|
* length [I] Length of output buffer
|
|
|
|
* single_entry [I] Only read and return one entry
|
|
|
|
* ea_list [I] Optional list with names of EAs to return
|
|
|
|
* ea_list_len [I] Length of ea_list in bytes
|
|
|
|
* ea_index [I] Optional pointer to 1-based index of attribute to return
|
|
|
|
* restart [I] restart EA scan
|
|
|
|
*
|
|
|
|
* RETURNS
|
2019-12-12 11:22:59 +01:00
|
|
|
* Success: 0. Attributes read into buffer
|
2008-09-23 19:12:19 +02:00
|
|
|
* Failure: An NTSTATUS error code describing the error.
|
|
|
|
*/
|
|
|
|
NTSTATUS WINAPI NtQueryEaFile( HANDLE hFile, PIO_STATUS_BLOCK iosb, PVOID buffer, ULONG length,
|
|
|
|
BOOLEAN single_entry, PVOID ea_list, ULONG ea_list_len,
|
|
|
|
PULONG ea_index, BOOLEAN restart )
|
|
|
|
{
|
|
|
|
FIXME("(%p,%p,%p,%d,%d,%p,%d,%p,%d) stub\n",
|
|
|
|
hFile, iosb, buffer, length, single_entry, ea_list,
|
|
|
|
ea_list_len, ea_index, restart);
|
|
|
|
return STATUS_ACCESS_DENIED;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/******************************************************************
|
|
|
|
* NtSetEaFile (NTDLL.@)
|
|
|
|
*
|
|
|
|
* Update extended attributes for NTFS files.
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* hFile [I] File handle, must be opened with FILE_READ_EA access
|
|
|
|
* iosb [O] Receives information about the operation on return
|
|
|
|
* buffer [I] Buffer with EA information
|
|
|
|
* length [I] Length of buffer
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Success: 0. Attributes are updated
|
|
|
|
* Failure: An NTSTATUS error code describing the error.
|
|
|
|
*/
|
|
|
|
NTSTATUS WINAPI NtSetEaFile( HANDLE hFile, PIO_STATUS_BLOCK iosb, PVOID buffer, ULONG length )
|
|
|
|
{
|
|
|
|
FIXME("(%p,%p,%p,%d) stub\n", hFile, iosb, buffer, length);
|
|
|
|
return STATUS_ACCESS_DENIED;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-04-22 06:04:17 +02:00
|
|
|
/******************************************************************
|
|
|
|
* NtFlushBuffersFile (NTDLL.@)
|
2003-07-19 00:55:28 +02:00
|
|
|
*
|
|
|
|
* Flush any buffered data on an open file handle.
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* FileHandle [I] Handle returned from ZwOpenFile() or ZwCreateFile()
|
|
|
|
* IoStatusBlock [O] Receives information about the operation on return
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Success: 0. IoStatusBlock is updated.
|
|
|
|
* Failure: An NTSTATUS error code describing the error.
|
2003-04-22 06:04:17 +02:00
|
|
|
*/
|
2018-10-20 19:19:17 +02:00
|
|
|
NTSTATUS WINAPI NtFlushBuffersFile( HANDLE hFile, IO_STATUS_BLOCK *io )
|
2003-04-22 06:04:17 +02:00
|
|
|
{
|
|
|
|
NTSTATUS ret;
|
2018-10-20 19:19:17 +02:00
|
|
|
HANDLE wait_handle;
|
2009-01-20 17:52:38 +01:00
|
|
|
enum server_fd_type type;
|
|
|
|
int fd, needs_close;
|
2003-05-15 06:22:45 +02:00
|
|
|
|
2020-06-02 17:08:59 +02:00
|
|
|
if (!io || !unix_funcs->virtual_check_buffer_for_write( io, sizeof(*io) )) return STATUS_ACCESS_VIOLATION;
|
2018-10-20 19:19:17 +02:00
|
|
|
|
2020-05-29 15:35:16 +02:00
|
|
|
ret = unix_funcs->server_get_unix_fd( hFile, FILE_WRITE_DATA, &fd, &needs_close, &type, NULL );
|
2017-03-03 16:21:08 +01:00
|
|
|
if (ret == STATUS_ACCESS_DENIED)
|
2020-05-29 15:35:16 +02:00
|
|
|
ret = unix_funcs->server_get_unix_fd( hFile, FILE_APPEND_DATA, &fd, &needs_close, &type, NULL );
|
2009-01-20 17:52:38 +01:00
|
|
|
|
|
|
|
if (!ret && type == FD_TYPE_SERIAL)
|
2003-04-22 06:04:17 +02:00
|
|
|
{
|
2013-09-05 00:10:19 +02:00
|
|
|
ret = COMM_FlushBuffersFile( fd );
|
2003-04-22 06:04:17 +02:00
|
|
|
}
|
2017-03-01 12:05:54 +01:00
|
|
|
else if (ret != STATUS_ACCESS_DENIED)
|
2003-05-15 06:22:45 +02:00
|
|
|
{
|
2018-10-30 16:08:48 +01:00
|
|
|
struct async_irp *async;
|
|
|
|
|
|
|
|
if (!(async = (struct async_irp *)alloc_fileio( sizeof(*async), irp_completion, hFile )))
|
|
|
|
return STATUS_NO_MEMORY;
|
|
|
|
async->buffer = NULL;
|
|
|
|
async->size = 0;
|
|
|
|
|
2015-05-05 05:23:08 +02:00
|
|
|
SERVER_START_REQ( flush )
|
2009-01-20 17:52:38 +01:00
|
|
|
{
|
2018-10-30 16:08:48 +01:00
|
|
|
req->async = server_async( hFile, &async->io, NULL, NULL, NULL, io );
|
2009-01-20 17:52:38 +01:00
|
|
|
ret = wine_server_call( req );
|
2018-10-20 19:19:17 +02:00
|
|
|
wait_handle = wine_server_ptr_handle( reply->event );
|
|
|
|
if (wait_handle && ret != STATUS_PENDING)
|
|
|
|
{
|
|
|
|
io->u.Status = ret;
|
|
|
|
io->Information = 0;
|
|
|
|
}
|
2009-01-20 17:52:38 +01:00
|
|
|
}
|
|
|
|
SERVER_END_REQ;
|
2015-05-05 05:23:08 +02:00
|
|
|
|
2018-10-30 16:08:48 +01:00
|
|
|
if (ret != STATUS_PENDING) RtlFreeHeap( GetProcessHeap(), 0, async );
|
|
|
|
|
2019-05-23 19:35:51 +02:00
|
|
|
if (wait_handle) ret = wait_async( wait_handle, FALSE, io );
|
2003-05-15 06:22:45 +02:00
|
|
|
}
|
2009-01-20 17:52:38 +01:00
|
|
|
|
|
|
|
if (needs_close) close( fd );
|
2003-04-22 06:04:17 +02:00
|
|
|
return ret;
|
|
|
|
}
|
2003-06-24 04:32:01 +02:00
|
|
|
|
|
|
|
/******************************************************************
|
|
|
|
* NtLockFile (NTDLL.@)
|
|
|
|
*
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
NTSTATUS WINAPI NtLockFile( HANDLE hFile, HANDLE lock_granted_event,
|
2003-07-19 00:55:28 +02:00
|
|
|
PIO_APC_ROUTINE apc, void* apc_user,
|
|
|
|
PIO_STATUS_BLOCK io_status, PLARGE_INTEGER offset,
|
2003-06-24 04:32:01 +02:00
|
|
|
PLARGE_INTEGER count, ULONG* key, BOOLEAN dont_wait,
|
|
|
|
BOOLEAN exclusive )
|
|
|
|
{
|
|
|
|
NTSTATUS ret;
|
|
|
|
HANDLE handle;
|
|
|
|
BOOLEAN async;
|
2008-10-07 20:07:22 +02:00
|
|
|
static BOOLEAN warn = TRUE;
|
2003-06-24 04:32:01 +02:00
|
|
|
|
|
|
|
if (apc || io_status || key)
|
|
|
|
{
|
|
|
|
FIXME("Unimplemented yet parameter\n");
|
|
|
|
return STATUS_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
2008-10-07 20:07:22 +02:00
|
|
|
if (apc_user && warn)
|
|
|
|
{
|
|
|
|
FIXME("I/O completion on lock not implemented yet\n");
|
|
|
|
warn = FALSE;
|
|
|
|
}
|
2007-11-09 23:12:07 +01:00
|
|
|
|
2003-06-24 04:32:01 +02:00
|
|
|
for (;;)
|
|
|
|
{
|
|
|
|
SERVER_START_REQ( lock_file )
|
|
|
|
{
|
2008-12-08 16:05:17 +01:00
|
|
|
req->handle = wine_server_obj_handle( hFile );
|
2007-10-10 14:06:25 +02:00
|
|
|
req->offset = offset->QuadPart;
|
|
|
|
req->count = count->QuadPart;
|
2003-06-24 04:32:01 +02:00
|
|
|
req->shared = !exclusive;
|
|
|
|
req->wait = !dont_wait;
|
|
|
|
ret = wine_server_call( req );
|
2008-12-08 16:05:17 +01:00
|
|
|
handle = wine_server_ptr_handle( reply->handle );
|
2003-06-24 04:32:01 +02:00
|
|
|
async = reply->overlapped;
|
|
|
|
}
|
|
|
|
SERVER_END_REQ;
|
|
|
|
if (ret != STATUS_PENDING)
|
|
|
|
{
|
|
|
|
if (!ret && lock_granted_event) NtSetEvent(lock_granted_event, NULL);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (async)
|
|
|
|
{
|
|
|
|
FIXME( "Async I/O lock wait not implemented, might deadlock\n" );
|
|
|
|
if (handle) NtClose( handle );
|
|
|
|
return STATUS_PENDING;
|
|
|
|
}
|
|
|
|
if (handle)
|
|
|
|
{
|
|
|
|
NtWaitForSingleObject( handle, FALSE, NULL );
|
|
|
|
NtClose( handle );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
LARGE_INTEGER time;
|
|
|
|
|
|
|
|
/* Unix lock conflict, sleep a bit and retry */
|
|
|
|
time.QuadPart = 100 * (ULONGLONG)10000;
|
|
|
|
time.QuadPart = -time.QuadPart;
|
2003-06-30 23:00:15 +02:00
|
|
|
NtDelayExecution( FALSE, &time );
|
2003-06-24 04:32:01 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/******************************************************************
|
|
|
|
* NtUnlockFile (NTDLL.@)
|
|
|
|
*
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
NTSTATUS WINAPI NtUnlockFile( HANDLE hFile, PIO_STATUS_BLOCK io_status,
|
|
|
|
PLARGE_INTEGER offset, PLARGE_INTEGER count,
|
|
|
|
PULONG key )
|
|
|
|
{
|
|
|
|
NTSTATUS status;
|
|
|
|
|
2006-10-16 13:49:06 +02:00
|
|
|
TRACE( "%p %x%08x %x%08x\n",
|
2004-01-23 02:51:33 +01:00
|
|
|
hFile, offset->u.HighPart, offset->u.LowPart, count->u.HighPart, count->u.LowPart );
|
2003-06-24 04:32:01 +02:00
|
|
|
|
|
|
|
if (io_status || key)
|
|
|
|
{
|
|
|
|
FIXME("Unimplemented yet parameter\n");
|
|
|
|
return STATUS_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
SERVER_START_REQ( unlock_file )
|
|
|
|
{
|
2008-12-08 16:05:17 +01:00
|
|
|
req->handle = wine_server_obj_handle( hFile );
|
2007-10-10 14:06:25 +02:00
|
|
|
req->offset = offset->QuadPart;
|
|
|
|
req->count = count->QuadPart;
|
2003-06-24 04:32:01 +02:00
|
|
|
status = wine_server_call( req );
|
|
|
|
}
|
|
|
|
SERVER_END_REQ;
|
|
|
|
return status;
|
|
|
|
}
|
2004-08-16 23:08:38 +02:00
|
|
|
|
|
|
|
/******************************************************************
|
|
|
|
* NtCreateNamedPipeFile (NTDLL.@)
|
|
|
|
*
|
|
|
|
*
|
|
|
|
*/
|
2005-04-18 16:57:04 +02:00
|
|
|
NTSTATUS WINAPI NtCreateNamedPipeFile( PHANDLE handle, ULONG access,
|
2005-10-26 12:11:08 +02:00
|
|
|
POBJECT_ATTRIBUTES attr, PIO_STATUS_BLOCK iosb,
|
2005-04-18 16:57:04 +02:00
|
|
|
ULONG sharing, ULONG dispo, ULONG options,
|
|
|
|
ULONG pipe_type, ULONG read_mode,
|
|
|
|
ULONG completion_mode, ULONG max_inst,
|
|
|
|
ULONG inbound_quota, ULONG outbound_quota,
|
|
|
|
PLARGE_INTEGER timeout)
|
2004-08-16 23:08:38 +02:00
|
|
|
{
|
2014-11-12 11:25:23 +01:00
|
|
|
NTSTATUS status;
|
2016-01-15 09:40:56 +01:00
|
|
|
data_size_t len;
|
|
|
|
struct object_attributes *objattr;
|
2005-04-18 16:57:04 +02:00
|
|
|
|
2019-04-06 22:54:31 +02:00
|
|
|
if (!attr) return STATUS_INVALID_PARAMETER;
|
|
|
|
|
2006-10-16 13:49:06 +02:00
|
|
|
TRACE("(%p %x %s %p %x %d %x %d %d %d %d %d %d %p)\n",
|
2019-04-06 22:54:31 +02:00
|
|
|
handle, access, debugstr_us(attr->ObjectName), iosb, sharing, dispo,
|
2005-08-16 17:57:59 +02:00
|
|
|
options, pipe_type, read_mode, completion_mode, max_inst, inbound_quota,
|
|
|
|
outbound_quota, timeout);
|
2005-04-18 16:57:04 +02:00
|
|
|
|
2007-04-17 20:08:59 +02:00
|
|
|
/* assume we only get relative timeout */
|
|
|
|
if (timeout->QuadPart > 0)
|
2005-04-18 16:57:04 +02:00
|
|
|
FIXME("Wrong time %s\n", wine_dbgstr_longlong(timeout->QuadPart));
|
|
|
|
|
2016-01-15 09:40:56 +01:00
|
|
|
if ((status = alloc_object_attributes( attr, &objattr, &len ))) return status;
|
2014-11-12 11:25:23 +01:00
|
|
|
|
2005-04-18 16:57:04 +02:00
|
|
|
SERVER_START_REQ( create_named_pipe )
|
|
|
|
{
|
2005-09-26 13:02:45 +02:00
|
|
|
req->access = access;
|
|
|
|
req->options = options;
|
2011-09-26 13:57:15 +02:00
|
|
|
req->sharing = sharing;
|
2005-04-18 16:57:04 +02:00
|
|
|
req->flags =
|
2011-12-11 20:10:32 +01:00
|
|
|
(pipe_type ? NAMED_PIPE_MESSAGE_STREAM_WRITE : 0) |
|
|
|
|
(read_mode ? NAMED_PIPE_MESSAGE_STREAM_READ : 0) |
|
|
|
|
(completion_mode ? NAMED_PIPE_NONBLOCKING_MODE : 0);
|
2005-04-18 16:57:04 +02:00
|
|
|
req->maxinstances = max_inst;
|
|
|
|
req->outsize = outbound_quota;
|
|
|
|
req->insize = inbound_quota;
|
2007-04-17 20:08:59 +02:00
|
|
|
req->timeout = timeout->QuadPart;
|
2016-01-15 09:40:56 +01:00
|
|
|
wine_server_add_data( req, objattr, len );
|
2005-04-18 16:57:04 +02:00
|
|
|
status = wine_server_call( req );
|
2008-12-08 16:05:17 +01:00
|
|
|
if (!status) *handle = wine_server_ptr_handle( reply->handle );
|
2005-04-18 16:57:04 +02:00
|
|
|
}
|
|
|
|
SERVER_END_REQ;
|
2014-11-12 11:25:23 +01:00
|
|
|
|
2016-01-15 09:40:56 +01:00
|
|
|
RtlFreeHeap( GetProcessHeap(), 0, objattr );
|
2005-04-18 16:57:04 +02:00
|
|
|
return status;
|
2004-08-16 23:08:38 +02:00
|
|
|
}
|
2004-08-27 21:11:01 +02:00
|
|
|
|
|
|
|
/******************************************************************
|
|
|
|
* NtDeleteFile (NTDLL.@)
|
|
|
|
*
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
NTSTATUS WINAPI NtDeleteFile( POBJECT_ATTRIBUTES ObjectAttributes )
|
|
|
|
{
|
2004-11-21 16:29:44 +01:00
|
|
|
NTSTATUS status;
|
|
|
|
HANDLE hFile;
|
|
|
|
IO_STATUS_BLOCK io;
|
|
|
|
|
|
|
|
TRACE("%p\n", ObjectAttributes);
|
2006-01-27 15:50:38 +01:00
|
|
|
status = NtCreateFile( &hFile, GENERIC_READ | GENERIC_WRITE | DELETE,
|
|
|
|
ObjectAttributes, &io, NULL, 0,
|
2004-11-21 16:29:44 +01:00
|
|
|
FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,
|
|
|
|
FILE_OPEN, FILE_DELETE_ON_CLOSE, NULL, 0 );
|
|
|
|
if (status == STATUS_SUCCESS) status = NtClose(hFile);
|
|
|
|
return status;
|
2004-08-27 21:11:01 +02:00
|
|
|
}
|
|
|
|
|
2009-08-09 06:11:30 +02:00
|
|
|
/******************************************************************
|
|
|
|
* NtCancelIoFileEx (NTDLL.@)
|
|
|
|
*
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
NTSTATUS WINAPI NtCancelIoFileEx( HANDLE hFile, PIO_STATUS_BLOCK iosb, PIO_STATUS_BLOCK io_status )
|
|
|
|
{
|
|
|
|
TRACE("%p %p %p\n", hFile, iosb, io_status );
|
|
|
|
|
|
|
|
SERVER_START_REQ( cancel_async )
|
|
|
|
{
|
|
|
|
req->handle = wine_server_obj_handle( hFile );
|
|
|
|
req->iosb = wine_server_client_ptr( iosb );
|
|
|
|
req->only_thread = FALSE;
|
|
|
|
io_status->u.Status = wine_server_call( req );
|
|
|
|
}
|
|
|
|
SERVER_END_REQ;
|
2015-05-07 08:13:34 +02:00
|
|
|
|
2009-08-09 06:11:30 +02:00
|
|
|
return io_status->u.Status;
|
|
|
|
}
|
|
|
|
|
2004-08-27 21:11:01 +02:00
|
|
|
/******************************************************************
|
|
|
|
* NtCancelIoFile (NTDLL.@)
|
|
|
|
*
|
|
|
|
*
|
|
|
|
*/
|
2005-01-14 20:54:38 +01:00
|
|
|
NTSTATUS WINAPI NtCancelIoFile( HANDLE hFile, PIO_STATUS_BLOCK io_status )
|
2004-08-27 21:11:01 +02:00
|
|
|
{
|
2005-01-14 20:54:38 +01:00
|
|
|
TRACE("%p %p\n", hFile, io_status );
|
|
|
|
|
|
|
|
SERVER_START_REQ( cancel_async )
|
|
|
|
{
|
2009-08-09 06:11:30 +02:00
|
|
|
req->handle = wine_server_obj_handle( hFile );
|
|
|
|
req->iosb = 0;
|
|
|
|
req->only_thread = TRUE;
|
|
|
|
io_status->u.Status = wine_server_call( req );
|
2005-01-14 20:54:38 +01:00
|
|
|
}
|
|
|
|
SERVER_END_REQ;
|
2015-05-07 08:13:34 +02:00
|
|
|
|
2009-08-09 06:11:30 +02:00
|
|
|
return io_status->u.Status;
|
2004-08-27 21:11:01 +02:00
|
|
|
}
|
2005-03-28 12:03:56 +02:00
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* NtCreateMailslotFile [NTDLL.@]
|
|
|
|
* ZwCreateMailslotFile [NTDLL.@]
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* pHandle [O] pointer to receive the handle created
|
|
|
|
* DesiredAccess [I] access mode (read, write, etc)
|
|
|
|
* ObjectAttributes [I] fully qualified NT path of the mailslot
|
|
|
|
* IoStatusBlock [O] receives completion status and other info
|
|
|
|
* CreateOptions [I]
|
|
|
|
* MailslotQuota [I]
|
|
|
|
* MaxMessageSize [I]
|
|
|
|
* TimeOut [I]
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* An NT status code
|
|
|
|
*/
|
|
|
|
NTSTATUS WINAPI NtCreateMailslotFile(PHANDLE pHandle, ULONG DesiredAccess,
|
|
|
|
POBJECT_ATTRIBUTES attr, PIO_STATUS_BLOCK IoStatusBlock,
|
|
|
|
ULONG CreateOptions, ULONG MailslotQuota, ULONG MaxMessageSize,
|
|
|
|
PLARGE_INTEGER TimeOut)
|
|
|
|
{
|
2007-02-27 13:42:06 +01:00
|
|
|
LARGE_INTEGER timeout;
|
2005-03-28 12:03:56 +02:00
|
|
|
NTSTATUS ret;
|
2016-01-15 10:57:02 +01:00
|
|
|
data_size_t len;
|
|
|
|
struct object_attributes *objattr;
|
2005-03-28 12:03:56 +02:00
|
|
|
|
2006-10-16 13:49:06 +02:00
|
|
|
TRACE("%p %08x %p %p %08x %08x %08x %p\n",
|
2005-03-28 12:03:56 +02:00
|
|
|
pHandle, DesiredAccess, attr, IoStatusBlock,
|
|
|
|
CreateOptions, MailslotQuota, MaxMessageSize, TimeOut);
|
|
|
|
|
2007-02-27 13:42:02 +01:00
|
|
|
if (!pHandle) return STATUS_ACCESS_VIOLATION;
|
2007-02-27 13:42:10 +01:00
|
|
|
if (!attr) return STATUS_INVALID_PARAMETER;
|
|
|
|
|
2016-01-15 10:57:02 +01:00
|
|
|
if ((ret = alloc_object_attributes( attr, &objattr, &len ))) return ret;
|
|
|
|
|
2007-02-27 13:42:06 +01:00
|
|
|
/*
|
|
|
|
* For a NULL TimeOut pointer set the default timeout value
|
|
|
|
*/
|
|
|
|
if (!TimeOut)
|
|
|
|
timeout.QuadPart = -1;
|
|
|
|
else
|
|
|
|
timeout.QuadPart = TimeOut->QuadPart;
|
|
|
|
|
2005-03-30 21:02:15 +02:00
|
|
|
SERVER_START_REQ( create_mailslot )
|
|
|
|
{
|
2005-10-27 20:30:37 +02:00
|
|
|
req->access = DesiredAccess;
|
2005-03-30 21:02:15 +02:00
|
|
|
req->max_msgsize = MaxMessageSize;
|
2007-04-17 20:08:59 +02:00
|
|
|
req->read_timeout = timeout.QuadPart;
|
2016-01-15 10:57:02 +01:00
|
|
|
wine_server_add_data( req, objattr, len );
|
2005-03-30 21:02:15 +02:00
|
|
|
ret = wine_server_call( req );
|
|
|
|
if( ret == STATUS_SUCCESS )
|
2008-12-08 16:05:17 +01:00
|
|
|
*pHandle = wine_server_ptr_handle( reply->handle );
|
2005-03-30 21:02:15 +02:00
|
|
|
}
|
|
|
|
SERVER_END_REQ;
|
2016-01-15 10:57:02 +01:00
|
|
|
|
|
|
|
RtlFreeHeap( GetProcessHeap(), 0, objattr );
|
2005-03-28 12:03:56 +02:00
|
|
|
return ret;
|
|
|
|
}
|