feat: a file system mapping for pci devices
[lunaix-os.git] / lunaix-os / kernel / fs / pcache.c
index 8ef8fc8aa4359a95a15d8653d0d361f6a8bc0ff3..c27f78ba6bf8282139c0f487eb761acb4e456f9d 100644 (file)
@@ -76,7 +76,7 @@ pcache_set_dirty(struct pcache* pcache, struct pcache_pg* pg)
     }
 }
 
-struct pcache_pg*
+int
 pcache_get_page(struct pcache* pcache,
                 uint32_t index,
                 uint32_t* offset,
@@ -137,10 +137,10 @@ pcache_read(struct v_inode* inode, void* data, uint32_t len, uint32_t fpos)
             }
 
             // Filling up the page
-            errno = inode->default_fops.read(inode, pg->pg, PG_SIZE, pg->fpos);
+            errno = inode->default_fops->read(inode, pg->pg, PG_SIZE, pg->fpos);
             if (errno >= 0 && errno < PG_SIZE) {
                 // EOF
-                len = buf_off + errno;
+                len = MIN(len, buf_off + errno);
             } else if (errno < 0) {
                 break;
             }
@@ -175,7 +175,8 @@ pcache_commit(struct v_inode* inode, struct pcache_pg* page)
         return;
     }
 
-    int errno = inode->default_fops.write(inode, page->pg, PG_SIZE, page->fpos);
+    int errno =
+      inode->default_fops->write(inode, page->pg, PG_SIZE, page->fpos);
 
     if (!errno) {
         page->flags &= ~PCACHE_DIRTY;