Added a basic vnode store, more or less the same as the old one.

git-svn-id: file:///srv/svn/repos/haiku/trunk/current@8829 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Axel Dörfler 2004-09-03 17:04:09 +00:00
parent 5cf089d64f
commit 447a16653a
3 changed files with 135 additions and 0 deletions

View File

@ -2,6 +2,7 @@ SubDir OBOS_TOP src kernel core cache ;
KernelMergeObject kernel_cache.o :
block_cache.cpp
vnode_store.cpp
: -fno-pic -Wno-unused -D_KERNEL_MODE=1
;

115
src/kernel/core/cache/vnode_store.cpp vendored Normal file
View File

@ -0,0 +1,115 @@
/*
** Copyright 2004, Axel Dörfler, axeld@pinc-software.de. All rights reserved.
** Distributed under the terms of the Haiku License.
*/
#include "vnode_store.h"
#include <file_cache.h>
#include <vfs.h>
#include <vm.h>
#include <stdlib.h>
static void
store_destroy(struct vm_store *store)
{
free(store);
}
static off_t
store_commit(struct vm_store *_store, off_t size)
{
vnode_store *store = (vnode_store *)_store;
// ToDo: enable this again when "size" is maintained correctly
#if 0
// we don't like committing more memory than we have
if (size > store->size)
size = store->size;
#endif
store->vm.committed_size = size;
return size;
}
static int
store_has_page(struct vm_store *_store, off_t offset)
{
// We always pretend to have the page - even if it's beyond the size of
// the file. The read function will only cut down the size of the read,
// it won't fail because of that.
return 1;
}
static ssize_t
store_read(struct vm_store *_store, off_t offset, iovecs *vecs)
{
vnode_store *store = (vnode_store *)_store;
return vfs_read_page(store->vnode, vecs, offset);
// ToDo: the file system must currently clear out the remainder of the last page...
}
static ssize_t
store_write(struct vm_store *_store, off_t offset, iovecs *vecs)
{
vnode_store *store = (vnode_store *)_store;
return vfs_write_page(store->vnode, vecs, offset);
}
static void
store_acquire_ref(struct vm_store *_store)
{
vnode_store *store = (vnode_store *)_store;
vfs_vnode_acquire_ref(store->vnode);
}
static void
store_release_ref(struct vm_store *_store)
{
vnode_store *store = (vnode_store *)_store;
vfs_vnode_release_ref(store->vnode);
}
static vm_store_ops sStoreOps = {
&store_destroy,
&store_commit,
&store_has_page,
&store_read,
&store_write,
NULL, /* fault */
&store_acquire_ref,
&store_release_ref
};
// #pragma mark -
extern "C" vm_store *
vm_create_vnode_store(void *vnode)
{
vnode_store *store = (vnode_store *)malloc(sizeof(struct vnode_store));
if (store == NULL) {
vfs_vnode_release_ref(vnode);
return NULL;
}
store->vm.ops = &sStoreOps;
store->vm.cache = NULL;
store->vm.committed_size = 0;
store->vnode = vnode;
store->size = 0;
// the file system will maintain this field through the file cache API
return &store->vm;
}

19
src/kernel/core/cache/vnode_store.h vendored Normal file
View File

@ -0,0 +1,19 @@
/*
** Copyright 2004, Axel Dörfler, axeld@pinc-software.de. All rights reserved.
** Distributed under the terms of the Haiku License.
*/
#ifndef VNODE_STORE_H
#define VNODE_STORE_H
#include <vm.h>
struct vnode_store {
vm_store vm;
void *vnode;
off_t size;
// the file system will maintain this field through the file cache API
};
#endif /* VNODE_STORE_H */