summaryrefslogtreecommitdiff
path: root/utils
diff options
context:
space:
mode:
authorMiles Bader <miles@gnu.org>1997-06-20 05:28:42 +0000
committerMiles Bader <miles@gnu.org>1997-06-20 05:28:42 +0000
commit438fe4ebb5c51128f458c499a161aeb3f1533c02 (patch)
treec4b072b2e7930db00a8fef806c3f7baa226449b0 /utils
parent84f15e03d7598f93827f392c88ddf3dcf3d159cf (diff)
Moved here from ../libstore
Diffstat (limited to 'utils')
-rw-r--r--utils/storecat.c69
-rw-r--r--utils/storeread.c119
2 files changed, 188 insertions, 0 deletions
diff --git a/utils/storecat.c b/utils/storecat.c
new file mode 100644
index 00000000..be65b63a
--- /dev/null
+++ b/utils/storecat.c
@@ -0,0 +1,69 @@
+/* Write a store to stdout
+
+ Copyright (C) 1996, 1997 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.,
+ 59 Temple Place - Suite 330, Boston, MA 02111, USA. */
+
+#include <unistd.h>
+#include <argp.h>
+#include <error.h>
+
+#include <hurd/store.h>
+
+int
+main (int argc, char **argv)
+{
+ error_t err;
+ struct store *s;
+ char *name;
+ off_t addr;
+ size_t left;
+ const struct argp_child kids[] = { { &store_argp }, { 0 }};
+ struct argp argp =
+ { 0, 0, 0, "Write the contents of a store to stdout", kids };
+ struct store_argp_params p = { 0 };
+
+ argp_parse (&argp, argc, argv, 0, 0, &p);
+ err = store_parsed_name (p.result, &name);
+ if (err)
+ error (2, err, "store_parsed_name");
+
+ err = store_parsed_open (p.result, STORE_READONLY, &s);
+ if (err)
+ error (4, err, "%s", name);
+
+ addr = 0;
+ left = s->size;
+ while (left > 0)
+ {
+ size_t read = left > 1024*1024 ? 1024*1024 : left;
+ char buf[4096];
+ void *data = buf;
+ size_t data_len = sizeof (buf);
+
+ err = store_read (s, addr, read, &data, &data_len);
+ if (err)
+ error (5, err, "%s", name);
+ if (write (1, data, data_len) < 0)
+ error (6, errno, "stdout");
+
+ addr += data_len >> s->log2_block_size;
+ left -= data_len;
+ }
+
+ exit (0);
+}
diff --git a/utils/storeread.c b/utils/storeread.c
new file mode 100644
index 00000000..51336275
--- /dev/null
+++ b/utils/storeread.c
@@ -0,0 +1,119 @@
+/* Write portions of a store to stdout
+
+ Copyright (C) 1996, 1997 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.,
+ 59 Temple Place - Suite 330, Boston, MA 02111, USA. */
+
+#include <argp.h>
+#include <error.h>
+#include <unistd.h>
+#include <hurd.h>
+#include <sys/fcntl.h>
+
+#include <hurd/store.h>
+
+struct argp_option options[] = {
+ {"file", 'f', 0, 0, "Use file IO instead of the raw device"},
+ {"block-size", 'b', "BYTES", 0, "Set the file block size"},
+ {0, 0}
+};
+char *arg_doc = "FILE [ADDR [LENGTH]]...";
+char *doc = "\vADDR is in blocks, and defaults to 0; LENGTH is in bytes, and defaults to the remainder of FILE.";
+
+int
+main (int argc, char **argv)
+{
+ struct store *store = 0;
+ off_t addr = -1;
+ int dumped = 0, use_file_io = 0, block_size = 0;
+
+ void dump (off_t addr, ssize_t len)
+ {
+ char buf[4096];
+ void *data = buf;
+ size_t data_len = sizeof (buf);
+ error_t err =
+ store_read (store, addr, len < 0 ? store->size : len,
+ &data, &data_len);
+ if (err)
+ error (5, err, store->name ? "%s" : "<store>", store->name);
+ if (write (1, data, data_len) < 0)
+ error (6, errno, "stdout");
+ if (data != buf)
+ vm_deallocate (mach_task_self (), (vm_address_t)data, data_len);
+ }
+
+ error_t parse_opt (int key, char *arg, struct argp_state *state)
+ {
+ switch (key)
+ {
+ case 'f': use_file_io = 1; break;
+ case 'b': block_size = atoi (arg); break;
+
+ case ARGP_KEY_ARG:
+ if (! store)
+ {
+ error_t err;
+ file_t source = file_name_lookup (arg, O_READ, 0);
+ if (errno)
+ error (2, errno, "%s", arg);
+ if (use_file_io)
+ if (block_size)
+ {
+ struct stat stat;
+ err = io_stat (source, &stat);
+ if (! err)
+ {
+ struct store_run run = {0, stat.st_size / block_size};
+ err = _store_file_create (source, 0, block_size, &run, 1,
+ &store);
+ }
+ }
+ else
+ err = store_file_create (source, 0, &store);
+ else
+ err = store_create (source, 0, 0, &store);
+ if (err)
+ error (err, 3, "%s", arg);
+ }
+ else if (addr < 0)
+ addr = atoi (arg);
+ else
+ {
+ dump (addr, atoi (arg));
+ dumped = 1;
+ addr = -1;
+ }
+ break;
+
+ case ARGP_KEY_END:
+ if (addr >= 0)
+ dump (addr, -1);
+ else if (! dumped)
+ dump (0, -1);
+ break;
+
+ case ARGP_KEY_NO_ARGS:
+ default:
+ return ARGP_ERR_UNKNOWN;
+ }
+ return 0;
+ }
+ struct argp argp = {options, parse_opt, arg_doc, doc};
+ argp_parse (&argp, argc, argv, 0, 0, 0);
+ exit (0);
+}