- FUSE: Add O_TRUNC support for open()

This commit is contained in:
Tomas Bzatek 2010-10-13 16:38:35 +02:00
parent 0a7db7a5b6
commit bac5a0e0bb
2 changed files with 86 additions and 1 deletions

View File

@ -0,0 +1,77 @@
From 0d1dc99a87d354e8af9cb0f98827bafb2cd7f577 Mon Sep 17 00:00:00 2001
From: Tomas Bzatek <tbzatek@redhat.com>
Date: Wed, 13 Oct 2010 16:25:51 +0200
Subject: [PATCH] fuse: Add O_TRUNC support for open()
This requires kernel version 2.6.24 or later.
See bug 627567 for details.
---
client/gvfsfusedaemon.c | 16 +++++++++++-----
1 files changed, 11 insertions(+), 5 deletions(-)
diff --git a/client/gvfsfusedaemon.c b/client/gvfsfusedaemon.c
index 13cb74d..bc3090d 100644
--- a/client/gvfsfusedaemon.c
+++ b/client/gvfsfusedaemon.c
@@ -948,7 +948,7 @@ setup_input_stream (GFile *file, FileHandle *fh)
}
static gint
-setup_output_stream (GFile *file, FileHandle *fh)
+setup_output_stream (GFile *file, FileHandle *fh, int flags)
{
GError *error = NULL;
gint result = 0;
@@ -968,7 +968,10 @@ setup_output_stream (GFile *file, FileHandle *fh)
if (!fh->stream)
{
- fh->stream = g_file_append_to (file, 0, NULL, &error);
+ if (flags & O_TRUNC)
+ fh->stream = g_file_replace (file, NULL, FALSE, 0, NULL, &error);
+ else
+ fh->stream = g_file_append_to (file, 0, NULL, &error);
if (fh->stream)
fh->pos = g_seekable_tell (G_SEEKABLE (fh->stream));
}
@@ -1024,7 +1027,7 @@ vfs_open (const gchar *path, struct fuse_file_info *fi)
set_pid_for_file (file);
if (fi->flags & O_WRONLY || fi->flags & O_RDWR)
- result = setup_output_stream (file, fh);
+ result = setup_output_stream (file, fh, fi->flags);
else
result = setup_input_stream (file, fh);
@@ -1406,7 +1409,7 @@ vfs_write (const gchar *path, const gchar *buf, size_t len, off_t offset,
{
g_mutex_lock (fh->mutex);
- result = setup_output_stream (file, fh);
+ result = setup_output_stream (file, fh, 0);
if (result == 0)
{
result = write_stream (fh, buf, len, offset);
@@ -1857,7 +1860,7 @@ vfs_ftruncate (const gchar *path, off_t size, struct fuse_file_info *fi)
{
g_mutex_lock (fh->mutex);
- result = setup_output_stream (file, fh);
+ result = setup_output_stream (file, fh, 0);
if (result == 0)
{
@@ -2336,6 +2339,9 @@ vfs_init (struct fuse_conn_info *conn)
subthread_main_loop = g_main_loop_new (NULL, FALSE);
subthread = g_thread_create ((GThreadFunc) subthread_main, NULL, FALSE, NULL);
+ /* Indicate O_TRUNC support for open() */
+ conn->want |= FUSE_CAP_ATOMIC_O_TRUNC;
+
return NULL;
}
--
1.7.3.1

View File

@ -1,7 +1,7 @@
Summary: Backends for the gio framework in GLib
Name: gvfs
Version: 1.6.4
Release: 2%{?dist}
Release: 3%{?dist}
License: LGPLv2+
Group: System Environment/Libraries
URL: http://www.gtk.org
@ -46,6 +46,10 @@ Patch16: gvfs-1.6.2-stringv-dbus.patch
# from upstream
Patch17: gvfs-1.6.5-sftp-poll-timeout.patch
# https://bugzilla.gnome.org/show_bug.cgi?id=627567
# Data loss when writing files
Patch18: gvfs-1.6.5-fuse-open-trunc-support.patch
Obsoletes: gnome-mount <= 0.8
Obsoletes: gnome-mount-nautilus-properties <= 0.8
@ -145,6 +149,7 @@ including phones and music players to applications using gvfs.
%patch15 -p1 -b .gphoto2-storageinfo
%patch16 -p1 -b .stringv-dbus
%patch17 -p1 -b .sftp-timeout
%patch18 -p1 -b .fuse-trunc
%build
@ -314,6 +319,9 @@ killall -USR1 gvfsd >&/dev/null || :
%endif
%changelog
* Wed Oct 13 2010 Tomas Bzatek <tbzatek@redhat.com> - 1.6.4-3
- FUSE: Add O_TRUNC support for open()
* Mon Oct 4 2010 Tomas Bzatek <tbzatek@redhat.com> - 1.6.4-2
- Fix sftp poll timeout