Second Extended Filesystem (ext2) and other improvements (#33)
[lunaix-os.git] / lunaix-os / kernel / fs / twimap.c
index e72f6c2e20dc50428d138d7bbdc3fa004a1a49cf..dff2de3f769569b0c6582e0193dc05d1ea148a90 100644 (file)
@@ -39,16 +39,22 @@ int
 twimap_read(struct twimap* map, void* buffer, size_t len, size_t fpos)
 {
     map->buffer = valloc(TWIMAP_BUFFER_SIZE);
+    map->size_acc = 0;
+
     map->reset(map);
 
     // FIXME what if TWIMAP_BUFFER_SIZE is not big enough?
 
-    size_t pos = 0;
-    do {
+    size_t pos = map->size_acc;
+    while (pos <= fpos) {
         map->size_acc = 0;
         map->read(map);
         pos += map->size_acc;
-    } while (pos <= fpos && map->go_next(map));
+        
+        if (!map->go_next(map)) {
+            break;
+        }
+    }
 
     if (pos <= fpos) {
         vfree(map->buffer);