git://scm.lunaixsky.com
/
lunaix-os.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
chore: fix almost *ALL* warnings.
[lunaix-os.git]
/
lunaix-os
/
kernel
/
fs
/
pcache.c
diff --git
a/lunaix-os/kernel/fs/pcache.c
b/lunaix-os/kernel/fs/pcache.c
index 8ef8fc8aa4359a95a15d8653d0d361f6a8bc0ff3..d3e871eadc9e0ae831c3673e96d2366b2cedbca7 100644
(file)
--- 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*
}
struct pcache_pg*
-pcache_new_page(struct pcache* pcache, u
int
32_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);
{
struct pcache_pg* ppg = vzalloc(sizeof(struct pcache_pg));
void* pg = valloc(PG_SIZE);
@@
-76,17
+76,18
@@
pcache_set_dirty(struct pcache* pcache, struct pcache_pg* pg)
}
}
}
}
-struct pcache_pg*
+int
pcache_get_page(struct pcache* pcache,
pcache_get_page(struct pcache* pcache,
- u
int
32_t index,
- u
int
32_t* offset,
+ u32_t index,
+ u32_t* offset,
struct pcache_pg** page)
{
struct pcache_pg* pg = btrie_get(&pcache->tree, index);
int is_new = 0;
struct pcache_pg** page)
{
struct pcache_pg* pg = btrie_get(&pcache->tree, index);
int is_new = 0;
- *offset = index & ((1 << pcache->tree.truncated) - 1);
+ u32_t mask = ((1 << pcache->tree.truncated) - 1);
+ *offset = index & mask;
if (!pg && (pg = pcache_new_page(pcache, index))) {
if (!pg && (pg = pcache_new_page(pcache, index))) {
- pg->fpos = index
- *offset
;
+ pg->fpos = index
& ~mask
;
pcache->n_pages++;
is_new = 1;
}
pcache->n_pages++;
is_new = 1;
}
@@
-97,9
+98,9
@@
pcache_get_page(struct pcache* pcache,
}
int
}
int
-pcache_write(struct v_inode* inode, void* data, u
int32_t len, uint
32_t fpos)
+pcache_write(struct v_inode* inode, void* data, u
32_t len, u
32_t fpos)
{
{
- u
int
32_t pg_off, buf_off = 0;
+ u32_t pg_off, buf_off = 0;
struct pcache* pcache = inode->pg_cache;
struct pcache_pg* pg;
struct pcache* pcache = inode->pg_cache;
struct pcache_pg* pg;
@@
-109,11
+110,12
@@
pcache_write(struct v_inode* inode, void* data, uint32_t len, uint32_t fpos)
return ENOMEM;
}
return ENOMEM;
}
- u
int
32_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);
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;
}
buf_off += wr_bytes;
fpos += wr_bytes;
}
@@
-122,9
+124,9
@@
pcache_write(struct v_inode* inode, void* data, uint32_t len, uint32_t fpos)
}
int
}
int
-pcache_read(struct v_inode* inode, void* data, u
int32_t len, uint
32_t fpos)
+pcache_read(struct v_inode* inode, void* data, u
32_t len, u
32_t fpos)
{
{
- u
int
32_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;
int errno = 0;
struct pcache* pcache = inode->pg_cache;
struct pcache_pg* pg;
@@
-137,22
+139,28
@@
pcache_read(struct v_inode* inode, void* data, uint32_t len, uint32_t fpos)
}
// Filling up the page
}
// Filling up the page
- errno = inode->default_fops.read(inode, pg->pg, PG_SIZE, pg->fpos);
+ errno =
+ inode->default_fops->read_page(inode, pg->pg, PG_SIZE, pg->fpos);
if (errno >= 0 && errno < PG_SIZE) {
// EOF
if (errno >= 0 && errno < PG_SIZE) {
// EOF
- len =
buf_off + errno
;
+ len =
MIN(len, buf_off + errno)
;
} else if (errno < 0) {
break;
}
} 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;
}
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
}
void
@@
-172,10
+180,11
@@
int
pcache_commit(struct v_inode* inode, struct pcache_pg* page)
{
if (!(page->flags & PCACHE_DIRTY)) {
pcache_commit(struct v_inode* inode, struct pcache_pg* page)
{
if (!(page->flags & PCACHE_DIRTY)) {
- return;
+ return
0
;
}
}
- int errno = inode->default_fops.write(inode, page->pg, PG_SIZE, page->fpos);
+ int errno =
+ inode->default_fops->write_page(inode, page->pg, PG_SIZE, page->fpos);
if (!errno) {
page->flags &= ~PCACHE_DIRTY;
if (!errno) {
page->flags &= ~PCACHE_DIRTY;