In response to reviewer comments, commit
fe56188b07 included changes
that modified some of the code used to output error messages when
checking user-supplied block numbers. These changes converted calls
to parse_ulonglong() to calls to strtoblk(). Because strtoblk() calls
parse_ulonglong(), and both output error messages, two redundant and
relatively generic messages were output on each error.
Fix this by removing the error message output from strtoblk(), and
extending it to accept an optional error message argument that it
supplies in lieu of a default to parse_ulonglong(). Also, revert to
the more descriptive original error messages with mods per reviewer
comments, and fix an error message in do_replace_node().
Signed-off-by: Eric Whitney <enwlinux@gmail.com>
Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
return;
break;
case 's':
- err = strtoblk(argv[0], optarg, &superblock);
+ err = strtoblk(argv[0], optarg,
+ "superblock block number", &superblock);
if (err)
return;
break;
return;
memset(¶m, 0, sizeof(struct ext2_super_block));
- err = strtoblk(argv[0], argv[2], &blocks);
+ err = strtoblk(argv[0], argv[2], "blocks count", &blocks);
if (err)
return;
ext2fs_blocks_count_set(¶m, blocks);
ino = string_to_inode(argv[1]);
if (!ino)
return;
- err = strtoblk(argv[0], argv[2], &blk);
+ err = strtoblk(argv[0], argv[2], "logical block", &blk);
if (err)
return;
ino = string_to_inode(argv[1]);
if (!ino)
return;
- err = strtoblk(argv[0], argv[2], &start);
+ err = strtoblk(argv[0], argv[2], "logical block", &start);
if (err)
return;
if (argc == 4) {
- err = strtoblk(argv[0], argv[3], &end);
+ err = strtoblk(argv[0], argv[3], "logical block", &end);
if (err)
return;
} else
"block size", 0);
break;
case 's':
- retval = strtoblk(argv[0], optarg, &superblock);
+ retval = strtoblk(argv[0], optarg,
+ "superblock block number",
+ &superblock);
if (retval)
return 1;
break;
const char *descr, int *err);
extern unsigned long long parse_ulonglong(const char *str, const char *cmd,
const char *descr, int *err);
-extern int strtoblk(const char *cmd, const char *str, blk64_t *ret);
+extern int strtoblk(const char *cmd, const char *str, const char *errmsg,
+ blk64_t *ret);
extern int common_args_process(int argc, char *argv[], int min_argc,
int max_argc, const char *cmd,
const char *usage, int flags);
return;
}
- err = strtoblk(argv[0], argv[1], &extent.e_lblk);
+ err = strtoblk(argv[0], argv[1], "logical block", &extent.e_lblk);
if (err)
return;
- extent.e_len = parse_ulong(argv[2], argv[0], "logical block", &err);
+ extent.e_len = parse_ulong(argv[2], argv[0], "length", &err);
if (err)
return;
- err = strtoblk(argv[0], argv[3], &extent.e_pblk);
+ err = strtoblk(argv[0], argv[3], "physical block", &extent.e_pblk);
if (err)
return;
return;
}
- err = strtoblk(cmd, argv[1], &extent.e_lblk);
+ err = strtoblk(cmd, argv[1], "logical block", &extent.e_lblk);
if (err)
return;
- extent.e_len = parse_ulong(argv[2], cmd,
- "length", &err);
+ extent.e_len = parse_ulong(argv[2], cmd, "length", &err);
if (err)
return;
- err = strtoblk(cmd, argv[3], &extent.e_pblk);
+ err = strtoblk(cmd, argv[3], "physical block", &extent.e_pblk);
if (err)
return;
return;
}
- err = strtoblk(cmd, argv[1], &logical);
+ err = strtoblk(cmd, argv[1], "logical block", &logical);
if (err)
return;
- err = strtoblk(cmd, argv[2], &physical);
+ err = strtoblk(cmd, argv[2], "physical block", &physical);
if (err)
return;
"block [level]", 0))
return;
- if (strtoblk(argv[0], argv[1], &blk))
+ if (strtoblk(argv[0], argv[1], NULL, &blk))
return;
if (argc == 3) {
}
for (i=1; i < argc; i++) {
- if (strtoblk(argv[0], argv[i], &bw.barray[i-1].blk))
+ if (strtoblk(argv[0], argv[i], NULL, &bw.barray[i-1].blk))
goto error_out;
}
/*
* This function will convert a string to a block number. It returns
- * 0 on success, 1 on failure.
+ * 0 on success, 1 on failure. On failure, it outputs either an optionally
+ * specified error message or a default.
*/
-int strtoblk(const char *cmd, const char *str, blk64_t *ret)
+int strtoblk(const char *cmd, const char *str, const char *errmsg,
+ blk64_t *ret)
{
blk64_t blk;
int err;
- blk = parse_ulonglong(str, cmd, "block number", &err);
+ if (errmsg == NULL)
+ blk = parse_ulonglong(str, cmd, "block number", &err);
+ else
+ blk = parse_ulonglong(str, cmd, errmsg, &err);
*ret = blk;
- if (err)
- com_err(cmd, 0, "Invalid block number: %s", str);
return err;
}
"<block> [count]", CHECK_FS_BITMAPS))
return 1;
- if (strtoblk(argv[0], argv[1], block))
+ if (strtoblk(argv[0], argv[1], NULL, block))
return 1;
if (*block == 0) {
com_err(argv[0], 0, "Invalid block number 0");
}
if (argc > 2) {
- err = strtoblk(argv[0], argv[2], count);
+ err = strtoblk(argv[0], argv[2], "count", count);
if (err)
return 1;
}