summaryrefslogtreecommitdiff
path: root/utils/syncfs.c
diff options
context:
space:
mode:
authorRoland McGrath <roland@gnu.org>1998-12-31 20:11:51 +0000
committerRoland McGrath <roland@gnu.org>1998-12-31 20:11:51 +0000
commit2abeaddff3fdcd15ad25e918708c88ced39b4e90 (patch)
treef28f9bfa482219b72dd7d45b52a710d5bc13e6d7 /utils/syncfs.c
parentd91076fa48a6598fa91f28687d76d00f07c32773 (diff)
1998-12-31 Roland McGrath <roland@baalperazim.frob.com>
* Makefile (SRCS, targets, targets rule): Rename sync to syncfs. * syncfs.c: Renamed from sync.c. Take flags -a/--asynchronous and -c/--no-children, and optional file arguments. Diagnose errors.
Diffstat (limited to 'utils/syncfs.c')
-rw-r--r--utils/syncfs.c80
1 files changed, 80 insertions, 0 deletions
diff --git a/utils/syncfs.c b/utils/syncfs.c
new file mode 100644
index 00000000..984af3da
--- /dev/null
+++ b/utils/syncfs.c
@@ -0,0 +1,80 @@
+/* syncfs -- User interface to file_syncfs, synchronize filesystems.
+ Copyright (C) 1994, 95, 96, 97, 98 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 <hurd.h>
+#include <argp.h>
+#include <error.h>
+#include <version.h>
+
+const char *argp_program_version = STANDARD_HURD_VERSION (sync);
+
+static int synchronous = 1, do_children = 1;
+
+static void
+sync_one (const char *name, file_t port)
+{
+ error_t err = (port == MACH_PORT_NULL ? errno
+ : file_syncfs (port, synchronous, do_children));
+ if (err)
+ error (1, err, "%s", name);
+}
+
+static error_t
+parser (int key, char *arg, struct argp_state *state)
+{
+ switch (key)
+ {
+ case 'a': synchronous = 0; break;
+ case 'c': do_children = 0; break;
+
+ case ARGP_KEY_NO_ARGS:
+ sync_one ("/", getcrdir ());
+ break;
+
+ case ARGP_KEY_ARG:
+ sync_one (arg, file_name_lookup (arg, 0, 0));
+ break;
+
+ default:
+ return ARGP_ERR_UNKNOWN;
+ }
+ return 0;
+}
+
+
+int
+main (int argc, char *argv[])
+{
+ static struct argp_option options[] =
+ {
+ {"asynchronous", 'a', 0, 0, "Do not wait for completion"},
+ {"no-children", 'c', 0, 0, "Do not synchronize child filesystems"},
+ {0}
+ };
+ struct argp argp =
+ {options, parser,
+ "[FILE...]", "Force all pending disk writes to be done immediately"
+ "\vThe filesystem containing each FILE is synchronized, and its child"
+ " filesystems unless --no-children is specified. With no FILE argument"
+ " synchronizes the root filesystem."};
+
+ argp_parse (&argp, argc, argv, 0, 0, 0);
+
+ return 0;
+}