From f3d2f0ffa2e39a17e4e7186edf06ba57a05d110a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Axel=20D=C3=B6rfler?= Date: Fri, 7 Jan 2005 00:55:08 +0000 Subject: [PATCH] cache_module_info::node_opened() was called with the wrong argument order. Added generic syscall to control the cache. Right now, only setting/removing cache modules is implemented. git-svn-id: file:///srv/svn/repos/haiku/trunk/current@10601 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/kernel/core/cache/file_cache.cpp | 52 ++++++++++++++++++++++++++-- 1 file changed, 50 insertions(+), 2 deletions(-) diff --git a/src/kernel/core/cache/file_cache.cpp b/src/kernel/core/cache/file_cache.cpp index 35b779cd8c..b9693e51e2 100644 --- a/src/kernel/core/cache/file_cache.cpp +++ b/src/kernel/core/cache/file_cache.cpp @@ -15,6 +15,7 @@ #include #include #include +#include #include #include @@ -465,6 +466,51 @@ cache_io(void *_cacheRef, off_t offset, addr_t bufferBase, size_t *_size, bool d } +static status_t +file_cache_control(const char *subsystem, uint32 function, void *buffer, size_t bufferSize) +{ + switch (function) { + case CACHE_CLEAR: + // ToDo: clear the cache + dprintf("cache_control: clear cache!\n"); + break; + case CACHE_SET_MODULE: + { + cache_module_info *module = sCacheModule; + + // unset previous module + + if (sCacheModule != NULL) { + sCacheModule = NULL; + snooze(100000); // 0.1 secs + put_module(module->info.name); + } + + // get new module, if any + + if (buffer == NULL) + break; + + char name[B_FILE_NAME_LENGTH]; + if (!IS_USER_ADDRESS(buffer) + || user_strlcpy(name, (char *)buffer, B_FILE_NAME_LENGTH) < B_OK) + return B_BAD_ADDRESS; + + if (strncmp(name, CACHE_MODULES_NAME, strlen(CACHE_MODULES_NAME))) + return B_BAD_VALUE; + + dprintf("cache_control: set module %s!\n", name); + + if (get_module(name, (module_info **)&module) == B_OK) + sCacheModule = module; + break; + } + } + + return B_OK; +} + + // #pragma mark - // kernel public API @@ -549,7 +595,7 @@ cache_node_opened(vm_cache_ref *cache, mount_id mountID, vnode_id vnodeID) file_cache_ref *ref = (file_cache_ref *)((vnode_store *)cache->cache->store)->file_cache_ref; if (ref != NULL && sCacheModule != NULL) - sCacheModule->node_opened(ref->cache->cache->virtual_size, mountID, vnodeID); + sCacheModule->node_opened(mountID, vnodeID, ref->cache->cache->virtual_size); } @@ -569,7 +615,9 @@ cache_node_closed(vm_cache_ref *cache, mount_id mountID, vnode_id vnodeID) extern "C" status_t file_cache_init(void) { - // ToDo: get cache module + // ToDo: get cache module out of driver settings + + register_generic_syscall(CACHE_SYSCALLS, file_cache_control, 1, 0); return B_OK; }