diff options
author | Tomas Bzatek <tbzatek@redhat.com> | 2010-11-12 16:42:27 +0100 |
---|---|---|
committer | Tomas Bzatek <tbzatek@redhat.com> | 2010-11-12 16:42:27 +0100 |
commit | 51da942cc7468acb27dd90905627b3596bb75cc0 (patch) | |
tree | e0079bc57265808efec27235fc38373fb6b1a504 | |
parent | 0b629b69457e84415364c3ea5371e61691115828 (diff) | |
download | gvfs-51da942cc7468acb27dd90905627b3596bb75cc0.tar.gz |
fuse: Add O_TRUNC support for open()
This requires kernel version 2.6.24 or later.
See bug 627567 for details.
-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; } |