[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[Libguestfs] [PATCH] fuse: Implement write syscall (RHBZ#592883).



Using this patch I'm able to edit files on a FUSE mounted (guestmount)
filesystem.

Rich.

-- 
Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones
Read my programming blog: http://rwmj.wordpress.com
Fedora now supports 80 OCaml packages (the OPEN alternative to F#)
http://cocan.org/getting_started_with_ocaml_on_red_hat_and_fedora
>From 6868052aec60424dac048cfc68a79b42014c3c38 Mon Sep 17 00:00:00 2001
From: Richard Jones <rjones redhat com>
Date: Tue, 18 May 2010 23:49:43 +0100
Subject: [PATCH] fuse: Implement write syscall (RHBZ#592883).

---
 fuse/guestmount.c |   12 +++++++++++-
 fuse/test-fuse.sh |   11 +++++++++++
 2 files changed, 22 insertions(+), 1 deletions(-)

diff --git a/fuse/guestmount.c b/fuse/guestmount.c
index 27a4cef..e1cb2d8 100644
--- a/fuse/guestmount.c
+++ b/fuse/guestmount.c
@@ -653,7 +653,17 @@ fg_write (const char *path, const char *buf, size_t size,
 
   dir_cache_invalidate (path);
 
-  return -ENOSYS;               /* XXX */
+  /* See fg_read. */
+  const size_t limit = 2 * 1024 * 1024;
+  if (size > limit)
+    size = limit;
+
+  int r;
+  r = guestfs_pwrite (g, path, buf, size, offset);
+  if (r == -1)
+    return error ();
+
+  return r;
 }
 
 static int
diff --git a/fuse/test-fuse.sh b/fuse/test-fuse.sh
index e31ea9d..d464f11 100755
--- a/fuse/test-fuse.sh
+++ b/fuse/test-fuse.sh
@@ -207,6 +207,17 @@ for ts in 12345 1234567 987654321; do
     [ "$(stat -c %Y timestamp)" -eq $ts ]
 done
 
+stage Checking writes
+cp hello.txt copy.txt
+echo >> copy.txt
+echo world >> copy.txt
+echo bigger >> copy.txt
+echo biggest >> copy.txt
+[ "$(cat copy.txt)" = "hello
+world
+bigger
+biggest" ]
+
 # These ones are not yet tested by the current script:
 #stage XXX statfs/statvfs
 #stage XXX xattr operations
-- 
1.6.6.1


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]