Project

General

Profile

Actions

Bug #640

open

number_to_scaled_string is duplicated in several commands

Added by Jason King over 12 years ago. Updated almost 6 years ago.

Status:
In Progress
Priority:
Normal
Assignee:
Category:
cmd - userland programs
Start date:
2011-01-17
Due date:
% Done:

100%

Estimated time:
Difficulty:
Medium
Tags:
needs-triage
Gerrit CR:
External Bug:

Description

du(1), df(1m), ls(1), and swap(1m) all include a copy (it appears literally copied) of the 'number_to_scaled_string' function in their source. This should be moved to a shared library and all 4 commands should use this instead.


Files

nicenum.diff (24.9 KB) nicenum.diff Jason King, 2015-04-10 11:03 PM

Related issues

Related to illumos gate - Bug #6259: size related bugs in /usr/bin/lsNew2015-09-24

Actions
Related to illumos gate - Bug #1202: "zdb -DD" histogram block count should be decimal-K/M based, not binaryNew2011-07-12

Actions
Related to illumos gate - Bug #9025: libzfs missing dependency on libcmdutilsClosedYuri Pankov2018-02-05

Actions
Has duplicate illumos gate - Feature #5827: Unify nicenum() in libcmdutilsClosed2015-04-10

Actions
Blocked by illumos gate - Bug #1140: sys/swap.h should work in large file environmentNew2011-06-23

Actions
Actions #1

Updated by Jason King over 12 years ago

Also, all the implementations (du/swap, df, ls) all use slightly different rounding algorithms, which can produce different results for the same value. Having consistency would probably be useful.

Actions #2

Updated by Albert Lee almost 12 years ago

  • Difficulty set to Medium
  • Tags set to needs-triage

The BSDs (all of 'em) call this humanize_number(3) and (9): http://www.daemon-systems.org/man/humanize_number.3.html ... and it's invertable with dehumanize_number().

Might be worth sticking to that interface.

Actions #3

Updated by Jason King almost 12 years ago

I had actually looked at that, but it's really overengineered.

The implementations in libzfs of nicenum (and it's inverse) seem much simpler and would work for anything I can forsee at least.

Actions #4

Updated by Albert Lee almost 12 years ago

Jason King wrote:

I had actually looked at that, but it's really overengineered.

The implementations in libzfs of nicenum (and it's inverse) seem much simpler and would work for anything I can forsee at least.

We can literally just copy the implementation, though. :)
It's in libbsd, the BSD compat library for GNU systems, which suggests there might be value in eventually making this a public interface.

It might even be cstyle clean:
http://cgit.freedesktop.org/libbsd/tree/src/humanize_number.c

Actions #5

Updated by Jason King about 8 years ago

Here's the work so far.. lint still produces a diarrhea of messages though.

Actions #6

Updated by Jason King over 7 years ago

  • Related to Bug #6259: size related bugs in /usr/bin/ls added
Actions #7

Updated by Jason King over 7 years ago

Current known list of duplicates:

du(1)
df(1m)
ls(1)
swap(1m)
beadm(1m)
zdb(1m)
fsstat(1m)
libzpool
libzfs
mdb dtrace module (dtrace_options_numtostr)
libipsecutil (bytecnt2str)
libpkg (pktstrScaleNumericString)
libmeta (meta_number_to_string)

Actions #8

Updated by Yuri Pankov about 6 years ago

Also cmd/dlstat, cmd/flowstat have copies of map_to_units(), these will require a bit more work, but will eventually benefit from single implementation as well.

Actions #9

Updated by Jason King almost 6 years ago

  • Status changed from New to In Progress
Actions #10

Updated by Gergő Mihály Doma almost 6 years ago

  • Related to Bug #1202: "zdb -DD" histogram block count should be decimal-K/M based, not binary added
Actions #11

Updated by Electric Monk almost 6 years ago

  • % Done changed from 0 to 100

git commit 0a0551200ecbcd4f1b17560acaeeb7b6c8b0090e

commit  0a0551200ecbcd4f1b17560acaeeb7b6c8b0090e
Author: Jason King <jason.brian.king@gmail.com>
Date:   2017-09-05T00:42:57.000Z

    640 number_to_scaled_string is duplicated in several commands
    Reviewed by: Sebastian Wiedenroth <wiedi@frubar.net>
    Reviewed by: Robert Mustacchi <rm@joyent.com>
    Reviewed by: Yuri Pankov <yuripv@gmx.com>
    Approved by: Dan McDonald <danmcd@joyent.com>

Actions #12

Updated by Yuri Pankov over 5 years ago

  • Related to Bug #9025: libzfs missing dependency on libcmdutils added
Actions

Also available in: Atom PDF