4 #include <minix/dmap.h>
5 #include <minix/endpoint.h>
6 #include <minix/vfsif.h>
11 FORWARD
_PROTOTYPE(void get_work
, (message
*m_in
) );
13 /* SEF functions and variables. */
14 FORWARD
_PROTOTYPE( void sef_local_startup
, (void) );
15 FORWARD
_PROTOTYPE( int sef_cb_init_fresh
, (int type
, sef_init_info_t
*info
) );
16 FORWARD
_PROTOTYPE( void sef_cb_signal_handler
, (int signo
) );
18 /*===========================================================================*
20 *===========================================================================*/
21 PUBLIC
int main(int argc
, char *argv
[])
23 /* This is the main routine of this service. The main loop consists of
24 * three major activities: getting new work, processing the work, and
25 * sending the reply. The loop never terminates, unless a panic occurs.
29 /* SEF local startup. */
30 env_setargs(argc
, argv
);
33 while(!exitsignaled
|| busy
) {
36 /* Wait for request message. */
39 src
= fs_m_in
.m_source
;
41 caller_uid
= -1; /* To trap errors */
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_fail
);
76 /* No live update support for now. */
78 /* Register signal callbacks. */
79 sef_setcb_signal_handler(sef_cb_signal_handler
);
81 /* Let SEF perform startup. */
85 /*===========================================================================*
87 *===========================================================================*/
88 PRIVATE
int sef_cb_init_fresh(int type
, sef_init_info_t
*info
)
90 /* Initialize the pipe file server. */
93 /* Initialize main loop parameters. */
94 exitsignaled
= 0; /* No exit request seen yet. */
95 busy
= 0; /* Server is not 'busy' (i.e., inodes in use). */
97 /* Init inode table */
98 for (i
= 0; i
< NR_INODES
; ++i
) {
105 /* Init driver mapping */
106 for (i
= 0; i
< NR_DEVICES
; ++i
)
107 driver_endpoints
[i
].driver_e
= NONE
;
109 SELF_E
= getprocnr();
115 /*===========================================================================*
116 * sef_cb_signal_handler *
117 *===========================================================================*/
118 PRIVATE
void sef_cb_signal_handler(int signo
)
120 /* Only check for termination signal, ignore anything else. */
121 if (signo
!= SIGTERM
) return;
126 /*===========================================================================*
128 *===========================================================================*/
129 PRIVATE
void get_work(m_in
)
130 message
*m_in
; /* pointer to message */
136 if ((r
= sef_receive(ANY
, m_in
)) != OK
) /* wait for message */
137 panic("sef_receive failed: %d", r
);
138 src
= fs_m_in
.m_source
;
140 if(src
== VFS_PROC_NR
) {
141 srcok
= 1; /* Normal FS request. */
143 printf("PFS: unexpected source %d\n", src
);
146 assert( src
== VFS_PROC_NR
);
150 /*===========================================================================*
152 *===========================================================================*/
153 PUBLIC
void reply(who
, m_out
)
155 message
*m_out
; /* report result */
157 if (OK
!= send(who
, m_out
)) /* send the message */
158 printf("PFS(%d) was unable to send reply\n", SELF_E
);