X-Git-Url: https://scm.lunaixsky.com/lunaix-os.git/blobdiff_plain/a36758a5018f6a3792c164cd2a313d4f61b7111e..7804c2dae30700296c3205aaf7f546f491999bf4:/lunaix-os/kernel/fs/pcache.c diff --git a/lunaix-os/kernel/fs/pcache.c b/lunaix-os/kernel/fs/pcache.c index 317e491..d3e871e 100644 --- a/lunaix-os/kernel/fs/pcache.c +++ b/lunaix-os/kernel/fs/pcache.c @@ -41,7 +41,7 @@ pcache_release_page(struct pcache* pcache, struct pcache_pg* page) } struct pcache_pg* -pcache_new_page(struct pcache* pcache, uint32_t index) +pcache_new_page(struct pcache* pcache, u32_t index) { struct pcache_pg* ppg = vzalloc(sizeof(struct pcache_pg)); void* pg = valloc(PG_SIZE); @@ -78,8 +78,8 @@ pcache_set_dirty(struct pcache* pcache, struct pcache_pg* pg) int pcache_get_page(struct pcache* pcache, - uint32_t index, - uint32_t* offset, + u32_t index, + u32_t* offset, struct pcache_pg** page) { struct pcache_pg* pg = btrie_get(&pcache->tree, index); @@ -98,9 +98,9 @@ pcache_get_page(struct pcache* pcache, } int -pcache_write(struct v_inode* inode, void* data, uint32_t len, uint32_t fpos) +pcache_write(struct v_inode* inode, void* data, u32_t len, u32_t fpos) { - uint32_t pg_off, buf_off = 0; + u32_t pg_off, buf_off = 0; struct pcache* pcache = inode->pg_cache; struct pcache_pg* pg; @@ -110,11 +110,12 @@ pcache_write(struct v_inode* inode, void* data, uint32_t len, uint32_t fpos) return ENOMEM; } - uint32_t wr_bytes = MIN(PG_SIZE - pg_off, len - buf_off); + u32_t wr_bytes = MIN(PG_SIZE - pg_off, len - buf_off); 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; } @@ -123,9 +124,9 @@ pcache_write(struct v_inode* inode, void* data, uint32_t len, uint32_t fpos) } int -pcache_read(struct v_inode* inode, void* data, uint32_t len, uint32_t fpos) +pcache_read(struct v_inode* inode, void* data, u32_t len, u32_t fpos) { - uint32_t pg_off, buf_off = 0, new_pg = 0; + u32_t pg_off, buf_off = 0, new_pg = 0; int errno = 0; struct pcache* pcache = inode->pg_cache; struct pcache_pg* pg; @@ -146,15 +147,20 @@ pcache_read(struct v_inode* inode, void* data, uint32_t len, uint32_t fpos) } else if (errno < 0) { break; } + pg->len = errno; } - uint32_t rd_bytes = MIN(PG_SIZE - pg_off, len - buf_off); + u32_t rd_bytes = MIN(pg->len - pg_off, len - buf_off); + + if (!rd_bytes) + break; + memcpy((data + buf_off), pg->pg + pg_off, rd_bytes); buf_off += rd_bytes; fpos += rd_bytes; } - return errno < 0 ? errno : buf_off; + return errno < 0 ? errno : (int)buf_off; } void @@ -174,7 +180,7 @@ int pcache_commit(struct v_inode* inode, struct pcache_pg* page) { if (!(page->flags & PCACHE_DIRTY)) { - return; + return 0; } int errno =