Repository navigation
Expand file tree
/
Copy pathmain.c
More file actions
147 lines (117 loc) · 4.2 KB
/
Copy pathmain.c
File metadata and controls
147 lines (117 loc) · 4.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
/* This file contains the main directory for the server. It waits for a
* request and then send a response. */
#include "inc.h"
#include <minix/vfsif.h>
#include <assert.h>
#include "const.h"
#include "glo.h"
/* Declare some local functions. */
static void get_work(message *m_in);
/* SEF functions and variables. */
static void sef_local_startup(void);
static int sef_cb_init_fresh(int type, sef_init_info_t *info);
static void sef_cb_signal_handler(int signo);
/*===========================================================================*
* main *
*===========================================================================*/
int main(void) {
endpoint_t who_e;
int ind, error, transid;
/* SEF local startup. */
sef_local_startup();
for (;;) {
/* Wait for request message. */
get_work(&fs_m_in);
transid = TRNS_GET_ID(fs_m_in.m_type);
fs_m_in.m_type = TRNS_DEL_ID(fs_m_in.m_type);
if (fs_m_in.m_type == 0) {
assert(!IS_VFS_FS_TRANSID(transid));
fs_m_in.m_type = transid; /* Backwards compat. */
transid = 0;
} else
assert(IS_VFS_FS_TRANSID(transid));
error = OK;
caller_uid = -1; /* To trap errors */
caller_gid = -1;
who_e = fs_m_in.m_source; /* source of the request */
if (who_e != VFS_PROC_NR) { /* If the message is not for us just
* continue */
continue;
}
req_nr = fs_m_in.m_type;
if (req_nr < FS_BASE) {
fs_m_in.m_type += FS_BASE;
req_nr = fs_m_in.m_type;
}
ind = req_nr-FS_BASE;
if (ind < 0 || ind >= NREQS) {
error = EINVAL;
} else
error = (*fs_call_vec[ind])(); /* Process the request calling
* the appropriate function. */
fs_m_out.m_type = error;
if (IS_VFS_FS_TRANSID(transid)) {
/* If a transaction ID was set, reset it */
fs_m_out.m_type = TRNS_ADD_ID(fs_m_out.m_type, transid);
}
reply(who_e, &fs_m_out); /* returns the response to VFS */
}
}
/*===========================================================================*
* sef_local_startup *
*===========================================================================*/
static void sef_local_startup()
{
/* Register init callbacks. */
sef_setcb_init_fresh(sef_cb_init_fresh);
sef_setcb_init_restart(sef_cb_init_fail);
/* No live update support for now. */
/* Register signal callbacks. */
sef_setcb_signal_handler(sef_cb_signal_handler);
/* Let SEF perform startup. */
sef_startup();
lmfs_buf_pool(10);
}
/*===========================================================================*
* sef_cb_init_fresh *
*===========================================================================*/
static int sef_cb_init_fresh(int type, sef_init_info_t *info)
{
/* Initialize the iso9660fs server. */
/* hash_init(); */ /* Init the table with the ids */
setenv("TZ","",1); /* Used to calculate the time */
return(OK);
}
/*===========================================================================*
* sef_cb_signal_handler *
*===========================================================================*/
static void sef_cb_signal_handler(int signo)
{
/* Only check for termination signal, ignore anything else. */
if (signo != SIGTERM) return;
/* No need to do a sync, as this is a read-only file system. */
/* If the file system has already been unmounted, exit immediately.
* We might not get another message.
*/
if (unmountdone) exit(0);
}
/*===========================================================================*
* get_work *
*===========================================================================*/
static void get_work(m_in)
message *m_in; /* pointer to message */
{
int s; /* receive status */
if (OK != (s = sef_receive(ANY, m_in))) /* wait for message */
panic("sef_receive failed: %d", s);
}
/*===========================================================================*
* reply *
*===========================================================================*/
void reply(who, m_out)
int who;
message *m_out; /* report result */
{
if (OK != ipc_send(who, m_out)) /* send the message */
printf("ISOFS(%d) was unable to send reply\n", sef_self());
}