linux-btrfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 0/4] Btrfs-progs: cleanups: new helper for parsing string to u64
@ 2014-02-20  1:30 Wang Shilong
  2014-02-20  1:30 ` [PATCH v2 1/4] Btrfs-progs: new helper to parse string to u64 for btrfs Wang Shilong
                   ` (3 more replies)
  0 siblings, 4 replies; 8+ messages in thread
From: Wang Shilong @ 2014-02-20  1:30 UTC (permalink / raw)
  To: linux-btrfs

There are many places that need parse string to u64 for btrfs commands,
in fact, we do such things *too casually*, using atoi/atol/atoll..is not
right at all, and even we don't check whether it is a valid string.

Let's do everything more gracefully, we introduce a new helper
arg_strtou64() which will do all the necessary checks.If we fail to
parse string to u64, we will output message and exit directly, this is
something like what usage() is doing. It is ok to not return erro to
it's caller, because this function should be called when parsing arg
(just like usage!)

I convert most places to arg_strtou64, test patches with xfstests.
Feel free to review and comment.

Changelog v1->v2:
	s/btrfs_strtoull64/arg_strtou64 addressed by G.Baroncelli
	fix out of range check,support hex and octal numbers pointed by Stefan.
	add negative check pointed by Eric Sandeen.
	plus more codes cleanups.

Wang Shilong (4):
  Btrfs-progs: new helper to parse string to u64 for btrfs
  Btrfs-progs: switch to arg_strtou64() part1
  Btrfs-progs: switch to arg_strtou64() part2
  Btrfs-progs: switch to arg_strtou64() part3

 btrfs-corrupt-block.c | 45 +++++++++------------------------------------
 btrfs-debug-tree.c    |  2 +-
 btrfs-find-root.c     | 23 +++--------------------
 btrfs-image.c         | 12 ++++++------
 btrfs-list.c          | 14 +++-----------
 btrfs-map-logical.c   | 26 ++++++--------------------
 btrfs-select-super.c  | 12 +++++++++---
 btrfs-show-super.c    | 10 +++++-----
 btrfstune.c           |  4 ++--
 cmds-check.c          | 14 ++++++++++----
 cmds-inspect.c        |  8 ++++----
 cmds-replace.c        |  7 +------
 cmds-restore.c        | 27 +++++----------------------
 cmds-subvolume.c      |  8 ++------
 utils.c               | 35 ++++++++++++++++++++++++++++++++++-
 utils.h               |  1 +
 16 files changed, 101 insertions(+), 147 deletions(-)

-- 
1.8.3.1


^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2014-02-20 16:43 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-02-20  1:30 [PATCH v2 0/4] Btrfs-progs: cleanups: new helper for parsing string to u64 Wang Shilong
2014-02-20  1:30 ` [PATCH v2 1/4] Btrfs-progs: new helper to parse string to u64 for btrfs Wang Shilong
2014-02-20  1:39   ` Eric Sandeen
2014-02-20  1:43     ` Wang Shilong
2014-02-20 16:43       ` Eric Sandeen
2014-02-20  1:30 ` [PATCH v2 2/4] Btrfs-progs: switch to arg_strtou64() part1 Wang Shilong
2014-02-20  1:30 ` [PATCH v2 3/4] Btrfs-progs: switch to arg_strtou64() part2 Wang Shilong
2014-02-20  1:30 ` [PATCH v2 4/4] Btrfs-progs: switch to arg_strtou64() part3 Wang Shilong

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).