summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--libdiskfs/opts-runtime-parse.c28
-rw-r--r--libdiskfs/opts-set.c94
-rw-r--r--libdiskfs/opts-std-startup.c77
3 files changed, 199 insertions, 0 deletions
diff --git a/libdiskfs/opts-runtime-parse.c b/libdiskfs/opts-runtime-parse.c
new file mode 100644
index 00000000..d46d3175
--- /dev/null
+++ b/libdiskfs/opts-runtime-parse.c
@@ -0,0 +1,28 @@
+/* A default diskfs_parse_runtime_options routine
+
+ Copyright (C) 1995 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 this program; if not, write to the Free Software
+ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
+
+#include "priv.h"
+
+error_t
+diskfs_parse_runtime_options (int argc, char **argv,
+ struct options *standard_options)
+{
+ return options_parse (standard_options, argc, argv, 0, 0);
+}
diff --git a/libdiskfs/opts-set.c b/libdiskfs/opts-set.c
new file mode 100644
index 00000000..77929e7e
--- /dev/null
+++ b/libdiskfs/opts-set.c
@@ -0,0 +1,94 @@
+/* Parse run-time options
+
+ Copyright (C) 1995 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 this program; if not, write to the Free Software
+ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
+
+#include "priv.h"
+
+#define SHORT_OPTIONS "rwsnm"
+
+static struct option long_options[] =
+{
+ {"readonly", no_argument, 0, 'r'},
+ {"writable", no_argument, 0, 'w'},
+ {"sync", optional_argument, 0, 's'},
+ {"nosync", no_argument, 0, 'n'},
+ {"remount", no_argument, 0, 'm'},
+ {0, 0, 0, 0}
+};
+
+error_t
+diskfs_set_options (int argc, char **argv)
+{
+ int readonly = diskfs_readonly;
+ int sync = diskfs_synchronous;
+ int sync_interval = -1;
+ error_t parse_opt (int opt, char *arg)
+ {
+ switch (opt)
+ {
+ case 'r':
+ readonly = 1; break;
+ case 'w':
+ readonly = 0; break;
+ case 'n':
+ sync_interval = 0; sync = 0; break;
+ case 's':
+ if (optarg)
+ sync_interval = atoi (arg);
+ else
+ sync = 1;
+ default:
+ return EINVAL;
+ }
+ return 0;
+ }
+ struct options options = { SHORT_OPTIONS, long_options, parse_opt, 0 };
+
+ /* Call the user option parsing routine, giving it our set of options to do
+ with as it pleases. */
+ error_t err = diskfs_parse_runtime_options (argc, argv, &options);
+
+ if (err)
+ return err;
+
+ /* Do things in this order: change-read/write, remount, change-sync. */
+
+ /* Going writable seems easy, but how do we switch to readonly mode? There
+ might be thread that are past the initial readonly checks which would
+ fail a !readonly assertion if we just set the variable... */
+ if (!readonly)
+ diskfs_readonly = 0;
+
+ /* Remount... */
+
+ /* Change sync mode. */
+ if (sync)
+ {
+ diskfs_synchronous = 1;
+ diskfs_set_sync_interval (0); /* Don't waste time syncing. */
+ }
+ else
+ {
+ diskfs_synchronous = 0;
+ if (sync_interval >= 0)
+ diskfs_set_sync_interval (sync_interval);
+ }
+
+ return 0;
+}
diff --git a/libdiskfs/opts-std-startup.c b/libdiskfs/opts-std-startup.c
new file mode 100644
index 00000000..699d516d
--- /dev/null
+++ b/libdiskfs/opts-std-startup.c
@@ -0,0 +1,77 @@
+/* Standard startup-time command line options
+
+ Copyright (C) 1995 Free Software Foundation, Inc.
+
+ Written by Miles Bader <miles@gnu.ai.mit.edu>
+
+ 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 this program; if not, write to the Free Software
+ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
+
+#include <stdio.h>
+#include <options.h>
+#include "priv.h"
+
+/* ---------------------------------------------------------------- */
+
+#define STD_SHORT_OPTS "rwsnV"
+
+static struct option
+std_long_opts[] =
+{
+ {"readonly", no_argument, 0, 'r'},
+ {"writable", no_argument, 0, 'w'},
+ {"sync", optional_argument, 0, 's'},
+ {"nosync", no_argument, 0, 'n'},
+ {"version", no_argument, 0, 'V'},
+ {0, 0, 0, 0}
+};
+
+static error_t
+parse_std_startup_opt (int opt, char *arg)
+{
+ switch (opt)
+ {
+ case 'r':
+ diskfs_readonly = 1; break;
+ case 'w':
+ diskfs_readonly = 0; break;
+ case 's':
+ if (arg == NULL)
+ diskfs_synchronous = 1;
+ else
+ diskfs_default_sync_interval = atoi (arg);
+ break;
+ case 'n':
+ diskfs_synchronous = 0;
+ diskfs_default_sync_interval = 0;
+ break;
+ case 'V':
+ printf("%s %d.%d.%d\n", diskfs_server_name, diskfs_major_version,
+ diskfs_minor_version, diskfs_edit_version);
+ exit(0);
+ default:
+ return EINVAL;
+ }
+
+ return 0;
+}
+
+/* This may be used with options_parse to parse standard diskfs startup
+ options, possible chained onto the end of a user options structure. */
+static struct options std_startup_opts =
+ { STD_SHORT_OPTS, std_long_opts, parse_std_startup_opt, 0 };
+
+struct options *diskfs_standard_startup_options = &std_startup_opts;