4 #include <minix/callnr.h>
6 #include <minix/config.h>
7 #include <minix/const.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>
28 /*===========================================================================*
30 *===========================================================================*/
31 PRIVATE
void register_callback(struct vmproc
*for_who
, callback_t callback
,
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
;
44 /*===========================================================================*
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
)
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
;
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
);
69 /*===========================================================================*
71 *===========================================================================*/
72 PUBLIC
int vfs_close(struct vmproc
*for_who
, callback_t callback
, int fd
)
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
;
83 if((r
=asynsend(VFS_PROC_NR
, &m
)) != OK
) {
84 vm_panic("vfs_close: asynsend failed", r
);
90 /*===========================================================================*
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.
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",
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",
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",
130 /* All desired callback state has been used, so save and reset
131 * the callback. This allows the callback to register another
134 cb
= vmp
->vm_callback
;
135 vmp
->vm_callback
= NULL
;