server: Fix overlapping shared and exclusive locks support.

Alexander Morozov amorozov at etersoft.ru
Wed Oct 12 06:29:28 CDT 2011


Added check for equal handles. Locks are added to the end of lists so that the 
first lock was found first when removing. Now it is sufficient to add locks to 
the end of fd->locks list but I add to the end for all lists to prevent bugs 
if the code will be changed later.
-------------- next part --------------
From e2fd297f72dee3ab9ec9e3ce06de11b9e2cc6311 Mon Sep 17 00:00:00 2001
From: Alexander Morozov <amorozov at etersoft.ru>
Date: Wed, 12 Oct 2011 14:58:57 +0400
Subject: [PATCH] server: Fix overlapping shared and exclusive locks support.

---
 dlls/kernel32/tests/file.c |    1 -
 server/fd.c                |    8 ++++----
 2 files changed, 4 insertions(+), 5 deletions(-)

diff --git a/dlls/kernel32/tests/file.c b/dlls/kernel32/tests/file.c
index f607cfd..a720d52 100644
--- a/dlls/kernel32/tests/file.c
+++ b/dlls/kernel32/tests/file.c
@@ -1671,7 +1671,6 @@ static void test_LockFile(void)
     ok( !LockFileEx( handle2, LOCKFILE_FAIL_IMMEDIATELY, 0, 100, 0, &overlapped ),
         "LockFileEx handle2 300,100 succeeded\n" );
     ret = LockFileEx( handle, LOCKFILE_FAIL_IMMEDIATELY, 0, 100, 0, &overlapped );
-    todo_wine
     ok( ret, "LockFileEx 300,100 failed\n" );
     ok( UnlockFileEx( handle, 0, 100, 0, &overlapped ), "UnlockFileEx 300,100 failed\n" );
     /* exclusive lock is removed first */
diff --git a/server/fd.c b/server/fd.c
index 798f99e..a8b3a5f 100644
--- a/server/fd.c
+++ b/server/fd.c
@@ -1321,9 +1321,9 @@ static struct file_lock *add_lock( struct fd *fd, int shared, file_pos_t start,
         release_object( lock );
         return NULL;
     }
-    list_add_head( &fd->locks, &lock->fd_entry );
-    list_add_head( &fd->inode->locks, &lock->inode_entry );
-    list_add_head( &lock->process->locks, &lock->proc_entry );
+    list_add_tail( &fd->locks, &lock->fd_entry );
+    list_add_tail( &fd->inode->locks, &lock->inode_entry );
+    list_add_tail( &lock->process->locks, &lock->proc_entry );
     return lock;
 }
 
@@ -1395,7 +1395,7 @@ obj_handle_t lock_fd( struct fd *fd, file_pos_t start, file_pos_t count, int sha
     {
         struct file_lock *lock = LIST_ENTRY( ptr, struct file_lock, inode_entry );
         if (!lock_overlaps( lock, start, end )) continue;
-        if (lock->shared && shared) continue;
+        if (shared && (lock->shared || lock->fd == fd)) continue;
         /* found one */
         if (!wait)
         {
-- 
1.7.6.1



More information about the wine-patches mailing list