Drop main() prototype. Syncs with NetBSD-8
[minix.git] / minix / lib / libpuffs / main.c
blob54e98f21d25d1f216e6b812dbfc0b7055ed6edfa
2 #include "fs.h"
4 static message fs_msg;
5 static int fs_ipc_status;
6 static int fs_pending;
8 #define PUFFS_MAX_ARGS 20
10 /*===========================================================================*
11 * sef_cb_init_fresh *
12 *===========================================================================*/
13 static int sef_cb_init_fresh(int type, sef_init_info_t *info)
15 /* Initialize the Minix file server. */
16 return(OK);
19 /*===========================================================================*
20 * sef_cb_signal_handler *
21 *===========================================================================*/
22 static void sef_cb_signal_handler(int signo)
24 /* Only check for termination signal, ignore anything else. */
25 if (signo != SIGTERM) return;
27 exitsignaled = 1;
28 if (mounted)
29 fs_sync();
31 sef_cancel();
34 /*===========================================================================*
35 * sef_local_startup *
36 *===========================================================================*/
37 static void sef_local_startup(void)
39 /* Register init callbacks. */
40 sef_setcb_init_fresh(sef_cb_init_fresh);
42 /* Register signal callbacks. */
43 sef_setcb_signal_handler(sef_cb_signal_handler);
45 /* Let SEF perform startup. */
46 sef_startup();
49 /*===========================================================================*
50 * get_work *
51 *===========================================================================*/
52 static int get_work(message *msg, int *ipc_status)
54 int r;
56 for (;;) {
57 if ((r = sef_receive_status(ANY, msg, ipc_status)) != OK) {
58 if (r == EINTR) /* sef_cancel from signal handler? */
59 break; /* see if we can exit the main loop */
60 panic("sef_receive failed: %d", r);
62 if (msg->m_source == VFS_PROC_NR)
63 break;
64 lpuffs_debug("libpuffs: unexpected source %d\n", msg->m_source);
67 return r;
70 int __wrap_main(int argc, char *argv[]);
71 int __real_main(int argc, char* argv[]);
73 int __wrap_main(int argc, char *argv[])
75 int i;
76 int new_argc = 0;
77 static char* new_argv[PUFFS_MAX_ARGS];
78 char *name;
80 /* SEF local startup. */
81 env_setargs(argc, argv);
82 sef_local_startup();
84 global_kcred.pkcr_type = PUFFCRED_TYPE_INTERNAL;
86 if (argc < 3) {
87 panic("Unexpected arguments, use:\
88 mount -t fs /dev/ /dir [-o option1,option2]\n");
91 name = argv[0] + strlen(argv[0]);
92 while (*name != '/' && name != argv[0])
93 name--;
94 if (name != argv[0])
95 name++;
96 strcpy(fs_name, name);
98 new_argv[new_argc] = argv[0];
99 new_argc++;
101 for (i = 1; i < argc; i++) {
102 if (new_argc >= PUFFS_MAX_ARGS) {
103 panic("Too many arguments, change PUFFS_MAX_ARGS");
105 new_argv[new_argc] = argv[i];
106 new_argc++;
109 assert(new_argc > 0);
111 /* Get the mount request from VFS, so we can deal with it later. */
112 (void)get_work(&fs_msg, &fs_ipc_status);
113 fs_pending = TRUE;
115 return __real_main(new_argc, new_argv);
119 * Receive a message unless one was already pending. Process the message, and
120 * send a reply if necessary. Return whether puffs should keep running.
123 lpuffs_pump(void)
126 if (fs_pending == TRUE || get_work(&fs_msg, &fs_ipc_status) == OK) {
127 fs_pending = FALSE;
129 fsdriver_process(&puffs_table, &fs_msg, fs_ipc_status, FALSE);
132 return mounted || !exitsignaled;
136 * Initialize MINIX3-specific settings.
138 void
139 lpuffs_init(struct puffs_usermount * pu)
142 buildpath = pu->pu_flags & PUFFS_FLAG_BUILDPATH; /* XXX */
144 LIST_INIT(&pu->pu_pnode_removed_lst);
146 global_pu = pu;