summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoland McGrath <roland@gnu.org>1999-01-24 02:41:57 +0000
committerRoland McGrath <roland@gnu.org>1999-01-24 02:41:57 +0000
commit1630c743bcf9ba229c7c2e9a7fa5533d384aacab (patch)
treede57d22abc32ec42a097ccd367f71342bb860b0b
parent82a6459a38c2e521e83d4dda3526120ae8ea06b6 (diff)
1999-01-22 Roland McGrath <roland@baalperazim.frob.com>
* init-main.c: New file, defining new function diskfs_init_main. * diskfs.h: Declare diskfs_init_main.
-rw-r--r--libdiskfs/diskfs.h23
-rw-r--r--libdiskfs/init-main.c78
2 files changed, 100 insertions, 1 deletions
diff --git a/libdiskfs/diskfs.h b/libdiskfs/diskfs.h
index aabbf6fb..2332bf9c 100644
--- a/libdiskfs/diskfs.h
+++ b/libdiskfs/diskfs.h
@@ -1,5 +1,5 @@
/* Definitions for fileserver helper functions
- Copyright (C) 1994, 95, 96, 97, 98 Free Software Foundation, Inc.
+ Copyright (C) 1994, 95, 96, 97, 98, 99 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License as
@@ -1024,6 +1024,27 @@ int diskfs_check_readonly (void);
fsys, interrupt, and notify interfaces. All the server routines
have the prefix `diskfs_S_'; `in' arguments of type file_t or io_t
appear as `struct protid *' to the stub. */
+
+
+/* All-in-one initialization function for diskfs filesystems using
+ libstore. This parses arguments using STARTUP_ARGP (defaulting to
+ diskfs_store_startup_argp if it's null; note that the ARGP_IN_ORDER
+ flag is always used); it calls diskfs_init_diskfs; it opens the
+ store with store_parsed_open, and sets diskfs_hard_readonly and
+ diskfs_readonly if the store is unwritable; it calls
+ diskfs_spawn_first_thread; finally, it returns the store and its
+ description in *STORE and *STORE_PARSED, and the bootstrap port in
+ *BOOTSTRAP. The caller should pass *BOOTSTRAP to
+ diskfs_startup_diskfs after setting diskfs_root_node.
+ (See <argp.h> and <hurd/store.h>.)
+
+ This call cannot return failure; if it encounters a fatal problem,
+ it prints a diagnostic on stderr (or the console) and exits the
+ program. */
+struct store *diskfs_init_main (struct argp *startup_argp,
+ int argc, char **argv,
+ struct store_parsed **store_parsed,
+ mach_port_t *bootstrap);
/* The following are optional convenience routines and global variable, which
can be used by any user program that uses a mach device to hold the
diff --git a/libdiskfs/init-main.c b/libdiskfs/init-main.c
new file mode 100644
index 00000000..a9680dd7
--- /dev/null
+++ b/libdiskfs/init-main.c
@@ -0,0 +1,78 @@
+/* diskfs_init_main -- initialize diskfs world, parse arguments, and open store
+ Copyright (C) 1999 Free Software Foundation, Inc.
+
+This file is part of the GNU Hurd.
+
+The GNU Hurd is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+The GNU Hurd is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with the GNU Hurd; see the file COPYING. If not, write to
+the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
+
+#include "diskfs.h"
+#include <argp.h>
+#include <assert.h>
+#include <error.h>
+#include <hurd/store.h>
+
+struct store *
+diskfs_init_main (struct argp *startup_argp,
+ int argc, char **argv,
+ struct store_parsed **store_parsed,
+ mach_port_t *bootstrap)
+{
+ error_t err;
+ struct store_argp_params store_params = { 0 };
+ struct store *store;
+
+ /* We must use ARGP_IN_ORDER for the parsing of --boot-command to work. */
+ err = argp_parse (startup_argp ?: &diskfs_store_startup_argp,
+ argc, argv, ARGP_IN_ORDER, NULL,
+ &store_params);
+ assert_perror (err);
+ *store_parsed = store_params.result;
+
+ err = store_parsed_name (*store_parsed, &diskfs_disk_name);
+ if (err)
+ error (2, err, "store_parsed_name");
+
+ /* This must come after the args have been parsed, as this is where the
+ host priv ports are set for booting. */
+ diskfs_console_stdio ();
+
+ if (diskfs_boot_flags)
+ /* We are the bootstrap filesystem. */
+ *bootstrap = MACH_PORT_NULL;
+ else
+ {
+ task_get_bootstrap_port (mach_task_self (), bootstrap);
+ if (bootstrap == MACH_PORT_NULL)
+ error (2, 0, "Must be started as a translator");
+ }
+
+ /* Initialize the diskfs library. Must come before any other diskfs call. */
+ err = diskfs_init_diskfs ();
+ if (err)
+ error (4, err, "init");
+
+ err = store_parsed_open (*store_parsed, diskfs_readonly ? STORE_READONLY : 0,
+ &store);
+ if (err)
+ error (3, err, "%s", diskfs_disk_name);
+
+ if (store->flags & STORE_HARD_READONLY)
+ diskfs_readonly = diskfs_hard_readonly = 1;
+
+ /* Start the first request thread, to handle RPCs and page requests. */
+ diskfs_spawn_first_thread ();
+
+ return store;
+}