3 #include <minix/dmap.h>
4 #include <minix/endpoint.h>
6 #include <minix/vfsif.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 /*===========================================================================*
22 *===========================================================================*/
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 */
33 /* Initialize the server, then go to work. */
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
);
43 if (fs_m_in
.m_type
!= REQ_READSUPER
) {
44 printf("MFS(%d): Invalid login reply\n", SELF_E
);
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;
55 /* Wait for request message. */
59 who_e
= fs_m_in
.m_source
;
60 if (who_e
!= FS_PROC_NR
) {
63 printf("MFS(%d): MSG from PM\n", SELF_E);
65 fs_m_out.m_type = error;
66 reply(who_e, &fs_m_out);
72 req_nr
= fs_m_in
.m_type
;
74 if (req_nr
< 0 || req_nr
>= NREQS
) {
78 error
= (*fs_call_vec
[req_nr
])();
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);
103 /*===========================================================================*
105 *===========================================================================*/
106 PRIVATE
void buf_pool(void)
108 /* Initialize the buffer pool. */
109 register struct buf
*bp
;
113 rear
= &buf
[NR_BUFS
- 1];
115 for (bp
= &buf
[0]; bp
< &buf
[NR_BUFS
]; bp
++) {
116 bp
->b_blocknr
= NO_BLOCK
;
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
;
130 /*===========================================================================*
132 *===========================================================================*/
133 PRIVATE
void init_server(void)
137 /* Init inode table */
138 for (i
= 0; i
< NR_INODES
; ++i
) {
139 inode
[i
].i_count
= 0;
145 /* Init driver mapping */
146 for (i
= 0; i
< NR_DEVICES
; ++i
)
147 driver_endpoints
[i
].driver_e
= NONE
;
149 SELF_E
= getprocnr();
153 /*===========================================================================*
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 /*===========================================================================*
167 *===========================================================================*/
168 PUBLIC
void reply(who
, m_out
)
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)
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
;