fuse: Implement write syscall (RHBZ#592883).
[libguestfs.git] / fuse / guestmount.c
index df11619..e1cb2d8 100644 (file)
@@ -40,6 +40,7 @@
 #include <assert.h>
 #include <sys/time.h>
 #include <sys/types.h>
+#include <locale.h>
 
 #include <fuse.h>
 #include <guestfs.h>
@@ -652,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
@@ -927,7 +938,7 @@ main (int argc, char *argv[])
   struct mp *mps = NULL;
   struct mp *mp;
   char *p;
-  int c, i, r;
+  int c, r;
   int option_index;
   struct sigaction sa;