From: Long An <lan@suse.com>
To: "krisman@collabora.com" <krisman@collabora.com>
Cc: "fstests@vger.kernel.org" <fstests@vger.kernel.org>
Subject: Re: [PATCH v2 1/2] common/rc: add _parse_size_string
Date: Fri, 17 Jun 2022 06:45:05 +0000 [thread overview]
Message-ID: <7fd0397ba90e7b54f0ca86692cd0b085e63c7707.camel@suse.com> (raw)
In-Reply-To: <874k0ky6ju.fsf@collabora.com>
On Thu, 2022-06-16 at 11:25 -0400, Gabriel Krisman Bertazi wrote:
> An Long <lan@suse.com> writes:
>
> > + if [[ $str =~ ^[0-9]+[a-zA-Z]$ ]] ; then
> > + size=${str:: -1}
> > + endchar=${str: -1}
> > + case $endchar in
> > + e|E)
> > + mult=$((mult * 1024))
> > + ;&
> > + p|P)
> > + mult=$((mult * 1024))
> > + ;&
> > + t|T)
> > + mult=$((mult * 1024))
> > + ;&
> > + g|G)
> > + mult=$((mult * 1024))
> > + ;&
> > + m|M)
> > + mult=$((mult * 1024))
> > + ;&
> > + k|K)
> > + mult=$((mult * 1024))
> > + ;&
> > + b|B)
> > + ;;
> > + *)
> > + echo "unknown size descriptor
> > $endchar"
> > + exit 1
> > + esac
> > + elif [[ $str =~ ^[0-9]+$ ]] ; then
> > + size=$str
> > + else
> > + echo "size value $str is invalid"
> > + exit 1
> > + fi
> > +
> > + size=$((size * mult))
> > + echo $size
> > +}
>
> Hi An,
>
> Coreutils has numfmt(1) to do this kind of conversion. I wonder if
> we
> could use it here, unless it is not available all the platforms that
> matters for xfstests, though:
>
> $ echo 1K | numfmt --from=iec
> 1024
>
Hi Gabriel,
Using numfmt should reduce the code. But it brings new problems:
1) numfmt doesn't support lowercase
echo 4k | numfmt --from=iec
numfmt: invalid suffix in input: '4k'
2) This cannot clearly point out the error
3) Value range is limited
echo 16E | numfmt --from=iec
numfmt: value too large to be printed: '1.84467e+19' (consider using --
to)
4) Added system dependencies
More code is required to solve above problems, and not elegant.
> > +
> > # Create fs of certain size on scratch device
> > # _scratch_mkfs_sized <size in bytes> [optional blocksize]
> > _scratch_mkfs_sized()
--
An Long <lan@suse.com>
SUSE QE LSG, QE 2, Beijing
next prev parent reply other threads:[~2022-06-17 6:45 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-06-16 4:38 [PATCH v2 0/2] Fix input value to _scratch_mkfs_sized An Long
2022-06-16 4:38 ` [PATCH v2 1/2] common/rc: add _parse_size_string An Long
2022-06-16 15:25 ` Gabriel Krisman Bertazi
2022-06-17 6:45 ` Long An [this message]
2022-06-16 4:38 ` [PATCH v2 2/2] common/rc: fix input value to _scratch_mkfs_sized An Long
2022-06-17 3:58 ` [PATCH v2 0/2] Fix " Dave Chinner
2022-06-17 7:03 ` Long An
2022-06-17 17:52 ` Zorro Lang
2022-06-17 22:24 ` Dave Chinner
2022-06-18 3:14 ` Zorro Lang
2022-06-20 23:12 ` Dave Chinner
2022-06-21 4:05 ` Zorro Lang
2022-06-21 4:25 ` Long An
2022-06-21 4:40 ` Zorro Lang
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=7fd0397ba90e7b54f0ca86692cd0b085e63c7707.camel@suse.com \
--to=lan@suse.com \
--cc=fstests@vger.kernel.org \
--cc=krisman@collabora.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox