Removed verbose statements from vfs and mfs
[minix3.git] / servers / mfs / main.c
blob9a61e637a9429c9ebbf4ac7eb75104d18b59fb79
2 #include "inc.h"
3 #include <minix/dmap.h>
4 #include <minix/endpoint.h>
6 #include <minix/vfsif.h>
7 #include "fs.h"
8 #include "buf.h"
9 #include "inode.h"
10 #include "drivers.h"
13 /* Declare some local functions. */
14 FORWARD _PROTOTYPE(void init_server, (void) );
15 FORWARD _PROTOTYPE(void get_work, (message *m_in) );
17 FORWARD _PROTOTYPE(void cch_check, (void) );
20 /*===========================================================================*
21 * main *
22 *===========================================================================*/
23 PUBLIC int main(void)
25 /* This is the main routine of this service. The main loop consists of
26 * three major activities: getting new work, processing the work, and
27 * sending the reply. The loop never terminates, unless a panic occurs.
29 int who_e; /* caller */
30 int error;
31 message m;
33 /* Initialize the server, then go to work. */
34 init_server();
36 fs_m_in.m_type = FS_READY;
38 if (sendrec(FS_PROC_NR, &fs_m_in) != OK) {
39 printf("MFS(%d): Error sending login to VFS\n", SELF_E);
40 return -1;
43 if (fs_m_in.m_type != REQ_READSUPER) {
44 printf("MFS(%d): Invalid login reply\n", SELF_E);
45 return -1;
47 else {
48 fs_m_out.m_type = fs_readsuper();
49 reply(FS_PROC_NR, &fs_m_out);
50 if (fs_m_out.m_type != OK) return -1;
54 for (;;) {
55 /* Wait for request message. */
56 get_work(&fs_m_in);
57 error = OK;
59 who_e = fs_m_in.m_source;
60 if (who_e != FS_PROC_NR) {
61 if (who_e == 0) {
63 printf("MFS(%d): MSG from PM\n", SELF_E);
64 error = 1;
65 fs_m_out.m_type = error;
66 reply(who_e, &fs_m_out);
69 continue;
72 req_nr = fs_m_in.m_type;
74 if (req_nr < 0 || req_nr >= NREQS) {
75 error = EINVAL;
77 else {
78 error = (*fs_call_vec[req_nr])();
79 /*cch_check();*/
82 fs_m_out.m_type = error;
83 reply(who_e, &fs_m_out);
86 if (error == OK && rdahed_inode != NIL_INODE) {
87 read_ahead(); /* do block read ahead */
91 * VFS asks RS to bring down the FS... */
93 if (req_nr == REQ_UNMOUNT ||
94 (req_nr == REQ_READSUPER && error != OK)) {
95 printf("MFS(%d) exit() cachehit: %d cachemiss: %d\n", SELF_E,
96 inode_cache_hit, inode_cache_miss);
97 return 0;
103 /*===========================================================================*
104 * buf_pool *
105 *===========================================================================*/
106 PRIVATE void buf_pool(void)
108 /* Initialize the buffer pool. */
109 register struct buf *bp;
111 bufs_in_use = 0;
112 front = &buf[0];
113 rear = &buf[NR_BUFS - 1];
115 for (bp = &buf[0]; bp < &buf[NR_BUFS]; bp++) {
116 bp->b_blocknr = NO_BLOCK;
117 bp->b_dev = NO_DEV;
118 bp->b_next = bp + 1;
119 bp->b_prev = bp - 1;
121 buf[0].b_prev = NIL_BUF;
122 buf[NR_BUFS - 1].b_next = NIL_BUF;
124 for (bp = &buf[0]; bp < &buf[NR_BUFS]; bp++) bp->b_hash = bp->b_next;
125 buf_hash[0] = front;
130 /*===========================================================================*
131 * init_server *
132 *===========================================================================*/
133 PRIVATE void init_server(void)
135 int i;
137 /* Init inode table */
138 for (i = 0; i < NR_INODES; ++i) {
139 inode[i].i_count = 0;
140 cch[i] = 0;
143 init_inode_cache();
145 /* Init driver mapping */
146 for (i = 0; i < NR_DEVICES; ++i)
147 driver_endpoints[i].driver_e = NONE;
149 SELF_E = getprocnr();
150 buf_pool();
153 /*===========================================================================*
154 * get_work *
155 *===========================================================================*/
156 PRIVATE void get_work(m_in)
157 message *m_in; /* pointer to message */
159 int s; /* receive status */
160 if (OK != (s = receive(ANY, m_in))) /* wait for message */
161 panic("MFS","receive failed", s);
165 /*===========================================================================*
166 * reply *
167 *===========================================================================*/
168 PUBLIC void reply(who, m_out)
169 int who;
170 message *m_out; /* report result */
172 if (OK != send(who, m_out)) /* send the message */
173 printf("MFS(%d) was unable to send reply\n", SELF_E);
176 PRIVATE void cch_check(void)
178 int i;
180 for (i = 0; i < NR_INODES; ++i) {
181 if (inode[i].i_count != cch[i] &&
182 req_nr != REQ_OPEN && req_nr != REQ_GETNODE &&
183 req_nr != REQ_PUTNODE && req_nr != REQ_GETDIR &&
184 req_nr != REQ_CLONE_OPCL && req_nr != REQ_READSUPER &&
185 req_nr != REQ_MOUNTPOINT && req_nr != REQ_UNMOUNT &&
186 req_nr != REQ_PIPE && req_nr != REQ_SYNC &&
187 req_nr != REQ_LOOKUP)
188 printf("MFS(%d) inode(%d) cc: %d req_nr: %d\n",
189 SELF_E, inode[i].i_num, inode[i].i_count - cch[i], req_nr);
191 cch[i] = inode[i].i_count;