diff options
author | Tomas Bzatek <tbzatek@redhat.com> | 2010-11-12 16:42:49 +0100 |
---|---|---|
committer | Tomas Bzatek <tbzatek@redhat.com> | 2010-11-12 16:42:49 +0100 |
commit | 84f66425ea74f2657f83d00347acf7fc0a638f99 (patch) | |
tree | 32b3d495c379d0a25e92b9db0f2141e7e9944402 /client | |
parent | 070b4c4968591b612f3db1aafd9bba07a4ee0004 (diff) | |
download | gvfs-84f66425ea74f2657f83d00347acf7fc0a638f99.tar.gz |
fuse: Add O_TRUNC support for open()
This requires kernel version 2.6.24 or later.
See bug 627567 for details.
Diffstat (limited to 'client')
-rw-r--r-- | client/gvfsfusedaemon.c | 16 |
1 files changed, 11 insertions, 5 deletions
diff --git a/client/gvfsfusedaemon.c b/client/gvfsfusedaemon.c index 13cb74d1..bc3090d6 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; } |