1 /* VTreeFS - vtreefs.c - by Alen Stojanov and David van Moolenbroek */
5 static int get_work(void);
6 static void send_reply(int err
, int transid
);
7 static void got_signal(int signal
);
9 static unsigned int inodes
;
10 static struct inode_stat
*root_stat
;
11 static index_t root_entries
;
13 /*===========================================================================*
15 *===========================================================================*/
16 static int init_server(int UNUSED(type
), sef_init_info_t
*UNUSED(info
))
18 /* Initialize internal state, and register with VFS.
21 /* Initialize the virtual tree. */
22 init_inodes(inodes
, root_stat
, root_entries
);
24 /* Do not yet allow any requests except REQ_READSUPER. */
30 /*===========================================================================*
32 *===========================================================================*/
33 static void sef_local_startup(void)
35 sef_setcb_init_fresh(init_server
);
36 sef_setcb_init_restart(init_server
);
38 sef_setcb_signal_handler(got_signal
);
40 /* No support for live update yet. */
45 /*===========================================================================*
47 *===========================================================================*/
48 void start_vtreefs(struct fs_hooks
*hooks
, unsigned int nr_inodes
,
49 struct inode_stat
*stat
, index_t nr_indexed_entries
)
51 /* This is the main routine of this service. The main loop consists of
52 * three major activities: getting new work, processing the work, and
53 * sending the reply. The loop exits when the process is signaled to
54 * exit; due to limitations of SEF, it can not return to the caller.
56 int call_nr
, err
, transid
;
58 /* Use global variables to work around the inability to pass parameters
59 * through SEF to the initialization function..
61 vtreefs_hooks
= hooks
;
64 root_entries
= nr_indexed_entries
;
71 transid
= TRNS_GET_ID(fs_m_in
.m_type
);
72 fs_m_in
.m_type
= TRNS_DEL_ID(fs_m_in
.m_type
);
73 if (fs_m_in
.m_type
== 0) {
74 assert(!IS_VFS_FS_TRANSID(transid
));
75 fs_m_in
.m_type
= transid
; /* Backwards compat. */
78 assert(IS_VFS_FS_TRANSID(transid
));
80 call_nr
= fs_m_in
.m_type
;
82 if (fs_m_in
.m_source
!= VFS_PROC_NR
) {
83 if (vtreefs_hooks
->message_hook
!= NULL
) {
84 /* If the request is not among the recognized
85 * requests, call the message hook.
87 vtreefs_hooks
->message_hook(&fs_m_in
);
93 if (fs_mounted
|| call_nr
== REQ_READSUPER
) {
96 if (call_nr
>= 0 && call_nr
< NREQS
) {
97 err
= (*fs_call_vec
[call_nr
])();
104 send_reply(err
, transid
);
108 /*===========================================================================*
110 *===========================================================================*/
111 static int get_work(void)
113 /* Retrieve work. Return the call number.
117 if ((r
= sef_receive(ANY
, &fs_m_in
)) != OK
)
118 panic(__FILE__
, "receive failed", r
);
120 return fs_m_in
.m_type
;
123 /*===========================================================================*
125 *===========================================================================*/
126 static void send_reply(int err
, int transid
)
128 /* Send a reply to the caller.
132 fs_m_out
.m_type
= err
;
133 if (IS_VFS_FS_TRANSID(transid
)) {
134 fs_m_out
.m_type
= TRNS_ADD_ID(fs_m_out
.m_type
, transid
);
137 if ((r
= send(fs_m_in
.m_source
, &fs_m_out
)) != OK
)
138 panic(__FILE__
, "unable to send reply", r
);
141 /*===========================================================================*
143 *===========================================================================*/
144 static void got_signal(int signal
)
146 /* We received a signal. If it is a termination signal, and the file
147 * system has already been unmounted, clean up and exit.
150 if (signal
!= SIGTERM
)