f44940
From 3f6f906c7c7b28dc30edb98200b6e13e1a513bb4 Mon Sep 17 00:00:00 2001
f44940
From: Ondrej Holy <oholy@redhat.com>
f44940
Date: Wed, 9 May 2018 12:54:59 +0200
f44940
Subject: [PATCH] smb: Use O_RDWR to fix fstat when writing
f44940
f44940
fstat fails with EINVAL on Windows servers if O_WRONLY is used to open
f44940
(though it works properly on SAMBA servers). O_RDWR is needed to make
f44940
it work. This causes issues when copying files over gvfsd-fuse among
f44940
others.
f44940
f44940
https://bugzilla.gnome.org/show_bug.cgi?id=795805
f44940
---
f44940
 daemon/gvfsbackendsmb.c | 10 +++++-----
f44940
 1 file changed, 5 insertions(+), 5 deletions(-)
f44940
f44940
diff --git a/daemon/gvfsbackendsmb.c b/daemon/gvfsbackendsmb.c
f44940
index d4944197..9571fa0d 100644
f44940
--- a/daemon/gvfsbackendsmb.c
f44940
+++ b/daemon/gvfsbackendsmb.c
f44940
@@ -808,7 +808,7 @@ do_create (GVfsBackend *backend,
f44940
   smbc_open = smbc_getFunctionOpen (op_backend->smb_context);
f44940
   errno = 0;
f44940
   file = smbc_open (op_backend->smb_context, uri,
f44940
-		    O_CREAT|O_WRONLY|O_EXCL, 0666);
f44940
+                    O_CREAT|O_RDWR|O_EXCL, 0666);
f44940
   g_free (uri);
f44940
 
f44940
   if (file == NULL)
f44940
@@ -850,7 +850,7 @@ do_append_to (GVfsBackend *backend,
f44940
   smbc_open = smbc_getFunctionOpen (op_backend->smb_context);
f44940
   errno = 0;
f44940
   file = smbc_open (op_backend->smb_context, uri,
f44940
-					O_CREAT|O_WRONLY|O_APPEND, 0666);
f44940
+                    O_CREAT|O_RDWR|O_APPEND, 0666);
f44940
   g_free (uri);
f44940
 
f44940
   if (file == NULL)
f44940
@@ -916,7 +916,7 @@ open_tmpfile (GVfsBackendSmb *backend,
f44940
     smbc_open = smbc_getFunctionOpen (backend->smb_context);
f44940
     errno = 0;
f44940
     file = smbc_open (backend->smb_context, tmp_uri,
f44940
-		      O_CREAT|O_WRONLY|O_EXCL, 0666);
f44940
+                      O_CREAT|O_RDWR|O_EXCL, 0666);
f44940
   } while (file == NULL && errno == EEXIST);
f44940
 
f44940
   g_free (dir_uri);
f44940
@@ -1040,7 +1040,7 @@ do_replace (GVfsBackend *backend,
f44940
   
f44940
   errno = 0;
f44940
   file = smbc_open (op_backend->smb_context, uri,
f44940
-		    O_CREAT|O_WRONLY|O_EXCL, 0);
f44940
+                    O_CREAT|O_RDWR|O_EXCL, 0);
f44940
   if (file == NULL && errno != EEXIST)
f44940
     {
f44940
       int errsv = fixup_open_errno (errno);
f44940
@@ -1110,7 +1110,7 @@ do_replace (GVfsBackend *backend,
f44940
 	  
f44940
 	  errno = 0;
f44940
 	  file = smbc_open (op_backend->smb_context, uri,
f44940
-			    O_CREAT|O_WRONLY|O_TRUNC, 0);
f44940
+                            O_CREAT|O_RDWR|O_TRUNC, 0);
f44940
 	  if (file == NULL)
f44940
 	    {
f44940
               int errsv = fixup_open_errno (errno);
f44940
-- 
f44940
2.35.3
f44940