aboutsummaryrefslogtreecommitdiff
path: root/ufs/main.c
diff options
context:
space:
mode:
Diffstat (limited to 'ufs/main.c')
-rw-r--r--ufs/main.c105
1 files changed, 44 insertions, 61 deletions
diff --git a/ufs/main.c b/ufs/main.c
index 353a1852..242107f4 100644
--- a/ufs/main.c
+++ b/ufs/main.c
@@ -1,5 +1,5 @@
/*
- Copyright (C) 1994, 1995, 1996 Free Software Foundation
+ Copyright (C) 1994,95,96,97,98,99,2002 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
@@ -26,9 +26,19 @@
#include <stdlib.h>
#include <string.h>
#include <argz.h>
+#include <argp.h>
+#include <hurd/store.h>
struct node *diskfs_root_node;
+struct store *store = 0;
+struct store_parsed *store_parsed = 0;
+
+char *diskfs_disk_name = 0;
+
+/* Number of device blocks per DEV_BSIZE block. */
+unsigned log2_dev_blocks_per_dev_bsize = 0;
+
/* Set diskfs_root_node to the root inode. */
static void
warp_root (void)
@@ -66,7 +76,7 @@ options[] =
{0}
};
-/* Parse a command line option. */
+/* Parse a ufs-specific command line option. */
static error_t
parse_opt (int key, char *arg, struct argp_state *state)
{
@@ -101,6 +111,7 @@ parse_opt (int key, char *arg, struct argp_state *state)
break;
case ARGP_KEY_INIT:
+ state->child_inputs[0] = state->input;
state->hook = (void *)compat_mode; break;
case ARGP_KEY_SUCCESS:
compat_mode = (enum compat_mode)state->hook; break;
@@ -112,37 +123,34 @@ parse_opt (int key, char *arg, struct argp_state *state)
}
/* Add our startup arguments to the standard diskfs set. */
-static const struct argp *startup_parents[] = { &diskfs_std_device_startup_argp, 0};
-static struct argp startup_argp = {options, parse_opt, 0, 0, startup_parents};
+static const struct argp_child startup_children[] =
+ {{&diskfs_store_startup_argp}, {0}};
+static struct argp startup_argp = {options, parse_opt, 0, 0, startup_children};
/* Similarly at runtime. */
-static const struct argp *runtime_parents[] = {&diskfs_std_runtime_argp, 0};
-static struct argp runtime_argp = {options, parse_opt, 0, 0, runtime_parents};
+static const struct argp_child runtime_children[] =
+ {{&diskfs_std_runtime_argp}, {0}};
+static struct argp runtime_argp = {options, parse_opt, 0, 0, runtime_children};
struct argp *diskfs_runtime_argp = (struct argp *)&runtime_argp;
/* Override the standard diskfs routine so we can add our own output. */
error_t
-diskfs_get_options (char **argz, unsigned *argz_len)
+diskfs_append_args (char **argz, size_t *argz_len)
{
error_t err;
- *argz = 0;
- *argz_len = 0;
-
/* Get the standard things. */
err = diskfs_append_std_options (argz, argz_len);
if (!err && compat_mode != COMPAT_GNU)
- {
- err =
- argz_add (argz, argz_len,
- ((compat_mode == COMPAT_BSD42)
- ? "--compat=4.2"
- : "--compat=4.4"));
- if (err)
- free (argz); /* Deallocate what diskfs returned. */
- }
+ err = argz_add (argz, argz_len,
+ ((compat_mode == COMPAT_BSD42)
+ ? "--compat=4.2"
+ : "--compat=4.4"));
+
+ if (! err)
+ err = store_parsed_append_args (store_parsed, argz, argz_len);
return err;
}
@@ -150,55 +158,28 @@ diskfs_get_options (char **argz, unsigned *argz_len)
int
main (int argc, char **argv)
{
- error_t err;
- off_t disk_size;
mach_port_t bootstrap;
- argp_parse (&startup_argp, argc, argv, 0, 0, 0);
-
- /* This must come after the args have been parsed, as this is where the
- host priv ports are set for booting. */
- diskfs_console_stdio ();
+ /* Initialize the diskfs library, parse arguments, and open the store.
+ This starts the first diskfs thread for us. */
+ store = diskfs_init_main (&startup_argp, argc, argv,
+ &store_parsed, &bootstrap);
- if (diskfs_boot_flags)
- {
- /* We are the bootstrap filesystem. */
- bootstrap = MACH_PORT_NULL;
- diskfs_use_mach_device = 1;
- compat_mode = COMPAT_GNU;
- }
- 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");
+ if (store->block_size > DEV_BSIZE)
+ error (4, 0, "%s: Bad device block size %zd (should be <= %d)",
+ diskfs_disk_name, store->block_size, DEV_BSIZE);
+ if (store->size < SBSIZE + SBOFF)
+ error (5, 0, "%s: Disk too small (%Ld bytes)", diskfs_disk_name,
+ store->size);
- err = diskfs_device_open ();
- if (err)
- error (3, err, "%s", diskfs_device_arg);
-
- if (diskfs_device_block_size != DEV_BSIZE)
- error (4, err, "%s: Bad device record size %d (should be %d)",
- diskfs_device_arg, diskfs_device_block_size, DEV_BSIZE);
- if (diskfs_log2_device_block_size == 0)
- error (4, err, "%s: Device block size (%d) not a power of 2",
- diskfs_device_arg, diskfs_device_block_size);
-
- disk_size = diskfs_device_size << diskfs_log2_device_block_size;
- assert (disk_size >= SBSIZE + SBOFF);
+ log2_dev_blocks_per_dev_bsize = 0;
+ while ((1 << log2_dev_blocks_per_dev_bsize) < DEV_BSIZE)
+ log2_dev_blocks_per_dev_bsize++;
+ log2_dev_blocks_per_dev_bsize -= store->log2_block_size;
/* Map the entire disk. */
create_disk_pager ();
- /* Start the first request thread, to handle RPCs and page requests. */
- diskfs_spawn_first_thread ();
-
get_hypermetadata ();
inode_init ();
@@ -211,6 +192,8 @@ main (int argc, char **argv)
outside world. */
diskfs_startup_diskfs (bootstrap, 0);
+ /* SET HOST NAME */
+
/* And this thread is done with its work. */
cthread_exit (0);
@@ -221,7 +204,7 @@ error_t
diskfs_reload_global_state ()
{
flush_pokes ();
- pager_flush (disk_pager, 1);
+ pager_flush (diskfs_disk_pager, 1);
get_hypermetadata ();
return 0;
}