summaryrefslogtreecommitdiffstats
path: root/sal/osl/unx/file.cxx
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-15 09:44:04 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-15 09:44:04 +0000
commiteb358d77291eba677141bab113dc27d7aabb0f3e (patch)
tree2e96f3b5d0c79beaeb536bbf05c3b8564846e65f /sal/osl/unx/file.cxx
parentAdding debian version 4:24.2.1-4. (diff)
downloadlibreoffice-eb358d77291eba677141bab113dc27d7aabb0f3e.tar.xz
libreoffice-eb358d77291eba677141bab113dc27d7aabb0f3e.zip
Merging upstream version 4:24.2.2.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'sal/osl/unx/file.cxx')
-rw-r--r--sal/osl/unx/file.cxx54
1 files changed, 47 insertions, 7 deletions
diff --git a/sal/osl/unx/file.cxx b/sal/osl/unx/file.cxx
index eeee7c803f..ee7412dd10 100644
--- a/sal/osl/unx/file.cxx
+++ b/sal/osl/unx/file.cxx
@@ -64,6 +64,14 @@
#include <vector>
#endif
+#ifdef LINUX
+#include <sys/vfs.h>
+// As documented by the kernel
+#define SMB_SUPER_MAGIC static_cast<__fsword_t>(0x517B)
+#define CIFS_SUPER_MAGIC static_cast<__fsword_t>(0xFF534D42)
+#define SMB2_SUPER_MAGIC static_cast<__fsword_t>(0xFE534D42)
+#endif
+
namespace {
enum class State
@@ -736,9 +744,11 @@ oslFileHandle osl::detail::createFileHandleFromFD(int fd)
return static_cast<oslFileHandle>(pImpl);
}
-static int osl_file_adjustLockFlags(const OString& path, int flags)
+static void osl_file_adjustLockFlags(const OString& path, int *flags, sal_uInt32 *uFlags)
{
#ifdef MACOSX
+ (void) uFlags;
+
/*
* The AFP implementation of MacOS X 10.4 treats O_EXLOCK in a way
* that makes it impossible for OOo to create a backup copy of the
@@ -751,20 +761,50 @@ static int osl_file_adjustLockFlags(const OString& path, int flags)
{
if(strncmp("afpfs", s.f_fstypename, 5) == 0)
{
- flags &= ~O_EXLOCK;
- flags |= O_SHLOCK;
+ *flags &= ~O_EXLOCK;
+ *flags |= O_SHLOCK;
}
else
{
/* Needed flags to allow opening a webdav file */
- flags &= ~(O_EXLOCK | O_SHLOCK | O_NONBLOCK);
+ *flags &= ~(O_EXLOCK | O_SHLOCK | O_NONBLOCK);
+ }
+ }
+#elif defined(LINUX)
+ (void) flags;
+
+ /* get filesystem info */
+ struct statfs aFileStatFs;
+ if (statfs(path.getStr(), &aFileStatFs) < 0)
+ {
+ int e = errno;
+ SAL_INFO("sal.file", "statfs(" << path << "): " << UnixErrnoString(e));
+ }
+ else
+ {
+ SAL_INFO("sal.file", "statfs(" << path << "): OK");
+
+ // We avoid locking if on a Linux CIFS mount otherwise this
+ // fill fail later on when opening the file for reading
+ // during backup creation at save time (even though this is a
+ // write lock and not a read lock).
+ // Fixes the following bug:
+ // https://bugs.documentfoundation.org/show_bug.cgi?id=55004
+ switch (aFileStatFs.f_type) {
+ case SMB_SUPER_MAGIC:
+ case CIFS_SUPER_MAGIC:
+ case SMB2_SUPER_MAGIC:
+ *uFlags |= osl_File_OpenFlag_NoLock;
+ break;
+ default:
+ break;
}
}
#else
(void) path;
+ (void) flags;
+ (void) uFlags;
#endif
-
- return flags;
}
static bool osl_file_queryLocking(sal_uInt32 uFlags)
@@ -981,7 +1021,7 @@ oslFileError openFilePath(const OString& filePath, oslFileHandle* pHandle,
}
else
{
- flags = osl_file_adjustLockFlags (filePath, flags);
+ osl_file_adjustLockFlags (filePath, &flags, &uFlags);
}
// O_EXCL can be set only when O_CREAT is set