From 447a16653a59ce15292167399b828aa3dee864ed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Axel=20D=C3=B6rfler?= Date: Fri, 3 Sep 2004 17:04:09 +0000 Subject: [PATCH] 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 --- src/kernel/core/cache/Jamfile | 1 + src/kernel/core/cache/vnode_store.cpp | 115 ++++++++++++++++++++++++++ src/kernel/core/cache/vnode_store.h | 19 +++++ 3 files changed, 135 insertions(+) create mode 100644 src/kernel/core/cache/vnode_store.cpp create mode 100644 src/kernel/core/cache/vnode_store.h diff --git a/src/kernel/core/cache/Jamfile b/src/kernel/core/cache/Jamfile index 43b4043cab..a78f496e8e 100644 --- a/src/kernel/core/cache/Jamfile +++ b/src/kernel/core/cache/Jamfile @@ -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 ; diff --git a/src/kernel/core/cache/vnode_store.cpp b/src/kernel/core/cache/vnode_store.cpp new file mode 100644 index 0000000000..f1075721af --- /dev/null +++ b/src/kernel/core/cache/vnode_store.cpp @@ -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 +#include +#include + +#include + + +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; +} + diff --git a/src/kernel/core/cache/vnode_store.h b/src/kernel/core/cache/vnode_store.h new file mode 100644 index 0000000000..4fb36ad793 --- /dev/null +++ b/src/kernel/core/cache/vnode_store.h @@ -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 + + +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 */