6 #include <minix/callnr.h>
8 #include <minix/config.h>
9 #include <minix/const.h>
11 #include <minix/endpoint.h>
12 #include <minix/keymap.h>
13 #include <minix/minlib.h>
14 #include <minix/type.h>
15 #include <minix/ipc.h>
16 #include <minix/sysutil.h>
17 #include <minix/syslib.h>
18 #include <minix/safecopies.h>
19 #include <minix/bitmap.h>
30 /*===========================================================================*
32 *===========================================================================*/
33 PRIVATE
void register_callback(struct vmproc
*for_who
, callback_t callback
,
36 if(for_who
->vm_callback
) {
37 vm_panic("register_callback: callback already registered",
38 for_who
->vm_callback_type
);
40 for_who
->vm_callback
= callback
;
41 for_who
->vm_callback_type
= callback_type
;
46 /*===========================================================================*
48 *===========================================================================*/
49 PUBLIC
int vfs_open(struct vmproc
*for_who
, callback_t callback
,
50 cp_grant_id_t filename_gid
, int filename_len
, int flags
, int mode
)
55 register_callback(for_who
, callback
, VM_VFS_REPLY_OPEN
);
57 m
.m_type
= VM_VFS_OPEN
;
58 m
.VMVO_NAME_GRANT
= filename_gid
;
59 m
.VMVO_NAME_LENGTH
= filename_len
;
62 m
.VMVO_ENDPOINT
= for_who
->vm_endpoint
;
64 if((r
=asynsend(VFS_PROC_NR
, &m
)) != OK
) {
65 vm_panic("vfs_open: asynsend failed", r
);
71 /*===========================================================================*
73 *===========================================================================*/
74 PUBLIC
int vfs_close(struct vmproc
*for_who
, callback_t callback
, int fd
)
79 register_callback(for_who
, callback
, VM_VFS_REPLY_CLOSE
);
81 m
.m_type
= VM_VFS_CLOSE
;
82 m
.VMVC_ENDPOINT
= for_who
->vm_endpoint
;
85 if((r
=asynsend(VFS_PROC_NR
, &m
)) != OK
) {
86 vm_panic("vfs_close: asynsend failed", r
);
92 /*===========================================================================*
94 *===========================================================================*/
95 PUBLIC
int do_vfs_reply(message
*m
)
97 /* Reply to a request has been received from vfs. Handle it. First verify
98 * and look up which process, identified by endpoint, this is about.
99 * Then call the callback function that was registered when the request
100 * was done. Return result to vfs.
106 ep
= m
->VMV_ENDPOINT
;
107 if(vm_isokendpt(ep
, &procno
) != OK
) {
108 printf("VM:do_vfs_reply: reply %d about invalid endpoint %d\n",
110 vm_panic("do_vfs_reply: invalid endpoint from vfs", NO_NUM
);
112 vmp
= &vmproc
[procno
];
113 if(!vmp
->vm_callback
) {
114 printf("VM:do_vfs_reply: reply %d: endpoint %d not waiting\n",
116 vm_panic("do_vfs_reply: invalid endpoint from vfs", NO_NUM
);
118 if(vmp
->vm_callback_type
!= m
->m_type
) {
119 printf("VM:do_vfs_reply: reply %d unexpected for endpoint %d\n"
120 " (expecting %d)\n", m
->m_type
, ep
, vmp
->vm_callback_type
);
121 vm_panic("do_vfs_reply: invalid reply from vfs", NO_NUM
);
123 if(vmp
->vm_flags
& VMF_EXITING
) {
124 /* This is not fatal or impossible, but the callback
125 * function has to realize it shouldn't do any PM or
126 * VFS calls for this process.
128 printf("VM:do_vfs_reply: reply %d for EXITING endpoint %d\n",
132 /* All desired callback state has been used, so save and reset
133 * the callback. This allows the callback to register another
136 cb
= vmp
->vm_callback
;
137 vmp
->vm_callback
= NULL
;