Fixed extern declaration from pointer to array
[minix.git] / servers / pfs / main.c
blobd52a506fad29ff0ce5a1453125004b0467698e2b
1 #include "fs.h"
2 #include <assert.h>
3 #include <minix/dmap.h>
4 #include <minix/endpoint.h>
5 #include <minix/vfsif.h>
6 #include "buf.h"
7 #include "inode.h"
8 #include "drivers.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 /*===========================================================================*
17 * main *
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.
25 int error, ind;
26 message m;
28 /* SEF local startup. */
29 env_setargs(argc, argv);
30 sef_local_startup();
32 while(!exitsignaled || busy) {
33 endpoint_t src;
35 /* Wait for request message. */
36 get_work(&fs_m_in);
38 src = fs_m_in.m_source;
39 error = OK;
40 caller_uid = -1; /* To trap errors */
41 caller_gid = -1;
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);
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_restart_fail);
76 /* No live update support for now. */
78 /* Let SEF perform startup. */
79 sef_startup();
82 /*===========================================================================*
83 * sef_cb_init_fresh *
84 *===========================================================================*/
85 PRIVATE int sef_cb_init_fresh(int type, sef_init_info_t *info)
87 /* Initialize the pipe file server. */
88 int i;
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) {
96 inode[i].i_count = 0;
97 cch[i] = 0;
100 init_inode_cache();
102 /* Init driver mapping */
103 for (i = 0; i < NR_DEVICES; ++i)
104 driver_endpoints[i].driver_e = NONE;
106 SELF_E = getprocnr();
107 buf_pool();
109 return(OK);
113 /*===========================================================================*
114 * get_work *
115 *===========================================================================*/
116 PRIVATE void get_work(m_in)
117 message *m_in; /* pointer to message */
119 int r, srcok = 0;
120 endpoint_t src;
122 do {
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. */
131 srcok = 1;
132 } else
133 printf("PFS: unexpected message from PM\n");
134 } else
135 printf("PFS: unexpected source %d\n", src);
136 } else if(src == VFS_PROC_NR) {
137 srcok = 1; /* Normal FS request. */
138 } else
139 printf("PFS: unexpected source %d\n", src);
140 } while(!srcok);
142 assert( src == VFS_PROC_NR ||
143 (src == PM_PROC_NR && is_notify(fs_m_in.m_type))
148 /*===========================================================================*
149 * reply *
150 *===========================================================================*/
151 PUBLIC void reply(who, m_out)
152 int who;
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);