etc/services - sync with NetBSD-8
[minix.git] / minix / lib / libsys / vm_cache.c
blobc91e4e396c12665ff553361dfeaf428c5bc7cb18
2 #include "syslib.h"
4 #include <string.h>
5 #include <assert.h>
7 #include <sys/mman.h>
9 #include <minix/vm.h>
10 #include <minix/sysutil.h>
12 #include <machine/param.h>
13 #include <machine/vmparam.h>
15 static int vm_cachecall(message *m, int call, void *addr, dev_t dev,
16 off_t dev_offset, ino_t ino, off_t ino_offset, u32_t *flags,
17 int blocksize, int setflags)
19 if(blocksize % PAGE_SIZE)
20 panic("blocksize %d should be a multiple of pagesize %d\n",
21 blocksize, PAGE_SIZE);
23 if(ino_offset % PAGE_SIZE)
24 panic("inode offset %lld should be a multiple of pagesize %d\n",
25 ino_offset, PAGE_SIZE);
27 if(dev_offset % PAGE_SIZE)
28 panic("dev offset offset %lld should be a multiple of pagesize %d\n",
29 dev_offset, PAGE_SIZE);
31 memset(m, 0, sizeof(*m));
33 assert(dev != NO_DEV);
35 m->m_vmmcp.dev_offset = dev_offset;
36 m->m_vmmcp.ino_offset = ino_offset;
37 m->m_vmmcp.ino = ino;
38 m->m_vmmcp.block = addr;
39 m->m_vmmcp.flags_ptr = flags;
40 m->m_vmmcp.dev = dev;
41 m->m_vmmcp.pages = blocksize / PAGE_SIZE;
42 m->m_vmmcp.flags = setflags;
44 return _taskcall(VM_PROC_NR, call, m);
47 void *vm_map_cacheblock(dev_t dev, off_t dev_offset,
48 ino_t ino, off_t ino_offset, u32_t *flags, int blocksize)
50 message m;
52 if(vm_cachecall(&m, VM_MAPCACHEPAGE, NULL, dev, dev_offset,
53 ino, ino_offset, flags, blocksize, 0) != OK)
54 return MAP_FAILED;
56 return m.m_vmmcp_reply.addr;
59 int vm_set_cacheblock(void *block, dev_t dev, off_t dev_offset,
60 ino_t ino, off_t ino_offset, u32_t *flags, int blocksize, int setflags)
62 message m;
64 return vm_cachecall(&m, VM_SETCACHEPAGE, block, dev, dev_offset,
65 ino, ino_offset, flags, blocksize, setflags);
68 int vm_forget_cacheblock(dev_t dev, off_t dev_offset, int blocksize)
70 message m;
72 return vm_cachecall(&m, VM_FORGETCACHEPAGE, NULL, dev, dev_offset,
73 VMC_NO_INODE, 0, 0, blocksize, 0);
76 int
77 vm_clear_cache(dev_t dev)
79 message m;
81 assert(dev != NO_DEV);
83 memset(&m, 0, sizeof(m));
85 m.m_vmmcp.dev = dev;
87 return _taskcall(VM_PROC_NR, VM_CLEARCACHE, &m);