Commit 23ef1568 authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent 8a00147e
......@@ -1127,15 +1127,12 @@ struct BigFileMMap {
};
typedef struct BigFileMMap BigFileMMap;
void *mmapfile_mmap_setup_read(BigFile *file, blk_t blk, size_t blklen, VMA *vma) {
void mmapfile_release(BigFile *file) {
BigFileMMap *f = upcast(BigFileMMap*, file);
void *addr;
addr = mmap(NULL, blklen*f->blksize, PROT_READ, MAP_SHARED, f->fd, blk*f->blksize);
if (addr == MAP_FAILED)
addr = NULL;
int err;
return addr;
err = close(f->fd);
BUG_ON(err);
}
int mmapfile_storeblk(BigFile *file, blk_t blk, const void *buf) {
......@@ -1157,17 +1154,37 @@ int mmapfile_storeblk(BigFile *file, blk_t blk, const void *buf) {
return 0;
}
void mmapfile_release(BigFile *file) {
void *mmapfile_mmap_setup_read(BigFile *file, blk_t blk, size_t blklen, VMA *vma) {
BigFileMMap *f = upcast(BigFileMMap*, file);
int err;
void *addr;
err = close(f->fd);
BUG_ON(err);
addr = mmap(NULL, blklen*f->blksize, PROT_READ, MAP_SHARED, f->fd, blk*f->blksize);
if (addr == MAP_FAILED)
addr = NULL;
return addr;
}
int mmapfile_remmap_blk_read(BigFile *file, blk_t blk, VMA *vma) {
BigFileMMap *f = upcast(BigFileMMap*, file);
TODO (f->blksize != vma->fileh->ramh->ram->pagesize);
ASSERT(vma->f_pgoffset <= blk && blk < vma_addr_fpgoffset(vma, vma->addr_stop));
pgoff_t pgoff_invma = blk - vma->f_pgoffset;
uintptr_t addr = vma->addr_start + pgoff_invma*f->blksize;
void *mapped;
mapped = mmap((void *)addr, 1*f->blksize, PROT_READ, MAP_SHARED | MAP_FIXED, f->fd, blk*f->blksize);
if (mapped == MAP_FAILED)
return -1;
ASSERT(mapped == (void *)addr);
return 0;
}
static const struct bigfile_ops mmapfile_ops = {
.loadblk = NULL,
.mmap_setup_read = mmapfile_mmap_setup_read,
.remmap_blk_read = mmapfile_remmap_blk_read,
.storeblk = mmapfile_storeblk,
.release = mmapfile_release,
};
......
......@@ -1068,7 +1068,7 @@ static void vma_page_ensure_unmapped(VMA *vma, Page *page)
int err;
TODO (file->blksize != page_size(page));
err = file->file_ops->remmap_blk_read(file, page->f_pgoffset /* =blk */, vma);
err = file->file_ops->remmap_blk_read(file, /* blk = */page->f_pgoffset, vma);
BUG_ON(err); /* must not fail */
}
else {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment