Commit 92d6dbf0 authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent 56411971
...@@ -1139,6 +1139,25 @@ void *mmapfile_mmap_setup_read(BigFile *file, blk_t blk, size_t blklen, VMA *vma ...@@ -1139,6 +1139,25 @@ void *mmapfile_mmap_setup_read(BigFile *file, blk_t blk, size_t blklen, VMA *vma
return addr; return addr;
} }
int mmapfile_storeblk(BigFile *file, blk_t blk, const void *buf) {
BigFileMMap *f = upcast(BigFileMMap*, file);
size_t n = f->blksize;
off_t at = blk*f->blksize;
while (n > 0) {
ssize_t wrote;
wrote = pwrite(f->fd, buf, n, at);
if (wrote == -1)
return -1;
BUG_ON(wrote > n);
n -= wrote;
buf += wrote;
}
return 0;
}
void mmapfile_release(BigFile *file) { void mmapfile_release(BigFile *file) {
BigFileMMap *f = upcast(BigFileMMap*, file); BigFileMMap *f = upcast(BigFileMMap*, file);
int err; int err;
...@@ -1149,8 +1168,8 @@ void mmapfile_release(BigFile *file) { ...@@ -1149,8 +1168,8 @@ void mmapfile_release(BigFile *file) {
static const struct bigfile_ops mmapfile_ops = { static const struct bigfile_ops mmapfile_ops = {
.loadblk = NULL, .loadblk = NULL,
// .storeblk = mmapfile_storeblk,
.mmap_setup_read = mmapfile_mmap_setup_read, .mmap_setup_read = mmapfile_mmap_setup_read,
.storeblk = mmapfile_storeblk,
.release = mmapfile_release, .release = mmapfile_release,
}; };
...@@ -1173,21 +1192,40 @@ void test_file_access_mmapbase(void) ...@@ -1173,21 +1192,40 @@ void test_file_access_mmapbase(void)
/* ensure we are starting from new ram */ /* ensure we are starting from new ram */
ok1(list_empty(&ram->lru_list)); ok1(list_empty(&ram->lru_list));
/* setup mmaped id file */ /* setup mmaped file */
char path[] = "/tmp/bigfile_mmap.XXXXXX"; char path[] = "/tmp/bigfile_mmap.XXXXXX";
fd = mkstemp(path); fd = mkstemp(path);
ok1(fd != -1); ok1(fd != -1);
err = unlink(path); err = unlink(path);
ok1(!err); ok1(!err);
// XXX write data
BigFileMMap fileid = { BigFileMMap file = {
.blksize = ram->pagesize, /* artificially blksize = pagesize */ .blksize = ram->pagesize, /* artificially blksize = pagesize */
.file_ops = &mmapfile_ops, .file_ops = &mmapfile_ops,
.fd = fd, .fd = fd,
}; };
err = fileh_open(fh, &fileid, ram); /* fstore stores date into file[blk] */
void fstore(blk_t blk, blk_t data) {
blk_t *buf;
int i;
buf = malloc(file.blksize);
BUG_ON(!buf);
for (i=0; i < file.blksize/sizeof(*buf); i++)
buf[i] = data;
err = file.file_ops->storeblk(&file, blk, buf);
BUG_ON(err);
free(buf);
}
/* initialize file[100 +4) */
fstore(100, 100);
fstore(101, 101);
fstore(102, 102);
fstore(103, 103);
err = fileh_open(fh, &file, ram);
ok1(!err); ok1(!err);
/* implicitly use fileh=fh */ /* implicitly use fileh=fh */
......
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