1 |
dang 10/11/08 02:30:20 |
2 |
|
3 |
Added: gvfs-1.6.4-O_TRUNC-fix.patch |
4 |
Log: |
5 |
Fix file truncation on open; bug #344079 |
6 |
|
7 |
(Portage version: 2.2.0_alpha3/cvs/Linux x86_64) |
8 |
|
9 |
Revision Changes Path |
10 |
1.1 gnome-base/gvfs/files/gvfs-1.6.4-O_TRUNC-fix.patch |
11 |
|
12 |
file : http://sources.gentoo.org/viewvc.cgi/gentoo-x86/gnome-base/gvfs/files/gvfs-1.6.4-O_TRUNC-fix.patch?rev=1.1&view=markup |
13 |
plain: http://sources.gentoo.org/viewvc.cgi/gentoo-x86/gnome-base/gvfs/files/gvfs-1.6.4-O_TRUNC-fix.patch?rev=1.1&content-type=text/plain |
14 |
|
15 |
Index: gvfs-1.6.4-O_TRUNC-fix.patch |
16 |
=================================================================== |
17 |
From 0d1dc99a87d354e8af9cb0f98827bafb2cd7f577 Mon Sep 17 00:00:00 2001 |
18 |
From: Tomas Bzatek <tbzatek@××××××.com> |
19 |
Date: Wed, 13 Oct 2010 16:25:51 +0200 |
20 |
Subject: [PATCH] fuse: Add O_TRUNC support for open() |
21 |
|
22 |
This requires kernel version 2.6.24 or later. |
23 |
|
24 |
See bug 627567 for details. |
25 |
--- |
26 |
client/gvfsfusedaemon.c | 16 +++++++++++----- |
27 |
1 files changed, 11 insertions(+), 5 deletions(-) |
28 |
|
29 |
diff --git a/client/gvfsfusedaemon.c b/client/gvfsfusedaemon.c |
30 |
index 13cb74d..bc3090d 100644 |
31 |
--- a/client/gvfsfusedaemon.c |
32 |
+++ b/client/gvfsfusedaemon.c |
33 |
@@ -948,7 +948,7 @@ setup_input_stream (GFile *file, FileHandle *fh) |
34 |
} |
35 |
|
36 |
static gint |
37 |
-setup_output_stream (GFile *file, FileHandle *fh) |
38 |
+setup_output_stream (GFile *file, FileHandle *fh, int flags) |
39 |
{ |
40 |
GError *error = NULL; |
41 |
gint result = 0; |
42 |
@@ -968,7 +968,10 @@ setup_output_stream (GFile *file, FileHandle *fh) |
43 |
|
44 |
if (!fh->stream) |
45 |
{ |
46 |
- fh->stream = g_file_append_to (file, 0, NULL, &error); |
47 |
+ if (flags & O_TRUNC) |
48 |
+ fh->stream = g_file_replace (file, NULL, FALSE, 0, NULL, &error); |
49 |
+ else |
50 |
+ fh->stream = g_file_append_to (file, 0, NULL, &error); |
51 |
if (fh->stream) |
52 |
fh->pos = g_seekable_tell (G_SEEKABLE (fh->stream)); |
53 |
} |
54 |
@@ -1024,7 +1027,7 @@ vfs_open (const gchar *path, struct fuse_file_info *fi) |
55 |
set_pid_for_file (file); |
56 |
|
57 |
if (fi->flags & O_WRONLY || fi->flags & O_RDWR) |
58 |
- result = setup_output_stream (file, fh); |
59 |
+ result = setup_output_stream (file, fh, fi->flags); |
60 |
else |
61 |
result = setup_input_stream (file, fh); |
62 |
|
63 |
@@ -1406,7 +1409,7 @@ vfs_write (const gchar *path, const gchar *buf, size_t len, off_t offset, |
64 |
{ |
65 |
g_mutex_lock (fh->mutex); |
66 |
|
67 |
- result = setup_output_stream (file, fh); |
68 |
+ result = setup_output_stream (file, fh, 0); |
69 |
if (result == 0) |
70 |
{ |
71 |
result = write_stream (fh, buf, len, offset); |
72 |
@@ -1857,7 +1860,7 @@ vfs_ftruncate (const gchar *path, off_t size, struct fuse_file_info *fi) |
73 |
{ |
74 |
g_mutex_lock (fh->mutex); |
75 |
|
76 |
- result = setup_output_stream (file, fh); |
77 |
+ result = setup_output_stream (file, fh, 0); |
78 |
|
79 |
if (result == 0) |
80 |
{ |
81 |
@@ -2336,6 +2339,9 @@ vfs_init (struct fuse_conn_info *conn) |
82 |
subthread_main_loop = g_main_loop_new (NULL, FALSE); |
83 |
subthread = g_thread_create ((GThreadFunc) subthread_main, NULL, FALSE, NULL); |
84 |
|
85 |
+ /* Indicate O_TRUNC support for open() */ |
86 |
+ conn->want |= FUSE_CAP_ATOMIC_O_TRUNC; |
87 |
+ |
88 |
return NULL; |
89 |
} |
90 |
|
91 |
-- |
92 |
1.7.3.1 |