3 #include <minix/dmap.h>
4 #include <minix/endpoint.h>
5 #include <minix/vfsif.h>
10 FORWARD
_PROTOTYPE(void get_work
, (message
*m_in
) );
12 /* SEF functions and variables. */
13 FORWARD
_PROTOTYPE( void sef_local_startup
, (void) );
14 FORWARD
_PROTOTYPE( int sef_cb_init_fresh
, (int type
, sef_init_info_t
*info
) );
16 /*===========================================================================*
18 *===========================================================================*/
19 PUBLIC
int main(int argc
, char *argv
[])
21 /* This is the main routine of this service. The main loop consists of
22 * three major activities: getting new work, processing the work, and
23 * sending the reply. The loop never terminates, unless a panic occurs.
28 /* SEF local startup. */
29 env_setargs(argc
, argv
);
32 while(!exitsignaled
|| busy
) {
35 /* Wait for request message. */
38 src
= fs_m_in
.m_source
;
40 caller_uid
= -1; /* To trap errors */
43 if (src
== PM_PROC_NR
) continue; /* Exit signal */
44 assert(src
== VFS_PROC_NR
); /* Otherwise this must be VFS talking */
45 req_nr
= fs_m_in
.m_type
;
46 if (req_nr
< VFS_BASE
) {
47 fs_m_in
.m_type
+= VFS_BASE
;
48 req_nr
= fs_m_in
.m_type
;
50 ind
= req_nr
- VFS_BASE
;
52 if (ind
< 0 || ind
>= NREQS
) {
53 printf("pfs: bad request %d\n", req_nr
);
54 printf("ind = %d\n", ind
);
57 error
= (*fs_call_vec
[ind
])();
60 fs_m_out
.m_type
= error
;
61 reply(src
, &fs_m_out
);
67 /*===========================================================================*
69 *===========================================================================*/
70 PRIVATE
void sef_local_startup()
72 /* Register init callbacks. */
73 sef_setcb_init_fresh(sef_cb_init_fresh
);
74 sef_setcb_init_restart(sef_cb_init_restart_fail
);
76 /* No live update support for now. */
78 /* Let SEF perform startup. */
82 /*===========================================================================*
84 *===========================================================================*/
85 PRIVATE
int sef_cb_init_fresh(int type
, sef_init_info_t
*info
)
87 /* Initialize the pipe file server. */
90 /* Initialize main loop parameters. */
91 exitsignaled
= 0; /* No exit request seen yet. */
92 busy
= 0; /* Server is not 'busy' (i.e., inodes in use). */
94 /* Init inode table */
95 for (i
= 0; i
< NR_INODES
; ++i
) {
102 /* Init driver mapping */
103 for (i
= 0; i
< NR_DEVICES
; ++i
)
104 driver_endpoints
[i
].driver_e
= NONE
;
106 SELF_E
= getprocnr();
113 /*===========================================================================*
115 *===========================================================================*/
116 PRIVATE
void get_work(m_in
)
117 message
*m_in
; /* pointer to message */
123 if ((r
= sef_receive(ANY
, m_in
)) != OK
) /* wait for message */
124 panic("PFS","sef_receive failed", r
);
125 src
= fs_m_in
.m_source
;
127 if (src
!= VFS_PROC_NR
) {
128 if(src
== PM_PROC_NR
) {
129 if(is_notify(fs_m_in
.m_type
)) {
130 exitsignaled
= 1; /* Normal exit request. */
133 printf("PFS: unexpected message from PM\n");
135 printf("PFS: unexpected source %d\n", src
);
136 } else if(src
== VFS_PROC_NR
) {
137 srcok
= 1; /* Normal FS request. */
139 printf("PFS: unexpected source %d\n", src
);
142 assert( src
== VFS_PROC_NR
||
143 (src
== PM_PROC_NR
&& is_notify(fs_m_in
.m_type
))
148 /*===========================================================================*
150 *===========================================================================*/
151 PUBLIC
void reply(who
, m_out
)
153 message
*m_out
; /* report result */
155 if (OK
!= send(who
, m_out
)) /* send the message */
156 printf("PFS(%d) was unable to send reply\n", SELF_E
);