custom message type for VM_INFO
[minix3.git] / lib / libsys / vm_cache.c
blob75a193be7636c8704bd9f54a32d4abcd04b9b67e
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 int vm_cachecall(message *m, int call, void *addr, dev_t dev, off_t dev_offset,
16 ino_t ino, off_t ino_offset, u32_t *flags, int blocksize)
18 if(blocksize % PAGE_SIZE)
19 panic("blocksize %d should be a multiple of pagesize %d\n",
20 blocksize, PAGE_SIZE);
22 if(ino_offset % PAGE_SIZE)
23 panic("inode offset %lld should be a multiple of pagesize %d\n",
24 ino_offset, PAGE_SIZE);
26 if(dev_offset % PAGE_SIZE)
27 panic("dev offset offset %lld should be a multiple of pagesize %d\n",
28 dev_offset, PAGE_SIZE);
30 memset(m, 0, sizeof(*m));
32 assert(dev != NO_DEV);
34 m->m_vmmcp.dev_offset = dev_offset;
35 m->m_vmmcp.ino_offset = ino_offset;
36 m->m_vmmcp.ino = ino;
37 m->m_vmmcp.block = addr;
38 m->m_vmmcp.flags_ptr = flags;
39 m->m_vmmcp.dev = dev;
40 m->m_vmmcp.pages = blocksize / PAGE_SIZE;
41 m->m_vmmcp.flags = 0;
43 return _taskcall(VM_PROC_NR, call, m);
46 void *vm_map_cacheblock(dev_t dev, off_t dev_offset,
47 ino_t ino, off_t ino_offset, u32_t *flags, int blocksize)
49 message m;
51 if(vm_cachecall(&m, VM_MAPCACHEPAGE, NULL, dev, dev_offset,
52 ino, ino_offset, flags, blocksize) != OK)
53 return MAP_FAILED;
55 return m.m_vmmcp_reply.addr;
58 int vm_set_cacheblock(void *block, dev_t dev, off_t dev_offset,
59 ino_t ino, off_t ino_offset, u32_t *flags, int blocksize)
61 message m;
63 return vm_cachecall(&m, VM_SETCACHEPAGE, block, dev, dev_offset,
64 ino, ino_offset, flags, blocksize);
67 int
68 vm_clear_cache(dev_t dev)
70 message m;
72 assert(dev != NO_DEV);
74 memset(&m, 0, sizeof(m));
76 m.m_vmmcp.dev = dev;
78 return _taskcall(VM_PROC_NR, VM_CLEARCACHE, &m);