tty: don't use custom kputc; this fixes tty printf()s.
[minix.git] / servers / pfs / main.c
blobefcb485033e8891088a34f3b17d98e5d22b8ae7d
1 #include "fs.h"
2 #include <assert.h>
3 #include <signal.h>
4 #include <minix/dmap.h>
5 #include <minix/endpoint.h>
6 #include <minix/vfsif.h>
7 #include "buf.h"
8 #include "inode.h"
9 #include "drivers.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 /*===========================================================================*
19 * main *
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.
27 int error, ind;
29 /* SEF local startup. */
30 env_setargs(argc, argv);
31 sef_local_startup();
33 while(!exitsignaled || busy) {
34 endpoint_t src;
36 /* Wait for request message. */
37 get_work(&fs_m_in);
39 src = fs_m_in.m_source;
40 error = OK;
41 caller_uid = -1; /* To trap errors */
42 caller_gid = -1;
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);
55 error = EINVAL;
56 } else {
57 error = (*fs_call_vec[ind])();
60 fs_m_out.m_type = error;
61 reply(src, &fs_m_out);
64 return(OK);
67 /*===========================================================================*
68 * sef_local_startup *
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. */
82 sef_startup();
85 /*===========================================================================*
86 * sef_cb_init_fresh *
87 *===========================================================================*/
88 PRIVATE int sef_cb_init_fresh(int type, sef_init_info_t *info)
90 /* Initialize the pipe file server. */
91 int i;
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) {
99 inode[i].i_count = 0;
100 cch[i] = 0;
103 init_inode_cache();
105 /* Init driver mapping */
106 for (i = 0; i < NR_DEVICES; ++i)
107 driver_endpoints[i].driver_e = NONE;
109 SELF_E = getprocnr();
110 buf_pool();
112 return(OK);
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;
123 exitsignaled = 1;
126 /*===========================================================================*
127 * get_work *
128 *===========================================================================*/
129 PRIVATE void get_work(m_in)
130 message *m_in; /* pointer to message */
132 int r, srcok = 0;
133 endpoint_t src;
135 do {
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. */
142 } else
143 printf("PFS: unexpected source %d\n", src);
144 } while(!srcok);
146 assert( src == VFS_PROC_NR );
150 /*===========================================================================*
151 * reply *
152 *===========================================================================*/
153 PUBLIC void reply(who, m_out)
154 int who;
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);