X-Git-Url: https://scm.lunaixsky.com/lunaix-os.git/blobdiff_plain/f6ab9c9ababa2cf6e5c723b83ffb9362094054e8..8b8f49b713d64065775fe538232f8639083601bd:/lunaix-os/kernel/fs/pcache.c?ds=sidebyside diff --git a/lunaix-os/kernel/fs/pcache.c b/lunaix-os/kernel/fs/pcache.c index f1969bd..8283fd1 100644 --- a/lunaix-os/kernel/fs/pcache.c +++ b/lunaix-os/kernel/fs/pcache.c @@ -133,23 +133,32 @@ pcache_write(struct v_inode* inode, void* data, u32_t len, u32_t fpos) struct pcache* pcache = inode->pg_cache; struct pcache_pg* pg; - while (buf_off < len) { + while (buf_off < len && errno >= 0) { u32_t wr_bytes = MIN(PG_SIZE - pg_off, len - buf_off); - pcache_get_page(pcache, fpos, &pg_off, &pg); + int new_page = pcache_get_page(pcache, fpos, &pg_off, &pg); + + if (new_page) { + // Filling up the page + errno = + inode->default_fops->read_page(inode, pg->pg, PG_SIZE, pg->fpos); - if (!pg) { - errno = inode->default_fops->write(inode, data, wr_bytes, fpos); if (errno < 0) { break; } - } else { - memcpy(pg->pg + pg_off, (data + buf_off), wr_bytes); - pcache_set_dirty(pcache, pg); - - pg->len = pg_off + wr_bytes; + if (errno < PG_SIZE) { + // EOF + len = MIN(len, buf_off + errno); + } + } else if (!pg) { + errno = inode->default_fops->write(inode, data, wr_bytes, fpos); + continue; } + memcpy(pg->pg + pg_off, (data + buf_off), wr_bytes); + pcache_set_dirty(pcache, pg); + + pg->len = pg_off + wr_bytes; buf_off += wr_bytes; fpos += wr_bytes; }