Fixed extern declaration from pointer to array
[minix.git] / servers / vm / vfs.c
blobdf2ec4e7936f685fcb974b12ea667c5c109298ff
2 #define _SYSTEM 1
4 #include <minix/callnr.h>
5 #include <minix/com.h>
6 #include <minix/config.h>
7 #include <minix/const.h>
8 #include <minix/ds.h>
9 #include <minix/endpoint.h>
10 #include <minix/keymap.h>
11 #include <minix/minlib.h>
12 #include <minix/type.h>
13 #include <minix/ipc.h>
14 #include <minix/sysutil.h>
15 #include <minix/syslib.h>
16 #include <minix/safecopies.h>
17 #include <minix/bitmap.h>
19 #include <errno.h>
20 #include <string.h>
21 #include <env.h>
22 #include <stdio.h>
24 #include "glo.h"
25 #include "proto.h"
26 #include "util.h"
28 /*===========================================================================*
29 * register_callback *
30 *===========================================================================*/
31 PRIVATE void register_callback(struct vmproc *for_who, callback_t callback,
32 int callback_type)
34 if(for_who->vm_callback) {
35 vm_panic("register_callback: callback already registered",
36 for_who->vm_callback_type);
38 for_who->vm_callback = callback;
39 for_who->vm_callback_type = callback_type;
41 return;
44 /*===========================================================================*
45 * vfs_open *
46 *===========================================================================*/
47 PUBLIC int vfs_open(struct vmproc *for_who, callback_t callback,
48 cp_grant_id_t filename_gid, int filename_len, int flags, int mode)
50 static message m;
51 int r;
53 register_callback(for_who, callback, VM_VFS_REPLY_OPEN);
55 m.m_type = VM_VFS_OPEN;
56 m.VMVO_NAME_GRANT = filename_gid;
57 m.VMVO_NAME_LENGTH = filename_len;
58 m.VMVO_FLAGS = flags;
59 m.VMVO_MODE = mode;
60 m.VMVO_ENDPOINT = for_who->vm_endpoint;
62 if((r=asynsend(VFS_PROC_NR, &m)) != OK) {
63 vm_panic("vfs_open: asynsend failed", r);
66 return r;
69 /*===========================================================================*
70 * vfs_close *
71 *===========================================================================*/
72 PUBLIC int vfs_close(struct vmproc *for_who, callback_t callback, int fd)
74 static message m;
75 int r;
77 register_callback(for_who, callback, VM_VFS_REPLY_CLOSE);
79 m.m_type = VM_VFS_CLOSE;
80 m.VMVC_ENDPOINT = for_who->vm_endpoint;
81 m.VMVC_FD = fd;
83 if((r=asynsend(VFS_PROC_NR, &m)) != OK) {
84 vm_panic("vfs_close: asynsend failed", r);
87 return r;
90 /*===========================================================================*
91 * do_vfs_reply *
92 *===========================================================================*/
93 PUBLIC int do_vfs_reply(message *m)
95 /* Reply to a request has been received from vfs. Handle it. First verify
96 * and look up which process, identified by endpoint, this is about.
97 * Then call the callback function that was registered when the request
98 * was done. Return result to vfs.
100 endpoint_t ep;
101 struct vmproc *vmp;
102 int procno;
103 callback_t cb;
104 ep = m->VMV_ENDPOINT;
105 if(vm_isokendpt(ep, &procno) != OK) {
106 printf("VM:do_vfs_reply: reply %d about invalid endpoint %d\n",
107 m->m_type, ep);
108 vm_panic("do_vfs_reply: invalid endpoint from vfs", NO_NUM);
110 vmp = &vmproc[procno];
111 if(!vmp->vm_callback) {
112 printf("VM:do_vfs_reply: reply %d: endpoint %d not waiting\n",
113 m->m_type, ep);
114 vm_panic("do_vfs_reply: invalid endpoint from vfs", NO_NUM);
116 if(vmp->vm_callback_type != m->m_type) {
117 printf("VM:do_vfs_reply: reply %d unexpected for endpoint %d\n"
118 " (expecting %d)\n", m->m_type, ep, vmp->vm_callback_type);
119 vm_panic("do_vfs_reply: invalid reply from vfs", NO_NUM);
121 if(vmp->vm_flags & VMF_EXITING) {
122 /* This is not fatal or impossible, but the callback
123 * function has to realize it shouldn't do any PM or
124 * VFS calls for this process.
126 printf("VM:do_vfs_reply: reply %d for EXITING endpoint %d\n",
127 m->m_type, ep);
130 /* All desired callback state has been used, so save and reset
131 * the callback. This allows the callback to register another
132 * one.
134 cb = vmp->vm_callback;
135 vmp->vm_callback = NULL;
136 cb(vmp, m);
137 return SUSPEND;