summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoland McGrath <roland@gnu.org>1999-10-03 10:23:20 +0000
committerRoland McGrath <roland@gnu.org>1999-10-03 10:23:20 +0000
commit85771440500ca6234a3bc9d609123dd99b680a4c (patch)
tree316a27f3ab38794c42226fe177ba0e9df2e3f793
parentddefbe973ca0616c045397d4ea4632822f6c3d13 (diff)
1999-10-03 Roland McGrath <roland@baalperazim.frob.com>
* ext2fs.h (sblock_block): Declare new variable. (SBLOCK_LBLOCK): Macro removed. (SBLOCK_OFFS): Define in terms of sblock_block. * ext2fs.c (options): Add --sblock/-S. (parse_opt): Parse it to set sblock_block. * hyper.c (sblock_block): New variable. (get_hypermetadata): Use sblock_block instead of constant SBLOCK_BLOCK. * ext2fs.c (options): List --debug/-D unconditionally, adding to help text #ifndef EXT2FS_DEBUG (parse_opt): Always grok -D. #ifndef EXT2FS_DEBUG, reject it with message saying debugging support not compiled in.
-rw-r--r--ext2fs/ext2fs.c48
1 files changed, 38 insertions, 10 deletions
diff --git a/ext2fs/ext2fs.c b/ext2fs/ext2fs.c
index 584e14ba..8cca73ed 100644
--- a/ext2fs/ext2fs.c
+++ b/ext2fs/ext2fs.c
@@ -63,9 +63,13 @@ int ext2_debug_flag = 0;
static const struct argp_option
options[] =
{
-#ifdef EXT2FS_DEBUG
- {"debug", 'D', 0, 0, "Toggle debugging output" },
+ {"debug", 'D', 0, 0, "Toggle debugging output"
+#ifndef EXT2FS_DEBUG
+ " (not compiled in)"
#endif
+ },
+ {"sblock", 'S', "BLOCKNO", 0,
+ "Use alternate superblock location (1kb blocks)"},
{0}
};
@@ -73,26 +77,50 @@ options[] =
static error_t
parse_opt (int key, char *arg, struct argp_state *state)
{
+ /* We save our parsed values in this structure, hung off STATE->hook.
+ Only after parsing all options successfully will we use these values. */
+ struct
+ {
+ int debug_flag;
+ unsigned int sb_block;
+ } *values = state->hook;
+
switch (key)
{
-#ifdef EXT2FS_DEBUG
case 'D':
- state->hook = (void *)1; /* Do it at the end */
+ values->debug_flag = 1;
+ break;
+ case 'S':
+ values->sb_block = strtoul (arg, &arg, 0);
+ if (!arg || *arg != '\0')
+ {
+ argp_error (state, "invalid number for --sblock");
+ return EINVAL;
+ }
break;
-#endif
case ARGP_KEY_INIT:
state->child_inputs[0] = state->input;
-#ifdef EXT2FS_DEBUG
- state->hook = 0;
-#endif
+ values = malloc (sizeof *values);
+ if (values == 0)
+ return ENOMEM;
+ state->hook = values;
+ bzero (values, sizeof *values);
+ values->sb_block = SBLOCK_BLOCK;
break;
+
case ARGP_KEY_SUCCESS:
/* All options parse successfully, so implement ours if possible. */
+ if (values->debug_flag)
+ {
#ifdef EXT2FS_DEBUG
- if (state->hook)
- ext2_debug_flag = !ext2_debug_flag;
+ ext2_debug_flag = !ext2_debug_flag;
+#else
+ argp_failure (state, 2, 0, "debugging support not compiled in");
+ return EINVAL;
#endif
+ }
+
break;
default: