X-Git-Url: https://scm.lunaixsky.com/lunaix-os.git/blobdiff_plain/28c176b668c841a3b7fb093faccf0efa39257603..6f65553ca5d2740738f399d88b3a4eb298255427:/lunaix-os/kernel/fs/twimap.c diff --git a/lunaix-os/kernel/fs/twimap.c b/lunaix-os/kernel/fs/twimap.c index e72f6c2..6a6dd0c 100644 --- a/lunaix-os/kernel/fs/twimap.c +++ b/lunaix-os/kernel/fs/twimap.c @@ -6,7 +6,7 @@ #include #include -#include +#include #define TWIMAP_BUFFER_SIZE PAGE_SIZE @@ -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); @@ -62,12 +68,16 @@ twimap_read(struct twimap* map, void* buffer, size_t len, size_t fpos) size_t acc_size = MIN(len, map->size_acc - (pos - fpos)), rdlen = acc_size; memcpy(buffer, map->buffer + (pos - fpos), acc_size); - while (acc_size < len && map->go_next(map)) { + while (acc_size < len) { map->size_acc = 0; map->read(map); rdlen = MIN(len - acc_size, map->size_acc); memcpy(buffer + acc_size, map->buffer, rdlen); acc_size += rdlen; + + if (!map->go_next(map)) { + break; + } } if (acc_size <= len - 1) {