Extra logging, begin defining BlueSky-specific error codes.
[bluesky.git] / bluesky / file.c
index 75768d1..ccb45e4 100644 (file)
@@ -9,6 +9,7 @@
 #include <stdint.h>
 #include <glib.h>
 #include <string.h>
+#include <inttypes.h>
 
 #include "bluesky-private.h"
 
@@ -55,6 +56,8 @@ void bluesky_file_truncate(BlueSkyInode *inode, uint64_t size)
     if (size == inode->size)
         return;
 
+    g_print("Truncating file to %"PRIi64" bytes\n", size);
+
     uint64_t blocks = (size + BLUESKY_BLOCK_SIZE - 1) / BLUESKY_BLOCK_SIZE;
 
     if (blocks > inode->blocks->len) {
@@ -98,6 +101,8 @@ void bluesky_file_truncate(BlueSkyInode *inode, uint64_t size)
 void bluesky_file_write(BlueSkyInode *inode, uint64_t offset,
                         const char *data, gint len)
 {
+    g_print("Write %d bytes at offset %"PRIi64"\n", len, offset);
+
     g_return_if_fail(inode->type == BLUESKY_REGULAR);
     g_return_if_fail(offset < inode->size);
     g_return_if_fail(len <= inode->size - offset);
@@ -128,6 +133,11 @@ void bluesky_file_write(BlueSkyInode *inode, uint64_t offset,
 void bluesky_file_read(BlueSkyInode *inode, uint64_t offset,
                        char *buf, gint len)
 {
+    g_print("Read %d bytes at offset %"PRIi64"\n", len, offset);
+
+    if (len == 0 && offset <= inode->size)
+        return;
+
     g_return_if_fail(inode->type == BLUESKY_REGULAR);
     g_return_if_fail(offset < inode->size);
     g_return_if_fail(len <= inode->size - offset);