aboutsummaryrefslogtreecommitdiff
path: root/utils/storeinfo.c
diff options
context:
space:
mode:
Diffstat (limited to 'utils/storeinfo.c')
-rw-r--r--utils/storeinfo.c87
1 files changed, 53 insertions, 34 deletions
diff --git a/utils/storeinfo.c b/utils/storeinfo.c
index ba6d0654..a738d50d 100644
--- a/utils/storeinfo.c
+++ b/utils/storeinfo.c
@@ -1,8 +1,8 @@
/* Show where a file exists
- Copyright (C) 1995, 1996 Free Software Foundation, Inc.
+ Copyright (C) 1995,96,97,98,99,2001,02 Free Software Foundation, Inc.
- Written by Miles Bader <miles@gnu.ai.mit.edu>
+ Written by Miles Bader <miles@gnu.org>
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License as
@@ -25,22 +25,24 @@
#include <argp.h>
#include <unistd.h>
#include <sys/fcntl.h>
+#include <version.h>
#include <error.h>
#include <hurd/fs.h>
#include <hurd/store.h>
-char *argp_program_version = "storeinfo 1.0 (GNU " HURD_RELEASE ")";
+const char *argp_program_version = STANDARD_HURD_VERSION (storeinfo);
static struct argp_option options[] =
{
- {"kind", 'k', 0, 0, "Print the type of store behind FILE"},
+ {"type", 't', 0, 0, "Print the type of store behind FILE"},
+ {"flags", 'f', 0, 0, "Print the flags associated with FILE's store"},
{"name", 'n', 0, 0, "Print the name of the store behind FILE"},
{"blocks", 'b', 0, 0, "Print the number of blocks in FILE"},
{"block-size", 'B', 0, 0, "Print the block size of FILE's store"},
{"size", 's', 0, 0, "Print the size, in bytes, of FILE"},
- {"runs", 'r', 0, 0, "Print the runs of blocks in FILE"},
+ {"block-list", 'l', 0, 0, "Print the blocks that are in FILE"},
{"children", 'c', 0, 0, "If the store has children, show them too"},
{"dereference", 'L', 0, 0, "If FILE is a symbolic link, follow it"},
{"prefix", 'p', 0, 0, "Always print `FILE: ' before info"},
@@ -48,26 +50,28 @@ static struct argp_option options[] =
{0, 0}
};
static char *args_doc = "FILE...";
-static char *doc = "With no FILE arguments, the file attached to standard \
-input is used. The fields to be printed are separated by colons, in this \
-order: PREFIX: KIND: NAME: BLOCK-SIZE: BLOCKS: SIZE: RUNS. If the store is a \
-composite one and --children is specified, children are printed on lines \
-following the main store, indented accordingly. By default, all \
-fields, and children, are printed.";
+static char *doc = "Show information about storage used by FILE..."
+"\vWith no FILE arguments, the file attached to standard"
+" input is used. The fields to be printed are separated by colons, in this"
+" order: PREFIX: TYPE (FLAGS): NAME: BLOCK-SIZE: BLOCKS: SIZE: BLOCK-LIST."
+" If the store is a composite one and --children is specified, children"
+" are printed on lines following the main store, indented accordingly."
+" By default, all fields, and children, are printed.";
/* ---------------------------------------------------------------- */
/* Things we can print about a file's storage. */
#define W_SOURCE 0x01
-#define W_KIND 0x02
+#define W_TYPE 0x02
#define W_NAME 0x04
#define W_BLOCKS 0x08
#define W_BLOCK_SIZE 0x10
#define W_SIZE 0x20
#define W_RUNS 0x40
#define W_CHILDREN 0x80
+#define W_FLAGS 0x100
-#define W_ALL 0xFF
+#define W_ALL 0x1FF
/* Print a line of information (exactly what is determinted by WHAT)
about store to stdout. LEVEL is the desired indentation level. */
@@ -87,7 +91,7 @@ print_store (struct store *store, int level, unsigned what)
putchar (' ');
}
}
- void pstr (char *str, unsigned mask)
+ void pstr (const char *str, unsigned mask)
{
if ((what & mask) == mask)
{
@@ -95,12 +99,20 @@ print_store (struct store *store, int level, unsigned what)
fputs (str ?: "-", stdout);
}
}
- void pint (off_t val, unsigned mask)
+ void psiz (size_t val, unsigned mask)
{
if ((what & mask) == mask)
{
psep ();
- printf ("%ld", val);
+ printf ("%zu", val);
+ }
+ }
+ void poff (store_offset_t val, unsigned mask)
+ {
+ if ((what & mask) == mask)
+ {
+ psep ();
+ printf ("%Ld", val);
}
}
@@ -111,9 +123,9 @@ print_store (struct store *store, int level, unsigned what)
putchar (' ');
}
- pstr (store->class->name,W_KIND);
+ pstr (store->class->name,W_TYPE);
- if (store->flags && (what & W_KIND))
+ if ((store->flags & ~STORE_INACTIVE) && (what & W_FLAGS))
{
int t = 0; /* flags tested */
int f = 1;
@@ -140,20 +152,20 @@ print_store (struct store *store, int level, unsigned what)
pf (STORE_ENFORCED, "enf");
pf (STORAGE_MUTATED, "mut");
- if (store->flags & ~t)
+ if (store->flags & ~(t | STORE_INACTIVE))
/* Leftover flags. */
{
if (! f)
putchar (';');
- printf ("0x%x", store->flags);
+ printf ("0x%x", store->flags & ~(t | STORE_INACTIVE));
}
- putchar ('(');
+ putchar (')');
}
pstr (store->name, W_NAME);
- pint (store->block_size, W_BLOCK_SIZE);
- pint (store->blocks, W_BLOCKS);
- pint (store->size, W_SIZE);
+ psiz (store->block_size, W_BLOCK_SIZE);
+ poff (store->blocks, W_BLOCKS);
+ poff (store->size, W_SIZE);
if (what & W_RUNS)
{
@@ -163,9 +175,10 @@ print_store (struct store *store, int level, unsigned what)
if (i > 0)
putchar (',');
if (store->runs[i].start < 0)
- printf ("[%ld]", store->runs[i].length);
+ /* A hole */
+ printf ("@+%Ld", store->runs[i].length);
else
- printf ("%ld[%ld]", store->runs[i].start, store->runs[i].length);
+ printf ("%Ld+%Ld", store->runs[i].start, store->runs[i].length);
}
}
@@ -177,8 +190,8 @@ print_store (struct store *store, int level, unsigned what)
print_store (store->children[i], level + 1, what);
}
-void
-main(int argc, char *argv[])
+int
+main (int argc, char *argv[])
{
int deref = 0, print_prefix = -1;
unsigned what = 0;
@@ -191,7 +204,7 @@ main(int argc, char *argv[])
struct store *store;
if (file == MACH_PORT_NULL)
- error (3, err, source);
+ error (3, err, "%s", source);
if (print_prefix < 0)
/* By default, only print filename prefixes for multiple files. */
@@ -200,9 +213,14 @@ main(int argc, char *argv[])
if (what == 0)
what = W_ALL;
- err = store_create (file, 0, 0, &store);
+ /* The STORE_NO_FILEIO flag tells it to give us the special
+ "unknown" class instead of an error if it cannot parse the
+ file_get_storage_info results. That will allow us to display
+ what we can from them, i.e. the name that shows at least some
+ of what the unknown data looked like. */
+ err = store_create (file, STORE_INACTIVE|STORE_NO_FILEIO, 0, &store);
if (err)
- error (4, err, source);
+ error (4, err, "%s", source);
print_store (store, 0, what);
store_free (store);
@@ -214,12 +232,13 @@ main(int argc, char *argv[])
case 'p': print_prefix = 1; break;
case 'P': print_prefix = 0; break;
- case 'k': what |= W_KIND; break;
+ case 't': what |= W_TYPE; break;
+ case 'f': what |= W_FLAGS; break;
case 'n': what |= W_NAME; break;
case 'b': what |= W_BLOCKS; break;
case 'B': what |= W_BLOCK_SIZE; break;
case 's': what |= W_SIZE; break;
- case 'r': what |= W_RUNS; break;
+ case 'l': what |= W_RUNS; break;
case 'c': what |= W_CHILDREN; break;
case ARGP_KEY_NO_ARGS:
@@ -245,5 +264,5 @@ main(int argc, char *argv[])
argp_parse (&argp, argc, argv, 0, 0, 0);
- exit(0);
+ return 0;
}