[2/3] server: Add support for setting file disposition information.
Sebastian Lackner
sebastian at fds-team.de
Wed Aug 19 04:18:01 CDT 2015
Based on a patch by Dmitry Timoshkov.
---
dlls/kernel32/tests/file.c | 1 -
dlls/ntdll/file.c | 16 ++++++++++++++++
dlls/ntdll/tests/file.c | 13 ++-----------
server/fd.c | 44 ++++++++++++++++++++++++++++++++++++++++++++
server/protocol.def | 7 +++++++
5 files changed, 69 insertions(+), 12 deletions(-)
diff --git a/dlls/kernel32/tests/file.c b/dlls/kernel32/tests/file.c
index 53d225c..dd64c91 100644
--- a/dlls/kernel32/tests/file.c
+++ b/dlls/kernel32/tests/file.c
@@ -4645,7 +4645,6 @@ todo_wine
dispinfo.DeleteFile = TRUE;
ret = pSetFileInformationByHandle(file, FileDispositionInfo, &dispinfo, sizeof(dispinfo));
-todo_wine
ok(ret, "setting FileDispositionInfo failed, error %d\n", GetLastError());
CloseHandle(file);
diff --git a/dlls/ntdll/file.c b/dlls/ntdll/file.c
index d081750..314c233 100644
--- a/dlls/ntdll/file.c
+++ b/dlls/ntdll/file.c
@@ -2765,6 +2765,22 @@ NTSTATUS WINAPI NtSetInformationFile(HANDLE handle, PIO_STATUS_BLOCK io,
else io->u.Status = STATUS_INVALID_PARAMETER_3;
break;
+ case FileDispositionInformation:
+ if (len >= sizeof(FILE_DISPOSITION_INFORMATION))
+ {
+ FILE_DISPOSITION_INFORMATION *info = ptr;
+
+ SERVER_START_REQ( set_fd_info )
+ {
+ 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;
+
default:
FIXME("Unsupported class (%d)\n", class);
io->u.Status = STATUS_NOT_IMPLEMENTED;
diff --git a/dlls/ntdll/tests/file.c b/dlls/ntdll/tests/file.c
index 86a4516..57ae15c 100644
--- a/dlls/ntdll/tests/file.c
+++ b/dlls/ntdll/tests/file.c
@@ -1473,7 +1473,6 @@ static void test_file_disposition_information(void)
ok( res == STATUS_INFO_LENGTH_MISMATCH, "expected STATUS_INFO_LENGTH_MISMATCH, got %x\n", res );
fdi2 = 0x100;
res = pNtSetInformationFile( handle, &io, &fdi2, sizeof(fdi2), FileDispositionInformation );
- todo_wine
ok( res == STATUS_SUCCESS, "expected STATUS_SUCCESS, got %x\n", res );
CloseHandle( handle );
fileDeleted = GetFileAttributesA( buffer ) == INVALID_FILE_ATTRIBUTES && GetLastError() == ERROR_FILE_NOT_FOUND;
@@ -1488,7 +1487,6 @@ static void test_file_disposition_information(void)
ok( res == STATUS_INVALID_INFO_CLASS || res == STATUS_NOT_IMPLEMENTED, "Unexpected NtQueryInformationFile result (expected STATUS_INVALID_INFO_CLASS, got %x)\n", res );
fdi.DoDeleteFile = TRUE;
res = pNtSetInformationFile( handle, &io, &fdi, sizeof fdi, FileDispositionInformation );
- todo_wine
ok( res == STATUS_ACCESS_DENIED, "unexpected FileDispositionInformation result (expected STATUS_ACCESS_DENIED, got %x)\n", res );
CloseHandle( handle );
fileDeleted = GetFileAttributesA( buffer ) == INVALID_FILE_ATTRIBUTES && GetLastError() == ERROR_FILE_NOT_FOUND;
@@ -1501,11 +1499,9 @@ static void test_file_disposition_information(void)
ok( handle != INVALID_HANDLE_VALUE, "failed to create temp file\n" );
fdi.DoDeleteFile = TRUE;
res = pNtSetInformationFile( handle, &io, &fdi, sizeof fdi, FileDispositionInformation );
- todo_wine
ok( res == STATUS_SUCCESS, "unexpected FileDispositionInformation result (expected STATUS_SUCCESS, got %x)\n", res );
CloseHandle( handle );
fileDeleted = GetFileAttributesA( buffer ) == INVALID_FILE_ATTRIBUTES && GetLastError() == ERROR_FILE_NOT_FOUND;
- todo_wine
ok( fileDeleted, "File should have been deleted\n" );
DeleteFileA( buffer );
@@ -1519,6 +1515,7 @@ static void test_file_disposition_information(void)
ok( res == STATUS_CANNOT_DELETE, "unexpected FileDispositionInformation result (expected STATUS_CANNOT_DELETE, got %x)\n", res );
CloseHandle( handle );
fileDeleted = GetFileAttributesA( buffer ) == INVALID_FILE_ATTRIBUTES && GetLastError() == ERROR_FILE_NOT_FOUND;
+ todo_wine
ok( !fileDeleted, "File shouldn't have been deleted\n" );
SetFileAttributesA( buffer, FILE_ATTRIBUTE_NORMAL );
DeleteFileA( buffer );
@@ -1529,11 +1526,9 @@ static void test_file_disposition_information(void)
ok( handle != INVALID_HANDLE_VALUE, "failed to create temp file\n" );
fdi.DoDeleteFile = TRUE;
res = pNtSetInformationFile( handle, &io, &fdi, sizeof fdi, FileDispositionInformation );
- todo_wine
ok( res == STATUS_SUCCESS, "unexpected FileDispositionInformation result (expected STATUS_SUCCESS, got %x)\n", res );
fdi.DoDeleteFile = FALSE;
res = pNtSetInformationFile( handle, &io, &fdi, sizeof fdi, FileDispositionInformation );
- todo_wine
ok( res == STATUS_SUCCESS, "unexpected FileDispositionInformation result (expected STATUS_SUCCESS, got %x)\n", res );
CloseHandle( handle );
fileDeleted = GetFileAttributesA( buffer ) == INVALID_FILE_ATTRIBUTES && GetLastError() == ERROR_FILE_NOT_FOUND;
@@ -1546,7 +1541,6 @@ static void test_file_disposition_information(void)
ok( handle != INVALID_HANDLE_VALUE, "failed to create temp file\n" );
fdi.DoDeleteFile = FALSE;
res = pNtSetInformationFile( handle, &io, &fdi, sizeof fdi, FileDispositionInformation );
- todo_wine
ok( res == STATUS_SUCCESS, "unexpected FileDispositionInformation result (expected STATUS_SUCCESS, got %x)\n", res );
CloseHandle( handle );
fileDeleted = GetFileAttributesA( buffer ) == INVALID_FILE_ATTRIBUTES && GetLastError() == ERROR_FILE_NOT_FOUND;
@@ -1561,7 +1555,6 @@ static void test_file_disposition_information(void)
CloseHandle( handle );
fdi.DoDeleteFile = FALSE;
res = pNtSetInformationFile( handle2, &io, &fdi, sizeof fdi, FileDispositionInformation );
- todo_wine
ok( res == STATUS_SUCCESS, "unexpected FileDispositionInformation result (expected STATUS_SUCCESS, got %x)\n", res );
CloseHandle( handle2 );
fileDeleted = GetFileAttributesA( buffer ) == INVALID_FILE_ATTRIBUTES && GetLastError() == ERROR_FILE_NOT_FOUND;
@@ -1576,11 +1569,9 @@ static void test_file_disposition_information(void)
ok( handle != INVALID_HANDLE_VALUE, "failed to open a directory\n" );
fdi.DoDeleteFile = TRUE;
res = pNtSetInformationFile( handle, &io, &fdi, sizeof fdi, FileDispositionInformation );
- todo_wine
ok( res == STATUS_SUCCESS, "unexpected FileDispositionInformation result (expected STATUS_SUCCESS, got %x)\n", res );
CloseHandle( handle );
fileDeleted = GetFileAttributesA( buffer ) == INVALID_FILE_ATTRIBUTES && GetLastError() == ERROR_FILE_NOT_FOUND;
- todo_wine
ok( fileDeleted, "Directory should have been deleted\n" );
RemoveDirectoryA( buffer );
@@ -1593,7 +1584,6 @@ static void test_file_disposition_information(void)
RemoveDirectoryA( buffer );
fdi.DoDeleteFile = FALSE;
res = pNtSetInformationFile( handle, &io, &fdi, sizeof fdi, FileDispositionInformation );
- todo_wine
ok( res == STATUS_SUCCESS, "unexpected FileDispositionInformation result (expected STATUS_SUCCESS, got %x)\n", res );
CloseHandle( handle );
fileDeleted = GetFileAttributesA( buffer ) == INVALID_FILE_ATTRIBUTES && GetLastError() == ERROR_FILE_NOT_FOUND;
@@ -1618,6 +1608,7 @@ static void test_file_disposition_information(void)
buffer[dirpos] = '\0';
CloseHandle( handle );
fileDeleted = GetFileAttributesA( buffer ) == INVALID_FILE_ATTRIBUTES && GetLastError() == ERROR_FILE_NOT_FOUND;
+ todo_wine
ok( !fileDeleted, "Directory shouldn't have been deleted\n" );
RemoveDirectoryA( buffer );
}
diff --git a/server/fd.c b/server/fd.c
index 6b95d6c..f607261 100644
--- a/server/fd.c
+++ b/server/fd.c
@@ -2214,6 +2214,39 @@ static struct fd *get_handle_fd_obj( struct process *process, obj_handle_t handl
return fd;
}
+/* set disposition for the fd */
+static void set_fd_disposition( struct fd *fd, int unlink )
+{
+ struct stat st;
+
+ if (!fd->inode)
+ {
+ set_error( STATUS_OBJECT_TYPE_MISMATCH );
+ return;
+ }
+
+ if (fd->unix_fd == -1)
+ {
+ set_error( fd->no_fd_status );
+ return;
+ }
+
+ if (fstat( fd->unix_fd, &st ) == -1)
+ {
+ file_set_error();
+ return;
+ }
+
+ /* can't unlink special files */
+ if (unlink && !S_ISDIR(st.st_mode) && !S_ISREG(st.st_mode))
+ {
+ set_error( STATUS_INVALID_PARAMETER );
+ return;
+ }
+
+ fd->closed->unlink = unlink || (fd->options & FILE_DELETE_ON_CLOSE);
+}
+
struct completion *fd_get_completion( struct fd *fd, apc_param_t *p_key )
{
*p_key = fd->comp_key;
@@ -2409,3 +2442,14 @@ DECL_HANDLER(add_fd_completion)
release_object( fd );
}
}
+
+/* set fd information */
+DECL_HANDLER(set_fd_info)
+{
+ struct fd *fd = get_handle_fd_obj( current->process, req->handle, DELETE );
+ if (fd)
+ {
+ set_fd_disposition( fd, req->unlink );
+ release_object( fd );
+ }
+}
diff --git a/server/protocol.def b/server/protocol.def
index ffee0c0..ea9eb12 100644
--- a/server/protocol.def
+++ b/server/protocol.def
@@ -3525,6 +3525,13 @@ enum coords_relative
@END
+/* set fd information */
+ at REQ(set_fd_info)
+ obj_handle_t handle; /* handle to a file or directory */
+ int unlink; /* whether to unlink file on close */
+ at END
+
+
/* Retrieve layered info for a window */
@REQ(get_window_layered_info)
user_handle_t handle; /* handle to the window */
--
2.5.0
More information about the wine-patches
mailing list